[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdeui/tests
From: David Faure <faure () kde ! org>
Date: 2010-05-11 23:42:05
Message-ID: 20100511234205.5B40FAC8B3 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1125695 by dfaure:
Convert to a QTestLib-based unittest, so that it's simpler to grasp, and more \
integrated in make test.
M +93 -101 kfindtest.cpp
M +22 -2 kfindtest.h
--- trunk/KDE/kdelibs/kdeui/tests/kfindtest.cpp #1125694:1125695
@@ -1,5 +1,7 @@
/*
Copyright (C) 2004, Arend van Beelen jr. <arend@auton.nl>
+ Copyright (C) 2010, David Faure <faure@kde.org>
+
This file is part of the KDE project
This library is free software; you can redistribute it and/or
@@ -17,35 +19,20 @@
Boston, MA 02110-1301, USA.
*/
-#include "kfind.h"
-#include "kfinddialog.h"
#include "kfindtest.h"
+#include "qtest_kde.h"
-#include <kapplication.h>
+#include "kfind.h"
+//#include "kfinddialog.h"
+
#include <kcmdlineargs.h>
#include <kdebug.h>
#include <stdlib.h>
#include <assert.h>
-static bool check(QString txt, QString a, QString b) // from kurltest
+void KFindRecorder::changeText(int line, const QString &text)
{
- if (a.isEmpty())
- a.clear();
- if (b.isEmpty())
- b.clear();
- if (a == b) {
- kDebug() << txt << " : checking '" << a << "' against expected value '" << b << \
"'... " << "ok";
- }
- else {
- kDebug() << txt << " : checking '" << a << "' against expected value '" << b << \
"'... " << "KO !";
- exit(1);
- }
- return true;
-}
-
-void KFindTest::changeText(int line, const QString &text)
-{
Q_ASSERT(line < m_text.count());
Q_ASSERT(m_find != 0);
@@ -54,7 +41,7 @@
m_find->setData(line, text);
}
-void KFindTest::find(const QString &pattern, long options)
+void KFindRecorder::find(const QString &pattern, long options)
{
delete m_find;
m_find = new KFind(pattern, options, 0);
@@ -79,7 +66,7 @@
} while(result == KFind::NoMatch && m_line < m_text.count());
}
-void KFindTest::findNext(const QString &pattern)
+void KFindRecorder::findNext(const QString &pattern)
{
Q_ASSERT(m_find != 0);
@@ -109,25 +96,24 @@
//kDebug() << "find next completed" << m_line;
}
-void KFindTest::slotHighlight(const QString &text, int index, int matchedLength)
+void KFindRecorder::slotHighlight(const QString &text, int index, int matchedLength)
{
m_hits.append("line: \"" + text + "\", index: " + QString::number(index) +
", length: " + QString::number(matchedLength) + "\n");
}
-void KFindTest::slotHighlight(int id, int index, int matchedLength)
+void KFindRecorder::slotHighlight(int id, int index, int matchedLength)
{
m_hits.append("line: \"" + m_text[id] + "\", index: " + QString::number(index) +
", length: " + QString::number(matchedLength) + "\n");
}
-int main(int argc, char **argv)
-{
- KCmdLineArgs::init(argc, argv, "kfindtest", 0, ki18n("KFindTest"), 0);
- //KApplication::disableAutoDcopRegistration();
- KApplication app;
+////
- QString text = "This file is part of the KDE project.\n"
+TestKFind::TestKFind()
+ : QObject()
+{
+ m_text = "This file is part of the KDE project.\n"
"This library is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU Library General Public\n"
"License version 2, as published by the Free Software Foundation.\n"
@@ -141,13 +127,55 @@
" along with this library; see the file COPYING.LIB. If not, \
write to\n"
" the Free Software Foundation, Inc., 51 Franklin Street, Fifth \
Floor,\n" " Boston, MA 02110-1301, USA.\n";
+}
- QString output1 = "line: \"This file is part of the KDE project.\", index: 0, \
length: 4\n" +void TestKFind::testSimpleSearch()
+{
+ // first we do a simple text searching the text and doing a few find nexts
+ KFindRecorder test(m_text.split('\n'));
+ test.find("This", 0);
+ test.findNext();
+ test.findNext();
+ test.findNext();
+ test.findNext();
+ test.findNext();
+
+ const QString output1 =
+ "line: \"This file is part of the KDE project.\", index: 0, length: 4\n"
"line: \"This library is free software; you can redistribute it \
and/or\", index: 0, length: 4\n"
"line: \" This library is distributed in the hope that it will \
be useful,\", index: 4, length: 4\n"
"line: \" along with this library; see the file COPYING.LIB. \
If not, write to\", index: 15, length: 4\n";
- QString output2 = "line: \"This file is part of the KDE project.\", index: 0, \
length: 0\n" + QCOMPARE(test.hits().join(""), output1);
+}
+
+void TestKFind::testRegexp()
+{
+ // TODO
+}
+
+void TestKFind::testFindIncremental()
+{
+ // FindIncremental with static contents...
+
+ KFindRecorder test(m_text.split('\n'));
+ test.find("", KFind::FindIncremental);
+ test.findNext("i");
+ test.findNext("is");
+ test.findNext("ist");
+ test.findNext();
+ test.findNext("istri");
+ test.findNext("istr");
+ test.findNext("ist");
+ test.findNext("is");
+ test.findNext("W");
+ test.findNext("WA");
+ test.findNext("WARRANTY");
+ test.findNext("Free");
+ test.findNext("Software Foundation");
+
+ const QString output2 =
+ "line: \"This file is part of the KDE project.\", index: 0, length: 0\n"
"line: \"This file is part of the KDE project.\", index: 2, \
length: 1\n"
"line: \"This file is part of the KDE project.\", index: 2, \
length: 2\n"
"line: \"This library is free software; you can redistribute it \
and/or\", index: 42, length: 3\n" @@ -162,7 +190,36 @@
"line: \"This library is free software; you can redistribute it \
and/or\", index: 16, length: 4\n"
"line: \"License version 2, as published by the Free Software \
Foundation.\", index: 44, length: 19\n";
- QString output3 = "line: \"This file is part of the KDE project.\", index: 0, \
length: 0\n" + QCOMPARE(test.hits().join(""), output2);
+}
+
+void TestKFind::testFindIncrementalDynamic()
+{
+ // Now do that again but with pages that change between searches
+ KFindRecorder test(m_text.split('\n'));
+
+ test.find("", KFind::FindIncremental);
+ test.findNext("i");
+ test.findNext("is");
+ test.findNext("ist");
+ test.findNext("istr");
+ test.findNext();
+ test.changeText(1, "The second line now looks a whole lot different.");
+ test.findNext("istri");
+ test.findNext("istr");
+ test.findNext("ist");
+ test.findNext("is");
+ test.findNext("i");
+ test.findNext("W");
+ test.findNext("WA");
+ test.findNext("WARRANTY");
+ test.changeText(6, " but WITHOUT ANY xxxx; without even the implied warranty \
of"); + test.findNext("WARRAN");
+ test.findNext("Free");
+ test.findNext("Software Foundation");
+
+ const QString output3 =
+ "line: \"This file is part of the KDE project.\", index: 0, length: 0\n"
"line: \"This file is part of the KDE project.\", index: 2, \
length: 1\n"
"line: \"This file is part of the KDE project.\", index: 2, \
length: 2\n"
"line: \"This library is free software; you can redistribute it \
and/or\", index: 42, length: 3\n" @@ -180,74 +237,9 @@
"line: \"License version 2, as published by the Free Software \
Foundation.\", index: 39, length: 4\n"
"line: \"License version 2, as published by the Free Software \
Foundation.\", index: 44, length: 19\n";
- KFindTest *test = new KFindTest(text.split('\n'));
-
- kDebug() << "Plain static search...";
-
- // first we do a simple text searching the text and doing a few find nexts
- test->find("This", 0);
- test->findNext();
- test->findNext();
- test->findNext();
- test->findNext();
- test->findNext();
-
- check("result", test->hits().join(""), output1);
- test->clearHits();
- kDebug() << "PASSED";
-
- kDebug() << "FindIncremental with static contents...";
-
- // now we'll do some searches using FindIncremental
- test->find("", KFind::FindIncremental);
- test->findNext("i");
- test->findNext("is");
- test->findNext("ist");
- test->findNext();
- test->findNext("istri");
- test->findNext("istr");
- test->findNext("ist");
- test->findNext("is");
- test->findNext("W");
- test->findNext("WA");
- test->findNext("WARRANTY");
- test->findNext("Free");
- test->findNext("Software Foundation");
-
- check("result", test->hits().join(""), output2);
- test->clearHits();
- kDebug() << "PASSED";
-
- kDebug() << "FindIncremental with dynamic contents...";
-
- // now do that again but with pages that change between searches
- test->find("", KFind::FindIncremental);
- test->findNext("i");
- test->findNext("is");
- test->findNext("ist");
- test->findNext("istr");
- test->findNext();
- test->changeText(1, "The second line now looks a whole lot different.");
- test->findNext("istri");
- test->findNext("istr");
- test->findNext("ist");
- test->findNext("is");
- test->findNext("i");
- test->findNext("W");
- test->findNext("WA");
- test->findNext("WARRANTY");
- test->changeText(6, " but WITHOUT ANY xxxx; without even the implied warranty \
of");
- test->findNext("WARRAN");
- test->findNext("Free");
- test->findNext("Software Foundation");
-
- check("result", test->hits().join(""), output3);
- test->clearHits();
- kDebug() << "PASSED";
-
- //return app.exec();
- delete test;
- return 0;
+ QCOMPARE(test.hits().join(""), output3);
}
+QTEST_KDEMAIN(TestKFind, GUI)
+
#include "kfindtest.moc"
--- trunk/KDE/kdelibs/kdeui/tests/kfindtest.h #1125694:1125695
@@ -1,5 +1,7 @@
/*
Copyright (C) 2004, Arend van Beelen jr. <arend@auton.nl>
+ Copyright (C) 2010, David Faure <faure@kde.org>
+
This file is part of the KDE project
This library is free software; you can redistribute it and/or
@@ -25,12 +27,12 @@
class KFind;
-class KFindTest : public QObject
+class KFindRecorder : public QObject
{
Q_OBJECT
public:
- KFindTest(const QStringList &text) :
+ KFindRecorder(const QStringList &text) :
QObject(0),
m_find(0),
m_text(text),
@@ -56,4 +58,22 @@
QStringList m_hits;
};
+class TestKFind : public QObject
+{
+ Q_OBJECT
+
+public:
+ TestKFind();
+
+private Q_SLOTS:
+
+ void testSimpleSearch();
+ void testRegexp();
+ void testFindIncremental();
+ void testFindIncrementalDynamic();
+
+private:
+ QString m_text;
+};
+
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic