From 7cfad460c56319ba89c4a3a0bbcb2e54ab1cdbc6 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 4 Oct 2011 11:51:31 +1000 Subject: Avoid using QSKIP in lieu of compile-time checks QSKIP is intended to be used to skip test functions that are found at run-time to be inapplicable or unsafe. If a test function can be determined to be inapplicable at compile-time, the entire test function should be omitted instead of replacing the body of the test function with a QSKIP, which only serves to slow down test runs and to inflate test run-rates with empty, inapplicable tests. Task-number: QTQAINFRA-278 Change-Id: Ib2025339422749cf216e87ac414a3056250bf8f9 Reviewed-on: http://codereview.qt-project.org/5942 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- .../corelib/tools/qbytearray/tst_qbytearray.cpp | 29 ++++------- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 8 +-- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 30 +++++------ .../tools/qsharedpointer/tst_qsharedpointer.cpp | 18 ++++--- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 60 +++++++++++----------- .../corelib/tools/qstringlist/tst_qstringlist.cpp | 9 ++-- 6 files changed, 73 insertions(+), 81 deletions(-) (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index 41922a0a42..05bc7399a0 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -71,8 +71,10 @@ private slots: void qCompress_data(); #ifndef QT_NO_COMPRESS void qCompress(); +#if !(defined Q_OS_HPUX && !defined __ia64 && defined Q_CC_GNU) && !defined Q_OS_SOLARIS && !defined Q_OS_QNX && !defined Q_OS_WIN void qUncompress_data(); void qUncompress(); +#endif void qCompressionZeroTermination(); #endif void constByteArray(); @@ -142,7 +144,9 @@ private slots: void reserve(); +#if defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU) void literals(); +#endif }; tst_QByteArray::tst_QByteArray() @@ -214,9 +218,9 @@ void tst_QByteArray::qCompress() QTEST( ::qUncompress( compressed ), "ba" ); } -/* - Just making sure it doesn't crash on invalid data. -*/ +// Corrupt data causes this test to lock up on HP-UX / PA-RISC with gcc, +// SOLARIS, QNX and Windows. +#if !(defined Q_OS_HPUX && !defined __ia64 && defined Q_CC_GNU) && !defined Q_OS_SOLARIS && !defined Q_OS_QNX && !defined Q_OS_WIN void tst_QByteArray::qUncompress_data() { QTest::addColumn("in"); @@ -241,16 +245,6 @@ void tst_QByteArray::qUncompress() QFETCH(QByteArray, in); QFETCH(QByteArray, out); -#if defined Q_OS_HPUX && !defined __ia64 && defined Q_CC_GNU - QSKIP("Corrupt data causes this tests to lock up on HP-UX / PA-RISC with gcc", SkipAll); -#elif defined Q_OS_SOLARIS - QSKIP("Corrupt data causes this tests to lock up on Solaris", SkipAll); -#elif defined Q_OS_QNX - QSKIP("Corrupt data causes this test to lock up on QNX", SkipAll); -#elif defined Q_OS_WIN - QSKIP("Corrupt data causes this test to lock up on Windows", SkipAll); -#endif - QByteArray res; res = ::qUncompress(in); QCOMPARE(res, out); @@ -258,6 +252,7 @@ void tst_QByteArray::qUncompress() res = ::qUncompress(in + "blah"); QCOMPARE(res, out); } +#endif void tst_QByteArray::qCompressionZeroTermination() { @@ -1540,9 +1535,10 @@ void tst_QByteArray::reserve() nil2.reserve(0); } +// Only tested on c++0x compliant compiler or gcc. +#if defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU) void tst_QByteArray::literals() { -#if defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU) QByteArray str(QByteArrayLiteral("abcd")); QVERIFY(str.length() == 4); @@ -1559,11 +1555,8 @@ void tst_QByteArray::literals() QVERIFY(str2.constData() == s); QVERIFY(str2.data() != s); - -#else - QSKIP("Only tested on c++0x compliant compiler or gcc", SkipAll); -#endif } +#endif const char globalChar = '1'; diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 95995e857b..c6a71a303b 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -124,7 +124,9 @@ private slots: void dateTimeFromStringFormat_data(); void dateTimeFromStringFormat(); +#ifdef Q_OS_WIN void fromString_LOCALE_ILDATE(); +#endif void fromString(); @@ -1583,19 +1585,17 @@ void tst_QDateTime::fromString() QLocale::setDefault(def); } +#ifdef Q_OS_WIN void tst_QDateTime::fromString_LOCALE_ILDATE() { -#ifdef Q_OS_WIN QString date1 = QLatin1String("Sun 1. Dec 13:02:00 1974"); QString date2 = QLatin1String("Sun Dec 1 13:02:00 1974"); QDateTime ref(QDate(1974, 12, 1), QTime(13, 2)); QCOMPARE(ref, QDateTime::fromString(date2, Qt::TextDate)); QCOMPARE(ref, QDateTime::fromString(date1, Qt::TextDate)); -#else - QSKIP("Windows only", SkipAll); -#endif } +#endif void tst_QDateTime::utcOffset() { diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index cd8634ad04..ccb3b9b255 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -83,11 +83,17 @@ public: tst_QLocale(); private slots: +#ifdef Q_OS_WIN void windowsDefaultLocale(); +#endif +#ifdef Q_OS_MAC void macDefaultLocale(); +#endif void ctor(); +#if !defined(Q_OS_WINCE) && !defined(QT_NO_PROCESS) void emptyCtor(); +#endif void unixLocaleName(); void double_conversion_data(); void double_conversion(); @@ -361,14 +367,10 @@ void tst_QLocale::ctor() #undef TEST_CTOR } +// Uses unsupported Windows CE QProcess functionality (std streams, env). +#if !defined(Q_OS_WINCE) && !defined(QT_NO_PROCESS) void tst_QLocale::emptyCtor() { -#if defined(Q_OS_WINCE) - QSKIP("Uses unsupported Windows CE QProcess functionality (std streams, env)", SkipAll); -#endif -#if defined(QT_NO_PROCESS) - QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll); -#else #define TEST_CTOR(req_lc, exp_str) \ { \ /* Test constructor without arguments. Needs separate process */ \ @@ -439,8 +441,8 @@ void tst_QLocale::emptyCtor() TEST_CTOR("123456", defaultLoc); #undef TEST_CTOR -#endif } +#endif void tst_QLocale::unixLocaleName() { @@ -1074,12 +1076,9 @@ void tst_QLocale::toDateTime() QCOMPARE(l.toDateTime(string, QLocale::LongFormat), result); } +#ifdef Q_OS_MAC void tst_QLocale::macDefaultLocale() { -#ifndef Q_OS_MAC - QSKIP("This is a Mac OS X-only test", SkipAll); -#endif - QLocale locale = QLocale::system(); if (locale.name() != QLatin1String("en_US")) { QSKIP("This test only tests for en_US", SkipAll); @@ -1156,8 +1155,8 @@ void tst_QLocale::macDefaultLocale() QList days; days << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday; QCOMPARE(locale.weekdays(), days); - } +#endif #ifdef Q_OS_WIN #include @@ -1212,14 +1211,11 @@ public: QString m_decimal, m_thousand, m_sdate, m_ldate, m_time; }; - #endif +#ifdef Q_OS_WIN void tst_QLocale::windowsDefaultLocale() { -#ifndef Q_OS_WIN - QSKIP("This is a Windows test", SkipAll); -#else RestoreLocaleHelper systemLocale; // set weird system defaults and make sure we're using them setWinLocaleInfo(LOCALE_SDECIMAL, QLatin1String("@")); @@ -1254,8 +1250,8 @@ void tst_QLocale::windowsDefaultLocale() QCOMPARE(locale.toString(QDateTime(QDate(1974, 12, 1), QTime(1,2,3)), QLocale::LongFormat), QString("1@12@1974 1^2^3")); QCOMPARE(locale.toString(QTime(1,2,3), QLocale::LongFormat), QString("1^2^3")); -#endif } +#endif void tst_QLocale::numberOptions() { diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 1c9818696e..5ad0b1c208 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -68,7 +68,9 @@ private slots: void basics(); void operators(); void swap(); +#ifndef Q_CC_SUN void forwardDeclaration1(); +#endif void forwardDeclaration2(); void memoryManagement(); void downCast(); @@ -98,8 +100,10 @@ private slots: void map(); void hash(); void validConstructs(); +#ifndef QTEST_CROSS_COMPILED void invalidConstructs_data(); void invalidConstructs(); +#endif public slots: void cleanup() { check(); } @@ -340,11 +344,10 @@ ForwardDeclared *forwardPointer(); void externalForwardDeclaration(); extern int forwardDeclaredDestructorRunCount; +// This type of forward declaration is not valid with SunCC. +#ifndef Q_CC_SUN void tst_QSharedPointer::forwardDeclaration1() { -#if defined(Q_CC_SUN) || defined(Q_CC_WINSCW) || defined(Q_CC_RVCT) - QSKIP("This type of forward declaration is not valid with this compiler", SkipAll); -#else externalForwardDeclaration(); struct Wrapper { QSharedPointer pointer; }; @@ -356,8 +359,8 @@ void tst_QSharedPointer::forwardDeclaration1() QVERIFY(!w.pointer.isNull()); } QCOMPARE(forwardDeclaredDestructorRunCount, 1); -#endif } +#endif #include "forwarddeclared.h" @@ -1657,6 +1660,9 @@ void tst_QSharedPointer::validConstructs() typedef bool (QTest::QExternalTest:: * TestFunction)(const QByteArray &body); Q_DECLARE_METATYPE(TestFunction) + +// This test does not work on cross compiled systems. +#ifndef QTEST_CROSS_COMPILED void tst_QSharedPointer::invalidConstructs_data() { QTest::addColumn("testFunction"); @@ -1801,9 +1807,6 @@ void tst_QSharedPointer::invalidConstructs() #ifdef Q_CC_MINGW QSKIP("The maintainer of QSharedPointer: 'We don't know what the problem is so skip the tests.'", SkipAll); #endif -#ifdef QTEST_CROSS_COMPILED - QSKIP("This test does not work on cross compiled systems", SkipAll); -#endif QTest::QExternalTest test; test.setQtModules(QTest::QExternalTest::QtCore); @@ -1858,6 +1861,7 @@ void tst_QSharedPointer::invalidConstructs() QFAIL("Fail"); } } +#endif namespace QTBUG11730 { struct IB diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index dc912f786e..fdfc5e1f2e 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -74,8 +74,10 @@ public slots: void init(); void cleanup(); private slots: +#if !defined(Q_CC_HPACC) && !defined(QT_NO_STL) void fromStdString(); void toStdString(); +#endif void check_QTextIOStream(); void check_QTextStream(); void check_QDataStream(); @@ -156,7 +158,9 @@ private slots: void constructor(); void constructorQByteArray_data(); void constructorQByteArray(); +#if !defined(Q_CC_HPACC) && !defined(QT_NO_STL) void STL(); +#endif void isEmpty(); void isNull(); void acc_01(); @@ -197,8 +201,10 @@ private slots: void integer_conversion(); void tortureSprintfDouble(); void toNum(); +#if !defined(Q_OS_MAC) && (!defined(Q_OS_WIN) || defined(Q_OS_WINCE)) void localeAwareCompare_data(); void localeAwareCompare(); +#endif void split_data(); void split(); void split_regexp(); @@ -222,8 +228,12 @@ private slots: void QTBUG10404_compareRef(); void QTBUG9281_arg_locale(); +#ifdef QT_USE_ICU void toUpperLower_icu(); +#endif +#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) void literals(); +#endif void reserve(); void toHtmlEscaped_data(); @@ -823,12 +833,10 @@ void tst_QString::constructorQByteArray() QCOMPARE( strBA, expected ); } +// This test crashes on HP-UX with aCC. +#if !defined(Q_CC_HPACC) && !defined(QT_NO_STL) void tst_QString::STL() { -#ifdef Q_CC_HPACC - QSKIP("This test crashes on HP-UX with aCC", SkipSingle); -#endif -#ifndef QT_NO_STL #ifndef QT_NO_CAST_TO_ASCII QString qt( "QString" ); @@ -877,10 +885,8 @@ void tst_QString::STL() QCOMPARE(s, QString::fromLatin1("hello")); QCOMPARE(stlStr, s.toStdWString()); #endif -#else - QSKIP( "Not tested without STL support", SkipAll); -#endif } +#endif void tst_QString::truncate() { @@ -3142,12 +3148,10 @@ void tst_QString::setRawData() QVERIFY(cstr.data_ptr() != csd); } +// This test crashes on HP-UX with aCC. +#if !defined(Q_CC_HPACC) && !defined(QT_NO_STL) void tst_QString::fromStdString() { -#ifdef Q_CC_HPACC - QSKIP("This test crashes on HP-UX with aCC", SkipSingle); -#endif -#if !defined(QT_NO_STL) std::string stroustrup = "foo"; QString eng = QString::fromStdString( stroustrup ); QCOMPARE( eng, QString("foo") ); @@ -3155,15 +3159,13 @@ void tst_QString::fromStdString() std::string stdnull( cnull, sizeof(cnull)-1 ); QString qtnull = QString::fromStdString( stdnull ); QCOMPARE( qtnull.size(), int(stdnull.size()) ); -#endif } +#endif +// This test crashes on HP-UX with aCC. +#if !defined(Q_CC_HPACC) && !defined(QT_NO_STL) void tst_QString::toStdString() { -#ifdef Q_CC_HPACC - QSKIP("This test crashes on HP-UX with aCC", SkipSingle); -#endif -#if !defined(QT_NO_STL) QString nord = "foo"; std::string stroustrup1 = nord.toStdString(); QVERIFY( qstrcmp(stroustrup1.c_str(), "foo") == 0 ); @@ -3177,8 +3179,8 @@ void tst_QString::toStdString() QString qtnull( qcnull, sizeof(qcnull)/sizeof(QChar) ); std::string stdnull = qtnull.toStdString(); QCOMPARE( int(stdnull.size()), qtnull.size() ); -#endif } +#endif void tst_QString::utf8() { @@ -4228,6 +4230,10 @@ void tst_QString::tortureSprintfDouble() #include +// Setting the locale is not supported on OS X (you can set the C locale, +// but that won't affect CFStringCompare which is used to compare strings). +// On Windows other than Win CE, we cannot set the system or user locale. +#if !defined(Q_OS_MAC) && (!defined(Q_OS_WIN) || defined(Q_OS_WINCE)) void tst_QString::localeAwareCompare_data() { #ifdef Q_OS_WIN @@ -4325,9 +4331,6 @@ void tst_QString::localeAwareCompare_data() void tst_QString::localeAwareCompare() { #ifdef Q_OS_WIN -# ifndef Q_OS_WINCE - QSKIP("On others than Win CE, we cannot set the system or user locale.", SkipAll); -# endif QFETCH(ulong, locale); #else QFETCH(QString, locale); @@ -4352,8 +4355,6 @@ void tst_QString::localeAwareCompare() QCOMPARE(locale, GetThreadLocale()); # endif -#elif defined (Q_OS_MAC) - QSKIP("Setting the locale is not supported on OS X (you can set the C locale, but that won't affect CFStringCompare which is used to compare strings)", SkipAll); #elif defined(QT_USE_ICU) QLocale::setDefault(QLocale(locale)); #else @@ -4429,6 +4430,7 @@ void tst_QString::localeAwareCompare() setlocale(LC_ALL, ""); #endif } +#endif void tst_QString::split_data() { @@ -5073,12 +5075,9 @@ void tst_QString::QTBUG9281_arg_locale() QLocale::setDefault(QLocale::C); } +#ifdef QT_USE_ICU void tst_QString::toUpperLower_icu() { -#ifndef QT_USE_ICU - QSKIP("Qt was built without ICU support", SkipAll); -#endif - QString s = QString::fromLatin1("i"); QCOMPARE(s.toUpper(), QString::fromLatin1("I")); @@ -5111,10 +5110,12 @@ void tst_QString::toUpperLower_icu() // the cleanup function will restore the default locale } +#endif +// Only tested on c++0x compliant compiler or gcc. +#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) void tst_QString::literals() { -#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) QString str(QStringLiteral("abcd")); QVERIFY(str.length() == 4); @@ -5131,11 +5132,8 @@ void tst_QString::literals() QVERIFY(str2.constData() == s); QVERIFY(str2.data() != s); - -#else - QSKIP("Only tested on c++0x compliant compiler or gcc", SkipAll); -#endif } +#endif void tst_QString::reserve() { diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp index 3342ec0d79..250badb231 100644 --- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp @@ -79,7 +79,9 @@ private slots: void join_data() const; void joinEmptiness() const; +#ifdef Q_COMPILER_INITIALIZER_LISTS void initializeList() const; +#endif }; extern const char email[]; @@ -323,16 +325,15 @@ void tst_QStringList::joinEmptiness() const QVERIFY(string.isNull()); } +// this test require C++0x support +#ifdef Q_COMPILER_INITIALIZER_LISTS void tst_QStringList::initializeList() const { -#ifdef Q_COMPILER_INITIALIZER_LISTS QStringList v1{QLatin1String("hello"),"world",QString::fromLatin1("plop")}; QCOMPARE(v1, (QStringList() << "hello" << "world" << "plop")); QCOMPARE(v1, (QStringList{"hello","world","plop"})); -#else - QSKIP("Require C++0x support, pass the right flag to the compiler", SkipAll); -#endif } +#endif QTEST_APPLESS_MAIN(tst_QStringList) #include "tst_qstringlist.moc" -- cgit v1.2.3