]> granicus.if.org Git - icinga2/blob - test/base-dictionary.cpp
Renamed Dictionary::{Set,Get}Property -> Dictionary::{Set,Get}
[icinga2] / test / base-dictionary.cpp
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_MODULE base_dictionary
3 #include <boost/test/unit_test.hpp>
4
5 #include <i2-base.h>
6 using namespace icinga;
7
8 BOOST_AUTO_TEST_CASE(construct)
9 {
10         Dictionary::Ptr dictionary = make_shared<Dictionary>();
11         BOOST_REQUIRE(dictionary);
12 }
13
14 BOOST_AUTO_TEST_CASE(getproperty)
15 {
16         Dictionary::Ptr dictionary = make_shared<Dictionary>();
17         dictionary->Set("test1", 7);
18         dictionary->Set("test2", "hello world");
19
20         long test1;
21         BOOST_REQUIRE(dictionary->Get("test1", &test1));
22         BOOST_REQUIRE(test1 == 7);
23
24         string test2;
25         BOOST_REQUIRE(dictionary->Get("test2", &test2));
26         BOOST_REQUIRE(test2 == "hello world");
27
28         long test3;
29         BOOST_REQUIRE(!dictionary->Get("test3", &test3));
30 }
31
32 BOOST_AUTO_TEST_CASE(getproperty_dict)
33 {
34         Dictionary::Ptr dictionary = make_shared<Dictionary>();
35         Dictionary::Ptr other = make_shared<Dictionary>();
36
37         dictionary->Set("test1", other);
38
39         Dictionary::Ptr test1;
40         BOOST_REQUIRE(dictionary->Get("test1", &test1));
41         BOOST_REQUIRE(other == test1);
42
43         Dictionary::Ptr test2;
44         BOOST_REQUIRE(!dictionary->Get("test2", &test2));
45 }
46
47 BOOST_AUTO_TEST_CASE(unnamed)
48 {
49         Dictionary::Ptr dictionary = make_shared<Dictionary>();
50         dictionary->Add("test1");
51         dictionary->Add("test2");
52         dictionary->Add("test3");
53
54         BOOST_REQUIRE(distance(dictionary->Begin(), dictionary->End()) == 3);
55 }