mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-26 07:49:50 -05:00
Refactor TestEntrySearcher.
This commit is contained in:
parent
819cfd459a
commit
4f60df029d
@ -20,19 +20,18 @@
|
||||
#include <QTest>
|
||||
|
||||
#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<Entry*> 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<Entry*> 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);
|
||||
}
|
||||
|
@ -21,7 +21,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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<Entry*> m_searchResult;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_TESTENTRYSEARCHER_H
|
||||
|
Loading…
Reference in New Issue
Block a user