1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-01-23 23:26:40 +00:00

Setup tests

This commit is contained in:
Quentin Rouland 2025-01-10 21:33:48 +01:00
parent 399173b776
commit 46145241fc
23 changed files with 244 additions and 62 deletions

View File

@ -35,9 +35,19 @@ set(DATA_DIR /)
set(DESKTOP_FILE_NAME ${PROJECT_NAME}.desktop)
add_executable(${PROJECT_NAME} main.cpp
qml/pages/settings/ImportGitClone.qml)
qt5_use_modules(${PROJECT_NAME} Gui Qml Quick)
if(NOT TESTS_PATH)
set(TESTS_PATH "./tests")
endif()
configure_file(main.in.cpp main.cpp)
add_executable(${PROJECT_NAME} main.cpp)
qt5_use_modules(${PROJECT_NAME} Gui Qml Quick QuickTest)
if(TESTS_RUNNER)
qt5_use_modules(${PROJECT_NAME} QuickTest)
endif()
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
@ -77,5 +87,9 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE_NAME} DESTINATION ${DAT
add_subdirectory(po)
add_subdirectory(plugins)
if(TESTS_RUNNER)
add_subdirectory(tests/plugins)
endif()
add_custom_target(${PROJECT_NAME}_FILES ALL SOURCES ${PROJECT_SRC_FILES})

View File

@ -4,7 +4,7 @@ kill: UTPass
scripts:
style: >-
echo 'Astyle :' && astyle --options=.astylerc main.cpp && astyle --options=.astylerc --recursive 'plugins/*.cpp,*.h' && echo 'Running QmlFormat' && find . -name "*.qml" -exec qmlformat -i {} \; && echo 'Success'
echo 'Running Astyle :' && astyle --options=.astylerc main.cpp && astyle --options=.astylerc --recursive 'plugins/*.cpp,*.h' && echo 'Running QmlFormat' && find . -name "*.qml" -exec qmlformat -i {} \; && echo 'Success'

View File

@ -6,6 +6,10 @@
#include <QtQml>
#ifdef TEST_RUNNER
#include <QtQuickTest/quicktest.h>
#endif
int main(int argc, char *argv[])
{
qDebug() << "Starting app from main.cpp";
@ -13,6 +17,7 @@ int main(int argc, char *argv[])
QGuiApplication::setApplicationName("utpass.qrouland");
#ifndef TEST_RUNNER
auto *view = new QQuickView();
view->setSource(QUrl(QStringLiteral("qml/Main.qml")));
view->setResizeMode(QQuickView::SizeRootObjectToView);
@ -23,4 +28,7 @@ int main(int argc, char *argv[])
Q_ARG(QVariant, QVariant::fromValue(mainView))
);
return QGuiApplication::exec();
#else
return quick_test_main(argc, argv, "@TESTS_PATH@", "@TESTS_PATH@");
#endif
}

View File

@ -13,7 +13,6 @@ bool Git::clone(QString url, QString destination_dir_path)
QDir tmp_dir(QStandardPaths::writableLocation(
QStandardPaths::CacheLocation).append("/clone"));
tmp_dir.removeRecursively();
tmp_dir.mkpath(".");
qDebug() << "Temp dir path is " << tmp_dir.absolutePath();
qDebug() << "Cloning " << url << " to tmp dir " << tmp_dir.absolutePath();

View File

