]> granicus.if.org Git - icinga2/blob - test/base-dictionary.cpp
Removed x64 build target (use Win64 instead).
[icinga2] / test / base-dictionary.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #include <boost/test/unit_test.hpp>
21
22 #include <i2-base.h>
23
24 using namespace icinga;
25
26 BOOST_AUTO_TEST_SUITE(base_dictionary)
27
28 BOOST_AUTO_TEST_CASE(construct)
29 {
30         Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
31         BOOST_CHECK(dictionary);
32 }
33
34 BOOST_AUTO_TEST_CASE(getproperty)
35 {
36         Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
37         dictionary->Set("test1", 7);
38         dictionary->Set("test2", "hello world");
39
40         Value test1;
41         test1 = dictionary->Get("test1");
42         BOOST_CHECK(test1 == 7);
43
44         Value test2;
45         test2 = dictionary->Get("test2");
46         BOOST_CHECK(test2 == "hello world");
47
48         Value test3;
49         test3 = dictionary->Get("test3");
50         BOOST_CHECK(test3.IsEmpty());
51 }
52
53 BOOST_AUTO_TEST_CASE(getproperty_dict)
54 {
55         Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
56         Dictionary::Ptr other = boost::make_shared<Dictionary>();
57
58         dictionary->Set("test1", other);
59
60         Dictionary::Ptr test1 = dictionary->Get("test1");
61         BOOST_CHECK(other == test1);
62
63         Dictionary::Ptr test2 = dictionary->Get("test2");
64         BOOST_CHECK(!test2);
65 }
66
67 BOOST_AUTO_TEST_CASE(unnamed)
68 {
69         Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
70         dictionary->Add("test1");
71         dictionary->Add("test2");
72         dictionary->Add("test3");
73
74         BOOST_CHECK(distance(dictionary->Begin(), dictionary->End()) == 3);
75 }
76
77 BOOST_AUTO_TEST_CASE(unnamed_order)
78 {
79         Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
80
81         for (int i = 0; i < 1000; i++)
82                 dictionary->Add(i);
83
84         /* unnamed items are guaranteed to be in whatever order they were
85          * inserted in. */
86         Value value;
87         int i = 0;
88         BOOST_FOREACH(tie(tuples::ignore, value), dictionary) {
89                 BOOST_CHECK(value == i);
90                 i++;
91         }
92 }
93
94 BOOST_AUTO_TEST_SUITE_END()