1 /******************************************************************************
3 * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
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. *
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. *
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 ******************************************************************************/
20 #include "icinga/perfdatavalue.h"
21 #include "base/dictionary.h"
22 #include "base/objectlock.h"
23 #include "base/serializer.h"
24 #include "base/array.h"
25 #include "base/dictionary.h"
26 #include <boost/test/unit_test.hpp>
27 #include <boost/foreach.hpp>
28 #include <boost/tuple/tuple.hpp>
30 using namespace icinga;
32 BOOST_AUTO_TEST_SUITE(base_serialize)
34 BOOST_AUTO_TEST_CASE(scalar)
36 BOOST_CHECK(Deserialize(Serialize(7)) == 7);
37 BOOST_CHECK(Deserialize(Serialize(7.3)) == 7.3);
38 BOOST_CHECK(Deserialize(Serialize(Empty)) == Empty);
39 BOOST_CHECK(Deserialize(Serialize("hello")) == "hello");
42 BOOST_AUTO_TEST_CASE(array)
44 Array::Ptr array = make_shared<Array>();
50 Array::Ptr result = Deserialize(Serialize(array));
52 BOOST_CHECK(result->GetLength() == array->GetLength());
54 BOOST_CHECK(result->Get(0) == 7);
55 BOOST_CHECK(result->Get(1) == 7.3);
56 BOOST_CHECK(result->Get(2) == Empty);
57 BOOST_CHECK(result->Get(3) == "hello");
60 BOOST_AUTO_TEST_CASE(dictionary)
62 Dictionary::Ptr dict = make_shared<Dictionary>();
65 dict->Set("k3", Empty);
66 dict->Set("k4", "hello");
68 Dictionary::Ptr result = Deserialize(Serialize(dict));
70 BOOST_CHECK(result->GetLength() == dict->GetLength());
72 BOOST_CHECK(result->Get("k1") == 7);
73 BOOST_CHECK(result->Get("k2") == 7.3);
74 BOOST_CHECK(result->Get("k3") == Empty);
75 BOOST_CHECK(result->Get("k4") == "hello");
78 BOOST_AUTO_TEST_CASE(object)
80 PerfdataValue::Ptr pdv = make_shared<PerfdataValue>(100, true, "bytes");
82 PerfdataValue::Ptr result = Deserialize(Serialize(pdv));
84 BOOST_CHECK(result->GetValue() == pdv->GetValue());
87 BOOST_AUTO_TEST_SUITE_END()