2012-05-28 11:53:51 +02:00
|
|
|
#define BOOST_TEST_DYN_LINK
|
|
|
|
#define BOOST_TEST_MODULE base_dictionary
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
#include <i2-base.h>
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(construct)
|
|
|
|
{
|
2012-07-10 09:44:11 +02:00
|
|
|
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
2012-05-28 11:53:51 +02:00
|
|
|
BOOST_REQUIRE(dictionary);
|
|
|
|
}
|
|
|
|
|
2012-05-29 06:25:01 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(getproperty)
|
2012-05-28 11:53:51 +02:00
|
|
|
{
|
2012-07-10 09:44:11 +02:00
|
|
|
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
2012-07-09 16:19:56 +02:00
|
|
|
dictionary->Set("test1", 7);
|
|
|
|
dictionary->Set("test2", "hello world");
|
2012-05-28 11:53:51 +02:00
|
|
|
|
2012-09-14 11:41:15 +02:00
|
|
|
Value test1;
|
|
|
|
test1 = dictionary->Get("test1");
|
2012-05-28 11:53:51 +02:00
|
|
|
BOOST_REQUIRE(test1 == 7);
|
|
|
|
|
2012-09-14 11:41:15 +02:00
|
|
|
Value test2;
|
|
|
|
test2 = dictionary->Get("test2");
|
2012-05-28 11:53:51 +02:00
|
|
|
BOOST_REQUIRE(test2 == "hello world");
|
2012-05-29 06:25:01 +02:00
|
|
|
|
2012-09-14 11:41:15 +02:00
|
|
|
Value test3;
|
|
|
|
test3 = dictionary->Get("test3");
|
|
|
|
BOOST_REQUIRE(test3.IsEmpty());
|
2012-05-29 06:25:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(getproperty_dict)
|
|
|
|
{
|
2012-07-10 09:44:11 +02:00
|
|
|
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
|
|
|
Dictionary::Ptr other = boost::make_shared<Dictionary>();
|
2012-05-29 06:25:01 +02:00
|
|
|
|
2012-07-09 16:19:56 +02:00
|
|
|
dictionary->Set("test1", other);
|
2012-05-29 06:25:01 +02:00
|
|
|
|
2012-09-14 11:41:15 +02:00
|
|
|
Dictionary::Ptr test1 = dictionary->Get("test1");
|
2012-05-29 06:25:01 +02:00
|
|
|
BOOST_REQUIRE(other == test1);
|
|
|
|
|
2012-09-14 11:41:15 +02:00
|
|
|
Dictionary::Ptr test2 = dictionary->Get("test2");
|
|
|
|
BOOST_REQUIRE(!test2);
|
2012-05-29 06:25:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(unnamed)
|
|
|
|
{
|
2012-07-10 09:44:11 +02:00
|
|
|
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
2012-07-09 16:19:56 +02:00
|
|
|
dictionary->Add("test1");
|
|
|
|
dictionary->Add("test2");
|
|
|
|
dictionary->Add("test3");
|
2012-05-29 06:25:01 +02:00
|
|
|
|
|
|
|
BOOST_REQUIRE(distance(dictionary->Begin(), dictionary->End()) == 3);
|
2012-05-28 11:53:51 +02:00
|
|
|
}
|
2013-02-07 09:36:17 +01:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(unnamed_order)
|
|
|
|
{
|
|
|
|
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
|
|
|
|
|
|
|
for (int i = 0; i < 1000; i++)
|
|
|
|
dictionary->Add(i);
|
|
|
|
|
|
|
|
/* unnamed items are guaranteed to be in whatever order they were
|
|
|
|
* inserted in. */
|
|
|
|
String key;
|
|
|
|
Value value;
|
|
|
|
int i = 0;
|
|
|
|
BOOST_FOREACH(tie(key, value), dictionary) {
|
|
|
|
BOOST_REQUIRE(value == i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|