diff options
Diffstat (limited to 'tests/auto/corelib')
33 files changed, 346 insertions, 114 deletions
diff --git a/tests/auto/corelib/io/qresourceengine/qresourceengine.pro b/tests/auto/corelib/io/qresourceengine/qresourceengine.pro index d6e2cb3171..e59746c158 100644 --- a/tests/auto/corelib/io/qresourceengine/qresourceengine.pro +++ b/tests/auto/corelib/io/qresourceengine/qresourceengine.pro @@ -1,4 +1,5 @@ CONFIG += testcase parallel_test +TARGET = tst_qresourceengine load(resources) QT = core testlib SOURCES = tst_qresourceengine.cpp diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 2ac0574ec5..f5b4f17732 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -45,6 +45,9 @@ #include "qjsonvalue.h" #include "qjsondocument.h" +#define INVALID_UNICODE "\357\277\277" // "\uffff" +#define UNICODE_DJE "\320\202" // Character from the Serbian Cyrillic alphabet + class TestQtJson: public QObject { Q_OBJECT @@ -1205,7 +1208,7 @@ void TestQtJson::fromJsonErrors() } { QJsonParseError error; - QByteArray json = "[\n \"foo\uffffbar\"]"; + QByteArray json = "[\n \"foo" INVALID_UNICODE "bar\"]"; QJsonDocument doc = QJsonDocument::fromJson(json, &error); QVERIFY(doc.isEmpty()); QCOMPARE(error.error, QJsonParseError::StringUTF8Scan); @@ -1221,7 +1224,7 @@ void TestQtJson::fromJsonErrors() } { QJsonParseError error; - QByteArray json = "[\n \"cЂa\\u12\"]"; + QByteArray json = "[\n \"c" UNICODE_DJE "a\\u12\"]"; QJsonDocument doc = QJsonDocument::fromJson(json, &error); QVERIFY(doc.isEmpty()); QCOMPARE(error.error, QJsonParseError::StringEscapeSequence); @@ -1229,7 +1232,7 @@ void TestQtJson::fromJsonErrors() } { QJsonParseError error; - QByteArray json = "[\n \"cЂa\uffffbar\"]"; + QByteArray json = "[\n \"c" UNICODE_DJE "a" INVALID_UNICODE "bar\"]"; QJsonDocument doc = QJsonDocument::fromJson(json, &error); QVERIFY(doc.isEmpty()); QCOMPARE(error.error, QJsonParseError::StringUTF8Scan); @@ -1237,7 +1240,7 @@ void TestQtJson::fromJsonErrors() } { QJsonParseError error; - QByteArray json = "[\n \"cЂa ]"; + QByteArray json = "[\n \"c" UNICODE_DJE "a ]"; QJsonDocument doc = QJsonDocument::fromJson(json, &error); QVERIFY(doc.isEmpty()); QCOMPARE(error.error, QJsonParseError::EndOfString); @@ -1378,7 +1381,7 @@ void TestQtJson::parseStrings() "abc\\rabc", "abc\\tabc", "abc\\u0019abc", - "abcЂabc", + "abc" UNICODE_DJE "abc", }; int size = sizeof(strings)/sizeof(const char *); @@ -1404,7 +1407,7 @@ void TestQtJson::parseStrings() }; Pairs pairs [] = { { "abc\\/abc", "abc/abc" }, - { "abc\\u0402abc", "abcЂabc" }, + { "abc\\u0402abc", "abc" UNICODE_DJE "abc" }, { "abc\\u0065abc", "abceabc" } }; size = sizeof(pairs)/sizeof(Pairs); @@ -1547,7 +1550,7 @@ void TestQtJson::validation() // only test the first 1000 bytes. Testing the full file takes too long for (int i = 0; i < 1000; ++i) { QByteArray corrupted = binary; - corrupted[i] = 0xff; + corrupted[i] = char(0xff); QJsonDocument doc = QJsonDocument::fromBinaryData(corrupted); if (doc.isNull()) continue; @@ -1567,7 +1570,7 @@ void TestQtJson::validation() for (int i = 0; i < binary.size(); ++i) { QByteArray corrupted = binary; - corrupted[i] = 0xff; + corrupted[i] = char(0xff); QJsonDocument doc = QJsonDocument::fromBinaryData(corrupted); if (doc.isNull()) continue; diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 68ff8e4bb6..09fd0a7adb 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -326,6 +326,8 @@ public slots: signals: void sig0(); QString sig1(QString s1); + void sig10(QString s1, QString s2, QString s3, QString s4, QString s5, QString s6, QString s7, + QString s8, QString s9, QString s10); protected: QtTestObject(QVariant) {} @@ -725,6 +727,7 @@ typedef QString CustomString; class QtTestCustomObject: public QObject { Q_OBJECT + friend class tst_QMetaObject; public: QtTestCustomObject(): QObject(), sum(0) {} @@ -1129,11 +1132,9 @@ void tst_QMetaObject::indexOfMethodPMF() } INDEXOFMETHODPMF_HELPER(tst_QMetaObject, value7Changed, (const QString&)) - INDEXOFMETHODPMF_HELPER(tst_QMetaObject, stdSet, ()) - INDEXOFMETHODPMF_HELPER(QtTestObject, sl10, (QString,QString,QString,QString,QString,QString,QString,QString,QString,QString)) INDEXOFMETHODPMF_HELPER(QtTestObject, sig0, ()) - INDEXOFMETHODPMF_HELPER(QtTestObject, testLongLong, (qint64, quint64)) - INDEXOFMETHODPMF_HELPER(QtTestObject, testReference, (QString&)) + INDEXOFMETHODPMF_HELPER(QtTestObject, sig10, (QString,QString,QString,QString,QString,QString,QString,QString,QString,QString)) + INDEXOFMETHODPMF_HELPER(QtTestCustomObject, sig_custom, (const CustomString &)) } QTEST_MAIN(tst_QMetaObject) diff --git a/tests/auto/corelib/kernel/qobject/qobject.pro b/tests/auto/corelib/kernel/qobject/qobject.pro index 0f86408fc9..6a7cf07f51 100644 --- a/tests/auto/corelib/kernel/qobject/qobject.pro +++ b/tests/auto/corelib/kernel/qobject/qobject.pro @@ -1,4 +1,6 @@ TEMPLATE = subdirs -SUBDIRS = signalbug -tst_qobject.pro.depends = $$SUBDIRS -SUBDIRS += tst_qobject.pro +CONFIG += ordered + +SUBDIRS += \ + signalbug \ + test diff --git a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro index 19d36a63a1..799ef34559 100644 --- a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro +++ b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro @@ -1,6 +1,3 @@ -TEMPLATE = app -DEPENDPATH += . -INCLUDEPATH += . CONFIG -= app_bundle debug_and_release CONFIG += console DESTDIR = ./ @@ -8,7 +5,7 @@ QT -= gui wince*: { LIBS += coredll.lib } -# Input + HEADERS += signalbug.h SOURCES += signalbug.cpp diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.pro b/tests/auto/corelib/kernel/qobject/test/test.pro index 30fd810a2e..9443b2e2c7 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.pro +++ b/tests/auto/corelib/kernel/qobject/test/test.pro @@ -1,11 +1,11 @@ CONFIG += testcase console -TARGET = tst_qobject +TARGET = ../tst_qobject QT = core-private network testlib -SOURCES = tst_qobject.cpp +SOURCES = ../tst_qobject.cpp # this is here for a reason, moc_oldnormalizedobject.cpp is not auto-generated, it was generated by # moc from Qt 4.6, and should *not* be generated by the current moc -SOURCES += moc_oldnormalizeobject.cpp +SOURCES += ../moc_oldnormalizeobject.cpp load(testcase) # for target.path and installTestHelperApp() installTestHelperApp("signalbug/signalbug",signalbug,signalbug) diff --git a/tests/auto/corelib/plugin/qlibrary/lib/lib.pro b/tests/auto/corelib/plugin/qlibrary/lib/lib.pro index d8551faddc..7a2b8cd3b6 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib/lib.pro +++ b/tests/auto/corelib/plugin/qlibrary/lib/lib.pro @@ -13,3 +13,11 @@ win32-borland: DEFINES += WIN32_BORLAND # This project is testdata for tst_qlibrary target.path = $$[QT_INSTALL_TESTS]/tst_qlibrary INSTALLS += target + +win32 { + CONFIG(debug, debug|release) { + DESTDIR = ../debug/ + } else { + DESTDIR = ../release/ + } +} diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro b/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro index a15393b214..8d5af0ea79 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro +++ b/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro @@ -15,13 +15,20 @@ win32-borland: DEFINES += WIN32_BORLAND # We want to test if we can load a shared library with *any* filename... win32 { + CONFIG(debug, debug|release) { + BUILD_FOLDER = debug + } else { + BUILD_FOLDER = release + } + DESTDIR = ../$$BUILD_FOLDER/ + # vcproj and Makefile generators refer to target differently contains(TEMPLATE,vc.*) { src = $(TargetPath) } else { src = $(DESTDIR_TARGET) } - files = mylib.dl2 system.qt.test.mylib.dll + files = $$BUILD_FOLDER$${QMAKE_DIR_SEP}mylib.dl2 $$BUILD_FOLDER$${QMAKE_DIR_SEP}system.qt.test.mylib.dll } else { src = $(DESTDIR)$(TARGET) files = libmylib.so2 system.qt.test.mylib.so @@ -34,7 +41,7 @@ renamed_target.path = $$target.path for(file, files) { QMAKE_POST_LINK += $$QMAKE_COPY $$src ..$$QMAKE_DIR_SEP$$file && renamed_target.extra += $$QMAKE_COPY $$src $(INSTALL_ROOT)$${target.path}$$QMAKE_DIR_SEP$$file && - CLEAN_FILES += ../$$file + CLEAN_FILES += ..$$QMAKE_DIR_SEP$$file } renamed_target.extra = $$member(renamed_target.extra, 0, -2) QMAKE_POST_LINK = $$member(QMAKE_POST_LINK, 0, -2) diff --git a/tests/auto/corelib/plugin/qlibrary/tst/tst.pro b/tests/auto/corelib/plugin/qlibrary/tst/tst.pro index ae6cf97891..d59cd738bf 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst/tst.pro +++ b/tests/auto/corelib/plugin/qlibrary/tst/tst.pro @@ -13,5 +13,3 @@ win32 { } TESTDATA += ../library_path/invalid.so - -win32:CONFIG += insignificant_test # QTBUG-24151 diff --git a/tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp b/tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp index 057db69174..e27085c293 100644 --- a/tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp +++ b/tests/auto/corelib/plugin/qplugin/debugplugin/main.cpp @@ -39,5 +39,14 @@ ** ****************************************************************************/ #include <QtPlugin> +#include <QObject> -Q_EXPORT_PLUGIN2(DebugPlugin, QObject) +class DebugPlugin : public QObject +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "SomeIID") +public: + DebugPlugin() {} +}; + +#include "main.moc" diff --git a/tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp b/tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp index 9542695112..d0875d2902 100644 --- a/tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp +++ b/tests/auto/corelib/plugin/qplugin/releaseplugin/main.cpp @@ -39,5 +39,14 @@ ** ****************************************************************************/ #include <QtPlugin> +#include <QObject> -Q_EXPORT_PLUGIN2(ReleasePlugin, QObject) +class ReleasePlugin : public QObject +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "SomeIID") +public: + ReleasePlugin() {} +}; + +#include "main.moc" diff --git a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp index e6a83cf3d7..af76fcc4a2 100644 --- a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp +++ b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp @@ -55,15 +55,23 @@ public: tst_QPlugin(); private slots: + void initTestCase(); void loadDebugPlugin(); void loadReleasePlugin(); }; tst_QPlugin::tst_QPlugin() - : dir("plugins") + : dir(QFINDTESTDATA("plugins")) { } +void tst_QPlugin::initTestCase() +{ + QVERIFY2(dir.exists(), + qPrintable(QString::fromLatin1("Cannot find the 'plugins' directory starting from '%1'"). + arg(QDir::toNativeSeparators(QDir::currentPath())))); +} + void tst_QPlugin::loadDebugPlugin() { foreach (QString fileName, dir.entryList(QStringList() << "*debug*", QDir::Files)) { diff --git a/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp index 4b2057087a..eaad3ceff5 100644 --- a/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.cpp @@ -47,5 +47,3 @@ QString AlmostPlugin::pluginName() const unresolvedSymbol(); return QLatin1String("Plugin ok"); } - -Q_EXPORT_PLUGIN2(almostplugin, AlmostPlugin) diff --git a/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h b/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h index 6658a5be8d..d64f5985ec 100644 --- a/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h +++ b/tests/auto/corelib/plugin/qpluginloader/almostplugin/almostplugin.h @@ -42,11 +42,13 @@ #define ALMOSTPLUGIN_H #include <QObject> +#include <QtPlugin> #include "../theplugin/plugininterface.h" class AlmostPlugin : public QObject, public PluginInterface { Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.autotests.plugininterface" FILE "../empty.json") Q_INTERFACES(PluginInterface) public: diff --git a/tests/auto/corelib/plugin/qpluginloader/empty.json b/tests/auto/corelib/plugin/qpluginloader/empty.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/tests/auto/corelib/plugin/qpluginloader/empty.json @@ -0,0 +1 @@ +{} diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h b/tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h index a568dd118d..fe0892c0fe 100644 --- a/tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h +++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/plugininterface.h @@ -41,13 +41,19 @@ #ifndef PLUGININTERFACE_H #define PLUGININTERFACE_H +#include <QtCore/QtGlobal> + struct PluginInterface { virtual ~PluginInterface() {} virtual QString pluginName() const = 0; }; QT_BEGIN_NAMESPACE -Q_DECLARE_INTERFACE(PluginInterface, "com.trolltect.autotests.plugininterface/1.0") + +#define PluginInterface_iid "org.qt-project.Qt.autotests.plugininterface" + +Q_DECLARE_INTERFACE(PluginInterface, PluginInterface_iid) + QT_END_NAMESPACE #endif // PLUGININTERFACE_H diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp index b064901a4d..8c97956a5f 100644 --- a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp @@ -46,6 +46,3 @@ QString ThePlugin::pluginName() const { return QLatin1String("Plugin ok"); } - -Q_EXPORT_PLUGIN2(theplugin, ThePlugin) - diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h index b769aa6eed..3b8f12140e 100644 --- a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h +++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.h @@ -42,11 +42,13 @@ #define THEPLUGIN_H #include <QObject> +#include <QtPlugin> #include "plugininterface.h" class ThePlugin : public QObject, public PluginInterface { Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.autotests.plugininterface" FILE "../empty.json") Q_INTERFACES(PluginInterface) public: diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index 25e1a0587c..8eccd17376 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -107,6 +107,8 @@ private slots: void customEventDispatcher(); void stressTest(); + + void quitLock(); }; enum { one_minute = 60 * 1000, five_minutes = 5 * one_minute }; @@ -1285,5 +1287,52 @@ void tst_QThread::customEventDispatcher() QVERIFY(weak_ed.isNull()); } +class Job : public QObject +{ + Q_OBJECT +public: + Job(QThread *thread, int deleteDelay, QObject *parent = 0) + : QObject(parent), quitLocker(thread), exitThreadCalled(false) + { + moveToThread(thread); + QTimer::singleShot(deleteDelay, this, SLOT(deleteLater())); + QTimer::singleShot(1000, this, SLOT(exitThread())); + } + +private slots: + void exitThread() + { + exitThreadCalled = true; + thread()->exit(1); + } + +private: + QEventLoopLocker quitLocker; +public: + bool exitThreadCalled; +}; + +void tst_QThread::quitLock() +{ + QThread thread; + + QEventLoop loop; + connect(&thread, SIGNAL(finished()), &loop, SLOT(quit())); + + Job *job; + + thread.start(); + job = new Job(&thread, 500); + QCOMPARE(job->thread(), &thread); + loop.exec(); + QVERIFY(!job->exitThreadCalled); + + thread.start(); + job = new Job(&thread, 2500); + QCOMPARE(job->thread(), &thread); + loop.exec(); + QVERIFY(job->exitThreadCalled); +} + QTEST_MAIN(tst_QThread) #include "tst_qthread.moc" diff --git a/tests/auto/corelib/thread/qthreadstorage/crashOnExit.pro b/tests/auto/corelib/thread/qthreadstorage/crashOnExit.pro deleted file mode 100644 index 68d0f1202b..0000000000 --- a/tests/auto/corelib/thread/qthreadstorage/crashOnExit.pro +++ /dev/null @@ -1,8 +0,0 @@ -SOURCES += crashOnExit.cpp -QT = core -CONFIG-=app_bundle -CONFIG+=console - -# This app is testdata for tst_qthreadstorage -target.path = $$[QT_INSTALL_TESTS]/tst_qthreadstorage -INSTALLS += target diff --git a/tests/auto/corelib/thread/qthreadstorage/crashOnExit.cpp b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashOnExit.cpp index 388c233d84..388c233d84 100644 --- a/tests/auto/corelib/thread/qthreadstorage/crashOnExit.cpp +++ b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashOnExit.cpp diff --git a/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro new file mode 100644 index 0000000000..94a0a01e94 --- /dev/null +++ b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro @@ -0,0 +1,9 @@ +SOURCES += crashOnExit.cpp +DESTDIR = ./ +QT = core +CONFIG -= app_bundle +CONFIG += console + +# This app is testdata for tst_qthreadstorage +target.path = $$[QT_INSTALL_TESTS]/tst_qthreadstorage/$$TARGET +INSTALLS += target diff --git a/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro b/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro index 0dc8d086df..2fa973d2f7 100644 --- a/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro +++ b/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs SUBDIRS = \ - tst_qthreadstorage.pro \ - crashOnExit.pro -CONFIG += parallel_test + crashonexit \ + test +CONFIG += ordered parallel_test diff --git a/tests/auto/corelib/thread/qthreadstorage/test/test.pro b/tests/auto/corelib/thread/qthreadstorage/test/test.pro new file mode 100644 index 0000000000..a7d8eb0106 --- /dev/null +++ b/tests/auto/corelib/thread/qthreadstorage/test/test.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = ../tst_qthreadstorage +CONFIG -= app_bundle +CONFIG += console +QT = core testlib +SOURCES = ../tst_qthreadstorage.cpp diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp index fff361ea2a..0529e67e0f 100644 --- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp +++ b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp @@ -46,6 +46,8 @@ #include <qthread.h> #include <qwaitcondition.h> #include <qthreadstorage.h> +#include <qdir.h> +#include <qfileinfo.h> #ifdef Q_OS_UNIX #include <pthread.h> @@ -61,6 +63,7 @@ class tst_QThreadStorage : public QObject { Q_OBJECT private slots: + void initTestCase(); void hasLocalData(); void localData(); void localData_const(); @@ -72,6 +75,9 @@ private slots: void leakInDestructor(); void resetInDestructor(); void valueBased(); + +private: + QString m_crashOnExit; }; class Pointer @@ -83,6 +89,20 @@ public: }; int Pointer::count = 0; +void tst_QThreadStorage::initTestCase() +{ + const QString crashOnExitDir = QFINDTESTDATA("crashonexit"); + QVERIFY2(!crashOnExitDir.isEmpty(), + qPrintable(QString::fromLatin1("Could not find 'crashonexit' starting from '%1'") + .arg(QDir::toNativeSeparators(QDir::currentPath())))); + m_crashOnExit = crashOnExitDir + QStringLiteral("/crashonexit"); +#ifdef Q_OS_WIN + m_crashOnExit += QStringLiteral(".exe"); +#endif + QVERIFY2(QFileInfo(m_crashOnExit).isExecutable(), + qPrintable(QDir::toNativeSeparators(m_crashOnExit) + QStringLiteral(" does not exist or is not executable."))); +} + void tst_QThreadStorage::hasLocalData() { QThreadStorage<Pointer *> pointers; @@ -285,18 +305,32 @@ void tst_QThreadStorage::ensureCleanupOrder() QVERIFY(First::order < Second::order); } -void tst_QThreadStorage::crashOnExit() +static inline bool runCrashOnExit(const QString &binary, QString *errorMessage) { + const int timeout = 60000; QProcess process; - // crashOnExit is always expected to be in the same directory - // as this test binary -#ifdef Q_OS_MAC - process.start(QCoreApplication::applicationDirPath() + "/../../../crashOnExit"); -#else - process.start(QCoreApplication::applicationDirPath() + "/crashOnExit"); -#endif - QVERIFY(process.waitForFinished()); - QVERIFY(process.exitStatus() != QProcess::CrashExit); + process.start(binary); + if (!process.waitForStarted()) { + *errorMessage = QString::fromLatin1("Could not start '%1': %2").arg(binary, process.errorString()); + return false; + } + if (!process.waitForFinished(timeout)) { + process.kill(); + *errorMessage = QString::fromLatin1("Timeout (%1ms) waiting for %2.").arg(timeout).arg(binary); + return false; + } + if (process.exitStatus() != QProcess::NormalExit) { + *errorMessage = binary + QStringLiteral(" crashed."); + return false; + } + return true; +} + +void tst_QThreadStorage::crashOnExit() +{ + QString errorMessage; + QVERIFY2(runCrashOnExit(m_crashOnExit, &errorMessage), + qPrintable(errorMessage)); } // S stands for thread Safe. diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.pro b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.pro deleted file mode 100644 index 15ced107d3..0000000000 --- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qthreadstorage -QT = core testlib -SOURCES = tst_qthreadstorage.cpp 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 } } |