diff options
Diffstat (limited to 'tests/TestEntrySearcher.cpp')
-rw-r--r-- | tests/TestEntrySearcher.cpp | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/TestEntrySearcher.cpp b/tests/TestEntrySearcher.cpp index e949b97b8..7b129df17 100644 --- a/tests/TestEntrySearcher.cpp +++ b/tests/TestEntrySearcher.cpp @@ -96,7 +96,7 @@ void TestEntrySearcher::testSearch() e3->setGroup(group3); Entry* e3b = new Entry(); - e3b->setTitle("test search test"); + e3b->setTitle("test search test 123"); e3b->setUsername("test@email.com"); e3b->setPassword("realpass"); e3b->setGroup(group3); @@ -108,16 +108,31 @@ void TestEntrySearcher::testSearch() m_searchResult = m_entrySearcher.search("search term", m_rootGroup); QCOMPARE(m_searchResult.count(), 3); + m_searchResult = m_entrySearcher.search("123", m_rootGroup); + QCOMPARE(m_searchResult.count(), 2); + m_searchResult = m_entrySearcher.search("search term", group211); QCOMPARE(m_searchResult.count(), 1); // Test advanced search terms + m_searchResult = m_entrySearcher.search("title:123", m_rootGroup); + QCOMPARE(m_searchResult.count(), 1); + + m_searchResult = m_entrySearcher.search("t:123", m_rootGroup); + QCOMPARE(m_searchResult.count(), 1); + m_searchResult = m_entrySearcher.search("password:testpass", m_rootGroup); QCOMPARE(m_searchResult.count(), 1); + m_searchResult = m_entrySearcher.search("pw:testpass", m_rootGroup); + QCOMPARE(m_searchResult.count(), 1); + m_searchResult = m_entrySearcher.search("!user:email.com", m_rootGroup); QCOMPARE(m_searchResult.count(), 5); + m_searchResult = m_entrySearcher.search("!u:email.com", m_rootGroup); + QCOMPARE(m_searchResult.count(), 5); + m_searchResult = m_entrySearcher.search("*user:\".*@.*\\.com\"", m_rootGroup); QCOMPARE(m_searchResult.count(), 1); @@ -210,4 +225,40 @@ void TestEntrySearcher::testSearchTermParser() QCOMPARE(terms[1]->field, EntrySearcher::Field::Username); QCOMPARE(terms[1]->regex.pattern(), QString("\\d+\\w{2}")); + + // Test custom attribute search terms + m_entrySearcher.parseSearchTerms("+_abc:efg _def:\"ddd\""); + terms = m_entrySearcher.m_searchTerms; + + QCOMPARE(terms.length(), 2); + + QCOMPARE(terms[0]->field, EntrySearcher::Field::AttributeValue); + QCOMPARE(terms[0]->word, QString("abc")); + QCOMPARE(terms[0]->regex.pattern(), QString("^efg$")); + + QCOMPARE(terms[1]->field, EntrySearcher::Field::AttributeValue); + QCOMPARE(terms[1]->word, QString("def")); + QCOMPARE(terms[1]->regex.pattern(), QString("ddd")); +} + +void TestEntrySearcher::testCustomAttributesAreSearched() +{ + QScopedPointer<Entry> e1(new Entry()); + e1->setGroup(m_rootGroup); + + e1->attributes()->set("testAttribute", "testE1"); + e1->attributes()->set("testProtected", "testP", true); + + QScopedPointer<Entry> e2(new Entry()); + e2->setGroup(m_rootGroup); + e2->attributes()->set("testAttribute", "testE2"); + e2->attributes()->set("testProtected", "testP2", true); + + // search for custom entries + m_searchResult = m_entrySearcher.search("_testAttribute:test", m_rootGroup); + QCOMPARE(m_searchResult.count(), 2); + + // protected attributes are ignored + m_searchResult = m_entrySearcher.search("_testAttribute:test _testProtected:testP2", m_rootGroup); + QCOMPARE(m_searchResult.count(), 2); } |