diff options
Diffstat (limited to 'tests/auto/corelib/tools')
7 files changed, 151 insertions, 54 deletions
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp index 81cc66f045..67c15682a2 100644 --- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp +++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp @@ -102,6 +102,22 @@ void tst_QCryptographicHash::intermediary_result_data() << QByteArray("abc") << QByteArray("abc") << QByteArray::fromHex("A9993E364706816ABA3E25717850C26C9CD0D89D") << QByteArray::fromHex("F8C1D87006FBF7E5CC4B026C3138BC046883DC71"); + QTest::newRow("sha224") << int(QCryptographicHash::Sha224) + << QByteArray("abc") << QByteArray("abc") + << QByteArray::fromHex("23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7") + << QByteArray::fromHex("7C9C91FC479626AA1A525301084DEB96716131D146A2DB61B533F4C9"); + QTest::newRow("sha256") << int(QCryptographicHash::Sha256) + << QByteArray("abc") << QByteArray("abc") + << QByteArray::fromHex("BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD") + << QByteArray::fromHex("BBB59DA3AF939F7AF5F360F2CEB80A496E3BAE1CD87DDE426DB0AE40677E1C2C"); + QTest::newRow("sha384") << int(QCryptographicHash::Sha384) + << QByteArray("abc") << QByteArray("abc") + << QByteArray::fromHex("CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7") + << QByteArray::fromHex("CAF33A735C9535CE7F5D24FB5B3A4834F0E9316664AD15A9E8221679D4A3B4FB7E962404BA0C10C1D43AB49D03A08B8D"); + QTest::newRow("sha512") << int(QCryptographicHash::Sha512) + << QByteArray("abc") << QByteArray("abc") + << QByteArray::fromHex("DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F") + << QByteArray::fromHex("F3C41E7B63EE869596FC28BAD64120612C520F65928AB4D126C72C6998B551B8FF1CEDDFED4373E6717554DC89D1EEE6F0AB22FD3675E561ABA9AE26A3EEC53B"); } void tst_QCryptographicHash::intermediary_result() diff --git a/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro b/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro index d510d82207..a97350ca3f 100644 --- a/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro +++ b/tests/auto/corelib/tools/qlocale/syslocaleapp/syslocaleapp.pro @@ -1,6 +1,7 @@ SOURCES += syslocaleapp.cpp DESTDIR = ./ +CONFIG += console CONFIG -= app_bundle QT = core diff --git a/tests/auto/corelib/tools/qlocale/test/test.pro b/tests/auto/corelib/tools/qlocale/test/test.pro index 5a4fb674c5..eafd8c1699 100644 --- a/tests/auto/corelib/tools/qlocale/test/test.pro +++ b/tests/auto/corelib/tools/qlocale/test/test.pro @@ -1,5 +1,6 @@ -CONFIG += testcase -QT = core testlib network +CONFIG += console testcase +CONFIG -= app_bundle +QT = core testlib embedded: QT += gui SOURCES = ../tst_qlocale.cpp diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index db7f503f57..02acb00548 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -43,6 +43,9 @@ #include <QtTest/QtTest> #include <math.h> #include <qglobal.h> +#include <qdir.h> +#include <qfileinfo.h> +#include <QScopedArrayPointer> #include <qtextcodec.h> #include <qdatetime.h> #include <float.h> @@ -83,6 +86,7 @@ public: tst_QLocale(); private slots: + void initTestCase(); void windowsDefaultLocale(); void macDefaultLocale(); @@ -131,6 +135,7 @@ private slots: private: QString m_decimal, m_thousand, m_sdate, m_ldate, m_time; + QString m_sysapp; }; tst_QLocale::tst_QLocale() @@ -138,6 +143,22 @@ tst_QLocale::tst_QLocale() qRegisterMetaType<QLocale::FormatType>("QLocale::FormatType"); } +void tst_QLocale::initTestCase() +{ + const QString syslocaleapp_dir = QFINDTESTDATA("syslocaleapp"); + QVERIFY2(!syslocaleapp_dir.isEmpty(), + qPrintable(QStringLiteral("Cannot find 'syslocaleapp' starting from ") + + QDir::toNativeSeparators(QDir::currentPath()))); + m_sysapp = syslocaleapp_dir + QStringLiteral("/syslocaleapp"); +#ifdef Q_OS_WIN + m_sysapp += QStringLiteral(".exe"); +#endif + const QFileInfo fi(m_sysapp); + QVERIFY2(fi.exists() && fi.isExecutable(), + qPrintable(QDir::toNativeSeparators(m_sysapp) + + QStringLiteral(" does not exist or is not executable."))); +} + void tst_QLocale::ctor() { QLocale default_locale = QLocale::system(); @@ -346,6 +367,54 @@ void tst_QLocale::ctor() #undef TEST_CTOR } +static inline bool runSysApp(const QString &binary, + const QStringList &env, + QString *output, + QString *errorMessage) +{ + output->clear(); + errorMessage->clear(); + QProcess process; + process.setEnvironment(env); + process.start(binary); + process.closeWriteChannel(); + if (!process.waitForStarted()) { + *errorMessage = QString::fromLatin1("Cannot start '%1': %2").arg(binary, process.errorString()); + return false; + } + if (!process.waitForFinished()) { + process.kill(); + *errorMessage = QStringLiteral("Timeout waiting for ") + binary; + return false; + } + *output = QString::fromLocal8Bit(process.readAllStandardOutput()); + return true; +} + +static inline bool runSysAppTest(const QString &binary, + QStringList baseEnv, + const QString &requestedLocale, + const QString &expectedOutput, + QString *errorMessage) +{ + QString output; + baseEnv.append(QStringLiteral("LANG=") + requestedLocale); + if (!runSysApp(binary, baseEnv, &output, errorMessage)) + return false; + + if (output.isEmpty()) { + *errorMessage = QString::fromLatin1("Empty output received for requested '%1' (expected '%2')"). + arg(requestedLocale, expectedOutput); + return false; + } + if (output != expectedOutput) { + *errorMessage = QString::fromLatin1("Output mismatch for requested '%1': Expected '%2', got '%3'"). + arg(requestedLocale, expectedOutput, output); + return false; + } + return true; +} + void tst_QLocale::emptyCtor() { #if defined(Q_OS_WINCE) @@ -358,15 +427,9 @@ void tst_QLocale::emptyCtor() { \ /* Test constructor without arguments. Needs separate process */ \ /* because of caching of the system locale. */ \ - QProcess process; \ - process.setEnvironment(QStringList(env) << QString("LANG=%1").arg(req_lc)); \ - process.start(syslocaleapp_dir + "syslocaleapp"); \ - process.waitForReadyRead(); \ - QString ret = QString(process.readAll()); \ - process.waitForFinished(); \ - QVERIFY2(!ret.isEmpty(), "Cannot launch external process"); \ - QVERIFY2(QString(exp_str) == ret, QString("Expected: " + QString(exp_str) + ", got: " \ - + ret + ". Requested: " + QString(req_lc)).toLatin1().constData()); \ + QString errorMessage; \ + QVERIFY2(runSysAppTest(m_sysapp, env, QLatin1String(req_lc), QLatin1String(exp_str), &errorMessage), \ + qPrintable(errorMessage)); \ } // Get an environment free of any locale-related variables @@ -377,15 +440,11 @@ void tst_QLocale::emptyCtor() env << entry; } - QString syslocaleapp_dir = QFINDTESTDATA("syslocaleapp/"); - // Get default locale. - QProcess p; - p.setEnvironment(env); - p.start(syslocaleapp_dir + "syslocaleapp"); - p.waitForReadyRead(); - QString defaultLoc = QString(p.readAll()); - p.waitForFinished(); + QString defaultLoc; + QString errorMessage; + QVERIFY2(runSysApp(m_sysapp, env, &defaultLoc, &errorMessage), + qPrintable(errorMessage)); TEST_CTOR("C", "C") TEST_CTOR("bla", "C") @@ -421,9 +480,9 @@ void tst_QLocale::emptyCtor() TEST_CTOR("DE", "de_DE"); TEST_CTOR("EN", "en_US"); - TEST_CTOR("en/", defaultLoc) - TEST_CTOR("asdfghj", defaultLoc); - TEST_CTOR("123456", defaultLoc); + TEST_CTOR("en/", defaultLoc.toLatin1()) + TEST_CTOR("asdfghj", defaultLoc.toLatin1()); + TEST_CTOR("123456", defaultLoc.toLatin1()); #undef TEST_CTOR #endif @@ -1147,17 +1206,15 @@ static QString getWinLocaleInfo(LCTYPE type) qWarning("QLocale: empty windows locale info (%d)", type); return QString(); } - - QByteArray buff(cnt, 0); - - cnt = GetLocaleInfo(id, type, reinterpret_cast<wchar_t*>(buff.data()), buff.size() / 2); + cnt /= sizeof(wchar_t); + QScopedArrayPointer<wchar_t> buf(new wchar_t[cnt]); + cnt = GetLocaleInfo(id, type, buf.data(), cnt); if (cnt == 0) { qWarning("QLocale: empty windows locale info (%d)", type); return QString(); } - - return QString::fromWCharArray(reinterpret_cast<wchar_t*>(buff.data())); + return QString::fromWCharArray(buf.data()); } static void setWinLocaleInfo(LCTYPE type, const QString &value) @@ -1189,13 +1246,13 @@ public: }; -#endif +#endif // Q_OS_WIN void tst_QLocale::windowsDefaultLocale() { -#ifndef Q_OS_WIN - QSKIP("This is a Windows test"); -#else +#ifdef Q_OS_WIN + QSKIP("This test currently fails - QTBUG-24543"); + RestoreLocaleHelper systemLocale; // set weird system defaults and make sure we're using them setWinLocaleInfo(LOCALE_SDECIMAL, QLatin1String("@")); @@ -1204,7 +1261,6 @@ void tst_QLocale::windowsDefaultLocale() setWinLocaleInfo(LOCALE_SLONGDATE, QLatin1String("d@M@yyyy")); setWinLocaleInfo(LOCALE_STIMEFORMAT, QLatin1String("h^m^s")); QLocale locale = QLocale::system(); - // make sure we are seeing the system's format strings QCOMPARE(locale.decimalPoint(), QChar('@')); QCOMPARE(locale.groupSeparator(), QChar('?')); @@ -1230,7 +1286,7 @@ void tst_QLocale::windowsDefaultLocale() QCOMPARE(locale.toString(QDateTime(QDate(1974, 12, 1), QTime(1,2,3)), QLocale::LongFormat), QString("1@12@1974 1^2^3")); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::LongFormat), QString("1^2^3")); -#endif +#endif // #ifdef Q_OS_WIN } void tst_QLocale::numberOptions() diff --git a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp index 0148e933e4..a697e23270 100644 --- a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp +++ b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp @@ -79,6 +79,8 @@ private slots: void posAndCapConsistency_data(); void posAndCapConsistency(); void interval(); + void validityCheck_data(); + void validityCheck(); }; // Testing get/set functions @@ -1344,6 +1346,33 @@ void tst_QRegExp::interval() } } +void tst_QRegExp::validityCheck_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<bool>("validity"); + QTest::newRow("validity01") << QString() << true; + QTest::newRow("validity02") << QString("abc.*abc") << true; + QTest::newRow("validity03") << QString("[a-z") << false; + QTest::newRow("validity04") << QString("a(b") << false; +} + +void tst_QRegExp::validityCheck() +{ + QFETCH(QString, pattern); + + QRegExp rx(pattern); + QTEST(rx.isValid(), "validity"); + QCOMPARE(rx.matchedLength(), -1); + QCOMPARE(rx.pos(), -1); + QCOMPARE(rx.cap(), QString("")); + + QRegExp rx2(rx); + QTEST(rx2.isValid(), "validity"); + QCOMPARE(rx2.matchedLength(), -1); + QCOMPARE(rx2.pos(), -1); + QCOMPARE(rx2.cap(), QString("")); +} + QTEST_APPLESS_MAIN(tst_QRegExp) #include "tst_qregexp.moc" diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 3fb253c646..7e4f591f47 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -808,10 +808,7 @@ void tst_QString::constructorQByteArray() QCOMPARE(str1.length(), expected.length()); QCOMPARE( str1, expected ); - QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1 QString strBA(src); - QTextCodec::setCodecForCStrings( 0 ); - QCOMPARE( strBA, expected ); } @@ -928,12 +925,7 @@ void tst_QString::sprintf() QCOMPARE(a.sprintf("%-5.5s", "Hello" ),(QString)"Hello"); // Check utf8 conversion for %s - QCOMPARE(a.sprintf("%s", "\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205"), QString("\366\344\374\326\304\334\370\346\345\330\306\305")); - - // Check codecForCStrings is used to read non-modifier sequences in the format string - QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - QCOMPARE(a.sprintf("\303\251\303\250\303\240 %s", "\303\251\303\250\303\240"), QString("\303\251\303\250\303\240 \303\251\303\250\303\240")); - QTextCodec::setCodecForCStrings(0); + QCOMPARE(a.sprintf("%s", "\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205"), QString::fromLatin1("\366\344\374\326\304\334\370\346\345\330\306\305")); int n1; a.sprintf("%s%n%s", "hello", &n1, "goodbye"); @@ -1871,9 +1863,7 @@ void tst_QString::append_bytearray() QFETCH( QString, str ); QFETCH( QByteArray, ba ); - QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1 str.append( ba ); - QTextCodec::setCodecForCStrings( 0 ); QTEST( str, "res" ); } @@ -1898,9 +1888,7 @@ void tst_QString::operator_pluseq_bytearray() QFETCH( QString, str ); QFETCH( QByteArray, ba ); - QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1 str += ba; - QTextCodec::setCodecForCStrings( 0 ); QTEST( str, "res" ); } @@ -1960,9 +1948,7 @@ void tst_QString::prepend_bytearray() QFETCH( QString, str ); QFETCH( QByteArray, ba ); - QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1 str.prepend( ba ); - QTextCodec::setCodecForCStrings( 0 ); QTEST( str, "res" ); } @@ -3211,7 +3197,7 @@ void tst_QString::utf8() QFETCH( QByteArray, utf8 ); QFETCH( QString, res ); - QCOMPARE( utf8, QByteArray(res.toUtf8()) ); + QCOMPARE(res.toUtf8(), utf8); } void tst_QString::stringRef_utf8_data() diff --git a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp index 95e24b22fb..afc16078b8 100644 --- a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp +++ b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp @@ -66,10 +66,8 @@ void runScenario() { - // set codec for C strings to 0, enforcing Latin1 - QTextCodec::setCodecForCStrings(0); - QVERIFY(!QTextCodec::codecForCStrings()); - + // this code is latin1. TODO: replace it with the utf8 block below, once + // strings default to utf8. QLatin1Literal l1literal(LITERAL); QLatin1String l1string(LITERAL); QString string(l1string); @@ -130,7 +128,10 @@ void runScenario() r = string P ba; QCOMPARE(r, r2); +#if 0 // now test with codec for C strings set + // TODO: to be re-enabled once strings default to utf8, in place of the + // latin1 code above. QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QVERIFY(QTextCodec::codecForCStrings()); QCOMPARE(QTextCodec::codecForCStrings()->name(), QByteArray("UTF-8")); @@ -153,6 +154,7 @@ void runScenario() QCOMPARE(r, r3); r = string P ba; QCOMPARE(r, r3); +#endif ba = QByteArray(); // empty r = ba P string; @@ -212,9 +214,12 @@ void runScenario() str += QLatin1String(LITERAL) P str; QCOMPARE(str, QString::fromUtf8(UTF8_LITERAL LITERAL UTF8_LITERAL)); #ifndef QT_NO_CAST_FROM_ASCII +#if 0 + // TODO: this relies on strings defaulting to utf8, so disable this for now. str = (QString::fromUtf8(UTF8_LITERAL) += QLatin1String(LITERAL) P UTF8_LITERAL); QCOMPARE(str, QString::fromUtf8(UTF8_LITERAL LITERAL UTF8_LITERAL)); #endif +#endif } //operator QByteArray += @@ -229,11 +234,14 @@ void runScenario() ba2 += ba2 P withZero; QCOMPARE(ba2, QByteArray(withZero + withZero + withZero)); #ifndef QT_NO_CAST_TO_ASCII +#if 0 + // TODO: this relies on strings defaulting to utf8, so disable this for now. ba = UTF8_LITERAL; ba2 = (ba += QLatin1String(LITERAL) + QString::fromUtf8(UTF8_LITERAL)); QCOMPARE(ba2, ba); QCOMPARE(ba, QByteArray(UTF8_LITERAL LITERAL UTF8_LITERAL)); #endif +#endif } } |