Skip to content

Commit b0f90f3

Browse files
Copilotdroidmonkey
andcommitted
Enhance cross-database reference test with comprehensive coverage
Co-authored-by: droidmonkey <[email protected]>
1 parent b60b242 commit b0f90f3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/TestEntry.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ void TestEntry::testCrossDatabaseReferences()
691691
originalEntry->setUsername("OriginalUsername");
692692
originalEntry->setPassword("OriginalPassword");
693693
originalEntry->setUrl("http://original.com");
694+
originalEntry->setNotes("OriginalNotes");
694695

695696
// Create entry with references to original entry in database 1
696697
auto* refEntry = new Entry();
@@ -700,12 +701,26 @@ void TestEntry::testCrossDatabaseReferences()
700701
refEntry->setUsername(QString("{REF:U@I:%1}").arg(originalEntry->uuidToHex()));
701702
refEntry->setPassword(QString("{REF:P@I:%1}").arg(originalEntry->uuidToHex()));
702703
refEntry->setUrl(QString("{REF:A@I:%1}").arg(originalEntry->uuidToHex()));
704+
refEntry->setNotes(QString("{REF:N@I:%1}").arg(originalEntry->uuidToHex()));
705+
706+
// Add custom attribute with reference
707+
refEntry->attributes()->set("CustomRef", QString("{REF:T@I:%1}").arg(originalEntry->uuidToHex()));
703708

704709
// Verify references work within same database
705710
QCOMPARE(refEntry->resolveMultiplePlaceholders(refEntry->title()), QString("OriginalTitle"));
706711
QCOMPARE(refEntry->resolveMultiplePlaceholders(refEntry->username()), QString("OriginalUsername"));
707712
QCOMPARE(refEntry->resolveMultiplePlaceholders(refEntry->password()), QString("OriginalPassword"));
708713
QCOMPARE(refEntry->resolveMultiplePlaceholders(refEntry->url()), QString("http://original.com"));
714+
QCOMPARE(refEntry->resolveMultiplePlaceholders(refEntry->notes()), QString("OriginalNotes"));
715+
QCOMPARE(refEntry->resolveMultiplePlaceholders(refEntry->attributes()->value("CustomRef")), QString("OriginalTitle"));
716+
717+
// Verify the attributes still contain references (not yet resolved)
718+
QVERIFY(refEntry->attributes()->isReference(EntryAttributes::TitleKey));
719+
QVERIFY(refEntry->attributes()->isReference(EntryAttributes::UserNameKey));
720+
QVERIFY(refEntry->attributes()->isReference(EntryAttributes::PasswordKey));
721+
QVERIFY(refEntry->attributes()->isReference(EntryAttributes::URLKey));
722+
QVERIFY(refEntry->attributes()->isReference(EntryAttributes::NotesKey));
723+
QVERIFY(refEntry->attributes()->isReference("CustomRef"));
709724

710725
// Move the referenced entry to database 2
711726
// This should resolve the references before the move
@@ -716,12 +731,26 @@ void TestEntry::testCrossDatabaseReferences()
716731
QCOMPARE(refEntry->username(), QString("OriginalUsername"));
717732
QCOMPARE(refEntry->password(), QString("OriginalPassword"));
718733
QCOMPARE(refEntry->url(), QString("http://original.com"));
734+
QCOMPARE(refEntry->notes(), QString("OriginalNotes"));
735+
QCOMPARE(refEntry->attributes()->value("CustomRef"), QString("OriginalTitle"));
719736

720737
// Verify that the references have been replaced with actual values
721738
QVERIFY(!refEntry->attributes()->isReference(EntryAttributes::TitleKey));
722739
QVERIFY(!refEntry->attributes()->isReference(EntryAttributes::UserNameKey));
723740
QVERIFY(!refEntry->attributes()->isReference(EntryAttributes::PasswordKey));
724741
QVERIFY(!refEntry->attributes()->isReference(EntryAttributes::URLKey));
742+
QVERIFY(!refEntry->attributes()->isReference(EntryAttributes::NotesKey));
743+
QVERIFY(!refEntry->attributes()->isReference("CustomRef"));
744+
745+
// Test case where original entry doesn't exist (should keep the reference string)
746+
auto* orphanEntry = new Entry();
747+
orphanEntry->setGroup(root1);
748+
orphanEntry->setUuid(QUuid::createUuid());
749+
orphanEntry->setTitle("{REF:T@I:NONEXISTENTUUID}");
750+
751+
// Move orphan entry - the unresolvable reference should remain unchanged
752+
orphanEntry->setGroup(root2);
753+
QCOMPARE(orphanEntry->title(), QString("{REF:T@I:NONEXISTENTUUID}"));
725754
}
726755

727756
void TestEntry::testIsRecycled()

0 commit comments

Comments
 (0)