@ -33,10 +33,10 @@ int LibGit::credentials_cb(git_cred **out, const char *url, const char *username
// store_error(error);
// return GIT_EUSER;
// }
// user = "user";
// pass = "pass";
// return git_cred_userpass_plaintext_new(out, user, pass);
return GIT_EUSER;
user = "pass";
pass = "pass";
return git_cred_userpass_plaintext_new(out, user, pass);
// return GIT_EUSER;
}
bool LibGit::clone(QString url, QString path)
@ -45,8 +45,12 @@ bool LibGit::clone(QString url, QString path)
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
opts.fetch_opts.callbacks.credentials = *credentials_cb;
int ret = git_clone(&repo, url.toLocal8Bit().data(), path.toLocal8Bit().data(), &opts);
if (ret != 0) {
qDebug() << git_error_last()->message;
}
if (repo) {
git_repository_free(repo);
}
return ret == 0; // TODO Clean error handling to return specifics errors for the ui
}

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: utpass.qrouland\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-10 14:39+0100\n"
"POT-Creation-Date: 2025-01-10 21:31+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,7 +17,7 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../qml/components/FileDir.qml:71
#: ../qml/components/FileDir.qml:69
msgid "Decryption failed !"
msgstr ""
@ -37,19 +37,19 @@ msgstr ""
msgid "Error !"
msgstr ""
#: ../qml/dialogs/ErrorDialog.qml:15
#: ../qml/dialogs/ErrorDialog.qml:16
msgid "Close"
msgstr ""
#: ../qml/dialogs/PassphraseDialog.qml:7
#: ../qml/dialogs/PassphraseDialog.qml:15
msgid "Authentication required"
msgstr ""
#: ../qml/dialogs/PassphraseDialog.qml:8
#: ../qml/dialogs/PassphraseDialog.qml:16
msgid "Enter passphrase:"
msgstr ""
#: ../qml/dialogs/PassphraseDialog.qml:20
#: ../qml/dialogs/PassphraseDialog.qml:21
msgid "passphrase"
msgstr ""
@ -57,69 +57,65 @@ msgstr ""
msgid "Success !"
msgstr ""
#: ../qml/dialogs/SuccessDialog.qml:15
#: ../qml/dialogs/SuccessDialog.qml:16
msgid "OK"
msgstr ""
#: ../qml/pages/Info.qml:11 ../qml/pages/headers/MainHeader.qml:58
msgid "Info"
msgstr ""
#: ../qml/pages/Info.qml:50
#: ../qml/pages/Info.qml:58
msgid "<b>Version</b>"
msgstr ""
#: ../qml/pages/Info.qml:68
#: ../qml/pages/Info.qml:77
msgid "<b>Maintainer</>"
msgstr ""
#: ../qml/pages/Info.qml:90
#: ../qml/pages/Info.qml:102
msgid "Suggest improvement(s) or report a bug(s)"
msgstr ""
#: ../qml/pages/Info.qml:94
#: ../qml/pages/Info.qml:107
msgid "Access to the source code"
msgstr ""
#: ../qml/pages/Info.qml:101
#: ../qml/pages/Info.qml:115
msgid "Released under the terms of the GNU GPL v3"
msgstr ""
#: ../qml/pages/PasswordList.qml:23
msgid "Back"
#: ../qml/pages/Info.qml:123 ../qml/pages/headers/MainHeader.qml:33
msgid "Info"
msgstr ""
#: ../qml/pages/PasswordList.qml:43
#: ../qml/pages/PasswordList.qml:26
msgid ""
"No password found<br>You can import a password store zip in the settings"
msgstr ""
#: ../qml/pages/headers/MainHeader.qml:8 ../qml/pages/headers/StackHeader.qml:8
#: ../qml/pages/PasswordList.qml:65
msgid "Back"
msgstr ""
#: ../qml/pages/headers/MainHeader.qml:9 ../qml/pages/headers/StackHeader.qml:9
#: UTPass.desktop.in.h:1
msgid "UTPass"
msgstr ""
#: ../qml/pages/headers/MainHeader.qml:23
msgid "Search"
msgstr ""
#: ../qml/pages/headers/MainHeader.qml:51 ../qml/pages/settings/Settings.qml:14
#: ../qml/pages/headers/MainHeader.qml:26 ../qml/pages/settings/Settings.qml:68
msgid "Settings"
msgstr ""
#: ../qml/pages/settings/ImportGitClone.qml:15
msgid "Git Clone Import"
#: ../qml/pages/headers/MainHeader.qml:57
msgid "Search"
msgstr ""
#: ../qml/pages/settings/ImportGitClone.qml:36
msgid "Repo Url"
msgstr ""
#: ../qml/pages/settings/ImportGitClone.qml:44
#: ../qml/pages/settings/ImportGitClone.qml:45
msgid "Git repo url"
msgstr ""
#: ../qml/pages/settings/ImportGitClone.qml:50
#: ../qml/pages/settings/ImportGitClone.qml:52
msgid "Clone"
msgstr ""
@ -129,85 +125,89 @@ msgid ""
"<br>Continue ?"
msgstr ""
#: ../qml/pages/settings/ImportGitClone.qml:78
#: ../qml/pages/settings/ImportGitClone.qml:80
msgid "An error occured during git clone !"
msgstr ""
#: ../qml/pages/settings/ImportGitClone.qml:85
#: ../qml/pages/settings/ImportZip.qml:89
#: ../qml/pages/settings/ImportGitClone.qml:89
#: ../qml/pages/settings/ImportZip.qml:82
msgid "Password store sucessfully imported !"
msgstr ""
#: ../qml/pages/settings/ImportKeyFile.qml:17
msgid "GPG Key Import"
#: ../qml/pages/settings/ImportGitClone.qml:101
msgid "Git Clone Import"
msgstr ""
#: ../qml/pages/settings/ImportKeyFile.qml:69
#: ../qml/pages/settings/ImportKeyFile.qml:57
msgid "Key import failed !"
msgstr ""
#: ../qml/pages/settings/ImportKeyFile.qml:76
#: ../qml/pages/settings/ImportKeyFile.qml:66
msgid "Key successfully imported !"
msgstr ""
#: ../qml/pages/settings/ImportZip.qml:17
msgid "Zip Password Store Import"
#: ../qml/pages/settings/ImportKeyFile.qml:77
msgid "GPG Key Import"
msgstr ""
#: ../qml/pages/settings/ImportZip.qml:72
#: ../qml/pages/settings/ImportZip.qml:61
msgid ""
"Importing a new zip will delete<br>any existing password store!<br>Continue ?"
msgstr ""
#: ../qml/pages/settings/ImportZip.qml:82
#: ../qml/pages/settings/ImportZip.qml:73
msgid "Password store import failed !"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:16
msgid "Info Keys"
#: ../qml/pages/settings/ImportZip.qml:94
msgid "Zip Password Store Import"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:44
#: ../qml/pages/settings/InfoKeys.qml:40
msgid "Key id : %1"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:49
#: ../qml/pages/settings/InfoKeys.qml:46
msgid "Delete this key"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:68
#: ../qml/pages/settings/InfoKeys.qml:67
msgid "You're are about to delete<br>%1<br>Continue ?"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:71
#: ../qml/pages/settings/InfoKeys.qml:68
msgid "%1<br>will be definitively removed.<br>Continue ?"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:87
#: ../qml/pages/settings/InfoKeys.qml:84
msgid "Key removal failed !"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:94
#: ../qml/pages/settings/InfoKeys.qml:93
msgid "Key successfully deleted !"
msgstr ""
#: ../qml/pages/settings/Settings.qml:28
#: ../qml/pages/settings/InfoKeys.qml:104
msgid "Info Keys"
msgstr ""
#: ../qml/pages/settings/Settings.qml:23
msgid "GPG"
msgstr ""
#: ../qml/pages/settings/Settings.qml:32
#: ../qml/pages/settings/Settings.qml:28
msgid "Import a GPG key file"
msgstr ""
#: ../qml/pages/settings/Settings.qml:36
#: ../qml/pages/settings/Settings.qml:33
msgid "Show GPG keys"
msgstr ""
#: ../qml/pages/settings/Settings.qml:43
#: ../qml/pages/settings/Settings.qml:41
msgid "Password Store"
msgstr ""
#: ../qml/pages/settings/Settings.qml:47
#: ../qml/pages/settings/Settings.qml:46
msgid "Import a Password Store using Git"
msgstr ""

