From 55b6ee19e140dc6e42f1bedae8404b6b902d223c Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Fri, 12 Oct 2018 15:51:13 +0200 Subject: [PATCH 01/24] Add tests infrastructure --- .gitmodules | 3 +++ CMakeLists.txt | 2 +- lib/CMakeLists.txt | 2 ++ lib/googletest | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) create mode 160000 lib/googletest diff --git a/.gitmodules b/.gitmodules index 16d0a42..1ce3cc8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -76,3 +76,6 @@ [submodule "lib/CImg"] path = lib/CImg url = https://github.com/dtschump/CImg.git +[submodule "lib/googletest"] + path = lib/googletest + url = https://github.com/google/googletest diff --git a/CMakeLists.txt b/CMakeLists.txt index 139842f..86c2ae5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,4 +12,4 @@ set(USE_SYSTEM_CIMG ON CACHE BOOL "Set to OFF to use CImg library bundled in lib add_subdirectory(lib) -add_subdirectory(src) +add_subdirectory(src) \ No newline at end of file diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a7befff..7f822ce 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -108,3 +108,5 @@ if(NOT USE_SYSTEM_BOOST) boost_type_traits boost_static_assert boost_integer boost_preprocessor boost_functional boost_detail ) endif() + +add_subdirectory(googletest) diff --git a/lib/googletest b/lib/googletest new file mode 160000 index 0000000..3bb00b7 --- /dev/null +++ b/lib/googletest @@ -0,0 +1 @@ +Subproject commit 3bb00b7ead35ca3a9b5817ce1ab78050fe6be0e3 From f1e752d452a2e10affab439771d04552fe63ccd5 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 15 Oct 2018 22:33:51 +0200 Subject: [PATCH 02/24] Add unit test for AppDir::createBasicStructure --- .gitignore | 1 - CMakeLists.txt | 8 ++- tests/AppDirUnitTests.cpp | 72 +++++++++++++++++++++++++ tests/CMakeLists.txt | 9 ++++ tests/simple_library/CMakeLists.txt | 2 + tests/simple_library/simple_library.cpp | 8 +++ 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 tests/AppDirUnitTests.cpp create mode 100644 tests/CMakeLists.txt create mode 100644 tests/simple_library/CMakeLists.txt create mode 100644 tests/simple_library/simple_library.cpp diff --git a/.gitignore b/.gitignore index ac0e8a5..3c31623 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ cmake-build-*/ *build*/ .idea/ squashfs-root/ -tests/ *.AppImage diff --git a/CMakeLists.txt b/CMakeLists.txt index 86c2ae5..65066bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,4 +12,10 @@ set(USE_SYSTEM_CIMG ON CACHE BOOL "Set to OFF to use CImg library bundled in lib add_subdirectory(lib) -add_subdirectory(src) \ No newline at end of file +add_subdirectory(src) + +option(BUILD_TEST "Build the tests" ON) +if(PACKAGE_TESTS) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/tests/AppDirUnitTests.cpp b/tests/AppDirUnitTests.cpp new file mode 100644 index 0000000..52d8672 --- /dev/null +++ b/tests/AppDirUnitTests.cpp @@ -0,0 +1,72 @@ +#include "gtest/gtest.h" +#include "linuxdeploy/core/appdir.h" + +using namespace linuxdeploy::core::appdir; +using namespace boost::filesystem; +namespace AppDirUnitTests { + class AppDirUnitTestsFixture : public ::testing::Test { + public: + AppDirUnitTestsFixture() : + tmpAppDir(temp_directory_path() / unique_path("linuxdeploy-tests-%%%%-%%%%-%%%%")), + appDir(tmpAppDir) { + } + + void SetUp() override { + } + + void TearDown() override { + remove_all(tmpAppDir); + } + + ~AppDirUnitTestsFixture() override = default; + + void listDeployedFiles() { + std::cout << "Files deployed in AppDir:"; + recursive_directory_iterator end_itr; // default construction yields past-the-end + for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr; itr++) { + std::cout << relative(itr->path(), tmpAppDir).string() << std::endl; + } + } + + path tmpAppDir; + AppDir appDir; + }; + + TEST_F(AppDirUnitTestsFixture, createBasicStructure) { + std::set expected = { + "usr", + "usr/bin", + "usr/share", + "usr/share/icons", + "usr/share/icons/hicolor", + "usr/share/icons/hicolor/scalable", + "usr/share/icons/hicolor/scalable/apps", + "usr/share/icons/hicolor/32x32", + "usr/share/icons/hicolor/32x32/apps", + "usr/share/icons/hicolor/256x256", + "usr/share/icons/hicolor/256x256/apps", + "usr/share/icons/hicolor/16x16", + "usr/share/icons/hicolor/16x16/apps", + "usr/share/icons/hicolor/128x128", + "usr/share/icons/hicolor/128x128/apps", + "usr/share/icons/hicolor/64x64", + "usr/share/icons/hicolor/64x64/apps", + "usr/share/applications", + "usr/lib", + }; + + appDir.createBasicStructure(); + + recursive_directory_iterator end_itr; // default construction yields past-the-end + for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr; itr++) { + std::string path = relative(itr->path(), tmpAppDir).string(); + if (expected.find(path) == expected.end()) + FAIL(); + else + expected.erase(path); + } + if (!expected.empty()) + FAIL(); + + } +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..9ea0119 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,9 @@ +if(NOT TARGET gtest) + include(AddGoogleTest) +endif() + +add_executable(AppDirUnitTests AppDirUnitTests.cpp) +target_link_libraries(AppDirUnitTests PRIVATE linuxdeploy_core) +target_include_directories(AppDirUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/include) + +add_gtest(AppDirUnitTests) diff --git a/tests/simple_library/CMakeLists.txt b/tests/simple_library/CMakeLists.txt new file mode 100644 index 0000000..8dc1801 --- /dev/null +++ b/tests/simple_library/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(simple_library SHARED simple_library.cpp) +target_link_libraries(simple_library cairo) \ No newline at end of file diff --git a/tests/simple_library/simple_library.cpp b/tests/simple_library/simple_library.cpp new file mode 100644 index 0000000..6507e98 --- /dev/null +++ b/tests/simple_library/simple_library.cpp @@ -0,0 +1,8 @@ +#include "CImg.h" +using namespace cimg_library; + +extern "C" { +void hello_world() { + cimg::info(); +} +} \ No newline at end of file From a0503a7102e1dd1db55f737dd652d170805b2d66 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Mon, 15 Oct 2018 23:16:07 +0200 Subject: [PATCH 03/24] Add test for AppDir::depoloyLibrary --- tests/AppDirUnitTests.cpp | 18 ++++++++++++++++++ tests/CMakeLists.txt | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/tests/AppDirUnitTests.cpp b/tests/AppDirUnitTests.cpp index 52d8672..e7d52f6 100644 --- a/tests/AppDirUnitTests.cpp +++ b/tests/AppDirUnitTests.cpp @@ -69,4 +69,22 @@ namespace AppDirUnitTests { FAIL(); } + + TEST_F(AppDirUnitTestsFixture, depoloyLibrary) { + path libPath = SIMPLE_LIBRARY_PATH; + appDir.deployLibrary(libPath); + appDir.executeDeferredOperations(); + + bool libsimple_library_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); itr++) { + const auto path = relative(itr->path(), tmpAppDir).filename().string(); + + if (path.find("libsimple_library") != path.npos) + libsimple_library_found = true; + } + + if (!libsimple_library_found) + FAIL(); + } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ea0119..50a894b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,8 +2,12 @@ if(NOT TARGET gtest) include(AddGoogleTest) endif() +add_subdirectory(simple_library) + 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="$") add_gtest(AppDirUnitTests) +add_dependencies(AppDirUnitTests simple_library) From 4c9943f0d12b57e6fcbcfae68d5d986f979f4462 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Fri, 12 Oct 2018 17:56:42 +0200 Subject: [PATCH 04/24] 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 From eacc907c85f85da52398f5dadc739abae833a14c Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sat, 13 Oct 2018 15:09:23 +0200 Subject: [PATCH 05/24] Add unit test for AppDir::deployDesktopFile --- tests/AppDirUnitTests.cpp | 20 ++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/data/SimpleApp.Desktop | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/data/SimpleApp.Desktop diff --git a/tests/AppDirUnitTests.cpp b/tests/AppDirUnitTests.cpp index 8bd9fed..3a25d65 100644 --- a/tests/AppDirUnitTests.cpp +++ b/tests/AppDirUnitTests.cpp @@ -2,6 +2,8 @@ #include "linuxdeploy/core/appdir.h" using namespace linuxdeploy::core::appdir; +using namespace linuxdeploy::core::desktopfile; + using namespace boost::filesystem; namespace AppDirUnitTests { class AppDirUnitTestsFixture : public ::testing::Test { @@ -111,4 +113,22 @@ namespace AppDirUnitTests { if (!libsimple_library_found || !simple_executable_found) FAIL(); } + + TEST_F(AppDirUnitTestsFixture, deployDesktopFile) { + DesktopFile desktopFile{SIMPLE_DESKTOP_ENTRY_PATH}; + appDir.deployDesktopFile(desktopFile); + appDir.executeDeferredOperations(); + + bool simple_app_desktop_found = false; + recursive_directory_iterator end_itr; // default construction yields past-the-end + for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr && (!simple_app_desktop_found); itr++) { + const auto path = relative(itr->path(), tmpAppDir).filename().string(); + + if (path.find("SimpleApp.Desktop") != std::string::npos) + simple_app_desktop_found = true; + } + + if (!simple_app_desktop_found) + FAIL(); + } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c1ba5c0..4ed4a43 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,7 @@ target_include_directories(AppDirUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/include target_compile_definitions(AppDirUnitTests PRIVATE -DSIMPLE_LIBRARY_PATH="$" -DSIMPLE_EXECUTABLE_PATH="$" + -DSIMPLE_DESKTOP_ENTRY_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data/SimpleApp.Desktop" ) add_gtest(AppDirUnitTests) diff --git a/tests/data/SimpleApp.Desktop b/tests/data/SimpleApp.Desktop new file mode 100644 index 0000000..3b1e223 --- /dev/null +++ b/tests/data/SimpleApp.Desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=Simple Application +Comment=The most simple application available! +TryExec=simple_executable +Exec=simple_executable %F +Icon=simple_icon +MimeType=image/x-foo; +Actions=SimpleAction;AnotherSimpleAction; + +[Desktop Action SimpleAction] +Exec=simple_executable --do-it +Name=Do something simple! + +[Desktop Action AnotherSimpleAction] +Exec=simple_executable --do-it-again +Name=Do another simple thing! +Icon=simple_icon \ No newline at end of file From 41371c9d9047d7fac660e0c22c1bff3db159ae69 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sun, 21 Oct 2018 16:54:30 +0200 Subject: [PATCH 06/24] Improve Travis uploading --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cf380d1..09bb3c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,7 +44,7 @@ script: after_success: - ls -lh # make sure only pushes to rewrite create a new release, otherwise pretend PR and upload to transfer.sh - - if [ "$TRAVIS_BRANCH" != "master" ]; then export TRAVIS_EVENT_TYPE=pull_request; fi + - if [ "$TRAVIS_TAG" != "$TRAVIS_BRANCH" ] && [ "$TRAVIS_BRANCH" == "master" ]; then export TRAVIS_EVENT_TYPE=pull_request; fi - wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh - bash upload.sh linuxdeploy-"$ARCH".AppImage* From 47ff6c8e9d5ff85649640d786e6c7494976ac1a5 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 14 Oct 2018 12:47:33 +0200 Subject: [PATCH 07/24] Add AppDir::deployIcon test. --- tests/AppDirUnitTests.cpp | 22 ++++++++++- tests/CMakeLists.txt | 3 +- .../{SimpleApp.Desktop => simple_app.Desktop} | 0 tests/data/simple_icon.svg | 38 +++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) rename tests/data/{SimpleApp.Desktop => simple_app.Desktop} (100%) create mode 100644 tests/data/simple_icon.svg diff --git a/tests/AppDirUnitTests.cpp b/tests/AppDirUnitTests.cpp index 3a25d65..3b5d774 100644 --- a/tests/AppDirUnitTests.cpp +++ b/tests/AppDirUnitTests.cpp @@ -124,11 +124,31 @@ namespace AppDirUnitTests { for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr && (!simple_app_desktop_found); itr++) { const auto path = relative(itr->path(), tmpAppDir).filename().string(); - if (path.find("SimpleApp.Desktop") != std::string::npos) + if (path.find("simple_app.Desktop") != std::string::npos) simple_app_desktop_found = true; } if (!simple_app_desktop_found) FAIL(); } + + + TEST_F(AppDirUnitTestsFixture, deployIcon) { + path iconPath = SIMPLE_ICON_PATH; + appDir.deployIcon(iconPath); + appDir.executeDeferredOperations(); + + bool simple_icon_found = false; + recursive_directory_iterator end_itr; // default construction yields past-the-end + for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr && (!simple_icon_found); itr++) { + const auto path = relative(itr->path(), tmpAppDir).filename().string(); + + if (path.find("simple_icon.svg") != std::string::npos) + simple_icon_found = true; + } + + if (!simple_icon_found) + FAIL(); + + } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4ed4a43..00e493e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,8 @@ target_include_directories(AppDirUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/include target_compile_definitions(AppDirUnitTests PRIVATE -DSIMPLE_LIBRARY_PATH="$" -DSIMPLE_EXECUTABLE_PATH="$" - -DSIMPLE_DESKTOP_ENTRY_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data/SimpleApp.Desktop" + -DSIMPLE_DESKTOP_ENTRY_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data/simple_app.Desktop" + -DSIMPLE_ICON_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data/simple_icon.svg" ) add_gtest(AppDirUnitTests) diff --git a/tests/data/SimpleApp.Desktop b/tests/data/simple_app.Desktop similarity index 100% rename from tests/data/SimpleApp.Desktop rename to tests/data/simple_app.Desktop diff --git a/tests/data/simple_icon.svg b/tests/data/simple_icon.svg new file mode 100644 index 0000000..39e3940 --- /dev/null +++ b/tests/data/simple_icon.svg @@ -0,0 +1,38 @@ + + + + + + + image/svg+xml + + + + + + + + + From 376eddb14d34bc69372d4aae7bf5c98a27cf558f Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 14 Oct 2018 13:53:58 +0200 Subject: [PATCH 08/24] Add unit test for AppDir::deployFile --- tests/AppDirUnitTests.cpp | 18 ++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/data/simple_file.txt | 1 + 3 files changed, 20 insertions(+) create mode 100644 tests/data/simple_file.txt diff --git a/tests/AppDirUnitTests.cpp b/tests/AppDirUnitTests.cpp index 3b5d774..dd93ce2 100644 --- a/tests/AppDirUnitTests.cpp +++ b/tests/AppDirUnitTests.cpp @@ -149,6 +149,24 @@ namespace AppDirUnitTests { if (!simple_icon_found) FAIL(); + } + + TEST_F(AppDirUnitTestsFixture, deployFile) { + path filePath = SIMPLE_FILE_PATH; + appDir.deployFile(filePath, tmpAppDir / "usr/share/doc/simple_application/"); + appDir.executeDeferredOperations(); + + bool simple_file_found = false; + recursive_directory_iterator end_itr; // default construction yields past-the-end + for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr && (!simple_file_found); itr++) { + const auto path = relative(itr->path(), tmpAppDir).filename().string(); + + if (path.find("simple_file.txt") != std::string::npos) + simple_file_found = true; + } + + if (!simple_file_found) + FAIL(); } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 00e493e..2731f3b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,6 +14,7 @@ target_compile_definitions(AppDirUnitTests PRIVATE -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) diff --git a/tests/data/simple_file.txt b/tests/data/simple_file.txt new file mode 100644 index 0000000..980a0d5 --- /dev/null +++ b/tests/data/simple_file.txt @@ -0,0 +1 @@ +Hello World! From d09186f69f940d38758e71f3f561f1ec848d36ea Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sun, 14 Oct 2018 15:04:38 +0200 Subject: [PATCH 09/24] Run unit tests on the build.sh script --- travis/build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/travis/build.sh b/travis/build.sh index 0dd8ccf..4cdd617 100755 --- a/travis/build.sh +++ b/travis/build.sh @@ -39,6 +39,9 @@ cmake "$REPO_ROOT" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo make -j$(nproc) +## Run Unit Tests +ctest + # args are used more than once LINUXDEPLOY_ARGS=("--appdir" "AppDir" "-e" "bin/linuxdeploy" "-i" "$REPO_ROOT/resources/linuxdeploy.png" "--create-desktop-file" "-e" "/usr/bin/patchelf" "-e" "/usr/bin/strip") From 172db5118698a8e693ead6c5594af414336431b1 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sat, 20 Oct 2018 23:48:55 +0200 Subject: [PATCH 10/24] Add unit test for AppDir::depoloyLibrary but with an invalid path. --- tests/AppDirUnitTests.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/AppDirUnitTests.cpp b/tests/AppDirUnitTests.cpp index dd93ce2..0d6c6a1 100644 --- a/tests/AppDirUnitTests.cpp +++ b/tests/AppDirUnitTests.cpp @@ -72,6 +72,12 @@ namespace AppDirUnitTests { } + + TEST_F(AppDirUnitTestsFixture, depoloyLibraryWrongPath) { + path libPath = "/lib/fakelib.so"; + ASSERT_THROW(appDir.deployLibrary(libPath), std::exception); + } + TEST_F(AppDirUnitTestsFixture, depoloyLibrary) { path libPath = SIMPLE_LIBRARY_PATH; appDir.deployLibrary(libPath); From 7e4a320f6128a75f9d227995793e08260fa82820 Mon Sep 17 00:00:00 2001 From: Alexis Lopez Zubieta Date: Sat, 20 Oct 2018 23:49:51 +0200 Subject: [PATCH 11/24] Make ctest run un verbose mode. --- CMakeLists.txt | 2 +- travis/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65066bd..62ce776 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ add_subdirectory(lib) add_subdirectory(src) option(BUILD_TEST "Build the tests" ON) -if(PACKAGE_TESTS) +if(BUILD_TEST) enable_testing() add_subdirectory(tests) endif() diff --git a/travis/build.sh b/travis/build.sh index 4cdd617..23f8f2d 100755 --- a/travis/build.sh +++ b/travis/build.sh @@ -40,7 +40,7 @@ cmake "$REPO_ROOT" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo make -j$(nproc) ## Run Unit Tests -ctest +ctest -V # args are used more than once LINUXDEPLOY_ARGS=("--appdir" "AppDir" "-e" "bin/linuxdeploy" "-i" "$REPO_ROOT/resources/linuxdeploy.png" "--create-desktop-file" "-e" "/usr/bin/patchelf" "-e" "/usr/bin/strip") From a1308955e76cece4d46a8619aea95ce3ac31bb7e Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 24 Oct 2018 13:03:50 +0200 Subject: [PATCH 12/24] Use CMake's BUILD_TESTING instead of proprietary custom variable --- CMakeLists.txt | 5 ++--- lib/CMakeLists.txt | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62ce776..f753055 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,7 @@ add_subdirectory(lib) add_subdirectory(src) -option(BUILD_TEST "Build the tests" ON) -if(BUILD_TEST) - enable_testing() +include(CTest) +if(BUILD_TESTING) add_subdirectory(tests) endif() diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7f822ce..0c22dcd 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -109,4 +109,7 @@ if(NOT USE_SYSTEM_BOOST) ) endif() -add_subdirectory(googletest) +include(CTest) +if(BUILD_TESTING) + add_subdirectory(googletest) +endif() From 2f96dec588d227de637205a4494e48040552ce52 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 24 Oct 2018 13:27:40 +0200 Subject: [PATCH 13/24] Fix tests' structure, code style and use of GTest --- tests/CMakeLists.txt | 18 +++++++++++------- tests/simple_executable/simple_executable.cpp | 3 +-- tests/simple_library/CMakeLists.txt | 5 +++-- tests/simple_library/simple_library.cpp | 2 -- tests/simple_library/simple_library.h | 1 + tests/{AppDirUnitTests.cpp => test_appdir.cpp} | 9 +++++++-- 6 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 tests/simple_library/simple_library.h rename tests/{AppDirUnitTests.cpp => test_appdir.cpp} (97%) 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(); +} From 5e94977f78390c01d0ed64b826ae6fd74fe3380f Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 24 Oct 2018 13:38:35 +0200 Subject: [PATCH 14/24] Fix cpp-feather-ini-parser test execution --- lib/CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 0c22dcd..ba4ccf3 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,3 +1,5 @@ +include(CTest) + add_library(subprocess INTERFACE) target_sources(subprocess INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/cpp-subprocess/subprocess.hpp) target_include_directories(subprocess INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/cpp-subprocess) @@ -11,9 +13,11 @@ add_library(cpp-feather-ini-parser INTERFACE) target_sources(cpp-feather-ini-parser INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/cpp-feather-ini-parser/INI.h) target_include_directories(cpp-feather-ini-parser INTERFACE cpp-feather-ini-parser) -add_executable(test_cpp_feather_ini_parser EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/cpp-feather-ini-parser/example/example.cpp) -target_link_libraries(test_cpp_feather_ini_parser PRIVATE cpp-feather-ini-parser) -add_test(test_cpp_feather_ini_parser test_cpp_feather_ini_parser) +if(BUILD_TESTING) + add_executable(test_cpp_feather_ini_parser ${CMAKE_CURRENT_SOURCE_DIR}/cpp-feather-ini-parser/example/example.cpp) + target_link_libraries(test_cpp_feather_ini_parser PRIVATE cpp-feather-ini-parser) + add_test(test_cpp_feather_ini_parser test_cpp_feather_ini_parser) +endif() if(NOT USE_SYSTEM_BOOST) add_library(boost_config INTERFACE) @@ -109,7 +113,6 @@ if(NOT USE_SYSTEM_BOOST) ) endif() -include(CTest) if(BUILD_TESTING) add_subdirectory(googletest) endif() From 8a31d3d677ae209521be049e5dbf17c4a35addb9 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 24 Oct 2018 14:07:55 +0200 Subject: [PATCH 15/24] Fix cross-compiling toolchain --- cmake/toolchains/i386-linux-gnu.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/toolchains/i386-linux-gnu.cmake b/cmake/toolchains/i386-linux-gnu.cmake index 65c7b8b..ba35ddd 100644 --- a/cmake/toolchains/i386-linux-gnu.cmake +++ b/cmake/toolchains/i386-linux-gnu.cmake @@ -3,3 +3,6 @@ set(CMAKE_SYSTEM_PROCESSOR i386 CACHE STRING "" FORCE) set(CMAKE_C_FLAGS "-m32" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "" FORCE) + +# https://gitlab.kitware.com/cmake/cmake/issues/16920#note_299077 +set(THREADS_PTHREAD_ARG "2" CACHE STRING "Forcibly set by CMakeLists.txt" FORCE) From ca6c710c386f6a7431ebe726491cc71e8aa1a962 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 00:18:11 +0200 Subject: [PATCH 16/24] Remove deprecated code --- tests/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c988f78..3d37a22 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,3 @@ -if(NOT TARGET gtest) - include(AddGoogleTest) -endif() - add_subdirectory(simple_library) add_subdirectory(simple_executable) From 4bdceec7d865bfbc504b8616bd3bbbd7e0994412 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 00:30:41 +0200 Subject: [PATCH 17/24] Use standard lower-case file extension --- tests/data/{simple_app.Desktop => simple_app.desktop} | 0 tests/test_appdir.cpp | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/data/{simple_app.Desktop => simple_app.desktop} (100%) diff --git a/tests/data/simple_app.Desktop b/tests/data/simple_app.desktop similarity index 100% rename from tests/data/simple_app.Desktop rename to tests/data/simple_app.desktop diff --git a/tests/test_appdir.cpp b/tests/test_appdir.cpp index c6f39e0..09d6f16 100644 --- a/tests/test_appdir.cpp +++ b/tests/test_appdir.cpp @@ -130,7 +130,7 @@ namespace AppDirTest { for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr && (!simple_app_desktop_found); itr++) { const auto path = relative(itr->path(), tmpAppDir).filename().string(); - if (path.find("simple_app.Desktop") != std::string::npos) + if (path.find("simple_app.desktop") != std::string::npos) simple_app_desktop_found = true; } From 7260078b6c0d6dad20d3e4405971154e7e686814 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 00:39:45 +0200 Subject: [PATCH 18/24] Move test into subdirectory named like internal library --- tests/CMakeLists.txt | 21 +++------------------ tests/core/CMakeLists.txt | 18 ++++++++++++++++++ tests/{ => core}/test_appdir.cpp | 0 3 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 tests/core/CMakeLists.txt rename tests/{ => core}/test_appdir.cpp (100%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3d37a22..9c9d1b6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,21 +1,6 @@ +# first build dependencies for tests add_subdirectory(simple_library) add_subdirectory(simple_executable) -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) - -# 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" -) - -# 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) +# now include actual tests +add_subdirectory(core) diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt new file mode 100644 index 0000000..58c3fc4 --- /dev/null +++ b/tests/core/CMakeLists.txt @@ -0,0 +1,18 @@ +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) + +# 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" +) + +# 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/test_appdir.cpp b/tests/core/test_appdir.cpp similarity index 100% rename from tests/test_appdir.cpp rename to tests/core/test_appdir.cpp From 2dce34daf936a0b8a6396f13bc1602d76f77aed4 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 00:46:46 +0200 Subject: [PATCH 19/24] Use ASSERT_* instead of if()s and FAIL() --- tests/core/test_appdir.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/core/test_appdir.cpp b/tests/core/test_appdir.cpp index 09d6f16..222f716 100644 --- a/tests/core/test_appdir.cpp +++ b/tests/core/test_appdir.cpp @@ -62,14 +62,10 @@ namespace AppDirTest { recursive_directory_iterator end_itr; // default construction yields past-the-end for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr; itr++) { std::string path = relative(itr->path(), tmpAppDir).string(); - if (expected.find(path) == expected.end()) - FAIL(); - else - expected.erase(path); + ASSERT_NE(expected.find(path), expected.end()); + expected.erase(path); } - if (!expected.empty()) - FAIL(); - + ASSERT_TRUE(expected.empty()); } @@ -92,8 +88,7 @@ namespace AppDirTest { libsimple_library_found = true; } - if (!libsimple_library_found) - FAIL(); + ASSERT_TRUE(libsimple_library_found); } TEST_F(AppDirUnitTestsFixture, deployExecutable) { @@ -116,8 +111,7 @@ namespace AppDirTest { simple_executable_found = true; } - if (!libsimple_library_found || !simple_executable_found) - FAIL(); + ASSERT_TRUE(libsimple_library_found && !simple_executable_found); } TEST_F(AppDirUnitTestsFixture, deployDesktopFile) { @@ -134,8 +128,7 @@ namespace AppDirTest { simple_app_desktop_found = true; } - if (!simple_app_desktop_found) - FAIL(); + ASSERT_TRUE(simple_app_desktop_found); } @@ -153,8 +146,7 @@ namespace AppDirTest { simple_icon_found = true; } - if (!simple_icon_found) - FAIL(); + ASSERT_TRUE(simple_icon_found); } @@ -172,8 +164,7 @@ namespace AppDirTest { simple_file_found = true; } - if (!simple_file_found) - FAIL(); + ASSERT_TRUE(simple_file_found); } } From e94494ea31f6f49f0a3b2ee6c02604d231210010 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 00:48:13 +0200 Subject: [PATCH 20/24] Move declaration of variables to top --- tests/core/test_appdir.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/core/test_appdir.cpp b/tests/core/test_appdir.cpp index 222f716..f0dbd46 100644 --- a/tests/core/test_appdir.cpp +++ b/tests/core/test_appdir.cpp @@ -7,6 +7,10 @@ using namespace boost::filesystem; namespace AppDirTest { class AppDirUnitTestsFixture : public ::testing::Test { + public: + path tmpAppDir; + AppDir appDir; + public: AppDirUnitTestsFixture() : tmpAppDir(temp_directory_path() / unique_path("linuxdeploy-tests-%%%%-%%%%-%%%%")), @@ -29,9 +33,6 @@ namespace AppDirTest { std::cout << relative(itr->path(), tmpAppDir).string() << std::endl; } } - - path tmpAppDir; - AppDir appDir; }; TEST_F(AppDirUnitTestsFixture, createBasicStructure) { From 9cf0663baa2ef9ce8b81c66bee285ee88f55dd26 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 01:06:12 +0200 Subject: [PATCH 21/24] Hardcode all paths to recognize sudden changes of destination paths --- tests/core/test_appdir.cpp | 74 +++++++++----------------------------- 1 file changed, 16 insertions(+), 58 deletions(-) diff --git a/tests/core/test_appdir.cpp b/tests/core/test_appdir.cpp index f0dbd46..e40b391 100644 --- a/tests/core/test_appdir.cpp +++ b/tests/core/test_appdir.cpp @@ -36,6 +36,7 @@ namespace AppDirTest { }; TEST_F(AppDirUnitTestsFixture, createBasicStructure) { + // in this test case we expect the following exact directory set to be created in the AppDir std::set expected = { "usr", "usr/bin", @@ -80,16 +81,7 @@ namespace AppDirTest { appDir.deployLibrary(libPath); appDir.executeDeferredOperations(); - bool libsimple_library_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); itr++) { - const auto path = relative(itr->path(), tmpAppDir).filename().string(); - - if (path.find("libsimple_library") != path.npos) - libsimple_library_found = true; - } - - ASSERT_TRUE(libsimple_library_found); + ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/lib" / libPath.filename())); } TEST_F(AppDirUnitTestsFixture, deployExecutable) { @@ -97,22 +89,8 @@ namespace AppDirTest { 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; - } - - ASSERT_TRUE(libsimple_library_found && !simple_executable_found); + ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/bin" / path(SIMPLE_EXECUTABLE_PATH).filename())); + ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/lib" / path(SIMPLE_LIBRARY_PATH).filename())); } TEST_F(AppDirUnitTestsFixture, deployDesktopFile) { @@ -120,16 +98,7 @@ namespace AppDirTest { appDir.deployDesktopFile(desktopFile); appDir.executeDeferredOperations(); - bool simple_app_desktop_found = false; - recursive_directory_iterator end_itr; // default construction yields past-the-end - for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr && (!simple_app_desktop_found); itr++) { - const auto path = relative(itr->path(), tmpAppDir).filename().string(); - - if (path.find("simple_app.desktop") != std::string::npos) - simple_app_desktop_found = true; - } - - ASSERT_TRUE(simple_app_desktop_found); + ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/share/applications" / path(SIMPLE_DESKTOP_ENTRY_PATH).filename())); } @@ -138,34 +107,23 @@ namespace AppDirTest { appDir.deployIcon(iconPath); appDir.executeDeferredOperations(); - bool simple_icon_found = false; - recursive_directory_iterator end_itr; // default construction yields past-the-end - for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr && (!simple_icon_found); itr++) { - const auto path = relative(itr->path(), tmpAppDir).filename().string(); - - if (path.find("simple_icon.svg") != std::string::npos) - simple_icon_found = true; - } - - ASSERT_TRUE(simple_icon_found); + ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/share/icons/hicolor/scalable/apps" / path(SIMPLE_DESKTOP_ENTRY_PATH).filename())); } - - TEST_F(AppDirUnitTestsFixture, deployFile) { - path filePath = SIMPLE_FILE_PATH; - appDir.deployFile(filePath, tmpAppDir / "usr/share/doc/simple_application/"); + TEST_F(AppDirUnitTestsFixture, deployFileToDirectory) { + auto destination = tmpAppDir / "usr/share/doc/simple_application/"; + appDir.deployFile(SIMPLE_FILE_PATH, destination); appDir.executeDeferredOperations(); - bool simple_file_found = false; - recursive_directory_iterator end_itr; // default construction yields past-the-end - for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr && (!simple_file_found); itr++) { - const auto path = relative(itr->path(), tmpAppDir).filename().string(); + ASSERT_TRUE(is_regular_file(destination / path(SIMPLE_DESKTOP_ENTRY_PATH).filename())); + } - if (path.find("simple_file.txt") != std::string::npos) - simple_file_found = true; - } + TEST_F(AppDirUnitTestsFixture, deployFileToAbsoluteFilePath) { + auto destination = tmpAppDir / "usr/share/doc/simple_application/test123"; + appDir.deployFile(SIMPLE_FILE_PATH, destination); + appDir.executeDeferredOperations(); - ASSERT_TRUE(simple_file_found); + ASSERT_TRUE(is_regular_file(destination)); } } From cbaa343a82363398e1b52c839fd01d911602603b Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 01:08:52 +0200 Subject: [PATCH 22/24] Add missing trailing newline character [ci skip] --- tests/data/simple_app.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/simple_app.desktop b/tests/data/simple_app.desktop index 3b1e223..f49e6be 100644 --- a/tests/data/simple_app.desktop +++ b/tests/data/simple_app.desktop @@ -16,4 +16,4 @@ Name=Do something simple! [Desktop Action AnotherSimpleAction] Exec=simple_executable --do-it-again Name=Do another simple thing! -Icon=simple_icon \ No newline at end of file +Icon=simple_icon From 90f8ed26b8bda864e4ac5fcf9981acda3359095e Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 01:12:47 +0200 Subject: [PATCH 23/24] Fix path in unit test --- tests/core/test_appdir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/test_appdir.cpp b/tests/core/test_appdir.cpp index e40b391..4d1bf66 100644 --- a/tests/core/test_appdir.cpp +++ b/tests/core/test_appdir.cpp @@ -115,7 +115,7 @@ namespace AppDirTest { appDir.deployFile(SIMPLE_FILE_PATH, destination); appDir.executeDeferredOperations(); - ASSERT_TRUE(is_regular_file(destination / path(SIMPLE_DESKTOP_ENTRY_PATH).filename())); + ASSERT_TRUE(is_regular_file(destination / path(SIMPLE_FILE_PATH).filename())); } TEST_F(AppDirUnitTestsFixture, deployFileToAbsoluteFilePath) { From 33829c07d0278c111ba39dd9c26b345f28292a3b Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 25 Oct 2018 01:16:05 +0200 Subject: [PATCH 24/24] Remove redundant variables and fix paths --- tests/core/test_appdir.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/core/test_appdir.cpp b/tests/core/test_appdir.cpp index 4d1bf66..39d9b00 100644 --- a/tests/core/test_appdir.cpp +++ b/tests/core/test_appdir.cpp @@ -72,21 +72,18 @@ namespace AppDirTest { TEST_F(AppDirUnitTestsFixture, depoloyLibraryWrongPath) { - path libPath = "/lib/fakelib.so"; - ASSERT_THROW(appDir.deployLibrary(libPath), std::exception); + ASSERT_THROW(appDir.deployLibrary("/lib/fakelib.so"), std::exception); } TEST_F(AppDirUnitTestsFixture, depoloyLibrary) { - path libPath = SIMPLE_LIBRARY_PATH; - appDir.deployLibrary(libPath); + appDir.deployLibrary(SIMPLE_LIBRARY_PATH); appDir.executeDeferredOperations(); - ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/lib" / libPath.filename())); + ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/lib" / path(SIMPLE_LIBRARY_PATH).filename())); } TEST_F(AppDirUnitTestsFixture, deployExecutable) { - path exePath = SIMPLE_EXECUTABLE_PATH; - appDir.deployExecutable(exePath); + appDir.deployExecutable(SIMPLE_EXECUTABLE_PATH); appDir.executeDeferredOperations(); ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/bin" / path(SIMPLE_EXECUTABLE_PATH).filename())); @@ -103,11 +100,10 @@ namespace AppDirTest { TEST_F(AppDirUnitTestsFixture, deployIcon) { - path iconPath = SIMPLE_ICON_PATH; - appDir.deployIcon(iconPath); + appDir.deployIcon(SIMPLE_ICON_PATH); appDir.executeDeferredOperations(); - ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/share/icons/hicolor/scalable/apps" / path(SIMPLE_DESKTOP_ENTRY_PATH).filename())); + ASSERT_TRUE(is_regular_file(tmpAppDir / "usr/share/icons/hicolor/scalable/apps" / path(SIMPLE_ICON_PATH).filename())); } TEST_F(AppDirUnitTestsFixture, deployFileToDirectory) {