diff --git a/tests/auto/corelib/kernel/qmetatype/CMakeLists.txt b/tests/auto/corelib/kernel/qmetatype/CMakeLists.txt index 49fcecebc3..08ab0d321e 100644 --- a/tests/auto/corelib/kernel/qmetatype/CMakeLists.txt +++ b/tests/auto/corelib/kernel/qmetatype/CMakeLists.txt @@ -10,6 +10,7 @@ list(APPEND test_data "./typeFlags.bin") qt_internal_add_test(tst_qmetatype SOURCES tst_qmetatype.h tst_qmetatype.cpp tst_qmetatype2.cpp + tst_qmetatype3.cpp DEFINES QT_DISABLE_DEPRECATED_BEFORE=0 INCLUDE_DIRECTORIES diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index f2e986e1b5..d7b1ff268a 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1545,30 +1545,7 @@ public: typedef MyObject* MyObjectPtr; Q_DECLARE_METATYPE(MyObjectPtr) -#if !defined(TST_QMETATYPE_BROKEN_COMPILER) -static QByteArray createTypeName(const char *begin, const char *va) -{ - QByteArray tn(begin); - const QList args = QByteArray(va).split(','); - tn += args.first().trimmed(); - if (args.size() > 1) { - QList::const_iterator it = args.constBegin() + 1; - const QList::const_iterator end = args.constEnd(); - for (; it != end; ++it) { - tn += ","; - tn += it->trimmed(); - } - } - if (tn.endsWith('>')) - tn += ' '; - tn += '>'; - return tn; -} -#endif - -Q_DECLARE_METATYPE(const void*) - -void tst_QMetaType::automaticTemplateRegistration() +void tst_QMetaType::automaticTemplateRegistration_1() { #define TEST_SEQUENTIAL_CONTAINER(CONTAINER, VALUE_TYPE) \ { \ @@ -1745,60 +1722,7 @@ void tst_QMetaType::automaticTemplateRegistration() #if !defined(TST_QMETATYPE_BROKEN_COMPILER) - #define FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \ - F(bool) \ - F(int) \ - F(qulonglong) \ - F(double) \ - F(short) \ - F(char) \ - F(ulong) \ - F(uchar) \ - F(float) \ - F(QObject*) \ - F(QString) \ - F(CustomMovable) - #define FOR_EACH_STATIC_PRIMITIVE_TYPE2(F, SecondaryRealName) \ - F(uint, SecondaryRealName) \ - F(qlonglong, SecondaryRealName) \ - F(char, SecondaryRealName) \ - F(uchar, SecondaryRealName) \ - F(QObject*, SecondaryRealName) - - #define CREATE_AND_VERIFY_CONTAINER(CONTAINER, ...) \ - { \ - CONTAINER< __VA_ARGS__ > t; \ - const QVariant v = QVariant::fromValue(t); \ - QByteArray tn = createTypeName(#CONTAINER "<", #__VA_ARGS__); \ - const int expectedType = ::qMetaTypeId >(); \ - const int type = QMetaType::type(tn); \ - QCOMPARE(type, expectedType); \ - QCOMPARE((QMetaType::fromType>().id()), expectedType); \ - } - - #define FOR_EACH_1ARG_TEMPLATE_TYPE(F, TYPE) \ - F(QList, TYPE) \ - F(QQueue, TYPE) \ - F(QStack, TYPE) \ - F(QSet, TYPE) - - #define PRINT_1ARG_TEMPLATE(RealName) \ - FOR_EACH_1ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName) - - #define FOR_EACH_2ARG_TEMPLATE_TYPE(F, RealName1, RealName2) \ - F(QHash, RealName1, RealName2) \ - F(QMap, RealName1, RealName2) \ - F(std::pair, RealName1, RealName2) - - #define PRINT_2ARG_TEMPLATE_INTERNAL(RealName1, RealName2) \ - FOR_EACH_2ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName1, RealName2) - - #define PRINT_2ARG_TEMPLATE(RealName) \ - FOR_EACH_STATIC_PRIMITIVE_TYPE2(PRINT_2ARG_TEMPLATE_INTERNAL, RealName) - - #define REGISTER_TYPEDEF(TYPE, ARG1, ARG2) \ - qRegisterMetaType>(#TYPE "<" #ARG1 "," #ARG2 ">"); REGISTER_TYPEDEF(QHash, int, uint) REGISTER_TYPEDEF(QMap, int, uint) @@ -1807,9 +1731,6 @@ void tst_QMetaType::automaticTemplateRegistration() FOR_EACH_STATIC_PRIMITIVE_TYPE( PRINT_1ARG_TEMPLATE ) - FOR_EACH_STATIC_PRIMITIVE_TYPE( - PRINT_2ARG_TEMPLATE - ) CREATE_AND_VERIFY_CONTAINER(QList, QList>>>) CREATE_AND_VERIFY_CONTAINER(QList, void*) diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h index fbb5cfdb64..6e02959add 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h @@ -119,7 +119,10 @@ private slots: void isRegisteredStaticLess_data(); void isRegisteredStaticLess(); void isEnum(); - void automaticTemplateRegistration(); + void automaticTemplateRegistration_1(); +#ifndef TST_QMETATYPE_BROKEN_COMPILER + void automaticTemplateRegistration_2(); // defined in tst_qmetatype3.cpp +#endif void saveAndLoadBuiltin_data(); void saveAndLoadBuiltin(); void saveAndLoadCustom(); @@ -244,3 +247,81 @@ QT_END_NAMESPACE #endif Q_DECLARE_METATYPE(CustomMovable); + +#define FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \ + F(bool) \ + F(int) \ + F(qulonglong) \ + F(double) \ + F(short) \ + F(char) \ + F(ulong) \ + F(uchar) \ + F(float) \ + F(QObject*) \ + F(QString) \ + F(CustomMovable) + +#define FOR_EACH_STATIC_PRIMITIVE_TYPE2(F, SecondaryRealName) \ + F(uint, SecondaryRealName) \ + F(qlonglong, SecondaryRealName) \ + F(char, SecondaryRealName) \ + F(uchar, SecondaryRealName) \ + F(QObject*, SecondaryRealName) + +#define CREATE_AND_VERIFY_CONTAINER(CONTAINER, ...) \ + { \ + CONTAINER< __VA_ARGS__ > t; \ + const QVariant v = QVariant::fromValue(t); \ + QByteArray tn = createTypeName(#CONTAINER "<", #__VA_ARGS__); \ + const int expectedType = ::qMetaTypeId >(); \ + const int type = QMetaType::type(tn); \ + QCOMPARE(type, expectedType); \ + QCOMPARE((QMetaType::fromType>().id()), expectedType); \ + } + +#define FOR_EACH_1ARG_TEMPLATE_TYPE(F, TYPE) \ + F(QList, TYPE) \ + F(QQueue, TYPE) \ + F(QStack, TYPE) \ + F(QSet, TYPE) + +#define PRINT_1ARG_TEMPLATE(RealName) \ + FOR_EACH_1ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName) + +#define FOR_EACH_2ARG_TEMPLATE_TYPE(F, RealName1, RealName2) \ + F(QHash, RealName1, RealName2) \ + F(QMap, RealName1, RealName2) \ + F(std::pair, RealName1, RealName2) + +#define PRINT_2ARG_TEMPLATE_INTERNAL(RealName1, RealName2) \ + FOR_EACH_2ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName1, RealName2) + +#define PRINT_2ARG_TEMPLATE(RealName) \ + FOR_EACH_STATIC_PRIMITIVE_TYPE2(PRINT_2ARG_TEMPLATE_INTERNAL, RealName) + +#define REGISTER_TYPEDEF(TYPE, ARG1, ARG2) \ + qRegisterMetaType>(#TYPE "<" #ARG1 "," #ARG2 ">"); + +#if !defined(TST_QMETATYPE_BROKEN_COMPILER) +static inline QByteArray createTypeName(const char *begin, const char *va) +{ + QByteArray tn(begin); + const QList args = QByteArray(va).split(','); + tn += args.first().trimmed(); + if (args.size() > 1) { + QList::const_iterator it = args.constBegin() + 1; + const QList::const_iterator end = args.constEnd(); + for (; it != end; ++it) { + tn += ","; + tn += it->trimmed(); + } + } + if (tn.endsWith('>')) + tn += ' '; + tn += '>'; + return tn; +} +#endif + +Q_DECLARE_METATYPE(const void*) diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype3.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype3.cpp new file mode 100644 index 0000000000..8dd1eaebb4 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype3.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "tst_qmetatype.h" + +#include + + +#if !defined(TST_QMETATYPE_BROKEN_COMPILER) + +void tst_QMetaType::automaticTemplateRegistration_2() +{ + FOR_EACH_STATIC_PRIMITIVE_TYPE( + PRINT_2ARG_TEMPLATE + ) +} + +#endif // !defined(TST_QMETATYPE_BROKEN_COMPILER)