1 /******************************************************************************
3 * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
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 "base/perfdatavalue.hpp"
21 #include "base/dictionary.hpp"
22 #include "base/objectlock.hpp"
23 #include "base/serializer.hpp"
24 #include "base/array.hpp"
25 #include "base/dictionary.hpp"
26 #include <BoostTestTargetConfig.h>
27 #include <boost/tuple/tuple.hpp>
29 using namespace icinga;
31 BOOST_AUTO_TEST_SUITE(base_serialize)
33 BOOST_AUTO_TEST_CASE(scalar)
35 BOOST_CHECK(Deserialize(Serialize(7)) == 7);
36 BOOST_CHECK(Deserialize(Serialize(7.3)) == 7.3);
37 BOOST_CHECK(Deserialize(Serialize(Empty)) == Empty);
38 BOOST_CHECK(Deserialize(Serialize("hello")) == "hello");
41 BOOST_AUTO_TEST_CASE(array)
43 Array::Ptr array = new Array();
49 Array::Ptr result = Deserialize(Serialize(array));
51 BOOST_CHECK(result->GetLength() == array->GetLength());
53 BOOST_CHECK(result->Get(0) == 7);
54 BOOST_CHECK(result->Get(1) == 7.3);
55 BOOST_CHECK(result->Get(2) == Empty);
56 BOOST_CHECK(result->Get(3) == "hello");
59 BOOST_AUTO_TEST_CASE(dictionary)
61 Dictionary::Ptr dict = new Dictionary();
64 dict->Set("k3", Empty);
65 dict->Set("k4", "hello");
67 Dictionary::Ptr result = Deserialize(Serialize(dict));
69 BOOST_CHECK(result->GetLength() == dict->GetLength());
71 BOOST_CHECK(result->Get("k1") == 7);
72 BOOST_CHECK(result->Get("k2") == 7.3);
73 BOOST_CHECK(result->Get("k3") == Empty);
74 BOOST_CHECK(result->Get("k4") == "hello");
77 BOOST_AUTO_TEST_CASE(object)
79 PerfdataValue::Ptr pdv = new PerfdataValue("size", 100, true, "bytes");
81 PerfdataValue::Ptr result = Deserialize(Serialize(pdv));
83 BOOST_CHECK(result->GetValue() == pdv->GetValue());
86 BOOST_AUTO_TEST_SUITE_END()