Merge pull request #1572 from Trial97/catpacks2
This commit is contained in:
commit
00af385619
@ -99,18 +99,22 @@ QDate ensureDay(int year, int month, int day)
|
|||||||
|
|
||||||
QString JsonCatPack::path()
|
QString JsonCatPack::path()
|
||||||
{
|
{
|
||||||
const QDate now = QDate::currentDate();
|
return path(QDate::currentDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString JsonCatPack::path(QDate now)
|
||||||
|
{
|
||||||
for (auto var : m_variants) {
|
for (auto var : m_variants) {
|
||||||
QDate startDate = ensureDay(now.year(), var.startTime.month, var.startTime.day);
|
QDate startDate = ensureDay(now.year(), var.startTime.month, var.startTime.day);
|
||||||
QDate endDate = ensureDay(now.year(), var.endTime.month, var.endTime.day);
|
QDate endDate = ensureDay(now.year(), var.endTime.month, var.endTime.day);
|
||||||
if (startDate > endDate) { // it's spans over multiple years
|
if (startDate > endDate) { // it's spans over multiple years
|
||||||
if (endDate <= now) // end date is in the past so jump one year into the future for endDate
|
if (endDate < now) // end date is in the past so jump one year into the future for endDate
|
||||||
endDate = endDate.addYears(1);
|
endDate = endDate.addYears(1);
|
||||||
else // end date is in the future so jump one year into the past for startDate
|
else // end date is in the future so jump one year into the past for startDate
|
||||||
startDate = startDate.addYears(-1);
|
startDate = startDate.addYears(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startDate >= now && now >= endDate)
|
if (startDate <= now && now <= endDate)
|
||||||
return var.path;
|
return var.path;
|
||||||
}
|
}
|
||||||
return m_defaultPath;
|
return m_defaultPath;
|
||||||
|
@ -52,9 +52,9 @@ class BasicCatPack : public CatPack {
|
|||||||
public:
|
public:
|
||||||
BasicCatPack(QString id, QString name) : m_id(id), m_name(name) {}
|
BasicCatPack(QString id, QString name) : m_id(id), m_name(name) {}
|
||||||
BasicCatPack(QString id) : BasicCatPack(id, id) {}
|
BasicCatPack(QString id) : BasicCatPack(id, id) {}
|
||||||
virtual QString id() { return m_id; }
|
virtual QString id() override { return m_id; }
|
||||||
virtual QString name() { return m_name; }
|
virtual QString name() override { return m_name; }
|
||||||
virtual QString path();
|
virtual QString path() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_id;
|
QString m_id;
|
||||||
@ -83,7 +83,8 @@ class JsonCatPack : public BasicCatPack {
|
|||||||
PartialDate endTime;
|
PartialDate endTime;
|
||||||
};
|
};
|
||||||
JsonCatPack(QFileInfo& manifestInfo);
|
JsonCatPack(QFileInfo& manifestInfo);
|
||||||
virtual QString path();
|
virtual QString path() override;
|
||||||
|
QString path(QDate now);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_defaultPath;
|
QString m_defaultPath;
|
||||||
|
@ -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
|
ecm_add_test(Version_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||||
TEST_NAME Version)
|
TEST_NAME Version)
|
||||||
|
|
||||||
|
ecm_add_test(CatPack_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||||
|
TEST_NAME CatPack)
|
||||||
|
40
tests/CatPack_test.cpp
Normal file
40
tests/CatPack_test.cpp
Normal file
@ -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"
|
50
tests/testdata/CatPacks/index.json
vendored
Normal file
50
tests/testdata/CatPacks/index.json
vendored
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user