diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 918fe5b8cda..e577d03589e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,6 +15,8 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +set(Boost_USE_STATIC_LIBS OFF) + include(BoostTestTargets) set(base_test_SOURCES @@ -31,7 +33,7 @@ if(ICINGA2_UNITY_BUILD) endif() add_boost_test(base - SOURCES base-test.cpp ${base_test_SOURCES} + SOURCES test-runner.cpp ${base_test_SOURCES} LIBRARIES base config icinga TESTS base_array/construct base_array/getset @@ -123,7 +125,7 @@ if(ICINGA2_WITH_LIVESTATUS) endif() add_boost_test(livestatus - SOURCES livestatus-test.cpp ${livestatus_test_SOURCES} + SOURCES test-runner.cpp livestatus-fixture.cpp ${livestatus_test_SOURCES} LIBRARIES base config icinga livestatus DEPENDENCIES methods TESTS livestatus/hosts livestatus/services diff --git a/test/base-array.cpp b/test/base-array.cpp index 61b2043dfd7..a748b3eeb87 100644 --- a/test/base-array.cpp +++ b/test/base-array.cpp @@ -20,7 +20,7 @@ #include "base/array.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" -#include +#include using namespace icinga; diff --git a/test/base-convert.cpp b/test/base-convert.cpp index 16e84da869f..0c330daa0af 100644 --- a/test/base-convert.cpp +++ b/test/base-convert.cpp @@ -19,7 +19,7 @@ #include "base/convert.hpp" #include "base/object.hpp" -#include +#include #include using namespace icinga; diff --git a/test/base-dictionary.cpp b/test/base-dictionary.cpp index bd336b4c2dd..903d9c185c8 100644 --- a/test/base-dictionary.cpp +++ b/test/base-dictionary.cpp @@ -20,7 +20,7 @@ #include "base/dictionary.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" -#include +#include #include using namespace icinga; diff --git a/test/base-fifo.cpp b/test/base-fifo.cpp index 06385f1b681..51b7391edf6 100644 --- a/test/base-fifo.cpp +++ b/test/base-fifo.cpp @@ -19,7 +19,7 @@ #include "base/fifo.hpp" #include "base/objectlock.hpp" -#include +#include using namespace icinga; diff --git a/test/base-json.cpp b/test/base-json.cpp index 3bb70153fb4..bbe89c733e2 100644 --- a/test/base-json.cpp +++ b/test/base-json.cpp @@ -21,7 +21,7 @@ #include "base/dictionary.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" -#include +#include #include using namespace icinga; diff --git a/test/base-match.cpp b/test/base-match.cpp index c150e579ebe..0b00f63ee2d 100644 --- a/test/base-match.cpp +++ b/test/base-match.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "base/utility.hpp" -#include +#include using namespace icinga; diff --git a/test/base-netstring.cpp b/test/base-netstring.cpp index 2e4d0adeee2..9c29229b69b 100644 --- a/test/base-netstring.cpp +++ b/test/base-netstring.cpp @@ -19,7 +19,7 @@ #include "base/netstring.hpp" #include "base/fifo.hpp" -#include +#include using namespace icinga; diff --git a/test/base-object.cpp b/test/base-object.cpp index 5fac6f7161c..004aa9e8e23 100644 --- a/test/base-object.cpp +++ b/test/base-object.cpp @@ -19,7 +19,7 @@ #include "base/object.hpp" #include "base/value.hpp" -#include +#include using namespace icinga; diff --git a/test/base-serialize.cpp b/test/base-serialize.cpp index 4373b2ec07a..7f5669c726d 100644 --- a/test/base-serialize.cpp +++ b/test/base-serialize.cpp @@ -23,7 +23,7 @@ #include "base/serializer.hpp" #include "base/array.hpp" #include "base/dictionary.hpp" -#include +#include #include using namespace icinga; diff --git a/test/base-shellescape.cpp b/test/base-shellescape.cpp index c6317dbbd4d..6f89cd34973 100644 --- a/test/base-shellescape.cpp +++ b/test/base-shellescape.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "base/utility.hpp" -#include +#include #include using namespace icinga; diff --git a/test/base-stacktrace.cpp b/test/base-stacktrace.cpp index 745338cffd6..2fceecd8883 100644 --- a/test/base-stacktrace.cpp +++ b/test/base-stacktrace.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "base/stacktrace.hpp" -#include +#include using namespace icinga; diff --git a/test/base-stream.cpp b/test/base-stream.cpp index c093b06e905..dfe3909dc0a 100644 --- a/test/base-stream.cpp +++ b/test/base-stream.cpp @@ -19,7 +19,7 @@ #include "base/stdiostream.hpp" #include "base/string.hpp" -#include +#include #include using namespace icinga; diff --git a/test/base-string.cpp b/test/base-string.cpp index f61a9382fdd..841f787769f 100644 --- a/test/base-string.cpp +++ b/test/base-string.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "base/string.hpp" -#include +#include using namespace icinga; diff --git a/test/base-test.cpp b/test/base-test.cpp deleted file mode 100644 index 0ed1d89a3e3..00000000000 --- a/test/base-test.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012-2016 Icinga Development Team (https://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. * - ******************************************************************************/ - -#define BOOST_TEST_MAIN -#define BOOST_TEST_MODULE icinga2_test - -#include "icinga/icingaapplication.hpp" -#include "base/application.hpp" -#include "base/timer.hpp" -#include - -using namespace icinga; - -struct InitLibBase -{ - IcingaApplication::Ptr appInst; - - InitLibBase(void) - { - Application::InitializeBase(); - - appInst = new IcingaApplication(); - static_pointer_cast(appInst)->OnConfigLoaded(); - } - - ~InitLibBase(void) - { - Application::UninitializeBase(); - } -}; - -BOOST_GLOBAL_FIXTURE(InitLibBase); diff --git a/test/base-timer.cpp b/test/base-timer.cpp index 14a39b86f53..cd4404fc476 100644 --- a/test/base-timer.cpp +++ b/test/base-timer.cpp @@ -20,7 +20,7 @@ #include "base/timer.hpp" #include "base/utility.hpp" #include "base/application.hpp" -#include +#include using namespace icinga; diff --git a/test/base-type.cpp b/test/base-type.cpp index 0c726f4cff9..0b83f9a719c 100644 --- a/test/base-type.cpp +++ b/test/base-type.cpp @@ -22,7 +22,7 @@ #include "base/objectlock.hpp" #include "base/application.hpp" #include "base/type.hpp" -#include +#include #include using namespace icinga; diff --git a/test/base-value.cpp b/test/base-value.cpp index a8170d1f9a0..f79f5f83fcd 100644 --- a/test/base-value.cpp +++ b/test/base-value.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "base/value.hpp" -#include +#include using namespace icinga; diff --git a/test/config-ops.cpp b/test/config-ops.cpp index ffa813bec05..77a384cadc0 100644 --- a/test/config-ops.cpp +++ b/test/config-ops.cpp @@ -19,7 +19,7 @@ #include "config/configcompiler.hpp" #include "base/exception.hpp" -#include +#include using namespace icinga; diff --git a/test/icinga-checkresult.cpp b/test/icinga-checkresult.cpp index 5241d43e2a5..703602d99cc 100644 --- a/test/icinga-checkresult.cpp +++ b/test/icinga-checkresult.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "icinga/host.hpp" -#include +#include using namespace icinga; diff --git a/test/icinga-macros.cpp b/test/icinga-macros.cpp index ef15cfba786..43f8f7910ee 100644 --- a/test/icinga-macros.cpp +++ b/test/icinga-macros.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "icinga/macroprocessor.hpp" -#include +#include using namespace icinga; diff --git a/test/icinga-perfdata.cpp b/test/icinga-perfdata.cpp index 7372159afcc..4ca535ee4da 100644 --- a/test/icinga-perfdata.cpp +++ b/test/icinga-perfdata.cpp @@ -19,7 +19,7 @@ #include "icinga/perfdatavalue.hpp" #include "icinga/pluginutility.hpp" -#include +#include using namespace icinga; diff --git a/test/livestatus-test.cpp b/test/livestatus-fixture.cpp similarity index 85% rename from test/livestatus-test.cpp rename to test/livestatus-fixture.cpp index 18aa93207a4..e034188e8a9 100644 --- a/test/livestatus-test.cpp +++ b/test/livestatus-fixture.cpp @@ -17,14 +17,10 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#define BOOST_TEST_MAIN -#define BOOST_TEST_MODULE icinga2_test - #include "config/configcompiler.hpp" #include "config/configitem.hpp" #include "base/application.hpp" #include "base/loader.hpp" -#include #include using namespace icinga; @@ -33,22 +29,11 @@ struct LivestatusFixture { LivestatusFixture(void) { - BOOST_TEST_MESSAGE("setup global config fixture"); - - Application::InitializeBase(); - - BOOST_TEST_MESSAGE( "Preparing config objects..."); + BOOST_TEST_MESSAGE("Preparing config objects..."); ConfigItem::RunWithActivationContext(new Function("CreateTestObjects", WrapFunction(CreateTestObjects))); } - ~LivestatusFixture(void) - { - BOOST_TEST_MESSAGE("cleanup global config fixture"); - - Application::UninitializeBase(); - } - static void CreateTestObjects(void) { String config = R"CONFIG( @@ -78,5 +63,4 @@ apply Service "livestatus" { } }; -BOOST_GLOBAL_FIXTURE(LivestatusFixture); - +BOOST_GLOBAL_FIXTURE(LivestatusFixture); \ No newline at end of file diff --git a/test/livestatus.cpp b/test/livestatus.cpp index a065bf1d01a..e6fb37edc8f 100644 --- a/test/livestatus.cpp +++ b/test/livestatus.cpp @@ -21,7 +21,7 @@ #include "base/application.hpp" #include "base/stdiostream.hpp" #include "base/json.hpp" -#include +#include using namespace icinga; diff --git a/test/remote-base64.cpp b/test/remote-base64.cpp index b0c78cc09a3..3dd01436919 100644 --- a/test/remote-base64.cpp +++ b/test/remote-base64.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "remote/base64.hpp" -#include +#include using namespace icinga; diff --git a/test/remote-url.cpp b/test/remote-url.cpp index 7ba9640d49f..b8d7c5fb7d4 100644 --- a/test/remote-url.cpp +++ b/test/remote-url.cpp @@ -19,7 +19,7 @@ #include "base/array.hpp" #include "remote/url.hpp" -#include +#include #include using namespace icinga; diff --git a/test/test-runner.cpp b/test/test-runner.cpp new file mode 100644 index 00000000000..3cc7bc8bdd0 --- /dev/null +++ b/test/test-runner.cpp @@ -0,0 +1,45 @@ +/****************************************************************************** +* Icinga 2 * +* Copyright (C) 2012-2016 Icinga Development Team (https://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 "icinga/icingaapplication.hpp" +#include "base/application.hpp" +#include + +using namespace icinga; + +static bool init_unit_test(void) +{ + return true; +} + +int main(int argc, char *argv[]) +{ + Application::InitializeBase(); + + IcingaApplication::Ptr appInst; + + appInst = new IcingaApplication(); + static_pointer_cast(appInst)->OnConfigLoaded(); + + int rc = boost::unit_test::unit_test_main(&init_unit_test, argc, argv); + + appInst.reset(); + + Application::Exit(rc); +} \ No newline at end of file diff --git a/third-party/cmake/BoostTestTargets.cmake b/third-party/cmake/BoostTestTargets.cmake index e2f664ee29d..8c263248547 100644 --- a/third-party/cmake/BoostTestTargets.cmake +++ b/third-party/cmake/BoostTestTargets.cmake @@ -78,9 +78,7 @@ if(Boost_FOUND AND NOT "${Boost_VERSION}0" LESS "1034000") if(Boost_USE_STATIC_LIBS) set(_boostConfig "BoostTestTargetsStatic.h") else() - if(NOT APPLE) - set(_boostConfig "BoostTestTargetsDynamic.h") - endif() + set(_boostConfig "BoostTestTargetsDynamic.h") endif() endif() get_filename_component(_moddir ${CMAKE_CURRENT_LIST_FILE} PATH)