diff options
Diffstat (limited to 'tests/auto/corelib/tools')
25 files changed, 941 insertions, 492 deletions
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index 38366e86ff..b40b1f0624 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -2620,6 +2620,8 @@ void testLinkedListLikeStlIterators() QVERIFY(i2 == c2); QVERIFY(c2 == i2); QVERIFY(c2 == c2); + QVERIFY(1 + i1 == i1 + 1); + QVERIFY(1 + c1 == c1 + 1); QVERIFY(i1 != i2); QVERIFY(i1 != c2); @@ -2731,6 +2733,8 @@ void testMapLikeStlIterators() QVERIFY(i2 == c2); QVERIFY(c2 == i2); QVERIFY(c2 == c2); + QVERIFY(1 + i1 == i1 + 1); + QVERIFY(1 + c1 == c1 + 1); QVERIFY(i1 != i2); QVERIFY(i1 != c2); diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index 338adaabf7..1ed41793dc 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -106,6 +106,8 @@ private slots: void number(); void toInt_data(); void toInt(); + void toDouble_data(); + void toDouble(); void blockSizeCalculations(); void resizeAfterFromRawData(); @@ -141,6 +143,8 @@ private slots: #endif void toUpperLower_data(); void toUpperLower(); + void isUpper(); + void isLower(); void macTypes(); @@ -856,15 +860,38 @@ void tst_QByteArray::qstricmp() if ( actual != 0 ) { actual = (actual < 0 ? -1 : 1); } - QCOMPARE(expected, actual); + QCOMPARE(actual, expected); + + actual = ::qstricmp("012345679abcd" + str1.toLatin1(), "012345679AbCd" + str2.toLatin1()); + if ( actual != 0 ) { + actual = (actual < 0 ? -1 : 1); + } + QCOMPARE(actual, expected); + + actual = str1.toLatin1().compare(str2.toLatin1(), Qt::CaseInsensitive); + if ( actual != 0 ) { + actual = (actual < 0 ? -1 : 1); + } + QCOMPARE(actual, expected); + + actual = str1.toLatin1().compare(str2.toLatin1().constData(), Qt::CaseInsensitive); + if ( actual != 0 ) { + actual = (actual < 0 ? -1 : 1); + } + QCOMPARE(actual, expected); } void tst_QByteArray::qstricmp_singularities() { QCOMPARE(::qstricmp(0, 0), 0); - QVERIFY(::qstricmp(0, "a") != 0); - QVERIFY(::qstricmp("a", 0) != 0); + QVERIFY(::qstricmp(0, "a") < 0); + QVERIFY(::qstricmp("a", 0) > 0); QCOMPARE(::qstricmp("", ""), 0); + QCOMPARE(QByteArray().compare(nullptr, Qt::CaseInsensitive), 0); + QCOMPARE(QByteArray().compare("", Qt::CaseInsensitive), 0); + QVERIFY(QByteArray("a").compare(nullptr, Qt::CaseInsensitive) > 0); + QVERIFY(QByteArray("a").compare("", Qt::CaseInsensitive) > 0); + QVERIFY(QByteArray().compare("a", Qt::CaseInsensitive) < 0); } void tst_QByteArray::qstrnicmp_singularities() @@ -874,6 +901,9 @@ void tst_QByteArray::qstrnicmp_singularities() QVERIFY(::qstrnicmp("a", 0, 123) != 0); QCOMPARE(::qstrnicmp("", "", 123), 0); QCOMPARE(::qstrnicmp("a", "B", 0), 0); + QCOMPARE(QByteArray().compare(QByteArray(), Qt::CaseInsensitive), 0); + QVERIFY(QByteArray().compare(QByteArray("a"), Qt::CaseInsensitive) < 0); + QVERIFY(QByteArray("a").compare(QByteArray(), Qt::CaseInsensitive) > 0); } void tst_QByteArray::chop_data() @@ -1289,6 +1319,11 @@ void tst_QByteArray::toInt_data() QTest::newRow("base 0-3") << QByteArray("010") << 0 << int(8) << true; QTest::newRow("empty") << QByteArray() << 0 << int(0) << false; + QTest::newRow("leading space") << QByteArray(" 100") << 10 << int(100) << true; + QTest::newRow("trailing space") << QByteArray("100 ") << 10 << int(100) << true; + QTest::newRow("leading junk") << QByteArray("x100") << 10 << int(0) << false; + QTest::newRow("trailing junk") << QByteArray("100x") << 10 << int(0) << false; + // using fromRawData QTest::newRow("raw1") << QByteArray::fromRawData("1", 1) << 10 << 1 << true; QTest::newRow("raw2") << QByteArray::fromRawData("1foo", 1) << 10 << 1 << true; @@ -1313,6 +1348,34 @@ void tst_QByteArray::toInt() QCOMPARE( number, expectednumber ); } +void tst_QByteArray::toDouble_data() +{ + QTest::addColumn<QByteArray>("string"); + QTest::addColumn<double>("expectedNumber"); + QTest::addColumn<bool>("expectedOk"); + + QTest::newRow("decimal") << QByteArray("1.2345") << 1.2345 << true; + QTest::newRow("exponent lowercase") << QByteArray("1.2345e+01") << 12.345 << true; + QTest::newRow("exponent uppercase") << QByteArray("1.2345E+02") << 123.45 << true; + QTest::newRow("leading spaces") << QByteArray(" \n\r\t1.2345") << 1.2345 << true; + QTest::newRow("trailing spaces") << QByteArray("1.2345 \n\r\t") << 1.2345 << true; + QTest::newRow("leading junk") << QByteArray("x1.2345") << 0.0 << false; + QTest::newRow("trailing junk") << QByteArray("1.2345x") << 0.0 << false; +} + +void tst_QByteArray::toDouble() +{ + QFETCH(QByteArray, string); + QFETCH(double, expectedNumber); + QFETCH(bool, expectedOk); + + bool ok; + const double number = string.toDouble(&ok); + + QCOMPARE(ok, expectedOk); + QCOMPARE(number, expectedNumber); +} + void tst_QByteArray::toULong_data() { QTest::addColumn<QByteArray>("str"); @@ -1326,6 +1389,11 @@ void tst_QByteArray::toULong_data() QTest::newRow("empty") << QByteArray("") << 10 << 0UL << false; QTest::newRow("ulong1") << QByteArray("3234567890") << 10 << 3234567890UL << true; QTest::newRow("ulong2") << QByteArray("fFFfFfFf") << 16 << 0xFFFFFFFFUL << true; + + QTest::newRow("leading spaces") << QByteArray(" \n\r\t100") << 10 << 100UL << true; + QTest::newRow("trailing spaces") << QByteArray("100 \n\r\t") << 10 << 100UL << true; + QTest::newRow("leading junk") << QByteArray("x100") << 10 << 0UL << false; + QTest::newRow("trailing junk") << QByteArray("100x") << 10 << 0UL << false; } void tst_QByteArray::toULong() @@ -1351,6 +1419,10 @@ void tst_QByteArray::toULongLong_data() QTest::newRow("default") << QByteArray() << 10 << (qulonglong)0 << false; QTest::newRow("out of base bound") << QByteArray("c") << 10 << (qulonglong)0 << false; + QTest::newRow("leading spaces") << QByteArray(" \n\r\t100") << 10 << qulonglong(100) << true; + QTest::newRow("trailing spaces") << QByteArray("100 \n\r\t") << 10 << qulonglong(100) << true; + QTest::newRow("leading junk") << QByteArray("x100") << 10 << qulonglong(0) << false; + QTest::newRow("trailing junk") << QByteArray("100x") << 10 << qulonglong(0) << false; } void tst_QByteArray::toULongLong() @@ -1757,6 +1829,12 @@ void tst_QByteArray::compare() const bool isLess = result < 0; const bool isGreater = result > 0; + int cmp = str1.compare(str2); + if (cmp) + cmp = (cmp < 0 ? -1 : 1); + + QCOMPARE(cmp, result); + // basic tests: QCOMPARE(str1 == str2, isEqual); QCOMPARE(str1 < str2, isLess); @@ -2188,6 +2266,51 @@ void tst_QByteArray::toUpperLower() QCOMPARE(qMove(copy).toUpper(), upper); } +void tst_QByteArray::isUpper() +{ + QVERIFY(!QByteArray().isUpper()); + QVERIFY(!QByteArray("").isUpper()); + QVERIFY(QByteArray("TEXT").isUpper()); + QVERIFY(QByteArray("\xD0\xDE").isUpper()); + QVERIFY(!QByteArray("\xD7").isUpper()); // multiplication sign is not upper + QVERIFY(!QByteArray("\xDF").isUpper()); // sz ligature is not upper + QVERIFY(!QByteArray("text").isUpper()); + QVERIFY(!QByteArray("Text").isUpper()); + QVERIFY(!QByteArray("tExt").isUpper()); + QVERIFY(!QByteArray("teXt").isUpper()); + QVERIFY(!QByteArray("texT").isUpper()); + QVERIFY(!QByteArray("TExt").isUpper()); + QVERIFY(!QByteArray("teXT").isUpper()); + QVERIFY(!QByteArray("tEXt").isUpper()); + QVERIFY(!QByteArray("tExT").isUpper()); + QVERIFY(!QByteArray("@ABYZ[").isUpper()); + QVERIFY(!QByteArray("@abyz[").isUpper()); + QVERIFY(!QByteArray("`ABYZ{").isUpper()); + QVERIFY(!QByteArray("`abyz{").isUpper()); +} + +void tst_QByteArray::isLower() +{ + QVERIFY(!QByteArray().isLower()); + QVERIFY(!QByteArray("").isLower()); + QVERIFY(QByteArray("text").isLower()); + QVERIFY(QByteArray("\xE0\xFF").isLower()); + QVERIFY(!QByteArray("\xF7").isLower()); // division sign is not lower + QVERIFY(!QByteArray("Text").isLower()); + QVERIFY(!QByteArray("tExt").isLower()); + QVERIFY(!QByteArray("teXt").isLower()); + QVERIFY(!QByteArray("texT").isLower()); + QVERIFY(!QByteArray("TExt").isLower()); + QVERIFY(!QByteArray("teXT").isLower()); + QVERIFY(!QByteArray("tEXt").isLower()); + QVERIFY(!QByteArray("tExT").isLower()); + QVERIFY(!QByteArray("TEXT").isLower()); + QVERIFY(!QByteArray("@ABYZ[").isLower()); + QVERIFY(!QByteArray("@abyz[").isLower()); + QVERIFY(!QByteArray("`ABYZ{").isLower()); + QVERIFY(!QByteArray("`abyz{").isLower()); +} + void tst_QByteArray::macTypes() { #ifndef Q_OS_MAC diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index 527e07593c..ce3bdc2d9d 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -100,7 +100,7 @@ void tst_QCommandLineParser::testInvalidOptions() QCoreApplication app(empty_argc, empty_argv); QCommandLineParser parser; QTest::ignoreMessage(QtWarningMsg, "QCommandLineOption: Option names cannot start with a '-'"); - parser.addOption(QCommandLineOption(QStringLiteral("-v"), QStringLiteral("Displays version information."))); + QVERIFY(!parser.addOption(QCommandLineOption(QStringLiteral("-v"), QStringLiteral("Displays version information.")))); } void tst_QCommandLineParser::testPositionalArguments() @@ -336,7 +336,7 @@ void tst_QCommandLineParser::testDoubleDash() QCoreApplication app(empty_argc, empty_argv); QCommandLineParser parser; - parser.addOption(QCommandLineOption(QStringList() << "o" << "output", QStringLiteral("Output file"), QStringLiteral("filename"))); + QVERIFY(parser.addOption(QCommandLineOption(QStringList() << "o" << "output", QStringLiteral("Output file"), QStringLiteral("filename")))); parser.setSingleDashWordOptionMode(parsingMode); QVERIFY(parser.parse(QStringList() << "tst_qcommandlineparser" << "--output" << "foo")); QCOMPARE(parser.value("output"), QString("foo")); @@ -382,7 +382,7 @@ void tst_QCommandLineParser::testMissingOptionValue() { QCoreApplication app(empty_argc, empty_argv); QCommandLineParser parser; - parser.addOption(QCommandLineOption(QStringLiteral("option"), QStringLiteral("An option"), "value")); + QVERIFY(parser.addOption(QCommandLineOption(QStringLiteral("option"), QStringLiteral("An option"), "value"))); QVERIFY(!parser.parse(QStringList() << "argv0" << "--option")); // the user forgot to pass a value for --option QCOMPARE(parser.value("option"), QString()); QCOMPARE(parser.errorText(), QString("Missing value after '--option'.")); @@ -400,8 +400,8 @@ void tst_QCommandLineParser::testStdinArgument() QCoreApplication app(empty_argc, empty_argv); QCommandLineParser parser; parser.setSingleDashWordOptionMode(parsingMode); - parser.addOption(QCommandLineOption(QStringList() << "i" << "input", QStringLiteral("Input file."), QStringLiteral("filename"))); - parser.addOption(QCommandLineOption("b", QStringLiteral("Boolean option."))); + QVERIFY(parser.addOption(QCommandLineOption(QStringList() << "i" << "input", QStringLiteral("Input file."), QStringLiteral("filename")))); + QVERIFY(parser.addOption(QCommandLineOption("b", QStringLiteral("Boolean option.")))); QVERIFY(parser.parse(QStringList() << "tst_qcommandlineparser" << "--input" << "-")); QCOMPARE(parser.value("input"), QString("-")); QCOMPARE(parser.positionalArguments(), QStringList()); @@ -471,14 +471,14 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes() QCoreApplication app(empty_argc, empty_argv); QCommandLineParser parser; parser.setSingleDashWordOptionMode(parsingMode); - parser.addOption(QCommandLineOption("a", QStringLiteral("a option."))); - parser.addOption(QCommandLineOption("b", QStringLiteral("b option."))); - parser.addOption(QCommandLineOption(QStringList() << "c" << "abc", QStringLiteral("c option."), QStringLiteral("value"))); - parser.addOption(QCommandLineOption("nn", QStringLiteral("nn option."))); + QVERIFY(parser.addOption(QCommandLineOption("a", QStringLiteral("a option.")))); + QVERIFY(parser.addOption(QCommandLineOption("b", QStringLiteral("b option.")))); + QVERIFY(parser.addOption(QCommandLineOption(QStringList() << "c" << "abc", QStringLiteral("c option."), QStringLiteral("value")))); + QVERIFY(parser.addOption(QCommandLineOption("nn", QStringLiteral("nn option.")))); QCommandLineOption forceShort(QStringLiteral("I"), QStringLiteral("always short option"), QStringLiteral("path"), QStringLiteral("default")); forceShort.setFlags(QCommandLineOption::ShortOptionStyle); - parser.addOption(forceShort); + QVERIFY(parser.addOption(forceShort)); QVERIFY(parser.parse(commandLine)); QCOMPARE(parser.optionNames(), expectedOptionNames); for (int i = 0; i < expectedOptionValues.count(); ++i) @@ -493,11 +493,11 @@ void tst_QCommandLineParser::testCpp11StyleInitialization() QCommandLineParser parser; // primarily check that this compiles: - parser.addOptions({ + QVERIFY(parser.addOptions({ { "a", "The A option." }, { { "v", "verbose" }, "The verbose option." }, { { "i", "infile" }, "The input file.", "value" }, - }); + })); // but do a very basic functionality test, too: QVERIFY(parser.parse({"tst_QCommandLineParser", "-a", "-vvv", "--infile=in.txt"})); QCOMPARE(parser.optionNames(), (QStringList{"a", "v", "v", "v", "infile"})); diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp index 17a0f3edd9..3eef7631c8 100644 --- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp +++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp @@ -29,6 +29,7 @@ #include <QtCore/QCoreApplication> #include <QtTest/QtTest> +#include <QtCore/QMetaEnum> Q_DECLARE_METATYPE(QCryptographicHash::Algorithm) @@ -45,6 +46,7 @@ private slots: void sha3(); void files_data(); void files(); + void hashLength(); }; void tst_QCryptographicHash::repeated_result_data() @@ -291,6 +293,15 @@ void tst_QCryptographicHash::files() } } +void tst_QCryptographicHash::hashLength() +{ + auto metaEnum = QMetaEnum::fromType<QCryptographicHash::Algorithm>(); + for (int i = 0, value = metaEnum.value(i); value != -1; value = metaEnum.value(++i)) { + auto algorithm = QCryptographicHash::Algorithm(value); + QByteArray output = QCryptographicHash::hash(QByteArrayLiteral("test"), algorithm); + QCOMPARE(QCryptographicHash::hashLength(algorithm), output.length()); + } +} QTEST_MAIN(tst_QCryptographicHash) #include "tst_qcryptographichash.moc" diff --git a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp index f545ead1f1..e89e634841 100644 --- a/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp +++ b/tests/auto/corelib/tools/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp @@ -159,6 +159,8 @@ void tst_QExplicitlySharedDataPointer::data() const { QExplicitlySharedDataPointer<const MyClass> pointer; QCOMPARE(pointer.data(), static_cast<const MyClass *>(0)); + QVERIFY(pointer == nullptr); + QVERIFY(nullptr == pointer); } /* On const pointer. Must not mutate the pointer. */ @@ -168,6 +170,9 @@ void tst_QExplicitlySharedDataPointer::data() const /* Check that this cast is possible. */ static_cast<const MyClass *>(pointer.data()); + + QVERIFY(! (pointer == nullptr)); + QVERIFY(! (nullptr == pointer)); } /* On mutatable pointer. Must not mutate the pointer. */ diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 4131c44c84..b76851a0ec 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -118,8 +118,10 @@ private slots: void monthName(); void standaloneMonthName(); - void defaultNumeringSystem(); + void defaultNumberingSystem_data(); + void defaultNumberingSystem(); + void ampm_data(); void ampm(); void currency(); void quoteString(); @@ -127,6 +129,7 @@ private slots: void weekendDays(); void listPatterns(); + void measurementSystems_data(); void measurementSystems(); void QTBUG_26035_positivesign(); @@ -135,6 +138,7 @@ private slots: void formattedDataSize_data(); void formattedDataSize(); + void bcp47Name_data(); void bcp47Name(); void systemLocale_data(); @@ -145,6 +149,7 @@ private slots: // QLocale::setDefault() *must* appear *after* all other tests ! void defaulted_ctor(); // This one must be the first of these. void legacyNames(); + void unixLocaleName_data(); void unixLocaleName(); void testNames_data(); void testNames(); @@ -214,32 +219,48 @@ void tst_QLocale::ctor() } // Exact matches - TEST_CTOR(Chinese, SimplifiedHanScript, China, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); - TEST_CTOR(Chinese, TraditionalHanScript, Taiwan, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); - TEST_CTOR(Chinese, TraditionalHanScript, HongKong, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::HongKong); + TEST_CTOR(Chinese, SimplifiedHanScript, China, + QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, TraditionalHanScript, Taiwan, + QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, TraditionalHanScript, HongKong, + QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::HongKong); // Best match for AnyCountry - TEST_CTOR(Chinese, SimplifiedHanScript, AnyCountry, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); - TEST_CTOR(Chinese, TraditionalHanScript, AnyCountry, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, SimplifiedHanScript, AnyCountry, + QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, TraditionalHanScript, AnyCountry, + QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); // Best match for AnyScript (and change country to supported one, if necessary) - TEST_CTOR(Chinese, AnyScript, China, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); - TEST_CTOR(Chinese, AnyScript, Taiwan, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); - TEST_CTOR(Chinese, AnyScript, HongKong, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::HongKong); - TEST_CTOR(Chinese, AnyScript, UnitedStates, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, AnyScript, China, + QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, AnyScript, Taiwan, + QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, AnyScript, HongKong, + QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::HongKong); + TEST_CTOR(Chinese, AnyScript, UnitedStates, + QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); // Fully-specified not found; find best alternate country - TEST_CTOR(Chinese, SimplifiedHanScript, Taiwan, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); - TEST_CTOR(Chinese, SimplifiedHanScript, UnitedStates, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); - TEST_CTOR(Chinese, TraditionalHanScript, China, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); - TEST_CTOR(Chinese, TraditionalHanScript, UnitedStates, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, SimplifiedHanScript, Taiwan, + QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, SimplifiedHanScript, UnitedStates, + QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, TraditionalHanScript, China, + QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, TraditionalHanScript, UnitedStates, + QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); // Fully-specified not found; find best alternate script - TEST_CTOR(Chinese, LatinScript, China, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); - TEST_CTOR(Chinese, LatinScript, Taiwan, QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); + TEST_CTOR(Chinese, LatinScript, China, + QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, LatinScript, Taiwan, + QLocale::Chinese, QLocale::TraditionalHanScript, QLocale::Taiwan); // Fully-specified not found; find best alternate country and script - TEST_CTOR(Chinese, LatinScript, UnitedStates, QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); + TEST_CTOR(Chinese, LatinScript, UnitedStates, + QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China); #undef TEST_CTOR } @@ -278,7 +299,8 @@ void tst_QLocale::defaulted_ctor() TEST_CTOR(French, France, QLocale::French, QLocale::France) TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry) - TEST_CTOR(Spanish, LatinAmericaAndTheCaribbean, QLocale::Spanish, QLocale::LatinAmericaAndTheCaribbean) + TEST_CTOR(Spanish, LatinAmericaAndTheCaribbean, QLocale::Spanish, + QLocale::LatinAmericaAndTheCaribbean) QLocale::setDefault(QLocale(QLocale::English, QLocale::France)); @@ -370,8 +392,9 @@ void tst_QLocale::defaulted_ctor() QVERIFY2(l.language() == QLocale::exp_lang \ && l.country() == QLocale::exp_country, \ QString("requested: \"" + QString(req_lc) + "\", got: " \ - + QLocale::languageToString(l.language()) \ - + QLatin1Char('/') + QLocale::countryToString(l.country())).toLatin1().constData()); \ + + QLocale::languageToString(l.language()) \ + + QLatin1Char('/') \ + + QLocale::countryToString(l.country())).toLatin1().constData()); \ QCOMPARE(l, QLocale(QLocale::exp_lang, QLocale::exp_country)); \ QCOMPARE(qHash(l), qHash(QLocale(QLocale::exp_lang, QLocale::exp_country))); \ } @@ -464,7 +487,8 @@ static inline bool runSysApp(const QString &binary, process.start(binary); process.closeWriteChannel(); if (!process.waitForStarted()) { - *errorMessage = QString::fromLatin1("Cannot start '%1': %2").arg(binary, process.errorString()); + *errorMessage = QLatin1String("Cannot start '") + binary + + QLatin1String("': ") + process.errorString(); return false; } if (!process.waitForFinished()) { @@ -488,13 +512,14 @@ static inline bool runSysAppTest(const QString &binary, return false; if (output.isEmpty()) { - *errorMessage = QString::fromLatin1("Empty output received for requested '%1' (expected '%2')"). - arg(requestedLocale, expectedOutput); + *errorMessage = QLatin1String("Empty output received for requested '") + requestedLocale + + QLatin1String("' (expected '") + expectedOutput + QLatin1String("')"); return false; } if (output != expectedOutput) { - *errorMessage = QString::fromLatin1("Output mismatch for requested '%1': Expected '%2', got '%3'"). - arg(requestedLocale, expectedOutput, output); + *errorMessage = QLatin1String("Output mismatch for requested '") + requestedLocale + + QLatin1String("': Expected '") + expectedOutput + QLatin1String("', got '") + + output + QLatin1String("'"); return false; } return true; @@ -598,8 +623,9 @@ void tst_QLocale::legacyNames() QVERIFY2(l.language() == QLocale::exp_lang \ && l.country() == QLocale::exp_country, \ QString("requested: \"" + QString(req_lc) + "\", got: " \ - + QLocale::languageToString(l.language()) \ - + QLatin1Char('/') + QLocale::countryToString(l.country())).toLatin1().constData()); \ + + QLocale::languageToString(l.language()) \ + + QLatin1Char('/') \ + + QLocale::countryToString(l.country())).toLatin1().constData()); \ } TEST_CTOR("mo_MD", Romanian, Moldova) @@ -649,22 +675,32 @@ void tst_QLocale::matchingLocales() QVERIFY(locales.contains(ru_RU)); } +void tst_QLocale::unixLocaleName_data() +{ + QTest::addColumn<QLocale::Language>("lang"); + QTest::addColumn<QLocale::Country>("land"); + QTest::addColumn<QString>("expect"); + +#define ADDROW(nom, lang, land, name) \ + QTest::newRow(nom) << QLocale::lang << QLocale::land << QStringLiteral(name) + + ADDROW("C_any", C, AnyCountry, "C"); + ADDROW("en_any", English, AnyCountry, "en_US"); + ADDROW("en_GB", English, UnitedKingdom, "en_GB"); + ADDROW("ay_GB", Aymara, UnitedKingdom, "C"); +#undef ADDROW +} + void tst_QLocale::unixLocaleName() { -#define TEST_NAME(req_lang, req_country, exp_name) \ - { \ - QLocale l(QLocale::req_lang, QLocale::req_country); \ - QCOMPARE(l.name(), QString(exp_name)); \ - } + QFETCH(QLocale::Language, lang); + QFETCH(QLocale::Country, land); + QFETCH(QString, expect); QLocale::setDefault(QLocale(QLocale::C)); - TEST_NAME(C, AnyCountry, "C") - TEST_NAME(English, AnyCountry, "en_US") - TEST_NAME(English, UnitedKingdom, "en_GB") - TEST_NAME(Aymara, UnitedKingdom, "C") - -#undef TEST_NAME + QLocale locale(lang, land); + QCOMPARE(locale.name(), expect); } void tst_QLocale::stringToDouble_data() @@ -1282,7 +1318,8 @@ void tst_QLocale::formatDate_data() QTest::newRow("26") << QDate(1974, 12, 1) << "\"yy\"" << "\"74\""; QTest::newRow("27") << QDate(1974, 12, 1) << "'\"yy\"'" << "\"yy\""; QTest::newRow("28") << QDate() << "'\"yy\"'" << ""; - QTest::newRow("29") << QDate(1974, 12, 1) << "hh:mm:ss.zzz ap d'd'dd/M/yy" << "hh:mm:ss.zzz ap 1d01/12/74"; + QTest::newRow("29") + << QDate(1974, 12, 1) << "hh:mm:ss.zzz ap d'd'dd/M/yy" << "hh:mm:ss.zzz ap 1d01/12/74"; QTest::newRow("dd MMMM yyyy") << QDate(1, 1, 1) << "dd MMMM yyyy" << "01 January 0001"; } @@ -1298,7 +1335,6 @@ void tst_QLocale::formatDate() QCOMPARE(l.toString(date, QStringView(format)), result); } - void tst_QLocale::formatTime_data() { QTest::addColumn<QTime>("time"); @@ -1577,7 +1613,8 @@ void tst_QLocale::formatTimeZone() QDateTime::currentDateTime().timeZoneAbbreviation()); // Time on its own will always be current local time zone - QCOMPARE(enUS.toString(QTime(1, 2, 3), "t"), QDateTime::currentDateTime().timeZoneAbbreviation()); + QCOMPARE(enUS.toString(QTime(1, 2, 3), "t"), + QDateTime::currentDateTime().timeZoneAbbreviation()); } void tst_QLocale::toDateTime_data() @@ -1614,7 +1651,8 @@ void tst_QLocale::toDateTime_data() QTest::newRow("bad-hour-C") << "C" << QDateTime() << "d-MMM-yy hh:m" << "4-Jun-11 1:2"; QTest::newRow("bad-min-C") << "C" << QDateTime() << "d-MMM-yy h:mm" << "4-Jun-11 1:2"; QTest::newRow("bad-sec-C") << "C" << QDateTime() << "d-MMM-yy h:m:ss" << "4-Jun-11 1:2:3"; - QTest::newRow("bad-milli-C") << "C" << QDateTime() << "d-MMM-yy h:m:s.zzz" << "4-Jun-11 1:2:3.4"; + QTest::newRow("bad-milli-C") + << "C" << QDateTime() << "d-MMM-yy h:m:s.zzz" << "4-Jun-11 1:2:3.4"; QTest::newRow("ok-C") << "C" << QDateTime(QDate(1911, 6, 4), QTime(1, 2, 3, 400)) << "d-MMM-yy h:m:s.z" << "4-Jun-11 1:2:3.4"; @@ -1637,11 +1675,13 @@ void tst_QLocale::toDateTime_data() QTest::newRow("12no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 0, 0)) << "d'd'dd/M/yyh" << "1d01/12/7415"; - QTest::newRow("RFC-1123") << "C" << QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30)) - << "ddd, dd MMM yyyy hh:mm:ss 'GMT'" << "Thu, 01 Nov 2007 18:08:30 GMT"; + QTest::newRow("RFC-1123") + << "C" << QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30)) + << "ddd, dd MMM yyyy hh:mm:ss 'GMT'" << "Thu, 01 Nov 2007 18:08:30 GMT"; - QTest::newRow("longFormat") << "en_US" << QDateTime(QDate(2009, 1, 5), QTime(11, 48, 32)) - << "dddd, MMMM d, yyyy h:mm:ss AP " << "Monday, January 5, 2009 11:48:32 AM "; + QTest::newRow("longFormat") + << "en_US" << QDateTime(QDate(2009, 1, 5), QTime(11, 48, 32)) + << "dddd, MMMM d, yyyy h:mm:ss AP " << "Monday, January 5, 2009 11:48:32 AM "; } void tst_QLocale::toDateTime() @@ -1716,8 +1756,10 @@ void tst_QLocale::macDefaultLocale() // To run this test make sure "Curreny" is US Dollar in System Preferences->Language & Region->Advanced. if (locale.currencySymbol() == QString("$")) { - QCOMPARE(locale.toCurrencyString(qulonglong(1234)), systemLocaleFormatNumber(QString("$1,234.00"))); - QCOMPARE(locale.toCurrencyString(double(1234.56)), systemLocaleFormatNumber(QString("$1,234.56"))); + QCOMPARE(locale.toCurrencyString(qulonglong(1234)), + systemLocaleFormatNumber(QString("$1,234.00"))); + QCOMPARE(locale.toCurrencyString(double(1234.56)), + systemLocaleFormatNumber(QString("$1,234.56"))); } // Depending on the configured time zone, the time string might not @@ -1730,7 +1772,8 @@ void tst_QLocale::macDefaultLocale() expectedGMTSpecifierBase.append(QLatin1Char('-')); QString expectedGMTSpecifier = expectedGMTSpecifierBase + QString("%1").arg(qAbs(diff)); - QString expectedGMTSpecifierZeroExtended = expectedGMTSpecifierBase + QString("0%1").arg(qAbs(diff)); + QString expectedGMTSpecifierZeroExtended + = expectedGMTSpecifierBase + QString("0%1").arg(qAbs(diff)); QVERIFY2(timeString.contains(expectedGMTSpecifier) || timeString.contains(expectedGMTSpecifierZeroExtended), @@ -1744,8 +1787,10 @@ void tst_QLocale::macDefaultLocale() QCOMPARE(locale.dayName(7), QString("Sunday")); QCOMPARE(locale.monthName(1), QString("January")); QCOMPARE(locale.monthName(12), QString("December")); - QCOMPARE(locale.quoteString("string"), QString::fromUtf8("\xe2\x80\x9c" "string" "\xe2\x80\x9d")); - QCOMPARE(locale.quoteString("string", QLocale::AlternateQuotation), QString::fromUtf8("\xe2\x80\x98" "string" "\xe2\x80\x99")); + QCOMPARE(locale.quoteString("string"), + QString::fromUtf8("\xe2\x80\x9c" "string" "\xe2\x80\x9d")); + QCOMPARE(locale.quoteString("string", QLocale::AlternateQuotation), + QString::fromUtf8("\xe2\x80\x98" "string" "\xe2\x80\x99")); QList<Qt::DayOfWeek> days; days << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday; @@ -1787,12 +1832,6 @@ static void setWinLocaleInfo(LCTYPE type, const QString &value) # define LOCALE_SSHORTTIME 0x00000079 #endif -static inline LCTYPE shortTimeType() -{ - return (QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) && QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7 ? - LOCALE_SSHORTTIME : LOCALE_STIMEFORMAT; -} - class RestoreLocaleHelper { public: RestoreLocaleHelper() { @@ -1800,7 +1839,7 @@ public: m_thousand = getWinLocaleInfo(LOCALE_STHOUSAND); m_sdate = getWinLocaleInfo(LOCALE_SSHORTDATE); m_ldate = getWinLocaleInfo(LOCALE_SLONGDATE); - m_time = getWinLocaleInfo(shortTimeType()); + m_time = getWinLocaleInfo(LOCALE_SSHORTTIME); } ~RestoreLocaleHelper() { @@ -1809,7 +1848,7 @@ public: setWinLocaleInfo(LOCALE_STHOUSAND, m_thousand); setWinLocaleInfo(LOCALE_SSHORTDATE, m_sdate); setWinLocaleInfo(LOCALE_SLONGDATE, m_ldate); - setWinLocaleInfo(shortTimeType(), m_time); + setWinLocaleInfo(LOCALE_SSHORTTIME, m_time); // make sure QLocale::system() gets updated QLocalePrivate::updateSystemPrivate(); @@ -1819,14 +1858,9 @@ public: }; -#endif // Q_OS_WIN - -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) - void tst_QLocale::windowsDefaultLocale() { RestoreLocaleHelper systemLocale; - const bool win7OrLater = (QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) && QSysInfo::windowsVersion(); // set weird system defaults and make sure we're using them setWinLocaleInfo(LOCALE_SDECIMAL, QLatin1String("@")); setWinLocaleInfo(LOCALE_STHOUSAND, QLatin1String("?")); @@ -1835,7 +1869,7 @@ void tst_QLocale::windowsDefaultLocale() const QString longDateFormat = QStringLiteral("d@M@yyyy"); setWinLocaleInfo(LOCALE_SLONGDATE, longDateFormat); const QString shortTimeFormat = QStringLiteral("h^m^s"); - setWinLocaleInfo(shortTimeType(), shortTimeFormat); + setWinLocaleInfo(LOCALE_SSHORTTIME, shortTimeFormat); // make sure QLocale::system() gets updated QLocalePrivate::updateSystemPrivate(); @@ -1847,21 +1881,24 @@ void tst_QLocale::windowsDefaultLocale() QCOMPARE(locale.dateFormat(QLocale::ShortFormat), shortDateFormat); QCOMPARE(locale.dateFormat(QLocale::LongFormat), longDateFormat); QCOMPARE(locale.timeFormat(QLocale::ShortFormat), shortTimeFormat); - QCOMPARE(locale.dateTimeFormat(QLocale::ShortFormat), shortDateFormat + QLatin1Char(' ') + shortTimeFormat); - const QString expectedLongDateTimeFormat = longDateFormat + QLatin1Char(' ') - + (win7OrLater ? QStringLiteral("h:mm:ss AP") : shortTimeFormat); + QCOMPARE(locale.dateTimeFormat(QLocale::ShortFormat), + shortDateFormat + QLatin1Char(' ') + shortTimeFormat); + const QString expectedLongDateTimeFormat + = longDateFormat + QLatin1Char(' ') + QStringLiteral("h:mm:ss AP"); QCOMPARE(locale.dateTimeFormat(QLocale::LongFormat), expectedLongDateTimeFormat); // make sure we are using the system to parse them QCOMPARE(locale.toString(1234.56), QString("1?234@56")); QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat), QString("1*12*1974")); - QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::NarrowFormat), locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat)); + QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::NarrowFormat), + locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat)); QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::LongFormat), QString("1@12@1974")); const QString expectedFormattedShortTimeSeconds = QStringLiteral("1^2^3"); - const QString expectedFormattedShortTime = win7OrLater ? QStringLiteral("1^2") : expectedFormattedShortTimeSeconds; + const QString expectedFormattedShortTime = QStringLiteral("1^2"); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::ShortFormat), expectedFormattedShortTime); - QCOMPARE(locale.toString(QTime(1,2,3), QLocale::NarrowFormat), locale.toString(QTime(1,2,3), QLocale::ShortFormat)); - const QString expectedFormattedLongTime = win7OrLater ? QStringLiteral("1:02:03 AM") : expectedFormattedShortTimeSeconds; + QCOMPARE(locale.toString(QTime(1,2,3), QLocale::NarrowFormat), + locale.toString(QTime(1,2,3), QLocale::ShortFormat)); + const QString expectedFormattedLongTime = QStringLiteral("1:02:03 AM"); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::LongFormat), expectedFormattedLongTime); QCOMPARE(locale.toString(QDateTime(QDate(1974, 12, 1), QTime(1,2,3)), QLocale::ShortFormat), QStringLiteral("1*12*1974 ") + expectedFormattedShortTime); @@ -1871,7 +1908,7 @@ void tst_QLocale::windowsDefaultLocale() QStringLiteral("1@12@1974 ") + expectedFormattedLongTime); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::LongFormat), expectedFormattedLongTime); } -#endif // #ifdef Q_OS_WIN +#endif // Q_OS_WIN but !Q_OS_WINRT void tst_QLocale::numberOptions() { @@ -2056,17 +2093,23 @@ void tst_QLocale::dayName_data() QTest::addColumn<int>("day"); QTest::addColumn<QLocale::FormatType>("format"); - QTest::newRow("no_NO") << QString("no_NO") << QString("tirsdag") << 2 << QLocale::LongFormat; - QTest::newRow("nb_NO") << QString("nb_NO") << QString("tirsdag") << 2 << QLocale::LongFormat; - QTest::newRow("nn_NO") << QString("nn_NO") << QString("tysdag") << 2 << QLocale::LongFormat; + QTest::newRow("no_NO") << QString("no_NO") << QString("tirsdag") << 2 << QLocale::LongFormat; + QTest::newRow("nb_NO") << QString("nb_NO") << QString("tirsdag") << 2 << QLocale::LongFormat; + QTest::newRow("nn_NO") << QString("nn_NO") << QString("tysdag") << 2 << QLocale::LongFormat; - QTest::newRow("C long") << QString("C") << QString("Sunday") << 7 << QLocale::LongFormat; - QTest::newRow("C short") << QString("C") << QString("Sun") << 7 << QLocale::ShortFormat; - QTest::newRow("C narrow") << QString("C") << QString("7") << 7 << QLocale::NarrowFormat; + QTest::newRow("C long") << QString("C") << QString("Sunday") << 7 << QLocale::LongFormat; + QTest::newRow("C short") << QString("C") << QString("Sun") << 7 << QLocale::ShortFormat; + QTest::newRow("C narrow") << QString("C") << QString("7") << 7 << QLocale::NarrowFormat; - QTest::newRow("ru_RU long") << QString("ru_RU") << QString::fromUtf8("\320\262\320\276\321\201\320\272\321\200\320\265\321\201\320\265\320\275\321\214\320\265") << 7 << QLocale::LongFormat; - QTest::newRow("ru_RU short") << QString("ru_RU") << QString::fromUtf8("\320\262\321\201") << 7 << QLocale::ShortFormat; - QTest::newRow("ru_RU narrow") << QString("ru_RU") << QString::fromUtf8("\320\262\321\201") << 7 << QLocale::NarrowFormat; + QTest::newRow("ru_RU long") + << QString("ru_RU") + << QString::fromUtf8("\320\262\320\276\321\201\320\272\321\200\320" + "\265\321\201\320\265\320\275\321\214\320\265") + << 7 << QLocale::LongFormat; + QTest::newRow("ru_RU short") + << QString("ru_RU") << QString::fromUtf8("\320\262\321\201") << 7 << QLocale::ShortFormat; + QTest::newRow("ru_RU narrow") + << QString("ru_RU") << QString::fromUtf8("\320\262\321\201") << 7 << QLocale::NarrowFormat; } void tst_QLocale::dayName() @@ -2096,24 +2139,30 @@ void tst_QLocale::standaloneDayName_data() QTest::addColumn<int>("day"); QTest::addColumn<QLocale::FormatType>("format"); - QTest::newRow("no_NO") << QString("no_NO") << QString("tirsdag") << 2 << QLocale::LongFormat; - QTest::newRow("nb_NO") << QString("nb_NO") << QString("tirsdag") << 2 << QLocale::LongFormat; - QTest::newRow("nn_NO") << QString("nn_NO") << QString("tysdag") << 2 << QLocale::LongFormat; + QTest::newRow("no_NO") << QString("no_NO") << QString("tirsdag") << 2 << QLocale::LongFormat; + QTest::newRow("nb_NO") << QString("nb_NO") << QString("tirsdag") << 2 << QLocale::LongFormat; + QTest::newRow("nn_NO") << QString("nn_NO") << QString("tysdag") << 2 << QLocale::LongFormat; - QTest::newRow("C invalid: 0 long") << QString("C") << QString() << 0 << QLocale::LongFormat; - QTest::newRow("C invalid: 0 short") << QString("C") << QString() << 0 << QLocale::ShortFormat; - QTest::newRow("C invalid: 0 narrow") << QString("C") << QString() << 0 << QLocale::NarrowFormat; - QTest::newRow("C invalid: 8 long") << QString("C") << QString() << 8 << QLocale::LongFormat; - QTest::newRow("C invalid: 8 short") << QString("C") << QString() << 8 << QLocale::ShortFormat; - QTest::newRow("C invalid: 8 narrow") << QString("C") << QString() << 8 << QLocale::NarrowFormat; + QTest::newRow("C invalid: 0 long") << QString("C") << QString() << 0 << QLocale::LongFormat; + QTest::newRow("C invalid: 0 short") << QString("C") << QString() << 0 << QLocale::ShortFormat; + QTest::newRow("C invalid: 0 narrow") << QString("C") << QString() << 0 << QLocale::NarrowFormat; + QTest::newRow("C invalid: 8 long") << QString("C") << QString() << 8 << QLocale::LongFormat; + QTest::newRow("C invalid: 8 short") << QString("C") << QString() << 8 << QLocale::ShortFormat; + QTest::newRow("C invalid: 8 narrow") << QString("C") << QString() << 8 << QLocale::NarrowFormat; - QTest::newRow("C long") << QString("C") << QString("Sunday") << 7 << QLocale::LongFormat; - QTest::newRow("C short") << QString("C") << QString("Sun") << 7 << QLocale::ShortFormat; - QTest::newRow("C narrow") << QString("C") << QString("S") << 7 << QLocale::NarrowFormat; + QTest::newRow("C long") << QString("C") << QString("Sunday") << 7 << QLocale::LongFormat; + QTest::newRow("C short") << QString("C") << QString("Sun") << 7 << QLocale::ShortFormat; + QTest::newRow("C narrow") << QString("C") << QString("S") << 7 << QLocale::NarrowFormat; - QTest::newRow("ru_RU long") << QString("ru_RU") << QString::fromUtf8("\320\262\320\276\321\201\320\272\321\200\320\265\321\201\320\265\320\275\321\214\320\265") << 7 << QLocale::LongFormat; - QTest::newRow("ru_RU short") << QString("ru_RU") << QString::fromUtf8("\320\262\321\201") << 7 << QLocale::ShortFormat; - QTest::newRow("ru_RU narrow") << QString("ru_RU") << QString::fromUtf8("\320\222") << 7 << QLocale::NarrowFormat; + QTest::newRow("ru_RU long") + << QString("ru_RU") + << QString::fromUtf8("\320\262\320\276\321\201\320\272\321\200\320" + "\265\321\201\320\265\320\275\321\214\320\265") + << 7 << QLocale::LongFormat; + QTest::newRow("ru_RU short") + << QString("ru_RU") << QString::fromUtf8("\320\262\321\201") << 7 << QLocale::ShortFormat; + QTest::newRow("ru_RU narrow") + << QString("ru_RU") << QString::fromUtf8("\320\222") << 7 << QLocale::NarrowFormat; } void tst_QLocale::standaloneDayName() @@ -2129,9 +2178,7 @@ void tst_QLocale::standaloneDayName() void tst_QLocale::underflowOverflow() { - QString -a(QLatin1String("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e10")); - + QString a(QLatin1String("0.") + QString(546, QLatin1Char('0')) + QLatin1String("1e10")); bool ok = false; double d = a.toDouble(&ok); QVERIFY(!ok); @@ -2160,75 +2207,56 @@ a(QLatin1String("0.0000000000000000000000000000000000000000000000000000000000000 QVERIFY(!ok); } -void tst_QLocale::defaultNumeringSystem() +void tst_QLocale::defaultNumberingSystem_data() { - QLocale sk("sk_SK"); - QCOMPARE(sk.toString(123), QLatin1String("123")); - - QLocale ta("ta_IN"); - QCOMPARE(ta.toString(123), QLatin1String("123")); - - QLocale te("te_IN"); - QCOMPARE(te.toString(123), QLatin1String("123")); - - QLocale hi("hi_IN"); - QCOMPARE(hi.toString(123), QLatin1String("123")); - - QLocale gu("gu_IN"); - QCOMPARE(gu.toString(123), QLatin1String("123")); - - QLocale kn("kn_IN"); - QCOMPARE(kn.toString(123), QLatin1String("123")); + QTest::addColumn<QString>("expect"); - QLocale pa("pa_IN"); - QCOMPARE(pa.toString(123), QLatin1String("123")); - - QLocale ne("ne_IN"); - QCOMPARE(ne.toString(123), QString::fromUtf8("१२३")); + QTest::newRow("sk_SK") << QStringLiteral("123"); + QTest::newRow("ta_IN") << QStringLiteral("123"); + QTest::newRow("te_IN") << QStringLiteral("123"); + QTest::newRow("hi_IN") << QStringLiteral("123"); + QTest::newRow("gu_IN") << QStringLiteral("123"); + QTest::newRow("kn_IN") << QStringLiteral("123"); + QTest::newRow("pa_IN") << QStringLiteral("123"); + QTest::newRow("ne_IN") << QString::fromUtf8("१२३"); + QTest::newRow("mr_IN") << QString::fromUtf8("१२३"); + QTest::newRow("ml_IN") << QStringLiteral("123"); + QTest::newRow("kok_IN") << QStringLiteral("123"); +} - QLocale mr("mr_IN"); - QCOMPARE(mr.toString(123), QString::fromUtf8("१२३")); +void tst_QLocale::defaultNumberingSystem() +{ + QFETCH(QString, expect); + QLatin1String name(QTest::currentDataTag()); + QLocale locale(name); + QCOMPARE(locale.toString(123), expect); +} - QLocale ml("ml_IN"); - QCOMPARE(ml.toString(123), QLatin1String("123")); +void tst_QLocale::ampm_data() +{ + QTest::addColumn<QString>("morn"); + QTest::addColumn<QString>("even"); - QLocale kok("kok_IN"); - QCOMPARE(kok.toString(123), QLatin1String("123")); + QTest::newRow("C") << QStringLiteral("AM") << QStringLiteral("PM"); + QTest::newRow("de_DE") << QStringLiteral("AM") << QStringLiteral("PM"); + QTest::newRow("sv_SE") << QStringLiteral("fm") << QStringLiteral("em"); + QTest::newRow("nl_NL") << QStringLiteral("a.m.") << QStringLiteral("p.m."); + QTest::newRow("uk_UA") << QString::fromUtf8("\320\264\320\277") + << QString::fromUtf8("\320\277\320\277"); + QTest::newRow("tr_TR") << QString::fromUtf8("\303\226\303\226") + << QString::fromUtf8("\303\226\123"); + QTest::newRow("id_ID") << QStringLiteral("AM") << QStringLiteral("PM"); + QTest::newRow("ta_LK") << QString::fromUtf8("முற்பகல்") << QString::fromUtf8("பிற்பகல்"); } void tst_QLocale::ampm() { - QLocale c(QLocale::C); - QCOMPARE(c.amText(), QLatin1String("AM")); - QCOMPARE(c.pmText(), QLatin1String("PM")); - - QLocale de("de_DE"); - QCOMPARE(de.amText(), QLatin1String("vorm.")); - QCOMPARE(de.pmText(), QLatin1String("nachm.")); - - QLocale sv("sv_SE"); - QCOMPARE(sv.amText(), QLatin1String("fm")); - QCOMPARE(sv.pmText(), QLatin1String("em")); - - QLocale nn("nl_NL"); - QCOMPARE(nn.amText(), QLatin1String("a.m.")); - QCOMPARE(nn.pmText(), QLatin1String("p.m.")); - - QLocale ua("uk_UA"); - QCOMPARE(ua.amText(), QString::fromUtf8("\320\264\320\277")); - QCOMPARE(ua.pmText(), QString::fromUtf8("\320\277\320\277")); - - QLocale tr("tr_TR"); - QCOMPARE(tr.amText(), QString::fromUtf8("\303\226\303\226")); - QCOMPARE(tr.pmText(), QString::fromUtf8("\303\226\123")); - - QLocale id("id_ID"); - QCOMPARE(id.amText(), QLatin1String("AM")); - QCOMPARE(id.pmText(), QLatin1String("PM")); - - QLocale ta("ta_LK"); - QCOMPARE(ta.amText(), QString::fromUtf8("முற்பகல்")); - QCOMPARE(ta.pmText(), QString::fromUtf8("பிற்பகல்")); + QFETCH(QString, morn); + QFETCH(QString, even); + QLatin1String name(QTest::currentDataTag()); + QLocale locale(name == QLatin1String("C") ? QLocale(QLocale::C) : QLocale(name)); + QCOMPARE(locale.amText(), morn); + QCOMPARE(locale.pmText(), even); } void tst_QLocale::dateFormat() @@ -2310,8 +2338,10 @@ void tst_QLocale::monthName() QCOMPARE(de.monthName(12, QLocale::NarrowFormat), QLatin1String("D")); QLocale ru("ru_RU"); - QCOMPARE(ru.monthName(1, QLocale::LongFormat), QString::fromUtf8("\321\217\320\275\320\262\320\260\321\200\321\217")); - QCOMPARE(ru.monthName(1, QLocale::ShortFormat), QString::fromUtf8("\321\217\320\275\320\262\56")); + QCOMPARE(ru.monthName(1, QLocale::LongFormat), + QString::fromUtf8("\321\217\320\275\320\262\320\260\321\200\321\217")); + QCOMPARE(ru.monthName(1, QLocale::ShortFormat), + QString::fromUtf8("\321\217\320\275\320\262\56")); QCOMPARE(ru.monthName(1, QLocale::NarrowFormat), QString::fromUtf8("\320\257")); QLocale ir("ga_IE"); @@ -2340,13 +2370,16 @@ void tst_QLocale::standaloneMonthName() // For de_DE locale Unicode CLDR database doesn't contain standalone long months // so just checking if the return value is the same as in monthName(). QCOMPARE(de.standaloneMonthName(12, QLocale::LongFormat), QLatin1String("Dezember")); - QCOMPARE(de.standaloneMonthName(12, QLocale::LongFormat), de.monthName(12, QLocale::LongFormat)); + QCOMPARE(de.standaloneMonthName(12, QLocale::LongFormat), + de.monthName(12, QLocale::LongFormat)); QCOMPARE(de.standaloneMonthName(12, QLocale::ShortFormat), QLatin1String("Dez")); QCOMPARE(de.standaloneMonthName(12, QLocale::NarrowFormat), QLatin1String("D")); QLocale ru("ru_RU"); - QCOMPARE(ru.standaloneMonthName(1, QLocale::LongFormat), QString::fromUtf8("\xd1\x8f\xd0\xbd\xd0\xb2\xd0\xb0\xd1\x80\xd1\x8c")); - QCOMPARE(ru.standaloneMonthName(1, QLocale::ShortFormat), QString::fromUtf8("\xd1\x8f\xd0\xbd\xd0\xb2.")); + QCOMPARE(ru.standaloneMonthName(1, QLocale::LongFormat), + QString::fromUtf8("\xd1\x8f\xd0\xbd\xd0\xb2\xd0\xb0\xd1\x80\xd1\x8c")); + QCOMPARE(ru.standaloneMonthName(1, QLocale::ShortFormat), + QString::fromUtf8("\xd1\x8f\xd0\xbd\xd0\xb2.")); QCOMPARE(ru.standaloneMonthName(1, QLocale::NarrowFormat), QString::fromUtf8("\xd0\xaf")); } @@ -2371,19 +2404,30 @@ void tst_QLocale::currency() QCOMPARE(en_US.toCurrencyString(double(-1234.56), NULL, 4), QString("$-1,234.5600")); const QLocale ru_RU("ru_RU"); - QCOMPARE(ru_RU.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1" "\xc2\xa0" "234\xc2\xa0\xe2\x82\xbd")); - QCOMPARE(ru_RU.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1" "\xc2\xa0" "234\xc2\xa0\xe2\x82\xbd")); - QCOMPARE(ru_RU.toCurrencyString(double(1234.56)), QString::fromUtf8("1" "\xc2\xa0" "234,56\xc2\xa0\xe2\x82\xbd")); - QCOMPARE(ru_RU.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1" "\xc2\xa0" "234,56\xc2\xa0\xe2\x82\xbd")); + QCOMPARE(ru_RU.toCurrencyString(qulonglong(1234)), + QString::fromUtf8("1" "\xc2\xa0" "234\xc2\xa0\xe2\x82\xbd")); + QCOMPARE(ru_RU.toCurrencyString(qlonglong(-1234)), + QString::fromUtf8("-1" "\xc2\xa0" "234\xc2\xa0\xe2\x82\xbd")); + QCOMPARE(ru_RU.toCurrencyString(double(1234.56)), + QString::fromUtf8("1" "\xc2\xa0" "234,56\xc2\xa0\xe2\x82\xbd")); + QCOMPARE(ru_RU.toCurrencyString(double(-1234.56)), + QString::fromUtf8("-1" "\xc2\xa0" "234,56\xc2\xa0\xe2\x82\xbd")); const QLocale de_DE("de_DE"); - QCOMPARE(de_DE.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1.234\xc2\xa0\xe2\x82\xac")); - QCOMPARE(de_DE.toCurrencyString(qulonglong(1234), QLatin1String("BAZ")), QString::fromUtf8("1.234\xc2\xa0" "BAZ")); - QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1.234\xc2\xa0\xe2\x82\xac")); - QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234), QLatin1String("BAZ")), QString::fromUtf8("-1.234\xc2\xa0" "BAZ")); - QCOMPARE(de_DE.toCurrencyString(double(1234.56)), QString::fromUtf8("1.234,56\xc2\xa0\xe2\x82\xac")); - QCOMPARE(de_DE.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1.234,56\xc2\xa0\xe2\x82\xac")); - QCOMPARE(de_DE.toCurrencyString(double(-1234.56), QLatin1String("BAZ")), QString::fromUtf8("-1.234,56\xc2\xa0" "BAZ")); + QCOMPARE(de_DE.toCurrencyString(qulonglong(1234)), + QString::fromUtf8("1.234\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(qulonglong(1234), QLatin1String("BAZ")), + QString::fromUtf8("1.234\xc2\xa0" "BAZ")); + QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234)), + QString::fromUtf8("-1.234\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234), QLatin1String("BAZ")), + QString::fromUtf8("-1.234\xc2\xa0" "BAZ")); + QCOMPARE(de_DE.toCurrencyString(double(1234.56)), + QString::fromUtf8("1.234,56\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(double(-1234.56)), + QString::fromUtf8("-1.234,56\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(double(-1234.56), QLatin1String("BAZ")), + QString::fromUtf8("-1.234,56\xc2\xa0" "BAZ")); const QLocale system = QLocale::system(); QVERIFY(system.toCurrencyString(1, QLatin1String("FOO")).contains(QLatin1String("FOO"))); @@ -2394,11 +2438,13 @@ void tst_QLocale::quoteString() const QString someText("text"); const QLocale c(QLocale::C); QCOMPARE(c.quoteString(someText), QString::fromUtf8("\x22" "text" "\x22")); - QCOMPARE(c.quoteString(someText, QLocale::AlternateQuotation), QString::fromUtf8("\x27" "text" "\x27")); + QCOMPARE(c.quoteString(someText, QLocale::AlternateQuotation), + QString::fromUtf8("\x27" "text" "\x27")); const QLocale de_CH("de_CH"); QCOMPARE(de_CH.quoteString(someText), QString::fromUtf8("\xe2\x80\x9e" "text" "\xe2\x80\x9c")); - QCOMPARE(de_CH.quoteString(someText, QLocale::AlternateQuotation), QString::fromUtf8("\xe2\x80\x9a" "text" "\xe2\x80\x98")); + QCOMPARE(de_CH.quoteString(someText, QLocale::AlternateQuotation), + QString::fromUtf8("\xe2\x80\x9a" "text" "\xe2\x80\x98")); } @@ -2480,23 +2526,28 @@ void tst_QLocale::listPatterns() QCOMPARE(zh_CN.createSeparatedList(sl1), QString("")); QCOMPARE(zh_CN.createSeparatedList(sl2), QString("aaa")); QCOMPARE(zh_CN.createSeparatedList(sl3), QString::fromUtf8("aaa" "\xe5\x92\x8c" "bbb")); - QCOMPARE(zh_CN.createSeparatedList(sl4), QString::fromUtf8("aaa" "\xe3\x80\x81" "bbb" "\xe5\x92\x8c" "ccc")); - QCOMPARE(zh_CN.createSeparatedList(sl5), QString::fromUtf8("aaa" "\xe3\x80\x81" "bbb" "\xe3\x80\x81" "ccc" "\xe5\x92\x8c" "ddd")); + QCOMPARE(zh_CN.createSeparatedList(sl4), + QString::fromUtf8("aaa" "\xe3\x80\x81" "bbb" "\xe5\x92\x8c" "ccc")); + QCOMPARE(zh_CN.createSeparatedList(sl5), + QString::fromUtf8("aaa" "\xe3\x80\x81" "bbb" "\xe3\x80\x81" + "ccc" "\xe5\x92\x8c" "ddd")); } -void tst_QLocale::measurementSystems() +void tst_QLocale::measurementSystems_data() { - QLocale locale(QLocale::English, QLocale::UnitedStates); - QCOMPARE(locale.measurementSystem(), QLocale::ImperialUSSystem); - - locale = QLocale(QLocale::English, QLocale::UnitedKingdom); - QCOMPARE(locale.measurementSystem(), QLocale::ImperialUKSystem); - - locale = QLocale(QLocale::English, QLocale::Australia); - QCOMPARE(locale.measurementSystem(), QLocale::MetricSystem); + QTest::addColumn<QLocale>("locale"); + QTest::addColumn<QLocale::MeasurementSystem>("system"); + QTest::newRow("en_US") << QLocale(QLocale::English, QLocale::UnitedStates) << QLocale::ImperialUSSystem; + QTest::newRow("en_GB") << QLocale(QLocale::English, QLocale::UnitedKingdom) << QLocale::ImperialUKSystem; + QTest::newRow("en_AU") << QLocale(QLocale::English, QLocale::Australia) << QLocale::MetricSystem; + QTest::newRow("de") << QLocale(QLocale::German) << QLocale::MetricSystem; +} - locale = QLocale(QLocale::German); - QCOMPARE(locale.measurementSystem(), QLocale::MetricSystem); +void tst_QLocale::measurementSystems() +{ + QFETCH(QLocale, locale); + QFETCH(QLocale::MeasurementSystem, system); + QCOMPARE(locale.measurementSystem(), system); } void tst_QLocale::QTBUG_26035_positivesign() @@ -2562,7 +2613,9 @@ void tst_QLocale::textDirection_data() case QLocale::Uighur: case QLocale::Urdu: case QLocale::Yiddish: - rightToLeft = QLocale(QLocale::Language(language)).language() == QLocale::Language(language); // false if there is no locale data for language + // false if there is no locale data for language: + rightToLeft = (QLocale(QLocale::Language(language)).language() + == QLocale::Language(language)); break; default: break; @@ -2659,25 +2712,33 @@ void tst_QLocale::formattedDataSize() QCOMPARE(QLocale(language).formattedDataSize(bytes, decimalPlaces, units), output); } -void tst_QLocale::bcp47Name() +void tst_QLocale::bcp47Name_data() { - QCOMPARE(QLocale("C").bcp47Name(), QStringLiteral("en")); - QCOMPARE(QLocale("en").bcp47Name(), QStringLiteral("en")); - QCOMPARE(QLocale("en_US").bcp47Name(), QStringLiteral("en")); - QCOMPARE(QLocale("en_GB").bcp47Name(), QStringLiteral("en-GB")); - QCOMPARE(QLocale("en_DE").bcp47Name(), QStringLiteral("en-DE")); - QCOMPARE(QLocale("de_DE").bcp47Name(), QStringLiteral("de")); - QCOMPARE(QLocale("sr_RS").bcp47Name(), QStringLiteral("sr")); - QCOMPARE(QLocale("sr_Cyrl_RS").bcp47Name(), QStringLiteral("sr")); - QCOMPARE(QLocale("sr_Latn_RS").bcp47Name(), QStringLiteral("sr-Latn")); - QCOMPARE(QLocale("sr_ME").bcp47Name(), QStringLiteral("sr-ME")); - QCOMPARE(QLocale("sr_Cyrl_ME").bcp47Name(), QStringLiteral("sr-Cyrl-ME")); - QCOMPARE(QLocale("sr_Latn_ME").bcp47Name(), QStringLiteral("sr-ME")); + QTest::addColumn<QString>("expect"); + + QTest::newRow("C") << QStringLiteral("en"); + QTest::newRow("en") << QStringLiteral("en"); + QTest::newRow("en_US") << QStringLiteral("en"); + QTest::newRow("en_GB") << QStringLiteral("en-GB"); + QTest::newRow("en_DE") << QStringLiteral("en-DE"); + QTest::newRow("de_DE") << QStringLiteral("de"); + QTest::newRow("sr_RS") << QStringLiteral("sr"); + QTest::newRow("sr_Cyrl_RS") << QStringLiteral("sr"); + QTest::newRow("sr_Latn_RS") << QStringLiteral("sr-Latn"); + QTest::newRow("sr_ME") << QStringLiteral("sr-ME"); + QTest::newRow("sr_Cyrl_ME") << QStringLiteral("sr-Cyrl-ME"); + QTest::newRow("sr_Latn_ME") << QStringLiteral("sr-ME"); // Fall back to defaults when country isn't in CLDR for this language: - QCOMPARE(QLocale("sr_HR").bcp47Name(), QStringLiteral("sr")); - QCOMPARE(QLocale("sr_Cyrl_HR").bcp47Name(), QStringLiteral("sr")); - QCOMPARE(QLocale("sr_Latn_HR").bcp47Name(), QStringLiteral("sr-Latn")); + QTest::newRow("sr_HR") << QStringLiteral("sr"); + QTest::newRow("sr_Cyrl_HR") << QStringLiteral("sr"); + QTest::newRow("sr_Latn_HR") << QStringLiteral("sr-Latn"); +} + +void tst_QLocale::bcp47Name() +{ + QFETCH(QString, expect); + QCOMPARE(QLocale(QLatin1String(QTest::currentDataTag())).bcp47Name(), expect); } class MySystemLocale : public QSystemLocale diff --git a/tests/auto/corelib/tools/qmakearray/qmakearray.pro b/tests/auto/corelib/tools/qmakearray/qmakearray.pro new file mode 100644 index 0000000000..abb3d9fdbc --- /dev/null +++ b/tests/auto/corelib/tools/qmakearray/qmakearray.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qmakearray +QT = core testlib core-private +SOURCES = $$PWD/tst_qmakearray.cpp diff --git a/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp b/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp new file mode 100644 index 0000000000..e0d3f52719 --- /dev/null +++ b/tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <private/qmakearray_p.h> + + +class tst_QMakeArray : public QObject +{ + Q_OBJECT + +private slots: + void quicksort(); +}; + +struct Pair { + unsigned int key; + unsigned int val; + + constexpr bool operator <=(const Pair &that) const noexcept + { + return key <= that.key; + } + + constexpr bool operator<(const Pair &that) const noexcept + { + return key < that.key; + } + + constexpr bool operator==(const Pair &that) const noexcept + { + return key == that.key; + } +}; + +template<std::size_t Key, std::size_t Val> +struct PairQuickSortElem +{ + using Type = Pair; + static constexpr Type data() noexcept { return Type{Key, Val}; } +}; + +void tst_QMakeArray::quicksort() +{ + constexpr const auto sorted_array = qMakeArray( + QSortedData< + PairQuickSortElem<10, 0>, + PairQuickSortElem<5, 0>, + PairQuickSortElem<7, 0>, + PairQuickSortElem<1, 0>, + PairQuickSortElem<8, 0>, + PairQuickSortElem<6, 0>, + PairQuickSortElem<4, 0>, + PairQuickSortElem<3, 0>, + PairQuickSortElem<1, 0>, + PairQuickSortElem<2, 0>, + PairQuickSortElem<10, 0>, + PairQuickSortElem<5, 0> + >::Data{}); + static_assert(sorted_array.size() == 12, "sorted_array.size() != 12"); + QCOMPARE(sorted_array[0].key, 1u); + QCOMPARE(sorted_array[1].key, 1u); + QCOMPARE(sorted_array[2].key, 2u); + QCOMPARE(sorted_array[3].key, 3u); + QCOMPARE(sorted_array[4].key, 4u); + QCOMPARE(sorted_array[5].key, 5u); + QCOMPARE(sorted_array[6].key, 5u); + QCOMPARE(sorted_array[7].key, 6u); + QCOMPARE(sorted_array[8].key, 7u); + QCOMPARE(sorted_array[9].key, 8u); + QCOMPARE(sorted_array[10].key, 10u); + QCOMPARE(sorted_array[11].key, 10u); +} + + +QTEST_APPLESS_MAIN(tst_QMakeArray) +#include "tst_qmakearray.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro b/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro deleted file mode 100644 index a27286ff20..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/alwaysoptimize.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -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/defaultoptimize/defaultoptimize.pro b/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro deleted file mode 100644 index 0b36c79c1b..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/defaultoptimize/defaultoptimize.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -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 deleted file mode 100644 index a815c6cab9..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/defaultoptimize/tst_qregularexpression_defaultoptimize.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $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/forceoptimize/forceoptimize.pro b/tests/auto/corelib/tools/qregularexpression/forceoptimize/forceoptimize.pro deleted file mode 100644 index 1db77781dd..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/forceoptimize/forceoptimize.pro +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG += testcase -TARGET = tst_qregularexpression_forceoptimize -QT = core testlib -HEADERS = ../tst_qregularexpression.h -SOURCES = \ - tst_qregularexpression_forceoptimize.cpp \ - ../tst_qregularexpression.cpp -DEFINES += forceOptimize=true diff --git a/tests/auto/corelib/tools/qregularexpression/forceoptimize/tst_qregularexpression_forceoptimize.cpp b/tests/auto/corelib/tools/qregularexpression/forceoptimize/tst_qregularexpression_forceoptimize.cpp deleted file mode 100644 index 38a3a64fa3..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/forceoptimize/tst_qregularexpression_forceoptimize.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "../tst_qregularexpression.h" - -class tst_QRegularExpression_ForceOptimize : public tst_QRegularExpression -{ - Q_OBJECT -}; - -QTEST_APPLESS_MAIN(tst_QRegularExpression_ForceOptimize) - -#include "tst_qregularexpression_forceoptimize.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro index e1840808ff..ec8189717e 100644 --- a/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro +++ b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro @@ -1,3 +1,4 @@ -TEMPLATE = subdirs -SUBDIRS = defaultoptimize forceoptimize -qtConfig(private_tests): SUBDIRS += alwaysoptimize +CONFIG += testcase +TARGET = tst_qregularexpression +QT = core testlib +SOURCES = tst_qregularexpression.cpp diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index c828551e44..5130b7cfcd 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -33,11 +33,60 @@ #include <qstringlist.h> #include <qhash.h> -#include "tst_qregularexpression.h" +#include <qobject.h> +#include <qregularexpression.h> +#include <qthread.h> -#ifndef forceOptimize -#define forceOptimize false -#endif +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 defaultConstructors(); + 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(); + void captureNames_data(); + void captureNames(); + void pcreJitStackUsage_data(); + void pcreJitStackUsage(); + void regularExpressionMatch_data(); + void regularExpressionMatch(); + void JOptionUsage_data(); + void JOptionUsage(); + void QStringAndQStringRefEquivalence(); + void threadSafety_data(); + void threadSafety(); + + void wildcard_data(); + void wildcard(); + void testInvalidWildcard_data(); + void testInvalidWildcard(); + +private: + void provideRegularExpressions(); +}; struct Match { @@ -292,9 +341,6 @@ static void testMatch(const QRegularExpression ®exp, QRegularExpression::MatchOptions matchOptions, const Result &result) { - if (forceOptimize) - regexp.optimize(); - // test with QString as subject type testMatchImpl<QREMatch>(regexp, matchingMethodForString, subject, offset, matchType, matchOptions, result); @@ -401,30 +447,22 @@ void tst_QRegularExpression::gettersSetters() { QRegularExpression re; re.setPattern(pattern); - if (forceOptimize) - re.optimize(); QCOMPARE(re.pattern(), pattern); QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); } { QRegularExpression re; re.setPatternOptions(patternOptions); - if (forceOptimize) - re.optimize(); QCOMPARE(re.pattern(), QString()); QCOMPARE(re.patternOptions(), patternOptions); } { QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); QCOMPARE(re.pattern(), pattern); QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); } { QRegularExpression re(pattern, patternOptions); - if (forceOptimize) - re.optimize(); QCOMPARE(re.pattern(), pattern); QCOMPARE(re.patternOptions(), patternOptions); } @@ -465,8 +503,6 @@ void tst_QRegularExpression::escape() QFETCH(QString, escaped); QCOMPARE(QRegularExpression::escape(string), escaped); QRegularExpression re(escaped); - if (forceOptimize) - re.optimize(); QCOMPARE(re.isValid(), true); } @@ -497,8 +533,6 @@ void tst_QRegularExpression::validity() QFETCH(QString, pattern); QFETCH(bool, validity); QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); QCOMPARE(re.isValid(), validity); if (!validity) QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object"); @@ -585,9 +619,6 @@ void tst_QRegularExpression::patternOptions() QFETCH(QString, subject); QFETCH(Match, match); - if (forceOptimize) - regexp.optimize(); - QRegularExpressionMatch m = regexp.match(subject); consistencyCheck(m); QVERIFY(m == match); @@ -1403,9 +1434,6 @@ void tst_QRegularExpression::serialize() QFETCH(QRegularExpression::PatternOptions, patternOptions); QRegularExpression outRe(pattern, patternOptions); - if (forceOptimize) - outRe.optimize(); - QByteArray buffer; { QDataStream out(&buffer, QIODevice::WriteOnly); @@ -1468,33 +1496,18 @@ void tst_QRegularExpression::operatoreq() QRegularExpression re1(pattern); QRegularExpression re2(pattern); - if (forceOptimize) - re1.optimize(); - if (forceOptimize) - re2.optimize(); - verifyEquality(re1, re2); } { QRegularExpression re1(QString(), patternOptions); QRegularExpression re2(QString(), patternOptions); - if (forceOptimize) - re1.optimize(); - if (forceOptimize) - re2.optimize(); - verifyEquality(re1, re2); } { QRegularExpression re1(pattern, patternOptions); QRegularExpression re2(pattern, patternOptions); - if (forceOptimize) - re1.optimize(); - if (forceOptimize) - re2.optimize(); - verifyEquality(re1, re2); } } @@ -1524,9 +1537,6 @@ void tst_QRegularExpression::captureCount() QFETCH(QString, pattern); QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); - QTEST(re.captureCount(), "captureCount"); if (!re.isValid()) QCOMPARE(re.captureCount(), -1); @@ -1595,9 +1605,6 @@ void tst_QRegularExpression::captureNames() QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); - QStringList namedCaptureGroups = re.namedCaptureGroups(); int namedCaptureGroupsCount = namedCaptureGroups.size(); @@ -1633,9 +1640,6 @@ void tst_QRegularExpression::pcreJitStackUsage() QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); - QVERIFY(re.isValid()); QRegularExpressionMatch match = re.match(subject); consistencyCheck(match); @@ -1663,9 +1667,6 @@ void tst_QRegularExpression::regularExpressionMatch() QRegularExpression re(pattern); - if (forceOptimize) - re.optimize(); - QVERIFY(re.isValid()); QRegularExpressionMatch match = re.match(subject); consistencyCheck(match); @@ -1705,8 +1706,6 @@ void tst_QRegularExpression::JOptionUsage() QRegularExpression re(pattern); if (isValid && JOptionUsed) QTest::ignoreMessage(QtWarningMsg, qPrintable(warningMessage.arg(pattern))); - if (forceOptimize) - re.optimize(); QCOMPARE(re.isValid(), isValid); } @@ -2066,3 +2065,166 @@ void tst_QRegularExpression::QStringAndQStringRefEquivalence() } } } + +class MatcherThread : public QThread +{ +public: + explicit MatcherThread(const QRegularExpression &re, const QString &subject, QObject *parent = nullptr) + : QThread(parent), + m_re(re), + m_subject(subject) + { + } + +private: + static const int MATCH_ITERATIONS = 50; + + void run() override + { + yieldCurrentThread(); + for (int i = 0; i < MATCH_ITERATIONS; ++i) + m_re.match(m_subject); + } + + const QRegularExpression &m_re; + const QString &m_subject; +}; + +void tst_QRegularExpression::threadSafety_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QString>("subject"); + + int i = 0; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abcd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abbbbcccd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abababcd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abcabcd"; + QTest::addRow("pattern%d", ++i) << "ab.*cd" << "abccccccababd"; + + { + QString subject(512*1024, QLatin1Char('x')); + QTest::addRow("pattern%d", ++i) << "ab.*cd" << subject; + } + + { + QString subject = "ab"; + subject.append(QString(512*1024, QLatin1Char('x'))); + subject.append("c"); + QTest::addRow("pattern%d", ++i) << "ab.*cd" << subject; + } + + { + QString subject = "ab"; + subject.append(QString(512*1024, QLatin1Char('x'))); + subject.append("cd"); + QTest::addRow("pattern%d", ++i) << "ab.*cd" << subject; + } + + QTest::addRow("pattern%d", ++i) << "(?(R)a*(?1)|((?R))b)" << "aaaabcde"; + QTest::addRow("pattern%d", ++i) << "(?(R)a*(?1)|((?R))b)" << "aaaaaaabcde"; +} + +void tst_QRegularExpression::threadSafety() +{ + QFETCH(QString, pattern); + QFETCH(QString, subject); + + static const int THREAD_SAFETY_ITERATIONS = 50; + + const int threadCount = qMax(QThread::idealThreadCount(), 4); + + for (int threadSafetyIteration = 0; threadSafetyIteration < THREAD_SAFETY_ITERATIONS; ++threadSafetyIteration) { + QRegularExpression re(pattern); + + QVector<MatcherThread *> threads; + for (int i = 0; i < threadCount; ++i) { + MatcherThread *thread = new MatcherThread(re, subject); + thread->start(); + threads.push_back(thread); + } + + for (int i = 0; i < threadCount; ++i) + threads[i]->wait(); + + qDeleteAll(threads); + } +} + +void tst_QRegularExpression::wildcard_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QString>("string"); + QTest::addColumn<int>("foundIndex"); + + auto addRow = [](const char *pattern, const char *string, int foundIndex) { + QTest::newRow(pattern) << pattern << string << foundIndex; + }; + + addRow("*.html", "test.html", 0); + addRow("*.html", "test.htm", -1); + addRow("bar*", "foobarbaz", 3); + addRow("*", "Qt Rocks!", 0); + addRow(".html", "test.html", 4); + addRow(".h", "test.cpp", -1); + addRow(".???l", "test.html", 4); + addRow("?", "test.html", 0); + addRow("?m", "test.html", 6); + addRow(".h[a-z]ml", "test.html", 4); + addRow(".h[A-Z]ml", "test.html", -1); + addRow(".h[A-Z]ml", "test.hTml", 4); + addRow(".h[!A-Z]ml", "test.hTml", -1); + addRow(".h[!A-Z]ml", "test.html", 4); + addRow(".h[!T]ml", "test.hTml", -1); + addRow(".h[!T]ml", "test.html", 4); + addRow(".h[!T]m[!L]", "test.htmL", -1); + addRow(".h[!T]m[!L]", "test.html", 4); + addRow(".h[][!]", "test.h]ml", 4); + addRow(".h[][!]", "test.h[ml", 4); + addRow(".h[][!]", "test.h!ml", 4); +} + +void tst_QRegularExpression::wildcard() +{ + QFETCH(QString, pattern); + QFETCH(QString, string); + QFETCH(int, foundIndex); + + QRegularExpression re; + re.setWildcardPattern(pattern); + + QRegularExpressionMatch match = re.match(string); + + QCOMPARE(match.capturedStart(), foundIndex); +} + +void tst_QRegularExpression::testInvalidWildcard_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<bool>("isValid"); + + QTest::newRow("valid []") << "[abc]" << true; + QTest::newRow("valid ending ]") << "abc]" << true; + QTest::newRow("invalid [") << "[abc" << false; + QTest::newRow("ending [") << "abc[" << false; + QTest::newRow("ending [^") << "abc[^" << false; + QTest::newRow("ending [\\") << "abc[\\" << false; + QTest::newRow("ending []") << "abc[]" << false; + QTest::newRow("ending [[") << "abc[[" << false; +} + +void tst_QRegularExpression::testInvalidWildcard() +{ + QFETCH(QString, pattern); + + QRegularExpression re; + re.setWildcardPattern(pattern); + + QFETCH(bool, isValid); + QCOMPARE(re.isValid(), isValid); +} + +QTEST_APPLESS_MAIN(tst_QRegularExpression) + +#include "tst_qregularexpression.moc" diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h deleted file mode 100644 index 8bb4aa0cce..0000000000 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $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 defaultConstructors(); - 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(); - void captureNames_data(); - void captureNames(); - void pcreJitStackUsage_data(); - void pcreJitStackUsage(); - void regularExpressionMatch_data(); - void regularExpressionMatch(); - void JOptionUsage_data(); - void JOptionUsage(); - void QStringAndQStringRefEquivalence(); - -private: - void provideRegularExpressions(); -}; diff --git a/tests/auto/corelib/tools/qscopeguard/qscopeguard.pro b/tests/auto/corelib/tools/qscopeguard/qscopeguard.pro new file mode 100644 index 0000000000..070d4b077c --- /dev/null +++ b/tests/auto/corelib/tools/qscopeguard/qscopeguard.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qscopeguard +QT = core testlib +SOURCES = tst_qscopeguard.cpp diff --git a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp b/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp index 6d2ae48235..f95d48f042 100644 --- a/tests/auto/corelib/tools/qregularexpression/alwaysoptimize/tst_qregularexpression_alwaysoptimize.cpp +++ b/tests/auto/corelib/tools/qscopeguard/tst_qscopeguard.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sérgio Martins <sergio.martins@kdab.com> ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -27,25 +27,59 @@ ****************************************************************************/ #include <QtTest/QtTest> -#include "../tst_qregularexpression.h" +#include <QtCore/QScopeGuard> -class tst_QRegularExpression_AlwaysOptimize : public tst_QRegularExpression +/*! + \class tst_QScopedGuard + \internal + \since 5.11 + \brief Tests class QScopedCleanup and function qScopeGuard + + */ +class tst_QScopedGuard : public QObject { Q_OBJECT -private slots: - void initTestCase(); +private Q_SLOTS: + void leavingScope(); + void exceptions(); }; -QT_BEGIN_NAMESPACE -extern Q_CORE_EXPORT unsigned int qt_qregularexpression_optimize_after_use_count; // from qregularexpression.cpp -QT_END_NAMESPACE +static int s_globalState = 0; -void tst_QRegularExpression_AlwaysOptimize::initTestCase() +void tst_QScopedGuard::leavingScope() { - qt_qregularexpression_optimize_after_use_count = 1; + auto cleanup = qScopeGuard([] { s_globalState++; QCOMPARE(s_globalState, 3); }); + QCOMPARE(s_globalState, 0); + + { + auto cleanup = qScopeGuard([] { s_globalState++; }); + QCOMPARE(s_globalState, 0); + } + + QCOMPARE(s_globalState, 1); + s_globalState++; } -QTEST_APPLESS_MAIN(tst_QRegularExpression_AlwaysOptimize) +void tst_QScopedGuard::exceptions() +{ + s_globalState = 0; + bool caught = false; + QT_TRY + { + auto cleanup = qScopeGuard([&caught] { s_globalState++; }); + QT_THROW(std::bad_alloc()); //if Qt compiled without exceptions this is noop + s_globalState = 100; + } + QT_CATCH(...) + { + caught = true; + QCOMPARE(s_globalState, 1); + } + + QVERIFY((caught && s_globalState == 1) || (!caught && s_globalState == 101)); + +} -#include "tst_qregularexpression_alwaysoptimize.moc" +QTEST_MAIN(tst_QScopedGuard) +#include "tst_qscopeguard.moc" diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp index 3e1668522e..4dc620e6ab 100644 --- a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp @@ -53,6 +53,12 @@ # include <unistd.h> #endif +enum { + QMakeTimeout = 300000, // 5 minutes + CompileTimeout = 600000, // 10 minutes + RunTimeout = 300000 // 5 minutes +}; + static QString makespec() { static const char default_makespec[] = DEFAULT_MAKESPEC; @@ -143,7 +149,7 @@ namespace QTest { bool prepareSourceCode(const QByteArray &body); bool createProjectFile(); bool runQmake(); - bool runMake(Target target); + bool runMake(Target target, int timeout); bool commonSetup(const QByteArray &body); }; @@ -602,7 +608,7 @@ namespace QTest { std_err += "qmake: "; std_err += qmake.errorString().toLocal8Bit(); } else { - ok = qmake.waitForFinished(); + ok = qmake.waitForFinished(QMakeTimeout); exitCode = qmake.exitCode(); if (!ok) QTest::ensureStopped(qmake); @@ -617,7 +623,7 @@ namespace QTest { #endif // QT_CONFIG(process) } - bool QExternalTestPrivate::runMake(Target target) + bool QExternalTestPrivate::runMake(Target target, int timeout) { #if !QT_CONFIG(process) return false; @@ -670,7 +676,7 @@ namespace QTest { } make.closeWriteChannel(); - bool ok = make.waitForFinished(channelMode == QProcess::ForwardedChannels ? -1 : 60000); + bool ok = make.waitForFinished(channelMode == QProcess::ForwardedChannels ? -1 : timeout); if (!ok) QTest::ensureStopped(make); exitCode = make.exitCode(); @@ -705,7 +711,7 @@ namespace QTest { failedStage = QExternalTest::CompilationStage; std_out += "\n### --- stdout from make (compilation) --- ###\n"; std_err += "\n### --- stderr from make (compilation) --- ###\n"; - return runMake(Compile); + return runMake(Compile, CompileTimeout); } bool QExternalTestPrivate::tryLink(const QByteArray &body) @@ -717,7 +723,7 @@ namespace QTest { failedStage = QExternalTest::LinkStage; std_out += "\n### --- stdout from make (linking) --- ###\n"; std_err += "\n### --- stderr from make (linking) --- ###\n"; - return runMake(Link); + return runMake(Link, CompileTimeout); } bool QExternalTestPrivate::tryRun(const QByteArray &body) @@ -729,7 +735,7 @@ namespace QTest { failedStage = QExternalTest::RunStage; std_out += "\n### --- stdout from process --- ###\n"; std_err += "\n### --- stderr from process --- ###\n"; - return runMake(Run); + return runMake(Run, RunTimeout); } } QT_END_NAMESPACE diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 2074c9789a..e6dfe81ca9 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -450,6 +450,8 @@ private slots: void trimmed(); void toUpper(); void toLower(); + void isUpper(); + void isLower(); void toCaseFolded(); void rightJustified(); void leftJustified(); @@ -529,10 +531,8 @@ private slots: void integer_conversion(); void tortureSprintfDouble(); void toNum(); -#if !defined(Q_OS_WIN) void localeAwareCompare_data(); void localeAwareCompare(); -#endif void reverseIterators(); void split_data(); void split(); @@ -2315,6 +2315,46 @@ void tst_QString::toLower() #endif } +void tst_QString::isUpper() +{ + QVERIFY(!QString().isUpper()); + QVERIFY(!QString("").isUpper()); + QVERIFY(QString("TEXT").isUpper()); + QVERIFY(!QString("text").isUpper()); + QVERIFY(!QString("Text").isUpper()); + QVERIFY(!QString("tExt").isUpper()); + QVERIFY(!QString("teXt").isUpper()); + QVERIFY(!QString("texT").isUpper()); + QVERIFY(!QString("TExt").isUpper()); + QVERIFY(!QString("teXT").isUpper()); + QVERIFY(!QString("tEXt").isUpper()); + QVERIFY(!QString("tExT").isUpper()); + QVERIFY(!QString("@ABYZ[").isUpper()); + QVERIFY(!QString("@abyz[").isUpper()); + QVERIFY(!QString("`ABYZ{").isUpper()); + QVERIFY(!QString("`abyz{").isUpper()); +} + +void tst_QString::isLower() +{ + QVERIFY(!QString().isLower()); + QVERIFY(!QString("").isLower()); + QVERIFY(QString("text").isLower()); + QVERIFY(!QString("Text").isLower()); + QVERIFY(!QString("tExt").isLower()); + QVERIFY(!QString("teXt").isLower()); + QVERIFY(!QString("texT").isLower()); + QVERIFY(!QString("TExt").isLower()); + QVERIFY(!QString("teXT").isLower()); + QVERIFY(!QString("tEXt").isLower()); + QVERIFY(!QString("tExT").isLower()); + QVERIFY(!QString("TEXT").isLower()); + QVERIFY(!QString("@ABYZ[").isLower()); + QVERIFY(!QString("@abyz[").isLower()); + QVERIFY(!QString("`ABYZ{").isLower()); + QVERIFY(!QString("`abyz{").isLower()); +} + void tst_QString::toCaseFolded() { QCOMPARE( QString().toCaseFolded(), QString() ); @@ -5468,8 +5508,6 @@ void tst_QString::tortureSprintfDouble() #include <locale.h> -#if !defined(Q_OS_WIN) -// On Q_OS_WIN, we cannot set the system or user locale void tst_QString::localeAwareCompare_data() { QTest::addColumn<QString>("locale"); @@ -5477,6 +5515,46 @@ void tst_QString::localeAwareCompare_data() QTest::addColumn<QString>("s2"); QTest::addColumn<int>("result"); + // Compare decomposed and composed form + { + // From ES6 test262 test suite (built-ins/String/prototype/localeCompare/15.5.4.9_CE.js). The test cases boil down to code like this: + // console.log("\u1111\u1171\u11B6".localeCompare("\ud4db") + + // example from Unicode 5.0, section 3.7, definition D70 + QTest::newRow("normalize1") << QString() << QString::fromUtf8("o\xCC\x88") << QString::fromUtf8("\xC3\xB6") << 0; + // examples from Unicode 5.0, chapter 3.11 + QTest::newRow("normalize2") << QString() << QString::fromUtf8("\xC3\xA4\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize3") << QString() << QString::fromUtf8("a\xCC\x88\xCC\xA3") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize4") << QString() << QString::fromUtf8("\xE1\xBA\xA1\xCC\x88") << QString::fromUtf8("a\xCC\xA3\xCC\x88") << 0; + QTest::newRow("normalize5") << QString() << QString::fromUtf8("\xC3\xA4\xCC\x86") << QString::fromUtf8("a\xCC\x88\xCC\x86") << 0; + QTest::newRow("normalize6") << QString() << QString::fromUtf8("\xC4\x83\xCC\x88") << QString::fromUtf8("a\xCC\x86\xCC\x88") << 0; + // example from Unicode 5.0, chapter 3.12 + QTest::newRow("normalize7") << QString() << QString::fromUtf8("\xE1\x84\x91\xE1\x85\xB1\xE1\x86\xB6") << QString::fromUtf8("\xED\x93\x9B") << 0; + // examples from UTS 10, Unicode Collation Algorithm + QTest::newRow("normalize8") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("\xC3\x85") << 0; + QTest::newRow("normalize9") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize10") << QString() << QString::fromUtf8("x\xCC\x9B\xCC\xA3") << QString::fromUtf8("x\xCC\xA3\xCC\x9B") << 0; + QTest::newRow("normalize11") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xE1\xBB\xA5\xCC\x9B") << 0; + QTest::newRow("normalize12") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\x9B\xCC\xA3") << 0; + QTest::newRow("normalize13") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("\xC6\xB0\xCC\xA3") << 0; + QTest::newRow("normalize14") << QString() << QString::fromUtf8("\xE1\xBB\xB1") << QString::fromUtf8("u\xCC\xA3\xCC\x9B") << 0; + // examples from UAX 15, Unicode Normalization Forms + QTest::newRow("normalize15") << QString() << QString::fromUtf8("\xC3\x87") << QString::fromUtf8("C\xCC\xA7") << 0; + QTest::newRow("normalize16") << QString() << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize17") << QString() << QString::fromUtf8("\xEA\xB0\x80") << QString::fromUtf8("\xE1\x84\x80\xE1\x85\xA1") << 0; + QTest::newRow("normalize18") << QString() << QString::fromUtf8("\xE2\x84\xAB") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize19") << QString() << QString::fromUtf8("\xE2\x84\xA6") << QString::fromUtf8("\xCE\xA9") << 0; + QTest::newRow("normalize20") << QString() << QString::fromUtf8("\xC3\x85") << QString::fromUtf8("A\xCC\x8A") << 0; + QTest::newRow("normalize21") << QString() << QString::fromUtf8("\xC3\xB4") << QString::fromUtf8("o\xCC\x82") << 0; + QTest::newRow("normalize22") << QString() << QString::fromUtf8("\xE1\xB9\xA9") << QString::fromUtf8("s\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize23") << QString() << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("d\xCC\xA3\xCC\x87") << 0; + QTest::newRow("normalize24") << QString() << QString::fromUtf8("\xE1\xB8\x8B\xCC\xA3") << QString::fromUtf8("\xE1\xB8\x8D\xCC\x87") << 0; + QTest::newRow("normalize25") << QString() << QString::fromUtf8("q\xCC\x87\xCC\xA3") << QString::fromUtf8("q\xCC\xA3\xCC\x87") << 0; + + } + +#if !defined(Q_OS_WIN) +// On Q_OS_WIN, we cannot set the system or user locale /* The C locale performs pure byte comparisons for Latin-1-specific characters (I think). Compare with Swedish @@ -5537,6 +5615,7 @@ void tst_QString::localeAwareCompare_data() QTest::newRow("german2") << QString("de_DE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1; QTest::newRow("german3") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1; #endif +#endif //!defined(Q_OS_WIN) } void tst_QString::localeAwareCompare() @@ -5549,17 +5628,17 @@ void tst_QString::localeAwareCompare() QStringRef r1(&s1, 0, s1.length()); QStringRef r2(&s2, 0, s2.length()); + if (!locale.isEmpty()) { #if defined (Q_OS_DARWIN) || defined(QT_USE_ICU) - QSKIP("Setting the locale is not supported on OS X or ICU (you can set the C locale, but that won't affect localeAwareCompare)"); + QSKIP("Setting the locale is not supported on OS X or ICU (you can set the C locale, but that won't affect localeAwareCompare)"); #else - if (!locale.isEmpty()) { const char *newLocale = setlocale(LC_ALL, locale.toLatin1()); if (!newLocale) { setlocale(LC_ALL, ""); QSKIP("Please install the proper locale on this machine to test properly"); } - } #endif + } #ifdef QT_USE_ICU // ### for c1, ICU disagrees with libc on how to compare @@ -5614,7 +5693,6 @@ void tst_QString::localeAwareCompare() if (!locale.isEmpty()) setlocale(LC_ALL, ""); } -#endif //!defined(Q_OS_WIN) void tst_QString::reverseIterators() { diff --git a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp index 4ae96005d0..e800a0d794 100644 --- a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp +++ b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp @@ -217,6 +217,8 @@ private Q_SLOTS: #endif } + void comparison(); + private: template <typename String> void conversion_tests(String arg) const; @@ -615,5 +617,23 @@ void tst_QStringView::conversion_tests(String string) const } } +void tst_QStringView::comparison() +{ + const QStringView aa = QStringViewLiteral("aa"); + const QStringView upperAa = QStringViewLiteral("AA"); + const QStringView bb = QStringViewLiteral("bb"); + + QVERIFY(aa == aa); + QVERIFY(aa != bb); + QVERIFY(aa < bb); + QVERIFY(bb > aa); + + QCOMPARE(aa.compare(aa), 0); + QVERIFY(aa.compare(upperAa) != 0); + QCOMPARE(aa.compare(upperAa, Qt::CaseInsensitive), 0); + QVERIFY(aa.compare(bb) < 0); + QVERIFY(bb.compare(aa) > 0); +} + QTEST_APPLESS_MAIN(tst_QStringView) #include "tst_qstringview.moc" diff --git a/tests/auto/corelib/tools/qtimeline/BLACKLIST b/tests/auto/corelib/tools/qtimeline/BLACKLIST index 74f84a4a6d..958563d15e 100644 --- a/tests/auto/corelib/tools/qtimeline/BLACKLIST +++ b/tests/auto/corelib/tools/qtimeline/BLACKLIST @@ -1,6 +1,7 @@ [interpolation] windows osx-10.12 +osx-10.13 [duration] windows [frameRate] diff --git a/tests/auto/corelib/tools/qtimezone/qtimezone.pro b/tests/auto/corelib/tools/qtimezone/qtimezone.pro index 19ebc13306..5ec8d008e7 100644 --- a/tests/auto/corelib/tools/qtimezone/qtimezone.pro +++ b/tests/auto/corelib/tools/qtimezone/qtimezone.pro @@ -3,7 +3,7 @@ TARGET = tst_qtimezone QT = core-private testlib SOURCES = tst_qtimezone.cpp qtConfig(icu) { - DEFINES += QT_USE_ICU + QMAKE_USE_PRIVATE += icu } darwin { diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index ed80d4528d..d335dae7bc 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -31,6 +31,10 @@ #include <private/qtimezoneprivate_p.h> #include <qlocale.h> +#if defined(Q_OS_WIN) && !QT_CONFIG(icu) +# define USING_WIN_TZ +#endif + class tst_QTimeZone : public QObject { Q_OBJECT @@ -413,7 +417,7 @@ void tst_QTimeZone::specificTransition_data() QTest::addColumn<int>("dstoff"); // Moscow ditched DST on 2010-10-31 but has since changed standard offset twice. -#ifdef Q_OS_WIN +#ifdef USING_WIN_TZ // Win7 is too old to know about this transition: if (QOperatingSystemVersion::current() > QOperatingSystemVersion::Windows7) #endif @@ -477,8 +481,9 @@ void tst_QTimeZone::transitionEachZone_data() }; QString name; + const auto zones = QTimeZone::availableTimeZoneIds(); for (int k = sizeof(table) / sizeof(table[0]); k-- > 0; ) { - foreach (QByteArray zone, QTimeZone::availableTimeZoneIds()) { + for (const QByteArray &zone : zones) { name.sprintf("%s@%d", zone.constData(), table[k].year); QTest::newRow(name.toUtf8().constData()) << zone @@ -500,7 +505,7 @@ void tst_QTimeZone::transitionEachZone() QTimeZone named(zone); for (int i = start; i < stop; i++) { -#ifdef Q_OS_WIN +#ifdef USING_WIN_TZ // See QTBUG-64985: MS's TZ APIs' misdescription of Europe/Samara leads // to mis-disambiguation of its fall-back here. if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::Windows7 @@ -833,7 +838,7 @@ void tst_QTimeZone::utcTest() void tst_QTimeZone::icuTest() { -#if defined(QT_BUILD_INTERNAL) && defined(QT_USE_ICU) +#if defined(QT_BUILD_INTERNAL) && QT_CONFIG(icu) // Known datetimes qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); @@ -881,7 +886,7 @@ void tst_QTimeZone::icuTest() testCetPrivate(tzp); testEpochTranPrivate(QIcuTimeZonePrivate("America/Toronto")); -#endif // QT_USE_ICU +#endif // icu } void tst_QTimeZone::tzTest() @@ -907,7 +912,7 @@ void tst_QTimeZone::tzTest() QLocale enUS("en_US"); // Only test names in debug mode, names used can vary by ICU version installed if (debug) { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::LongName, enUS), QString("Central European Standard Time")); QCOMPARE(tzp.displayName(QTimeZone::StandardTime, QTimeZone::ShortName, enUS), @@ -946,7 +951,7 @@ void tst_QTimeZone::tzTest() QString("CET")); QCOMPARE(tzp.displayName(QTimeZone::GenericTime, QTimeZone::OffsetName, enUS), QString("CET")); -#endif // QT_USE_ICU +#endif // icu // Test Abbreviations QCOMPARE(tzp.abbreviation(std), QString("CET")); @@ -1123,7 +1128,7 @@ void tst_QTimeZone::darwinTypes() void tst_QTimeZone::winTest() { -#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) +#if defined(QT_BUILD_INTERNAL) && defined(USING_WIN_TZ) // Known datetimes qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); @@ -1174,7 +1179,7 @@ void tst_QTimeZone::winTest() testCetPrivate(tzp); testEpochTranPrivate(QWinTimeZonePrivate("America/Toronto")); -#endif // Q_OS_WIN +#endif // QT_BUILD_INTERNAL && USING_WIN_TZ } #ifdef QT_BUILD_INTERNAL @@ -1286,7 +1291,7 @@ void tst_QTimeZone::testEpochTranPrivate(const QTimeZonePrivate &tzp) // 1970-04-26 02:00 EST, -5 -> -4 const QDateTime after = QDateTime(QDate(1970, 4, 26), QTime(2, 0), Qt::OffsetFromUTC, -5 * 3600); const QDateTime found = QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, Qt::UTC); -#ifdef Q_OS_WIN // MS gets the date wrong: 5th April instead of 26th. +#ifdef USING_WIN_TZ // MS gets the date wrong: 5th April instead of 26th. QCOMPARE(found.toOffsetFromUtc(-5 * 3600).time(), after.time()); #else QCOMPARE(found, after); diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index f35ed026ac..f28cf21b8b 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -30,6 +30,7 @@ SUBDIRS=\ qlist \ qlist_strictiterators \ qlocale \ + qmakearray \ qmap \ qmap_strictiterators \ qmargins \ |