diff options
author | louib <louib@users.noreply.github.com> | 2017-06-22 00:34:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-22 00:34:49 +0300 |
commit | 48ea024d7e1846beadfca557fa8f5a367c3a126f (patch) | |
tree | 6585aaabb24c663b6ee2439825207a7399bf6dfd /tests/TestGroup.cpp | |
parent | 9d6cf95cf08795fe030c7d4d283e5513b8104d65 (diff) |
Adding support for listing a group. (#652)
* Adding support for listing a group.
* added findGroupByPath
* Removing useless asserts.
* Code review.
Diffstat (limited to 'tests/TestGroup.cpp')
-rw-r--r-- | tests/TestGroup.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index d2a8465bf..50997dcca 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -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(); |