diff --git a/tests/TestMerge.cpp b/tests/TestMerge.cpp index fc5c58b8a..a54a8e21f 100644 --- a/tests/TestMerge.cpp +++ b/tests/TestMerge.cpp @@ -119,15 +119,15 @@ void TestMerge::testResolveConflictNewer() createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries)); // sanity check - QPointer groupSourceInitial = dbSource->rootGroup()->findChildByName("group1"); + auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group1"); QVERIFY(groupSourceInitial != nullptr); QCOMPARE(groupSourceInitial->entries().size(), 2); - QPointer groupDestinationInitial = dbSource->rootGroup()->findChildByName("group1"); + auto groupDestinationInitial = dbSource->rootGroup()->findChildByName("group1"); QVERIFY(groupDestinationInitial != nullptr); QCOMPARE(groupDestinationInitial->entries().size(), 2); - QPointer entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entrySourceInitial != nullptr); QVERIFY(entrySourceInitial->group() == groupSourceInitial); @@ -156,12 +156,12 @@ void TestMerge::testResolveConflictNewer() merger.merge(); // sanity check - QPointer groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1"); + auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1"); QVERIFY(groupDestinationMerged != nullptr); QCOMPARE(groupDestinationMerged->entries().size(), 2); QCOMPARE(groupDestinationMerged->timeInfo(), groupDestinationInitialTimeInfo); - QPointer entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationMerged != nullptr); QVERIFY(entryDestinationMerged->group() != nullptr); QCOMPARE(entryDestinationMerged->password(), QString("password")); @@ -186,15 +186,15 @@ void TestMerge::testResolveConflictExisting() createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries)); // sanity check - QPointer groupSourceInitial = dbSource->rootGroup()->findChildByName("group1"); + auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group1"); QVERIFY(groupSourceInitial != nullptr); QCOMPARE(groupSourceInitial->entries().size(), 2); - QPointer groupDestinationInitial = dbDestination->rootGroup()->findChildByName("group1"); + auto groupDestinationInitial = dbDestination->rootGroup()->findChildByName("group1"); QVERIFY(groupDestinationInitial != nullptr); QCOMPARE(groupSourceInitial->entries().size(), 2); - QPointer entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entrySourceInitial != nullptr); QVERIFY(entrySourceInitial->group() == groupSourceInitial); @@ -212,10 +212,10 @@ void TestMerge::testResolveConflictExisting() const TimeInfo entrySourceUpdatedOlderTimeInfo = entrySourceInitial->timeInfo(); const TimeInfo groupSourceUpdatedOlderTimeInfo = groupSourceInitial->timeInfo(); - QPointer groupDestinationUpdated = dbDestination->rootGroup()->findChildByName("group1"); + auto groupDestinationUpdated = dbDestination->rootGroup()->findChildByName("group1"); QVERIFY(groupDestinationUpdated != nullptr); QCOMPARE(groupDestinationUpdated->entries().size(), 2); - QPointer entryDestinationUpdated = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationUpdated = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationUpdated != nullptr); QVERIFY(entryDestinationUpdated->group() == groupDestinationUpdated); @@ -241,12 +241,12 @@ void TestMerge::testResolveConflictExisting() merger.merge(); // sanity check - QPointer groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1"); + auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1"); QVERIFY(groupDestinationMerged != nullptr); QCOMPARE(groupDestinationMerged->entries().size(), 2); QCOMPARE(groupDestinationMerged->timeInfo(), groupDestinationUpdatedNewerTimeInfo); - QPointer entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationMerged != nullptr); QCOMPARE(entryDestinationMerged->password(), QString("password2")); QCOMPARE(entryDestinationMerged->timeInfo(), entryDestinationUpdatedNewerTimeInfo); @@ -271,7 +271,7 @@ void TestMerge::testResolveConflictDuplicate() QCOMPARE(dbDestination->rootGroup()->children().at(0)->entries().size(), 2); // make this entry newer than in original db - QPointer updatedDestinationEntry = dbDestination->rootGroup()->children().at(0)->entries().at(0); + auto updatedDestinationEntry = dbDestination->rootGroup()->children().at(0)->entries().at(0); const TimeInfo initialEntryTimeInfo = updatedDestinationEntry->timeInfo(); const TimeInfo updatedEntryTimeInfo = modificationTime(initialEntryTimeInfo, 1, 0, 0); @@ -289,8 +289,8 @@ void TestMerge::testResolveConflictDuplicate() QCOMPARE(dbDestination->rootGroup()->children().at(0)->entries().size(), 3); QCOMPARE(dbDestination->rootGroup()->children().at(0)->entries().at(0)->historyItems().isEmpty(), false); // the older entry was merged from the other db as last in the group - QPointer newerEntry = dbDestination->rootGroup()->children().at(0)->entries().at(0); - QPointer olderEntry = dbDestination->rootGroup()->children().at(0)->entries().at(2); + auto newerEntry = dbDestination->rootGroup()->children().at(0)->entries().at(0); + auto olderEntry = dbDestination->rootGroup()->children().at(0)->entries().at(2); QVERIFY(newerEntry->title() == olderEntry->title()); QVERIFY2(!newerEntry->attributes()->hasKey("merged"), "newer entry is not marked with an attribute \"merged\""); QVERIFY2(olderEntry->attributes()->hasKey("merged"), "older entry is marked with an attribute \"merged\""); @@ -304,9 +304,9 @@ void TestMerge::testResolveConflictDuplicate() void TestMerge::testResolveConflictTemplate( int mergeMode, - std::function&)> verification) + std::function&)> verification) { - QMap timestamps; + QMap timestamps; timestamps["initialTime"] = m_clock->currentDateTimeUtc(); QScopedPointer dbDestination(createTestDatabase()); @@ -340,10 +340,10 @@ void TestMerge::testResolveConflictTemplate( QCOMPARE(dbSource->rootGroup()->children().at(0)->entries().at(1)->historyItems().count(), 1); // simulate some work in the dbs (manipulate the history) - QPointer destinationEntry1 = dbDestination->rootGroup()->children().at(0)->entries().at(0); - QPointer destinationEntry2 = dbDestination->rootGroup()->children().at(0)->entries().at(1); - QPointer sourceEntry1 = dbSource->rootGroup()->children().at(0)->entries().at(0); - QPointer sourceEntry2 = dbSource->rootGroup()->children().at(0)->entries().at(1); + auto destinationEntry1 = dbDestination->rootGroup()->children().at(0)->entries().at(0); + auto destinationEntry2 = dbDestination->rootGroup()->children().at(0)->entries().at(1); + auto sourceEntry1 = dbSource->rootGroup()->children().at(0)->entries().at(0); + auto sourceEntry2 = dbSource->rootGroup()->children().at(0)->entries().at(1); timestamps["newestCommonHistoryTime"] = m_clock->advanceMinute(1); @@ -386,9 +386,9 @@ void TestMerge::testResolveConflictTemplate( m_clock->advanceMinute(1); - QPointer deletedEntryDestination = dbDestination->rootGroup()->findEntryByPath("deletedDestination"); + auto deletedEntryDestination = dbDestination->rootGroup()->findEntryByPath("deletedDestination"); dbDestination->recycleEntry(deletedEntryDestination); - QPointer deletedEntrySource = dbSource->rootGroup()->findEntryByPath("deletedSource"); + auto deletedEntrySource = dbSource->rootGroup()->findEntryByPath("deletedSource"); dbSource->recycleEntry(deletedEntrySource); m_clock->advanceMinute(1); @@ -417,13 +417,13 @@ void TestMerge::testResolveConflictTemplate( Merger merger(dbSource.data(), dbDestination.data()); merger.merge(); - QPointer mergedRootGroup = dbDestination->rootGroup(); + auto mergedRootGroup = dbDestination->rootGroup(); QCOMPARE(mergedRootGroup->entries().size(), 0); // Both databases contain their own generated recycleBin - just one is considered a real recycleBin, the other // exists as normal group, therefore only one entry is considered deleted QCOMPARE(dbDestination->metadata()->recycleBin()->entries().size(), 1); - QPointer mergedGroup1 = mergedRootGroup->children().at(0); - QPointer mergedGroup2 = mergedRootGroup->children().at(1); + auto mergedGroup1 = mergedRootGroup->children().at(0); + auto mergedGroup2 = mergedRootGroup->children().at(1); QVERIFY(mergedGroup1); QVERIFY(mergedGroup2); QCOMPARE(mergedGroup2->entries().size(), 2); @@ -454,7 +454,7 @@ void TestMerge::testDeletionConflictTemplate(int mergeMode, // entry indirectly deleted in target before updated in source // entry indirectly deleted in target after updated in source - auto createGroup = [&](const char* name, Group* parent) { + auto createGroup = [&](QString name, Group* parent) { auto group = new Group(); group->setUuid(QUuid::createUuid()); group->setName(name); @@ -462,7 +462,7 @@ void TestMerge::testDeletionConflictTemplate(int mergeMode, identifiers[group->name()] = group->uuid(); return group; }; - auto createEntry = [&](const char* title, Group* parent) { + auto createEntry = [&](QString title, Group* parent) { auto entry = new Entry(); entry->setUuid(QUuid::createUuid()); entry->setTitle(title); @@ -501,70 +501,70 @@ void TestMerge::testDeletionConflictTemplate(int mergeMode, QScopedPointer dbSource( createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneIncludeHistory, Group::CloneIncludeEntries)); - QPointer sourceEntryDeletedInSourceBeforeChangedInTarget = + auto sourceEntryDeletedInSourceBeforeChangedInTarget = dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeChangedInTarget"]); - QPointer targetEntryDeletedInSourceBeforeChangedInTarget = + auto targetEntryDeletedInSourceBeforeChangedInTarget = dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeChangedInTarget"]); - QPointer sourceEntryDeletedInSourceAfterChangedInTarget = + auto sourceEntryDeletedInSourceAfterChangedInTarget = dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceAfterChangedInTarget"]); - QPointer targetEntryDeletedInSourceAfterChangedInTarget = + auto targetEntryDeletedInSourceAfterChangedInTarget = dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceAfterChangedInTarget"]); - QPointer sourceEntryDeletedInTargetBeforeChangedInSource = + auto sourceEntryDeletedInTargetBeforeChangedInSource = dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetBeforeChangedInSource"]); - QPointer targetEntryDeletedInTargetBeforeChangedInSource = + auto targetEntryDeletedInTargetBeforeChangedInSource = dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetBeforeChangedInSource"]); - QPointer sourceEntryDeletedInTargetAfterChangedInSource = + auto sourceEntryDeletedInTargetAfterChangedInSource = dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetAfterChangedInSource"]); - QPointer targetEntryDeletedInTargetAfterChangedInSource = + auto targetEntryDeletedInTargetAfterChangedInSource = dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetAfterChangedInSource"]); - QPointer sourceGroupDeletedInSourceBeforeEntryUpdatedInTarget = + auto sourceGroupDeletedInSourceBeforeEntryUpdatedInTarget = dbSource->rootGroup()->findGroupByUuid(identifiers["GroupDeletedInSourceBeforeEntryUpdatedInTarget"]); - QPointer targetEntryDeletedInSourceBeforeEntryUpdatedInTarget = + auto targetEntryDeletedInSourceBeforeEntryUpdatedInTarget = dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeEntryUpdatedInTarget"]); - QPointer sourceGroupDeletedInSourceAfterEntryUpdatedInTarget = + auto sourceGroupDeletedInSourceAfterEntryUpdatedInTarget = dbSource->rootGroup()->findGroupByUuid(identifiers["GroupDeletedInSourceAfterEntryUpdatedInTarget"]); - QPointer targetEntryDeletedInSourceAfterEntryUpdatedInTarget = + auto targetEntryDeletedInSourceAfterEntryUpdatedInTarget = dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceAfterEntryUpdatedInTarget"]); - QPointer targetGroupDeletedInTargetBeforeEntryUpdatedInSource = + auto targetGroupDeletedInTargetBeforeEntryUpdatedInSource = dbDestination->rootGroup()->findGroupByUuid(identifiers["GroupDeletedInTargetBeforeEntryUpdatedInSource"]); - QPointer sourceEntryDeletedInTargetBeforeEntryUpdatedInSource = + auto sourceEntryDeletedInTargetBeforeEntryUpdatedInSource = dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetBeforeEntryUpdatedInSource"]); - QPointer targetGroupDeletedInTargetAfterEntryUpdatedInSource = + auto targetGroupDeletedInTargetAfterEntryUpdatedInSource = dbDestination->rootGroup()->findGroupByUuid(identifiers["GroupDeletedInTargetAfterEntryUpdatedInSource"]); - QPointer sourceEntryDeletedInTargetAfterEntryUpdatedInSoruce = + auto sourceEntryDeletedInTargetAfterEntryUpdatedInSoruce = dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetAfterEntryUpdatedInSource"]); // simulate some work in the dbs (manipulate the history) m_clock->advanceMinute(1); - delete sourceEntryDeletedInSourceBeforeChangedInTarget.data(); + delete sourceEntryDeletedInSourceBeforeChangedInTarget; changeEntry(targetEntryDeletedInSourceAfterChangedInTarget); - delete targetEntryDeletedInTargetBeforeChangedInSource.data(); + delete targetEntryDeletedInTargetBeforeChangedInSource; changeEntry(sourceEntryDeletedInTargetAfterChangedInSource); - delete sourceGroupDeletedInSourceBeforeEntryUpdatedInTarget.data(); + delete sourceGroupDeletedInSourceBeforeEntryUpdatedInTarget; changeEntry(targetEntryDeletedInSourceAfterEntryUpdatedInTarget); - delete targetGroupDeletedInTargetBeforeEntryUpdatedInSource.data(); + delete targetGroupDeletedInTargetBeforeEntryUpdatedInSource; changeEntry(sourceEntryDeletedInTargetAfterEntryUpdatedInSoruce); m_clock->advanceMinute(1); changeEntry(targetEntryDeletedInSourceBeforeChangedInTarget); - delete sourceEntryDeletedInSourceAfterChangedInTarget.data(); + delete sourceEntryDeletedInSourceAfterChangedInTarget; changeEntry(sourceEntryDeletedInTargetBeforeChangedInSource); - delete targetEntryDeletedInTargetAfterChangedInSource.data(); + delete targetEntryDeletedInTargetAfterChangedInSource; changeEntry(targetEntryDeletedInSourceBeforeEntryUpdatedInTarget); - delete sourceGroupDeletedInSourceAfterEntryUpdatedInTarget.data(); + delete sourceGroupDeletedInSourceAfterEntryUpdatedInTarget; changeEntry(sourceEntryDeletedInTargetBeforeEntryUpdatedInSource); - delete targetGroupDeletedInTargetAfterEntryUpdatedInSource.data(); + delete targetGroupDeletedInTargetAfterEntryUpdatedInSource; m_clock->advanceMinute(1); dbDestination->rootGroup()->setMergeMode(static_cast(mergeMode)); @@ -577,7 +577,7 @@ void TestMerge::testDeletionConflictTemplate(int mergeMode, void TestMerge::assertDeletionNewerOnly(Database* db, const QMap& identifiers) { - QPointer mergedRootGroup = db->rootGroup(); + auto mergedRootGroup = db->rootGroup(); // newer change in target prevents deletion QVERIFY(mergedRootGroup->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeChangedInTarget"])); QVERIFY(!db->containsDeletedObject(identifiers["EntryDeletedInSourceBeforeChangedInTarget"])); @@ -614,7 +614,7 @@ void TestMerge::assertDeletionNewerOnly(Database* db, const QMap void TestMerge::assertDeletionLocalOnly(Database* db, const QMap& identifiers) { - QPointer mergedRootGroup = db->rootGroup(); + auto mergedRootGroup = db->rootGroup(); QVERIFY(mergedRootGroup->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeChangedInTarget"])); QVERIFY(!db->containsDeletedObject(identifiers["EntryDeletedInSourceBeforeChangedInTarget"])); @@ -650,8 +650,9 @@ void TestMerge::assertDeletionLocalOnly(Database* db, const QMap QVERIFY(db->containsDeletedObject(identifiers["EntryDeletedInTargetAfterEntryUpdatedInSource"])); } -void TestMerge::assertUpdateMergedEntry1(Entry* mergedEntry1, const QMap& timestamps) +void TestMerge::assertUpdateMergedEntry1(Entry* mergedEntry1, const QMap& timestamps) { + auto initial = timestamps.keys(); QCOMPARE(mergedEntry1->historyItems().count(), 4); QCOMPARE(mergedEntry1->historyItems().at(0)->notes(), QString("")); QCOMPARE(mergedEntry1->historyItems().at(0)->timeInfo().lastModificationTime(), timestamps["initialTime"]); @@ -668,7 +669,7 @@ void TestMerge::assertUpdateMergedEntry1(Entry* mergedEntry1, const QMaptimeInfo().lastModificationTime(), timestamps["newestDivergingHistoryTime"]); } -void TestMerge::assertUpdateReappliedEntry2(Entry* mergedEntry2, const QMap& timestamps) +void TestMerge::assertUpdateReappliedEntry2(Entry* mergedEntry2, const QMap& timestamps) { QCOMPARE(mergedEntry2->historyItems().count(), 5); QCOMPARE(mergedEntry2->historyItems().at(0)->notes(), QString("")); @@ -689,7 +690,7 @@ void TestMerge::assertUpdateReappliedEntry2(Entry* mergedEntry2, const QMaptimeInfo().lastModificationTime(), timestamps["mergeTime"]); } -void TestMerge::assertUpdateReappliedEntry1(Entry* mergedEntry1, const QMap& timestamps) +void TestMerge::assertUpdateReappliedEntry1(Entry* mergedEntry1, const QMap& timestamps) { QCOMPARE(mergedEntry1->historyItems().count(), 5); QCOMPARE(mergedEntry1->historyItems().at(0)->notes(), QString("")); @@ -710,7 +711,7 @@ void TestMerge::assertUpdateReappliedEntry1(Entry* mergedEntry1, const QMaptimeInfo().lastModificationTime(), timestamps["mergeTime"]); } -void TestMerge::assertUpdateMergedEntry2(Entry* mergedEntry2, const QMap& timestamps) +void TestMerge::assertUpdateMergedEntry2(Entry* mergedEntry2, const QMap& timestamps) { QCOMPARE(mergedEntry2->historyItems().count(), 4); QCOMPARE(mergedEntry2->historyItems().at(0)->notes(), QString("")); @@ -758,9 +759,9 @@ void TestMerge::testDeletionConflictEntry_Duplicate() */ void TestMerge::testResolveConflictEntry_Synchronize() { - testResolveConflictTemplate(Group::Synchronize, [](Database* db, const QMap& timestamps) { - QPointer mergedRootGroup = db->rootGroup(); - QPointer mergedGroup1 = mergedRootGroup->children().at(0); + testResolveConflictTemplate(Group::Synchronize, [](Database* db, const QMap& timestamps) { + auto mergedRootGroup = db->rootGroup(); + auto mergedGroup1 = mergedRootGroup->children().at(0); TestMerge::assertUpdateMergedEntry1(mergedGroup1->entries().at(0), timestamps); TestMerge::assertUpdateMergedEntry2(mergedGroup1->entries().at(1), timestamps); }); @@ -771,9 +772,9 @@ void TestMerge::testResolveConflictEntry_Synchronize() */ void TestMerge::testResolveConflictEntry_KeepLocal() { - testResolveConflictTemplate(Group::KeepLocal, [](Database* db, const QMap& timestamps) { - QPointer mergedRootGroup = db->rootGroup(); - QPointer mergedGroup1 = mergedRootGroup->children().at(0); + testResolveConflictTemplate(Group::KeepLocal, [](Database* db, const QMap& timestamps) { + auto mergedRootGroup = db->rootGroup(); + auto mergedGroup1 = mergedRootGroup->children().at(0); TestMerge::assertUpdateMergedEntry1(mergedGroup1->entries().at(0), timestamps); TestMerge::assertUpdateReappliedEntry2(mergedGroup1->entries().at(1), timestamps); }); @@ -781,9 +782,9 @@ void TestMerge::testResolveConflictEntry_KeepLocal() void TestMerge::testResolveConflictEntry_KeepRemote() { - testResolveConflictTemplate(Group::KeepRemote, [](Database* db, const QMap& timestamps) { - QPointer mergedRootGroup = db->rootGroup(); - QPointer mergedGroup1 = mergedRootGroup->children().at(0); + testResolveConflictTemplate(Group::KeepRemote, [](Database* db, const QMap& timestamps) { + auto mergedRootGroup = db->rootGroup(); + auto mergedGroup1 = mergedRootGroup->children().at(0); TestMerge::assertUpdateReappliedEntry1(mergedGroup1->entries().at(0), timestamps); TestMerge::assertUpdateMergedEntry2(mergedGroup1->entries().at(1), timestamps); }); @@ -791,9 +792,9 @@ void TestMerge::testResolveConflictEntry_KeepRemote() void TestMerge::testResolveConflictEntry_KeepNewer() { - testResolveConflictTemplate(Group::KeepNewer, [](Database* db, const QMap& timestamps) { - QPointer mergedRootGroup = db->rootGroup(); - QPointer mergedGroup1 = mergedRootGroup->children().at(0); + testResolveConflictTemplate(Group::KeepNewer, [](Database* db, const QMap& timestamps) { + auto mergedRootGroup = db->rootGroup(); + auto mergedGroup1 = mergedRootGroup->children().at(0); TestMerge::assertUpdateMergedEntry1(mergedGroup1->entries().at(0), timestamps); TestMerge::assertUpdateMergedEntry2(mergedGroup1->entries().at(1), timestamps); }); @@ -809,10 +810,10 @@ void TestMerge::testMoveEntry() QScopedPointer dbSource( createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries)); - QPointer entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entrySourceInitial != nullptr); - QPointer groupSourceInitial = dbSource->rootGroup()->findChildByName("group2"); + auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group2"); QVERIFY(groupSourceInitial != nullptr); // Make sure the two changes have a different timestamp. @@ -826,7 +827,7 @@ void TestMerge::testMoveEntry() Merger merger(dbSource.data(), dbDestination.data()); merger.merge(); - QPointer entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationMerged != nullptr); QCOMPARE(entryDestinationMerged->group()->name(), QString("group2")); QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2); @@ -843,10 +844,10 @@ void TestMerge::testMoveEntryPreserveChanges() QScopedPointer dbSource( createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries)); - QPointer entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entrySourceInitial != nullptr); - QPointer group2Source = dbSource->rootGroup()->findChildByName("group2"); + auto group2Source = dbSource->rootGroup()->findChildByName("group2"); QVERIFY(group2Source != nullptr); m_clock->advanceSecond(1); @@ -854,7 +855,7 @@ void TestMerge::testMoveEntryPreserveChanges() entrySourceInitial->setGroup(group2Source); QCOMPARE(entrySourceInitial->group()->name(), QString("group2")); - QPointer entryDestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationInitial != nullptr); m_clock->advanceSecond(1); @@ -868,7 +869,7 @@ void TestMerge::testMoveEntryPreserveChanges() Merger merger(dbSource.data(), dbDestination.data()); merger.merge(); - QPointer entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationMerged != nullptr); QCOMPARE(entryDestinationMerged->group()->name(), QString("group2")); QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2); @@ -893,7 +894,7 @@ void TestMerge::testCreateNewGroups() Merger merger(dbSource.data(), dbDestination.data()); merger.merge(); - QPointer groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group3"); + auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group3"); QVERIFY(groupDestinationMerged != nullptr); QCOMPARE(groupDestinationMerged->name(), QString("group3")); } @@ -911,7 +912,7 @@ void TestMerge::testMoveEntryIntoNewGroup() groupSourceCreated->setUuid(QUuid::createUuid()); groupSourceCreated->setParent(dbSource->rootGroup()); - QPointer entrySourceMoved = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entrySourceMoved = dbSource->rootGroup()->findEntryByPath("entry1"); entrySourceMoved->setGroup(groupSourceCreated); m_clock->advanceSecond(1); @@ -921,12 +922,12 @@ void TestMerge::testMoveEntryIntoNewGroup() QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2); - QPointer groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group3"); + auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group3"); QVERIFY(groupDestinationMerged != nullptr); QCOMPARE(groupDestinationMerged->name(), QString("group3")); QCOMPARE(groupDestinationMerged->entries().size(), 1); - QPointer entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationMerged != nullptr); QCOMPARE(entryDestinationMerged->group()->name(), QString("group3")); } @@ -948,7 +949,7 @@ void TestMerge::testUpdateEntryDifferentLocation() m_clock->advanceSecond(1); - QPointer entryDestinationMoved = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationMoved = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationMoved != nullptr); entryDestinationMoved->setGroup(groupDestinationCreated); QUuid uuidBeforeSyncing = entryDestinationMoved->uuid(); @@ -957,7 +958,7 @@ void TestMerge::testUpdateEntryDifferentLocation() // Change the entry in the source db. m_clock->advanceSecond(1); - QPointer entrySourceMoved = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entrySourceMoved = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entrySourceMoved != nullptr); entrySourceMoved->beginUpdate(); entrySourceMoved->setUsername("username"); @@ -973,7 +974,7 @@ void TestMerge::testUpdateEntryDifferentLocation() QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2); - QPointer entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entryDestinationMerged != nullptr); QVERIFY(entryDestinationMerged->group() != nullptr); QCOMPARE(entryDestinationMerged->username(), QString("username")); @@ -994,14 +995,14 @@ void TestMerge::testUpdateGroup() m_clock->advanceSecond(1); - QPointer groupSourceInitial = dbSource->rootGroup()->findChildByName("group2"); + auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group2"); groupSourceInitial->setName("group2 renamed"); groupSourceInitial->setNotes("updated notes"); QUuid customIconId = QUuid::createUuid(); dbSource->metadata()->addCustomIcon(customIconId, QString("custom icon").toLocal8Bit()); groupSourceInitial->setIcon(customIconId); - QPointer entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entrySourceInitial != nullptr); entrySourceInitial->setGroup(groupSourceInitial); entrySourceInitial->setTitle("entry1 renamed"); @@ -1014,13 +1015,13 @@ void TestMerge::testUpdateGroup() QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2); - QPointer entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1 renamed"); + auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1 renamed"); QVERIFY(entryDestinationMerged != nullptr); QVERIFY(entryDestinationMerged->group() != nullptr); QCOMPARE(entryDestinationMerged->group()->name(), QString("group2 renamed")); QCOMPARE(uuidBeforeSyncing, entryDestinationMerged->uuid()); - QPointer groupMerged = dbDestination->rootGroup()->findChildByName("group2 renamed"); + auto groupMerged = dbDestination->rootGroup()->findChildByName("group2 renamed"); QCOMPARE(groupMerged->notes(), QString("updated notes")); QCOMPARE(groupMerged->iconUuid(), customIconId); } @@ -1038,14 +1039,14 @@ void TestMerge::testUpdateGroupLocation() createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries)); // Sanity check - QPointer group3SourceInitial = dbSource->rootGroup()->findGroupByUuid(group3Uuid); + auto group3SourceInitial = dbSource->rootGroup()->findGroupByUuid(group3Uuid); QVERIFY(group3DestinationCreated != nullptr); QDateTime initialLocationChanged = group3SourceInitial->timeInfo().locationChanged(); m_clock->advanceSecond(1); - QPointer group3SourceMoved = dbSource->rootGroup()->findGroupByUuid(group3Uuid); + auto group3SourceMoved = dbSource->rootGroup()->findGroupByUuid(group3Uuid); QVERIFY(group3SourceMoved != nullptr); group3SourceMoved->setParent(dbSource->rootGroup()->findChildByName("group2")); @@ -1057,7 +1058,7 @@ void TestMerge::testUpdateGroupLocation() Merger merger1(dbSource.data(), dbDestination.data()); merger1.merge(); - QPointer group3DestinationMerged1 = dbDestination->rootGroup()->findGroupByUuid(group3Uuid); + auto group3DestinationMerged1 = dbDestination->rootGroup()->findGroupByUuid(group3Uuid); QVERIFY(group3DestinationMerged1 != nullptr); QCOMPARE(group3DestinationMerged1->parent(), dbDestination->rootGroup()->findChildByName("group2")); QCOMPARE(group3DestinationMerged1->timeInfo().locationChanged(), movedLocaltionChanged); @@ -1067,7 +1068,7 @@ void TestMerge::testUpdateGroupLocation() Merger merger2(dbSource.data(), dbDestination.data()); merger2.merge(); - QPointer group3DestinationMerged2 = dbDestination->rootGroup()->findGroupByUuid(group3Uuid); + auto group3DestinationMerged2 = dbDestination->rootGroup()->findGroupByUuid(group3Uuid); QVERIFY(group3DestinationMerged2 != nullptr); QCOMPARE(group3DestinationMerged2->parent(), dbDestination->rootGroup()->findChildByName("group2")); QCOMPARE(group3DestinationMerged1->timeInfo().locationChanged(), movedLocaltionChanged); @@ -1244,7 +1245,7 @@ void TestMerge::testDeletedEntry() m_clock->advanceSecond(1); - QPointer entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entry1SourceInitial != nullptr); QUuid entry1Uuid = entry1SourceInitial->uuid(); delete entry1SourceInitial; @@ -1252,7 +1253,7 @@ void TestMerge::testDeletedEntry() m_clock->advanceSecond(1); - QPointer entry2DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry2"); + auto entry2DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry2"); QVERIFY(entry2DestinationInitial != nullptr); QUuid entry2Uuid = entry2DestinationInitial->uuid(); delete entry2DestinationInitial; @@ -1263,10 +1264,10 @@ void TestMerge::testDeletedEntry() Merger merger(dbSource.data(), dbDestination.data()); merger.merge(); - QPointer entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entry1DestinationMerged); QVERIFY(!dbDestination->containsDeletedObject(entry1Uuid)); - QPointer entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2"); + auto entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2"); QVERIFY(entry2DestinationMerged); // Uuid in db and deletedObjects is intended according to KeePass #1752 QVERIFY(dbDestination->containsDeletedObject(entry2Uuid)); @@ -1282,7 +1283,7 @@ void TestMerge::testDeletedGroup() m_clock->advanceSecond(1); - QPointer group2DestinationInitial = dbDestination->rootGroup()->findChildByName("group2"); + auto group2DestinationInitial = dbDestination->rootGroup()->findChildByName("group2"); QVERIFY(group2DestinationInitial != nullptr); auto entry3DestinationCreated = new Entry(); entry3DestinationCreated->beginUpdate(); @@ -1293,11 +1294,11 @@ void TestMerge::testDeletedGroup() m_clock->advanceSecond(1); - QPointer group1SourceInitial = dbSource->rootGroup()->findChildByName("group1"); + auto group1SourceInitial = dbSource->rootGroup()->findChildByName("group1"); QVERIFY(group1SourceInitial != nullptr); - QPointer entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entry1SourceInitial != nullptr); - QPointer entry2SourceInitial = dbSource->rootGroup()->findEntryByPath("entry2"); + auto entry2SourceInitial = dbSource->rootGroup()->findEntryByPath("entry2"); QVERIFY(entry2SourceInitial != nullptr); QUuid group1Uuid = group1SourceInitial->uuid(); QUuid entry1Uuid = entry1SourceInitial->uuid(); @@ -1309,7 +1310,7 @@ void TestMerge::testDeletedGroup() m_clock->advanceSecond(1); - QPointer group2SourceInitial = dbSource->rootGroup()->findChildByName("group2"); + auto group2SourceInitial = dbSource->rootGroup()->findChildByName("group2"); QVERIFY(group2SourceInitial != nullptr); QUuid group2Uuid = group2SourceInitial->uuid(); delete group2SourceInitial; @@ -1325,15 +1326,15 @@ void TestMerge::testDeletedGroup() QVERIFY(!dbDestination->containsDeletedObject(entry2Uuid)); QVERIFY(!dbDestination->containsDeletedObject(group2Uuid)); - QPointer entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entry1DestinationMerged); - QPointer entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2"); + auto entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2"); QVERIFY(entry2DestinationMerged); - QPointer entry3DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry3"); + auto entry3DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry3"); QVERIFY(entry3DestinationMerged); - QPointer group1DestinationMerged = dbDestination->rootGroup()->findChildByName("group1"); + auto group1DestinationMerged = dbDestination->rootGroup()->findChildByName("group1"); QVERIFY(group1DestinationMerged); - QPointer group2DestinationMerged = dbDestination->rootGroup()->findChildByName("group2"); + auto group2DestinationMerged = dbDestination->rootGroup()->findChildByName("group2"); QVERIFY(group2DestinationMerged); QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 3); @@ -1347,7 +1348,7 @@ void TestMerge::testDeletedRevertedEntry() m_clock->advanceSecond(1); - QPointer entry1DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entry1DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entry1DestinationInitial != nullptr); QUuid entry1Uuid = entry1DestinationInitial->uuid(); delete entry1DestinationInitial; @@ -1355,7 +1356,7 @@ void TestMerge::testDeletedRevertedEntry() m_clock->advanceSecond(1); - QPointer entry2SourceInitial = dbSource->rootGroup()->findEntryByPath("entry2"); + auto entry2SourceInitial = dbSource->rootGroup()->findEntryByPath("entry2"); QVERIFY(entry2SourceInitial != nullptr); QUuid entry2Uuid = entry2SourceInitial->uuid(); delete entry2SourceInitial; @@ -1363,11 +1364,11 @@ void TestMerge::testDeletedRevertedEntry() m_clock->advanceSecond(1); - QPointer entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); + auto entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1"); QVERIFY(entry1SourceInitial != nullptr); entry1SourceInitial->setNotes("Updated"); - QPointer entry2DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry2"); + auto entry2DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry2"); QVERIFY(entry2DestinationInitial != nullptr); entry2DestinationInitial->setNotes("Updated"); @@ -1378,10 +1379,10 @@ void TestMerge::testDeletedRevertedEntry() QVERIFY(dbDestination->containsDeletedObject(entry1Uuid)); QVERIFY(!dbDestination->containsDeletedObject(entry2Uuid)); - QPointer entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); + auto entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1"); QVERIFY(entry1DestinationMerged); QVERIFY(entry1DestinationMerged->notes() == "Updated"); - QPointer entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2"); + auto entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2"); QVERIFY(entry2DestinationMerged); QVERIFY(entry2DestinationMerged->notes() == "Updated"); } @@ -1394,7 +1395,7 @@ void TestMerge::testDeletedRevertedGroup() m_clock->advanceSecond(1); - QPointer group2SourceInitial = dbSource->rootGroup()->findChildByName("group2"); + auto group2SourceInitial = dbSource->rootGroup()->findChildByName("group2"); QVERIFY(group2SourceInitial); QUuid group2Uuid = group2SourceInitial->uuid(); delete group2SourceInitial; @@ -1402,7 +1403,7 @@ void TestMerge::testDeletedRevertedGroup() m_clock->advanceSecond(1); - QPointer group1DestinationInitial = dbDestination->rootGroup()->findChildByName("group1"); + auto group1DestinationInitial = dbDestination->rootGroup()->findChildByName("group1"); QVERIFY(group1DestinationInitial); QUuid group1Uuid = group1DestinationInitial->uuid(); delete group1DestinationInitial; @@ -1410,13 +1411,13 @@ void TestMerge::testDeletedRevertedGroup() m_clock->advanceSecond(1); - QPointer group1SourceInitial = dbSource->rootGroup()->findChildByName("group1"); + auto group1SourceInitial = dbSource->rootGroup()->findChildByName("group1"); QVERIFY(group1SourceInitial); group1SourceInitial->setNotes("Updated"); m_clock->advanceSecond(1); - QPointer group2DestinationInitial = dbDestination->rootGroup()->findChildByName("group2"); + auto group2DestinationInitial = dbDestination->rootGroup()->findChildByName("group2"); QVERIFY(group2DestinationInitial); group2DestinationInitial->setNotes("Updated"); @@ -1429,10 +1430,10 @@ void TestMerge::testDeletedRevertedGroup() QVERIFY(dbDestination->containsDeletedObject(group1Uuid)); QVERIFY(!dbDestination->containsDeletedObject(group2Uuid)); - QPointer group1DestinationMerged = dbDestination->rootGroup()->findChildByName("group1"); + auto group1DestinationMerged = dbDestination->rootGroup()->findChildByName("group1"); QVERIFY(group1DestinationMerged); QVERIFY(group1DestinationMerged->notes() == "Updated"); - QPointer group2DestinationMerged = dbDestination->rootGroup()->findChildByName("group2"); + auto group2DestinationMerged = dbDestination->rootGroup()->findChildByName("group2"); QVERIFY(group2DestinationMerged); QVERIFY(group2DestinationMerged->notes() == "Updated"); } @@ -1449,7 +1450,7 @@ void TestMerge::testResolveGroupConflictOlder() createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries)); // sanity check - QPointer groupSourceInitial = dbSource->rootGroup()->findChildByName("group1"); + auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group1"); QVERIFY(groupSourceInitial != nullptr); // Make sure the two changes have a different timestamp. @@ -1460,7 +1461,7 @@ void TestMerge::testResolveGroupConflictOlder() // Make sure the two changes have a different timestamp. m_clock->advanceSecond(1); - QPointer groupDestinationUpdated = dbDestination->rootGroup()->findChildByName("group1"); + auto groupDestinationUpdated = dbDestination->rootGroup()->findChildByName("group1"); groupDestinationUpdated->setName("group1 updated in destination"); m_clock->advanceSecond(1); @@ -1469,7 +1470,7 @@ void TestMerge::testResolveGroupConflictOlder() merger.merge(); // sanity check - QPointer groupDestinationMerged = + auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1 updated in destination"); QVERIFY(groupDestinationMerged != nullptr); } diff --git a/tests/TestMerge.h b/tests/TestMerge.h index cb17ac8fb..34d95f728 100644 --- a/tests/TestMerge.h +++ b/tests/TestMerge.h @@ -66,15 +66,15 @@ private: Database* createTestDatabase(); Database* createTestDatabaseStructureClone(Database* source, int entryFlags, int groupFlags); void testResolveConflictTemplate(int mergeMode, - std::function&)> verification); + std::function&)> verification); void testDeletionConflictTemplate(int mergeMode, std::function&)> verification); static void assertDeletionNewerOnly(Database* db, const QMap& identifiers); static void assertDeletionLocalOnly(Database* db, const QMap& identifiers); - static void assertUpdateMergedEntry1(Entry* entry, const QMap& timestamps); - static void assertUpdateReappliedEntry2(Entry* entry, const QMap& timestamps); - static void assertUpdateReappliedEntry1(Entry* entry, const QMap& timestamps); - static void assertUpdateMergedEntry2(Entry* entry, const QMap& timestamps); + static void assertUpdateMergedEntry1(Entry* entry, const QMap& timestamps); + static void assertUpdateReappliedEntry2(Entry* entry, const QMap& timestamps); + static void assertUpdateReappliedEntry1(Entry* entry, const QMap& timestamps); + static void assertUpdateMergedEntry2(Entry* entry, const QMap& timestamps); }; #endif // KEEPASSX_TESTMERGE_H diff --git a/tests/gui/TestGuiBrowser.cpp b/tests/gui/TestGuiBrowser.cpp index 075d49dc9..2be058073 100644 --- a/tests/gui/TestGuiBrowser.cpp +++ b/tests/gui/TestGuiBrowser.cpp @@ -70,6 +70,10 @@ void TestGuiBrowser::initTestCase() config()->set(Config::GUI_AdvancedSettings, false); // Disable the update check first time alert config()->set(Config::UpdateCheckMessageShown, true); + // Disable quick unlock + config()->set(Config::Security_QuickUnlock, false); + // Disable showing expired entries on unlock + config()->set(Config::GUI_ShowExpiredEntriesOnDatabaseUnlock, false); m_mainWindow.reset(new MainWindow()); m_tabWidget = m_mainWindow->findChild("tabWidget");