mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-17 00:09:36 -04:00
added some unit tests for search strings
git-svn-id: http://svn.osgeo.org/qgis/trunk@13196 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
57c498ef05
commit
0ff7cc973a
@ -112,3 +112,4 @@ ADD_QGIS_TEST(maprenderertest testqgsmaprenderer.cpp)
|
|||||||
ADD_QGIS_TEST(geometrytest testqgsgeometry.cpp)
|
ADD_QGIS_TEST(geometrytest testqgsgeometry.cpp)
|
||||||
ADD_QGIS_TEST(coordinatereferencesystemtest testqgscoordinatereferencesystem.cpp)
|
ADD_QGIS_TEST(coordinatereferencesystemtest testqgscoordinatereferencesystem.cpp)
|
||||||
ADD_QGIS_TEST(pointtest testqgspoint.cpp)
|
ADD_QGIS_TEST(pointtest testqgspoint.cpp)
|
||||||
|
ADD_QGIS_TEST(searchstringtest testqgssearchstring.cpp)
|
||||||
|
72
tests/src/core/testqgssearchstring.cpp
Normal file
72
tests/src/core/testqgssearchstring.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
testqgssearchstring.cpp
|
||||||
|
--------------------------------------
|
||||||
|
Date : March 28, 2010
|
||||||
|
Copyright : (C) 2010 Martin Dobias
|
||||||
|
Email : wonder.sk at gmail.com
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* 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 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include <qgssearchstring.h>
|
||||||
|
#include <qgssearchtreenode.h>
|
||||||
|
|
||||||
|
class TestQgsSearchString : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT;
|
||||||
|
private slots:
|
||||||
|
//void initTestCase();// will be called before the first testfunction is executed.
|
||||||
|
//void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||||
|
//void init();// will be called before each testfunction is executed.
|
||||||
|
//void cleanup();// will be called after every testfunction.
|
||||||
|
|
||||||
|
void testLike();
|
||||||
|
void testRegexp();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString mReport;
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool evalString(QString str)
|
||||||
|
{
|
||||||
|
QgsSearchString ss;
|
||||||
|
ss.setString(str);
|
||||||
|
return ss.tree()->checkAgainst(QgsFieldMap(), QgsAttributeMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsSearchString::testLike()
|
||||||
|
{
|
||||||
|
QVERIFY( evalString("'a' LIKE 'a'") );
|
||||||
|
QVERIFY( ! evalString("'aa' LIKE 'a'") );
|
||||||
|
QVERIFY( ! evalString("'a' LIKE 'b'") );
|
||||||
|
|
||||||
|
QVERIFY( evalString("'abba' LIKE 'a%'") );
|
||||||
|
QVERIFY( ! evalString("'abba' LIKE 'b%'") );
|
||||||
|
QVERIFY( evalString("'abba' LIKE '%a'") );
|
||||||
|
QVERIFY( ! evalString("'abba' LIKE '%b'") );
|
||||||
|
|
||||||
|
QVERIFY( evalString("'abba' LIKE '%bb%'") );
|
||||||
|
QVERIFY( evalString("'abba' LIKE 'a%a'") );
|
||||||
|
QVERIFY( ! evalString("'abba' LIKE 'b%b'") );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsSearchString::testRegexp()
|
||||||
|
{
|
||||||
|
QVERIFY( evalString("'a' ~ 'a'") );
|
||||||
|
QVERIFY( ! evalString("'b' ~ 'a'") );
|
||||||
|
|
||||||
|
QVERIFY( evalString("'abba' ~ 'a'") );
|
||||||
|
QVERIFY( ! evalString("'abba' ~ 'aba'") );
|
||||||
|
QVERIFY( evalString("'abba' ~ 'a.*a'") );
|
||||||
|
QVERIFY( evalString("'abba' ~ 'a[b]+a'") );
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(TestQgsSearchString)
|
||||||
|
#include "moc_testqgssearchstring.cxx"
|
Loading…
x
Reference in New Issue
Block a user