From 0915b3ef56dfac3113cce55a59a5765dc94976be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:34:54 +0200 Subject: Adding upstream version 2.13.6. Signed-off-by: Daniel Baumann --- test/base-serialize.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/base-serialize.cpp (limited to 'test/base-serialize.cpp') diff --git a/test/base-serialize.cpp b/test/base-serialize.cpp new file mode 100644 index 0000000..3293f86 --- /dev/null +++ b/test/base-serialize.cpp @@ -0,0 +1,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 + +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() -- cgit v1.2.3