Add flags to Entry::clone() for customized cloning.
This commit is contained in:
@@ -21,6 +21,12 @@
|
||||
|
||||
#include "tests.h"
|
||||
#include "core/Entry.h"
|
||||
#include "crypto/Crypto.h"
|
||||
|
||||
void TestEntry::initTestCase()
|
||||
{
|
||||
Crypto::init();
|
||||
}
|
||||
|
||||
void TestEntry::testHistoryItemDeletion()
|
||||
{
|
||||
@@ -74,4 +80,46 @@ void TestEntry::testCopyDataFrom()
|
||||
QCOMPARE(entry2->autoTypeAssociations()->get(1).window, QString("3"));
|
||||
}
|
||||
|
||||
void TestEntry::testClone()
|
||||
{
|
||||
Entry* entryOrg = new Entry();
|
||||
entryOrg->setUuid(Uuid::random());
|
||||
entryOrg->setTitle("Original Title");
|
||||
entryOrg->beginUpdate();
|
||||
entryOrg->setTitle("New Title");
|
||||
entryOrg->endUpdate();
|
||||
TimeInfo entryOrgTime = entryOrg->timeInfo();
|
||||
QDateTime dateTime;
|
||||
dateTime.setTimeSpec(Qt::UTC);
|
||||
dateTime.setMSecsSinceEpoch(60);
|
||||
entryOrgTime.setCreationTime(dateTime);
|
||||
entryOrg->setTimeInfo(entryOrgTime);
|
||||
|
||||
Entry* entryCloneNone = entryOrg->clone(Entry::CloneNoFlags);
|
||||
QCOMPARE(entryCloneNone->uuid(), entryOrg->uuid());
|
||||
QCOMPARE(entryCloneNone->title(), QString("New Title"));
|
||||
QCOMPARE(entryCloneNone->historyItems().size(), 0);
|
||||
QCOMPARE(entryCloneNone->timeInfo().creationTime(), entryOrg->timeInfo().creationTime());
|
||||
|
||||
Entry* entryCloneNewUuid = entryOrg->clone(Entry::CloneNewUuid);
|
||||
QVERIFY(entryCloneNewUuid->uuid() != entryOrg->uuid());
|
||||
QVERIFY(!entryCloneNewUuid->uuid().isNull());
|
||||
QCOMPARE(entryCloneNewUuid->title(), QString("New Title"));
|
||||
QCOMPARE(entryCloneNewUuid->historyItems().size(), 0);
|
||||
QCOMPARE(entryCloneNewUuid->timeInfo().creationTime(), entryOrg->timeInfo().creationTime());
|
||||
|
||||
Entry* entryCloneResetTime = entryOrg->clone(Entry::CloneResetTimeInfo);
|
||||
QCOMPARE(entryCloneNone->uuid(), entryOrg->uuid());
|
||||
QCOMPARE(entryCloneResetTime->title(), QString("New Title"));
|
||||
QCOMPARE(entryCloneResetTime->historyItems().size(), 0);
|
||||
QVERIFY(entryCloneResetTime->timeInfo().creationTime() != entryOrg->timeInfo().creationTime());
|
||||
|
||||
Entry* entryCloneHistory = entryOrg->clone(Entry::CloneIncludeHistory);
|
||||
QCOMPARE(entryCloneNone->uuid(), entryOrg->uuid());
|
||||
QCOMPARE(entryCloneHistory->title(), QString("New Title"));
|
||||
QCOMPARE(entryCloneHistory->historyItems().size(), 1);
|
||||
QCOMPARE(entryCloneHistory->historyItems().first()->title(), QString("Original Title"));
|
||||
QCOMPARE(entryCloneHistory->timeInfo().creationTime(), entryOrg->timeInfo().creationTime());
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestEntry)
|
||||
|
||||
@@ -27,8 +27,10 @@ class TestEntry : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void testHistoryItemDeletion();
|
||||
void testCopyDataFrom();
|
||||
void testClone();
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_TESTENTRY_H
|
||||
|
||||
@@ -441,8 +441,11 @@ void TestGroup::testClone()
|
||||
|
||||
Entry* originalGroupEntry = new Entry();
|
||||
originalGroupEntry->setGroup(originalGroup);
|
||||
originalGroupEntry->setTitle("GroupEntry");
|
||||
originalGroupEntry->setTitle("GroupEntryOld");
|
||||
originalGroupEntry->setIcon(43);
|
||||
originalGroupEntry->beginUpdate();
|
||||
originalGroupEntry->setTitle("GroupEntry");
|
||||
originalGroupEntry->endUpdate();
|
||||
|
||||
Group* subGroup = new Group();
|
||||
subGroup->setParent(originalGroup);
|
||||
@@ -465,6 +468,7 @@ void TestGroup::testClone()
|
||||
QVERIFY(clonedGroupEntry->uuid() != originalGroupEntry->uuid());
|
||||
QCOMPARE(clonedGroupEntry->title(), QString("GroupEntry"));
|
||||
QCOMPARE(clonedGroupEntry->iconNumber(), 43);
|
||||
QCOMPARE(clonedGroupEntry->historyItems().size(), 0);
|
||||
|
||||
Group* clonedSubGroup = clonedGroup->children().at(0);
|
||||
QVERIFY(clonedSubGroup->uuid() != subGroup->uuid());
|
||||
|
||||
Reference in New Issue
Block a user