summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp45
-rw-r--r--tests/auto/corelib/global/qflags/tst_qflags.cpp9
-rw-r--r--tests/auto/corelib/global/qlogging/test/test.pro3
-rw-r--r--tests/auto/corelib/io/qdir/tst_qdir.cpp9
-rw-r--r--tests/auto/corelib/io/qsettings/qsettings.pro2
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp20
-rw-r--r--tests/auto/corelib/json/test.bjsonbin60992 -> 60992 bytes
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp16
-rw-r--r--tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp2
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp189
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp15
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro2
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp9
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro2
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp4
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase.pro2
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp161
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h10
-rw-r--r--tests/auto/corelib/tools/qchar/tst_qchar.cpp4
-rw-r--r--tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro3
-rw-r--r--tests/auto/corelib/tools/qlocale/test/test.pro4
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp4
-rw-r--r--tests/auto/corelib/tools/qpair/qpair.pro4
-rw-r--r--tests/auto/corelib/tools/qpair/tst_qpair.cpp105
-rw-r--r--tests/auto/corelib/tools/qregexp/tst_qregexp.cpp290
-rw-r--r--tests/auto/corelib/tools/qregularexpression/.gitignore2
-rw-r--r--tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro7
-rw-r--r--tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp64
-rw-r--r--tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro7
-rw-r--r--tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp52
-rw-r--r--tests/auto/corelib/tools/qregularexpression/qregularexpression.pro3
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp1198
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h77
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp11
-rw-r--r--tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp3
-rw-r--r--tests/auto/corelib/tools/tools.pro2
36 files changed, 2110 insertions, 230 deletions
diff --git a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
index 534dec8160..05d1569988 100644
--- a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
+++ b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
@@ -123,6 +123,7 @@ private slots:
void deletedInUpdateCurrentTime();
void totalDuration();
void zeroLoopCount();
+ void recursiveAnimations();
};
void tst_QPropertyAnimation::initTestCase()
@@ -1237,5 +1238,49 @@ void tst_QPropertyAnimation::zeroLoopCount()
QCOMPARE(finishedSpy.count(), 0);
}
+
+class RecursiveObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal x READ x WRITE setX)
+ Q_PROPERTY(qreal y READ y WRITE setY)
+public:
+ RecursiveObject() : m_x(0), m_y(0) {
+ animation.setTargetObject(this);
+ animation.setPropertyName("y");
+ animation.setDuration(30);
+ }
+ qreal x() const { return m_x; }
+ void setX(qreal x) {
+ m_x = x;
+ animation.setEndValue(x);
+ animation.start();
+ }
+ qreal y() const { return m_y; }
+ void setY(qreal y) { m_y = y; }
+
+ qreal m_x;
+ qreal m_y;
+ QPropertyAnimation animation;
+};
+
+
+void tst_QPropertyAnimation::recursiveAnimations()
+{
+ RecursiveObject o;
+ QPropertyAnimation anim;
+ anim.setTargetObject(&o);
+ anim.setPropertyName("x");
+ anim.setDuration(30);
+
+ anim.setEndValue(4000);
+ anim.start();
+ QTest::qWait(anim.duration() + o.animation.duration());
+ QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QTRY_COMPARE(o.animation.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(o.y(), qreal(4000));
+}
+
+
QTEST_MAIN(tst_QPropertyAnimation)
#include "tst_qpropertyanimation.moc"
diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp
index d466d7b8d8..2794c174ba 100644
--- a/tests/auto/corelib/global/qflags/tst_qflags.cpp
+++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp
@@ -123,6 +123,15 @@ void tst_QFlags::constExpr()
#endif
}
+// (statically) check QTypeInfo for QFlags instantiations:
+enum MyEnum { Zero, One, Two, Four=4 };
+Q_DECLARE_FLAGS( MyFlags, MyEnum );
+Q_DECLARE_OPERATORS_FOR_FLAGS( MyFlags );
+
+Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isComplex );
+Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isStatic );
+Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isLarge );
+Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isPointer );
QTEST_MAIN(tst_QFlags)
#include "tst_qflags.moc"
diff --git a/tests/auto/corelib/global/qlogging/test/test.pro b/tests/auto/corelib/global/qlogging/test/test.pro
index 6e4939ffc9..6e9b86d753 100644
--- a/tests/auto/corelib/global/qlogging/test/test.pro
+++ b/tests/auto/corelib/global/qlogging/test/test.pro
@@ -2,3 +2,6 @@ CONFIG += testcase parallel_test
TARGET = ../tst_qlogging
QT = core testlib
SOURCES = ../tst_qlogging.cpp
+
+load(testcase) # for target.path and installTestHelperApp()
+installTestHelperApp("../app/app",app,app)
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp
index 04967d8313..b7fc366a39 100644
--- a/tests/auto/corelib/io/qdir/tst_qdir.cpp
+++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp
@@ -1214,7 +1214,8 @@ void tst_QDir::remove()
f.close();
QDir dir;
QVERIFY(dir.remove("remove-test"));
- QVERIFY(!dir.remove("/remove-test"));
+ // Test that the file just removed is gone
+ QVERIFY(!dir.remove("remove-test"));
QTest::ignoreMessage(QtWarningMsg, "QDir::remove: Empty or null file name");
QVERIFY(!dir.remove(""));
}
@@ -1231,8 +1232,14 @@ void tst_QDir::rename()
QVERIFY(!dir.rename("rename-test", "/etc/rename-test-renamed"));
#elif !defined(Q_OS_WIN)
// on windows this is possible - maybe make the test a bit better
+#ifdef Q_OS_UNIX
+ // not valid if run as root so skip if needed
+ if (::getuid() != 0)
+ QVERIFY(!dir.rename("rename-test", "/rename-test-renamed"));
+#else
QVERIFY(!dir.rename("rename-test", "/rename-test-renamed"));
#endif
+#endif
QTest::ignoreMessage(QtWarningMsg, "QDir::rename: Empty or null file name(s)");
QVERIFY(!dir.rename("rename-test", ""));
QTest::ignoreMessage(QtWarningMsg, "QDir::rename: Empty or null file name(s)");
diff --git a/tests/auto/corelib/io/qsettings/qsettings.pro b/tests/auto/corelib/io/qsettings/qsettings.pro
index 9de476fe13..1772f4b65f 100644
--- a/tests/auto/corelib/io/qsettings/qsettings.pro
+++ b/tests/auto/corelib/io/qsettings/qsettings.pro
@@ -5,5 +5,3 @@ SOURCES = tst_qsettings.cpp
RESOURCES += qsettings.qrc
win32-msvc*:LIBS += advapi32.lib
-
-win32: CONFIG += insignificant_test # QTBUG-24145
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index a74d817b8a..3bff330db2 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -262,9 +262,16 @@ void tst_QUrl::hashInPath()
QCOMPARE(withHashInPath.path(), QString::fromLatin1("hi#mum.txt"));
QCOMPARE(withHashInPath.toEncoded(), QByteArray("hi%23mum.txt"));
QCOMPARE(withHashInPath.toString(), QString("hi%23mum.txt"));
+ QCOMPARE(withHashInPath.toDisplayString(QUrl::PreferLocalFile), QString("hi%23mum.txt"));
QUrl fromHashInPath = QUrl::fromEncoded(withHashInPath.toEncoded());
QVERIFY(withHashInPath == fromHashInPath);
+
+ const QUrl localWithHash = QUrl::fromLocalFile("/hi#mum.txt");
+ QCOMPARE(localWithHash.path(), QString::fromLatin1("/hi#mum.txt"));
+ QCOMPARE(localWithHash.toEncoded(), QByteArray("file:///hi%23mum.txt"));
+ QCOMPARE(localWithHash.toString(), QString("file:///hi%23mum.txt"));
+ QCOMPARE(localWithHash.toDisplayString(QUrl::PreferLocalFile), QString("/hi#mum.txt"));
}
void tst_QUrl::unc()
@@ -352,6 +359,7 @@ void tst_QUrl::setUrl()
QCOMPARE(url.port(), -1);
QCOMPARE(url.toString(), QString::fromLatin1("file:///"));
QCOMPARE(url.toDisplayString(), QString::fromLatin1("file:///"));
+ QCOMPARE(url.toDisplayString(QUrl::PreferLocalFile), QString::fromLatin1("/"));
}
{
@@ -367,6 +375,7 @@ void tst_QUrl::setUrl()
QCOMPARE(url.port(), 80);
QCOMPARE(url.toString(), QString::fromLatin1("http://www.foo.bar:80"));
QCOMPARE(url.toDisplayString(), QString::fromLatin1("http://www.foo.bar:80"));
+ QCOMPARE(url.toDisplayString(QUrl::PreferLocalFile), QString::fromLatin1("http://www.foo.bar:80"));
QUrl url2("//www1.foo.bar");
QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("http://www1.foo.bar"));
@@ -451,15 +460,7 @@ void tst_QUrl::setUrl()
QUrl url = u1;
QVERIFY(url.isValid());
QCOMPARE(url.toString(), QString::fromLatin1("file:///home/dfaure/my#myref"));
- QCOMPARE(url.fragment(), QString::fromLatin1("myref"));
- }
-
- {
- QString u1 = "file:/home/dfaure/my#myref";
- QUrl url = u1;
- QVERIFY(url.isValid());
-
- QCOMPARE(url.toString(), QString::fromLatin1("file:///home/dfaure/my#myref"));
+ QCOMPARE(url.toString(QUrl::PreferLocalFile), QString::fromLatin1("file:///home/dfaure/my#myref"));
QCOMPARE(url.fragment(), QString::fromLatin1("myref"));
}
@@ -1001,6 +1002,7 @@ void tst_QUrl::toLocalFile()
QUrl url(theUrl);
QCOMPARE(url.toLocalFile(), theFile);
+ QCOMPARE(url.isLocalFile(), !theFile.isEmpty());
}
void tst_QUrl::fromLocalFile_data()
diff --git a/tests/auto/corelib/json/test.bjson b/tests/auto/corelib/json/test.bjson
index aa412eec67..9a0515f3ef 100644
--- a/tests/auto/corelib/json/test.bjson
+++ b/tests/auto/corelib/json/test.bjson
Binary files differ
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index f5b4f17732..f35831c900 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -115,6 +115,8 @@ private Q_SLOTS:
void testCompaction();
void testDebugStream();
void testCompactionError();
+
+ void parseUnicodeEscapes();
private:
QString testDataDir;
};
@@ -1758,5 +1760,19 @@ void TestQtJson::testCompactionError()
}
}
+void TestQtJson::parseUnicodeEscapes()
+{
+ const QByteArray json = "[ \"A\\u00e4\\u00C4\" ]";
+
+ QJsonDocument doc = QJsonDocument::fromJson(json);
+ QJsonArray array = doc.array();
+
+ QString result = QLatin1String("A");
+ result += QChar(0xe4);
+ result += QChar(0xc4);
+
+ QCOMPARE(array.first().toString(), result);
+}
+
QTEST_MAIN(TestQtJson)
#include "tst_qtjson.moc"
diff --git a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
index e2144134d9..61484c1736 100644
--- a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
+++ b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
@@ -132,7 +132,7 @@ public:
class StartStopEvent: public QEvent
{
public:
- StartStopEvent(int type, QEventLoop *loop = 0)
+ explicit StartStopEvent(int type, QEventLoop *loop = 0)
: QEvent(Type(type)), el(loop)
{ }
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 4f283cef90..84d28c7959 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -100,12 +100,29 @@ private slots:
struct Foo { int i; };
+
+class CustomQObject : public QObject
+{
+ Q_OBJECT
+public:
+ CustomQObject(QObject *parent = 0)
+ : QObject(parent)
+ {
+ }
+};
+
+class CustomNonQObject {};
+
void tst_QMetaType::defined()
{
QCOMPARE(int(QMetaTypeId2<QString>::Defined), 1);
QCOMPARE(int(QMetaTypeId2<Foo>::Defined), 0);
QCOMPARE(int(QMetaTypeId2<void*>::Defined), 1);
QCOMPARE(int(QMetaTypeId2<int*>::Defined), 0);
+ QVERIFY(QMetaTypeId2<CustomQObject*>::Defined);
+ QVERIFY(!QMetaTypeId2<CustomQObject>::Defined);
+ QVERIFY(!QMetaTypeId2<CustomNonQObject>::Defined);
+ QVERIFY(!QMetaTypeId2<CustomNonQObject*>::Defined);
}
struct Bar
@@ -685,6 +702,36 @@ public:
};
Q_DECLARE_METATYPE(CustomMultiInheritanceObject*);
+class C { char _[4]; };
+class M { char _[4]; };
+class P { char _[4]; };
+
+QT_BEGIN_NAMESPACE
+Q_DECLARE_TYPEINFO(M, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(P, Q_PRIMITIVE_TYPE);
+QT_END_NAMESPACE
+
+// avoid the comma:
+typedef QPair<C,C> QPairCC;
+typedef QPair<C,M> QPairCM;
+typedef QPair<C,P> QPairCP;
+typedef QPair<M,C> QPairMC;
+typedef QPair<M,M> QPairMM;
+typedef QPair<M,P> QPairMP;
+typedef QPair<P,C> QPairPC;
+typedef QPair<P,M> QPairPM;
+typedef QPair<P,P> QPairPP;
+
+Q_DECLARE_METATYPE(QPairCC)
+Q_DECLARE_METATYPE(QPairCM)
+Q_DECLARE_METATYPE(QPairCP)
+Q_DECLARE_METATYPE(QPairMC)
+Q_DECLARE_METATYPE(QPairMM)
+Q_DECLARE_METATYPE(QPairMP)
+Q_DECLARE_METATYPE(QPairPC)
+Q_DECLARE_METATYPE(QPairPM)
+Q_DECLARE_METATYPE(QPairPP)
+
void tst_QMetaType::flags_data()
{
QTest::addColumn<int>("type");
@@ -703,6 +750,15 @@ QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW)
QTest::newRow("CustomMovable") << ::qMetaTypeId<CustomMovable>() << true << true << false;
QTest::newRow("CustomObject*") << ::qMetaTypeId<CustomObject*>() << true << false << true;
QTest::newRow("CustomMultiInheritanceObject*") << ::qMetaTypeId<CustomMultiInheritanceObject*>() << true << false << true;
+ QTest::newRow("QPair<C,C>") << ::qMetaTypeId<QPair<C,C> >() << false << true << false;
+ QTest::newRow("QPair<C,M>") << ::qMetaTypeId<QPair<C,M> >() << false << true << false;
+ QTest::newRow("QPair<C,P>") << ::qMetaTypeId<QPair<C,P> >() << false << true << false;
+ QTest::newRow("QPair<M,C>") << ::qMetaTypeId<QPair<M,C> >() << false << true << false;
+ QTest::newRow("QPair<M,M>") << ::qMetaTypeId<QPair<M,M> >() << true << true << false;
+ QTest::newRow("QPair<M,P>") << ::qMetaTypeId<QPair<M,P> >() << true << true << false;
+ QTest::newRow("QPair<P,C>") << ::qMetaTypeId<QPair<P,C> >() << false << true << false;
+ QTest::newRow("QPair<P,M>") << ::qMetaTypeId<QPair<P,M> >() << true << true << false;
+ QTest::newRow("QPair<P,P>") << ::qMetaTypeId<QPair<P,P> >() << true << false << false;
}
void tst_QMetaType::flags()
@@ -1018,6 +1074,61 @@ void tst_QMetaType::registerStreamBuiltin()
Q_DECLARE_METATYPE(QSharedPointer<QObject>)
+typedef QHash<int, uint> IntUIntHash;
+Q_DECLARE_METATYPE(IntUIntHash)
+typedef QMap<int, uint> IntUIntMap;
+Q_DECLARE_METATYPE(IntUIntMap)
+typedef QPair<int, uint> IntUIntPair;
+Q_DECLARE_METATYPE(IntUIntPair)
+
+struct CustomComparable
+{
+ CustomComparable(int i_ = 0) :i(i_) { }
+ bool operator==(const CustomComparable &other) const
+ {
+ return i == other.i;
+ }
+ int i;
+};
+
+struct UnregisteredType {};
+
+typedef QHash<int, CustomComparable> IntComparableHash;
+Q_DECLARE_METATYPE(IntComparableHash)
+typedef QMap<int, CustomComparable> IntComparableMap;
+Q_DECLARE_METATYPE(IntComparableMap)
+typedef QPair<int, CustomComparable> IntComparablePair;
+Q_DECLARE_METATYPE(IntComparablePair)
+
+typedef QHash<int, int> IntIntHash;
+typedef int NaturalNumber;
+class AutoMetaTypeObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(IntIntHash someHash READ someHash CONSTANT)
+ Q_PROPERTY(NaturalNumber someInt READ someInt CONSTANT)
+public:
+ AutoMetaTypeObject(QObject *parent = 0)
+ : QObject(parent), m_int(42)
+ {
+ m_hash.insert(4, 2);
+ }
+
+ QHash<int,int> someHash() const
+ {
+ return m_hash;
+ }
+
+ int someInt() const
+ {
+ return m_int;
+ }
+
+private:
+ QHash<int,int> m_hash;
+ int m_int;
+};
+
void tst_QMetaType::automaticTemplateRegistration()
{
{
@@ -1059,6 +1170,84 @@ void tst_QMetaType::automaticTemplateRegistration()
vectorList << sharedPointerList;
QVERIFY(QVariant::fromValue(vectorList).value<QVector<QList<QSharedPointer<QObject> > > >().first().first() == testObject);
}
+ {
+ IntIntHash intIntHash;
+ intIntHash.insert(4, 2);
+ QCOMPARE(QVariant::fromValue(intIntHash).value<IntIntHash>().value(4), 2);
+
+ AutoMetaTypeObject amto;
+
+ qRegisterMetaType<QHash<int, int> >("IntIntHash");
+ QVariant hashVariant = amto.property("someHash");
+ QCOMPARE(hashVariant.value<IntIntHash>().value(4), 2);
+
+ qRegisterMetaType<int>("NaturalNumber");
+ QVariant intVariant = amto.property("someInt");
+ QCOMPARE(intVariant.value<NaturalNumber>(), 42);
+ }
+ {
+ IntUIntHash intUIntHash;
+ intUIntHash.insert(4, 2);
+ QCOMPARE(QVariant::fromValue(intUIntHash).value<IntUIntHash>().value(4), (uint)2);
+ }
+ {
+ IntComparableHash intComparableHash;
+ CustomComparable m;
+ intComparableHash.insert(4, m);
+ QCOMPARE(QVariant::fromValue(intComparableHash).value<IntComparableHash>().value(4), m);
+ }
+ {
+ QVariantHash variantHash;
+ variantHash.insert(QStringLiteral("4"), 2);
+ QCOMPARE(QVariant::fromValue(variantHash).value<QVariantHash>().value(QStringLiteral("4")), QVariant(2));
+ }
+ {
+ typedef QMap<int, int> IntIntMap;
+ IntIntMap intIntMap;
+ intIntMap.insert(4, 2);
+ QCOMPARE(QVariant::fromValue(intIntMap).value<IntIntMap>().value(4), 2);
+ }
+ {
+ IntUIntMap intUIntMap;
+ intUIntMap.insert(4, 2);
+ QCOMPARE(QVariant::fromValue(intUIntMap).value<IntUIntMap>().value(4), (uint)2);
+ }
+ {
+ IntComparableMap intComparableMap;
+ CustomComparable m;
+ intComparableMap.insert(4, m);
+ QCOMPARE(QVariant::fromValue(intComparableMap).value<IntComparableMap>().value(4), m);
+ }
+ {
+ QVariantMap variantMap;
+ variantMap.insert(QStringLiteral("4"), 2);
+ QCOMPARE(QVariant::fromValue(variantMap).value<QVariantMap>().value(QStringLiteral("4")), QVariant(2));
+ }
+ {
+ typedef QPair<int, int> IntIntPair;
+ IntIntPair intIntPair = qMakePair(4, 2);
+ QCOMPARE(QVariant::fromValue(intIntPair).value<IntIntPair>().first, 4);
+ QCOMPARE(QVariant::fromValue(intIntPair).value<IntIntPair>().second, 2);
+ }
+ {
+ IntUIntPair intUIntPair = qMakePair<int, uint>(4, 2);
+ QCOMPARE(QVariant::fromValue(intUIntPair).value<IntUIntPair>().first, 4);
+ QCOMPARE(QVariant::fromValue(intUIntPair).value<IntUIntPair>().second, (uint)2);
+ }
+ {
+ CustomComparable m;
+ IntComparablePair intComparablePair = qMakePair(4, m);
+ QCOMPARE(QVariant::fromValue(intComparablePair).value<IntComparablePair>().first, 4);
+ QCOMPARE(QVariant::fromValue(intComparablePair).value<IntComparablePair>().second, m);
+ }
+ {
+ typedef QHash<int, UnregisteredType> IntUnregisteredTypeHash;
+ QVERIFY(qRegisterMetaType<IntUnregisteredTypeHash>("IntUnregisteredTypeHash") > 0);
+ }
+ {
+ typedef QList<UnregisteredType> UnregisteredTypeList;
+ QVERIFY(qRegisterMetaType<UnregisteredTypeList>("UnregisteredTypeList") > 0);
+ }
}
// Compile-time test, it should be possible to register function pointer types
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index ffe1d2bec4..c48a384e58 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -2541,9 +2541,24 @@ public:
};
Q_DECLARE_METATYPE(CustomQObjectDerived*)
+class CustomQObjectDerivedNoMetaType : public CustomQObject {
+ Q_OBJECT
+public:
+ CustomQObjectDerivedNoMetaType(QObject *parent = 0) : CustomQObject(parent) {}
+};
+
void tst_QVariant::qvariant_cast_QObject_derived()
{
{
+ CustomQObjectDerivedNoMetaType *object = new CustomQObjectDerivedNoMetaType(this);
+ QVariant data = QVariant::fromValue(object);
+ QVERIFY(data.userType() == qMetaTypeId<CustomQObjectDerivedNoMetaType*>());
+ QCOMPARE(data.value<QObject *>(), object);
+ QCOMPARE(data.value<CustomQObjectDerivedNoMetaType *>(), object);
+ QCOMPARE(data.value<CustomQObject *>(), object);
+ QVERIFY(data.value<CustomQWidget*>() == 0);
+ }
+ {
CustomQObjectDerived *object = new CustomQObjectDerived(this);
QVariant data = QVariant::fromValue(object);
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro
index 815401ce1e..ba68167a6f 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro
@@ -7,6 +7,6 @@ QT = core testlib concurrent
SOURCES = tst_qmimedatabase-cache.cpp
HEADERS = ../tst_qmimedatabase.h
-DEFINES += SRCDIR='"\\"$$PWD/../\\""'
+DEFINES += CORE_SOURCES='"\\"$$QT.core.sources\\""'
*-g++*:QMAKE_CXXFLAGS += -W -Wall -Wextra -Werror -Wshadow -Wno-long-long -Wnon-virtual-dtor
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp
index 205331d4dd..5ef04dc01d 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp
@@ -47,10 +47,9 @@
#include "../tst_qmimedatabase.cpp"
-tst_QMimeDatabase::tst_QMimeDatabase()
+void tst_QMimeDatabase::init()
{
- QDir here = QDir::currentPath();
- const QString tempMime = here.absolutePath() + QString::fromLatin1("/mime");
- runUpdateMimeDatabase(tempMime);
- QVERIFY(QFile::exists(tempMime + QString::fromLatin1("/mime.cache")));
+ const QString mimeDirName = m_globalXdgDir + QStringLiteral("/mime");
+ runUpdateMimeDatabase(mimeDirName);
+ QVERIFY(QFile::exists(mimeDirName + QStringLiteral("/mime.cache")));
}
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro
index ac7515f781..4c00e84fc1 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro
@@ -9,6 +9,6 @@ CONFIG += depend_includepath
SOURCES += tst_qmimedatabase-xml.cpp
HEADERS += ../tst_qmimedatabase.h
-DEFINES += SRCDIR='"\\"$$PWD/../\\""'
+DEFINES += CORE_SOURCES='"\\"$$QT.core.sources\\""'
*-g++*:QMAKE_CXXFLAGS += -W -Wall -Wextra -Werror -Wshadow -Wno-long-long -Wnon-virtual-dtor
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp
index 13ca372290..30c7677198 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp
@@ -40,10 +40,8 @@
****************************************************************************/
#include "../tst_qmimedatabase.h"
-#include <QDebug>
-#include <QDir>
-tst_QMimeDatabase::tst_QMimeDatabase()
+void tst_QMimeDatabase::init()
{
qputenv("QT_NO_MIME_CACHE", "1");
}
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase.pro b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase.pro
index 876b4377dd..1ff5546e5c 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase.pro
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase.pro
@@ -1,3 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = qmimedatabase-xml
-unix: SUBDIRS += qmimedatabase-cache
+unix:!mac: SUBDIRS += qmimedatabase-cache
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
index 858f977a72..9076f37c7c 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
@@ -44,49 +44,85 @@
#include "qstandardpaths.h"
#include <QtCore/QFile>
+#include <QtCore/QFileInfo>
+#include <QtCore/QTextStream>
#include <QtConcurrent/QtConcurrentRun>
#include <QtConcurrent/QFuture>
#include <QtTest/QtTest>
+static const char yastFileName[] ="yast2-metapackage-handler-mimetypes.xml";
+
void initializeLang()
{
qputenv("LC_ALL", "");
qputenv("LANG", "en_US");
+ QCoreApplication::setApplicationName("tst_qmimedatabase"); // temporary directory pattern
+}
+
+static inline QString testSuiteWarning()
+{
+
+ QString result;
+ QTextStream str(&result);
+ str << "\nCannot find the shared-mime-info test suite\nstarting from: "
+ << QDir::toNativeSeparators(QDir::currentPath()) << "\n"
+ "cd " << QDir::toNativeSeparators(QStringLiteral("tests/auto/corelib/mimetypes/qmimedatabase")) << "\n"
+ "wget http://cgit.freedesktop.org/xdg/shared-mime-info/snapshot/Release-1-0.zip\n"
+ "unzip Release-1-0.zip\n";
+#ifdef Q_OS_WIN
+ str << "mkdir testfiles\nxcopy /s Release-1-0\\tests testfiles\n";
+#else
+ str << "ln -s Release-1-0/tests testfiles\n";
+#endif
+ return result;
}
// Set LANG before QCoreApplication is created
Q_CONSTRUCTOR_FUNCTION(initializeLang)
+tst_QMimeDatabase::tst_QMimeDatabase()
+{
+}
+
void tst_QMimeDatabase::initTestCase()
{
+ QVERIFY(m_temporaryDir.isValid());
+
// Create a "global" and a "local" XDG data dir, right here.
// The local dir will be empty initially, while the global dir will contain a copy of freedesktop.org.xml
- QDir here = QDir::currentPath();
+ const QDir here = QDir(m_temporaryDir.path());
- qputenv("XDG_DATA_DIRS", QFile::encodeName(here.absolutePath()));
- QDir(here.absolutePath() + "/mime").removeRecursively();
- here.mkpath(QString::fromLatin1("mime/packages"));
+ m_globalXdgDir = m_temporaryDir.path() + QStringLiteral("/global");
+ m_localXdgDir = m_temporaryDir.path() + QStringLiteral("/local");
- QFile xml(QFile::decodeName(SRCDIR "../../../src/mimetypes/mime/packages/freedesktop.org.xml"));
- const QString mimeDir = here.absolutePath() + QLatin1String("/mime");
- xml.copy(mimeDir + QLatin1String("/packages/freedesktop.org.xml"));
+ const QString globalPackageDir = m_globalXdgDir + QStringLiteral("/mime/packages");
+ QVERIFY(here.mkpath(globalPackageDir) && here.mkpath(m_localXdgDir));
- m_dataHome = here.absolutePath() + QLatin1String("/../datahome");
- qputenv("XDG_DATA_HOME", QFile::encodeName(m_dataHome));
- //qDebug() << "XDG_DATA_HOME=" << m_dataHome;
+ qputenv("XDG_DATA_DIRS", QFile::encodeName(m_globalXdgDir));
+ qputenv("XDG_DATA_HOME", QFile::encodeName(m_localXdgDir));
+ qDebug() << "\nLocal XDG_DATA_HOME: " << m_localXdgDir
+ << "\nGlobal XDG_DATA_DIRS: " << m_globalXdgDir;
- // Make sure we start clean
- cleanupTestCase();
-}
+ const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml");
+ const QString xmlFileName = QLatin1String(CORE_SOURCES)
+ + QStringLiteral("/mimetypes/mime/packages/")
+ + freeDesktopXml;
+ QVERIFY2(QFileInfo(xmlFileName).exists(), qPrintable(xmlFileName + QStringLiteral(" does not exist")));
+ QFile xml(xmlFileName);
+ QVERIFY(xml.copy(globalPackageDir + '/' + freeDesktopXml));
-void tst_QMimeDatabase::cleanupTestCase()
-{
- QDir here = QDir::currentPath();
- here.remove(QString::fromLatin1("mime/packages/yast2-metapackage-handler-mimetypes.xml"));
+ m_testSuite = QFINDTESTDATA("testfiles");
+ if (m_testSuite.isEmpty())
+ qWarning("%s", qPrintable(testSuiteWarning()));
+
+ m_yastMimeTypes = QFINDTESTDATA(yastFileName);
+ QVERIFY2(!m_yastMimeTypes.isEmpty(),
+ qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'").
+ arg(yastFileName, QDir::currentPath())));
- QDir(m_dataHome).removeRecursively();
+ init();
}
void tst_QMimeDatabase::mimeTypeForName()
@@ -171,6 +207,20 @@ void tst_QMimeDatabase::mimeTypeForFileName_data()
QTest::newRow("directory") << "/" << "inode/directory";
QTest::newRow("doesn't exist, no extension") << "IDontExist" << "application/octet-stream";
QTest::newRow("doesn't exist but has known extension") << "IDontExist.txt" << "text/plain";
+ QTest::newRow("empty") << "" << "application/octet-stream";
+}
+
+static inline QByteArray msgMimeTypeForFileNameFailed(const QList<QMimeType> &actual,
+ const QString &expected)
+{
+ QByteArray result = "Actual (";
+ foreach (const QMimeType &m, actual) {
+ result += m.name().toLocal8Bit();
+ result += ' ';
+ }
+ result += ") , expected: ";
+ result += expected.toLocal8Bit();
+ return result;
}
void tst_QMimeDatabase::mimeTypeForFileName()
@@ -186,8 +236,8 @@ void tst_QMimeDatabase::mimeTypeForFileName()
if (expectedMimeType == "application/octet-stream") {
QVERIFY(mimes.isEmpty());
} else {
- QVERIFY(!mimes.isEmpty());
- QCOMPARE(mimes.count(), 1);
+ QVERIFY2(!mimes.isEmpty(), msgMimeTypeForFileNameFailed(mimes, expectedMimeType).constData());
+ QVERIFY2(mimes.count() == 1, msgMimeTypeForFileNameFailed(mimes, expectedMimeType).constData());
QCOMPARE(mimes.first().name(), expectedMimeType);
}
}
@@ -549,20 +599,14 @@ void tst_QMimeDatabase::findByFileName_data()
QTest::addColumn<QString>("mimeTypeName");
QTest::addColumn<QString>("xFail");
- QString prefix = QLatin1String(SRCDIR "testfiles/");
-
- QFile f(prefix + QLatin1String("list"));
- if (!f.open(QIODevice::ReadOnly)) {
- const QString warning = QString::fromLatin1(
- "Please download the shared-mime-info test suite:\n"
- "cd tests/auto/corelib/mimetypes/qmimedatabase\n"
- "wget http://cgit.freedesktop.org/xdg/shared-mime-info/snapshot/Release-1-0.zip\n"
- "unzip Release-1-0.zip\n"
- "ln -s Release-1-0/tests testfiles\n"
- );
- qWarning() << warning;
+ if (m_testSuite.isEmpty())
QSKIP("shared-mime-info test suite not available.");
- }
+
+ const QString prefix = m_testSuite + QLatin1Char('/');
+ const QString fileName = prefix + QLatin1String("list");
+ QFile f(fileName);
+ QVERIFY2(f.open(QIODevice::ReadOnly|QIODevice::Text),
+ qPrintable(QString::fromLatin1("Cannot open %1: %2").arg(fileName, f.errorString())));
QByteArray line(1024, Qt::Uninitialized);
@@ -582,7 +626,9 @@ void tst_QMimeDatabase::findByFileName_data()
if (list.size() >= 3)
xFail = list.at(2);
- QTest::newRow(filePath.toLatin1().constData()) << QString(prefix + filePath) << mimeTypeType << xFail;
+ QTest::newRow(filePath.toLatin1().constData())
+ << QString(prefix + filePath)
+ << mimeTypeType << xFail;
}
}
@@ -676,6 +722,9 @@ void tst_QMimeDatabase::findByFile_data()
findByFileName_data();
}
+// Note: this test fails on "testcompress.z" when using a shared-mime-info older than 1.0.
+// This because of commit 0f9a506069c in shared-mime-info, which fixed the writing of
+// case-insensitive patterns into mime.cache.
void tst_QMimeDatabase::findByFile()
{
QFETCH(QString, filePath);
@@ -717,13 +766,21 @@ void tst_QMimeDatabase::fromThreads()
static bool runUpdateMimeDatabase(const QString &path) // TODO make it a QMimeDatabase method?
{
- const QString umd = QStandardPaths::findExecutable(QString::fromLatin1("update-mime-database"));
- if (umd.isEmpty())
+ const QString umdCommand = QString::fromLatin1("update-mime-database");
+ const QString umd = QStandardPaths::findExecutable(umdCommand);
+ if (umd.isEmpty()) {
+ qWarning("%s does not exist.", qPrintable(umdCommand));
return false;
+ }
QProcess proc;
proc.setProcessChannelMode(QProcess::MergedChannels); // silence output
- proc.start(umd, QStringList() << path);
+ proc.start(umd, QStringList(path));
+ if (!proc.waitForStarted()) {
+ qWarning("Cannot start %s: %s",
+ qPrintable(umd), qPrintable(proc.errorString()));
+ return false;
+ }
proc.waitForFinished();
//qDebug() << "runUpdateMimeDatabase" << path;
return true;
@@ -733,7 +790,7 @@ static bool waitAndRunUpdateMimeDatabase(const QString &path)
{
QFileInfo mimeCacheInfo(path + QString::fromLatin1("/mime.cache"));
if (mimeCacheInfo.exists()) {
- // Wait until the begining of the next second
+ // Wait until the beginning of the next second
while (mimeCacheInfo.lastModified().secsTo(QDateTime::currentDateTime()) == 0) {
QTest::qSleep(200);
}
@@ -767,16 +824,15 @@ void tst_QMimeDatabase::installNewGlobalMimeType()
QMimeDatabase db;
QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid());
- const QString fileName = QLatin1String("yast2-metapackage-handler-mimetypes.xml");
- const QString srcFile = QFile::decodeName(SRCDIR) + fileName;
-
- QDir here = QDir::currentPath();
- const QString mimeDir = here.absolutePath() + QLatin1String("/mime");
+ const QString mimeDir = m_globalXdgDir + QLatin1String("/mime");
const QString destDir = mimeDir + QLatin1String("/packages/");
- const QString destFile = destDir + fileName;
+ const QString destFile = destDir + QLatin1String(yastFileName);
QFile::remove(destFile);
//qDebug() << destFile;
- QVERIFY(QFile::copy(srcFile, destFile));
+
+ if (!QFileInfo(destDir).isDir())
+ QVERIFY(QDir(m_globalXdgDir).mkpath(destDir));
+ QVERIFY(QFile::copy(m_yastMimeTypes, destFile));
if (!waitAndRunUpdateMimeDatabase(mimeDir))
QSKIP("shared-mime-info not found, skipping mime.cache test");
@@ -801,16 +857,17 @@ void tst_QMimeDatabase::installNewLocalMimeType()
QMimeDatabase db;
QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid());
- const QString fileName = QLatin1String("yast2-metapackage-handler-mimetypes.xml");
- const QString srcFile = QFile::decodeName(SRCDIR) + fileName;
- const QString mimeDir = m_dataHome + QLatin1String("/mime");
+ const QString mimeDir = m_localXdgDir + QLatin1String("/mime");
const QString destDir = mimeDir + QLatin1String("/packages/");
QDir().mkpath(destDir);
- const QString destFile = destDir + fileName;
+ const QString destFile = destDir + QLatin1String(yastFileName);
QFile::remove(destFile);
- QVERIFY(QFile::copy(srcFile, destFile));
- if (!runUpdateMimeDatabase(mimeDir))
- QSKIP("shared-mime-info not found, skipping mime.cache test");;
+ QVERIFY(QFile::copy(m_yastMimeTypes, destFile));
+ if (!runUpdateMimeDatabase(mimeDir)) {
+ const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (")
+ + QDir::toNativeSeparators(mimeDir) + QLatin1Char(')');
+ QSKIP(qPrintable(skipWarning));
+ }
QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(),
QString::fromLatin1("text/x-suse-ymu"));
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h
index 869990401c..94baf77ee9 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h
@@ -43,6 +43,7 @@
#define TST_QMIMEDATABASE_H
#include <QtCore/QObject>
+#include <QtCore/QTemporaryDir>
class tst_QMimeDatabase : public QObject
{
@@ -53,7 +54,6 @@ public:
private slots:
void initTestCase();
- void cleanupTestCase();
void mimeTypeForName();
void mimeTypeForFileName_data();
@@ -93,7 +93,13 @@ private slots:
void installNewLocalMimeType();
private:
- QString m_dataHome;
+ void init(); // test-specific
+
+ QString m_globalXdgDir;
+ QString m_localXdgDir;
+ QString m_yastMimeTypes;
+ QTemporaryDir m_temporaryDir;
+ QString m_testSuite;
};
#endif // TST_QMIMEDATABASE_H
diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
index 1732f628ea..e72af11fbb 100644
--- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
@@ -580,7 +580,9 @@ void tst_QChar::normalization_data()
int linenum = 0;
int part = 0;
- QFile f(QFINDTESTDATA("NormalizationTest.txt"));
+ QString testFile = QFINDTESTDATA("NormalizationTest.txt");
+ QVERIFY2(!testFile.isEmpty(), "NormalizationTest.txt not found!");
+ QFile f(testFile);
QVERIFY(f.exists());
f.open(QIODevice::ReadOnly);
diff --git a/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro b/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro
index a97350ca3f..b61f51d53a 100644
--- a/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro
+++ b/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro
@@ -6,6 +6,3 @@ CONFIG -= app_bundle
QT = core
-# This app is testdata for tst_qlocale
-target.path = $$[QT_INSTALL_TESTS]/tst_qlocale/$$TARGET
-INSTALLS += target
diff --git a/tests/auto/corelib/tools/qlocale/test/test.pro b/tests/auto/corelib/tools/qlocale/test/test.pro
index eafd8c1699..24dcc0638a 100644
--- a/tests/auto/corelib/tools/qlocale/test/test.pro
+++ b/tests/auto/corelib/tools/qlocale/test/test.pro
@@ -12,6 +12,8 @@ win32 {
TARGET = ../../release/tst_qlocale
}
}
-TESTDATA += syslocaleapp
+
+load(testcase) # for target.path and installTestHelperApp()
+installTestHelperApp("../syslocaleapp/syslocaleapp",syslocaleapp,syslocaleapp)
mac: CONFIG += insignificant_test # QTBUG-22769
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index 02acb00548..b3b573c64b 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -809,11 +809,7 @@ void tst_QLocale::negativeZero()
{
double negativeZero( 0.0 ); // Initialise to zero.
uchar *ptr = (uchar *)&negativeZero;
-#ifdef QT_ARMFPA
- ptr[3] = 0x80;
-#else
ptr[QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 7] = 0x80;
-#endif
QString s = QString::number(negativeZero);
QCOMPARE(s, QString("0"));
}
diff --git a/tests/auto/corelib/tools/qpair/qpair.pro b/tests/auto/corelib/tools/qpair/qpair.pro
new file mode 100644
index 0000000000..9c7752327e
--- /dev/null
+++ b/tests/auto/corelib/tools/qpair/qpair.pro
@@ -0,0 +1,4 @@
+CONFIG += testcase parallel_test
+TARGET = tst_qpair
+QT = core testlib
+SOURCES = tst_qpair.cpp
diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp
new file mode 100644
index 0000000000..5de1e8f8bb
--- /dev/null
+++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QPair>
+
+class tst_QPair : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void dummy() {}
+};
+
+class C { char _[4]; };
+class M { char _[4]; };
+class P { char _[4]; };
+
+QT_BEGIN_NAMESPACE
+Q_DECLARE_TYPEINFO(M, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(P, Q_PRIMITIVE_TYPE);
+QT_END_NAMESPACE
+
+// avoid the comma:
+typedef QPair<C,C> QPairCC;
+typedef QPair<C,M> QPairCM;
+typedef QPair<C,P> QPairCP;
+typedef QPair<M,C> QPairMC;
+typedef QPair<M,M> QPairMM;
+typedef QPair<M,P> QPairMP;
+typedef QPair<P,C> QPairPC;
+typedef QPair<P,M> QPairPM;
+typedef QPair<P,P> QPairPP;
+
+Q_STATIC_ASSERT( QTypeInfo<QPairCC>::isComplex);
+Q_STATIC_ASSERT( QTypeInfo<QPairCC>::isStatic );
+
+Q_STATIC_ASSERT( QTypeInfo<QPairCM>::isComplex);
+Q_STATIC_ASSERT( QTypeInfo<QPairCM>::isStatic );
+
+Q_STATIC_ASSERT( QTypeInfo<QPairCP>::isComplex);
+Q_STATIC_ASSERT( QTypeInfo<QPairCP>::isStatic );
+
+Q_STATIC_ASSERT( QTypeInfo<QPairMC>::isComplex);
+Q_STATIC_ASSERT( QTypeInfo<QPairMC>::isStatic );
+
+Q_STATIC_ASSERT( QTypeInfo<QPairMM>::isComplex);
+Q_STATIC_ASSERT(!QTypeInfo<QPairMM>::isStatic );
+
+Q_STATIC_ASSERT( QTypeInfo<QPairMP>::isComplex);
+Q_STATIC_ASSERT(!QTypeInfo<QPairMP>::isStatic );
+
+Q_STATIC_ASSERT( QTypeInfo<QPairPC>::isComplex);
+Q_STATIC_ASSERT( QTypeInfo<QPairPC>::isStatic );
+
+Q_STATIC_ASSERT( QTypeInfo<QPairPM>::isComplex);
+Q_STATIC_ASSERT(!QTypeInfo<QPairPM>::isStatic );
+
+Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isComplex);
+Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isStatic );
+
+Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isDummy );
+Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isPointer);
+
+
+QTEST_APPLESS_MAIN(tst_QPair)
+#include "tst_qpair.moc"
diff --git a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
index a697e23270..5470de76ee 100644
--- a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
+++ b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
@@ -81,6 +81,7 @@ private slots:
void interval();
void validityCheck_data();
void validityCheck();
+ void escapeSequences();
};
// Testing get/set functions
@@ -118,43 +119,43 @@ void tst_QRegExp::indexIn_data()
stri.setNum(i);
// anchors
- QTest::newRow( stri + "anc00" ) << QString("a(?=)z") << QString("az") << 0 << 2 << QStringList();
- QTest::newRow( stri + "anc01" ) << QString("a(?!)z") << QString("az") << -1 << -1 << QStringList();
- QTest::newRow( stri + "anc02" ) << QString("a(?:(?=)|(?=))z") << QString("az") << 0 << 2
+ QTest::newRow(qPrintable(stri + "anc00")) << QString("a(?=)z") << QString("az") << 0 << 2 << QStringList();
+ QTest::newRow(qPrintable(stri + "anc01")) << QString("a(?!)z") << QString("az") << -1 << -1 << QStringList();
+ QTest::newRow(qPrintable(stri + "anc02")) << QString("a(?:(?=)|(?=))z") << QString("az") << 0 << 2
<< QStringList();
- QTest::newRow( stri + "anc03" ) << QString("a(?:(?=)|(?!))z") << QString("az") << 0 << 2
+ QTest::newRow(qPrintable(stri + "anc03")) << QString("a(?:(?=)|(?!))z") << QString("az") << 0 << 2
<< QStringList();
- QTest::newRow( stri + "anc04" ) << QString("a(?:(?!)|(?=))z") << QString("az") << 0 << 2
+ QTest::newRow(qPrintable(stri + "anc04")) << QString("a(?:(?!)|(?=))z") << QString("az") << 0 << 2
<< QStringList();
- QTest::newRow( stri + "anc05" ) << QString("a(?:(?!)|(?!))z") << QString("az") << -1 << -1
+ QTest::newRow(qPrintable(stri + "anc05")) << QString("a(?:(?!)|(?!))z") << QString("az") << -1 << -1
<< QStringList();
- QTest::newRow( stri + "anc06" ) << QString("a(?:(?=)|b)z") << QString("az") << 0 << 2
+ QTest::newRow(qPrintable(stri + "anc06")) << QString("a(?:(?=)|b)z") << QString("az") << 0 << 2
<< QStringList();
- QTest::newRow( stri + "anc07" ) << QString("a(?:(?=)|b)z") << QString("abz") << 0 << 3
+ QTest::newRow(qPrintable(stri + "anc07")) << QString("a(?:(?=)|b)z") << QString("abz") << 0 << 3
<< QStringList();
- QTest::newRow( stri + "anc08" ) << QString("a(?:(?!)|b)z") << QString("az") << -1 << -1
+ QTest::newRow(qPrintable(stri + "anc08")) << QString("a(?:(?!)|b)z") << QString("az") << -1 << -1
<< QStringList();
- QTest::newRow( stri + "anc09" ) << QString("a(?:(?!)|b)z") << QString("abz") << 0 << 3
+ QTest::newRow(qPrintable(stri + "anc09")) << QString("a(?:(?!)|b)z") << QString("abz") << 0 << 3
<< QStringList();
#if 0
- QTest::newRow( stri + "anc10" ) << QString("a?(?=^b$)") << QString("ab") << 0 << 1
+ QTest::newRow(qPrintable(stri + "anc10")) << QString("a?(?=^b$)") << QString("ab") << 0 << 1
<< QStringList();
- QTest::newRow( stri + "anc11" ) << QString("a?(?=^b$)") << QString("b") << 0 << 0
+ QTest::newRow(qPrintable(stri + "anc11")) << QString("a?(?=^b$)") << QString("b") << 0 << 0
<< QStringList();
#endif
// back-references
- QTest::newRow( stri + "bref00" ) << QString("(a*)(\\1)") << QString("aaaaa") << 0 << 4
+ QTest::newRow(qPrintable(stri + "bref00")) << QString("(a*)(\\1)") << QString("aaaaa") << 0 << 4
<< QStringList( QStringList() << "aa" << "aa" );
- QTest::newRow( stri + "bref01" ) << QString("<(\\w*)>.+</\\1>") << QString("<b>blabla</b>bla</>")
+ QTest::newRow(qPrintable(stri + "bref01")) << QString("<(\\w*)>.+</\\1>") << QString("<b>blabla</b>bla</>")
<< 0 << 13 << QStringList( QStringList() << "b" );
- QTest::newRow( stri + "bref02" ) << QString("<(\\w*)>.+</\\1>") << QString("<>blabla</b>bla</>")
+ QTest::newRow(qPrintable(stri + "bref02")) << QString("<(\\w*)>.+</\\1>") << QString("<>blabla</b>bla</>")
<< 0 << 18 << QStringList( QStringList() << "" );
- QTest::newRow( stri + "bref03" ) << QString("((a*\\2)\\2)") << QString("aaaa") << 0 << 4
+ QTest::newRow(qPrintable(stri + "bref03")) << QString("((a*\\2)\\2)") << QString("aaaa") << 0 << 4
<< QStringList( QStringList() << QString("aaaa") << "aa" );
- QTest::newRow( stri + "bref04" ) << QString("^(aa+)\\1+$") << QString("aaaaaa") << 0 << 6
+ QTest::newRow(qPrintable(stri + "bref04")) << QString("^(aa+)\\1+$") << QString("aaaaaa") << 0 << 6
<< QStringList( QStringList() << QString("aa") );
- QTest::newRow( stri + "bref05" ) << QString("^(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11)(12)(13)(14)"
+ QTest::newRow(qPrintable(stri + "bref05")) << QString("^(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11)(12)(13)(14)"
"\\14\\13\\12\\11\\10\\9\\8\\7\\6\\5\\4\\3\\2\\1")
<< QString("12345678910111213141413121110987654321") << 0 << 38
<< QStringList( QStringList() << "1" << "2" << "3" << "4" << "5" << "6"
@@ -162,49 +163,49 @@ void tst_QRegExp::indexIn_data()
<< "12" << "13" << "14");
// captures
- QTest::newRow( stri + "cap00" ) << QString("(a*)") << QString("") << 0 << 0
+ QTest::newRow(qPrintable(stri + "cap00")) << QString("(a*)") << QString("") << 0 << 0
<< QStringList( QStringList() << QString("") );
- QTest::newRow( stri + "cap01" ) << QString("(a*)") << QString("aaa") << 0 << 3
+ QTest::newRow(qPrintable(stri + "cap01")) << QString("(a*)") << QString("aaa") << 0 << 3
<< QStringList( QStringList() << "aaa" );
- QTest::newRow( stri + "cap02" ) << QString("(a*)") << QString("baaa") << 0 << 0
+ QTest::newRow(qPrintable(stri + "cap02")) << QString("(a*)") << QString("baaa") << 0 << 0
<< QStringList( QStringList() << QString("") );
- QTest::newRow( stri + "cap03" ) << QString("(a*)(a*)") << QString("aaa") << 0 << 3
+ QTest::newRow(qPrintable(stri + "cap03")) << QString("(a*)(a*)") << QString("aaa") << 0 << 3
<< QStringList( QStringList() << QString("aaa") << QString("") );
- QTest::newRow( stri + "cap04" ) << QString("(a*)(b*)") << QString("aaabbb") << 0 << 6
+ QTest::newRow(qPrintable(stri + "cap04")) << QString("(a*)(b*)") << QString("aaabbb") << 0 << 6
<< QStringList( QStringList() << QString("aaa") << QString("bbb") );
- QTest::newRow( stri + "cap06" ) << QString("(a*)a*") << QString("aaa") << 0 << 3
+ QTest::newRow(qPrintable(stri + "cap06")) << QString("(a*)a*") << QString("aaa") << 0 << 3
<< QStringList( QStringList() << QString("aaa") );
- QTest::newRow( stri + "cap07" ) << QString("((a*a*)*)") << QString("aaa") << 0 << 3
+ QTest::newRow(qPrintable(stri + "cap07")) << QString("((a*a*)*)") << QString("aaa") << 0 << 3
<< QStringList( QStringList() << "aaa" << QString("aaa") );
- QTest::newRow( stri + "cap08" ) << QString("(((a)*(b)*)*)") << QString("ababa") << 0 << 5
+ QTest::newRow(qPrintable(stri + "cap08")) << QString("(((a)*(b)*)*)") << QString("ababa") << 0 << 5
<< QStringList( QStringList() << QString("ababa") << QString("a") << QString("a")
<< "" );
- QTest::newRow( stri + "cap09" ) << QString("(((a)*(b)*)c)*") << QString("") << 0 << 0
+ QTest::newRow(qPrintable(stri + "cap09")) << QString("(((a)*(b)*)c)*") << QString("") << 0 << 0
<< QStringList( QStringList() << QString("") << QString("") << QString("") << QString("") );
- QTest::newRow( stri + "cap10" ) << QString("(((a)*(b)*)c)*") << QString("abc") << 0 << 3
+ QTest::newRow(qPrintable(stri + "cap10")) << QString("(((a)*(b)*)c)*") << QString("abc") << 0 << 3
<< QStringList( QStringList() << "abc" << "ab" << "a"
<< "b" );
- QTest::newRow( stri + "cap11" ) << QString("(((a)*(b)*)c)*") << QString("abcc") << 0 << 4
+ QTest::newRow(qPrintable(stri + "cap11")) << QString("(((a)*(b)*)c)*") << QString("abcc") << 0 << 4
<< QStringList( QStringList() << "c" << "" << "" << "" );
- QTest::newRow( stri + "cap12" ) << QString("(((a)*(b)*)c)*") << QString("abcac") << 0 << 5
+ QTest::newRow(qPrintable(stri + "cap12")) << QString("(((a)*(b)*)c)*") << QString("abcac") << 0 << 5
<< QStringList( QStringList() << "ac" << "a" << "a" << "" );
- QTest::newRow( stri + "cap13" ) << QString("(to|top)?(o|polo)?(gical|o?logical)")
+ QTest::newRow(qPrintable(stri + "cap13")) << QString("(to|top)?(o|polo)?(gical|o?logical)")
<< QString("topological") << 0 << 11
<< QStringList( QStringList() << "top" << "o"
<< "logical" );
- QTest::newRow( stri + "cap14" ) << QString("(a)+") << QString("aaaa") << 0 << 4
+ QTest::newRow(qPrintable(stri + "cap14")) << QString("(a)+") << QString("aaaa") << 0 << 4
<< QStringList( QStringList() << "a" );
// concatenation
- QTest::newRow( stri + "cat00" ) << QString("") << QString("") << 0 << 0 << QStringList();
- QTest::newRow( stri + "cat01" ) << QString("") << QString("a") << 0 << 0 << QStringList();
- QTest::newRow( stri + "cat02" ) << QString("a") << QString("") << -1 << -1 << QStringList();
- QTest::newRow( stri + "cat03" ) << QString("a") << QString("a") << 0 << 1 << QStringList();
- QTest::newRow( stri + "cat04" ) << QString("a") << QString("b") << -1 << -1 << QStringList();
- QTest::newRow( stri + "cat05" ) << QString("b") << QString("a") << -1 << -1 << QStringList();
- QTest::newRow( stri + "cat06" ) << QString("ab") << QString("ab") << 0 << 2 << QStringList();
- QTest::newRow( stri + "cat07" ) << QString("ab") << QString("ba") << -1 << -1 << QStringList();
- QTest::newRow( stri + "cat08" ) << QString("abab") << QString("abbaababab") << 4 << 4 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat00")) << QString("") << QString("") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat01")) << QString("") << QString("a") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat02")) << QString("a") << QString("") << -1 << -1 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat03")) << QString("a") << QString("a") << 0 << 1 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat04")) << QString("a") << QString("b") << -1 << -1 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat05")) << QString("b") << QString("a") << -1 << -1 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat06")) << QString("ab") << QString("ab") << 0 << 2 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat07")) << QString("ab") << QString("ba") << -1 << -1 << QStringList();
+ QTest::newRow(qPrintable(stri + "cat08")) << QString("abab") << QString("abbaababab") << 4 << 4 << QStringList();
indexIn_addMoreRows(stri);
}
@@ -213,96 +214,96 @@ void tst_QRegExp::indexIn_data()
void tst_QRegExp::indexIn_addMoreRows(const QByteArray &stri)
{
// from Perl Cookbook
- QTest::newRow( stri + "cook00" ) << QString("^(m*)(d?c{0,3}|c[dm])(1?x{0,3}|x[lc])(v?i{0,3}|i[vx])$")
+ QTest::newRow(qPrintable(stri + "cook00")) << QString("^(m*)(d?c{0,3}|c[dm])(1?x{0,3}|x[lc])(v?i{0,3}|i[vx])$")
<< QString("mmxl") << 0 << 4
<< QStringList( QStringList() << "mm" << "" << "xl"
<< "" );
- QTest::newRow( stri + "cook01" ) << QString("(\\S+)(\\s+)(\\S+)") << QString(" a b") << 1 << 5
+ QTest::newRow(qPrintable(stri + "cook01")) << QString("(\\S+)(\\s+)(\\S+)") << QString(" a b") << 1 << 5
<< QStringList( QStringList() << "a" << " " << "b" );
- QTest::newRow( stri + "cook02" ) << QString("(\\w+)\\s*=\\s*(.*)\\s*$") << QString(" PATH=. ") << 1
+ QTest::newRow(qPrintable(stri + "cook02")) << QString("(\\w+)\\s*=\\s*(.*)\\s*$") << QString(" PATH=. ") << 1
<< 7 << QStringList( QStringList() << "PATH" << ". " );
- QTest::newRow( stri + "cook03" ) << QString(".{80,}")
+ QTest::newRow(qPrintable(stri + "cook03")) << QString(".{80,}")
<< QString("0000000011111111222222223333333344444444555"
"5555566666666777777778888888899999999000000"
"00aaaaaaaa")
<< 0 << 96 << QStringList();
- QTest::newRow( stri + "cook04" ) << QString("(\\d+)/(\\d+)/(\\d+) (\\d+):(\\d+):(\\d+)")
+ QTest::newRow(qPrintable(stri + "cook04")) << QString("(\\d+)/(\\d+)/(\\d+) (\\d+):(\\d+):(\\d+)")
<< QString("1978/05/24 07:30:00") << 0 << 19
<< QStringList( QStringList() << "1978" << "05" << "24"
<< "07" << "30" << "00" );
- QTest::newRow( stri + "cook05" ) << QString("/usr/bin") << QString("/usr/local/bin:/usr/bin")
+ QTest::newRow(qPrintable(stri + "cook05")) << QString("/usr/bin") << QString("/usr/local/bin:/usr/bin")
<< 15 << 8 << QStringList();
- QTest::newRow( stri + "cook06" ) << QString("%([0-9A-Fa-f]{2})") << QString("http://%7f") << 7 << 3
+ QTest::newRow(qPrintable(stri + "cook06")) << QString("%([0-9A-Fa-f]{2})") << QString("http://%7f") << 7 << 3
<< QStringList( QStringList() << "7f" );
- QTest::newRow( stri + "cook07" ) << QString("/\\*.*\\*/") << QString("i++; /* increment i */") << 5
+ QTest::newRow(qPrintable(stri + "cook07")) << QString("/\\*.*\\*/") << QString("i++; /* increment i */") << 5
<< 17 << QStringList();
- QTest::newRow( stri + "cook08" ) << QString("^\\s+") << QString(" aaa ") << 0 << 3
+ QTest::newRow(qPrintable(stri + "cook08")) << QString("^\\s+") << QString(" aaa ") << 0 << 3
<< QStringList();
- QTest::newRow( stri + "cook09" ) << QString("\\s+$") << QString(" aaa ") << 6 << 3
+ QTest::newRow(qPrintable(stri + "cook09")) << QString("\\s+$") << QString(" aaa ") << 6 << 3
<< QStringList();
- QTest::newRow( stri + "cook10" ) << QString("^.*::") << QString("Box::cat") << 0 << 5
+ QTest::newRow(qPrintable(stri + "cook10")) << QString("^.*::") << QString("Box::cat") << 0 << 5
<< QStringList();
- QTest::newRow( stri + "cook11" ) << QString("^([01]?\\d\\d|2[0-4]\\d|25[0-5])\\.([01]?\\"
+ QTest::newRow(qPrintable(stri + "cook11")) << QString("^([01]?\\d\\d|2[0-4]\\d|25[0-5])\\.([01]?\\"
"d\\d|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d|2[0-"
"4]\\d|25[0-5])\\.([01]?\\d\\d|2[0-4]\\d|25["
"0-5])$")
<< QString("255.00.40.30") << 0 << 12
<< QStringList( QStringList() << "255" << "00" << "40"
<< "30" );
- QTest::newRow( stri + "cook12" ) << QString("^.*/") << QString(" /usr/local/bin/moc") << 0 << 16
+ QTest::newRow(qPrintable(stri + "cook12")) << QString("^.*/") << QString(" /usr/local/bin/moc") << 0 << 16
<< QStringList();
- QTest::newRow( stri + "cook13" ) << QString(":co#(\\d+):") << QString("bla:co#55:") << 3 << 7
+ QTest::newRow(qPrintable(stri + "cook13")) << QString(":co#(\\d+):") << QString("bla:co#55:") << 3 << 7
<< QStringList( QStringList() << "55" );
- QTest::newRow( stri + "cook14" ) << QString("linux") << QString("alphalinuxinunix") << 5 << 5
+ QTest::newRow(qPrintable(stri + "cook14")) << QString("linux") << QString("alphalinuxinunix") << 5 << 5
<< QStringList();
- QTest::newRow( stri + "cook15" ) << QString("(\\d+\\.?\\d*|\\.\\d+)") << QString("0.0.5") << 0 << 3
+ QTest::newRow(qPrintable(stri + "cook15")) << QString("(\\d+\\.?\\d*|\\.\\d+)") << QString("0.0.5") << 0 << 3
<< QStringList( QStringList() << "0.0" );
// mathematical trivia
- QTest::newRow( stri + "math00" ) << QString("^(a\\1*)$") << QString("a") << 0 << 1
+ QTest::newRow(qPrintable(stri + "math00")) << QString("^(a\\1*)$") << QString("a") << 0 << 1
<< QStringList( QStringList() << "a" );
- QTest::newRow( stri + "math01" ) << QString("^(a\\1*)$") << QString("aa") << 0 << 2
+ QTest::newRow(qPrintable(stri + "math01")) << QString("^(a\\1*)$") << QString("aa") << 0 << 2
<< QStringList( QStringList() << "aa" );
- QTest::newRow( stri + "math02" ) << QString("^(a\\1*)$") << QString("aaa") << -1 << -1
+ QTest::newRow(qPrintable(stri + "math02")) << QString("^(a\\1*)$") << QString("aaa") << -1 << -1
<< QStringList( QStringList() << QString() );
- QTest::newRow( stri + "math03" ) << QString("^(a\\1*)$") << QString("aaaa") << 0 << 4
+ QTest::newRow(qPrintable(stri + "math03")) << QString("^(a\\1*)$") << QString("aaaa") << 0 << 4
<< QStringList( QStringList() << "aaaa" );
- QTest::newRow( stri + "math04" ) << QString("^(a\\1*)$") << QString("aaaaa") << -1 << -1
+ QTest::newRow(qPrintable(stri + "math04")) << QString("^(a\\1*)$") << QString("aaaaa") << -1 << -1
<< QStringList( QStringList() << QString() );
- QTest::newRow( stri + "math05" ) << QString("^(a\\1*)$") << QString("aaaaaa") << -1 << -1
+ QTest::newRow(qPrintable(stri + "math05")) << QString("^(a\\1*)$") << QString("aaaaaa") << -1 << -1
<< QStringList( QStringList() << QString() );
- QTest::newRow( stri + "math06" ) << QString("^(a\\1*)$") << QString("aaaaaaa") << -1 << -1
+ QTest::newRow(qPrintable(stri + "math06")) << QString("^(a\\1*)$") << QString("aaaaaaa") << -1 << -1
<< QStringList( QStringList() << QString() );
- QTest::newRow( stri + "math07" ) << QString("^(a\\1*)$") << QString("aaaaaaaa") << 0 << 8
+ QTest::newRow(qPrintable(stri + "math07")) << QString("^(a\\1*)$") << QString("aaaaaaaa") << 0 << 8
<< QStringList( QStringList() << "aaaaaaaa" );
- QTest::newRow( stri + "math08" ) << QString("^(a\\1*)$") << QString("aaaaaaaaa") << -1 << -1
+ QTest::newRow(qPrintable(stri + "math08")) << QString("^(a\\1*)$") << QString("aaaaaaaaa") << -1 << -1
<< QStringList( QStringList() << QString() );
- QTest::newRow( stri + "math09" ) << QString("^a(?:a(\\1a))*$") << QString("a") << 0 << 1
+ QTest::newRow(qPrintable(stri + "math09")) << QString("^a(?:a(\\1a))*$") << QString("a") << 0 << 1
<< QStringList( QStringList() << "" );
- QTest::newRow( stri + "math10" ) << QString("^a(?:a(\\1a))*$") << QString("aaa") << 0 << 3
+ QTest::newRow(qPrintable(stri + "math10")) << QString("^a(?:a(\\1a))*$") << QString("aaa") << 0 << 3
<< QStringList( QStringList() << "a" );
- QTest::newRow( stri + "math13" ) << QString("^(?:((?:^a)?\\2\\3)(\\3\\1|(?=a$))(\\1\\2|("
+ QTest::newRow(qPrintable(stri + "math13")) << QString("^(?:((?:^a)?\\2\\3)(\\3\\1|(?=a$))(\\1\\2|("
"?=a$)))*a$")
<< QString("aaa") << 0 << 3
<< QStringList( QStringList() << "a" << "a" << "" );
- QTest::newRow( stri + "math14" ) << QString("^(?:((?:^a)?\\2\\3)(\\3\\1|(?=a$))(\\1\\2|("
+ QTest::newRow(qPrintable(stri + "math14")) << QString("^(?:((?:^a)?\\2\\3)(\\3\\1|(?=a$))(\\1\\2|("
"?=a$)))*a$")
<< QString("aaaaa") << 0 << 5
<< QStringList( QStringList() << "a" << "a" << "aa" );
- QTest::newRow( stri + "math17" ) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?"
+ QTest::newRow(qPrintable(stri + "math17")) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?"
":(\\4(?:^a)?\\6)(\\4\\5))*(?:\\4\\6)?))$")
<< QString("aaa") << 0 << 3
<< QStringList( QStringList() << "" << "" << "" << "aaa" << "a" << "aa" );
- QTest::newRow( stri + "math18" ) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?"
+ QTest::newRow(qPrintable(stri + "math18")) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?"
":(\\4(?:^a)?\\6)(\\4\\5))*(?:\\4\\6)?))$")
<< QString("aaaaa") << 0 << 5
<< QStringList( QStringList() << "aaaaa" << "a" << "aaa" << "" << "" << "" );
- QTest::newRow( stri + "math19" ) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?"
+ QTest::newRow(qPrintable(stri + "math19")) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?"
":(\\4(?:^a)?\\6)(\\4\\5))*(?:\\4\\6)?))$")
<< QString("aaaaaaaa") << 0 << 8
<< QStringList( QStringList() << "" << "" << "" << "aaaaaaaa" << "a" << "aa" );
- QTest::newRow( stri + "math20" ) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?"
+ QTest::newRow(qPrintable(stri + "math20")) << QString("^(?:(a(?:(\\1\\3)(\\1\\2))*(?:\\1\\3)?)|((?"
":(\\4(?:^a)?\\6)(\\4\\5))*(?:\\4\\6)?))$")
<< QString("aaaaaaaaa") << -1 << -1
<< QStringList( QStringList() << QString()
@@ -311,7 +312,7 @@ void tst_QRegExp::indexIn_addMoreRows(const QByteArray &stri)
<< QString()
<< QString()
<< QString() );
- QTest::newRow( stri + "math21" ) << QString("^(aa+)\\1+$") << QString("aaaaaaaaaaaa") << 0 << 12
+ QTest::newRow(qPrintable(stri + "math21")) << QString("^(aa+)\\1+$") << QString("aaaaaaaaaaaa") << 0 << 12
<< QStringList( QStringList() << "aa" );
static const char * const squareRegExp[] = {
@@ -349,129 +350,129 @@ void tst_QRegExp::indexIn_addMoreRows(const QByteArray &stri)
}
// miscellaneous
- QTest::newRow( stri + "misc00" ) << QString(email)
+ QTest::newRow(qPrintable(stri + "misc00")) << QString(email)
<< QString("email123@example.com") << 0 << 20
<< QStringList();
- QTest::newRow( stri + "misc01" ) << QString("[0-9]*\\.[0-9]+") << QString("pi = 3.14") << 5 << 4
+ QTest::newRow(qPrintable(stri + "misc01")) << QString("[0-9]*\\.[0-9]+") << QString("pi = 3.14") << 5 << 4
<< QStringList();
// or operator
- QTest::newRow( stri + "or00" ) << QString("(?:|b)") << QString("xxx") << 0 << 0 << QStringList();
- QTest::newRow( stri + "or01" ) << QString("(?:|b)") << QString("b") << 0 << 1 << QStringList();
- QTest::newRow( stri + "or02" ) << QString("(?:b|)") << QString("") << 0 << 0 << QStringList();
- QTest::newRow( stri + "or03" ) << QString("(?:b|)") << QString("b") << 0 << 1 << QStringList();
- QTest::newRow( stri + "or04" ) << QString("(?:||b||)") << QString("") << 0 << 0 << QStringList();
- QTest::newRow( stri + "or05" ) << QString("(?:||b||)") << QString("b") << 0 << 1 << QStringList();
- QTest::newRow( stri + "or06" ) << QString("(?:a|b)") << QString("") << -1 << -1 << QStringList();
- QTest::newRow( stri + "or07" ) << QString("(?:a|b)") << QString("cc") << -1 << -1 << QStringList();
- QTest::newRow( stri + "or08" ) << QString("(?:a|b)") << QString("abc") << 0 << 1 << QStringList();
- QTest::newRow( stri + "or09" ) << QString("(?:a|b)") << QString("cba") << 1 << 1 << QStringList();
- QTest::newRow( stri + "or10" ) << QString("(?:ab|ba)") << QString("aba") << 0 << 2
+ QTest::newRow(qPrintable(stri + "or00")) << QString("(?:|b)") << QString("xxx") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "or01")) << QString("(?:|b)") << QString("b") << 0 << 1 << QStringList();
+ QTest::newRow(qPrintable(stri + "or02")) << QString("(?:b|)") << QString("") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "or03")) << QString("(?:b|)") << QString("b") << 0 << 1 << QStringList();
+ QTest::newRow(qPrintable(stri + "or04")) << QString("(?:||b||)") << QString("") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "or05")) << QString("(?:||b||)") << QString("b") << 0 << 1 << QStringList();
+ QTest::newRow(qPrintable(stri + "or06")) << QString("(?:a|b)") << QString("") << -1 << -1 << QStringList();
+ QTest::newRow(qPrintable(stri + "or07")) << QString("(?:a|b)") << QString("cc") << -1 << -1 << QStringList();
+ QTest::newRow(qPrintable(stri + "or08")) << QString("(?:a|b)") << QString("abc") << 0 << 1 << QStringList();
+ QTest::newRow(qPrintable(stri + "or09")) << QString("(?:a|b)") << QString("cba") << 1 << 1 << QStringList();
+ QTest::newRow(qPrintable(stri + "or10")) << QString("(?:ab|ba)") << QString("aba") << 0 << 2
<< QStringList();
- QTest::newRow( stri + "or11" ) << QString("(?:ab|ba)") << QString("bab") << 0 << 2
+ QTest::newRow(qPrintable(stri + "or11")) << QString("(?:ab|ba)") << QString("bab") << 0 << 2
<< QStringList();
- QTest::newRow( stri + "or12" ) << QString("(?:ab|ba)") << QString("caba") << 1 << 2
+ QTest::newRow(qPrintable(stri + "or12")) << QString("(?:ab|ba)") << QString("caba") << 1 << 2
<< QStringList();
- QTest::newRow( stri + "or13" ) << QString("(?:ab|ba)") << QString("cbab") << 1 << 2
+ QTest::newRow(qPrintable(stri + "or13")) << QString("(?:ab|ba)") << QString("cbab") << 1 << 2
<< QStringList();
// quantifiers
- QTest::newRow( stri + "qua00" ) << QString("((([a-j])){0,0})") << QString("") << 0 << 0
+ QTest::newRow(qPrintable(stri + "qua00")) << QString("((([a-j])){0,0})") << QString("") << 0 << 0
<< QStringList( QStringList() << "" << "" << "" );
- QTest::newRow( stri + "qua01" ) << QString("((([a-j])){0,0})") << QString("a") << 0 << 0
+ QTest::newRow(qPrintable(stri + "qua01")) << QString("((([a-j])){0,0})") << QString("a") << 0 << 0
<< QStringList( QStringList() << "" << "" << "" );
- QTest::newRow( stri + "qua02" ) << QString("((([a-j])){0,0})") << QString("xyz") << 0 << 0
+ QTest::newRow(qPrintable(stri + "qua02")) << QString("((([a-j])){0,0})") << QString("xyz") << 0 << 0
<< QStringList( QStringList() << "" << "" << "" );
- QTest::newRow( stri + "qua03" ) << QString("((([a-j]))?)") << QString("") << 0 << 0
+ QTest::newRow(qPrintable(stri + "qua03")) << QString("((([a-j]))?)") << QString("") << 0 << 0
<< QStringList( QStringList() << "" << "" << "" );
- QTest::newRow( stri + "qua04" ) << QString("((([a-j]))?)") << QString("a") << 0 << 1
+ QTest::newRow(qPrintable(stri + "qua04")) << QString("((([a-j]))?)") << QString("a") << 0 << 1
<< QStringList( QStringList() << "a" << "a" << "a" );
- QTest::newRow( stri + "qua05" ) << QString("((([a-j]))?)") << QString("x") << 0 << 0
+ QTest::newRow(qPrintable(stri + "qua05")) << QString("((([a-j]))?)") << QString("x") << 0 << 0
<< QStringList( QStringList() << "" << "" << "" );
- QTest::newRow( stri + "qua06" ) << QString("((([a-j]))?)") << QString("ab") << 0 << 1
+ QTest::newRow(qPrintable(stri + "qua06")) << QString("((([a-j]))?)") << QString("ab") << 0 << 1
<< QStringList( QStringList() << "a" << "a" << "a" );
- QTest::newRow( stri + "qua07" ) << QString("((([a-j]))?)") << QString("xa") << 0 << 0
+ QTest::newRow(qPrintable(stri + "qua07")) << QString("((([a-j]))?)") << QString("xa") << 0 << 0
<< QStringList( QStringList() << "" << "" << "" );
- QTest::newRow( stri + "qua08" ) << QString("((([a-j])){0,3})") << QString("") << 0 << 0
+ QTest::newRow(qPrintable(stri + "qua08")) << QString("((([a-j])){0,3})") << QString("") << 0 << 0
<< QStringList( QStringList() << "" << "" << "" );
- QTest::newRow( stri + "qua09" ) << QString("((([a-j])){0,3})") << QString("a") << 0 << 1
+ QTest::newRow(qPrintable(stri + "qua09")) << QString("((([a-j])){0,3})") << QString("a") << 0 << 1
<< QStringList( QStringList() << "a" << "a" << "a" );
- QTest::newRow( stri + "qua10" ) << QString("((([a-j])){0,3})") << QString("abcd") << 0 << 3
+ QTest::newRow(qPrintable(stri + "qua10")) << QString("((([a-j])){0,3})") << QString("abcd") << 0 << 3
<< QStringList( QStringList() << "abc" << "c" << "c" );
- QTest::newRow( stri + "qua11" ) << QString("((([a-j])){0,3})") << QString("abcde") << 0 << 3
+ QTest::newRow(qPrintable(stri + "qua11")) << QString("((([a-j])){0,3})") << QString("abcde") << 0 << 3
<< QStringList( QStringList() << "abc" << "c" << "c" );
- QTest::newRow( stri + "qua12" ) << QString("((([a-j])){2,4})") << QString("a") << -1 << -1
+ QTest::newRow(qPrintable(stri + "qua12")) << QString("((([a-j])){2,4})") << QString("a") << -1 << -1
<< QStringList( QStringList() << QString()
<< QString()
<< QString() );
- QTest::newRow( stri + "qua13" ) << QString("((([a-j])){2,4})") << QString("ab") << 0 << 2
+ QTest::newRow(qPrintable(stri + "qua13")) << QString("((([a-j])){2,4})") << QString("ab") << 0 << 2
<< QStringList( QStringList() << "ab" << "b" << "b" );
- QTest::newRow( stri + "qua14" ) << QString("((([a-j])){2,4})") << QString("abcd") << 0 << 4
+ QTest::newRow(qPrintable(stri + "qua14")) << QString("((([a-j])){2,4})") << QString("abcd") << 0 << 4
<< QStringList( QStringList() << "abcd" << "d" << "d" );
- QTest::newRow( stri + "qua15" ) << QString("((([a-j])){2,4})") << QString("abcdef") << 0 << 4
+ QTest::newRow(qPrintable(stri + "qua15")) << QString("((([a-j])){2,4})") << QString("abcdef") << 0 << 4
<< QStringList( QStringList() << "abcd" << "d" << "d" );
- QTest::newRow( stri + "qua16" ) << QString("((([a-j])){2,4})") << QString("xaybcd") << 3 << 3
+ QTest::newRow(qPrintable(stri + "qua16")) << QString("((([a-j])){2,4})") << QString("xaybcd") << 3 << 3
<< QStringList( QStringList() << "bcd" << "d" << "d" );
- QTest::newRow( stri + "qua17" ) << QString("((([a-j])){0,})") << QString("abcdefgh") << 0 << 8
+ QTest::newRow(qPrintable(stri + "qua17")) << QString("((([a-j])){0,})") << QString("abcdefgh") << 0 << 8
<< QStringList( QStringList() << "abcdefgh" << "h" << "h" );
- QTest::newRow( stri + "qua18" ) << QString("((([a-j])){,0})") << QString("abcdefgh") << 0 << 0
+ QTest::newRow(qPrintable(stri + "qua18")) << QString("((([a-j])){,0})") << QString("abcdefgh") << 0 << 0
<< QStringList( QStringList() << "" << "" << "" );
- QTest::newRow( stri + "qua19" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("123332333") << 0
+ QTest::newRow(qPrintable(stri + "qua19")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("123332333") << 0
<< 9
<< QStringList( QStringList() << "123332333" << "2333"
<< "3" );
- QTest::newRow( stri + "qua20" ) << QString("(1(2(3){3,4}){2,3}){1,2}")
+ QTest::newRow(qPrintable(stri + "qua20")) << QString("(1(2(3){3,4}){2,3}){1,2}")
<< QString("12333323333233331233332333323333") << 0 << 32
<< QStringList( QStringList() << "1233332333323333"
<< "23333" << "3" );
- QTest::newRow( stri + "qua21" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("") << -1 << -1
+ QTest::newRow(qPrintable(stri + "qua21")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("") << -1 << -1
<< QStringList( QStringList() << QString()
<< QString()
<< QString() );
- QTest::newRow( stri + "qua22" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333") << -1
+ QTest::newRow(qPrintable(stri + "qua22")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333") << -1
<< -1
<< QStringList( QStringList() << QString()
<< QString()
<< QString() );
- QTest::newRow( stri + "qua23" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333233") << -1
+ QTest::newRow(qPrintable(stri + "qua23")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("12333233") << -1
<< -1
<< QStringList( QStringList() << QString()
<< QString()
<< QString() );
- QTest::newRow( stri + "qua24" ) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("122333") << -1
+ QTest::newRow(qPrintable(stri + "qua24")) << QString("(1(2(3){3,4}){2,3}){1,2}") << QString("122333") << -1
<< -1
<< QStringList( QStringList() << QString()
<< QString()
<< QString() );
// star operator
- QTest::newRow( stri + "star00" ) << QString("(?:)*") << QString("") << 0 << 0 << QStringList();
- QTest::newRow( stri + "star01" ) << QString("(?:)*") << QString("abc") << 0 << 0 << QStringList();
- QTest::newRow( stri + "star02" ) << QString("(?:a)*") << QString("") << 0 << 0 << QStringList();
- QTest::newRow( stri + "star03" ) << QString("(?:a)*") << QString("a") << 0 << 1 << QStringList();
- QTest::newRow( stri + "star04" ) << QString("(?:a)*") << QString("aaa") << 0 << 3 << QStringList();
- QTest::newRow( stri + "star05" ) << QString("(?:a)*") << QString("bbbbaaa") << 0 << 0
+ QTest::newRow(qPrintable(stri + "star00")) << QString("(?:)*") << QString("") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "star01")) << QString("(?:)*") << QString("abc") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "star02")) << QString("(?:a)*") << QString("") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "star03")) << QString("(?:a)*") << QString("a") << 0 << 1 << QStringList();
+ QTest::newRow(qPrintable(stri + "star04")) << QString("(?:a)*") << QString("aaa") << 0 << 3 << QStringList();
+ QTest::newRow(qPrintable(stri + "star05")) << QString("(?:a)*") << QString("bbbbaaa") << 0 << 0
<< QStringList();
- QTest::newRow( stri + "star06" ) << QString("(?:a)*") << QString("bbbbaaabbaaaaa") << 0 << 0
+ QTest::newRow(qPrintable(stri + "star06")) << QString("(?:a)*") << QString("bbbbaaabbaaaaa") << 0 << 0
<< QStringList();
- QTest::newRow( stri + "star07" ) << QString("(?:b)*(?:a)*") << QString("") << 0 << 0
+ QTest::newRow(qPrintable(stri + "star07")) << QString("(?:b)*(?:a)*") << QString("") << 0 << 0
<< QStringList();
- QTest::newRow( stri + "star08" ) << QString("(?:b)*(?:a)*") << QString("a") << 0 << 1
+ QTest::newRow(qPrintable(stri + "star08")) << QString("(?:b)*(?:a)*") << QString("a") << 0 << 1
<< QStringList();
- QTest::newRow( stri + "star09" ) << QString("(?:b)*(?:a)*") << QString("aaa") << 0 << 3
+ QTest::newRow(qPrintable(stri + "star09")) << QString("(?:b)*(?:a)*") << QString("aaa") << 0 << 3
<< QStringList();
- QTest::newRow( stri + "star10" ) << QString("(?:b)*(?:a)*") << QString("bbbbaaa") << 0 << 7
+ QTest::newRow(qPrintable(stri + "star10")) << QString("(?:b)*(?:a)*") << QString("bbbbaaa") << 0 << 7
<< QStringList();
- QTest::newRow( stri + "star11" ) << QString("(?:b)*(?:a)*") << QString("bbbbaaabbaaaaa") << 0 << 7
+ QTest::newRow(qPrintable(stri + "star11")) << QString("(?:b)*(?:a)*") << QString("bbbbaaabbaaaaa") << 0 << 7
<< QStringList();
- QTest::newRow( stri + "star12" ) << QString("(?:a|b)*") << QString("c") << 0 << 0 << QStringList();
- QTest::newRow( stri + "star13" ) << QString("(?:a|b)*") << QString("abac") << 0 << 3
+ QTest::newRow(qPrintable(stri + "star12")) << QString("(?:a|b)*") << QString("c") << 0 << 0 << QStringList();
+ QTest::newRow(qPrintable(stri + "star13")) << QString("(?:a|b)*") << QString("abac") << 0 << 3
<< QStringList();
- QTest::newRow( stri + "star14" ) << QString("(?:a|b|)*") << QString("c") << 0 << 0
+ QTest::newRow(qPrintable(stri + "star14")) << QString("(?:a|b|)*") << QString("c") << 0 << 0
<< QStringList();
- QTest::newRow( stri + "star15" ) << QString("(?:a|b|)*") << QString("abac") << 0 << 3
+ QTest::newRow(qPrintable(stri + "star15")) << QString("(?:a|b|)*") << QString("abac") << 0 << 3
<< QStringList();
- QTest::newRow( stri + "star16" ) << QString("(?:ab|ba|b)*") << QString("abbbababbbaaab") << 0 << 11
+ QTest::newRow(qPrintable(stri + "star16")) << QString("(?:ab|ba|b)*") << QString("abbbababbbaaab") << 0 << 11
<< QStringList();
}
@@ -1373,6 +1374,29 @@ void tst_QRegExp::validityCheck()
QCOMPARE(rx2.cap(), QString(""));
}
+void tst_QRegExp::escapeSequences()
+{
+ QString perlSyntaxSpecialChars("0123456789afnrtvbBdDwWsSx\\|[]{}()^$?+*");
+ QString w3cXmlSchema11SyntaxSpecialChars("cCiIpP"); // as well as the perl ones
+ for (int i = ' '; i <= 127; ++i) {
+ QLatin1Char c(i);
+ if (perlSyntaxSpecialChars.indexOf(c) == -1) {
+ QRegExp rx(QString("\\%1").arg(c), Qt::CaseSensitive, QRegExp::RegExp);
+ // we'll never have c == 'a' since it's a special character
+ QString s = QString("aaa%1aaa").arg(c);
+ QCOMPARE(rx.indexIn(s), 3);
+
+ rx.setPatternSyntax(QRegExp::RegExp2);
+ QCOMPARE(rx.indexIn(s), 3);
+
+ if (w3cXmlSchema11SyntaxSpecialChars.indexOf(c) == -1) {
+ rx.setPatternSyntax(QRegExp::W3CXmlSchema11);
+ QCOMPARE(rx.indexIn(s), 3);
+ }
+ }
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QRegExp)
#include "tst_qregexp.moc"
diff --git a/tests/auto/corelib/tools/qregularexpression/.gitignore b/tests/auto/corelib/tools/qregularexpression/.gitignore
new file mode 100644
index 0000000000..c9249e090e
--- /dev/null
+++ b/tests/auto/corelib/tools/qregularexpression/.gitignore
@@ -0,0 +1,2 @@
+tst_qregularexpression_alwaysoptimize
+tst_qregularexpression_defaultoptimize
diff --git a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro
new file mode 100644
index 0000000000..f48b1ee96a
--- /dev/null
+++ b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro
@@ -0,0 +1,7 @@
+CONFIG += testcase parallel_test
+TARGET = tst_qregularexpression_alwaysoptimize
+QT = core testlib
+HEADERS = ../tst_qregularexpression.h
+SOURCES = \
+ tst_qregularexpression_alwaysoptimize.cpp \
+ ../tst_qregularexpression.cpp
diff --git a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp
new file mode 100644
index 0000000000..9190f183a1
--- /dev/null
+++ b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include "../tst_qregularexpression.h"
+
+class tst_QRegularExpression_AlwaysOptimize : public tst_QRegularExpression
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+};
+
+QT_BEGIN_NAMESPACE
+extern Q_CORE_EXPORT unsigned int qt_qregularexpression_optimize_after_use_count; // from qregularexpression.cpp
+QT_END_NAMESPACE
+
+void tst_QRegularExpression_AlwaysOptimize::initTestCase()
+{
+ qt_qregularexpression_optimize_after_use_count = 1;
+}
+
+QTEST_APPLESS_MAIN(tst_QRegularExpression_AlwaysOptimize)
+
+#include "tst_qregularexpression_alwaysoptimize.moc"
diff --git a/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro
new file mode 100644
index 0000000000..dd1a90cfbc
--- /dev/null
+++ b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro
@@ -0,0 +1,7 @@
+CONFIG += testcase parallel_test
+TARGET = tst_qregularexpression_defaultoptimize
+QT = core testlib
+HEADERS = ../tst_qregularexpression.h
+SOURCES = \
+ tst_qregularexpression_defaultoptimize.cpp \
+ ../tst_qregularexpression.cpp
diff --git a/tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp
new file mode 100644
index 0000000000..d0b5bee4b7
--- /dev/null
+++ b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include "../tst_qregularexpression.h"
+
+class tst_QRegularExpression_DefaultOptimize : public tst_QRegularExpression
+{
+ Q_OBJECT
+};
+
+QTEST_APPLESS_MAIN(tst_QRegularExpression_DefaultOptimize)
+
+#include "tst_qregularexpression_defaultoptimize.moc"
diff --git a/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro
new file mode 100644
index 0000000000..0cae10112f
--- /dev/null
+++ b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = defaultoptimize
+contains(QT_CONFIG,private_tests):SUBDIRS += alwaysoptimize
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
new file mode 100644
index 0000000000..72157c0536
--- /dev/null
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
@@ -0,0 +1,1198 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <qstring.h>
+#include <qlist.h>
+#include <qstringlist.h>
+#include <qhash.h>
+
+#include "tst_qregularexpression.h"
+
+struct Match
+{
+ Match()
+ {
+ clear();
+ }
+
+ void clear()
+ {
+ isValid = false;
+ hasMatch = false;
+ hasPartialMatch = false;
+ captured.clear();
+ namedCaptured.clear();
+ }
+
+ bool isValid;
+ bool hasMatch;
+ bool hasPartialMatch;
+ QStringList captured;
+ QHash<QString, QString> namedCaptured;
+};
+
+Q_DECLARE_METATYPE(Match)
+Q_DECLARE_METATYPE(QList<Match>)
+
+bool operator==(const QRegularExpressionMatch &rem, const Match &m)
+{
+ if (rem.isValid() != m.isValid)
+ return false;
+ if (!rem.isValid())
+ return true;
+ if ((rem.hasMatch() != m.hasMatch) || (rem.hasPartialMatch() != m.hasPartialMatch))
+ return false;
+ if (rem.hasMatch() || rem.hasPartialMatch()) {
+ if (rem.lastCapturedIndex() != (m.captured.size() - 1))
+ return false;
+ for (int i = 0; i <= rem.lastCapturedIndex(); ++i) {
+ QString remCaptured = rem.captured(i);
+ QString mCaptured = m.captured.at(i);
+ if (remCaptured != mCaptured
+ || remCaptured.isNull() != mCaptured.isNull()
+ || remCaptured.isEmpty() != mCaptured.isEmpty()) {
+ return false;
+ }
+ }
+
+ Q_FOREACH (const QString &name, m.namedCaptured.keys()) {
+ if (rem.captured(name) != m.namedCaptured.value(name))
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool operator==(const Match &m, const QRegularExpressionMatch &rem)
+{
+ return operator==(rem, m);
+}
+
+bool operator!=(const QRegularExpressionMatch &rem, const Match &m)
+{
+ return !operator==(rem, m);
+}
+
+bool operator!=(const Match &m, const QRegularExpressionMatch &rem)
+{
+ return !operator==(m, rem);
+}
+
+
+bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList)
+{
+ QRegularExpressionMatchIterator i = iterator;
+ if (i.isValid() != (!expectedMatchList.isEmpty()))
+ return false;
+
+ foreach (const Match &expectedMatch, expectedMatchList)
+ {
+ if (!i.hasNext())
+ return false;
+
+ QRegularExpressionMatch match = i.next();
+ if (match != expectedMatch)
+ return false;
+ }
+
+ if (i.hasNext())
+ return false;
+
+ return true;
+}
+
+bool operator==(const QList<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator)
+{
+ return operator==(iterator, expectedMatchList);
+}
+
+bool operator!=(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList)
+{
+ return !operator==(iterator, expectedMatchList);
+}
+
+bool operator!=(const QList<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator)
+{
+ return !operator==(expectedMatchList, iterator);
+}
+
+void consistencyCheck(const QRegularExpressionMatch &match)
+{
+ if (match.isValid()) {
+ QVERIFY(match.regularExpression().isValid());
+ QVERIFY(!(match.hasMatch() && match.hasPartialMatch()));
+
+ if (match.hasMatch() || match.hasPartialMatch()) {
+ QVERIFY(match.lastCapturedIndex() >= 0);
+ if (match.hasPartialMatch())
+ QVERIFY(match.lastCapturedIndex() == 0);
+
+ for (int i = 0; i <= match.lastCapturedIndex(); ++i) {
+ int startPos = match.capturedStart(i);
+ int endPos = match.capturedEnd(i);
+ int length = match.capturedLength(i);
+ QString captured = match.captured(i);
+ QStringRef capturedRef = match.capturedRef(i);
+
+ if (!captured.isNull()) {
+ QVERIFY(startPos >= 0);
+ QVERIFY(endPos >= 0);
+ QVERIFY(length >= 0);
+ QVERIFY(endPos >= startPos);
+ QVERIFY((endPos - startPos) == length);
+ QVERIFY(captured == capturedRef);
+ } else {
+ QVERIFY(startPos == -1);
+ QVERIFY(endPos == -1);
+ QVERIFY((endPos - startPos) == length);
+ QVERIFY(capturedRef.isNull());
+ }
+ }
+ }
+ } else {
+ QVERIFY(!match.hasMatch());
+ QVERIFY(!match.hasPartialMatch());
+ QVERIFY(match.captured(0).isNull());
+ QVERIFY(match.capturedStart(0) == -1);
+ QVERIFY(match.capturedEnd(0) == -1);
+ QVERIFY(match.capturedLength(0) == 0);
+ }
+}
+
+void consistencyCheck(const QRegularExpressionMatchIterator &iterator)
+{
+ QRegularExpressionMatchIterator i(iterator); // make a copy, we modify it
+ if (i.isValid()) {
+ while (i.hasNext()) {
+ QRegularExpressionMatch peeked = i.peekNext();
+ QRegularExpressionMatch match = i.next();
+ consistencyCheck(peeked);
+ consistencyCheck(match);
+ QVERIFY(match.isValid());
+ QVERIFY(match.hasMatch() || match.hasPartialMatch());
+ QCOMPARE(i.regularExpression(), match.regularExpression());
+ QCOMPARE(i.matchOptions(), match.matchOptions());
+ QCOMPARE(i.matchType(), match.matchType());
+
+ QVERIFY(peeked.isValid() == match.isValid());
+ QVERIFY(peeked.hasMatch() == match.hasMatch());
+ QVERIFY(peeked.hasPartialMatch() == match.hasPartialMatch());
+ QVERIFY(peeked.lastCapturedIndex() == match.lastCapturedIndex());
+ for (int i = 0; i <= peeked.lastCapturedIndex(); ++i) {
+ QVERIFY(peeked.captured(i) == match.captured(i));
+ QVERIFY(peeked.capturedStart(i) == match.capturedStart(i));
+ QVERIFY(peeked.capturedEnd(i) == match.capturedEnd(i));
+ }
+ }
+ } else {
+ QVERIFY(!i.hasNext());
+ QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatchIterator::peekNext() called on an iterator already at end");
+ QRegularExpressionMatch peeked = i.peekNext();
+ QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatchIterator::next() called on an iterator already at end");
+ QRegularExpressionMatch match = i.next();
+ consistencyCheck(peeked);
+ consistencyCheck(match);
+ QVERIFY(!match.isValid());
+ QVERIFY(!peeked.isValid());
+ }
+
+}
+
+void tst_QRegularExpression::provideRegularExpressions()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<QRegularExpression::PatternOptions>("patternOptions");
+
+ QTest::newRow("emptynull01") << QString()
+ << QRegularExpression::PatternOptions(0);
+ QTest::newRow("emptynull02") << QString()
+ << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption
+ | QRegularExpression::DotMatchesEverythingOption
+ | QRegularExpression::MultilineOption);
+ QTest::newRow("emptynull03") << ""
+ << QRegularExpression::PatternOptions(0);
+ QTest::newRow("emptynull04") << ""
+ << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption
+ | QRegularExpression::DotMatchesEverythingOption
+ | QRegularExpression::MultilineOption);
+
+ QTest::newRow("regexp01") << "a pattern"
+ << QRegularExpression::PatternOptions(0);
+ QTest::newRow("regexp02") << "^a (.*) more complicated(?<P>pattern)$"
+ << QRegularExpression::PatternOptions(0);
+ QTest::newRow("regexp03") << "(?:a) pAttErN"
+ << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption);
+ QTest::newRow("regexp04") << "a\nmultiline\npattern"
+ << QRegularExpression::PatternOptions(QRegularExpression::MultilineOption);
+ QTest::newRow("regexp05") << "an extended # IGNOREME\npattern"
+ << QRegularExpression::PatternOptions(QRegularExpression::ExtendedPatternSyntaxOption);
+ QTest::newRow("regexp06") << "a [sS]ingleline .* match"
+ << QRegularExpression::PatternOptions(QRegularExpression::DotMatchesEverythingOption);
+ QTest::newRow("regexp07") << "multiple.*options"
+ << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption
+ | QRegularExpression::DotMatchesEverythingOption
+ | QRegularExpression::MultilineOption
+ | QRegularExpression::DontCaptureOption
+ | QRegularExpression::InvertedGreedinessOption);
+
+ QTest::newRow("unicode01") << QString::fromUtf8("^s[ome] latin-1 \xc3\x80\xc3\x88\xc3\x8c\xc3\x92\xc3\x99 chars$")
+ << QRegularExpression::PatternOptions(0);
+ QTest::newRow("unicode02") << QString::fromUtf8("^s[ome] latin-1 \xc3\x80\xc3\x88\xc3\x8c\xc3\x92\xc3\x99 chars$")
+ << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption
+ | QRegularExpression::DotMatchesEverythingOption
+ | QRegularExpression::InvertedGreedinessOption);
+ QTest::newRow("unicode03") << QString::fromUtf8("Unicode \xf0\x9d\x85\x9d \xf0\x9d\x85\x9e\xf0\x9d\x85\x9f")
+ << QRegularExpression::PatternOptions(0);
+ QTest::newRow("unicode04") << QString::fromUtf8("Unicode \xf0\x9d\x85\x9d \xf0\x9d\x85\x9e\xf0\x9d\x85\x9f")
+ << QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption
+ | QRegularExpression::DotMatchesEverythingOption
+ | QRegularExpression::InvertedGreedinessOption);
+}
+
+void tst_QRegularExpression::gettersSetters_data()
+{
+ provideRegularExpressions();
+}
+
+void tst_QRegularExpression::gettersSetters()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QRegularExpression::PatternOptions, patternOptions);
+ {
+ QRegularExpression re;
+ re.setPattern(pattern);
+ QCOMPARE(re.pattern(), pattern);
+ QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption);
+ }
+ {
+ QRegularExpression re;
+ re.setPatternOptions(patternOptions);
+ QCOMPARE(re.pattern(), QString());
+ QCOMPARE(re.patternOptions(), patternOptions);
+ }
+ {
+ QRegularExpression re(pattern);
+ QCOMPARE(re.pattern(), pattern);
+ QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption);
+ }
+ {
+ QRegularExpression re(pattern, patternOptions);
+ QCOMPARE(re.pattern(), pattern);
+ QCOMPARE(re.patternOptions(), patternOptions);
+ }
+}
+
+void tst_QRegularExpression::escape_data()
+{
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<QString>("escaped");
+ QTest::newRow("escape01") << "a normal pattern"
+ << "a\\ normal\\ pattern";
+
+ QTest::newRow("escape02") << "abcdefghijklmnopqrstuvzABCDEFGHIJKLMNOPQRSTUVZ1234567890_"
+ << "abcdefghijklmnopqrstuvzABCDEFGHIJKLMNOPQRSTUVZ1234567890_";
+
+ QTest::newRow("escape03") << "^\\ba\\b.*(?<NAME>reg|exp)$"
+ << "\\^\\\\ba\\\\b\\.\\*\\(\\?\\<NAME\\>reg\\|exp\\)\\$";
+
+ QString nulString("abcXabcXXabc");
+ nulString[3] = nulString[7] = nulString[8] = QChar(0, 0);
+ QTest::newRow("NUL") << nulString
+ << "abc\\0abc\\0\\0abc";
+
+ QTest::newRow("unicode01") << QString::fromUtf8("^s[ome] latin-1 \xc3\x80\xc3\x88\xc3\x8c\xc3\x92\xc3\x99 chars$")
+ << QString::fromUtf8("\\^s\\[ome\\]\\ latin\\-1\\ \\\xc3\x80\\\xc3\x88\\\xc3\x8c\\\xc3\x92\\\xc3\x99\\ chars\\$");
+ QTest::newRow("unicode02") << QString::fromUtf8("Unicode \xf0\x9d\x85\x9d \xf0\x9d\x85\x9e\xf0\x9d\x85\x9f")
+ << QString::fromUtf8("Unicode\\ \\\xf0\x9d\x85\x9d\\ \\\xf0\x9d\x85\x9e\\\xf0\x9d\x85\x9f");
+
+ QString unicodeAndNulString = QString::fromUtf8("^\xc3\x80\xc3\x88\xc3\x8cN\xc3\x92NN\xc3\x99 chars$");
+ unicodeAndNulString[4] = unicodeAndNulString[6] = unicodeAndNulString[7] = QChar(0, 0);
+ QTest::newRow("unicode03") << unicodeAndNulString
+ << QString::fromUtf8("\\^\\\xc3\x80\\\xc3\x88\\\xc3\x8c\\0\\\xc3\x92\\0\\0\\\xc3\x99\\ chars\\$");
+}
+
+void tst_QRegularExpression::escape()
+{
+ QFETCH(QString, string);
+ QFETCH(QString, escaped);
+ QCOMPARE(QRegularExpression::escape(string), escaped);
+ QRegularExpression re(escaped);
+ QCOMPARE(re.isValid(), true);
+}
+
+void tst_QRegularExpression::validity_data()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<bool>("validity");
+
+ QTest::newRow("valid01") << "a pattern" << true;
+ QTest::newRow("valid02") << "(a|pattern)" << true;
+ QTest::newRow("valid03") << "a [pP]attern" << true;
+ QTest::newRow("valid04") << "^(?<article>a).*(?<noun>pattern)$" << true;
+ QTest::newRow("valid05") << "a \\P{Ll}attern" << true;
+
+ QTest::newRow("invalid01") << "a pattern\\" << false;
+ QTest::newRow("invalid02") << "(a|pattern" << false;
+ QTest::newRow("invalid03") << "a \\P{BLAH}attern" << false;
+
+ QString pattern;
+ // 0xD800 (high surrogate) not followed by a low surrogate
+ pattern = "abcdef";
+ pattern[3] = QChar(0x00, 0xD8);
+ QTest::newRow("invalidUnicode01") << pattern << false;
+}
+
+void tst_QRegularExpression::validity()
+{
+ QFETCH(QString, pattern);
+ QFETCH(bool, validity);
+ QRegularExpression re(pattern);
+ QCOMPARE(re.isValid(), validity);
+ if (!validity)
+ QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object");
+ QRegularExpressionMatch match = re.match("a pattern");
+ QCOMPARE(match.isValid(), validity);
+ consistencyCheck(match);
+
+ if (!validity)
+ QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object");
+ QRegularExpressionMatchIterator iterator = re.globalMatch("a pattern");
+ QCOMPARE(iterator.isValid(), validity);
+}
+
+void tst_QRegularExpression::patternOptions_data()
+{
+ QTest::addColumn<QRegularExpression>("regexp");
+ QTest::addColumn<QString>("subject");
+ QTest::addColumn<Match>("match");
+
+ // none of these would successfully match if the respective
+ // pattern option is not set
+
+ Match m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << QString::fromUtf8("AbC\xc3\xa0");
+ QTest::newRow("/i") << QRegularExpression(QString::fromUtf8("abc\xc3\x80"), QRegularExpression::CaseInsensitiveOption)
+ << QString::fromUtf8("AbC\xc3\xa0")
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "abc123\n678def";
+ QTest::newRow("/s") << QRegularExpression("\\Aabc.*def\\z", QRegularExpression::DotMatchesEverythingOption)
+ << "abc123\n678def"
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "jumped over";
+ QTest::newRow("/m") << QRegularExpression("^\\w+ \\w+$", QRegularExpression::MultilineOption)
+ << "the quick fox\njumped over\nthe lazy\ndog"
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "abc 123456";
+ QTest::newRow("/x") << QRegularExpression("\\w+ # a word\n"
+ "\\ # a space\n"
+ "\\w+ # another word",
+ QRegularExpression::ExtendedPatternSyntaxOption)
+ << "abc 123456 def"
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "the quick fox" << "the" << "quick fox";
+ QTest::newRow("/U") << QRegularExpression("(.+) (.+?)", QRegularExpression::InvertedGreedinessOption)
+ << "the quick fox"
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "the quick fox" << "quick";
+ m.namedCaptured["named"] = "quick";
+ QTest::newRow("no cap") << QRegularExpression("(\\w+) (?<named>\\w+) (\\w+)", QRegularExpression::DontCaptureOption)
+ << "the quick fox"
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << QString::fromUtf8("abc\xc3\x80\xc3\xa0 12\xdb\xb1\xdb\xb2\xf0\x9d\x9f\x98")
+ << QString::fromUtf8("abc\xc3\x80\xc3\xa0")
+ << QString::fromUtf8("12\xdb\xb1\xdb\xb2\xf0\x9d\x9f\x98");
+ QTest::newRow("unicode properties") << QRegularExpression("(\\w+) (\\d+)", QRegularExpression::UseUnicodePropertiesOption)
+ << QString::fromUtf8("abc\xc3\x80\xc3\xa0 12\xdb\xb1\xdb\xb2\xf0\x9d\x9f\x98")
+ << m;
+}
+
+void tst_QRegularExpression::patternOptions()
+{
+ QFETCH(QRegularExpression, regexp);
+ QFETCH(QString, subject);
+ QFETCH(Match, match);
+
+ QRegularExpressionMatch m = regexp.match(subject);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+}
+
+void tst_QRegularExpression::normalMatch_data()
+{
+ QTest::addColumn<QRegularExpression>("regexp");
+ QTest::addColumn<QString>("subject");
+ QTest::addColumn<int>("offset");
+ QTest::addColumn<QRegularExpression::MatchOptions>("matchOptions");
+ QTest::addColumn<Match>("match");
+
+ Match m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "string" << "string";
+ QTest::newRow("match01") << QRegularExpression("(\\bstring\\b)")
+ << "a string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "a string" << "a" << "string";
+ QTest::newRow("match02") << QRegularExpression("(\\w+) (\\w+)")
+ << "a string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "a string" << "a" << "string";
+ m.namedCaptured["article"] = "a";
+ m.namedCaptured["noun"] = "string";
+ QTest::newRow("match03") << QRegularExpression("(?<article>\\w+) (?<noun>\\w+)")
+ << "a string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << " string" << QString() << "string";
+ QTest::newRow("match04") << QRegularExpression("(\\w+)? (\\w+)")
+ << " string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << " string" << QString("") << "string";
+ QTest::newRow("match05") << QRegularExpression("(\\w*) (\\w+)")
+ << " string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "c123def" << "c12" << "3" << "def";
+ QTest::newRow("match06") << QRegularExpression("(\\w*)(\\d+)(\\w*)")
+ << "abc123def"
+ << 2
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << QString("");
+ QTest::newRow("match07") << QRegularExpression("\\w*")
+ << "abc123def"
+ << 9
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << QString("a string") << QString("a string") << QString("");
+ QTest::newRow("match08") << QRegularExpression("(.*)(.*)")
+ << "a string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << QString("a string") << QString("") << QString("a string");
+ QTest::newRow("match09") << QRegularExpression("(.*?)(.*)")
+ << "a string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ // ***
+
+ m.clear();
+ m.isValid = true;
+ QTest::newRow("nomatch01") << QRegularExpression("\\d+")
+ << "a string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true;
+ QTest::newRow("nomatch02") << QRegularExpression("(\\w+) (\\w+)")
+ << "a string"
+ << 1
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true;
+ QTest::newRow("nomatch03") << QRegularExpression("\\w+")
+ << "abc123def"
+ << 9
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ // ***
+
+ m.clear();
+ m.isValid = true;
+ QTest::newRow("anchoredmatch01") << QRegularExpression("\\d+")
+ << "abc123def"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::AnchoredMatchOption)
+ << m;
+}
+
+
+void tst_QRegularExpression::normalMatch()
+{
+ QFETCH(QRegularExpression, regexp);
+ QFETCH(QString, subject);
+ QFETCH(int, offset);
+ QFETCH(QRegularExpression::MatchOptions, matchOptions);
+ QFETCH(Match, match);
+
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+}
+
+
+void tst_QRegularExpression::partialMatch_data()
+{
+ QTest::addColumn<QRegularExpression>("regexp");
+ QTest::addColumn<QString>("subject");
+ QTest::addColumn<int>("offset");
+ QTest::addColumn<QRegularExpression::MatchType>("matchType");
+ QTest::addColumn<QRegularExpression::MatchOptions>("matchOptions");
+ QTest::addColumn<Match>("match");
+
+ Match m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "str";
+ QTest::newRow("softmatch01") << QRegularExpression("string")
+ << "a str"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << " str";
+ QTest::newRow("softmatch02") << QRegularExpression("\\bstring\\b")
+ << "a str"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << " str";
+ QTest::newRow("softmatch03") << QRegularExpression("(\\bstring\\b)")
+ << "a str"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "8 Dec 19";
+ QTest::newRow("softmatch04") << QRegularExpression("^(\\d{1,2}) (\\w{3}) (\\d{4})$")
+ << "8 Dec 19"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "8 Dec 1985" << "8" << "Dec" << "1985";
+ QTest::newRow("softmatch05") << QRegularExpression("^(\\d{1,2}) (\\w{3}) (\\d{4})$")
+ << "8 Dec 1985"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "def";
+ QTest::newRow("softmatch06") << QRegularExpression("abc\\w+X|def")
+ << "abcdef"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "abcdef";
+ QTest::newRow("softmatch07") << QRegularExpression("abc\\w+X|defY")
+ << "abcdef"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "def";
+ QTest::newRow("softmatch08") << QRegularExpression("abc\\w+X|defY")
+ << "abcdef"
+ << 1
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ // ***
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "str";
+ QTest::newRow("hardmatch01") << QRegularExpression("string")
+ << "a str"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << " str";
+ QTest::newRow("hardmatch02") << QRegularExpression("\\bstring\\b")
+ << "a str"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << " str";
+ QTest::newRow("hardmatch03") << QRegularExpression("(\\bstring\\b)")
+ << "a str"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "8 Dec 19";
+ QTest::newRow("hardmatch04") << QRegularExpression("^(\\d{1,2}) (\\w{3}) (\\d{4})$")
+ << "8 Dec 19"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "8 Dec 1985";
+ QTest::newRow("hardmatch05") << QRegularExpression("^(\\d{1,2}) (\\w{3}) (\\d{4})$")
+ << "8 Dec 1985"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "abcdef";
+ QTest::newRow("hardmatch06") << QRegularExpression("abc\\w+X|def")
+ << "abcdef"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "abcdef";
+ QTest::newRow("hardmatch07") << QRegularExpression("abc\\w+X|defY")
+ << "abcdef"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "def";
+ QTest::newRow("hardmatch08") << QRegularExpression("abc\\w+X|defY")
+ << "abcdef"
+ << 1
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "ab";
+ QTest::newRow("hardmatch09") << QRegularExpression("abc|ab")
+ << "ab"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "abc";
+ QTest::newRow("hardmatch10") << QRegularExpression("abc(def)?")
+ << "abc"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasPartialMatch = true;
+ m.captured << "abc";
+ QTest::newRow("hardmatch11") << QRegularExpression("(abc)*")
+ << "abc"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+
+ // ***
+
+ m.clear();
+ m.isValid = true;
+ QTest::newRow("nomatch01") << QRegularExpression("abc\\w+X|defY")
+ << "123456"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true;
+ QTest::newRow("nomatch02") << QRegularExpression("abc\\w+X|defY")
+ << "123456"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true;
+ QTest::newRow("nomatch03") << QRegularExpression("abc\\w+X|defY")
+ << "ab123"
+ << 0
+ << QRegularExpression::PartialPreferCompleteMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true;
+ QTest::newRow("nomatch04") << QRegularExpression("abc\\w+X|defY")
+ << "ab123"
+ << 0
+ << QRegularExpression::PartialPreferFirstMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+}
+
+void tst_QRegularExpression::partialMatch()
+{
+ QFETCH(QRegularExpression, regexp);
+ QFETCH(QString, subject);
+ QFETCH(int, offset);
+ QFETCH(QRegularExpression::MatchType, matchType);
+ QFETCH(QRegularExpression::MatchOptions, matchOptions);
+ QFETCH(Match, match);
+
+ QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+}
+
+void tst_QRegularExpression::globalMatch_data()
+{
+ QTest::addColumn<QRegularExpression>("regexp");
+ QTest::addColumn<QString>("subject");
+ QTest::addColumn<int>("offset");
+ QTest::addColumn<QRegularExpression::MatchType>("matchType");
+ QTest::addColumn<QRegularExpression::MatchOptions>("matchOptions");
+ QTest::addColumn<QList<Match> >("matchList");
+
+ QList<Match> matchList;
+ Match m;
+
+ matchList.clear();
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured = QStringList() << "the";
+ matchList << m;
+ m.captured = QStringList() << "quick";
+ matchList << m;
+ m.captured = QStringList() << "fox";
+ matchList << m;
+ QTest::newRow("globalmatch01") << QRegularExpression("\\w+")
+ << "the quick fox"
+ << 0
+ << QRegularExpression::NormalMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << matchList;
+
+ matchList.clear();
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured = QStringList() << "the" << "t" << "he";
+ matchList << m;
+ m.captured = QStringList() << "quick" << "q" << "uick";
+ matchList << m;
+ m.captured = QStringList() << "fox" << "f" << "ox";
+ matchList << m;
+ QTest::newRow("globalmatch02") << QRegularExpression("(\\w+?)(\\w+)")
+ << "the quick fox"
+ << 0
+ << QRegularExpression::NormalMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << matchList;
+
+ matchList.clear();
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "c";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "c";
+ matchList << m;
+ m.captured = QStringList() << "aabb";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+
+ QTest::newRow("globalmatch_emptycaptures01") << QRegularExpression("a*b*|c")
+ << "ccaabbd"
+ << 0
+ << QRegularExpression::NormalMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << matchList;
+
+ matchList.clear();
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured = QStringList() << "the";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "quick";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "fox";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+
+ QTest::newRow("globalmatch_emptycaptures02") << QRegularExpression(".*")
+ << "the\nquick\nfox"
+ << 0
+ << QRegularExpression::NormalMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << matchList;
+
+ matchList.clear();
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured = QStringList() << "the";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "quick";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "fox";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+
+ QTest::newRow("globalmatch_emptycaptures03") << QRegularExpression(".*")
+ << "the\nquick\nfox\n"
+ << 0
+ << QRegularExpression::NormalMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << matchList;
+
+ matchList.clear();
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured = QStringList() << "the";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "quick";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "fox";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+
+ QTest::newRow("globalmatch_emptycaptures04") << QRegularExpression("(*CRLF).*")
+ << "the\r\nquick\r\nfox"
+ << 0
+ << QRegularExpression::NormalMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << matchList;
+
+ matchList.clear();
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured = QStringList() << "the";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "quick";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "fox";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+
+ QTest::newRow("globalmatch_emptycaptures05") << QRegularExpression("(*CRLF).*")
+ << "the\r\nquick\r\nfox\r\n"
+ << 0
+ << QRegularExpression::NormalMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << matchList;
+
+ matchList.clear();
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured = QStringList() << "the";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "quick";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "fox";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+ m.captured = QStringList() << "jumped";
+ matchList << m;
+ m.captured = QStringList() << "";
+ matchList << m;
+
+ QTest::newRow("globalmatch_emptycaptures06") << QRegularExpression("(*ANYCRLF).*")
+ << "the\r\nquick\nfox\rjumped"
+ << 0
+ << QRegularExpression::NormalMatch
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << matchList;
+}
+
+void tst_QRegularExpression::globalMatch()
+{
+ QFETCH(QRegularExpression, regexp);
+ QFETCH(QString, subject);
+ QFETCH(int, offset);
+ QFETCH(QRegularExpression::MatchType, matchType);
+ QFETCH(QRegularExpression::MatchOptions, matchOptions);
+ QFETCH(QList<Match>, matchList);
+
+ QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
+ consistencyCheck(iterator);
+ QVERIFY(iterator == matchList);
+}
+
+void tst_QRegularExpression::serialize_data()
+{
+ provideRegularExpressions();
+}
+
+void tst_QRegularExpression::serialize()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QRegularExpression::PatternOptions, patternOptions);
+ QRegularExpression outRe(pattern, patternOptions);
+ QByteArray buffer;
+ {
+ QDataStream out(&buffer, QIODevice::WriteOnly);
+ out << outRe;
+ }
+ QRegularExpression inRe;
+ {
+ QDataStream in(&buffer, QIODevice::ReadOnly);
+ in >> inRe;
+ }
+ QCOMPARE(inRe, outRe);
+}
+
+static void verifyEquality(const QRegularExpression &re1, const QRegularExpression &re2)
+{
+ QVERIFY(re1 == re2);
+ QVERIFY(re2 == re1);
+ QVERIFY(!(re1 != re2));
+ QVERIFY(!(re2 != re1));
+
+ QRegularExpression re3(re1);
+
+ QVERIFY(re1 == re3);
+ QVERIFY(re3 == re1);
+ QVERIFY(!(re1 != re3));
+ QVERIFY(!(re3 != re1));
+
+ QVERIFY(re2 == re3);
+ QVERIFY(re3 == re2);
+ QVERIFY(!(re2 != re3));
+ QVERIFY(!(re3 != re2));
+
+ re3 = re2;
+ QVERIFY(re1 == re3);
+ QVERIFY(re3 == re1);
+ QVERIFY(!(re1 != re3));
+ QVERIFY(!(re3 != re1));
+
+ QVERIFY(re2 == re3);
+ QVERIFY(re3 == re2);
+ QVERIFY(!(re2 != re3));
+ QVERIFY(!(re3 != re2));
+}
+
+void tst_QRegularExpression::operatoreq_data()
+{
+ provideRegularExpressions();
+}
+
+void tst_QRegularExpression::operatoreq()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QRegularExpression::PatternOptions, patternOptions);
+ {
+ QRegularExpression re1(pattern);
+ QRegularExpression re2(pattern);
+ verifyEquality(re1, re2);
+ }
+ {
+ QRegularExpression re1(QString(), patternOptions);
+ QRegularExpression re2(QString(), patternOptions);
+ verifyEquality(re1, re2);
+ }
+ {
+ QRegularExpression re1(pattern, patternOptions);
+ QRegularExpression re2(pattern, patternOptions);
+ verifyEquality(re1, re2);
+ }
+}
+
+void tst_QRegularExpression::captureCount_data()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<int>("captureCount");
+ QTest::newRow("captureCount01") << "a pattern" << 0;
+ QTest::newRow("captureCount02") << "a.*pattern" << 0;
+ QTest::newRow("captureCount03") << "(a) pattern" << 1;
+ QTest::newRow("captureCount04") << "(a).*(pattern)" << 2;
+ QTest::newRow("captureCount05") << "^(?<article>\\w+) (?<noun>\\w+)$" << 2;
+ QTest::newRow("captureCount06") << "^(\\w+) (?<word>\\w+) (.)$" << 3;
+ QTest::newRow("captureCount07") << "(?:non capturing) (capturing) (?<n>named) (?:non (capturing))" << 3;
+ QTest::newRow("captureCount08") << "(?|(a)(b)|(c)(d))" << 2;
+ QTest::newRow("captureCount09") << "(?|(a)(b)|(c)(d)(?:e))" << 2;
+ QTest::newRow("captureCount10") << "(?|(a)(b)|(c)(d)(e)) (f)(g)" << 5;
+ QTest::newRow("captureCount11") << "(?|(a)(b)|(c)(d)(e)) (f)(?:g)" << 4;
+ QTest::newRow("captureCount_invalid01") << "(.*" << -1;
+ QTest::newRow("captureCount_invalid02") << "\\" << -1;
+ QTest::newRow("captureCount_invalid03") << "(?<noun)" << -1;
+}
+
+void tst_QRegularExpression::captureCount()
+{
+ QFETCH(QString, pattern);
+ QRegularExpression re(pattern);
+ QTEST(re.captureCount(), "captureCount");
+ if (!re.isValid())
+ QCOMPARE(re.captureCount(), -1);
+}
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
new file mode 100644
index 0000000000..1a703a8f92
--- /dev/null
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qobject.h>
+#include <qregularexpression.h>
+
+Q_DECLARE_METATYPE(QRegularExpression::PatternOptions)
+Q_DECLARE_METATYPE(QRegularExpression::MatchType)
+Q_DECLARE_METATYPE(QRegularExpression::MatchOptions)
+
+class tst_QRegularExpression : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void gettersSetters_data();
+ void gettersSetters();
+ void escape_data();
+ void escape();
+ void validity_data();
+ void validity();
+ void patternOptions_data();
+ void patternOptions();
+ void normalMatch_data();
+ void normalMatch();
+ void partialMatch_data();
+ void partialMatch();
+ void globalMatch_data();
+ void globalMatch();
+ void serialize_data();
+ void serialize();
+ void operatoreq_data();
+ void operatoreq();
+ void captureCount_data();
+ void captureCount();
+
+private:
+ void provideRegularExpressions();
+};
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 88c5e5b595..a8f706ff80 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -4217,16 +4217,7 @@ void tst_QString::tortureSprintfDouble()
# error "Q_BYTE_ORDER not defined"
# endif
-# ifdef QT_ARMFPA
- buff[0] = data->bytes[4];
- buff[1] = data->bytes[5];
- buff[2] = data->bytes[6];
- buff[3] = data->bytes[7];
- buff[4] = data->bytes[0];
- buff[5] = data->bytes[1];
- buff[6] = data->bytes[2];
- buff[7] = data->bytes[3];
-# elif Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
for (uint i = 0; i < 8; ++i)
buff[i] = data->bytes[i];
# else
diff --git a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
index afc16078b8..556b9ac16a 100644
--- a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
+++ b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
@@ -73,6 +73,7 @@ void runScenario()
QString string(l1string);
QStringRef stringref(&string, 2, 10);
QLatin1Char achar('c');
+ QChar::SpecialCharacter special(QChar::Nbsp);
QString r2(QLatin1String(LITERAL LITERAL));
QString r3 = QString::fromUtf8(UTF8_LITERAL UTF8_LITERAL);
QString r;
@@ -97,6 +98,8 @@ void runScenario()
QCOMPARE(r, QString(string P achar));
r = achar + string;
QCOMPARE(r, QString(achar P string));
+ r = special + string;
+ QCOMPARE(r, QString(special P string));
#ifdef Q_COMPILER_UNICODE_STRINGS
r = QStringLiteral(UNICODE_LITERAL);
diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro
index e2002a98b6..38225e12f7 100644
--- a/tests/auto/corelib/tools/tools.pro
+++ b/tests/auto/corelib/tools/tools.pro
@@ -21,10 +21,12 @@ SUBDIRS=\
qlocale \
qmap \
qmargins \
+ qpair \
qpoint \
qqueue \
qrect \
qregexp \
+ qregularexpression \
qringbuffer \
qscopedpointer \
qscopedvaluerollback \