mirror of
https://github.com/QRouland/UTPass.git
synced 2025-06-24 22:42:28 +00:00
Setup tests
This commit is contained in:
1
tests/plugins/CMakeLists.txt
Normal file
1
tests/plugins/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_subdirectory(TestsUtils)
|
29
tests/plugins/TestsUtils/CMakeLists.txt
Normal file
29
tests/plugins/TestsUtils/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(PLUGIN "TestsUtils")
|
||||
|
||||
set(
|
||||
SRC
|
||||
plugin.cpp
|
||||
utils.cpp
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
execute_process(
|
||||
COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
|
||||
OUTPUT_VARIABLE ARCH_TRIPLET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
if(ARCH_TRIPLET STREQUAL "")
|
||||
set(ARCH_TRIPLET x86_64-linux-gnu)
|
||||
endif()
|
||||
|
||||
add_library(${PLUGIN} MODULE ${SRC})
|
||||
set_target_properties(${PLUGIN} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN})
|
||||
qt5_use_modules(${PLUGIN} Qml Quick DBus)
|
||||
|
||||
set(QT_IMPORTS_DIR "/lib/${ARCH_TRIPLET}")
|
||||
|
||||
install(TARGETS ${PLUGIN} DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN}/)
|
||||
install(FILES qmldir DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN}/)
|
10
tests/plugins/TestsUtils/plugin.cpp
Normal file
10
tests/plugins/TestsUtils/plugin.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <QtQml>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "utils.h"
|
||||
|
||||
void TestsUtilsPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
//@uri TestUtils
|
||||
qmlRegisterSingletonType<TestsUtilsPlugin>(uri, 1, 0, "TestUtils", [](QQmlEngine *, QJSEngine *) -> QObject * { return new TestsUtils; });
|
||||
}
|
16
tests/plugins/TestsUtils/plugin.h
Normal file
16
tests/plugins/TestsUtils/plugin.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef TESTSUTILSPLUGIN_H
|
||||
#define TESTSUTILSPLUGIN_H
|
||||
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class TestsUtilsPlugin : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID
|
||||
"org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char *uri) override;
|
||||
};
|
||||
|
||||
#endif
|
2
tests/plugins/TestsUtils/qmldir
Normal file
2
tests/plugins/TestsUtils/qmldir
Normal file
@ -0,0 +1,2 @@
|
||||
module TestUtils
|
||||
plugin TestUtils
|
37
tests/plugins/TestsUtils/utils.cpp
Normal file
37
tests/plugins/TestsUtils/utils.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
#include <QtCore/QStandardPaths>
|
||||
#include <quazip5/JlCompress.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
QString TestsUtils::getTempPath() {
|
||||
qFatal("yp");
|
||||
// Get the system's temporary directory
|
||||
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
||||
qDebug() << "TempDir : " << tempDir;
|
||||
|
||||
// Generate a unique UUID
|
||||
QString uuid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
|
||||
// Create a new directory using the generated UUID
|
||||
QString newTempDir = tempDir + "/" + uuid;
|
||||
|
||||
QDir dir;
|
||||
if (!dir.exists(newTempDir)) {
|
||||
// Create the directory
|
||||
if (dir.mkpath(newTempDir)) {
|
||||
return newTempDir; // Return the path if successful
|
||||
} else {
|
||||
return "Failed to create directory"; // Return an error message
|
||||
}
|
||||
} else {
|
||||
return newTempDir; // If the directory already exists, return its path
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
19
tests/plugins/TestsUtils/utils.h
Normal file
19
tests/plugins/TestsUtils/utils.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef TESTSUTILS_H
|
||||
#define TESTSUTILS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QQuickWindow>
|
||||
|
||||
class TestsUtils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestsUtils() = default;
|
||||
~TestsUtils() override = default;
|
||||
|
||||
Q_INVOKABLE QString getTempPath();
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user