|
| 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