X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=test%2Fbase-array.cpp;h=33e54e8f142526ac9089652fb47529840d5b5707;hb=7c1f716dad8c959ef30944035ef9e2c296cadcb2;hp=0e2d024fcb34f176d77020d9e0304c4b9cf2cb25;hpb=78bfd0204c376d87129b3140ceef027f63dcf63e;p=icinga2 diff --git a/test/base-array.cpp b/test/base-array.cpp index 0e2d024fc..33e54e8f1 100644 --- a/test/base-array.cpp +++ b/test/base-array.cpp @@ -1,27 +1,9 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software Foundation * - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ******************************************************************************/ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "base/array.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" -#include -#include +#include using namespace icinga; @@ -92,7 +74,7 @@ BOOST_AUTO_TEST_CASE(remove) { ObjectLock olock(array); - Array::Iterator it = array->Begin(); + auto it = array->Begin(); array->Remove(it); } @@ -103,6 +85,27 @@ BOOST_AUTO_TEST_CASE(remove) BOOST_CHECK(array->GetLength() == 0); } +BOOST_AUTO_TEST_CASE(unique) +{ + Array::Ptr array = new Array(); + array->Add("group1"); + array->Add("group2"); + array->Add("group1"); + array->Add("group2"); + + Array::Ptr result; + + { + ObjectLock olock(array); + result = array->Unique(); + } + + BOOST_CHECK(result->GetLength() == 2); + result->Sort(); + + BOOST_CHECK(result->Get(0) == "group1"); + BOOST_CHECK(result->Get(1) == "group2"); +} BOOST_AUTO_TEST_CASE(foreach) { Array::Ptr array = new Array(); @@ -114,7 +117,7 @@ BOOST_AUTO_TEST_CASE(foreach) int n = 0; - BOOST_FOREACH(const Value& item, array) { + for (const Value& item : array) { BOOST_CHECK(n != 0 || item == 7); BOOST_CHECK(n != 1 || item == 2); BOOST_CHECK(n != 2 || item == 5);