diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2012-03-12 21:03:49 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2012-03-12 21:03:49 +0100 |
commit | d5098f2802255da10b749b93705084ad1fdfc6a5 (patch) | |
tree | 6462008a4ab7d13435d93490fed96c62c516cbdf /tests/auto/corelib | |
parent | d5a85940f785459d7b982d5fdf59a9fd18825092 (diff) | |
parent | b5b41c18345719612e5411cc482466d2dbafdaf7 (diff) |
Merge remote-tracking branch 'origin/master' into api_changes
Conflicts:
tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
Change-Id: I884afc3b6d65c6411733a897a1949e19393573a7
Diffstat (limited to 'tests/auto/corelib')
9 files changed, 672 insertions, 382 deletions
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 8fedaf427a..b3d76bef8a 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -41,10 +41,12 @@ #include <QtTest/QtTest> +#include <QtCore/qtypetraits.h> class tst_QGlobal: public QObject { Q_OBJECT + private slots: void qIsNull(); void for_each(); @@ -53,6 +55,7 @@ private slots: void checkptr(); void qstaticassert(); void qConstructorFunction(); + void isEnum(); }; void tst_QGlobal::qIsNull() @@ -293,5 +296,124 @@ void tst_QGlobal::qConstructorFunction() QCOMPARE(qConstructorFunctionValue, 123); } +struct isEnum_A { + int n_; +}; + +enum isEnum_B_Byte { isEnum_B_Byte_x = 63 }; +enum isEnum_B_Short { isEnum_B_Short_x = 1024 }; +enum isEnum_B_Int { isEnum_B_Int_x = 1 << 20 }; + +union isEnum_C {}; + +class isEnum_D { +public: + operator int() const; +}; + +class isEnum_E { +private: + operator int() const; +}; + +class isEnum_F { +public: + enum AnEnum {}; +}; + +#if defined (Q_COMPILER_CLASS_ENUM) +enum class isEnum_G : qint64 {}; +#endif + +void tst_QGlobal::isEnum() +{ +#if defined (Q_CC_MSVC) +#define IS_ENUM_TRUE(x) (Q_IS_ENUM(x) == true) +#define IS_ENUM_FALSE(x) (Q_IS_ENUM(x) == false) +#else +#define IS_ENUM_TRUE(x) (Q_IS_ENUM(x) == true && QtPrivate::is_enum<x>::value == true) +#define IS_ENUM_FALSE(x) (Q_IS_ENUM(x) == false && QtPrivate::is_enum<x>::value == false) +#endif + + QVERIFY(IS_ENUM_TRUE(isEnum_B_Byte)); + QVERIFY(IS_ENUM_TRUE(const isEnum_B_Byte)); + QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Byte)); + QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Byte)); + + QVERIFY(IS_ENUM_TRUE(isEnum_B_Short)); + QVERIFY(IS_ENUM_TRUE(const isEnum_B_Short)); + QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Short)); + QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Short)); + + QVERIFY(IS_ENUM_TRUE(isEnum_B_Int)); + QVERIFY(IS_ENUM_TRUE(const isEnum_B_Int)); + QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Int)); + QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Int)); + + QVERIFY(IS_ENUM_TRUE(isEnum_F::AnEnum)); + QVERIFY(IS_ENUM_TRUE(const isEnum_F::AnEnum)); + QVERIFY(IS_ENUM_TRUE(volatile isEnum_F::AnEnum)); + QVERIFY(IS_ENUM_TRUE(const volatile isEnum_F::AnEnum)); + + QVERIFY(IS_ENUM_FALSE(void)); + QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte &)); + QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte[1])); + QVERIFY(IS_ENUM_FALSE(const isEnum_B_Byte[1])); + QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte[])); + QVERIFY(IS_ENUM_FALSE(int)); + QVERIFY(IS_ENUM_FALSE(float)); + QVERIFY(IS_ENUM_FALSE(isEnum_A)); + QVERIFY(IS_ENUM_FALSE(isEnum_A *)); + QVERIFY(IS_ENUM_FALSE(const isEnum_A)); + QVERIFY(IS_ENUM_FALSE(isEnum_C)); + QVERIFY(IS_ENUM_FALSE(isEnum_D)); + QVERIFY(IS_ENUM_FALSE(isEnum_E)); + QVERIFY(IS_ENUM_FALSE(void())); + QVERIFY(IS_ENUM_FALSE(void(*)())); + QVERIFY(IS_ENUM_FALSE(int isEnum_A::*)); + QVERIFY(IS_ENUM_FALSE(void (isEnum_A::*)())); + + QVERIFY(IS_ENUM_FALSE(size_t)); + QVERIFY(IS_ENUM_FALSE(bool)); + QVERIFY(IS_ENUM_FALSE(wchar_t)); + + QVERIFY(IS_ENUM_FALSE(char)); + QVERIFY(IS_ENUM_FALSE(unsigned char)); + QVERIFY(IS_ENUM_FALSE(short)); + QVERIFY(IS_ENUM_FALSE(unsigned short)); + QVERIFY(IS_ENUM_FALSE(int)); + QVERIFY(IS_ENUM_FALSE(unsigned int)); + QVERIFY(IS_ENUM_FALSE(long)); + QVERIFY(IS_ENUM_FALSE(unsigned long)); + + QVERIFY(IS_ENUM_FALSE(qint8)); + QVERIFY(IS_ENUM_FALSE(quint8)); + QVERIFY(IS_ENUM_FALSE(qint16)); + QVERIFY(IS_ENUM_FALSE(quint16)); + QVERIFY(IS_ENUM_FALSE(qint32)); + QVERIFY(IS_ENUM_FALSE(quint32)); + QVERIFY(IS_ENUM_FALSE(qint64)); + QVERIFY(IS_ENUM_FALSE(quint64)); + + QVERIFY(IS_ENUM_FALSE(void *)); + QVERIFY(IS_ENUM_FALSE(int *)); + +#if defined (Q_COMPILER_UNICODE_STRINGS) + QVERIFY(IS_ENUM_FALSE(char16_t)); + QVERIFY(IS_ENUM_FALSE(char32_t)); +#endif + +#if defined (Q_COMPILER_CLASS_ENUM) + // Strongly type class enums are not handled by the + // fallback type traits implementation. Any compiler + // supported by Qt that supports C++0x class enums + // should also support the __is_enum intrinsic. + QVERIFY(Q_IS_ENUM(isEnum_G) == true); +#endif + +#undef IS_ENUM_TRUE +#undef IS_ENUM_FALSE +} + QTEST_MAIN(tst_QGlobal) #include "tst_qglobal.moc" diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index f35831c900..079ff6e76b 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -117,6 +117,9 @@ private Q_SLOTS: void testCompactionError(); void parseUnicodeEscapes(); + + void assignObjects(); + void assignArrays(); private: QString testDataDir; }; @@ -1774,5 +1777,35 @@ void TestQtJson::parseUnicodeEscapes() QCOMPARE(array.first().toString(), result); } +void TestQtJson::assignObjects() +{ + const char *json = + "[ { \"Key\": 1 }, { \"Key\": 2 } ]"; + + QJsonDocument doc = QJsonDocument::fromJson(json); + QJsonArray array = doc.array(); + + QJsonObject object = array.at(0).toObject(); + QCOMPARE(object.value("Key").toDouble(), 1.); + + object = array.at(1).toObject(); + QCOMPARE(object.value("Key").toDouble(), 2.); +} + +void TestQtJson::assignArrays() +{ + const char *json = + "[ [ 1 ], [ 2 ] ]"; + + QJsonDocument doc = QJsonDocument::fromJson(json); + QJsonArray array = doc.array(); + + QJsonArray inner = array.at(0).toArray() ; + QCOMPARE(inner.at(0).toDouble(), 1.); + + inner= array.at(1).toArray(); + QCOMPARE(inner.at(0).toDouble(), 2.); +} + QTEST_MAIN(TestQtJson) #include "tst_qtjson.moc" diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index 572c2fdfd1..84d723ca61 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -85,7 +85,7 @@ public: void tst_QCoreApplication::sendEventsOnProcessEvents() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); EventSpy spy; @@ -107,7 +107,7 @@ void tst_QCoreApplication::getSetCheck() // Test the property { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); QCOMPARE(app.property("applicationVersion").toString(), v); } @@ -119,7 +119,7 @@ void tst_QCoreApplication::getSetCheck() void tst_QCoreApplication::qAppName() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); QVERIFY(!::qAppName().isEmpty()); } @@ -131,7 +131,7 @@ void tst_QCoreApplication::argc() #endif { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); QCOMPARE(argc, 1); QCOMPARE(app.arguments().count(), 1); @@ -139,7 +139,10 @@ void tst_QCoreApplication::argc() { int argc = 4; - char *argv[] = { "tst_qcoreapplication", "arg1", "arg2", "arg3" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication"), + const_cast<char*>("arg1"), + const_cast<char*>("arg2"), + const_cast<char*>("arg3") }; QCoreApplication app(argc, argv); QCOMPARE(argc, 4); QCOMPARE(app.arguments().count(), 4); @@ -155,7 +158,8 @@ void tst_QCoreApplication::argc() { int argc = 2; - char *argv[] = { "tst_qcoreapplication", "-qmljsdebugger=port:3768,block" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication"), + const_cast<char*>("-qmljsdebugger=port:3768,block") }; QCoreApplication app(argc, argv); QCOMPARE(argc, 1); QCOMPARE(app.arguments().count(), 1); @@ -187,7 +191,7 @@ public: void tst_QCoreApplication::postEvent() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); EventSpy spy; @@ -272,7 +276,7 @@ void tst_QCoreApplication::postEvent() void tst_QCoreApplication::removePostedEvents() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); EventSpy spy; @@ -451,7 +455,7 @@ public: void tst_QCoreApplication::deliverInDefinedOrder() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); DeliverInDefinedOrderObject obj(&app); @@ -491,7 +495,7 @@ public: void tst_QCoreApplication::globalPostedEventsCount() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); QCoreApplication::sendPostedEvents(); @@ -537,7 +541,7 @@ public: void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); ProcessEventsAlwaysSendsPostedEventsObject object; @@ -555,7 +559,7 @@ void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents() void tst_QCoreApplication::reexec() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); // exec once @@ -570,7 +574,7 @@ void tst_QCoreApplication::reexec() void tst_QCoreApplication::execAfterExit() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); app.exit(1); @@ -581,7 +585,7 @@ void tst_QCoreApplication::execAfterExit() void tst_QCoreApplication::eventLoopExecAfterExit() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); // exec once and exit @@ -633,8 +637,7 @@ void tst_QCoreApplication::customEventDispatcher() QVERIFY(!weak_ed.isNull()); { int argc = 1; - char *arg0 = "tst_qcoreapplication"; - char *argv[] = { arg0 }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); // instantiating app should not overwrite the ED QCOMPARE(QCoreApplication::eventDispatcher(), ed); @@ -728,10 +731,12 @@ private slots: QCOMPARE(privateClass->quitLockRef.load(), 2); JobObject *job3 = new JobObject(job2); + Q_UNUSED(job3); QCOMPARE(privateClass->quitLockRef.load(), 3); JobObject *job4 = new JobObject(job2); + Q_UNUSED(job4); QCOMPARE(privateClass->quitLockRef.load(), 4); @@ -747,7 +752,7 @@ private slots: void tst_QCoreApplication::testQuitLock() { int argc = 1; - char *argv[] = { "tst_qcoreapplication" }; + char *argv[] = { const_cast<char*>("tst_qcoreapplication") }; QCoreApplication app(argc, argv); QuitTester tester; diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 84d28c7959..589b8385a1 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -94,6 +94,7 @@ private slots: void isRegistered(); void isRegisteredStaticLess_data(); void isRegisteredStaticLess(); + void isEnum(); void registerStreamBuiltin(); void automaticTemplateRegistration(); }; @@ -322,17 +323,21 @@ void tst_QMetaType::normalizedTypes() #define TYPENAME_DATA(MetaTypeName, MetaTypeId, RealType)\ QTest::newRow(#RealType) << QMetaType::MetaTypeName << #RealType; -#define TYPENAME_DATA_ALIAS(MetaTypeName, MetaTypeId, AliasType, RealTypeString)\ - QTest::newRow(RealTypeString) << QMetaType::MetaTypeName << #AliasType; - void tst_QMetaType::typeName_data() { QTest::addColumn<QMetaType::Type>("aType"); QTest::addColumn<QString>("aTypeName"); QT_FOR_EACH_STATIC_TYPE(TYPENAME_DATA) - QT_FOR_EACH_STATIC_ALIAS_TYPE(TYPENAME_DATA_ALIAS) QTest::newRow("QMetaType::UnknownType") << QMetaType::UnknownType << static_cast<const char*>(0); + + QTest::newRow("Whity<double>") << static_cast<QMetaType::Type>(::qMetaTypeId<Whity<double> >()) << QString::fromLatin1("Whity<double>"); + QTest::newRow("Whity<int>") << static_cast<QMetaType::Type>(::qMetaTypeId<Whity<int> >()) << QString::fromLatin1("Whity<int>"); + QTest::newRow("Testspace::Foo") << static_cast<QMetaType::Type>(::qMetaTypeId<TestSpace::Foo>()) << QString::fromLatin1("TestSpace::Foo"); + + QTest::newRow("-1") << QMetaType::Type(-1) << QString(); + QTest::newRow("-124125534") << QMetaType::Type(-124125534) << QString(); + QTest::newRow("124125534") << QMetaType::Type(124125534) << QString(); } void tst_QMetaType::typeName() @@ -759,6 +764,12 @@ QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) 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; + + // invalid ids. + QTest::newRow("-1") << -1 << false << false << false; + QTest::newRow("-124125534") << -124125534 << false << false << false; + QTest::newRow("124125534") << 124125534 << false << false << false; + } void tst_QMetaType::flags() @@ -1053,6 +1064,39 @@ void tst_QMetaType::isRegistered() QCOMPARE(QMetaType::isRegistered(typeId), registered); } +enum isEnumTest_Enum0 {}; +struct isEnumTest_Struct0 { enum A{}; }; + +enum isEnumTest_Enum1 {}; +struct isEnumTest_Struct1 {}; + +Q_DECLARE_METATYPE(isEnumTest_Struct1) +Q_DECLARE_METATYPE(isEnumTest_Enum1) + +void tst_QMetaType::isEnum() +{ + int type0 = qRegisterMetaType<int>("int"); + QVERIFY((QMetaType::typeFlags(type0) & QMetaType::IsEnumeration) == 0); + + int type1 = qRegisterMetaType<isEnumTest_Enum0>("isEnumTest_Enum0"); + QVERIFY((QMetaType::typeFlags(type1) & QMetaType::IsEnumeration) == QMetaType::IsEnumeration); + + int type2 = qRegisterMetaType<isEnumTest_Struct0>("isEnumTest_Struct0"); + QVERIFY((QMetaType::typeFlags(type2) & QMetaType::IsEnumeration) == 0); + + int type3 = qRegisterMetaType<isEnumTest_Enum0 *>("isEnumTest_Enum0 *"); + QVERIFY((QMetaType::typeFlags(type3) & QMetaType::IsEnumeration) == 0); + + int type4 = qRegisterMetaType<isEnumTest_Struct0::A>("isEnumTest_Struct0::A"); + QVERIFY((QMetaType::typeFlags(type4) & QMetaType::IsEnumeration) == QMetaType::IsEnumeration); + + int type5 = ::qMetaTypeId<isEnumTest_Struct1>(); + QVERIFY((QMetaType::typeFlags(type5) & QMetaType::IsEnumeration) == 0); + + int type6 = ::qMetaTypeId<isEnumTest_Enum1>(); + QVERIFY((QMetaType::typeFlags(type6) & QMetaType::IsEnumeration) == QMetaType::IsEnumeration); +} + void tst_QMetaType::isRegisteredStaticLess_data() { isRegistered_data(); diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index c48a384e58..9c9c9be99b 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -228,7 +228,7 @@ private slots: void podUserType(); - void data_(); // data is virtual function in QtTestCase + void data(); void constData(); void saveLoadCustomTypes(); @@ -612,6 +612,12 @@ void tst_QVariant::canConvert() QCOMPARE(val.canConvert(QVariant::Time), TimeCast); QCOMPARE(val.canConvert(QVariant::UInt), UIntCast); QCOMPARE(val.canConvert(QVariant::ULongLong), ULongLongCast); + + // Invalid type ids + QCOMPARE(val.canConvert(-1), false); + QCOMPARE(val.canConvert(-23), false); + QCOMPARE(val.canConvert(-23876), false); + QCOMPARE(val.canConvert(23876), false); } void tst_QVariant::toInt_data() @@ -2215,7 +2221,7 @@ void tst_QVariant::basicUserType() QCOMPARE(v.toByteArray(), QByteArray("bar")); } -void tst_QVariant::data_() +void tst_QVariant::data() { QVariant v; diff --git a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp index 0e1fa47a3e..a9fbde8037 100644 --- a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp +++ b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp @@ -73,10 +73,10 @@ public: void run() { - mutex.lock(); - cond.wakeOne(); - cond.wait(&mutex); - mutex.unlock(); + mutex.lock(); + cond.wakeOne(); + cond.wait(&mutex); + mutex.unlock(); } }; @@ -94,10 +94,10 @@ public: void run() { - mutex->lock(); - started.wakeOne(); - cond->wait(mutex); - mutex->unlock(); + mutex->lock(); + started.wakeOne(); + cond->wait(mutex); + mutex->unlock(); } }; @@ -112,10 +112,10 @@ public: void run() { - readWriteLock.lockForWrite(); - cond.wakeOne(); - cond.wait(&readWriteLock); - readWriteLock.unlock(); + readWriteLock.lockForWrite(); + cond.wakeOne(); + cond.wait(&readWriteLock); + readWriteLock.unlock(); } }; @@ -133,10 +133,10 @@ public: void run() { - readWriteLock->lockForRead(); - started.wakeOne(); - cond->wait(readWriteLock); - readWriteLock->unlock(); + readWriteLock->lockForRead(); + started.wakeOne(); + cond->wait(readWriteLock); + readWriteLock->unlock(); } }; @@ -144,80 +144,80 @@ void tst_QWaitCondition::wait_QMutex() { int x; for (int i = 0; i < iterations; ++i) { - { - QMutex mutex; - QWaitCondition cond; - - mutex.lock(); + { + QMutex mutex; + QWaitCondition cond; - cond.wakeOne(); - QVERIFY(!cond.wait(&mutex, 1)); - - cond.wakeAll(); - QVERIFY(!cond.wait(&mutex, 1)); + mutex.lock(); - mutex.unlock(); - } + cond.wakeOne(); + QVERIFY(!cond.wait(&mutex, 1)); - { - // test multiple threads waiting on separate wait conditions - wait_QMutex_Thread_1 thread[ThreadCount]; + cond.wakeAll(); + QVERIFY(!cond.wait(&mutex, 1)); - for (x = 0; x < ThreadCount; ++x) { - thread[x].mutex.lock(); - thread[x].start(); - // wait for thread to start - QVERIFY(thread[x].cond.wait(&thread[x].mutex, 1000)); - thread[x].mutex.unlock(); + mutex.unlock(); } - for (x = 0; x < ThreadCount; ++x) { - QVERIFY(thread[x].isRunning()); - QVERIFY(!thread[x].isFinished()); - } + { + // test multiple threads waiting on separate wait conditions + wait_QMutex_Thread_1 thread[ThreadCount]; - for (x = 0; x < ThreadCount; ++x) { - thread[x].mutex.lock(); - thread[x].cond.wakeOne(); - thread[x].mutex.unlock(); - } + for (x = 0; x < ThreadCount; ++x) { + thread[x].mutex.lock(); + thread[x].start(); + // wait for thread to start + QVERIFY(thread[x].cond.wait(&thread[x].mutex, 1000)); + thread[x].mutex.unlock(); + } - for (x = 0; x < ThreadCount; ++x) { - QVERIFY(thread[x].wait(1000)); - } - } + for (x = 0; x < ThreadCount; ++x) { + QVERIFY(thread[x].isRunning()); + QVERIFY(!thread[x].isFinished()); + } - { - // test multiple threads waiting on a wait condition - QMutex mutex; - QWaitCondition cond1, cond2; - wait_QMutex_Thread_2 thread[ThreadCount]; + for (x = 0; x < ThreadCount; ++x) { + thread[x].mutex.lock(); + thread[x].cond.wakeOne(); + thread[x].mutex.unlock(); + } - mutex.lock(); - for (x = 0; x < ThreadCount; ++x) { - thread[x].mutex = &mutex; - thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2; - thread[x].start(); - // wait for thread to start - QVERIFY(thread[x].started.wait(&mutex, 1000)); + for (x = 0; x < ThreadCount; ++x) { + QVERIFY(thread[x].wait(1000)); + } } - mutex.unlock(); - for (x = 0; x < ThreadCount; ++x) { - QVERIFY(thread[x].isRunning()); - QVERIFY(!thread[x].isFinished()); - } + { + // test multiple threads waiting on a wait condition + QMutex mutex; + QWaitCondition cond1, cond2; + wait_QMutex_Thread_2 thread[ThreadCount]; + + mutex.lock(); + for (x = 0; x < ThreadCount; ++x) { + thread[x].mutex = &mutex; + thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2; + thread[x].start(); + // wait for thread to start + QVERIFY(thread[x].started.wait(&mutex, 1000)); + } + mutex.unlock(); - mutex.lock(); - cond1.wakeAll(); - cond2.wakeAll(); - mutex.unlock(); + for (x = 0; x < ThreadCount; ++x) { + QVERIFY(thread[x].isRunning()); + QVERIFY(!thread[x].isFinished()); + } - for (x = 0; x < ThreadCount; ++x) { - QVERIFY(thread[x].wait(1000)); + mutex.lock(); + cond1.wakeAll(); + cond2.wakeAll(); + mutex.unlock(); + + for (x = 0; x < ThreadCount; ++x) { + QVERIFY(thread[x].wait(1000)); + } } } - } } void tst_QWaitCondition::wait_QReadWriteLock() @@ -263,96 +263,95 @@ void tst_QWaitCondition::wait_QReadWriteLock() int x; for (int i = 0; i < iterations; ++i) { - { - QReadWriteLock readWriteLock; - QWaitCondition waitCondition; + { + QReadWriteLock readWriteLock; + QWaitCondition waitCondition; - readWriteLock.lockForRead(); + readWriteLock.lockForRead(); - waitCondition.wakeOne(); - QVERIFY(!waitCondition.wait(&readWriteLock, 1)); - - waitCondition.wakeAll(); - QVERIFY(!waitCondition.wait(&readWriteLock, 1)); + waitCondition.wakeOne(); + QVERIFY(!waitCondition.wait(&readWriteLock, 1)); - readWriteLock.unlock(); - } - - { - QReadWriteLock readWriteLock; - QWaitCondition waitCondition; + waitCondition.wakeAll(); + QVERIFY(!waitCondition.wait(&readWriteLock, 1)); - readWriteLock.lockForWrite(); + readWriteLock.unlock(); + } - waitCondition.wakeOne(); - QVERIFY(!waitCondition.wait(&readWriteLock, 1)); + { + QReadWriteLock readWriteLock; + QWaitCondition waitCondition; - waitCondition.wakeAll(); - QVERIFY(!waitCondition.wait(&readWriteLock, 1)); + readWriteLock.lockForWrite(); - readWriteLock.unlock(); - } + waitCondition.wakeOne(); + QVERIFY(!waitCondition.wait(&readWriteLock, 1)); - { - // test multiple threads waiting on separate wait conditions - wait_QReadWriteLock_Thread_1 thread[ThreadCount]; + waitCondition.wakeAll(); + QVERIFY(!waitCondition.wait(&readWriteLock, 1)); - for (x = 0; x < ThreadCount; ++x) { - thread[x].readWriteLock.lockForRead(); - thread[x].start(); - // wait for thread to start - QVERIFY(thread[x].cond.wait(&thread[x].readWriteLock, 1000)); - thread[x].readWriteLock.unlock(); + readWriteLock.unlock(); } - for (x = 0; x < ThreadCount; ++x) { - QVERIFY(thread[x].isRunning()); - QVERIFY(!thread[x].isFinished()); - } + { + // test multiple threads waiting on separate wait conditions + wait_QReadWriteLock_Thread_1 thread[ThreadCount]; - for (x = 0; x < ThreadCount; ++x) { - thread[x].readWriteLock.lockForRead(); - thread[x].cond.wakeOne(); - thread[x].readWriteLock.unlock(); - } + for (x = 0; x < ThreadCount; ++x) { + thread[x].readWriteLock.lockForRead(); + thread[x].start(); + // wait for thread to start + QVERIFY(thread[x].cond.wait(&thread[x].readWriteLock, 1000)); + thread[x].readWriteLock.unlock(); + } - for (x = 0; x < ThreadCount; ++x) { - QVERIFY(thread[x].wait(1000)); - } - } + for (x = 0; x < ThreadCount; ++x) { + QVERIFY(thread[x].isRunning()); + QVERIFY(!thread[x].isFinished()); + } - { - // test multiple threads waiting on a wait condition - QReadWriteLock readWriteLock; - QWaitCondition cond1, cond2; - wait_QReadWriteLock_Thread_2 thread[ThreadCount]; + for (x = 0; x < ThreadCount; ++x) { + thread[x].readWriteLock.lockForRead(); + thread[x].cond.wakeOne(); + thread[x].readWriteLock.unlock(); + } - readWriteLock.lockForWrite(); - for (x = 0; x < ThreadCount; ++x) { - thread[x].readWriteLock = &readWriteLock; - thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2; - thread[x].start(); - // wait for thread to start - QVERIFY(thread[x].started.wait(&readWriteLock, 1000)); + for (x = 0; x < ThreadCount; ++x) { + QVERIFY(thread[x].wait(1000)); + } } - readWriteLock.unlock(); - for (x = 0; x < ThreadCount; ++x) { - QVERIFY(thread[x].isRunning()); - QVERIFY(!thread[x].isFinished()); - } + { + // test multiple threads waiting on a wait condition + QReadWriteLock readWriteLock; + QWaitCondition cond1, cond2; + wait_QReadWriteLock_Thread_2 thread[ThreadCount]; + + readWriteLock.lockForWrite(); + for (x = 0; x < ThreadCount; ++x) { + thread[x].readWriteLock = &readWriteLock; + thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2; + thread[x].start(); + // wait for thread to start + QVERIFY(thread[x].started.wait(&readWriteLock, 1000)); + } + readWriteLock.unlock(); - readWriteLock.lockForWrite(); - cond1.wakeAll(); - cond2.wakeAll(); - readWriteLock.unlock(); + for (x = 0; x < ThreadCount; ++x) { + QVERIFY(thread[x].isRunning()); + QVERIFY(!thread[x].isFinished()); + } - for (x = 0; x < ThreadCount; ++x) { - QVERIFY(thread[x].wait(1000)); + readWriteLock.lockForWrite(); + cond1.wakeAll(); + cond2.wakeAll(); + readWriteLock.unlock(); + + for (x = 0; x < ThreadCount; ++x) { + QVERIFY(thread[x].wait(1000)); + } } } - } - } class wake_Thread : public QThread @@ -375,14 +374,14 @@ public: void run() { - mutex->lock(); - ++count; + mutex->lock(); + ++count; dummy.wakeOne(); // this wakeup should be lost - started.wakeOne(); + started.wakeOne(); dummy.wakeAll(); // this one too - cond->wait(mutex); + cond->wait(mutex); --count; - mutex->unlock(); + mutex->unlock(); } }; @@ -408,14 +407,14 @@ public: void run() { - readWriteLock->lockForWrite(); - ++count; + readWriteLock->lockForWrite(); + ++count; dummy.wakeOne(); // this wakeup should be lost started.wakeOne(); dummy.wakeAll(); // this one too - cond->wait(readWriteLock); + cond->wait(readWriteLock); --count; - readWriteLock->unlock(); + readWriteLock->unlock(); } }; @@ -426,264 +425,264 @@ void tst_QWaitCondition::wakeOne() int x; // wake up threads, one at a time for (int i = 0; i < iterations; ++i) { - QMutex mutex; - QWaitCondition cond; - - // QMutex - wake_Thread thread[ThreadCount]; - bool thread_exited[ThreadCount]; - - mutex.lock(); - for (x = 0; x < ThreadCount; ++x) { - thread[x].mutex = &mutex; - thread[x].cond = &cond; - thread_exited[x] = false; - thread[x].start(); - // wait for thread to start - QVERIFY(thread[x].started.wait(&mutex, 1000)); - // make sure wakeups are not queued... if nothing is - // waiting at the time of the wakeup, nothing happens - QVERIFY(!thread[x].dummy.wait(&mutex, 1)); - } - mutex.unlock(); + QMutex mutex; + QWaitCondition cond; - QCOMPARE(wake_Thread::count, ThreadCount); + // QMutex + wake_Thread thread[ThreadCount]; + bool thread_exited[ThreadCount]; - // wake up threads one at a time - for (x = 0; x < ThreadCount; ++x) { mutex.lock(); - cond.wakeOne(); - QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME)); - QVERIFY(!thread[x].dummy.wait(&mutex, 1)); + for (x = 0; x < ThreadCount; ++x) { + thread[x].mutex = &mutex; + thread[x].cond = &cond; + thread_exited[x] = false; + thread[x].start(); + // wait for thread to start + QVERIFY(thread[x].started.wait(&mutex, 1000)); + // make sure wakeups are not queued... if nothing is + // waiting at the time of the wakeup, nothing happens + QVERIFY(!thread[x].dummy.wait(&mutex, 1)); + } mutex.unlock(); - int exited = 0; - for (int y = 0; y < ThreadCount; ++y) { - if (thread_exited[y]) - continue; - if (thread[y].wait(exited > 0 ? 10 : 1000)) { - thread_exited[y] = true; - ++exited; - } - } + QCOMPARE(wake_Thread::count, ThreadCount); - QCOMPARE(exited, 1); - QCOMPARE(wake_Thread::count, ThreadCount - (x + 1)); - } + // wake up threads one at a time + for (x = 0; x < ThreadCount; ++x) { + mutex.lock(); + cond.wakeOne(); + QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME)); + QVERIFY(!thread[x].dummy.wait(&mutex, 1)); + mutex.unlock(); + + int exited = 0; + for (int y = 0; y < ThreadCount; ++y) { + if (thread_exited[y]) + continue; + if (thread[y].wait(exited > 0 ? 10 : 1000)) { + thread_exited[y] = true; + ++exited; + } + } - QCOMPARE(wake_Thread::count, 0); + QCOMPARE(exited, 1); + QCOMPARE(wake_Thread::count, ThreadCount - (x + 1)); + } - // QReadWriteLock - QReadWriteLock readWriteLock; - wake_Thread_2 rwthread[ThreadCount]; - - readWriteLock.lockForWrite(); - for (x = 0; x < ThreadCount; ++x) { - rwthread[x].readWriteLock = &readWriteLock; - rwthread[x].cond = &cond; - thread_exited[x] = false; - rwthread[x].start(); - // wait for thread to start - QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000)); - // make sure wakeups are not queued... if nothing is - // waiting at the time of the wakeup, nothing happens - QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1)); - } - readWriteLock.unlock(); + QCOMPARE(wake_Thread::count, 0); - QCOMPARE(wake_Thread_2::count, ThreadCount); + // QReadWriteLock + QReadWriteLock readWriteLock; + wake_Thread_2 rwthread[ThreadCount]; - // wake up threads one at a time - for (x = 0; x < ThreadCount; ++x) { readWriteLock.lockForWrite(); - cond.wakeOne(); - QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME)); - QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1)); + for (x = 0; x < ThreadCount; ++x) { + rwthread[x].readWriteLock = &readWriteLock; + rwthread[x].cond = &cond; + thread_exited[x] = false; + rwthread[x].start(); + // wait for thread to start + QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000)); + // make sure wakeups are not queued... if nothing is + // waiting at the time of the wakeup, nothing happens + QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1)); + } readWriteLock.unlock(); - int exited = 0; - for (int y = 0; y < ThreadCount; ++y) { - if (thread_exited[y]) - continue; - if (rwthread[y].wait(exited > 0 ? 10 : 1000)) { - thread_exited[y] = true; - ++exited; + QCOMPARE(wake_Thread_2::count, ThreadCount); + + // wake up threads one at a time + for (x = 0; x < ThreadCount; ++x) { + readWriteLock.lockForWrite(); + cond.wakeOne(); + QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME)); + QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1)); + readWriteLock.unlock(); + + int exited = 0; + for (int y = 0; y < ThreadCount; ++y) { + if (thread_exited[y]) + continue; + if (rwthread[y].wait(exited > 0 ? 10 : 1000)) { + thread_exited[y] = true; + ++exited; + } } - } - QCOMPARE(exited, 1); - QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 1)); - } + QCOMPARE(exited, 1); + QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 1)); + } - QCOMPARE(wake_Thread_2::count, 0); + QCOMPARE(wake_Thread_2::count, 0); } // wake up threads, two at a time for (int i = 0; i < iterations; ++i) { - QMutex mutex; - QWaitCondition cond; + QMutex mutex; + QWaitCondition cond; // QMutex - wake_Thread thread[ThreadCount]; - bool thread_exited[ThreadCount]; - - mutex.lock(); - for (x = 0; x < ThreadCount; ++x) { - thread[x].mutex = &mutex; - thread[x].cond = &cond; - thread_exited[x] = false; - thread[x].start(); - // wait for thread to start - QVERIFY(thread[x].started.wait(&mutex, 1000)); - // make sure wakeups are not queued... if nothing is - // waiting at the time of the wakeup, nothing happens - QVERIFY(!thread[x].dummy.wait(&mutex, 1)); - } - mutex.unlock(); - - QCOMPARE(wake_Thread::count, ThreadCount); + wake_Thread thread[ThreadCount]; + bool thread_exited[ThreadCount]; - // wake up threads one at a time - for (x = 0; x < ThreadCount; x += 2) { mutex.lock(); - cond.wakeOne(); - cond.wakeOne(); - QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME)); - QVERIFY(!thread[x].dummy.wait(&mutex, 1)); - QVERIFY(!thread[x + 1].dummy.wait(&mutex, 1)); + for (x = 0; x < ThreadCount; ++x) { + thread[x].mutex = &mutex; + thread[x].cond = &cond; + thread_exited[x] = false; + thread[x].start(); + // wait for thread to start + QVERIFY(thread[x].started.wait(&mutex, 1000)); + // make sure wakeups are not queued... if nothing is + // waiting at the time of the wakeup, nothing happens + QVERIFY(!thread[x].dummy.wait(&mutex, 1)); + } mutex.unlock(); - int exited = 0; - for (int y = 0; y < ThreadCount; ++y) { - if (thread_exited[y]) - continue; - if (thread[y].wait(exited > 0 ? 10 : 1000)) { - thread_exited[y] = true; - ++exited; + QCOMPARE(wake_Thread::count, ThreadCount); + + // wake up threads one at a time + for (x = 0; x < ThreadCount; x += 2) { + mutex.lock(); + cond.wakeOne(); + cond.wakeOne(); + QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME)); + QVERIFY(!thread[x].dummy.wait(&mutex, 1)); + QVERIFY(!thread[x + 1].dummy.wait(&mutex, 1)); + mutex.unlock(); + + int exited = 0; + for (int y = 0; y < ThreadCount; ++y) { + if (thread_exited[y]) + continue; + if (thread[y].wait(exited > 0 ? 10 : 1000)) { + thread_exited[y] = true; + ++exited; + } } - } - QCOMPARE(exited, 2); - QCOMPARE(wake_Thread::count, ThreadCount - (x + 2)); - } + QCOMPARE(exited, 2); + QCOMPARE(wake_Thread::count, ThreadCount - (x + 2)); + } - QCOMPARE(wake_Thread::count, 0); + QCOMPARE(wake_Thread::count, 0); // QReadWriteLock QReadWriteLock readWriteLock; wake_Thread_2 rwthread[ThreadCount]; - readWriteLock.lockForWrite(); - for (x = 0; x < ThreadCount; ++x) { - rwthread[x].readWriteLock = &readWriteLock; - rwthread[x].cond = &cond; - thread_exited[x] = false; - rwthread[x].start(); - // wait for thread to start - QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000)); - // make sure wakeups are not queued... if nothing is - // waiting at the time of the wakeup, nothing happens - QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1)); - } - readWriteLock.unlock(); - - QCOMPARE(wake_Thread_2::count, ThreadCount); - - // wake up threads one at a time - for (x = 0; x < ThreadCount; x += 2) { readWriteLock.lockForWrite(); - cond.wakeOne(); - cond.wakeOne(); - QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME)); - QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1)); - QVERIFY(!rwthread[x + 1].dummy.wait(&readWriteLock, 1)); + for (x = 0; x < ThreadCount; ++x) { + rwthread[x].readWriteLock = &readWriteLock; + rwthread[x].cond = &cond; + thread_exited[x] = false; + rwthread[x].start(); + // wait for thread to start + QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000)); + // make sure wakeups are not queued... if nothing is + // waiting at the time of the wakeup, nothing happens + QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1)); + } readWriteLock.unlock(); - int exited = 0; - for (int y = 0; y < ThreadCount; ++y) { - if (thread_exited[y]) - continue; - if (rwthread[y].wait(exited > 0 ? 10 : 1000)) { - thread_exited[y] = true; - ++exited; + QCOMPARE(wake_Thread_2::count, ThreadCount); + + // wake up threads one at a time + for (x = 0; x < ThreadCount; x += 2) { + readWriteLock.lockForWrite(); + cond.wakeOne(); + cond.wakeOne(); + QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME)); + QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1)); + QVERIFY(!rwthread[x + 1].dummy.wait(&readWriteLock, 1)); + readWriteLock.unlock(); + + int exited = 0; + for (int y = 0; y < ThreadCount; ++y) { + if (thread_exited[y]) + continue; + if (rwthread[y].wait(exited > 0 ? 10 : 1000)) { + thread_exited[y] = true; + ++exited; + } } + + QCOMPARE(exited, 2); + QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 2)); } - QCOMPARE(exited, 2); - QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 2)); + QCOMPARE(wake_Thread_2::count, 0); } - - QCOMPARE(wake_Thread_2::count, 0); -} } void tst_QWaitCondition::wakeAll() { int x; for (int i = 0; i < iterations; ++i) { - QMutex mutex; - QWaitCondition cond; + QMutex mutex; + QWaitCondition cond; - // QMutex - wake_Thread thread[ThreadCount]; + // QMutex + wake_Thread thread[ThreadCount]; - mutex.lock(); - for (x = 0; x < ThreadCount; ++x) { - thread[x].mutex = &mutex; - thread[x].cond = &cond; - thread[x].start(); - // wait for thread to start - QVERIFY(thread[x].started.wait(&mutex, 1000)); - } - mutex.unlock(); + mutex.lock(); + for (x = 0; x < ThreadCount; ++x) { + thread[x].mutex = &mutex; + thread[x].cond = &cond; + thread[x].start(); + // wait for thread to start + QVERIFY(thread[x].started.wait(&mutex, 1000)); + } + mutex.unlock(); - QCOMPARE(wake_Thread::count, ThreadCount); + QCOMPARE(wake_Thread::count, ThreadCount); - // wake up all threads at once - mutex.lock(); - cond.wakeAll(); - QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME)); - mutex.unlock(); + // wake up all threads at once + mutex.lock(); + cond.wakeAll(); + QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME)); + mutex.unlock(); - int exited = 0; - for (x = 0; x < ThreadCount; ++x) { - if (thread[x].wait(1000)) - ++exited; - } + int exited = 0; + for (x = 0; x < ThreadCount; ++x) { + if (thread[x].wait(1000)) + ++exited; + } - QCOMPARE(exited, ThreadCount); - QCOMPARE(wake_Thread::count, 0); + QCOMPARE(exited, ThreadCount); + QCOMPARE(wake_Thread::count, 0); - // QReadWriteLock - QReadWriteLock readWriteLock; - wake_Thread_2 rwthread[ThreadCount]; - - readWriteLock.lockForWrite(); - for (x = 0; x < ThreadCount; ++x) { - rwthread[x].readWriteLock = &readWriteLock; - rwthread[x].cond = &cond; - rwthread[x].start(); - // wait for thread to start - QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000)); - } - readWriteLock.unlock(); + // QReadWriteLock + QReadWriteLock readWriteLock; + wake_Thread_2 rwthread[ThreadCount]; - QCOMPARE(wake_Thread_2::count, ThreadCount); + readWriteLock.lockForWrite(); + for (x = 0; x < ThreadCount; ++x) { + rwthread[x].readWriteLock = &readWriteLock; + rwthread[x].cond = &cond; + rwthread[x].start(); + // wait for thread to start + QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000)); + } + readWriteLock.unlock(); - // wake up all threads at once - readWriteLock.lockForWrite(); - cond.wakeAll(); - QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME)); - readWriteLock.unlock(); + QCOMPARE(wake_Thread_2::count, ThreadCount); - exited = 0; - for (x = 0; x < ThreadCount; ++x) { - if (rwthread[x].wait(1000)) - ++exited; - } + // wake up all threads at once + readWriteLock.lockForWrite(); + cond.wakeAll(); + QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME)); + readWriteLock.unlock(); + + exited = 0; + for (x = 0; x < ThreadCount; ++x) { + if (rwthread[x].wait(1000)) + ++exited; + } - QCOMPARE(exited, ThreadCount); - QCOMPARE(wake_Thread_2::count, 0); + QCOMPARE(exited, ThreadCount); + QCOMPARE(wake_Thread_2::count, 0); } } diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp index 3baa47f013..c883c1c5f6 100644 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp @@ -43,12 +43,6 @@ #include <QtTest/QtTest> #include <QList> -/*! - \class tst_QVector - \internal - \since 4.5 - \brief Test Qt's class QList. - */ class tst_QList : public QObject { Q_OBJECT diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 72157c0536..a4c04d6207 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -95,8 +95,13 @@ bool operator==(const QRegularExpressionMatch &rem, const Match &m) } Q_FOREACH (const QString &name, m.namedCaptured.keys()) { - if (rem.captured(name) != m.namedCaptured.value(name)) + QString remCaptured = rem.captured(name); + QString mCaptured = m.namedCaptured.value(name); + if (remCaptured != mCaptured + || remCaptured.isNull() != mCaptured.isNull() + || remCaptured.isEmpty() != mCaptured.isEmpty()) { return false; + } } } @@ -571,6 +576,32 @@ void tst_QRegularExpression::normalMatch_data() << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) << m; + // non existing names for capturing groups + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "a string" << "a" << "string"; + m.namedCaptured["article"] = "a"; + m.namedCaptured["noun"] = "string"; + m.namedCaptured["nonexisting1"] = QString(); + m.namedCaptured["nonexisting2"] = QString(); + m.namedCaptured["nonexisting3"] = QString(); + QTest::newRow("match10") << QRegularExpression("(?<article>\\w+) (?<noun>\\w+)") + << "a string" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + + m.clear(); + m.isValid = true; m.hasMatch = true; + m.captured << "" << ""; + m.namedCaptured["digits"] = ""; // empty VS null + m.namedCaptured["nonexisting"] = QString(); + QTest::newRow("match11") << QRegularExpression("(?<digits>\\d*)") + << "abcde" + << 0 + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + // *** m.clear(); @@ -1196,3 +1227,55 @@ void tst_QRegularExpression::captureCount() if (!re.isValid()) QCOMPARE(re.captureCount(), -1); } + +void tst_QRegularExpression::pcreJitStackUsage_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QString>("subject"); + // these patterns cause enough backtrack (or even infinite recursion) + // in the regexp engine, so that JIT requests more memory. + QTest::newRow("jitstack01") << "(?(R)a*(?1)|((?R))b)" << "aaaabcde"; + QTest::newRow("jitstack02") << "(?(R)a*(?1)|((?R))b)" << "aaaaaaabcde"; +} + +void tst_QRegularExpression::pcreJitStackUsage() +{ + QFETCH(QString, pattern); + QFETCH(QString, subject); + + QRegularExpression re(pattern); + QVERIFY(re.isValid()); + QRegularExpressionMatch match = re.match(subject); + consistencyCheck(match); + QRegularExpressionMatchIterator iterator = re.globalMatch(subject); + consistencyCheck(iterator); + while (iterator.hasNext()) { + match = iterator.next(); + consistencyCheck(match); + } +} + +void tst_QRegularExpression::regularExpressionMatch_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QString>("subject"); + + QTest::newRow("validity01") << "(?<digits>\\d+)" << "1234 abcd"; + QTest::newRow("validity02") << "(?<digits>\\d+) (?<alpha>\\w+)" << "1234 abcd"; +} + +void tst_QRegularExpression::regularExpressionMatch() +{ + QFETCH(QString, pattern); + QFETCH(QString, subject); + + QRegularExpression re(pattern); + QVERIFY(re.isValid()); + QRegularExpressionMatch match = re.match(subject); + consistencyCheck(match); + QCOMPARE(match.captured("non-existing").isNull(), true); + QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatch::captured: empty capturing group name passed"); + QCOMPARE(match.captured("").isNull(), true); + QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatch::captured: empty capturing group name passed"); + QCOMPARE(match.captured(QString()).isNull(), true); +} diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h index 1a703a8f92..72a19199fd 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h @@ -71,6 +71,10 @@ private slots: void operatoreq(); void captureCount_data(); void captureCount(); + void pcreJitStackUsage_data(); + void pcreJitStackUsage(); + void regularExpressionMatch_data(); + void regularExpressionMatch(); private: void provideRegularExpressions(); |