From 4c9943f0d12b57e6fcbcfae68d5d986f979f4462 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Fri, 12 Oct 2018 17:56:42 +0200 Subject: [PATCH] Add unit test for AppDir::deployExecutable --- tests/AppDirUnitTests.cpp | 24 +++++++++++++++++++ tests/CMakeLists.txt | 9 +++++-- tests/simple_executable/CMakeLists.txt | 2 ++ tests/simple_executable/simple_executable.cpp | 10 ++++++++ tests/simple_library/CMakeLists.txt | 2 +- 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tests/simple_executable/CMakeLists.txt create mode 100644 tests/simple_executable/simple_executable.cpp diff --git a/tests/AppDirUnitTests.cpp b/tests/AppDirUnitTests.cpp index e7d52f6..8bd9fed 100644 --- a/tests/AppDirUnitTests.cpp +++ b/tests/AppDirUnitTests.cpp @@ -87,4 +87,28 @@ namespace AppDirUnitTests { if (!libsimple_library_found) FAIL(); } + + TEST_F(AppDirUnitTestsFixture, deployExecutable) { + path exePath = SIMPLE_EXECUTABLE_PATH; + appDir.deployExecutable(exePath); + appDir.executeDeferredOperations(); + + bool libsimple_library_found = false; + bool simple_executable_found = false; + recursive_directory_iterator end_itr; // default construction yields past-the-end + for (recursive_directory_iterator itr(tmpAppDir); + itr != end_itr && (!libsimple_library_found || !simple_executable_found); + itr++) { + const auto path = relative(itr->path(), tmpAppDir).filename().string(); + + if (path.find("libsimple_library") != std::string::npos) + libsimple_library_found = true; + + if (path.find("simple_executable") != std::string::npos) + simple_executable_found = true; + } + + if (!libsimple_library_found || !simple_executable_found) + FAIL(); + } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 50a894b..c1ba5c0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,11 +3,16 @@ if(NOT TARGET gtest) 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) -target_compile_definitions(AppDirUnitTests PRIVATE -DSIMPLE_LIBRARY_PATH="$") + +target_compile_definitions(AppDirUnitTests PRIVATE + -DSIMPLE_LIBRARY_PATH="$" + -DSIMPLE_EXECUTABLE_PATH="$" + ) add_gtest(AppDirUnitTests) -add_dependencies(AppDirUnitTests simple_library) +add_dependencies(AppDirUnitTests simple_library simple_executable) diff --git a/tests/simple_executable/CMakeLists.txt b/tests/simple_executable/CMakeLists.txt new file mode 100644 index 0000000..a552550 --- /dev/null +++ b/tests/simple_executable/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(simple_executable simple_executable.cpp) +target_link_libraries(simple_executable simple_library pthread) \ No newline at end of file diff --git a/tests/simple_executable/simple_executable.cpp b/tests/simple_executable/simple_executable.cpp new file mode 100644 index 0000000..96611bf --- /dev/null +++ b/tests/simple_executable/simple_executable.cpp @@ -0,0 +1,10 @@ +#include + +extern "C" { void hello_world(); } + +int main() { + printf("Hello World"); + hello_world(); + + return 0; +} diff --git a/tests/simple_library/CMakeLists.txt b/tests/simple_library/CMakeLists.txt index 8dc1801..7af5b14 100644 --- a/tests/simple_library/CMakeLists.txt +++ b/tests/simple_library/CMakeLists.txt @@ -1,2 +1,2 @@ add_library(simple_library SHARED simple_library.cpp) -target_link_libraries(simple_library cairo) \ No newline at end of file +target_link_libraries(simple_library CImg) \ No newline at end of file