aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/CatPack_test.cpp40
-rw-r--r--tests/testdata/CatPacks/index.json50
3 files changed, 93 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a26a49fe..59e0e314 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -56,3 +56,6 @@ ecm_add_test(Index_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}:
ecm_add_test(Version_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
TEST_NAME Version)
+
+ecm_add_test(CatPack_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
+ TEST_NAME CatPack)
diff --git a/tests/CatPack_test.cpp b/tests/CatPack_test.cpp
new file mode 100644
index 00000000..330d1a81
--- /dev/null
+++ b/tests/CatPack_test.cpp
@@ -0,0 +1,40 @@
+#include <QTest>
+
+#include <QDate>
+#include <QFileInfo>
+#include <QList>
+#include <QTemporaryFile>
+#include "FileSystem.h"
+#include "ui/themes/CatPack.h"
+
+class CatPackTest : public QObject {
+ Q_OBJECT
+ private slots:
+ void test_catPack()
+ {
+ auto dataDir = QDir(QFINDTESTDATA("testdata/CatPacks")).absolutePath();
+ auto fileName = FS::PathCombine(dataDir, "index.json");
+ auto fileinfo = QFileInfo(fileName);
+ try {
+ auto cat = JsonCatPack(fileinfo);
+ QCOMPARE(cat.path(QDate(2023, 4, 12)), FS::PathCombine(fileinfo.path(), "oneDay.png"));
+ QCOMPARE(cat.path(QDate(2023, 4, 11)), FS::PathCombine(fileinfo.path(), "maxwell.png"));
+ QCOMPARE(cat.path(QDate(2023, 4, 13)), FS::PathCombine(fileinfo.path(), "maxwell.png"));
+ QCOMPARE(cat.path(QDate(2023, 12, 21)), FS::PathCombine(fileinfo.path(), "christmas.png"));
+ QCOMPARE(cat.path(QDate(2023, 12, 28)), FS::PathCombine(fileinfo.path(), "christmas.png"));
+ QCOMPARE(cat.path(QDate(2023, 12, 29)), FS::PathCombine(fileinfo.path(), "newyear.png"));
+ QCOMPARE(cat.path(QDate(2023, 12, 30)), FS::PathCombine(fileinfo.path(), "newyear2.png"));
+ QCOMPARE(cat.path(QDate(2023, 12, 31)), FS::PathCombine(fileinfo.path(), "newyear2.png"));
+ QCOMPARE(cat.path(QDate(2024, 1, 1)), FS::PathCombine(fileinfo.path(), "newyear2.png"));
+ QCOMPARE(cat.path(QDate(2024, 1, 2)), FS::PathCombine(fileinfo.path(), "newyear.png"));
+ QCOMPARE(cat.path(QDate(2024, 1, 3)), FS::PathCombine(fileinfo.path(), "newyear.png"));
+ QCOMPARE(cat.path(QDate(2024, 1, 4)), FS::PathCombine(fileinfo.path(), "maxwell.png"));
+ } catch (const Exception& e) {
+ QFAIL(e.cause().toLatin1());
+ }
+ }
+};
+
+QTEST_GUILESS_MAIN(CatPackTest)
+
+#include "CatPack_test.moc"
diff --git a/tests/testdata/CatPacks/index.json b/tests/testdata/CatPacks/index.json
new file mode 100644
index 00000000..b5401d23
--- /dev/null
+++ b/tests/testdata/CatPacks/index.json
@@ -0,0 +1,50 @@
+{
+ "name": "My Cute Cat",
+ "default": "maxwell.png",
+ "variants": [
+ {
+ "startTime": {
+ "day": 12,
+ "month": 4
+ },
+ "endTime": {
+ "day": 12,
+ "month": 4
+ },
+ "path": "oneDay.png"
+ },
+ {
+ "startTime": {
+ "day": 20,
+ "month": 12
+ },
+ "endTime": {
+ "day": 28,
+ "month": 12
+ },
+ "path": "christmas.png"
+ },
+ {
+ "startTime": {
+ "day": 30,
+ "month": 12
+ },
+ "endTime": {
+ "day": 1,
+ "month": 1
+ },
+ "path": "newyear2.png"
+ },
+ {
+ "startTime": {
+ "day": 28,
+ "month": 12
+ },
+ "endTime": {
+ "day": 3,
+ "month": 1
+ },
+ "path": "newyear.png"
+ }
+ ]
+}