Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/TestEntry.cpp')
-rw-r--r--tests/TestEntry.cpp57
1 files changed, 54 insertions, 3 deletions
diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp
index c174e798d..39e4bd12c 100644
--- a/tests/TestEntry.cpp
+++ b/tests/TestEntry.cpp
@@ -21,6 +21,7 @@
#include "TestEntry.h"
#include "TestGlobal.h"
#include "core/Clock.h"
+#include "core/Metadata.h"
#include "crypto/Crypto.h"
QTEST_GUILESS_MAIN(TestEntry)
@@ -106,18 +107,43 @@ void TestEntry::testClone()
QCOMPARE(entryCloneNewUuid->historyItems().size(), 0);
QCOMPARE(entryCloneNewUuid->timeInfo().creationTime(), entryOrg->timeInfo().creationTime());
+ // Reset modification time
+ entryOrgTime.setLastModificationTime(Clock::datetimeUtc(60));
+ entryOrg->setTimeInfo(entryOrgTime);
+
+ QScopedPointer<Entry> entryCloneRename(entryOrg->clone(Entry::CloneRenameTitle));
+ QCOMPARE(entryCloneRename->uuid(), entryOrg->uuid());
+ QCOMPARE(entryCloneRename->title(), QString("New Title - Clone"));
+ // Cloning should not modify time info unless explicity requested
+ QCOMPARE(entryCloneRename->timeInfo(), entryOrg->timeInfo());
+
QScopedPointer<Entry> entryCloneResetTime(entryOrg->clone(Entry::CloneResetTimeInfo));
QCOMPARE(entryCloneResetTime->uuid(), entryOrg->uuid());
QCOMPARE(entryCloneResetTime->title(), QString("New Title"));
QCOMPARE(entryCloneResetTime->historyItems().size(), 0);
QVERIFY(entryCloneResetTime->timeInfo().creationTime() != entryOrg->timeInfo().creationTime());
- QScopedPointer<Entry> entryCloneHistory(entryOrg->clone(Entry::CloneIncludeHistory));
+ // Date back history of original entry
+ Entry* firstHistoryItem = entryOrg->historyItems()[0];
+ TimeInfo entryOrgHistoryTimeInfo = firstHistoryItem->timeInfo();
+ QDateTime datedBackEntryOrgModificationTime = entryOrgHistoryTimeInfo.lastModificationTime().addMSecs(-10);
+ entryOrgHistoryTimeInfo.setLastModificationTime(datedBackEntryOrgModificationTime);
+ entryOrgHistoryTimeInfo.setCreationTime(datedBackEntryOrgModificationTime);
+ firstHistoryItem->setTimeInfo(entryOrgHistoryTimeInfo);
+
+ QScopedPointer<Entry> entryCloneHistory(entryOrg->clone(Entry::CloneIncludeHistory | Entry::CloneResetTimeInfo));
QCOMPARE(entryCloneHistory->uuid(), entryOrg->uuid());
QCOMPARE(entryCloneHistory->title(), QString("New Title"));
- QCOMPARE(entryCloneHistory->historyItems().size(), 1);
+ QCOMPARE(entryCloneHistory->historyItems().size(), entryOrg->historyItems().size());
QCOMPARE(entryCloneHistory->historyItems().at(0)->title(), QString("Original Title"));
- QCOMPARE(entryCloneHistory->timeInfo().creationTime(), entryOrg->timeInfo().creationTime());
+ QVERIFY(entryCloneHistory->timeInfo().creationTime() != entryOrg->timeInfo().creationTime());
+ // Timeinfo of history items should not be modified
+ QList<Entry*> entryOrgHistory = entryOrg->historyItems(), clonedHistory = entryCloneHistory->historyItems();
+ auto entryOrgHistoryItem = entryOrgHistory.constBegin();
+ for (auto entryCloneHistoryItem = clonedHistory.constBegin(); entryCloneHistoryItem != clonedHistory.constEnd();
+ ++entryCloneHistoryItem, ++entryOrgHistoryItem) {
+ QCOMPARE((*entryOrgHistoryItem)->timeInfo(), (*entryCloneHistoryItem)->timeInfo());
+ }
Database db;
auto* entryOrgClone = entryOrg->clone(Entry::CloneNoFlags);
@@ -561,3 +587,28 @@ void TestEntry::testResolveClonedEntry()
QCOMPARE(cclone4->resolveMultiplePlaceholders(cclone4->username()), original->username());
QCOMPARE(cclone4->resolveMultiplePlaceholders(cclone4->password()), original->password());
}
+
+void TestEntry::testIsRecycled()
+{
+ Entry* entry = new Entry();
+ QVERIFY(!entry->isRecycled());
+
+ Database db;
+ Group* root = db.rootGroup();
+ QVERIFY(root);
+ entry->setGroup(root);
+ QVERIFY(!entry->isRecycled());
+
+ QVERIFY(db.metadata()->recycleBinEnabled());
+ db.recycleEntry(entry);
+ QVERIFY(entry->isRecycled());
+
+ Group* group1 = new Group();
+ group1->setParent(root);
+
+ Entry* entry1 = new Entry();
+ entry1->setGroup(group1);
+ QVERIFY(!entry1->isRecycled());
+ db.recycleGroup(group1);
+ QVERIFY(entry1->isRecycled());
+}