From 4f60df029d28f7e6f89d2b17405e878be03c307e Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Fri, 16 May 2014 00:26:09 +0200 Subject: [PATCH] Refactor TestEntrySearcher. --- tests/TestEntrySearcher.cpp | 66 ++++++++++++++++--------------------- tests/TestEntrySearcher.h | 7 ++-- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/tests/TestEntrySearcher.cpp b/tests/TestEntrySearcher.cpp index 564d71a77..fec2a4ae2 100644 --- a/tests/TestEntrySearcher.cpp +++ b/tests/TestEntrySearcher.cpp @@ -20,19 +20,18 @@ #include #include "tests.h" -#include "core/EntrySearcher.h" -#include "core/Group.h" + QTEST_GUILESS_MAIN(TestEntrySearcher) void TestEntrySearcher::initTestCase() { - groupRoot = new Group(); + m_groupRoot = new Group(); } void TestEntrySearcher::cleanupTestCase() { - delete groupRoot; + delete m_groupRoot; } void TestEntrySearcher::testSearch() @@ -41,9 +40,9 @@ void TestEntrySearcher::testSearch() Group* group2 = new Group(); Group* group3 = new Group(); - group1->setParent(groupRoot); - group2->setParent(groupRoot); - group3->setParent(groupRoot); + group1->setParent(m_groupRoot); + group2->setParent(m_groupRoot); + group3->setParent(m_groupRoot); Group* group11 = new Group(); @@ -62,11 +61,11 @@ void TestEntrySearcher::testSearch() Entry* eRoot = new Entry(); eRoot->setNotes("test search term test"); - eRoot->setGroup(groupRoot); + eRoot->setGroup(m_groupRoot); Entry* eRoot2 = new Entry(); eRoot2->setNotes("test term test"); - eRoot2->setGroup(groupRoot); + eRoot2->setGroup(m_groupRoot); Entry* e1 = new Entry(); e1->setNotes("test search term test"); @@ -92,22 +91,18 @@ void TestEntrySearcher::testSearch() e3b->setNotes("test search test"); e3b->setGroup(group3); - QList searchResult; + m_searchResult = m_entrySearcher.search("search term", m_groupRoot, Qt::CaseInsensitive); - EntrySearcher entrySearcher; + QCOMPARE(m_searchResult.count(), 3); - searchResult = entrySearcher.search("search term", groupRoot, Qt::CaseInsensitive); + m_searchResult = m_entrySearcher.search("search term", group211, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 1); - QCOMPARE(searchResult.count(), 3); + m_searchResult = m_entrySearcher.search("search term", group11, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 1); - searchResult = entrySearcher.search("search term", group211, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 1); - - searchResult = entrySearcher.search("search term", group11, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 1); - - searchResult = entrySearcher.search("search term", group1, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 0); + m_searchResult = m_entrySearcher.search("search term", group1, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 0); } void TestEntrySearcher::testAndConcatenationInSearch() @@ -115,26 +110,23 @@ void TestEntrySearcher::testAndConcatenationInSearch() Entry* entry = new Entry(); entry->setNotes("abc def ghi"); entry->setTitle("jkl"); - entry->setGroup(groupRoot); + entry->setGroup(m_groupRoot); - EntrySearcher entrySearcher; - QList searchResult; + m_searchResult = m_entrySearcher.search("", m_groupRoot, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 1); - searchResult = entrySearcher.search("", groupRoot, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 1); + m_searchResult = m_entrySearcher.search("def", m_groupRoot, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 1); - searchResult = entrySearcher.search("def", groupRoot, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 1); + m_searchResult = m_entrySearcher.search(" abc ghi ", m_groupRoot, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 1); - searchResult = entrySearcher.search(" abc ghi ", groupRoot, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 1); + m_searchResult = m_entrySearcher.search("ghi ef", m_groupRoot, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 1); - searchResult = entrySearcher.search("ghi ef", groupRoot, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 1); + m_searchResult = m_entrySearcher.search("abc ef xyz", m_groupRoot, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 0); - searchResult = entrySearcher.search("abc ef xyz", groupRoot, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 0); - - searchResult = entrySearcher.search("abc kl", groupRoot, Qt::CaseInsensitive); - QCOMPARE(searchResult.count(), 1); + m_searchResult = m_entrySearcher.search("abc kl", m_groupRoot, Qt::CaseInsensitive); + QCOMPARE(m_searchResult.count(), 1); } diff --git a/tests/TestEntrySearcher.h b/tests/TestEntrySearcher.h index 3e9d4f66d..194e29f0f 100644 --- a/tests/TestEntrySearcher.h +++ b/tests/TestEntrySearcher.h @@ -21,7 +21,8 @@ #include -class Group; +#include "core/EntrySearcher.h" +#include "core/Group.h" class TestEntrySearcher : public QObject { @@ -34,7 +35,9 @@ private Q_SLOTS: void testAndConcatenationInSearch(); void testSearch(); private: - Group* groupRoot; + Group* m_groupRoot; + EntrySearcher m_entrySearcher; + QList m_searchResult; }; #endif // KEEPASSX_TESTENTRYSEARCHER_H