summaryrefslogtreecommitdiffstats
path: root/test/base-serialize.cpp
blob: 3293f86ab7a96f8b4c3404014f5a81996c4566ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */

#include "base/perfdatavalue.hpp"
#include "base/dictionary.hpp"
#include "base/objectlock.hpp"
#include "base/serializer.hpp"
#include "base/array.hpp"
#include "base/dictionary.hpp"
#include <BoostTestTargetConfig.h>

using namespace icinga;

BOOST_AUTO_TEST_SUITE(base_serialize)

BOOST_AUTO_TEST_CASE(scalar)
{
	BOOST_CHECK(Deserialize(Serialize(7)) == 7);
	BOOST_CHECK(Deserialize(Serialize(7.3)) == 7.3);
	BOOST_CHECK(Deserialize(Serialize(Empty)) == Empty);
	BOOST_CHECK(Deserialize(Serialize("hello")) == "hello");
}

BOOST_AUTO_TEST_CASE(array)
{
	Array::Ptr array = new Array();
	array->Add(7);
	array->Add(7.3);
	array->Add(Empty);
	array->Add("hello");

	Array::Ptr result = Deserialize(Serialize(array));

	BOOST_CHECK(result->GetLength() == array->GetLength());

	BOOST_CHECK(result->Get(0) == 7);
	BOOST_CHECK(result->Get(1) == 7.3);
	BOOST_CHECK(result->Get(2) == Empty);
	BOOST_CHECK(result->Get(3) == "hello");
}

BOOST_AUTO_TEST_CASE(dictionary)
{
	Dictionary::Ptr dict = new Dictionary();
	dict->Set("k1", 7);
	dict->Set("k2", 7.3);
	dict->Set("k3", Empty);
	dict->Set("k4", "hello");

	Dictionary::Ptr result = Deserialize(Serialize(dict));

	BOOST_CHECK(result->GetLength() == dict->GetLength());

	BOOST_CHECK(result->Get("k1") == 7);
	BOOST_CHECK(result->Get("k2") == 7.3);
	BOOST_CHECK(result->Get("k3") == Empty);
	BOOST_CHECK(result->Get("k4") == "hello");
}

BOOST_AUTO_TEST_CASE(object)
{
	PerfdataValue::Ptr pdv = new PerfdataValue("size", 100, true, "bytes");

	PerfdataValue::Ptr result = Deserialize(Serialize(pdv));

	BOOST_CHECK(result->GetValue() == pdv->GetValue());
}

BOOST_AUTO_TEST_SUITE_END()