Skip to content

Commit 24b1c16

Browse files
author
wonder
committed
added some unit tests for search strings
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13196 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9c2db9a commit 24b1c16

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

tests/src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ ADD_QGIS_TEST(maprenderertest testqgsmaprenderer.cpp)
112112
ADD_QGIS_TEST(geometrytest testqgsgeometry.cpp)
113113
ADD_QGIS_TEST(coordinatereferencesystemtest testqgscoordinatereferencesystem.cpp)
114114
ADD_QGIS_TEST(pointtest testqgspoint.cpp)
115+
ADD_QGIS_TEST(searchstringtest testqgssearchstring.cpp)
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/***************************************************************************
2+
testqgssearchstring.cpp
3+
--------------------------------------
4+
Date : March 28, 2010
5+
Copyright : (C) 2010 Martin Dobias
6+
Email : wonder.sk at gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include <QtTest>
17+
18+
#include <qgssearchstring.h>
19+
#include <qgssearchtreenode.h>
20+
21+
class TestQgsSearchString : public QObject
22+
{
23+
Q_OBJECT;
24+
private slots:
25+
//void initTestCase();// will be called before the first testfunction is executed.
26+
//void cleanupTestCase();// will be called after the last testfunction was executed.
27+
//void init();// will be called before each testfunction is executed.
28+
//void cleanup();// will be called after every testfunction.
29+
30+
void testLike();
31+
void testRegexp();
32+
33+
private:
34+
QString mReport;
35+
};
36+
37+
static bool evalString(QString str)
38+
{
39+
QgsSearchString ss;
40+
ss.setString(str);
41+
return ss.tree()->checkAgainst(QgsFieldMap(), QgsAttributeMap());
42+
}
43+
44+
void TestQgsSearchString::testLike()
45+
{
46+
QVERIFY( evalString("'a' LIKE 'a'") );
47+
QVERIFY( ! evalString("'aa' LIKE 'a'") );
48+
QVERIFY( ! evalString("'a' LIKE 'b'") );
49+
50+
QVERIFY( evalString("'abba' LIKE 'a%'") );
51+
QVERIFY( ! evalString("'abba' LIKE 'b%'") );
52+
QVERIFY( evalString("'abba' LIKE '%a'") );
53+
QVERIFY( ! evalString("'abba' LIKE '%b'") );
54+
55+
QVERIFY( evalString("'abba' LIKE '%bb%'") );
56+
QVERIFY( evalString("'abba' LIKE 'a%a'") );
57+
QVERIFY( ! evalString("'abba' LIKE 'b%b'") );
58+
}
59+
60+
void TestQgsSearchString::testRegexp()
61+
{
62+
QVERIFY( evalString("'a' ~ 'a'") );
63+
QVERIFY( ! evalString("'b' ~ 'a'") );
64+
65+
QVERIFY( evalString("'abba' ~ 'a'") );
66+
QVERIFY( ! evalString("'abba' ~ 'aba'") );
67+
QVERIFY( evalString("'abba' ~ 'a.*a'") );
68+
QVERIFY( evalString("'abba' ~ 'a[b]+a'") );
69+
}
70+
71+
QTEST_MAIN(TestQgsSearchString)
72+
#include "moc_testqgssearchstring.cxx"

0 commit comments

Comments
 (0)