diff options
Diffstat (limited to 'tests/auto/corelib/global')
-rw-r--r-- | tests/auto/corelib/global/global.pro | 2 | ||||
-rw-r--r-- | tests/auto/corelib/global/qflags/tst_qflags.cpp | 24 | ||||
-rw-r--r-- | tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 64 | ||||
-rw-r--r-- | tests/auto/corelib/global/qhooks/qhooks.pro | 4 | ||||
-rw-r--r-- | tests/auto/corelib/global/qhooks/tst_qhooks.cpp | 90 |
5 files changed, 183 insertions, 1 deletions
diff --git a/tests/auto/corelib/global/global.pro b/tests/auto/corelib/global/global.pro index c05905bd15..219e9de818 100644 --- a/tests/auto/corelib/global/global.pro +++ b/tests/auto/corelib/global/global.pro @@ -9,4 +9,4 @@ SUBDIRS=\ qlogging \ qtendian \ qglobalstatic \ - + qhooks diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 73a69a1309..42add6150a 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -50,6 +50,7 @@ private slots: void constExpr(); void signedness(); void classEnum(); + void initializerLists(); }; void tst_QFlags::testFlag() const @@ -143,6 +144,9 @@ enum class MyStrictEnum { StrictZero, StrictOne, StrictTwo, StrictFour=4 }; Q_DECLARE_FLAGS( MyStrictFlags, MyStrictEnum ) Q_DECLARE_OPERATORS_FOR_FLAGS( MyStrictFlags ) +enum class MyStrictNoOpEnum { StrictZero, StrictOne, StrictTwo, StrictFour=4 }; +Q_DECLARE_FLAGS( MyStrictNoOpFlags, MyStrictNoOpEnum ) + Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isComplex ); Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isStatic ); Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isLarge ); @@ -253,6 +257,26 @@ void tst_QFlags::classEnum() #endif } +void tst_QFlags::initializerLists() +{ +#if defined(Q_COMPILER_INITIALIZER_LISTS) + Qt::MouseButtons bts = { Qt::LeftButton, Qt::RightButton }; + QVERIFY(bts.testFlag(Qt::LeftButton)); + QVERIFY(bts.testFlag(Qt::RightButton)); + QVERIFY(!bts.testFlag(Qt::MiddleButton)); + +#if defined(Q_COMPILER_CLASS_ENUM) + MyStrictNoOpFlags flags = { MyStrictNoOpEnum::StrictOne, MyStrictNoOpEnum::StrictFour }; + QVERIFY(flags.testFlag(MyStrictNoOpEnum::StrictOne)); + QVERIFY(flags.testFlag(MyStrictNoOpEnum::StrictFour)); + QVERIFY(!flags.testFlag(MyStrictNoOpEnum::StrictTwo)); +#endif // Q_COMPILER_CLASS_ENUM + +#else + QSKIP("This test requires C++11 initializer_list support."); +#endif // Q_COMPILER_INITIALIZER_LISTS +} + // (statically) check QTypeInfo for QFlags instantiations: enum MyEnum { Zero, One, Two, Four=4 }; Q_DECLARE_FLAGS( MyFlags, MyEnum ) diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 4eb3e4fc98..0389ae7976 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -43,6 +43,9 @@ #include <QtTest/QtTest> #include <QtCore/qtypetraits.h> +#include <QPair> +#include <QTextCodec> + class tst_QGlobal: public QObject { Q_OBJECT @@ -60,6 +63,8 @@ private slots: void isEnum(); void qAlignOf(); void integerForSize(); + void qprintable(); + void qprintable_data(); }; void tst_QGlobal::qIsNull() @@ -588,5 +593,64 @@ void tst_QGlobal::integerForSize() Q_STATIC_ASSERT(sizeof(QIntegerForSize<8>::Unsigned) == 8); } +typedef QPair<const char *, const char *> stringpair; +Q_DECLARE_METATYPE(stringpair) + +void tst_QGlobal::qprintable() +{ + QFETCH(QList<stringpair>, localestrings); + QFETCH(int, utf8index); + + QVERIFY(utf8index >= 0 && utf8index < localestrings.count()); + if (utf8index < 0 || utf8index >= localestrings.count()) + return; + + const char *const utf8string = localestrings.at(utf8index).second; + + QString string = QString::fromUtf8(utf8string); + + foreach (const stringpair &pair, 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) { + 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) { + if (qstrcmp(pair2.second, utf8string) == 0) + continue; + QVERIFY(qstrcmp(qUtf8Printable(string), pair2.second) != 0); + } + } + + QTextCodec::setCodecForLocale(0); +} + +void tst_QGlobal::qprintable_data() +{ + QTest::addColumn<QList<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) + static const char *const utf8string = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a"; + 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; + japanesestrings << stringpair("UTF-8", utf8string) + << stringpair("EUC-JP", eucjpstring) + << stringpair("Shift_JIS", sjisstring); + + QTest::newRow("Japanese") << japanesestrings << 0; + +} + QTEST_APPLESS_MAIN(tst_QGlobal) #include "tst_qglobal.moc" diff --git a/tests/auto/corelib/global/qhooks/qhooks.pro b/tests/auto/corelib/global/qhooks/qhooks.pro new file mode 100644 index 0000000000..f886e7d49a --- /dev/null +++ b/tests/auto/corelib/global/qhooks/qhooks.pro @@ -0,0 +1,4 @@ +CONFIG += testcase parallel_test +TARGET = tst_qhooks +QT = core-private testlib +SOURCES = tst_qhooks.cpp diff --git a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp new file mode 100644 index 0000000000..817c0b8173 --- /dev/null +++ b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Volker Krause <volker.krause@kdab.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> +#include <QtCore/private/qhooks_p.h> + +class tst_QHooks: public QObject +{ + Q_OBJECT + +private slots: + void testVersion(); + void testAddRemoveObject(); +}; + +void tst_QHooks::testVersion() +{ + QVERIFY(qtHookData[QHooks::HookDataVersion] >= 1); + QCOMPARE(qtHookData[QHooks::HookDataSize], (quintptr)QHooks::LastHookIndex); + QCOMPARE(qtHookData[QHooks::QtVersion], (quintptr)QT_VERSION); +} + +static int objectCount = 0; + +static void objectAddHook(QObject*) +{ + ++objectCount; +} + +static void objectRemoveHook(QObject*) +{ + --objectCount; +} + +void tst_QHooks::testAddRemoveObject() +{ + QCOMPARE(qtHookData[QHooks::AddQObject], (quintptr)0); + QCOMPARE(qtHookData[QHooks::RemoveQObject], (quintptr)0); + + qtHookData[QHooks::AddQObject] = (quintptr)&objectAddHook; + qtHookData[QHooks::RemoveQObject] = (quintptr)&objectRemoveHook; + + QCOMPARE(objectCount, 0); + QObject *obj = new QObject; + QVERIFY(objectCount > 0); + delete obj; + QCOMPARE(objectCount, 0); +} + +QTEST_APPLESS_MAIN(tst_QHooks) +#include "tst_qhooks.moc" |