]> granicus.if.org Git - icinga2/blob - test/base-serialize.cpp
Merge pull request #6602 from Icinga/fix/improve-tls-handshake-exception-logging
[icinga2] / test / base-serialize.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
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/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
28 using namespace icinga;
29
30 BOOST_AUTO_TEST_SUITE(base_serialize)
31
32 BOOST_AUTO_TEST_CASE(scalar)
33 {
34         BOOST_CHECK(Deserialize(Serialize(7)) == 7);
35         BOOST_CHECK(Deserialize(Serialize(7.3)) == 7.3);
36         BOOST_CHECK(Deserialize(Serialize(Empty)) == Empty);
37         BOOST_CHECK(Deserialize(Serialize("hello")) == "hello");
38 }
39
40 BOOST_AUTO_TEST_CASE(array)
41 {
42         Array::Ptr array = new Array();
43         array->Add(7);
44         array->Add(7.3);
45         array->Add(Empty);
46         array->Add("hello");
47
48         Array::Ptr result = Deserialize(Serialize(array));
49
50         BOOST_CHECK(result->GetLength() == array->GetLength());
51
52         BOOST_CHECK(result->Get(0) == 7);
53         BOOST_CHECK(result->Get(1) == 7.3);
54         BOOST_CHECK(result->Get(2) == Empty);
55         BOOST_CHECK(result->Get(3) == "hello");
56 }
57
58 BOOST_AUTO_TEST_CASE(dictionary)
59 {
60         Dictionary::Ptr dict = new Dictionary();
61         dict->Set("k1", 7);
62         dict->Set("k2", 7.3);
63         dict->Set("k3", Empty);
64         dict->Set("k4", "hello");
65
66         Dictionary::Ptr result = Deserialize(Serialize(dict));
67
68         BOOST_CHECK(result->GetLength() == dict->GetLength());
69
70         BOOST_CHECK(result->Get("k1") == 7);
71         BOOST_CHECK(result->Get("k2") == 7.3);
72         BOOST_CHECK(result->Get("k3") == Empty);
73         BOOST_CHECK(result->Get("k4") == "hello");
74 }
75
76 BOOST_AUTO_TEST_CASE(object)
77 {
78         PerfdataValue::Ptr pdv = new PerfdataValue("size", 100, true, "bytes");
79
80         PerfdataValue::Ptr result = Deserialize(Serialize(pdv));
81
82         BOOST_CHECK(result->GetValue() == pdv->GetValue());
83 }
84
85 BOOST_AUTO_TEST_SUITE_END()