]> granicus.if.org Git - icinga2/blob - test/base-dictionary.cpp
3196b4dfbee1faa5e153a8aaa58bc54c7184b274
[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 "base/dictionary.h"
21 #include <boost/test/unit_test.hpp>
22 #include <boost/smart_ptr/make_shared.hpp>
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_SUITE_END()