forked from linuxdeploy/linuxdeploy-plugin-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_deploy_qml.cpp
More file actions
122 lines (96 loc) · 5.03 KB
/
Copy pathtest_deploy_qml.cpp
File metadata and controls
122 lines (96 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// library includes
#include <gtest/gtest.h>
// local includes
#include "../src/qml.h"
#include "../src/util.h"
namespace fs = std::filesystem;
namespace linuxdeploy {
namespace plugin {
namespace qt {
namespace test {
class TestDeployQml : public testing::Test {
public:
std::filesystem::path appDirPath;
std::filesystem::path projectQmlRoot;
std::filesystem::path defaultQmlImportPath;
void SetUp() override {
appDirPath = getTempDirName();
projectQmlRoot = appDirPath.string() + "/usr/qml";
std::filesystem::create_directories(projectQmlRoot);
std::filesystem::copy_file(TESTS_DATA_DIR "/qml_project/file.qml",
projectQmlRoot.string() + "/file.qml");
setenv(ENV_KEY_QML_MODULES_PATHS, TESTS_DATA_DIR, 1);
defaultQmlImportPath = getQmlImportPath();
}
std::string getTempDirName() const {
char tmpl[] = "/tmp/linuxdeploy-plugin-qt-unit-tests-appdir-XXXXXX";
char* tempDir = mkdtemp(tmpl);
std::string name{tempDir};
return name;
}
void TearDown() override {
std::filesystem::remove_all(appDirPath);
unsetenv(ENV_KEY_QML_MODULES_PATHS);
}
fs::path getQmlImportPath() {
const auto& qmakePath = findQmake();
return queryQmake(qmakePath)["QT_INSTALL_QML"];
}
};
TEST_F(TestDeployQml, find_qmlimporter_path) {
auto result = findQmlImportScanner();
ASSERT_FALSE(result.empty());
ASSERT_EQ(result.filename().string(), "qmlimportscanner");
}
TEST_F(TestDeployQml, runQmlImportScanner) {
auto result = runQmlImportScanner({projectQmlRoot},
{TESTS_DATA_DIR, defaultQmlImportPath});
ASSERT_FALSE(result.empty());
std::cout << result;
}
TEST_F(TestDeployQml, run_qmlimportscanner_without_qml_import_paths) {
auto result = runQmlImportScanner({projectQmlRoot}, {});
ASSERT_FALSE(result.empty());
std::cout << result;
}
// disabled, as Debian's qmlimportscanner does not behave as expected
/*
TEST_F(TestDeployQml, getQmlImports) {
auto results = getQmlImports(projectQmlRoot, defaultQmlImportPath);
ASSERT_FALSE(results.empty());
std::cout << "Imported Qml Modules Found:";
for (auto result : results) {
std::cout << "\n\tName: " << result.name << "\n\tPath: " << result.path << "\n\tRelative path:"
<< result.relativePath << std::endl;
ASSERT_FALSE(result.path.empty());
ASSERT_FALSE(result.relativePath.empty());
}
}
*/
TEST_F(TestDeployQml, deploy_qml_imports) {
linuxdeploy::core::appdir::AppDir appDir(appDirPath);
// speed up test runs; we don't check for the copyright files anyway
appDir.setDisableCopyrightFilesDeployment(true);
deployQml(appDir, defaultQmlImportPath);
appDir.executeDeferredOperations();
ASSERT_TRUE(std::filesystem::exists(projectQmlRoot.string() + "/QtQuick.2"));
ASSERT_TRUE(std::filesystem::exists(projectQmlRoot.string() + "/qml_module"));
}
TEST_F(TestDeployQml, getQmlModuleRelativePath) {
std::vector<fs::path> qmlModulesImportPaths = {"/usr/lib/x86_64-linux-gnu/qt5/qml", "/usr/lib/",
"/usr/lib/qt5.10/qml", TESTS_DATA_DIR};
auto rpath = getQmlModuleRelativePath(qmlModulesImportPaths,
"/usr/lib/x86_64-linux-gnu/qt5/qml/QtQuick.2");
ASSERT_EQ(rpath, "QtQuick.2");
rpath = getQmlModuleRelativePath(qmlModulesImportPaths,
"/usr/lib/x86_64-linux-gnu/qt5/qml/org/kde/plasma");
ASSERT_EQ(rpath, "org/kde/plasma");
rpath = getQmlModuleRelativePath(qmlModulesImportPaths, TESTS_DATA_DIR "/qml_module");
ASSERT_EQ(rpath, "qml_module");
rpath = getQmlModuleRelativePath(qmlModulesImportPaths, "/qml_module");
ASSERT_EQ(rpath, "");
}
}
}
}
}