diff options
author | David Boddie <dboddie@trolltech.com> | 2010-08-11 11:50:37 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2010-08-11 11:50:37 (GMT) |
commit | c6ed32dc7e9c8a566f376d1baa7e616a1019f9af (patch) | |
tree | 95ce43172963aa266630d8836ccb6b23dde78991 /tests | |
parent | 9986c3f0c0681c7ea8bc8e5cfea5662880db6654 (diff) | |
parent | 5fa15620d09df1164cc28aa9b1e646a61f87e909 (diff) | |
download | Qt-c6ed32dc7e9c8a566f376d1baa7e616a1019f9af.zip Qt-c6ed32dc7e9c8a566f376d1baa7e616a1019f9af.tar.gz Qt-c6ed32dc7e9c8a566f376d1baa7e616a1019f9af.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
Diffstat (limited to 'tests')
24 files changed, 510 insertions, 15 deletions
diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/signalEmission.qml b/tests/auto/declarative/qdeclarativefocusscope/data/signalEmission.qml new file mode 100644 index 0000000..07601c7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativefocusscope/data/signalEmission.qml @@ -0,0 +1,33 @@ +import Qt 4.7 + +Rectangle { + width: 200 + height: 200 + + FocusScope { + focus: true + Rectangle { + objectName: "item1" + color: "blue" + onFocusChanged: focus ? color = "red" : color = "blue" + } + Rectangle { + objectName: "item2" + color: "blue" + onFocusChanged: focus ? color = "red" : color = "blue" + } + } + + FocusScope { + Rectangle { + objectName: "item3" + color: "blue" + onFocusChanged: focus ? color = "red" : color = "blue" + } + Rectangle { + objectName: "item4" + color: "blue" + onFocusChanged: focus ? color = "red" : color = "blue" + } + } +} diff --git a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp index b0c9c03..ec8f048 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp +++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp @@ -69,6 +69,7 @@ private slots: void textEdit(); void forceFocus(); void noParentFocus(); + void signalEmission(); }; /* @@ -335,7 +336,7 @@ void tst_qdeclarativefocusscope::noParentFocus() view->setSource(QUrl::fromLocalFile(SRCDIR "/data/chain.qml")); QVERIFY(view->rootObject()); - QVERIFY(view->rootObject()->property("focus1") == true); + QVERIFY(view->rootObject()->property("focus1") == false); QVERIFY(view->rootObject()->property("focus2") == false); QVERIFY(view->rootObject()->property("focus3") == true); QVERIFY(view->rootObject()->property("focus4") == true); @@ -344,6 +345,61 @@ void tst_qdeclarativefocusscope::noParentFocus() delete view; } +void tst_qdeclarativefocusscope::signalEmission() +{ + QDeclarativeView *view = new QDeclarativeView; + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/signalEmission.qml")); + + QDeclarativeRectangle *item1 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item1")); + QDeclarativeRectangle *item2 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item2")); + QDeclarativeRectangle *item3 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item3")); + QDeclarativeRectangle *item4 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item4")); + QVERIFY(item1 != 0); + QVERIFY(item2 != 0); + QVERIFY(item3 != 0); + QVERIFY(item4 != 0); + + view->show(); + qApp->setActiveWindow(view); + qApp->processEvents(); + +#ifdef Q_WS_X11 + // to be safe and avoid failing setFocus with window managers + qt_x11_wait_for_window_manager(view); +#endif + + QVariant blue(QColor("blue")); + QVariant red(QColor("red")); + + QVERIFY(view->hasFocus()); + QVERIFY(view->scene()->hasFocus()); + item1->setFocus(true); + QCOMPARE(item1->property("color"), red); + QCOMPARE(item2->property("color"), blue); + QCOMPARE(item3->property("color"), blue); + QCOMPARE(item4->property("color"), blue); + + item2->setFocus(true); + QCOMPARE(item1->property("color"), blue); + QCOMPARE(item2->property("color"), red); + QCOMPARE(item3->property("color"), blue); + QCOMPARE(item4->property("color"), blue); + + item3->setFocus(true); + QCOMPARE(item1->property("color"), blue); + QCOMPARE(item2->property("color"), red); + QCOMPARE(item3->property("color"), red); + QCOMPARE(item4->property("color"), blue); + + item4->setFocus(true); + QCOMPARE(item1->property("color"), blue); + QCOMPARE(item2->property("color"), red); + QCOMPARE(item3->property("color"), blue); + QCOMPARE(item4->property("color"), red); + + delete view; +} + QTEST_MAIN(tst_qdeclarativefocusscope) #include "tst_qdeclarativefocusscope.moc" diff --git a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp index d5a911a..db1f191 100644 --- a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp +++ b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp @@ -585,7 +585,7 @@ void tst_qdeclarativeinstruction::dump() << "45\t\t48\tDEFER\t\t\t7" << "46\t\tNA\tDEFER\t\t\t7" << "47\t\t48\tSTORE_IMPORTED_SCRIPT\t2" - << "48\t\t50\tXXX UNKOWN INSTRUCTION\t1234" + << "48\t\t50\tXXX UNKNOWN INSTRUCTION\t1234" << "49\t\t51\tSTORE_VARIANT_INTEGER\t\t32\t11" << "50\t\t52\tSTORE_VARIANT_DOUBLE\t\t19\t33.7" << "-------------------------------------------------------------------------------"; diff --git a/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml new file mode 100644 index 0000000..54b5b68 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml @@ -0,0 +1,15 @@ +import Qt 4.7 + +Rectangle { + width: 300 + height: 300 + + Rectangle { + height: childrenRect.height + + Repeater { + model: 1 + Rectangle { } + } + } +} diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index d76d360..25ca157 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -75,6 +75,7 @@ private slots: void childrenRect(); void childrenRectBug(); void childrenRectBug2(); + void childrenRectBug3(); void childrenProperty(); void resourcesProperty(); @@ -780,6 +781,17 @@ void tst_QDeclarativeItem::childrenRectBug2() delete canvas; } +// QTBUG-12722 +void tst_QDeclarativeItem::childrenRectBug3() +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/childrenRectBug3.qml")); + canvas->show(); + + //don't crash on delete + delete canvas; +} + template<typename T> T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName) { diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 858c26d..10805b4 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -271,6 +271,9 @@ void tst_qdeclarativelistmodel::dynamic_data() QTest::newRow("nested-insert") << "{append({'foo':123});insert(0,{'bars':[{'a':1},{'b':2},{'c':3}]});get(0).bars.get(0).a}" << 1 << ""; QTest::newRow("nested-set") << "{append({'foo':123});set(0,{'foo':[{'x':123}]});get(0).foo.get(0).x}" << 123 << ""; + QTest::newRow("nested-count") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]}); get(0).bars.count}" << 3 << ""; + QTest::newRow("nested-clear") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]}); get(0).bars.clear(); get(0).bars.count}" << 0 << ""; + // XXX //QTest::newRow("nested-setprop") << "{append({'foo':123});setProperty(0,'foo',[{'x':123}]);get(0).foo.get(0).x}" << 123 << ""; } @@ -344,9 +347,7 @@ void tst_qdeclarativelistmodel::dynamic_worker() waitForWorker(item); QDeclarativeExpression e(eng.rootContext(), &model, operations.last().toString()); - if (QByteArray(QTest::currentDataTag()).startsWith("nested")) - QVERIFY(e.evaluate().toInt() != result); - else + if (!QByteArray(QTest::currentDataTag()).startsWith("nested")) QCOMPARE(e.evaluate().toInt(), result); } diff --git a/tests/auto/qdom/qdom.pro b/tests/auto/qdom/qdom.pro index 5434ada..9040b91 100644 --- a/tests/auto/qdom/qdom.pro +++ b/tests/auto/qdom/qdom.pro @@ -9,7 +9,9 @@ wince*|symbian: { addFiles.path = . DEPLOYMENT += addFiles - DEPLOYMENT_PLUGIN += qcncodecs qjpcodecs qkrcodecs qtwcodecs + wince*|qt_not_deployed { + DEPLOYMENT_PLUGIN += qcncodecs qjpcodecs qkrcodecs qtwcodecs + } !symbian:DEFINES += SRCDIR=\\\"\\\" } else { diff --git a/tests/auto/qfile/qfile.pro b/tests/auto/qfile/qfile.pro index 0383e30..727f660 100644 --- a/tests/auto/qfile/qfile.pro +++ b/tests/auto/qfile/qfile.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs -wince*:{ +wince*|symbian:{ SUBDIRS = test } else { SUBDIRS = test stdinprocess diff --git a/tests/auto/qfileinfo/qfileinfo.pro b/tests/auto/qfileinfo/qfileinfo.pro index ef5ed22..30656e2 100644 --- a/tests/auto/qfileinfo/qfileinfo.pro +++ b/tests/auto/qfileinfo/qfileinfo.pro @@ -16,6 +16,7 @@ wince*:|symbian: { symbian { TARGET.CAPABILITY=AllFiles LIBS *= -lefsrv + INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE # Needed for e32svr.h in S^3 envs } # support for running test from shadow build directory diff --git a/tests/auto/qlocale/test/test.pro b/tests/auto/qlocale/test/test.pro index e33d0fe..6512e19 100644 --- a/tests/auto/qlocale/test/test.pro +++ b/tests/auto/qlocale/test/test.pro @@ -37,3 +37,5 @@ symbian:contains(S60_VERSION,3.2) { "$${LITERAL_HASH}endif" MMP_RULES += custom_paged_rule } + +symbian: INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE # Needed for e32svr.h in S^3 envs diff --git a/tests/auto/qpluginloader/lib/lib.pro b/tests/auto/qpluginloader/lib/lib.pro index 96a9732..ce9bf13 100644 --- a/tests/auto/qpluginloader/lib/lib.pro +++ b/tests/auto/qpluginloader/lib/lib.pro @@ -2,7 +2,7 @@ TEMPLATE = lib CONFIG += dll CONFIG -= staticlib SOURCES = mylib.c -TARGET = mylib +TARGET = tst_qpluginloaderlib DESTDIR = ../bin QT = core diff --git a/tests/auto/qpluginloader/tst/tst.pro b/tests/auto/qpluginloader/tst/tst.pro index 2de0912..2d757e7 100644 --- a/tests/auto/qpluginloader/tst/tst.pro +++ b/tests/auto/qpluginloader/tst/tst.pro @@ -20,7 +20,7 @@ wince*: { } symbian: { - libDep.sources = mylib.dll + libDep.sources = tst_qpluginloaderlib.dll libDep.path = /sys/bin pluginDep.sources = theplugin.dll pluginDep.path = bin diff --git a/tests/auto/qpluginloader/tst_qpluginloader.cpp b/tests/auto/qpluginloader/tst_qpluginloader.cpp index 705e600..e913cb5 100644 --- a/tests/auto/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/qpluginloader/tst_qpluginloader.cpp @@ -169,7 +169,7 @@ void tst_QPluginLoader::errorString() QCOMPARE(loader.errorString(), unknown); } { - QPluginLoader loader( sys_qualifiedLibraryName("mylib")); //not a plugin + QPluginLoader loader( sys_qualifiedLibraryName("tst_qpluginloaderlib")); //not a plugin bool loaded = loader.load(); #ifdef SHOW_ERRORS qDebug() << loader.errorString(); diff --git a/tests/auto/qsslsocket/qsslsocket.pro b/tests/auto/qsslsocket/qsslsocket.pro index 3557fc8..accfa89 100644 --- a/tests/auto/qsslsocket/qsslsocket.pro +++ b/tests/auto/qsslsocket/qsslsocket.pro @@ -29,6 +29,7 @@ wince* { certFiles.sources = certs ssl.tar.gz certFiles.path = . DEPLOYMENT += certFiles + INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE # Needed for e32svr.h in S^3 envs } else { DEFINES += SRCDIR=\\\"$$PWD/\\\" } diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp index 0c12974..6c1dd8f 100644 --- a/tests/auto/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp @@ -1072,6 +1072,7 @@ void tst_QSslSocket::wildcardCertificateNames() QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString("*.example.com"), QString("www.example.com")), true ); QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString("xxx*.example.com"), QString("xxxwww.example.com")), true ); QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString("f*.example.com"), QString("foo.example.com")), true ); + QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString("192.168.0.0"), QString("192.168.0.0")), true ); // Failing CN matches QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString("xxx.example.com"), QString("www.example.com")), false ); @@ -1085,6 +1086,7 @@ void tst_QSslSocket::wildcardCertificateNames() QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString("*.example."), QString("www.example")), false ); QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString(""), QString("www")), false ); QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString("*"), QString("www")), false ); + QCOMPARE( QSslSocketBackendPrivate::isMatchingHostname(QString("*.168.0.0"), QString("192.168.0.0")), false ); } void tst_QSslSocket::wildcard() diff --git a/tests/auto/qsvgrenderer/qsvgrenderer.pro b/tests/auto/qsvgrenderer/qsvgrenderer.pro index 8cfbcce..0b785e3 100644 --- a/tests/auto/qsvgrenderer/qsvgrenderer.pro +++ b/tests/auto/qsvgrenderer/qsvgrenderer.pro @@ -13,6 +13,8 @@ wince*|symbian { addFiles.path = . DEPLOYMENT += addFiles - DEPLOYMENT_PLUGIN += qsvg + wince*|qt_not_deployed { + DEPLOYMENT_PLUGIN += qsvg + } } diff --git a/tests/auto/qtextcodec/qtextcodec.pro b/tests/auto/qtextcodec/qtextcodec.pro index 0bcf067..6cb13a9 100644 --- a/tests/auto/qtextcodec/qtextcodec.pro +++ b/tests/auto/qtextcodec/qtextcodec.pro @@ -1,4 +1,4 @@ TEMPLATE = subdirs SUBDIRS = test -!wince*:SUBDIRS += echo +!wince*:!symbian:SUBDIRS += echo diff --git a/tests/auto/qtextcodec/test/test.pro b/tests/auto/qtextcodec/test/test.pro index efa2e85..b85032a 100644 --- a/tests/auto/qtextcodec/test/test.pro +++ b/tests/auto/qtextcodec/test/test.pro @@ -20,7 +20,9 @@ wince*|symbian { addFiles.sources = ../*.txt addFiles.path = . DEPLOYMENT += addFiles - DEPLOYMENT_PLUGIN += qcncodecs qjpcodecs qkrcodecs qtwcodecs + wince*|qt_not_deployed { + DEPLOYMENT_PLUGIN += qcncodecs qjpcodecs qkrcodecs qtwcodecs + } } wince*: { diff --git a/tests/auto/qtextcodec/tst_qtextcodec.cpp b/tests/auto/qtextcodec/tst_qtextcodec.cpp index 0946c93..cc41591 100644 --- a/tests/auto/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/qtextcodec/tst_qtextcodec.cpp @@ -1946,6 +1946,8 @@ void tst_QTextCodec::toLocal8Bit() { #ifdef QT_NO_PROCESS QSKIP("This test requires QProcess", SkipAll); +#elif defined(Q_OS_SYMBIAN) + QSKIP("This test requires streams support in QProcess", SkipAll); #else QProcess process; process.start("echo/echo"); diff --git a/tests/auto/qtextstream/qtextstream.pro b/tests/auto/qtextstream/qtextstream.pro index 8346d7f..a2dcc81 100644 --- a/tests/auto/qtextstream/qtextstream.pro +++ b/tests/auto/qtextstream/qtextstream.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs -SUBDIRS = test stdinProcess readAllStdinProcess readLineStdinProcess +SUBDIRS = test +!symbian: SUBDIRS += stdinProcess readAllStdinProcess readLineStdinProcess diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp index a0408ef..8d213ed 100644 --- a/tests/auto/qtimer/tst_qtimer.cpp +++ b/tests/auto/qtimer/tst_qtimer.cpp @@ -86,6 +86,7 @@ private slots: void timerIdPersistsAfterThreadExit(); void cancelLongTimer(); void singleShotStaticFunctionZeroTimeout(); + void recurseOnTimeoutAndStopTimer(); }; class TimerHelper : public QObject @@ -623,5 +624,48 @@ void tst_QTimer::singleShotStaticFunctionZeroTimeout() QCOMPARE(helper.count, 1); } +class RecursOnTimeoutAndStopTimerTimer : public QObject +{ + Q_OBJECT + +public: + QTimer *one; + QTimer *two; + +public slots: + void onetrigger() + { + QCoreApplication::processEvents(); + } + + void twotrigger() + { + one->stop(); + } +}; + +void tst_QTimer::recurseOnTimeoutAndStopTimer() +{ + QEventLoop eventLoop; + QTimer::singleShot(1000, &eventLoop, SLOT(quit())); + + RecursOnTimeoutAndStopTimerTimer t; + t.one = new QTimer(&t); + t.two = new QTimer(&t); + + QObject::connect(t.one, SIGNAL(timeout()), &t, SLOT(onetrigger())); + QObject::connect(t.two, SIGNAL(timeout()), &t, SLOT(twotrigger())); + + t.two->setSingleShot(true); + + t.one->start(); + t.two->start(); + + (void) eventLoop.exec(); + + QVERIFY(!t.one->isActive()); + QVERIFY(!t.two->isActive()); +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" diff --git a/tests/benchmarks/corelib/tools/qregexp/main.cpp b/tests/benchmarks/corelib/tools/qregexp/main.cpp index ab9ed71..51cde95 100644 --- a/tests/benchmarks/corelib/tools/qregexp/main.cpp +++ b/tests/benchmarks/corelib/tools/qregexp/main.cpp @@ -38,16 +38,27 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include <QDebug> #include <QRegExp> #include <QString> +#include <QFile> #include <qtest.h> +#ifdef HAVE_BOOST +#include <boost/regex.hpp> +#endif + +#include <QtScript> +#include "pcre/pcre.h" +#define ZLIB_VERSION "1.2.3.4" class tst_qregexp : public QObject { Q_OBJECT +public: + tst_qregexp(); private slots: void escape_old(); void escape_old_data() { escape_data(); } @@ -59,10 +70,56 @@ private slots: void escape_new3_data() { escape_data(); } void escape_new4(); void escape_new4_data() { escape_data(); } +/* + JSC outperforms everything. + Boost is less impressive then expected. + */ + void simpleFind1(); + void rangeReplace1(); + void matchReplace1(); + + void simpleFind2(); + void rangeReplace2(); + void matchReplace2(); + + void simpleFindJSC(); + void rangeReplaceJSC(); + void matchReplaceJSC(); + +#ifdef HAVE_BOOST + void simpleFindBoost(); + void rangeReplaceBoost(); + void matchReplaceBoost(); +#endif + +/* those apply an (incorrect) regexp on entire source + (this main.cpp). JSC appears to handle this + (ab)use case best. QRegExp performs extremly bad. + */ + void horribleWrongReplace1(); + void horribleReplace1(); + void horribleReplace2(); + void horribleWrongReplace2(); + void horribleWrongReplaceJSC(); + void horribleReplaceJSC(); +#ifdef HAVE_BOOST + void horribleWrongReplaceBoost(); + void horribleReplaceBoost(); +#endif private: + QString str1; + QString str2; void escape_data(); }; +tst_qregexp::tst_qregexp() + :QObject() + ,str1("We are all happy monkeys") +{ + QFile f(":/main.cpp"); + f.open(QFile::ReadOnly); + str2=f.readAll(); +} static void verify(const QString "ed, const QString &expected) { @@ -285,6 +342,253 @@ void tst_qregexp::escape_new4() // "return quoted" } } + + +void tst_qregexp::simpleFind1() +{ + int roff; + QRegExp rx("happy"); + rx.setPatternSyntax(QRegExp::RegExp); + QBENCHMARK{ + roff = rx.indexIn(str1); + } + QCOMPARE(roff, 11); +} + +void tst_qregexp::rangeReplace1() +{ + QString r; + QRegExp rx("[a-f]"); + rx.setPatternSyntax(QRegExp::RegExp); + QBENCHMARK{ + r = QString(str1).replace(rx, "-"); + } + QCOMPARE(r, QString("W- -r- -ll h-ppy monk-ys")); +} + +void tst_qregexp::matchReplace1() +{ + QString r; + QRegExp rx("[^a-f]*([a-f]+)[^a-f]*"); + rx.setPatternSyntax(QRegExp::RegExp); + QBENCHMARK{ + r = QString(str1).replace(rx, "\\1"); + } + QCOMPARE(r, QString("eaeaae")); +} + +void tst_qregexp::horribleWrongReplace1() +{ + QString r; + QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*"); + rx.setPatternSyntax(QRegExp::RegExp); + QBENCHMARK{ + r = QString(str2).replace(rx, "\\1.\\2.\\3"); + } + QCOMPARE(r, str2); +} + +void tst_qregexp::horribleReplace1() +{ + QString r; + QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*"); + rx.setPatternSyntax(QRegExp::RegExp); + QBENCHMARK{ + r = QString(str2).replace(rx, "\\1.\\2.\\3"); + } + QCOMPARE(r, QString("1.2.3")); +} + + +void tst_qregexp::simpleFind2() +{ + int roff; + QRegExp rx("happy"); + rx.setPatternSyntax(QRegExp::RegExp2); + QBENCHMARK{ + roff = rx.indexIn(str1); + } + QCOMPARE(roff, 11); +} + +void tst_qregexp::rangeReplace2() +{ + QString r; + QRegExp rx("[a-f]"); + rx.setPatternSyntax(QRegExp::RegExp2); + QBENCHMARK{ + r = QString(str1).replace(rx, "-"); + } + QCOMPARE(r, QString("W- -r- -ll h-ppy monk-ys")); +} + +void tst_qregexp::matchReplace2() +{ + QString r; + QRegExp rx("[^a-f]*([a-f]+)[^a-f]*"); + rx.setPatternSyntax(QRegExp::RegExp2); + QBENCHMARK{ + r = QString(str1).replace(rx, "\\1"); + } + QCOMPARE(r, QString("eaeaae")); +} + +void tst_qregexp::horribleWrongReplace2() +{ + QString r; + QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*"); + rx.setPatternSyntax(QRegExp::RegExp2); + QBENCHMARK{ + r = QString(str2).replace(rx, "\\1.\\2.\\3"); + } + QCOMPARE(r, str2); +} + +void tst_qregexp::horribleReplace2() +{ + QString r; + QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*"); + rx.setPatternSyntax(QRegExp::RegExp2); + QBENCHMARK{ + r = QString(str2).replace(rx, "\\1.\\2.\\3"); + } + QCOMPARE(r, QString("1.2.3")); +} + + +void tst_qregexp::simpleFindJSC() +{ + int numr; + const char * errmsg=" "; + QString rxs("happy"); + JSRegExp *rx = jsRegExpCompile(rxs.utf16(), rxs.length(), JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, 0, &errmsg); + QVERIFY(rx != 0); + QString s(str1); + int offsetVector[3]; + QBENCHMARK{ + numr = jsRegExpExecute(rx, s.utf16(), s.length(), 0, offsetVector, 3); + } + jsRegExpFree(rx); + QCOMPARE(numr, 1); + QCOMPARE(offsetVector[0], 11); +} + +void tst_qregexp::rangeReplaceJSC() +{ + QScriptValue r; + QScriptEngine engine; + engine.globalObject().setProperty("s", str1); + QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/[a-f]/g, '-') } )"); + QVERIFY(replaceFunc.isFunction()); + QBENCHMARK{ + r = replaceFunc.call(QScriptValue()); + } + QCOMPARE(r.toString(), QString("W- -r- -ll h-ppy monk-ys")); +} + +void tst_qregexp::matchReplaceJSC() +{ + QScriptValue r; + QScriptEngine engine; + engine.globalObject().setProperty("s", str1); + QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/[^a-f]*([a-f]+)[^a-f]*/g, '$1') } )"); + QVERIFY(replaceFunc.isFunction()); + QBENCHMARK{ + r = replaceFunc.call(QScriptValue()); + } + QCOMPARE(r.toString(), QString("eaeaae")); +} + +void tst_qregexp::horribleWrongReplaceJSC() +{ + QScriptValue r; + QScriptEngine engine; + engine.globalObject().setProperty("s", str2); + QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/.*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*/gm, '$1.$2.$3') } )"); + QVERIFY(replaceFunc.isFunction()); + QBENCHMARK{ + r = replaceFunc.call(QScriptValue()); + } + QCOMPARE(r.toString(), str2); +} + +void tst_qregexp::horribleReplaceJSC() +{ + QScriptValue r; + QScriptEngine engine; + // the m flag doesnt actually work here; dunno + engine.globalObject().setProperty("s", str2.replace('\n', ' ')); + QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/.*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*/gm, '$1.$2.$3') } )"); + QVERIFY(replaceFunc.isFunction()); + QBENCHMARK{ + r = replaceFunc.call(QScriptValue()); + } + QCOMPARE(r.toString(), QString("1.2.3")); +} + + +#ifdef HAVE_BOOST +void tst_qregexp::simpleFindBoost(){ + int roff; + boost::regex rx ("happy", boost::regex_constants::perl); + std::string s = str1.toStdString(); + std::string::const_iterator start, end; + start = s.begin(); + end = s.end(); + boost::match_flag_type flags = boost::match_default; + QBENCHMARK{ + boost::match_results<std::string::const_iterator> what; + regex_search(start, end, what, rx, flags); + roff = (what[0].first)-start; + } + QCOMPARE(roff, 11); +} + +void tst_qregexp::rangeReplaceBoost() +{ + boost::regex pattern ("[a-f]", boost::regex_constants::perl); + std::string s = str1.toStdString(); + std::string r; + QBENCHMARK{ + r = boost::regex_replace (s, pattern, "-"); + } + QCOMPARE(r, std::string("W- -r- -ll h-ppy monk-ys")); +} + +void tst_qregexp::matchReplaceBoost() +{ + boost::regex pattern ("[^a-f]*([a-f]+)[^a-f]*",boost::regex_constants::perl); + std::string s = str1.toStdString(); + std::string r; + QBENCHMARK{ + r = boost::regex_replace (s, pattern, "$1"); + } + QCOMPARE(r, std::string("eaeaae")); +} + +void tst_qregexp::horribleWrongReplaceBoost() +{ + boost::regex pattern (".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*", boost::regex_constants::perl); + std::string s = str2.toStdString(); + std::string r; + QBENCHMARK{ + r = boost::regex_replace (s, pattern, "$1.$2.$3"); + } + QCOMPARE(r, s); +} + +void tst_qregexp::horribleReplaceBoost() +{ + boost::regex pattern (".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*", boost::regex_constants::perl); + std::string s = str2.toStdString(); + std::string r; + QBENCHMARK{ + r = boost::regex_replace (s, pattern, "$1.$2.$3"); + } + QCOMPARE(r, std::string("1.2.3")); +} +#endif //HAVE_BOOST + QTEST_MAIN(tst_qregexp) #include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qregexp/qregexp.pro b/tests/benchmarks/corelib/tools/qregexp/qregexp.pro index e0f47c9..ffdad12 100644 --- a/tests/benchmarks/corelib/tools/qregexp/qregexp.pro +++ b/tests/benchmarks/corelib/tools/qregexp/qregexp.pro @@ -3,10 +3,19 @@ TEMPLATE = app TARGET = tst_bench_qregexp DEPENDPATH += . INCLUDEPATH += . - +RESOURCES+=qregexp.qrc QT -= gui +QT += script CONFIG += release # Input SOURCES += main.cpp + +include( $${QT_SOURCE_TREE}/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pri ) + +exists( /usr/include/boost/regex.hpp ){ +DEFINES+=HAVE_BOOST +LIBS+=-lboost_regex +} + diff --git a/tests/benchmarks/corelib/tools/qregexp/qregexp.qrc b/tests/benchmarks/corelib/tools/qregexp/qregexp.qrc new file mode 100644 index 0000000..a7fe13c --- /dev/null +++ b/tests/benchmarks/corelib/tools/qregexp/qregexp.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>main.cpp</file> +</qresource> +</RCC> + |