diff options
Diffstat (limited to 'tests/auto/corelib/global')
-rw-r--r-- | tests/auto/corelib/global/qflags/qflags.pro | 4 | ||||
-rw-r--r-- | tests/auto/corelib/global/qflags/tst_qflags.cpp | 8 | ||||
-rw-r--r-- | tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 112 | ||||
-rw-r--r-- | tests/auto/corelib/global/qhooks/tst_qhooks.cpp | 70 | ||||
-rw-r--r-- | tests/auto/corelib/global/qlogging/test/test.pro | 4 | ||||
-rw-r--r-- | tests/auto/corelib/global/qlogging/tst_qlogging.cpp | 4 | ||||
-rw-r--r-- | tests/auto/corelib/global/qtendian/qtendian.pro | 4 |
7 files changed, 88 insertions, 118 deletions
diff --git a/tests/auto/corelib/global/qflags/qflags.pro b/tests/auto/corelib/global/qflags/qflags.pro index 29dfb0684c..c3c11fa81b 100644 --- a/tests/auto/corelib/global/qflags/qflags.pro +++ b/tests/auto/corelib/global/qflags/qflags.pro @@ -2,5 +2,5 @@ CONFIG += testcase TARGET = tst_qflags QT = core testlib SOURCES = tst_qflags.cpp -contains(QT_CONFIG, c++11): CONFIG += c++11 -contains(QT_CONFIG, c++14): CONFIG += c++14 +qtConfig(c++11): CONFIG += c++11 +qtConfig(c++14): CONFIG += c++14 diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 10902b6f55..634d9a2df3 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -134,11 +134,11 @@ void tst_QFlags::signedness() // underlying type is implementation-defined, we need to allow for // a different signedness, so we only check that the relative // signedness of the types matches: - Q_STATIC_ASSERT((QtPrivate::is_unsigned<Qt::MouseButton>::value == - QtPrivate::is_unsigned<Qt::MouseButtons::Int>::value)); + Q_STATIC_ASSERT((QtPrivate::QIsUnsignedEnum<Qt::MouseButton>::value == + QtPrivate::QIsUnsignedEnum<Qt::MouseButtons::Int>::value)); - Q_STATIC_ASSERT((QtPrivate::is_signed<Qt::AlignmentFlag>::value == - QtPrivate::is_signed<Qt::Alignment::Int>::value)); + Q_STATIC_ASSERT((QtPrivate::QIsSignedEnum<Qt::AlignmentFlag>::value == + QtPrivate::QIsSignedEnum<Qt::Alignment::Int>::value)); } #if defined(Q_COMPILER_CLASS_ENUM) diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index bb4d1f4bf2..bb6ec1c8e7 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -28,7 +28,6 @@ #include <QtTest/QtTest> -#include <QtCore/qtypetraits.h> #include <QPair> #include <QTextCodec> @@ -49,7 +48,6 @@ private slots: void qConstructorFunction(); void qCoreAppStartupFunction(); void qCoreAppStartupFunctionRestart(); - void isEnum(); void qAlignOf(); void integerForSize(); void qprintable(); @@ -81,7 +79,7 @@ void tst_QGlobal::qIsNull() void tst_QGlobal::for_each() { - QList<int> list; + QVector<int> list; list << 0 << 1 << 2 << 3 << 4 << 5; int counter = 0; @@ -100,7 +98,7 @@ void tst_QGlobal::for_each() // check whether we can pass a constructor as container argument counter = 0; - foreach (int i, QList<int>(list)) { + foreach (int i, QVector<int>(list)) { QCOMPARE(i, counter++); } QCOMPARE(counter, list.count()); @@ -366,100 +364,6 @@ public: enum AnEnum {}; }; -#if defined (Q_COMPILER_CLASS_ENUM) -enum class isEnum_G : qint64 {}; -#endif - -void tst_QGlobal::isEnum() -{ -#if defined (Q_CC_MSVC) -#define IS_ENUM_TRUE(x) (Q_IS_ENUM(x) == true) -#define IS_ENUM_FALSE(x) (Q_IS_ENUM(x) == false) -#else -#define IS_ENUM_TRUE(x) (Q_IS_ENUM(x) == true && QtPrivate::is_enum<x>::value == true) -#define IS_ENUM_FALSE(x) (Q_IS_ENUM(x) == false && QtPrivate::is_enum<x>::value == false) -#endif - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Byte)); - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Short)); - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Int)); - - QVERIFY(IS_ENUM_TRUE(isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(const isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_F::AnEnum)); - - QVERIFY(IS_ENUM_FALSE(void)); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte &)); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte[1])); - QVERIFY(IS_ENUM_FALSE(const isEnum_B_Byte[1])); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte[])); - QVERIFY(IS_ENUM_FALSE(int)); - QVERIFY(IS_ENUM_FALSE(float)); - QVERIFY(IS_ENUM_FALSE(isEnum_A)); - QVERIFY(IS_ENUM_FALSE(isEnum_A *)); - QVERIFY(IS_ENUM_FALSE(const isEnum_A)); - QVERIFY(IS_ENUM_FALSE(isEnum_C)); - QVERIFY(IS_ENUM_FALSE(isEnum_D)); - QVERIFY(IS_ENUM_FALSE(isEnum_E)); - QVERIFY(IS_ENUM_FALSE(void())); - QVERIFY(IS_ENUM_FALSE(void(*)())); - QVERIFY(IS_ENUM_FALSE(int isEnum_A::*)); - QVERIFY(IS_ENUM_FALSE(void (isEnum_A::*)())); - - QVERIFY(IS_ENUM_FALSE(size_t)); - QVERIFY(IS_ENUM_FALSE(bool)); - QVERIFY(IS_ENUM_FALSE(wchar_t)); - - QVERIFY(IS_ENUM_FALSE(char)); - QVERIFY(IS_ENUM_FALSE(unsigned char)); - QVERIFY(IS_ENUM_FALSE(short)); - QVERIFY(IS_ENUM_FALSE(unsigned short)); - QVERIFY(IS_ENUM_FALSE(int)); - QVERIFY(IS_ENUM_FALSE(unsigned int)); - QVERIFY(IS_ENUM_FALSE(long)); - QVERIFY(IS_ENUM_FALSE(unsigned long)); - - QVERIFY(IS_ENUM_FALSE(qint8)); - QVERIFY(IS_ENUM_FALSE(quint8)); - QVERIFY(IS_ENUM_FALSE(qint16)); - QVERIFY(IS_ENUM_FALSE(quint16)); - QVERIFY(IS_ENUM_FALSE(qint32)); - QVERIFY(IS_ENUM_FALSE(quint32)); - QVERIFY(IS_ENUM_FALSE(qint64)); - QVERIFY(IS_ENUM_FALSE(quint64)); - - QVERIFY(IS_ENUM_FALSE(void *)); - QVERIFY(IS_ENUM_FALSE(int *)); - -#if defined (Q_COMPILER_UNICODE_STRINGS) - QVERIFY(IS_ENUM_FALSE(char16_t)); - QVERIFY(IS_ENUM_FALSE(char32_t)); -#endif - -#if defined (Q_COMPILER_CLASS_ENUM) - // Strongly type class enums are not handled by the - // fallback type traits implementation. Any compiler - // supported by Qt that supports C++0x class enums - // should also support the __is_enum intrinsic. - QVERIFY(Q_IS_ENUM(isEnum_G)); -#endif - -#undef IS_ENUM_TRUE -#undef IS_ENUM_FALSE -} - struct Empty {}; template <class T> struct AlignmentInStruct { T dummy; }; @@ -589,7 +493,7 @@ Q_DECLARE_METATYPE(stringpair) void tst_QGlobal::qprintable() { - QFETCH(QList<stringpair>, localestrings); + QFETCH(QVector<stringpair>, localestrings); QFETCH(int, utf8index); QVERIFY(utf8index >= 0 && utf8index < localestrings.count()); @@ -600,21 +504,21 @@ void tst_QGlobal::qprintable() QString string = QString::fromUtf8(utf8string); - foreach (const stringpair &pair, localestrings) { + for (const stringpair &pair : qAsConst(localestrings)) { QTextCodec *codec = QTextCodec::codecForName(pair.first); if (!codec) continue; QTextCodec::setCodecForLocale(codec); // test qPrintable() QVERIFY(qstrcmp(qPrintable(string), pair.second) == 0); - foreach (const stringpair &pair2, localestrings) { + for (const stringpair &pair2 : qAsConst(localestrings)) { if (pair2.second == pair.second) continue; QVERIFY(qstrcmp(qPrintable(string), pair2.second) != 0); } // test qUtf8Printable() QVERIFY(qstrcmp(qUtf8Printable(string), utf8string) == 0); - foreach (const stringpair &pair2, localestrings) { + for (const stringpair &pair2 : qAsConst(localestrings)) { if (qstrcmp(pair2.second, utf8string) == 0) continue; QVERIFY(qstrcmp(qUtf8Printable(string), pair2.second) != 0); @@ -626,7 +530,7 @@ void tst_QGlobal::qprintable() void tst_QGlobal::qprintable_data() { - QTest::addColumn<QList<stringpair> >("localestrings"); + QTest::addColumn<QVector<stringpair> >("localestrings"); QTest::addColumn<int>("utf8index"); // index of utf8 string // Unicode: HIRAGANA LETTER A, I, U, E, O (U+3442, U+3444, U+3446, U+3448, U+344a) @@ -634,7 +538,7 @@ void tst_QGlobal::qprintable_data() static const char *const eucjpstring = "\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"; static const char *const sjisstring = "\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8"; - QList<stringpair> japanesestrings; + QVector<stringpair> japanesestrings; japanesestrings << stringpair("UTF-8", utf8string) << stringpair("EUC-JP", eucjpstring) << stringpair("Shift_JIS", sjisstring); diff --git a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp index f0685d64c5..5fa7566e86 100644 --- a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp +++ b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp @@ -35,10 +35,18 @@ class tst_QHooks: public QObject Q_OBJECT private slots: + void cleanup(); void testVersion(); void testAddRemoveObject(); + void testChaining(); }; +void tst_QHooks::cleanup() +{ + qtHookData[QHooks::AddQObject] = 0; + qtHookData[QHooks::RemoveQObject] = 0; +} + void tst_QHooks::testVersion() { QVERIFY(qtHookData[QHooks::HookDataVersion] >= 3); @@ -73,5 +81,67 @@ void tst_QHooks::testAddRemoveObject() QCOMPARE(objectCount, 0); } +static QVector<QString> hookOrder; + +static QHooks::AddQObjectCallback existingAddHook = 0; +static QHooks::RemoveQObjectCallback existingRemoveHook = 0; + +static void firstAddHook(QObject *) +{ + hookOrder.append(QLatin1String("firstAddHook")); +} + +static void firstRemoveHook(QObject *) +{ + hookOrder.append(QLatin1String("firstRemoveHook")); +} + +static void secondAddHook(QObject *object) +{ + if (existingAddHook) + existingAddHook(object); + + hookOrder.append(QLatin1String("secondAddHook")); +} + +static void secondRemoveHook(QObject *object) +{ + if (existingRemoveHook) + existingRemoveHook(object); + + hookOrder.append(QLatin1String("secondRemoveHook")); +} + +// Tests that it's possible to "chain" hooks together (i.e. have multiple hooks) +void tst_QHooks::testChaining() +{ + QCOMPARE(qtHookData[QHooks::AddQObject], (quintptr)0); + QCOMPARE(qtHookData[QHooks::RemoveQObject], (quintptr)0); + + // Set the add and remove hooks (could just skip this and go straight to the next step, + // but it's for illustrative purposes). + qtHookData[QHooks::AddQObject] = (quintptr)&firstAddHook; + qtHookData[QHooks::RemoveQObject] = (quintptr)&firstRemoveHook; + + // Store them so that we can call them later. + existingAddHook = reinterpret_cast<QHooks::AddQObjectCallback>(qtHookData[QHooks::AddQObject]); + existingRemoveHook = reinterpret_cast<QHooks::RemoveQObjectCallback>(qtHookData[QHooks::RemoveQObject]); + + // Overide them with hooks that call them first. + qtHookData[QHooks::AddQObject] = (quintptr)&secondAddHook; + qtHookData[QHooks::RemoveQObject] = (quintptr)&secondRemoveHook; + + QObject *obj = new QObject; + QCOMPARE(hookOrder.size(), 2); + QCOMPARE(hookOrder.at(0), QLatin1String("firstAddHook")); + QCOMPARE(hookOrder.at(1), QLatin1String("secondAddHook")); + delete obj; + QCOMPARE(hookOrder.size(), 4); + QCOMPARE(hookOrder.at(2), QLatin1String("firstRemoveHook")); + QCOMPARE(hookOrder.at(3), QLatin1String("secondRemoveHook")); + + hookOrder.clear(); +} + QTEST_APPLESS_MAIN(tst_QHooks) #include "tst_qhooks.moc" diff --git a/tests/auto/corelib/global/qlogging/test/test.pro b/tests/auto/corelib/global/qlogging/test/test.pro index b5b75be3a6..93eee7307a 100644 --- a/tests/auto/corelib/global/qlogging/test/test.pro +++ b/tests/auto/corelib/global/qlogging/test/test.pro @@ -1,7 +1,7 @@ CONFIG += testcase CONFIG -= app_bundle debug_and_release_target -contains(QT_CONFIG, c++11): CONFIG += c++11 -contains(QT_CONFIG, c++14): CONFIG += c++14 +qtConfig(c++11): CONFIG += c++11 +qtConfig(c++14): CONFIG += c++14 TARGET = ../tst_qlogging QT = core testlib SOURCES = ../tst_qlogging.cpp diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index ce227a6c8b..c2d7338042 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -30,7 +30,7 @@ #include <qdebug.h> #include <qglobal.h> #include <QtCore/QProcess> -#include <QtTest/QtTest> +#include <QtTest/QTest> class tst_qmessagehandler : public QObject { @@ -841,7 +841,7 @@ void tst_qmessagehandler::qMessagePattern() QVERIFY(!output.isEmpty()); QCOMPARE(!output.contains("QT_MESSAGE_PATTERN"), valid); - foreach (const QByteArray &e, expected) { + for (const QByteArray &e : qAsConst(expected)) { if (!output.contains(e)) { qDebug() << output; qDebug() << "expected: " << e; diff --git a/tests/auto/corelib/global/qtendian/qtendian.pro b/tests/auto/corelib/global/qtendian/qtendian.pro index 2b0af4fa4c..214c706ca5 100644 --- a/tests/auto/corelib/global/qtendian/qtendian.pro +++ b/tests/auto/corelib/global/qtendian/qtendian.pro @@ -2,7 +2,3 @@ CONFIG += testcase TARGET = tst_qtendian QT = core testlib SOURCES = tst_qtendian.cpp -wince* { # QTBUG-37194 , internal compiler errors with MSVC2008 for Windows CE - QMAKE_CFLAGS_RELEASE -= -O2 - QMAKE_CXXFLAGS_RELEASE -= -O2 -} |