Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1fa90fb

Browse filesBrowse files
author
Alexis Lopez Zubieta
committed
Add namespace and prepare unittest
1 parent 7318d68 commit 1fa90fb
Copy full SHA for 1fa90fb

5 files changed

+151-54Lines changed: 151 additions & 54 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/linuxdeploy.cpp‎

Copy file name to clipboardExpand all lines: src/linuxdeploy.cpp
+50-49Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,69 @@ using namespace linuxdeploy::core::log;
1313
using namespace linuxdeploy::util;
1414
namespace bf = boost::filesystem;
1515

16+
namespace linuxdeploy {
17+
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
18+
args::ValueFlag<std::string>& customAppRunPath, appdir::AppDir& appDir) {
19+
// search for desktop file and deploy it to AppDir root
20+
ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl;
1621

17-
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
18-
args::ValueFlag<std::string>& customAppRunPath, appdir::AppDir& appDir) {
19-
// search for desktop file and deploy it to AppDir root
20-
ldLog() << std::endl << "-- Deploying files into AppDir root directory --" << std::endl;
22+
if (is_regular_file(appDir.path() / "AppRun")) {
23+
if (customAppRunPath)
24+
ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun"
25+
<< std::endl;
26+
else
27+
ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl;
28+
} else {
29+
auto deployedDesktopFiles = appDir.deployedDesktopFiles();
2130

22-
if (is_regular_file(appDir.path() / "AppRun")) {
23-
if (customAppRunPath)
24-
ldLog() << LD_WARNING << "AppRun exists but custom AppRun specified, overwriting existing AppRun"
25-
<< std::endl;
26-
else
27-
ldLog() << LD_WARNING << "AppRun exists, skipping deployment" << std::endl;
28-
} else {
29-
auto deployedDesktopFiles = appDir.deployedDesktopFiles();
31+
desktopfile::DesktopFile desktopFile;
3032

31-
desktopfile::DesktopFile desktopFile;
33+
if (deployedDesktopFiles.empty()) {
34+
ldLog() << LD_WARNING
35+
<< "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root"
36+
<< std::endl;
37+
} else {
38+
if (!desktopFilePaths.Get().empty()) {
39+
auto firstDeployedDesktopFileName = boost::filesystem::path(
40+
desktopFilePaths.Get().front()).filename().string();
3241

33-
if (deployedDesktopFiles.empty()) {
34-
ldLog() << LD_WARNING
35-
<< "Could not find desktop file in AppDir, cannot create links for AppRun, desktop file and icon in AppDir root"
36-
<< std::endl;
37-
} else {
38-
if (!desktopFilePaths.Get().empty()) {
39-
auto firstDeployedDesktopFileName = boost::filesystem::path(
40-
desktopFilePaths.Get().front()).filename().string();
42+
auto desktopFileMatchingName = find_if(
43+
deployedDesktopFiles.begin(),
44+
deployedDesktopFiles.end(),
45+
[&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) {
46+
auto fileName = desktopFile.path().filename().string();
47+
return fileName == firstDeployedDesktopFileName;
48+
}
49+
);
4150

42-
auto desktopFileMatchingName = find_if(
43-
deployedDesktopFiles.begin(),
44-
deployedDesktopFiles.end(),
45-
[&firstDeployedDesktopFileName](const desktopfile::DesktopFile& desktopFile) {
46-
auto fileName = desktopFile.path().filename().string();
47-
return fileName == firstDeployedDesktopFileName;
51+
if (desktopFileMatchingName != deployedDesktopFiles.end()) {
52+
desktopFile = *desktopFileMatchingName;
53+
} else {
54+
ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:"
55+
<< firstDeployedDesktopFileName << std::endl;
56+
return 1;
4857
}
49-
);
50-
51-
if (desktopFileMatchingName != deployedDesktopFiles.end()) {
52-
desktopFile = *desktopFileMatchingName;
5358
} else {
54-
ldLog() << LD_ERROR << "Could not find desktop file deployed earlier any more:"
55-
<< firstDeployedDesktopFileName << std::endl;
56-
return 1;
59+
desktopFile = deployedDesktopFiles[0];
60+
ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:"
61+
<< desktopFile.path() << std::endl;
5762
}
58-
} else {
59-
desktopFile = deployedDesktopFiles[0];
60-
ldLog() << LD_WARNING << "No desktop file specified, using first desktop file found:"
61-
<< desktopFile.path() << std::endl;
62-
}
6363

64-
ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl;
64+
ldLog() << "Deploying desktop file:" << desktopFile.path() << std::endl;
6565

66-
bool rv;
66+
bool rv;
6767

68-
if (customAppRunPath) {
69-
rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get());
70-
} else {
71-
rv = appDir.createLinksInAppDirRoot(desktopFile);
72-
}
68+
if (customAppRunPath) {
69+
rv = appDir.createLinksInAppDirRoot(desktopFile, customAppRunPath.Get());
70+
} else {
71+
rv = appDir.createLinksInAppDirRoot(desktopFile);
72+
}
7373

74-
if (!rv) {
75-
return 1;
74+
if (!rv) {
75+
return 1;
76+
}
7677
}
7778
}
79+
return true;
7880
}
79-
return true;
8081
}
Collapse file

‎src/linuxdeploy.h‎

Copy file name to clipboardExpand all lines: src/linuxdeploy.h
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <linuxdeploy/core/log.h>
88
#include <linuxdeploy/util/util.h>
99
#include <args.hxx>
10-
11-
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
12-
args::ValueFlag<std::string>& customAppRunPath,
13-
linuxdeploy::core::appdir::AppDir& appDir);
10+
namespace linuxdeploy {
11+
int deployAppDirRootFiles(args::ValueFlagList<std::string>& desktopFilePaths,
12+
args::ValueFlag<std::string>& customAppRunPath,
13+
linuxdeploy::core::appdir::AppDir& appDir);
14+
}
Collapse file

‎src/main.cpp‎

Copy file name to clipboardExpand all lines: src/main.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ int main(int argc, char** argv) {
254254
return 1;
255255
}
256256
}
257-
if (!deployAppDirRootFiles(desktopFilePaths, customAppRunPath, appDir))
257+
if (!linuxdeploy::deployAppDirRootFiles(desktopFilePaths, customAppRunPath, appDir))
258258
return 1;
259259

260260
if (outputPlugins) {
Collapse file

‎tests/core/CMakeLists.txt‎

Copy file name to clipboardExpand all lines: tests/core/CMakeLists.txt
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,24 @@ add_test(test_appdir test_appdir)
1616

1717
# make sure library and executable are built before test_appdir
1818
add_dependencies(test_appdir simple_library simple_executable)
19+
20+
21+
22+
add_executable(test_linuxdeploy test_linuxdeploy.cpp ../../src/linuxdeploy.cpp)
23+
target_link_libraries(test_linuxdeploy PRIVATE linuxdeploy_core args gtest gtest_main)
24+
target_include_directories(test_linuxdeploy PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src)
25+
26+
# calculate paths to resources using CMake and hardcode them in the test binary
27+
target_compile_definitions(test_linuxdeploy PRIVATE
28+
-DSIMPLE_LIBRARY_PATH="$<TARGET_FILE:simple_library>"
29+
-DSIMPLE_EXECUTABLE_PATH="$<TARGET_FILE:simple_executable>"
30+
-DSIMPLE_DESKTOP_ENTRY_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_app.desktop"
31+
-DSIMPLE_ICON_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_icon.svg"
32+
-DSIMPLE_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../data/simple_file.txt"
33+
)
34+
35+
# register in CTest
36+
add_test(test_linuxdeploy test_linuxdeploy)
37+
38+
# make sure library and executable are built before test_appdir
39+
add_dependencies(test_linuxdeploy simple_library simple_executable)
Collapse file

‎tests/core/test_linuxdeploy.cpp‎

Copy file name to clipboard
+74Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "gtest/gtest.h"
2+
3+
#include "linuxdeploy.h"
4+
5+
using namespace boost::filesystem;
6+
7+
namespace LinuxDeployTest {
8+
class LinuxDeployTestsFixture : public ::testing::Test {
9+
public:
10+
path tmpAppDir;
11+
12+
public:
13+
LinuxDeployTestsFixture() = default;
14+
15+
void SetUp() override {
16+
tmpAppDir = temp_directory_path() / unique_path("linuxdeploy-tests-%%%%-%%%%-%%%%");
17+
create_directories(tmpAppDir);
18+
}
19+
20+
void TearDown() override {
21+
remove_all(tmpAppDir);
22+
}
23+
24+
~LinuxDeployTestsFixture() override = default;
25+
26+
void listDeployedFiles() {
27+
std::cout << "Files deployed in AppDir:" << std::endl;
28+
recursive_directory_iterator end_itr; // default construction yields past-the-end
29+
for (recursive_directory_iterator itr(tmpAppDir); itr != end_itr; itr++) {
30+
std::cout << relative(itr->path(), tmpAppDir).string() << std::endl;
31+
}
32+
}
33+
34+
void fillRegularAppDir() {
35+
add_executable();
36+
add_desktop();
37+
add_icon();
38+
}
39+
40+
void add_executable() const {
41+
path source_executable_path = SIMPLE_EXECUTABLE_PATH;
42+
path target_executable_path = tmpAppDir / "usr/bin" / source_executable_path.filename();
43+
create_directories(target_executable_path.parent_path());
44+
copy_file(source_executable_path, target_executable_path);
45+
}
46+
47+
void add_desktop() const {
48+
path source_desktop_path = SIMPLE_DESKTOP_ENTRY_PATH;
49+
path target_desktop_path = tmpAppDir / "usr/share/applications" / source_desktop_path.filename();
50+
create_directories(target_desktop_path.parent_path());
51+
copy_file(source_desktop_path, target_desktop_path);
52+
}
53+
54+
void add_icon() const {
55+
path source_icon_path = SIMPLE_ICON_PATH;
56+
path target_icon_path = tmpAppDir / "usr/share/icons/hicolor/scalable/apps" / source_icon_path.filename();
57+
create_directories(target_icon_path.parent_path());
58+
copy_file(source_icon_path, target_icon_path);
59+
}
60+
61+
void add_apprun() const {
62+
path source_apprun_path = SIMPLE_FILE_PATH;
63+
path target_apprun_path = tmpAppDir / "AppRun";
64+
copy_file(source_apprun_path, target_apprun_path);
65+
}
66+
};
67+
68+
TEST_F(LinuxDeployTestsFixture, deployAppDirRootFilesWithExistentAppRun) {
69+
fillRegularAppDir();
70+
add_apprun();
71+
72+
listDeployedFiles();
73+
}
74+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.