feat: add test for desktopentry and jobmanager
Log:
This commit is contained in:
39
tests/CMakeLists.txt
Normal file
39
tests/CMakeLists.txt
Normal file
@ -0,0 +1,39 @@
|
||||
set(BIN_NAME "ut-ddeam")
|
||||
|
||||
include(FindGTest)
|
||||
find_package(GTest REQUIRED)
|
||||
|
||||
add_compile_definitions(DDEAM_UNIT_TESTING)
|
||||
|
||||
file(GLOB_RECURSE SRCS ${PROJECT_SOURCE_DIR}/src/*.cpp)
|
||||
file(GLOB_RECURSE TESTS ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
|
||||
|
||||
list(REMOVE_ITEM SRCS "${PROJECT_SOURCE_DIR}/src/main.cpp")
|
||||
list(REMOVE_ITEM SRCS "${PROJECT_SOURCE_DIR}/src/utils.cpp")
|
||||
|
||||
add_executable(${BIN_NAME} ${SRCS} ${TESTS})
|
||||
|
||||
target_include_directories(${BIN_NAME} PRIVATE
|
||||
${PROJECT_BINARY_DIR}/
|
||||
)
|
||||
|
||||
target_link_libraries(${BIN_NAME} PRIVATE
|
||||
GTest::gtest
|
||||
${AdaptorLib}
|
||||
)
|
||||
|
||||
target_compile_options(${BIN_NAME} PRIVATE
|
||||
-fsanitize=undefined
|
||||
-fsanitize=address
|
||||
)
|
||||
|
||||
target_link_options(${BIN_NAME} PRIVATE
|
||||
-fsanitize=undefined
|
||||
-fsanitize=address
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME UnitTest
|
||||
COMMAND ${BIN_NAME}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
110
tests/data/desktopExample.desktop
Normal file
110
tests/data/desktopExample.desktop
Normal file
@ -0,0 +1,110 @@
|
||||
[Desktop Entry]
|
||||
Categories=Utility;TextEditor;
|
||||
Comment=Simple and easy to use text editor
|
||||
Exec=deepin-editor %F
|
||||
Icon=deepin-editor
|
||||
Name=Text Editor
|
||||
GenericName=Text Editor
|
||||
StartupNotify=false
|
||||
Type=Application
|
||||
X-Deepin-AppID=deepin-editor
|
||||
X-MultipleArgs=false
|
||||
X-Deepin-CreatedBy=com.deepin.dde.daemon.Launcher
|
||||
X-Deepin-Vendor=deepin
|
||||
# Translations:
|
||||
# Do not manually modify!
|
||||
Comment[ar]=محرر النصوص بسيط وسهل الاستخدام
|
||||
Comment[bo]=སྟབས་བདེ་ལ་སྤྱོད་བདེ་བའི་ཡིག་ཆ་རྩོམ་སྒྲིག་ཆས།
|
||||
Comment[br]=An aozer testennoù simpl hag aes d'ober gantañ
|
||||
Comment[ca]=Editor de text simple i fàcil d'usar
|
||||
Comment[cs]=Jednoduchý a snadno se používající textový editor
|
||||
Comment[da]=Simpel og letanvendelig teksteditor
|
||||
Comment[de]=Einfacher, leicht zu bedienender Texteditor
|
||||
Comment[es]=Editor de texto simple y fácil de usar
|
||||
Comment[et]=Lihtne ja kergesti kasutatav tekstiredaktor
|
||||
Comment[fi]=Yksinkertainen ja helppokäyttöinen tekstieditori
|
||||
Comment[fr]=Éditeur de texte simple et facile à utiliser
|
||||
Comment[gl_ES]=Editor de texto sinxelo e fácil de usar
|
||||
Comment[hr]=Jednostavan i lagan za korištenje uređivač teksta
|
||||
Comment[hu]=Letisztult és könnyen használható szövegszerkesztő
|
||||
Comment[it]=Editor di testo semplice e facile da usare. Localizzazione italiana a cura di Massimo A. Carofano.
|
||||
Comment[ko]=단순하고 사용하기 쉬운 텍스트 편집기
|
||||
Comment[lt]=Paprastas ir lengvas naudoti tekstų redaktorius
|
||||
Comment[ms]=Penyunting teks yang ringkas dan mudah digunakan
|
||||
Comment[nl]=Eenvoudig te gebruiken tekstbewerker
|
||||
Comment[pl]=Prosty i łatwy w użyciu edytor tekstu
|
||||
Comment[pt]=Editor de texto simples e fácil de usar
|
||||
Comment[pt_BR]=Um editor de texto simples e fácil de usar
|
||||
Comment[ru]=Простой и удобный текстовый редактор
|
||||
Comment[sq]=Përpunues tekstesh i thjeshtë dhe i kollajtë për t’u përdorur
|
||||
Comment[sr]=Уењђивач текста који је једноставан за употребу
|
||||
Comment[tr]=Basit ve kullanımı kolay metin düzenleyici
|
||||
Comment[ug]=ئاددىي، قوللىنىشچان تېكىست تەھرىرلىگۈچ
|
||||
Comment[uk]=Простий і доступний текстовий редактор
|
||||
Comment[zh_CN]=简单好用的文本编辑器
|
||||
Comment[zh_HK]=簡單好用的文本編輯器
|
||||
Comment[zh_TW]=簡單好用的文字編輯器
|
||||
GenericName[ar]=محرر النصوص
|
||||
GenericName[bo]=ཡིག་ཆ་རྩོམ་སྒྲུག་ཆས།
|
||||
GenericName[br]=Aozer testennoù
|
||||
GenericName[ca]=Editor de text
|
||||
GenericName[cs]=Textový editor
|
||||
GenericName[da]=Teksteditor
|
||||
GenericName[de]=Text Editor
|
||||
GenericName[es]=Editor de texto
|
||||
GenericName[et]=Tekstiredaktor
|
||||
GenericName[fi]=Tekstieditori
|
||||
GenericName[fr]=Éditeur de texte
|
||||
GenericName[en_US.UTF-8@euro;collation=traditional]=just for test\;teststing=abab\;
|
||||
GenericName[gl_ES]=Editor de texto
|
||||
GenericName[hr]=Uređivač teksta
|
||||
GenericName[hu]=Szövegszerkesztő
|
||||
GenericName[it]=Editor di Testo
|
||||
GenericName[ko]=텍스트 편집기
|
||||
GenericName[lt]=Tekstų redaktorius
|
||||
GenericName[ms]=Penyunting Teks
|
||||
GenericName[nl]=Tekstbewerker
|
||||
GenericName[pl]=Edytor tekstu
|
||||
GenericName[pt]=Editor de texto
|
||||
GenericName[pt_BR]=Editor de Textos
|
||||
GenericName[ru]=Текстовый редактор
|
||||
GenericName[sq]=Përpunues Tekstesh
|
||||
GenericName[sr]=Уређивач Текста
|
||||
GenericName[tr]=Metin Düzenleyici
|
||||
GenericName[ug]=تېكىست تەھرىرلىگۈچ
|
||||
GenericName[uk]=Текстовий редактор
|
||||
GenericName[zh_CN]=文本编辑器
|
||||
GenericName[zh_HK]=文本編輯器
|
||||
GenericName[zh_TW]=文字編輯器
|
||||
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-patch;text/x-adasrc;text/x-chdr;text/x-csrc;text/css;application/x-desktop;text/x-patch;text/x-fortran;text/html;text/x-java;text/x-tex;text/x-makefile;text/x-objcsrc;text/x-pascal;application/x-perl;application/x-perl;application/x-php;text/vnd.wap.wml;text/x-python;application/x-ruby;text/sgml;application/xml;model/vrml;image/svg+xml;application/json;
|
||||
Name[ar]=محرر نصوص ديبين
|
||||
Name[bo]=གཏིང་ཟབ་ཡིག་ཆ་རྩོམ་སྒྲིག་ཆས།
|
||||
Name[br]=Aozer testennoù Deepin
|
||||
Name[ca]=Editor de text del Deepin
|
||||
Name[cs]=Deepin textový editor
|
||||
Name[da]=Deepin teksteditor
|
||||
Name[de@euro]=Deepin Text Editor
|
||||
Name[es]=Editor de texto
|
||||
Name[et]=Deepin tekstiredaktor
|
||||
Name[fi]=Deepin tekstieditori
|
||||
Name[fr]=Éditeur de texte Deepin
|
||||
Name[gl_ES]=Editor de texto Deepin
|
||||
Name[hr]=Deepin uređivač teksta
|
||||
Name[hu]=Deepin® Szövegszerkesztő
|
||||
Name[it]=Editor di Testo di Deepin
|
||||
Name[ko]=Deepin 텍스트 편집기
|
||||
Name[lt]=Deepin tekstų redaktorius
|
||||
Name[ms]=Penyunting Teks Deepin
|
||||
Name[nl]=Deepin Tekstbewerker
|
||||
Name[pl]=Edytor Tekstu Deepin
|
||||
Name[pt]=Editor de texto Deepin
|
||||
Name[pt_BR]=deepin Editor de Textos
|
||||
Name[ru]=Текстовый Редактор Deepin
|
||||
Name[sq]=Përpunues Tekstesh Deepin
|
||||
Name[sr]=Дипин Уређивач Текста
|
||||
Name[tr]=Deepin Metin Düzenleyici
|
||||
Name[ug]=Deepin تېكىست تەھرىرلىگۈچ
|
||||
Name[uk]=Текстовий редактор Deepin
|
||||
Name[zh_CN]=文本编辑器
|
||||
Name[zh_HK]=Deepin 文本編輯器
|
||||
Name[zh_TW]=Deepin 文字編輯器
|
22
tests/main.cpp
Normal file
22
tests/main.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <gtest/gtest.h>
|
||||
#include <QTimer>
|
||||
#include <sanitizer/asan_interface.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
int ret{0};
|
||||
QTimer::singleShot(0, &app, [&ret] {
|
||||
ret = RUN_ALL_TESTS();
|
||||
QCoreApplication::quit();
|
||||
});
|
||||
__sanitizer_set_report_path("asan_am.log");
|
||||
QCoreApplication::exec();
|
||||
return ret;
|
||||
}
|
81
tests/ut_desktopentry.cpp
Normal file
81
tests/ut_desktopentry.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "desktopentry.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <QTextStream>
|
||||
#include <QSharedPointer>
|
||||
#include <QLocale>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
||||
class TestDesktopEntry : public testing::Test
|
||||
{
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
auto curDir = QDir::current();
|
||||
QString path{curDir.absolutePath() + "/data/desktopExample.desktop"};
|
||||
ParseError err;
|
||||
auto file = DesktopFile::searchDesktopFile(path,err);
|
||||
if (!file.has_value()) {
|
||||
qWarning() << "search " << path << "failed:" << err;
|
||||
return;
|
||||
}
|
||||
m_file.reset(new DesktopFile{std::move(file).value()});
|
||||
}
|
||||
void SetUp() override
|
||||
{
|
||||
|
||||
}
|
||||
void TearDown() override {}
|
||||
QSharedPointer<DesktopFile> file() { return m_file; }
|
||||
private:
|
||||
static inline QSharedPointer<DesktopFile> m_file;
|
||||
};
|
||||
|
||||
TEST_F(TestDesktopEntry, desktopFile)
|
||||
{
|
||||
const auto& fileptr = file();
|
||||
ASSERT_FALSE(fileptr.isNull());
|
||||
const auto &exampleFile = file();
|
||||
auto curDir = QDir::current();
|
||||
QString path{curDir.absolutePath() + "/data/desktopExample.desktop"};
|
||||
EXPECT_EQ(exampleFile->filePath().toStdString(), path.toStdString());
|
||||
EXPECT_EQ(exampleFile->desktopId().toStdString(), "");
|
||||
}
|
||||
|
||||
TEST_F(TestDesktopEntry, prase)
|
||||
{
|
||||
const auto &exampleFile = file();
|
||||
ASSERT_FALSE(exampleFile.isNull());;
|
||||
DesktopEntry entry;
|
||||
QFile in{exampleFile->filePath()};
|
||||
ASSERT_TRUE(in.open(QFile::ExistingOnly | QFile::ReadOnly | QFile::Text));
|
||||
QTextStream fs{&in};
|
||||
auto err = entry.parse(fs);
|
||||
ASSERT_EQ(err, ParseError::NoError);
|
||||
|
||||
auto group = entry.group("Desktop Entry");
|
||||
ASSERT_FALSE(group.isEmpty());
|
||||
|
||||
auto name = group.constFind("Name");
|
||||
ASSERT_NE(name, group.cend());
|
||||
|
||||
bool ok;
|
||||
name->toBoolean(ok);
|
||||
EXPECT_FALSE(ok);
|
||||
|
||||
name->toNumeric(ok);
|
||||
EXPECT_FALSE(ok);
|
||||
|
||||
auto defaultName = name->toString(ok);
|
||||
ASSERT_TRUE(ok);
|
||||
EXPECT_TRUE(defaultName == "Text Editor");
|
||||
|
||||
auto localeString = name->toLocaleString(QLocale{"zh_CN"}, ok);
|
||||
ASSERT_TRUE(ok);
|
||||
|
||||
EXPECT_TRUE(localeString == "文本编辑器");
|
||||
}
|
41
tests/ut_jobmanager.cpp
Normal file
41
tests/ut_jobmanager.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#include "jobmanager1service.h"
|
||||
#include "jobservice.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
class TestJobManager : public testing::Test
|
||||
{
|
||||
public:
|
||||
JobManager1Service& service() { return m_jobManager; }
|
||||
private:
|
||||
JobManager1Service m_jobManager;
|
||||
};
|
||||
|
||||
TEST_F(TestJobManager, addJob)
|
||||
{
|
||||
QDBusObjectPath sourcePath{"/org/deepin/Test1"};
|
||||
QVariantList args{{"Application"}, {"Application"}, {"Application"}, {"Application"}};
|
||||
auto &manager = service();
|
||||
QDBusObjectPath jobPath;
|
||||
QObject::connect(&manager, &JobManager1Service::JobNew, [&](const QDBusObjectPath &job, const QDBusObjectPath &source) {
|
||||
jobPath = job;
|
||||
EXPECT_TRUE(source == sourcePath);
|
||||
});
|
||||
QObject::connect(&manager,
|
||||
&JobManager1Service::JobRemoved,
|
||||
[&](const QDBusObjectPath &job, const QString &status, const QVariantList &result) {
|
||||
EXPECT_TRUE(jobPath == job);
|
||||
EXPECT_TRUE(status == "finished");
|
||||
EXPECT_TRUE(result.count() == 4);
|
||||
qDebug() << "job was really removed";
|
||||
});
|
||||
|
||||
manager.addJob(sourcePath, [](auto value) -> QVariant {
|
||||
EXPECT_TRUE(value.toString() == "Application");
|
||||
return QVariant::fromValue(true);
|
||||
}, args);
|
||||
QThread::sleep(1); // force wait
|
||||
}
|
6
tests/utils.cpp
Normal file
6
tests/utils.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "global.h"
|
||||
|
||||
bool registerObjectToDbus(QObject *, const QString &, const QString &)
|
||||
{
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user