AC_CHECK_LIB(shlwapi, PathRemoveFileSpecA)
AC_CHECK_FUNCS([backtrace_symbols execvpe pipe2])
+CFLAGS="$CFLAGS -Wall -Wextra"
+CXXFLAGS="$CXXFLAGS -Wall -Wextra"
+
AC_MSG_CHECKING(whether to enable debugging)
AC_ARG_ENABLE(debug, [ --enable-debug=[no/yes] turn on debugging (default=no)],, enable_debug=no)
if test "x$enable_debug" = "xyes"; then
- CFLAGS="$CFLAGS -g -O0 -D_DEBUG -Wall -Wextra"
- CXXFLAGS="$CXXFLAGS -g -O0 -D_DEBUG -Wall -Wextra"
+ CFLAGS="$CFLAGS -g -O0 -D_DEBUG"
+ CXXFLAGS="$CXXFLAGS -g -O0 -D_DEBUG"
else
CFLAGS="$CFLAGS -DNDEBUG"
CXXFLAGS="$CXXFLAGS -DNDEBUG"
fi
AC_MSG_RESULT($enable_debug)
+AC_MSG_CHECKING(whether to enable coverage)
+AC_ARG_ENABLE(coverage, [ --enable-coverage=[no/yes] turn on profiling (default=no)],, enable_coverage=no)
+if test "x$enable_coverage" = "xyes"; then
+ CFLAGS="$CFLAGS -g -O0 -fprofile-arcs -ftest-coverage -lgcov"
+ CXXFLAGS="$CXXFLAGS -g -O0 -fprofile-arcs -ftest-coverage -lgcov"
+fi
+AC_MSG_RESULT($enable_coverage)
+
AX_PYTHON_DEFAULT
AX_PYTHON_ENABLE
AX_PYTHON_VERSION_ENSURE([2.5])
icinga2_test_SOURCES = \
test.cpp \
+ base-array.cpp \
+ base-convert.cpp \
base-dictionary.cpp \
+ base-fifo.cpp \
+ base-object.cpp \
base-shellescape.cpp
icinga2_test_CPPFLAGS = \
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 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. *
+ ******************************************************************************/
+
+#include "base/array.h"
+#include "base/objectlock.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
+
+using namespace icinga;
+
+BOOST_AUTO_TEST_SUITE(base_array)
+
+BOOST_AUTO_TEST_CASE(construct)
+{
+ Array::Ptr array = boost::make_shared<Array>();
+ BOOST_CHECK(array);
+ BOOST_CHECK(array->GetLength() == 0);
+}
+
+BOOST_AUTO_TEST_CASE(getset)
+{
+ Array::Ptr array = boost::make_shared<Array>();
+ array->Add(7);
+ array->Add(2);
+ array->Add(5);
+ BOOST_CHECK(array->GetLength() == 3);
+ BOOST_CHECK(array->Get(0) == 7);
+ BOOST_CHECK(array->Get(1) == 2);
+ BOOST_CHECK(array->Get(2) == 5);
+
+ array->Set(1, 9);
+ BOOST_CHECK(array->Get(1) == 9);
+
+ array->Remove(1);
+ BOOST_CHECK(array->GetLength() == 2);
+ BOOST_CHECK(array->Get(1) == 5);
+}
+
+BOOST_AUTO_TEST_CASE(foreach)
+{
+ Array::Ptr array = boost::make_shared<Array>();
+ array->Add(7);
+ array->Add(2);
+ array->Add(5);
+
+ ObjectLock olock(array);
+
+ int n = 0;
+
+ BOOST_FOREACH(const Value& item, array) {
+ BOOST_CHECK(n != 0 || item == 7);
+ BOOST_CHECK(n != 1 || item == 2);
+ BOOST_CHECK(n != 2 || item == 5);
+
+ n++;
+ }
+}
+
+BOOST_AUTO_TEST_CASE(clone)
+{
+ Array::Ptr array = boost::make_shared<Array>();
+ array->Add(7);
+ array->Add(2);
+ array->Add(5);
+
+ Array::Ptr clone = array->ShallowClone();
+
+ BOOST_CHECK(clone->GetLength() == 3);
+ BOOST_CHECK(clone->Get(0) == 7);
+ BOOST_CHECK(clone->Get(1) == 2);
+ BOOST_CHECK(clone->Get(2) == 5);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 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. *
+ ******************************************************************************/
+
+#include "base/convert.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+using namespace icinga;
+
+BOOST_AUTO_TEST_SUITE(base_convert)
+
+BOOST_AUTO_TEST_CASE(tolong)
+{
+ BOOST_CHECK_THROW(Convert::ToLong(" 7"), boost::exception);
+ BOOST_CHECK(Convert::ToLong("7") == 7);
+ BOOST_CHECK_THROW(Convert::ToLong("7a"), boost::exception);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
dictionary->Set("test1", 7);
dictionary->Set("test2", "hello world");
+ BOOST_CHECK(dictionary->GetLength() == 2);
+
Value test1;
test1 = dictionary->Get("test1");
BOOST_CHECK(test1 == 7);
test2 = dictionary->Get("test2");
BOOST_CHECK(test2 == "hello world");
+ String key3 = "test3";
Value test3;
- test3 = dictionary->Get("test3");
+ test3 = dictionary->Get(key3);
BOOST_CHECK(test3.IsEmpty());
}
dictionary->Set("test1", other);
+ BOOST_CHECK(dictionary->GetLength() == 1);
+
Dictionary::Ptr test1 = dictionary->Get("test1");
BOOST_CHECK(other == test1);
BOOST_CHECK(!test2);
}
+BOOST_AUTO_TEST_CASE(remove_dict)
+{
+ Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
+
+ dictionary->Set("test1", 7);
+ dictionary->Set("test2", "hello world");
+
+ BOOST_CHECK(dictionary->Contains("test1"));
+ BOOST_CHECK(dictionary->GetLength() == 2);
+
+ dictionary->Set("test1", Empty);
+
+ BOOST_CHECK(!dictionary->Contains("test1"));
+ BOOST_CHECK(dictionary->GetLength() == 1);
+
+ dictionary->Remove("test2");
+
+ BOOST_CHECK(!dictionary->Contains("test2"));
+ BOOST_CHECK(dictionary->GetLength() == 0);
+}
+
BOOST_AUTO_TEST_SUITE_END()
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 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. *
+ ******************************************************************************/
+
+#include "base/fifo.h"
+#include "base/objectlock.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
+
+using namespace icinga;
+
+BOOST_AUTO_TEST_SUITE(base_fifo)
+
+BOOST_AUTO_TEST_CASE(construct)
+{
+ FIFO::Ptr fifo = boost::make_shared<FIFO>();
+ BOOST_CHECK(fifo);
+ BOOST_CHECK(fifo->GetAvailableBytes() == 0);
+}
+
+BOOST_AUTO_TEST_CASE(io)
+{
+ FIFO::Ptr fifo = boost::make_shared<FIFO>();
+
+ fifo->Write("hello", 5);
+ BOOST_CHECK(fifo->GetAvailableBytes() == 5);
+
+ char buffer1[2];
+ fifo->Read(buffer1, 2);
+ BOOST_CHECK(memcmp(buffer1, "he", 2) == 0);
+ BOOST_CHECK(fifo->GetAvailableBytes() == 3);
+
+ char buffer2[3];
+ fifo->Read(buffer2, 3);
+ BOOST_CHECK(memcmp(buffer2, "llo", 3) == 0);
+ BOOST_CHECK(fifo->GetAvailableBytes() == 0);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 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. *
+ ******************************************************************************/
+
+#include "base/object.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+using namespace icinga;
+
+class TestObject : public Object
+{
+public:
+ typedef boost::shared_ptr<TestObject> Ptr;
+ typedef boost::weak_ptr<TestObject> WeakPtr;
+
+ TestObject::Ptr GetTestRef(void)
+ {
+ return GetSelf();
+ }
+};
+
+BOOST_AUTO_TEST_SUITE(base_object)
+
+BOOST_AUTO_TEST_CASE(construct)
+{
+ Object::Ptr tobject = boost::make_shared<TestObject>();
+ BOOST_CHECK(tobject);
+}
+
+BOOST_AUTO_TEST_CASE(getself)
+{
+ TestObject::Ptr tobject = boost::make_shared<TestObject>();
+ TestObject::Ptr tobject_self = tobject->GetTestRef();
+ BOOST_CHECK(tobject == tobject_self);
+}
+
+BOOST_AUTO_TEST_CASE(weak)
+{
+ TestObject::Ptr tobject = boost::make_shared<TestObject>();
+ TestObject::WeakPtr wtobject = tobject;
+ tobject.reset();
+ BOOST_CHECK(!tobject);
+ BOOST_CHECK(!wtobject.lock());
+}
+
+BOOST_AUTO_TEST_SUITE_END()