]> granicus.if.org Git - icinga2/blobdiff - test/base-dictionary.cpp
Merge pull request #5925 from Icinga/fix/missing-variable-name
[icinga2] / test / base-dictionary.cpp
index 5ef3b714c8562b77843cd99a334c6c5898456f85..466892dc7ebb8e63af13d1ce49a39f68f2bec1bd 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * Icinga 2                                                                   *
- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
+ * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
  *                                                                            *
  * This program is free software; you can redistribute it and/or              *
  * modify it under the terms of the GNU General Public License                *
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#include "base/dictionary.h"
-#include "base/objectlock.h"
-#include <boost/test/unit_test.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
-#include <boost/foreach.hpp>
-#include <boost/tuple/tuple.hpp>
+#include "base/dictionary.hpp"
+#include "base/objectlock.hpp"
+#include "base/json.hpp"
+#include <BoostTestTargetConfig.h>
 
 using namespace icinga;
 
@@ -30,13 +28,13 @@ BOOST_AUTO_TEST_SUITE(base_dictionary)
 
 BOOST_AUTO_TEST_CASE(construct)
 {
-       Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
+       Dictionary::Ptr dictionary = new Dictionary();
        BOOST_CHECK(dictionary);
 }
 
 BOOST_AUTO_TEST_CASE(get1)
 {
-       Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
+       Dictionary::Ptr dictionary = new Dictionary();
        dictionary->Set("test1", 7);
        dictionary->Set("test2", "hello world");
 
@@ -58,8 +56,8 @@ BOOST_AUTO_TEST_CASE(get1)
 
 BOOST_AUTO_TEST_CASE(get2)
 {
-       Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
-       Dictionary::Ptr other = boost::make_shared<Dictionary>();
+       Dictionary::Ptr dictionary = new Dictionary();
+       Dictionary::Ptr other = new Dictionary();
 
        dictionary->Set("test1", other);
 
@@ -74,7 +72,7 @@ BOOST_AUTO_TEST_CASE(get2)
 
 BOOST_AUTO_TEST_CASE(foreach)
 {
-       Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
+       Dictionary::Ptr dictionary = new Dictionary();
        dictionary->Set("test1", 7);
        dictionary->Set("test2", "hello world");
 
@@ -82,23 +80,21 @@ BOOST_AUTO_TEST_CASE(foreach)
 
        bool seen_test1 = false, seen_test2 = false;
 
-       String key;
-       Value value;
-       BOOST_FOREACH(boost::tie(key, value), dictionary) {
-               BOOST_CHECK(key == "test1" || key == "test2");
+       for (const Dictionary::Pair& kv : dictionary) {
+               BOOST_CHECK(kv.first == "test1" || kv.first == "test2");
 
-               if (key == "test1") {
+               if (kv.first == "test1") {
                        BOOST_CHECK(!seen_test1);
                        seen_test1 = true;
 
-                       BOOST_CHECK(value == 7);
+                       BOOST_CHECK(kv.second == 7);
 
                        continue;
-               } else if (key == "test2") {
+               } else if (kv.first == "test2") {
                        BOOST_CHECK(!seen_test2);
                        seen_test2 = true;
 
-                       BOOST_CHECK(value == "hello world");
+                       BOOST_CHECK(kv.second == "hello world");
                }
        }
 
@@ -108,7 +104,7 @@ BOOST_AUTO_TEST_CASE(foreach)
 
 BOOST_AUTO_TEST_CASE(remove)
 {
-       Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
+       Dictionary::Ptr dictionary = new Dictionary();
 
        dictionary->Set("test1", 7);
        dictionary->Set("test2", "hello world");
@@ -118,6 +114,11 @@ BOOST_AUTO_TEST_CASE(remove)
 
        dictionary->Set("test1", Empty);
 
+       BOOST_CHECK(dictionary->Contains("test1"));
+       BOOST_CHECK(dictionary->GetLength() == 2);
+
+       dictionary->Remove("test1");
+
        BOOST_CHECK(!dictionary->Contains("test1"));
        BOOST_CHECK(dictionary->GetLength() == 1);
 
@@ -141,7 +142,7 @@ BOOST_AUTO_TEST_CASE(remove)
 
 BOOST_AUTO_TEST_CASE(clone)
 {
-       Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
+       Dictionary::Ptr dictionary = new Dictionary();
 
        dictionary->Set("test1", 7);
        dictionary->Set("test2", "hello world");
@@ -162,16 +163,16 @@ BOOST_AUTO_TEST_CASE(clone)
        BOOST_CHECK(dictionary->Get("test2") == "hello world");
 }
 
-BOOST_AUTO_TEST_CASE(serialize)
+BOOST_AUTO_TEST_CASE(json)
 {
-       Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
+       Dictionary::Ptr dictionary = new Dictionary();
 
        dictionary->Set("test1", 7);
        dictionary->Set("test2", "hello world");
 
-       String json = Value(dictionary).Serialize();
+       String json = JsonEncode(dictionary);
        BOOST_CHECK(json.GetLength() > 0);
-       Dictionary::Ptr deserialized = Value::Deserialize(json);
+       Dictionary::Ptr deserialized = JsonDecode(json);
        BOOST_CHECK(deserialized->GetLength() == 2);
        BOOST_CHECK(deserialized->Get("test1") == 7);
        BOOST_CHECK(deserialized->Get("test2") == "hello world");