summaryrefslogtreecommitdiffstats
path: root/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp')
-rw-r--r--tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp206
1 files changed, 96 insertions, 110 deletions
diff --git a/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp b/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp
index 4b926dcd05..be9a240fd5 100644
--- a/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp
+++ b/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp
@@ -1,35 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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 <qcoreapplication.h>
-#include <qmetatype.h>
-#include <QtTest/QtTest>
-
-#include <QtDBus/QtDBus>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+#include <QCoreApplication>
+#include <QMetaType>
+#include <QDBusArgument>
+#include <QDBusMetaType>
class tst_QDBusMetaType: public QObject
{
@@ -108,8 +84,6 @@ typedef QMap<int, QString> IntStringMap;
typedef QMap<QString, QString> StringStringMap;
typedef QMap<QString, Struct1> StringStruct1Map;
-Q_DECLARE_METATYPE(QVariant::Type)
-
QT_BEGIN_NAMESPACE
QDBusArgument &operator<<(QDBusArgument &arg, const Struct1 &)
{
@@ -271,6 +245,15 @@ void tst_QDBusMetaType::initTestCase()
qDBusRegisterMetaType<QList<Struct3> >();
qDBusRegisterMetaType<QList<Struct4> >();
+#ifdef Q_CC_GNU_ONLY
+ // GCC has a defect/extension (depending on your point of view) that allows
+ // a template class with defaulted template parameters to match a Template
+ // Template Parameter (TTP) with fewer template arguments. The call below
+ // tries to use the template<template <typename> class Container, ...>
+ // template functions qdbusargument.h
+ qDBusRegisterMetaType<std::vector<Struct1> >();
+#endif
+
qDBusRegisterMetaType<Invalid0>();
qDBusRegisterMetaType<Invalid1>();
qDBusRegisterMetaType<Invalid2>();
@@ -282,79 +265,82 @@ void tst_QDBusMetaType::initTestCase()
qDBusRegisterMetaType<QList<Invalid0> >();
- intStringMap = qDBusRegisterMetaType<QMap<int, QString> >();
- stringStringMap = qDBusRegisterMetaType<QMap<QString, QString> >();
- stringStruct1Map = qDBusRegisterMetaType<QMap<QString, Struct1> >();
+ intStringMap = qDBusRegisterMetaType<QMap<int, QString> >().id();
+ stringStringMap = qDBusRegisterMetaType<QMap<QString, QString> >().id();
+ stringStruct1Map = qDBusRegisterMetaType<QMap<QString, Struct1> >().id();
}
void tst_QDBusMetaType::staticTypes_data()
{
- QTest::addColumn<QVariant::Type>("typeId");
+ QTest::addColumn<int>("typeId");
QTest::addColumn<QString>("signature");
- QTest::newRow("uchar") << QVariant::Type(QMetaType::UChar) << "y";
- QTest::newRow("bool") << QVariant::Bool << "b";
- QTest::newRow("short") << QVariant::Type(QMetaType::Short) << "n";
- QTest::newRow("ushort") << QVariant::Type(QMetaType::UShort) << "q";
- QTest::newRow("int") << QVariant::Int << "i";
- QTest::newRow("uint") << QVariant::UInt << "u";
- QTest::newRow("qlonglong") << QVariant::LongLong << "x";
- QTest::newRow("qulonglong") << QVariant::ULongLong << "t";
- QTest::newRow("double") << QVariant::Double << "d";
- QTest::newRow("QString") << QVariant::String << "s";
- QTest::newRow("QDBusObjectPath") << QVariant::Type(qMetaTypeId<QDBusObjectPath>()) << "o";
- QTest::newRow("QDBusSignature") << QVariant::Type(qMetaTypeId<QDBusSignature>()) << "g";
- QTest::newRow("QDBusVariant") << QVariant::Type(qMetaTypeId<QDBusVariant>()) << "v";
-
- QTest::newRow("QByteArray") << QVariant::ByteArray << "ay";
- QTest::newRow("QStringList") << QVariant::StringList << "as";
+ QTest::newRow("uchar") << int(QMetaType::UChar) << "y";
+ QTest::newRow("bool") << int(QMetaType::Bool) << "b";
+ QTest::newRow("short") << int(QMetaType::Short) << "n";
+ QTest::newRow("ushort") << int(QMetaType::UShort) << "q";
+ QTest::newRow("int") << int(QMetaType::Int) << "i";
+ QTest::newRow("uint") << int(QMetaType::UInt) << "u";
+ QTest::newRow("qlonglong") << int(QMetaType::LongLong) << "x";
+ QTest::newRow("qulonglong") << int(QMetaType::ULongLong) << "t";
+ QTest::newRow("double") << int(QMetaType::Double) << "d";
+ QTest::newRow("QString") << int(QMetaType::QString) << "s";
+ QTest::newRow("QDBusObjectPath") << qMetaTypeId<QDBusObjectPath>() << "o";
+ QTest::newRow("QDBusSignature") << qMetaTypeId<QDBusSignature>() << "g";
+ QTest::newRow("QDBusVariant") << qMetaTypeId<QDBusVariant>() << "v";
+
+ QTest::newRow("QByteArray") << int(QMetaType::QByteArray) << "ay";
+ QTest::newRow("QStringList") << int(QMetaType::QStringList) << "as";
}
void tst_QDBusMetaType::dynamicTypes_data()
{
- QTest::addColumn<QVariant::Type>("typeId");
+ QTest::addColumn<int>("typeId");
QTest::addColumn<QString>("signature");
- QTest::newRow("QVariantList") << QVariant::List << "av";
- QTest::newRow("QVariantMap") << QVariant::Map << "a{sv}";
- QTest::newRow("QDate") << QVariant::Date << "(iii)";
- QTest::newRow("QTime") << QVariant::Time << "(iiii)";
- QTest::newRow("QDateTime") << QVariant::DateTime << "((iii)(iiii)i)";
- QTest::newRow("QRect") << QVariant::Rect << "(iiii)";
- QTest::newRow("QRectF") << QVariant::RectF << "(dddd)";
- QTest::newRow("QSize") << QVariant::Size << "(ii)";
- QTest::newRow("QSizeF") << QVariant::SizeF << "(dd)";
- QTest::newRow("QPoint") << QVariant::Point << "(ii)";
- QTest::newRow("QPointF") << QVariant::PointF << "(dd)";
- QTest::newRow("QLine") << QVariant::Line << "((ii)(ii))";
- QTest::newRow("QLineF") << QVariant::LineF << "((dd)(dd))";
-
- QTest::newRow("Struct1") << QVariant::Type(qMetaTypeId<Struct1>()) << "(s)";
- QTest::newRow("QList<Struct1>") << QVariant::Type(qMetaTypeId<QList<Struct1> >()) << "a(s)";
-
- QTest::newRow("Struct2") << QVariant::Type(qMetaTypeId<Struct2>()) << "(sos)";
- QTest::newRow("QList<Struct2>") << QVariant::Type(qMetaTypeId<QList<Struct2> >()) << "a(sos)";
-
- QTest::newRow("QList<Struct3>") << QVariant::Type(qMetaTypeId<QList<Struct3> >()) << "a(sas)";
- QTest::newRow("Struct3") << QVariant::Type(qMetaTypeId<Struct3>()) << "(sas)";
-
- QTest::newRow("Struct4") << QVariant::Type(qMetaTypeId<Struct4>()) << "(ssa(ss)sayasx)";
- QTest::newRow("QList<Struct4>") << QVariant::Type(qMetaTypeId<QList<Struct4> >()) << "a(ssa(ss)sayasx)";
-
- QTest::newRow("Struct5") << QVariant::Type(qMetaTypeId<Struct5>()) << "a{sa{sv}}";
-
- QTest::newRow("Struct6") << QVariant::Type(qMetaTypeId<Struct6>()) << "av";
-
- QTest::newRow("QMap<int,QString>") << QVariant::Type(intStringMap) << "a{is}";
- QTest::newRow("QMap<QString,QString>") << QVariant::Type(stringStringMap) << "a{ss}";
- QTest::newRow("QMap<QString,Struct1>") << QVariant::Type(stringStruct1Map) << "a{s(s)}";
+ QTest::newRow("QVariantList") << int(QMetaType::QVariantList) << "av";
+ QTest::newRow("QVariantMap") << int(QMetaType::QVariantMap) << "a{sv}";
+ QTest::newRow("QDate") << int(QMetaType::QDate) << "(iii)";
+ QTest::newRow("QTime") << int(QMetaType::QTime) << "(iiii)";
+ QTest::newRow("QDateTime") << int(QMetaType::QDateTime) << "((iii)(iiii)i)";
+ QTest::newRow("QRect") << int(QMetaType::QRect) << "(iiii)";
+ QTest::newRow("QRectF") << int(QMetaType::QRectF) << "(dddd)";
+ QTest::newRow("QSize") << int(QMetaType::QSize) << "(ii)";
+ QTest::newRow("QSizeF") << int(QMetaType::QSizeF) << "(dd)";
+ QTest::newRow("QPoint") << int(QMetaType::QPoint) << "(ii)";
+ QTest::newRow("QPointF") << int(QMetaType::QPointF) << "(dd)";
+ QTest::newRow("QLine") << int(QMetaType::QLine) << "((ii)(ii))";
+ QTest::newRow("QLineF") << int(QMetaType::QLineF) << "((dd)(dd))";
+
+ QTest::newRow("Struct1") << qMetaTypeId<Struct1>() << "(s)";
+ QTest::newRow("QList<Struct1>") << qMetaTypeId<QList<Struct1> >() << "a(s)";
+#ifdef Q_CC_GNU_ONLY
+ QTest::newRow("std::vector<Struct1>") << qMetaTypeId<std::vector<Struct1> >() << "a(s)";
+#endif
+
+ QTest::newRow("Struct2") << qMetaTypeId<Struct2>() << "(sos)";
+ QTest::newRow("QList<Struct2>") << qMetaTypeId<QList<Struct2>>() << "a(sos)";
+
+ QTest::newRow("QList<Struct3>") << qMetaTypeId<QList<Struct3>>() << "a(sas)";
+ QTest::newRow("Struct3") << qMetaTypeId<Struct3>() << "(sas)";
+
+ QTest::newRow("Struct4") << qMetaTypeId<Struct4>() << "(ssa(ss)sayasx)";
+ QTest::newRow("QList<Struct4>") << qMetaTypeId<QList<Struct4>>() << "a(ssa(ss)sayasx)";
+
+ QTest::newRow("Struct5") << qMetaTypeId<Struct5>() << "a{sa{sv}}";
+
+ QTest::newRow("Struct6") << qMetaTypeId<Struct6>() << "av";
+
+ QTest::newRow("QMap<int,QString>") << intStringMap << "a{is}";
+ QTest::newRow("QMap<QString,QString>") << stringStringMap << "a{ss}";
+ QTest::newRow("QMap<QString,Struct1>") << stringStruct1Map << "a{s(s)}";
}
void tst_QDBusMetaType::staticTypes()
{
- QFETCH(QVariant::Type, typeId);
+ QFETCH(int, typeId);
- QString result = QDBusMetaType::typeToSignature(typeId);
+ QString result = QDBusMetaType::typeToSignature(QMetaType(typeId));
QTEST(result, "signature");
}
@@ -366,43 +352,43 @@ void tst_QDBusMetaType::dynamicTypes()
void tst_QDBusMetaType::invalidTypes_data()
{
- QTest::addColumn<QVariant::Type>("typeId");
+ QTest::addColumn<int>("typeId");
QTest::addColumn<QString>("signature");
- QTest::newRow("Invalid0") << QVariant::Type(qMetaTypeId<Invalid0>()) << "";
- QTest::newRow("Invalid1") << QVariant::Type(qMetaTypeId<Invalid1>()) << "";
- QTest::newRow("Invalid2") << QVariant::Type(qMetaTypeId<Invalid2>()) << "";
- QTest::newRow("Invalid3") << QVariant::Type(qMetaTypeId<Invalid3>()) << "";
- QTest::newRow("Invalid4") << QVariant::Type(qMetaTypeId<Invalid4>()) << "";
- QTest::newRow("Invalid5") << QVariant::Type(qMetaTypeId<Invalid5>()) << "";
- QTest::newRow("Invalid6") << QVariant::Type(qMetaTypeId<Invalid6>()) << "";
- QTest::newRow("Invalid7") << QVariant::Type(qMetaTypeId<Invalid7>()) << "";
+ QTest::newRow("Invalid0") << qMetaTypeId<Invalid0>() << "";
+ QTest::newRow("Invalid1") << qMetaTypeId<Invalid1>() << "";
+ QTest::newRow("Invalid2") << qMetaTypeId<Invalid2>() << "";
+ QTest::newRow("Invalid3") << qMetaTypeId<Invalid3>() << "";
+ QTest::newRow("Invalid4") << qMetaTypeId<Invalid4>() << "";
+ QTest::newRow("Invalid5") << qMetaTypeId<Invalid5>() << "";
+ QTest::newRow("Invalid6") << qMetaTypeId<Invalid6>() << "";
+ QTest::newRow("Invalid7") << qMetaTypeId<Invalid7>() << "";
- QTest::newRow("QList<Invalid0>") << QVariant::Type(qMetaTypeId<QList<Invalid0> >()) << "";
+ QTest::newRow("QList<Invalid0>") << qMetaTypeId<QList<Invalid0>>() << "";
- QTest::newRow("long") << QVariant::Type(QMetaType::Long) << "";
- QTest::newRow("void*") << QVariant::Type(QMetaType::VoidStar) << "";
+ QTest::newRow("long") << int(QMetaType::Long) << "";
+ QTest::newRow("void*") << int(QMetaType::VoidStar) << "";
}
void tst_QDBusMetaType::invalidTypes()
{
// same test
if (qstrcmp(QTest::currentDataTag(), "Invalid0") == 0)
- QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid0' produces invalid D-BUS signature `<empty>' (Did you forget to call beginStructure() ?)");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid0' produces invalid D-Bus signature '<empty>' (Did you forget to call beginStructure() ?)");
else if (qstrcmp(QTest::currentDataTag(), "Invalid1") == 0)
- QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid1' attempts to redefine basic D-BUS type 's' (QString) (Did you forget to call beginStructure() ?)");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid1' attempts to redefine basic D-Bus type 's' (QString) (Did you forget to call beginStructure() ?)");
else if (qstrcmp(QTest::currentDataTag(), "Invalid2") == 0)
- QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid2' attempts to redefine basic D-BUS type 'o' (QDBusObjectPath) (Did you forget to call beginStructure() ?)");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid2' attempts to redefine basic D-Bus type 'o' (QDBusObjectPath) (Did you forget to call beginStructure() ?)");
else if (qstrcmp(QTest::currentDataTag(), "Invalid3") == 0)
- QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid3' attempts to redefine basic D-BUS type 'as' (QStringList) (Did you forget to call beginStructure() ?)");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid3' attempts to redefine basic D-Bus type 'as' (QStringList) (Did you forget to call beginStructure() ?)");
else if (qstrcmp(QTest::currentDataTag(), "Invalid4") == 0)
- QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid4' attempts to redefine basic D-BUS type 'ay' (QByteArray) (Did you forget to call beginStructure() ?)");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid4' attempts to redefine basic D-Bus type 'ay' (QByteArray) (Did you forget to call beginStructure() ?)");
else if (qstrcmp(QTest::currentDataTag(), "Invalid5") == 0)
- QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid5' produces invalid D-BUS signature `ii' (Did you forget to call beginStructure() ?)");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid5' produces invalid D-Bus signature 'ii' (Did you forget to call beginStructure() ?)");
else if (qstrcmp(QTest::currentDataTag(), "Invalid7") == 0)
- QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid7' produces invalid D-BUS signature `()' (Did you forget to call beginStructure() ?)");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid7' produces invalid D-Bus signature '()' (Did you forget to call beginStructure() ?)");
else if (qstrcmp(QTest::currentDataTag(), "QList<Invalid0>") == 0)
- QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `QList<Invalid0>' produces invalid D-BUS signature `a' (Did you forget to call beginStructure() ?)");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'QList<Invalid0>' produces invalid D-Bus signature 'a' (Did you forget to call beginStructure() ?)");
staticTypes();
staticTypes(); // run twice: the error messages should be printed once only