From b4b5c987a65371b5be4e60f119ec0efc8fc56294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 17 Feb 2017 10:12:08 +0100 Subject: [PATCH] unittests: add setup code to call param_init() --- unittests/CMakeLists.txt | 2 +- unittests/setup.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 unittests/setup.cpp diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 2c76e6f2d3..6572ee80d6 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -105,7 +105,7 @@ endfunction() # add_gtest(example_test) # param_test -add_executable(param_test param_test.cpp uorb_stub.cpp +add_executable(param_test setup.cpp param_test.cpp uorb_stub.cpp ${PX4_SRC}/modules/systemlib/bson/tinybson.c ${PX4_SRC}/modules/systemlib/param/param.c) target_link_libraries(param_test ${PX4_PLATFORM}) diff --git a/unittests/setup.cpp b/unittests/setup.cpp new file mode 100644 index 0000000000..34038ffc41 --- /dev/null +++ b/unittests/setup.cpp @@ -0,0 +1,23 @@ +#include + +#include "gtest/gtest.h" + + +class TestEnvironment: public ::testing::Environment { +public: + /** + * Testing setup: this is called before the actual tests are executed. + */ + virtual void SetUp() + { + param_init(); + } +}; + +int main(int argc, char* argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + // gtest takes ownership of the TestEnvironment ptr - we don't delete it. + ::testing::AddGlobalTestEnvironment(new TestEnvironment); + return RUN_ALL_TESTS(); +}