mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-23 22:39:43 -05:00
Rename TestClock to MockClock and move it to the mock directory
This commit is contained in:
parent
108e4efc8a
commit
bea31f9bcc
@ -95,7 +95,7 @@ set(TEST_LIBRARIES
|
||||
${ZLIB_LIBRARIES}
|
||||
)
|
||||
|
||||
set(testsupport_SOURCES TestGlobal.h modeltest.cpp FailDevice.cpp stub/TestClock.cpp util/TemporaryFile.cpp)
|
||||
set(testsupport_SOURCES TestGlobal.h modeltest.cpp FailDevice.cpp mock/MockClock.cpp util/TemporaryFile.cpp)
|
||||
add_library(testsupport STATIC ${testsupport_SOURCES})
|
||||
target_link_libraries(testsupport Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test)
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include "TestGroup.h"
|
||||
#include "TestGlobal.h"
|
||||
#include "stub/TestClock.h"
|
||||
#include "mock/MockClock.h"
|
||||
|
||||
#include <QSignalSpy>
|
||||
|
||||
@ -29,7 +29,7 @@ QTEST_GUILESS_MAIN(TestGroup)
|
||||
|
||||
namespace
|
||||
{
|
||||
TestClock* m_clock = nullptr;
|
||||
MockClock* m_clock = nullptr;
|
||||
}
|
||||
|
||||
void TestGroup::initTestCase()
|
||||
@ -42,13 +42,13 @@ void TestGroup::initTestCase()
|
||||
void TestGroup::init()
|
||||
{
|
||||
Q_ASSERT(m_clock == nullptr);
|
||||
m_clock = new TestClock(2010, 5, 5, 10, 30, 10);
|
||||
TestClock::setup(m_clock);
|
||||
m_clock = new MockClock(2010, 5, 5, 10, 30, 10);
|
||||
MockClock::setup(m_clock);
|
||||
}
|
||||
|
||||
void TestGroup::cleanup()
|
||||
{
|
||||
TestClock::teardown();
|
||||
MockClock::teardown();
|
||||
m_clock = nullptr;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include "TestKeePass2Format.h"
|
||||
#include "TestGlobal.h"
|
||||
#include "stub/TestClock.h"
|
||||
#include "mock/MockClock.h"
|
||||
|
||||
#include "core/Metadata.h"
|
||||
#include "crypto/Crypto.h"
|
||||
@ -78,14 +78,14 @@ void TestKeePass2Format::testXmlMetadata()
|
||||
{
|
||||
QCOMPARE(m_xmlDb->metadata()->generator(), QString("KeePass"));
|
||||
QCOMPARE(m_xmlDb->metadata()->name(), QString("ANAME"));
|
||||
QCOMPARE(m_xmlDb->metadata()->nameChanged(), TestClock::datetimeUtc(2010, 8, 8, 17, 24, 53));
|
||||
QCOMPARE(m_xmlDb->metadata()->nameChanged(), MockClock::datetimeUtc(2010, 8, 8, 17, 24, 53));
|
||||
QCOMPARE(m_xmlDb->metadata()->description(), QString("ADESC"));
|
||||
QCOMPARE(m_xmlDb->metadata()->descriptionChanged(), TestClock::datetimeUtc(2010, 8, 8, 17, 27, 12));
|
||||
QCOMPARE(m_xmlDb->metadata()->descriptionChanged(), MockClock::datetimeUtc(2010, 8, 8, 17, 27, 12));
|
||||
QCOMPARE(m_xmlDb->metadata()->defaultUserName(), QString("DEFUSERNAME"));
|
||||
QCOMPARE(m_xmlDb->metadata()->defaultUserNameChanged(), TestClock::datetimeUtc(2010, 8, 8, 17, 27, 45));
|
||||
QCOMPARE(m_xmlDb->metadata()->defaultUserNameChanged(), MockClock::datetimeUtc(2010, 8, 8, 17, 27, 45));
|
||||
QCOMPARE(m_xmlDb->metadata()->maintenanceHistoryDays(), 127);
|
||||
QCOMPARE(m_xmlDb->metadata()->color(), QColor(0xff, 0xef, 0x00));
|
||||
QCOMPARE(m_xmlDb->metadata()->masterKeyChanged(), TestClock::datetimeUtc(2012, 4, 5, 17, 9, 34));
|
||||
QCOMPARE(m_xmlDb->metadata()->masterKeyChanged(), MockClock::datetimeUtc(2012, 4, 5, 17, 9, 34));
|
||||
QCOMPARE(m_xmlDb->metadata()->masterKeyChangeRec(), 101);
|
||||
QCOMPARE(m_xmlDb->metadata()->masterKeyChangeForce(), -1);
|
||||
QCOMPARE(m_xmlDb->metadata()->protectTitle(), false);
|
||||
@ -96,9 +96,9 @@ void TestKeePass2Format::testXmlMetadata()
|
||||
QCOMPARE(m_xmlDb->metadata()->recycleBinEnabled(), true);
|
||||
QVERIFY(m_xmlDb->metadata()->recycleBin() != nullptr);
|
||||
QCOMPARE(m_xmlDb->metadata()->recycleBin()->name(), QString("Recycle Bin"));
|
||||
QCOMPARE(m_xmlDb->metadata()->recycleBinChanged(), TestClock::datetimeUtc(2010, 8, 25, 16, 12, 57));
|
||||
QCOMPARE(m_xmlDb->metadata()->recycleBinChanged(), MockClock::datetimeUtc(2010, 8, 25, 16, 12, 57));
|
||||
QVERIFY(m_xmlDb->metadata()->entryTemplatesGroup() == nullptr);
|
||||
QCOMPARE(m_xmlDb->metadata()->entryTemplatesGroupChanged(), TestClock::datetimeUtc(2010, 8, 8, 17, 24, 19));
|
||||
QCOMPARE(m_xmlDb->metadata()->entryTemplatesGroupChanged(), MockClock::datetimeUtc(2010, 8, 8, 17, 24, 19));
|
||||
QVERIFY(m_xmlDb->metadata()->lastSelectedGroup() != nullptr);
|
||||
QCOMPARE(m_xmlDb->metadata()->lastSelectedGroup()->name(), QString("NewDatabase"));
|
||||
QVERIFY(m_xmlDb->metadata()->lastTopVisibleGroup() == m_xmlDb->metadata()->lastSelectedGroup());
|
||||
@ -136,13 +136,13 @@ void TestKeePass2Format::testXmlGroupRoot()
|
||||
QCOMPARE(group->iconUuid(), QUuid());
|
||||
QVERIFY(group->isExpanded());
|
||||
TimeInfo ti = group->timeInfo();
|
||||
QCOMPARE(ti.lastModificationTime(), TestClock::datetimeUtc(2010, 8, 8, 17, 24, 27));
|
||||
QCOMPARE(ti.creationTime(), TestClock::datetimeUtc(2010, 8, 7, 17, 24, 27));
|
||||
QCOMPARE(ti.lastAccessTime(), TestClock::datetimeUtc(2010, 8, 9, 9, 9, 44));
|
||||
QCOMPARE(ti.expiryTime(), TestClock::datetimeUtc(2010, 8, 8, 17, 24, 17));
|
||||
QCOMPARE(ti.lastModificationTime(), MockClock::datetimeUtc(2010, 8, 8, 17, 24, 27));
|
||||
QCOMPARE(ti.creationTime(), MockClock::datetimeUtc(2010, 8, 7, 17, 24, 27));
|
||||
QCOMPARE(ti.lastAccessTime(), MockClock::datetimeUtc(2010, 8, 9, 9, 9, 44));
|
||||
QCOMPARE(ti.expiryTime(), MockClock::datetimeUtc(2010, 8, 8, 17, 24, 17));
|
||||
QVERIFY(!ti.expires());
|
||||
QCOMPARE(ti.usageCount(), 52);
|
||||
QCOMPARE(ti.locationChanged(), TestClock::datetimeUtc(2010, 8, 8, 17, 24, 27));
|
||||
QCOMPARE(ti.locationChanged(), MockClock::datetimeUtc(2010, 8, 8, 17, 24, 27));
|
||||
QCOMPARE(group->defaultAutoTypeSequence(), QString(""));
|
||||
QCOMPARE(group->autoTypeEnabled(), Group::Inherit);
|
||||
QCOMPARE(group->searchingEnabled(), Group::Inherit);
|
||||
@ -203,13 +203,13 @@ void TestKeePass2Format::testXmlEntry1()
|
||||
QCOMPARE(entry->tags(), QString("a b c"));
|
||||
|
||||
const TimeInfo ti = entry->timeInfo();
|
||||
QCOMPARE(ti.lastModificationTime(), TestClock::datetimeUtc(2010, 8, 25, 16, 19, 25));
|
||||
QCOMPARE(ti.creationTime(), TestClock::datetimeUtc(2010, 8, 25, 16, 13, 54));
|
||||
QCOMPARE(ti.lastAccessTime(), TestClock::datetimeUtc(2010, 8, 25, 16, 19, 25));
|
||||
QCOMPARE(ti.expiryTime(), TestClock::datetimeUtc(2010, 8, 25, 16, 12, 57));
|
||||
QCOMPARE(ti.lastModificationTime(), MockClock::datetimeUtc(2010, 8, 25, 16, 19, 25));
|
||||
QCOMPARE(ti.creationTime(), MockClock::datetimeUtc(2010, 8, 25, 16, 13, 54));
|
||||
QCOMPARE(ti.lastAccessTime(), MockClock::datetimeUtc(2010, 8, 25, 16, 19, 25));
|
||||
QCOMPARE(ti.expiryTime(), MockClock::datetimeUtc(2010, 8, 25, 16, 12, 57));
|
||||
QVERIFY(!ti.expires());
|
||||
QCOMPARE(ti.usageCount(), 8);
|
||||
QCOMPARE(ti.locationChanged(), TestClock::datetimeUtc(2010, 8, 25, 16, 13, 54));
|
||||
QCOMPARE(ti.locationChanged(), MockClock::datetimeUtc(2010, 8, 25, 16, 13, 54));
|
||||
|
||||
QList<QString> attrs = entry->attributes()->keys();
|
||||
QCOMPARE(entry->attributes()->value("Notes"), QString("Notes"));
|
||||
@ -308,7 +308,7 @@ void TestKeePass2Format::testXmlEntryHistory()
|
||||
const Entry* entry = entryMain->historyItems().at(0);
|
||||
QCOMPARE(entry->uuid(), entryMain->uuid());
|
||||
QVERIFY(!entry->parent());
|
||||
QCOMPARE(entry->timeInfo().lastModificationTime(), TestClock::datetimeUtc(2010, 8, 25, 16, 13, 54));
|
||||
QCOMPARE(entry->timeInfo().lastModificationTime(), MockClock::datetimeUtc(2010, 8, 25, 16, 13, 54));
|
||||
QCOMPARE(entry->timeInfo().usageCount(), 3);
|
||||
QCOMPARE(entry->title(), QString("Sample Entry"));
|
||||
QCOMPARE(entry->url(), QString("http://www.somesite.com/"));
|
||||
@ -318,7 +318,7 @@ void TestKeePass2Format::testXmlEntryHistory()
|
||||
const Entry* entry = entryMain->historyItems().at(1);
|
||||
QCOMPARE(entry->uuid(), entryMain->uuid());
|
||||
QVERIFY(!entry->parent());
|
||||
QCOMPARE(entry->timeInfo().lastModificationTime(), TestClock::datetimeUtc(2010, 8, 25, 16, 15, 43));
|
||||
QCOMPARE(entry->timeInfo().lastModificationTime(), MockClock::datetimeUtc(2010, 8, 25, 16, 15, 43));
|
||||
QCOMPARE(entry->timeInfo().usageCount(), 7);
|
||||
QCOMPARE(entry->title(), QString("Sample Entry 1"));
|
||||
QCOMPARE(entry->url(), QString("http://www.somesite.com/"));
|
||||
@ -332,11 +332,11 @@ void TestKeePass2Format::testXmlDeletedObjects()
|
||||
|
||||
delObj = objList.takeFirst();
|
||||
QCOMPARE(delObj.uuid, QUuid::fromRfc4122(QByteArray::fromBase64("5K/bzWCSmkCv5OZxYl4N/w==")));
|
||||
QCOMPARE(delObj.deletionTime, TestClock::datetimeUtc(2010, 8, 25, 16, 14, 12));
|
||||
QCOMPARE(delObj.deletionTime, MockClock::datetimeUtc(2010, 8, 25, 16, 14, 12));
|
||||
|
||||
delObj = objList.takeFirst();
|
||||
QCOMPARE(delObj.uuid, QUuid::fromRfc4122(QByteArray::fromBase64("80h8uSNWgkKhKCp1TgXF7g==")));
|
||||
QCOMPARE(delObj.deletionTime, TestClock::datetimeUtc(2010, 8, 25, 16, 14, 14));
|
||||
QCOMPARE(delObj.deletionTime, MockClock::datetimeUtc(2010, 8, 25, 16, 14, 14));
|
||||
|
||||
QVERIFY(objList.isEmpty());
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include "TestMerge.h"
|
||||
#include "TestGlobal.h"
|
||||
#include "stub/TestClock.h"
|
||||
#include "mock/MockClock.h"
|
||||
|
||||
#include "core/Merger.h"
|
||||
#include "core/Metadata.h"
|
||||
@ -34,7 +34,7 @@ namespace
|
||||
return timeInfo;
|
||||
}
|
||||
|
||||
TestClock* m_clock = nullptr;
|
||||
MockClock* m_clock = nullptr;
|
||||
}
|
||||
|
||||
void TestMerge::initTestCase()
|
||||
@ -47,13 +47,13 @@ void TestMerge::initTestCase()
|
||||
void TestMerge::init()
|
||||
{
|
||||
Q_ASSERT(m_clock == nullptr);
|
||||
m_clock = new TestClock(2010, 5, 5, 10, 30, 10);
|
||||
TestClock::setup(m_clock);
|
||||
m_clock = new MockClock(2010, 5, 5, 10, 30, 10);
|
||||
MockClock::setup(m_clock);
|
||||
}
|
||||
|
||||
void TestMerge::cleanup()
|
||||
{
|
||||
TestClock::teardown();
|
||||
MockClock::teardown();
|
||||
m_clock = nullptr;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
#include "TestModified.h"
|
||||
#include "stub/TestClock.h"
|
||||
#include "mock/MockClock.h"
|
||||
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
@ -31,7 +31,7 @@ QTEST_GUILESS_MAIN(TestModified)
|
||||
|
||||
namespace
|
||||
{
|
||||
TestClock* m_clock = nullptr;
|
||||
MockClock* m_clock = nullptr;
|
||||
}
|
||||
|
||||
void TestModified::initTestCase()
|
||||
@ -42,13 +42,13 @@ void TestModified::initTestCase()
|
||||
void TestModified::init()
|
||||
{
|
||||
Q_ASSERT(m_clock == nullptr);
|
||||
m_clock = new TestClock(2010, 5, 5, 10, 30, 10);
|
||||
TestClock::setup(m_clock);
|
||||
m_clock = new MockClock(2010, 5, 5, 10, 30, 10);
|
||||
MockClock::setup(m_clock);
|
||||
}
|
||||
|
||||
void TestModified::cleanup()
|
||||
{
|
||||
TestClock::teardown();
|
||||
MockClock::teardown();
|
||||
m_clock = nullptr;
|
||||
}
|
||||
|
||||
|
@ -15,72 +15,72 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TestClock.h"
|
||||
#include "MockClock.h"
|
||||
|
||||
TestClock::TestClock(int year, int month, int day, int hour, int min, int second)
|
||||
MockClock::MockClock(int year, int month, int day, int hour, int min, int second)
|
||||
: Clock()
|
||||
, m_utcCurrent(datetimeUtc(year, month, day, hour, min, second))
|
||||
{
|
||||
}
|
||||
|
||||
TestClock::TestClock(QDateTime utcBase)
|
||||
MockClock::MockClock(QDateTime utcBase)
|
||||
: Clock()
|
||||
, m_utcCurrent(utcBase)
|
||||
{
|
||||
}
|
||||
|
||||
const QDateTime& TestClock::advanceSecond(int seconds)
|
||||
const QDateTime& MockClock::advanceSecond(int seconds)
|
||||
{
|
||||
m_utcCurrent = m_utcCurrent.addSecs(seconds);
|
||||
return m_utcCurrent;
|
||||
}
|
||||
|
||||
const QDateTime& TestClock::advanceMinute(int minutes)
|
||||
const QDateTime& MockClock::advanceMinute(int minutes)
|
||||
{
|
||||
m_utcCurrent = m_utcCurrent.addSecs(minutes * 60);
|
||||
return m_utcCurrent;
|
||||
}
|
||||
|
||||
const QDateTime& TestClock::advanceHour(int hours)
|
||||
const QDateTime& MockClock::advanceHour(int hours)
|
||||
{
|
||||
m_utcCurrent = m_utcCurrent.addSecs(hours * 60 * 60);
|
||||
return m_utcCurrent;
|
||||
}
|
||||
|
||||
const QDateTime& TestClock::advanceDay(int days)
|
||||
const QDateTime& MockClock::advanceDay(int days)
|
||||
{
|
||||
m_utcCurrent = m_utcCurrent.addDays(days);
|
||||
return m_utcCurrent;
|
||||
}
|
||||
|
||||
const QDateTime& TestClock::advanceMonth(int months)
|
||||
const QDateTime& MockClock::advanceMonth(int months)
|
||||
{
|
||||
m_utcCurrent = m_utcCurrent.addMonths(months);
|
||||
return m_utcCurrent;
|
||||
}
|
||||
|
||||
const QDateTime& TestClock::advanceYear(int years)
|
||||
const QDateTime& MockClock::advanceYear(int years)
|
||||
{
|
||||
m_utcCurrent = m_utcCurrent.addYears(years);
|
||||
return m_utcCurrent;
|
||||
}
|
||||
|
||||
void TestClock::setup(Clock* clock)
|
||||
void MockClock::setup(Clock* clock)
|
||||
{
|
||||
Clock::setInstance(clock);
|
||||
}
|
||||
|
||||
void TestClock::teardown()
|
||||
void MockClock::teardown()
|
||||
{
|
||||
Clock::resetInstance();
|
||||
}
|
||||
|
||||
QDateTime TestClock::currentDateTimeUtcImpl() const
|
||||
QDateTime MockClock::currentDateTimeUtcImpl() const
|
||||
{
|
||||
return m_utcCurrent;
|
||||
}
|
||||
|
||||
QDateTime TestClock::currentDateTimeImpl() const
|
||||
QDateTime MockClock::currentDateTimeImpl() const
|
||||
{
|
||||
return m_utcCurrent.toLocalTime();
|
||||
}
|
@ -22,12 +22,12 @@
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
class TestClock : public Clock
|
||||
class MockClock : public Clock
|
||||
{
|
||||
public:
|
||||
TestClock(int year, int month, int day, int hour, int min, int second);
|
||||
MockClock(int year, int month, int day, int hour, int min, int second);
|
||||
|
||||
TestClock(QDateTime utcBase = QDateTime::currentDateTimeUtc());
|
||||
MockClock(QDateTime utcBase = QDateTime::currentDateTimeUtc());
|
||||
|
||||
const QDateTime& advanceSecond(int seconds);
|
||||
const QDateTime& advanceMinute(int minutes);
|
Loading…
Reference in New Issue
Block a user