]> granicus.if.org Git - icinga2/commitdiff
test-runner: Replace initialization by global fixture
authorMarkus Frosch <markus.frosch@icinga.com>
Wed, 7 Feb 2018 12:11:10 +0000 (13:11 +0100)
committerMarkus Frosch <markus.frosch@icinga.com>
Wed, 7 Feb 2018 19:30:37 +0000 (20:30 +0100)
This is required to even be able to build tests static
for Windows.

test/test-runner.cpp

index ea09e8744a1fe66c67713e4f0f4dc91c088547b5..f950c48342fb054eb8c8095f1f6a6191609cf68a 100644 (file)
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ******************************************************************************/
 
+#define BOOST_TEST_MAIN
+
 #include "icinga/icingaapplication.hpp"
 #include "base/application.hpp"
 #include <BoostTestTargetConfig.h>
 
 using namespace icinga;
 
-static bool init_unit_test()
-{
-       return true;
-}
-
-int main(int argc, char *argv[])
+struct TestIcingaApplication
 {
-       Application::InitializeBase();
-
-       IcingaApplication::Ptr appInst;
+       TestIcingaApplication()
+       {
+               Application::InitializeBase();
 
-       appInst = new IcingaApplication();
-       static_pointer_cast<ConfigObject>(appInst)->OnConfigLoaded();
+               IcingaApplication::Ptr appInst;
 
-       int rc = boost::unit_test::unit_test_main(&init_unit_test, argc, argv);
+               appInst = new IcingaApplication();
+               static_pointer_cast<ConfigObject>(appInst)->OnConfigLoaded();
+       }
 
-       appInst.reset();
+       ~TestIcingaApplication()
+       {
+               IcingaApplication::GetInstance().reset();
+       }
+};
 
-       Application::Exit(rc);
-}
+BOOST_GLOBAL_FIXTURE(TestIcingaApplication);