BIN
tests/assets/archive.zip Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
utpasspassphrase

Binary file not shown.

View File

@ -0,0 +1 @@
*.gpg diff=gpg

View File

@ -0,0 +1 @@
UTPass Test

View File

View File

@ -0,0 +1 @@
└^ШзАщн8m@%f#▄≥┌б╧┌пмnW▐[qЬ╜┴Xз&ч>&MO`0жБ@ o▀▓(М≤R▒╖└+-В┌щ╧ 'ZHБ╗╖╤лEЗfКцJ╧Nxаь⌠8РтE ⌠з│W/°<┐-И7л# oJ╛dЭ≥7^т?аыHЫ4²H9└`kОdеwg╨d©╓Р9╣лА·ё▒x╫│╧Ж

View File

@ -0,0 +1 @@
add_subdirectory(TestsUtils)

View 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}/)

View 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; });
}

View 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

View File

@ -0,0 +1,2 @@
module TestUtils
plugin TestUtils

View 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
}
}

View 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

12
tests/unit/tst_git.qml Normal file
View File

@ -0,0 +1,12 @@
import QtQuick 2.9
import QtTest 1.2
import Git 1.0
TestCase {
name: "git"
function test_git_clone() {
verify(Git.clone("",""));
}
}

12
tests/unit/tst_pass.qml Normal file
View File

@ -0,0 +1,12 @@
import QtQuick 2.9
import QtTest 1.2
import Git 1.0
TestCase {
name: "git"
function test_git_clone() {
verify(Git.clone("",""));
}
}

15
tests/unit/tst_utils.qml Normal file
View File

@ -0,0 +1,15 @@
import QtQuick 2.9
import QtTest 1.2
import TestUtils 1.0
import Utils 1.0
TestCase {
name: "utils"
function test_unzip() {
var tempPath = TestUtils.getTempPath() + "/password-store";
var zipUrl = Qt.resolvedUrl("../assets/archive.zip");
var r = Utils.unzip(zipUrl, tempPath)
verify(r, "Unzip return an error %1".arg(zipUrl))
}
}