diff options
author | Jonathan White <droidmonkey@users.noreply.github.com> | 2018-10-30 15:42:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 15:42:35 +0300 |
commit | fa687f246ea056338c2d2b5c736aebc8af99474f (patch) | |
tree | 8f44c0f4ef202b3ec1be4e78e2217f4f93f22a41 /tests/TestGroup.cpp | |
parent | 7263dcddfe52552747c478da941f1f078d8d91e0 (diff) |
Fix issues with group functions (#2410)
Diffstat (limited to 'tests/TestGroup.cpp')
-rw-r--r-- | tests/TestGroup.cpp | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 9ee9389c0..7abb808d1 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -493,57 +493,64 @@ void TestGroup::testFindEntry() Entry* entry; - entry = db->rootGroup()->findEntry(entry1->uuidToHex()); - QVERIFY(entry != nullptr); + entry = db->rootGroup()->findEntryByUuid(entry1->uuid()); + QVERIFY(entry); QCOMPARE(entry->title(), QString("entry1")); - entry = db->rootGroup()->findEntry(QString("entry1")); - QVERIFY(entry != nullptr); + entry = db->rootGroup()->findEntryByPath(QString("entry1")); + QVERIFY(entry); QCOMPARE(entry->title(), QString("entry1")); // We also can find the entry with the leading slash. - entry = db->rootGroup()->findEntry(QString("/entry1")); - QVERIFY(entry != nullptr); + entry = db->rootGroup()->findEntryByPath(QString("/entry1")); + QVERIFY(entry); QCOMPARE(entry->title(), QString("entry1")); // But two slashes should not be accepted. - entry = db->rootGroup()->findEntry(QString("//entry1")); - QVERIFY(entry == nullptr); + entry = db->rootGroup()->findEntryByPath(QString("//entry1")); + QVERIFY(!entry); - entry = db->rootGroup()->findEntry(entry2->uuidToHex()); - QVERIFY(entry != nullptr); + entry = db->rootGroup()->findEntryByUuid(entry2->uuid()); + QVERIFY(entry); QCOMPARE(entry->title(), QString("entry2")); - entry = db->rootGroup()->findEntry(QString("group1/entry2")); - QVERIFY(entry != nullptr); + entry = db->rootGroup()->findEntryByPath(QString("group1/entry2")); + QVERIFY(entry); QCOMPARE(entry->title(), QString("entry2")); - entry = db->rootGroup()->findEntry(QString("/entry2")); - QVERIFY(entry == nullptr); + entry = db->rootGroup()->findEntryByPath(QString("/entry2")); + QVERIFY(!entry); // We also can find the entry with the leading slash. - entry = db->rootGroup()->findEntry(QString("/group1/entry2")); - QVERIFY(entry != nullptr); + entry = db->rootGroup()->findEntryByPath(QString("/group1/entry2")); + QVERIFY(entry); QCOMPARE(entry->title(), QString("entry2")); // Should also find the entry only by title. - entry = db->rootGroup()->findEntry(QString("entry2")); - QVERIFY(entry != nullptr); + entry = db->rootGroup()->findEntryByPath(QString("entry2")); + QVERIFY(entry); QCOMPARE(entry->title(), QString("entry2")); - entry = db->rootGroup()->findEntry(QString("invalid/path/to/entry2")); - QVERIFY(entry == nullptr); + entry = db->rootGroup()->findEntryByPath(QString("invalid/path/to/entry2")); + QVERIFY(!entry); - entry = db->rootGroup()->findEntry(QString("entry27")); - QVERIFY(entry == nullptr); + entry = db->rootGroup()->findEntryByPath(QString("entry27")); + QVERIFY(!entry); // A valid UUID that does not exist in this database. - entry = db->rootGroup()->findEntry(QString("febfb01ebcdf9dbd90a3f1579dc75281")); - QVERIFY(entry == nullptr); + entry = db->rootGroup()->findEntryByUuid(QUuid("febfb01ebcdf9dbd90a3f1579dc75281")); + QVERIFY(!entry); // An invalid UUID. - entry = db->rootGroup()->findEntry(QString("febfb01ebcdf9dbd90a3f1579dc")); - QVERIFY(entry == nullptr); + entry = db->rootGroup()->findEntryByUuid(QUuid("febfb01ebcdf9dbd90a3f1579dc")); + QVERIFY(!entry); + + // Empty strings + entry = db->rootGroup()->findEntryByUuid({}); + QVERIFY(!entry); + + entry = db->rootGroup()->findEntryByPath({}); + QVERIFY(!entry); } void TestGroup::testFindGroupByPath() @@ -561,51 +568,51 @@ void TestGroup::testFindGroupByPath() Group* group; group = db->rootGroup()->findGroupByPath("/"); - QVERIFY(group != nullptr); + QVERIFY(group); QCOMPARE(group->uuid(), db->rootGroup()->uuid()); // We also accept it if the leading slash is missing. group = db->rootGroup()->findGroupByPath(""); - QVERIFY(group != nullptr); + QVERIFY(group); QCOMPARE(group->uuid(), db->rootGroup()->uuid()); group = db->rootGroup()->findGroupByPath("/group1/"); - QVERIFY(group != nullptr); + QVERIFY(group); QCOMPARE(group->uuid(), group1->uuid()); // We also accept it if the leading slash is missing. group = db->rootGroup()->findGroupByPath("group1/"); - QVERIFY(group != nullptr); + QVERIFY(group); QCOMPARE(group->uuid(), group1->uuid()); // Too many slashes at the end group = db->rootGroup()->findGroupByPath("group1//"); - QVERIFY(group == nullptr); + QVERIFY(!group); // Missing a slash at the end. group = db->rootGroup()->findGroupByPath("/group1"); - QVERIFY(group != nullptr); + QVERIFY(group); QCOMPARE(group->uuid(), group1->uuid()); // Too many slashes at the start group = db->rootGroup()->findGroupByPath("//group1"); - QVERIFY(group == nullptr); + QVERIFY(!group); group = db->rootGroup()->findGroupByPath("/group1/group2/"); - QVERIFY(group != nullptr); + QVERIFY(group); QCOMPARE(group->uuid(), group2->uuid()); // We also accept it if the leading slash is missing. group = db->rootGroup()->findGroupByPath("group1/group2/"); - QVERIFY(group != nullptr); + QVERIFY(group); QCOMPARE(group->uuid(), group2->uuid()); group = db->rootGroup()->findGroupByPath("group1/group2"); - QVERIFY(group != nullptr); + QVERIFY(group); QCOMPARE(group->uuid(), group2->uuid()); group = db->rootGroup()->findGroupByPath("invalid"); - QVERIFY(group == nullptr); + QVERIFY(!group); } void TestGroup::testPrint() @@ -697,7 +704,7 @@ void TestGroup::testLocate() QVERIFY(results.contains("/entry1")); results = db->rootGroup()->locate("invalid"); - QVERIFY(results.size() == 0); + QVERIFY(results.isEmpty()); results = db->rootGroup()->locate("google"); QVERIFY(results.size() == 1); @@ -725,37 +732,37 @@ void TestGroup::testAddEntryWithPath() group2->setParent(group1); Entry* entry = db->rootGroup()->addEntryWithPath("entry1"); - QVERIFY(entry != nullptr); + QVERIFY(entry); QVERIFY(!entry->uuid().isNull()); entry = db->rootGroup()->addEntryWithPath("entry1"); - QVERIFY(entry == nullptr); + QVERIFY(!entry); entry = db->rootGroup()->addEntryWithPath("/entry1"); - QVERIFY(entry == nullptr); + QVERIFY(!entry); entry = db->rootGroup()->addEntryWithPath("entry2"); - QVERIFY(entry != nullptr); + QVERIFY(entry); QVERIFY(entry->title() == "entry2"); QVERIFY(!entry->uuid().isNull()); entry = db->rootGroup()->addEntryWithPath("/entry3"); - QVERIFY(entry != nullptr); + QVERIFY(entry); QVERIFY(entry->title() == "entry3"); QVERIFY(!entry->uuid().isNull()); entry = db->rootGroup()->addEntryWithPath("/group1/entry4"); - QVERIFY(entry != nullptr); + QVERIFY(entry); QVERIFY(entry->title() == "entry4"); QVERIFY(!entry->uuid().isNull()); entry = db->rootGroup()->addEntryWithPath("/group1/group2/entry5"); - QVERIFY(entry != nullptr); + QVERIFY(entry); QVERIFY(entry->title() == "entry5"); QVERIFY(!entry->uuid().isNull()); entry = db->rootGroup()->addEntryWithPath("/group1/invalid_group/entry6"); - QVERIFY(entry == nullptr); + QVERIFY(!entry); delete db; } |