Skip to content
Permalink
Browse files
added some unit tests for search strings
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13196 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 29, 2010
1 parent 9c2db9a commit 24b1c166d3d021b58fc5d74c556b049104fc98db
Showing with 73 additions and 0 deletions.
  1. +1 −0 tests/src/core/CMakeLists.txt
  2. +72 −0 tests/src/core/testqgssearchstring.cpp
@@ -112,3 +112,4 @@ ADD_QGIS_TEST(maprenderertest testqgsmaprenderer.cpp)
ADD_QGIS_TEST(geometrytest testqgsgeometry.cpp)
ADD_QGIS_TEST(coordinatereferencesystemtest testqgscoordinatereferencesystem.cpp)
ADD_QGIS_TEST(pointtest testqgspoint.cpp)
ADD_QGIS_TEST(searchstringtest testqgssearchstring.cpp)
@@ -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"

0 comments on commit 24b1c16

Please sign in to comment.