diff options
Diffstat (limited to 'tests/auto/corelib/kernel')
43 files changed, 1539 insertions, 670 deletions
diff --git a/tests/auto/corelib/kernel/.prev_CMakeLists.txt b/tests/auto/corelib/kernel/.prev_CMakeLists.txt new file mode 100644 index 0000000000..515720e282 --- /dev/null +++ b/tests/auto/corelib/kernel/.prev_CMakeLists.txt @@ -0,0 +1,40 @@ +# Generated from kernel.pro. + +add_subdirectory(qcoreapplication) +add_subdirectory(qdeadlinetimer) +add_subdirectory(qelapsedtimer) +add_subdirectory(qeventdispatcher) +if(TARGET Qt::Network) + add_subdirectory(qeventloop) +endif() +add_subdirectory(qmath) +add_subdirectory(qmetaobject) +add_subdirectory(qmetaobjectbuilder) +add_subdirectory(qmetamethod) +add_subdirectory(qmetaproperty) +add_subdirectory(qmetatype) +add_subdirectory(qmetaenum) +if(TARGET Qt::Gui) + add_subdirectory(qmimedata) +endif() +if(TARGET Qt::Network AND NOT ANDROID AND NOT UIKIT) + add_subdirectory(qobject) +endif() +add_subdirectory(qpointer) +if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT UIKIT) + add_subdirectory(qsharedmemory) +endif() +add_subdirectory(qsignalblocker) +add_subdirectory(qsignalmapper) +if(QT_FEATURE_private_tests AND TARGET Qt::Network) + add_subdirectory(qsocketnotifier) +endif() +if(QT_FEATURE_systemsemaphore AND NOT ANDROID AND NOT UIKIT) + add_subdirectory(qsystemsemaphore) +endif() +add_subdirectory(qtimer) +add_subdirectory(qtranslator) +add_subdirectory(qvariant) +if(win32_x_ AND NOT WINRT) + add_subdirectory(qwineventnotifier) +endif() diff --git a/tests/auto/corelib/kernel/CMakeLists.txt b/tests/auto/corelib/kernel/CMakeLists.txt new file mode 100644 index 0000000000..f4f7b32bf3 --- /dev/null +++ b/tests/auto/corelib/kernel/CMakeLists.txt @@ -0,0 +1,43 @@ +# Generated from kernel.pro. + +# add_subdirectory(qcoreapplication) # special case +add_subdirectory(qdeadlinetimer) +add_subdirectory(qelapsedtimer) +add_subdirectory(qeventdispatcher) +if(TARGET Qt::Network) + add_subdirectory(qeventloop) +endif() +add_subdirectory(qmath) +add_subdirectory(qmetaobject) +add_subdirectory(qmetaobjectbuilder) +add_subdirectory(qmetamethod) +add_subdirectory(qmetaproperty) +add_subdirectory(qmetatype) +add_subdirectory(qmetaenum) +if(TARGET Qt::Gui) + add_subdirectory(qmimedata) +endif() +if(TARGET Qt::Network AND NOT ANDROID AND NOT UIKIT) + # add_subdirectory(qobject) # special case +endif() +add_subdirectory(qpointer) +if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT UIKIT) + add_subdirectory(qsharedmemory) +endif() +add_subdirectory(qsignalblocker) +add_subdirectory(qsignalmapper) +if(QT_FEATURE_private_tests AND TARGET Qt::Network) + add_subdirectory(qsocketnotifier) +endif() +if(QT_FEATURE_systemsemaphore AND NOT ANDROID AND NOT UIKIT) + add_subdirectory(qsystemsemaphore) +endif() +# add_subdirectory(qtimer) # special case +add_subdirectory(qtranslator) +add_subdirectory(qvariant) +if(win32_x_ AND NOT WINRT) + add_subdirectory(qwineventnotifier) +endif() +if(QT_FEATURE_private_tests) + add_subdirectory(qproperty) +endif() diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro index 09074a9e8a..26cc00ea40 100644 --- a/tests/auto/corelib/kernel/kernel.pro +++ b/tests/auto/corelib/kernel/kernel.pro @@ -23,7 +23,8 @@ SUBDIRS=\ qtimer \ qtranslator \ qvariant \ - qwineventnotifier + qwineventnotifier \ + qproperty !qtHaveModule(gui): SUBDIRS -= \ qmimedata @@ -35,7 +36,8 @@ SUBDIRS=\ !qtConfig(private_tests): SUBDIRS -= \ qsocketnotifier \ - qsharedmemory + qsharedmemory \ + qproperty # This test is only applicable on Windows !win32*|winrt: SUBDIRS -= qwineventnotifier diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/CMakeLists.txt b/tests/auto/corelib/kernel/qdeadlinetimer/CMakeLists.txt new file mode 100644 index 0000000000..5feb9ff535 --- /dev/null +++ b/tests/auto/corelib/kernel/qdeadlinetimer/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qdeadlinetimer.pro. + +##################################################################### +## tst_qdeadlinetimer Test: +##################################################################### + +add_qt_test(tst_qdeadlinetimer + SOURCES + tst_qdeadlinetimer.cpp +) diff --git a/tests/auto/corelib/kernel/qelapsedtimer/CMakeLists.txt b/tests/auto/corelib/kernel/qelapsedtimer/CMakeLists.txt new file mode 100644 index 0000000000..e188c94933 --- /dev/null +++ b/tests/auto/corelib/kernel/qelapsedtimer/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qelapsedtimer.pro. + +##################################################################### +## tst_qelapsedtimer Test: +##################################################################### + +add_qt_test(tst_qelapsedtimer + SOURCES + tst_qelapsedtimer.cpp +) diff --git a/tests/auto/corelib/kernel/qeventdispatcher/CMakeLists.txt b/tests/auto/corelib/kernel/qeventdispatcher/CMakeLists.txt new file mode 100644 index 0000000000..4dbabc2d69 --- /dev/null +++ b/tests/auto/corelib/kernel/qeventdispatcher/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qeventdispatcher.pro. + +##################################################################### +## tst_qeventdispatcher Test: +##################################################################### + +add_qt_test(tst_qeventdispatcher + SOURCES + tst_qeventdispatcher.cpp +) diff --git a/tests/auto/corelib/kernel/qeventloop/CMakeLists.txt b/tests/auto/corelib/kernel/qeventloop/CMakeLists.txt new file mode 100644 index 0000000000..ac952f64f7 --- /dev/null +++ b/tests/auto/corelib/kernel/qeventloop/CMakeLists.txt @@ -0,0 +1,26 @@ +# Generated from qeventloop.pro. + +##################################################################### +## tst_qeventloop Test: +##################################################################### + +add_qt_test(tst_qeventloop + SOURCES + tst_qeventloop.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Network +) + +## Scopes: +##################################################################### + +extend_target(tst_qeventloop CONDITION WIN32 AND NOT WINRT + PUBLIC_LIBRARIES + user32 +) + +extend_target(tst_qeventloop CONDITION QT_FEATURE_glib + DEFINES + HAVE_GLIB +) diff --git a/tests/auto/corelib/kernel/qmath/CMakeLists.txt b/tests/auto/corelib/kernel/qmath/CMakeLists.txt new file mode 100644 index 0000000000..5e73597c67 --- /dev/null +++ b/tests/auto/corelib/kernel/qmath/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qmath.pro. + +##################################################################### +## tst_qmath Test: +##################################################################### + +add_qt_test(tst_qmath + SOURCES + tst_qmath.cpp +) diff --git a/tests/auto/corelib/kernel/qmetaenum/CMakeLists.txt b/tests/auto/corelib/kernel/qmetaenum/CMakeLists.txt new file mode 100644 index 0000000000..12c9d9a8a7 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetaenum/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qmetaenum.pro. + +##################################################################### +## tst_qmetaenum Test: +##################################################################### + +add_qt_test(tst_qmetaenum + SOURCES + tst_qmetaenum.cpp +) diff --git a/tests/auto/corelib/kernel/qmetamethod/CMakeLists.txt b/tests/auto/corelib/kernel/qmetamethod/CMakeLists.txt new file mode 100644 index 0000000000..b16101a1a1 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetamethod/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qmetamethod.pro. + +##################################################################### +## tst_qmetamethod Test: +##################################################################### + +add_qt_test(tst_qmetamethod + SOURCES + tst_qmetamethod.cpp +) diff --git a/tests/auto/corelib/kernel/qmetaobject/CMakeLists.txt b/tests/auto/corelib/kernel/qmetaobject/CMakeLists.txt new file mode 100644 index 0000000000..888bfeaa78 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetaobject/CMakeLists.txt @@ -0,0 +1,15 @@ +# Generated from qmetaobject.pro. + +##################################################################### +## tst_qmetaobject Test: +##################################################################### + +add_qt_test(tst_qmetaobject + SOURCES + tst_qmetaobject.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate +) + +## Scopes: +##################################################################### diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 60000316cc..9db2bb241a 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -1320,32 +1320,38 @@ void tst_QMetaObject::normalizedSignature_data() QTest::newRow("function ptr spaces") << "void foo( void ( * ) ( void ))" << "void foo(void(*)())"; QTest::newRow("function ptr void*") << "void foo(void(*)(void*))" << "void foo(void(*)(void*))"; QTest::newRow("function ptr void* spaces") << "void foo( void ( * ) ( void * ))" << "void foo(void(*)(void*))"; - QTest::newRow("template args") << " void foo( QMap<a, a>, QList<b>) " - << "void foo(QMap<a,a>,QList<b>)"; + QTest::newRow("template args") << " void foo( QMap<a, a>, QVector<b>) " + << "void foo(QMap<a,a>,QVector<b>)"; QTest::newRow("void template args") << " void foo( Foo<void>, Bar<void> ) " << "void foo(Foo<void>,Bar<void>)"; QTest::newRow("void* template args") << " void foo( Foo<void*>, Bar<void *> ) " << "void foo(Foo<void*>,Bar<void*>)"; - QTest::newRow("rettype") << "QList<int, int> foo()" << "QList<int,int>foo()"; + QTest::newRow("rettype") << "QVector<int, int> foo()" << "QVector<int,int>foo()"; QTest::newRow("rettype void template") << "Foo<void> foo()" << "Foo<void>foo()"; QTest::newRow("const rettype") << "const QString *foo()" << "const QString*foo()"; QTest::newRow("const ref") << "const QString &foo()" << "const QString&foo()"; QTest::newRow("reference") << "QString &foo()" << "QString&foo()"; QTest::newRow("const1") << "void foo(QString const *)" << "void foo(const QString*)"; - QTest::newRow("const2") << "void foo(QString * const)" << "void foo(QString*const)"; + QTest::newRow("const2") << "void foo(QString * const)" << "void foo(QString*)"; QTest::newRow("const3") << "void foo(QString const &)" << "void foo(QString)"; QTest::newRow("const4") << "void foo(const int)" << "void foo(int)"; QTest::newRow("const5") << "void foo(const int, int const, const int &, int const &)" << "void foo(int,int,int,int)"; - QTest::newRow("const6") << "void foo(QList<const int>)" << "void foo(QList<const int>)"; - QTest::newRow("const7") << "void foo(QList<const int*>)" << "void foo(QList<const int*>)"; - QTest::newRow("const8") << "void foo(QList<int const*>)" << "void foo(QList<const int*>)"; + QTest::newRow("const6") << "void foo(QVector<const int>)" << "void foo(QVector<const int>)"; + QTest::newRow("const7") << "void foo(QVector<const int*>)" << "void foo(QVector<const int*>)"; + QTest::newRow("const8") << "void foo(QVector<int const*>)" << "void foo(QVector<const int*>)"; QTest::newRow("const9") << "void foo(const Foo<Bar>)" << "void foo(Foo<Bar>)"; QTest::newRow("const10") << "void foo(Foo<Bar>const)" << "void foo(Foo<Bar>)"; - QTest::newRow("const11") << "void foo(Foo<Bar> *const)" << "void foo(Foo<Bar>*const)"; - QTest::newRow("const12") << "void foo(Foo<Bar>const*const *const)" << "void foo(Foo<Bar>*const*const)"; + QTest::newRow("const11") << "void foo(Foo<Bar> *const)" << "void foo(Foo<Bar>*)"; + QTest::newRow("const12") << "void foo(Foo<Bar>const*const *const)" << "void foo(const Foo<Bar>*const*)"; QTest::newRow("const13") << "void foo(const Foo<Bar>&)" << "void foo(Foo<Bar>)"; QTest::newRow("const14") << "void foo(Foo<Bar>const&)" << "void foo(Foo<Bar>)"; + QTest::newRow("QList") << "void foo(QList<int>)" << "void foo(QVector<int>)"; + QTest::newRow("QList1") << "void foo(const Template<QList, MyQList const>)" + << "void foo(Template<QVector,const MyQList>)"; + + QTest::newRow("refref") << "const char* foo(const X &&,X const &&, const X* &&) && " + << "const char*foo(const X&&,const X&&,const X*&&)&&"; QTest::newRow("invalid1") << "a( b" << "a(b"; } @@ -1367,26 +1373,63 @@ void tst_QMetaObject::normalizedType_data() QTest::newRow("white") << " int " << "int"; QTest::newRow("const1") << "int const *" << "const int*"; QTest::newRow("const2") << "const int *" << "const int*"; - QTest::newRow("template1") << "QList<int const *>" << "QList<const int*>"; - QTest::newRow("template2") << "QList<const int *>" << "QList<const int*>"; + QTest::newRow("template1") << "QVector<int const *>" << "QVector<const int*>"; + QTest::newRow("template2") << "QVector<const int *>" << "QVector<const int*>"; QTest::newRow("template3") << "QMap<QString, int>" << "QMap<QString,int>"; QTest::newRow("template4") << "const QMap<QString, int> &" << "QMap<QString,int>"; - QTest::newRow("template5") << "QList< ::Foo::Bar>" << "QList< ::Foo::Bar>"; - QTest::newRow("template6") << "QList<::Foo::Bar>" << "QList<::Foo::Bar>"; - QTest::newRow("template7") << "QList<QList<int> >" << "QList<QList<int> >"; + QTest::newRow("template5") << "QVector< ::Foo::Bar>" << "QVector<::Foo::Bar>"; + QTest::newRow("template6") << "QVector<::Foo::Bar>" << "QVector<::Foo::Bar>"; + QTest::newRow("template7") << "QVector<QVector<int> >" << "QVector<QVector<int>>"; QTest::newRow("template8") << "QMap<const int, const short*>" << "QMap<const int,const short*>"; - QTest::newRow("template9") << "QPair<const QPair<int, int const *> , QPair<QHash<int, const char*> > >" << "QPair<const QPair<int,const int*>,QPair<QHash<int,const char*> > >"; + QTest::newRow("template9") << "QPair<const QPair<int, int const *> , QPair<QHash<int, const char*> > >" << "QPair<const QPair<int,const int*>,QPair<QHash<int,const char*>>>"; + QTest::newRow("template10") << "QList<int const * const> const" << "QVector<const int*const>"; + QTest::newRow("template11") << " QSharedPointer<QVarLengthArray< QString const, ( 16>> 2 )> > const & " + << "QSharedPointer<QVarLengthArray<const QString,(16>>2)>>"; + QTest::newRow("template_sub") << "X<( Y < 8), (Y >6)> const & " << "X<(Y<8),(Y>6)>"; QTest::newRow("value1") << "const QString &" << "QString"; QTest::newRow("value2") << "QString const &" << "QString"; QTest::newRow("constInName1") << "constconst" << "constconst"; QTest::newRow("constInName2") << "constconst*" << "constconst*"; QTest::newRow("constInName3") << "const constconst&" << "constconst"; - QTest::newRow("constInName4") << "constconst const*const" << "constconst*const"; + QTest::newRow("constInName4") << "constconst const*const" << "const constconst*"; QTest::newRow("class") << "const class foo&" << "foo"; QTest::newRow("struct") << "const struct foo*" << "const foo*"; QTest::newRow("struct2") << "struct foo const*" << "const foo*"; QTest::newRow("enum") << "enum foo" << "foo"; QTest::newRow("void") << "void" << "void"; + QTest::newRow("QList") << "QList<int>" << "QVector<int>"; + QTest::newRow("refref") << "X const*const&&" << "const X*const&&"; + QTest::newRow("refref2") << "const X<T const&&>&&" << "const X<const T&&>&&"; + QTest::newRow("long1") << "long unsigned int long" << "unsigned long long"; + QTest::newRow("long2") << "int signed long" << "long"; + QTest::newRow("long3") << "long unsigned" << "ulong"; + QTest::newRow("long double") << " long double" << "long double"; + QTest::newRow("signed char") << "char signed" << "signed char"; + QTest::newRow("unsigned char") << "char unsigned" << "unsigned char"; + QTest::newRow("signed short") << "short signed" << "short"; + QTest::newRow("unsigned shot") << "short unsigned" << "unsigned short"; + QTest::newRow("unsigned shot") << "short unsigned" << "unsigned short"; + QTest::newRow("array1") << "unsigned int [4]" << "uint[4]"; + QTest::newRow("array2") << "unsigned int const [4][5]" << "const uint[4][5]"; + QTest::newRow("array3") << "unsigned[] const" << "uint[]"; + QTest::newRow("nttp1") << "S<'>', int const> const" + << "S<'>',const int>"; + QTest::newRow("nttp2") << "S< \"> \\\">const * \\\\\" , int const> const" + << "S<\"> \\\">const * \\\\\",const int>"; + QTest::newRow("nttp3") << "S<\"Q <\" , int const> const*" + << "const S<\"Q <\",const int>*"; + QTest::newRow("nttp4") << "S< 1'2 , int const> const" + << "S<1'2,const int>"; + QTest::newRow("invalid") << "'const" + << "'const"; + QTest::newRow("anonym1") << "XX::<unnamed struct>" + << "XX::<unnamed struct>"; + QTest::newRow("anonym2") << "XX::{unnamed type#1}" + << "XX::{unnamed type#1}"; + QTest::newRow("anonym3") << "struct XX::<unnamed-type-s>" + << "XX::<unnamed-type-s>"; + QTest::newRow("anonym4") << "XX::(anonymous struct at ./example.cpp:10:13)" + << "XX::(anonymous struct at./example.cpp:10:13)"; } void tst_QMetaObject::normalizedType() @@ -1395,6 +1438,7 @@ void tst_QMetaObject::normalizedType() QFETCH(QString, result); QCOMPARE(QMetaObject::normalizedType(type.toLatin1()), result.toLatin1()); + QCOMPARE(QMetaObject::normalizedType(result.toLatin1()), result.toLatin1()); } void tst_QMetaObject::customPropertyType() @@ -1402,13 +1446,15 @@ void tst_QMetaObject::customPropertyType() QMetaProperty prop = metaObject()->property(metaObject()->indexOfProperty("value3")); QCOMPARE(prop.type(), QVariant::UserType); - QCOMPARE(prop.userType(), 0); + QCOMPARE(prop.userType(), QMetaType::fromType<MyStruct>().id()); + QCOMPARE(prop.metaType(), QMetaType::fromType<MyStruct>()); qRegisterMetaType<MyStruct>("MyStruct"); QCOMPARE(prop.userType(), QMetaType::type("MyStruct")); prop = metaObject()->property(metaObject()->indexOfProperty("value4")); QCOMPARE(prop.type(), QVariant::List); + QCOMPARE(prop.metaType(), QMetaType::fromType<QList<QVariant>>()); prop = metaObject()->property(metaObject()->indexOfProperty("value5")); QCOMPARE(prop.type(), QVariant::List); diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/CMakeLists.txt b/tests/auto/corelib/kernel/qmetaobjectbuilder/CMakeLists.txt new file mode 100644 index 0000000000..e7586d580b --- /dev/null +++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qmetaobjectbuilder.pro. + +##################################################################### +## tst_qmetaobjectbuilder Test: +##################################################################### + +add_qt_test(tst_qmetaobjectbuilder + SOURCES + tst_qmetaobjectbuilder.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate +) diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp index 9fe7d63727..14719f36f8 100644 --- a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp +++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp @@ -1702,9 +1702,10 @@ void tst_QMetaObjectBuilder::classNameFirstInStringData() builder.setClassName(QByteArrayLiteral("TestClass")); QMetaObject *mo = builder.toMetaObject(); - QByteArrayDataPtr header; - header.ptr = const_cast<QByteArrayData*>(mo->d.stringdata); - QCOMPARE(QByteArray(header), QByteArrayLiteral("TestClass")); + uint offset = mo->d.stringdata[0]; + uint len = mo->d.stringdata[1]; + QByteArray className(reinterpret_cast<const char *>(mo->d.stringdata) + offset, len); + QCOMPARE(className, QByteArrayLiteral("TestClass")); free(mo); } diff --git a/tests/auto/corelib/kernel/qmetaproperty/CMakeLists.txt b/tests/auto/corelib/kernel/qmetaproperty/CMakeLists.txt new file mode 100644 index 0000000000..2d657d5217 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetaproperty/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qmetaproperty.pro. + +##################################################################### +## tst_qmetaproperty Test: +##################################################################### + +add_qt_test(tst_qmetaproperty + SOURCES + tst_qmetaproperty.cpp +) diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp index cc67fc7884..43ed535019 100644 --- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp +++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp @@ -138,6 +138,7 @@ void tst_QMetaProperty::gadget() const QMetaObject *mo = &MyGadget::staticMetaObject; QMetaProperty valueProp = mo->property(mo->indexOfProperty("value")); QVERIFY(valueProp.isValid()); + QCOMPARE(valueProp.metaType(), QMetaType::fromType<QString>()); { MyGadget g; QString hello = QLatin1String("hello"); diff --git a/tests/auto/corelib/kernel/qmetatype/.prev_CMakeLists.txt b/tests/auto/corelib/kernel/qmetatype/.prev_CMakeLists.txt new file mode 100644 index 0000000000..9a0bbc189c --- /dev/null +++ b/tests/auto/corelib/kernel/qmetatype/.prev_CMakeLists.txt @@ -0,0 +1,41 @@ +# Generated from qmetatype.pro. + +##################################################################### +## tst_qmetatype Test: +##################################################################### + +# Collect test data +list(APPEND test_data "./typeFlags.bin") + +add_qt_test(tst_qmetatype + SOURCES + tst_qmetatype.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0 + INCLUDE_DIRECTORIES + ../../../other/qvariant_common + PUBLIC_LIBRARIES + Qt::CorePrivate + TESTDATA ${test_data} +) + +## Scopes: +##################################################################### + +extend_target(tst_qmetatype CONDITION MSVC OR WINRT + COMPILE_OPTIONS + /bigobj +) + +#### Keys ignored in scope 3:.:.:qmetatype.pro:WINRT: +# QMAKE_CFLAGS_RELEASE = "--O2" +# QMAKE_CXXFLAGS_RELEASE = "--O2" + +#### Keys ignored in scope 4:.:.:qmetatype.pro:CLANG: +# QMAKE_CFLAGS_RELEASE = "--O2" "--g" +# QMAKE_CXXFLAGS_RELEASE = "--O2" "--g" + +extend_target(tst_qmetatype CONDITION CLANG AND (TEST_architecture_arch STREQUAL "arm") + DEFINES + TST_QMETATYPE_BROKEN_COMPILER +) diff --git a/tests/auto/corelib/kernel/qmetatype/CMakeLists.txt b/tests/auto/corelib/kernel/qmetatype/CMakeLists.txt new file mode 100644 index 0000000000..8f72ce51f3 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetatype/CMakeLists.txt @@ -0,0 +1,42 @@ +# Generated from qmetatype.pro. + +##################################################################### +## tst_qmetatype Test: +##################################################################### + +# Collect test data +list(APPEND test_data "./typeFlags.bin") + +add_qt_test(tst_qmetatype + SOURCES + tst_qmetatype.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0 + INCLUDE_DIRECTORIES + ../../../other/qvariant_common + PUBLIC_LIBRARIES + Qt::CorePrivate + Threads::Threads # special case + TESTDATA ${test_data} +) + +## Scopes: +##################################################################### + +extend_target(tst_qmetatype CONDITION MSVC OR WINRT + COMPILE_OPTIONS + /bigobj +) + +#### Keys ignored in scope 3:.:.:qmetatype.pro:WINRT: +# QMAKE_CFLAGS_RELEASE = "--O2" +# QMAKE_CXXFLAGS_RELEASE = "--O2" + +#### Keys ignored in scope 4:.:.:qmetatype.pro:CLANG: +# QMAKE_CFLAGS_RELEASE = "--O2" "--g" +# QMAKE_CXXFLAGS_RELEASE = "--O2" "--g" + +extend_target(tst_qmetatype CONDITION CLANG AND (TEST_architecture_arch STREQUAL "arm") + DEFINES + TST_QMETATYPE_BROKEN_COMPILER +) diff --git a/tests/auto/corelib/kernel/qmetatype/qmetatype.pro b/tests/auto/corelib/kernel/qmetatype/qmetatype.pro index 4856b138c3..56b8c071c3 100644 --- a/tests/auto/corelib/kernel/qmetatype/qmetatype.pro +++ b/tests/auto/corelib/kernel/qmetatype/qmetatype.pro @@ -5,7 +5,6 @@ INCLUDEPATH += $$PWD/../../../other/qvariant_common SOURCES = tst_qmetatype.cpp TESTDATA=./typeFlags.bin DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 -DEFINES -= QT_NO_LINKED_LIST msvc|winrt { # Prevents "fatal error C1128: number of sections exceeded object file format limit". diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 19b3289390..f144aad7e4 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -120,17 +120,19 @@ private slots: void constRefs(); void convertCustomType_data(); void convertCustomType(); - void compareCustomType_data(); - void compareCustomType(); void compareCustomEqualOnlyType(); void customDebugStream(); void unknownType(); void fromType(); + void operatorEq_data(); + void operatorEq(); + void typesWithInaccessibleDTors(); }; struct BaseGenericType { int m_typeId = -1; + QMetaType m_metatype; virtual void *constructor(int typeId, void *where, const void *copy) = 0; virtual void staticMetacallFunction(QMetaObject::Call _c, int _id, void **_a) = 0; virtual void saveOperator(QDataStream & out) const = 0; @@ -302,11 +304,19 @@ void tst_QMetaType::registerGadget(const char *name, const QVector<GadgetPropert meta->d.static_metacall = &GadgetsStaticMetacallFunction; meta->d.superdata = nullptr; const auto flags = QMetaType::WasDeclaredAsMetaType | QMetaType::IsGadget | QMetaType::NeedsConstruction | QMetaType::NeedsDestruction; - int gadgetTypeId = QMetaType::registerType(name, - &GadgetTypedDestructor, - &GadgetTypedConstructor, - sizeof(GenericGadgetType), - flags, meta); + using TypeInfo = QtPrivate::QMetaTypeInterface; + auto typeInfo = new TypeInfo { + 0, sizeof(GenericGadgetType), alignof(GenericGadgetType), uint(flags), meta, name, 0, + QtPrivate::RefCount{ 0 }, + [](TypeInfo *self) { delete self; }, + [](const TypeInfo *self, void *where) { GadgetTypedConstructor(self->typeId, where, nullptr); }, + [](const TypeInfo *self, void *where, const void *copy) { GadgetTypedConstructor(self->typeId, where, copy); }, + [](const TypeInfo *self, void *where, void *copy) { GadgetTypedConstructor(self->typeId, where, copy); }, + [](const TypeInfo *self, void *ptr) { GadgetTypedDestructor(self->typeId, ptr); }, + nullptr }; + QMetaType gadgetMetaType(typeInfo); + dynamicGadgetProperties->m_metatype = gadgetMetaType; + int gadgetTypeId = QMetaType(typeInfo).id(); QVERIFY(gadgetTypeId > 0); QMetaType::registerStreamOperators(gadgetTypeId, &GadgetSaveOperator, &GadgetLoadOperator); s_managedTypes[gadgetTypeId] = qMakePair(dynamicGadgetProperties, std::shared_ptr<QMetaObject>{meta, [](QMetaObject *ptr){ ::free(ptr); }}); @@ -392,10 +402,6 @@ protected: ++failureCount; qWarning() << "Wrong metatype returned for" << name; } - if (QMetaType::typeName(tp) != name) { - ++failureCount; - qWarning() << "Wrong typeName returned for" << tp; - } void *buf1 = QMetaType::create(tp, 0); void *buf2 = QMetaType::create(tp, buf1); void *buf3 = info.create(tp, 0); @@ -574,11 +580,13 @@ void tst_QMetaType::typeName_data() QTest::newRow("124125534") << 124125534 << QString(); // automatic registration - QTest::newRow("QList<int>") << ::qMetaTypeId<QList<int> >() << QString::fromLatin1("QList<int>"); QTest::newRow("QHash<int,int>") << ::qMetaTypeId<QHash<int, int> >() << QString::fromLatin1("QHash<int,int>"); QTest::newRow("QMap<int,int>") << ::qMetaTypeId<QMap<int, int> >() << QString::fromLatin1("QMap<int,int>"); - QTest::newRow("QVector<QList<int>>") << ::qMetaTypeId<QVector<QList<int> > >() << QString::fromLatin1("QVector<QList<int> >"); - QTest::newRow("QVector<QMap<int,int>>") << ::qMetaTypeId<QVector<QMap<int, int> > >() << QString::fromLatin1("QVector<QMap<int,int> >"); + QTest::newRow("QVector<QMap<int,int>>") << ::qMetaTypeId<QVector<QMap<int, int> > >() << QString::fromLatin1("QVector<QMap<int,int>>"); + + // automatic registration with automatic QList to QVector aliasing + QTest::newRow("QList<int>") << ::qMetaTypeId<QList<int> >() << QString::fromLatin1("QVector<int>"); + QTest::newRow("QVector<QList<int>>") << ::qMetaTypeId<QVector<QList<int> > >() << QString::fromLatin1("QVector<QVector<int>>"); QTest::newRow("CustomQObject*") << ::qMetaTypeId<CustomQObject*>() << QString::fromLatin1("CustomQObject*"); QTest::newRow("CustomGadget") << ::qMetaTypeId<CustomGadget>() << QString::fromLatin1("CustomGadget"); @@ -1006,6 +1014,10 @@ void tst_QMetaType::flagsBinaryCompatibility5_0_data() for (int i = 0; i < buffer.size(); i+=2) { const quint32 id = buffer.at(i); const quint32 flags = buffer.at(i + 1); + if (id > QMetaType::LastCoreType) + continue; // We do not link against QtGui, so we do longer consider such type as registered + if (id == QMetaType::Void) + continue; // The meaning of QMetaType::Void has changed in Qt6 QVERIFY2(QMetaType::isRegistered(id), "A type could not be removed in BC way"); QTest::newRow(QMetaType::typeName(id)) << id << flags; } @@ -1032,9 +1044,9 @@ static void testConstructHelper() typedef typename MetaEnumToType<ID>::Type Type; QMetaType info(ID); int size = info.sizeOf(); - void *storage1 = qMallocAligned(size, Q_ALIGNOF(Type)); + void *storage1 = qMallocAligned(size, alignof(Type)); void *actual1 = QMetaType::construct(ID, storage1, /*copy=*/0); - void *storage2 = qMallocAligned(size, Q_ALIGNOF(Type)); + void *storage2 = qMallocAligned(size, alignof(Type)); void *actual2 = info.construct(storage2, /*copy=*/0); QCOMPARE(actual1, storage1); QCOMPARE(actual2, storage2); @@ -1158,11 +1170,19 @@ void tst_QMetaType::typedConstruct() auto dynamicGadgetProperties = std::make_shared<GenericPODType>(); dynamicGadgetProperties->podData = myPodTesData; const auto flags = QMetaType::NeedsConstruction | QMetaType::NeedsDestruction; - int podTypeId = QMetaType::registerType(podTypeName, - &GadgetTypedDestructor, - &GadgetTypedConstructor, - sizeof(GenericGadgetType), - flags, nullptr); + using TypeInfo = QtPrivate::QMetaTypeInterface; + auto typeInfo = new TypeInfo { + 0, sizeof(GenericGadgetType), alignof(GenericGadgetType), uint(flags), nullptr, podTypeName, + 0, QtPrivate::RefCount{0}, + [](TypeInfo *self) { delete self; }, + [](const TypeInfo *self, void *where) { GadgetTypedConstructor(self->typeId, where, nullptr); }, + [](const TypeInfo *self, void *where, const void *copy) { GadgetTypedConstructor(self->typeId, where, copy); }, + [](const TypeInfo *self, void *where, void *copy) { GadgetTypedConstructor(self->typeId, where, copy); }, + [](const TypeInfo *self, void *ptr) { GadgetTypedDestructor(self->typeId, ptr); }, + nullptr }; + QMetaType metatype(typeInfo); + dynamicGadgetProperties->m_metatype = metatype; + int podTypeId = metatype.id(); QVERIFY(podTypeId > 0); QMetaType::registerStreamOperators(podTypeId, &GadgetSaveOperator, &GadgetLoadOperator); s_managedTypes[podTypeId] = qMakePair(dynamicGadgetProperties, std::shared_ptr<QMetaObject>{}); @@ -1186,9 +1206,9 @@ static void testConstructCopyHelper() QMetaType info(ID); int size = QMetaType::sizeOf(ID); QCOMPARE(info.sizeOf(), size); - void *storage1 = qMallocAligned(size, Q_ALIGNOF(Type)); + void *storage1 = qMallocAligned(size, alignof(Type)); void *actual1 = QMetaType::construct(ID, storage1, expected); - void *storage2 = qMallocAligned(size, Q_ALIGNOF(Type)); + void *storage2 = qMallocAligned(size, alignof(Type)); void *actual2 = info.construct(storage2, expected); QCOMPARE(actual1, storage1); QCOMPARE(actual2, storage2); @@ -1309,54 +1329,6 @@ void tst_QMetaType::registerType() QCOMPARE(qRegisterMetaType<MyFoo>("MyFoo"), fooId); QCOMPARE(QMetaType::type("MyFoo"), fooId); - - // cannot unregister built-in types - QVERIFY(!QMetaType::unregisterType(QMetaType::QString)); - QCOMPARE(QMetaType::type("QString"), int(QMetaType::QString)); - QCOMPARE(QMetaType::type("MyString"), int(QMetaType::QString)); - - // cannot unregister declared types - QVERIFY(!QMetaType::unregisterType(fooId)); - QCOMPARE(QMetaType::type("TestSpace::Foo"), fooId); - QCOMPARE(QMetaType::type("MyFoo"), fooId); - - // test unregistration of dynamic types (used by Qml) - int unregId = QMetaType::registerType("UnregisterMe", - 0, - 0, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, - 0, QMetaType::TypeFlags(), 0); - QCOMPARE(QMetaType::registerTypedef("UnregisterMeTypedef", unregId), unregId); - int unregId2 = QMetaType::registerType("UnregisterMe2", - 0, - 0, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, - 0, QMetaType::TypeFlags(), 0); - QVERIFY(unregId >= int(QMetaType::User)); - QCOMPARE(unregId2, unregId + 2); - - QVERIFY(QMetaType::unregisterType(unregId)); - QCOMPARE(QMetaType::type("UnregisterMe"), 0); - QCOMPARE(QMetaType::type("UnregisterMeTypedef"), 0); - QCOMPARE(QMetaType::type("UnregisterMe2"), unregId2); - QVERIFY(QMetaType::unregisterType(unregId2)); - QCOMPARE(QMetaType::type("UnregisterMe2"), 0); - - // re-registering should always return the lowest free index - QCOMPARE(QMetaType::registerType("UnregisterMe2", - 0, - 0, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, - 0, QMetaType::TypeFlags(), 0), unregId); - QCOMPARE(QMetaType::registerType("UnregisterMe", - 0, - 0, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, - 0, QMetaType::TypeFlags(), 0), unregId + 1); } class IsRegisteredDummyType { }; @@ -1367,7 +1339,7 @@ void tst_QMetaType::isRegistered_data() QTest::addColumn<bool>("registered"); // predefined/custom types - QTest::newRow("QMetaType::Void") << int(QMetaType::Void) << true; + QTest::newRow("QMetaType::Void") << int(QMetaType::Void) << false; QTest::newRow("QMetaType::Int") << int(QMetaType::Int) << true; int dummyTypeId = qRegisterMetaType<IsRegisteredDummyType>("IsRegisteredDummyType"); @@ -1733,8 +1705,8 @@ void tst_QMetaType::automaticTemplateRegistration() CONTAINER< __VA_ARGS__ > t; \ const QVariant v = QVariant::fromValue(t); \ QByteArray tn = createTypeName(#CONTAINER "<", #__VA_ARGS__); \ - const int type = QMetaType::type(tn); \ const int expectedType = ::qMetaTypeId<CONTAINER< __VA_ARGS__ > >(); \ + const int type = QMetaType::type(tn); \ QCOMPARE(type, expectedType); \ QCOMPARE((QMetaType::fromType<CONTAINER< __VA_ARGS__ >>().id()), expectedType); \ } @@ -1742,7 +1714,6 @@ void tst_QMetaType::automaticTemplateRegistration() #define FOR_EACH_1ARG_TEMPLATE_TYPE(F, TYPE) \ F(QList, TYPE) \ F(QVector, TYPE) \ - F(QLinkedList, TYPE) \ F(QVector, TYPE) \ F(QVector, TYPE) \ F(QQueue, TYPE) \ @@ -1777,7 +1748,7 @@ void tst_QMetaType::automaticTemplateRegistration() PRINT_2ARG_TEMPLATE ) - CREATE_AND_VERIFY_CONTAINER(QList, QList<QMap<int, QHash<char, QVariantList> > >) + CREATE_AND_VERIFY_CONTAINER(QList, QList<QMap<int, QHash<char, QList<QVariant> > > >) CREATE_AND_VERIFY_CONTAINER(QVector, void*) CREATE_AND_VERIFY_CONTAINER(QVector, const void*) CREATE_AND_VERIFY_CONTAINER(QList, void*) @@ -2017,7 +1988,7 @@ void tst_QMetaType::metaObject_data() QTest::newRow("MyGadget") << ::qMetaTypeId<MyGadget>() << &MyGadget::staticMetaObject << true << false << false; QTest::newRow("MyGadget*") << ::qMetaTypeId<MyGadget*>() << &MyGadget::staticMetaObject << false << true << false; QTest::newRow("MyEnum") << ::qMetaTypeId<MyGadget::MyEnum>() << &MyGadget::staticMetaObject << false << false << false; - QTest::newRow("Qt::ScrollBarPolicy") << ::qMetaTypeId<Qt::ScrollBarPolicy>() << &QObject::staticQtMetaObject << false << false << false; + QTest::newRow("Qt::ScrollBarPolicy") << ::qMetaTypeId<Qt::ScrollBarPolicy>() << &Qt::staticMetaObject << false << false << false; QTest::newRow("MyQObjectFromGadget*") << ::qMetaTypeId<MyQObjectFromGadget*>() << &MyQObjectFromGadget::staticMetaObject << false << false << true; QTest::newRow("GadgetDerivedAndTyped<int>") << ::qMetaTypeId<GadgetDerivedAndTyped<int>>() << &GadgetDerivedAndTyped<int>::staticMetaObject << true << false << false; @@ -2139,7 +2110,7 @@ struct CustomConvertibleType }; bool operator<(const CustomConvertibleType &lhs, const CustomConvertibleType &rhs) -{ return lhs.m_foo < rhs.m_foo; } +{ return lhs.m_foo.toString() < rhs.m_foo.toString(); } bool operator==(const CustomConvertibleType &lhs, const CustomConvertibleType &rhs) { return lhs.m_foo == rhs.m_foo; } bool operator!=(const CustomConvertibleType &lhs, const CustomConvertibleType &rhs) @@ -2429,43 +2400,6 @@ void tst_QMetaType::convertCustomType() QCOMPARE(v.value<CustomConvertibleType2>().m_foo, testCustom.m_foo); } -void tst_QMetaType::compareCustomType_data() -{ - QMetaType::registerComparators<CustomConvertibleType>(); - - QTest::addColumn<QVariantList>("unsorted"); - QTest::addColumn<QVariantList>("sorted"); - - QTest::newRow("int") << (QVariantList() << 37 << 458 << 1 << 243 << -4 << 383) - << (QVariantList() << -4 << 1 << 37 << 243 << 383 << 458); - - QTest::newRow("dobule") << (QVariantList() << 4934.93 << 0.0 << 302.39 << -39.0) - << (QVariantList() << -39.0 << 0.0 << 302.39 << 4934.93); - - QTest::newRow("QString") << (QVariantList() << "Hello" << "World" << "this" << "is" << "a" << "test") - << (QVariantList() << "a" << "Hello" << "is" << "test" << "this" << "World"); - - QTest::newRow("QTime") << (QVariantList() << QTime(14, 39) << QTime(0, 0) << QTime(18, 18) << QTime(9, 27)) - << (QVariantList() << QTime(0, 0) << QTime(9, 27) << QTime(14, 39) << QTime(18, 18)); - - QTest::newRow("QDate") << (QVariantList() << QDate(2013, 3, 23) << QDate(1900, 12, 1) << QDate(2001, 2, 2) << QDate(1982, 12, 16)) - << (QVariantList() << QDate(1900, 12, 1) << QDate(1982, 12, 16) << QDate(2001, 2, 2) << QDate(2013, 3, 23)); - - QTest::newRow("mixed") << (QVariantList() << "Hello" << "World" << QChar('a') << 38 << QChar('z') << -39 << 4.6) - << (QVariantList() << -39 << 4.6 << 38 << QChar('a') << "Hello" << "World" << QChar('z')); - - QTest::newRow("custom") << (QVariantList() << QVariant::fromValue(CustomConvertibleType(1)) << QVariant::fromValue(CustomConvertibleType(100)) << QVariant::fromValue(CustomConvertibleType(50))) - << (QVariantList() << QVariant::fromValue(CustomConvertibleType(1)) << QVariant::fromValue(CustomConvertibleType(50)) << QVariant::fromValue(CustomConvertibleType(100))); -} - -void tst_QMetaType::compareCustomType() -{ - QFETCH(QVariantList, unsorted); - QFETCH(QVariantList, sorted); - std::sort(unsorted.begin(), unsorted.end()); - QCOMPARE(unsorted, sorted); -} - void tst_QMetaType::compareCustomEqualOnlyType() { int metaTypeId = qRegisterMetaType<CustomEqualsOnlyType>(); @@ -2487,11 +2421,6 @@ void tst_QMetaType::compareCustomEqualOnlyType() QCOMPARE(variant100, variant100x); QCOMPARE(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); @@ -2588,7 +2517,8 @@ void tst_QMetaType::fromType() QCOMPARE(QMetaType::fromType<RealType>(), QMetaType(MetaTypeId)); \ QVERIFY(QMetaType::fromType<RealType>() == QMetaType(MetaTypeId)); \ QVERIFY(!(QMetaType::fromType<RealType>() != QMetaType(MetaTypeId))); \ - QCOMPARE(QMetaType::fromType<RealType>().id(), MetaTypeId); + if (MetaTypeId != QMetaType::Void) \ + QCOMPARE(QMetaType::fromType<RealType>().id(), MetaTypeId); FOR_EACH_CORE_METATYPE(FROMTYPE_CHECK) @@ -2600,6 +2530,65 @@ void tst_QMetaType::fromType() #undef FROMTYPE_CHECK } +template<char X, typename T = void> +struct CharTemplate +{ + struct + { + int a; + } x; +}; + +void tst_QMetaType::operatorEq_data() +{ + QTest::addColumn<QMetaType>("typeA"); + QTest::addColumn<QMetaType>("typeB"); + QTest::addColumn<bool>("eq"); + + QTest::newRow("String") << QMetaType(QMetaType::QString) + << QMetaType::fromType<const QString &>() << true; + QTest::newRow("void1") << QMetaType(QMetaType::UnknownType) << QMetaType::fromType<void>() + << true; + QTest::newRow("void2") << QMetaType::fromType<const void>() << QMetaType::fromType<void>() + << true; + QTest::newRow("vec1") << QMetaType::fromType<QVector<const int *>>() + << QMetaType::fromType<QVector<const int *>>() << true; + QTest::newRow("vec2") << QMetaType::fromType<QVector<const int *>>() + << QMetaType::fromType<QVector<int *>>() << false; + QTest::newRow("char1") << QMetaType::fromType<CharTemplate<'>'>>() + << QMetaType::fromType<CharTemplate<'>', void>>() << true; + QTest::newRow("annon1") << QMetaType::fromType<decltype(CharTemplate<'>'>::x)>() + << QMetaType::fromType<decltype(CharTemplate<'>'>::x)>() << true; + QTest::newRow("annon2") << QMetaType::fromType<decltype(CharTemplate<'>'>::x)>() + << QMetaType::fromType<decltype(CharTemplate<'<'>::x)>() << false; +} + +void tst_QMetaType::operatorEq() +{ + QFETCH(QMetaType, typeA); + QFETCH(QMetaType, typeB); + QFETCH(bool, eq); + + QCOMPARE(typeA == typeB, eq); + QCOMPARE(typeB == typeA, eq); + QCOMPARE(typeA != typeB, !eq); + QCOMPARE(typeB != typeA, !eq); +} + +class WithPrivateDTor { + ~WithPrivateDTor(){}; +}; + +struct WithDeletedDtor { + ~WithDeletedDtor() = delete; +}; + +void tst_QMetaType::typesWithInaccessibleDTors() +{ + // should compile + Q_UNUSED(QMetaType::fromType<WithPrivateDTor>()); + Q_UNUSED(QMetaType::fromType<WithDeletedDtor>()); +} // Compile-time test, it should be possible to register function pointer types class Undefined; diff --git a/tests/auto/corelib/kernel/qmetatype/typeFlags.bin b/tests/auto/corelib/kernel/qmetatype/typeFlags.bin Binary files differindex 7009be98a2..0aa282efc9 100644 --- a/tests/auto/corelib/kernel/qmetatype/typeFlags.bin +++ b/tests/auto/corelib/kernel/qmetatype/typeFlags.bin diff --git a/tests/auto/corelib/kernel/qmimedata/CMakeLists.txt b/tests/auto/corelib/kernel/qmimedata/CMakeLists.txt new file mode 100644 index 0000000000..b4965302dd --- /dev/null +++ b/tests/auto/corelib/kernel/qmimedata/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qmimedata.pro. + +##################################################################### +## tst_qmimedata Test: +##################################################################### + +add_qt_test(tst_qmimedata + SOURCES + tst_qmimedata.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/corelib/kernel/qobject/CMakeLists.txt b/tests/auto/corelib/kernel/qobject/CMakeLists.txt new file mode 100644 index 0000000000..3be3287532 --- /dev/null +++ b/tests/auto/corelib/kernel/qobject/CMakeLists.txt @@ -0,0 +1,29 @@ +# Generated from qobject.pro. + +##################################################################### +## tst_qobject Test: +##################################################################### + +add_qt_test(tst_qobject + SOURCES + tst_qobject.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0 + LIBRARIES + Qt::CorePrivate + PUBLIC_LIBRARIES + Qt::Network +) + +#### Keys ignored in scope 3:.:.:test.pro:<TRUE>: +# CONFIG = "testcase" "console" + +## Scopes: +##################################################################### + +#### Keys ignored in scope 4:.:.:test.pro:QT_CONFIG___contains___c++1z: +# CONFIG = "c++1z" + +if(NOT WINRT) + add_subdirectory(signalbug) +endif() diff --git a/tests/auto/corelib/kernel/qobject/signalbug/CMakeLists.txt b/tests/auto/corelib/kernel/qobject/signalbug/CMakeLists.txt new file mode 100644 index 0000000000..e798028b1b --- /dev/null +++ b/tests/auto/corelib/kernel/qobject/signalbug/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from signalbug.pro. + +##################################################################### +## signalbug_helper Binary: +##################################################################### + +add_qt_test_helper(signalbug_helper + SOURCES + signalbug.cpp signalbug.h +) diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 63d06497ce..05599f9585 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -81,9 +81,6 @@ private slots: void senderTest(); void declareInterface(); void qpointerResetBeforeDestroyedSignal(); -#ifndef QT_NO_USERDATA - void testUserData(); -#endif void childDeletesItsSibling(); void dynamicProperties(); void floatProperty(); @@ -463,7 +460,7 @@ void tst_QObject::connectSlotsByName() sender.setObjectName("Sender"); QTest::ignoreMessage(QtWarningMsg, "QMetaObject::connectSlotsByName: No matching signal for on_child_signal()"); - QTest::ignoreMessage(QtWarningMsg, "QMetaObject::connectSlotsByName: Connecting slot on_Sender_signalManyParams() with the first of the following compatible signals: (\"signalManyParams(int,int,int,QString,bool)\", \"signalManyParams(int,int,int,QString,bool,bool)\")"); + QTest::ignoreMessage(QtWarningMsg, "QMetaObject::connectSlotsByName: Connecting slot on_Sender_signalManyParams() with the first of the following compatible signals: QVector(\"signalManyParams(int,int,int,QString,bool)\", \"signalManyParams(int,int,int,QString,bool,bool)\")"); QMetaObject::connectSlotsByName(&receiver); receiver.called_slots.clear(); @@ -1917,7 +1914,7 @@ void tst_QObject::property() property = mo->property(mo->indexOfProperty("alpha")); QVERIFY(property.isEnumType()); QCOMPARE(property.typeName(), "Alpha"); - QCOMPARE(property.type(), QVariant::Int); + QCOMPARE(property.userType(), QMetaType::fromType<PropertyObject::Alpha>().id()); QVariant var = object.property("alpha"); QVERIFY(!var.isNull()); @@ -1928,7 +1925,8 @@ void tst_QObject::property() QCOMPARE(object.property("alpha").toInt(), int(PropertyObject::Alpha2)); QVERIFY(object.setProperty("alpha", "Alpha1")); QCOMPARE(object.property("alpha").toInt(), int(PropertyObject::Alpha1)); - QVERIFY(!object.setProperty("alpha", QVariant())); + QVERIFY(object.setProperty("alpha", QVariant())); + QCOMPARE(object.property("alpha").toInt(), 0); QVERIFY(mo->indexOfProperty("number") != -1); QCOMPARE(object.property("number").toInt(), 0); @@ -1998,7 +1996,7 @@ void tst_QObject::property() property = mo->property(mo->indexOfProperty("priority")); QVERIFY(property.isEnumType()); QCOMPARE(property.typeName(), "Priority"); - QCOMPARE(property.type(), QVariant::Int); + QCOMPARE(property.userType(), QMetaType::fromType<PropertyObject::Priority>().id()); var = object.property("priority"); QVERIFY(!var.isNull()); @@ -2009,7 +2007,8 @@ void tst_QObject::property() QCOMPARE(object.property("priority").toInt(), int(PropertyObject::VeryHigh)); QVERIFY(object.setProperty("priority", "High")); QCOMPARE(object.property("priority").toInt(), int(PropertyObject::High)); - QVERIFY(!object.setProperty("priority", QVariant())); + QVERIFY(object.setProperty("priority", QVariant())); + QCOMPARE(object.property("priority").toInt(), 0); // now it's registered, so it works as expected int priorityMetaTypeId = qRegisterMetaType<PropertyObject::Priority>("PropertyObject::Priority"); @@ -2031,7 +2030,8 @@ void tst_QObject::property() QCOMPARE(qvariant_cast<PropertyObject::Priority>(object.property("priority")), PropertyObject::VeryHigh); QVERIFY(object.setProperty("priority", "High")); QCOMPARE(qvariant_cast<PropertyObject::Priority>(object.property("priority")), PropertyObject::High); - QVERIFY(!object.setProperty("priority", QVariant())); + QVERIFY(object.setProperty("priority", QVariant())); + QCOMPARE(object.property("priority").toInt(), 0); var = object.property("priority"); QCOMPARE(qvariant_cast<PropertyObject::Priority>(var), PropertyObject::High); @@ -2341,51 +2341,6 @@ void tst_QObject::declareInterface() } -#ifndef QT_NO_USERDATA -class CustomData : public QObjectUserData -{ -public: - int id; -}; - -void tst_QObject::testUserData() -{ - const int USER_DATA_COUNT = 100; - int user_data_ids[USER_DATA_COUNT]; - - // Register a few - for (int i=0; i<USER_DATA_COUNT; ++i) { - user_data_ids[i] = QObject::registerUserData(); - } - - // Randomize the table a bit - for (int i=0; i<100; ++i) { - int p1 = QRandomGenerator::global()->bounded(USER_DATA_COUNT); - int p2 = QRandomGenerator::global()->bounded(USER_DATA_COUNT); - - int tmp = user_data_ids[p1]; - user_data_ids[p1] = user_data_ids[p2]; - user_data_ids[p2] = tmp; - } - - // insert the user data into an object - QObject my_test_object; - for (int i=0; i<USER_DATA_COUNT; ++i) { - CustomData *data = new CustomData; - data->id = user_data_ids[i]; - my_test_object.setUserData(data->id, data); - } - - // verify that all ids and positions are matching - for (int i=0; i<USER_DATA_COUNT; ++i) { - int id = user_data_ids[i]; - CustomData *data = static_cast<CustomData *>(my_test_object.userData(id)); - QVERIFY(data != nullptr); - QCOMPARE(data->id, id); - } -} -#endif // QT_NO_USERDATA - class DestroyedListener : public QObject { Q_OBJECT @@ -6974,8 +6929,7 @@ void tst_QObject::noDeclarativeParentChangedOnDestruction() QObject *parent = new QObject; QObject *child = new QObject; - QAbstractDeclarativeDataImpl dummy; - dummy.ownedByQml1 = false; + QAbstractDeclarativeData dummy; QObjectPrivate::get(child)->declarativeData = &dummy; parentChangeCalled = false; diff --git a/tests/auto/corelib/kernel/qpointer/CMakeLists.txt b/tests/auto/corelib/kernel/qpointer/CMakeLists.txt new file mode 100644 index 0000000000..804a3a9def --- /dev/null +++ b/tests/auto/corelib/kernel/qpointer/CMakeLists.txt @@ -0,0 +1,18 @@ +# Generated from qpointer.pro. + +##################################################################### +## tst_qpointer Test: +##################################################################### + +add_qt_test(tst_qpointer + SOURCES + tst_qpointer.cpp +) + +## Scopes: +##################################################################### + +extend_target(tst_qpointer CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets +) diff --git a/tests/auto/corelib/kernel/qproperty/CMakeLists.txt b/tests/auto/corelib/kernel/qproperty/CMakeLists.txt new file mode 100644 index 0000000000..5521111ef8 --- /dev/null +++ b/tests/auto/corelib/kernel/qproperty/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qproperty.pro. + +##################################################################### +## tst_qproperty Test: +##################################################################### + +qt_add_test(tst_qproperty + SOURCES + tst_qproperty.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate +) diff --git a/tests/auto/corelib/kernel/qproperty/qproperty.pro b/tests/auto/corelib/kernel/qproperty/qproperty.pro new file mode 100644 index 0000000000..bae67e70a4 --- /dev/null +++ b/tests/auto/corelib/kernel/qproperty/qproperty.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qproperty +QT = core core-private testlib +SOURCES = tst_qproperty.cpp diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp new file mode 100644 index 0000000000..cc04c2f1b5 --- /dev/null +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -0,0 +1,683 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QObject> +#include <qtest.h> +#include <qproperty.h> +#include <private/qproperty_p.h> +#include <private/qpropertybinding_p.h> + +using namespace QtPrivate; + +class tst_QProperty : public QObject +{ + Q_OBJECT +private slots: + void functorBinding(); + void basicDependencies(); + void multipleDependencies(); + void bindingWithDeletedDependency(); + void recursiveDependency(); + void bindingAfterUse(); + void switchBinding(); + void avoidDependencyAllocationAfterFirstEval(); + void propertyArrays(); + void boolProperty(); + void takeBinding(); + void replaceBinding(); + void swap(); + void moveNotifies(); + void moveCtor(); + void changeHandler(); + void propertyChangeHandlerApi(); + void subscribe(); + void changeHandlerThroughBindings(); + void dontTriggerDependenciesIfUnchangedValue(); + void bindingSourceLocation(); + void bindingError(); + void bindingLoop(); + void changePropertyFromWithinChangeHandler(); + void changePropertyFromWithinChangeHandlerThroughDependency(); + void changePropertyFromWithinChangeHandler2(); + void settingPropertyValueDoesRemoveBinding(); + void genericPropertyBinding(); + void genericPropertyBindingBool(); + void staticChangeHandler(); +}; + +void tst_QProperty::functorBinding() +{ + QProperty<int> property([]() { return 42; }); + QCOMPARE(property.value(), int(42)); + property = Qt::makePropertyBinding([]() { return 100; }); + QCOMPARE(property.value(), int(100)); + property.setBinding([]() { return 50; }); + QCOMPARE(property.value(), int(50)); +} + +void tst_QProperty::basicDependencies() +{ + QProperty<int> right(100); + + QProperty<int> left = Qt::makePropertyBinding(right); + + QCOMPARE(left.value(), int(100)); + + right = 42; + + QCOMPARE(left.value(), int(42)); +} + +void tst_QProperty::multipleDependencies() +{ + QProperty<int> firstDependency(1); + QProperty<int> secondDependency(2); + + QProperty<int> sum; + sum = Qt::makePropertyBinding([&]() { return firstDependency + secondDependency; }); + + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 0); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 0); + + QCOMPARE(sum.value(), int(3)); + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + + firstDependency = 10; + + QCOMPARE(sum.value(), int(12)); + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + + secondDependency = 20; + + QCOMPARE(sum.value(), int(30)); + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); + + firstDependency = 1; + secondDependency = 1; + QCOMPARE(sum.value(), int(2)); + QCOMPARE(QPropertyBasePointer::get(firstDependency).observerCount(), 1); + QCOMPARE(QPropertyBasePointer::get(secondDependency).observerCount(), 1); +} + +void tst_QProperty::bindingWithDeletedDependency() +{ + QScopedPointer<QProperty<int>> dynamicProperty(new QProperty<int>(100)); + + QProperty<int> staticProperty(1000); + + QProperty<bool> bindingReturnsDynamicProperty(false); + + QProperty<int> propertySelector; + propertySelector = Qt::makePropertyBinding([&]() { + if (bindingReturnsDynamicProperty && !dynamicProperty.isNull()) + return dynamicProperty->value(); + else + return staticProperty.value(); + }); + + QCOMPARE(propertySelector.value(), staticProperty.value()); + + bindingReturnsDynamicProperty = true; + + QCOMPARE(propertySelector.value(), dynamicProperty->value()); + + dynamicProperty.reset(); + + QCOMPARE(propertySelector.value(), 100); + + bindingReturnsDynamicProperty = false; + + QCOMPARE(propertySelector.value(), staticProperty.value()); +} + +void tst_QProperty::recursiveDependency() +{ + QProperty<int> first(1); + + QProperty<int> second; + second = Qt::makePropertyBinding(first); + + QProperty<int> third; + third = Qt::makePropertyBinding(second); + + QCOMPARE(third.value(), int(1)); + + first = 2; + + QCOMPARE(third.value(), int(2)); +} + +void tst_QProperty::bindingAfterUse() +{ + QProperty<int> propWithBindingLater(1); + + QProperty<int> propThatUsesFirstProp; + propThatUsesFirstProp = Qt::makePropertyBinding(propWithBindingLater); + + QCOMPARE(propThatUsesFirstProp.value(), int(1)); + QCOMPARE(QPropertyBasePointer::get(propWithBindingLater).observerCount(), 1); + + QProperty<int> injectedValue(42); + propWithBindingLater = Qt::makePropertyBinding(injectedValue); + + QCOMPARE(propThatUsesFirstProp.value(), int(42)); + QCOMPARE(QPropertyBasePointer::get(propWithBindingLater).observerCount(), 1); +} + +void tst_QProperty::switchBinding() +{ + QProperty<int> first(1); + + QProperty<int> propWithChangingBinding; + propWithChangingBinding = Qt::makePropertyBinding(first); + + QCOMPARE(propWithChangingBinding.value(), 1); + + QProperty<int> output; + output = Qt::makePropertyBinding(propWithChangingBinding); + QCOMPARE(output.value(), 1); + + QProperty<int> second(2); + propWithChangingBinding = Qt::makePropertyBinding(second); + QCOMPARE(output.value(), 2); +} + +void tst_QProperty::avoidDependencyAllocationAfterFirstEval() +{ + QProperty<int> firstDependency(1); + QProperty<int> secondDependency(10); + + QProperty<int> propWithBinding; + propWithBinding = Qt::makePropertyBinding([&]() { return firstDependency + secondDependency; }); + + QCOMPARE(propWithBinding.value(), int(11)); + + QVERIFY(QPropertyBasePointer::get(propWithBinding).bindingPtr()); + QCOMPARE(QPropertyBasePointer::get(propWithBinding).bindingPtr()->dependencyObserverCount, 2); + + firstDependency = 100; + QCOMPARE(propWithBinding.value(), int(110)); + QCOMPARE(QPropertyBasePointer::get(propWithBinding).bindingPtr()->dependencyObserverCount, 2); +} + +void tst_QProperty::propertyArrays() +{ + std::vector<QProperty<int>> properties; + + int expectedSum = 0; + for (int i = 0; i < 10; ++i) { + properties.emplace_back(i); + expectedSum += i; + } + + QProperty<int> sum; + sum = Qt::makePropertyBinding([&]() { + return std::accumulate(properties.begin(), properties.end(), 0); + }); + + QCOMPARE(sum.value(), expectedSum); + + properties[4] = properties[4] + 42; + expectedSum += 42; + QCOMPARE(sum.value(), expectedSum); +} + +void tst_QProperty::boolProperty() +{ + static_assert(sizeof(QProperty<bool>) == sizeof(void*), "Size of QProperty<bool> specialization must not exceed size of pointer"); + + QProperty<bool> first(true); + QProperty<bool> second(false); + QProperty<bool> all; + all = Qt::makePropertyBinding([&]() { return first && second; }); + + QCOMPARE(all.value(), false); + + second = true; + + QCOMPARE(all.value(), true); +} + +void tst_QProperty::takeBinding() +{ + QPropertyBinding<int> existingBinding; + QVERIFY(existingBinding.isNull()); + + QProperty<int> first(100); + QProperty<int> second = Qt::makePropertyBinding(first); + + QCOMPARE(second.value(), int(100)); + + existingBinding = second.takeBinding(); + QVERIFY(!existingBinding.isNull()); + + first = 10; + QCOMPARE(second.value(), int(100)); + + second = 25; + QCOMPARE(second.value(), int(25)); + + second = existingBinding; + QCOMPARE(second.value(), int(10)); + QVERIFY(!existingBinding.isNull()); +} + +void tst_QProperty::replaceBinding() +{ + QProperty<int> first(100); + QProperty<int> second = Qt::makePropertyBinding(first); + + QCOMPARE(second.value(), 100); + + auto constantBinding = Qt::makePropertyBinding([]() { return 42; }); + auto oldBinding = second.setBinding(constantBinding); + QCOMPARE(second.value(), 42); + + second = oldBinding; + QCOMPARE(second.value(), 100); +} + +void tst_QProperty::swap() +{ + QProperty<int> firstDependency(1); + QProperty<int> secondDependency(2); + + QProperty<int> first = Qt::makePropertyBinding(firstDependency); + QProperty<int> second = Qt::makePropertyBinding(secondDependency); + + QCOMPARE(first.value(), 1); + QCOMPARE(second.value(), 2); + + std::swap(first, second); + + QCOMPARE(first.value(), 2); + QCOMPARE(second.value(), 1); + + secondDependency = 20; + QCOMPARE(first.value(), 20); + QCOMPARE(second.value(), 1); + + firstDependency = 100; + QCOMPARE(first.value(), 20); + QCOMPARE(second.value(), 100); +} + +void tst_QProperty::moveNotifies() +{ + QProperty<int> first(1); + QProperty<int> second(2); + + QProperty<int> propertyInTheMiddle = Qt::makePropertyBinding(first); + + QProperty<int> finalProp1 = Qt::makePropertyBinding(propertyInTheMiddle); + QProperty<int> finalProp2 = Qt::makePropertyBinding(propertyInTheMiddle); + + QCOMPARE(finalProp1.value(), 1); + QCOMPARE(finalProp2.value(), 1); + + QCOMPARE(QPropertyBasePointer::get(propertyInTheMiddle).observerCount(), 2); + + QProperty<int> other = Qt::makePropertyBinding(second); + QCOMPARE(other.value(), 2); + + QProperty<int> otherDep = Qt::makePropertyBinding(other); + QCOMPARE(otherDep.value(), 2); + QCOMPARE(QPropertyBasePointer::get(other).observerCount(), 1); + + propertyInTheMiddle = std::move(other); + + QCOMPARE(QPropertyBasePointer::get(other).observerCount(), 0); + + QCOMPARE(finalProp1.value(), 2); + QCOMPARE(finalProp2.value(), 2); +} + +void tst_QProperty::moveCtor() +{ + QProperty<int> first(1); + + QProperty<int> intermediate = Qt::makePropertyBinding(first); + QCOMPARE(intermediate.value(), 1); + QCOMPARE(QPropertyBasePointer::get(first).observerCount(), 1); + + QProperty<int> targetProp(std::move(first)); + + QCOMPARE(QPropertyBasePointer::get(targetProp).observerCount(), 0); +} + +void tst_QProperty::changeHandler() +{ + QProperty<int> testProperty(0); + QVector<int> recordedValues; + + { + auto handler = testProperty.onValueChanged([&]() { + recordedValues << testProperty; + }); + + testProperty = 1; + testProperty = 2; + } + testProperty = 3; + + QCOMPARE(recordedValues.count(), 2); + QCOMPARE(recordedValues.at(0), 1); + QCOMPARE(recordedValues.at(1), 2); +} + +void tst_QProperty::propertyChangeHandlerApi() +{ + int changeHandlerCallCount = 0; + QPropertyChangeHandler handler([&changeHandlerCallCount]() { + ++changeHandlerCallCount; + }); + + QProperty<int> source1; + QProperty<int> source2; + + handler.setSource(source1); + + source1 = 100; + QCOMPARE(changeHandlerCallCount, 1); + + handler.setSource(source2); + source1 = 101; + QCOMPARE(changeHandlerCallCount, 1); + + source2 = 200; + QCOMPARE(changeHandlerCallCount, 2); +} + +void tst_QProperty::subscribe() +{ + QProperty<int> testProperty(42); + QVector<int> recordedValues; + + { + auto handler = testProperty.subscribe([&]() { + recordedValues << testProperty; + }); + + testProperty = 1; + testProperty = 2; + } + testProperty = 3; + + QCOMPARE(recordedValues.count(), 3); + QCOMPARE(recordedValues.at(0), 42); + QCOMPARE(recordedValues.at(1), 1); + QCOMPARE(recordedValues.at(2), 2); +} + +void tst_QProperty::changeHandlerThroughBindings() +{ + QProperty<bool> trigger(false); + QProperty<bool> blockTrigger(false); + QProperty<bool> condition = Qt::makePropertyBinding([&]() { + bool triggerValue = trigger; + bool blockTriggerValue = blockTrigger; + return triggerValue && !blockTriggerValue; + }); + bool changeHandlerCalled = false; + auto handler = condition.onValueChanged([&]() { + changeHandlerCalled = true; + }); + + QVERIFY(!condition); + QVERIFY(!changeHandlerCalled); + + trigger = true; + + QVERIFY(condition); + QVERIFY(changeHandlerCalled); + changeHandlerCalled = false; + + trigger = false; + + QVERIFY(!condition); + QVERIFY(changeHandlerCalled); + changeHandlerCalled = false; + + blockTrigger = true; + + QVERIFY(!condition); + QVERIFY(!changeHandlerCalled); +} + +void tst_QProperty::dontTriggerDependenciesIfUnchangedValue() +{ + QProperty<int> property(42); + + bool triggered = false; + QProperty<int> observer = Qt::makePropertyBinding([&]() { triggered = true; return property.value(); }); + + QCOMPARE(observer.value(), 42); + QVERIFY(triggered); + triggered = false; + property = 42; + QCOMPARE(observer.value(), 42); + QVERIFY(!triggered); +} + +void tst_QProperty::bindingSourceLocation() +{ +#if defined(QT_PROPERTY_COLLECT_BINDING_LOCATION) + auto bindingLine = std::experimental::source_location::current().line() + 1; + auto binding = Qt::makePropertyBinding([]() { return 42; }); + QCOMPARE(QPropertyBindingPrivate::get(binding)->sourceLocation().line, bindingLine); +#else + QSKIP("Skipping this in the light of missing binding source location support"); +#endif +} + +void tst_QProperty::bindingError() +{ + QProperty<int> prop = Qt::makePropertyBinding([]() -> std::variant<int, QPropertyBindingError> { + QPropertyBindingError error(QPropertyBindingError::UnknownError); + error.setDescription(QLatin1String("my error")); + return error; + }); + QCOMPARE(prop.value(), 0); + QCOMPARE(prop.binding().error().description(), QString("my error")); +} + +void tst_QProperty::bindingLoop() +{ + QScopedPointer<QProperty<int>> firstProp; + + QProperty<int> secondProp = Qt::makePropertyBinding([&]() -> int { + return firstProp ? firstProp->value() : 0; + }); + + QProperty<int> thirdProp = Qt::makePropertyBinding([&]() -> int { + return secondProp.value(); + }); + + firstProp.reset(new QProperty<int>()); + *firstProp = Qt::makePropertyBinding([&]() -> int { + return secondProp.value(); + }); + + QCOMPARE(thirdProp.value(), 0); + QCOMPARE(secondProp.binding().error().type(), QPropertyBindingError::BindingLoop); +} + +void tst_QProperty::changePropertyFromWithinChangeHandler() +{ + QProperty<int> property(100); + bool resetPropertyOnChange = false; + int changeHandlerCallCount = 0; + + auto handler = property.onValueChanged([&]() { + ++changeHandlerCallCount; + if (resetPropertyOnChange) + property = 100; + }); + + QCOMPARE(property.value(), 100); + + resetPropertyOnChange = true; + property = 42; + QCOMPARE(property.value(), 100); + // changing the property value inside the change handler won't result in the change + // handler being called again. + QCOMPARE(changeHandlerCallCount, 1); + changeHandlerCallCount = 0; +} + +void tst_QProperty::changePropertyFromWithinChangeHandlerThroughDependency() +{ + QProperty<int> sourceProperty(100); + QProperty<int> property = Qt::makePropertyBinding(sourceProperty); + bool resetPropertyOnChange = false; + int changeHandlerCallCount = 0; + + auto handler = property.onValueChanged([&]() { + ++changeHandlerCallCount; + if (resetPropertyOnChange) + sourceProperty = 100; + }); + + QCOMPARE(property.value(), 100); + + resetPropertyOnChange = true; + sourceProperty = 42; + QCOMPARE(property.value(), 100); + // changing the property value inside the change handler won't result in the change + // handler being called again. + QCOMPARE(changeHandlerCallCount, 1); + changeHandlerCallCount = 0; +} + +void tst_QProperty::changePropertyFromWithinChangeHandler2() +{ + QProperty<int> property(100); + int changeHandlerCallCount = 0; + + auto handler = property.onValueChanged([&]() { + ++changeHandlerCallCount; + property = property.value() + 1; + }); + + QCOMPARE(property.value(), 100); + + property = 42; + QCOMPARE(property.value(), 43); +} + +void tst_QProperty::settingPropertyValueDoesRemoveBinding() +{ + QProperty<int> source(42); + + QProperty<int> property = Qt::makePropertyBinding(source); + + QCOMPARE(property.value(), 42); + QVERIFY(!property.binding().isNull()); + + property = 100; + QCOMPARE(property.value(), 100); + QVERIFY(property.binding().isNull()); + + source = 1; + QCOMPARE(property.value(), 100); + QVERIFY(property.binding().isNull()); +} + +void tst_QProperty::genericPropertyBinding() +{ + QProperty<int> property; + + { + QUntypedPropertyBinding doubleBinding(QMetaType::fromType<double>(), + [](const QMetaType &, void *) -> bool { + Q_ASSERT(false); + return false; + }, QPropertyBindingSourceLocation()); + QVERIFY(!property.setBinding(doubleBinding)); + } + + QUntypedPropertyBinding intBinding(QMetaType::fromType<int>(), + [](const QMetaType &metaType, void *dataPtr) -> bool { + Q_ASSERT(metaType.id() == qMetaTypeId<int>()); + + int *intPtr = reinterpret_cast<int*>(dataPtr); + if (*intPtr == 100) + return false; + *intPtr = 100; + return true; + }, QPropertyBindingSourceLocation()); + + QVERIFY(property.setBinding(intBinding)); + + QCOMPARE(property.value(), 100); +} + +void tst_QProperty::genericPropertyBindingBool() +{ + QProperty<bool> property; + + QVERIFY(!property.value()); + + QUntypedPropertyBinding boolBinding(QMetaType::fromType<bool>(), + [](const QMetaType &, void *dataPtr) -> bool { + auto boolPtr = reinterpret_cast<bool *>(dataPtr); + if (*boolPtr) + return false; + *boolPtr = true; + return true; + }, QPropertyBindingSourceLocation()); + QVERIFY(property.setBinding(boolBinding)); + + QVERIFY(property.value()); +} + +struct ItemType +{ + QProperty<int> x; + QVector<int> observedValues; + void xChanged() { + observedValues << x.value(); + } + QPropertyMemberChangeHandler<&ItemType::x, &ItemType::xChanged> test{this}; +}; + +void tst_QProperty::staticChangeHandler() +{ + ItemType t; + t.x = 42; + t.x = 100; + QVector<int> values{42, 100}; + QCOMPARE(t.observedValues, values); +} + +QTEST_MAIN(tst_QProperty); + +#include "tst_qproperty.moc" diff --git a/tests/auto/corelib/kernel/qsharedmemory/CMakeLists.txt b/tests/auto/corelib/kernel/qsharedmemory/CMakeLists.txt new file mode 100644 index 0000000000..366e76d034 --- /dev/null +++ b/tests/auto/corelib/kernel/qsharedmemory/CMakeLists.txt @@ -0,0 +1,30 @@ +# Generated from qsharedmemory.pro. + + +if(QT_FEATURE_sharedmemory) + ##################################################################### + ## tst_qsharedmemory Test: + ##################################################################### + + add_qt_test(tst_qsharedmemory + SOURCES + tst_qsharedmemory.cpp + LIBRARIES + Qt::CorePrivate + ) + +#### Keys ignored in scope 4:.:.:test.pro:<TRUE>: + # CONFIG = "testcase" + + ## Scopes: + ##################################################################### + + extend_target(tst_qsharedmemory CONDITION LINUX + PUBLIC_LIBRARIES + rt + ) + + if(NOT WINRT) + add_subdirectory(producerconsumer) + endif() +endif() diff --git a/tests/auto/corelib/kernel/qsharedmemory/producerconsumer/CMakeLists.txt b/tests/auto/corelib/kernel/qsharedmemory/producerconsumer/CMakeLists.txt new file mode 100644 index 0000000000..2e16a673b1 --- /dev/null +++ b/tests/auto/corelib/kernel/qsharedmemory/producerconsumer/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from producerconsumer.pro. + +##################################################################### +## producerconsumer_helper Binary: +##################################################################### + +add_qt_test_helper(producerconsumer_helper + SOURCES + main.cpp + PUBLIC_LIBRARIES + Qt::Test +) diff --git a/tests/auto/corelib/kernel/qsignalblocker/CMakeLists.txt b/tests/auto/corelib/kernel/qsignalblocker/CMakeLists.txt new file mode 100644 index 0000000000..ae86137c94 --- /dev/null +++ b/tests/auto/corelib/kernel/qsignalblocker/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qsignalblocker.pro. + +##################################################################### +## tst_qsignalblocker Test: +##################################################################### + +add_qt_test(tst_qsignalblocker + SOURCES + tst_qsignalblocker.cpp +) diff --git a/tests/auto/corelib/kernel/qsignalmapper/CMakeLists.txt b/tests/auto/corelib/kernel/qsignalmapper/CMakeLists.txt new file mode 100644 index 0000000000..1360e76ea1 --- /dev/null +++ b/tests/auto/corelib/kernel/qsignalmapper/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qsignalmapper.pro. + +##################################################################### +## tst_qsignalmapper Test: +##################################################################### + +add_qt_test(tst_qsignalmapper + SOURCES + tst_qsignalmapper.cpp +) diff --git a/tests/auto/corelib/kernel/qsocketnotifier/CMakeLists.txt b/tests/auto/corelib/kernel/qsocketnotifier/CMakeLists.txt new file mode 100644 index 0000000000..cb847dc503 --- /dev/null +++ b/tests/auto/corelib/kernel/qsocketnotifier/CMakeLists.txt @@ -0,0 +1,38 @@ +# Generated from qsocketnotifier.pro. + +if(NOT QT_FEATURE_private_tests) + return() +endif() + +##################################################################### +## tst_qsocketnotifier Test: +##################################################################### + +add_qt_test(tst_qsocketnotifier + SOURCES + tst_qsocketnotifier.cpp + INCLUDE_DIRECTORIES + ${QT_SOURCE_TREE}/src/network + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Network + Qt::NetworkPrivate +) + +#### Keys ignored in scope 1:.:.:qsocketnotifier.pro:<TRUE>: +# _REQUIREMENTS = "qtConfig(private_tests)" + +## Scopes: +##################################################################### + +extend_target(tst_qsocketnotifier CONDITION WIN32 + PUBLIC_LIBRARIES + ws2_32 +) + +extend_target(tst_qsocketnotifier CONDITION QT_FEATURE_reduce_exports AND UNIX + SOURCES + ${QT_SOURCE_TREE}/src/network/socket/qabstractsocketengine.cpp ${QT_SOURCE_TREE}/src/network/socket/qabstractsocketengine_p.h + ${QT_SOURCE_TREE}/src/network/socket/qnativesocketengine.cpp ${QT_SOURCE_TREE}/src/network/socket/qnativesocketengine_p.h + ${QT_SOURCE_TREE}/src/network/socket/qnativesocketengine_unix.cpp +) diff --git a/tests/auto/corelib/kernel/qsystemsemaphore/CMakeLists.txt b/tests/auto/corelib/kernel/qsystemsemaphore/CMakeLists.txt new file mode 100644 index 0000000000..1e6889eec0 --- /dev/null +++ b/tests/auto/corelib/kernel/qsystemsemaphore/CMakeLists.txt @@ -0,0 +1,20 @@ +# Generated from qsystemsemaphore.pro. + +add_subdirectory(acquirerelease) +##################################################################### +## tst_qsystemsemaphore Test: +##################################################################### + +add_qt_test(tst_qsystemsemaphore + SOURCES + tst_qsystemsemaphore.cpp +) + +#### Keys ignored in scope 2:.:.:test.pro:<TRUE>: +# CONFIG = "testcase" + +## Scopes: +##################################################################### + +#### Keys ignored in scope 3:.:.:test.pro:WIN32: +# CONFIG = "console" diff --git a/tests/auto/corelib/kernel/qsystemsemaphore/acquirerelease/CMakeLists.txt b/tests/auto/corelib/kernel/qsystemsemaphore/acquirerelease/CMakeLists.txt new file mode 100644 index 0000000000..ddce7297d2 --- /dev/null +++ b/tests/auto/corelib/kernel/qsystemsemaphore/acquirerelease/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from acquirerelease.pro. + +##################################################################### +## acquirerelease_helper Binary: +##################################################################### + +add_qt_test_helper(acquirerelease_helper + SOURCES + main.cpp + PUBLIC_LIBRARIES + Qt::Test +) diff --git a/tests/auto/corelib/kernel/qtimer/CMakeLists.txt b/tests/auto/corelib/kernel/qtimer/CMakeLists.txt new file mode 100644 index 0000000000..84585751ac --- /dev/null +++ b/tests/auto/corelib/kernel/qtimer/CMakeLists.txt @@ -0,0 +1,15 @@ +# Generated from qtimer.pro. + +##################################################################### +## tst_qtimer Test: +##################################################################### + +add_qt_test(tst_qtimer + SOURCES + tst_qtimer.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate +) + +## Scopes: +##################################################################### diff --git a/tests/auto/corelib/kernel/qtranslator/CMakeLists.txt b/tests/auto/corelib/kernel/qtranslator/CMakeLists.txt new file mode 100644 index 0000000000..79e44bc928 --- /dev/null +++ b/tests/auto/corelib/kernel/qtranslator/CMakeLists.txt @@ -0,0 +1,47 @@ +# Generated from qtranslator.pro. + +##################################################################### +## tst_qtranslator Test: +##################################################################### + +add_qt_test(tst_qtranslator + SOURCES + tst_qtranslator.cpp +) + +# Resources: +set(qtranslator_resource_files + "hellotr_empty.qm" + "hellotr_la.qm" +) + +add_qt_resource(tst_qtranslator "qtranslator" + PREFIX + "/tst_qtranslator" + FILES + ${qtranslator_resource_files} +) + + +## Scopes: +##################################################################### + +if(ANDROID AND NOT ANDROID_EMBEDDED) + # Resources: + set(android_testdata_resource_files + "dependencies_la.qm" + "hellotr_empty.qm" + "hellotr_la.qm" + "msgfmt_from_po.qm" + ) + + add_qt_resource(tst_qtranslator "android_testdata" + PREFIX + "/android_testdata" + FILES + ${android_testdata_resource_files} + ) +endif() + +#### Keys ignored in scope 3:.:.:qtranslator.pro:else: +# TESTDATA = "dependencies_la.qm" "hellotr_empty.qm" "hellotr_la.qm" "msgfmt_from_po.qm" diff --git a/tests/auto/corelib/kernel/qvariant/.prev_CMakeLists.txt b/tests/auto/corelib/kernel/qvariant/.prev_CMakeLists.txt new file mode 100644 index 0000000000..bdf2e2f461 --- /dev/null +++ b/tests/auto/corelib/kernel/qvariant/.prev_CMakeLists.txt @@ -0,0 +1,38 @@ +# Generated from qvariant.pro. + +##################################################################### +## tst_qvariant Test: +##################################################################### + +add_qt_test(tst_qvariant + SOURCES + tst_qvariant.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0 + INCLUDE_DIRECTORIES + ../../../other/qvariant_common + PUBLIC_LIBRARIES + Qt::CorePrivate +) + +# Resources: +set(qvariant_resource_files + "stream/qt4.9/" + "stream/qt5.0/" +) + +add_qt_resource(tst_qvariant "qvariant" + PREFIX + "/" + FILES + ${qvariant_resource_files} +) + + +## Scopes: +##################################################################### + +extend_target(tst_qvariant CONDITION NOT QT_FEATURE_doubleconversion AND NOT QT_FEATURE_system_doubleconversion + DEFINES + QT_NO_DOUBLECONVERSION +) diff --git a/tests/auto/corelib/kernel/qvariant/CMakeLists.txt b/tests/auto/corelib/kernel/qvariant/CMakeLists.txt new file mode 100644 index 0000000000..bdf2e2f461 --- /dev/null +++ b/tests/auto/corelib/kernel/qvariant/CMakeLists.txt @@ -0,0 +1,38 @@ +# Generated from qvariant.pro. + +##################################################################### +## tst_qvariant Test: +##################################################################### + +add_qt_test(tst_qvariant + SOURCES + tst_qvariant.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0 + INCLUDE_DIRECTORIES + ../../../other/qvariant_common + PUBLIC_LIBRARIES + Qt::CorePrivate +) + +# Resources: +set(qvariant_resource_files + "stream/qt4.9/" + "stream/qt5.0/" +) + +add_qt_resource(tst_qvariant "qvariant" + PREFIX + "/" + FILES + ${qvariant_resource_files} +) + + +## Scopes: +##################################################################### + +extend_target(tst_qvariant CONDITION NOT QT_FEATURE_doubleconversion AND NOT QT_FEATURE_system_doubleconversion + DEFINES + QT_NO_DOUBLECONVERSION +) diff --git a/tests/auto/corelib/kernel/qvariant/qvariant.pro b/tests/auto/corelib/kernel/qvariant/qvariant.pro index 0b5280df86..a620be0091 100644 --- a/tests/auto/corelib/kernel/qvariant/qvariant.pro +++ b/tests/auto/corelib/kernel/qvariant/qvariant.pro @@ -5,7 +5,6 @@ INCLUDEPATH += $$PWD/../../../other/qvariant_common SOURCES = tst_qvariant.cpp RESOURCES += qvariant.qrc DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 -DEFINES -= QT_NO_LINKED_LIST qtConfig(c++14): CONFIG += c++14 qtConfig(c++1z): CONFIG += c++1z !qtConfig(doubleconversion):!qtConfig(system-doubleconversion) { diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 86c61cba12..86465d25fb 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -49,7 +49,6 @@ #if __has_include(<variant>) && __cplusplus >= 201703L #include <variant> #endif -#include <QLinkedList> #include <QRegularExpression> #include <QDir> #include <QBuffer> @@ -190,8 +189,6 @@ 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(); @@ -270,9 +267,6 @@ private slots: void enums(); void metaEnums(); - void compareSanity_data(); - void compareSanity(); - void compareRich(); void nullConvert(); @@ -355,13 +349,13 @@ void tst_QVariant::constructor_invalid() QFETCH(uint, typeId); { - QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type")); QVariant variant(static_cast<QVariant::Type>(typeId)); QVERIFY(!variant.isValid()); QCOMPARE(variant.userType(), int(QMetaType::UnknownType)); } { - QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:")); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type")); QVariant variant(typeId, /* copy */ 0); QVERIFY(!variant.isValid()); QCOMPARE(variant.userType(), int(QMetaType::UnknownType)); @@ -1439,10 +1433,7 @@ void tst_QVariant::checkDataStream() const int typeId = QMetaType::LastCoreType + 1; QVERIFY(!QMetaType::isRegistered(typeId)); - QByteArray errorMessage("Trying to construct an instance of an invalid type, type id: "); - errorMessage.append(QString::number(typeId, 10)); - - QTest::ignoreMessage(QtWarningMsg, errorMessage.constData()); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type")); QByteArray settingsHex("000000"); settingsHex.append(QString::number(typeId, 16)); settingsHex.append("ffffffffff"); @@ -1732,344 +1723,6 @@ 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") << QVariant::fromValue(char(0)) << QVariant::fromValue(char(0)) << 0; - QTest::newRow("char2") << QVariant::fromValue(CHAR_MAX) << QVariant::fromValue(CHAR_MAX) << 0; - QTest::newRow("char3") << QVariant::fromValue(CHAR_MIN) << QVariant::fromValue(CHAR_MIN) << 0; - QTest::newRow("char4") << QVariant::fromValue(CHAR_MIN) << QVariant::fromValue(CHAR_MAX) << -1; - QTest::newRow("char5") << QVariant::fromValue(CHAR_MAX) << QVariant::fromValue(CHAR_MIN) << +1; - - QTest::newRow("schar1") << QVariant::fromValue(schar(0)) << QVariant::fromValue(schar(0)) << 0; - QTest::newRow("schar2") << QVariant::fromValue(SCHAR_MAX) << QVariant::fromValue(SCHAR_MAX) << 0; - QTest::newRow("schar3") << QVariant::fromValue(SCHAR_MIN) << QVariant::fromValue(SCHAR_MIN) << 0; - QTest::newRow("schar4") << QVariant::fromValue(SCHAR_MIN) << QVariant::fromValue(SCHAR_MAX) << -1; - QTest::newRow("schar5") << QVariant::fromValue(SCHAR_MAX) << QVariant::fromValue(SCHAR_MIN) << +1; - - QTest::newRow("uchar1") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(uchar(0)) << 0; - QTest::newRow("uchar2") << QVariant::fromValue(UCHAR_MAX) << QVariant::fromValue(UCHAR_MAX) << 0; - QTest::newRow("uchar3") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(UCHAR_MAX) << -1; - QTest::newRow("uchar4") << QVariant::fromValue(UCHAR_MAX) << QVariant::fromValue(uchar(0)) << +1; - - QTest::newRow("short1") << QVariant::fromValue(short(0)) << QVariant::fromValue(short(0)) << 0; - QTest::newRow("short2") << QVariant::fromValue(SHRT_MAX) << QVariant::fromValue(SHRT_MAX) << 0; - QTest::newRow("short3") << QVariant::fromValue(SHRT_MIN) << QVariant::fromValue(SHRT_MIN) << 0; - QTest::newRow("short4") << QVariant::fromValue(SHRT_MIN) << QVariant::fromValue(SHRT_MAX) << -1; - QTest::newRow("short5") << QVariant::fromValue(SHRT_MAX) << QVariant::fromValue(SHRT_MIN) << +1; - - QTest::newRow("ushort1") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(ushort(0)) << 0; - QTest::newRow("ushort2") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(USHRT_MAX) << 0; - QTest::newRow("ushort3") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(USHRT_MAX) << -1; - QTest::newRow("ushort4") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(ushort(0)) << +1; - - QTest::newRow("int1") << QVariant::fromValue(int(0)) << QVariant::fromValue(int(0)) << 0; - QTest::newRow("int2") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(INT_MAX) << 0; - QTest::newRow("int3") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(INT_MIN) << 0; - QTest::newRow("int4") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(INT_MAX) << -1; - QTest::newRow("int5") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(INT_MIN) << +1; - - QTest::newRow("uint1") << QVariant::fromValue(uint(0)) << QVariant::fromValue(uint(0)) << 0; - QTest::newRow("uint2") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(UINT_MAX) << 0; - QTest::newRow("uint3") << QVariant::fromValue(uint(0)) << QVariant::fromValue(UINT_MAX) << -1; - QTest::newRow("uint4") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(uint(0)) << +1; - - QTest::newRow("long1") << QVariant::fromValue(long(0)) << QVariant::fromValue(long(0)) << 0; - QTest::newRow("long2") << QVariant::fromValue(LONG_MAX) << QVariant::fromValue(LONG_MAX) << 0; - QTest::newRow("long3") << QVariant::fromValue(LONG_MIN) << QVariant::fromValue(LONG_MIN) << 0; - QTest::newRow("long4") << QVariant::fromValue(LONG_MIN) << QVariant::fromValue(LONG_MAX) << -1; - QTest::newRow("long5") << QVariant::fromValue(LONG_MAX) << QVariant::fromValue(LONG_MIN) << +1; - - QTest::newRow("ulong1") << QVariant::fromValue(ulong(0)) << QVariant::fromValue(ulong(0)) << 0; - QTest::newRow("ulong2") << QVariant::fromValue(ULONG_MAX) << QVariant::fromValue(ULONG_MAX) << 0; - QTest::newRow("ulong3") << QVariant::fromValue(ulong(0)) << QVariant::fromValue(ULONG_MAX) << -1; - QTest::newRow("ulong4") << QVariant::fromValue(ULONG_MAX) << QVariant::fromValue(ulong(0)) << +1; - - QTest::newRow("llong1") << QVariant::fromValue(qlonglong(0)) << QVariant::fromValue(qlonglong(0)) << 0; - QTest::newRow("llong2") << QVariant::fromValue(LLONG_MAX) << QVariant::fromValue(LLONG_MAX) << 0; - QTest::newRow("llong3") << QVariant::fromValue(LLONG_MIN) << QVariant::fromValue(LLONG_MIN) << 0; - QTest::newRow("llong4") << QVariant::fromValue(LLONG_MIN) << QVariant::fromValue(LLONG_MAX) << -1; - QTest::newRow("llong5") << QVariant::fromValue(LLONG_MAX) << QVariant::fromValue(LLONG_MIN) << +1; - - QTest::newRow("ullong1") << QVariant::fromValue(qulonglong(0)) << QVariant::fromValue(qulonglong(0)) << 0; - QTest::newRow("ullong2") << QVariant::fromValue(ULLONG_MAX) << QVariant::fromValue(ULLONG_MAX) << 0; - QTest::newRow("ullong3") << QVariant::fromValue(qulonglong(0)) << QVariant::fromValue(ULLONG_MAX) << -1; - QTest::newRow("ullong4") << QVariant::fromValue(ULLONG_MAX) << QVariant::fromValue(qulonglong(0)) << +1; - - QTest::newRow("float1") << QVariant::fromValue(0.f) << QVariant::fromValue(0.f) << 0; - QTest::newRow("float2") << QVariant::fromValue(-1.f) << QVariant::fromValue(0.f) << -1; - QTest::newRow("float3") << QVariant::fromValue(0.f) << QVariant::fromValue(-1.f) << +1; - QTest::newRow("float4") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(0.f) << -1; - QTest::newRow("float5") << QVariant::fromValue(0.f) << QVariant::fromValue(-float(qInf())) << +1; - QTest::newRow("float6") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(-float(qInf())) << 0; - QTest::newRow("float7") << QVariant::fromValue(float(qInf())) << QVariant::fromValue(float(qInf())) << 0; - - QTest::newRow("double1") << QVariant::fromValue(0.) << QVariant::fromValue(0.) << 0; - QTest::newRow("double2") << QVariant::fromValue(-1.) << QVariant::fromValue(0.) << -1; - QTest::newRow("double3") << QVariant::fromValue(0.) << QVariant::fromValue(-1.) << +1; - QTest::newRow("double4") << QVariant::fromValue(-qInf()) << QVariant::fromValue(0.) << -1; - QTest::newRow("double5") << QVariant::fromValue(0.) << QVariant::fromValue(-qInf()) << +1; - QTest::newRow("double6") << QVariant::fromValue(-double(qInf())) << QVariant::fromValue(-qInf()) << 0; - QTest::newRow("double7") << QVariant::fromValue(qInf()) << QVariant::fromValue(qInf()) << 0; - QTest::newRow("double8") << QVariant::fromValue(-qInf()) << QVariant::fromValue(qInf()) << -1; - QTest::newRow("double9") << QVariant::fromValue(qQNaN()) << QVariant::fromValue(0.) << INT_MAX; - QTest::newRow("double10") << QVariant::fromValue(0.) << QVariant::fromValue(qQNaN()) << INT_MAX; - QTest::newRow("double11") << QVariant::fromValue(qQNaN()) << QVariant::fromValue(qQNaN()) << INT_MAX; - - // mixed comparisons - // fp + fp - QTest::newRow("float+double1") << QVariant::fromValue(0.f) << QVariant::fromValue(0.) << 0; - QTest::newRow("float+double2") << QVariant::fromValue(-1.f) << QVariant::fromValue(0.) << -1; - QTest::newRow("float+double3") << QVariant::fromValue(0.f) << QVariant::fromValue(-1.) << +1; - QTest::newRow("float+double4") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(0.) << -1; - QTest::newRow("float+double5") << QVariant::fromValue(0.f) << QVariant::fromValue(-qInf()) << +1; - QTest::newRow("float+double6") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(-qInf()) << 0; - QTest::newRow("float+double7") << QVariant::fromValue(float(qInf())) << QVariant::fromValue(qInf()) << 0; - QTest::newRow("float+double8") << QVariant::fromValue(-float(qInf())) << QVariant::fromValue(qInf()) << -1; - QTest::newRow("float+double9") << QVariant::fromValue(qQNaN()) << QVariant::fromValue(0.) << INT_MAX; - QTest::newRow("float+double10") << QVariant::fromValue(0.) << QVariant::fromValue(qQNaN()) << INT_MAX; - QTest::newRow("float+double11") << QVariant::fromValue(qQNaN()) << QVariant::fromValue(qQNaN()) << INT_MAX; - - // fp + int - QTest::newRow("float+int1") << QVariant::fromValue(0.f) << QVariant::fromValue(0) << 0; - QTest::newRow("double+int1") << QVariant::fromValue(0.) << QVariant::fromValue(0) << 0; - QTest::newRow("float+int2") << QVariant::fromValue(-1.f) << QVariant::fromValue(0) << -1; - QTest::newRow("double+int2") << QVariant::fromValue(-1.) << QVariant::fromValue(0) << -1; - QTest::newRow("float+int3") << QVariant::fromValue(0.f) << QVariant::fromValue(-1) << +1; - QTest::newRow("double+int3") << QVariant::fromValue(0.) << QVariant::fromValue(-1) << +1; - QTest::newRow("float+int4") << QVariant::fromValue(1.5f) << QVariant::fromValue(1) << +1; - QTest::newRow("double+int4") << QVariant::fromValue(1.5) << QVariant::fromValue(1) << +1; - QTest::newRow("double+int5") << QVariant::fromValue(qInf()) << QVariant::fromValue(1) << +1; - - // fp + uint - QTest::newRow("float+uint1") << QVariant::fromValue(0.f) << QVariant::fromValue(0U) << 0; - QTest::newRow("double+uint1") << QVariant::fromValue(0.) << QVariant::fromValue(0U) << 0; - QTest::newRow("float+uint2") << QVariant::fromValue(-1.f) << QVariant::fromValue(0U) << -1; - QTest::newRow("double+uint2") << QVariant::fromValue(-1.) << QVariant::fromValue(0U) << -1; - QTest::newRow("float+uint3") << QVariant::fromValue(0.f) << QVariant::fromValue(1U) << -1; - QTest::newRow("double+uint3") << QVariant::fromValue(0.) << QVariant::fromValue(1U) << -1; - QTest::newRow("float+uint4") << QVariant::fromValue(1.5f) << QVariant::fromValue(1U) << +1; - QTest::newRow("double+uint4") << QVariant::fromValue(1.5) << QVariant::fromValue(1U) << +1; - - // lower ranked + int - QTest::newRow("bool+int1") << QVariant::fromValue(false) << QVariant::fromValue(0) << 0; - QTest::newRow("bool+int2") << QVariant::fromValue(false) << QVariant::fromValue(1) << -1; - QTest::newRow("bool+int3") << QVariant::fromValue(true) << QVariant::fromValue(0) << +1; - QTest::newRow("bool+int4") << QVariant::fromValue(true) << QVariant::fromValue(1) << 0; - QTest::newRow("bool+int5") << QVariant::fromValue(true) << QVariant::fromValue(2) << -1; - - QTest::newRow("char+int1") << QVariant::fromValue(char(0)) << QVariant::fromValue(0) << 0; - QTest::newRow("char+int2") << QVariant::fromValue(char(0)) << QVariant::fromValue(1) << -1; - QTest::newRow("char+int3") << QVariant::fromValue(char(1)) << QVariant::fromValue(0) << +1; - QTest::newRow("char+int4") << QVariant::fromValue(char(1)) << QVariant::fromValue(1) << 0; - if (std::numeric_limits<char>::is_signed) { - QTest::newRow("char+int5") << QVariant::fromValue(char(-1)) << QVariant::fromValue(0) << -1; - QTest::newRow("char+int6") << QVariant::fromValue(char(-1)) << QVariant::fromValue(-1) << 0; - } - - QTest::newRow("schar+int1") << QVariant::fromValue(schar(0)) << QVariant::fromValue(0) << 0; - QTest::newRow("schar+int2") << QVariant::fromValue(schar(0)) << QVariant::fromValue(1) << -1; - QTest::newRow("schar+int3") << QVariant::fromValue(schar(1)) << QVariant::fromValue(0) << +1; - QTest::newRow("schar+int4") << QVariant::fromValue(schar(1)) << QVariant::fromValue(1) << 0; - QTest::newRow("schar+int5") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(0) << -1; - QTest::newRow("schar+int6") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(-1) << 0; - - QTest::newRow("uchar+int1") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(0) << 0; - QTest::newRow("uchar+int2") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(1) << -1; - QTest::newRow("uchar+int3") << QVariant::fromValue(uchar(1)) << QVariant::fromValue(0) << +1; - QTest::newRow("uchar+int4") << QVariant::fromValue(uchar(1)) << QVariant::fromValue(1) << 0; - - QTest::newRow("short+int1") << QVariant::fromValue(short(0)) << QVariant::fromValue(0) << 0; - QTest::newRow("short+int2") << QVariant::fromValue(short(0)) << QVariant::fromValue(1) << -1; - QTest::newRow("short+int3") << QVariant::fromValue(short(1)) << QVariant::fromValue(0) << +1; - QTest::newRow("short+int4") << QVariant::fromValue(short(1)) << QVariant::fromValue(1) << 0; - QTest::newRow("short+int5") << QVariant::fromValue(short(-1)) << QVariant::fromValue(0) << -1; - QTest::newRow("short+int6") << QVariant::fromValue(short(-1)) << QVariant::fromValue(-1) << 0; - - QTest::newRow("ushort+int1") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(0) << 0; - QTest::newRow("ushort+int2") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(1) << -1; - QTest::newRow("ushort+int3") << QVariant::fromValue(ushort(1)) << QVariant::fromValue(0) << +1; - QTest::newRow("ushort+int4") << QVariant::fromValue(ushort(1)) << QVariant::fromValue(1) << 0; - - // lower ranked + uint (without sign change) - QTest::newRow("bool+uint1") << QVariant::fromValue(false) << QVariant::fromValue(0U) << 0; - QTest::newRow("bool+uint2") << QVariant::fromValue(false) << QVariant::fromValue(1U) << -1; - QTest::newRow("bool+uint3") << QVariant::fromValue(true) << QVariant::fromValue(0U) << +1; - QTest::newRow("bool+uint4") << QVariant::fromValue(true) << QVariant::fromValue(1U) << 0; - QTest::newRow("bool+uint5") << QVariant::fromValue(true) << QVariant::fromValue(2U) << -1; - - QTest::newRow("char+uint1") << QVariant::fromValue(char(0)) << QVariant::fromValue(0U) << 0; - QTest::newRow("char+uint2") << QVariant::fromValue(char(0)) << QVariant::fromValue(1U) << -1; - QTest::newRow("char+uint3") << QVariant::fromValue(char(1)) << QVariant::fromValue(0U) << +1; - QTest::newRow("char+uint4") << QVariant::fromValue(char(1)) << QVariant::fromValue(1U) << 0; - - QTest::newRow("schar+uint1") << QVariant::fromValue(schar(0)) << QVariant::fromValue(0U) << 0; - QTest::newRow("schar+uint2") << QVariant::fromValue(schar(0)) << QVariant::fromValue(1U) << -1; - QTest::newRow("schar+uint3") << QVariant::fromValue(schar(1)) << QVariant::fromValue(0U) << +1; - QTest::newRow("schar+uint4") << QVariant::fromValue(schar(1)) << QVariant::fromValue(1U) << 0; - - QTest::newRow("uchar+uint1") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(0U) << 0; - QTest::newRow("uchar+uint2") << QVariant::fromValue(uchar(0)) << QVariant::fromValue(1U) << -1; - QTest::newRow("uchar+uint3") << QVariant::fromValue(uchar(1)) << QVariant::fromValue(0U) << +1; - QTest::newRow("uchar+uint4") << QVariant::fromValue(uchar(1)) << QVariant::fromValue(1U) << 0; - - QTest::newRow("short+uint1") << QVariant::fromValue(short(0)) << QVariant::fromValue(0U) << 0; - QTest::newRow("short+uint2") << QVariant::fromValue(short(0)) << QVariant::fromValue(1U) << -1; - QTest::newRow("short+uint3") << QVariant::fromValue(short(1)) << QVariant::fromValue(0U) << +1; - QTest::newRow("short+uint4") << QVariant::fromValue(short(1)) << QVariant::fromValue(1U) << 0; - - QTest::newRow("ushort+uint1") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(0U) << 0; - QTest::newRow("ushort+uint2") << QVariant::fromValue(ushort(0)) << QVariant::fromValue(1U) << -1; - QTest::newRow("ushort+uint3") << QVariant::fromValue(ushort(1)) << QVariant::fromValue(0U) << +1; - QTest::newRow("ushort+uint4") << QVariant::fromValue(ushort(1)) << QVariant::fromValue(1U) << 0; - - // int + qlonglong - QTest::newRow("int+qlonglong1") << QVariant::fromValue(0) << QVariant::fromValue(Q_INT64_C(0)) << 0; - QTest::newRow("int+qlonglong2") << QVariant::fromValue(1) << QVariant::fromValue(Q_INT64_C(0)) << +1; - QTest::newRow("int+qlonglong3") << QVariant::fromValue(0) << QVariant::fromValue(Q_INT64_C(1)) << -1; - QTest::newRow("int+qlonglong4") << QVariant::fromValue(1) << QVariant::fromValue(Q_INT64_C(1)) << 0; - QTest::newRow("int+qlonglong5") << QVariant::fromValue(0) << QVariant::fromValue(Q_INT64_C(-1)) << +1; - QTest::newRow("int+qlonglong6") << QVariant::fromValue(-1) << QVariant::fromValue(Q_INT64_C(0)) << -1; - QTest::newRow("int+qlonglong7") << QVariant::fromValue(-1) << QVariant::fromValue(Q_INT64_C(-1)) << 0; - - // uint + qulonglong - QTest::newRow("uint+qulonglong1") << QVariant::fromValue(0U) << QVariant::fromValue(Q_UINT64_C(0)) << 0; - QTest::newRow("uint+qulonglong2") << QVariant::fromValue(1U) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("uint+qulonglong3") << QVariant::fromValue(0U) << QVariant::fromValue(Q_UINT64_C(1)) << -1; - QTest::newRow("uint+qulonglong4") << QVariant::fromValue(1U) << QVariant::fromValue(Q_UINT64_C(1)) << 0; - - // int + uint (without sign change) - QTest::newRow("int+uint1") << QVariant::fromValue(0) << QVariant::fromValue(0U) << 0; - QTest::newRow("int+uint2") << QVariant::fromValue(1) << QVariant::fromValue(0U) << +1; - QTest::newRow("int+uint3") << QVariant::fromValue(0) << QVariant::fromValue(1U) << -1; - QTest::newRow("int+uint4") << QVariant::fromValue(1) << QVariant::fromValue(1U) << 0; - - // uint + qlonglong - QTest::newRow("uint+qlonglong1") << QVariant::fromValue(0U) << QVariant::fromValue(Q_INT64_C(0)) << 0; - QTest::newRow("uint+qlonglong2") << QVariant::fromValue(1U) << QVariant::fromValue(Q_INT64_C(0)) << +1; - QTest::newRow("uint+qlonglong3") << QVariant::fromValue(0U) << QVariant::fromValue(Q_INT64_C(1)) << -1; - QTest::newRow("uint+qlonglong4") << QVariant::fromValue(1U) << QVariant::fromValue(Q_INT64_C(1)) << 0; - QTest::newRow("uint+qlonglong5") << QVariant::fromValue(0U) << QVariant::fromValue(Q_INT64_C(-1)) << +1; - - // boundary conditions - QTest::newRow("charmax+intmax") << QVariant::fromValue(CHAR_MAX) << QVariant::fromValue(INT_MAX) << -1; - QTest::newRow("charmax+uintmax") << QVariant::fromValue(CHAR_MAX) << QVariant::fromValue(UINT_MAX) << -1; - QTest::newRow("scharmax+intmax") << QVariant::fromValue(SCHAR_MAX) << QVariant::fromValue(INT_MAX) << -1; - QTest::newRow("scharmax+uintmax") << QVariant::fromValue(SCHAR_MAX) << QVariant::fromValue(UINT_MAX) << -1; - QTest::newRow("ucharmax+intmax") << QVariant::fromValue(UCHAR_MAX) << QVariant::fromValue(INT_MAX) << -1; - QTest::newRow("ucharmax+uintmax") << QVariant::fromValue(UCHAR_MAX) << QVariant::fromValue(UINT_MAX) << -1; - QTest::newRow("shortmax+intmax") << QVariant::fromValue(SHRT_MAX) << QVariant::fromValue(INT_MAX) << -1; - QTest::newRow("shortmax+uintmax") << QVariant::fromValue(SHRT_MAX) << QVariant::fromValue(UINT_MAX) << -1; - QTest::newRow("ushortmax+intmax") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(INT_MAX) << -1; - QTest::newRow("ushortmax+uintmax") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(UINT_MAX) << -1; - - QTest::newRow("intmin+qlonglongmin") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(LLONG_MIN) << +1; - QTest::newRow("intmax+uintmax") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(UINT_MAX) << -1; - QTest::newRow("intmax+qlonglongmax") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(LLONG_MAX) << -1; - QTest::newRow("uintmax+qlonglongmax") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(LLONG_MAX) << -1; - QTest::newRow("intmax+qulonglongmax") << QVariant::fromValue(INT_MAX) << QVariant::fromValue(ULLONG_MAX) << -1; - QTest::newRow("qlonglongmax+qulonglongmax") << QVariant::fromValue(LLONG_MAX) << QVariant::fromValue(ULLONG_MAX) << -1; - QTest::newRow("uintmax+qlonglongmin") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(LLONG_MIN) << +1; - - // check for no sign-extension issues - QTest::newRow("ushortmax+intzero") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(0) << +1; - QTest::newRow("ushortmax+qlonglongzero") << QVariant::fromValue(USHRT_MAX) << QVariant::fromValue(Q_INT64_C(0)) << +1; - QTest::newRow("uintmax+qlonglongzero") << QVariant::fromValue(UINT_MAX) << QVariant::fromValue(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") << QVariant::fromValue(char(-1)) << QVariant::fromValue(0U) << +1; - QTest::newRow("signchange-char+uintmax") << QVariant::fromValue(char(-1)) << QVariant::fromValue(UINT_MAX) << 0; - QTest::newRow("signchange-charmin+uint") << QVariant::fromValue(CHAR_MIN) << QVariant::fromValue(0U) << +1; - QTest::newRow("signchange-char+qulonglong") << QVariant::fromValue(char(-1)) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-char+qulonglongmax") << QVariant::fromValue(char(-1)) << QVariant::fromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-charmin+qulonglong") << QVariant::fromValue(CHAR_MIN) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - } - QTest::newRow("signchange-schar+uint") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(0U) << +1; - QTest::newRow("signchange-schar+uintmax") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(UINT_MAX) << 0; - QTest::newRow("signchange-scharmin+uint") << QVariant::fromValue(SCHAR_MIN) << QVariant::fromValue(0U) << +1; - QTest::newRow("signchange-schar+qulonglong") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-schar+qulonglongmax") << QVariant::fromValue(schar(-1)) << QVariant::fromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-scharmin+qulonglong") << QVariant::fromValue(SCHAR_MIN) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-short+uint") << QVariant::fromValue(short(-1)) << QVariant::fromValue(0U) << +1; - QTest::newRow("signchange-short+uintmax") << QVariant::fromValue(short(-1)) << QVariant::fromValue(UINT_MAX) << 0; - QTest::newRow("signchange-shortmin+uint") << QVariant::fromValue(SHRT_MIN) << QVariant::fromValue(0U) << +1; - QTest::newRow("signchange-short+qulonglong") << QVariant::fromValue(short(-1)) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-short+qulonglongmax") << QVariant::fromValue(short(-1)) << QVariant::fromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-shortmin+qulonglong") << QVariant::fromValue(SHRT_MIN) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-int+uint") << QVariant::fromValue(-1) << QVariant::fromValue(0U) << +1; - QTest::newRow("signchange-int+uintmax") << QVariant::fromValue(-1) << QVariant::fromValue(UINT_MAX) << 0; - QTest::newRow("signchange-intmin+uint") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(0U) << +1; - QTest::newRow("signchange-int+qulonglong") << QVariant::fromValue(-1) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-int+qulonglongmax") << QVariant::fromValue(-1) << QVariant::fromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-intmin+qulonglong") << QVariant::fromValue(INT_MIN) << QVariant::fromValue(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") << QVariant::fromValue(Q_INT64_C(-1)) << QVariant::fromValue(Q_UINT64_C(0)) << +1; - QTest::newRow("signchange-qlonglong+qulonglongmax") << QVariant::fromValue(Q_INT64_C(-1)) << QVariant::fromValue(ULLONG_MAX) << 0; - QTest::newRow("signchange-qlonglongmin+qulonglong") << QVariant::fromValue(LLONG_MIN) << QVariant::fromValue(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 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 { - // unorderable (NaN) - QVERIFY(!(v1 == v2)); - } -} - void tst_QVariant::typeName_data() { QTest::addColumn<int>("type"); @@ -2116,7 +1769,6 @@ void tst_QVariant::typeName_data() QTest::newRow("39") << int(QVariant::RectF) << QByteArray("QRectF"); QTest::newRow("40") << int(QVariant::PointF) << QByteArray("QPointF"); QTest::newRow("41") << int(QVariant::RegExp) << QByteArray("QRegExp"); - QTest::newRow("43") << int(QVariant::Matrix) << QByteArray("QMatrix"); QTest::newRow("44") << int(QVariant::Transform) << QByteArray("QTransform"); QTest::newRow("45") << int(QVariant::Hash) << QByteArray("QVariantHash"); QTest::newRow("46") << int(QVariant::Matrix4x4) << QByteArray("QMatrix4x4"); @@ -2624,16 +2276,6 @@ void tst_QVariant::variantMap() QCOMPARE(qvariant_cast<QVariantMap>(v3).value("test").toInt(), 42); QCOMPARE(v, QVariant(v.toHash())); - - // multi-keys - map.insertMulti("test", 47); - v = map; - map2 = qvariant_cast<QVariantMap>(v); - QCOMPARE(map2, map); - map2 = v.toMap(); - QCOMPARE(map2, map); - - QCOMPARE(v, QVariant(v.toHash())); } void tst_QVariant::variantHash() @@ -2657,16 +2299,6 @@ void tst_QVariant::variantHash() QCOMPARE(qvariant_cast<QVariantHash>(v3).value("test").toInt(), 42); QCOMPARE(v, QVariant(v.toMap())); - - // multi-keys - hash.insertMulti("test", 47); - v = hash; - hash2 = qvariant_cast<QVariantHash>(v); - QCOMPARE(hash2, hash); - hash2 = v.toHash(); - QCOMPARE(hash2, hash); - - QCOMPARE(v, QVariant(v.toMap())); } class CustomQObject : public QObject { @@ -3203,7 +2835,7 @@ void tst_QVariant::loadUnknownUserType() void tst_QVariant::loadBrokenUserType() { - QTest::ignoreMessage(QtWarningMsg, "Trying to construct an instance of an invalid type, type id: 127"); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type")); char data[] = {0, 0, 0, 127, 0 }; QByteArray ba(data, sizeof(data)); @@ -3408,7 +3040,7 @@ void tst_QVariant::convertIterables() const QCOMPARE(QVariant::fromValue(map).value<QVariantHash>().count(), map.count()); QCOMPARE(QVariant::fromValue(map).value<QVariantMap>().count(), map.count()); - map.insertMulti("3", 5); + map.insert("4", 5); QCOMPARE(QVariant::fromValue(map).value<QVariantHash>().count(), map.count()); QCOMPARE(QVariant::fromValue(map).value<QVariantMap>().count(), map.count()); } @@ -3418,7 +3050,7 @@ void tst_QVariant::convertIterables() const QCOMPARE(QVariant::fromValue(map).value<QVariantHash>().count(), map.count()); QCOMPARE(QVariant::fromValue(map).value<QVariantMap>().count(), map.count()); - map.insertMulti("3", 5); + map.insert("4", 5); QCOMPARE(QVariant::fromValue(map).value<QVariantHash>().count(), map.count()); QCOMPARE(QVariant::fromValue(map).value<QVariantMap>().count(), map.count()); } @@ -3428,7 +3060,7 @@ void tst_QVariant::convertIterables() const QCOMPARE(QVariant::fromValue(hash).value<QVariantHash>().count(), hash.count()); QCOMPARE(QVariant::fromValue(hash).value<QVariantMap>().count(), hash.count()); - hash.insertMulti("3", 5); + hash.insert("4", 5); QCOMPARE(QVariant::fromValue(hash).value<QVariantHash>().count(), hash.count()); QCOMPARE(QVariant::fromValue(hash).value<QVariantMap>().count(), hash.count()); } @@ -3438,7 +3070,7 @@ void tst_QVariant::convertIterables() const QCOMPARE(QVariant::fromValue(hash).value<QVariantHash>().count(), hash.count()); QCOMPARE(QVariant::fromValue(hash).value<QVariantMap>().count(), hash.count()); - hash.insertMulti("3", 5); + hash.insert("4", 5); QCOMPARE(QVariant::fromValue(hash).value<QVariantHash>().count(), hash.count()); QCOMPARE(QVariant::fromValue(hash).value<QVariantMap>().count(), hash.count()); } @@ -3884,18 +3516,6 @@ void tst_QVariant::moreCustomTypes() data << (QSet<int>() << 42); PLAY_WITH_VARIANT(data, false, QString(), 0, false); } - -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - { - QList<QLinkedList<int> > data; - PLAY_WITH_VARIANT(data, false, QString(), 0, false); - data << (QLinkedList<int>() << 42); - PLAY_WITH_VARIANT(data, false, QString(), 0, false); - } -QT_WARNING_POP -#endif } void tst_QVariant::movabilityTest() @@ -3968,8 +3588,7 @@ Q_DECLARE_METATYPE(Convertible); struct BigConvertible { double d; - double dummy; - double dummy2; + double dummy[sizeof(QVariant) / sizeof(double)]; operator int() const { return (int)d; } operator double() const { return d; } operator QString() const { return QString::number(d); } @@ -4870,86 +4489,6 @@ void tst_QVariant::metaEnums() METAENUMS_TEST(MetaEnumTest_Enum8_value); } -void tst_QVariant::compareSanity_data() -{ - QTest::addColumn<QVariant>("value1"); - QTest::addColumn<QVariant>("value2"); - - QTest::newRow( "int <>/== QUrl" ) << QVariant( 97 ) << QVariant(QUrl("a")); - QTest::newRow( "int <>/== QChar" ) << QVariant( 97 ) << QVariant(QChar('a')); - QTest::newRow( "int <>/== QString" ) << QVariant( 97 ) << QVariant(QString("a")); - QTest::newRow( "QUrl <>/== QChar" ) << QVariant(QUrl("a")) << QVariant(QChar('a')); - QTest::newRow( "QUrl <>/== QString" ) << QVariant(QUrl("a")) << QVariant(QString("a")); - QTest::newRow( "QChar <>/== QString" ) << QVariant(QChar('a')) << QVariant(QString("a")); -} - -void tst_QVariant::compareSanity() -{ - QFETCH(QVariant, value1); - QFETCH(QVariant, value2); - - if (value1 == value2) { - QVERIFY(!(value1 < value2) && !(value1 > value2)); - } else { - QVERIFY(value1 != value2); - QVERIFY((value1 < value2) || (value1 > value2)); - } -} - -static void richComparison(const QVariant& less, const QVariant& more) -{ - QVERIFY(less.type() == more.type()); - - QVERIFY(less < more); - QVERIFY(!(more < less)); - - QVERIFY(more > less); - QVERIFY(!(less > more)); - - QVERIFY(less <= more); - QVERIFY(!(more <= less)); - QVERIFY(less <= less); - - QVERIFY(more >= less); - QVERIFY(!(less >= more)); - QVERIFY(more >= more); -} - -void tst_QVariant::compareRich() -{ - richComparison(QUuid("{49d8ad2a-2ee8-4c3d-949f-1b5a3765ddf0}"), - QUuid("{f6d56824-16e9-4543-a375-add2877c2d05}")); - richComparison(QByteArray::fromRawData("a", 1), - QByteArray::fromRawData("b", 1)); - richComparison(QStringLiteral("a"), QStringLiteral("b")); - richComparison(QLatin1String("a"), QLatin1String("b")); - richComparison(QChar('a'), QChar('b')); - richComparison(QDate(2016, 7, 23), QDate(2016, 7, 24)); - richComparison(QTime(0, 0), QTime(0, 1)); - richComparison(QDateTime(QDate(2016, 7, 23), QTime(0, 0)), - QDateTime(QDate(2016, 7, 23), QTime(0, 1))); - - richComparison(QStringList(), QStringList() << QStringLiteral("a")); - richComparison(QStringList(), QStringList() << QStringLiteral("a") - << QStringLiteral("b")); - richComparison(QStringList() << QStringLiteral("a"), - QStringList() << QStringLiteral("b")); - richComparison(QStringList() << QStringLiteral("a"), - QStringList() << QStringLiteral("b") - << QStringLiteral("c")); - richComparison(QStringList() << QStringLiteral("a") - << QStringLiteral("c"), - QStringList() << QStringLiteral("b")); - richComparison(QStringList() << QStringLiteral("a") - << QStringLiteral("c"), - QStringList() << QStringLiteral("b") - << QStringLiteral("d")); - richComparison(QStringList() << QStringLiteral("a") - << QStringLiteral("c"), - QStringList() << QStringLiteral("a") - << QStringLiteral("d")); -} - void tst_QVariant::nullConvert() { // Test quirks with QVariants different types of null states. diff --git a/tests/auto/corelib/kernel/qwineventnotifier/CMakeLists.txt b/tests/auto/corelib/kernel/qwineventnotifier/CMakeLists.txt new file mode 100644 index 0000000000..0f287a1652 --- /dev/null +++ b/tests/auto/corelib/kernel/qwineventnotifier/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qwineventnotifier.pro. + +##################################################################### +## tst_qwineventnotifier Test: +##################################################################### + +add_qt_test(tst_qwineventnotifier + SOURCES + tst_qwineventnotifier.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate +) |