diff options
Diffstat (limited to 'tests/auto/corelib')
79 files changed, 4046 insertions, 628 deletions
diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp index 7daed397d5..4144e82a29 100644 --- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp @@ -172,75 +172,72 @@ void tst_QTextCodec::fromUnicode_data() QTest::addColumn<QString>("codecName"); QTest::addColumn<bool>("eightBit"); - QTest::newRow("data1") << "ISO-8859-1" << true; - QTest::newRow("data2") << "ISO-8859-2" << true; - QTest::newRow("data3") << "ISO-8859-3" << true; - QTest::newRow("data4") << "ISO-8859-4" << true; - QTest::newRow("data5") << "ISO-8859-5" << true; - QTest::newRow("data6") << "ISO-8859-6" << true; - QTest::newRow("data7") << "ISO-8859-7" << true; - QTest::newRow("data8") << "ISO-8859-8" << true; - QTest::newRow("data9") << "ISO-8859-9" << true; - QTest::newRow("data10") << "ISO-8859-10" << true; - QTest::newRow("data13") << "ISO-8859-13" << true; - QTest::newRow("data14") << "ISO-8859-14" << true; - QTest::newRow("data15") << "ISO-8859-15" << true; - QTest::newRow("data16") << "ISO-8859-16" << true; - - QTest::newRow("data18") << "IBM850" << true; - QTest::newRow("data19") << "IBM874" << true; - QTest::newRow("data20") << "IBM866" << true; - - QTest::newRow("data21") << "windows-1250" << true; - QTest::newRow("data22") << "windows-1251" << true; - QTest::newRow("data23") << "windows-1252" << true; - QTest::newRow("data24") << "windows-1253" << true; - QTest::newRow("data25") << "windows-1254" << true; - QTest::newRow("data26") << "windows-1255" << true; - QTest::newRow("data27") << "windows-1256" << true; - QTest::newRow("data28") << "windows-1257" << true; - QTest::newRow("data28") << "windows-1258" << true; - - QTest::newRow("data29") << "Apple Roman" << true; - QTest::newRow("data29") << "WINSAMI2" << true; - QTest::newRow("data30") << "TIS-620" << true; - QTest::newRow("data31") << "roman8" << true; - - QTest::newRow("data32") << "SJIS" << false; - QTest::newRow("data33") << "EUC-KR" << false; + QTest::newRow("ISO-8859-1") << "ISO-8859-1" << true; + QTest::newRow("ISO-8859-2") << "ISO-8859-2" << true; + QTest::newRow("ISO-8859-3") << "ISO-8859-3" << true; + QTest::newRow("ISO-8859-4") << "ISO-8859-4" << true; + QTest::newRow("ISO-8859-5") << "ISO-8859-5" << true; + QTest::newRow("ISO-8859-6") << "ISO-8859-6" << true; + QTest::newRow("ISO-8859-7") << "ISO-8859-7" << true; + QTest::newRow("ISO-8859-8") << "ISO-8859-8" << true; + QTest::newRow("ISO-8859-9") << "ISO-8859-9" << true; + QTest::newRow("ISO-8859-10") << "ISO-8859-10" << true; + QTest::newRow("ISO-8859-13") << "ISO-8859-13" << true; + QTest::newRow("ISO-8859-14") << "ISO-8859-14" << true; + QTest::newRow("ISO-8859-15") << "ISO-8859-15" << true; + QTest::newRow("ISO-8859-16") << "ISO-8859-16" << true; + + QTest::newRow("IBM850") << "IBM850" << true; + QTest::newRow("IBM874") << "IBM874" << true; + QTest::newRow("IBM866") << "IBM866" << true; + + QTest::newRow("windows-1250") << "windows-1250" << true; + QTest::newRow("windows-1251") << "windows-1251" << true; + QTest::newRow("windows-1252") << "windows-1252" << true; + QTest::newRow("windows-1253") << "windows-1253" << true; + QTest::newRow("windows-1254") << "windows-1254" << true; + QTest::newRow("windows-1255") << "windows-1255" << true; + QTest::newRow("windows-1256") << "windows-1256" << true; + QTest::newRow("windows-1257") << "windows-1257" << true; + QTest::newRow("windows-1258") << "windows-1258" << true; + + QTest::newRow("Apple Roman") << "Apple Roman" << true; + QTest::newRow("WINSAMI2") << "WINSAMI2" << true; + QTest::newRow("TIS-620") << "TIS-620" << true; + QTest::newRow("roman8") << "roman8" << true; + QTest::newRow("SJIS") << "SJIS" << false; // all codecs from documentation - QTest::newRow("doc2") << "Big5" << false; - QTest::newRow("doc3") << "Big5-HKSCS" << false; - QTest::newRow("doc4") << "CP949" << false; - QTest::newRow("doc5") << "EUC-JP" << false; - QTest::newRow("doc6") << "EUC-KR" << false; - //QTest::newRow("doc7") << "GB18030-0" << false; // only GB18030 works - QTest::newRow("doc7-bis") << "GB18030" << false; - QTest::newRow("doc8") << "IBM 850" << false; - QTest::newRow("doc9") << "IBM 866" << false; - QTest::newRow("doc10") << "IBM 874" << false; - QTest::newRow("doc11") << "ISO 2022-JP" << false; + QTest::newRow("Big5") << "Big5" << false; + QTest::newRow("Big5-HKSCS") << "Big5-HKSCS" << false; + QTest::newRow("CP949") << "CP949" << false; + QTest::newRow("EUC-JP") << "EUC-JP" << false; + QTest::newRow("EUC-KR") << "EUC-KR" << false; + //QTest::newRow("GB18030-0") << "GB18030-0" << false; // only GB18030 works + QTest::newRow("GB18030") << "GB18030" << false; + QTest::newRow("IBM 850") << "IBM 850" << false; + QTest::newRow("IBM 866") << "IBM 866" << false; + QTest::newRow("IBM 874") << "IBM 874" << false; + QTest::newRow("ISO 2022-JP") << "ISO 2022-JP" << false; //ISO 8859-1 to 10 and ISO 8859-13 to 16 tested previously // Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml tested in Iscii test - //QTest::newRow("doc12") << "JIS X 0201" << false; //actually not there - //QTest::newRow("doc13") << "JIS X 0208" << false; // actually not there - QTest::newRow("doc14") << "KOI8-R" << false; - QTest::newRow("doc15") << "KOI8-U" << false; - //QTest::newRow("doc16") << "MuleLao-1" << false; //only on x11 - QTest::newRow("doc17") << "ROMAN8" << false; - QTest::newRow("doc18") << "Shift-JIS" << false; - QTest::newRow("doc19") << "TIS-620" << false; - QTest::newRow("doc20") << "TSCII" << false; - QTest::newRow("doc21") << "UTF-8" << false; - QTest::newRow("doc22") << "UTF-16" << false; - QTest::newRow("doc23") << "UTF-16BE" << false; - QTest::newRow("doc24") << "UTF-16LE" << false; - QTest::newRow("doc25") << "UTF-32" << false; - QTest::newRow("doc26") << "UTF-32BE" << false; - QTest::newRow("doc27") << "UTF-32LE" << false; + //QTest::newRow("JIS X 0201") << "JIS X 0201" << false; // actually not there + //QTest::newRow("JIS X 0208") << "JIS X 0208" << false; // actually not there + QTest::newRow("KOI8-R") << "KOI8-R" << false; + QTest::newRow("KOI8-U") << "KOI8-U" << false; + //QTest::newRow("MuleLao-1") << "MuleLao-1" << false; //only on x11 + QTest::newRow("ROMAN8") << "ROMAN8" << false; + QTest::newRow("Shift-JIS") << "Shift-JIS" << false; + QTest::newRow("TIS-620") << "TIS-620" << false; + QTest::newRow("TSCII") << "TSCII" << false; + QTest::newRow("UTF-8") << "UTF-8" << false; + QTest::newRow("UTF-16") << "UTF-16" << false; + QTest::newRow("UTF-16BE") << "UTF-16BE" << false; + QTest::newRow("UTF-16LE") << "UTF-16LE" << false; + QTest::newRow("UTF-32") << "UTF-32" << false; + QTest::newRow("UTF-32BE") << "UTF-32BE" << false; + QTest::newRow("UTF-32LE") << "UTF-32LE" << false; //Windows-1250 to 1258 tested previously - QTest::newRow("doc3") << "WINSAMI2" << false; } void tst_QTextCodec::fromUnicode() @@ -1222,7 +1219,7 @@ void tst_QTextCodec::utf8Codec_data() utf8.clear(); utf8 += char(0xff); str = fromInvalidUtf8Sequence(utf8); - QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1; + QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.2") << utf8 << str << -1; // 3.5.2 utf8.clear(); @@ -1230,7 +1227,7 @@ void tst_QTextCodec::utf8Codec_data() utf8 += char(0xfe); utf8 += char(0xff); str = fromInvalidUtf8Sequence(utf8); - QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.1") << utf8 << str << -1; + QTest::newRow("http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html 3.5.2-1") << utf8 << str << -1; // 4.1.1 utf8.clear(); diff --git a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp index 69b91683d4..e07b7cb239 100644 --- a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp +++ b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp @@ -239,7 +239,7 @@ void tst_Utf8::invalidUtf8_data() QTest::newRow("non-unicode-3") << QByteArray("\xFC\x84\x80\x80\x80\x80"); // 0x7fffffff: 1 11 1111 11 1111 11 1111 11 1111 11 1111 // encoding: xxxx:xxz0 xz00:0100 xz00:0000 xz00:0000 xz00:0001 xz00:0001 - QTest::newRow("non-unicode-3") << QByteArray("\xFD\xBF\xBF\xBF\xBF\xBF"); + QTest::newRow("non-unicode-4") << QByteArray("\xFD\xBF\xBF\xBF\xBF\xBF"); // As seen above, 0xFE and 0xFF never appear: QTest::newRow("fe") << QByteArray("\xFE"); @@ -269,9 +269,9 @@ void tst_Utf8::invalidUtf8_data() // overlong 4: xxxx:z000 xz00:0000 xz00:0010 xz00:0000 QTest::newRow("overlong-2-4") << QByteArray("\xF0\x80\x82\x80"); // overlong 5: xxxx:xz00 xz00:0000 xz00:0000 xz00:0010 xz00:0000 - QTest::newRow("overlong-2-4") << QByteArray("\xF8\x80\x80\x82\x80"); + QTest::newRow("overlong-2-5") << QByteArray("\xF8\x80\x80\x82\x80"); // overlong 6: xxxx:xxz0 xz00:0000 xz00:0000 xz00:0000 xz00:0010 xz00:0000 - QTest::newRow("overlong-2-4") << QByteArray("\xFC\x80\x80\x80\x82\x80"); + QTest::newRow("overlong-2-6") << QByteArray("\xFC\x80\x80\x80\x82\x80"); // U+0800: 10 0000 00 0000 // proper encoding: xxxz:0000 xz10:0000 xz00:0000 diff --git a/tests/auto/corelib/corelib.pro b/tests/auto/corelib/corelib.pro index 4f284ac21e..a85a385f80 100644 --- a/tests/auto/corelib/corelib.pro +++ b/tests/auto/corelib/corelib.pro @@ -7,6 +7,7 @@ SUBDIRS=\ itemmodels \ json \ kernel \ + mimetypes \ plugin \ statemachine \ thread \ diff --git a/tests/auto/corelib/global/global.pro b/tests/auto/corelib/global/global.pro index a6c638f530..d4293a896c 100644 --- a/tests/auto/corelib/global/global.pro +++ b/tests/auto/corelib/global/global.pro @@ -6,4 +6,4 @@ SUBDIRS=\ qglobal \ qnumeric \ qrand \ - qmessagehandler + qlogging diff --git a/tests/auto/corelib/global/qlogging/app/app.pro b/tests/auto/corelib/global/qlogging/app/app.pro new file mode 100644 index 0000000000..1088d08a58 --- /dev/null +++ b/tests/auto/corelib/global/qlogging/app/app.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = app +QT = core + +DESTDIR = ./ + +CONFIG -= app_bundle +CONFIG += console + +SOURCES += main.cpp diff --git a/tests/auto/corelib/global/qlogging/app/main.cpp b/tests/auto/corelib/global/qlogging/app/main.cpp new file mode 100644 index 0000000000..dfa52315c7 --- /dev/null +++ b/tests/auto/corelib/global/qlogging/app/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QCoreApplication> + +struct T { + T() { qDebug("static constructor"); } + ~T() { qDebug("static destructor"); } +} t; + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + app.setApplicationName("tst_qlogging"); + + qDebug("qDebug"); + qWarning("qWarning"); + qCritical("qCritical"); + return 0; +} diff --git a/tests/auto/corelib/global/qlogging/qlogging.pro b/tests/auto/corelib/global/qlogging/qlogging.pro new file mode 100644 index 0000000000..1d5e7681df --- /dev/null +++ b/tests/auto/corelib/global/qlogging/qlogging.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs +CONFIG += ordered + +SUBDIRS += \ + app \ + tst_qlogging.pro diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp new file mode 100644 index 0000000000..aaec46fe64 --- /dev/null +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -0,0 +1,674 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qdebug.h> +#include <qglobal.h> +#include <QtCore/QProcess> +#include <QtTest/QtTest> + +class tst_qmessagehandler : public QObject +{ + Q_OBJECT +public slots: + void initTestCase(); + +private slots: + void cleanup(); + + void defaultHandler(); + void installMessageHandler(); + void installMsgHandler(); + void installBothHandler(); + + void cleanupFuncinfo_data(); + void cleanupFuncinfo(); + + void qMessagePattern(); + +private: + QString m_appDir; +}; + +static QtMsgType s_type; +const char *s_file; +int s_line; +const char *s_function; +static QString s_message; + +void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const char *msg) +{ + s_type = type; + s_file = context.file; + s_line = context.line; + s_function = context.function; + s_message = QString::fromLocal8Bit(msg); +} + +void customMsgHandler(QtMsgType type, const char *msg) +{ + s_type = type; + s_file = 0; + s_line = 0; + s_function = 0; + s_message = QString::fromLocal8Bit(msg); +} + +void tst_qmessagehandler::initTestCase() +{ + m_appDir = QFINDTESTDATA("app"); + QVERIFY2(!m_appDir.isEmpty(), qPrintable( + QString::fromLatin1("Couldn't find helper app dir starting from %1.").arg(QDir::currentPath()))); +} + +void tst_qmessagehandler::cleanup() +{ + qInstallMsgHandler(0); + qInstallMessageHandler(0); + s_type = QtFatalMsg; + s_file = 0; + s_line = 0; + s_function = 0; +} + +void tst_qmessagehandler::defaultHandler() +{ + // check that the default works + QTest::ignoreMessage(QtDebugMsg, "defaultHandler"); + qDebug("defaultHandler"); +} + +void tst_qmessagehandler::installMessageHandler() +{ + QMessageHandler oldHandler = qInstallMessageHandler(customMessageHandler); + + qDebug("installMessageHandler"); int line = __LINE__; + + QCOMPARE(s_type, QtDebugMsg); + QCOMPARE(s_message, QString::fromLocal8Bit("installMessageHandler")); + QCOMPARE(s_file, __FILE__); + QCOMPARE(s_function, Q_FUNC_INFO); + QCOMPARE(s_line, line); + + QMessageHandler myHandler = qInstallMessageHandler(oldHandler); + QCOMPARE((void*)myHandler, (void*)customMessageHandler); +} + +void tst_qmessagehandler::installMsgHandler() +{ + QtMsgHandler oldHandler = qInstallMsgHandler(customMsgHandler); + + qDebug("installMsgHandler"); + + QCOMPARE(s_type, QtDebugMsg); + QCOMPARE(s_message, QString::fromLocal8Bit("installMsgHandler")); + QCOMPARE(s_file, (const char*)0); + QCOMPARE(s_function, (const char*)0); + QCOMPARE(s_line, 0); + + QtMsgHandler myHandler = qInstallMsgHandler(oldHandler); + QCOMPARE((void*)myHandler, (void*)customMsgHandler); +} + +void tst_qmessagehandler::installBothHandler() +{ + qInstallMessageHandler(customMessageHandler); + qInstallMsgHandler(customMsgHandler); + + qDebug("installBothHandler"); int line = __LINE__; + + QCOMPARE(s_type, QtDebugMsg); + QCOMPARE(s_message, QString::fromLocal8Bit("installBothHandler")); + QCOMPARE(s_file, __FILE__); + QCOMPARE(s_function, Q_FUNC_INFO); + QCOMPARE(s_line, line); +} + +# define ADD(x) QTest::newRow(x) << Q_FUNC_INFO << x; + +class TestClass1 +{ +public: + enum Something { foo }; + char c; + + void func_void() { ADD("TestClass1::func_void"); } + int func_int() { ADD("TestClass1::func_int"); return 0; } + unsigned func_unsigned() { ADD("TestClass1::func_unsigned"); return 0; } + long func_long() { ADD("TestClass1::func_long"); return 0; } + long long func_ll() { ADD("TestClass1::func_ll"); return 0; } + unsigned long long func_ull() { ADD("TestClass1::func_ull"); return 0; } + char func_char() { ADD("TestClass1::func_char"); return 0; } + signed char func_schar() { ADD("TestClass1::func_schar"); return 0; } + unsigned char func_uchar() { ADD("TestClass1::func_uchar"); return 0; } + char &func_Rchar() { ADD("TestClass1::func_Rchar"); return c; } + char *func_Pchar() { ADD("TestClass1::func_Pchar"); return 0; } + const char *func_KPchar() { ADD("TestClass1::func_KPchar"); return 0; } + const volatile char *func_VKPchar() { ADD("TestClass1::func_VKPchar"); return 0; } + const volatile unsigned long long * const volatile func_KVPKVull() { ADD("TestClass1::func_KVPKVull"); return 0; } + const void * const volatile *func_KPKVvoid() { ADD("TestClass1::func_KPKVvoid"); return 0; } + + QList<int> func_ai() { ADD("TestClass1::func_ai"); return QList<int>(); } + QList<unsigned long long const volatile*> func_aptr() { ADD("TestClass1::func_aptr"); return QList<unsigned long long const volatile*>(); } + + QList<Something> func_aenum() { ADD("TestClass1::func_aenum"); return QList<Something>(); } + QList<QList<const void *> > func_aaptr() { ADD("TestClass1::func_aaptr"); return QList<QList<const void *> >(); } + + QMap<int, Something> func_ienummap() { ADD("TestClass1::func_ienummap"); return QMap<int, Something>(); } + + template<typename T> + T* func_template1() { ADD("TestClass1::func_template1"); return 0; } + template<Something val> + long func_template2() { ADD("TestClass1::func_template2"); return long(val); } + + typedef unsigned long long * ( *fptr)(); + typedef unsigned long long * (TestClass1::* pmf)(); + typedef fptr (TestClass1::* uglypmf)(); + fptr func_fptr() { ADD("TestClass1::func_fptr"); return 0; } + pmf func_pmf() { ADD("TestClass1::func_pmf"); return 0; } + uglypmf func_uglypmf(uglypmf = 0) { ADD("TestClass1::func_uglypmf"); return 0; } + QMap<QString, uglypmf> func_uglypmf2() { ADD("TestClass1::func_uglypmf2"); return QMap<QString, uglypmf>(); } + + void operator()() { ADD("TestClass1::operator()"); } + int operator<(int) { ADD("TestClass1::operator<"); return 0; } + int operator>(int) { ADD("TestClass1::operator>"); return 0; } + int operator<=(int) { ADD("TestClass1::operator<="); return 0; } + int operator>=(int) { ADD("TestClass1::operator>="); return 0; } + int operator=(int) { ADD("TestClass1::operator="); return 0; } + int operator+(int) { ADD("TestClass1::operator+"); return 0; } + int operator-(int) { ADD("TestClass1::operator-"); return 0; } + int operator*(int) { ADD("TestClass1::operator*"); return 0; } + int operator/(int) { ADD("TestClass1::operator/"); return 0; } + int operator%(int) { ADD("TestClass1::operator%"); return 0; } + int x; + int &operator++() { ADD("TestClass1::operator++"); return x; } + int operator++(int) { ADD("TestClass1::operator++"); return 0; } + int &operator--() { ADD("TestClass1::operator--"); return x; } + int operator--(int) { ADD("TestClass1::operator--"); return 0; } + +public: + TestClass1() + { + // instantiate + func_void(); + func_int(); + func_unsigned(); + func_long(); + func_ll(); + func_ull(); + func_char(); + func_schar(); + func_uchar(); + func_Rchar(); + func_Pchar(); + func_KPchar(); + func_VKPchar(); + func_KVPKVull(); + func_KPKVvoid(); + func_ai(); + func_aptr(); + func_aenum(); + func_aaptr(); + func_ienummap(); + func_template1<TestClass1>(); + func_template2<foo>(); + func_fptr(); + func_pmf(); + func_uglypmf(); + func_uglypmf2(); + operator()(); + operator<(0); + operator>(0); + operator<=(0); + operator>=(0); + operator=(0); + operator+(0); + operator-(0); + operator*(0); + operator/(0); + operator%(0); + operator++(); + operator++(0); + operator--(); + operator--(0); + } +}; + +template<typename T> class TestClass2 +{ + long func_long() { ADD("TestClass2::func_long"); return 0; } + template<typename S> + T* func_template1() { ADD("TestClass2::func_template1"); return 0; } + template<TestClass1::Something val> + long func_template2() { ADD("TestClass2::func_template2"); return long(val); } +public: + TestClass2() + { + func_long(); + func_template1<TestClass2>(); + func_template2<TestClass1::foo>(); + } +}; + +template<typename T, TestClass1::Something v> class TestClass3 +{ + long func_long() { ADD("TestClass3::func_long"); return 0; } + template<typename S> + S* func_template1() { ADD("TestClass3::func_template1"); return 0; } + template<TestClass1::Something val> + long func_template2() { ADD("TestClass3::func_template2"); return long(val); } +public: + struct Foo { TestClass3 foo; }; + TestClass3() + { + func_long(); + func_template1<TestClass2<T> >(); + func_template2<TestClass1::foo>(); + } +}; + +class TestClass4 +{ + TestClass1 c1; + + TestClass2<std::map<long, const void *> > func2() + { ADD("TestClass4::func2"); return TestClass2<std::map<long, const void *> >(); } + TestClass3<std::map<std::list<int>, const void *>, TestClass1::foo>::Foo func3() + { ADD("TestClass4::func3"); return TestClass3<std::map<std::list<int>, const void *>, TestClass1::foo>::Foo(); } +public: + TestClass4() + { + func2(); + func3(); + ADD("TestClass4::TestClass4"); + } + ~TestClass4() + { + ADD("TestClass4::~TestClass4"); + } +}; + + +void tst_qmessagehandler::cleanupFuncinfo_data() +{ +#ifndef QT_BUILD_INTERNAL + QSKIP("Requires -developer-build"); +#endif + QTest::addColumn<QString>("funcinfo"); + QTest::addColumn<QString>("expected"); + + TestClass4 c4; + + QTest::newRow("msvc_01") + << "void __thiscall TestClass1::func_void(void)" + << "TestClass1::func_void"; + QTest::newRow("gcc_01") + << "void TestClass1::func_void()" + << "TestClass1::func_void"; + + QTest::newRow("msvc_02") + << "int __thiscall TestClass1::func_int(void)" + << "TestClass1::func_int"; + QTest::newRow("gcc_02") + << "int TestClass1::func_int()" + << "TestClass1::func_int"; + + QTest::newRow("msvc_03") + << "unsigned int __thiscall TestClass1::func_unsigned(void)" + << "TestClass1::func_unsigned"; + QTest::newRow("gcc_03") + << "unsigned int TestClass1::func_unsigned()" + << "TestClass1::func_unsigned"; + + QTest::newRow("msvc_04") + << "long __thiscall TestClass1::func_long(void)" + << "TestClass1::func_long"; + QTest::newRow("gcc_04") + << "long int TestClass1::func_long()" + << "TestClass1::func_long"; + + QTest::newRow("msvc_05") + << "__int64 __thiscall TestClass1::func_ll(void)" + << "TestClass1::func_ll"; + QTest::newRow("gcc_05") + << "long long int TestClass1::func_ll()" + << "TestClass1::func_ll"; + + QTest::newRow("msvc_06") + << "unsigned __int64 __thiscall TestClass1::func_ull(void)" + << "TestClass1::func_ull"; + QTest::newRow("gcc_06") + << "long long unsigned int TestClass1::func_ull()" + << "TestClass1::func_ull"; + + QTest::newRow("msvc_07") + << "char __thiscall TestClass1::func_char(void)" + << "TestClass1::func_char"; + QTest::newRow("gcc_07") + << "char TestClass1::func_char()" + << "TestClass1::func_char"; + + QTest::newRow("msvc_08") + << "signed char __thiscall TestClass1::func_schar(void)" + << "TestClass1::func_schar"; + QTest::newRow("gcc_08") + << "signed char TestClass1::func_schar()" + << "TestClass1::func_schar"; + + QTest::newRow("msvc_09") + << "unsigned char __thiscall TestClass1::func_uchar(void)" + << "TestClass1::func_uchar"; + QTest::newRow("gcc_09") + << "unsigned char TestClass1::func_uchar()" + << "TestClass1::func_uchar"; + + QTest::newRow("msvc_09a") + << "char &__thiscall TestClass1::func_Rchar(void)" + << "TestClass1::func_Rchar"; + QTest::newRow("gcc_09a") + << "char& TestClass1::func_Rchar()" + << "TestClass1::func_Rchar"; + QTest::newRow("clang_09a") + << "char &TestClass1::func_Rchar()" + << "TestClass1::func_Rchar"; + + QTest::newRow("msvc_10") + << "char *__thiscall TestClass1::func_Pchar(void)" + << "TestClass1::func_Pchar"; + QTest::newRow("gcc_10") + << "char* TestClass1::func_Pchar()" + << "TestClass1::func_Pchar"; + QTest::newRow("clang_10") + << "char *TestClass1::func_Pchar()" + << "TestClass1::func_Pchar"; + + QTest::newRow("msvc_11") + << "const char *__thiscall TestClass1::func_KPchar(void)" + << "TestClass1::func_KPchar"; + QTest::newRow("gcc_11") + << "const char* TestClass1::func_KPchar()" + << "TestClass1::func_KPchar"; + + QTest::newRow("msvc_12") + << "volatile const char *__thiscall TestClass1::func_VKPchar(void)" + << "TestClass1::func_VKPchar"; + QTest::newRow("gcc_12") + << "const volatile char* TestClass1::func_VKPchar()" + << "TestClass1::func_VKPchar"; + + QTest::newRow("msvc_13") + << "volatile const unsigned __int64 *volatile const __thiscall TestClass1::func_KVPKVull(void)" + << "TestClass1::func_KVPKVull"; + QTest::newRow("gcc_13") + << "const volatile long long unsigned int* const volatile TestClass1::func_KVPKVull()" + << "TestClass1::func_KVPKVull"; + + QTest::newRow("msvc_14") + << "const void *volatile const *__thiscall TestClass1::func_KPKVvoid(void)" + << "TestClass1::func_KPKVvoid"; + QTest::newRow("gcc_14") + << "const void* const volatile* TestClass1::func_KPKVvoid()" + << "TestClass1::func_KPKVvoid"; + + QTest::newRow("msvc_15") + << "class QList<int> __thiscall TestClass1::func_ai(void)" + << "TestClass1::func_ai"; + QTest::newRow("gcc_15") + << "QList<int> TestClass1::func_ai()" + << "TestClass1::func_ai"; + + QTest::newRow("msvc_16") + << "class QList<unsigned __int64 const volatile *> __thiscall TestClass1::func_aptr(void)" + << "TestClass1::func_aptr"; + QTest::newRow("gcc_16") + << "QList<const volatile long long unsigned int*> TestClass1::func_aptr()" + << "TestClass1::func_aptr"; + + QTest::newRow("msvc_17") + << "class QList<enum TestClass1::Something> __thiscall TestClass1::func_aenum(void)" + << "TestClass1::func_aenum"; + QTest::newRow("gcc_17") + << "QList<TestClass1::Something> TestClass1::func_aenum()" + << "TestClass1::func_aenum"; + + QTest::newRow("msvc_18") + << "class QList<class QList<void const *> > __thiscall TestClass1::func_aaptr(void)" + << "TestClass1::func_aaptr"; + QTest::newRow("gcc_18") + << "QList<QList<const void*> > TestClass1::func_aaptr()" + << "TestClass1::func_aaptr"; + + QTest::newRow("msvc_19") + << "class QMap<int,enum TestClass1::Something> __thiscall TestClass1::func_ienummap(void)" + << "TestClass1::func_ienummap"; + QTest::newRow("gcc_19") + << "QMap<int, TestClass1::Something> TestClass1::func_ienummap()" + << "TestClass1::func_ienummap"; + + QTest::newRow("msvc_20") + << "class TestClass1 *__thiscall TestClass1::func_template1<class TestClass1>(void)" + << "TestClass1::func_template1"; + QTest::newRow("gcc_20") + << "T* TestClass1::func_template1() [with T = TestClass1]" + << "TestClass1::func_template1"; + + QTest::newRow("msvc_21") + << "long __thiscall TestClass1::func_template2<foo>(void)" + << "TestClass1::func_template2"; + QTest::newRow("gcc_21") + << "long int TestClass1::func_template2() [with TestClass1::Something val = foo]" + << "TestClass1::func_template2"; + + QTest::newRow("msvc_22") + << "unsigned __int64 *(__cdecl *__thiscall TestClass1::func_fptr(void))(void)" + << "TestClass1::func_fptr"; + QTest::newRow("gcc_22") + << "long long unsigned int* (* TestClass1::func_fptr())()" + << "TestClass1::func_fptr"; + + QTest::newRow("msvc_23") + << "unsigned __int64 *(__thiscall TestClass1::* __thiscall TestClass1::func_pmf(void))(void)" + << "TestClass1::func_pmf"; + QTest::newRow("gcc_23") + << "long long unsigned int* (TestClass1::* TestClass1::func_pmf())()" + << "TestClass1::func_pmf"; + + QTest::newRow("msvc_24") + << "unsigned __int64 *(__cdecl *(__thiscall TestClass1::* __thiscall TestClass1::func_uglypmf(unsigned __int64 *(__cdecl *(__thiscall TestClass1::* )(void))(void)))(void))(void)" + << "TestClass1::func_uglypmf"; + QTest::newRow("gcc_24") + << "long long unsigned int* (* (TestClass1::* TestClass1::func_uglypmf(long long unsigned int* (* (TestClass1::*)())()))())()" + << "TestClass1::func_uglypmf"; + + QTest::newRow("msvc_25") + << "class QMap<class QString,unsigned __int64 * (__cdecl*(__thiscall TestClass1::*)(void))(void)> __thiscall TestClass1::func_uglypmf2(void)" + << "TestClass1::func_uglypmf2"; + QTest::newRow("gcc_25") + << "QMap<QString, long long unsigned int* (* (TestClass1::*)())()> TestClass1::func_uglypmf2()" + << "TestClass1::func_uglypmf2"; + + QTest::newRow("msvc_26") + << "class TestClass2<class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > > __thiscall TestClass4::func2(void)" + << "TestClass4::func2"; + QTest::newRow("gcc_26") + << "TestClass2<std::map<long int, const void*, std::less<long int>, std::allocator<std::pair<const long int, const void*> > > > TestClass4::func2()" + << "TestClass4::func2"; + + QTest::newRow("msvc_27") + << "long __thiscall TestClass2<class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > >::func_long(void)" + << "TestClass2::func_long"; + QTest::newRow("gcc_27") + << "long int TestClass2<T>::func_long() [with T = std::map<long int, const void*, std::less<long int>, std::allocator<std::pair<const long int, const void*> > >]" + << "TestClass2::func_long"; + + QTest::newRow("msvc_28") + << "class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > *__thiscall TestClass2<class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > >::func_template1<class TestClass2<class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > >>(void)" + << "TestClass2::func_template1"; + QTest::newRow("gcc_21") + << "T* TestClass2<T>::func_template1() [with S = TestClass2<std::map<long int, const void*, std::less<long int>, std::allocator<std::pair<const long int, const void*> > > >, T = std::map<long int, const void*, std::less<long int>, std::allocator<std::pair<const long int, const void*> > >]" + << "TestClass2::func_template1"; + + QTest::newRow("msvc_29") + << "long __thiscall TestClass2<class std::map<long,void const *,struct std::less<long>,class std::allocator<struct std::pair<long const ,void const *> > > >::func_template2<foo>(void)" + << "TestClass2::func_template2"; + QTest::newRow("gcc_29") + << "long int TestClass2<T>::func_template2() [with TestClass1::Something val = foo, T = std::map<long int, const void*, std::less<long int>, std::allocator<std::pair<const long int, const void*> > >]" + << "TestClass2::func_template2"; + + QTest::newRow("msvc_30") + << "struct TestClass3<class std::map<class std::list<int,class std::allocator<int> >,void const *,struct std::less<class std::list<int,class std::allocator<int> > >,class std::allocator<struct std::pair<class std::list<int,class std::allocator<int> > const ,void const *> > >,0>::Foo __thiscall TestClass4::func3(void)" + << "TestClass4::func3"; + QTest::newRow("gcc_30") + << "TestClass3<std::map<std::list<int, std::allocator<int> >, const void*, std::less<std::list<int, std::allocator<int> > >, std::allocator<std::pair<const std::list<int, std::allocator<int> >, const void*> > >, foo>::Foo TestClass4::func3()" + << "TestClass4::func3"; + + QTest::newRow("msvc_31") + << "long __thiscall TestClass3<class std::map<class std::list<int,class std::allocator<int> >,void const *,struct std::less<class std::list<int,class std::allocator<int> > >,class std::allocator<struct std::pair<class std::list<int,class std::allocator<int> > const ,void const *> > >,0>::func_long(void)" + << "TestClass3::func_long"; + QTest::newRow("gcc_31") + << "long int TestClass3<T, v>::func_long() [with T = std::map<std::list<int, std::allocator<int> >, const void*, std::less<std::list<int, std::allocator<int> > >, std::allocator<std::pair<const std::list<int, std::allocator<int> >, const void*> > >, TestClass1::Something v = foo]" + << "TestClass3::func_long"; + + QTest::newRow("msvc_32") + << "class TestClass2<class std::map<class std::list<int,class std::allocator<int> >,void const *,struct std::less<class std::list<int,class std::allocator<int> > >,class std::allocator<struct std::pair<class std::list<int,class std::allocator<int> > const ,void const *> > > > *__thiscall TestClass3<class std::map<class std::list<int,class std::allocator<int> >,void const *,struct std::less<class std::list<int,class std::allocator<int> > >,class std::allocator<struct std::pair<class std::list<int,class std::allocator<int> > const ,void const *> > >,0>::func_template1<class TestClass2<class std::map<class std::list<int,class std::allocator<int> >,void const *,struct std::less<class std::list<int,class std::allocator<int> > >,class std::allocator<struct std::pair<class std::list<int,class std::allocator<int> > const ,void const *> > > >>(void)" + << "TestClass3::func_template1"; + QTest::newRow("gcc_32") + << "S* TestClass3<T, v>::func_template1() [with S = TestClass2<std::map<std::list<int, std::allocator<int> >, const void*, std::less<std::list<int, std::allocator<int> > >, std::allocator<std::pair<const std::list<int, std::allocator<int> >, const void*> > > >, T = std::map<std::list<int, std::allocator<int> >, const void*, std::less<std::list<int, std::allocator<int> > >, std::allocator<std::pair<const std::list<int, std::allocator<int> >, const void*> > >, TestClass1::Something v = foo]" + << "TestClass3::func_template1"; + + QTest::newRow("msvc_33") + << "long __thiscall TestClass3<class std::map<class std::list<int,class std::allocator<int> >,void const *,struct std::less<class std::list<int,class std::allocator<int> > >,class std::allocator<struct std::pair<class std::list<int,class std::allocator<int> > const ,void const *> > >,0>::func_template2<foo>(void)" + << "TestClass3::func_template2"; + QTest::newRow("gcc_33") + << "long int TestClass3<T, v>::func_template2() [with TestClass1::Something val = foo, T = std::map<std::list<int, std::allocator<int> >, const void*, std::less<std::list<int, std::allocator<int> > >, std::allocator<std::pair<const std::list<int, std::allocator<int> >, const void*> > >, TestClass1::Something v = foo]" + << "TestClass3::func_template2"; + + QTest::newRow("msvc_34") + << "__thiscall TestClass4::TestClass4(void)" + << "TestClass4::TestClass4"; + QTest::newRow("gcc_34") + << "TestClass4::TestClass4()" + << "TestClass4::TestClass4"; + + QTest::newRow("msvc_35") + << "__thiscall TestClass4::~TestClass4(void)" + << "TestClass4::~TestClass4"; + QTest::newRow("gcc_35") + << "TestClass4::~TestClass4()" + << "TestClass4::~TestClass4"; + + QTest::newRow("gcc_36") + << "void TestClass1::operator()()" + << "TestClass1::operator()"; + + QTest::newRow("gcc_37") + << "long int TestClass1::func_template2() [with TestClass1::Something val = (TestClass1::Something)0u]" + << "TestClass1::func_template2"; + + QTest::newRow("gcc_38") + << "int TestClass1::operator<(int)" + << "TestClass1::operator<"; + + QTest::newRow("gcc_39") + << "int TestClass1::operator>(int)" + << "TestClass1::operator>";} + +#ifdef QT_BUILD_INTERNAL +QT_BEGIN_NAMESPACE +extern QByteArray qCleanupFuncinfo(QByteArray); +QT_END_NAMESPACE +#endif + +void tst_qmessagehandler::cleanupFuncinfo() +{ +#ifdef QT_BUILD_INTERNAL + QFETCH(QString, funcinfo); + +// qDebug() << funcinfo.toLatin1(); + QByteArray result = qCleanupFuncinfo(funcinfo.toLatin1()); + QTEST(QString::fromLatin1(result), "expected"); +#endif +} + +void tst_qmessagehandler::qMessagePattern() +{ + QProcess process; + + QStringList environment = QProcess::systemEnvironment(); + // %{file} is tricky because of shadow builds + environment.prepend("QT_MESSAGE_PATTERN=\"%{type} %{appname} %{line} %{function} %{message}\""); + process.setEnvironment(environment); + + QString appExe = m_appDir + "/app"; + process.start(appExe); + QVERIFY2(process.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString()))); + process.waitForFinished(); + + QByteArray output = process.readAllStandardError(); +// qDebug() << output; + QVERIFY(!output.isEmpty()); + + QVERIFY(output.contains("debug 45 T::T static constructor")); + // we can't be sure whether the QT_MESSAGE_PATTERN is already destructed + QVERIFY(output.contains("static destructor")); + QVERIFY(output.contains("debug tst_qlogging 54 main qDebug")); + QVERIFY(output.contains("warning tst_qlogging 55 main qWarning")); + QVERIFY(output.contains("critical tst_qlogging 56 main qCritical")); + + environment = QProcess::systemEnvironment(); + environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{message}\""); + process.setEnvironment(environment); + + process.start(appExe); + QVERIFY2(process.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString()))); + process.waitForFinished(); + + output = process.readAllStandardError(); +// qDebug() << output; + QVERIFY(!output.isEmpty()); + + QVERIFY(output.contains("QT_MESSAGE_PATTERN: Unknown placeholder %{unknown}")); + QVERIFY(output.contains("PREFIX: qDebug")); +} + +QTEST_MAIN(tst_qmessagehandler) +#include "tst_qlogging.moc" diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.pro b/tests/auto/corelib/global/qlogging/tst_qlogging.pro new file mode 100644 index 0000000000..60377e0fdc --- /dev/null +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.pro @@ -0,0 +1,4 @@ +CONFIG += testcase parallel_test +TARGET = tst_qlogging +QT = core testlib +SOURCES = tst_qlogging.cpp diff --git a/tests/auto/corelib/global/qmessagehandler/qmessagehandler.pro b/tests/auto/corelib/global/qmessagehandler/qmessagehandler.pro deleted file mode 100644 index 8bdba4bfc4..0000000000 --- a/tests/auto/corelib/global/qmessagehandler/qmessagehandler.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase parallel_test -TARGET = tst_qmessagehandler -QT = core testlib -SOURCES = tst_qmessagehandler.cpp diff --git a/tests/auto/corelib/global/qmessagehandler/tst_qmessagehandler.cpp b/tests/auto/corelib/global/qmessagehandler/tst_qmessagehandler.cpp deleted file mode 100644 index 39bd0986a5..0000000000 --- a/tests/auto/corelib/global/qmessagehandler/tst_qmessagehandler.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qdebug.h> -#include <QtTest/QtTest> - -#include <qglobal.h> - -class tst_qmessagehandler : public QObject -{ - Q_OBJECT -private slots: - void cleanup(); - - void defaultHandler(); - void installMessageHandler(); - void installMsgHandler(); - void installBothHandler(); -}; - -static QtMsgType s_type; -const char *s_file; -int s_line; -const char *s_function; -static QString s_message; - -void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const char *msg) -{ - s_type = type; - s_file = context.file; - s_line = context.line; - s_function = context.function; - s_message = QString::fromLocal8Bit(msg); -} - -void customMsgHandler(QtMsgType type, const char *msg) -{ - s_type = type; - s_file = 0; - s_line = 0; - s_function = 0; - s_message = QString::fromLocal8Bit(msg); -} - -void tst_qmessagehandler::cleanup() -{ - qInstallMsgHandler(0); - qInstallMessageHandler(0); - s_type = QtFatalMsg; - s_file = 0; - s_line = 0; - s_function = 0; -} - -void tst_qmessagehandler::defaultHandler() -{ - // check that the default works - QTest::ignoreMessage(QtDebugMsg, "defaultHandler"); - qDebug("defaultHandler"); -} - -void tst_qmessagehandler::installMessageHandler() -{ - QMessageHandler oldHandler = qInstallMessageHandler(customMessageHandler); - - qDebug("installMessageHandler"); int line = __LINE__; - - QCOMPARE(s_type, QtDebugMsg); - QCOMPARE(s_message, QString::fromLocal8Bit("installMessageHandler")); - QCOMPARE(s_file, __FILE__); - QCOMPARE(s_function, Q_FUNC_INFO); - QCOMPARE(s_line, line); - - QMessageHandler myHandler = qInstallMessageHandler(oldHandler); - QCOMPARE((void*)myHandler, (void*)customMessageHandler); -} - -void tst_qmessagehandler::installMsgHandler() -{ - QtMsgHandler oldHandler = qInstallMsgHandler(customMsgHandler); - - qDebug("installMsgHandler"); - - QCOMPARE(s_type, QtDebugMsg); - QCOMPARE(s_message, QString::fromLocal8Bit("installMsgHandler")); - QCOMPARE(s_file, (const char*)0); - QCOMPARE(s_function, (const char*)0); - QCOMPARE(s_line, 0); - - QtMsgHandler myHandler = qInstallMsgHandler(oldHandler); - QCOMPARE((void*)myHandler, (void*)customMsgHandler); -} - -void tst_qmessagehandler::installBothHandler() -{ - qInstallMessageHandler(customMessageHandler); - qInstallMsgHandler(customMsgHandler); - - qDebug("installBothHandler"); int line = __LINE__; - - QCOMPARE(s_type, QtDebugMsg); - QCOMPARE(s_message, QString::fromLocal8Bit("installBothHandler")); - QCOMPARE(s_file, __FILE__); - QCOMPARE(s_function, Q_FUNC_INFO); - QCOMPARE(s_line, line); -} - -QTEST_MAIN(tst_qmessagehandler) -#include "tst_qmessagehandler.moc" diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index 064724e888..899efc11d9 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -72,7 +72,7 @@ void tst_QNumeric::fuzzyCompare_data() QTest::newRow("mis2") << 0.0 << 10000000.0 << false; QTest::newRow("mis3") << 0.0 << 0.000000001 << false; QTest::newRow("mis4") << 100000000.0 << 0.000000001 << false; - QTest::newRow("mis4") << 0.0000000001 << 0.000000001 << false; + QTest::newRow("mis5") << 0.0000000001 << 0.000000001 << false; } void tst_QNumeric::fuzzyCompare() diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index eb227625a7..79c96fbdc9 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -2680,8 +2680,8 @@ void tst_QDataStream::status_QBitArray_data() // past end QTest::newRow("empty") << QByteArray() << (int) QDataStream::ReadPastEnd << QBitArray(); QTest::newRow("badsize 0a") << QByteArray("\x00", 1) << (int) QDataStream::ReadPastEnd << QBitArray(); - QTest::newRow("badsize 0a") << QByteArray("\x00\x00", 2) << (int) QDataStream::ReadPastEnd << QBitArray(); - QTest::newRow("badsize 0a") << QByteArray("\x00\x00\x00", 3) << (int) QDataStream::ReadPastEnd << QBitArray(); + QTest::newRow("badsize 0b") << QByteArray("\x00\x00", 2) << (int) QDataStream::ReadPastEnd << QBitArray(); + QTest::newRow("badsize 0c") << QByteArray("\x00\x00\x00", 3) << (int) QDataStream::ReadPastEnd << QBitArray(); QTest::newRow("badsize 1") << QByteArray("\x00\x00\x00\x01", 4) << (int) QDataStream::ReadPastEnd << QBitArray(); QTest::newRow("badsize 2") << QByteArray("\x00\x00\x00\x02", 4) << (int) QDataStream::ReadPastEnd << QBitArray(); QTest::newRow("badsize 3") << QByteArray("\x00\x00\x00\x03", 4) << (int) QDataStream::ReadPastEnd << QBitArray(); diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index f1c9015092..6a48d7e60f 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -190,6 +190,8 @@ private slots: void isReadable(); + void cdBelowRoot(); + private: QString m_dataPath; }; @@ -383,6 +385,10 @@ void tst_QDir::removeRecursively() void tst_QDir::removeRecursivelyFailure() { +#ifdef Q_OS_UNIX + if (::getuid() == 0) + QSKIP("Running this test as root doesn't make sense"); +#endif const QString tmpdir = QDir::currentPath() + "/tmpdir/"; const QString path = tmpdir + "undeletable"; QDir().mkpath(path); @@ -1930,6 +1936,10 @@ void tst_QDir::isRelative() void tst_QDir::isReadable() { +#ifdef Q_OS_UNIX + if (::getuid() == 0) + QSKIP("Running this test as root doesn't make sense"); +#endif QDir dir; QVERIFY(dir.isReadable()); @@ -1942,6 +1952,36 @@ void tst_QDir::isReadable() #endif } +void tst_QDir::cdBelowRoot() +{ +#if defined (Q_OS_UNIX) +#define ROOT QString("/") +#define DIR QString("/tmp") +#define CD_INTO "tmp" +#else +#define ROOT QString::fromLocal8Bit(qgetenv("SystemDrive"))+"/" +#define DIR QString::fromLocal8Bit(qgetenv("SystemRoot")).replace('\\', '/') +#define CD_INTO QString::fromLocal8Bit(qgetenv("SystemRoot")).mid(3) +#endif + + QDir root(ROOT); + QVERIFY(!root.cd("..")); + QCOMPARE(root.path(), ROOT); + QVERIFY(root.cd(CD_INTO)); + QCOMPARE(root.path(), DIR); +#ifdef Q_OS_UNIX + if (::getuid() == 0) + QSKIP("Running this test as root doesn't make sense"); +#endif + QDir dir(DIR); + QVERIFY(!dir.cd("../..")); + QCOMPARE(dir.path(), DIR); + QVERIFY(!dir.cd("../abs/../..")); + QCOMPARE(dir.path(), DIR); + QVERIFY(dir.cd("..")); + QCOMPARE(dir.path(), ROOT); +} + QTEST_MAIN(tst_QDir) #include "tst_qdir.moc" diff --git a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp index ad61db51d6..d5d490dc29 100644 --- a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp +++ b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp @@ -403,8 +403,11 @@ void tst_QDirIterator::iterateResource() QDirIterator it(dirName, nameFilters, filters, flags); QStringList list; - while (it.hasNext()) - list << it.next(); + while (it.hasNext()) { + const QString dir = it.next(); + if (!dir.startsWith(":/qt-project.org")) + list << dir; + } list.sort(); QStringList sortedEntries = entries; diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 00e45354ba..d1a0debf4d 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -53,7 +53,9 @@ #include <QHostInfo> #endif #include <QProcess> -#ifndef Q_OS_WIN +#ifdef Q_OS_WIN +# include <qt_windows.h> +#else # include <sys/types.h> # include <unistd.h> #endif @@ -476,8 +478,16 @@ void tst_QFile::open_data() QTest::newRow("noreadfile") << QString("noreadfile") << int(QIODevice::ReadOnly) << false << QFile::OpenError; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly) - << true << QFile::NoError; + //opening devices requires administrative privileges (and elevation). + HANDLE hTest = CreateFile(_T("\\\\.\\PhysicalDrive0"), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + if (hTest != INVALID_HANDLE_VALUE) { + CloseHandle(hTest); + QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly) + << true << QFile::NoError; + } else { + QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly) + << false << QFile::OpenError; + } QTest::newRow("uncFile") << "//" + QtNetworkSettings::winServerName() + "/testshare/test.pri" << int(QIODevice::ReadOnly) << true << QFile::NoError; #endif @@ -2339,6 +2349,13 @@ void tst_QFile::rename() QFETCH(QString, destination); QFETCH(bool, result); +#if defined(Q_OS_UNIX) + if (strcmp(QTest::currentDataTag(), "renamefile -> /etc/renamefile") == 0) { + if (::getuid() == 0) + QSKIP("Running this test as root doesn't make sense"); + } +#endif + QFile::remove("renamedfile"); QFile f("renamefile"); f.open(QFile::WriteOnly); @@ -3011,25 +3028,28 @@ void tst_QFile::openStandardStreamsBufferedStreams() { QFile in; in.open(stdin, QIODevice::ReadOnly); + if (!in.isSequential()) + QSKIP("Standard input redirected."); QCOMPARE( in.pos(), (qint64)0 ); QCOMPARE( in.size(), (qint64)0 ); - QVERIFY( in.isSequential() ); } { QFile out; out.open(stdout, QIODevice::WriteOnly); + if (!out.isSequential()) + QSKIP("Standard output redirected."); QCOMPARE( out.pos(), (qint64)0 ); QCOMPARE( out.size(), (qint64)0 ); - QVERIFY( out.isSequential() ); } { QFile err; err.open(stderr, QIODevice::WriteOnly); + if (!err.isSequential()) + QSKIP("Standard error redirected."); QCOMPARE( err.pos(), (qint64)0 ); QCOMPARE( err.size(), (qint64)0 ); - QVERIFY( err.isSequential() ); } } diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 7b80152b62..797d5ff5e3 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -159,8 +159,8 @@ private slots: void isBundle_data(); void isBundle(); - void isLocalFs_data(); - void isLocalFs(); + void isNativePath_data(); + void isNativePath(); void refresh(); @@ -1222,10 +1222,13 @@ void tst_QFileInfo::isBundle() QCOMPARE(fi.isBundle(), isBundle); } -void tst_QFileInfo::isLocalFs_data() +void tst_QFileInfo::isNativePath_data() { QTest::addColumn<QString>("path"); - QTest::addColumn<bool>("isLocalFs"); + QTest::addColumn<bool>("isNativePath"); + + QTest::newRow("default-constructed") << QString() << false; + QTest::newRow("empty") << QString("") << true; QTest::newRow("local root") << QString::fromLatin1("/") << true; QTest::newRow("local non-existent file") << QString::fromLatin1("/abrakadabra.boo") << true; @@ -1233,17 +1236,15 @@ void tst_QFileInfo::isLocalFs_data() QTest::newRow("qresource root") << QString::fromLatin1(":/") << false; } -void tst_QFileInfo::isLocalFs() +void tst_QFileInfo::isNativePath() { QFETCH(QString, path); - QFETCH(bool, isLocalFs); + QFETCH(bool, isNativePath); QFileInfo info(path); - QFileInfoPrivate *privateInfo = getPrivate(info); - QCOMPARE((privateInfo->fileEngine == 0), isLocalFs); - if (privateInfo->fileEngine) - QCOMPARE(bool(privateInfo->fileEngine->fileFlags(QAbstractFileEngine::LocalDiskFlag) - & QAbstractFileEngine::LocalDiskFlag), isLocalFs); + if (path.isNull()) + info = QFileInfo(); + QCOMPARE(info.isNativePath(), isNativePath); } void tst_QFileInfo::refresh() @@ -1722,7 +1723,13 @@ void tst_QFileInfo::group() #if defined(Q_OS_UNIX) struct group *gr; gid_t gid = getegid(); + + errno = 0; gr = getgrgid(gid); + + QVERIFY2(gr, qPrintable( + QString("getgrgid returned 0: %1, cannot determine my own group") + .arg(QString::fromLocal8Bit(strerror(errno))))); expected = QString::fromLocal8Bit(gr->gr_name); #endif diff --git a/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp b/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp index fe2e30a95c..b083d3b1c3 100644 --- a/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp +++ b/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp @@ -241,15 +241,15 @@ void tst_QFileSystemEntry::suffix_data() QTest::newRow("data1") << "file.tar.gz" << "gz"; QTest::newRow("data2") << "/path/file/file.tar.gz" << "gz"; QTest::newRow("data3") << "/path/file.tar" << "tar"; - QTest::newRow("hidden1") << ".ext1" << "ext1"; - QTest::newRow("hidden1") << ".ext" << "ext"; - QTest::newRow("hidden1") << ".ex" << "ex"; - QTest::newRow("hidden1") << ".e" << "e"; - QTest::newRow("hidden2") << ".ext1.ext2" << "ext2"; - QTest::newRow("hidden2") << ".ext.ext2" << "ext2"; - QTest::newRow("hidden2") << ".ex.ext2" << "ext2"; - QTest::newRow("hidden2") << ".e.ext2" << "ext2"; - QTest::newRow("hidden2") << "..ext2" << "ext2"; + QTest::newRow("hidden1-1") << ".ext1" << "ext1"; + QTest::newRow("hidden1-2") << ".ext" << "ext"; + QTest::newRow("hidden1-3") << ".ex" << "ex"; + QTest::newRow("hidden1-4") << ".e" << "e"; + QTest::newRow("hidden2-1") << ".ext1.ext2" << "ext2"; + QTest::newRow("hidden2-2") << ".ext.ext2" << "ext2"; + QTest::newRow("hidden2-3") << ".ex.ext2" << "ext2"; + QTest::newRow("hidden2-4") << ".e.ext2" << "ext2"; + QTest::newRow("hidden2-5") << "..ext2" << "ext2"; QTest::newRow("dots") << "/path/file.with.dots/file..ext2" << "ext2"; QTest::newRow("dots2") << "/path/file.with.dots/.file..ext2" << "ext2"; } diff --git a/tests/auto/corelib/io/qfilesystemwatcher/qfilesystemwatcher.pro b/tests/auto/corelib/io/qfilesystemwatcher/qfilesystemwatcher.pro index e712a6ad5f..8ada44fdf7 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/qfilesystemwatcher.pro +++ b/tests/auto/corelib/io/qfilesystemwatcher/qfilesystemwatcher.pro @@ -2,5 +2,3 @@ CONFIG += testcase parallel_test TARGET = tst_qfilesystemwatcher QT = core testlib SOURCES = tst_qfilesystemwatcher.cpp - -mac: CONFIG += insignificant_test # QTBUG-22744 diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 5e5a99f937..8caccb6da9 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -42,6 +42,7 @@ #include <QCoreApplication> +#include <QTemporaryDir> #include <QFileSystemWatcher> #ifdef Q_OS_LINUX @@ -52,9 +53,15 @@ # endif #endif +/* All tests need to run in temporary directories not used + * by the application to avoid non-deterministic failures on Windows + * due to locked directories and left-overs from previous tests. */ + class tst_QFileSystemWatcher : public QObject { Q_OBJECT +public: + tst_QFileSystemWatcher(); private slots: void basicTest_data(); @@ -75,11 +82,20 @@ private slots: void removeFileAndUnWatch(); - void cleanup(); - void destroyAfterQCoreApplication(); + +private: + QString m_tempDirPattern; }; +tst_QFileSystemWatcher::tst_QFileSystemWatcher() +{ + m_tempDirPattern = QDir::tempPath(); + if (!m_tempDirPattern.endsWith(QLatin1Char('/'))) + m_tempDirPattern += QLatin1Char('/'); + m_tempDirPattern += QStringLiteral("tst_qfilesystemwatcherXXXXXX"); +} + void tst_QFileSystemWatcher::basicTest_data() { QTest::addColumn<QString>("backend"); @@ -92,7 +108,9 @@ void tst_QFileSystemWatcher::basicTest() QFETCH(QString, backend); // create test file - QFile testFile("testfile.txt"); + QTemporaryDir temporaryDirectory(m_tempDirPattern); + QVERIFY(temporaryDirectory.isValid()); + QFile testFile(temporaryDirectory.path() + QStringLiteral("/testfile.txt")); testFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner); testFile.remove(); QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); @@ -151,14 +169,16 @@ void tst_QFileSystemWatcher::basicTest() QCOMPARE(changedSpy.count(), 0); // readd the file watch with a relative path - QVERIFY(watcher.addPath(testFile.fileName().prepend("./"))); + const QString relativeTestFileName = QDir::current().relativeFilePath(testFile.fileName()); + QVERIFY(!relativeTestFileName.isEmpty()); + QVERIFY(watcher.addPath(relativeTestFileName)); testFile.open(QIODevice::WriteOnly | QIODevice::Truncate); testFile.write(QByteArray("hello multiverse!")); testFile.close(); QTRY_VERIFY(changedSpy.count() > 0); - QVERIFY(watcher.removePath(testFile.fileName().prepend("./"))); + QVERIFY(watcher.removePath(relativeTestFileName)); changedSpy.clear(); @@ -222,15 +242,21 @@ void tst_QFileSystemWatcher::watchDirectory() { QFETCH(QString, backend); - QDir().mkdir("testDir"); - QDir testDir("testDir"); + QTemporaryDir temporaryDirectory(m_tempDirPattern); + QVERIFY(temporaryDirectory.isValid()); + + QDir temporaryDir(temporaryDirectory.path()); + const QString testDirName = QStringLiteral("testDir"); + QVERIFY(temporaryDir.mkdir(testDirName)); + QDir testDir = temporaryDir; + QVERIFY(testDir.cd(testDirName)); QString testFileName = testDir.filePath("testFile.txt"); QFile::remove(testFileName); QFileSystemWatcher watcher; watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_") + backend); - QVERIFY(watcher.addPath(testDir.dirName())); + QVERIFY(watcher.addPath(testDir.absolutePath())); QSignalSpy changedSpy(&watcher, SIGNAL(directoryChanged(const QString &))); QVERIFY(changedSpy.isValid()); @@ -246,7 +272,7 @@ void tst_QFileSystemWatcher::watchDirectory() QString fileName; // remove the watch, should not get notification of a new file - QVERIFY(watcher.removePath(testDir.dirName())); + QVERIFY(watcher.removePath(testDir.absolutePath())); QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); testFile.close(); @@ -256,7 +282,7 @@ void tst_QFileSystemWatcher::watchDirectory() QCOMPARE(changedSpy.count(), 0); - QVERIFY(watcher.addPath(testDir.dirName())); + QVERIFY(watcher.addPath(testDir.absolutePath())); // remove the file again, should get a signal from the watcher QVERIFY(testFile.remove()); @@ -265,7 +291,7 @@ void tst_QFileSystemWatcher::watchDirectory() eventLoop.exec(); // remove the directory, should get a signal from the watcher - QVERIFY(QDir().rmdir("testDir")); + QVERIFY(temporaryDir.rmdir(testDirName)); // waiting max 5 seconds for notification for directory removal to trigger #ifdef Q_OS_WINCE @@ -276,15 +302,16 @@ void tst_QFileSystemWatcher::watchDirectory() QCOMPARE(changedSpy.at(1).count(), 1); fileName = changedSpy.at(0).at(0).toString(); - QCOMPARE(fileName, testDir.dirName()); + QCOMPARE(fileName, testDir.absolutePath()); fileName = changedSpy.at(1).at(0).toString(); - QCOMPARE(fileName, testDir.dirName()); + QCOMPARE(fileName, testDir.absolutePath()); changedSpy.clear(); // recreate the file, we should not get any notification - if (!QDir().mkdir("testDir")) - QSKIP("Failed to recreate directory, skipping final test."); + if (!temporaryDir.mkdir(testDirName)) + QSKIP(qPrintable(QString::fromLatin1("Failed to recreate directory '%1' under '%2', skipping final test."). + arg(testDirName, temporaryDir.absolutePath()))); // waiting max 5 seconds for notification for dir recreation to trigger timer.start(5000); @@ -292,7 +319,7 @@ void tst_QFileSystemWatcher::watchDirectory() QCOMPARE(changedSpy.count(), 0); - QVERIFY(QDir().rmdir("testDir")); + QVERIFY(temporaryDir.rmdir(testDirName)); } void tst_QFileSystemWatcher::addPath() @@ -360,8 +387,15 @@ void tst_QFileSystemWatcher::removePaths() void tst_QFileSystemWatcher::watchFileAndItsDirectory() { QFETCH(QString, backend); - QDir().mkdir("testDir"); - QDir testDir("testDir"); + + QTemporaryDir temporaryDirectory(m_tempDirPattern); + QVERIFY(temporaryDirectory.isValid()); + + QDir temporaryDir(temporaryDirectory.path()); + const QString testDirName = QStringLiteral("testDir"); + QVERIFY(temporaryDir.mkdir(testDirName)); + QDir testDir = temporaryDir; + QVERIFY(testDir.cd(testDirName)); QString testFileName = testDir.filePath("testFile.txt"); QString secondFileName = testDir.filePath("testFile2.txt"); @@ -378,7 +412,7 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() QFileSystemWatcher watcher; watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_") + backend); - QVERIFY(watcher.addPath(testDir.dirName())); + QVERIFY(watcher.addPath(testDir.absolutePath())); QVERIFY(watcher.addPath(testFileName)); QSignalSpy fileChangedSpy(&watcher, SIGNAL(fileChanged(const QString &))); @@ -398,6 +432,11 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() testFile.write(QByteArray("hello again")); testFile.close(); +#ifdef Q_OS_MAC + // wait again for the file's atime to be updated + QTest::qWait(2000); +#endif + QTRY_VERIFY(fileChangedSpy.count() > 0); //according to Qt 4 documentation: @@ -443,17 +482,7 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() QCOMPARE(fileChangedSpy.count(), 0); QCOMPARE(dirChangedSpy.count(), 1); - QVERIFY(QDir().rmdir("testDir")); -} - -void tst_QFileSystemWatcher::cleanup() -{ - QDir testDir("testDir"); - QString testFileName = testDir.filePath("testFile.txt"); - QString secondFileName = testDir.filePath("testFile2.txt"); - QFile::remove(testFileName); - QFile::remove(secondFileName); - QDir().rmdir("testDir"); + QVERIFY(temporaryDir.rmdir(testDirName)); } void tst_QFileSystemWatcher::nonExistingFile() @@ -475,22 +504,33 @@ void tst_QFileSystemWatcher::nonExistingFile() void tst_QFileSystemWatcher::removeFileAndUnWatch() { - static const char * const filename = "foo.txt"; + QTemporaryDir temporaryDirectory(m_tempDirPattern); + QVERIFY(temporaryDirectory.isValid()); + + const QString filename = temporaryDirectory.path() + QStringLiteral("/foo.txt"); + QFileSystemWatcher watcher; { QFile testFile(filename); - testFile.open(QIODevice::WriteOnly); + QVERIFY2(testFile.open(QIODevice::WriteOnly), + qPrintable(QString::fromLatin1("Cannot open %1 for writing: %2").arg(filename, testFile.errorString()))); testFile.close(); } QVERIFY(watcher.addPath(filename)); QFile::remove(filename); - QVERIFY(watcher.removePath(filename)); + /* There are potential race conditions here; the watcher thread might remove the file from its list + * before the call to watcher.removePath(), which then fails. When that happens, the auto-signal + * notification to remove the file from the watcher's main list will not be delivered before the next + * event loop such that the call to watcher.addPath() fails since the file is still in the main list. */ + if (!watcher.removePath(filename)) + QSKIP("Skipping remaining test due to race condition."); { QFile testFile(filename); - testFile.open(QIODevice::WriteOnly); + QVERIFY2(testFile.open(QIODevice::WriteOnly), + qPrintable(QString::fromLatin1("Cannot open %1 for writing: %2").arg(filename, testFile.errorString()))); testFile.close(); } QVERIFY(watcher.addPath(filename)); diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index fa72083dcc..796282d6d8 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -92,6 +92,7 @@ void tst_QResourceEngine::checkStructure_data() << QString() << (QStringList() << "search_file.txt") << (QStringList() << QLatin1String("aliasdir") << QLatin1String("otherdir") + << QLatin1String("qt-project.org") << QLatin1String("runtime_resource") << QLatin1String("searchpath1") << QLatin1String("searchpath2") << QLatin1String("secondary_root") diff --git a/tests/auto/corelib/io/qsettings/qsettings.pro b/tests/auto/corelib/io/qsettings/qsettings.pro index ed3be0f23f..9de476fe13 100644 --- a/tests/auto/corelib/io/qsettings/qsettings.pro +++ b/tests/auto/corelib/io/qsettings/qsettings.pro @@ -6,4 +6,4 @@ RESOURCES += qsettings.qrc win32-msvc*:LIBS += advapi32.lib -mac: CONFIG += insignificant_test # QTBUG-22745 +win32: CONFIG += insignificant_test # QTBUG-24145 diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 0d6443c5ac..df8e97ab9c 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -580,6 +580,9 @@ void tst_QSettings::ctor() QCoreApplication::instance()->setOrganizationName(""); QCoreApplication::instance()->setApplicationName(""); QSettings settings; +#ifdef Q_OS_MAC + QEXPECT_FAIL("native", "Default settings on Mac are valid, despite organization domain, name, and app name being null", Continue); +#endif QCOMPARE(settings.status(), QSettings::AccessError); QCoreApplication::instance()->setOrganizationName("software.org"); QCoreApplication::instance()->setApplicationName("KillerAPP"); @@ -592,6 +595,9 @@ void tst_QSettings::ctor() } QSettings settings(format, QSettings::UserScope, "", ""); +#ifdef Q_OS_MAC + QEXPECT_FAIL("native", "Default settings on Mac are valid, despite organization domain, name, and app name being null", Continue); +#endif QCOMPARE(settings.status(), QSettings::AccessError); QSettings settings2(format, QSettings::UserScope, "software.org", "KillerAPP"); QCOMPARE(settings2.status(), QSettings::NoError); diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 1e288e2418..ebfd640dfb 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -229,6 +229,11 @@ void tst_qstandardpaths::testRuntimeDirectory() void tst_qstandardpaths::testCustomRuntimeDirectory() { +#if defined(Q_OS_UNIX) + if (::getuid() == 0) + QSKIP("Running this test as root doesn't make sense"); +#endif + #ifdef Q_XDG_PLATFORM qputenv("XDG_RUNTIME_DIR", QFile::encodeName("/tmp")); // It's very unlikely that /tmp is 0600 or that we can chmod it diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 46d2fa2bde..0b2e1e1902 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -50,6 +50,10 @@ #ifdef Q_OS_WIN # include <windows.h> #endif +#ifdef Q_OS_UNIX // for geteuid() +# include <sys/types.h> +# include <unistd.h> +#endif class tst_QTemporaryDir : public QObject { diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 01aecc2a21..37a1556cf9 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -2755,7 +2755,7 @@ void tst_QTextStream::double_write_with_flags_data() QTest::newRow("inf uppercase") << qInf() << QString("INF") << (int)QTextStream::UppercaseDigits << 0; QTest::newRow("-inf uppercase") << -qInf() << QString("-INF") << (int)QTextStream::UppercaseDigits << 0; QTest::newRow("nan") << qQNaN() << QString("nan") << 0 << 0; - QTest::newRow("nan") << qQNaN() << QString("NAN") << (int)QTextStream::UppercaseDigits << 0; + QTest::newRow("NAN") << qQNaN() << QString("NAN") << (int)QTextStream::UppercaseDigits << 0; QTest::newRow("scientific") << 1.234567e+02 << QString("1.234567e+02") << 0 << (int)QTextStream::ScientificNotation; QTest::newRow("scientific2") << 1.234567e+02 << QString("1.234567e+02") << (int)QTextStream::UppercaseBase << (int)QTextStream::ScientificNotation; QTest::newRow("scientific uppercase") << 1.234567e+02 << QString("1.234567E+02") << (int)QTextStream::UppercaseDigits << (int)QTextStream::ScientificNotation; diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 611847852f..a74d817b8a 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -350,6 +350,8 @@ void tst_QUrl::setUrl() QVERIFY(url.authority().isEmpty()); QVERIFY(url.fragment().isEmpty()); QCOMPARE(url.port(), -1); + QCOMPARE(url.toString(), QString::fromLatin1("file:///")); + QCOMPARE(url.toDisplayString(), QString::fromLatin1("file:///")); } { @@ -363,6 +365,8 @@ void tst_QUrl::setUrl() QCOMPARE(url.host(), QString::fromLatin1("www.foo.bar")); QCOMPARE(url.authority(), QString::fromLatin1("www.foo.bar:80")); QCOMPARE(url.port(), 80); + QCOMPARE(url.toString(), QString::fromLatin1("http://www.foo.bar:80")); + QCOMPARE(url.toDisplayString(), QString::fromLatin1("http://www.foo.bar:80")); QUrl url2("//www1.foo.bar"); QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("http://www1.foo.bar")); @@ -379,6 +383,8 @@ void tst_QUrl::setUrl() QCOMPARE(url.host(), QString::fromLatin1("56::56:56:56:127.0.0.1")); QCOMPARE(url.authority(), QString::fromLatin1("user:pass@[56::56:56:56:127.0.0.1]:99")); QCOMPARE(url.port(), 99); + QCOMPARE(url.url(), QString::fromLatin1("http://user:pass@[56::56:56:56:127.0.0.1]:99")); + QCOMPARE(url.toDisplayString(), QString::fromLatin1("http://user@[56::56:56:56:127.0.0.1]:99")); } { @@ -3114,8 +3120,8 @@ void tst_QUrl::fromUserInput_data() QTest::newRow("port-0") << "example.org:80" << portUrl; QTest::newRow("port-1") << "http://example.org:80" << portUrl; portUrl.setPath("path"); - QTest::newRow("port-1") << "example.org:80/path" << portUrl; - QTest::newRow("port-1") << "http://example.org:80/path" << portUrl; + QTest::newRow("port-2") << "example.org:80/path" << portUrl; + QTest::newRow("port-3") << "http://example.org:80/path" << portUrl; // mailto doesn't have a ://, but is valid QUrl mailto("ben@example.net"); diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 2ca5df477b..8d451dbff9 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -1257,13 +1257,13 @@ void tst_QAbstractItemModel::testMoveToGrandParent_data() QTest::newRow("move09") << 8 << 8 << 8; // Moving to the row of my parent and its neighbours doesn't confuse things - QTest::newRow("move09") << 8 << 8 << 4; - QTest::newRow("move10") << 8 << 8 << 5; - QTest::newRow("move11") << 8 << 8 << 6; + QTest::newRow("move10") << 8 << 8 << 4; + QTest::newRow("move11") << 8 << 8 << 5; + QTest::newRow("move12") << 8 << 8 << 6; // Moving everything from one parent to another - QTest::newRow("move12") << 0 << 9 << 10; - QTest::newRow("move13") << 0 << 9 << 0; + QTest::newRow("move13") << 0 << 9 << 10; + QTest::newRow("move14") << 0 << 9 << 0; } void tst_QAbstractItemModel::testMoveToGrandParent() @@ -1397,14 +1397,14 @@ void tst_QAbstractItemModel::testMoveToSibling_data() QTest::newRow("move09") << 8 << 8 << 8; // Moving to the row of my target and its neighbours doesn't confuse things - QTest::newRow("move09") << 8 << 8 << 4; - QTest::newRow("move10") << 8 << 8 << 5; - QTest::newRow("move11") << 8 << 8 << 6; + QTest::newRow("move10") << 8 << 8 << 4; + QTest::newRow("move11") << 8 << 8 << 5; + QTest::newRow("move12") << 8 << 8 << 6; // Move such that the destination parent no longer valid after the move. // The destination parent is always QMI(5, 0), but after this move the // row count is 5, so (5, 0) (used internally in QAIM) no longer refers to a valid index. - QTest::newRow("move12") << 0 << 4 << 0; + QTest::newRow("move13") << 0 << 4 << 0; } void tst_QAbstractItemModel::testMoveToSibling() @@ -1541,12 +1541,12 @@ void tst_QAbstractItemModel::testMoveToUncle_data() QTest::newRow("move09") << 8 << 8 << 8; // Moving to the row of my parent and its neighbours doesn't confuse things - QTest::newRow("move09") << 8 << 8 << 4; - QTest::newRow("move10") << 8 << 8 << 5; - QTest::newRow("move11") << 8 << 8 << 6; + QTest::newRow("move10") << 8 << 8 << 4; + QTest::newRow("move11") << 8 << 8 << 5; + QTest::newRow("move12") << 8 << 8 << 6; // Moving everything from one parent to another - QTest::newRow("move12") << 0 << 9 << 10; + QTest::newRow("move13") << 0 << 9 << 10; } void tst_QAbstractItemModel::testMoveToUncle() @@ -1734,22 +1734,22 @@ void tst_QAbstractItemModel::testMoveWithinOwnRange_data() QTest::newRow("move07") << 0 << 5 << 4; QTest::newRow("move08") << 0 << 5 << 5; QTest::newRow("move09") << 0 << 5 << 6; - QTest::newRow("move08") << 3 << 5 << 5; - QTest::newRow("move08") << 3 << 5 << 6; - QTest::newRow("move09") << 4 << 5 << 5; - QTest::newRow("move10") << 4 << 5 << 6; - QTest::newRow("move11") << 5 << 5 << 5; - QTest::newRow("move12") << 5 << 5 << 6; - QTest::newRow("move13") << 5 << 9 << 9; - QTest::newRow("move14") << 5 << 9 << 10; - QTest::newRow("move15") << 6 << 9 << 9; - QTest::newRow("move16") << 6 << 9 << 10; - QTest::newRow("move17") << 7 << 9 << 9; - QTest::newRow("move18") << 7 << 9 << 10; - QTest::newRow("move19") << 8 << 9 << 9; - QTest::newRow("move20") << 8 << 9 << 10; - QTest::newRow("move21") << 9 << 9 << 9; - QTest::newRow("move22") << 0 << 9 << 10; + QTest::newRow("move10") << 3 << 5 << 5; + QTest::newRow("move11") << 3 << 5 << 6; + QTest::newRow("move12") << 4 << 5 << 5; + QTest::newRow("move13") << 4 << 5 << 6; + QTest::newRow("move14") << 5 << 5 << 5; + QTest::newRow("move15") << 5 << 5 << 6; + QTest::newRow("move16") << 5 << 9 << 9; + QTest::newRow("move17") << 5 << 9 << 10; + QTest::newRow("move18") << 6 << 9 << 9; + QTest::newRow("move19") << 6 << 9 << 10; + QTest::newRow("move20") << 7 << 9 << 9; + QTest::newRow("move21") << 7 << 9 << 10; + QTest::newRow("move22") << 8 << 9 << 9; + QTest::newRow("move23") << 8 << 9 << 10; + QTest::newRow("move24") << 9 << 9 << 9; + QTest::newRow("move25") << 0 << 9 << 10; } void tst_QAbstractItemModel::testMoveWithinOwnRange() diff --git a/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp b/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp index cbe7da11ad..d27d685f37 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp @@ -779,19 +779,19 @@ void tst_QItemModel::remove_data() makeTestRow(":none at the middle", MIDDLE, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); makeTestRow(":none at the end", END, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", -99, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", 9999, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", -99, 1, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", 9999, 1, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", -99, MANY, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", 9999, MANY, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - - makeTestRow(":valid start, invalid count", START, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":valid start, invalid count", MIDDLE, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":valid start, invalid count", END, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":valid start, invalid count", START, 9999, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":valid start, invalid count", MIDDLE, 9999, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":valid start, invalid count", END, 9999, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 1", -99, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 2", 9999, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 3", -99, 1, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 4", 9999, 1, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 5", -99, MANY, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 6", 9999, MANY, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + + makeTestRow(":valid start, invalid count 1", START, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":valid start, invalid count 2", MIDDLE, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":valid start, invalid count 3", END, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":valid start, invalid count 4", START, 9999, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":valid start, invalid count 5", MIDDLE, 9999, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":valid start, invalid count 6", END, 9999, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); // Recursive remove's might assert, haven't decided yet... //makeTestRow(":one at the start recursivly", START, DEFAULTCOUNT, 2, DNS, 2, DNS, RECURSIVE, START, DEFAULTCOUNT, FAIL); @@ -1126,16 +1126,16 @@ void tst_QItemModel::insert_data() makeTestRow(":none at the middle", MIDDLE, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); makeTestRow(":none at the end", END, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", -99, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", 9999, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", -99, 1, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", 9999, 1, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", -99, MANY, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":invalid start, valid count", 9999, MANY, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 1", -99, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 2", 9999, 0, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 3", -99, 1, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 4", 9999, 1, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 5", -99, MANY, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":invalid start, valid count 6", 9999, MANY, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":valid start, invalid count", START, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":valid start, invalid count", MIDDLE, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); - makeTestRow(":valid start, invalid count", END, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":valid start, invalid count 1", START, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":valid start, invalid count 2", MIDDLE, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); + makeTestRow(":valid start, invalid count 3", END, -2, NOSIGNALS, NOSIGNALS, NOSIGNALS, NOSIGNALS, !RECURSIVE, 0, 0, FAIL); // Recursive insert's might assert, haven't decided yet... //makeTestRow(":one at the start recursivly", START, DEFAULTCOUNT, 2, DNS, 2, DNS, RECURSIVE, START, DEFAULTCOUNT, FAIL); diff --git a/tests/auto/corelib/json/json.pro b/tests/auto/corelib/json/json.pro index 5158b7337a..7978a74278 100644 --- a/tests/auto/corelib/json/json.pro +++ b/tests/auto/corelib/json/json.pro @@ -3,6 +3,6 @@ QT = core testlib CONFIG -= app_bundle CONFIG += testcase -DEFINES += SRCDIR=\\\"$$PWD/\\\" +TESTDATA += test.json test.bjson test3.json test2.json SOURCES += tst_qtjson.cpp diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index e35f645ef6..2ac0574ec5 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -92,6 +92,7 @@ private Q_SLOTS: void toJson(); void fromJson(); + void fromJsonErrors(); void fromBinary(); void toAndFromBinary_data(); void toAndFromBinary(); @@ -111,6 +112,8 @@ private Q_SLOTS: void testCompaction(); void testDebugStream(); void testCompactionError(); +private: + QString testDataDir; }; TestQtJson::TestQtJson(QObject *parent) : QObject(parent) @@ -119,6 +122,9 @@ TestQtJson::TestQtJson(QObject *parent) : QObject(parent) void TestQtJson::initTestCase() { + testDataDir = QFileInfo(QFINDTESTDATA("test.json")).absolutePath(); + if (testDataDir.isEmpty()) + testDataDir = QCoreApplication::applicationDirPath(); } void TestQtJson::cleanupTestCase() @@ -1075,9 +1081,173 @@ void TestQtJson::fromJson() } } +void TestQtJson::fromJsonErrors() +{ + { + QJsonParseError error; + QByteArray json = "{\n \n\n"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::UnterminatedObject); + QCOMPARE(error.offset, 8); + } + { + QJsonParseError error; + QByteArray json = "{\n \"key\" 10\n"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::MissingNameSeparator); + QCOMPARE(error.offset, 13); + } + { + QJsonParseError error; + QByteArray json = "[\n \n\n"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::UnterminatedArray); + QCOMPARE(error.offset, 8); + } + { + QJsonParseError error; + QByteArray json = "[\n 1, true\n\n"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::UnterminatedArray); + QCOMPARE(error.offset, 14); + } + { + QJsonParseError error; + QByteArray json = "[\n 1 true\n\n"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::MissingValueSeparator); + QCOMPARE(error.offset, 7); + } + { + QJsonParseError error; + QByteArray json = "[\n nul"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::IllegalValue); + QCOMPARE(error.offset, 7); + } + { + QJsonParseError error; + QByteArray json = "[\n nulzz"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::IllegalValue); + QCOMPARE(error.offset, 10); + } + { + QJsonParseError error; + QByteArray json = "[\n tru"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::IllegalValue); + QCOMPARE(error.offset, 7); + } + { + QJsonParseError error; + QByteArray json = "[\n trud]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::IllegalValue); + QCOMPARE(error.offset, 10); + } + { + QJsonParseError error; + QByteArray json = "[\n fal"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::IllegalValue); + QCOMPARE(error.offset, 7); + } + { + QJsonParseError error; + QByteArray json = "[\n falsd]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::IllegalValue); + QCOMPARE(error.offset, 11); + } + { + QJsonParseError error; + QByteArray json = "[\n 11111"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::EndOfNumber); + QCOMPARE(error.offset, 11); + } + { + QJsonParseError error; + QByteArray json = "[\n -1E10000]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::IllegalNumber); + QCOMPARE(error.offset, 14); + } + { + QJsonParseError error; + QByteArray json = "[\n -1e-10000]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::IllegalNumber); + QCOMPARE(error.offset, 15); + } + { + QJsonParseError error; + QByteArray json = "[\n \"\\u12\"]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::StringEscapeSequence); + QCOMPARE(error.offset, 11); + } + { + QJsonParseError error; + QByteArray json = "[\n \"foo\uffffbar\"]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::StringUTF8Scan); + QCOMPARE(error.offset, 13); + } + { + QJsonParseError error; + QByteArray json = "[\n \""; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::EndOfString); + QCOMPARE(error.offset, 8); + } + { + QJsonParseError error; + QByteArray json = "[\n \"cЂa\\u12\"]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::StringEscapeSequence); + QCOMPARE(error.offset, 15); + } + { + QJsonParseError error; + QByteArray json = "[\n \"cЂa\uffffbar\"]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::StringUTF8Scan); + QCOMPARE(error.offset, 14); + } + { + QJsonParseError error; + QByteArray json = "[\n \"cЂa ]"; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(doc.isEmpty()); + QCOMPARE(error.error, QJsonParseError::EndOfString); + QCOMPARE(error.offset, 14); + } +} + void TestQtJson::fromBinary() { - QFile file(QLatin1String(SRCDIR "test.json")); + QFile file(testDataDir + "/test.json"); file.open(QFile::ReadOnly); QByteArray testJson = file.readAll(); @@ -1086,7 +1256,7 @@ void TestQtJson::fromBinary() QVERIFY(!outdoc.isNull()); QVERIFY(doc == outdoc); - QFile bfile(QLatin1String(SRCDIR "test.bjson")); + QFile bfile(testDataDir + "/test.bjson"); bfile.open(QFile::ReadOnly); QByteArray binary = bfile.readAll(); @@ -1099,8 +1269,8 @@ void TestQtJson::fromBinary() void TestQtJson::toAndFromBinary_data() { QTest::addColumn<QString>("filename"); - QTest::newRow("test.json") << QString::fromLatin1(SRCDIR "test.json"); - QTest::newRow("test2.json") << QString::fromLatin1(SRCDIR "test2.json"); + QTest::newRow("test.json") << (testDataDir + "/test.json"); + QTest::newRow("test2.json") << (testDataDir + "/test2.json"); } void TestQtJson::toAndFromBinary() @@ -1279,7 +1449,7 @@ void TestQtJson::parseDuplicateKeys() void TestQtJson::testParser() { - QFile file(QLatin1String(SRCDIR "test.json")); + QFile file(testDataDir + "/test.json"); file.open(QFile::ReadOnly); QByteArray testJson = file.readAll(); @@ -1364,7 +1534,7 @@ void TestQtJson::compactObject() void TestQtJson::validation() { // this basically tests that we don't crash on corrupt data - QFile file(QLatin1String(SRCDIR "test.json")); + QFile file(testDataDir + "/test.json"); QVERIFY(file.open(QFile::ReadOnly)); QByteArray testJson = file.readAll(); QVERIFY(!testJson.isEmpty()); @@ -1385,7 +1555,7 @@ void TestQtJson::validation() } - QFile file2(QLatin1String(SRCDIR "test3.json")); + QFile file2(testDataDir + "/test3.json"); file2.open(QFile::ReadOnly); testJson = file2.readAll(); QVERIFY(!testJson.isEmpty()); diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro index 3c697f4149..7ec01d4a36 100644 --- a/tests/auto/corelib/kernel/kernel.pro +++ b/tests/auto/corelib/kernel/kernel.pro @@ -1,10 +1,12 @@ TEMPLATE=subdirs SUBDIRS=\ qcoreapplication \ + qeventdispatcher \ qeventloop \ qmath \ qmetaobject \ qmetaobjectbuilder \ + qmetamethod \ qmetaproperty \ qmetatype \ qmimedata \ diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index 97c9757107..572c2fdfd1 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -126,6 +126,9 @@ void tst_QCoreApplication::qAppName() void tst_QCoreApplication::argc() { +#ifdef Q_OS_WIN + QSKIP("QCoreApplication::arguments() always parses arguments from actual command line in Windows, making this test invalid."); +#endif { int argc = 1; char *argv[] = { "tst_qcoreapplication" }; diff --git a/tests/auto/corelib/kernel/qeventdispatcher/qeventdispatcher.pro b/tests/auto/corelib/kernel/qeventdispatcher/qeventdispatcher.pro new file mode 100644 index 0000000000..ff048d0429 --- /dev/null +++ b/tests/auto/corelib/kernel/qeventdispatcher/qeventdispatcher.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qeventdispatcher +QT = core testlib +SOURCES += tst_qeventdispatcher.cpp diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp new file mode 100644 index 0000000000..bc6d6bfadd --- /dev/null +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -0,0 +1,213 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifdef QT_GUI_LIB +# include <QtGui/QGuiApplication> +#else +# include <QtCore/QCoreApplication> +#endif +#include <QtTest/QtTest> + +enum { + PreciseTimerInterval = 10, + CoarseTimerInterval = 200, + VeryCoarseTimerInterval = 1000 +}; + +class tst_QEventDispatcher : public QObject +{ + Q_OBJECT + + QAbstractEventDispatcher *eventDispatcher; + int receivedEventType; + int timerIdFromEvent; + +protected: + bool event(QEvent *e); + +public: + inline tst_QEventDispatcher() + : QObject(), + eventDispatcher(QAbstractEventDispatcher::instance(thread())), + receivedEventType(-1), + timerIdFromEvent(-1) + { } + +private slots: + void initTestCase(); + void registerTimer(); + /* void registerSocketNotifier(); */ // Not implemented here, see tst_QSocketNotifier instead + /* void registerEventNotifiier(); */ // Not implemented here, see tst_QWinEventNotifier instead + void sendPostedEvents_data(); + void sendPostedEvents(); +}; + +bool tst_QEventDispatcher::event(QEvent *e) +{ + switch (receivedEventType = e->type()) { + case QEvent::Timer: + { + timerIdFromEvent = static_cast<QTimerEvent *>(e)->timerId(); + return true; + } + default: + break; + } + return QObject::event(e); +} + +// drain the system event queue after the test starts to avoid destabilizing the test functions +void tst_QEventDispatcher::initTestCase() +{ + QElapsedTimer elapsedTimer; + elapsedTimer.start(); + while (!elapsedTimer.hasExpired(CoarseTimerInterval) && eventDispatcher->processEvents(QEventLoop::AllEvents)) { + ; + } +} + +// test that the eventDispatcher's timer implementation is complete and working +void tst_QEventDispatcher::registerTimer() +{ +#define FIND_TIMERS() \ + do { \ + foundPrecise = false; \ + foundCoarse = false; \ + foundVeryCoarse = false; \ + for (int i = 0; i < registeredTimers.count(); ++i) { \ + const QAbstractEventDispatcher::TimerInfo &timerInfo = registeredTimers.at(i); \ + if (timerInfo.timerId == preciseTimerId) { \ + QCOMPARE(timerInfo.interval, int(PreciseTimerInterval)); \ + QCOMPARE(timerInfo.timerType, Qt::PreciseTimer); \ + foundPrecise = true; \ + } else if (timerInfo.timerId == coarseTimerId) { \ + QCOMPARE(timerInfo.interval, int(CoarseTimerInterval)); \ + QCOMPARE(timerInfo.timerType, Qt::CoarseTimer); \ + foundCoarse = true; \ + } else if (timerInfo.timerId == veryCoarseTimerId) { \ + QCOMPARE(timerInfo.interval, int(VeryCoarseTimerInterval)); \ + QCOMPARE(timerInfo.timerType, Qt::VeryCoarseTimer); \ + foundVeryCoarse = true; \ + } \ + } \ + } while (0) + + // start 3 timers, each with the different timer types and different intervals + int preciseTimerId = eventDispatcher->registerTimer(PreciseTimerInterval, Qt::PreciseTimer, this); + int coarseTimerId = eventDispatcher->registerTimer(CoarseTimerInterval, Qt::CoarseTimer, this); + int veryCoarseTimerId = eventDispatcher->registerTimer(VeryCoarseTimerInterval, Qt::VeryCoarseTimer, this); + QVERIFY(preciseTimerId > 0); + QVERIFY(coarseTimerId > 0); + QVERIFY(veryCoarseTimerId > 0); + + // check that all 3 are present in the eventDispatcher's registeredTimer() list + QList<QAbstractEventDispatcher::TimerInfo> registeredTimers = eventDispatcher->registeredTimers(this); + QCOMPARE(registeredTimers.count(), 3); + bool foundPrecise, foundCoarse, foundVeryCoarse; + FIND_TIMERS(); + QVERIFY(foundPrecise && foundCoarse && foundVeryCoarse); + + // process events, waiting for the next event... this should only fire the precise timer + receivedEventType = -1; + timerIdFromEvent = -1; + QVERIFY(eventDispatcher->processEvents(QEventLoop::WaitForMoreEvents)); + QCOMPARE(receivedEventType, int(QEvent::Timer)); + QCOMPARE(timerIdFromEvent, preciseTimerId); + // now unregister it and make sure it's gone + eventDispatcher->unregisterTimer(preciseTimerId); + registeredTimers = eventDispatcher->registeredTimers(this); + QCOMPARE(registeredTimers.count(), 2); + FIND_TIMERS(); + QVERIFY(!foundPrecise && foundCoarse && foundVeryCoarse); + + // do the same again for the coarse timer + receivedEventType = -1; + timerIdFromEvent = -1; + QVERIFY(eventDispatcher->processEvents(QEventLoop::WaitForMoreEvents)); + QCOMPARE(receivedEventType, int(QEvent::Timer)); + QCOMPARE(timerIdFromEvent, coarseTimerId); + // now unregister it and make sure it's gone + eventDispatcher->unregisterTimer(coarseTimerId); + registeredTimers = eventDispatcher->registeredTimers(this); + QCOMPARE(registeredTimers.count(), 1); + FIND_TIMERS(); + QVERIFY(!foundPrecise && !foundCoarse && foundVeryCoarse); + + // not going to wait for the VeryCoarseTimer, would take too long, just unregister it + eventDispatcher->unregisterTimers(this); + registeredTimers = eventDispatcher->registeredTimers(this); + QVERIFY(registeredTimers.isEmpty()); + +#undef FIND_TIMERS +} + +void tst_QEventDispatcher::sendPostedEvents_data() +{ + QTest::addColumn<int>("processEventsFlagsInt"); + + QTest::newRow("WaitForMoreEvents") << int(QEventLoop::WaitForMoreEvents); + QTest::newRow("AllEvents") << int(QEventLoop::AllEvents); +} + +// test that the eventDispatcher sends posted events correctly +void tst_QEventDispatcher::sendPostedEvents() +{ + QFETCH(int, processEventsFlagsInt); + QEventLoop::ProcessEventsFlags processEventsFlags = QEventLoop::ProcessEventsFlags(processEventsFlagsInt); + + QElapsedTimer elapsedTimer; + elapsedTimer.start(); + while (!elapsedTimer.hasExpired(200)) { + receivedEventType = -1; + QCoreApplication::postEvent(this, new QEvent(QEvent::User)); + + // event shouldn't be delivered as a result of posting + QCOMPARE(receivedEventType, -1); + + // since there is a pending posted event, this should not actually block, it should send the posted event and return + QVERIFY(eventDispatcher->processEvents(processEventsFlags)); + // event shouldn't be delivered as a result of posting + QCOMPARE(receivedEventType, int(QEvent::User)); + } +} + +QTEST_MAIN(tst_QEventDispatcher) +#include "tst_qeventdispatcher.moc" diff --git a/tests/auto/corelib/kernel/qmetamethod/qmetamethod.pro b/tests/auto/corelib/kernel/qmetamethod/qmetamethod.pro new file mode 100644 index 0000000000..f909742748 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetamethod/qmetamethod.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +TARGET = tst_qmetamethod +QT = core testlib +SOURCES = tst_qmetamethod.cpp +macx:CONFIG -= app_bundle diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp new file mode 100644 index 0000000000..1651d00738 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp @@ -0,0 +1,630 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> + +#include <qobject.h> +#include <qmetaobject.h> + +class tst_QMetaMethod : public QObject +{ + Q_OBJECT + +private slots: + void method_data(); + void method(); + + void invalidMethod(); +}; + +struct CustomType { }; +Q_DECLARE_METATYPE(CustomType) + +struct CustomUnregisteredType { }; + +Q_DECLARE_METATYPE(QMetaMethod::Access) +Q_DECLARE_METATYPE(QMetaMethod::MethodType) + +class MethodTestObject : public QObject +{ + Q_OBJECT +public: + Q_INVOKABLE MethodTestObject(); + Q_INVOKABLE MethodTestObject(int constructorIntArg); + Q_INVOKABLE MethodTestObject(qreal constructorQRealArg); + Q_INVOKABLE MethodTestObject(const QString &constructorQStringArg); + Q_INVOKABLE MethodTestObject(CustomType constructorCustomTypeArg); + Q_INVOKABLE MethodTestObject(CustomUnregisteredType constructorCustomUnregisteredTypeArg); + Q_INVOKABLE MethodTestObject(bool boolArg, int intArg, uint uintArg, + qlonglong longlongArg, qulonglong ulonglongArg, + double doubleArg, long longArg, short shortArg, + char charArg, ulong ulongArg, ushort ushortArg, + uchar ucharArg, float floatArg); + Q_INVOKABLE MethodTestObject(bool, int); + + Q_INVOKABLE void voidInvokable(); + Q_INVOKABLE void voidInvokableInt(int voidInvokableIntArg); + Q_INVOKABLE void voidInvokableQReal(qreal voidInvokableQRealArg); + Q_INVOKABLE void voidInvokableQString(const QString &voidInvokableQStringArg); + Q_INVOKABLE void voidInvokableCustomType(CustomType voidInvokableCustomTypeArg); + Q_INVOKABLE void voidInvokableCustomUnregisteredType(CustomUnregisteredType voidInvokableCustomUnregisteredTypeArg); + Q_INVOKABLE bool boolInvokable(); + Q_INVOKABLE qreal qrealInvokable(); + Q_INVOKABLE QString qstringInvokable(); + Q_INVOKABLE CustomType customTypeInvokable(); + Q_INVOKABLE CustomUnregisteredType customUnregisteredTypeInvokable(); + Q_INVOKABLE QVariant qvariantInvokableBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat( + bool boolArg, int intArg, uint uintArg, qlonglong longlongArg, qulonglong ulonglongArg, double doubleArg, + long longArg, short shortArg, char charArg, ulong ulongArg, ushort ushortArg, uchar ucharArg, float floatArg); + Q_INVOKABLE void voidInvokableNoParameterNames(bool, int); +public slots: + void voidSlot(); + void voidSlotInt(int voidSlotIntArg); + void voidSlotQReal(qreal voidSlotQRealArg); + void voidSlotQString(const QString &voidSlotQStringArg); + void voidSlotCustomType(CustomType voidSlotCustomTypeArg); + void voidSlotCustomUnregisteredType(CustomUnregisteredType voidSlotCustomUnregisteredTypeArg); + bool boolSlot(); + qreal qrealSlot(); + QString qstringSlot(); + CustomType customTypeSlot(); + CustomUnregisteredType customUnregisteredTypeSlot(); + QVariant qvariantSlotBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat( + bool boolArg, int intArg, uint uintArg, qlonglong longlongArg, qulonglong ulonglongArg, double doubleArg, + long longArg, short shortArg, char charArg, ulong ulongArg, ushort ushortArg, uchar ucharArg, float floatArg); + void voidSlotNoParameterNames(bool, int); +signals: + void voidSignal(); + void voidSignalInt(int voidSignalIntArg); + void voidSignalQReal(qreal voidSignalQRealArg); + void voidSignalQString(const QString &voidSignalQStringArg); + void voidSignalCustomType(CustomType voidSignalCustomTypeArg); + void voidSignalCustomUnregisteredType(CustomUnregisteredType voidSignalCustomUnregisteredTypeArg); + bool boolSignal(); + qreal qrealSignal(); + QString qstringSignal(); + CustomType customTypeSignal(); + CustomUnregisteredType customUnregisteredTypeSignal(); + QVariant qvariantSignalBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat( + bool boolArg, int intArg, uint uintArg, qlonglong longlongArg, qulonglong ulonglongArg, double doubleArg, + long longArg, short shortArg, char charArg, ulong ulongArg, ushort ushortArg, uchar ucharArg, float floatArg); + void voidSignalNoParameterNames(bool, int); +}; + +MethodTestObject::MethodTestObject() {} +MethodTestObject::MethodTestObject(int) {} +MethodTestObject::MethodTestObject(qreal) {} +MethodTestObject::MethodTestObject(const QString &) {} +MethodTestObject::MethodTestObject(CustomType) {} +MethodTestObject::MethodTestObject(CustomUnregisteredType) {} +MethodTestObject::MethodTestObject(bool, int, uint, qlonglong, qulonglong, + double, long, short, char, ulong, ushort, + uchar, float) {} +MethodTestObject::MethodTestObject(bool, int) {} + +void MethodTestObject::voidInvokable() {} +void MethodTestObject::voidInvokableInt(int) {} +void MethodTestObject::voidInvokableQReal(qreal) {} +void MethodTestObject::voidInvokableQString(const QString &) {} +void MethodTestObject::voidInvokableCustomType(CustomType) {} +void MethodTestObject::voidInvokableCustomUnregisteredType(CustomUnregisteredType) {} +bool MethodTestObject::boolInvokable() { return true; } +qreal MethodTestObject::qrealInvokable() { return 1.0; } +QString MethodTestObject::qstringInvokable() { return QString(); } +CustomType MethodTestObject::customTypeInvokable() { return CustomType(); } +CustomUnregisteredType MethodTestObject::customUnregisteredTypeInvokable() +{ + return CustomUnregisteredType(); +} +QVariant MethodTestObject::qvariantInvokableBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat( + bool, int, uint, qlonglong, qulonglong, double, long, short, char, ulong, ushort, uchar, float) +{ + return QVariant(); +} +void MethodTestObject::voidInvokableNoParameterNames(bool, int) {} + +void MethodTestObject::voidSlot() {} +void MethodTestObject::voidSlotInt(int) {} +void MethodTestObject::voidSlotQReal(qreal) {} +void MethodTestObject::voidSlotQString(const QString &) {} +void MethodTestObject::voidSlotCustomType(CustomType) {} +void MethodTestObject::voidSlotCustomUnregisteredType(CustomUnregisteredType) {} +bool MethodTestObject::boolSlot() { return true; } +qreal MethodTestObject::qrealSlot() { return 1.0; } +QString MethodTestObject::qstringSlot() { return QString(); } +CustomType MethodTestObject::customTypeSlot() { return CustomType(); } +CustomUnregisteredType MethodTestObject::customUnregisteredTypeSlot() +{ + return CustomUnregisteredType(); +} +QVariant MethodTestObject::qvariantSlotBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat( + bool, int, uint, qlonglong, qulonglong, double, long, short, char, ulong, ushort, uchar, float) +{ + return QVariant(); +} +void MethodTestObject::voidSlotNoParameterNames(bool, int) {} + +void tst_QMetaMethod::method_data() +{ + QTest::addColumn<QByteArray>("signature"); + QTest::addColumn<int>("returnType"); + QTest::addColumn<QByteArray>("returnTypeName"); + QTest::addColumn<QList<int> >("parameterTypes"); + QTest::addColumn<QList<QByteArray> >("parameterTypeNames"); + QTest::addColumn<QList<QByteArray> >("parameterNames"); + QTest::addColumn<QMetaMethod::Access>("access"); + QTest::addColumn<QMetaMethod::MethodType>("methodType"); + + QTest::newRow("voidSignal") + << QByteArray("voidSignal()") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("voidInvokable") + << QByteArray("voidInvokable()") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("voidSlot") + << QByteArray("voidSlot()") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("MethodTestObject()") + << QByteArray("MethodTestObject()") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Constructor; + + QTest::newRow("voidSignalInt") + << QByteArray("voidSignalInt(int)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::Int)) + << (QList<QByteArray>() << QByteArray("int")) + << (QList<QByteArray>() << QByteArray("voidSignalIntArg")) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("voidInvokableInt") + << QByteArray("voidInvokableInt(int)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::Int)) + << (QList<QByteArray>() << QByteArray("int")) + << (QList<QByteArray>() << QByteArray("voidInvokableIntArg")) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("voidSlotInt") + << QByteArray("voidSlotInt(int)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::Int)) + << (QList<QByteArray>() << QByteArray("int")) + << (QList<QByteArray>() << QByteArray("voidSlotIntArg")) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("MethodTestObject(int)") + << QByteArray("MethodTestObject(int)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::Int)) + << (QList<QByteArray>() << QByteArray("int")) + << (QList<QByteArray>() << QByteArray("constructorIntArg")) + << QMetaMethod::Public + << QMetaMethod::Constructor; + + QTest::newRow("voidSignalQReal") + << QByteArray("voidSignalQReal(qreal)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << qMetaTypeId<qreal>()) + << (QList<QByteArray>() << QByteArray("qreal")) + << (QList<QByteArray>() << QByteArray("voidSignalQRealArg")) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("voidInvokableQReal") + << QByteArray("voidInvokableQReal(qreal)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << qMetaTypeId<qreal>()) + << (QList<QByteArray>() << QByteArray("qreal")) + << (QList<QByteArray>() << QByteArray("voidInvokableQRealArg")) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("voidSlotQReal") + << QByteArray("voidSlotQReal(qreal)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << qMetaTypeId<qreal>()) + << (QList<QByteArray>() << QByteArray("qreal")) + << (QList<QByteArray>() << QByteArray("voidSlotQRealArg")) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("MethodTestObject(qreal)") + << QByteArray("MethodTestObject(qreal)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << qMetaTypeId<qreal>()) + << (QList<QByteArray>() << QByteArray("qreal")) + << (QList<QByteArray>() << QByteArray("constructorQRealArg")) + << QMetaMethod::Public + << QMetaMethod::Constructor; + + QTest::newRow("voidSignalQString") + << QByteArray("voidSignalQString(QString)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::QString)) + << (QList<QByteArray>() << QByteArray("QString")) + << (QList<QByteArray>() << QByteArray("voidSignalQStringArg")) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("voidInvokableQString") + << QByteArray("voidInvokableQString(QString)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::QString)) + << (QList<QByteArray>() << QByteArray("QString")) + << (QList<QByteArray>() << QByteArray("voidInvokableQStringArg")) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("voidSlotQString") + << QByteArray("voidSlotQString(QString)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::QString)) + << (QList<QByteArray>() << QByteArray("QString")) + << (QList<QByteArray>() << QByteArray("voidSlotQStringArg")) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("MethodTestObject(QString)") + << QByteArray("MethodTestObject(QString)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::QString)) + << (QList<QByteArray>() << QByteArray("QString")) + << (QList<QByteArray>() << QByteArray("constructorQStringArg")) + << QMetaMethod::Public + << QMetaMethod::Constructor; + + QTest::newRow("voidSignalCustomType") + << QByteArray("voidSignalCustomType(CustomType)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << qMetaTypeId<CustomType>()) + << (QList<QByteArray>() << QByteArray("CustomType")) + << (QList<QByteArray>() << QByteArray("voidSignalCustomTypeArg")) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("voidInvokableCustomType") + << QByteArray("voidInvokableCustomType(CustomType)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << qMetaTypeId<CustomType>()) + << (QList<QByteArray>() << QByteArray("CustomType")) + << (QList<QByteArray>() << QByteArray("voidInvokableCustomTypeArg")) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("voidSlotCustomType") + << QByteArray("voidSlotCustomType(CustomType)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << qMetaTypeId<CustomType>()) + << (QList<QByteArray>() << QByteArray("CustomType")) + << (QList<QByteArray>() << QByteArray("voidSlotCustomTypeArg")) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("MethodTestObject(CustomType)") + << QByteArray("MethodTestObject(CustomType)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << qMetaTypeId<CustomType>()) + << (QList<QByteArray>() << QByteArray("CustomType")) + << (QList<QByteArray>() << QByteArray("constructorCustomTypeArg")) + << QMetaMethod::Public + << QMetaMethod::Constructor; + + QTest::newRow("voidSignalCustomUnregisteredType") + << QByteArray("voidSignalCustomUnregisteredType(CustomUnregisteredType)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << 0) + << (QList<QByteArray>() << QByteArray("CustomUnregisteredType")) + << (QList<QByteArray>() << QByteArray("voidSignalCustomUnregisteredTypeArg")) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("voidInvokableCustomUnregisteredType") + << QByteArray("voidInvokableCustomUnregisteredType(CustomUnregisteredType)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << 0) + << (QList<QByteArray>() << QByteArray("CustomUnregisteredType")) + << (QList<QByteArray>() << QByteArray("voidInvokableCustomUnregisteredTypeArg")) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("voidSlotCustomUnregisteredType") + << QByteArray("voidSlotCustomUnregisteredType(CustomUnregisteredType)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << 0) + << (QList<QByteArray>() << QByteArray("CustomUnregisteredType")) + << (QList<QByteArray>() << QByteArray("voidSlotCustomUnregisteredTypeArg")) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("MethodTestObject(CustomUnregisteredType)") + << QByteArray("MethodTestObject(CustomUnregisteredType)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << 0) + << (QList<QByteArray>() << QByteArray("CustomUnregisteredType")) + << (QList<QByteArray>() << QByteArray("constructorCustomUnregisteredTypeArg")) + << QMetaMethod::Public + << QMetaMethod::Constructor; + + QTest::newRow("boolSignal") + << QByteArray("boolSignal()") + << int(QMetaType::Bool) << QByteArray("bool") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("boolInvokable") + << QByteArray("boolInvokable()") + << int(QMetaType::Bool) << QByteArray("bool") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("boolSlot") + << QByteArray("boolSlot()") + << int(QMetaType::Bool) << QByteArray("bool") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("qrealSignal") + << QByteArray("qrealSignal()") + << int(QMetaType::QReal) << QByteArray("qreal") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("qrealInvokable") + << QByteArray("qrealInvokable()") + << int(QMetaType::QReal) << QByteArray("qreal") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("qrealSlot") + << QByteArray("qrealSlot()") + << int(QMetaType::QReal) << QByteArray("qreal") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("qstringSignal") + << QByteArray("qstringSignal()") + << int(QMetaType::QString) << QByteArray("QString") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("qstringInvokable") + << QByteArray("qstringInvokable()") + << int(QMetaType::QString) << QByteArray("QString") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("qstringSlot") + << QByteArray("qstringSlot()") + << int(QMetaType::QString) << QByteArray("QString") + << (QList<int>()) + << (QList<QByteArray>()) + << (QList<QByteArray>()) + << QMetaMethod::Public + << QMetaMethod::Slot; + + { + QList<int> parameterTypes = QList<int>() + << int(QMetaType::Bool) << int(QMetaType::Int) << int(QMetaType::UInt) + << int(QMetaType::LongLong) << int(QMetaType::ULongLong) << int(QMetaType::Double) + << int(QMetaType::Long) << int(QMetaType::Short) << int(QMetaType::Char) + << int(QMetaType::ULong) << int(QMetaType::UShort) << int(QMetaType::UChar) + << int(QMetaType::Float); + QList<QByteArray> parameterTypeNames = QList<QByteArray>() + << QByteArray("bool") << QByteArray("int") << QByteArray("uint") + << QByteArray("qlonglong") << QByteArray("qulonglong") << QByteArray("double") + << QByteArray("long") << QByteArray("short") << QByteArray("char") << QByteArray("ulong") + << QByteArray("ushort") << QByteArray("uchar") << QByteArray("float"); + QList<QByteArray> parameterNames = QList<QByteArray>() + << QByteArray("boolArg") << QByteArray("intArg") << QByteArray("uintArg") + << QByteArray("longlongArg") << QByteArray("ulonglongArg") << QByteArray("doubleArg") + << QByteArray("longArg") << QByteArray("shortArg") << QByteArray("charArg") + << QByteArray("ulongArg") << QByteArray("ushortArg") << QByteArray("ucharArg") + << QByteArray("floatArg"); + + QTest::newRow("qvariantSignalBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat") + << QByteArray("qvariantSignalBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat(" + "bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)") + << int(QMetaType::QVariant) << QByteArray("QVariant") + << parameterTypes << parameterTypeNames << parameterNames + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("qvariantInvokableBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat") + << QByteArray("qvariantInvokableBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat(" + "bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)") + << int(QMetaType::QVariant) << QByteArray("QVariant") + << parameterTypes << parameterTypeNames << parameterNames + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("qvariantSlotBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat") + << QByteArray("qvariantSlotBoolIntUIntLonglongULonglongDoubleLongShortCharUlongUshortUcharFloat(" + "bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)") + << int(QMetaType::QVariant) << QByteArray("QVariant") + << parameterTypes << parameterTypeNames << parameterNames + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("MethodTestObject(bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)") + << QByteArray("MethodTestObject(bool,int,uint,qlonglong,qulonglong,double,long,short,char,ulong,ushort,uchar,float)") + << int(QMetaType::Void) << QByteArray("") + << parameterTypes << parameterTypeNames << parameterNames + << QMetaMethod::Public + << QMetaMethod::Constructor; + } + + QTest::newRow("voidSignalNoParameterNames") + << QByteArray("voidSignalNoParameterNames(bool,int)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int)) + << (QList<QByteArray>() << QByteArray("bool") << QByteArray("int")) + << (QList<QByteArray>() << QByteArray("") << QByteArray("")) + << QMetaMethod::Protected + << QMetaMethod::Signal; + + QTest::newRow("voidInvokableNoParameterNames") + << QByteArray("voidInvokableNoParameterNames(bool,int)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int)) + << (QList<QByteArray>() << QByteArray("bool") << QByteArray("int")) + << (QList<QByteArray>() << QByteArray("") << QByteArray("")) + << QMetaMethod::Public + << QMetaMethod::Method; + + QTest::newRow("voidSlotNoParameterNames") + << QByteArray("voidSlotNoParameterNames(bool,int)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int)) + << (QList<QByteArray>() << QByteArray("bool") << QByteArray("int")) + << (QList<QByteArray>() << QByteArray("") << QByteArray("")) + << QMetaMethod::Public + << QMetaMethod::Slot; + + QTest::newRow("MethodTestObject(bool,int)") + << QByteArray("MethodTestObject(bool,int)") + << int(QMetaType::Void) << QByteArray("") + << (QList<int>() << int(QMetaType::Bool) << int(QMetaType::Int)) + << (QList<QByteArray>() << QByteArray("bool") << QByteArray("int")) + << (QList<QByteArray>() << QByteArray("") << QByteArray("")) + << QMetaMethod::Public + << QMetaMethod::Constructor; +} + +void tst_QMetaMethod::method() +{ + QFETCH(QByteArray, signature); + QFETCH(int, returnType); + QFETCH(QByteArray, returnTypeName); + QFETCH(QList<int>, parameterTypes); + QFETCH(QList<QByteArray>, parameterTypeNames); + QFETCH(QList<QByteArray>, parameterNames); + QFETCH(QMetaMethod::MethodType, methodType); + QFETCH(QMetaMethod::Access, access); + + QVERIFY(parameterTypes.size() == parameterTypeNames.size()); + QVERIFY(parameterTypes.size() == parameterNames.size()); + + const QMetaObject *mo = &MethodTestObject::staticMetaObject; + int index = (methodType == QMetaMethod::Constructor) + ? mo->indexOfConstructor(signature) : mo->indexOfMethod(signature); + QVERIFY(index != -1); + QMetaMethod method = (methodType == QMetaMethod::Constructor) + ? mo->constructor(index) : mo->method(index); + QVERIFY(method.isValid()); + QCOMPARE(method.methodType(), methodType); + QCOMPARE(method.access(), access); + + QCOMPARE(method.signature(), signature.constData()); + + QCOMPARE(method.tag(), ""); + + QCOMPARE(method.typeName(), returnTypeName.constData()); + QCOMPARE(QMetaType::type(method.typeName()), returnType); + + QCOMPARE(method.parameterTypes(), parameterTypeNames); + QCOMPARE(method.parameterNames(), parameterNames); +} + +void tst_QMetaMethod::invalidMethod() +{ + QMetaMethod method; + QVERIFY(!method.isValid()); + + QMetaMethod method2 = staticMetaObject.method(staticMetaObject.methodCount()); + QVERIFY(!method2.isValid()); + + QMetaMethod method3 = staticMetaObject.method(-1); + QVERIFY(!method3.isValid()); +} + +QTEST_MAIN(tst_QMetaMethod) +#include "tst_qmetamethod.moc" diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp index def1b74ea4..97b14a374e 100644 --- a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp +++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -64,6 +64,7 @@ private slots: void staticMetacall(); void copyMetaObject(); void serialize(); + void relocatableData(); void removeNotifySignal(); void usage_signal(); @@ -90,6 +91,7 @@ class SomethingOfEverything : public QObject Q_CLASSINFO("ci_bar", "DEF") Q_PROPERTY(QString prop READ prop WRITE setProp NOTIFY propChanged) Q_PROPERTY(QString prop2 READ prop WRITE setProp) + Q_PROPERTY(QString revisionProp READ prop WRITE setProp REVISION 42) Q_PROPERTY(SomethingEnum eprop READ eprop) Q_PROPERTY(SomethingFlagEnum fprop READ fprop) Q_PROPERTY(QLocale::Language language READ language) @@ -123,6 +125,7 @@ public: public slots: void slot1(const QString&) {} void slot2(int, const QString&) {} + Q_REVISION(24) void revisionSlot() {} private slots: void slot3() {} @@ -218,6 +221,7 @@ void tst_QMetaObjectBuilder::method() QVERIFY(nullMethod.tag().isEmpty()); QVERIFY(nullMethod.access() == QMetaMethod::Public); QCOMPARE(nullMethod.attributes(), 0); + QCOMPARE(nullMethod.revision(), 0); QCOMPARE(nullMethod.index(), 0); // Add a method and check its attributes. @@ -229,6 +233,7 @@ void tst_QMetaObjectBuilder::method() QVERIFY(method1.tag().isEmpty()); QVERIFY(method1.access() == QMetaMethod::Public); QCOMPARE(method1.attributes(), 0); + QCOMPARE(method1.revision(), 0); QCOMPARE(method1.index(), 0); QCOMPARE(builder.methodCount(), 1); @@ -241,6 +246,7 @@ void tst_QMetaObjectBuilder::method() QVERIFY(method2.tag().isEmpty()); QVERIFY(method2.access() == QMetaMethod::Public); QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.revision(), 0); QCOMPARE(method2.index(), 1); QCOMPARE(builder.methodCount(), 2); @@ -255,6 +261,7 @@ void tst_QMetaObjectBuilder::method() method1.setTag("tag"); method1.setAccess(QMetaMethod::Private); method1.setAttributes(42); + method1.setRevision(123); // Check that method1 is changed, but method2 is not. QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); @@ -264,6 +271,7 @@ void tst_QMetaObjectBuilder::method() QCOMPARE(method1.tag(), QByteArray("tag")); QVERIFY(method1.access() == QMetaMethod::Private); QCOMPARE(method1.attributes(), 42); + QCOMPARE(method1.revision(), 123); QCOMPARE(method1.index(), 0); QCOMPARE(method2.signature(), QByteArray("bar(QString)")); QVERIFY(method2.methodType() == QMetaMethod::Method); @@ -272,6 +280,7 @@ void tst_QMetaObjectBuilder::method() QVERIFY(method2.tag().isEmpty()); QVERIFY(method2.access() == QMetaMethod::Public); QCOMPARE(method2.attributes(), 0); + QCOMPARE(method2.revision(), 0); QCOMPARE(method2.index(), 1); QCOMPARE(builder.methodCount(), 2); @@ -281,6 +290,7 @@ void tst_QMetaObjectBuilder::method() method2.setTag("Q_FOO"); method2.setAccess(QMetaMethod::Protected); method2.setAttributes(24); + method2.setRevision(321); // This time check that only method2 changed. QCOMPARE(method1.signature(), QByteArray("foo(QString,int)")); @@ -290,6 +300,7 @@ void tst_QMetaObjectBuilder::method() QCOMPARE(method1.tag(), QByteArray("tag")); QVERIFY(method1.access() == QMetaMethod::Private); QCOMPARE(method1.attributes(), 42); + QCOMPARE(method1.revision(), 123); QCOMPARE(method1.index(), 0); QCOMPARE(method2.signature(), QByteArray("bar(QString)")); QVERIFY(method2.methodType() == QMetaMethod::Method); @@ -298,6 +309,7 @@ void tst_QMetaObjectBuilder::method() QCOMPARE(method2.tag(), QByteArray("Q_FOO")); QVERIFY(method2.access() == QMetaMethod::Protected); QCOMPARE(method2.attributes(), 24); + QCOMPARE(method2.revision(), 321); QCOMPARE(method2.index(), 1); QCOMPARE(builder.methodCount(), 2); @@ -312,6 +324,7 @@ void tst_QMetaObjectBuilder::method() QCOMPARE(method2.tag(), QByteArray("Q_FOO")); QVERIFY(method2.access() == QMetaMethod::Protected); QCOMPARE(method2.attributes(), 24); + QCOMPARE(method2.revision(), 321); QCOMPARE(method2.index(), 0); // Perform index-based lookup again. @@ -541,6 +554,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!nullProp.isConstant()); QVERIFY(!nullProp.isFinal()); QCOMPARE(nullProp.index(), 0); + QCOMPARE(nullProp.revision(), 0); // Add a property and check its attributes. QMetaPropertyBuilder prop1 = builder.addProperty("foo", "const QString &"); @@ -559,6 +573,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop1.isEnumOrFlag()); QVERIFY(!prop1.isConstant()); QVERIFY(!prop1.isFinal()); + QCOMPARE(prop1.revision(), 0); QCOMPARE(prop1.index(), 0); QCOMPARE(builder.propertyCount(), 1); @@ -579,6 +594,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isEnumOrFlag()); QVERIFY(!prop2.isConstant()); QVERIFY(!prop2.isFinal()); + QCOMPARE(prop2.revision(), 0); QCOMPARE(prop2.index(), 1); QCOMPARE(builder.propertyCount(), 2); @@ -602,6 +618,7 @@ void tst_QMetaObjectBuilder::property() prop1.setEnumOrFlag(true); prop1.setConstant(true); prop1.setFinal(true); + prop1.setRevision(123); // Check that prop1 is changed, but prop2 is not. QCOMPARE(prop1.name(), QByteArray("foo")); @@ -618,6 +635,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(prop1.isEnumOrFlag()); QVERIFY(prop1.isConstant()); QVERIFY(prop1.isFinal()); + QCOMPARE(prop1.revision(), 123); QVERIFY(prop2.isReadable()); QVERIFY(prop2.isWritable()); QCOMPARE(prop2.name(), QByteArray("bar")); @@ -632,6 +650,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isEnumOrFlag()); QVERIFY(!prop2.isConstant()); QVERIFY(!prop2.isFinal()); + QCOMPARE(prop2.revision(), 0); // Remove prop1 and check that prop2 becomes index 0. builder.removeProperty(0); @@ -649,6 +668,7 @@ void tst_QMetaObjectBuilder::property() QVERIFY(!prop2.isEnumOrFlag()); QVERIFY(!prop2.isConstant()); QVERIFY(!prop2.isFinal()); + QCOMPARE(prop2.revision(), 0); QCOMPARE(prop2.index(), 0); // Perform index-based lookup again. @@ -1028,6 +1048,39 @@ void tst_QMetaObjectBuilder::serialize() } } +void tst_QMetaObjectBuilder::relocatableData() +{ + QMetaObjectBuilder builder; + builder.setClassName("TestObject"); + + QMetaMethodBuilder intPropChanged = builder.addSignal("intPropChanged(int)"); + intPropChanged.setParameterNames(QList<QByteArray>() << "newIntPropValue"); + + QMetaPropertyBuilder prop = builder.addProperty("intProp", "int"); + prop.setNotifySignal(intPropChanged); + + QMetaMethodBuilder voidSlotInt = builder.addSlot("voidSlotInt(int)"); + voidSlotInt.setParameterNames(QList<QByteArray>() << "slotIntArg"); + + QMetaMethodBuilder listInvokableQRealQString = builder.addMethod("listInvokableQRealQString(qreal,QString)"); + listInvokableQRealQString.setReturnType("QVariantList"); + listInvokableQRealQString.setParameterNames(QList<QByteArray>() << "qrealArg" << "qstringArg"); + + bool ok = false; + QByteArray data = builder.toRelocatableData(&ok); + QVERIFY(ok); + + QMetaObjectBuilder builder2; + QMetaObject meta2; + builder2.fromRelocatableData(&meta2, &QObject::staticMetaObject, data); + + QMetaObject *meta = builder.toMetaObject(); + + QVERIFY(sameMetaObject(meta, &meta2)); + free(meta); +} + + // Check that removing a method updates notify signals appropriately void tst_QMetaObjectBuilder::removeNotifySignal() { @@ -1129,6 +1182,9 @@ static bool sameMethod(const QMetaMethod& method1, const QMetaMethod& method2) if (method1.attributes() != method2.attributes()) return false; + if (method1.revision() != method2.revision()) + return false; + return true; } @@ -1159,6 +1215,9 @@ static bool sameProperty(const QMetaProperty& prop1, const QMetaProperty& prop2) return false; } + if (prop1.revision() != prop2.revision()) + return false; + return true; } @@ -1282,11 +1341,11 @@ class TestObject : public QObject // Manually expanded from Q_OBJECT macro public: Q_OBJECT_CHECK + static QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); private: - Q_DECL_HIDDEN static const QMetaObjectExtraData staticMetaObjectExtraData; Q_DECL_HIDDEN static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); //Q_PROPERTY(int intProp READ intProp WRITE setIntProp NOTIFY intPropChanged) @@ -1319,14 +1378,15 @@ private: int m_voidSlotIntArg; }; -const QMetaObjectExtraData TestObject::staticMetaObjectExtraData = { - 0, qt_static_metacall +QMetaObject TestObject::staticMetaObject = { + { 0, 0, 0, 0 } }; TestObject::TestObject(QObject *parent) : QObject(parent), m_metaObject(buildMetaObject()), m_intProp(-1), m_voidSlotIntArg(-1) { + staticMetaObject = *m_metaObject; } TestObject::~TestObject() @@ -1422,9 +1482,6 @@ void TestObject::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, } } } else if (_c == QMetaObject::IndexOfMethod) { - // This code is currently unreachable because it's only used by the - // template-based versions of connect() and disconnect(), which don't - // work with dynamically generated meta-objects (see test). int *result = reinterpret_cast<int *>(_a[0]); void **func = reinterpret_cast<void **>(_a[1]); { @@ -1445,7 +1502,6 @@ void TestObject::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, *result = 2; } } - qFatal("You forgot to add one or more IndexOfMethod cases"); } } @@ -1609,11 +1665,22 @@ void tst_QMetaObjectBuilder::usage_templateConnect() { QScopedPointer<TestObject> testObject(new TestObject); - QTest::ignoreMessage(QtWarningMsg, "QObject::connect: signal not found in QObject"); QMetaObject::Connection con = QObject::connect(testObject.data(), &TestObject::intPropChanged, testObject.data(), &TestObject::voidSlotInt); - QEXPECT_FAIL("", "template-based connect() fails because meta-object is deduced at compile-time", Abort); QVERIFY(con); + + QVERIFY(testObject->voidSlotIntArgument() == -1); + testObject->setProperty("intProp", 123); + QCOMPARE(testObject->voidSlotIntArgument(), 123); + + QVERIFY(QObject::disconnect(testObject.data(), &TestObject::intPropChanged, + testObject.data(), &TestObject::voidSlotInt)); + + // Something that isn't a signal + QTest::ignoreMessage(QtWarningMsg, "QObject::connect: signal not found in TestObject"); + con = QObject::connect(testObject.data(), &TestObject::setIntProp, + testObject.data(), &TestObject::intPropChanged); + QVERIFY(!con); } QTEST_MAIN(tst_QMetaObjectBuilder) diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index be13b39e7e..72913d10f2 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -78,16 +78,22 @@ private slots: void createCopy(); void sizeOf_data(); void sizeOf(); + void sizeOfStaticLess_data(); + void sizeOfStaticLess(); void flags_data(); void flags(); + void flagsStaticLess_data(); + void flagsStaticLess(); void construct_data(); void construct(); void constructCopy_data(); void constructCopy(); void typedefs(); + void registerType(); void isRegistered_data(); void isRegistered(); - void unregisterType(); + void isRegisteredStaticLess_data(); + void isRegisteredStaticLess(); void registerStreamBuiltin(); void automaticTemplateRegistration(); }; @@ -125,6 +131,9 @@ class MetaTypeTorturer: public QThread protected: void run() { + Bar space[1]; + space[0].~Bar(); + for (int i = 0; i < 1000; ++i) { const QByteArray name = QString("Bar%1_%2").arg(i).arg((size_t)QThread::currentThreadId()).toLatin1(); const char *nm = name.constData(); @@ -132,6 +141,15 @@ protected: #ifdef Q_OS_LINUX pthread_yield(); #endif + QMetaType info(tp); + if (!info.isValid()) { + ++failureCount; + qWarning() << "Wrong typeInfo returned for" << tp; + } + if (!info.isRegistered()) { + ++failureCount; + qWarning() << name << "is not a registered metatype"; + } if (QMetaType::typeFlags(tp) != (QMetaType::NeedsConstruction | QMetaType::NeedsDestruction)) { ++failureCount; qWarning() << "Wrong typeInfo returned for" << tp; @@ -148,9 +166,22 @@ protected: ++failureCount; qWarning() << "Wrong typeName returned for" << tp; } - void *buf = QMetaType::create(tp, 0); - void *buf2 = QMetaType::create(tp, buf); - if (!buf) { + void *buf1 = QMetaType::create(tp, 0); + void *buf2 = QMetaType::create(tp, buf1); + void *buf3 = info.create(tp, 0); + void *buf4 = info.create(tp, buf1); + + QMetaType::construct(tp, space, 0); + QMetaType::destruct(tp, space); + QMetaType::construct(tp, space, buf1); + QMetaType::destruct(tp, space); + + info.construct(space, 0); + info.destruct(space); + info.construct(space, buf1); + info.destruct(space); + + if (!buf1) { ++failureCount; qWarning() << "Null buffer returned by QMetaType::create(tp, 0)"; } @@ -158,9 +189,20 @@ protected: ++failureCount; qWarning() << "Null buffer returned by QMetaType::create(tp, buf)"; } - QMetaType::destroy(tp, buf); + if (!buf3) { + ++failureCount; + qWarning() << "Null buffer returned by info.create(tp, 0)"; + } + if (!buf4) { + ++failureCount; + qWarning() << "Null buffer returned by infocreate(tp, buf)"; + } + QMetaType::destroy(tp, buf1); QMetaType::destroy(tp, buf2); + info.destroy(buf3); + info.destroy(buf4); } + new (space) Bar; } public: MetaTypeTorturer() : failureCount(0) { } @@ -480,13 +522,17 @@ template<int ID> static void testCreateHelper() { typedef typename MetaEnumToType<ID>::Type Type; - void *actual = QMetaType::create(ID); + QMetaType info(ID); + void *actual1 = QMetaType::create(ID); + void *actual2 = info.create(); if (DefaultValueTraits<ID>::IsInitialized) { Type *expected = DefaultValueFactory<ID>::create(); - QCOMPARE(*static_cast<Type *>(actual), *expected); + QCOMPARE(*static_cast<Type *>(actual1), *expected); + QCOMPARE(*static_cast<Type *>(actual2), *expected); delete expected; } - QMetaType::destroy(ID, actual); + QMetaType::destroy(ID, actual1); + info.destroy(actual2); } template<> @@ -529,9 +575,13 @@ static void testCreateCopyHelper() { typedef typename MetaEnumToType<ID>::Type Type; Type *expected = TestValueFactory<ID>::create(); - void *actual = QMetaType::create(ID, expected); - QCOMPARE(*static_cast<Type *>(actual), *expected); - QMetaType::destroy(ID, actual); + QMetaType info(ID); + void *actual1 = QMetaType::create(ID, expected); + void *actual2 = info.create(expected); + QCOMPARE(*static_cast<Type *>(actual1), *expected); + QCOMPARE(*static_cast<Type *>(actual2), *expected); + QMetaType::destroy(ID, actual1); + info.destroy(actual2); delete expected; } @@ -588,6 +638,18 @@ void tst_QMetaType::sizeOf() QCOMPARE(QMetaType::sizeOf(type), size); } +void tst_QMetaType::sizeOfStaticLess_data() +{ + sizeOf_data(); +} + +void tst_QMetaType::sizeOfStaticLess() +{ + QFETCH(QMetaType::Type, type); + QFETCH(int, size); + QCOMPARE(QMetaType(type).sizeOf(), size); +} + struct CustomMovable {}; QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(CustomMovable, Q_MOVABLE_TYPE); @@ -653,6 +715,23 @@ void tst_QMetaType::flags() QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::PointerToQObject), isPointerToQObject); } +void tst_QMetaType::flagsStaticLess_data() +{ + flags_data(); +} + +void tst_QMetaType::flagsStaticLess() +{ + QFETCH(int, type); + QFETCH(bool, isMovable); + QFETCH(bool, isComplex); + + int flags = QMetaType(type).flags(); + QCOMPARE(bool(flags & QMetaType::NeedsConstruction), isComplex); + QCOMPARE(bool(flags & QMetaType::NeedsDestruction), isComplex); + QCOMPARE(bool(flags & QMetaType::MovableType), isMovable); +} + void tst_QMetaType::construct_data() { create_data(); @@ -688,20 +767,30 @@ template<int ID> static void testConstructHelper() { typedef typename MetaEnumToType<ID>::Type Type; - int size = QMetaType::sizeOf(ID); - void *storage = qMallocAligned(size, TypeAlignment<Type>::Value); - void *actual = QMetaType::construct(ID, storage, /*copy=*/0); - QCOMPARE(actual, storage); + QMetaType info(ID); + int size = info.sizeOf(); + void *storage1 = qMallocAligned(size, TypeAlignment<Type>::Value); + void *actual1 = QMetaType::construct(ID, storage1, /*copy=*/0); + void *storage2 = qMallocAligned(size, TypeAlignment<Type>::Value); + void *actual2 = info.construct(storage2, /*copy=*/0); + QCOMPARE(actual1, storage1); + QCOMPARE(actual2, storage2); if (DefaultValueTraits<ID>::IsInitialized) { Type *expected = DefaultValueFactory<ID>::create(); - QCOMPARE(*static_cast<Type *>(actual), *expected); + QCOMPARE(*static_cast<Type *>(actual1), *expected); + QCOMPARE(*static_cast<Type *>(actual2), *expected); delete expected; } - QMetaType::destruct(ID, actual); - qFreeAligned(storage); + QMetaType::destruct(ID, actual1); + qFreeAligned(storage1); + info.destruct(actual2); + qFreeAligned(storage2); QVERIFY(QMetaType::construct(ID, 0, /*copy=*/0) == 0); QMetaType::destruct(ID, 0); + + QVERIFY(info.construct(0, /*copy=*/0) == 0); + info.destruct(0); } template<> @@ -748,15 +837,24 @@ static void testConstructCopyHelper() { typedef typename MetaEnumToType<ID>::Type Type; Type *expected = TestValueFactory<ID>::create(); + QMetaType info(ID); int size = QMetaType::sizeOf(ID); - void *storage = qMallocAligned(size, TypeAlignment<Type>::Value); - void *actual = QMetaType::construct(ID, storage, expected); - QCOMPARE(actual, storage); - QCOMPARE(*static_cast<Type *>(actual), *expected); - QMetaType::destruct(ID, actual); - qFreeAligned(storage); + QCOMPARE(info.sizeOf(), size); + void *storage1 = qMallocAligned(size, TypeAlignment<Type>::Value); + void *actual1 = QMetaType::construct(ID, storage1, expected); + void *storage2 = qMallocAligned(size, TypeAlignment<Type>::Value); + void *actual2 = info.construct(storage2, expected); + QCOMPARE(actual1, storage1); + QCOMPARE(actual2, storage2); + QCOMPARE(*static_cast<Type *>(actual1), *expected); + QCOMPARE(*static_cast<Type *>(actual2), *expected); + QMetaType::destruct(ID, actual1); + qFreeAligned(storage1); + info.destruct(actual2); + qFreeAligned(storage2); QVERIFY(QMetaType::construct(ID, 0, expected) == 0); + QVERIFY(info.construct(0, expected) == 0); delete expected; } @@ -829,6 +927,44 @@ void tst_QMetaType::typedefs() QCOMPARE(QMetaType::type("WhityDouble"), ::qMetaTypeId<WhityDouble>()); } +void tst_QMetaType::registerType() +{ + // Built-in + QCOMPARE(qRegisterMetaType<QString>("QString"), int(QMetaType::QString)); + QCOMPARE(qRegisterMetaType<QString>("QString"), int(QMetaType::QString)); + + // Custom + int fooId = qRegisterMetaType<TestSpace::Foo>("TestSpace::Foo"); + QVERIFY(fooId >= int(QMetaType::User)); + QCOMPARE(qRegisterMetaType<TestSpace::Foo>("TestSpace::Foo"), fooId); + + int movableId = qRegisterMetaType<CustomMovable>("CustomMovable"); + QVERIFY(movableId >= int(QMetaType::User)); + QCOMPARE(qRegisterMetaType<CustomMovable>("CustomMovable"), movableId); + + // Alias to built-in + typedef QString MyString; + + QCOMPARE(qRegisterMetaType<MyString>("MyString"), int(QMetaType::QString)); + QCOMPARE(qRegisterMetaType<MyString>("MyString"), int(QMetaType::QString)); + + QCOMPARE(QMetaType::type("MyString"), int(QMetaType::QString)); + + // Alias to custom type + typedef CustomMovable MyMovable; + typedef TestSpace::Foo MyFoo; + + QCOMPARE(qRegisterMetaType<MyMovable>("MyMovable"), movableId); + QCOMPARE(qRegisterMetaType<MyMovable>("MyMovable"), movableId); + + QCOMPARE(QMetaType::type("MyMovable"), movableId); + + QCOMPARE(qRegisterMetaType<MyFoo>("MyFoo"), fooId); + QCOMPARE(qRegisterMetaType<MyFoo>("MyFoo"), fooId); + + QCOMPARE(QMetaType::type("MyFoo"), fooId); +} + class IsRegisteredDummyType { }; void tst_QMetaType::isRegistered_data() @@ -857,26 +993,16 @@ void tst_QMetaType::isRegistered() QCOMPARE(QMetaType::isRegistered(typeId), registered); } -class RegUnreg +void tst_QMetaType::isRegisteredStaticLess_data() { -public: - RegUnreg() {}; - RegUnreg(const RegUnreg &) {}; - ~RegUnreg() {}; -}; - -void tst_QMetaType::unregisterType() -{ - // cannot unregister standard types - int typeId = qRegisterMetaType<QList<QVariant> >("QList<QVariant>"); - QCOMPARE(QMetaType::isRegistered(typeId), true); - QMetaType::unregisterType("QList<QVariant>"); - QCOMPARE(QMetaType::isRegistered(typeId), true); - // allow unregister user types - typeId = qRegisterMetaType<RegUnreg>("RegUnreg"); - QCOMPARE(QMetaType::isRegistered(typeId), true); - QMetaType::unregisterType("RegUnreg"); - QCOMPARE(QMetaType::isRegistered(typeId), false); + isRegistered_data(); +} + +void tst_QMetaType::isRegisteredStaticLess() +{ + QFETCH(int, typeId); + QFETCH(bool, registered); + QCOMPARE(QMetaType(typeId).isRegistered(), registered); } void tst_QMetaType::registerStreamBuiltin() diff --git a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp index 09f17602b3..f9a6bae087 100644 --- a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp +++ b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp @@ -317,19 +317,22 @@ void tst_QMimeData::setUrls() const longUrlList += QUrl("http://www.google.com"); // verify initial state - QVERIFY(mimeData.hasUrls() == false); + QCOMPARE(mimeData.hasUrls(), false); // set a few, verify mimeData.setUrls(shortUrlList); QCOMPARE(mimeData.urls(), shortUrlList); + QCOMPARE(mimeData.text(), QString("http://qt.nokia.com")); // change them, verify mimeData.setUrls(longUrlList); QCOMPARE(mimeData.urls(), longUrlList); + QCOMPARE(mimeData.text(), QString("http://qt.nokia.com\nhttp://www.google.com\n")); // clear, verify mimeData.clear(); - QVERIFY(mimeData.hasUrls() == false); + QCOMPARE(mimeData.hasUrls(), false); + QCOMPARE(mimeData.hasText(), false); } QTEST_MAIN(tst_QMimeData) diff --git a/tests/auto/corelib/kernel/qobject/qobject.pro b/tests/auto/corelib/kernel/qobject/qobject.pro index ee48f56b1d..0f86408fc9 100644 --- a/tests/auto/corelib/kernel/qobject/qobject.pro +++ b/tests/auto/corelib/kernel/qobject/qobject.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs -SUBDIRS = signalbug tst_qobject.pro -CONFIG += parallel_test +SUBDIRS = signalbug +tst_qobject.pro.depends = $$SUBDIRS +SUBDIRS += tst_qobject.pro diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 7f95f68075..a6ad1d53bc 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -1703,7 +1703,9 @@ void tst_QObject::property() QVERIFY(property.isWritable()); QVERIFY(!property.isEnumType()); QCOMPARE(property.typeName(), "CustomType*"); + qRegisterMetaType<CustomType*>(); QCOMPARE(property.type(), QVariant::UserType); + QCOMPARE(property.userType(), qMetaTypeId<CustomType*>()); CustomType *customPointer = 0; QVariant customVariant = object.property("custom"); @@ -1718,6 +1720,7 @@ void tst_QObject::property() QVERIFY(property.isWritable()); QCOMPARE(property.typeName(), "CustomType*"); QCOMPARE(property.type(), QVariant::UserType); + QCOMPARE(property.userType(), qMetaTypeId<CustomType*>()); QVERIFY(object.setProperty("custom", customVariant)); QCOMPARE(object.custom(), customPointer); @@ -3183,6 +3186,14 @@ void tst_QObject::dumpObjectInfo() QObject a, b; QObject::connect(&a, SIGNAL(destroyed(QObject *)), &b, SLOT(deleteLater())); a.disconnect(&b); +#ifdef QT_DEBUG + QTest::ignoreMessage(QtDebugMsg, "OBJECT QObject::unnamed"); + QTest::ignoreMessage(QtDebugMsg, " SIGNALS OUT"); + QTest::ignoreMessage(QtDebugMsg, " signal: destroyed(QObject*)"); + QTest::ignoreMessage(QtDebugMsg, " <Disconnected receiver>"); + QTest::ignoreMessage(QtDebugMsg, " SIGNALS IN"); + QTest::ignoreMessage(QtDebugMsg, " <None>"); +#endif a.dumpObjectInfo(); // should not crash } @@ -3810,12 +3821,18 @@ void tst_QObject::sameName() c2.emitSignal1(); QCOMPARE(c1.s, 2); +#ifndef QT_NO_DEBUG + QTest::ignoreMessage(QtWarningMsg, "QMetaObject::indexOfSignal: signal aPublicSlot() from SenderObject redefined in ConfusingObject"); +#endif QVERIFY(connect(&c2, SIGNAL(aPublicSlot()), &c1, SLOT(signal1()))); c2.aPublicSlot(); QCOMPARE(c2.aPublicSlotCalled, 0); QCOMPARE(c1.aPublicSlotCalled, 0); QCOMPARE(c1.s, 3); +#ifndef QT_NO_DEBUG + QTest::ignoreMessage(QtWarningMsg, "QMetaObject::indexOfSignal: signal aPublicSlot() from SenderObject redefined in ConfusingObject"); +#endif QVERIFY(connect(&c2, SIGNAL(aPublicSlot()), &c1, SLOT(aPublicSlot()))); c2.aPublicSlot(); QCOMPARE(c2.aPublicSlotCalled, 0); @@ -4149,9 +4166,6 @@ void tst_QObject::pointerConnect() QVERIFY( connect( s, &SenderObject::signal1 , r2, &ReceiverObject::slot1 ) ); QVERIFY( connect( s, &SenderObject::signal1 , r1, &ReceiverObject::slot3 ) ); QVERIFY( connect( s, &SenderObject::signal3 , r1, &ReceiverObject::slot3 ) ); -#if defined(Q_CC_GNU) && defined(Q_OS_UNIX) - QEXPECT_FAIL("", "Test may fail due to failing comparison of pointers to member functions caused by problems with -reduce-relocations on this platform.", Continue); -#endif QVERIFY2( connect( &timer, &QTimer::timeout, r1, &ReceiverObject::deleteLater ), "Signal connection failed most likely due to failing comparison of pointers to member functions caused by problems with -reduce-relocations on this platform."); diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.pro b/tests/auto/corelib/kernel/qobject/tst_qobject.pro index d74f2bcb0f..30fd810a2e 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.pro +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.pro @@ -6,3 +6,6 @@ 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 + +load(testcase) # for target.path and installTestHelperApp() +installTestHelperApp("signalbug/signalbug",signalbug,signalbug) diff --git a/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro b/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro index 55f6934fc9..58e4b98af7 100644 --- a/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro +++ b/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro @@ -6,5 +6,3 @@ SOURCES = tst_qsocketnotifier.cpp requires(contains(QT_CONFIG,private_tests)) include(../../../network/socket/platformsocketengine/platformsocketengine.pri) - -mac: CONFIG += insignificant_test # QTBUG-22746 diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp index e3bfe3bc6d..5442303e7e 100644 --- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp +++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp @@ -237,7 +237,7 @@ void tst_QSocketNotifier::mixingWithTimers() QCoreApplication::processEvents(); QCOMPARE(helper.timerActivated, true); - QCOMPARE(helper.socketActivated, true); + QTRY_COMPARE(helper.socketActivated, true); } void tst_QSocketNotifier::posixSockets() @@ -264,10 +264,7 @@ void tst_QSocketNotifier::posixSockets() connect(&rn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); QSignalSpy readSpy(&rn, SIGNAL(activated(int))); QVERIFY(readSpy.isValid()); - QSocketNotifier wn(posixSocket, QSocketNotifier::Write); - connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); - QSignalSpy writeSpy(&wn, SIGNAL(activated(int))); - QVERIFY(writeSpy.isValid()); + // No write notifier, some systems trigger write notification on socket creation, but not all QSocketNotifier en(posixSocket, QSocketNotifier::Exception); connect(&en, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); QSignalSpy errorSpy(&en, SIGNAL(activated(int))); @@ -278,19 +275,27 @@ void tst_QSocketNotifier::posixSockets() QTestEventLoop::instance().enterLoop(3); QCOMPARE(readSpy.count(), 1); - writeSpy.clear(); //depending on OS, write notifier triggers on creation or not. QCOMPARE(errorSpy.count(), 0); char buffer[100]; - qt_safe_read(posixSocket, buffer, 100); + int r = qt_safe_read(posixSocket, buffer, 100); + QCOMPARE(r, 6); QCOMPARE(buffer, "hello"); + QSocketNotifier wn(posixSocket, QSocketNotifier::Write); + connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); + QSignalSpy writeSpy(&wn, SIGNAL(activated(int))); + QVERIFY(writeSpy.isValid()); qt_safe_write(posixSocket, "goodbye", 8); QTestEventLoop::instance().enterLoop(3); QCOMPARE(readSpy.count(), 1); QCOMPARE(writeSpy.count(), 1); QCOMPARE(errorSpy.count(), 0); + + // Write notifier may have fired before the read notifier inside + // QTcpSocket, give QTcpSocket a chance to see the incoming data + passive->waitForReadyRead(100); QCOMPARE(passive->readAll(), QByteArray("goodbye",8)); } qt_safe_close(posixSocket); diff --git a/tests/auto/corelib/kernel/qvariant/qvariant.pro b/tests/auto/corelib/kernel/qvariant/qvariant.pro index 48229ee140..9b4b346d35 100644 --- a/tests/auto/corelib/kernel/qvariant/qvariant.pro +++ b/tests/auto/corelib/kernel/qvariant/qvariant.pro @@ -3,5 +3,3 @@ TARGET = tst_qvariant QT += widgets network testlib SOURCES = tst_qvariant.cpp RESOURCES += qvariant.qrc - -mac: CONFIG += insignificant_test # QTBUG-QTBUG-22747 diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 2bf554dd78..ccdab17668 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -83,11 +83,22 @@ Q_DECLARE_METATYPE(QFont) Q_DECLARE_METATYPE(QColor) Q_DECLARE_METATYPE(QKeySequence) +class CustomNonQObject; + class tst_QVariant : public QObject { Q_OBJECT +public: + tst_QVariant(QObject *parent = 0) + : QObject(parent), customNonQObjectPointer(0) + { + + } + private slots: + void cleanupTestCase(); + void constructor(); void copy_constructor(); void isNull(); @@ -176,6 +187,7 @@ private slots: void qvariant_cast_QObject_data(); void qvariant_cast_QObject(); + void qvariant_cast_QObject_derived(); void toLocale(); @@ -275,6 +287,9 @@ private: void dataStream_data(QDataStream::Version version); void loadQVariantFromDataStream(QDataStream::Version version); void saveQVariantFromDataStream(QDataStream::Version version); + + CustomNonQObject *customNonQObjectPointer; + QVector<QObject*> objectPointerTestData; }; Q_DECLARE_METATYPE(QDate) @@ -1842,10 +1857,6 @@ void tst_QVariant::operator_eq_eq_data() QTest::newRow("HashSecondLarger") << QVariant(hash1) << QVariant(hash2) << false; } - - QTest::newRow( "UserType" ) << QVariant(QVariant::UserType) << QVariant(QVariant::UserType) << true; - QVariant mUserType(QVariant::UserType); - QTest::newRow( "Shared UserType" ) << mUserType << mUserType << true; } void tst_QVariant::operator_eq_eq() @@ -1919,7 +1930,6 @@ void tst_QVariant::typeName_data() QTest::newRow("39") << int(QVariant::RectF) << QByteArray("QRectF"); QTest::newRow("40") << int(QVariant::PointF) << QByteArray("QPointF"); QTest::newRow("41") << int(QVariant::RegExp) << QByteArray("QRegExp"); - QTest::newRow("42") << int(QVariant::UserType) << QByteArray(); QTest::newRow("43") << int(QVariant::Matrix) << QByteArray("QMatrix"); QTest::newRow("44") << int(QVariant::Transform) << QByteArray("QTransform"); QTest::newRow("45") << int(QVariant::Hash) << QByteArray("QVariantHash"); @@ -2031,10 +2041,10 @@ void tst_QVariant::userType() qVariantSetValue(userVar, data); QCOMPARE(userVar.type(), QVariant::UserType); + QCOMPARE(userVar.userType(), qMetaTypeId<MyType>()); QCOMPARE(userVar.typeName(), "MyType"); QVERIFY(!userVar.isNull()); QVERIFY(!userVar.canConvert(QVariant::String)); - QVERIFY(!userVar.canConvert(QVariant::UserType)); QVariant userVar2(userVar); QVERIFY(userVar == userVar2); @@ -2060,10 +2070,10 @@ void tst_QVariant::userType() qVariantSetValue(userVar, &data); QCOMPARE(userVar.type(), QVariant::UserType); + QCOMPARE(userVar.userType(), qMetaTypeId<MyType*>()); QCOMPARE(userVar.typeName(), "MyType*"); QVERIFY(!userVar.isNull()); QVERIFY(!userVar.canConvert(QVariant::String)); - QVERIFY(!userVar.canConvert(QVariant::UserType)); QVariant userVar2(userVar); QVERIFY(userVar == userVar2); @@ -2457,20 +2467,63 @@ void tst_QVariant::invalidQColor() const QVERIFY(!qvariant_cast<QColor>(va).isValid()); } -void tst_QVariant::qvariant_cast_QObject_data() { +class CustomQObject : public QObject { + Q_OBJECT +public: + CustomQObject(QObject *parent = 0) : QObject(parent) {} +}; +class CustomQWidget : public QWidget { + Q_OBJECT +public: + CustomQWidget(QWidget *parent = 0) : QWidget(parent) {} +}; +Q_DECLARE_METATYPE(CustomQObject*) +Q_DECLARE_METATYPE(CustomQWidget*) + +class CustomNonQObject { }; +Q_DECLARE_METATYPE(CustomNonQObject) +Q_DECLARE_METATYPE(CustomNonQObject*) +void tst_QVariant::cleanupTestCase() +{ + delete customNonQObjectPointer; + qDeleteAll(objectPointerTestData); +} + +void tst_QVariant::qvariant_cast_QObject_data() +{ QTest::addColumn<QVariant>("data"); QTest::addColumn<bool>("success"); - QObject *obj = new QObject(this); + QObject *obj = new QObject; obj->setObjectName(QString::fromLatin1("Hello")); QTest::newRow("from QObject") << QVariant(QMetaType::QObjectStar, &obj) << true; QTest::newRow("from QObject2") << QVariant::fromValue(obj) << true; QTest::newRow("from String") << QVariant(QLatin1String("1, 2, 3")) << false; QTest::newRow("from int") << QVariant((int) 123) << false; -} - - -void tst_QVariant::qvariant_cast_QObject() { + QWidget *widget = new QWidget; + widget->setObjectName(QString::fromLatin1("Hello")); + QTest::newRow("from QWidget") << QVariant::fromValue(widget) << true; + CustomQObject *customObject = new CustomQObject(this); + customObject->setObjectName(QString::fromLatin1("Hello")); + QTest::newRow("from Derived QObject") << QVariant::fromValue(customObject) << true; + CustomQWidget *customWidget = new CustomQWidget; + customWidget->setObjectName(QString::fromLatin1("Hello")); + QTest::newRow("from Derived QWidget") << QVariant::fromValue(customWidget) << true; + QTest::newRow("from custom Object") << QVariant::fromValue(CustomNonQObject()) << false; + + // Deleted in cleanupTestCase. + customNonQObjectPointer = new CustomNonQObject; + QTest::newRow("from custom ObjectStar") << QVariant::fromValue(customNonQObjectPointer) << false; + + // Deleted in cleanupTestCase. + objectPointerTestData.push_back(obj); + objectPointerTestData.push_back(widget); + objectPointerTestData.push_back(customObject); + objectPointerTestData.push_back(customWidget); +} + +void tst_QVariant::qvariant_cast_QObject() +{ QFETCH(QVariant, data); QFETCH(bool, success); @@ -2481,6 +2534,38 @@ void tst_QVariant::qvariant_cast_QObject() { } } +class CustomQObjectDerived : public CustomQObject { + Q_OBJECT +public: + CustomQObjectDerived(QObject *parent = 0) : CustomQObject(parent) {} +}; +Q_DECLARE_METATYPE(CustomQObjectDerived*) + +void tst_QVariant::qvariant_cast_QObject_derived() +{ + { + CustomQObjectDerived *object = new CustomQObjectDerived(this); + QVariant data = QVariant::fromValue(object); + + QVERIFY(data.userType() == qMetaTypeId<CustomQObjectDerived*>()); + + QCOMPARE(data.value<QObject *>(), object); + QCOMPARE(data.value<CustomQObjectDerived *>(), object); + QCOMPARE(data.value<CustomQObject *>(), object); + QVERIFY(data.value<CustomQWidget*>() == 0); + } + { + CustomQWidget customWidget; + QWidget *widget = &customWidget; + QVariant data = QVariant::fromValue(widget); + QVERIFY(data.userType() == QMetaType::QWidgetStar); + + QCOMPARE(data.value<QObject*>(), widget); + QCOMPARE(data.value<QWidget*>(), widget); + QCOMPARE(data.value<CustomQWidget*>(), widget); + } +} + Q_DECLARE_METATYPE(qint8); void tst_QVariant::convertToQUint8() const @@ -2696,7 +2781,7 @@ Q_DECLARE_METATYPE( MyClass ) void tst_QVariant::loadUnknownUserType() { qRegisterMetaType<MyClass>("MyClass"); - char data[] = {0, 0, 0, 127, 0, 0, 0, 0, 8, 77, 121, 67, 108, 97, 115, 115, 0}; + char data[] = {0, 0, 1, 0, 0, 0, 0, 0, 8, 77, 121, 67, 108, 97, 115, 115, 0}; QByteArray ba(data, sizeof(data)); QDataStream ds(&ba, QIODevice::ReadOnly); @@ -3306,6 +3391,7 @@ void tst_QVariant::movabilityTest() memcpy(buffer, &variant, sizeof(QVariant)); QCOMPARE(buffer[0].type(), QVariant::UserType); + QCOMPARE(buffer[0].userType(), qMetaTypeId<MyNotMovable>()); MyNotMovable tmp(buffer[0].value<MyNotMovable>()); new (&variant) QVariant(); @@ -3365,12 +3451,8 @@ void tst_QVariant::colorInteger() } class Forward; -QT_BEGIN_NAMESPACE namespace QtPrivate { -template <> struct IsPointerToTypeDerivedFromQObject<Forward*> { - enum { Value = false }; -}; -} QT_END_NAMESPACE -Q_DECLARE_METATYPE(Forward*); +Q_DECLARE_OPAQUE_POINTER(Forward*) +Q_DECLARE_METATYPE(Forward*) void tst_QVariant::forwardDeclare() { @@ -3460,6 +3542,7 @@ void tst_QVariant::loadQVariantFromDataStream(QDataStream::Version version) stream >> typeName >> loadedVariant; const int id = QMetaType::type(typeName.toLatin1()); + QVariant constructedVariant(static_cast<QVariant::Type>(id)); QCOMPARE(constructedVariant.userType(), id); QCOMPARE(QMetaType::typeName(loadedVariant.userType()), typeName.toLatin1().constData()); @@ -3534,7 +3617,7 @@ void tst_QVariant::debugStream_data() { QTest::addColumn<QVariant>("variant"); QTest::addColumn<int>("typeId"); - for (int id = QMetaType::Void; id < QMetaType::User; ++id) { + for (int id = 0; id < QMetaType::User; ++id) { const char *tagName = QMetaType::typeName(id); if (!tagName) continue; diff --git a/tests/auto/corelib/mimetypes/mimetypes.pro b/tests/auto/corelib/mimetypes/mimetypes.pro new file mode 100644 index 0000000000..9063d677e7 --- /dev/null +++ b/tests/auto/corelib/mimetypes/mimetypes.pro @@ -0,0 +1,8 @@ +TEMPLATE=subdirs + +SUBDIRS = \ + qmimetype \ + qmimedatabase + +!contains(QT_CONFIG, private_tests): SUBDIRS -= \ + qmimetype diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro new file mode 100644 index 0000000000..815401ce1e --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/qmimedatabase-cache.pro @@ -0,0 +1,12 @@ +CONFIG += testcase parallel_test + +TARGET = tst_qmimedatabase-cache + +QT = core testlib concurrent + +SOURCES = tst_qmimedatabase-cache.cpp +HEADERS = ../tst_qmimedatabase.h + +DEFINES += SRCDIR='"\\"$$PWD/../\\""' + +*-g++*:QMAKE_CXXFLAGS += -W -Wall -Wextra -Werror -Wshadow -Wno-long-long -Wnon-virtual-dtor diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp new file mode 100644 index 0000000000..205331d4dd --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "../tst_qmimedatabase.h" +#include <QDir> +#include <QFile> +#include <QtTest/QtTest> +#include <qstandardpaths.h> + +#include "../tst_qmimedatabase.cpp" + +tst_QMimeDatabase::tst_QMimeDatabase() +{ + QDir here = QDir::currentPath(); + const QString tempMime = here.absolutePath() + QString::fromLatin1("/mime"); + runUpdateMimeDatabase(tempMime); + QVERIFY(QFile::exists(tempMime + QString::fromLatin1("/mime.cache"))); +} diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro new file mode 100644 index 0000000000..ac7515f781 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/qmimedatabase-xml.pro @@ -0,0 +1,14 @@ +CONFIG += testcase parallel_test + +TARGET = tst_qmimedatabase-xml + +QT = core testlib concurrent + +CONFIG += depend_includepath + +SOURCES += tst_qmimedatabase-xml.cpp +HEADERS += ../tst_qmimedatabase.h + +DEFINES += SRCDIR='"\\"$$PWD/../\\""' + +*-g++*:QMAKE_CXXFLAGS += -W -Wall -Wextra -Werror -Wshadow -Wno-long-long -Wnon-virtual-dtor diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp new file mode 100644 index 0000000000..13ca372290 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "../tst_qmimedatabase.h" +#include <QDebug> +#include <QDir> + +tst_QMimeDatabase::tst_QMimeDatabase() +{ + qputenv("QT_NO_MIME_CACHE", "1"); +} + +#include "../tst_qmimedatabase.cpp" diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase.pro b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase.pro new file mode 100644 index 0000000000..876b4377dd --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = qmimedatabase-xml +unix: SUBDIRS += qmimedatabase-cache diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp new file mode 100644 index 0000000000..fc86fa5431 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -0,0 +1,834 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qmimedatabase.h> + +#include "qstandardpaths.h" + +#include <QtCore/QFile> +#include <QtConcurrent/QtConcurrentRun> +#include <QtConcurrent/QFuture> + +#include <QtTest/QtTest> + +void initializeLang() +{ + qputenv("LANG", "en_US"); +} + +// Set LANG before QCoreApplication is created +Q_CONSTRUCTOR_FUNCTION(initializeLang) + +void tst_QMimeDatabase::initTestCase() +{ + // Create a "global" and a "local" XDG data dir, right here. + // The local dir will be empty initially, while the global dir will contain a copy of freedesktop.org.xml + + QDir here = QDir::currentPath(); + + qputenv("XDG_DATA_DIRS", QFile::encodeName(here.absolutePath())); + QDir(here.absolutePath() + "/mime").removeRecursively(); + here.mkpath(QString::fromLatin1("mime/packages")); + + QFile xml(QFile::decodeName(SRCDIR "../../../src/mimetypes/mime/packages/freedesktop.org.xml")); + const QString mimeDir = here.absolutePath() + QLatin1String("/mime"); + xml.copy(mimeDir + QLatin1String("/packages/freedesktop.org.xml")); + + m_dataHome = here.absolutePath() + QLatin1String("/../datahome"); + qputenv("XDG_DATA_HOME", QFile::encodeName(m_dataHome)); + //qDebug() << "XDG_DATA_HOME=" << m_dataHome; + + // Make sure we start clean + cleanupTestCase(); +} + +void tst_QMimeDatabase::cleanupTestCase() +{ + QDir here = QDir::currentPath(); + here.remove(QString::fromLatin1("mime/packages/yast2-metapackage-handler-mimetypes.xml")); + + QDir(m_dataHome).removeRecursively(); +} + +void tst_QMimeDatabase::mimeTypeForName() +{ + QMimeDatabase db; + QMimeType s0 = db.mimeTypeForName(QString::fromLatin1("application/x-zerosize")); + QVERIFY(s0.isValid()); + QCOMPARE(s0.name(), QString::fromLatin1("application/x-zerosize")); + QCOMPARE(s0.comment(), QString::fromLatin1("empty document")); + + QMimeType s0Again = db.mimeTypeForName(QString::fromLatin1("application/x-zerosize")); + QCOMPARE(s0Again.name(), s0.name()); + + QMimeType s1 = db.mimeTypeForName(QString::fromLatin1("text/plain")); + QVERIFY(s1.isValid()); + QCOMPARE(s1.name(), QString::fromLatin1("text/plain")); + //qDebug("Comment is %s", qPrintable(s1.comment())); + + QMimeType krita = db.mimeTypeForName(QString::fromLatin1("application/x-krita")); + QVERIFY(krita.isValid()); + + // Test <comment> parsing with application/rdf+xml which has the english comment after the other ones + QMimeType rdf = db.mimeTypeForName(QString::fromLatin1("application/rdf+xml")); + QVERIFY(rdf.isValid()); + QCOMPARE(rdf.comment(), QString::fromLatin1("RDF file")); + + QMimeType bzip2 = db.mimeTypeForName(QString::fromLatin1("application/x-bzip2")); + QVERIFY(bzip2.isValid()); + QCOMPARE(bzip2.comment(), QString::fromLatin1("Bzip archive")); + + QMimeType defaultMime = db.mimeTypeForName(QString::fromLatin1("application/octet-stream")); + QVERIFY(defaultMime.isValid()); + QVERIFY(defaultMime.isDefault()); + + QMimeType doesNotExist = db.mimeTypeForName(QString::fromLatin1("foobar/x-doesnot-exist")); + QVERIFY(!doesNotExist.isValid()); + + // TODO move to findByFile +#ifdef Q_OS_LINUX + QString exePath = QStandardPaths::findExecutable(QLatin1String("ls")); + if (exePath.isEmpty()) + qWarning() << "ls not found"; + else { + const QString executableType = QString::fromLatin1("application/x-executable"); + //QTest::newRow("executable") << exePath << executableType; + QCOMPARE(db.mimeTypeForFile(exePath).name(), executableType); + } +#endif + +} + +void tst_QMimeDatabase::mimeTypeForFileName_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QString>("expectedMimeType"); + + QTest::newRow("text") << "textfile.txt" << "text/plain"; + QTest::newRow("case-insensitive search") << "textfile.TxT" << "text/plain"; + + // Needs shared-mime-info > 0.91. Earlier versions wrote .Z to the mime.cache file... + //QTest::newRow("case-insensitive match on a non-lowercase glob") << "foo.z" << "application/x-compress"; + + QTest::newRow("case-sensitive uppercase match") << "textfile.C" << "text/x-c++src"; + QTest::newRow("case-sensitive lowercase match") << "textfile.c" << "text/x-csrc"; + QTest::newRow("case-sensitive long-extension match") << "foo.PS.gz" << "application/x-gzpostscript"; + QTest::newRow("case-sensitive-only match") << "core" << "application/x-core"; + QTest::newRow("case-sensitive-only match") << "Core" << "application/octet-stream"; // #198477 + + QTest::newRow("desktop file") << "foo.desktop" << "application/x-desktop"; + QTest::newRow("old kdelnk file is x-desktop too") << "foo.kdelnk" << "application/x-desktop"; + QTest::newRow("double-extension file") << "foo.tar.bz2" << "application/x-bzip-compressed-tar"; + QTest::newRow("single-extension file") << "foo.bz2" << "application/x-bzip"; + QTest::newRow(".doc should assume msword") << "somefile.doc" << "application/msword"; // #204139 + QTest::newRow("glob that uses [] syntax, 1") << "Makefile" << "text/x-makefile"; + QTest::newRow("glob that uses [] syntax, 2") << "makefile" << "text/x-makefile"; + QTest::newRow("glob that ends with *, no extension") << "README" << "text/x-readme"; + QTest::newRow("glob that ends with *, extension") << "README.foo" << "text/x-readme"; + QTest::newRow("glob that ends with *, also matches *.txt. Higher weight wins.") << "README.txt" << "text/plain"; + QTest::newRow("glob that ends with *, also matches *.nfo. Higher weight wins.") << "README.nfo" << "text/x-nfo"; + // fdo bug 15436, needs shared-mime-info >= 0.40 (and this tests the globs2-parsing code). + QTest::newRow("glob that ends with *, also matches *.pdf. *.pdf has higher weight") << "README.pdf" << "application/pdf"; + QTest::newRow("directory") << "/" << "inode/directory"; + QTest::newRow("doesn't exist, no extension") << "IDontExist" << "application/octet-stream"; + QTest::newRow("doesn't exist but has known extension") << "IDontExist.txt" << "text/plain"; +} + +void tst_QMimeDatabase::mimeTypeForFileName() +{ + QFETCH(QString, fileName); + QFETCH(QString, expectedMimeType); + QMimeDatabase db; + QMimeType mime = db.mimeTypeForFile(fileName, QMimeDatabase::MatchExtension); + QVERIFY(mime.isValid()); + QCOMPARE(mime.name(), expectedMimeType); + + QList<QMimeType> mimes = db.mimeTypesForFileName(fileName); + if (expectedMimeType == "application/octet-stream") { + QVERIFY(mimes.isEmpty()); + } else { + QVERIFY(!mimes.isEmpty()); + QCOMPARE(mimes.count(), 1); + QCOMPARE(mimes.first().name(), expectedMimeType); + } +} + +void tst_QMimeDatabase::mimeTypesForFileName_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QStringList>("expectedMimeTypes"); + + QTest::newRow("txt, 1 hit") << "foo.txt" << (QStringList() << "text/plain"); + QTest::newRow("txtfoobar, 0 hit") << "foo.foobar" << QStringList(); + QTest::newRow("m, 2 hits") << "foo.m" << (QStringList() << "text/x-matlab" << "text/x-objcsrc"); + QTest::newRow("sub, 3 hits") << "foo.sub" << (QStringList() << "text/x-microdvd" << "text/x-mpsub" << "text/x-subviewer"); +} + +void tst_QMimeDatabase::mimeTypesForFileName() +{ + QFETCH(QString, fileName); + QFETCH(QStringList, expectedMimeTypes); + QMimeDatabase db; + QList<QMimeType> mimes = db.mimeTypesForFileName(fileName); + QStringList mimeNames; + foreach (const QMimeType &mime, mimes) + mimeNames.append(mime.name()); + QCOMPARE(mimeNames, expectedMimeTypes); +} + +void tst_QMimeDatabase::inheritance() +{ + QMimeDatabase db; + + // All file-like mimetypes inherit from octet-stream + const QMimeType wordperfect = db.mimeTypeForName(QString::fromLatin1("application/vnd.wordperfect")); + QVERIFY(wordperfect.isValid()); + QCOMPARE(wordperfect.parentMimeTypes().join(QString::fromLatin1(",")), QString::fromLatin1("application/octet-stream")); + QVERIFY(wordperfect.inherits(QLatin1String("application/octet-stream"))); + + QVERIFY(db.mimeTypeForName(QString::fromLatin1("image/svg+xml-compressed")).inherits(QLatin1String("application/x-gzip"))); + + // Check that msword derives from ole-storage + const QMimeType msword = db.mimeTypeForName(QString::fromLatin1("application/msword")); + QVERIFY(msword.isValid()); + const QMimeType olestorage = db.mimeTypeForName(QString::fromLatin1("application/x-ole-storage")); + QVERIFY(olestorage.isValid()); + QVERIFY(msword.inherits(olestorage.name())); + QVERIFY(msword.inherits(QLatin1String("application/octet-stream"))); + + const QMimeType directory = db.mimeTypeForName(QString::fromLatin1("inode/directory")); + QVERIFY(directory.isValid()); + QCOMPARE(directory.parentMimeTypes().count(), 0); + QVERIFY(!directory.inherits(QLatin1String("application/octet-stream"))); + + // Check that text/x-patch knows that it inherits from text/plain (it says so explicitly) + const QMimeType plain = db.mimeTypeForName(QString::fromLatin1("text/plain")); + const QMimeType derived = db.mimeTypeForName(QString::fromLatin1("text/x-patch")); + QVERIFY(derived.isValid()); + QCOMPARE(derived.parentMimeTypes().join(QString::fromLatin1(",")), plain.name()); + QVERIFY(derived.inherits(QLatin1String("text/plain"))); + QVERIFY(derived.inherits(QLatin1String("application/octet-stream"))); + + // Check that application/x-shellscript inherits from application/x-executable + // (Otherwise KRun cannot start shellscripts...) + // This is a test for multiple inheritance... + const QMimeType shellscript = db.mimeTypeForName(QString::fromLatin1("application/x-shellscript")); + QVERIFY(shellscript.isValid()); + QVERIFY(shellscript.inherits(QLatin1String("text/plain"))); + QVERIFY(shellscript.inherits(QLatin1String("application/x-executable"))); + const QStringList shellParents = shellscript.parentMimeTypes(); + QVERIFY(shellParents.contains(QLatin1String("text/plain"))); + QVERIFY(shellParents.contains(QLatin1String("application/x-executable"))); + QCOMPARE(shellParents.count(), 2); // only the above two + const QStringList allShellAncestors = shellscript.allAncestors(); + QVERIFY(allShellAncestors.contains(QLatin1String("text/plain"))); + QVERIFY(allShellAncestors.contains(QLatin1String("application/x-executable"))); + QVERIFY(allShellAncestors.contains(QLatin1String("application/octet-stream"))); + // Must be least-specific last, i.e. breadth first. + QCOMPARE(allShellAncestors.last(), QString::fromLatin1("application/octet-stream")); + + const QStringList allSvgAncestors = db.mimeTypeForName(QString::fromLatin1("image/svg+xml")).allAncestors(); + QCOMPARE(allSvgAncestors, QStringList() << QLatin1String("application/xml") << QLatin1String("text/plain") << QLatin1String("application/octet-stream")); + + // Check that text/x-mrml knows that it inherits from text/plain (implicitly) + const QMimeType mrml = db.mimeTypeForName(QString::fromLatin1("text/x-mrml")); + QVERIFY(mrml.isValid()); + QVERIFY(mrml.inherits(QLatin1String("text/plain"))); + QVERIFY(mrml.inherits(QLatin1String("application/octet-stream"))); + + // Check that msword-template inherits msword + const QMimeType mswordTemplate = db.mimeTypeForName(QString::fromLatin1("application/msword-template")); + QVERIFY(mswordTemplate.isValid()); + QVERIFY(mswordTemplate.inherits(QLatin1String("application/msword"))); +} + +void tst_QMimeDatabase::aliases() +{ + QMimeDatabase db; + + const QMimeType canonical = db.mimeTypeForName(QString::fromLatin1("application/xml")); + QVERIFY(canonical.isValid()); + + QMimeType resolvedAlias = db.mimeTypeForName(QString::fromLatin1("text/xml")); + QVERIFY(resolvedAlias.isValid()); + QCOMPARE(resolvedAlias.name(), QString::fromLatin1("application/xml")); + + QVERIFY(resolvedAlias.inherits(QLatin1String("application/xml"))); + QVERIFY(canonical.inherits(QLatin1String("text/xml"))); + + // Test for kde bug 197346: does nspluginscan see that audio/mp3 already exists? + bool mustWriteMimeType = !db.mimeTypeForName(QString::fromLatin1("audio/mp3")).isValid(); + QVERIFY(!mustWriteMimeType); +} + +void tst_QMimeDatabase::icons() +{ + QMimeDatabase db; + QMimeType directory = db.mimeTypeForFile(QString::fromLatin1("/")); + QCOMPARE(directory.name(), QString::fromLatin1("inode/directory")); + QCOMPARE(directory.iconName(), QString::fromLatin1("inode-directory")); + QCOMPARE(directory.genericIconName(), QString::fromLatin1("inode-x-generic")); + + QMimeType pub = db.mimeTypeForFile(QString::fromLatin1("foo.epub"), QMimeDatabase::MatchExtension); + QCOMPARE(pub.name(), QString::fromLatin1("application/epub+zip")); + QCOMPARE(pub.iconName(), QString::fromLatin1("application-epub+zip")); + QCOMPARE(pub.genericIconName(), QString::fromLatin1("x-office-document")); +} + +// In here we do the tests that need some content in a temporary file. +// This could also be added to shared-mime-info's testsuite... +void tst_QMimeDatabase::mimeTypeForFileWithContent() +{ + QMimeDatabase db; + QMimeType mime; + + // Test a real PDF file. + // If we find x-matlab because it starts with '%' then we are not ordering by priority. + QTemporaryFile tempFile; + QVERIFY(tempFile.open()); + QString tempFileName = tempFile.fileName(); + tempFile.write("%PDF-"); + tempFile.close(); + mime = db.mimeTypeForFile(tempFileName); + QCOMPARE(mime.name(), QString::fromLatin1("application/pdf")); + QFile file(tempFileName); + mime = db.mimeTypeForData(&file); // QIODevice ctor + QCOMPARE(mime.name(), QString::fromLatin1("application/pdf")); + // by name only, we cannot find the mimetype + mime = db.mimeTypeForFile(tempFileName, QMimeDatabase::MatchExtension); + QVERIFY(mime.isValid()); + QVERIFY(mime.isDefault()); + + // Test the case where the extension doesn't match the contents: extension wins + { + QTemporaryFile txtTempFile(QDir::tempPath() + QLatin1String("/tst_QMimeDatabase_XXXXXX.txt")); + QVERIFY(txtTempFile.open()); + txtTempFile.write("%PDF-"); + QString txtTempFileName = txtTempFile.fileName(); + txtTempFile.close(); + mime = db.mimeTypeForFile(txtTempFileName); + QCOMPARE(mime.name(), QString::fromLatin1("text/plain")); + // fast mode finds the same + mime = db.mimeTypeForFile(txtTempFileName, QMimeDatabase::MatchExtension); + QCOMPARE(mime.name(), QString::fromLatin1("text/plain")); + } + + // Now the case where extension differs from contents, but contents has >80 magic rule + // XDG spec says: contents wins. But we can't sniff all files... + { + QTemporaryFile txtTempFile(QDir::tempPath() + QLatin1String("/tst_QMimeDatabase_XXXXXX.txt")); + QVERIFY(txtTempFile.open()); + txtTempFile.write("<smil"); + QString txtTempFileName = txtTempFile.fileName(); + txtTempFile.close(); + mime = db.mimeTypeForFile(txtTempFileName); + QCOMPARE(mime.name(), QString::fromLatin1("text/plain")); + } + + // Test what happens with an incorrect path + mime = db.mimeTypeForFile(QString::fromLatin1("file:///etc/passwd" /* incorrect code, use a path instead */)); + QVERIFY(mime.isDefault()); + + // findByData when the device cannot be opened (e.g. a directory) + QFile dir("/"); + mime = db.mimeTypeForData(&dir); + QVERIFY(mime.isDefault()); +} + +void tst_QMimeDatabase::mimeTypeForUrl() +{ + QMimeDatabase db; + QVERIFY(db.mimeTypeForUrl(QUrl::fromEncoded("http://foo/bar.png")).isDefault()); // HTTP can't know before downloading + QCOMPARE(db.mimeTypeForUrl(QUrl::fromEncoded("ftp://foo/bar.png")).name(), QString::fromLatin1("image/png")); + QCOMPARE(db.mimeTypeForUrl(QUrl::fromEncoded("ftp://foo/bar")).name(), QString::fromLatin1("application/octet-stream")); // unknown extension +} + +void tst_QMimeDatabase::mimeTypeForData_data() +{ + QTest::addColumn<QByteArray>("data"); + QTest::addColumn<QString>("expectedMimeTypeName"); + + QTest::newRow("tnef data, needs smi >= 0.20") << QByteArray("\x78\x9f\x3e\x22") << "application/vnd.ms-tnef"; + QTest::newRow("PDF magic") << QByteArray("%PDF-") << "application/pdf"; + QTest::newRow("PHP, High-priority rule") << QByteArray("<?php") << "application/x-php"; + QTest::newRow("unknown") << QByteArray("\001abc?}") << "application/octet-stream"; +} + +void tst_QMimeDatabase::mimeTypeForData() +{ + QFETCH(QByteArray, data); + QFETCH(QString, expectedMimeTypeName); + + QMimeDatabase db; + QCOMPARE(db.mimeTypeForData(data).name(), expectedMimeTypeName); + QBuffer buffer(&data); + QCOMPARE(db.mimeTypeForData(&buffer).name(), expectedMimeTypeName); + QVERIFY(!buffer.isOpen()); // initial state was restored + + QVERIFY(buffer.open(QIODevice::ReadOnly)); + QCOMPARE(db.mimeTypeForData(&buffer).name(), expectedMimeTypeName); + QVERIFY(buffer.isOpen()); + QCOMPARE(buffer.pos(), qint64(0)); +} + +void tst_QMimeDatabase::mimeTypeForFileAndContent_data() +{ + QTest::addColumn<QString>("name"); + QTest::addColumn<QByteArray>("data"); + QTest::addColumn<QString>("expectedMimeTypeName"); + + QTest::newRow("plain text, no extension") << QString::fromLatin1("textfile") << QByteArray("Hello world") << "text/plain"; + QTest::newRow("plain text, unknown extension") << QString::fromLatin1("textfile.foo") << QByteArray("Hello world") << "text/plain"; + // Needs kde/mimetypes.xml + //QTest::newRow("plain text, doc extension") << QString::fromLatin1("textfile.doc") << QByteArray("Hello world") << "text/plain"; + + // If you get powerpoint instead, then you're hit by https://bugs.freedesktop.org/show_bug.cgi?id=435, + // upgrade to shared-mime-info >= 0.22 + const QByteArray oleData("\320\317\021\340\241\261\032\341"); // same as \xD0\xCF\x11\xE0 \xA1\xB1\x1A\xE1 + QTest::newRow("msword file, unknown extension") << QString::fromLatin1("mswordfile") << oleData << "application/x-ole-storage"; + QTest::newRow("excel file, found by extension") << QString::fromLatin1("excelfile.xls") << oleData << "application/vnd.ms-excel"; + QTest::newRow("text.xls, found by extension, user is in control") << QString::fromLatin1("text.xls") << oleData << "application/vnd.ms-excel"; +} + +void tst_QMimeDatabase::mimeTypeForFileAndContent() +{ + QFETCH(QString, name); + QFETCH(QByteArray, data); + QFETCH(QString, expectedMimeTypeName); + + QMimeDatabase db; + QCOMPARE(db.mimeTypeForNameAndData(name, data).name(), expectedMimeTypeName); + + QBuffer buffer(&data); + QCOMPARE(db.mimeTypeForNameAndData(name, &buffer).name(), expectedMimeTypeName); + QVERIFY(!buffer.isOpen()); // initial state was restored + + QVERIFY(buffer.open(QIODevice::ReadOnly)); + QCOMPARE(db.mimeTypeForNameAndData(name, &buffer).name(), expectedMimeTypeName); + QVERIFY(buffer.isOpen()); + QCOMPARE(buffer.pos(), qint64(0)); +} + +void tst_QMimeDatabase::allMimeTypes() +{ + QMimeDatabase db; + const QList<QMimeType> lst = db.allMimeTypes(); // does NOT include aliases + QVERIFY(!lst.isEmpty()); + + // Hardcoding this is the only way to check both providers find the same number of mimetypes. + QCOMPARE(lst.count(), 661); + + foreach (const QMimeType &mime, lst) { + const QString name = mime.name(); + QVERIFY(!name.isEmpty()); + QCOMPARE(name.count(QLatin1Char('/')), 1); + const QMimeType lookedupMime = db.mimeTypeForName(name); + QVERIFY(lookedupMime.isValid()); + QCOMPARE(lookedupMime.name(), name); // if this fails, you have an alias defined as a real mimetype too! + } +} + +void tst_QMimeDatabase::inheritsPerformance() +{ + // Check performance of inherits(). + // This benchmark (which started in 2009 in kmimetypetest.cpp) uses 40 mimetypes. + QStringList mimeTypes; mimeTypes << QLatin1String("image/jpeg") << QLatin1String("image/png") << QLatin1String("image/tiff") << QLatin1String("text/plain") << QLatin1String("text/html"); + mimeTypes += mimeTypes; + mimeTypes += mimeTypes; + mimeTypes += mimeTypes; + QCOMPARE(mimeTypes.count(), 40); + QMimeDatabase db; + QMimeType mime = db.mimeTypeForName(QString::fromLatin1("text/x-chdr")); + QVERIFY(mime.isValid()); + QBENCHMARK { + QString match; + foreach (const QString &mt, mimeTypes) { + if (mime.inherits(mt)) { + match = mt; + // of course there would normally be a "break" here, but we're testing worse-case + // performance here + } + } + QCOMPARE(match, QString::fromLatin1("text/plain")); + } + // Numbers from 2011, in release mode: + // KDE 4.7 numbers: 0.21 msec / 494,000 ticks / 568,345 instr. loads per iteration + // QMimeBinaryProvider (with Qt 5): 0.16 msec / NA / 416,049 instr. reads per iteration + // QMimeXmlProvider (with Qt 5): 0.062 msec / NA / 172,889 instr. reads per iteration + // (but the startup time is way higher) + // And memory usage is flat at 200K with QMimeBinaryProvider, while it peaks at 6 MB when + // parsing XML, and then keeps being around 4.5 MB for all the in-memory hashes. +} + +void tst_QMimeDatabase::suffixes_data() +{ + QTest::addColumn<QString>("mimeType"); + QTest::addColumn<QString>("patterns"); + QTest::addColumn<QString>("preferredSuffix"); + + QTest::newRow("mimetype with a single pattern") << "application/pdf" << "*.pdf" << "pdf"; + QTest::newRow("mimetype with multiple patterns") << "application/x-kpresenter" << "*.kpr;*.kpt" << "kpr"; + //if (KMimeType::sharedMimeInfoVersion() > KDE_MAKE_VERSION(0, 60, 0)) { + QTest::newRow("mimetype with many patterns") << "application/vnd.wordperfect" << "*.wp;*.wp4;*.wp5;*.wp6;*.wpd;*.wpp" << "wp"; + //} + QTest::newRow("oasis text mimetype") << "application/vnd.oasis.opendocument.text" << "*.odt" << "odt"; + QTest::newRow("oasis presentation mimetype") << "application/vnd.oasis.opendocument.presentation" << "*.odp" << "odp"; + QTest::newRow("mimetype with multiple patterns") << "text/plain" << "*.asc;*.txt;*,v" << "txt"; + QTest::newRow("mimetype with uncommon pattern") << "text/x-readme" << "README*" << QString(); + QTest::newRow("mimetype with no patterns") << "application/x-ole-storage" << QString() << QString(); +} + +void tst_QMimeDatabase::suffixes() +{ + QFETCH(QString, mimeType); + QFETCH(QString, patterns); + QFETCH(QString, preferredSuffix); + QMimeDatabase db; + QMimeType mime = db.mimeTypeForName(mimeType); + QVERIFY(mime.isValid()); + // Sort both lists; order is unreliable since shared-mime-info uses hashes internally. + QStringList expectedPatterns = patterns.split(QLatin1Char(';')); + expectedPatterns.sort(); + QStringList mimePatterns = mime.globPatterns(); + mimePatterns.sort(); + QCOMPARE(mimePatterns.join(QLatin1String(";")), expectedPatterns.join(QLatin1String(";"))); + QCOMPARE(mime.preferredSuffix(), preferredSuffix); +} + +void tst_QMimeDatabase::knownSuffix() +{ + QMimeDatabase db; + QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.tar")), QString::fromLatin1("tar")); + QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.bz2")), QString::fromLatin1("bz2")); + QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.bar.bz2")), QString::fromLatin1("bz2")); + QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.tar.bz2")), QString::fromLatin1("tar.bz2")); +} + +void tst_QMimeDatabase::findByFileName_data() +{ + QTest::addColumn<QString>("filePath"); + QTest::addColumn<QString>("mimeTypeName"); + QTest::addColumn<QString>("xFail"); + + QString prefix = QLatin1String(SRCDIR "testfiles/"); + + QFile f(prefix + QLatin1String("list")); + if (!f.open(QIODevice::ReadOnly)) { + const QString warning = QString::fromLatin1( + "Please download the shared-mime-info test suite:\n" + "cd tests/auto/corelib/mimetypes/qmimedatabase\n" + "wget http://cgit.freedesktop.org/xdg/shared-mime-info/snapshot/Release-1-0.zip\n" + "unzip Release-1-0.zip\n" + "ln -s Release-1-0/tests testfiles\n" + ); + qWarning() << warning; + QSKIP("shared-mime-info test suite not available."); + } + + QByteArray line(1024, Qt::Uninitialized); + + while (!f.atEnd()) { + int len = f.readLine(line.data(), 1023); + + if (len <= 2 || line.at(0) == '#') + continue; + + QString string = QString::fromLatin1(line.constData(), len - 1).trimmed(); + QStringList list = string.split(QLatin1Char(' '), QString::SkipEmptyParts); + QVERIFY(list.size() >= 2); + + QString filePath = list.at(0); + QString mimeTypeType = list.at(1); + QString xFail; + if (list.size() >= 3) + xFail = list.at(2); + + QTest::newRow(filePath.toLatin1().constData()) << QString(prefix + filePath) << mimeTypeType << xFail; + } +} + +void tst_QMimeDatabase::findByFileName() +{ + QFETCH(QString, filePath); + QFETCH(QString, mimeTypeName); + QFETCH(QString, xFail); + + QMimeDatabase database; + + //qDebug() << Q_FUNC_INFO << filePath; + + const QMimeType resultMimeType(database.mimeTypeForFile(filePath, QMimeDatabase::MatchExtension)); + if (resultMimeType.isValid()) { + //qDebug() << Q_FUNC_INFO << "MIME type" << resultMimeType.name() << "has generic icon name" << resultMimeType.genericIconName() << "and icon name" << resultMimeType.iconName(); + +// Loading icons depend on the icon theme, we can't enable this test +#if 0 + QCOMPARE(resultMimeType.genericIconName(), QIcon::fromTheme(resultMimeType.genericIconName()).name()); + QVERIFY2(!QIcon::fromTheme(resultMimeType.genericIconName()).isNull(), qPrintable(resultMimeType.genericIconName())); + QVERIFY2(QIcon::hasThemeIcon(resultMimeType.genericIconName()), qPrintable(resultMimeType.genericIconName())); + + QCOMPARE(resultMimeType.iconName(), QIcon::fromTheme(resultMimeType.iconName()).name()); + QVERIFY2(!QIcon::fromTheme(resultMimeType.iconName()).isNull(), qPrintable(resultMimeType.iconName())); + QVERIFY2(QIcon::hasThemeIcon(resultMimeType.iconName()), qPrintable(resultMimeType.iconName())); +#endif + } + const QString resultMimeTypeName = resultMimeType.name(); + //qDebug() << Q_FUNC_INFO << "mimeTypeForFile() returned" << resultMimeTypeName; + + const bool failed = resultMimeTypeName != mimeTypeName; + const bool shouldFail = (xFail.length() >= 1 && xFail.at(0) == QLatin1Char('x')); + if (shouldFail != failed) { + // Results are ambiguous when multiple MIME types have the same glob + // -> accept the current result if the found MIME type actually + // matches the file's extension. + // TODO: a better file format in testfiles/list! + const QMimeType foundMimeType = database.mimeTypeForName(resultMimeTypeName); + QVERIFY2(resultMimeType == foundMimeType, qPrintable(resultMimeType.name() + QString::fromLatin1(" vs. ") + foundMimeType.name())); + if (foundMimeType.isValid()) { + const QString extension = QFileInfo(filePath).suffix(); + //qDebug() << Q_FUNC_INFO << "globPatterns:" << foundMimeType.globPatterns() << "- extension:" << QString() + "*." + extension; + if (foundMimeType.globPatterns().contains(QString::fromLatin1("*.") + extension)) + return; + } + } + if (shouldFail) { + // Expected to fail + QVERIFY2(resultMimeTypeName != mimeTypeName, qPrintable(resultMimeTypeName)); + } else { + QCOMPARE(resultMimeTypeName, mimeTypeName); + } + + // Test QFileInfo overload + const QMimeType mimeForFileInfo = database.mimeTypeForFile(QFileInfo(filePath), QMimeDatabase::MatchExtension); + QCOMPARE(mimeForFileInfo.name(), resultMimeTypeName); +} + +void tst_QMimeDatabase::findByData_data() +{ + findByFileName_data(); +} + +void tst_QMimeDatabase::findByData() +{ + QFETCH(QString, filePath); + QFETCH(QString, mimeTypeName); + QFETCH(QString, xFail); + + QMimeDatabase database; + QFile f(filePath); + QVERIFY(f.open(QIODevice::ReadOnly)); + QByteArray data = f.read(16384); + + const QString resultMimeTypeName = database.mimeTypeForData(data).name(); + if (xFail.length() >= 2 && xFail.at(1) == QLatin1Char('x')) { + // Expected to fail + QVERIFY2(resultMimeTypeName != mimeTypeName, qPrintable(resultMimeTypeName)); + } else { + QCOMPARE(resultMimeTypeName, mimeTypeName); + } + + QFileInfo info(filePath); + QString mimeForInfo = database.mimeTypeForFile(info, QMimeDatabase::MatchContent).name(); + QCOMPARE(mimeForInfo, resultMimeTypeName); +} + +void tst_QMimeDatabase::findByFile_data() +{ + findByFileName_data(); +} + +void tst_QMimeDatabase::findByFile() +{ + QFETCH(QString, filePath); + QFETCH(QString, mimeTypeName); + QFETCH(QString, xFail); + + QMimeDatabase database; + const QString resultMimeTypeName = database.mimeTypeForFile(filePath).name(); + //qDebug() << Q_FUNC_INFO << filePath << "->" << resultMimeTypeName; + if (xFail.length() >= 3 && xFail.at(2) == QLatin1Char('x')) { + // Expected to fail + QVERIFY2(resultMimeTypeName != mimeTypeName, qPrintable(resultMimeTypeName)); + } else { + QCOMPARE(resultMimeTypeName, mimeTypeName); + } + + // Test QFileInfo overload + const QMimeType mimeForFileInfo = database.mimeTypeForFile(QFileInfo(filePath)); + QCOMPARE(mimeForFileInfo.name(), resultMimeTypeName); +} + + +void tst_QMimeDatabase::fromThreads() +{ + QThreadPool::globalInstance()->setMaxThreadCount(20); + // Note that data-based tests cannot be used here (QTest::fetchData asserts). + QList<QFuture<void> > futures; + futures << QtConcurrent::run(this, &tst_QMimeDatabase::mimeTypeForName); + futures << QtConcurrent::run(this, &tst_QMimeDatabase::aliases); + futures << QtConcurrent::run(this, &tst_QMimeDatabase::allMimeTypes); + futures << QtConcurrent::run(this, &tst_QMimeDatabase::icons); + futures << QtConcurrent::run(this, &tst_QMimeDatabase::inheritance); + futures << QtConcurrent::run(this, &tst_QMimeDatabase::knownSuffix); + futures << QtConcurrent::run(this, &tst_QMimeDatabase::mimeTypeForFileWithContent); + futures << QtConcurrent::run(this, &tst_QMimeDatabase::allMimeTypes); // a second time + Q_FOREACH (QFuture<void> f, futures) + f.waitForFinished(); +} + +static bool runUpdateMimeDatabase(const QString &path) // TODO make it a QMimeDatabase method? +{ + const QString umd = QStandardPaths::findExecutable(QString::fromLatin1("update-mime-database")); + if (umd.isEmpty()) + return false; + + QProcess proc; + proc.setProcessChannelMode(QProcess::MergedChannels); // silence output + proc.start(umd, QStringList() << path); + proc.waitForFinished(); + //qDebug() << "runUpdateMimeDatabase" << path; + return true; +} + +static bool waitAndRunUpdateMimeDatabase(const QString &path) +{ + QFileInfo mimeCacheInfo(path + QString::fromLatin1("/mime.cache")); + if (mimeCacheInfo.exists()) { + // Wait until the begining of the next second + while (mimeCacheInfo.lastModified().secsTo(QDateTime::currentDateTime()) == 0) { + QTest::qSleep(200); + } + } + return runUpdateMimeDatabase(path); +} + +static void checkHasMimeType(const QString &mimeType) +{ + QMimeDatabase db; + QVERIFY(db.mimeTypeForName(mimeType).isValid()); + + bool found = false; + foreach (const QMimeType &mt, db.allMimeTypes()) { + if (mt.name() == mimeType) { + found = true; + break; + } + } + QVERIFY(found); +} + +QT_BEGIN_NAMESPACE +extern Q_CORE_EXPORT int qmime_secondsBetweenChecks; // see qmimeprovider.cpp +QT_END_NAMESPACE + +void tst_QMimeDatabase::installNewGlobalMimeType() +{ + qmime_secondsBetweenChecks = 0; + + QMimeDatabase db; + QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); + + const QString fileName = QLatin1String("yast2-metapackage-handler-mimetypes.xml"); + const QString srcFile = QFile::decodeName(SRCDIR) + fileName; + + QDir here = QDir::currentPath(); + const QString mimeDir = here.absolutePath() + QLatin1String("/mime"); + const QString destDir = mimeDir + QLatin1String("/packages/"); + const QString destFile = destDir + fileName; + QFile::remove(destFile); + //qDebug() << destFile; + QVERIFY(QFile::copy(srcFile, destFile)); + if (!waitAndRunUpdateMimeDatabase(mimeDir)) + QSKIP("shared-mime-info not found, skipping mime.cache test"); + + QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), + QString::fromLatin1("text/x-suse-ymu")); + QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); + checkHasMimeType("text/x-suse-ymp"); + + // Now test removing it again + QFile::remove(destFile); + if (!waitAndRunUpdateMimeDatabase(mimeDir)) + QSKIP("shared-mime-info not found, skipping mime.cache test"); + QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), + QString::fromLatin1("application/octet-stream")); + QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); +} + +void tst_QMimeDatabase::installNewLocalMimeType() +{ + qmime_secondsBetweenChecks = 0; + + QMimeDatabase db; + QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); + + const QString fileName = QLatin1String("yast2-metapackage-handler-mimetypes.xml"); + const QString srcFile = QFile::decodeName(SRCDIR) + fileName; + const QString mimeDir = m_dataHome + QLatin1String("/mime"); + const QString destDir = mimeDir + QLatin1String("/packages/"); + QDir().mkpath(destDir); + const QString destFile = destDir + fileName; + QFile::remove(destFile); + QVERIFY(QFile::copy(srcFile, destFile)); + if (!runUpdateMimeDatabase(mimeDir)) + QSKIP("shared-mime-info not found, skipping mime.cache test");; + + QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), + QString::fromLatin1("text/x-suse-ymu")); + QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); + checkHasMimeType("text/x-suse-ymp"); + + // Now test removing it again (note, this leaves a mostly-empty mime.cache file) + QFile::remove(destFile); + if (!waitAndRunUpdateMimeDatabase(mimeDir)) + QSKIP("shared-mime-info not found, skipping mime.cache test"); + QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), + QString::fromLatin1("application/octet-stream")); + QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); + + // And now the user goes wild and uses rm -rf + QFile::remove(mimeDir + QString::fromLatin1("/mime.cache")); + QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), + QString::fromLatin1("application/octet-stream")); + QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); +} + +QTEST_GUILESS_MAIN(tst_QMimeDatabase) diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h new file mode 100644 index 0000000000..869990401c --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TST_QMIMEDATABASE_H +#define TST_QMIMEDATABASE_H + +#include <QtCore/QObject> + +class tst_QMimeDatabase : public QObject +{ + Q_OBJECT + +public: + tst_QMimeDatabase(); + +private slots: + void initTestCase(); + void cleanupTestCase(); + + void mimeTypeForName(); + void mimeTypeForFileName_data(); + void mimeTypeForFileName(); + void mimeTypesForFileName_data(); + void mimeTypesForFileName(); + void inheritance(); + void aliases(); + void icons(); + void mimeTypeForFileWithContent(); + void mimeTypeForUrl(); + void mimeTypeForData_data(); + void mimeTypeForData(); + void mimeTypeForFileAndContent_data(); + void mimeTypeForFileAndContent(); + void allMimeTypes(); + void inheritsPerformance(); + void suffixes_data(); + void suffixes(); + void knownSuffix(); + void fromThreads(); + + // shared-mime-info test suite + + void findByFileName_data(); + void findByFileName(); + + void findByData_data(); + void findByData(); + + void findByFile_data(); + void findByFile(); + + // + + void installNewGlobalMimeType(); + void installNewLocalMimeType(); + +private: + QString m_dataHome; +}; + +#endif // TST_QMIMEDATABASE_H diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/yast2-metapackage-handler-mimetypes.xml b/tests/auto/corelib/mimetypes/qmimedatabase/yast2-metapackage-handler-mimetypes.xml new file mode 100644 index 0000000000..ef3035ef4a --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/yast2-metapackage-handler-mimetypes.xml @@ -0,0 +1,15 @@ +<?xml version="1.0"?> +<!-- http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec --> +<!-- to to ${PREFIX-~/.local}/share/mime/packages --> +<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> + <mime-type type="text/x-suse-ymp"> + <comment>YaST Meta Package</comment> + <glob pattern="*.ymp"/> + </mime-type> + + <mime-type type="text/x-suse-ymu"> + <comment>URL of a YaST Meta Package</comment> + <glob pattern="*.ymu"/> + </mime-type> +</mime-info> + diff --git a/tests/auto/corelib/mimetypes/qmimetype/qmimetype.pro b/tests/auto/corelib/mimetypes/qmimetype/qmimetype.pro new file mode 100644 index 0000000000..125d0d280f --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimetype/qmimetype.pro @@ -0,0 +1,7 @@ +CONFIG += testcase parallel_test +TARGET = tst_qmimetype +QT = core-private testlib + +*-g++*:QMAKE_CXXFLAGS += -W -Wall -Wextra -Werror -Wshadow -Wno-long-long -Wnon-virtual-dtor + +SOURCES = tst_qmimetype.cpp diff --git a/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp b/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp new file mode 100644 index 0000000000..6f24bfe6f1 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp @@ -0,0 +1,257 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <private/qmimetype_p.h> + +#include <qmimetype.h> +#include <qmimedatabase.h> + +#include <QtTest/QtTest> + + +class tst_qmimetype : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + + void isValid(); + void name(); + void genericIconName(); + void iconName(); + void suffixes(); +}; + +// ------------------------------------------------------------------------------------------------ + +void tst_qmimetype::initTestCase() +{ + qputenv("XDG_DATA_DIRS", "doesnotexist"); +} + +// ------------------------------------------------------------------------------------------------ + +static QString qMimeTypeName() +{ + static const QString result ("No name of the MIME type"); + return result; +} + +static QString qMimeTypeGenericIconName() +{ + static const QString result ("No file name of an icon image that represents the MIME type"); + return result; +} + +static QString qMimeTypeIconName() +{ + static const QString result ("No file name of an icon image that represents the MIME type"); + return result; +} + +static QStringList buildQMimeTypeFilenameExtensions() +{ + QStringList result; + result << QString::fromLatin1("*.png"); + return result; +} + +static QStringList qMimeTypeGlobPatterns() +{ + static const QStringList result (buildQMimeTypeFilenameExtensions()); + return result; +} + +// ------------------------------------------------------------------------------------------------ + +#ifndef Q_COMPILER_RVALUE_REFS +QMIMETYPE_BUILDER +#else +QMIMETYPE_BUILDER_FROM_RVALUE_REFS +#endif + +// ------------------------------------------------------------------------------------------------ + +void tst_qmimetype::isValid() +{ + QMimeType instantiatedQMimeType ( + buildQMimeType ( + qMimeTypeName(), + qMimeTypeGenericIconName(), + qMimeTypeIconName(), + qMimeTypeGlobPatterns() + ) + ); + + QVERIFY(instantiatedQMimeType.isValid()); + + QMimeType otherQMimeType (instantiatedQMimeType); + + QVERIFY(otherQMimeType.isValid()); + QCOMPARE(instantiatedQMimeType, otherQMimeType); + + QMimeType defaultQMimeType; + + QVERIFY(!defaultQMimeType.isValid()); +} + +// ------------------------------------------------------------------------------------------------ + +void tst_qmimetype::name() +{ + QMimeType instantiatedQMimeType ( + buildQMimeType ( + qMimeTypeName(), + qMimeTypeGenericIconName(), + qMimeTypeIconName(), + qMimeTypeGlobPatterns() + ) + ); + + QMimeType otherQMimeType ( + buildQMimeType ( + QString(), + qMimeTypeGenericIconName(), + qMimeTypeIconName(), + qMimeTypeGlobPatterns() + ) + ); + + // Verify that the Name is part of the equality test: + QCOMPARE(instantiatedQMimeType.name(), qMimeTypeName()); + + QVERIFY(instantiatedQMimeType != otherQMimeType); + QVERIFY(!(instantiatedQMimeType == otherQMimeType)); +} + +// ------------------------------------------------------------------------------------------------ + +void tst_qmimetype::genericIconName() +{ + QMimeType instantiatedQMimeType ( + buildQMimeType ( + qMimeTypeName(), + qMimeTypeGenericIconName(), + qMimeTypeIconName(), + qMimeTypeGlobPatterns() + ) + ); + + QMimeType otherQMimeType ( + buildQMimeType ( + qMimeTypeName(), + QString(), + qMimeTypeGenericIconName(), + qMimeTypeGlobPatterns() + ) + ); + + // Verify that the GenericIconName is part of the equality test: + QCOMPARE(instantiatedQMimeType.genericIconName(), qMimeTypeGenericIconName()); + + QVERIFY(instantiatedQMimeType != otherQMimeType); + QVERIFY(!(instantiatedQMimeType == otherQMimeType)); +} + +// ------------------------------------------------------------------------------------------------ + +void tst_qmimetype::iconName() +{ + QMimeType instantiatedQMimeType ( + buildQMimeType ( + qMimeTypeName(), + qMimeTypeGenericIconName(), + qMimeTypeIconName(), + qMimeTypeGlobPatterns() + ) + ); + + QMimeType otherQMimeType ( + buildQMimeType ( + qMimeTypeName(), + qMimeTypeGenericIconName(), + QString(), + qMimeTypeGlobPatterns() + ) + ); + + // Verify that the IconName is part of the equality test: + QCOMPARE(instantiatedQMimeType.iconName(), qMimeTypeIconName()); + + QVERIFY(instantiatedQMimeType != otherQMimeType); + QVERIFY(!(instantiatedQMimeType == otherQMimeType)); +} + +// ------------------------------------------------------------------------------------------------ + +void tst_qmimetype::suffixes() +{ + QMimeType instantiatedQMimeType ( + buildQMimeType ( + qMimeTypeName(), + qMimeTypeGenericIconName(), + qMimeTypeIconName(), + qMimeTypeGlobPatterns() + ) + ); + + QMimeType otherQMimeType ( + buildQMimeType ( + qMimeTypeName(), + qMimeTypeGenericIconName(), + qMimeTypeIconName(), + QStringList() + ) + ); + + // Verify that the Suffixes are part of the equality test: + QCOMPARE(instantiatedQMimeType.globPatterns(), qMimeTypeGlobPatterns()); + QCOMPARE(instantiatedQMimeType.suffixes(), QStringList() << QString::fromLatin1("png")); + + QVERIFY(instantiatedQMimeType != otherQMimeType); + QVERIFY(!(instantiatedQMimeType == otherQMimeType)); +} + +// ------------------------------------------------------------------------------------------------ + +QTEST_GUILESS_MAIN(tst_qmimetype) +#include "tst_qmimetype.moc" diff --git a/tests/auto/corelib/plugin/qlibrary/tst/tst.pro b/tests/auto/corelib/plugin/qlibrary/tst/tst.pro index 6e71ec8ff9..ae6cf97891 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst/tst.pro +++ b/tests/auto/corelib/plugin/qlibrary/tst/tst.pro @@ -1,4 +1,5 @@ CONFIG += testcase +CONFIG -= app_bundle TARGET = ../tst_qlibrary QT = core testlib SOURCES = ../tst_qlibrary.cpp @@ -12,3 +13,5 @@ win32 { } TESTDATA += ../library_path/invalid.so + +win32:CONFIG += insignificant_test # QTBUG-24151 diff --git a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp index cff98de54f..efbc89880f 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp +++ b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp @@ -258,7 +258,7 @@ void tst_QLibrary::unload() void tst_QLibrary::unload_after_implicit_load() { - QLibrary library( "./mylib" ); + QLibrary library( QCoreApplication::applicationDirPath() + "/mylib" ); QFunctionPointer p = library.resolve("mylibversion"); QVERIFY(p); // Check if it was loaded QVERIFY(library.isLoaded()); diff --git a/tests/auto/corelib/thread/qsemaphore/qsemaphore.pro b/tests/auto/corelib/thread/qsemaphore/qsemaphore.pro index cd87e68848..0ad311de99 100644 --- a/tests/auto/corelib/thread/qsemaphore/qsemaphore.pro +++ b/tests/auto/corelib/thread/qsemaphore/qsemaphore.pro @@ -2,5 +2,3 @@ CONFIG += testcase parallel_test TARGET = tst_qsemaphore QT = core testlib SOURCES = tst_qsemaphore.cpp - -mac*:CONFIG+=insignificant_test diff --git a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp index 1d54c8e036..884e8718cb 100644 --- a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp +++ b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp @@ -223,11 +223,21 @@ void tst_QSemaphore::tryAcquireWithTimeout() { QFETCH(int, timeout); + // timers are not guaranteed to be accurate down to the last millisecond, + // so we permit the elapsed times to be up to this far from the expected value. + int fuzz = 10; + QSemaphore semaphore; QTime time; -#define QVERIFYGE(a,b) QVERIFY2(a >= b, qPrintable(QString("%1 = %2 !>= %3 = %4").arg(#a).arg(a).arg(#b).arg(b))); -#define QVERIFYLE(a,b) QVERIFY2(a <= b, qPrintable(QString("%1 = %2 !<= %3 = %4").arg(#a).arg(a).arg(#b).arg(b))); +#define FUZZYCOMPARE(a,e) \ + do { \ + int a1 = a; \ + int e1 = e; \ + QVERIFY2(qAbs(a1-e1) < fuzz, \ + qPrintable(QString("(%1=%2) is more than %3 milliseconds different from (%4=%5)") \ + .arg(#a).arg(a1).arg(fuzz).arg(#e).arg(e1))); \ + } while (0) QCOMPARE(semaphore.available(), 0); @@ -235,73 +245,72 @@ void tst_QSemaphore::tryAcquireWithTimeout() QCOMPARE(semaphore.available(), 1); time.start(); QVERIFY(!semaphore.tryAcquire(2, timeout)); - QVERIFYGE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), timeout); QCOMPARE(semaphore.available(), 1); semaphore.release(); QCOMPARE(semaphore.available(), 2); time.start(); QVERIFY(!semaphore.tryAcquire(3, timeout)); - QVERIFYGE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), timeout); QCOMPARE(semaphore.available(), 2); semaphore.release(10); QCOMPARE(semaphore.available(), 12); time.start(); QVERIFY(!semaphore.tryAcquire(100, timeout)); - QVERIFYGE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), timeout); QCOMPARE(semaphore.available(), 12); semaphore.release(10); QCOMPARE(semaphore.available(), 22); time.start(); QVERIFY(!semaphore.tryAcquire(100, timeout)); - QVERIFYGE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), timeout); QCOMPARE(semaphore.available(), 22); time.start(); QVERIFY(semaphore.tryAcquire(1, timeout)); - QVERIFYLE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), 0); QCOMPARE(semaphore.available(), 21); time.start(); QVERIFY(semaphore.tryAcquire(1, timeout)); - QVERIFYLE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), 0); QCOMPARE(semaphore.available(), 20); time.start(); QVERIFY(semaphore.tryAcquire(10, timeout)); - QVERIFYLE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), 0); QCOMPARE(semaphore.available(), 10); time.start(); QVERIFY(semaphore.tryAcquire(10, timeout)); - QVERIFYLE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), 0); QCOMPARE(semaphore.available(), 0); // should not be able to acquire more time.start(); QVERIFY(!semaphore.tryAcquire(1, timeout)); - QVERIFYGE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), timeout); QCOMPARE(semaphore.available(), 0); time.start(); QVERIFY(!semaphore.tryAcquire(1, timeout)); - QVERIFYGE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), timeout); QCOMPARE(semaphore.available(), 0); time.start(); QVERIFY(!semaphore.tryAcquire(10, timeout)); - QVERIFYGE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), timeout); QCOMPARE(semaphore.available(), 0); time.start(); QVERIFY(!semaphore.tryAcquire(10, timeout)); - QVERIFYGE(time.elapsed(), timeout); + FUZZYCOMPARE(time.elapsed(), timeout); QCOMPARE(semaphore.available(), 0); -#undef QVERIFYGE -#undef QVERIFYLE +#undef FUZZYCOMPARE } void tst_QSemaphore::tryAcquireWithTimeoutStarvation() diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 1dd0410f41..aa4d163fc4 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -367,17 +367,17 @@ void tst_QThreadPool::setMaxThreadCount_data() { QTest::addColumn<int>("limit"); - QTest::newRow("") << 1; - QTest::newRow("") << -1; - QTest::newRow("") << 2; - QTest::newRow("") << -2; - QTest::newRow("") << 4; - QTest::newRow("") << -4; - QTest::newRow("") << 0; - QTest::newRow("") << 12345; - QTest::newRow("") << -6789; - QTest::newRow("") << 42; - QTest::newRow("") << -666; + QTest::newRow("1") << 1; + QTest::newRow("-1") << -1; + QTest::newRow("2") << 2; + QTest::newRow("-2") << -2; + QTest::newRow("4") << 4; + QTest::newRow("-4") << -4; + QTest::newRow("0") << 0; + QTest::newRow("12345") << 12345; + QTest::newRow("-6789") << -6789; + QTest::newRow("42") << 42; + QTest::newRow("-666") << -666; } void tst_QThreadPool::setMaxThreadCount() diff --git a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp index 578f867032..0e1fa47a3e 100644 --- a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp +++ b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp @@ -59,14 +59,8 @@ private slots: void wait_RaceCondition(); }; -static const int iterations = 10; - -// Note: some tests rely on ThreadCount being multiple of 2 -#if defined(Q_OS_SOLARIS) || ( defined(Q_OS_LINUX) && defined(QT_ARCH_ARMV6) ) +static const int iterations = 4; static const int ThreadCount = 4; -#else -static const int ThreadCount = 10; -#endif class wait_QMutex_Thread_1 : public QThread { diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index e442aa7e1a..13a6b3d471 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -521,7 +521,10 @@ void tst_QByteArray::qvsnprintf() QCOMPARE(::qsnprintf(buf, 10, "%s", "bubu"), 4); QCOMPARE(static_cast<const char *>(buf), "bubu"); +#ifndef Q_CC_MSVC + // MSVC implementation of vsnprintf overwrites bytes after null terminator so this would fail. QCOMPARE(buf[5], char(42)); +#endif qMemSet(buf, 42, sizeof(buf)); QCOMPARE(::qsnprintf(buf, 5, "%s", "bubu"), 4); @@ -862,7 +865,7 @@ void tst_QByteArray::indexOf_data() QTest::newRow("BoyerMooreStressTest4") << QByteArray(veryBigHaystack) << QByteArray(veryBigHaystack + 'c') << 0 << -1; QTest::newRow("BoyerMooreStressTest5") << QByteArray(veryBigHaystack) << QByteArray('c' + veryBigHaystack) << 0 << -1; QTest::newRow("BoyerMooreStressTest6") << QByteArray('d' + veryBigHaystack) << QByteArray('c' + veryBigHaystack) << 0 << -1; - QTest::newRow("BoyerMooreStressTest6") << QByteArray(veryBigHaystack + 'c') << QByteArray('c' + veryBigHaystack) << 0 << -1; + QTest::newRow("BoyerMooreStressTest7") << QByteArray(veryBigHaystack + 'c') << QByteArray('c' + veryBigHaystack) << 0 << -1; } void tst_QByteArray::indexOf() @@ -985,13 +988,13 @@ void tst_QByteArray::toInt_data() QTest::addColumn<bool>("expectedok"); QTest::newRow("base 10") << QByteArray("100") << 10 << int(100) << true; - QTest::newRow("base 16") << QByteArray("100") << 16 << int(256) << true; - QTest::newRow("base 16") << QByteArray("0400") << 16 << int(1024) << true; + QTest::newRow("base 16-1") << QByteArray("100") << 16 << int(256) << true; + QTest::newRow("base 16-2") << QByteArray("0400") << 16 << int(1024) << true; QTest::newRow("base 2") << QByteArray("1111") << 2 << int(15) << true; QTest::newRow("base 8") << QByteArray("100") << 8 << int(64) << true; - QTest::newRow("base 0") << QByteArray("0x10") << 0 << int(16) << true; - QTest::newRow("base 0") << QByteArray("10") << 0 << int(10) << true; - QTest::newRow("base 0") << QByteArray("010") << 0 << int(8) << true; + QTest::newRow("base 0-1") << QByteArray("0x10") << 0 << int(16) << true; + QTest::newRow("base 0-2") << QByteArray("10") << 0 << int(10) << true; + QTest::newRow("base 0-3") << QByteArray("010") << 0 << int(8) << true; QTest::newRow("empty") << QByteArray() << 0 << int(0) << false; // using fromRawData @@ -999,7 +1002,7 @@ void tst_QByteArray::toInt_data() QTest::newRow("raw2") << QByteArray::fromRawData("1foo", 1) << 10 << 1 << true; QTest::newRow("raw3") << QByteArray::fromRawData("12", 1) << 10 << 1 << true; QTest::newRow("raw4") << QByteArray::fromRawData("123456789", 1) << 10 << 1 << true; - QTest::newRow("raw4") << QByteArray::fromRawData("123456789", 2) << 10 << 12 << true; + QTest::newRow("raw5") << QByteArray::fromRawData("123456789", 2) << 10 << 12 << true; QTest::newRow("raw-static") << QByteArray::fromRawData(&globalChar, 1) << 10 << 1 << true; } @@ -1398,58 +1401,58 @@ void tst_QByteArray::repeated_data() const QTest::addColumn<int>("count" ); /* Empty strings. */ - QTest::newRow("") + QTest::newRow("data1") << QByteArray() << QByteArray() << 0; - QTest::newRow("") + QTest::newRow("data2") << QByteArray() << QByteArray() << -1004; - QTest::newRow("") + QTest::newRow("data3") << QByteArray() << QByteArray() << 1; - QTest::newRow("") + QTest::newRow("data4") << QByteArray() << QByteArray() << 5; /* On simple string. */ - QTest::newRow("") + QTest::newRow("data5") << QByteArray("abc") << QByteArray() << -1004; - QTest::newRow("") + QTest::newRow("data6") << QByteArray("abc") << QByteArray() << -1; - QTest::newRow("") + QTest::newRow("data7") << QByteArray("abc") << QByteArray() << 0; - QTest::newRow("") + QTest::newRow("data8") << QByteArray("abc") << QByteArray("abc") << 1; - QTest::newRow("") + QTest::newRow("data9") << QByteArray(("abc")) << QByteArray(("abcabc")) << 2; - QTest::newRow("") + QTest::newRow("data10") << QByteArray(("abc")) << QByteArray(("abcabcabc")) << 3; - QTest::newRow("") + QTest::newRow("data11") << QByteArray(("abc")) << QByteArray(("abcabcabcabc")) << 4; diff --git a/tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro b/tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro index fddd67fbd6..1c4b74e16d 100644 --- a/tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro +++ b/tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro @@ -3,14 +3,4 @@ TARGET = tst_qcryptographichash QT = core testlib SOURCES = tst_qcryptographichash.cpp - -wince* { - addFiles.files = data/* - addFiles.path = data/ - DEPLOYMENT += addFiles - - DEFINES += SRCDIR=\\\".\\\" -} -else { - DEFINES += SRCDIR=\\\"$$PWD/\\\" -}
\ No newline at end of file +TESTDATA += data/* diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp index 3a257c2f11..81cc66f045 100644 --- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp +++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp @@ -158,8 +158,8 @@ void tst_QCryptographicHash::files_data() { QTest::addColumn<QString>("filename"); QTest::addColumn<QCryptographicHash::Algorithm>("algorithm"); QTest::addColumn<QByteArray>("md5sum"); - QTest::newRow("Line") << QString::fromAscii("data/2c1517dad3678f03917f15849b052fd5.md5") << QCryptographicHash::Md5 << QByteArray("2c1517dad3678f03917f15849b052fd5"); - QTest::newRow("Line") << QString::fromAscii("data/d41d8cd98f00b204e9800998ecf8427e.md5") << QCryptographicHash::Md5 << QByteArray("d41d8cd98f00b204e9800998ecf8427e"); + QTest::newRow("data1") << QString::fromAscii("data/2c1517dad3678f03917f15849b052fd5.md5") << QCryptographicHash::Md5 << QByteArray("2c1517dad3678f03917f15849b052fd5"); + QTest::newRow("data2") << QString::fromAscii("data/d41d8cd98f00b204e9800998ecf8427e.md5") << QCryptographicHash::Md5 << QByteArray("d41d8cd98f00b204e9800998ecf8427e"); } @@ -169,7 +169,9 @@ void tst_QCryptographicHash::files() QFETCH(QCryptographicHash::Algorithm, algorithm); QFETCH(QByteArray, md5sum); { - QFile f(QString::fromLocal8Bit(SRCDIR) + filename); + QString testData = QFINDTESTDATA(filename); + QVERIFY2(!testData.isEmpty(), qPrintable(QString("Cannot find test data: %1").arg(filename))); + QFile f(testData); QCryptographicHash hash(algorithm); QVERIFY(! hash.addData(&f)); // file is not open for reading; if (f.open(QIODevice::ReadOnly)) { diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp index 4921a7e734..258dbf8625 100644 --- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp @@ -147,14 +147,14 @@ void tst_QDate::isValid_data() QTest::newRow("month 13") << 2000 << 13 << 1 << nullJd << false; // test leap years - QTest::newRow("non-leap") << 2006 << 2 << 29 << nullJd << false; - QTest::newRow("normal leap") << 2004 << 2 << 29 << qint64(2453065) << true; - QTest::newRow("century leap") << 1900 << 2 << 29 << nullJd << false; - QTest::newRow("century leap") << 2100 << 2 << 29 << nullJd << false; - QTest::newRow("400-years leap") << 2000 << 2 << 29 << qint64(2451604) << true; - QTest::newRow("400-years leap 2") << 2400 << 2 << 29 << qint64(2597701) << true; - QTest::newRow("400-years leap 3") << 1600 << 2 << 29 << qint64(2305507) << true; - QTest::newRow("year 0") << 0 << 2 << 27 << nullJd << false; + QTest::newRow("non-leap") << 2006 << 2 << 29 << nullJd << false; + QTest::newRow("normal leap") << 2004 << 2 << 29 << qint64(2453065) << true; + QTest::newRow("century leap 1900") << 1900 << 2 << 29 << nullJd << false; + QTest::newRow("century leap 2100") << 2100 << 2 << 29 << nullJd << false; + QTest::newRow("400-years leap 2000") << 2000 << 2 << 29 << qint64(2451604) << true; + QTest::newRow("400-years leap 2400") << 2400 << 2 << 29 << qint64(2597701) << true; + QTest::newRow("400-years leap 1600") << 1600 << 2 << 29 << qint64(2305507) << true; + QTest::newRow("year 0") << 0 << 2 << 27 << nullJd << false; // test the number of days in months: QTest::newRow("jan") << 2000 << 1 << 31 << qint64(2451575) << true; @@ -262,7 +262,7 @@ void tst_QDate::dayOfWeek_data() QTest::newRow("data8") << -4800 << 1 << 1 << 1; QTest::newRow("data9") << -4800 << 1 << 2 << 2; QTest::newRow("data10") << -4800 << 1 << 3 << 3; - QTest::newRow("data12") << -4800 << 1 << 4 << 4; + QTest::newRow("data11") << -4800 << 1 << 4 << 4; QTest::newRow("data12") << -4800 << 1 << 5 << 5; QTest::newRow("data13") << -4800 << 1 << 6 << 6; QTest::newRow("data14") << -4800 << 1 << 7 << 7; @@ -580,10 +580,10 @@ void tst_QDate::addMonths_data() QTest::newRow( "data14" ) << 2000 << 2 << 29 << -12 << 1999 << 2 << 28; // year sign change: - QTest::newRow( "data14" ) << 1 << 1 << 1 << -1 << -1 << 12 << 1; - QTest::newRow( "data15" ) << 1 << 1 << 1 << -12 << -1 << 1 << 1; - QTest::newRow( "data16" ) << -1 << 12 << 1 << 1 << 1 << 1 << 1; - QTest::newRow( "data17" ) << -1 << 1 << 1 << 12 << 1 << 1 << 1; + QTest::newRow( "data15" ) << 1 << 1 << 1 << -1 << -1 << 12 << 1; + QTest::newRow( "data16" ) << 1 << 1 << 1 << -12 << -1 << 1 << 1; + QTest::newRow( "data17" ) << -1 << 12 << 1 << 1 << 1 << 1 << 1; + QTest::newRow( "data18" ) << -1 << 1 << 1 << 12 << 1 << 1 << 1; } void tst_QDate::addYears() diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index af8deefa4c..eb6af23ba5 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -1363,19 +1363,19 @@ void tst_QDateTime::dateFromStringFormat_data() QTest::newRow("data24") << tuesday << QString("dddd") << QDate(1900, 1, 2); QTest::newRow("data25") << wednesday << QString("dddd") << QDate(1900, 1, 3); QTest::newRow("data26") << thursday << QString("dddd") << QDate(1900, 1, 4); - QTest::newRow("data26") << friday << QString("dddd") << QDate(1900, 1, 5); - QTest::newRow("data27") << saturday << QString("dddd") << QDate(1900, 1, 6); - QTest::newRow("data28") << sunday << QString("dddd") << QDate(1900, 1, 7); - - QTest::newRow("data29") << monday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 2); - QTest::newRow("data30") << tuesday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 3); - QTest::newRow("data31") << wednesday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 4); - QTest::newRow("data32") << thursday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 5); - QTest::newRow("data33") << friday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 6); - QTest::newRow("data34") << saturday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 7); - QTest::newRow("data35") << sunday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 1); - - QTest::newRow("data36 ") << tuesday + " 2007 " + march << QString("dddd yyyy MMMM") << QDate(2007, 3, 6); + QTest::newRow("data27") << friday << QString("dddd") << QDate(1900, 1, 5); + QTest::newRow("data28") << saturday << QString("dddd") << QDate(1900, 1, 6); + QTest::newRow("data29") << sunday << QString("dddd") << QDate(1900, 1, 7); + + QTest::newRow("data30") << monday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 2); + QTest::newRow("data31") << tuesday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 3); + QTest::newRow("data32") << wednesday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 4); + QTest::newRow("data33") << thursday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 5); + QTest::newRow("data34") << friday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 6); + QTest::newRow("data35") << saturday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 7); + QTest::newRow("data36") << sunday + " 2006" << QString("dddd yyyy") << QDate(2006, 1, 1); + + QTest::newRow("data37") << tuesday + " 2007 " + march << QString("dddd yyyy MMMM") << QDate(2007, 3, 6); } diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 5544c0fd71..db7f503f57 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -59,7 +59,6 @@ #endif #ifdef Q_OS_WINCE -#include <qcoreapplication.h> #include <windows.h> // needed for GetUserDefaultLCID #define _control87 _controlfp extern "C" DWORD GetThreadLocale(void) { @@ -141,11 +140,6 @@ tst_QLocale::tst_QLocale() void tst_QLocale::ctor() { -#ifdef Q_OS_WINCE - int argc = 1; - char argv[20] = "tst_qlocale.exe"; - QCoreApplication app(argc, (char**)&argv); -#endif QLocale default_locale = QLocale::system(); QLocale::Language default_lang = default_locale.language(); QLocale::Country default_country = default_locale.country(); @@ -934,7 +928,7 @@ void tst_QLocale::formatDateTime_data() << "\"yymm\"" << "\"7414\""; QTest::newRow("27C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13)) << "'\"yymm\"'" << "\"yymm\""; - QTest::newRow("27C") << "C" << QDateTime() + QTest::newRow("28C") << "C" << QDateTime() << "'\"yymm\"'" << ""; QTest::newRow("1no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(5, 14, 13)) @@ -976,7 +970,7 @@ void tst_QLocale::formatDateTime_data() << "\"yymm\"" << "\"7414\""; QTest::newRow("27no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13)) << "'\"yymm\"'" << "\"yymm\""; - QTest::newRow("27no_NO") << "no_NO" << QDateTime() + QTest::newRow("28no_NO") << "no_NO" << QDateTime() << "'\"yymm\"'" << ""; } @@ -1988,5 +1982,5 @@ void tst_QLocale::listPatterns() QCOMPARE(zh_CN.createSeparatedList(sl5), QString::fromUtf8("aaa" "\xe3\x80\x81" "bbb" "\xe3\x80\x81" "ccc" "\xe5\x92\x8c" "ddd")); } -QTEST_APPLESS_MAIN(tst_QLocale) +QTEST_MAIN(tst_QLocale) #include "tst_qlocale.moc" diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.pri b/tests/auto/corelib/tools/qsharedpointer/externaltests.pri index e12bb914c0..10d30e3c76 100644 --- a/tests/auto/corelib/tools/qsharedpointer/externaltests.pri +++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.pri @@ -3,5 +3,5 @@ HEADERS += $$PWD/externaltests.h cleanedQMAKESPEC = $$replace(QMAKESPEC, \\\\, /) DEFINES += DEFAULT_MAKESPEC=\\\"$$cleanedQMAKESPEC\\\" -embedded:DEFINES += QTEST_NO_RTTI QTEST_CROSS_COMPILED +cross_compile:DEFINES += QTEST_NO_RTTI QTEST_CROSS_COMPILED wince*:DEFINES += QTEST_CROSS_COMPILED QTEST_NO_RTTI diff --git a/tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro b/tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro index b1cd309293..1b227109b3 100644 --- a/tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro +++ b/tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro @@ -13,3 +13,5 @@ HEADERS = forwarddeclared.h \ TESTDATA += forwarddeclared.cpp forwarddeclared.h include(externaltests.pri) + +win32:CONFIG += insignificant_test # QTBUG-24160 diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 2bae52a622..5b697a3509 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -76,6 +76,7 @@ private slots: void upCast(); void qobjectWeakManagement(); void noSharedPointerFromWeakQObject(); + void sharedPointerFromQObjectWithWeak(); void weakQObjectFromSharedPointer(); void objectCast(); void differentPointers(); @@ -692,12 +693,34 @@ void tst_QSharedPointer::noSharedPointerFromWeakQObject() QObject obj; QWeakPointer<QObject> weak(&obj); - QSharedPointer<QObject> strong = weak.toStrongRef(); - QVERIFY(strong.isNull()); + { + QTest::ignoreMessage(QtWarningMsg , "QSharedPointer: cannot create a QSharedPointer from a QObject-tracking QWeakPointer"); + QSharedPointer<QObject> strong = weak.toStrongRef(); + QVERIFY(strong.isNull()); + } + { + QTest::ignoreMessage(QtWarningMsg , "QSharedPointer: cannot create a QSharedPointer from a QObject-tracking QWeakPointer"); + QSharedPointer<QObject> strong = weak; + QVERIFY(strong.isNull()); + } + QCOMPARE(weak.data(), &obj); // if something went wrong, we'll probably crash here } +void tst_QSharedPointer::sharedPointerFromQObjectWithWeak() +{ + QObject *ptr = new QObject; + QWeakPointer<QObject> weak = ptr; + { + QSharedPointer<QObject> shared(ptr); + QVERIFY(!weak.isNull()); + QCOMPARE(shared.data(), ptr); + QCOMPARE(weak.data(), ptr); + } + QVERIFY(weak.isNull()); +} + void tst_QSharedPointer::weakQObjectFromSharedPointer() { // this is the inverse of the above: you're allowed to create a QWeakPointer @@ -1070,10 +1093,6 @@ void tst_QSharedPointer::constCorrectness() ptr = cptr.constCast<Data>(); ptr = vptr.constCast<Data>(); -#if !defined(Q_CC_HPACC) && !defined(QT_ARCH_PARISC) - // the aCC series 3 compiler we have on the PA-RISC - // machine crashes compiling this code - QSharedPointer<const volatile Data> cvptr(ptr); QSharedPointer<const volatile Data> cvptr2(cptr); QSharedPointer<const volatile Data> cvptr3(vptr); @@ -1082,7 +1101,6 @@ void tst_QSharedPointer::constCorrectness() cvptr3 = vptr; ptr = qSharedPointerConstCast<Data>(cvptr); ptr = cvptr.constCast<Data>(); -#endif } safetyCheck(); @@ -1767,12 +1785,6 @@ void tst_QSharedPointer::invalidConstructs_data() << "Data *ptr = 0;\n" "QWeakPointer<Data> weakptr(ptr);\n"; - QTest::newRow("shared-pointer-from-unmanaged-qobject") - << &QTest::QExternalTest::tryRunFail - << "QObject *ptr = new QObject;\n" - "QWeakPointer<QObject> weak = ptr;\n" // this makes the object unmanaged - "QSharedPointer<QObject> shared(ptr);\n"; - QTest::newRow("shared-pointer-implicit-from-uninitialized") << &QTest::QExternalTest::tryCompileFail << "Data *ptr = 0;\n" diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 7dd801b50b..e3808244d3 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -447,7 +447,7 @@ void tst_QString::replace_uint_uint_data() QTest::newRow( "rep08" ) << QString("ACABCAB") << 3 << 2 << QString("XX") << QString("ACAXXAB"); QTest::newRow( "rep09" ) << QString("ACABCAB") << 4 << 2 << QString("XX") << QString("ACABXXB"); QTest::newRow( "rep10" ) << QString("ACABCAB") << 5 << 2 << QString("XX") << QString("ACABCXX"); - QTest::newRow( "rep10" ) << QString("ACABCAB") << 6 << 2 << QString("XX") << QString("ACABCAXX"); + QTest::newRow( "rep11" ) << QString("ACABCAB") << 6 << 2 << QString("XX") << QString("ACABCAXX"); QTest::newRow( "rep12" ) << QString() << 0 << 10 << QString("X") << QString("X"); QTest::newRow( "rep13" ) << QString("short") << 0 << 10 << QString("X") << QString("X"); QTest::newRow( "rep14" ) << QString() << 0 << 10 << QString("XX") << QString("XX"); @@ -1042,7 +1042,7 @@ void tst_QString::indexOf_data() QTest::newRow("BoyerMooreStressTest4") << veryBigHaystack << QString(veryBigHaystack + 'c') << 0 << true << -1; QTest::newRow("BoyerMooreStressTest5") << veryBigHaystack << QString('c' + veryBigHaystack) << 0 << true << -1; QTest::newRow("BoyerMooreStressTest6") << QString('d' + veryBigHaystack) << QString('c' + veryBigHaystack) << 0 << true << -1; - QTest::newRow("BoyerMooreStressTest6") << QString(veryBigHaystack + 'c') << QString('c' + veryBigHaystack) << 0 << true << -1; + QTest::newRow("BoyerMooreStressTest7") << QString(veryBigHaystack + 'c') << QString('c' + veryBigHaystack) << 0 << true << -1; QTest::newRow("BoyerMooreInsensitiveStressTest") << veryBigHaystack << veryBigHaystack << 0 << false << 0; @@ -1211,15 +1211,15 @@ void tst_QString::lastIndexOf_data() QTest::newRow("4") << a << "G" << 14 << 14 << true; QTest::newRow("5") << a << "G" << 13 << 11 << true; QTest::newRow("6") << a << "B" << a.size() - 1 << 1 << true; - QTest::newRow("6") << a << "B" << - 1 << 1 << true; - QTest::newRow("7") << a << "B" << 1 << 1 << true; - QTest::newRow("8") << a << "B" << 0 << -1 << true; + QTest::newRow("7") << a << "B" << - 1 << 1 << true; + QTest::newRow("8") << a << "B" << 1 << 1 << true; + QTest::newRow("9") << a << "B" << 0 << -1 << true; - QTest::newRow("9") << a << "G" << -1 << a.size()-1 << true; - QTest::newRow("10") << a << "G" << a.size()-1 << a.size()-1 << true; - QTest::newRow("11") << a << "G" << a.size() << -1 << true; - QTest::newRow("12") << a << "A" << 0 << 0 << true; - QTest::newRow("13") << a << "A" << -1*a.size() << 0 << true; + QTest::newRow("10") << a << "G" << -1 << a.size()-1 << true; + QTest::newRow("11") << a << "G" << a.size()-1 << a.size()-1 << true; + QTest::newRow("12") << a << "G" << a.size() << -1 << true; + QTest::newRow("13") << a << "A" << 0 << 0 << true; + QTest::newRow("14") << a << "A" << -1*a.size() << 0 << true; QTest::newRow("15") << a << "efg" << 0 << -1 << false; QTest::newRow("16") << a << "efg" << a.size() << -1 << false; @@ -4742,8 +4742,8 @@ void tst_QString::compare_data() // different length QTest::newRow("data6") << QString("abcdef") << QString("abc") << 1 << 1; - QTest::newRow("data6") << QString("abCdef") << QString("abc") << -1 << 1; - QTest::newRow("data7") << QString("abc") << QString("abcdef") << -1 << -1; + QTest::newRow("data7") << QString("abCdef") << QString("abc") << -1 << 1; + QTest::newRow("data8") << QString("abc") << QString("abcdef") << -1 << -1; QString upper; upper += QChar(QChar::highSurrogate(0x10400)); @@ -4755,12 +4755,12 @@ void tst_QString::compare_data() // embedded nulls // These don't work as of now. It's OK that these don't work since \0 is not a valid unicode - /*QTest::newRow("data9") << QString(QByteArray("\0", 1)) << QString(QByteArray("\0", 1)) << 0 << 0; - QTest::newRow("data10") << QString(QByteArray("\0", 1)) << QString("") << 1 << 1; - QTest::newRow("data11") << QString("") << QString(QByteArray("\0", 1)) << -1 << -1; - QTest::newRow("data12") << QString("ab\0c") << QString(QByteArray("ab\0c", 4)) << 0 << 0; - QTest::newRow("data13") << QString(QByteArray("ab\0c", 4)) << QString("abc") << -1 << -1; - QTest::newRow("data14") << QString("abc") << QString(QByteArray("ab\0c", 4)) << 1 << 1;*/ + /*QTest::newRow("data10") << QString(QByteArray("\0", 1)) << QString(QByteArray("\0", 1)) << 0 << 0; + QTest::newRow("data11") << QString(QByteArray("\0", 1)) << QString("") << 1 << 1; + QTest::newRow("data12") << QString("") << QString(QByteArray("\0", 1)) << -1 << -1; + QTest::newRow("data13") << QString("ab\0c") << QString(QByteArray("ab\0c", 4)) << 0 << 0; + QTest::newRow("data14") << QString(QByteArray("ab\0c", 4)) << QString("abc") << -1 << -1; + QTest::newRow("data15") << QString("abc") << QString(QByteArray("ab\0c", 4)) << 1 << 1;*/ } static bool isLatin(const QString &s) @@ -5004,58 +5004,58 @@ void tst_QString::repeated_data() const QTest::addColumn<int>("count" ); /* Empty strings. */ - QTest::newRow("") + QTest::newRow("data1") << QString() << QString() << 0; - QTest::newRow("") + QTest::newRow("data2") << QString() << QString() << -1004; - QTest::newRow("") + QTest::newRow("data3") << QString() << QString() << 1; - QTest::newRow("") + QTest::newRow("data4") << QString() << QString() << 5; /* On simple string. */ - QTest::newRow("") + QTest::newRow("data5") << QString(QLatin1String("abc")) << QString() << -1004; - QTest::newRow("") + QTest::newRow("data6") << QString(QLatin1String("abc")) << QString() << -1; - QTest::newRow("") + QTest::newRow("data7") << QString(QLatin1String("abc")) << QString() << 0; - QTest::newRow("") + QTest::newRow("data8") << QString(QLatin1String("abc")) << QString(QLatin1String("abc")) << 1; - QTest::newRow("") + QTest::newRow("data9") << QString(QLatin1String("abc")) << QString(QLatin1String("abcabc")) << 2; - QTest::newRow("") + QTest::newRow("data10") << QString(QLatin1String("abc")) << QString(QLatin1String("abcabcabc")) << 3; - QTest::newRow("") + QTest::newRow("data11") << QString(QLatin1String("abc")) << QString(QLatin1String("abcabcabcabc")) << 4; diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp index e3eb1a21ac..6066f7c8e0 100644 --- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp @@ -193,8 +193,8 @@ void tst_QStringList::removeDuplicates_data() QTest::addColumn<QString>("after"); QTest::addColumn<int>("count"); - QTest::newRow("empty") << "Hello,Hello" << "Hello" << 1; - QTest::newRow("empty") << "Hello,World" << "Hello,World" << 0; + QTest::newRow("empty-1") << "Hello,Hello" << "Hello" << 1; + QTest::newRow("empty-2") << "Hello,World" << "Hello,World" << 0; } void tst_QStringList::removeDuplicates() @@ -245,35 +245,35 @@ void tst_QStringList::join_data() const QTest::addColumn<QString>("separator"); QTest::addColumn<QString>("expectedResult"); - QTest::newRow("") + QTest::newRow("data1") << QStringList() << QString() << QString(); - QTest::newRow("") + QTest::newRow("data2") << QStringList() << QString(QLatin1String("separator")) << QString(); - QTest::newRow("") + QTest::newRow("data3") << QStringList("one") << QString(QLatin1String("separator")) << QString("one"); - QTest::newRow("") + QTest::newRow("data4") << QStringList("one") << QString(QLatin1String("separator")) << QString("one"); - QTest::newRow("") + QTest::newRow("data5") << (QStringList() << QLatin1String("a") << QLatin1String("b")) << QString(QLatin1String(" ")) << QString("a b"); - QTest::newRow("") + QTest::newRow("data6") << (QStringList() << QLatin1String("a") << QLatin1String("b") diff --git a/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp b/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp index ebbad86c81..5829c0e917 100644 --- a/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp +++ b/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp @@ -81,16 +81,16 @@ void tst_QStringMatcher::indexIn_data() QTest::addColumn<QString>("haystack"); QTest::addColumn<int>("from"); QTest::addColumn<int>("indexIn"); - QTest::newRow("empty") << QString() << QString("foo") << 0 << 0; - QTest::newRow("empty") << QString() << QString("foo") << 10 << -1; - QTest::newRow("empty") << QString() << QString("foo") << -10 << 0; - - QTest::newRow("simple") << QString("a") << QString("foo") << 0 << -1; - QTest::newRow("simple") << QString("a") << QString("bar") << 0 << 1; - QTest::newRow("harder") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 0 << 26; - QTest::newRow("harder") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 20 << 26; - QTest::newRow("harder") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 26 << 26; - QTest::newRow("harder") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 27 << -1; + QTest::newRow("empty-1") << QString() << QString("foo") << 0 << 0; + QTest::newRow("empty-2") << QString() << QString("foo") << 10 << -1; + QTest::newRow("empty-3") << QString() << QString("foo") << -10 << 0; + + QTest::newRow("simple-1") << QString("a") << QString("foo") << 0 << -1; + QTest::newRow("simple-2") << QString("a") << QString("bar") << 0 << 1; + QTest::newRow("harder-1") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 0 << 26; + QTest::newRow("harder-2") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 20 << 26; + QTest::newRow("harder-3") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 26 << 26; + QTest::newRow("harder-4") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 27 << -1; } void tst_QStringMatcher::indexIn() diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp index 77d2101320..de01df2001 100644 --- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp +++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp @@ -288,7 +288,7 @@ void tst_QStringRef::indexOf_data() QTest::newRow("BoyerMooreStressTest4") << veryBigHaystack << veryBigHaystack + 'c' << 0 << true << -1; QTest::newRow("BoyerMooreStressTest5") << veryBigHaystack << 'c' + veryBigHaystack << 0 << true << -1; QTest::newRow("BoyerMooreStressTest6") << 'd' + veryBigHaystack << 'c' + veryBigHaystack << 0 << true << -1; - QTest::newRow("BoyerMooreStressTest6") << veryBigHaystack + 'c' << 'c' + veryBigHaystack << 0 << true << -1; + QTest::newRow("BoyerMooreStressTest7") << veryBigHaystack + 'c' << 'c' + veryBigHaystack << 0 << true << -1; QTest::newRow("BoyerMooreInsensitiveStressTest") << veryBigHaystack << veryBigHaystack << 0 << false << 0; @@ -441,15 +441,15 @@ void tst_QStringRef::lastIndexOf_data() QTest::newRow("4") << a << "G" << 14 << 14 << true; QTest::newRow("5") << a << "G" << 13 << 11 << true; QTest::newRow("6") << a << "B" << a.size() - 1 << 1 << true; - QTest::newRow("6") << a << "B" << - 1 << 1 << true; - QTest::newRow("7") << a << "B" << 1 << 1 << true; - QTest::newRow("8") << a << "B" << 0 << -1 << true; + QTest::newRow("7") << a << "B" << - 1 << 1 << true; + QTest::newRow("8") << a << "B" << 1 << 1 << true; + QTest::newRow("9") << a << "B" << 0 << -1 << true; - QTest::newRow("9") << a << "G" << -1 << a.size()-1 << true; - QTest::newRow("10") << a << "G" << a.size()-1 << a.size()-1 << true; - QTest::newRow("11") << a << "G" << a.size() << -1 << true; - QTest::newRow("12") << a << "A" << 0 << 0 << true; - QTest::newRow("13") << a << "A" << -1*a.size() << 0 << true; + QTest::newRow("10") << a << "G" << -1 << a.size()-1 << true; + QTest::newRow("11") << a << "G" << a.size()-1 << a.size()-1 << true; + QTest::newRow("12") << a << "G" << a.size() << -1 << true; + QTest::newRow("13") << a << "A" << 0 << 0 << true; + QTest::newRow("14") << a << "A" << -1*a.size() << 0 << true; QTest::newRow("15") << a << "efg" << 0 << -1 << false; QTest::newRow("16") << a << "efg" << a.size() << -1 << false; @@ -777,8 +777,8 @@ void tst_QStringRef::compare_data() // different length QTest::newRow("data6") << QString("abcdef") << QString("abc") << 1 << 1; - QTest::newRow("data6") << QString("abCdef") << QString("abc") << -1 << 1; - QTest::newRow("data7") << QString("abc") << QString("abcdef") << -1 << -1; + QTest::newRow("data7") << QString("abCdef") << QString("abc") << -1 << 1; + QTest::newRow("data8") << QString("abc") << QString("abcdef") << -1 << -1; QString upper; upper += QChar(QChar::highSurrogate(0x10400)); @@ -786,7 +786,7 @@ void tst_QStringRef::compare_data() QString lower; lower += QChar(QChar::highSurrogate(0x10428)); lower += QChar(QChar::lowSurrogate(0x10428)); - QTest::newRow("data8") << upper << lower << -1 << 0; + QTest::newRow("data9") << upper << lower << -1 << 0; } static bool isLatin(const QString &s) diff --git a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp index 89dd01ac3a..b8ae709fd0 100644 --- a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp +++ b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp @@ -302,22 +302,22 @@ void tst_QTextBoundaryFinder::toNextBoundary_data() QList<int> boundaries; boundaries << 0 << 3 << 4 << 7 << 8 << 11 << 12 << 13 << 16 << 17 << 20 << 21 << 24 << 25; - QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Word) \ + QTest::newRow("data1") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Word) \ << boundaries; boundaries.clear(); boundaries << 0 << 13 << 25; - QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Sentence) \ + QTest::newRow("data2") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Sentence) \ << boundaries; boundaries.clear(); boundaries << 0 << 4 << 8 << 13 << 17 << 21 << 25; - QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Line) \ + QTest::newRow("data3") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Line) \ << boundaries; boundaries.clear(); boundaries << 0 << 5 << 9 << 15 << 17 << 21 << 28; - QTest::newRow("Line") << QString::fromUtf8("Diga-nos qualé a sua opinião") << int(QTextBoundaryFinder::Line) + QTest::newRow("data4") << QString::fromUtf8("Diga-nos qualé a sua opinião") << int(QTextBoundaryFinder::Line) << boundaries; } @@ -344,22 +344,22 @@ void tst_QTextBoundaryFinder::toPreviousBoundary_data() QList<int> boundaries; boundaries << 25 << 24 << 21 << 20 << 17 << 16 << 13 << 12 << 11 << 8 << 7 << 4 << 3 << 0; - QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Word) + QTest::newRow("data1") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Word) << boundaries; boundaries.clear(); boundaries << 25 << 13 << 0; - QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Sentence) + QTest::newRow("data2") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Sentence) << boundaries; boundaries.clear(); boundaries << 25 << 21 << 17 << 13 << 8 << 4 << 0; - QTest::newRow("Line") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Line) + QTest::newRow("data3") << QString("Aaa bbb ccc. Ddd eee fff.") << int(QTextBoundaryFinder::Line) << boundaries; boundaries.clear(); boundaries << 28 << 21 << 17 << 15 << 9 << 5 << 0; - QTest::newRow("Line") << QString::fromUtf8("Diga-nos qualé a sua opinião") << int(QTextBoundaryFinder::Line) + QTest::newRow("data4") << QString::fromUtf8("Diga-nos qualé a sua opinião") << int(QTextBoundaryFinder::Line) << boundaries; } diff --git a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp index 0ce0da06aa..bd9fa2a8db 100644 --- a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp @@ -674,7 +674,7 @@ void tst_QXmlStream::reportSuccess_data() const const int len = m_handler.successes.count(); for(int i = 0; i < len; ++i) - QTest::newRow(m_handler.successes.at(i).toLatin1().constData()) << false; + QTest::newRow(qPrintable(QString("%1. %2").arg(i).arg(m_handler.successes.at(i)))) << false; if(len == 0) QTest::newRow("No test cases succeeded.") << true; |