mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-02 14:46:07 -04:00
Adding support for listing a group. (#652)
* Adding support for listing a group. * added findGroupByPath * Removing useless asserts. * Code review.
This commit is contained in:
parent
9d6cf95cf0
commit
48ea024d7e
5 changed files with 133 additions and 6 deletions
|
@ -599,6 +599,15 @@ void TestGroup::testFindEntry()
|
|||
QVERIFY(entry != nullptr);
|
||||
QCOMPARE(entry->title(), QString("entry1"));
|
||||
|
||||
// We also can find the entry with the leading slash.
|
||||
entry = db->rootGroup()->findEntry(QString("/entry1"));
|
||||
QVERIFY(entry != nullptr);
|
||||
QCOMPARE(entry->title(), QString("entry1"));
|
||||
|
||||
// But two slashes should not be accepted.
|
||||
entry = db->rootGroup()->findEntry(QString("//entry1"));
|
||||
QVERIFY(entry == nullptr);
|
||||
|
||||
entry = db->rootGroup()->findEntry(entry2->uuid().toHex());
|
||||
QVERIFY(entry != nullptr);
|
||||
QCOMPARE(entry->title(), QString("entry2"));
|
||||
|
@ -607,6 +616,14 @@ void TestGroup::testFindEntry()
|
|||
QVERIFY(entry != nullptr);
|
||||
QCOMPARE(entry->title(), QString("entry2"));
|
||||
|
||||
entry = db->rootGroup()->findEntry(QString("/entry2"));
|
||||
QVERIFY(entry == nullptr);
|
||||
|
||||
// We also can find the entry with the leading slash.
|
||||
entry = db->rootGroup()->findEntry(QString("/group1/entry2"));
|
||||
QVERIFY(entry != nullptr);
|
||||
QCOMPARE(entry->title(), QString("entry2"));
|
||||
|
||||
// Should also find the entry only by title.
|
||||
entry = db->rootGroup()->findEntry(QString("entry2"));
|
||||
QVERIFY(entry != nullptr);
|
||||
|
@ -629,6 +646,70 @@ void TestGroup::testFindEntry()
|
|||
delete db;
|
||||
}
|
||||
|
||||
void TestGroup::testFindGroupByPath()
|
||||
{
|
||||
Database* db = new Database();
|
||||
|
||||
Group* group1 = new Group();
|
||||
group1->setName("group1");
|
||||
group1->setParent(db->rootGroup());
|
||||
|
||||
Group* group2 = new Group();
|
||||
group2->setName("group2");
|
||||
group2->setParent(group1);
|
||||
|
||||
Group* group;
|
||||
|
||||
group = db->rootGroup()->findGroupByPath("/");
|
||||
QVERIFY(group != nullptr);
|
||||
QCOMPARE(group->uuid(), db->rootGroup()->uuid());
|
||||
|
||||
// We also accept it if the leading slash is missing.
|
||||
group = db->rootGroup()->findGroupByPath("");
|
||||
QVERIFY(group != nullptr);
|
||||
QCOMPARE(group->uuid(), db->rootGroup()->uuid());
|
||||
|
||||
group = db->rootGroup()->findGroupByPath("/group1/");
|
||||
QVERIFY(group != nullptr);
|
||||
QCOMPARE(group->uuid(), group1->uuid());
|
||||
|
||||
// We also accept it if the leading slash is missing.
|
||||
group = db->rootGroup()->findGroupByPath("group1/");
|
||||
QVERIFY(group != nullptr);
|
||||
QCOMPARE(group->uuid(), group1->uuid());
|
||||
|
||||
// Too many slashes at the end
|
||||
group = db->rootGroup()->findGroupByPath("group1//");
|
||||
QVERIFY(group == nullptr);
|
||||
|
||||
// Missing a slash at the end.
|
||||
group = db->rootGroup()->findGroupByPath("/group1");
|
||||
QVERIFY(group != nullptr);
|
||||
QCOMPARE(group->uuid(), group1->uuid());
|
||||
|
||||
// Too many slashes at the start
|
||||
group = db->rootGroup()->findGroupByPath("//group1");
|
||||
QVERIFY(group == nullptr);
|
||||
|
||||
group = db->rootGroup()->findGroupByPath("/group1/group2/");
|
||||
QVERIFY(group != nullptr);
|
||||
QCOMPARE(group->uuid(), group2->uuid());
|
||||
|
||||
// We also accept it if the leading slash is missing.
|
||||
group = db->rootGroup()->findGroupByPath("group1/group2/");
|
||||
QVERIFY(group != nullptr);
|
||||
QCOMPARE(group->uuid(), group2->uuid());
|
||||
|
||||
group = db->rootGroup()->findGroupByPath("group1/group2");
|
||||
QVERIFY(group != nullptr);
|
||||
QCOMPARE(group->uuid(), group2->uuid());
|
||||
|
||||
group = db->rootGroup()->findGroupByPath("invalid");
|
||||
QVERIFY(group == nullptr);
|
||||
|
||||
delete db;
|
||||
}
|
||||
|
||||
void TestGroup::testPrint()
|
||||
{
|
||||
Database* db = new Database();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue