change permissions before fsync()
[libi2ncommon] / test / test_containerfunc.cpp
1 /*
2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
4
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
7
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
13
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
16
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
19 */
20 /** @file
21  *
22  * tests for the module "containerfunc"
23  *
24  * (c) Copyright 2007-2008 by Intra2net AG
25  */
26
27 //#define NOISEDEBUG
28
29 #include <string>
30 #include <vector>
31 #include <list>
32 #include <algorithm>
33
34 #define BOOST_TEST_DYN_LINK
35 #include <boost/test/unit_test.hpp>
36
37 #include <containerfunc.hpp>
38
39 using namespace I2n;
40
41 BOOST_AUTO_TEST_SUITE(TestContainerFunc)
42
43 BOOST_AUTO_TEST_CASE(FillStringVector)
44 {
45     std::vector< std::string > v;
46     BOOST_CHECK_EQUAL( true, v.empty() );
47
48     get_push_back_filler(v)("1")("2")("drei");
49
50     BOOST_CHECK_EQUAL( 3u, v.size() );
51     BOOST_CHECK_EQUAL( std::string("2"), v[1]);
52     BOOST_CHECK_EQUAL( std::string("drei"), v[2]);
53     BOOST_CHECK_EQUAL( std::string("1"), v[0]);
54
55     get_push_back_filler(v)("i3")("i4");
56
57     BOOST_CHECK_EQUAL( 5u, v.size() );
58     BOOST_CHECK_EQUAL( std::string("i4"), v[4]);
59     BOOST_CHECK_EQUAL( std::string("i3"), v[3]);
60 } // eo FillStringVector
61
62
63
64 BOOST_AUTO_TEST_CASE(RetrieveMapKeys)
65 {
66     std::map< int, std::string > map1;
67     std::list< int > key_list;
68     std::set< int > key_set;
69
70     {
71         MapFiller< int, std::string > fill(map1);
72         fill
73             (1, "one")
74             (2, "two")
75             (3, "three" )
76             (4, "many..." )
77         ;
78     }
79     BOOST_CHECK_EQUAL( 4u, map1.size() );
80
81     get_key_list(map1, key_list);
82     BOOST_CHECK_EQUAL( 4u, key_list.size() );
83     BOOST_CHECK( std::find(key_list.begin(), key_list.end(), 1) != key_list.end() );
84     BOOST_CHECK( std::find(key_list.begin(), key_list.end(), 2) != key_list.end() );
85     BOOST_CHECK( std::find(key_list.begin(), key_list.end(), 3) != key_list.end() );
86     BOOST_CHECK( std::find(key_list.begin(), key_list.end(), 4) != key_list.end() );
87
88     get_key_set(map1, key_set);
89     BOOST_CHECK_EQUAL( 4u, key_set.size() );
90     BOOST_CHECK( key_set.find(1) != key_set.end() );
91     BOOST_CHECK( key_set.find(2) != key_set.end() );
92     BOOST_CHECK( key_set.find(3) != key_set.end() );
93     BOOST_CHECK( key_set.find(4) != key_set.end() );
94 } // RetrieveMapKeys()
95
96 BOOST_AUTO_TEST_SUITE_END()