diff options
Diffstat (limited to 'tests/auto/corelib/kernel')
30 files changed, 1206 insertions, 274 deletions
diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro index 4b3b2e824e..6b93439a56 100644 --- a/tests/auto/corelib/kernel/kernel.pro +++ b/tests/auto/corelib/kernel/kernel.pro @@ -9,6 +9,7 @@ SUBDIRS=\ qmetamethod \ qmetaproperty \ qmetatype \ + qmetaenum \ qmimedata \ qobject \ qpointer \ @@ -37,4 +38,4 @@ SUBDIRS=\ # This test is only applicable on Windows !win32*|winrt: SUBDIRS -= qwineventnotifier -android|qnx: SUBDIRS -= qsharedmemory qsystemsemaphore +android: SUBDIRS -= qsharedmemory qsystemsemaphore diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index 442d9db85c..93a6daa6b9 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -109,11 +109,11 @@ void tst_QCoreApplication::qAppName() QCOMPARE(QCoreApplication::applicationName(), QString::fromLatin1(appName)); } -// "QCoreApplication::arguments() always parses arguments from actual command line on Windows -// making this test invalid." -#ifndef Q_OS_WIN void tst_QCoreApplication::argc() { +#if defined(Q_OS_WINCE) || defined(Q_OS_WINRT) + QSKIP("QCoreApplication::arguments() parses arguments from actual command line on this platform."); +#endif { int argc = 1; char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; @@ -150,7 +150,6 @@ void tst_QCoreApplication::argc() QCOMPARE(app.arguments().count(), 1); } } -#endif class EventGenerator : public QObject { diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h index 6f09399654..3dd84482d7 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -43,9 +43,7 @@ private slots: void sendEventsOnProcessEvents(); // this must be the first test void getSetCheck(); void qAppName(); -#ifndef Q_OS_WIN void argc(); -#endif void postEvent(); void removePostedEvents(); #ifndef QT_NO_THREAD diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp index 9c9d644c54..aaacfcae03 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp index befd45018a..f555d2e58e 100644 --- a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp +++ b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp index 02eea4d0c0..f709c29bc3 100644 --- a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp +++ b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp @@ -1,8 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2015 The Qt Company Ltd. ** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -11,9 +11,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -24,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qmetaenum/qmetaenum.pro b/tests/auto/corelib/kernel/qmetaenum/qmetaenum.pro new file mode 100644 index 0000000000..f045fc5d88 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetaenum/qmetaenum.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +CONFIG += parallel_test +TARGET = tst_qmetaenum +QT = core testlib +SOURCES = tst_qmetaenum.cpp diff --git a/tests/auto/corelib/kernel/qmetaenum/tst_qmetaenum.cpp b/tests/auto/corelib/kernel/qmetaenum/tst_qmetaenum.cpp new file mode 100644 index 0000000000..e81e105bfb --- /dev/null +++ b/tests/auto/corelib/kernel/qmetaenum/tst_qmetaenum.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> + +#include <QtCore/qobject.h> +#include <QtCore/qmetaobject.h> + +class tst_QMetaEnum : public QObject +{ + Q_OBJECT +public: + enum SuperEnum { SuperValue1 = 1 , SuperValue2 = 2 }; + Q_ENUM(SuperEnum) + +private slots: + void fromType(); +}; + +void tst_QMetaEnum::fromType() +{ + QMetaEnum meta = QMetaEnum::fromType<SuperEnum>(); + QVERIFY(meta.isValid()); + QCOMPARE(meta.name(), "SuperEnum"); + QCOMPARE(meta.enclosingMetaObject(), &staticMetaObject); + QCOMPARE(meta.keyCount(), 2); +} + +QTEST_MAIN(tst_QMetaEnum) +#include "tst_qmetaenum.moc" diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp index 1d39280afb..cf3ff04aa4 100644 --- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp +++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com> +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +11,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -50,6 +51,8 @@ private slots: void comparisonOperators(); void fromSignal(); + + void gadget(); }; struct CustomType { }; @@ -727,5 +730,51 @@ void tst_QMetaMethod::fromSignal() #undef FROMSIGNAL_HELPER } +class MyGadget { + Q_GADGET +public: + QString m_value; + Q_INVOKABLE void setValue(const QString &value) { m_value = value; } + Q_INVOKABLE QString getValue() { return m_value; } +}; + +void tst_QMetaMethod::gadget() +{ + int idx; + + idx = MyGadget::staticMetaObject.indexOfMethod("setValue(QString)"); + QVERIFY(idx >= 0); + QMetaMethod setValueMethod = MyGadget::staticMetaObject.method(idx); + QVERIFY(setValueMethod.isValid()); + + idx = MyGadget::staticMetaObject.indexOfMethod("getValue()"); + QVERIFY(idx >= 0); + QMetaMethod getValueMethod = MyGadget::staticMetaObject.method(idx); + QVERIFY(getValueMethod.isValid()); + + { + MyGadget gadget; + QString string; + + QVERIFY(getValueMethod.invokeOnGadget(&gadget, Q_RETURN_ARG(QString, string))); + QCOMPARE(string, gadget.m_value); + + QVERIFY(setValueMethod.invokeOnGadget(&gadget, Q_ARG(QString, QLatin1String("hello")))); + QCOMPARE(gadget.m_value, QLatin1String("hello")); + + QVERIFY(getValueMethod.invokeOnGadget(&gadget, Q_RETURN_ARG(QString, string))); + QCOMPARE(string, gadget.m_value); + } + + { + // Call with null should not crash + MyGadget *gadget = Q_NULLPTR; + QString string; + QVERIFY(!setValueMethod.invokeOnGadget(gadget, Q_ARG(QString, QLatin1String("hi")))); + QVERIFY(!getValueMethod.invokeOnGadget(gadget, Q_RETURN_ARG(QString, string))); + } +} + + QTEST_MAIN(tst_QMetaMethod) #include "tst_qmetamethod.moc" diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 8a7e945730..90242f78a2 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -46,15 +46,13 @@ struct MyStruct }; namespace MyNamespace { + // Used in tst_QMetaObject::checkScope class MyClass : public QObject { Q_OBJECT Q_PROPERTY(MyEnum myEnum READ myEnum WRITE setMyEnum) Q_PROPERTY(MyFlags myFlags READ myFlags WRITE setMyFlags) - Q_ENUMS(MyEnum) - Q_ENUMS(MyAnotherEnum) - Q_FLAGS(MyFlags) public: enum MyEnum { MyEnum1, @@ -85,17 +83,65 @@ namespace MyNamespace { m_flags(MyFlag1|MyFlag2) { } private: + Q_ENUM(MyEnum) + Q_ENUM(MyAnotherEnum) + Q_FLAG(MyFlags) + MyEnum m_enum; MyFlags m_flags; }; Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::MyFlags) + + + // test the old Q_ENUMS macro + class MyClass2 : public QObject + { + Q_OBJECT + Q_PROPERTY(MyEnum myEnum READ myEnum WRITE setMyEnum) + Q_PROPERTY(MyFlags myFlags READ myFlags WRITE setMyFlags) + + public: + enum MyEnum { + MyEnum1, + MyEnum2, + MyEnum3 + }; + enum MyAnotherEnum { + MyAnotherEnum1 = 1, + MyAnotherEnum2 = 2, + MyAnotherEnum3 = -1 + }; + enum MyFlag { + MyFlag1 = 0x01, + MyFlag2 = 0x02, + MyFlag3 = 0x04 + }; + Q_DECLARE_FLAGS(MyFlags, MyFlag) + + MyEnum myEnum() const { return m_enum; } + void setMyEnum(MyEnum val) { m_enum = val; } + + MyFlags myFlags() const { return m_flags; } + void setMyFlags(MyFlags val) { m_flags = val; } + + MyClass2(QObject *parent = 0) + : QObject(parent), + m_enum(MyEnum1), + m_flags(MyFlag1|MyFlag2) + { } + private: + Q_ENUMS(MyEnum MyAnotherEnum) + Q_FLAGS(MyFlags) + + MyEnum m_enum; + MyFlags m_flags; + }; } class tst_QMetaObject : public QObject { Q_OBJECT - Q_ENUMS(EnumType) Q_PROPERTY(EnumType value WRITE setValue READ getValue) Q_PROPERTY(EnumType value2 WRITE set_value READ get_value) Q_PROPERTY(MyStruct value3 WRITE setVal3 READ val3) @@ -109,6 +155,7 @@ class tst_QMetaObject : public QObject public: enum EnumType { EnumType1 }; + Q_ENUM(EnumType); void setValue(EnumType) {} EnumType getValue() const { return EnumType1; } @@ -154,6 +201,7 @@ private slots: void normalizedType_data(); void normalizedType(); void customPropertyType(); + void checkScope_data(); void checkScope(); void propertyNotify(); void propertyConstant(); @@ -177,6 +225,7 @@ private slots: void signal(); void signalIndex_data(); void signalIndex(); + void enumDebugStream(); signals: void value6Changed(); @@ -420,7 +469,7 @@ void QtTestObject::testLongLong(qint64 ll1, quint64 ll2) void QtTestObject::testSender() { - slotResult.sprintf("%p", sender()); + slotResult = QString::asprintf("%p", sender()); } void QtTestObject::slotWithUnregisteredParameterType(MyUnregisteredType) @@ -990,19 +1039,35 @@ void tst_QMetaObject::customPropertyType() QCOMPARE(prop.type(), QVariant::List); } +void tst_QMetaObject::checkScope_data() +{ + QTest::addColumn<QObject *>("object"); + QTest::addColumn<QByteArray>("name"); + + static MyNamespace::MyClass obj1; + static MyNamespace::MyClass2 obj2; + + QTest::newRow("MyClass") << static_cast<QObject*>(&obj1) << QByteArray("MyClass"); + QTest::newRow("MyClass2") << static_cast<QObject*>(&obj2) << QByteArray("MyClass2"); + +} + + void tst_QMetaObject::checkScope() { - MyNamespace::MyClass obj; + QFETCH(QObject *, object); + QFETCH(QByteArray, name); + QObject &obj = *object; bool ok; const QMetaObject *mo = obj.metaObject(); QMetaEnum me = mo->enumerator(mo->indexOfEnumerator("MyEnum")); QVERIFY(me.isValid()); QVERIFY(!me.isFlag()); - QCOMPARE(QLatin1String(me.scope()), QLatin1String("MyNamespace::MyClass")); - QCOMPARE(me.keyToValue("MyNamespace::MyClass::MyEnum2", &ok), 1); + QCOMPARE(QByteArray(me.scope()), QByteArray("MyNamespace::" + name)); + QCOMPARE(me.keyToValue("MyNamespace::" + name + "::MyEnum2", &ok), 1); QCOMPARE(ok, true); - QCOMPARE(me.keyToValue("MyClass::MyEnum2", &ok), -1); + QCOMPARE(me.keyToValue(name + "::MyEnum2", &ok), -1); QCOMPARE(ok, false); QCOMPARE(me.keyToValue("MyNamespace::MyEnum2", &ok), -1); QCOMPARE(ok, false); @@ -1027,10 +1092,10 @@ void tst_QMetaObject::checkScope() QMetaEnum mf = mo->enumerator(mo->indexOfEnumerator("MyFlags")); QVERIFY(mf.isValid()); QVERIFY(mf.isFlag()); - QCOMPARE(QLatin1String(mf.scope()), QLatin1String("MyNamespace::MyClass")); - QCOMPARE(mf.keysToValue("MyNamespace::MyClass::MyFlag2", &ok), 2); + QCOMPARE(QByteArray(mf.scope()), QByteArray("MyNamespace::" + name)); + QCOMPARE(mf.keysToValue("MyNamespace::" + name + "::MyFlag2", &ok), 2); QCOMPARE(ok, true); - QCOMPARE(mf.keysToValue("MyClass::MyFlag2", &ok), -1); + QCOMPARE(mf.keysToValue(name + "::MyFlag2", &ok), -1); QCOMPARE(ok, false); QCOMPARE(mf.keysToValue("MyNamespace::MyFlag2", &ok), -1); QCOMPARE(ok, false); @@ -1039,9 +1104,9 @@ void tst_QMetaObject::checkScope() QCOMPARE(mf.keysToValue("MyFlag", &ok), -1); QCOMPARE(ok, false); QCOMPARE(QLatin1String(mf.valueToKey(2)), QLatin1String("MyFlag2")); - QCOMPARE(mf.keysToValue("MyNamespace::MyClass::MyFlag1|MyNamespace::MyClass::MyFlag2", &ok), 3); + QCOMPARE(mf.keysToValue("MyNamespace::" + name + "::MyFlag1|MyNamespace::" + name + "::MyFlag2", &ok), 3); QCOMPARE(ok, true); - QCOMPARE(mf.keysToValue("MyClass::MyFlag1|MyClass::MyFlag2", &ok), -1); + QCOMPARE(mf.keysToValue(name + "::MyFlag1|" + name + "::MyFlag2", &ok), -1); QCOMPARE(ok, false); QCOMPARE(mf.keysToValue("MyNamespace::MyFlag1|MyNamespace::MyFlag2", &ok), -1); QCOMPARE(ok, false); @@ -1049,9 +1114,9 @@ void tst_QMetaObject::checkScope() QCOMPARE(ok, true); QCOMPARE(mf.keysToValue("MyFlag2|MyFlag2", &ok), 2); QCOMPARE(ok, true); - QCOMPARE(mf.keysToValue("MyFlag1|MyNamespace::MyClass::MyFlag2", &ok), 3); + QCOMPARE(mf.keysToValue("MyFlag1|MyNamespace::" + name + "::MyFlag2", &ok), 3); QCOMPARE(ok, true); - QCOMPARE(mf.keysToValue("MyNamespace::MyClass::MyFlag2|MyNamespace::MyClass::MyFlag2", &ok), 2); + QCOMPARE(mf.keysToValue("MyNamespace::" + name + "::MyFlag2|MyNamespace::" + name + "::MyFlag2", &ok), 2); QCOMPARE(ok, true); QCOMPARE(QLatin1String(mf.valueToKeys(3)), QLatin1String("MyFlag1|MyFlag2")); } @@ -1142,7 +1207,6 @@ void tst_QMetaObject::metaMethod() QCOMPARE(str, QString("foo")); QCOMPARE(ret, QString("bar")); - QtTestObject obj; QString t1("1"); QString t2("2"); QString t3("3"); QString t4("4"); QString t5("5"); QString t6("6"); QString t7("7"); QString t8("8"); QString t9("9"); QString t10("X"); @@ -1348,5 +1412,15 @@ void tst_QMetaObject::signalIndex() SignalTestHelper::signalIndex(mm)); } +void tst_QMetaObject::enumDebugStream() +{ + QTest::ignoreMessage(QtDebugMsg, "hello MyNamespace::MyClass::MyEnum(MyEnum2) world "); + MyNamespace::MyClass::MyEnum e = MyNamespace::MyClass::MyEnum2; + qDebug() << "hello" << e << "world"; + + QTest::ignoreMessage(QtDebugMsg, "Qt::WindowType(WindowTitleHint) Qt::WindowType(Window) Qt::WindowType(Desktop) Qt::WindowType(WindowSystemMenuHint)"); + qDebug() << Qt::WindowTitleHint << Qt::Window <<Qt::Desktop << Qt::WindowSystemMenuHint; +} + QTEST_MAIN(tst_QMetaObject) #include "tst_qmetaobject.moc" diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp index d76f1b764d..74fcde2e71 100644 --- a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp +++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp index 5cac80191c..a18c9eb370 100644 --- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp +++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com> +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +11,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -50,6 +51,8 @@ private slots: void hasStdCppSet(); void isConstant(); void isFinal(); + void gadget(); + void readAndWriteWithLazyRegistration(); public: enum EnumType { EnumType1 }; @@ -103,5 +106,82 @@ void tst_QMetaProperty::isFinal() QVERIFY(!prop.isFinal()); } +class MyGadget { + Q_GADGET + Q_PROPERTY(QString value READ getValue WRITE setValue RESET resetValue) +public: + QString m_value; + void setValue(const QString &value) { m_value = value; } + QString getValue() { return m_value; } + void resetValue() { m_value = QLatin1Literal("reset"); } +}; + +void tst_QMetaProperty::gadget() +{ + const QMetaObject *mo = &MyGadget::staticMetaObject; + QMetaProperty valueProp = mo->property(mo->indexOfProperty("value")); + QVERIFY(valueProp.isValid()); + { + MyGadget g; + QString hello = QLatin1Literal("hello"); + QVERIFY(valueProp.writeOnGadget(&g, hello)); + QCOMPARE(g.m_value, QLatin1String("hello")); + QCOMPARE(valueProp.readOnGadget(&g), QVariant(hello)); + QVERIFY(valueProp.resetOnGadget(&g)); + QCOMPARE(valueProp.readOnGadget(&g), QVariant(QLatin1String("reset"))); + } +} + +struct CustomReadObject : QObject +{ + Q_OBJECT +}; + +struct CustomWriteObject : QObject +{ + Q_OBJECT +}; + +struct CustomWriteObjectChild : CustomWriteObject +{ + Q_OBJECT +}; + +struct TypeLazyRegistration : QObject +{ + Q_OBJECT + Q_PROPERTY(CustomReadObject *read MEMBER _read) + Q_PROPERTY(CustomWriteObject *write MEMBER _write) + + CustomReadObject *_read; + CustomWriteObject *_write; + +public: + TypeLazyRegistration() + : _read() + , _write() + {} +}; + +void tst_QMetaProperty::readAndWriteWithLazyRegistration() +{ + QCOMPARE(QMetaType::type("CustomReadObject*"), int(QMetaType::UnknownType)); + QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType)); + + TypeLazyRegistration o; + QVERIFY(o.property("read").isValid()); + QVERIFY(QMetaType::type("CustomReadObject*") != QMetaType::UnknownType); + QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType)); + + CustomWriteObjectChild data; + QVariant value = QVariant::fromValue(&data); // this register CustomWriteObjectChild + // check if base classes are not registered automatically, otherwise this test would be meaningless + QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType)); + QVERIFY(o.setProperty("write", value)); + QVERIFY(QMetaType::type("CustomWriteObject*") != QMetaType::UnknownType); + QCOMPARE(o.property("write").value<CustomWriteObjectChild*>(), &data); +} + + QTEST_MAIN(tst_QMetaProperty) #include "tst_qmetaproperty.moc" diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index a35896283a..717a7633f5 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -79,6 +79,10 @@ private slots: void normalizedTypes(); void typeName_data(); void typeName(); + void type_data(); + void type(); + void type_fromSubString_data(); + void type_fromSubString(); void create_data(); void create(); void createCopy_data(); @@ -109,6 +113,7 @@ private slots: void saveAndLoadBuiltin_data(); void saveAndLoadBuiltin(); void saveAndLoadCustom(); + void metaObject_data(); void metaObject(); void constexprMetaTypeIds(); void constRefs(); @@ -116,6 +121,7 @@ private slots: void convertCustomType(); void compareCustomType_data(); void compareCustomType(); + void compareCustomEqualOnlyType(); void customDebugStream(); }; @@ -130,6 +136,11 @@ public: : QObject(parent) { } + enum CustomQEnum { Val1, Val2 }; + Q_ENUM(CustomQEnum) +}; +class CustomGadget { + Q_GADGET }; class CustomNonQObject {}; @@ -140,10 +151,13 @@ void tst_QMetaType::defined() QCOMPARE(int(QMetaTypeId2<Foo>::Defined), 0); QCOMPARE(int(QMetaTypeId2<void*>::Defined), 1); QCOMPARE(int(QMetaTypeId2<int*>::Defined), 0); - QVERIFY(QMetaTypeId2<CustomQObject*>::Defined); + QCOMPARE(int(QMetaTypeId2<CustomQObject::CustomQEnum>::Defined), 1); + QCOMPARE(int(QMetaTypeId2<CustomGadget>::Defined), 1); + QVERIFY(int(QMetaTypeId2<CustomQObject*>::Defined)); QVERIFY(!QMetaTypeId2<CustomQObject>::Defined); QVERIFY(!QMetaTypeId2<CustomNonQObject>::Defined); QVERIFY(!QMetaTypeId2<CustomNonQObject*>::Defined); + QVERIFY(!QMetaTypeId2<CustomGadget*>::Defined); } struct Bar @@ -372,6 +386,11 @@ void tst_QMetaType::typeName_data() QTest::newRow("QMap<int,int>") << static_cast<QMetaType::Type>(::qMetaTypeId<QMap<int, int> >()) << QString::fromLatin1("QMap<int,int>"); QTest::newRow("QVector<QList<int>>") << static_cast<QMetaType::Type>(::qMetaTypeId<QVector<QList<int> > >()) << QString::fromLatin1("QVector<QList<int> >"); QTest::newRow("QVector<QMap<int,int>>") << static_cast<QMetaType::Type>(::qMetaTypeId<QVector<QMap<int, int> > >()) << QString::fromLatin1("QVector<QMap<int,int> >"); + + QTest::newRow("CustomQObject*") << static_cast<QMetaType::Type>(::qMetaTypeId<CustomQObject*>()) << QString::fromLatin1("CustomQObject*"); + QTest::newRow("CustomGadget") << static_cast<QMetaType::Type>(::qMetaTypeId<CustomGadget>()) << QString::fromLatin1("CustomGadget"); + QTest::newRow("CustomQObject::CustomQEnum") << static_cast<QMetaType::Type>(::qMetaTypeId<CustomQObject::CustomQEnum>()) << QString::fromLatin1("CustomQObject::CustomQEnum"); + QTest::newRow("Qt::ArrowType") << static_cast<QMetaType::Type>(::qMetaTypeId<Qt::ArrowType>()) << QString::fromLatin1("Qt::ArrowType"); } void tst_QMetaType::typeName() @@ -385,6 +404,61 @@ void tst_QMetaType::typeName() QCOMPARE(name.toLatin1(), QMetaObject::normalizedType(name.toLatin1().constData())); } +void tst_QMetaType::type_data() +{ + QTest::addColumn<QMetaType::Type>("aType"); + QTest::addColumn<QByteArray>("aTypeName"); + +#define TST_QMETATYPE_TYPE_DATA(MetaTypeName, MetaTypeId, RealType)\ + QTest::newRow(#RealType) << QMetaType::MetaTypeName << QByteArray( #RealType ); +#define TST_QMETATYPE_TYPE_DATA_ALIAS(MetaTypeName, MetaTypeId, AliasType, RealTypeString)\ + QTest::newRow(RealTypeString) << QMetaType::MetaTypeName << QByteArray( #AliasType ); + + QTest::newRow("empty") << QMetaType::UnknownType << QByteArray(); + + QT_FOR_EACH_STATIC_TYPE(TST_QMETATYPE_TYPE_DATA) + QT_FOR_EACH_STATIC_ALIAS_TYPE(TST_QMETATYPE_TYPE_DATA_ALIAS) + +#undef TST_QMETATYPE_TYPE_DATA +#undef TST_METATYPE_TYPE_DATA_ALIAS +} + +void tst_QMetaType::type() +{ + QFETCH(QMetaType::Type, aType); + QFETCH(QByteArray, aTypeName); + + // QMetaType::type(QByteArray) + QCOMPARE(QMetaType::type(aTypeName), int(aType)); + // QMetaType::type(const char *) + QCOMPARE(QMetaType::type(aTypeName.constData()), int(aType)); +} + +void tst_QMetaType::type_fromSubString_data() +{ + QTest::addColumn<int>("offset"); + QTest::addColumn<int>("size"); + QTest::addColumn<int>("expectedType"); + + // The test string is defined in the test function below + QTest::newRow("int") << 0 << 3 << int(QMetaType::Int); + QTest::newRow("boo") << 3 << 3 << 0; + QTest::newRow("bool") << 3 << 4 << int(QMetaType::Bool); + QTest::newRow("intbool") << 0 << 7 << 0; + QTest::newRow("QMetaType::Type") << 7 << 15 << ::qMetaTypeId<QMetaType::Type>(); + QTest::newRow("double") << 22 << 6 << int(QMetaType::Double); +} + +void tst_QMetaType::type_fromSubString() +{ + static const char *types = "intboolQMetaType::Typedoublexxx"; + QFETCH(int, offset); + QFETCH(int, size); + QFETCH(int, expectedType); + QByteArray ba = QByteArray::fromRawData(types + offset, size); + QCOMPARE(QMetaType::type(ba), expectedType); +} + #define FOR_EACH_PRIMITIVE_METATYPE(F) \ QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \ QT_FOR_EACH_STATIC_CORE_POINTER(F) \ @@ -968,7 +1042,9 @@ void tst_QMetaType::flagsBinaryCompatibility5_0() QFETCH(quint32, id); QFETCH(quint32, flags); - QCOMPARE(quint32(QMetaType::typeFlags(id)), flags); + quint32 mask_5_0 = 0x1ff; // Only compare the values that were already defined in 5.0 + + QCOMPARE(quint32(QMetaType::typeFlags(id)) & mask_5_0, flags); } void tst_QMetaType::construct_data() @@ -1772,17 +1848,48 @@ void tst_QMetaType::saveAndLoadCustom() QCOMPARE(stream.status(), QDataStream::ReadPastEnd); } +class MyGadget { + Q_GADGET; +public: + enum MyEnum { Val1, Val2, Val3 }; + Q_ENUM(MyEnum) +}; + +Q_DECLARE_METATYPE(MyGadget); +Q_DECLARE_METATYPE(const QMetaObject *); +Q_DECLARE_METATYPE(Qt::ScrollBarPolicy); +Q_DECLARE_METATYPE(MyGadget::MyEnum); + +void tst_QMetaType::metaObject_data() +{ + QTest::addColumn<int>("type"); + QTest::addColumn<const QMetaObject*>("result"); + QTest::addColumn<bool>("isGadget"); + QTest::addColumn<bool>("isQObjectPtr"); + + QTest::newRow("QObject") << int(QMetaType::QObjectStar) << &QObject::staticMetaObject << false << true; + QTest::newRow("QFile*") << ::qMetaTypeId<QFile*>() << &QFile::staticMetaObject << false << true; + QTest::newRow("MyObject*") << ::qMetaTypeId<MyObject*>() << &MyObject::staticMetaObject << false << true; + QTest::newRow("int") << int(QMetaType::Int) << static_cast<const QMetaObject *>(0) << false << false; + QTest::newRow("QEasingCurve") << ::qMetaTypeId<QEasingCurve>() << &QEasingCurve::staticMetaObject << true << false; + QTest::newRow("MyGadget") << ::qMetaTypeId<MyGadget>() << &MyGadget::staticMetaObject << true << false; + QTest::newRow("MyEnum") << ::qMetaTypeId<MyGadget::MyEnum>() << &MyGadget::staticMetaObject << false << false; + QTest::newRow("Qt::ScrollBarPolicy") << ::qMetaTypeId<Qt::ScrollBarPolicy>() << &QObject::staticQtMetaObject << false << false; +} + + void tst_QMetaType::metaObject() { - QCOMPARE(QMetaType::metaObjectForType(QMetaType::QObjectStar), &QObject::staticMetaObject); - QCOMPARE(QMetaType::metaObjectForType(::qMetaTypeId<QFile*>()), &QFile::staticMetaObject); - QCOMPARE(QMetaType::metaObjectForType(::qMetaTypeId<MyObject*>()), &MyObject::staticMetaObject); - QCOMPARE(QMetaType::metaObjectForType(QMetaType::Int), static_cast<const QMetaObject *>(0)); + QFETCH(int, type); + QFETCH(const QMetaObject *, result); + QFETCH(bool, isGadget); + QFETCH(bool, isQObjectPtr); - QCOMPARE(QMetaType(QMetaType::QObjectStar).metaObject(), &QObject::staticMetaObject); - QCOMPARE(QMetaType(::qMetaTypeId<QFile*>()).metaObject(), &QFile::staticMetaObject); - QCOMPARE(QMetaType(::qMetaTypeId<MyObject*>()).metaObject(), &MyObject::staticMetaObject); - QCOMPARE(QMetaType(QMetaType::Int).metaObject(), static_cast<const QMetaObject *>(0)); + QCOMPARE(QMetaType::metaObjectForType(type), result); + QMetaType mt(type); + QCOMPARE(mt.metaObject(), result); + QCOMPARE(!!(mt.flags() & QMetaType::IsGadget), isGadget); + QCOMPARE(!!(mt.flags() & QMetaType::PointerToQObject), isQObjectPtr); } #define METATYPE_ID_FUNCTION(Type, MetaTypeId, Name) \ @@ -1917,9 +2024,23 @@ bool operator==(const CustomConvertibleType2 &lhs, const CustomConvertibleType2 bool operator!=(const CustomConvertibleType2 &lhs, const CustomConvertibleType2 &rhs) { return !operator==(lhs, rhs); } + +struct CustomEqualsOnlyType +{ + explicit CustomEqualsOnlyType(int value = 0) : val(value) {} + virtual ~CustomEqualsOnlyType() {} + + int val; +}; +bool operator==(const CustomEqualsOnlyType &lhs, const CustomEqualsOnlyType &rhs) +{ return lhs.val == rhs.val;} +bool operator!=(const CustomEqualsOnlyType &lhs, const CustomEqualsOnlyType &rhs) +{ return !operator==(lhs, rhs); } + Q_DECLARE_METATYPE(CustomConvertibleType); Q_DECLARE_METATYPE(CustomConvertibleType2); Q_DECLARE_METATYPE(CustomDebugStreamableType); +Q_DECLARE_METATYPE(CustomEqualsOnlyType); template<typename T, typename U> U convert(const T &t) @@ -2196,6 +2317,81 @@ void tst_QMetaType::compareCustomType() QCOMPARE(unsorted, sorted); } +void tst_QMetaType::compareCustomEqualOnlyType() +{ + int metaTypeId = qRegisterMetaType<CustomEqualsOnlyType>(); + QMetaType::registerEqualsComparator<CustomEqualsOnlyType>(); + int result; + + CustomEqualsOnlyType val50(50); + CustomEqualsOnlyType val100(100); + CustomEqualsOnlyType val100x(100); + + QVariant variant50 = QVariant::fromValue(val50); + QVariant variant100 = QVariant::fromValue(val100); + QVariant variant100x = QVariant::fromValue(val100x); + + QVERIFY(variant50 != variant100); + QVERIFY(variant50 != variant100x); + QVERIFY(variant100 != variant50); + QVERIFY(variant100x != variant50); + QVERIFY(variant100 == variant100x); + QVERIFY(variant100 == variant100); + + // compare always fails + QVERIFY(!(variant50 < variant50)); + QVERIFY(!(variant50 < variant100)); + QVERIFY(!(variant100 < variant50)); + + // check QMetaType::compare works/doesn't crash for equals only comparators + bool wasSuccess = QMetaType::compare(variant50.constData(), variant50.constData(), + metaTypeId, &result); + QCOMPARE(result, 0); + QVERIFY(wasSuccess); + wasSuccess = QMetaType::compare(variant100.constData(), variant100x.constData(), + metaTypeId, &result); + QCOMPARE(result, 0); + QVERIFY(wasSuccess); + + wasSuccess = QMetaType::compare(variant50.constData(), variant100.constData(), + metaTypeId, &result); + QVERIFY(!wasSuccess); + + // check QMetaType::equals works for equals only comparator + wasSuccess = QMetaType::equals(variant50.constData(), variant50.constData(), + metaTypeId, &result); + QCOMPARE(result, 0); + QVERIFY(wasSuccess); + wasSuccess = QMetaType::equals(variant100.constData(), variant100.constData(), + metaTypeId, &result); + QCOMPARE(result, 0); + QVERIFY(wasSuccess); + wasSuccess = QMetaType::equals(variant100x.constData(), variant100x.constData(), + metaTypeId, &result); + QCOMPARE(result, 0); + QVERIFY(wasSuccess); + wasSuccess = QMetaType::equals(variant100.constData(), variant100x.constData(), + metaTypeId, &result); + QCOMPARE(result, 0); + QVERIFY(wasSuccess); + wasSuccess = QMetaType::equals(variant50.constData(), variant100.constData(), + metaTypeId, &result); + QCOMPARE(result, -1); + QVERIFY(wasSuccess); + wasSuccess = QMetaType::equals(variant50.constData(), variant100x.constData(), + metaTypeId, &result); + QCOMPARE(result, -1); + QVERIFY(wasSuccess); + + //check QMetaType::equals for type w/o equals comparator being registered + CustomMovable movable1; + CustomMovable movable2; + wasSuccess = QMetaType::equals(&movable1, &movable2, + qRegisterMetaType<CustomMovable>(), &result); + QVERIFY(!wasSuccess); + +} + struct MessageHandlerCustom : public MessageHandler { MessageHandlerCustom(const int typeId) diff --git a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp index f4c267e321..3886051fdc 100644 --- a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp +++ b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.cpp b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.cpp index 4e4717bd1c..93146a9b66 100644 --- a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.cpp +++ b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.h b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.h index 735f1a8cd9..6f4fbf88ac 100644 --- a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.h +++ b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 83cdde5aa4..24cfe8f3bc 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -1,8 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2015 The Qt Company Ltd. ** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com> -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -11,9 +11,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -24,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -1502,7 +1502,6 @@ typedef QString CustomString; class PropertyObject : public QObject { Q_OBJECT - Q_ENUMS(Alpha Priority) Q_PROPERTY(Alpha alpha READ alpha WRITE setAlpha) Q_PROPERTY(Priority priority READ priority WRITE setPriority) @@ -1564,6 +1563,9 @@ private: float m_float; qreal m_qreal; CustomString m_customString; + + Q_ENUM(Alpha) + Q_ENUM(Priority) }; Q_DECLARE_METATYPE(PropertyObject::Priority) diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp index 689b008551..814c4bb691 100644 --- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp +++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qsharedmemory/sharedmemoryhelper/main.cpp b/tests/auto/corelib/kernel/qsharedmemory/sharedmemoryhelper/main.cpp index b3c69c7bf7..03c5a13da9 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/sharedmemoryhelper/main.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/sharedmemoryhelper/main.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/test.pro b/tests/auto/corelib/kernel/qsharedmemory/test/test.pro index 97ba1153df..fabd2cf7a3 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/test/test.pro +++ b/tests/auto/corelib/kernel/qsharedmemory/test/test.pro @@ -3,6 +3,7 @@ CONFIG += testcase QT = core-private testlib mac:CONFIG -= app_bundle +linux:LIBS += -lrt SOURCES += tst_qsharedmemory.cpp TARGET = tst_qsharedmemory diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp index 7182428f14..af932202fe 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -174,7 +174,11 @@ void tst_QSharedMemory::cleanup() #include <private/qsharedmemory_p.h> #include <sys/types.h> #include <sys/ipc.h> +#ifndef QT_POSIX_IPC #include <sys/shm.h> +#else +#include <sys/mman.h> +#endif // QT_POSIX_IPC #include <errno.h> #endif @@ -189,7 +193,10 @@ QString tst_QSharedMemory::helperBinary() int tst_QSharedMemory::remove(const QString &key) { -#ifndef Q_OS_WIN +#ifdef Q_OS_WIN + Q_UNUSED(key); + return 0; +#else // On unix the shared memory might exists from a previously failed test // or segfault, remove it it does if (key.isEmpty()) @@ -202,6 +209,7 @@ int tst_QSharedMemory::remove(const QString &key) return -2; } +#ifndef QT_POSIX_IPC int unix_key = ftok(fileName.toLatin1().constData(), 'Q'); if (-1 == unix_key) { qDebug() << "ftok failed"; @@ -219,11 +227,15 @@ int tst_QSharedMemory::remove(const QString &key) qDebug() << "shmctl failed"; return -5; } - return QFile::remove(fileName); #else - Q_UNUSED(key); - return 0; -#endif + if (shm_unlink(QFile::encodeName(fileName).constData()) == -1) { + qDebug() << "shm_unlink failed"; + return -5; + } +#endif // QT_POSIX_IPC + + return QFile::remove(fileName); +#endif // Q_OS_WIN } /*! diff --git a/tests/auto/corelib/kernel/qsignalblocker/tst_qsignalblocker.cpp b/tests/auto/corelib/kernel/qsignalblocker/tst_qsignalblocker.cpp index 461537d9f4..9a2dfb451b 100644 --- a/tests/auto/corelib/kernel/qsignalblocker/tst_qsignalblocker.cpp +++ b/tests/auto/corelib/kernel/qsignalblocker/tst_qsignalblocker.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@woboq.com> -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp b/tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp index 4316c4bebf..579aa78ac4 100644 --- a/tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp +++ b/tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp index 561f5673f1..930a17c3a9 100644 --- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp +++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qsystemsemaphore/systemsemaphorehelper/main.cpp b/tests/auto/corelib/kernel/qsystemsemaphore/systemsemaphorehelper/main.cpp index 8796cf3e19..e7e92e55ac 100644 --- a/tests/auto/corelib/kernel/qsystemsemaphore/systemsemaphorehelper/main.cpp +++ b/tests/auto/corelib/kernel/qsystemsemaphore/systemsemaphorehelper/main.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp b/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp index 8195efed99..b2198e9267 100644 --- a/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp +++ b/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -65,7 +65,7 @@ private slots: void processes_data(); void processes(); -#ifndef Q_OS_WIN +#if !defined(Q_OS_WIN) && !defined(QT_POSIX_IPC) void undo(); #endif void initialValue(); @@ -233,8 +233,8 @@ void tst_QSystemSemaphore::processes() } } -// This test only checks a unix behavior. -#ifndef Q_OS_WIN +// This test only checks a system v unix behavior. +#if !defined(Q_OS_WIN) && !defined(QT_POSIX_IPC) void tst_QSystemSemaphore::undo() { QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 5833123dfe..c7011dbc04 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp index 077da6fce8..2707b6df41 100644 --- a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp +++ b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 41a6de214a..52fc4e1806 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com> +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +11,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -43,9 +44,10 @@ #include <qlocale.h> #include <qdebug.h> #include <qjsondocument.h> - +#include <quuid.h> #include <limits.h> +#include <float.h> #include <QLinkedList> #include <QRegularExpression> @@ -57,6 +59,12 @@ class CustomNonQObject; +#if defined(Q_COMPILER_CLASS_ENUM) +#define ENUM_SIZE(X) : X +#else +#define ENUM_SIZE(X) +#endif + class tst_QVariant : public QObject { Q_OBJECT @@ -68,6 +76,23 @@ public: } + + enum MetaEnumTest_Enum0 { MetaEnumTest_Enum0_value = 42, MetaEnsureSignedEnum0 = -1 }; + Q_ENUM(MetaEnumTest_Enum0) + enum MetaEnumTest_Enum1 { MetaEnumTest_Enum1_value = 42, MetaEnumTest_Enum1_bigValue = (Q_INT64_C(1) << 33) + 50 }; + Q_ENUM(MetaEnumTest_Enum1) + + enum MetaEnumTest_Enum3 ENUM_SIZE(qint64) { MetaEnumTest_Enum3_value = -47, MetaEnumTest_Enum3_bigValue = (Q_INT64_C(1) << 56) + 5 }; + Q_ENUM(MetaEnumTest_Enum3) + enum MetaEnumTest_Enum4 ENUM_SIZE(quint64) { MetaEnumTest_Enum4_value = 47, MetaEnumTest_Enum4_bigValue = (Q_INT64_C(1) << 52) + 45 }; + Q_ENUM(MetaEnumTest_Enum4) + enum MetaEnumTest_Enum5 ENUM_SIZE(uint) { MetaEnumTest_Enum5_value = 47 }; + Q_ENUM(MetaEnumTest_Enum5) + enum MetaEnumTest_Enum6 ENUM_SIZE(uchar) { MetaEnumTest_Enum6_value = 47 }; + Q_ENUM(MetaEnumTest_Enum6) + enum MetaEnumTest_Enum8 ENUM_SIZE(short) { MetaEnumTest_Enum8_value = 47 }; + Q_ENUM(MetaEnumTest_Enum8) + private slots: void cleanupTestCase(); @@ -169,8 +194,9 @@ private slots: void operator_eq_eq_data(); void operator_eq_eq(); - void operator_eq_eq_rhs(); + void compareNumbers_data() const; + void compareNumbers() const; void typeName_data(); void typeName(); @@ -213,7 +239,10 @@ private slots: void toIntFromQString() const; void toIntFromDouble() const; void setValue(); + void fpStringRoundtrip_data() const; + void fpStringRoundtrip() const; + void numericalConvert_data(); void numericalConvert(); void moreCustomTypes(); void movabilityTest(); @@ -244,7 +273,7 @@ private slots: void pairElements(); void enums(); - + void metaEnums(); void compareSanity_data(); void compareSanity(); @@ -465,7 +494,13 @@ void tst_QVariant::canConvert_data() << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; var = QVariant::fromValue<QJsonValue>(QJsonValue(QStringLiteral("hello"))); QTest::newRow("JsonValue") - << var << N << N << Y << N << N << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; + << var << N << N << Y << N << N << N << N << N << N << Y << N << N << Y << N << N << Y << Y << Y << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; + var = QVariant::fromValue<QJsonArray>(QJsonArray()); + QTest::newRow("JsonArray") + << var << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << Y << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N; + var = QVariant::fromValue<QJsonObject>(QJsonObject()); + QTest::newRow("JsonObject") + << var << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << Y << N << N << N << N << N << N << N << N << N << N << N << N << N; #undef N #undef Y @@ -521,7 +556,8 @@ void tst_QVariant::toInt_data() bytearray[2] = '0'; bytearray[3] = '0'; QTest::newRow( "QByteArray2" ) << QVariant( bytearray ) << 4500 << true; - QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << 321 << true; + QTest::newRow("int-QJsonValue") << QVariant(QJsonValue(321)) << 321 << true; + QTest::newRow("undefined-QJsonValue") << QVariant(QJsonValue(QJsonValue::Undefined)) << 0 << false; } void tst_QVariant::toInt() @@ -568,7 +604,8 @@ void tst_QVariant::toUInt_data() bytearray[2] = '2'; bytearray[3] = '1'; QTest::newRow( "QByteArray" ) << QVariant( bytearray ) << (uint)4321 << true; - QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << (uint)321 << true; + QTest::newRow("int-QJsonValue") << QVariant(QJsonValue(321)) << (uint)321 << true; + QTest::newRow("null-QJsonValue") << QVariant(QJsonValue(QJsonValue::Null)) << (uint)0 << false; } void tst_QVariant::toUInt() @@ -819,7 +856,8 @@ void tst_QVariant::toDouble_data() bytearray[2] = '.'; bytearray[3] = '1'; QTest::newRow( "bytearray" ) << QVariant( bytearray ) << 32.1 << true; - QTest::newRow("QJsonValue") << QVariant(QJsonValue(32.1)) << 32.1 << true; + QTest::newRow("double-QJsonValue") << QVariant(QJsonValue(32.1)) << 32.1 << true; + QTest::newRow("null-QJsonValue") << QVariant(QJsonValue(QJsonValue::Null)) << 0.0 << false; } void tst_QVariant::toDouble() @@ -847,7 +885,8 @@ void tst_QVariant::toFloat_data() bytearray[2] = '.'; bytearray[3] = '1'; QTest::newRow("QByteArray") << QVariant(bytearray) << float(32.1) << true; - QTest::newRow("QJsonValue") << QVariant(QJsonValue(32.1)) << float(32.1) << true; + QTest::newRow("double-QJsonValue") << QVariant(QJsonValue(32.1)) << float(32.1) << true; + QTest::newRow("undefined-QJsonValue") << QVariant(QJsonValue(QJsonValue::Undefined)) << float(0.0) << false; } void tst_QVariant::toFloat() @@ -886,7 +925,8 @@ void tst_QVariant::toLongLong_data() bytearray[2] = '0'; bytearray[3] = '0'; QTest::newRow( "QByteArray" ) << QVariant( bytearray ) << (qlonglong) 3200 << true; - QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << (qlonglong)321 << true; + QTest::newRow("int-QJsonValue") << QVariant(QJsonValue(321)) << (qlonglong)321 << true; + QTest::newRow("string-QJsonValue") << QVariant(QJsonValue(QString("string"))) << (qlonglong)0 << false; qint64 value64 = (Q_INT64_C(12) << 35) + 8; QTest::newRow("qint64") << QVariant::fromValue(value64) << qlonglong(value64) << true; @@ -942,7 +982,8 @@ void tst_QVariant::toULongLong_data() bytearray[2] = '0'; bytearray[3] = '1'; QTest::newRow( "QByteArray" ) << QVariant( bytearray ) << (qulonglong) 3201 << true; - QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << (qulonglong)321 << true; + QTest::newRow("int-QJsonValue") << QVariant(QJsonValue(321)) << (qulonglong)321 << true; + QTest::newRow("bool-QJsonValue") << QVariant(QJsonValue(true)) << (qulonglong)0 << false; quint64 value64 = (Q_INT64_C(12) << 35) + 8; QTest::newRow("qint64") << QVariant::fromValue(value64) << qulonglong(value64) << true; @@ -985,7 +1026,7 @@ void tst_QVariant::toByteArray_data() QTest::newRow( "int" ) << QVariant( -123 ) << QByteArray( "-123" ); QTest::newRow( "uint" ) << QVariant( (uint)123 ) << QByteArray( "123" ); QTest::newRow( "double" ) << QVariant( 123.456 ) << QByteArray( "123.456" ); - QTest::newRow( "float" ) << QVariant( 123.456f ) << QByteArray( "123.456" ); + QTest::newRow( "float" ) << QVariant( 123.456f ) << QByteArray( "123.456001" ); QTest::newRow( "longlong" ) << QVariant( (qlonglong)34 ) << QByteArray( "34" ); QTest::newRow( "ulonglong" ) << QVariant( (qulonglong)34 ) << QByteArray( "34" ); } @@ -1011,7 +1052,7 @@ void tst_QVariant::toString_data() QTest::newRow( "int" ) << QVariant( -123 ) << QString( "-123" ); QTest::newRow( "uint" ) << QVariant( (uint)123 ) << QString( "123" ); QTest::newRow( "double" ) << QVariant( 123.456 ) << QString( "123.456" ); - QTest::newRow( "float" ) << QVariant( 123.456f ) << QString( "123.456" ); + QTest::newRow( "float" ) << QVariant( 123.456f ) << QString( "123.456001" ); QTest::newRow( "bool" ) << QVariant( true ) << QString( "true" ); QTest::newRow( "qdate" ) << QVariant( QDate( 2002, 1, 1 ) ) << QString( "2002-01-01" ); QTest::newRow( "qtime" ) << QVariant( QTime( 12, 34, 56 ) ) << QString( "12:34:56" ); @@ -1019,6 +1060,7 @@ void tst_QVariant::toString_data() QTest::newRow( "llong" ) << QVariant( (qlonglong)Q_INT64_C(123456789012) ) << QString( "123456789012" ); QTest::newRow("QJsonValue") << QVariant(QJsonValue(QString("hello"))) << QString("hello"); + QTest::newRow("QJsonValue(Null)") << QVariant(QJsonValue(QJsonValue::Null)) << QString(); } void tst_QVariant::toString() @@ -1367,12 +1409,12 @@ void tst_QVariant::operator_eq_eq_data() QVariant mUIntQString(QString("42")); QVariant mDouble(42.11); - QVariant mDoubleString(QByteArray("42.11")); - QVariant mDoubleQString(QString("42.11")); + QVariant mDoubleString(QByteArray("42.109999999999999")); + QVariant mDoubleQString(QString("42.109999999999999")); QVariant mFloat(42.11f); - QVariant mFloatString(QByteArray("42.11")); - QVariant mFloatQString(QString("42.11")); + QVariant mFloatString(QByteArray("42.1100006")); + QVariant mFloatQString(QString("42.1100006")); QVariant mLongLong((qlonglong)-42); QVariant mLongLongString(QByteArray("-42")); @@ -1433,6 +1475,13 @@ void tst_QVariant::operator_eq_eq_data() // ### many other combinations missing { + // QUuid can convert to QString, but not the opposite + QUuid uuid(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + QTest::newRow("uuidstring") << QVariant(uuid) << QVariant(uuid.toString()) << true; + QTest::newRow("stringuuid") << QVariant(uuid.toString()) << QVariant(uuid) << true; + } + + { QMap<QString, QVariant> map1; map1.insert( "X", 1 ); @@ -1580,6 +1629,326 @@ void tst_QVariant::operator_eq_eq_rhs() #endif } +void tst_QVariant::compareNumbers_data() const +{ + typedef signed char schar; + QTest::addColumn<QVariant>("v1"); + QTest::addColumn<QVariant>("v2"); + QTest::addColumn<int>("expected"); + + // sanity checking: same types + QTest::newRow("bool1") << QVariant(false) << QVariant(false) << 0; + QTest::newRow("bool2") << QVariant(true) << QVariant(true) << 0; + QTest::newRow("bool3") << QVariant(false) << QVariant(true) << -1; + QTest::newRow("bool4") << QVariant(true) << QVariant(false) << +1; + + QTest::newRow("char1") << qVariantFromValue(char(0)) << qVariantFromValue(char(0)) << 0; + QTest::newRow("char2") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(CHAR_MAX) << 0; + QTest::newRow("char3") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(CHAR_MIN) << 0; + QTest::newRow("char4") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(CHAR_MAX) << -1; + QTest::newRow("char5") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(CHAR_MIN) << +1; + + QTest::newRow("schar1") << qVariantFromValue(schar(0)) << qVariantFromValue(schar(0)) << 0; + QTest::newRow("schar2") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(SCHAR_MAX) << 0; + QTest::newRow("schar3") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(SCHAR_MIN) << 0; + QTest::newRow("schar4") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(SCHAR_MAX) << -1; + QTest::newRow("schar5") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(SCHAR_MIN) << +1; + + QTest::newRow("uchar1") << qVariantFromValue(uchar(0)) << qVariantFromValue(uchar(0)) << 0; + QTest::newRow("uchar2") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(UCHAR_MAX) << 0; + QTest::newRow("uchar3") << qVariantFromValue(uchar(0)) << qVariantFromValue(UCHAR_MAX) << -1; + QTest::newRow("uchar4") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(uchar(0)) << +1; + + QTest::newRow("short1") << qVariantFromValue(short(0)) << qVariantFromValue(short(0)) << 0; + QTest::newRow("short2") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(SHRT_MAX) << 0; + QTest::newRow("short3") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(SHRT_MIN) << 0; + QTest::newRow("short4") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(SHRT_MAX) << -1; + QTest::newRow("short5") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(SHRT_MIN) << +1; + + QTest::newRow("ushort1") << qVariantFromValue(ushort(0)) << qVariantFromValue(ushort(0)) << 0; + QTest::newRow("ushort2") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(USHRT_MAX) << 0; + QTest::newRow("ushort3") << qVariantFromValue(ushort(0)) << qVariantFromValue(USHRT_MAX) << -1; + QTest::newRow("ushort4") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(ushort(0)) << +1; + + QTest::newRow("int1") << qVariantFromValue(int(0)) << qVariantFromValue(int(0)) << 0; + QTest::newRow("int2") << qVariantFromValue(INT_MAX) << qVariantFromValue(INT_MAX) << 0; + QTest::newRow("int3") << qVariantFromValue(INT_MIN) << qVariantFromValue(INT_MIN) << 0; + QTest::newRow("int4") << qVariantFromValue(INT_MIN) << qVariantFromValue(INT_MAX) << -1; + QTest::newRow("int5") << qVariantFromValue(INT_MAX) << qVariantFromValue(INT_MIN) << +1; + + QTest::newRow("uint1") << qVariantFromValue(uint(0)) << qVariantFromValue(uint(0)) << 0; + QTest::newRow("uint2") << qVariantFromValue(UINT_MAX) << qVariantFromValue(UINT_MAX) << 0; + QTest::newRow("uint3") << qVariantFromValue(uint(0)) << qVariantFromValue(UINT_MAX) << -1; + QTest::newRow("uint4") << qVariantFromValue(UINT_MAX) << qVariantFromValue(uint(0)) << +1; + + QTest::newRow("long1") << qVariantFromValue(long(0)) << qVariantFromValue(long(0)) << 0; + QTest::newRow("long2") << qVariantFromValue(LONG_MAX) << qVariantFromValue(LONG_MAX) << 0; + QTest::newRow("long3") << qVariantFromValue(LONG_MIN) << qVariantFromValue(LONG_MIN) << 0; + QTest::newRow("long4") << qVariantFromValue(LONG_MIN) << qVariantFromValue(LONG_MAX) << -1; + QTest::newRow("long5") << qVariantFromValue(LONG_MAX) << qVariantFromValue(LONG_MIN) << +1; + + QTest::newRow("ulong1") << qVariantFromValue(ulong(0)) << qVariantFromValue(ulong(0)) << 0; + QTest::newRow("ulong2") << qVariantFromValue(ULONG_MAX) << qVariantFromValue(ULONG_MAX) << 0; + QTest::newRow("ulong3") << qVariantFromValue(ulong(0)) << qVariantFromValue(ULONG_MAX) << -1; + QTest::newRow("ulong4") << qVariantFromValue(ULONG_MAX) << qVariantFromValue(ulong(0)) << +1; + + QTest::newRow("llong1") << qVariantFromValue(qlonglong(0)) << qVariantFromValue(qlonglong(0)) << 0; + QTest::newRow("llong2") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(LLONG_MAX) << 0; + QTest::newRow("llong3") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(LLONG_MIN) << 0; + QTest::newRow("llong4") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(LLONG_MAX) << -1; + QTest::newRow("llong5") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(LLONG_MIN) << +1; + + QTest::newRow("ullong1") << qVariantFromValue(qulonglong(0)) << qVariantFromValue(qulonglong(0)) << 0; + QTest::newRow("ullong2") << qVariantFromValue(ULLONG_MAX) << qVariantFromValue(ULLONG_MAX) << 0; + QTest::newRow("ullong3") << qVariantFromValue(qulonglong(0)) << qVariantFromValue(ULLONG_MAX) << -1; + QTest::newRow("ullong4") << qVariantFromValue(ULLONG_MAX) << qVariantFromValue(qulonglong(0)) << +1; + + QTest::newRow("float1") << qVariantFromValue(0.f) << qVariantFromValue(0.f) << 0; + QTest::newRow("float2") << qVariantFromValue(-1.f) << qVariantFromValue(0.f) << -1; + QTest::newRow("float3") << qVariantFromValue(0.f) << qVariantFromValue(-1.f) << +1; + QTest::newRow("float4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.f) << -1; + QTest::newRow("float5") << qVariantFromValue(0.f) << qVariantFromValue(-float(qInf())) << +1; + + QTest::newRow("double1") << qVariantFromValue(0.) << qVariantFromValue(0.) << 0; + QTest::newRow("double2") << qVariantFromValue(-1.) << qVariantFromValue(0.) << -1; + QTest::newRow("double3") << qVariantFromValue(0.) << qVariantFromValue(-1.) << +1; + QTest::newRow("double4") << qVariantFromValue(-qInf()) << qVariantFromValue(0.) << -1; + QTest::newRow("double5") << qVariantFromValue(0.) << qVariantFromValue(-qInf()) << +1; + + // mixed comparisons + // fp + fp + QTest::newRow("float+double1") << qVariantFromValue(0.f) << qVariantFromValue(0.) << 0; + QTest::newRow("float+double2") << qVariantFromValue(-1.f) << qVariantFromValue(0.) << -1; + QTest::newRow("float+double3") << qVariantFromValue(0.f) << qVariantFromValue(-1.) << +1; + QTest::newRow("float+double4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.) << -1; + QTest::newRow("float+double5") << qVariantFromValue(0.f) << qVariantFromValue(-qInf()) << +1; + + // fp + int + QTest::newRow("float+int1") << qVariantFromValue(0.f) << qVariantFromValue(0) << 0; + QTest::newRow("double+int1") << qVariantFromValue(0.) << qVariantFromValue(0) << 0; + QTest::newRow("float+int2") << qVariantFromValue(-1.f) << qVariantFromValue(0) << -1; + QTest::newRow("double+int2") << qVariantFromValue(-1.) << qVariantFromValue(0) << -1; + QTest::newRow("float+int3") << qVariantFromValue(0.f) << qVariantFromValue(-1) << +1; + QTest::newRow("double+int3") << qVariantFromValue(0.) << qVariantFromValue(-1) << +1; + QTest::newRow("float+int4") << qVariantFromValue(1.5f) << qVariantFromValue(1) << +1; + QTest::newRow("double+int4") << qVariantFromValue(1.5) << qVariantFromValue(1) << +1; + + // fp + uint + QTest::newRow("float+uint1") << qVariantFromValue(0.f) << qVariantFromValue(0U) << 0; + QTest::newRow("double+uint1") << qVariantFromValue(0.) << qVariantFromValue(0U) << 0; + QTest::newRow("float+uint2") << qVariantFromValue(-1.f) << qVariantFromValue(0U) << -1; + QTest::newRow("double+uint2") << qVariantFromValue(-1.) << qVariantFromValue(0U) << -1; + QTest::newRow("float+uint3") << qVariantFromValue(0.f) << qVariantFromValue(1U) << -1; + QTest::newRow("double+uint3") << qVariantFromValue(0.) << qVariantFromValue(1U) << -1; + QTest::newRow("float+uint4") << qVariantFromValue(1.5f) << qVariantFromValue(1U) << +1; + QTest::newRow("double+uint4") << qVariantFromValue(1.5) << qVariantFromValue(1U) << +1; + + // lower ranked + int + QTest::newRow("bool+int1") << qVariantFromValue(false) << qVariantFromValue(0) << 0; + QTest::newRow("bool+int2") << qVariantFromValue(false) << qVariantFromValue(1) << -1; + QTest::newRow("bool+int3") << qVariantFromValue(true) << qVariantFromValue(0) << +1; + QTest::newRow("bool+int4") << qVariantFromValue(true) << qVariantFromValue(1) << 0; + QTest::newRow("bool+int5") << qVariantFromValue(true) << qVariantFromValue(2) << -1; + + QTest::newRow("char+int1") << qVariantFromValue(char(0)) << qVariantFromValue(0) << 0; + QTest::newRow("char+int2") << qVariantFromValue(char(0)) << qVariantFromValue(1) << -1; + QTest::newRow("char+int3") << qVariantFromValue(char(1)) << qVariantFromValue(0) << +1; + QTest::newRow("char+int4") << qVariantFromValue(char(1)) << qVariantFromValue(1) << 0; + if (std::numeric_limits<char>::is_signed) { + QTest::newRow("char+int5") << qVariantFromValue(char(-1)) << qVariantFromValue(0) << -1; + QTest::newRow("char+int6") << qVariantFromValue(char(-1)) << qVariantFromValue(-1) << 0; + } + + QTest::newRow("schar+int1") << qVariantFromValue(schar(0)) << qVariantFromValue(0) << 0; + QTest::newRow("schar+int2") << qVariantFromValue(schar(0)) << qVariantFromValue(1) << -1; + QTest::newRow("schar+int3") << qVariantFromValue(schar(1)) << qVariantFromValue(0) << +1; + QTest::newRow("schar+int4") << qVariantFromValue(schar(1)) << qVariantFromValue(1) << 0; + QTest::newRow("schar+int5") << qVariantFromValue(schar(-1)) << qVariantFromValue(0) << -1; + QTest::newRow("schar+int6") << qVariantFromValue(schar(-1)) << qVariantFromValue(-1) << 0; + + QTest::newRow("uchar+int1") << qVariantFromValue(uchar(0)) << qVariantFromValue(0) << 0; + QTest::newRow("uchar+int2") << qVariantFromValue(uchar(0)) << qVariantFromValue(1) << -1; + QTest::newRow("uchar+int3") << qVariantFromValue(uchar(1)) << qVariantFromValue(0) << +1; + QTest::newRow("uchar+int4") << qVariantFromValue(uchar(1)) << qVariantFromValue(1) << 0; + + QTest::newRow("short+int1") << qVariantFromValue(short(0)) << qVariantFromValue(0) << 0; + QTest::newRow("short+int2") << qVariantFromValue(short(0)) << qVariantFromValue(1) << -1; + QTest::newRow("short+int3") << qVariantFromValue(short(1)) << qVariantFromValue(0) << +1; + QTest::newRow("short+int4") << qVariantFromValue(short(1)) << qVariantFromValue(1) << 0; + QTest::newRow("short+int5") << qVariantFromValue(short(-1)) << qVariantFromValue(0) << -1; + QTest::newRow("short+int6") << qVariantFromValue(short(-1)) << qVariantFromValue(-1) << 0; + + QTest::newRow("ushort+int1") << qVariantFromValue(ushort(0)) << qVariantFromValue(0) << 0; + QTest::newRow("ushort+int2") << qVariantFromValue(ushort(0)) << qVariantFromValue(1) << -1; + QTest::newRow("ushort+int3") << qVariantFromValue(ushort(1)) << qVariantFromValue(0) << +1; + QTest::newRow("ushort+int4") << qVariantFromValue(ushort(1)) << qVariantFromValue(1) << 0; + + // lower ranked + uint (without sign change) + QTest::newRow("bool+uint1") << qVariantFromValue(false) << qVariantFromValue(0U) << 0; + QTest::newRow("bool+uint2") << qVariantFromValue(false) << qVariantFromValue(1U) << -1; + QTest::newRow("bool+uint3") << qVariantFromValue(true) << qVariantFromValue(0U) << +1; + QTest::newRow("bool+uint4") << qVariantFromValue(true) << qVariantFromValue(1U) << 0; + QTest::newRow("bool+uint5") << qVariantFromValue(true) << qVariantFromValue(2U) << -1; + + QTest::newRow("char+uint1") << qVariantFromValue(char(0)) << qVariantFromValue(0U) << 0; + QTest::newRow("char+uint2") << qVariantFromValue(char(0)) << qVariantFromValue(1U) << -1; + QTest::newRow("char+uint3") << qVariantFromValue(char(1)) << qVariantFromValue(0U) << +1; + QTest::newRow("char+uint4") << qVariantFromValue(char(1)) << qVariantFromValue(1U) << 0; + + QTest::newRow("schar+uint1") << qVariantFromValue(schar(0)) << qVariantFromValue(0U) << 0; + QTest::newRow("schar+uint2") << qVariantFromValue(schar(0)) << qVariantFromValue(1U) << -1; + QTest::newRow("schar+uint3") << qVariantFromValue(schar(1)) << qVariantFromValue(0U) << +1; + QTest::newRow("schar+uint4") << qVariantFromValue(schar(1)) << qVariantFromValue(1U) << 0; + + QTest::newRow("uchar+uint1") << qVariantFromValue(uchar(0)) << qVariantFromValue(0U) << 0; + QTest::newRow("uchar+uint2") << qVariantFromValue(uchar(0)) << qVariantFromValue(1U) << -1; + QTest::newRow("uchar+uint3") << qVariantFromValue(uchar(1)) << qVariantFromValue(0U) << +1; + QTest::newRow("uchar+uint4") << qVariantFromValue(uchar(1)) << qVariantFromValue(1U) << 0; + + QTest::newRow("short+uint1") << qVariantFromValue(short(0)) << qVariantFromValue(0U) << 0; + QTest::newRow("short+uint2") << qVariantFromValue(short(0)) << qVariantFromValue(1U) << -1; + QTest::newRow("short+uint3") << qVariantFromValue(short(1)) << qVariantFromValue(0U) << +1; + QTest::newRow("short+uint4") << qVariantFromValue(short(1)) << qVariantFromValue(1U) << 0; + + QTest::newRow("ushort+uint1") << qVariantFromValue(ushort(0)) << qVariantFromValue(0U) << 0; + QTest::newRow("ushort+uint2") << qVariantFromValue(ushort(0)) << qVariantFromValue(1U) << -1; + QTest::newRow("ushort+uint3") << qVariantFromValue(ushort(1)) << qVariantFromValue(0U) << +1; + QTest::newRow("ushort+uint4") << qVariantFromValue(ushort(1)) << qVariantFromValue(1U) << 0; + + // int + qlonglong + QTest::newRow("int+qlonglong1") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(0)) << 0; + QTest::newRow("int+qlonglong2") << qVariantFromValue(1) << qVariantFromValue(Q_INT64_C(0)) << +1; + QTest::newRow("int+qlonglong3") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(1)) << -1; + QTest::newRow("int+qlonglong4") << qVariantFromValue(1) << qVariantFromValue(Q_INT64_C(1)) << 0; + QTest::newRow("int+qlonglong5") << qVariantFromValue(0) << qVariantFromValue(Q_INT64_C(-1)) << +1; + QTest::newRow("int+qlonglong6") << qVariantFromValue(-1) << qVariantFromValue(Q_INT64_C(0)) << -1; + QTest::newRow("int+qlonglong7") << qVariantFromValue(-1) << qVariantFromValue(Q_INT64_C(-1)) << 0; + + // uint + qulonglong + QTest::newRow("uint+qulonglong1") << qVariantFromValue(0U) << qVariantFromValue(Q_UINT64_C(0)) << 0; + QTest::newRow("uint+qulonglong2") << qVariantFromValue(1U) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("uint+qulonglong3") << qVariantFromValue(0U) << qVariantFromValue(Q_UINT64_C(1)) << -1; + QTest::newRow("uint+qulonglong4") << qVariantFromValue(1U) << qVariantFromValue(Q_UINT64_C(1)) << 0; + + // int + uint (without sign change) + QTest::newRow("int+uint1") << qVariantFromValue(0) << qVariantFromValue(0U) << 0; + QTest::newRow("int+uint2") << qVariantFromValue(1) << qVariantFromValue(0U) << +1; + QTest::newRow("int+uint3") << qVariantFromValue(0) << qVariantFromValue(1U) << -1; + QTest::newRow("int+uint4") << qVariantFromValue(1) << qVariantFromValue(1U) << 0; + + // uint + qlonglong + QTest::newRow("uint+qlonglong1") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(0)) << 0; + QTest::newRow("uint+qlonglong2") << qVariantFromValue(1U) << qVariantFromValue(Q_INT64_C(0)) << +1; + QTest::newRow("uint+qlonglong3") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(1)) << -1; + QTest::newRow("uint+qlonglong4") << qVariantFromValue(1U) << qVariantFromValue(Q_INT64_C(1)) << 0; + QTest::newRow("uint+qlonglong5") << qVariantFromValue(0U) << qVariantFromValue(Q_INT64_C(-1)) << +1; + + // boundary conditions + QTest::newRow("charmax+intmax") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(INT_MAX) << -1; + QTest::newRow("charmax+uintmax") << qVariantFromValue(CHAR_MAX) << qVariantFromValue(UINT_MAX) << -1; + QTest::newRow("scharmax+intmax") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(INT_MAX) << -1; + QTest::newRow("scharmax+uintmax") << qVariantFromValue(SCHAR_MAX) << qVariantFromValue(UINT_MAX) << -1; + QTest::newRow("ucharmax+intmax") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(INT_MAX) << -1; + QTest::newRow("ucharmax+uintmax") << qVariantFromValue(UCHAR_MAX) << qVariantFromValue(UINT_MAX) << -1; + QTest::newRow("shortmax+intmax") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(INT_MAX) << -1; + QTest::newRow("shortmax+uintmax") << qVariantFromValue(SHRT_MAX) << qVariantFromValue(UINT_MAX) << -1; + QTest::newRow("ushortmax+intmax") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(INT_MAX) << -1; + QTest::newRow("ushortmax+uintmax") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(UINT_MAX) << -1; + + QTest::newRow("intmin+qlonglongmin") << qVariantFromValue(INT_MIN) << qVariantFromValue(LLONG_MIN) << +1; + QTest::newRow("intmax+uintmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(UINT_MAX) << -1; + QTest::newRow("intmax+qlonglongmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(LLONG_MAX) << -1; + QTest::newRow("uintmax+qlonglongmax") << qVariantFromValue(UINT_MAX) << qVariantFromValue(LLONG_MAX) << -1; + QTest::newRow("intmax+qulonglongmax") << qVariantFromValue(INT_MAX) << qVariantFromValue(ULLONG_MAX) << -1; + QTest::newRow("qlonglongmax+qulonglongmax") << qVariantFromValue(LLONG_MAX) << qVariantFromValue(ULLONG_MAX) << -1; + QTest::newRow("uintmax+qlonglongmin") << qVariantFromValue(UINT_MAX) << qVariantFromValue(LLONG_MIN) << +1; + + // check for no sign-extension issues + QTest::newRow("ushortmax+intzero") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(0) << +1; + QTest::newRow("ushortmax+qlonglongzero") << qVariantFromValue(USHRT_MAX) << qVariantFromValue(Q_INT64_C(0)) << +1; + QTest::newRow("uintmax+qlonglongzero") << qVariantFromValue(UINT_MAX) << qVariantFromValue(Q_INT64_C(0)) << +1; + + // sign changes + // the tests below check that a signed negative number sign-changes to a non-zero unsigned number and that + // signed -1 sign-changes to unsigned maximum (all bits set, ~0). This works on two's complement machines + // (all that Qt supports), and would also work on one's complement. + if (std::numeric_limits<char>::is_signed) { + QTest::newRow("signchange-char+uint") << qVariantFromValue(char(-1)) << qVariantFromValue(0U) << +1; + QTest::newRow("signchange-char+uintmax") << qVariantFromValue(char(-1)) << qVariantFromValue(UINT_MAX) << 0; + QTest::newRow("signchange-charmin+uint") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(0U) << +1; + QTest::newRow("signchange-char+qulonglong") << qVariantFromValue(char(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-char+qulonglongmax") << qVariantFromValue(char(-1)) << qVariantFromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-charmin+qulonglong") << qVariantFromValue(CHAR_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; + } + QTest::newRow("signchange-schar+uint") << qVariantFromValue(schar(-1)) << qVariantFromValue(0U) << +1; + QTest::newRow("signchange-schar+uintmax") << qVariantFromValue(schar(-1)) << qVariantFromValue(UINT_MAX) << 0; + QTest::newRow("signchange-scharmin+uint") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(0U) << +1; + QTest::newRow("signchange-schar+qulonglong") << qVariantFromValue(schar(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-schar+qulonglongmax") << qVariantFromValue(schar(-1)) << qVariantFromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-scharmin+qulonglong") << qVariantFromValue(SCHAR_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-short+uint") << qVariantFromValue(short(-1)) << qVariantFromValue(0U) << +1; + QTest::newRow("signchange-short+uintmax") << qVariantFromValue(short(-1)) << qVariantFromValue(UINT_MAX) << 0; + QTest::newRow("signchange-shortmin+uint") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(0U) << +1; + QTest::newRow("signchange-short+qulonglong") << qVariantFromValue(short(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-short+qulonglongmax") << qVariantFromValue(short(-1)) << qVariantFromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-shortmin+qulonglong") << qVariantFromValue(SHRT_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-int+uint") << qVariantFromValue(-1) << qVariantFromValue(0U) << +1; + QTest::newRow("signchange-int+uintmax") << qVariantFromValue(-1) << qVariantFromValue(UINT_MAX) << 0; + QTest::newRow("signchange-intmin+uint") << qVariantFromValue(INT_MIN) << qVariantFromValue(0U) << +1; + QTest::newRow("signchange-int+qulonglong") << qVariantFromValue(-1) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-int+qulonglongmax") << qVariantFromValue(-1) << qVariantFromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-intmin+qulonglong") << qVariantFromValue(INT_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; + // no qlonglong+uint, since that should promote to qlonglong and then the comparison is signed (tested above) + QTest::newRow("signchange-qlonglong+qulonglong") << qVariantFromValue(Q_INT64_C(-1)) << qVariantFromValue(Q_UINT64_C(0)) << +1; + QTest::newRow("signchange-qlonglong+qulonglongmax") << qVariantFromValue(Q_INT64_C(-1)) << qVariantFromValue(ULLONG_MAX) << 0; + QTest::newRow("signchange-qlonglongmin+qulonglong") << qVariantFromValue(LLONG_MIN) << qVariantFromValue(Q_UINT64_C(0)) << +1; +} + +void tst_QVariant::compareNumbers() const +{ + QFETCH(QVariant, v1); + QFETCH(QVariant, v2); + QFETCH(int, expected); + + if (expected == -1) { + QVERIFY(v1 < v2); + QVERIFY(v1 <= v2); + QVERIFY(!(v1 == v2)); + QVERIFY(!(v1 > v2)); + QVERIFY(!(v1 >= v2)); + + QVERIFY(!(v2 < v1)); + QVERIFY(!(v2 <= v1)); + QVERIFY(!(v2 == v1)); + QVERIFY(v2 >= v1); + QVERIFY(v2 > v1); + } else if (expected == 0) { + QVERIFY(!(v1 < v2)); + QVERIFY(v1 <= v2); + QCOMPARE(v1, v2); + QVERIFY(!(v1 > v2)); + QVERIFY(v1 >= v2); + + QVERIFY(!(v2 < v1)); + QVERIFY(v2 <= v1); + QCOMPARE(v2, v1); + QVERIFY(v2 >= v1); + QVERIFY(!(v2 > v1)); + } else { + QVERIFY(!(v1 < v2)); + QVERIFY(!(v1 <= v2)); + QVERIFY(!(v1 == v2)); + QVERIFY(v1 > v2); + QVERIFY(v1 >= v2); + + QVERIFY(v2 < v1); + QVERIFY(v2 <= v1); + QVERIFY(!(v2 == v1)); + QVERIFY(!(v2 >= v1)); + QVERIFY(!(v2 > v1)); + } +} + void tst_QVariant::typeName_data() { QTest::addColumn<int>("type"); @@ -2945,41 +3314,72 @@ void tst_QVariant::setValue() QVERIFY( v2.isDetached() ); } +void tst_QVariant::fpStringRoundtrip_data() const +{ + QTest::addColumn<QVariant>("number"); + + QTest::newRow("float") << QVariant(1 + FLT_EPSILON); + QTest::newRow("double") << QVariant(1 + DBL_EPSILON); +} + +void tst_QVariant::fpStringRoundtrip() const +{ + QFETCH(QVariant, number); + + QVariant converted = number; + QVERIFY(converted.convert(QVariant::String)); + QVERIFY(converted.convert(number.type())); + QCOMPARE(converted, number); + + converted = number; + QVERIFY(converted.convert(QVariant::ByteArray)); + QVERIFY(converted.convert(number.type())); + QCOMPARE(converted, number); +} + +void tst_QVariant::numericalConvert_data() +{ + QTest::addColumn<QVariant>("v"); + QTest::addColumn<bool>("isInteger"); + QTest::newRow("float") << QVariant(float(5.3)) << false; + QTest::newRow("double") << QVariant(double(5.3)) << false; + QTest::newRow("qreal") << QVariant(qreal(5.3)) << false; + QTest::newRow("int") << QVariant(int(5)) << true; + QTest::newRow("uint") << QVariant(uint(5)) << true; + QTest::newRow("short") << QVariant(short(5)) << true; + QTest::newRow("longlong") << QVariant(quint64(5)) << true; + QTest::newRow("long") << QVariant::fromValue(long(5)) << true; + QTest::newRow("stringint") << QVariant(QString::fromLatin1("5")) << true; + QTest::newRow("string") << QVariant(QString::fromLatin1("5.30000019")) << false; +} + void tst_QVariant::numericalConvert() { #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__) QSKIP("Known to fail due to a GCC bug on at least Ubuntu 10.04 32-bit - check QTBUG-8959"); #endif - QVariant vfloat(float(5.3)); - QVariant vdouble(double(5.3)); - QVariant vreal(qreal(5.3)); - QVariant vint(int(5)); - QVariant vuint(uint(5)); - QVariant vshort(short(5)); - QVariant vlonglong(quint64(5)); - QVariant vlong = QVariant::fromValue(long(5)); - QVariant vstringint(QString::fromLatin1("5")); - QVariant vstring(QString::fromLatin1("5.3")); - - QVector<QVariant *> vect; - vect << &vfloat << &vdouble << &vreal << &vint << &vuint << &vshort<< &vlonglong << &vlong << &vstringint << &vstring; - - for(int i = 0; i < vect.size(); i++) { - double num = 5.3; - if (i >= 3 && i <= 8) - num = 5; - QVariant *v = vect.at(i); - QCOMPARE(v->toFloat() , float(num)); - QCOMPARE(float(v->toReal()) , float(num)); - QCOMPARE(float(v->toDouble()) , float(num)); - if (i != 9) { - QCOMPARE(v->toInt() , int(num)); - QCOMPARE(v->toUInt() , uint(num)); - QCOMPARE(v->toULongLong() , quint64(num)); - QCOMPARE(v->value<ulong>() , ulong(num)); - QCOMPARE(v->value<ushort>() , ushort(num)); - } - QCOMPARE(v->toString() , QString::number(num)); + QFETCH(QVariant, v); + QFETCH(bool, isInteger); + double num = isInteger ? 5 : 5.3; + + QCOMPARE(v.toFloat() , float(num)); + QCOMPARE(float(v.toReal()) , float(num)); + QCOMPARE(float(v.toDouble()) , float(num)); + if (isInteger) { + QCOMPARE(v.toInt() , int(num)); + QCOMPARE(v.toUInt() , uint(num)); + QCOMPARE(v.toULongLong() , quint64(num)); + QCOMPARE(v.value<ulong>() , ulong(num)); + QCOMPARE(v.value<ushort>() , ushort(num)); + } + switch (v.userType()) + { + case QVariant::Double: + QCOMPARE(v.toString() , QString::number(num, 'g', DBL_MANT_DIG * log10(2.) + 2)); + break; + case QMetaType::Float: + QCOMPARE(v.toString() , QString::number(float(num), 'g', FLT_MANT_DIG * log10(2.) + 2)); + break; } } @@ -3214,8 +3614,8 @@ void tst_QVariant::moreCustomTypes() QCOMPARE(MyNotMovable::count, 0); { - PLAY_WITH_VARIANT(12.12, false, "12.12", 12.12, true); - PLAY_WITH_VARIANT(12.12f, false, "12.12", 12.12f, true); + PLAY_WITH_VARIANT(12.12, false, "12.119999999999999", 12.12, true); + PLAY_WITH_VARIANT(12.12f, false, "12.1199999", 12.12f, true); PLAY_WITH_VARIANT('a', false, "a", 'a', true); PLAY_WITH_VARIANT((unsigned char)('a'), false, "a", 'a', true); PLAY_WITH_VARIANT( quint8(12), false, "\xc", 12, true); @@ -4044,10 +4444,13 @@ void tst_QVariant::iterateContainerElements() QCOMPARE(varMap.value(QString::number(key)).value<MAPPED_TYPE>(), expected); \ QCOMPARE(varHash.value(QString::number(key)).value<MAPPED_TYPE>(), expected); \ QCOMPARE(actual, expected); \ + const QAssociativeIterable::const_iterator it = mappingIter.find(key); \ + QVERIFY(it != mappingIter.end()); \ + QCOMPARE(it.value().value<MAPPED_TYPE>(), expected); \ } \ QCOMPARE(numSeen, (int)std::distance(mapping.begin(), mapping.end())); \ QCOMPARE(containerIter, containerEnd); \ - \ + QVERIFY(mappingIter.find(10) == mappingIter.end()); \ } TEST_ASSOCIATIVE_ITERATION(QHash, int, bool) @@ -4112,7 +4515,7 @@ void tst_QVariant::pairElements() TEST_PAIR_ELEMENT_ACCESS(std::pair, int, QVariant, 44, 15) } -enum EnumTest_Enum0 { EnumTest_Enum0_value = 42, ensureSignedEnum0 = -1 }; +enum EnumTest_Enum0 { EnumTest_Enum0_value = 42, EnumTest_Enum0_negValue = -8 }; Q_DECLARE_METATYPE(EnumTest_Enum0) enum EnumTest_Enum1 { EnumTest_Enum1_value = 42, EnumTest_Enum1_bigValue = (Q_INT64_C(1) << 33) + 50 }; Q_DECLARE_METATYPE(EnumTest_Enum1) @@ -4154,6 +4557,11 @@ template<typename Enum> void testVariant(Enum value, bool *ok) QCOMPARE(var.value<short>(), static_cast<short>(value)); QCOMPARE(var.value<unsigned short>(), static_cast<unsigned short>(value)); QCOMPARE(var.value<qint64>(), static_cast<qint64>(value)); + if (sizeof(value) < 8 && static_cast<qint64>(value) < 0) { + QEXPECT_FAIL("", "The metatype system don't store the sign of enums", Continue); + // The value is stored internaly with 32 bit. When asked to convert it to 64 bit unsigned, + // we consider that the value was unsigned, so we don't extent the bit signs + } QCOMPARE(var.value<quint64>(), static_cast<quint64>(value)); QVariant var2 = var; @@ -4168,6 +4576,8 @@ void tst_QVariant::enums() bool ok = false; testVariant(EnumTest_Enum0_value, &ok); QVERIFY(ok); + testVariant(EnumTest_Enum0_negValue, &ok); + QVERIFY(ok); testVariant(EnumTest_Enum1_value, &ok); QVERIFY(ok); testVariant(EnumTest_Enum1_bigValue, &ok); @@ -4194,6 +4604,50 @@ void tst_QVariant::enums() #endif } +template<typename Enum> void testVariantMeta(Enum value, bool *ok, const char *string) +{ + testVariant<Enum>(value, ok); + QVERIFY(ok); + *ok = false; + + QVariant var = QVariant::fromValue(value); + QVERIFY(var.canConvert<QString>()); + QVERIFY(var.canConvert<QByteArray>()); + + QCOMPARE(var.value<QString>(), QString::fromLatin1(string)); + QCOMPARE(var.value<QByteArray>(), QByteArray(string)); + + QVariant strVar = QString::fromLatin1(string); + QVERIFY(strVar.canConvert<Enum>()); + if (value > INT_MAX) { + QEXPECT_FAIL("", "QMetaEnum api uses 'int' as return type QTBUG-27451", Abort); + *ok = true; + } + QCOMPARE(strVar.value<Enum>(), value); + strVar = QByteArray(string); + QVERIFY(strVar.canConvert<Enum>()); + QCOMPARE(strVar.value<Enum>(), value); + *ok = true; +} + +void tst_QVariant::metaEnums() +{ + bool ok = false; +#define METAENUMS_TEST(Value) \ + testVariantMeta(Value, &ok, #Value); QVERIFY(ok) + + METAENUMS_TEST(MetaEnumTest_Enum0_value); + METAENUMS_TEST(MetaEnumTest_Enum1_value); + METAENUMS_TEST(MetaEnumTest_Enum1_bigValue); + METAENUMS_TEST(MetaEnumTest_Enum3_value); + METAENUMS_TEST(MetaEnumTest_Enum3_bigValue); + METAENUMS_TEST(MetaEnumTest_Enum4_value); + METAENUMS_TEST(MetaEnumTest_Enum4_bigValue); + METAENUMS_TEST(MetaEnumTest_Enum5_value); + METAENUMS_TEST(MetaEnumTest_Enum6_value); + METAENUMS_TEST(MetaEnumTest_Enum8_value); +} + void tst_QVariant::compareSanity_data() { QTest::addColumn<QVariant>("value1"); diff --git a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp index 72aad0dd63..7fc28e2615 100644 --- a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp +++ b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** 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 +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ |