Merge branch 'daemon-ext'
[libi2ncommon] / test / test_containerfunc.cpp
CommitLineData
0e23f538
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
57e78ccd
RP
20/** @file
21 *
22 * tests for the module "containerfunc"
23 *
24 * (c) Copyright 2007-2008 by Intra2net AG
57e78ccd
RP
25 */
26
27//#define NOISEDEBUG
28
29#include <string>
30#include <vector>
31#include <list>
32#include <algorithm>
33
9fe0853b
TJ
34#define BOOST_TEST_DYN_LINK
35#include <boost/test/unit_test.hpp>
57e78ccd
RP
36
37#include <containerfunc.hpp>
38
9fe0853b 39using namespace I2n;
57e78ccd 40
9fe0853b 41BOOST_AUTO_TEST_SUITE(TestContainerFunc)
57e78ccd 42
9fe0853b
TJ
43BOOST_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");
57e78ccd 49
9fe0853b
TJ
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]);
57e78ccd 54
9fe0853b 55 get_push_back_filler(v)("i3")("i4");
57e78ccd 56
9fe0853b
TJ
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
57e78ccd 61
57e78ccd
RP
62
63
9fe0853b 64BOOST_AUTO_TEST_CASE(RetrieveMapKeys)
57e78ccd 65{
9fe0853b
TJ
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
96BOOST_AUTO_TEST_SUITE_END()