diff options
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp | 11 | ||||
-rw-r--r-- | tests/auto/corelib/global/qflags/tst_qflags.cpp | 116 | ||||
-rw-r--r-- | tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp | 3 | ||||
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 34 | ||||
-rw-r--r-- | tests/auto/corelib/json/tst_qtjson.cpp | 77 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 25 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp | 53 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 20 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qhash/tst_qhash.cpp | 22 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 1 |
10 files changed, 346 insertions, 16 deletions
diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp index b5f736cfbb..616fe33309 100644 --- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp @@ -1917,6 +1917,17 @@ void tst_QTextCodec::codecForHtml_data() html = "<!DOCTYPE html><html><head><meta charset=\" utf' 8 /><title>Test</title></head>"; QTest::newRow("invalid charset, early terminator (')") << html << noDefault << fallback; + + const char src[] = { char(0xff), char(0xfe), char(0x7a), char(0x03), 0, 0 }; + html = src; + QTest::newRow("greek text UTF-16LE") << html << 106 << 1014; + + html = "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"><span style=\"color: rgb(0, 0, 0); font-family: " + "'Galatia SIL'; font-size: 27px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; " + "line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: " + "auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; display: inline !important; float: " + "none;\">ͻ</span>\000"; + QTest::newRow("greek text UTF-8") << html << 106 << 106; } void tst_QTextCodec::codecForHtml() diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index b9b817d688..e50a6b63fe 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -49,6 +49,7 @@ private slots: void testFlagMultiBits() const; void constExpr(); void signedness(); + void classEnum(); }; void tst_QFlags::testFlag() const @@ -137,6 +138,121 @@ void tst_QFlags::signedness() QtPrivate::is_signed<Qt::Alignment::Int>::value)); } +#if defined(Q_COMPILER_CLASS_ENUM) +enum class MyStrictEnum { StrictZero, StrictOne, StrictTwo, StrictFour=4 }; +Q_DECLARE_FLAGS( MyStrictFlags, MyStrictEnum ) +Q_DECLARE_OPERATORS_FOR_FLAGS( MyStrictFlags ) + +Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isComplex ); +Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isStatic ); +Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isLarge ); +Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isPointer ); +#endif + +void tst_QFlags::classEnum() +{ +#if defined(Q_COMPILER_CLASS_ENUM) + // The main aim of the test is making sure it compiles + // The QCOMPARE are there as an extra + MyStrictEnum e1 = MyStrictEnum::StrictOne; + MyStrictEnum e2 = MyStrictEnum::StrictTwo; + + MyStrictFlags f1(MyStrictEnum::StrictOne); + QCOMPARE(f1, 1); + + MyStrictFlags f2(e2); + QCOMPARE(f2, 2); + + MyStrictFlags f0; + QCOMPARE(f0, 0); + + MyStrictFlags f3(e2 | e1); + QCOMPARE(f3, 3); + + QVERIFY(f3.testFlag(MyStrictEnum::StrictOne)); + QVERIFY(!f1.testFlag(MyStrictEnum::StrictTwo)); + + QVERIFY(!f0); + + QCOMPARE(f3 & int(1), 1); + QCOMPARE(f3 & uint(1), 1); + QCOMPARE(f3 & MyStrictEnum::StrictOne, 1); + + MyStrictFlags aux; + aux = f3; + aux &= int(1); + QCOMPARE(aux, 1); + + aux = f3; + aux &= uint(1); + QCOMPARE(aux, 1); + + aux = f3; + aux &= MyStrictEnum::StrictOne; + QCOMPARE(aux, 1); + + aux = f3; + aux &= f1; + QCOMPARE(aux, 1); + + aux = f3 ^ f3; + QCOMPARE(aux, 0); + + aux = f3 ^ f1; + QCOMPARE(aux, 2); + + aux = f3 ^ f0; + QCOMPARE(aux, 3); + + aux = f3 ^ MyStrictEnum::StrictOne; + QCOMPARE(aux, 2); + + aux = f3 ^ MyStrictEnum::StrictZero; + QCOMPARE(aux, 3); + + aux = f3; + aux ^= f3; + QCOMPARE(aux, 0); + + aux = f3; + aux ^= f1; + QCOMPARE(aux, 2); + + aux = f3; + aux ^= f0; + QCOMPARE(aux, 3); + + aux = f3; + aux ^= MyStrictEnum::StrictOne; + QCOMPARE(aux, 2); + + aux = f3; + aux ^= MyStrictEnum::StrictZero; + QCOMPARE(aux, 3); + + aux = f1 | f2; + QCOMPARE(aux, 3); + + aux = MyStrictEnum::StrictOne | MyStrictEnum::StrictTwo; + QCOMPARE(aux, 3); + + aux = f1; + aux |= f2; + QCOMPARE(aux, 3); + + aux = MyStrictEnum::StrictOne; + aux |= MyStrictEnum::StrictTwo; + QCOMPARE(aux, 3); + + aux = ~f1; + QCOMPARE(aux, -2); + + // Just to make sure it compiles + if (false) + qDebug() << f3; +#endif +} + // (statically) check QTypeInfo for QFlags instantiations: enum MyEnum { Zero, One, Two, Four=4 }; Q_DECLARE_FLAGS( MyFlags, MyEnum ) diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index d7fc76d980..3607467ff9 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -268,7 +268,8 @@ static int NColorRoles[] = { QPalette::ToolTipText + 1, // Qt_4_5 QPalette::ToolTipText + 1, // Qt_4_6 QPalette::ToolTipText + 1, // Qt_5_0 - 0 // add the correct value for Qt_5_1 here later + QPalette::ToolTipText + 1, // Qt_5_1 + 0 // add the correct value for Qt_5_2 here later }; // Testing get/set functions diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index f01e319872..613bfd5c17 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -152,6 +152,7 @@ private slots: void invalidProgramString_data(); void invalidProgramString(); void onlyOneStartedSignal(); + void finishProcessBeforeReadingDone(); // keep these at the end, since they use lots of processes and sometimes // caused obscure failures to occur in tests that followed them (esp. on the Mac) @@ -2168,6 +2169,39 @@ void tst_QProcess::onlyOneStartedSignal() QCOMPARE(spyFinished.count(), 1); } +//----------------------------------------------------------------------------- + +class BlockOnReadStdOut : public QObject +{ + Q_OBJECT +public: + BlockOnReadStdOut(QProcess *process) + { + connect(process, SIGNAL(readyReadStandardOutput()), SLOT(block())); + } + +public slots: + void block() + { + QThread::sleep(1); + } +}; + +void tst_QProcess::finishProcessBeforeReadingDone() +{ + QProcess process; + BlockOnReadStdOut blocker(&process); + QEventLoop loop; + connect(&process, SIGNAL(finished(int)), &loop, SLOT(quit())); + process.start("testProcessOutput/testProcessOutput"); + QVERIFY(process.waitForStarted()); + loop.exec(); + QStringList lines = QString::fromLocal8Bit(process.readAllStandardOutput()).split( + QRegExp(QStringLiteral("[\r\n]")), QString::SkipEmptyParts); + QVERIFY(!lines.isEmpty()); + QCOMPARE(lines.last(), QStringLiteral("10239 -this is a number")); +} + #endif //QT_NO_PROCESS QTEST_MAIN(tst_QProcess) diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 543226978c..010c8acb5f 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -234,9 +234,54 @@ void tst_QtJson::testNumbers() QJsonArray array; for (int i = 0; i < n; ++i) array.append((double)numbers[i]); + + QByteArray serialized = QJsonDocument(array).toJson(); + QJsonDocument json = QJsonDocument::fromJson(serialized); + QJsonArray array2 = json.array(); + + QCOMPARE(array.size(), array2.size()); + for (int i = 0; i < array.size(); ++i) { + QCOMPARE(array.at(i).type(), QJsonValue::Double); + QCOMPARE(array.at(i).toDouble(), (double)numbers[i]); + QCOMPARE(array2.at(i).type(), QJsonValue::Double); + QCOMPARE(array2.at(i).toDouble(), (double)numbers[i]); + } + } + + { + qint64 numbers[] = { + 0, + -1, + 1, + (1UL<<54), + (1UL<<55), + (1UL<<56), + -(1UL<<54), + -(1UL<<55), + -(1UL<<56), + (1UL<<54) - 1, + (1UL<<55) - 1, + (1UL<<56) - 1, + -((1UL<<54) - 1), + -((1UL<<55) - 1), + -((1UL<<56) - 1) + }; + int n = sizeof(numbers)/sizeof(qint64); + + QJsonArray array; + for (int i = 0; i < n; ++i) + array.append((double)numbers[i]); + + QByteArray serialized = QJsonDocument(array).toJson(); + QJsonDocument json = QJsonDocument::fromJson(serialized); + QJsonArray array2 = json.array(); + + QCOMPARE(array.size(), array2.size()); for (int i = 0; i < array.size(); ++i) { QCOMPARE(array.at(i).type(), QJsonValue::Double); QCOMPARE(array.at(i).toDouble(), (double)numbers[i]); + QCOMPARE(array2.at(i).type(), QJsonValue::Double); + QCOMPARE(array2.at(i).toDouble(), (double)numbers[i]); } } @@ -245,18 +290,18 @@ void tst_QtJson::testNumbers() 0, -1, 1, - (1<<26), - (1<<27), - (1<<28), - -(1<<26), - -(1<<27), - -(1<<28), - (1<<26) - 1, - (1<<27) - 1, - (1<<28) - 1, - -((1<<26) - 1), - -((1<<27) - 1), - -((1<<28) - 1), + (1UL<<54), + (1UL<<55), + (1UL<<56), + -(1UL<<54), + -(1UL<<55), + -(1UL<<56), + (1UL<<54) - 1, + (1UL<<55) - 1, + (1UL<<56) - 1, + -((1UL<<54) - 1), + -((1UL<<55) - 1), + -((1UL<<56) - 1), 1.1, 0.1, -0.1, @@ -269,9 +314,17 @@ void tst_QtJson::testNumbers() QJsonArray array; for (int i = 0; i < n; ++i) array.append(numbers[i]); + + QByteArray serialized = QJsonDocument(array).toJson(); + QJsonDocument json = QJsonDocument::fromJson(serialized); + QJsonArray array2 = json.array(); + + QCOMPARE(array.size(), array2.size()); for (int i = 0; i < array.size(); ++i) { QCOMPARE(array.at(i).type(), QJsonValue::Double); QCOMPARE(array.at(i).toDouble(), numbers[i]); + QCOMPARE(array2.at(i).type(), QJsonValue::Double); + QCOMPARE(array2.at(i).toDouble(), numbers[i]); } } diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 06fc89f657..d16369de02 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -145,6 +145,7 @@ private slots: void connectFunctorArgDifference(); void connectFunctorOverloads(); void disconnectDoesNotLeakFunctor(); + void connectBase(); }; struct QObjectCreatedOnShutdown @@ -5811,5 +5812,29 @@ void tst_QObject::disconnectDoesNotLeakFunctor() QCOMPARE(countedStructObjectsCount, 0); } +class SubSender : public SenderObject { + Q_OBJECT +}; + +void tst_QObject::connectBase() +{ + SubSender sub; + ReceiverObject r1; + r1.reset(); + + QVERIFY( connect( &sub, &SubSender::signal1 , &r1, &ReceiverObject::slot1 ) ); + QVERIFY( connect( &sub, static_cast<void (SenderObject::*)()>(&SubSender::signal2) , &r1, &ReceiverObject::slot2 ) ); + QVERIFY( connect( &sub, static_cast<void (SubSender::*)()>(&SubSender::signal3) , &r1, &ReceiverObject::slot3 ) ); + + sub.emitSignal1(); + sub.emitSignal2(); + sub.emitSignal3(); + + QCOMPARE( r1.count_slot1, 1 ); + QCOMPARE( r1.count_slot2, 1 ); + QCOMPARE( r1.count_slot3, 1 ); +} + + QTEST_MAIN(tst_QObject) #include "tst_qobject.moc" diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 8a72ae5bce..fb34afb880 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -94,6 +94,8 @@ private slots: void tryStart(); void tryStartPeakThreadCount(); void tryStartCount(); + void priorityStart_data(); + void priorityStart(); void waitForDone(); void waitForDoneTimeout(); void destroyingWaitsForTasksToFinish(); @@ -747,6 +749,57 @@ void tst_QThreadPool::tryStartCount() } } +void tst_QThreadPool::priorityStart_data() +{ + QTest::addColumn<int>("otherCount"); + QTest::newRow("0") << 0; + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; +} + +void tst_QThreadPool::priorityStart() +{ + class Holder : public QRunnable + { + public: + QSemaphore &sem; + Holder(QSemaphore &sem) : sem(sem) {} + void run() + { + sem.acquire(); + } + }; + class Runner : public QRunnable + { + public: + QAtomicPointer<QRunnable> &ptr; + Runner(QAtomicPointer<QRunnable> &ptr) : ptr(ptr) {} + void run() + { + ptr.testAndSetRelaxed(0, this); + } + }; + + QFETCH(int, otherCount); + QSemaphore sem; + QAtomicPointer<QRunnable> firstStarted; + QRunnable *expected; + QThreadPool threadPool; + threadPool.setMaxThreadCount(1); // start only one thread at a time + + // queue the holder first + // We need to be sure that all threads are active when we + // queue the two Runners + threadPool.start(new Holder(sem)); + while (otherCount--) + threadPool.start(new Runner(firstStarted), 0); // priority 0 + threadPool.start(expected = new Runner(firstStarted), 1); // priority 1 + + sem.release(); + QVERIFY(threadPool.waitForDone()); + QCOMPARE(firstStarted.load(), expected); +} + void tst_QThreadPool::waitForDone() { QTime total, pass; diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 6cfcf74069..0ec3f64020 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -1398,13 +1398,19 @@ void tst_QDateTime::operator_insert_extract() { QDataStream dataStream(&byteArray, QIODevice::WriteOnly); dataStream.setVersion(dataStreamVersion); - if (dataStreamVersion >= QDataStream::Qt_5_0) { + if (dataStreamVersion == QDataStream::Qt_5_0) { // Qt 5 serialises as UTC and converts back to the stored timeSpec when // deserialising; we don't need to do it ourselves... dataStream << dateTime << dateTime; } else { - // ... but lower versions don't, so we have to here. + // ... but other versions don't, so we have to here. dataStream << dateTimeAsUTC << dateTimeAsUTC; + // We'll also make sure that a deserialised local datetime is the same + // time of day (potentially different UTC time), regardless of which + // timezone it was serialised in. E.g.: Tue Aug 14 08:00:00 2012 + // serialised in WST should be deserialised as Tue Aug 14 08:00:00 2012 + // HST. + dataStream << dateTime; } } @@ -1420,7 +1426,7 @@ void tst_QDateTime::operator_insert_extract() QDateTime deserialised; dataStream >> deserialised; - if (dataStreamVersion >= QDataStream::Qt_5_0) { + if (dataStreamVersion == QDataStream::Qt_5_0) { // Ensure local time is still correct. Again, Qt 5 handles the timeSpec // conversion (in this case, UTC => LocalTime) for us when deserialising. QCOMPARE(deserialised, expectedLocalTime); @@ -1453,6 +1459,14 @@ void tst_QDateTime::operator_insert_extract() QCOMPARE(deserialised, expectedLocalTime); // Sanity check UTC times. QCOMPARE(deserialised.toUTC(), expectedLocalTime.toUTC()); + + if (dataStreamVersion != QDataStream::Qt_5_0) { + // Deserialised local datetime should be the same time of day, + // regardless of which timezone it was serialised in. + QDateTime localDeserialized; + dataStream >> localDeserialized; + QCOMPARE(localDeserialized, dateTime); + } } qputenv("TZ", previousTimeZone.toLocal8Bit().constData()); diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 1cbf181286..71428310b8 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -75,6 +75,9 @@ private slots: void const_shared_null(); void twoArguments_qHash(); void initializerList(); + + void qthash_data(); + void qthash(); }; struct Foo { @@ -1330,5 +1333,24 @@ void tst_QHash::initializerList() #endif } +void tst_QHash::qthash_data() +{ + QTest::addColumn<QString>("key"); + QTest::addColumn<uint>("hash"); + + QTest::newRow("null") << QString() << 0u; + QTest::newRow("empty") << QStringLiteral("") << 0u; + QTest::newRow("abcdef") << QStringLiteral("abcdef") << 108567222u; + QTest::newRow("tqbfjotld") << QStringLiteral("The quick brown fox jumps over the lazy dog") << 140865879u; + QTest::newRow("42") << QStringLiteral("42") << 882u; +} + +void tst_QHash::qthash() +{ + QFETCH(QString, key); + const uint result = qt_hash(key); + QTEST(result, "hash"); +} + QTEST_APPLESS_MAIN(tst_QHash) #include "tst_qhash.moc" diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index f8775bc75f..0f6015ebdc 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -350,6 +350,7 @@ void tst_QLocale::ctor() TEST_CTOR("es_ES", Spanish, Spain) TEST_CTOR("es_419", Spanish, LatinAmericaAndTheCaribbean) TEST_CTOR("es-419", Spanish, LatinAmericaAndTheCaribbean) + TEST_CTOR("fr_MA", French, Morocco) // test default countries for languages TEST_CTOR("zh", Chinese, China) |