forked from keepassxreboot/keepassxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestWildcardMatcher.cpp
88 lines (76 loc) · 3.2 KB
/
TestWildcardMatcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright (C) 2012 Felix Geyer <[email protected]>
*
* 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 "TestWildcardMatcher.h"
#include "TestGlobal.h"
#include "autotype/WildcardMatcher.h"
QTEST_GUILESS_MAIN(TestWildcardMatcher)
const QString TestWildcardMatcher::DefaultText = QString("some text");
const QString TestWildcardMatcher::AlternativeText = QString("some other text");
void TestWildcardMatcher::testMatcher_data()
{
QTest::addColumn<QString>("text");
QTest::addColumn<QString>("pattern");
QTest::addColumn<bool>("match");
QTest::newRow("MatchWithoutWildcard") << DefaultText << DefaultText << true;
QTest::newRow("NoMatchWithoutWildcard") << DefaultText << QString("no match text") << false;
QTest::newRow("MatchWithOneWildcardInTheMiddle") << AlternativeText << QString("some*text") << true;
QTest::newRow("NoMatchWithOneWildcardInTheMiddle") << AlternativeText << QString("differen*text") << false;
QTest::newRow("MatchWithOneWildcardAtBegin") << DefaultText << QString("*text") << true;
QTest::newRow("NoMatchWithOneWildcardAtBegin") << DefaultText << QString("*text something else") << false;
QTest::newRow("NatchWithOneWildcardAtEnd") << DefaultText << QString("some*") << true;
QTest::newRow("NoMatchWithOneWildcardAtEnd") << DefaultText << QString("some other*") << false;
QTest::newRow("MatchWithMultipleWildcards") << AlternativeText << QString("some*th*text") << true;
QTest::newRow("NoMatchWithMultipleWildcards") << AlternativeText << QString("some*abc*text") << false;
QTest::newRow("MatchJustWildcard") << DefaultText << QString("*") << true;
QTest::newRow("MatchFollowingWildcards") << DefaultText << QString("some t**t") << true;
QTest::newRow("CaseSensitivity") << DefaultText.toUpper() << QString("some t**t") << true;
}
void TestWildcardMatcher::testMatcher()
{
QFETCH(QString, text);
QFETCH(QString, pattern);
QFETCH(bool, match);
initMatcher(text);
verifyMatchResult(pattern, match);
cleanupMatcher();
}
void TestWildcardMatcher::initMatcher(QString text)
{
m_matcher = new WildcardMatcher(text);
}
void TestWildcardMatcher::cleanupMatcher()
{
delete m_matcher;
}
void TestWildcardMatcher::verifyMatchResult(QString pattern, bool expected)
{
if (expected) {
verifyMatch(pattern);
} else {
verifyNoMatch(pattern);
}
}
void TestWildcardMatcher::verifyMatch(QString pattern)
{
bool matchResult = m_matcher->match(pattern);
QVERIFY(matchResult);
}
void TestWildcardMatcher::verifyNoMatch(QString pattern)
{
bool matchResult = m_matcher->match(pattern);
QVERIFY(!matchResult);
}