Mock datetime to avoid test failures on second lapse (#13115)
Some checks are pending
CodeQL / Analyze (push) Waiting to run

Fixes #13059
This commit is contained in:
Janek Bevendorff 2026-03-08 22:26:10 +01:00 committed by GitHub
parent cc309ff813
commit 5c91c9986a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View file

@ -218,7 +218,7 @@ add_unit_test(NAME testdatabase SOURCES TestDatabase.cpp
LIBS testsupport ${TEST_LIBRARIES})
add_unit_test(NAME testtools SOURCES TestTools.cpp
LIBS ${TEST_LIBRARIES})
LIBS testsupport ${TEST_LIBRARIES})
add_unit_test(NAME testconfig SOURCES TestConfig.cpp
LIBS testsupport ${TEST_LIBRARIES})

View file

@ -19,6 +19,7 @@
#include "core/Clock.h"
#include "core/Tools.h"
#include "mock/MockClock.h"
#include <QFileInfo>
#include <QRegularExpression>
@ -33,8 +34,23 @@ namespace
{
return wholes + QLocale().decimalPoint() + fractions + " " + unit;
}
MockClock* s_clock = nullptr;
} // namespace
void TestTools::initTestCase()
{
Q_ASSERT(s_clock == nullptr);
s_clock = new MockClock(2026, 3, 8, 21, 45, 05);
MockClock::setup(s_clock);
}
void TestTools::cleanupTestCase()
{
MockClock::teardown();
s_clock = nullptr;
}
void TestTools::testHumanReadableFileSize()
{
constexpr auto kibibyte = 1024u;

View file

@ -24,6 +24,8 @@ class TestTools : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void testHumanReadableFileSize();
void testIsHex();
void testIsBase64();