diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2731f3b..c988f78 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,17 +5,21 @@ endif() add_subdirectory(simple_library) add_subdirectory(simple_executable) -add_executable(AppDirUnitTests AppDirUnitTests.cpp) -target_link_libraries(AppDirUnitTests PRIVATE linuxdeploy_core) -target_include_directories(AppDirUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/include) +add_executable(test_appdir test_appdir.cpp) +target_link_libraries(test_appdir PRIVATE linuxdeploy_core gtest) +target_include_directories(test_appdir PRIVATE ${PROJECT_SOURCE_DIR}/include) -target_compile_definitions(AppDirUnitTests PRIVATE +# calculate paths to resources using CMake and hardcode them in the test binary +target_compile_definitions(test_appdir PRIVATE -DSIMPLE_LIBRARY_PATH="$" -DSIMPLE_EXECUTABLE_PATH="$" -DSIMPLE_DESKTOP_ENTRY_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data/simple_app.Desktop" -DSIMPLE_ICON_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data/simple_icon.svg" -DSIMPLE_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data/simple_file.txt" - ) +) -add_gtest(AppDirUnitTests) -add_dependencies(AppDirUnitTests simple_library simple_executable) +# register in CTest +add_test(test_appdir test_appdir) + +# make sure library and executable are built before test_appdir +add_dependencies(test_appdir simple_library simple_executable) diff --git a/tests/simple_executable/simple_executable.cpp b/tests/simple_executable/simple_executable.cpp index 96611bf..73906dd 100644 --- a/tests/simple_executable/simple_executable.cpp +++ b/tests/simple_executable/simple_executable.cpp @@ -1,6 +1,5 @@ #include - -extern "C" { void hello_world(); } +#include int main() { printf("Hello World"); diff --git a/tests/simple_library/CMakeLists.txt b/tests/simple_library/CMakeLists.txt index 7af5b14..41fd25d 100644 --- a/tests/simple_library/CMakeLists.txt +++ b/tests/simple_library/CMakeLists.txt @@ -1,2 +1,3 @@ -add_library(simple_library SHARED simple_library.cpp) -target_link_libraries(simple_library CImg) \ No newline at end of file +add_library(simple_library SHARED simple_library.cpp simple_library.h) +target_link_libraries(simple_library PUBLIC CImg) +target_include_directories(simple_library PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/simple_library/simple_library.cpp b/tests/simple_library/simple_library.cpp index 6507e98..4346a90 100644 --- a/tests/simple_library/simple_library.cpp +++ b/tests/simple_library/simple_library.cpp @@ -1,8 +1,6 @@ #include "CImg.h" using namespace cimg_library; -extern "C" { void hello_world() { cimg::info(); } -} \ No newline at end of file diff --git a/tests/simple_library/simple_library.h b/tests/simple_library/simple_library.h new file mode 100644 index 0000000..100fd32 --- /dev/null +++ b/tests/simple_library/simple_library.h @@ -0,0 +1 @@ +void hello_world(); diff --git a/tests/AppDirUnitTests.cpp b/tests/test_appdir.cpp similarity index 97% rename from tests/AppDirUnitTests.cpp rename to tests/test_appdir.cpp index 0d6c6a1..c6f39e0 100644 --- a/tests/AppDirUnitTests.cpp +++ b/tests/test_appdir.cpp @@ -3,9 +3,9 @@ using namespace linuxdeploy::core::appdir; using namespace linuxdeploy::core::desktopfile; - using namespace boost::filesystem; -namespace AppDirUnitTests { + +namespace AppDirTest { class AppDirUnitTestsFixture : public ::testing::Test { public: AppDirUnitTestsFixture() : @@ -176,3 +176,8 @@ namespace AppDirUnitTests { FAIL(); } } + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}