2014-05-15 17:48:54 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Florian Geyer <blueice@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TestEntrySearcher.h"
|
2021-07-11 22:10:29 -04:00
|
|
|
#include "core/Group.h"
|
2023-07-04 07:24:10 -04:00
|
|
|
#include "core/Tools.h"
|
2021-07-11 22:10:29 -04:00
|
|
|
|
|
|
|
#include <QTest>
|
2014-05-15 17:48:54 -04:00
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestEntrySearcher)
|
|
|
|
|
2018-11-17 09:55:57 -05:00
|
|
|
void TestEntrySearcher::init()
|
2014-05-15 17:48:54 -04:00
|
|
|
{
|
2018-03-25 16:24:30 -04:00
|
|
|
m_rootGroup = new Group();
|
2020-01-24 12:42:00 -05:00
|
|
|
m_entrySearcher = EntrySearcher();
|
2014-05-15 17:59:26 -04:00
|
|
|
}
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-11-17 09:55:57 -05:00
|
|
|
void TestEntrySearcher::cleanup()
|
2014-05-15 17:59:26 -04:00
|
|
|
{
|
2018-03-25 16:24:30 -04:00
|
|
|
delete m_rootGroup;
|
2014-05-15 17:48:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestEntrySearcher::testSearch()
|
|
|
|
{
|
2018-03-25 16:24:30 -04:00
|
|
|
/**
|
|
|
|
* Root
|
|
|
|
* - group1 (search disabled)
|
|
|
|
* - group11
|
|
|
|
* - group2
|
|
|
|
* - group21
|
|
|
|
* - group211
|
|
|
|
* - group2111
|
|
|
|
*/
|
2022-04-11 20:06:50 -04:00
|
|
|
auto group1 = new Group();
|
|
|
|
auto group2 = new Group();
|
|
|
|
auto group3 = new Group();
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
group1->setParent(m_rootGroup);
|
|
|
|
group2->setParent(m_rootGroup);
|
|
|
|
group3->setParent(m_rootGroup);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto group11 = new Group();
|
2014-05-15 17:48:54 -04:00
|
|
|
|
|
|
|
group11->setParent(group1);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto group21 = new Group();
|
|
|
|
auto group211 = new Group();
|
|
|
|
auto group2111 = new Group();
|
2014-05-15 17:48:54 -04:00
|
|
|
|
|
|
|
group21->setParent(group2);
|
|
|
|
group211->setParent(group21);
|
|
|
|
group2111->setParent(group211);
|
|
|
|
|
|
|
|
group1->setSearchingEnabled(Group::Disable);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto eRoot = new Entry();
|
2018-03-25 16:24:30 -04:00
|
|
|
eRoot->setTitle("test search term test");
|
|
|
|
eRoot->setGroup(m_rootGroup);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto eRoot2 = new Entry();
|
2014-05-15 17:48:54 -04:00
|
|
|
eRoot2->setNotes("test term test");
|
2018-03-25 16:24:30 -04:00
|
|
|
eRoot2->setGroup(m_rootGroup);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-11-17 09:55:57 -05:00
|
|
|
// Searching is disabled for these
|
2022-04-11 20:06:50 -04:00
|
|
|
auto e1 = new Entry();
|
2018-03-25 16:24:30 -04:00
|
|
|
e1->setUsername("test search term test");
|
2014-05-15 17:48:54 -04:00
|
|
|
e1->setGroup(group1);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto e11 = new Entry();
|
2014-05-15 17:48:54 -04:00
|
|
|
e11->setNotes("test search term test");
|
|
|
|
e11->setGroup(group11);
|
2018-11-17 09:55:57 -05:00
|
|
|
// End searching disabled
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto e2111 = new Entry();
|
2018-03-25 16:24:30 -04:00
|
|
|
e2111->setTitle("test search term test");
|
2014-05-15 17:48:54 -04:00
|
|
|
e2111->setGroup(group2111);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto e2111b = new Entry();
|
2014-05-15 17:48:54 -04:00
|
|
|
e2111b->setNotes("test search test");
|
2018-11-17 09:55:57 -05:00
|
|
|
e2111b->setUsername("user123");
|
2018-03-25 16:24:30 -04:00
|
|
|
e2111b->setPassword("testpass");
|
2014-05-15 17:48:54 -04:00
|
|
|
e2111b->setGroup(group2111);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto e3 = new Entry();
|
2018-03-25 16:24:30 -04:00
|
|
|
e3->setUrl("test search term test");
|
2014-05-15 17:48:54 -04:00
|
|
|
e3->setGroup(group3);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto e3b = new Entry();
|
2019-08-12 10:33:31 -04:00
|
|
|
e3b->setTitle("test search test 123");
|
2018-11-17 09:55:57 -05:00
|
|
|
e3b->setUsername("test@email.com");
|
2018-03-25 16:24:30 -04:00
|
|
|
e3b->setPassword("realpass");
|
2014-05-15 17:48:54 -04:00
|
|
|
e3b->setGroup(group3);
|
|
|
|
|
2018-11-17 09:55:57 -05:00
|
|
|
// Simple search term testing
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("search", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 5);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("search term", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 3);
|
|
|
|
|
2019-08-12 10:33:31 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("123", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 2);
|
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("search term", group211);
|
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
|
|
|
|
2018-11-17 09:55:57 -05:00
|
|
|
// Test advanced search terms
|
2019-08-12 10:33:31 -04:00
|
|
|
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);
|
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("password:testpass", m_rootGroup);
|
2014-05-15 18:26:09 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2019-08-12 10:33:31 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("pw:testpass", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
|
|
|
|
2018-11-17 09:55:57 -05:00
|
|
|
m_searchResult = m_entrySearcher.search("!user:email.com", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 5);
|
|
|
|
|
2019-08-12 10:33:31 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("!u:email.com", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 5);
|
|
|
|
|
2018-11-17 09:55:57 -05:00
|
|
|
m_searchResult = m_entrySearcher.search("*user:\".*@.*\\.com\"", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
|
|
|
|
|
|
|
m_searchResult = m_entrySearcher.search("+user:email", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 0);
|
|
|
|
|
|
|
|
// Terms are logical AND together
|
|
|
|
m_searchResult = m_entrySearcher.search("password:pass user:user", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
// Parent group has search disabled
|
|
|
|
m_searchResult = m_entrySearcher.search("search term", group11);
|
2014-05-15 18:26:09 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 0);
|
2014-05-15 17:48:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestEntrySearcher::testAndConcatenationInSearch()
|
|
|
|
{
|
2022-04-11 20:06:50 -04:00
|
|
|
auto entry = new Entry();
|
2014-05-15 17:48:54 -04:00
|
|
|
entry->setNotes("abc def ghi");
|
|
|
|
entry->setTitle("jkl");
|
2018-03-25 16:24:30 -04:00
|
|
|
entry->setGroup(m_rootGroup);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("", m_rootGroup);
|
2014-05-15 18:26:09 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("def", m_rootGroup);
|
2014-05-15 18:26:09 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search(" abc ghi ", m_rootGroup);
|
2014-05-15 18:26:09 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("ghi ef", m_rootGroup);
|
2014-05-15 18:26:09 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("abc ef xyz", m_rootGroup);
|
2014-05-15 18:26:09 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 0);
|
2014-05-15 17:48:54 -04:00
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
m_searchResult = m_entrySearcher.search("abc kl", m_rootGroup);
|
2014-05-15 18:26:09 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
2014-05-15 17:48:54 -04:00
|
|
|
}
|
2014-05-16 04:51:22 -04:00
|
|
|
|
|
|
|
void TestEntrySearcher::testAllAttributesAreSearched()
|
|
|
|
{
|
2022-04-11 20:06:50 -04:00
|
|
|
auto entry = new Entry();
|
2018-03-25 16:24:30 -04:00
|
|
|
entry->setGroup(m_rootGroup);
|
2014-05-16 04:51:22 -04:00
|
|
|
|
|
|
|
entry->setTitle("testTitle");
|
|
|
|
entry->setUsername("testUsername");
|
|
|
|
entry->setUrl("testUrl");
|
|
|
|
entry->setNotes("testNote");
|
|
|
|
|
2018-03-25 16:24:30 -04:00
|
|
|
// Default is to AND all terms together
|
|
|
|
m_searchResult = m_entrySearcher.search("testTitle testUsername testUrl testNote", m_rootGroup);
|
2014-05-16 04:51:22 -04:00
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
|
|
|
}
|
2018-03-25 16:24:30 -04:00
|
|
|
|
|
|
|
void TestEntrySearcher::testSearchTermParser()
|
|
|
|
{
|
|
|
|
// Test standard search terms
|
2019-02-22 17:17:51 -05:00
|
|
|
m_entrySearcher.parseSearchTerms("-test \"quoted \\\"string\\\"\" user:user pass:\"test me\" noquote ");
|
|
|
|
auto terms = m_entrySearcher.m_searchTerms;
|
2018-03-25 16:24:30 -04:00
|
|
|
|
|
|
|
QCOMPARE(terms.length(), 5);
|
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[0].field, EntrySearcher::Field::Undefined);
|
|
|
|
QCOMPARE(terms[0].word, QString("test"));
|
|
|
|
QCOMPARE(terms[0].exclude, true);
|
2018-03-25 16:24:30 -04:00
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[1].field, EntrySearcher::Field::Undefined);
|
2022-09-07 19:25:23 -04:00
|
|
|
QCOMPARE(terms[1].word, QString("quoted \"string\""));
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[1].exclude, false);
|
2018-03-25 16:24:30 -04:00
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[2].field, EntrySearcher::Field::Username);
|
|
|
|
QCOMPARE(terms[2].word, QString("user"));
|
2018-03-25 16:24:30 -04:00
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[3].field, EntrySearcher::Field::Password);
|
|
|
|
QCOMPARE(terms[3].word, QString("test me"));
|
2018-03-25 16:24:30 -04:00
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[4].field, EntrySearcher::Field::Undefined);
|
|
|
|
QCOMPARE(terms[4].word, QString("noquote"));
|
2018-03-25 16:24:30 -04:00
|
|
|
|
|
|
|
// Test wildcard and regex search terms
|
2019-02-22 17:17:51 -05:00
|
|
|
m_entrySearcher.parseSearchTerms("+url:*.google.com *user:\\d+\\w{2}");
|
|
|
|
terms = m_entrySearcher.m_searchTerms;
|
2018-03-25 16:24:30 -04:00
|
|
|
|
|
|
|
QCOMPARE(terms.length(), 2);
|
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[0].field, EntrySearcher::Field::Url);
|
2022-05-21 10:21:33 -04:00
|
|
|
QCOMPARE(terms[0].regex.pattern(), QString("^(?:.*\\.google\\.com)$"));
|
2018-03-25 16:24:30 -04:00
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[1].field, EntrySearcher::Field::Username);
|
|
|
|
QCOMPARE(terms[1].regex.pattern(), QString("\\d+\\w{2}"));
|
2019-02-21 00:51:23 -05:00
|
|
|
|
|
|
|
// Test custom attribute search terms
|
|
|
|
m_entrySearcher.parseSearchTerms("+_abc:efg _def:\"ddd\"");
|
|
|
|
terms = m_entrySearcher.m_searchTerms;
|
|
|
|
|
|
|
|
QCOMPARE(terms.length(), 2);
|
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[0].field, EntrySearcher::Field::AttributeValue);
|
|
|
|
QCOMPARE(terms[0].word, QString("abc"));
|
2022-05-21 10:21:33 -04:00
|
|
|
QCOMPARE(terms[0].regex.pattern(), QString("^(?:efg)$"));
|
2019-02-21 00:51:23 -05:00
|
|
|
|
2019-11-01 16:23:26 -04:00
|
|
|
QCOMPARE(terms[1].field, EntrySearcher::Field::AttributeValue);
|
|
|
|
QCOMPARE(terms[1].word, QString("def"));
|
|
|
|
QCOMPARE(terms[1].regex.pattern(), QString("ddd"));
|
2019-02-21 00:51:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-01-24 12:42:00 -05:00
|
|
|
m_entrySearcher = EntrySearcher(false, true);
|
2019-02-21 00:51:23 -05:00
|
|
|
m_searchResult = m_entrySearcher.search("_testAttribute:test _testProtected:testP2", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 2);
|
2018-03-25 16:24:30 -04:00
|
|
|
}
|
2020-05-08 11:13:15 -04:00
|
|
|
|
|
|
|
void TestEntrySearcher::testGroup()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Root
|
|
|
|
* - group1 (1 entry)
|
|
|
|
* - subgroup1 (2 entries)
|
|
|
|
* - group2
|
|
|
|
* - subgroup2 (1 entry)
|
|
|
|
*/
|
2022-04-11 20:06:50 -04:00
|
|
|
auto group1 = new Group();
|
|
|
|
auto group2 = new Group();
|
2020-05-08 11:13:15 -04:00
|
|
|
|
|
|
|
group1->setParent(m_rootGroup);
|
|
|
|
group1->setName("group1");
|
|
|
|
group2->setParent(m_rootGroup);
|
|
|
|
group2->setName("group2");
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto subgroup1 = new Group();
|
2020-05-08 11:13:15 -04:00
|
|
|
subgroup1->setName("subgroup1");
|
|
|
|
subgroup1->setParent(group1);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto subgroup2 = new Group();
|
2020-05-08 11:13:15 -04:00
|
|
|
subgroup2->setName("subgroup2");
|
|
|
|
subgroup2->setParent(group2);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto eGroup1 = new Entry();
|
2020-05-08 11:13:15 -04:00
|
|
|
eGroup1->setTitle("Entry Group 1");
|
|
|
|
eGroup1->setGroup(group1);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto eSub1 = new Entry();
|
2020-05-08 11:13:15 -04:00
|
|
|
eSub1->setTitle("test search term test");
|
|
|
|
eSub1->setGroup(subgroup1);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto eSub2 = new Entry();
|
2020-05-08 11:13:15 -04:00
|
|
|
eSub2->setNotes("test test");
|
|
|
|
eSub2->setGroup(subgroup1);
|
|
|
|
|
2022-04-11 20:06:50 -04:00
|
|
|
auto eSub3 = new Entry();
|
2020-05-08 11:13:15 -04:00
|
|
|
eSub3->setNotes("test term test");
|
|
|
|
eSub3->setGroup(subgroup2);
|
|
|
|
|
|
|
|
m_searchResult = m_entrySearcher.search("group:subgroup", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 3);
|
|
|
|
|
|
|
|
m_searchResult = m_entrySearcher.search("g:subgroup1", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 2);
|
|
|
|
|
|
|
|
m_searchResult = m_entrySearcher.search("g:subgroup1 search", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
|
|
|
|
|
|
|
m_searchResult = m_entrySearcher.search("g:*1/sub*1", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 2);
|
|
|
|
|
|
|
|
m_searchResult = m_entrySearcher.search("g:/group1 search", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
|
|
|
}
|
2020-01-24 12:42:00 -05:00
|
|
|
|
|
|
|
void TestEntrySearcher::testSkipProtected()
|
|
|
|
{
|
|
|
|
QScopedPointer<Entry> e1(new Entry());
|
|
|
|
e1->setGroup(m_rootGroup);
|
|
|
|
|
|
|
|
e1->attributes()->set("testAttribute", "testE1");
|
|
|
|
e1->attributes()->set("testProtected", "apple", true);
|
|
|
|
|
|
|
|
QScopedPointer<Entry> e2(new Entry());
|
|
|
|
e2->setGroup(m_rootGroup);
|
|
|
|
e2->attributes()->set("testAttribute", "testE2");
|
|
|
|
e2->attributes()->set("testProtected", "banana", true);
|
|
|
|
|
|
|
|
const QList<Entry*> expectE1{e1.data()};
|
|
|
|
const QList<Entry*> expectE2{e2.data()};
|
|
|
|
const QList<Entry*> expectBoth{e1.data(), e2.data()};
|
|
|
|
|
|
|
|
// when not skipping protected, empty term matches everything
|
|
|
|
m_searchResult = m_entrySearcher.search("", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, expectBoth);
|
|
|
|
|
|
|
|
// now test the searcher with skipProtected = true
|
|
|
|
m_entrySearcher = EntrySearcher(false, true);
|
|
|
|
|
|
|
|
// when skipping protected, empty term matches nothing
|
|
|
|
m_searchResult = m_entrySearcher.search("", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, {});
|
|
|
|
|
|
|
|
// having a protected entry in terms should not affect the results in anyways
|
|
|
|
m_searchResult = m_entrySearcher.search("_testProtected:apple", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, {});
|
|
|
|
m_searchResult = m_entrySearcher.search("_testProtected:apple _testAttribute:testE2", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, expectE2);
|
|
|
|
m_searchResult = m_entrySearcher.search("_testProtected:apple _testAttribute:testE1", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, expectE1);
|
|
|
|
m_searchResult =
|
|
|
|
m_entrySearcher.search("_testProtected:apple _testAttribute:testE1 _testAttribute:testE2", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, {});
|
|
|
|
|
2023-12-22 15:12:07 -05:00
|
|
|
// also move the protected term around to exercise the short-circuit logic
|
2020-01-24 12:42:00 -05:00
|
|
|
m_searchResult = m_entrySearcher.search("_testAttribute:testE2 _testProtected:apple", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, expectE2);
|
|
|
|
m_searchResult = m_entrySearcher.search("_testAttribute:testE1 _testProtected:apple", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, expectE1);
|
|
|
|
m_searchResult =
|
|
|
|
m_entrySearcher.search("_testAttribute:testE1 _testProtected:apple _testAttribute:testE2", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult, {});
|
|
|
|
}
|
2023-07-04 07:24:10 -04:00
|
|
|
|
|
|
|
void TestEntrySearcher::testUUIDSearch()
|
|
|
|
{
|
|
|
|
auto entry1 = new Entry();
|
|
|
|
entry1->setGroup(m_rootGroup);
|
|
|
|
entry1->setTitle("testTitle");
|
|
|
|
auto uuid1 = QUuid::createUuid();
|
|
|
|
entry1->setUuid(uuid1);
|
|
|
|
|
|
|
|
auto entry2 = new Entry();
|
|
|
|
entry2->setGroup(m_rootGroup);
|
|
|
|
entry2->setTitle("testTitle2");
|
|
|
|
auto uuid2 = QUuid::createUuid();
|
|
|
|
entry2->setUuid(uuid2);
|
|
|
|
|
|
|
|
m_searchResult = m_entrySearcher.search("uuid:", m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 2);
|
|
|
|
|
|
|
|
m_searchResult = m_entrySearcher.search("uuid:" + Tools::uuidToHex(uuid1), m_rootGroup);
|
|
|
|
QCOMPARE(m_searchResult.count(), 1);
|
|
|
|
}
|