diff options
Diffstat (limited to 'tests/auto/corelib')
53 files changed, 950 insertions, 4131 deletions
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index b33dec8a61..047130d5ea 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -49,7 +49,6 @@ private slots: void qConstructorFunction(); void qCoreAppStartupFunction(); void qCoreAppStartupFunctionRestart(); - void qAlignOf(); void integerForSize(); void qprintable(); void qprintable_data(); @@ -434,106 +433,6 @@ template <class T> struct AlignmentInStruct { T dummy; }; typedef int (*fun) (); typedef int (Empty::*memFun) (); -#define TEST_AlignOf(type, alignment) \ - do { \ - TEST_AlignOf_impl(type, alignment); \ - \ - TEST_AlignOf_impl(type &, alignment); \ - TEST_AlignOf_RValueRef(type &&, alignment); \ - \ - TEST_AlignOf_impl(type [5], alignment); \ - TEST_AlignOf_impl(type (&) [5], alignment); \ - \ - TEST_AlignOf_impl(AlignmentInStruct<type>, alignment); \ - \ - /* Some internal sanity validation, just for fun */ \ - TEST_AlignOf_impl(AlignmentInStruct<type [5]>, alignment); \ - TEST_AlignOf_impl(AlignmentInStruct<type &>, Q_ALIGNOF(void *)); \ - TEST_AlignOf_impl(AlignmentInStruct<type (&) [5]>, \ - Q_ALIGNOF(void *)); \ - TEST_AlignOf_RValueRef(AlignmentInStruct<type &&>, \ - Q_ALIGNOF(void *)); \ - } while (false) \ - /**/ - -#define TEST_AlignOf_RValueRef(type, alignment) \ - TEST_AlignOf_impl(type, alignment) - -#define TEST_AlignOf_impl(type, alignment) \ - do { \ - QCOMPARE(Q_ALIGNOF(type), size_t(alignment)); \ - /* Compare to native operator for compilers that support it, - otherwise... erm... check consistency! :-) */ \ - QCOMPARE(alignof(type), Q_ALIGNOF(type)); \ - } while (false) - /**/ - -void tst_QGlobal::qAlignOf() -{ - // Built-in types, except 64-bit integers and double - TEST_AlignOf(char, 1); - TEST_AlignOf(signed char, 1); - TEST_AlignOf(unsigned char, 1); - TEST_AlignOf(qint8, 1); - TEST_AlignOf(quint8, 1); - TEST_AlignOf(qint16, 2); - TEST_AlignOf(quint16, 2); - TEST_AlignOf(qint32, 4); - TEST_AlignOf(quint32, 4); - TEST_AlignOf(void *, sizeof(void *)); - - // Depends on platform and compiler, disabling test for now - // TEST_AlignOf(long double, 16); - - // Empty struct - TEST_AlignOf(Empty, 1); - - // Function pointers - TEST_AlignOf(fun, Q_ALIGNOF(void *)); - TEST_AlignOf(memFun, Q_ALIGNOF(void *)); - - - // 64-bit integers and double - TEST_AlignOf_impl(qint64, 8); - TEST_AlignOf_impl(quint64, 8); - TEST_AlignOf_impl(double, 8); - - TEST_AlignOf_impl(qint64 &, 8); - TEST_AlignOf_impl(quint64 &, 8); - TEST_AlignOf_impl(double &, 8); - - TEST_AlignOf_RValueRef(qint64 &&, 8); - TEST_AlignOf_RValueRef(quint64 &&, 8); - TEST_AlignOf_RValueRef(double &&, 8); - - // 32-bit x86 ABI idiosyncrasies -#if defined(Q_PROCESSOR_X86_32) && !defined(Q_OS_WIN) - TEST_AlignOf_impl(AlignmentInStruct<qint64>, 4); -#else - TEST_AlignOf_impl(AlignmentInStruct<qint64>, 8); -#endif - - TEST_AlignOf_impl(AlignmentInStruct<quint64>, Q_ALIGNOF(AlignmentInStruct<qint64>)); - TEST_AlignOf_impl(AlignmentInStruct<double>, Q_ALIGNOF(AlignmentInStruct<qint64>)); - - // 32-bit x86 ABI, Clang disagrees with gcc -#if !defined(Q_PROCESSOR_X86_32) || !defined(Q_CC_CLANG) || defined(Q_OS_ANDROID) - TEST_AlignOf_impl(qint64 [5], Q_ALIGNOF(qint64)); -#else - TEST_AlignOf_impl(qint64 [5], Q_ALIGNOF(AlignmentInStruct<qint64>)); -#endif - - TEST_AlignOf_impl(qint64 (&) [5], Q_ALIGNOF(qint64 [5])); - TEST_AlignOf_impl(quint64 [5], Q_ALIGNOF(quint64 [5])); - TEST_AlignOf_impl(quint64 (&) [5], Q_ALIGNOF(quint64 [5])); - TEST_AlignOf_impl(double [5], Q_ALIGNOF(double [5])); - TEST_AlignOf_impl(double (&) [5], Q_ALIGNOF(double [5])); -} - -#undef TEST_AlignOf -#undef TEST_AlignOf_RValueRef -#undef TEST_AlignOf_impl - void tst_QGlobal::integerForSize() { // compile-only test: diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 09ef0ea44f..ebb9a0a44c 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -116,7 +116,7 @@ static DWORD createSymbolicLink(const QString &symLinkName, const QString &targe reinterpret_cast<const wchar_t*>(nativeTarget.utf16()), flags) == FALSE) { result = GetLastError(); QTextStream(errorMessage) << "CreateSymbolicLink(" << nativeSymLinkName << ", " - << nativeTarget << ", 0x" << hex << flags << dec << ") failed with error " << result + << nativeTarget << ", 0x" << Qt::hex << flags << Qt::dec << ") failed with error " << result << ": " << qt_error_string(int(result)); } return result; diff --git a/tests/auto/corelib/io/qfileselector/platforms/+mac/test5 b/tests/auto/corelib/io/qfileselector/platforms/+mac/test5 deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/corelib/io/qfileselector/platforms/+mac/test5 +++ /dev/null diff --git a/tests/auto/corelib/io/qfileselector/platforms/+osx/test4 b/tests/auto/corelib/io/qfileselector/platforms/+osx/test4 deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/corelib/io/qfileselector/platforms/+osx/test4 +++ /dev/null diff --git a/tests/auto/corelib/io/qfileselector/platforms/+mac/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+ios/test index e69de29bb2..e69de29bb2 100644 --- a/tests/auto/corelib/io/qfileselector/platforms/+mac/test +++ b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+ios/test diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+ios/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+ios/test deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+ios/test +++ /dev/null diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+macos/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+macos/test deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+macos/test +++ /dev/null diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+osx/+macos/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+osx/+macos/test deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+osx/+macos/test +++ /dev/null diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+osx/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+osx/test deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/+osx/test +++ /dev/null diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/test deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+mac/test +++ /dev/null diff --git a/tests/auto/corelib/io/qfileselector/platforms/+osx/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+macos/test index e69de29bb2..e69de29bb2 100644 --- a/tests/auto/corelib/io/qfileselector/platforms/+osx/test +++ b/tests/auto/corelib/io/qfileselector/platforms/+unix/+darwin/+macos/test diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.qrc b/tests/auto/corelib/io/qfileselector/qfileselector.qrc index 54b2e0a0e2..f3b3ede575 100644 --- a/tests/auto/corelib/io/qfileselector/qfileselector.qrc +++ b/tests/auto/corelib/io/qfileselector/qfileselector.qrc @@ -1,65 +1,51 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource prefix="/"> - <file>extras/test</file> - <file>extras/test2</file> - <file>extras/+custom1/test</file> - <file>extras/+custom1/test3</file> - <file>extras/+custom2/test</file> - <file>extras/+custom3/test</file> - <file>extras/+custom3/+custom2/test</file> - <file>extras/+custom3/+custom4/test</file> - <file>extras/+custom3/+custom5/test</file> - <file>extras/+custom5/+custom3/test</file> - - <!-- platforms/test: deepest possible selection --> - <file>platforms/test</file> - <file>platforms/+unix/+android/test</file> - <file>platforms/+unix/+darwin/+mac/+ios/test</file> - <file>platforms/+unix/+darwin/+mac/+osx/+macos/test</file> - <file>platforms/+unix/+darwin/+mac/+osx/test</file> - <file>platforms/+unix/+darwin/+mac/test</file> - <file>platforms/+unix/+darwin/test</file> - <file>platforms/+unix/+haiku/test</file> - <file>platforms/+unix/+linux/test</file> - <file>platforms/+unix/+qnx/test</file> - <file>platforms/+unix/test</file> - <file>platforms/+windows/+wince/test</file> - <file>platforms/+windows/+winnt/test</file> - <file>platforms/+windows/+winrt/test</file> - <file>platforms/+windows/test</file> - <file>platforms/+android/test</file> - <file>platforms/+ios/test</file> - <file>platforms/+macos/test</file> - <file>platforms/+osx/test</file> - <file>platforms/+darwin/test</file> - <file>platforms/+mac/test</file> - <file>platforms/+haiku/test</file> - <file>platforms/+linux/test</file> - <file>platforms/+qnx/test</file> - <file>platforms/+wince/test</file> - <file>platforms/+winrt/test</file> - - <!-- platforms/test2: shallow selection for the deepest selector --> - <file>platforms/test2</file> - <file>platforms/+android/test2</file> - <file>platforms/+ios/test2</file> - <file>platforms/+macos/test2</file> - <file>platforms/+haiku/test2</file> - <file>platforms/+linux/test2</file> - <file>platforms/+qnx/test2</file> - <file>platforms/+wince/test2</file> - <file>platforms/+winnt/test2</file> - <file>platforms/+winrt/test2</file> - - <!-- platforms/test3: selection for the family only --> - <file>platforms/test3</file> - <file>platforms/+windows/test3</file> - <file>platforms/+unix/test3</file> - - <!-- platforms/test4 and 5: special cases for macOS --> - <file>platforms/test4</file> - <file>platforms/+osx/test4</file> - <file>platforms/test5</file> - <file>platforms/+mac/test5</file> -</qresource> +<RCC> + <qresource prefix="/"> + <file>extras/test</file> + <file>extras/test2</file> + <file>extras/+custom1/test</file> + <file>extras/+custom1/test3</file> + <file>extras/+custom2/test</file> + <file>extras/+custom3/test</file> + <file>extras/+custom3/+custom2/test</file> + <file>extras/+custom3/+custom4/test</file> + <file>extras/+custom3/+custom5/test</file> + <file>extras/+custom5/+custom3/test</file> + <file>platforms/test</file> + <file>platforms/+unix/+android/test</file> + <file>platforms/+unix/+darwin/test</file> + <file>platforms/+unix/+haiku/test</file> + <file>platforms/+unix/+linux/test</file> + <file>platforms/+unix/+qnx/test</file> + <file>platforms/+unix/test</file> + <file>platforms/+windows/+wince/test</file> + <file>platforms/+windows/+winnt/test</file> + <file>platforms/+windows/+winrt/test</file> + <file>platforms/+windows/test</file> + <file>platforms/+android/test</file> + <file>platforms/+ios/test</file> + <file>platforms/+macos/test</file> + <file>platforms/+darwin/test</file> + <file>platforms/+haiku/test</file> + <file>platforms/+linux/test</file> + <file>platforms/+qnx/test</file> + <file>platforms/+wince/test</file> + <file>platforms/+winrt/test</file> + <file>platforms/test2</file> + <file>platforms/+android/test2</file> + <file>platforms/+ios/test2</file> + <file>platforms/+macos/test2</file> + <file>platforms/+haiku/test2</file> + <file>platforms/+linux/test2</file> + <file>platforms/+qnx/test2</file> + <file>platforms/+wince/test2</file> + <file>platforms/+winnt/test2</file> + <file>platforms/+winrt/test2</file> + <file>platforms/test3</file> + <file>platforms/+windows/test3</file> + <file>platforms/+unix/test3</file> + <file>platforms/test4</file> + <file>platforms/test5</file> + <file>platforms/+unix/+darwin/+macos/test</file> + <file>platforms/+unix/+darwin/+ios/test</file> + </qresource> </RCC> diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp index 11b1fdaeeb..bac7a69e0f 100644 --- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp +++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp @@ -126,14 +126,6 @@ void tst_QFileSelector::basicTest_data() QTest::newRow("platform3") << QString(":/platforms/test3") << QStringList() << expectedPlatform3File; -#ifdef Q_OS_MACOS - // special case for compatibility code - QTest::newRow("osx-compat") << QString(":/platforms/test4") << QStringList() - << ":/platforms/+osx/test4"; - QTest::newRow("mac-compat") << QString(":/platforms/test5") << QStringList() - << ":/platforms/+mac/test5"; -#endif - QString resourceTestPath(":/extras/test"); QString custom1("custom1"); QTest::newRow("custom1-noselector") << resourceTestPath << QStringList() diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 0f07ba4bb2..c969e72c18 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -39,7 +39,9 @@ #include <QtCore/QDir> #include <QtCore/QThread> #include <QtCore/QSysInfo> -#include <QtGui/QKeySequence> +#if QT_CONFIG(shortcut) +# include <QtGui/QKeySequence> +#endif #include <QtCore> #include <QtGui> @@ -1364,6 +1366,7 @@ void tst_QSettings::testVariantTypes() dt.setOffsetFromUtc(3600); testVal("key14", dt, QDateTime, DateTime); +#if QT_CONFIG(shortcut) // We store key sequences as strings instead of binary variant blob, for improved // readability in the resulting format. if (format >= QSettings::InvalidFormat) { @@ -1373,6 +1376,7 @@ void tst_QSettings::testVariantTypes() QKeySequence(Qt::ControlModifier + Qt::Key_F1).toString(QKeySequence::NativeText), QString, String); } +#endif // QT_CONFIG(shortcut) #undef testVal } diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 60000316cc..c83e7af503 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -1320,13 +1320,13 @@ 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()"; @@ -1337,15 +1337,16 @@ void tst_QMetaObject::normalizedSignature_data() 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("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("invalid1") << "a( b" << "a(b"; } @@ -1367,13 +1368,13 @@ 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("value1") << "const QString &" << "QString"; @@ -1387,6 +1388,7 @@ void tst_QMetaObject::normalizedType_data() 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>"; } void tst_QMetaObject::normalizedType() 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/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 19b3289390..4e30f210b1 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -120,8 +120,6 @@ private slots: void constRefs(); void convertCustomType_data(); void convertCustomType(); - void compareCustomType_data(); - void compareCustomType(); void compareCustomEqualOnlyType(); void customDebugStream(); void unknownType(); @@ -574,12 +572,14 @@ 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> >"); + // 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"); QTest::newRow("CustomGadget*") << ::qMetaTypeId<CustomGadget*>() << QString::fromLatin1("CustomGadget*"); @@ -1032,9 +1032,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); @@ -1186,9 +1186,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); @@ -2017,7 +2017,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 +2139,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 +2429,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 +2450,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); diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index a805bfb747..91ea83be3d 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(); @@ -2341,51 +2338,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 +6926,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/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 45eb61f6e4..9f022b3b14 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -190,8 +190,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 +268,6 @@ private slots: void enums(); void metaEnums(); - void compareSanity_data(); - void compareSanity(); - void compareRich(); void nullConvert(); @@ -1730,344 +1725,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"); @@ -3961,8 +3618,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); } @@ -4863,86 +4519,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/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 45f815f810..4c85482c6a 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -52,6 +52,8 @@ private Q_SLOTS: void testNumbers_3(); void testNumbers_4(); + void testNumberComparisons(); + void testObjectSimple(); void testObjectSmallKeys(); void testArraySimple(); @@ -218,26 +220,32 @@ void tst_QtJson::testNumbers() { int numbers[] = { 0, - -1, 1, + 2, + -1, + -2, + (1<<25), (1<<26), (1<<27), (1<<28), + -(1<<25), -(1<<26), -(1<<27), -(1<<28), (1<<26) - 1, (1<<27) - 1, (1<<28) - 1, + (1<<29) - 1, -((1<<26) - 1), -((1<<27) - 1), - -((1<<28) - 1) + -((1<<28) - 1), + -((1<<29) - 1) }; int n = sizeof(numbers)/sizeof(int); QJsonArray array; for (int i = 0; i < n; ++i) - array.append((double)numbers[i]); + array.append(numbers[i]); QByteArray serialized = QJsonDocument(array).toJson(); QJsonDocument json = QJsonDocument::fromJson(serialized); @@ -246,8 +254,10 @@ void tst_QtJson::testNumbers() QCOMPARE(array.size(), array2.size()); for (int i = 0; i < array.size(); ++i) { QCOMPARE(array.at(i).type(), QJsonValue::Double); + QCOMPARE(array.at(i).toInt(), numbers[i]); QCOMPARE(array.at(i).toDouble(), (double)numbers[i]); QCOMPARE(array2.at(i).type(), QJsonValue::Double); + QCOMPARE(array2.at(i).toInt(), numbers[i]); QCOMPARE(array2.at(i).toDouble(), (double)numbers[i]); } } @@ -255,8 +265,10 @@ void tst_QtJson::testNumbers() { qint64 numbers[] = { 0, - -1, 1, + 2, + -1, + -2, (1ll<<54), (1ll<<55), (1ll<<56), @@ -266,15 +278,21 @@ void tst_QtJson::testNumbers() (1ll<<54) - 1, (1ll<<55) - 1, (1ll<<56) - 1, + (1ll<<57) - 1, + (1ll<<58) - 1, + (1ll<<59) + 1001, -((1ll<<54) - 1), -((1ll<<55) - 1), - -((1ll<<56) - 1) + -((1ll<<56) - 1), + -((1ll<<57) - 1), + -((1ll<<58) - 1), + -((1ll<<59) + 1001), }; int n = sizeof(numbers)/sizeof(qint64); QJsonArray array; for (int i = 0; i < n; ++i) - array.append((double)numbers[i]); + array.append(QJsonValue(numbers[i])); QByteArray serialized = QJsonDocument(array).toJson(); QJsonDocument json = QJsonDocument::fromJson(serialized); @@ -283,8 +301,10 @@ void tst_QtJson::testNumbers() QCOMPARE(array.size(), array2.size()); for (int i = 0; i < array.size(); ++i) { QCOMPARE(array.at(i).type(), QJsonValue::Double); + QCOMPARE(array.at(i).toInteger(), numbers[i]); QCOMPARE(array.at(i).toDouble(), (double)numbers[i]); QCOMPARE(array2.at(i).type(), QJsonValue::Double); + QCOMPARE(array2.at(i).toInteger(), numbers[i]); QCOMPARE(array2.at(i).toDouble(), (double)numbers[i]); } } @@ -422,6 +442,46 @@ void tst_QtJson::testNumbers_4() " -18446744073709552000\n" "]\n"; QCOMPARE(json, expected); + + QJsonArray array2; + array2 << QJsonValue(Q_INT64_C(+1000000000000000)); + array2 << QJsonValue(Q_INT64_C(-1000000000000000)); + array2 << QJsonValue(Q_INT64_C(+9007199254740992)); + array2 << QJsonValue(Q_INT64_C(-9007199254740992)); + array2 << QJsonValue(Q_INT64_C(+9223372036854775807)); + array2 << QJsonValue(Q_INT64_C(-9223372036854775807)); + const QByteArray json2(QJsonDocument(array2).toJson()); + const QByteArray expected2 = + "[\n" + " 1000000000000000,\n" + " -1000000000000000,\n" + " 9007199254740992,\n" + " -9007199254740992,\n" + " 9223372036854775807,\n" + " -9223372036854775807\n" + "]\n"; + QCOMPARE(json2, expected2); +} + +void tst_QtJson::testNumberComparisons() +{ + // QJsonValues created using doubles only have double precision + QJsonValue llMinDbl(-9223372036854775807.0); + QJsonValue llMinPlus1Dbl(-9223372036854775806.0); + QCOMPARE(llMinDbl == llMinPlus1Dbl, -9223372036854775807.0 == -9223372036854775806.0); // true + + // QJsonValues created using qint64 have full qint64 precision + QJsonValue llMin(Q_INT64_C(-9223372036854775807)); + QJsonValue llMinPlus1(Q_INT64_C(-9223372036854775806)); + QCOMPARE(llMin == llMinPlus1, Q_INT64_C(-9223372036854775807) == Q_INT64_C(-9223372036854775806)); // false + + // The different storage formats should be able to compare as their C++ versions (all true) + QCOMPARE(llMin == llMinDbl, Q_INT64_C(-9223372036854775807) == -9223372036854775807.0); + QCOMPARE(llMinDbl == llMin, -9223372036854775807.0 == Q_INT64_C(-9223372036854775807)); + QCOMPARE(llMinPlus1 == llMinPlus1Dbl, Q_INT64_C(-9223372036854775806) == -9223372036854775806.0); + QCOMPARE(llMinPlus1Dbl == llMinPlus1, -9223372036854775806.0 == Q_INT64_C(-9223372036854775806)); + QCOMPARE(llMinPlus1 == llMinDbl, Q_INT64_C(-9223372036854775806) == -9223372036854775807.0); + QCOMPARE(llMinPlus1Dbl == llMin, -9223372036854775806.0 == Q_INT64_C(-9223372036854775807)); } void tst_QtJson::testObjectSimple() @@ -1162,8 +1222,8 @@ void tst_QtJson::fromVariant_data() bool boolValue = true; int intValue = -1; uint uintValue = 1; - long long longlongValue = -2; - unsigned long long ulonglongValue = 2; + qlonglong longlongValue = -2; + qulonglong ulonglongValue = 2; float floatValue = 3.3f; double doubleValue = 4.4; QString stringValue("str"); @@ -1209,7 +1269,7 @@ void tst_QtJson::fromVariant_data() QTest::newRow("nullptr") << QVariant::fromValue(nullptr) << QJsonValue(QJsonValue::Null); QTest::newRow("bool") << QVariant(boolValue) << QJsonValue(boolValue); QTest::newRow("int") << QVariant(intValue) << QJsonValue(intValue); - QTest::newRow("uint") << QVariant(uintValue) << QJsonValue(static_cast<double>(uintValue)); + QTest::newRow("uint") << QVariant(uintValue) << QJsonValue(static_cast<qint64>(uintValue)); QTest::newRow("longlong") << QVariant(longlongValue) << QJsonValue(longlongValue); QTest::newRow("ulonglong") << QVariant(ulonglongValue) << QJsonValue(static_cast<double>(ulonglongValue)); QTest::newRow("float") << QVariant(floatValue) << QJsonValue(floatValue); diff --git a/tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp b/tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp index 56245a7173..76f2bb924a 100644 --- a/tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp +++ b/tests/auto/corelib/serialization/qcborvalue_json/tst_qcborvalue_json.cpp @@ -97,9 +97,12 @@ void tst_QCborValue_Json::toVariant_data() add(1, 1, 1); add(-1, -1, -1); add(0., 0., 0.); + add(2., 2., 2.); add(1.25, 1.25, 1.25); add(-1.25, -1.25, -1.25); add("Hello", "Hello", "Hello"); + add(std::numeric_limits<qint64>::max(), std::numeric_limits<qint64>::max(), std::numeric_limits<qint64>::max()); + add(std::numeric_limits<qint64>::min(), std::numeric_limits<qint64>::min(), std::numeric_limits<qint64>::min()); // converts to string in JSON: add(QByteArray("Hello"), QByteArray("Hello"), "SGVsbG8"); @@ -123,14 +126,6 @@ void tst_QCborValue_Json::toVariant_data() << QVariant(qQNaN()) << QJsonValue(); - // large integral values lose precision in JSON - QTest::newRow("Integer:max") << QCborValue(std::numeric_limits<qint64>::max()) - << QVariant(std::numeric_limits<qint64>::max()) - << QJsonValue(std::numeric_limits<qint64>::max()); - QTest::newRow("Integer:min") << QCborValue(std::numeric_limits<qint64>::min()) - << QVariant(std::numeric_limits<qint64>::min()) - << QJsonValue(std::numeric_limits<qint64>::min()); - // empty arrays and maps add(QCborArray(), QVariantList(), QJsonArray()); add(QCborMap(), QVariantMap(), QJsonObject()); @@ -257,6 +252,10 @@ void tst_QCborValue_Json::fromJson_data() QTest::newRow("0") << QCborValue(0) << QJsonValue(0.); QTest::newRow("1") << QCborValue(1) << QJsonValue(1); QTest::newRow("1.5") << QCborValue(1.5) << QJsonValue(1.5); + QTest::newRow("Integer:max") << QCborValue(std::numeric_limits<qint64>::max()) + << QJsonValue(std::numeric_limits<qint64>::max()); + QTest::newRow("Integer:min") << QCborValue(std::numeric_limits<qint64>::min()) + << QJsonValue(std::numeric_limits<qint64>::min()); QTest::newRow("string") << QCborValue("Hello") << QJsonValue("Hello"); QTest::newRow("array") << QCborValue(QCborValue::Array) << QJsonValue(QJsonValue::Array); QTest::newRow("map") << QCborValue(QCborValue::Map) << QJsonValue(QJsonValue::Object); diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index 8197c386c5..d402e3f63b 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -2327,6 +2327,7 @@ void tst_QDataStream::setVersion() QDataStream latest; QFETCH(int, vers); +#if QT_CONFIG(shortcut) /* Test QKeySequence. */ @@ -2351,6 +2352,7 @@ void tst_QDataStream::setVersion() } QCOMPARE(deadbeef, 0xDEADBEEF); } +#endif // QT_CONFIG(shortcut) /* Test QPalette. diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index 48dd7a241e..e3009a78fb 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -149,36 +149,17 @@ private slots: void stdString(); }; -static const struct StaticByteArrays { - struct Standard { - QByteArrayData data; - const char string[8]; - } standard; - struct NotNullTerminated { - QByteArrayData data; - const char string[8]; - } notNullTerminated; - struct Shifted { - QByteArrayData data; - const char dummy; // added to change offset of string - const char string[8]; - } shifted; - struct ShiftedNotNullTerminated { - QByteArrayData data; - const char dummy; // added to change offset of string - const char string[8]; - } shiftedNotNullTerminated; - -} statics = {{Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(4), "data"} - ,{Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(4), "dataBAD"} - ,{Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(4, sizeof(QByteArrayData) + sizeof(char)), 0, "data"} - ,{Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(4, sizeof(QByteArrayData) + sizeof(char)), 0, "dataBAD"} - }; - -static const QByteArrayDataPtr staticStandard = { const_cast<QByteArrayData *>(&statics.standard.data) }; -static const QByteArrayDataPtr staticNotNullTerminated = { const_cast<QByteArrayData *>(&statics.notNullTerminated.data) }; -static const QByteArrayDataPtr staticShifted = { const_cast<QByteArrayData *>(&statics.shifted.data) }; -static const QByteArrayDataPtr staticShiftedNotNullTerminated = { const_cast<QByteArrayData *>(&statics.shiftedNotNullTerminated.data) }; +static const QArrayData staticDataFlags = { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 }; +static const QByteArray::DataPointer staticStandard = { + static_cast<QTypedArrayData<char> *>(const_cast<QArrayData *>(&staticDataFlags)), + const_cast<char *>("data"), + 4 +}; +static const QByteArray::DataPointer staticNotNullTerminated = { + static_cast<QTypedArrayData<char> *>(const_cast<QArrayData *>(&staticDataFlags)), + const_cast<char *>("dataBAD"), + 4 +}; template <class T> const T &verifyZeroTermination(const T &t) { return t; } @@ -186,11 +167,10 @@ QByteArray verifyZeroTermination(const QByteArray &ba) { // This test does some evil stuff, it's all supposed to work. - QByteArray::DataPtr baDataPtr = const_cast<QByteArray &>(ba).data_ptr(); + QByteArray::DataPointer baDataPtr = const_cast<QByteArray &>(ba).data_ptr(); // Skip if isStatic() or fromRawData(), as those offer no guarantees - if (baDataPtr->ref.isStatic() - || baDataPtr->offset != QByteArray().data_ptr()->offset) + if (baDataPtr->isStatic() || baDataPtr->flags() & QArrayData::RawDataType) return ba; int baSize = ba.size(); @@ -201,7 +181,7 @@ QByteArray verifyZeroTermination(const QByteArray &ba) .arg(baTerminator, 2, 16, QChar('0')).toLatin1(); // Skip mutating checks on shared strings - if (baDataPtr->ref.isShared()) + if (baDataPtr->isShared()) return ba; const char *baData = ba.constData(); @@ -253,11 +233,11 @@ void tst_QByteArray::qChecksum_data() QTest::addColumn<uint>("checksum"); // Examples from ISO 14443-3 - QTest::newRow("1") << QByteArray("\x00\x00") << 2U << Qt::ChecksumItuV41 << 0x1EA0U; - QTest::newRow("2") << QByteArray("\x12\x34") << 2U << Qt::ChecksumItuV41 << 0xCF26U; - QTest::newRow("3") << QByteArray("\x00\x00\x00") << 3U << Qt::ChecksumIso3309 << 0xC6CCU; - QTest::newRow("4") << QByteArray("\x0F\xAA\xFF") << 3U << Qt::ChecksumIso3309 << 0xD1FCU; - QTest::newRow("5") << QByteArray("\x0A\x12\x34\x56") << 4U << Qt::ChecksumIso3309 << 0xF62CU; + QTest::newRow("1") << QByteArray("\x00\x00", 2) << 2U << Qt::ChecksumItuV41 << 0x1EA0U; + QTest::newRow("2") << QByteArray("\x12\x34", 2) << 2U << Qt::ChecksumItuV41 << 0xCF26U; + QTest::newRow("3") << QByteArray("\x00\x00\x00", 3) << 3U << Qt::ChecksumIso3309 << 0xC6CCU; + QTest::newRow("4") << QByteArray("\x0F\xAA\xFF", 3) << 3U << Qt::ChecksumIso3309 << 0xD1FCU; + QTest::newRow("5") << QByteArray("\x0A\x12\x34\x56", 4) << 4U << Qt::ChecksumIso3309 << 0xF62CU; } void tst_QByteArray::qChecksum() @@ -267,6 +247,7 @@ void tst_QByteArray::qChecksum() QFETCH(Qt::ChecksumType, standard); QFETCH(uint, checksum); + QCOMPARE(data.length(), int(len)); if (standard == Qt::ChecksumIso3309) { QCOMPARE(::qChecksum(data.constData(), len), static_cast<quint16>(checksum)); } @@ -1054,9 +1035,7 @@ void tst_QByteArray::prependExtended_data() QTest::addColumn<QByteArray>("array"); QTest::newRow("literal") << QByteArray(QByteArrayLiteral("data")); QTest::newRow("standard") << QByteArray(staticStandard); - QTest::newRow("shifted") << QByteArray(staticShifted); QTest::newRow("notNullTerminated") << QByteArray(staticNotNullTerminated); - QTest::newRow("shiftedNotNullTerminated") << QByteArray(staticShiftedNotNullTerminated); QTest::newRow("non static data") << QByteArray("data"); QTest::newRow("from raw data") << QByteArray::fromRawData("data", 4); QTest::newRow("from raw data not terminated") << QByteArray::fromRawData("dataBAD", 4); @@ -2122,21 +2101,13 @@ void tst_QByteArray::repeated_data() const << QByteArray(staticStandard) << QByteArray("datadatadatadata") << 4; - QTest::newRow("static shifted not null terminated") - << QByteArray(staticShiftedNotNullTerminated) - << QByteArray("datadatadatadata") - << 4; - QTest::newRow("static shifted") - << QByteArray(staticShifted) - << QByteArray("datadatadatadata") - << 4; } void tst_QByteArray::byteRefDetaching() const { { QByteArray str = "str"; - QByteArray copy; + QByteArray copy = str; copy[0] = 'S'; QCOMPARE(str, QByteArray("str")); @@ -2266,7 +2237,7 @@ void tst_QByteArray::movablity() const int newSize = size + 2; const bool newIsEmpty = false; const bool newIsNull = false; - const int newCapacity = 16; + const int newCapacity = memSpace.capacity(); // move back memSpace -> array array.~QByteArray(); @@ -2301,8 +2272,7 @@ void tst_QByteArray::literals() QVERIFY(str.length() == 4); QVERIFY(str == "abcd"); - QVERIFY(str.data_ptr()->ref.isStatic()); - QVERIFY(str.data_ptr()->offset == sizeof(QByteArrayData)); + QVERIFY(str.data_ptr()->isStatic()); const char *s = str.constData(); QByteArray str2 = str; diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index f86fbc5988..84e12cd46b 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -607,11 +607,10 @@ QString verifyZeroTermination(const QString &str) { // This test does some evil stuff, it's all supposed to work. - QString::DataPtr strDataPtr = const_cast<QString &>(str).data_ptr(); + QString::DataPointer strDataPtr = const_cast<QString &>(str).data_ptr(); // Skip if isStatic() or fromRawData(), as those offer no guarantees - if (strDataPtr->ref.isStatic() - || strDataPtr->offset != QString().data_ptr()->offset) + if (strDataPtr->isStatic() || !strDataPtr->isMutable()) return str; int strSize = str.size(); @@ -622,7 +621,7 @@ QString verifyZeroTermination(const QString &str) .arg(strTerminator.unicode(), 4, 16, QChar('0')); // Skip mutating checks on shared strings - if (strDataPtr->ref.isShared()) + if (strDataPtr->isShared()) return str; const QChar *strData = str.constData(); @@ -986,28 +985,6 @@ void tst_QString::acc_01() f[7]='F'; QCOMPARE(text[7],'!'); - a=""; - a[0]='A'; - QCOMPARE(a, QLatin1String("A")); - QCOMPARE(a.length(),1); - a[1]='B'; - QCOMPARE(a, QLatin1String("AB")); - QCOMPARE(a.length(),2); - a[2]='C'; - QCOMPARE(a, QLatin1String("ABC")); - QCOMPARE(a.length(),3); - a = QString(); - QVERIFY(a.isNull()); - a[0]='A'; - QCOMPARE(a, QLatin1String("A")); - QCOMPARE(a.length(),1); - a[1]='B'; - QCOMPARE(a, QLatin1String("AB")); - QCOMPARE(a.length(),2); - a[2]='C'; - QCOMPARE(a, QLatin1String("ABC")); - QCOMPARE(a.length(),3); - a="123"; b="456"; a[0]=a[1]; @@ -4071,8 +4048,9 @@ void tst_QString::setRawData() QVERIFY(cstr.constData() == ptr); QVERIFY(cstr == QString(ptr, 1)); + QSKIP("This is currently not working."); // This actually tests the recycling of the shared data object - QString::DataPtr csd = cstr.data_ptr(); + QString::DataPointer csd = cstr.data_ptr(); cstr.setRawData(ptr2, 1); QVERIFY(cstr.isDetached()); QVERIFY(cstr.constData() == ptr2); @@ -6418,7 +6396,7 @@ void tst_QString::QCharRefDetaching() const { { QString str = QString::fromLatin1("str"); - QString copy; + QString copy = str; copy[0] = QLatin1Char('S'); QCOMPARE(str, QString::fromLatin1("str")); @@ -6639,8 +6617,7 @@ void tst_QString::literals() QVERIFY(str.length() == 4); QVERIFY(str == QLatin1String("abcd")); - QVERIFY(str.data_ptr()->ref.isStatic()); - QVERIFY(str.data_ptr()->offset == sizeof(QStringData)); + QVERIFY(str.data_ptr()->isStatic()); const QChar *s = str.constData(); QString str2 = str; diff --git a/tests/auto/corelib/text/qstringref/tst_qstringref.cpp b/tests/auto/corelib/text/qstringref/tst_qstringref.cpp index 6f01947131..20d5426bf7 100644 --- a/tests/auto/corelib/text/qstringref/tst_qstringref.cpp +++ b/tests/auto/corelib/text/qstringref/tst_qstringref.cpp @@ -87,6 +87,7 @@ private slots: void mid(); void split_data(); void split(); + void nullToString(); }; static QStringRef emptyRef() @@ -2177,6 +2178,18 @@ void tst_QStringRef::split() } } +void tst_QStringRef::nullToString() +{ + QStringRef nullRef; + QVERIFY(nullRef.isNull()); + QVERIFY(nullRef.toString().isNull()); + + QString str; + nullRef = &str; + QVERIFY(nullRef.isNull()); + QVERIFY(nullRef.toString().isNull()); +} + QTEST_APPLESS_MAIN(tst_QStringRef) #include "tst_qstringref.moc" diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp index bef491d5f0..22ee7d17b7 100644 --- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp @@ -237,28 +237,23 @@ template <typename T> struct TypeInStruct { T type; }; void tst_QAtomicInt::alignment() { -#ifdef Q_ALIGNOF - // this will cause a build error if the alignment isn't the same - char dummy1[Q_ALIGNOF(QBasicAtomicInt) == Q_ALIGNOF(TypeInStruct<int>) ? 1 : -1]; - char dummy2[Q_ALIGNOF(QAtomicInt) == Q_ALIGNOF(TypeInStruct<int>) ? 1 : -1]; - (void)dummy1; (void)dummy2; + Q_STATIC_ASSERT(alignof(QBasicAtomicInt) == alignof(TypeInStruct<int>)); + Q_STATIC_ASSERT(alignof(QBasicAtomicInt) == alignof(TypeInStruct<int>)); #ifdef Q_ATOMIC_INT32_IS_SUPPORTED - QCOMPARE(Q_ALIGNOF(QBasicAtomicInteger<int>), Q_ALIGNOF(TypeInStruct<int>)); + QCOMPARE(alignof(QBasicAtomicInteger<int>), alignof(TypeInStruct<int>)); #endif #ifdef Q_ATOMIC_INT16_IS_SUPPORTED - QCOMPARE(Q_ALIGNOF(QBasicAtomicInteger<short>), Q_ALIGNOF(TypeInStruct<short>)); + QCOMPARE(alignof(QBasicAtomicInteger<short>), alignof(TypeInStruct<short>)); #endif #ifdef Q_ATOMIC_INT8_IS_SUPPORTED - QCOMPARE(Q_ALIGNOF(QBasicAtomicInteger<char>), Q_ALIGNOF(TypeInStruct<char>)); + QCOMPARE(alignof(QBasicAtomicInteger<char>), alignof(TypeInStruct<char>)); #endif #ifdef Q_ATOMIC_INT64_IS_SUPPORTED - QCOMPARE(Q_ALIGNOF(QBasicAtomicInteger<qlonglong>), Q_ALIGNOF(TypeInStruct<qlonglong>)); -#endif - + QCOMPARE(alignof(QBasicAtomicInteger<qlonglong>), alignof(TypeInStruct<qlonglong>)); #endif } diff --git a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp index a699cf6202..9e12e7ccce 100644 --- a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp +++ b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp @@ -108,11 +108,7 @@ void tst_QAtomicPointer::warningFree() void tst_QAtomicPointer::alignment() { -#ifdef Q_ALIGNOF - // this will cause a build error if the alignment isn't the same - char dummy[Q_ALIGNOF(QBasicAtomicPointer<void>) == Q_ALIGNOF(void*) ? 1 : -1]; - (void)dummy; -#endif + Q_STATIC_ASSERT(alignof(QBasicAtomicPointer<void>) == alignof(void*)); } void tst_QAtomicPointer::constructor() diff --git a/tests/auto/corelib/thread/qfuture/qfuture.pro b/tests/auto/corelib/thread/qfuture/qfuture.pro index 1f21130af7..fe097edf20 100644 --- a/tests/auto/corelib/thread/qfuture/qfuture.pro +++ b/tests/auto/corelib/thread/qfuture/qfuture.pro @@ -2,5 +2,4 @@ CONFIG += testcase TARGET = tst_qfuture QT = core core-private testlib SOURCES = tst_qfuture.cpp -DEFINES += QT_STRICT_ITERATORS DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/thread/qresultstore/qresultstore.pro b/tests/auto/corelib/thread/qresultstore/qresultstore.pro index bbebe0976b..80e79b1c1a 100644 --- a/tests/auto/corelib/thread/qresultstore/qresultstore.pro +++ b/tests/auto/corelib/thread/qresultstore/qresultstore.pro @@ -2,4 +2,3 @@ CONFIG += testcase TARGET = tst_qresultstore QT = core-private testlib SOURCES = tst_qresultstore.cpp -DEFINES += QT_STRICT_ITERATORS diff --git a/tests/auto/corelib/tools/collections/collections.pro b/tests/auto/corelib/tools/collections/collections.pro index e0f9f0a0ea..d5e4e226b5 100644 --- a/tests/auto/corelib/tools/collections/collections.pro +++ b/tests/auto/corelib/tools/collections/collections.pro @@ -5,5 +5,4 @@ QT = core testlib # This test does not work with strict iterators DEFINES -= QT_NO_LINKED_LIST -DEFINES -= QT_STRICT_ITERATORS DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index e79a4dba29..023b22b4ba 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -84,10 +84,6 @@ void foo() #include "qvector.h" #include "qqueue.h" -QT_BEGIN_NAMESPACE -template class QList<int>; -QT_END_NAMESPACE - class tst_Collections : public QObject { Q_OBJECT @@ -551,19 +547,12 @@ void tst_Collections::list() list << "foo" << "bar"; QVERIFY(!list.isEmpty()); - list.insert(-1, "lessthanzero"); - QCOMPARE(list.at(0), QString("lessthanzero")); - list.insert(0, "atzero"); QCOMPARE(list.at(0), QString("atzero")); int listCount = list.count(); list.insert(listCount, "atcount"); QCOMPARE(list.at(listCount), QString("atcount")); - - listCount = list.count(); - list.insert(listCount + 1, "beyondcount"); - QCOMPARE(list.at(listCount), QString("beyondcount")); } { @@ -2337,12 +2326,6 @@ void populate(QLinkedList<int> &container) } template <> -void populate(QVector<int> &container) -{ - container << 1 << 2 << 4 << 8; -} - -template <> void populate(QMap<int, int> &container) { container.insert(1, 1); @@ -3214,9 +3197,7 @@ void tst_Collections::forwardDeclared() { typedef QSet<T1> C; C *x = 0; /* C::iterator i; */ C::const_iterator j; Q_UNUSED(x) } } -#if defined(Q_ALIGNOF) && defined(Q_DECL_ALIGN) - -class Q_DECL_ALIGN(4) Aligned4 +class alignas(4) Aligned4 { char i; public: @@ -3228,7 +3209,7 @@ public: inline bool operator<(const Aligned4 &other) const { return i < other.i; } friend inline int qHash(const Aligned4 &a) { return qHash(a.i); } }; -Q_STATIC_ASSERT(Q_ALIGNOF(Aligned4) % 4 == 0); +Q_STATIC_ASSERT(alignof(Aligned4) % 4 == 0); #if defined(Q_PROCESSOR_ARM) # if defined(Q_COMPILER_ALIGNAS) && defined(__BIGGEST_ALIGNMENT__) @@ -3242,7 +3223,7 @@ Q_STATIC_ASSERT(Q_ALIGNOF(Aligned4) % 4 == 0); # define BIGGEST_ALIGNMENT_TO_TEST 128 #endif -class Q_DECL_ALIGN(BIGGEST_ALIGNMENT_TO_TEST) AlignedBiggest +class alignas(BIGGEST_ALIGNMENT_TO_TEST) AlignedBiggest { char i; public: @@ -3254,7 +3235,7 @@ public: inline bool operator<(const AlignedBiggest &other) const { return i < other.i; } friend inline int qHash(const AlignedBiggest &a) { return qHash(a.i); } }; -Q_STATIC_ASSERT(Q_ALIGNOF(AlignedBiggest) % BIGGEST_ALIGNMENT_TO_TEST == 0); +Q_STATIC_ASSERT(alignof(AlignedBiggest) % BIGGEST_ALIGNMENT_TO_TEST == 0); template<typename C> void testVectorAlignment() @@ -3325,13 +3306,6 @@ void tst_Collections::alignment() testAssociativeContainerAlignment<QHash<AlignedBiggest, AlignedBiggest> >(); } -#else -void tst_Collections::alignment() -{ - QSKIP("Compiler doesn't support necessary extension keywords"); -} -#endif - #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS template<template<class> class C> @@ -3510,9 +3484,6 @@ void tst_Collections::foreach_2() QCOMPARE(varl1.count(), intlist.count()); QCOMPARE(varl2.count(), intlist.count()); QCOMPARE(varl3.count(), intlist.count()); - foreach_test_arrays(varl1); - foreach_test_arrays(varl2); - foreach_test_arrays(varl3); QVarLengthArray<QString> varl4; QVarLengthArray<QString, 3> varl5; @@ -3525,9 +3496,6 @@ void tst_Collections::foreach_2() QCOMPARE(varl4.count(), strlist.count()); QCOMPARE(varl5.count(), strlist.count()); QCOMPARE(varl6.count(), strlist.count()); - foreach_test_arrays(varl4); - foreach_test_arrays(varl5); - foreach_test_arrays(varl6); } struct IntOrString @@ -3615,30 +3583,8 @@ template<class Container> void insert_remove_loop_impl() } -//Add insert(int, int, T) so it has the same interface as QVector and QVarLengthArray for the test. template<typename T> -struct ExtList : QList<T> { - using QList<T>::insert; - void insert(int before, int n, const T&x) { - while (n--) { - this->insert(before, x ); - } - } - void insert(typename QList<T>::iterator before, int n, const T&x) { - while (n--) { - before = this->insert(before, x); - } - } - - void remove(int i) { - this->removeAt(i); - } - void remove(int i, int n) { - while (n--) { - this->removeAt(i); - } - } -}; +using ExtList = QList<T>; void tst_Collections::insert_remove_loop() { diff --git a/tests/auto/corelib/tools/containerapisymmetry/containerapisymmetry.pro b/tests/auto/corelib/tools/containerapisymmetry/containerapisymmetry.pro index e46d51761e..efdb7fc2df 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/containerapisymmetry.pro +++ b/tests/auto/corelib/tools/containerapisymmetry/containerapisymmetry.pro @@ -3,6 +3,4 @@ TARGET = tst_containerapisymmetry SOURCES += tst_containerapisymmetry.cpp QT = core testlib -# This test does not work with strict iterators -DEFINES -= QT_STRICT_ITERATORS DEFINES -= QT_NO_LINKED_LIST diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 88c0c5055c..0e4517e740 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -580,9 +580,6 @@ template<typename ... T> struct ContainerDuplicatedValuesStrategy<VarLengthArray<T...>> : ContainerAcceptsDuplicateValues {}; template<typename ... T> -struct ContainerDuplicatedValuesStrategy<QList<T...>> : ContainerAcceptsDuplicateValues {}; - -template<typename ... T> struct ContainerDuplicatedValuesStrategy<std::list<T...>> : ContainerAcceptsDuplicateValues {}; #if COMPILER_HAS_STDLIB_INCLUDE(<forward_list>) @@ -798,8 +795,6 @@ template <> QStringView make(int size) { return QStringView(s_string).left(siz template <> QLatin1String make(int size) { return QLatin1String("\1\2\3\4\5\6\7", size); } template <typename T> T clean(T &&t) { return std::forward<T>(t); } -inline QChar clean(QCharRef ch) { return ch; } -inline char clean(QByteRef ch) { return ch; } inline char clean(QLatin1Char ch) { return ch.toLatin1(); } template <typename Container> diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h index 9dd8b05796..94cee5d887 100644 --- a/tests/auto/corelib/tools/qarraydata/simplevector.h +++ b/tests/auto/corelib/tools/qarraydata/simplevector.h @@ -76,25 +76,32 @@ public: { } - explicit SimpleVector(Data *ptr) - : d(ptr) + template <size_t N> + explicit SimpleVector(QStaticArrayData<T, N> &ptr) + : d(static_cast<Data *>(&ptr.header), ptr.data, N) + { + } + + SimpleVector(Data *header, T *data, size_t len = 0) + : d(header, data, len) + { + } + + explicit SimpleVector(QPair<Data*, T*> ptr, size_t len = 0) + : d(ptr, len) { } - bool empty() const { return d->size == 0; } + bool empty() const { return d.size == 0; } bool isNull() const { return d.isNull(); } bool isEmpty() const { return this->empty(); } - bool isStatic() const { return d->ref.isStatic(); } - bool isShared() const { return d->ref.isShared(); } + bool isStatic() const { return d->isStatic(); } + bool isShared() const { return d->isShared(); } bool isSharedWith(const SimpleVector &other) const { return d == other.d; } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - bool isSharable() const { return d->ref.isSharable(); } - void setSharable(bool sharable) { d.setSharable(sharable); } -#endif - size_t size() const { return d->size; } - size_t capacity() const { return d->alloc; } + size_t size() const { return d.size; } + size_t capacity() const { return d->constAllocatedCapacity(); } iterator begin() { detach(); return d->begin(); } iterator end() { detach(); return d->end(); } @@ -143,10 +150,10 @@ public: return; if (n <= capacity()) { - if (d->capacityReserved) + if (d->flags() & Data::CapacityReserved) return; - if (!d->ref.isShared()) { - d->capacityReserved = 1; + if (!d->isShared()) { + d->flags() |= Data::CapacityReserved; return; } } @@ -163,7 +170,7 @@ public: if (size() == newSize) return; - if (d.needsDetach() || newSize > capacity()) { + if (d->needsDetach() || newSize > capacity()) { SimpleVector detached(Data::allocate( d->detachCapacity(newSize), d->detachFlags())); if (newSize) { @@ -199,11 +206,11 @@ public: return; T *const begin = d->begin(); - if (d.needsDetach() + if (d->needsDetach() || capacity() - size() < size_t(last - first)) { SimpleVector detached(Data::allocate( d->detachCapacity(size() + (last - first)), - d->detachFlags() | Data::Grow)); + d->detachFlags() | Data::GrowsForward)); detached.d->copyAppend(first, last); detached.d->copyAppend(begin, begin + d->size); @@ -220,11 +227,11 @@ public: if (first == last) return; - if (d.needsDetach() + if (d->needsDetach() || capacity() - size() < size_t(last - first)) { SimpleVector detached(Data::allocate( d->detachCapacity(size() + (last - first)), - d->detachFlags() | Data::Grow)); + d->detachFlags() | Data::GrowsForward)); if (d->size) { const T *const begin = constBegin(); @@ -260,11 +267,11 @@ public: const iterator begin = d->begin(); const iterator where = begin + position; const iterator end = begin + d->size; - if (d.needsDetach() + if (d->needsDetach() || capacity() - size() < size_t(last - first)) { SimpleVector detached(Data::allocate( d->detachCapacity(size() + (last - first)), - d->detachFlags() | Data::Grow)); + d->detachFlags() | Data::GrowsForward)); if (position) detached.d->copyAppend(begin, where); @@ -298,7 +305,7 @@ public: const T *const begin = d->begin(); const T *const end = begin + d->size; - if (d.needsDetach()) { + if (d->needsDetach()) { SimpleVector detached(Data::allocate( d->detachCapacity(size() - (last - first)), d->detachFlags())); @@ -332,7 +339,7 @@ public: } static SimpleVector fromRawData(const T *data, size_t size, - QArrayData::AllocationOptions options = Data::Default) + QArrayData::ArrayOptions options = Data::DefaultRawFlags) { return SimpleVector(Data::fromRawData(data, size, options)); } diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 25e2f21d03..1366eebf97 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -37,11 +37,8 @@ struct SharedNullVerifier { SharedNullVerifier() { - Q_ASSERT(QArrayData::shared_null[0].ref.isStatic()); - Q_ASSERT(QArrayData::shared_null[0].ref.isShared()); -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - Q_ASSERT(QArrayData::shared_null[0].ref.isSharable()); -#endif + Q_ASSERT(QArrayData::shared_null[0].isStatic()); + Q_ASSERT(QArrayData::shared_null[0].isShared()); } }; @@ -59,7 +56,6 @@ class tst_QArrayData : public QObject private slots: void referenceCounting(); void sharedNullEmpty(); - void staticData(); void simpleVector(); void simpleVectorReserve_data(); void simpleVectorReserve(); @@ -73,8 +69,6 @@ private slots: void gccBug43247(); void arrayOps(); void arrayOps2(); - void setSharable_data(); - void setSharable(); void fromRawData_data(); void fromRawData(); void literals(); @@ -89,70 +83,42 @@ void tst_QArrayData::referenceCounting() { { // Reference counting initialized to 1 (owned) - QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(1) }, 0, 0, 0, 0 }; + QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(1), QArrayData::DefaultRawFlags, 0 }; - QCOMPARE(array.ref.atomic.loadRelaxed(), 1); + QCOMPARE(array.ref_.loadRelaxed(), 1); - QVERIFY(!array.ref.isStatic()); -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QVERIFY(array.ref.isSharable()); -#endif + QVERIFY(!array.isStatic()); - QVERIFY(array.ref.ref()); - QCOMPARE(array.ref.atomic.loadRelaxed(), 2); + QVERIFY(array.ref()); + QCOMPARE(array.ref_.loadRelaxed(), 2); - QVERIFY(array.ref.deref()); - QCOMPARE(array.ref.atomic.loadRelaxed(), 1); + QVERIFY(array.deref()); + QCOMPARE(array.ref_.loadRelaxed(), 1); - QVERIFY(array.ref.ref()); - QCOMPARE(array.ref.atomic.loadRelaxed(), 2); + QVERIFY(array.ref()); + QCOMPARE(array.ref_.loadRelaxed(), 2); - QVERIFY(array.ref.deref()); - QCOMPARE(array.ref.atomic.loadRelaxed(), 1); + QVERIFY(array.deref()); + QCOMPARE(array.ref_.loadRelaxed(), 1); - QVERIFY(!array.ref.deref()); - QCOMPARE(array.ref.atomic.loadRelaxed(), 0); + QVERIFY(!array.deref()); + QCOMPARE(array.ref_.loadRelaxed(), 0); // Now would be a good time to free/release allocated data } - -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - { - // Reference counting initialized to 0 (non-sharable) - QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 }; - - QCOMPARE(array.ref.atomic.loadRelaxed(), 0); - - QVERIFY(!array.ref.isStatic()); - QVERIFY(!array.ref.isSharable()); - - QVERIFY(!array.ref.ref()); - // Reference counting fails, data should be copied - QCOMPARE(array.ref.atomic.loadRelaxed(), 0); - - QVERIFY(!array.ref.deref()); - QCOMPARE(array.ref.atomic.loadRelaxed(), 0); - - // Free/release data - } -#endif - { // Reference counting initialized to -1 (static read-only data) - QArrayData array = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 }; + QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 }; - QCOMPARE(array.ref.atomic.loadRelaxed(), -1); + QCOMPARE(array.ref_.loadRelaxed(), -1); - QVERIFY(array.ref.isStatic()); -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QVERIFY(array.ref.isSharable()); -#endif + QVERIFY(array.isStatic()); - QVERIFY(array.ref.ref()); - QCOMPARE(array.ref.atomic.loadRelaxed(), -1); + QVERIFY(array.ref()); + QCOMPARE(array.ref_.loadRelaxed(), -1); - QVERIFY(array.ref.deref()); - QCOMPARE(array.ref.atomic.loadRelaxed(), -1); + QVERIFY(array.deref()); + QCOMPARE(array.ref_.loadRelaxed(), -1); } } @@ -160,74 +126,39 @@ void tst_QArrayData::referenceCounting() void tst_QArrayData::sharedNullEmpty() { QArrayData *null = const_cast<QArrayData *>(QArrayData::shared_null); - QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0); - - QVERIFY(null->ref.isStatic()); - QVERIFY(null->ref.isShared()); + QArrayData *empty; + QArrayData::allocate(&empty, 1, alignof(QArrayData), 0); - QVERIFY(empty->ref.isStatic()); - QVERIFY(empty->ref.isShared()); + QVERIFY(null->isStatic()); + QVERIFY(null->isShared()); - QCOMPARE(null->ref.atomic.loadRelaxed(), -1); - QCOMPARE(empty->ref.atomic.loadRelaxed(), -1); + QVERIFY(empty->isStatic()); + QVERIFY(empty->isShared()); -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QVERIFY(null->ref.isSharable()); - QVERIFY(empty->ref.isSharable()); -#endif + QCOMPARE(null->ref_.loadRelaxed(), -1); + QCOMPARE(empty->ref_.loadRelaxed(), -1); - QVERIFY(null->ref.ref()); - QVERIFY(empty->ref.ref()); + QCOMPARE(null->ref_.loadRelaxed(), -1); + QCOMPARE(empty->ref_.loadRelaxed(), -1); - QCOMPARE(null->ref.atomic.loadRelaxed(), -1); - QCOMPARE(empty->ref.atomic.loadRelaxed(), -1); + QVERIFY(null->deref()); + QVERIFY(empty->deref()); - QVERIFY(null->ref.deref()); - QVERIFY(empty->ref.deref()); - - QCOMPARE(null->ref.atomic.loadRelaxed(), -1); - QCOMPARE(empty->ref.atomic.loadRelaxed(), -1); + QCOMPARE(null->ref_.loadRelaxed(), -1); + QCOMPARE(empty->ref_.loadRelaxed(), -1); QVERIFY(null != empty); - QCOMPARE(null->size, 0); - QCOMPARE(null->alloc, 0u); - QCOMPARE(null->capacityReserved, 0u); + QCOMPARE(null->allocatedCapacity(), size_t(0)); - QCOMPARE(empty->size, 0); - QCOMPARE(empty->alloc, 0u); - QCOMPARE(empty->capacityReserved, 0u); -} - -void tst_QArrayData::staticData() -{ - QStaticArrayData<char, 10> charArray = { - Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(char, 10), - { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' } - }; - QStaticArrayData<int, 10> intArray = { - Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 10), - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } - }; - QStaticArrayData<double, 10> doubleArray = { - Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(double, 10), - { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f } - }; - - QCOMPARE(charArray.header.size, 10); - QCOMPARE(intArray.header.size, 10); - QCOMPARE(doubleArray.header.size, 10); - - QCOMPARE(charArray.header.data(), reinterpret_cast<void *>(&charArray.data)); - QCOMPARE(intArray.header.data(), reinterpret_cast<void *>(&intArray.data)); - QCOMPARE(doubleArray.header.data(), reinterpret_cast<void *>(&doubleArray.data)); + QCOMPARE(empty->allocatedCapacity(), size_t(0)); } void tst_QArrayData::simpleVector() { - QArrayData data0 = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 }; + QArrayData data0 = { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 }; QStaticArrayData<int, 7> data1 = { - Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 7), + { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 }, { 0, 1, 2, 3, 4, 5, 6 } }; @@ -235,10 +166,10 @@ void tst_QArrayData::simpleVector() SimpleVector<int> v1; SimpleVector<int> v2(v1); - SimpleVector<int> v3(static_cast<QTypedArrayData<int> *>(&data0)); - SimpleVector<int> v4(static_cast<QTypedArrayData<int> *>(&data1.header)); - SimpleVector<int> v5(static_cast<QTypedArrayData<int> *>(&data0)); - SimpleVector<int> v6(static_cast<QTypedArrayData<int> *>(&data1.header)); + SimpleVector<int> v3(static_cast<QTypedArrayData<int> *>(&data0), 0, 0); + SimpleVector<int> v4(data1); + SimpleVector<int> v5(static_cast<QTypedArrayData<int> *>(&data0), 0, 0); + SimpleVector<int> v6(data1); SimpleVector<int> v7(10, 5); SimpleVector<int> v8(array, array + sizeof(array)/sizeof(*array)); @@ -302,17 +233,6 @@ void tst_QArrayData::simpleVector() QVERIFY(!v7.isShared()); QVERIFY(!v8.isShared()); -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QVERIFY(v1.isSharable()); - QVERIFY(v2.isSharable()); - QVERIFY(v3.isSharable()); - QVERIFY(v4.isSharable()); - QVERIFY(v5.isSharable()); - QVERIFY(v6.isSharable()); - QVERIFY(v7.isSharable()); - QVERIFY(v8.isSharable()); -#endif - QVERIFY(v1.isSharedWith(v2)); QVERIFY(v1.isSharedWith(v3)); QVERIFY(v1.isSharedWith(v4)); @@ -494,71 +414,6 @@ void tst_QArrayData::simpleVector() for (int i = 0; i < 120; ++i) QCOMPARE(v1[i], v8[i % 10]); - -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - { - v7.setSharable(true); - QVERIFY(v7.isSharable()); - - SimpleVector<int> copy1(v7); - QVERIFY(copy1.isSharedWith(v7)); - - v7.setSharable(false); - QVERIFY(!v7.isSharable()); - - QVERIFY(!copy1.isSharedWith(v7)); - QCOMPARE(v7.size(), copy1.size()); - for (size_t i = 0; i < copy1.size(); ++i) - QCOMPARE(v7[i], copy1[i]); - - SimpleVector<int> clone(v7); - QVERIFY(!clone.isSharedWith(v7)); - QCOMPARE(clone.size(), copy1.size()); - for (size_t i = 0; i < copy1.size(); ++i) - QCOMPARE(clone[i], copy1[i]); - - v7.setSharable(true); - QVERIFY(v7.isSharable()); - - SimpleVector<int> copy2(v7); - QVERIFY(copy2.isSharedWith(v7)); - } - - { - SimpleVector<int> null; - SimpleVector<int> empty(0, 5); - - QVERIFY(null.isSharable()); - QVERIFY(empty.isSharable()); - - null.setSharable(true); - empty.setSharable(true); - - QVERIFY(null.isSharable()); - QVERIFY(empty.isSharable()); - - QVERIFY(null.isEmpty()); - QVERIFY(empty.isEmpty()); - - null.setSharable(false); - empty.setSharable(false); - - QVERIFY(!null.isSharable()); - QVERIFY(!empty.isSharable()); - - QVERIFY(null.isEmpty()); - QVERIFY(empty.isEmpty()); - - null.setSharable(true); - empty.setSharable(true); - - QVERIFY(null.isSharable()); - QVERIFY(empty.isSharable()); - - QVERIFY(null.isEmpty()); - QVERIFY(empty.isEmpty()); - } -#endif } Q_DECLARE_METATYPE(SimpleVector<int>) @@ -574,11 +429,13 @@ void tst_QArrayData::simpleVectorReserve_data() QTest::newRow("non-empty") << SimpleVector<int>(5, 42) << size_t(5) << size_t(5); static const QStaticArrayData<int, 15> array = { - Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 15), + { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } }; - QArrayDataPointerRef<int> p = { + const QArrayDataPointerRef<int> p = { static_cast<QTypedArrayData<int> *>( - const_cast<QArrayData *>(&array.header)) }; + const_cast<QArrayData *>(&array.header)), + const_cast<int *>(array.data), + sizeof(array.data) / sizeof(array.data[0]) }; QTest::newRow("static") << SimpleVector<int>(p) << size_t(0) << size_t(15); QTest::newRow("raw-data") << SimpleVector<int>::fromRawData(array.data, 15) << size_t(0) << size_t(15); @@ -641,15 +498,14 @@ struct Deallocator }; Q_DECLARE_METATYPE(const QArrayData *) -Q_DECLARE_METATYPE(QArrayData::AllocationOptions) +Q_DECLARE_METATYPE(QArrayData::ArrayOptions) void tst_QArrayData::allocate_data() { QTest::addColumn<size_t>("objectSize"); QTest::addColumn<size_t>("alignment"); - QTest::addColumn<QArrayData::AllocationOptions>("allocateOptions"); + QTest::addColumn<QArrayData::ArrayOptions>("allocateOptions"); QTest::addColumn<bool>("isCapacityReserved"); - QTest::addColumn<bool>("isSharable"); // ### Qt6: remove QTest::addColumn<const QArrayData *>("commonEmpty"); struct { @@ -657,35 +513,24 @@ void tst_QArrayData::allocate_data() size_t objectSize; size_t alignment; } types[] = { - { "char", sizeof(char), Q_ALIGNOF(char) }, - { "short", sizeof(short), Q_ALIGNOF(short) }, - { "void *", sizeof(void *), Q_ALIGNOF(void *) } + { "char", sizeof(char), alignof(char) }, + { "short", sizeof(short), alignof(short) }, + { "void *", sizeof(void *), alignof(void *) } }; - QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0); + QArrayData *shared_empty; + QArrayData::allocate(&shared_empty, 1, alignof(QArrayData), 0); QVERIFY(shared_empty); -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable); - QVERIFY(unsharable_empty); -#endif - struct { char const *description; - QArrayData::AllocationOptions allocateOptions; + QArrayData::ArrayOptions allocateOptions; bool isCapacityReserved; - bool isSharable; const QArrayData *commonEmpty; } options[] = { - { "Default", QArrayData::Default, false, true, shared_empty }, - { "Reserved", QArrayData::CapacityReserved, true, true, shared_empty }, -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - { "Reserved | Unsharable", - QArrayData::CapacityReserved | QArrayData::Unsharable, true, false, - unsharable_empty }, - { "Unsharable", QArrayData::Unsharable, false, false, unsharable_empty }, -#endif - { "Grow", QArrayData::Grow, false, true, shared_empty } + { "Default", QArrayData::DefaultAllocationFlags, false, shared_empty }, + { "Reserved", QArrayData::CapacityReserved, true, shared_empty }, + { "Grow", QArrayData::GrowsForward, false, shared_empty } }; for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); ++i) @@ -696,47 +541,45 @@ void tst_QArrayData::allocate_data() + QLatin1String(options[j].description))) << types[i].objectSize << types[i].alignment << options[j].allocateOptions << options[j].isCapacityReserved - << options[j].isSharable << options[j].commonEmpty; + << options[j].commonEmpty; } void tst_QArrayData::allocate() { QFETCH(size_t, objectSize); QFETCH(size_t, alignment); - QFETCH(QArrayData::AllocationOptions, allocateOptions); + QFETCH(QArrayData::ArrayOptions, allocateOptions); QFETCH(bool, isCapacityReserved); QFETCH(const QArrayData *, commonEmpty); // Minimum alignment that can be requested is that of QArrayData. // Typically, this alignment is sizeof(void *) and ensured by malloc. - size_t minAlignment = qMax(alignment, Q_ALIGNOF(QArrayData)); + size_t minAlignment = qMax(alignment, alignof(QArrayData)); // Shared Empty - QCOMPARE(QArrayData::allocate(objectSize, minAlignment, 0, - QArrayData::AllocationOptions(allocateOptions)), commonEmpty); + QArrayData *empty; + QCOMPARE((QArrayData::allocate(&empty, objectSize, minAlignment, 0, + QArrayData::ArrayOptions(allocateOptions)), empty), commonEmpty); Deallocator keeper(objectSize, minAlignment); keeper.headers.reserve(1024); for (int capacity = 1; capacity <= 1024; capacity <<= 1) { - QArrayData *data = QArrayData::allocate(objectSize, minAlignment, - capacity, QArrayData::AllocationOptions(allocateOptions)); + QArrayData *data; + void *dataPointer = QArrayData::allocate(&data, objectSize, minAlignment, + capacity, QArrayData::ArrayOptions(allocateOptions)); + keeper.headers.append(data); - QCOMPARE(data->size, 0); - if (allocateOptions & QArrayData::Grow) - QVERIFY(data->alloc > uint(capacity)); + if (allocateOptions & QArrayData::GrowsForward) + QVERIFY(data->allocatedCapacity() > uint(capacity)); else - QCOMPARE(data->alloc, uint(capacity)); - QCOMPARE(data->capacityReserved, uint(isCapacityReserved)); -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QFETCH(bool, isSharable); - QCOMPARE(data->ref.isSharable(), isSharable); -#endif + QCOMPARE(data->allocatedCapacity(), size_t(capacity)); + QCOMPARE(bool(data->flags & QArrayData::CapacityReserved), isCapacityReserved); // Check that the allocated array can be used. Best tested with a // memory checker, such as valgrind, running. - ::memset(data->data(), 'A', objectSize * capacity); + ::memset(dataPointer, 'A', objectSize * capacity); } } @@ -744,47 +587,40 @@ void tst_QArrayData::reallocate() { QFETCH(size_t, objectSize); QFETCH(size_t, alignment); - QFETCH(QArrayData::AllocationOptions, allocateOptions); + QFETCH(QArrayData::ArrayOptions, allocateOptions); QFETCH(bool, isCapacityReserved); - // Maximum alignment that can be requested is that of QArrayData, - // otherwise, we can't use reallocate(). - Q_ASSERT(alignment <= Q_ALIGNOF(QArrayData)); - // Minimum alignment that can be requested is that of QArrayData. // Typically, this alignment is sizeof(void *) and ensured by malloc. - size_t minAlignment = qMax(alignment, Q_ALIGNOF(QArrayData)); + size_t minAlignment = qMax(alignment, alignof(QArrayData)); int capacity = 10; Deallocator keeper(objectSize, minAlignment); - QArrayData *data = QArrayData::allocate(objectSize, minAlignment, capacity, - QArrayData::AllocationOptions(allocateOptions) & ~QArrayData::Grow); + QArrayData *data; + void *dataPointer = QArrayData::allocate(&data, objectSize, minAlignment, capacity, + QArrayData::ArrayOptions(allocateOptions) & ~QArrayData::GrowsForward); keeper.headers.append(data); - memset(data->data(), 'A', objectSize * capacity); - data->size = capacity; + memset(dataPointer, 'A', objectSize * capacity); // now try to reallocate int newCapacity = 40; - data = QArrayData::reallocateUnaligned(data, objectSize, newCapacity, - QArrayData::AllocationOptions(allocateOptions)); + auto pair = QArrayData::reallocateUnaligned(data, dataPointer, objectSize, newCapacity, + QArrayData::ArrayOptions(allocateOptions)); + data = pair.first; + dataPointer = pair.second; QVERIFY(data); keeper.headers.clear(); keeper.headers.append(data); - QCOMPARE(data->size, capacity); - if (allocateOptions & QArrayData::Grow) - QVERIFY(data->alloc > uint(newCapacity)); + if (allocateOptions & QArrayData::GrowsForward) + QVERIFY(data->allocatedCapacity() > size_t(newCapacity)); else - QCOMPARE(data->alloc, uint(newCapacity)); - QCOMPARE(data->capacityReserved, uint(isCapacityReserved)); -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QFETCH(bool, isSharable); - QCOMPARE(data->ref.isSharable(), isSharable); -#endif + QCOMPARE(data->allocatedCapacity(), size_t(newCapacity)); + QCOMPARE(!(data->flags & QArrayData::CapacityReserved), !isCapacityReserved); for (int i = 0; i < capacity; ++i) - QCOMPARE(static_cast<char *>(data->data())[i], 'A'); + QCOMPARE(static_cast<char *>(dataPointer)[i], 'A'); } class Unaligned @@ -808,95 +644,52 @@ void tst_QArrayData::alignment() // Minimum alignment that can be requested is that of QArrayData. // Typically, this alignment is sizeof(void *) and ensured by malloc. - size_t minAlignment = qMax(alignment, Q_ALIGNOF(QArrayData)); + size_t minAlignment = qMax(alignment, alignof(QArrayData)); Deallocator keeper(sizeof(Unaligned), minAlignment); keeper.headers.reserve(100); for (int i = 0; i < 100; ++i) { - QArrayData *data = QArrayData::allocate(sizeof(Unaligned), - minAlignment, 8, QArrayData::Default); + QArrayData *data; + void *dataPointer = QArrayData::allocate(&data, sizeof(Unaligned), + minAlignment, 8, QArrayData::DefaultAllocationFlags); keeper.headers.append(data); QVERIFY(data); - QCOMPARE(data->size, 0); - QVERIFY(data->alloc >= uint(8)); + QVERIFY(data->allocatedCapacity() >= uint(8)); // These conditions should hold as long as header and array are // allocated together - QVERIFY(data->offset >= qptrdiff(sizeof(QArrayData))); - QVERIFY(data->offset <= qptrdiff(sizeof(QArrayData) - + minAlignment - Q_ALIGNOF(QArrayData))); + qptrdiff offset = reinterpret_cast<char *>(dataPointer) - + reinterpret_cast<char *>(data); + QVERIFY(offset >= qptrdiff(sizeof(QArrayData))); + QVERIFY(offset <= qptrdiff(sizeof(QArrayData) + + minAlignment - alignof(QArrayData))); // Data is aligned - QCOMPARE(quintptr(quintptr(data->data()) % alignment), quintptr(0u)); + QCOMPARE(quintptr(quintptr(dataPointer) % alignment), quintptr(0u)); // Check that the allocated array can be used. Best tested with a // memory checker, such as valgrind, running. - ::memset(data->data(), 'A', sizeof(Unaligned) * 8); + ::memset(dataPointer, 'A', sizeof(Unaligned) * 8); } } void tst_QArrayData::typedData() { - QStaticArrayData<int, 10> data = { - Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 10), - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } - }; - QCOMPARE(data.header.size, 10); - - { - QTypedArrayData<int> *array = - static_cast<QTypedArrayData<int> *>(&data.header); - QCOMPARE(array->data(), data.data); - - int j = 0; - for (QTypedArrayData<int>::iterator iter = array->begin(); - iter != array->end(); ++iter, ++j) - QCOMPARE((const int *)iter, data.data + j); - QCOMPARE(j, 10); - } - - { - const QTypedArrayData<int> *array = - static_cast<const QTypedArrayData<int> *>(&data.header); - - QCOMPARE(array->data(), data.data); - - int j = 0; - for (QTypedArrayData<int>::const_iterator iter = array->begin(); - iter != array->end(); ++iter, ++j) - QCOMPARE((const int *)iter, data.data + j); - QCOMPARE(j, 10); - } - - { - QTypedArrayData<int> *null = QTypedArrayData<int>::sharedNull(); - QTypedArrayData<int> *empty = QTypedArrayData<int>::allocate(0); - - QVERIFY(null != empty); - - QCOMPARE(null->size, 0); - QCOMPARE(empty->size, 0); - - QCOMPARE(null->begin(), null->end()); - QCOMPARE(empty->begin(), empty->end()); - } - - { Deallocator keeper(sizeof(char), - Q_ALIGNOF(QTypedArrayData<char>::AlignmentDummy)); - QArrayData *array = QTypedArrayData<char>::allocate(10); + alignof(QTypedArrayData<char>::AlignmentDummy)); + QPair<QTypedArrayData<char> *, char *> pair = QTypedArrayData<char>::allocate(10); + QArrayData *array = pair.first; keeper.headers.append(array); QVERIFY(array); - QCOMPARE(array->size, 0); - QCOMPARE(array->alloc, 10u); + QCOMPARE(array->allocatedCapacity(), size_t(10)); // Check that the allocated array can be used. Best tested with a // memory checker, such as valgrind, running. - ::memset(array->data(), 0, 10 * sizeof(char)); + ::memset(pair.second, 0, 10 * sizeof(char)); keeper.headers.clear(); QTypedArrayData<short>::deallocate(array); @@ -906,17 +699,17 @@ void tst_QArrayData::typedData() { Deallocator keeper(sizeof(short), - Q_ALIGNOF(QTypedArrayData<short>::AlignmentDummy)); - QArrayData *array = QTypedArrayData<short>::allocate(10); + alignof(QTypedArrayData<short>::AlignmentDummy)); + QPair<QTypedArrayData<short> *, short *> pair = QTypedArrayData<short>::allocate(10); + QArrayData *array = pair.first; keeper.headers.append(array); QVERIFY(array); - QCOMPARE(array->size, 0); - QCOMPARE(array->alloc, 10u); + QCOMPARE(array->allocatedCapacity(), size_t(10)); // Check that the allocated array can be used. Best tested with a // memory checker, such as valgrind, running. - ::memset(array->data(), 0, 10 * sizeof(short)); + ::memset(pair.second, 0, 10 * sizeof(short)); keeper.headers.clear(); QTypedArrayData<short>::deallocate(array); @@ -926,17 +719,17 @@ void tst_QArrayData::typedData() { Deallocator keeper(sizeof(double), - Q_ALIGNOF(QTypedArrayData<double>::AlignmentDummy)); - QArrayData *array = QTypedArrayData<double>::allocate(10); + alignof(QTypedArrayData<double>::AlignmentDummy)); + QPair<QTypedArrayData<double> *, double *> pair = QTypedArrayData<double>::allocate(10); + QArrayData *array = pair.first; keeper.headers.append(array); QVERIFY(array); - QCOMPARE(array->size, 0); - QCOMPARE(array->alloc, 10u); + QCOMPARE(array->allocatedCapacity(), size_t(10)); // Check that the allocated array can be used. Best tested with a // memory checker, such as valgrind, running. - ::memset(array->data(), 0, 10 * sizeof(double)); + ::memset(pair.second, 0, 10 * sizeof(double)); keeper.headers.clear(); QTypedArrayData<double>::deallocate(array); @@ -1354,136 +1147,6 @@ static inline bool arrayIsFilledWith(const QArrayDataPointer<int> &array, return true; } -void tst_QArrayData::setSharable_data() -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QTest::addColumn<QArrayDataPointer<int> >("array"); - QTest::addColumn<size_t>("size"); - QTest::addColumn<size_t>("capacity"); - QTest::addColumn<bool>("isCapacityReserved"); - QTest::addColumn<int>("fillValue"); - - QArrayDataPointer<int> null; - QArrayDataPointer<int> empty; empty.clear(); - - static QStaticArrayData<int, 10> staticArrayData = { - Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 10), - { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } - }; - - QArrayDataPointer<int> emptyReserved(QTypedArrayData<int>::allocate(5, - QArrayData::CapacityReserved)); - QArrayDataPointer<int> nonEmpty(QTypedArrayData<int>::allocate(5, - QArrayData::Default)); - QArrayDataPointer<int> nonEmptyExtraCapacity( - QTypedArrayData<int>::allocate(10, QArrayData::Default)); - QArrayDataPointer<int> nonEmptyReserved(QTypedArrayData<int>::allocate(15, - QArrayData::CapacityReserved)); - QArrayDataPointer<int> staticArray( - static_cast<QTypedArrayData<int> *>(&staticArrayData.header)); - QArrayDataPointer<int> rawData( - QTypedArrayData<int>::fromRawData(staticArrayData.data, 10)); - - nonEmpty->copyAppend(5, 1); - nonEmptyExtraCapacity->copyAppend(5, 1); - nonEmptyReserved->copyAppend(7, 2); - - QTest::newRow("shared-null") << null << size_t(0) << size_t(0) << false << 0; - QTest::newRow("shared-empty") << empty << size_t(0) << size_t(0) << false << 0; - // unsharable-empty implicitly tested in shared-empty - QTest::newRow("empty-reserved") << emptyReserved << size_t(0) << size_t(5) << true << 0; - QTest::newRow("non-empty") << nonEmpty << size_t(5) << size_t(5) << false << 1; - QTest::newRow("non-empty-extra-capacity") << nonEmptyExtraCapacity << size_t(5) << size_t(10) << false << 1; - QTest::newRow("non-empty-reserved") << nonEmptyReserved << size_t(7) << size_t(15) << true << 2; - QTest::newRow("static-array") << staticArray << size_t(10) << size_t(0) << false << 3; - QTest::newRow("raw-data") << rawData << size_t(10) << size_t(0) << false << 3; -#endif -} - -void tst_QArrayData::setSharable() -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QFETCH(QArrayDataPointer<int>, array); - QFETCH(size_t, size); - QFETCH(size_t, capacity); - QFETCH(bool, isCapacityReserved); - QFETCH(int, fillValue); - - QVERIFY(array->ref.isShared()); // QTest has a copy - QVERIFY(array->ref.isSharable()); - - QCOMPARE(size_t(array->size), size); - QCOMPARE(size_t(array->alloc), capacity); - QCOMPARE(bool(array->capacityReserved), isCapacityReserved); - QVERIFY(arrayIsFilledWith(array, fillValue, size)); - - // shared-null becomes shared-empty, may otherwise detach - array.setSharable(true); - - QVERIFY(array->ref.isSharable()); - QVERIFY(arrayIsFilledWith(array, fillValue, size)); - - { - QArrayDataPointer<int> copy(array); - QVERIFY(array->ref.isShared()); - QVERIFY(array->ref.isSharable()); - QCOMPARE(copy.data(), array.data()); - } - - // Unshare, must detach - array.setSharable(false); - - // Immutability (alloc == 0) is lost on detach, as is additional capacity - // if capacityReserved flag is not set. - if ((capacity == 0 && size != 0) - || (!isCapacityReserved && capacity > size)) - capacity = size; - - QVERIFY(!array->ref.isShared()); - QVERIFY(!array->ref.isSharable()); - - QCOMPARE(size_t(array->size), size); - QCOMPARE(size_t(array->alloc), capacity); - QCOMPARE(bool(array->capacityReserved), isCapacityReserved); - QVERIFY(arrayIsFilledWith(array, fillValue, size)); - - { - QArrayDataPointer<int> copy(array); - QVERIFY(!array->ref.isShared()); - QVERIFY(!array->ref.isSharable()); - - // Null/empty is always shared - QCOMPARE(copy->ref.isShared(), !(size || isCapacityReserved)); - QVERIFY(copy->ref.isSharable()); - - QCOMPARE(size_t(copy->size), size); - QCOMPARE(size_t(copy->alloc), capacity); - QCOMPARE(bool(copy->capacityReserved), isCapacityReserved); - QVERIFY(arrayIsFilledWith(copy, fillValue, size)); - } - - // Make sharable, again - array.setSharable(true); - - QCOMPARE(array->ref.isShared(), !(size || isCapacityReserved)); - QVERIFY(array->ref.isSharable()); - - QCOMPARE(size_t(array->size), size); - QCOMPARE(size_t(array->alloc), capacity); - QCOMPARE(bool(array->capacityReserved), isCapacityReserved); - QVERIFY(arrayIsFilledWith(array, fillValue, size)); - - { - QArrayDataPointer<int> copy(array); - QVERIFY(array->ref.isShared()); - QCOMPARE(copy.data(), array.data()); - } - - QCOMPARE(array->ref.isShared(), !(size || isCapacityReserved)); - QVERIFY(array->ref.isSharable()); -#endif -} - struct ResetOnDtor { ResetOnDtor() @@ -1517,7 +1180,7 @@ void fromRawData_impl() { // Default: Immutable, sharable SimpleVector<T> raw = SimpleVector<T>::fromRawData(array, - sizeof(array)/sizeof(array[0]), QArrayData::Default); + sizeof(array)/sizeof(array[0]), QArrayData::DefaultRawFlags); QCOMPARE(raw.size(), size_t(11)); QCOMPARE((const T *)raw.constBegin(), array); @@ -1531,37 +1194,6 @@ void fromRawData_impl() QCOMPARE(raw.back(), T(11)); QVERIFY((const T *)raw.constBegin() != array); } - -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - { - // Immutable, unsharable - SimpleVector<T> raw = SimpleVector<T>::fromRawData(array, - sizeof(array)/sizeof(array[0]), QArrayData::Unsharable); - - QCOMPARE(raw.size(), size_t(11)); - QCOMPARE((const T *)raw.constBegin(), array); - QCOMPARE((const T *)raw.constEnd(), (const T *)(array + sizeof(array)/sizeof(array[0]))); - - SimpleVector<T> copy(raw); - QVERIFY(!copy.isSharedWith(raw)); - QVERIFY(!raw.isShared()); - - QCOMPARE(copy.size(), size_t(11)); - - for (size_t i = 0; i < 11; ++i) { - QCOMPARE(const_(copy)[i], const_(raw)[i]); - QCOMPARE(const_(copy)[i], T(i + 1)); - } - - QCOMPARE(raw.size(), size_t(11)); - QCOMPARE((const T *)raw.constBegin(), array); - QCOMPARE((const T *)raw.constEnd(), (const T *)(array + sizeof(array)/sizeof(array[0]))); - - // Detach - QCOMPARE(raw.back(), T(11)); - QVERIFY((const T *)raw.constBegin() != array); - } -#endif } void tst_QArrayData::fromRawData_data() @@ -1593,17 +1225,17 @@ void tst_QArrayData::literals() { { QArrayDataPointer<char> d = Q_ARRAY_LITERAL(char, "ABCDEFGHIJ"); - QCOMPARE(d->size, 10 + 1); + QCOMPARE(d.size, 10u + 1u); for (int i = 0; i < 10; ++i) - QCOMPARE(d->data()[i], char('A' + i)); + QCOMPARE(d.data()[i], char('A' + i)); } { // wchar_t is not necessarily 2-bytes QArrayDataPointer<wchar_t> d = Q_ARRAY_LITERAL(wchar_t, L"ABCDEFGHIJ"); - QCOMPARE(d->size, 10 + 1); + QCOMPARE(d.size, 10u + 1u); for (int i = 0; i < 10; ++i) - QCOMPARE(d->data()[i], wchar_t('A' + i)); + QCOMPARE(d.data()[i], wchar_t('A' + i)); } { @@ -1615,10 +1247,6 @@ void tst_QArrayData::literals() // v.capacity() is unspecified, for now QVERIFY(v.isStatic()); - -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QVERIFY(v.isSharable()); -#endif QCOMPARE((void*)(const char*)(v.constBegin() + v.size()), (void*)(const char*)v.constEnd()); for (int i = 0; i < 10; ++i) @@ -1645,26 +1273,26 @@ void tst_QArrayData::variadicLiterals() { QArrayDataPointer<int> d = Q_ARRAY_LITERAL(int, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); - QCOMPARE(d->size, 10); + QCOMPARE(d.size, 10u); for (int i = 0; i < 10; ++i) - QCOMPARE(d->data()[i], i); + QCOMPARE(d.data()[i], i); } { QArrayDataPointer<char> d = Q_ARRAY_LITERAL(char, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'); - QCOMPARE(d->size, 10); + QCOMPARE(d.size, 10u); for (int i = 0; i < 10; ++i) - QCOMPARE(d->data()[i], char('A' + i)); + QCOMPARE(d.data()[i], char('A' + i)); } { QArrayDataPointer<const char *> d = Q_ARRAY_LITERAL(const char *, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"); - QCOMPARE(d->size, 10); + QCOMPARE(d.size, 10u); for (int i = 0; i < 10; ++i) { - QCOMPARE(d->data()[i][0], char('A' + i)); - QCOMPARE(d->data()[i][1], '\0'); + QCOMPARE(d.data()[i][0], char('A' + i)); + QCOMPARE(d.data()[i][1], '\0'); } } @@ -1677,10 +1305,6 @@ void tst_QArrayData::variadicLiterals() // v.capacity() is unspecified, for now QVERIFY(v.isStatic()); - -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QVERIFY(v.isSharable()); -#endif QCOMPARE((const int *)(v.constBegin() + v.size()), (const int *)v.constEnd()); for (int i = 0; i < 7; ++i) diff --git a/tests/auto/corelib/tools/qarraydata_strictiterators/qarraydata_strictiterators.pro b/tests/auto/corelib/tools/qarraydata_strictiterators/qarraydata_strictiterators.pro deleted file mode 100644 index b01fbd84d1..0000000000 --- a/tests/auto/corelib/tools/qarraydata_strictiterators/qarraydata_strictiterators.pro +++ /dev/null @@ -1,3 +0,0 @@ -include(../qarraydata/qarraydata.pro) -TARGET = tst_qarraydata_strictiterators -DEFINES += QT_STRICT_ITERATORS=1 tst_QArrayData=tst_QArrayData_StrictIterators diff --git a/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp b/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp index 9a7c099228..b2c7915aa0 100644 --- a/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp +++ b/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp @@ -86,6 +86,9 @@ private slots: void resize(); void fromBits_data(); void fromBits(); + + void toUInt32_data(); + void toUInt32(); }; void tst_QBitArray::size_data() @@ -667,5 +670,95 @@ void tst_QBitArray::fromBits() QCOMPARE(QBitArray::fromBits(fromBits.bits(), fromBits.size()), expected); } +void tst_QBitArray::toUInt32_data() +{ + QTest::addColumn<QBitArray>("data"); + QTest::addColumn<int>("endianness"); + QTest::addColumn<bool>("check"); + QTest::addColumn<quint32>("result"); + + QTest::newRow("ctor") << QBitArray() + << static_cast<int>(QSysInfo::Endian::LittleEndian) + << true + << quint32(0); + + QTest::newRow("empty") << QBitArray(0) + << static_cast<int>(QSysInfo::Endian::LittleEndian) + << true + << quint32(0); + + QTest::newRow("LittleEndian4") << QStringToQBitArray(QString("0111")) + << static_cast<int>(QSysInfo::Endian::LittleEndian) + << true + << quint32(14); + + QTest::newRow("BigEndian4") << QStringToQBitArray(QString("0111")) + << static_cast<int>(QSysInfo::Endian::BigEndian) + << true + << quint32(7); + + QTest::newRow("LittleEndian8") << QStringToQBitArray(QString("01111111")) + << static_cast<int>(QSysInfo::Endian::LittleEndian) + << true + << quint32(254); + + QTest::newRow("BigEndian8") << QStringToQBitArray(QString("01111111")) + << static_cast<int>(QSysInfo::Endian::BigEndian) + << true + << quint32(127); + + QTest::newRow("LittleEndian16") << QStringToQBitArray(QString("0111111111111111")) + << static_cast<int>(QSysInfo::Endian::LittleEndian) + << true + << quint32(65534); + + QTest::newRow("BigEndian16") << QStringToQBitArray(QString("0111111111111111")) + << static_cast<int>(QSysInfo::Endian::BigEndian) + << true + << quint32(32767); + + QTest::newRow("LittleEndian31") << QBitArray(31, true) + << static_cast<int>(QSysInfo::Endian::LittleEndian) + << true + << quint32(2147483647); + + QTest::newRow("BigEndian31") << QBitArray(31, true) + << static_cast<int>(QSysInfo::Endian::BigEndian) + << true + << quint32(2147483647); + + QTest::newRow("LittleEndian32") << QBitArray(32, true) + << static_cast<int>(QSysInfo::Endian::LittleEndian) + << true + << quint32(4294967295); + + QTest::newRow("BigEndian32") << QBitArray(32, true) + << static_cast<int>(QSysInfo::Endian::BigEndian) + << true + << quint32(4294967295); + + QTest::newRow("LittleEndian33") << QBitArray(33, true) + << static_cast<int>(QSysInfo::Endian::LittleEndian) + << false + << quint32(0); + + QTest::newRow("BigEndian33") << QBitArray(33, true) + << static_cast<int>(QSysInfo::Endian::BigEndian) + << false + << quint32(0); +} + +void tst_QBitArray::toUInt32() +{ + QFETCH(QBitArray, data); + QFETCH(int, endianness); + QFETCH(bool, check); + QFETCH(quint32, result); + bool ok = false; + + QCOMPARE(data.toUInt32(static_cast<QSysInfo::Endian>(endianness), &ok), result); + QCOMPARE(ok, check); +} + QTEST_APPLESS_MAIN(tst_QBitArray) #include "tst_qbitarray.moc" diff --git a/tests/auto/corelib/tools/qflatmap/qflatmap.pro b/tests/auto/corelib/tools/qflatmap/qflatmap.pro new file mode 100644 index 0000000000..3927cee30c --- /dev/null +++ b/tests/auto/corelib/tools/qflatmap/qflatmap.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qflatmap +QT = core-private testlib +SOURCES = tst_qflatmap.cpp diff --git a/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp b/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp new file mode 100644 index 0000000000..a5ae6f5f44 --- /dev/null +++ b/tests/auto/corelib/tools/qflatmap/tst_qflatmap.cpp @@ -0,0 +1,453 @@ +/**************************************************************************** +** +** 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 <QtTest/QtTest> + +#include <private/qflatmap_p.h> +#include <qbytearray.h> +#include <qstring.h> +#include <qstringview.h> +#include <qvarlengtharray.h> +#include <qvector.h> + +#include <algorithm> +#include <list> +#include <tuple> + +class tst_QFlatMap : public QObject +{ + Q_OBJECT +private slots: + void constructing(); + void constAccess(); + void insertion(); + void removal(); + void extraction(); + void iterators(); + void statefulComparator(); + void transparency(); + void viewIterators(); + void varLengthArray(); +}; + +void tst_QFlatMap::constructing() +{ + using Map = QFlatMap<int, QByteArray>; + Map fmDefault; + QVERIFY(fmDefault.isEmpty()); + QCOMPARE(fmDefault.size(), Map::size_type(0)); + QCOMPARE(fmDefault.size(), fmDefault.count()); + + auto key_compare = fmDefault.key_comp(); + auto selfbuilt_value_compare + = [&key_compare](const Map::value_type &a, const Map::value_type &b) + { + return key_compare(a.first, b.first); + }; + auto value_compare = fmDefault.value_comp(); + + Map::key_container_type kv = { 6, 2, 1 }; + Map::mapped_container_type mv = { "foo", "bar", "baz" }; + Map fmCopy{kv, mv}; + QCOMPARE(fmCopy.size(), Map::size_type(3)); + QVERIFY(std::is_sorted(fmCopy.begin(), fmCopy.end(), selfbuilt_value_compare)); + QVERIFY(std::is_sorted(fmCopy.begin(), fmCopy.end(), value_compare)); + + Map fmMove{ + Map::key_container_type{ 6, 2, 1 }, + Map::mapped_container_type{ "foo", "bar", "baz" } + }; + QCOMPARE(fmMove.size(), Map::size_type(3)); + QVERIFY(std::is_sorted(fmMove.begin(), fmMove.end(), value_compare)); + + auto fmInitList = Map{ { 1, 2 }, { "foo", "bar" } }; + QVERIFY(std::is_sorted(fmInitList.begin(), fmInitList.end(), value_compare)); + + auto fmRange = Map(fmCopy.begin(), fmCopy.end()); + QVERIFY(std::is_sorted(fmRange.begin(), fmRange.end(), value_compare)); + + kv.clear(); + mv.clear(); + std::vector<Map::value_type> sv; + for (auto it = fmRange.begin(); it != fmRange.end(); ++it) { + kv.push_back(it->first); + mv.push_back(it->second); + sv.push_back(*it); + } + auto fmFromSortedVectorCopy = Map(Qt::OrderedUniqueRange, kv, mv); + auto fmFromSortedVectorMove = Map(Qt::OrderedUniqueRange, Map::key_container_type(kv), + Map::mapped_container_type(mv)); + auto fmFromSortedInitList = Map(Qt::OrderedUniqueRange, { { 1, "foo" }, { 2, "bar" } }); + auto fmFromSortedRange = Map(Qt::OrderedUniqueRange, sv.begin(), sv.end()); +} + +void tst_QFlatMap::constAccess() +{ + using Map = QFlatMap<QByteArray, QByteArray>; + const Map m{ { { "foo", "FOO" }, { "bar", "BAR" } } }; + + const std::vector<Map::value_type> v{ { "foo", "FOO" }, { "bar", "BAR" } }; + + QCOMPARE(m.value("foo").data(), "FOO"); + QCOMPARE(m.value("bar").data(), "BAR"); + QCOMPARE(m.value("nix"), QByteArray()); + QCOMPARE(m.value("nix", "NIX").data(), "NIX"); + QCOMPARE(m["foo"].data(), "FOO"); + QCOMPARE(m["bar"].data(), "BAR"); + QCOMPARE(m["nix"], QByteArray()); + QVERIFY(m.contains("foo")); + QVERIFY(!m.contains("nix")); +} + +void tst_QFlatMap::insertion() +{ + using Map = QFlatMap<QByteArray, QByteArray>; + Map m; + QByteArray foo = "foo"; + m[foo] = foo.toUpper(); + m["bar"] = "BAR"; + m["baz"] = "BAZ"; + QVERIFY(m.insert("oof", "eek").second); + QVERIFY(!m.insert("oof", "OOF").second); + const std::vector<Map::value_type> container = { { "bla", "BLA" }, { "blubb", "BLUBB" } }; + m.insert(container.begin(), container.end()); + QCOMPARE(m.value("foo").data(), "FOO"); + QCOMPARE(m.value("bar").data(), "BAR"); + QCOMPARE(m.value("baz").data(), "BAZ"); + QCOMPARE(m.value("oof").data(), "OOF"); + QCOMPARE(m.value("bla").data(), "BLA"); + QCOMPARE(m.value("blubb").data(), "BLUBB"); + + Map::value_type a1[] = { { "narf", "NARF" }, + { "zort", "ZORT" }, + { "troz", "TROZ" } }; + Map::value_type a2[] = { { "gnampf", "GNAMPF" }, + { "narf", "NARFFFF" }, + { "narf", "NARFFFFF" }, + { "narf", "NARFFFFFF" } }; + m.insert(std::begin(a1), std::end(a1)); + m.insert(Qt::OrderedUniqueRange, std::begin(a2), std::end(a2)); + QCOMPARE(m.size(), 10); + QCOMPARE(m.value("narf").data(), "NARFFFFFF"); + QCOMPARE(m.value("gnampf").data(), "GNAMPF"); +} + +void tst_QFlatMap::extraction() +{ + using Map = QFlatMap<int, QByteArray>; + Map::key_container_type expectedKeys = { 1, 2, 3 }; + Map::mapped_container_type expectedValues = { "een", "twee", "dree" }; + Map m(expectedKeys, expectedValues); + auto keys = m.keys(); + auto values = m.values(); + QCOMPARE(keys, expectedKeys); + QCOMPARE(values, expectedValues); + Map::containers c = std::move(m).extract(); + QCOMPARE(c.keys, expectedKeys); + QCOMPARE(c.values, expectedValues); +} + +void tst_QFlatMap::iterators() +{ + using Map = QFlatMap<int, QByteArray>; + auto m = Map{ { 1, "foo" }, { 2, "bar" }, { 3, "baz" } }; + { + // forward / backward + Map::iterator a = m.begin(); + QVERIFY(a != m.end()); + QCOMPARE(a.key(), 1); + QCOMPARE(a.value(), "foo"); + ++a; + QCOMPARE(a.key(), 2); + QCOMPARE(a.value(), "bar"); + Map::iterator b = a++; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(3, "baz")); + QCOMPARE(std::tie(b.key(), b.value()), std::make_tuple(2, "bar")); + QCOMPARE(++a, m.end()); + --a; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(3, "baz")); + a.value() = "buzz"; + b = a--; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(2, "bar")); + QCOMPARE(std::tie(b.key(), b.value()), std::make_tuple(3, "buzz")); + b.value() = "baz"; + + // random access + a = m.begin(); + a += 2; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(3, "baz")); + a = m.begin() + 1; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(2, "bar")); + a = 1 + m.begin(); + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(2, "bar")); + a = m.end() - 1; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(3, "baz")); + b = m.end(); + b -= 1; + QCOMPARE(std::tie(b.key(), b.value()), std::make_tuple(3, "baz")); + QCOMPARE(m.end() - m.begin(), m.size()); + + // comparison + a = m.begin() + m.size() - 1; + b = m.end() - 1; + QVERIFY(a == b); + a = m.begin(); + b = m.end(); + QVERIFY(a < b); + QVERIFY(a <= b); + QVERIFY(b > a); + QVERIFY(b >= a); + a = b; + QVERIFY(!(a < b)); + QVERIFY(a <= b); + QVERIFY(!(b > a)); + QVERIFY(b >= a); + + // de-referencing + a = m.begin(); + auto ref0 = *a; + QCOMPARE(ref0.first, 1); + QCOMPARE(ref0.second, "foo"); + auto ref1 = a[1]; + QCOMPARE(ref1.first, 2); + QCOMPARE(ref1.second, "bar"); + } + { + // forward / backward + Map::const_iterator a = m.cbegin(); + QVERIFY(a != m.cend()); + QCOMPARE(a.key(), 1); + QCOMPARE(a.value(), "foo"); + ++a; + QCOMPARE(a.key(), 2); + QCOMPARE(a.value(), "bar"); + Map::const_iterator b = a++; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(3, "baz")); + QCOMPARE(std::tie(b.key(), b.value()), std::make_tuple(2, "bar")); + QCOMPARE(++a, m.cend()); + --a; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(3, "baz")); + b = a--; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(2, "bar")); + + // random access + a = m.cbegin(); + a += 2; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(3, "baz")); + a = m.cbegin() + 1; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(2, "bar")); + a = 1 + m.cbegin(); + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(2, "bar")); + a = m.cend() - 1; + QCOMPARE(std::tie(a.key(), a.value()), std::make_tuple(3, "baz")); + b = m.cend(); + b -= 1; + QCOMPARE(std::tie(b.key(), b.value()), std::make_tuple(3, "baz")); + QCOMPARE(m.cend() - m.cbegin(), m.size()); + + // comparison + a = m.cbegin() + m.size() - 1; + b = m.cend() - 1; + QVERIFY(a == b); + a = m.cbegin(); + b = m.cend(); + QVERIFY(a < b); + QVERIFY(a <= b); + QVERIFY(b > a); + QVERIFY(b >= a); + a = b; + QVERIFY(!(a < b)); + QVERIFY(a <= b); + QVERIFY(!(b > a)); + QVERIFY(b >= a); + + // de-referencing + a = m.cbegin(); + auto ref0 = *a; + QCOMPARE(ref0.first, 1); + QCOMPARE(ref0.second, "foo"); + auto ref1 = a[1]; + QCOMPARE(ref1.first, 2); + QCOMPARE(ref1.second, "bar"); + } + { + Map::iterator it = m.begin(); + Map::const_iterator cit = it; + Q_UNUSED(it); + Q_UNUSED(cit); + } + { + std::list<Map::value_type> revlst; + std::copy(m.begin(), m.end(), std::front_inserter(revlst)); + std::vector<Map::value_type> v0; + std::copy(revlst.begin(), revlst.end(), std::back_inserter(v0)); + std::vector<Map::value_type> v1; + std::copy(m.rbegin(), m.rend(), std::back_inserter(v1)); + const Map cm = m; + std::vector<Map::value_type> v2; + std::copy(cm.rbegin(), cm.rend(), std::back_inserter(v2)); + std::vector<Map::value_type> v3; + std::copy(m.crbegin(), m.crend(), std::back_inserter(v3)); + QCOMPARE(v0, v1); + QCOMPARE(v1, v2); + QCOMPARE(v2, v3); + } +} + +void tst_QFlatMap::removal() +{ + using Map = QFlatMap<int, QByteArray>; + Map m({ { 2, "bar" }, { 3, "baz" }, { 1, "foo" } }); + QCOMPARE(m.value(2).data(), "bar"); + QCOMPARE(m.take(2).data(), "bar"); + QVERIFY(!m.contains(2)); + QCOMPARE(m.size(), Map::size_type(2)); + QVERIFY(m.remove(1)); + QVERIFY(!m.contains(1)); + QVERIFY(!m.remove(1)); + QCOMPARE(m.size(), Map::size_type(1)); + m.clear(); + QVERIFY(m.isEmpty()); + QVERIFY(m.empty()); + + m[1] = "een"; + m[2] = "twee"; + m[3] = "dree"; + auto it = m.lower_bound(1); + QCOMPARE(it.key(), 1); + it = m.erase(it); + QCOMPARE(it.key(), 2); + QVERIFY(!m.contains(1)); +} + +void tst_QFlatMap::statefulComparator() +{ + struct CountingCompare { + mutable int count = 0; + + bool operator()(const QString &lhs, const QString &rhs) const + { + ++count; + return lhs < rhs; + } + }; + + using Map = QFlatMap<QString, QString, CountingCompare>; + auto m1 = Map{ { "en", "een"}, { "to", "twee" }, { "tre", "dree" } }; + QVERIFY(m1.key_comp().count > 0); + auto m2 = Map(m1.key_comp()); + QCOMPARE(m2.key_comp().count, m1.key_comp().count); + m2.insert(m1.begin(), m1.end()); + QVERIFY(m2.key_comp().count > m1.key_comp().count); +} + +void tst_QFlatMap::transparency() +{ + struct StringViewCompare + { + using is_transparent = void; + bool operator()(const QStringView &lhs, const QStringView &rhs) const + { + return lhs < rhs; + } + }; + + using Map = QFlatMap<QString, QString, StringViewCompare>; + auto m = Map{ { "one", "een" }, { "two", "twee" }, { "three", "dree" } }; + + const QString numbers = "one two three"; + const QStringView sv1{numbers.constData(), 3}; + const QStringView sv2{numbers.constData() + 4, 3}; + const QStringView sv3{numbers.constData() + 8, 5}; + QCOMPARE(m.lower_bound(sv1).value(), "een"); + QCOMPARE(m.lower_bound(sv2).value(), "twee"); + QCOMPARE(m.lower_bound(sv3).value(), "dree"); +} + +void tst_QFlatMap::viewIterators() +{ + using Map = QFlatMap<QByteArray, QByteArray>; + Map m({ { "yksi", "een"}, { "kaksi", "twee" }, { "kolme", "dree" } }); + { + std::vector<QByteArray> keys; + std::transform(m.begin(), m.end(), std::back_inserter(keys), + [](const Map::value_type &v) + { + return v.first; + }); + auto it = keys.begin(); + QCOMPARE(*it, "kaksi"); + QCOMPARE(it->length(), 5); + ++it; + QCOMPARE(*it, "kolme"); + it++; + QCOMPARE(*it, "yksi"); + ++it; + QCOMPARE(it, keys.end()); + --it; + QCOMPARE(*it, "yksi"); + it--; + QCOMPARE(*it, "kolme"); + } + { + std::vector<QByteArray> values; + std::transform(m.begin(), m.end(), std::back_inserter(values), + [](const Map::value_type &v) + { + return v.second; + }); + auto it = values.begin(); + QCOMPARE(*it, "twee"); + QCOMPARE(it->length(), 4); + ++it; + QCOMPARE(*it, "dree"); + it++; + QCOMPARE(*it, "een"); + ++it; + QCOMPARE(it, values.end()); + --it; + QCOMPARE(*it, "een"); + it--; + QCOMPARE(*it, "dree"); + } +} + +void tst_QFlatMap::varLengthArray() +{ + using Map = QFlatMap<int, QByteArray, std::less<int>, + QVarLengthArray<int, 1024>, QVarLengthArray<QByteArray, 1024>>; + Map m{ { 2, "twee" } }; + m.insert(1, "een"); + m.remove(1); + QVERIFY(!m.isEmpty()); + m.remove(2); + QVERIFY(m.isEmpty()); +} + +QTEST_APPLESS_MAIN(tst_QFlatMap) +#include "tst_qflatmap.moc" diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index b98ac38288..91cd3eb0bd 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -1373,13 +1373,6 @@ void tst_QHash::noNeedlessRehashes() void tst_QHash::const_shared_null() { QHash<int, QString> hash2; -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QHash<int, QString> hash1; - hash1.setSharable(false); - QVERIFY(hash1.isDetached()); - - hash2.setSharable(true); -#endif QVERIFY(!hash2.isDetached()); } diff --git a/tests/auto/corelib/tools/qhash_strictiterators/qhash_strictiterators.pro b/tests/auto/corelib/tools/qhash_strictiterators/qhash_strictiterators.pro deleted file mode 100644 index 715e9bf0c9..0000000000 --- a/tests/auto/corelib/tools/qhash_strictiterators/qhash_strictiterators.pro +++ /dev/null @@ -1,3 +0,0 @@ -include(../qhash/qhash.pro) -TARGET = tst_qhash_strictiterators -DEFINES += QT_STRICT_ITERATORS tst_QHash=tst_QHash_StrictIterators diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp index df42b5dea9..ed0abff456 100644 --- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp +++ b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp @@ -225,8 +225,6 @@ private slots: void constSharedNullInt() const; void constSharedNullMovable() const; void constSharedNullComplex() const; - - void setSharableInt() const; private: template<typename T> void length() const; template<typename T> void first() const; @@ -1048,13 +1046,6 @@ template<typename T> void tst_QLinkedList::constSharedNull() const { QLinkedList<T> list2; -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QLinkedList<T> list1; - list1.setSharable(false); - QVERIFY(list1.isDetached()); - - list2.setSharable(true); -#endif QVERIFY(!list2.isDetached()); } @@ -1077,57 +1068,5 @@ void tst_QLinkedList::constSharedNullComplex() const QCOMPARE(liveCount, Complex::getLiveCount()); } - -void tst_QLinkedList::setSharableInt() const -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QLinkedList<int> orglist; - orglist << 0 << 1 << 2 << 3 << 4 << 5; - int size = 6; - - QLinkedList<int> list; - list = orglist; - - QVERIFY(!list.isDetached()); - list.setSharable(true); - - QCOMPARE(list.size(), size); - - { - QLinkedList<int> copy(list); - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(list)); - } - - list.setSharable(false); - QVERIFY(list.isDetached() || list.isSharedWith(QLinkedList<int>())); - - { - QLinkedList<int> copy(list); - - QVERIFY(copy.isDetached() || copy.isSharedWith(QLinkedList<int>())); - QCOMPARE(copy.size(), size); - QCOMPARE(copy, list); - } - - list.setSharable(true); - - { - QLinkedList<int> copy(list); - - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(list)); - } - - QLinkedList<int>::const_iterator it = list.constBegin(); - for (int i = 0; i < list.size(); ++i) { - QCOMPARE(int(*it), i); - ++it; - } - - QCOMPARE(list.size(), size); -#endif -} - QTEST_APPLESS_MAIN(tst_QLinkedList) #include "tst_qlinkedlist.moc" diff --git a/tests/auto/corelib/tools/qlist/.gitignore b/tests/auto/corelib/tools/qlist/.gitignore deleted file mode 100644 index df208b6e78..0000000000 --- a/tests/auto/corelib/tools/qlist/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qlist diff --git a/tests/auto/corelib/tools/qlist/qlist.pro b/tests/auto/corelib/tools/qlist/qlist.pro deleted file mode 100644 index 118c607880..0000000000 --- a/tests/auto/corelib/tools/qlist/qlist.pro +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG += testcase -TARGET = tst_qlist -QT = core testlib -qtConfig(c++14): CONFIG += c++14 -qtConfig(c++1z): CONFIG += c++1z -SOURCES = $$PWD/tst_qlist.cpp diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp deleted file mode 100644 index cc9a3a16d1..0000000000 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ /dev/null @@ -1,2115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> -#include <QList> - -template <typename T, class MemoryLayout> -class is_qlist_array_memory_layout { - struct No { char c; }; - struct Yes { No n[2]; }; - Q_STATIC_ASSERT(sizeof(No) != sizeof(Yes)); - static No check(...); - static Yes check(MemoryLayout); -public: - enum { value = sizeof(check(typename QList<T>::MemoryLayout())) == sizeof(Yes) }; -}; - -struct Movable { - Movable(char input = 'j') - : i(input) - , state(Constructed) - { - ++liveCount; - } - Movable(const Movable &other) - : i(other.i) - , state(Constructed) - { - check(other.state, Constructed); - ++liveCount; - } - - ~Movable() - { - check(state, Constructed); - i = 0; - --liveCount; - state = Destructed; - } - - bool operator ==(const Movable &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i == other.i; - } - - bool operator<(const Movable &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i < other.i; - } - - Movable &operator=(const Movable &other) - { - check(state, Constructed); - check(other.state, Constructed); - i = other.i; - return *this; - } - char i; - - static int getLiveCount() { return liveCount; } -private: - static int liveCount; - - enum State { Constructed = 106, Destructed = 110 }; - uchar state; - - static void check(const uchar state1, const uchar state2) - { - QCOMPARE(state1, state2); - } -}; - -Q_STATIC_ASSERT(sizeof(Movable) < sizeof(void*)); - -int Movable::liveCount = 0; - -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(Movable, Q_MOVABLE_TYPE); -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(Movable); - -int qHash(const Movable& movable) -{ - return qHash(movable.i); -} - -struct Optimal -{ - Optimal(char input = 'j') - : i(input), - state(Constructed) - { - ++liveCount; - } - Optimal(const Optimal &other) - : i(other.i), - state(Constructed) - { - check(other.state, Constructed); - ++liveCount; - } - - ~Optimal() - { - check(state, Constructed); - i = 0; - --liveCount; - state = Destructed; - } - - bool operator ==(const Optimal &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i == other.i; - } - - bool operator<(const Optimal &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i < other.i; - } - - Optimal &operator=(const Optimal &other) - { - check(state, Constructed); - check(other.state, Constructed); - i = other.i; - return *this; - } - char i; - - static int getLiveCount() { return liveCount; } -private: - static int liveCount; - - enum State { Constructed = 106, Destructed = 110 }; - uchar state; - char padding[sizeof(void*) - 2]; - - static void check(const uchar state1, const uchar state2) - { - QCOMPARE(state1, state2); - } -}; - -Q_STATIC_ASSERT(sizeof(Optimal) == sizeof(void*)); - -int Optimal::liveCount = 0; - -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(Optimal, Q_MOVABLE_TYPE); -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(Optimal); - -int qHash(const Optimal& key) -{ - return qHash(key.i); -} - -struct Complex -{ - Complex(int val = 0) - : value(val) - , checkSum(this) - { - ++liveCount; - } - - Complex(Complex const &other) - : value(other.value) - , checkSum(this) - { - ++liveCount; - } - - Complex &operator=(Complex const &other) - { - check(); other.check(); - - value = other.value; - return *this; - } - - ~Complex() - { - --liveCount; - check(); - } - - operator int() const { return value; } - - bool operator==(Complex const &other) const - { - check(); other.check(); - return value == other.value; - } - - bool operator<(Complex const &other) const - { - check(); other.check(); - return value < other.value; - } - - void check() const - { - QVERIFY(this == checkSum); - } - - static int getLiveCount() { return liveCount; } -private: - static int liveCount; - - int value; - void *checkSum; -}; - -int Complex::liveCount = 0; - -Q_DECLARE_METATYPE(Complex); - -// Tests depend on the fact that: -Q_STATIC_ASSERT(!QTypeInfo<int>::isStatic); -Q_STATIC_ASSERT(!QTypeInfo<int>::isComplex); -Q_STATIC_ASSERT(!QTypeInfo<Movable>::isStatic); -Q_STATIC_ASSERT(QTypeInfo<Movable>::isComplex); -Q_STATIC_ASSERT(!QTypeInfo<Optimal>::isStatic); -Q_STATIC_ASSERT(QTypeInfo<Optimal>::isComplex); -Q_STATIC_ASSERT(QTypeInfo<Complex>::isStatic); -Q_STATIC_ASSERT(QTypeInfo<Complex>::isComplex); -// iow: -Q_STATIC_ASSERT(( is_qlist_array_memory_layout<int, QListData::NotIndirectLayout> ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<int, QListData::IndirectLayout> ::value)); - -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<Optimal, QListData::InlineWithPaddingLayout> ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<Optimal, QListData::NotArrayCompatibleLayout>::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout<Optimal, QListData::NotIndirectLayout> ::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout<Optimal, QListData::ArrayCompatibleLayout> ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<Optimal, QListData::IndirectLayout> ::value)); - -Q_STATIC_ASSERT(( is_qlist_array_memory_layout<Movable, QListData::InlineWithPaddingLayout> ::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout<Movable, QListData::NotArrayCompatibleLayout>::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout<Movable, QListData::NotIndirectLayout> ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<Movable, QListData::ArrayCompatibleLayout> ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<Movable, QListData::IndirectLayout> ::value)); - -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<Complex, QListData::InlineWithPaddingLayout> ::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout<Complex, QListData::NotArrayCompatibleLayout>::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<Complex, QListData::NotIndirectLayout> ::value)); -Q_STATIC_ASSERT((!is_qlist_array_memory_layout<Complex, QListData::ArrayCompatibleLayout> ::value)); -Q_STATIC_ASSERT(( is_qlist_array_memory_layout<Complex, QListData::IndirectLayout> ::value)); - -class tst_QList : public QObject -{ - Q_OBJECT - -private slots: - void lengthOptimal() const; - void lengthMovable() const; - void lengthComplex() const; - void lengthSignature() const; - void appendOptimal() const; - void appendMovable() const; - void appendComplex() const; - void prepend() const; - void midOptimal() const; - void midMovable() const; - void midComplex() const; - void atOptimal() const; - void atMovable() const; - void atComplex() const; - void firstOptimal() const; - void firstMovable() const; - void firstComplex() const; - void lastOptimal() const; - void lastMovable() const; - void lastComplex() const; - void constFirst() const; - void constLast() const; - void cpp17ctad() const; - void beginOptimal() const; - void beginMovable() const; - void beginComplex() const; - void endOptimal() const; - void endMovable() const; - void endComplex() const; - void containsOptimal() const; - void containsMovable() const; - void containsComplex() const; - void countOptimal() const; - void countMovable() const; - void countComplex() const; - void emptyOptimal() const; - void emptyMovable() const; - void emptyComplex() const; - void endsWithOptimal() const; - void endsWithMovable() const; - void endsWithComplex() const; - void lastIndexOfOptimal() const; - void lastIndexOfMovable() const; - void lastIndexOfComplex() const; - void moveOptimal() const; - void moveMovable() const; - void moveComplex() const; - void removeAllOptimal() const; - void removeAllMovable() const; - void removeAllComplex() const; - void removeAtOptimal() const; - void removeAtMovable() const; - void removeAtComplex() const; - void removeOneOptimal() const; - void removeOneMovable() const; - void removeOneComplex() const; - void replaceOptimal() const; - void replaceMovable() const; - void replaceComplex() const; - void reverseIteratorsOptimal() const; - void reverseIteratorsMovable() const; - void reverseIteratorsComplex() const; - void startsWithOptimal() const; - void startsWithMovable() const; - void startsWithComplex() const; - void swapOptimal() const; - void swapMovable() const; - void swapComplex() const; - void takeAtOptimal() const; - void takeAtMovable() const; - void takeAtComplex() const; - void takeFirstOptimal() const; - void takeFirstMovable() const; - void takeFirstComplex() const; - void takeLastOptimal() const; - void takeLastMovable() const; - void takeLastComplex() const; -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - void toSetOptimal() const; - void toSetMovable() const; - void toSetComplex() const; - void toStdListOptimal() const; - void toStdListMovable() const; - void toStdListComplex() const; -#endif - void toVectorOptimal() const; - void toVectorMovable() const; - void toVectorComplex() const; - void valueOptimal() const; - void valueMovable() const; - void valueComplex() const; - - void testOperatorsOptimal() const; - void testOperatorsMovable() const; - void testOperatorsComplex() const; - void testSTLIteratorsOptimal() const; - void testSTLIteratorsMovable() const; - void testSTLIteratorsComplex() const; - - void initializeList() const; - - void constSharedNullOptimal() const; - void constSharedNullMovable() const; - void constSharedNullComplex() const; - void setSharableInt_data() const; - void setSharableInt() const; - void setSharableComplex_data() const; - void setSharableComplex() const; - void eraseValidIteratorsOnSharedList() const; - void insertWithValidIteratorsOnSharedList() const; - - void qhashOptimal() const { qhash<Optimal>(); } - void qhashMovable() const { qhash<Movable>(); } - void qhashComplex() const { qhash<Complex>(); } - void reserve() const; -private: - template<typename T> void length() const; - template<typename T> void append() const; - template<typename T> void mid() const; - template<typename T> void at() const; - template<typename T> void first() const; - template<typename T> void last() const; - template<typename T> void begin() const; - template<typename T> void end() const; - template<typename T> void contains() const; - template<typename T> void count() const; - template<typename T> void empty() const; - template<typename T> void endsWith() const; - template<typename T> void lastIndexOf() const; - template<typename T> void move() const; - template<typename T> void qhash() const; - template<typename T> void removeAll() const; - template<typename T> void removeAt() const; - template<typename T> void removeOne() const; - template<typename T> void replace() const; - template<typename T> void reverseIterators() const; - template<typename T> void startsWith() const; - template<typename T> void swap() const; - template<typename T> void takeAt() const; - template<typename T> void takeFirst() const; - template<typename T> void takeLast() const; -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - template<typename T> void toSet() const; - template<typename T> void toStdList() const; -#endif - template<typename T> void toVector() const; - template<typename T> void value() const; - - template<typename T> void testOperators() const; - template<typename T> void testSTLIterators() const; - - template<typename T> void constSharedNull() const; - - int dummyForGuard; -}; - -template<typename T> struct SimpleValue -{ - static T at(int index) - { - return values[index % maxSize]; - } - static const uint maxSize = 7; - static const T values[maxSize]; -}; - -template<> -const Optimal SimpleValue<Optimal>::values[] = { 10, 20, 30, 40, 100, 101, 102 }; -template<> -const Movable SimpleValue<Movable>::values[] = { 10, 20, 30, 40, 100, 101, 102 }; -template<> -const Complex SimpleValue<Complex>::values[] = { 10, 20, 30, 40, 100, 101, 102 }; - -// Make some macros for the tests to use in order to be slightly more readable... -#define T_FOO SimpleValue<T>::at(0) -#define T_BAR SimpleValue<T>::at(1) -#define T_BAZ SimpleValue<T>::at(2) -#define T_CAT SimpleValue<T>::at(3) -#define T_DOG SimpleValue<T>::at(4) -#define T_BLAH SimpleValue<T>::at(5) -#define T_WEEE SimpleValue<T>::at(6) - -template<typename T> -void tst_QList::length() const -{ - /* Empty list. */ - { - const QList<T> list; - QCOMPARE(list.length(), 0); - } - - /* One entry. */ - { - QList<T> list; - list.append(T_FOO); - QCOMPARE(list.length(), 1); - } - - /* Two entries. */ - { - QList<T> list; - list.append(T_FOO); - list.append(T_BAR); - QCOMPARE(list.length(), 2); - } - - /* Three entries. */ - { - QList<T> list; - list.append(T_FOO); - list.append(T_BAR); - list.append(T_BAZ); - QCOMPARE(list.length(), 3); - } -} - -void tst_QList::lengthOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - length<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::lengthMovable() const -{ - const int liveCount = Movable::getLiveCount(); - length<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::lengthComplex() const -{ - const int liveCount = Complex::getLiveCount(); - length<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QList::lengthSignature() const -{ - /* Constness. */ - { - const QList<int> list; - /* The function should be const. */ - list.length(); - } -} - -template<typename T> -void tst_QList::append() const -{ - /* test append(const QList<T> &) function */ - T one(T_FOO); - T two(T_BAR); - T three(T_BAZ); - T four(T_CAT); - QList<T> list1; - QList<T> list2; - QList<T> listTotal; - list1.append(one); - list1.append(two); - list2.append(three); - list2.append(four); - list1.append(list2); - listTotal.append(one); - listTotal.append(two); - listTotal.append(three); - listTotal.append(four); - QCOMPARE(list1, listTotal); -} - -void tst_QList::appendOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - append<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::appendMovable() const -{ - const int liveCount = Movable::getLiveCount(); - append<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::appendComplex() const -{ - const int liveCount = Complex::getLiveCount(); - append<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QList::prepend() const -{ - QList<int *> list; - int *t1 = new int(0); - list.prepend(t1); - QVERIFY(list.size() == 1); - QVERIFY(list.at(0) == t1); - int *t2 = new int(0); - list.prepend(t2); - QVERIFY(list.size() == 2); - QVERIFY(list.at(0) == t2); - QVERIFY(list.at(1) == t1); - int *t3 = new int(0); - list.prepend(t3); - QVERIFY(list.size() == 3); - QVERIFY(list.at(0) == t3); - QVERIFY(list.at(1) == t2); - QVERIFY(list.at(2) == t1); - list.removeAll(t2); - delete t2; - QVERIFY(list.size() == 2); - QVERIFY(list.at(0) == t3); - QVERIFY(list.at(1) == t1); - int *t4 = new int(0); - list.prepend(t4); - QVERIFY(list.size() == 3); - QVERIFY(list.at(0) == t4); - QVERIFY(list.at(1) == t3); - QVERIFY(list.at(2) == t1); - qDeleteAll(list); - list.clear(); -} - -template<typename T> -void tst_QList::mid() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ << T_CAT << T_DOG << T_BLAH << T_WEEE; - - QCOMPARE(list.mid(3, 3), - QList<T>() << T_CAT << T_DOG << T_BLAH); - - QList<T> list1; - QCOMPARE(list1.mid(1, 1).length(), 0); -} - -void tst_QList::midOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - mid<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::midMovable() const -{ - const int liveCount = Movable::getLiveCount(); - mid<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::midComplex() const -{ - const int liveCount = Complex::getLiveCount(); - mid<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::at() const -{ - // test at() and make sure it functions correctly with some simple list manipulation. - QList<T> list; - - // create a list - list << T_FOO << T_BAR << T_BAZ; - QVERIFY(list.size() == 3); - QCOMPARE(list.at(0), T_FOO); - QCOMPARE(list.at(1), T_BAR); - QCOMPARE(list.at(2), T_BAZ); - - // append an item - list << T_CAT; - QVERIFY(list.size() == 4); - QCOMPARE(list.at(0), T_FOO); - QCOMPARE(list.at(1), T_BAR); - QCOMPARE(list.at(2), T_BAZ); - QCOMPARE(list.at(3), T_CAT); - - // remove an item - list.removeAt(1); - QVERIFY(list.size() == 3); - QCOMPARE(list.at(0), T_FOO); - QCOMPARE(list.at(1), T_BAZ); - QCOMPARE(list.at(2), T_CAT); -} - -void tst_QList::atOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - at<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::atMovable() const -{ - const int liveCount = Movable::getLiveCount(); - at<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::atComplex() const -{ - const int liveCount = Complex::getLiveCount(); - at<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::first() const -{ - QList<T> list; - list << T_FOO << T_BAR; - - QCOMPARE(list.first(), T_FOO); - - // remove an item, make sure it still works - list.pop_front(); - QVERIFY(list.size() == 1); - QCOMPARE(list.first(), T_BAR); -} - -void tst_QList::firstOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - first<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::firstMovable() const -{ - const int liveCount = Movable::getLiveCount(); - first<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::firstComplex() const -{ - const int liveCount = Complex::getLiveCount(); - first<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QList::constFirst() const -{ - // Based on tst_QVector::constFirst() - QList<int> list; - list << 69 << 42 << 3; - - // test it starts ok - QCOMPARE(list.constFirst(), 69); - QVERIFY(list.isDetached()); - - QList<int> listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constFirst(), 69); - QCOMPARE(listCopy.constFirst(), 69); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - // test removal changes - list.removeAt(0); - QVERIFY(list.isDetached()); - QVERIFY(!list.isSharedWith(listCopy)); - QCOMPARE(list.constFirst(), 42); - QCOMPARE(listCopy.constFirst(), 69); - - listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constFirst(), 42); - QCOMPARE(listCopy.constFirst(), 42); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - // test prepend changes - list.prepend(23); - QVERIFY(list.isDetached()); - QVERIFY(!list.isSharedWith(listCopy)); - QCOMPARE(list.constFirst(), 23); - QCOMPARE(listCopy.constFirst(), 42); - - listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constFirst(), 23); - QCOMPARE(listCopy.constFirst(), 23); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); -} - -void tst_QList::constLast() const -{ - // Based on tst_QVector::constLast() - QList<int> list; - list << 69 << 42 << 3; - - // test it starts ok - QCOMPARE(list.constLast(), 3); - QVERIFY(list.isDetached()); - - QList<int> listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constLast(), 3); - QCOMPARE(listCopy.constLast(), 3); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - // test removal changes - list.removeLast(); - QVERIFY(list.isDetached()); - QVERIFY(!list.isSharedWith(listCopy)); - QCOMPARE(list.constLast(), 42); - QCOMPARE(listCopy.constLast(), 3); - - listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constLast(), 42); - QCOMPARE(listCopy.constLast(), 42); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - // test prepend changes - list.append(23); - QVERIFY(list.isDetached()); - QVERIFY(!list.isSharedWith(listCopy)); - QCOMPARE(list.constLast(), 23); - QCOMPARE(listCopy.constLast(), 42); - - listCopy = list; - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); - - QCOMPARE(list.constLast(), 23); - QCOMPARE(listCopy.constLast(), 23); - - QVERIFY(!list.isDetached()); - QVERIFY(!listCopy.isDetached()); - QVERIFY(list.isSharedWith(listCopy)); - QVERIFY(listCopy.isSharedWith(list)); -} - -void tst_QList::cpp17ctad() const -{ -#ifdef __cpp_deduction_guides -#define QVERIFY_IS_LIST_OF(obj, Type) \ - QVERIFY2((std::is_same<decltype(obj), QList<Type>>::value), \ - QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>())) -#define CHECK(Type, One, Two, Three) \ - do { \ - const Type v[] = {One, Two, Three}; \ - QList v1 = {One, Two, Three}; \ - QVERIFY_IS_LIST_OF(v1, Type); \ - QList v2(v1.begin(), v1.end()); \ - QVERIFY_IS_LIST_OF(v2, Type); \ - QList v3(std::begin(v), std::end(v)); \ - QVERIFY_IS_LIST_OF(v3, Type); \ - } while (false) \ - /*end*/ - CHECK(int, 1, 2, 3); - CHECK(double, 1.0, 2.0, 3.0); - CHECK(QString, QStringLiteral("one"), QStringLiteral("two"), QStringLiteral("three")); -#undef QVERIFY_IS_LIST_OF -#undef CHECK -#else - QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler."); -#endif -} - -template<typename T> -void tst_QList::last() const -{ - QList<T> list; - list << T_FOO << T_BAR; - - QCOMPARE(list.last(), T_BAR); - - // remove an item, make sure it still works - list.pop_back(); - QVERIFY(list.size() == 1); - QCOMPARE(list.last(), T_FOO); -} - -void tst_QList::lastOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - last<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::lastMovable() const -{ - const int liveCount = Movable::getLiveCount(); - last<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::lastComplex() const -{ - const int liveCount = Complex::getLiveCount(); - last<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::begin() const -{ - QList<T> list; - list << T_FOO << T_BAR; - - QCOMPARE(*list.begin(), T_FOO); - - // remove an item, make sure it still works - list.pop_front(); - QVERIFY(list.size() == 1); - QCOMPARE(*list.begin(), T_BAR); -} - -void tst_QList::beginOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - begin<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::beginMovable() const -{ - const int liveCount = Movable::getLiveCount(); - begin<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::beginComplex() const -{ - const int liveCount = Complex::getLiveCount(); - begin<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::end() const -{ - QList<T> list; - list << T_FOO << T_BAR; - - QCOMPARE(*--list.end(), T_BAR); - - // remove an item, make sure it still works - list.pop_back(); - QVERIFY(list.size() == 1); - QCOMPARE(*--list.end(), T_FOO); -} - -void tst_QList::endOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - end<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::endMovable() const -{ - const int liveCount = Movable::getLiveCount(); - end<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::endComplex() const -{ - const int liveCount = Complex::getLiveCount(); - end<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::contains() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - QVERIFY(list.contains(T_FOO)); - QVERIFY(list.contains(T_BLAH) != true); - - // add it and make sure it matches - list.append(T_BLAH); - QVERIFY(list.contains(T_BLAH)); -} - -void tst_QList::containsOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - contains<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::containsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - contains<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::containsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - contains<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::count() const -{ - QList<T> list; - - // starts empty - QVERIFY(list.count() == 0); - - // goes up - list.append(T_FOO); - QVERIFY(list.count() == 1); - - // and up - list.append(T_BAR); - QVERIFY(list.count() == 2); - - // and down - list.pop_back(); - QVERIFY(list.count() == 1); - - // and empty. :) - list.pop_back(); - QVERIFY(list.count() == 0); -} - -void tst_QList::countOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - count<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::countMovable() const -{ - const int liveCount = Movable::getLiveCount(); - count<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::countComplex() const -{ - const int liveCount = Complex::getLiveCount(); - count<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::empty() const -{ - QList<T> list; - - // make sure it starts empty - QVERIFY(list.empty()); - - // and doesn't stay empty - list.append(T_FOO); - QVERIFY(!list.empty()); - - // and goes back to being empty - list.pop_back(); - QVERIFY(list.empty()); -} - -void tst_QList::emptyOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - empty<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::emptyMovable() const -{ - const int liveCount = Movable::getLiveCount(); - empty<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::emptyComplex() const -{ - const int liveCount = Complex::getLiveCount(); - empty<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::endsWith() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // test it returns correctly in both cases - QVERIFY(list.endsWith(T_BAZ)); - QVERIFY(!list.endsWith(T_BAR)); - - // remove an item and make sure the end item changes - list.pop_back(); - QVERIFY(list.endsWith(T_BAR)); -} - -void tst_QList::endsWithOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - endsWith<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::endsWithMovable() const -{ - const int liveCount = Movable::getLiveCount(); - endsWith<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::endsWithComplex() const -{ - const int liveCount = Complex::getLiveCount(); - endsWith<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::lastIndexOf() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // one instance of the target item - QVERIFY(list.lastIndexOf(T_BAZ) == 2); - - // shouldn't find this - QVERIFY(list.lastIndexOf(T_WEEE) == -1); - - // multiple instances - list.append(T_BAZ); - list.append(T_BAZ); - QVERIFY(list.lastIndexOf(T_BAZ) == 4); - - // search from the middle to find the last one - QVERIFY(list.lastIndexOf(T_BAZ, 3) == 3); - - // try to find none - QVERIFY(list.lastIndexOf(T_BAZ, 1) == -1); -} - -void tst_QList::lastIndexOfOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - lastIndexOf<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::lastIndexOfMovable() const -{ - const int liveCount = Movable::getLiveCount(); - lastIndexOf<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::lastIndexOfComplex() const -{ - const int liveCount = Complex::getLiveCount(); - lastIndexOf<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::move() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // move an item - list.move(0, list.count() - 1); - QCOMPARE(list, QList<T>() << T_BAR << T_BAZ << T_FOO); - - // move it back - list.move(list.count() - 1, 0); - QCOMPARE(list, QList<T>() << T_FOO << T_BAR << T_BAZ); - - // move an item in the middle - list.move(1, 0); - QCOMPARE(list, QList<T>() << T_BAR << T_FOO << T_BAZ); -} - -void tst_QList::moveOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - move<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::moveMovable() const -{ - const int liveCount = Movable::getLiveCount(); - move<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::moveComplex() const -{ - const int liveCount = Complex::getLiveCount(); - move<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::removeAll() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // remove one instance - list.removeAll(T_BAR); - QCOMPARE(list, QList<T>() << T_FOO << T_BAZ); - - // many instances - list << T_FOO << T_BAR << T_BAZ << T_FOO << T_BAR << T_BAZ << T_FOO << T_BAR << T_BAZ; - list.removeAll(T_BAR); - QCOMPARE(list, QList<T>() << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ); - - // try remove something that doesn't exist - list.removeAll(T_WEEE); - QCOMPARE(list, QList<T>() << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ); -} - -void tst_QList::removeAllOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - removeAll<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::removeAllMovable() const -{ - const int liveCount = Movable::getLiveCount(); - removeAll<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::removeAllComplex() const -{ - const int liveCount = Complex::getLiveCount(); - removeAll<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::removeAt() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // middle - list.removeAt(1); - QCOMPARE(list, QList<T>() << T_FOO << T_BAZ); - - // start - list.removeAt(0); - QCOMPARE(list, QList<T>() << T_BAZ); - - // final - list.removeAt(0); - QCOMPARE(list, QList<T>()); -} - -void tst_QList::removeAtOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - removeAt<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::removeAtMovable() const -{ - const int liveCount = Movable::getLiveCount(); - removeAt<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::removeAtComplex() const -{ - const int liveCount = Complex::getLiveCount(); - removeAt<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::removeOne() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // middle - list.removeOne(T_BAR); - QCOMPARE(list, QList<T>() << T_FOO << T_BAZ); - - // start - list.removeOne(T_FOO); - QCOMPARE(list, QList<T>() << T_BAZ); - - // last - list.removeOne(T_BAZ); - QCOMPARE(list, QList<T>()); - - // make sure it really only removes one :) - list << T_FOO << T_FOO; - list.removeOne(T_FOO); - QCOMPARE(list, QList<T>() << T_FOO); - - // try remove something that doesn't exist - list.removeOne(T_WEEE); - QCOMPARE(list, QList<T>() << T_FOO); -} - -void tst_QList::removeOneOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - removeOne<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::removeOneMovable() const -{ - const int liveCount = Movable::getLiveCount(); - removeOne<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::removeOneComplex() const -{ - const int liveCount = Complex::getLiveCount(); - removeOne<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::replace() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // start - list.replace(0, T_CAT); - QCOMPARE(list, QList<T>() << T_CAT - << T_BAR << T_BAZ); - - // middle - list.replace(1, T_DOG); - QCOMPARE(list, QList<T>() << T_CAT - << T_DOG << T_BAZ); - - // end - list.replace(2, T_BLAH); - QCOMPARE(list, QList<T>() << T_CAT - << T_DOG << T_BLAH); -} - -void tst_QList::replaceOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - replace<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::replaceMovable() const -{ - const int liveCount = Movable::getLiveCount(); - replace<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::replaceComplex() const -{ - const int liveCount = Complex::getLiveCount(); - replace<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::reverseIterators() const -{ - QList<T> v; - v << T_CAT << T_DOG << T_BLAH << T_BAZ; - QList<T> vr = v; - std::reverse(vr.begin(), vr.end()); - const QList<T> &cvr = vr; - QVERIFY(std::equal(v.begin(), v.end(), vr.rbegin())); - QVERIFY(std::equal(v.begin(), v.end(), vr.crbegin())); - QVERIFY(std::equal(v.begin(), v.end(), cvr.rbegin())); - QVERIFY(std::equal(vr.rbegin(), vr.rend(), v.begin())); - QVERIFY(std::equal(vr.crbegin(), vr.crend(), v.begin())); - QVERIFY(std::equal(cvr.rbegin(), cvr.rend(), v.begin())); -} - -void tst_QList::reverseIteratorsOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - reverseIterators<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::reverseIteratorsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - reverseIterators<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::reverseIteratorsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - reverseIterators<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::startsWith() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // make sure it starts ok - QVERIFY(list.startsWith(T_FOO)); - - // remove an item - list.removeFirst(); - QVERIFY(list.startsWith(T_BAR)); -} - -void tst_QList::startsWithOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - startsWith<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::startsWithMovable() const -{ - const int liveCount = Movable::getLiveCount(); - startsWith<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::startsWithComplex() const -{ - const int liveCount = Complex::getLiveCount(); - startsWith<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::swap() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // swap - list.swapItemsAt(0, 2); - QCOMPARE(list, QList<T>() << T_BAZ << T_BAR << T_FOO); - - // swap again - list.swapItemsAt(1, 2); - QCOMPARE(list, QList<T>() << T_BAZ << T_FOO << T_BAR); - - QList<T> list2; - list2 << T_DOG << T_BLAH; - - list.swap(list2); - QCOMPARE(list, QList<T>() << T_DOG << T_BLAH); - QCOMPARE(list2, QList<T>() << T_BAZ << T_FOO << T_BAR); -} - -void tst_QList::swapOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - swap<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::swapMovable() const -{ - const int liveCount = Movable::getLiveCount(); - swap<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::swapComplex() const -{ - const int liveCount = Complex::getLiveCount(); - swap<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::takeAt() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.takeAt(0), T_FOO); - QVERIFY(list.size() == 2); - QCOMPARE(list.takeAt(1), T_BAZ); - QVERIFY(list.size() == 1); - QCOMPARE(list.takeAt(0), T_BAR); - QVERIFY(list.size() == 0); -} - -void tst_QList::takeAtOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - takeAt<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::takeAtMovable() const -{ - const int liveCount = Movable::getLiveCount(); - takeAt<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::takeAtComplex() const -{ - const int liveCount = Complex::getLiveCount(); - takeAt<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::takeFirst() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.takeFirst(), T_FOO); - QVERIFY(list.size() == 2); - QCOMPARE(list.takeFirst(), T_BAR); - QVERIFY(list.size() == 1); - QCOMPARE(list.takeFirst(), T_BAZ); - QVERIFY(list.size() == 0); -} - -void tst_QList::takeFirstOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - takeFirst<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::takeFirstMovable() const -{ - const int liveCount = Movable::getLiveCount(); - takeFirst<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::takeFirstComplex() const -{ - const int liveCount = Complex::getLiveCount(); - takeFirst<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::takeLast() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.takeLast(), T_BAZ); - QCOMPARE(list.takeLast(), T_BAR); - QCOMPARE(list.takeLast(), T_FOO); -} - -void tst_QList::takeLastOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - takeLast<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::takeLastMovable() const -{ - const int liveCount = Movable::getLiveCount(); - takeLast<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::takeLastComplex() const -{ - const int liveCount = Complex::getLiveCount(); - takeLast<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) -template<typename T> -void tst_QList::toSet() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // no duplicates - QCOMPARE(list.toSet(), QSet<T>() << T_FOO << T_BAR << T_BAZ); - QCOMPARE(list, QList<T>() << T_FOO << T_BAR << T_BAZ); - - // duplicates (is this more of a QSet test?) - list << T_FOO << T_BAR << T_BAZ; - QCOMPARE(list.toSet(), QSet<T>() << T_FOO << T_BAR << T_BAZ); - QCOMPARE(list, QList<T>() << T_FOO << T_BAR << T_BAZ - << T_FOO << T_BAR << T_BAZ); -} - -void tst_QList::toSetOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - toSet<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::toSetMovable() const -{ - const int liveCount = Movable::getLiveCount(); - toSet<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::toSetComplex() const -{ - const int liveCount = Complex::getLiveCount(); - toSet<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::toStdList() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // yuck. - std::list<T> slist; - slist.push_back(T_FOO); - slist.push_back(T_BAR); - slist.push_back(T_BAZ); - - QCOMPARE(list.toStdList(), slist); - QCOMPARE(list, QList<T>() << T_FOO << T_BAR << T_BAZ); -} - -void tst_QList::toStdListOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - toStdList<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::toStdListMovable() const -{ - const int liveCount = Movable::getLiveCount(); - toStdList<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::toStdListComplex() const -{ - const int liveCount = Complex::getLiveCount(); - toStdList<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} -#endif - -template<typename T> -void tst_QList::toVector() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.toVector(), QVector<T>() << T_FOO << T_BAR << T_BAZ); -} - -void tst_QList::toVectorOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - toVector<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::toVectorMovable() const -{ - const int liveCount = Movable::getLiveCount(); - toVector<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::toVectorComplex() const -{ - const int liveCount = Complex::getLiveCount(); - toVector<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::value() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - // test real values - QCOMPARE(list.value(0), T_FOO); - QCOMPARE(list.value(2), T_BAZ); - - // test empty default - QCOMPARE(list.value(3), T()); - QCOMPARE(list.value(-1), T()); - - // test defaults - T defaultT(T_WEEE); - QCOMPARE(list.value(-1, defaultT), defaultT); - QCOMPARE(list.value(3, defaultT), defaultT); -} - -void tst_QList::valueOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - value<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::valueMovable() const -{ - const int liveCount = Movable::getLiveCount(); - value<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::valueComplex() const -{ - const int liveCount = Complex::getLiveCount(); - value<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::testOperators() const -{ - QList<T> list; - list << T_FOO << T_BAR << T_BAZ; - - QList<T> listtwo; - listtwo << T_FOO << T_BAR << T_BAZ; - - // test equal - QVERIFY(list == listtwo); - - // not equal - listtwo.append(T_CAT); - QVERIFY(list != listtwo); - - // += - list += listtwo; - QVERIFY(list.size() == 7); - QVERIFY(listtwo.size() == 4); - QCOMPARE(list, QList<T>() << T_FOO << T_BAR << T_BAZ - << T_FOO << T_BAR << T_BAZ << T_CAT); - - // = - list = listtwo; - QCOMPARE(list, listtwo); - QCOMPARE(list, QList<T>() << T_FOO << T_BAR << T_BAZ << T_CAT); - - // [] - QCOMPARE(list[0], T_FOO); - QCOMPARE(list[list.size() - 1], T_CAT); - - // <, >, <=, >= - QVERIFY(!(list < listtwo)); - QVERIFY(!(list > listtwo)); - QVERIFY( list <= listtwo); - QVERIFY( list >= listtwo); - listtwo.push_back(T_CAT); - QVERIFY( list < listtwo); - QVERIFY(!(list > listtwo)); - QVERIFY( list <= listtwo); - QVERIFY(!(list >= listtwo)); - QVERIFY(listtwo > list); - QVERIFY(listtwo >= list); -} - -void tst_QList::testOperatorsOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - testOperators<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::testOperatorsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - testOperators<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::testOperatorsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - testOperators<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template<typename T> -void tst_QList::testSTLIterators() const -{ - QList<T> list; - - // create a list - list << T_FOO << T_BAR << T_BAZ; - typename QList<T>::iterator it = list.begin(); - QCOMPARE(*it, T_FOO); it++; - QCOMPARE(*it, T_BAR); it++; - QCOMPARE(*it, T_BAZ); it++; - QCOMPARE(it, list.end()); it--; - - // walk backwards - QCOMPARE(*it, T_BAZ); it--; - QCOMPARE(*it, T_BAR); it--; - QCOMPARE(*it, T_FOO); - - // test erase - it = list.erase(it); - QVERIFY(list.size() == 2); - QCOMPARE(*it, T_BAR); - - // test multiple erase - it = list.erase(it, it + 2); - QVERIFY(list.size() == 0); - QCOMPARE(it, list.end()); - - // insert again - it = list.insert(it, T_FOO); - QVERIFY(list.size() == 1); - QCOMPARE(*it, T_FOO); - - // insert again - it = list.insert(it, T_BAR); - QVERIFY(list.size() == 2); - QCOMPARE(*it++, T_BAR); - QCOMPARE(*it, T_FOO); -} - -void tst_QList::testSTLIteratorsOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - testSTLIterators<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::testSTLIteratorsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - testSTLIterators<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::testSTLIteratorsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - testSTLIterators<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QList::initializeList() const -{ - QList<int> v1{2,3,4}; - QCOMPARE(v1, QList<int>() << 2 << 3 << 4); - QCOMPARE(v1, (QList<int>{2,3,4})); - - QList<QList<int>> v2{ v1, {1}, QList<int>(), {2,3,4} }; - QList<QList<int>> v3; - v3 << v1 << (QList<int>() << 1) << QList<int>() << v1; - QCOMPARE(v3, v2); -} - -template<typename T> -void tst_QList::constSharedNull() const -{ - QList<T> list2; -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QList<T> list1; - list1.setSharable(false); - QVERIFY(list1.isDetached()); - - list2.setSharable(true); -#endif - QVERIFY(!list2.isDetached()); -} - -void tst_QList::constSharedNullOptimal() const -{ - const int liveCount = Optimal::getLiveCount(); - constSharedNull<Optimal>(); - QCOMPARE(liveCount, Optimal::getLiveCount()); -} - -void tst_QList::constSharedNullMovable() const -{ - const int liveCount = Movable::getLiveCount(); - constSharedNull<Movable>(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QList::constSharedNullComplex() const -{ - const int liveCount = Complex::getLiveCount(); - constSharedNull<Complex>(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template <class T> -void generateSetSharableData() -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QTest::addColumn<QList<T> >("list"); - QTest::addColumn<int>("size"); - - QTest::newRow("null") << QList<T>() << 0; - QTest::newRow("non-empty") << (QList<T>() << T(0) << T(1) << T(2) << T(3) << T(4)) << 5; -#endif -} - -template <class T> -void runSetSharableTest() -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QFETCH(QList<T>, list); - QFETCH(int, size); - - QVERIFY(!list.isDetached()); // Shared with QTest - - list.setSharable(true); - - QCOMPARE(list.size(), size); - - { - QList<T> copy(list); - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(list)); - } - - list.setSharable(false); - QVERIFY(list.isDetached() || list.isSharedWith(QList<T>())); - - { - QList<T> copy(list); - - QVERIFY(copy.isDetached() || copy.isSharedWith(QList<T>())); - QCOMPARE(copy.size(), size); - QCOMPARE(copy, list); - } - - list.setSharable(true); - - { - QList<T> copy(list); - - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(list)); - } - - for (int i = 0; i < list.size(); ++i) - QCOMPARE(int(list[i]), i); - - QCOMPARE(list.size(), size); -#endif -} - -void tst_QList::setSharableInt_data() const -{ - generateSetSharableData<int>(); -} - -void tst_QList::setSharableComplex_data() const -{ - generateSetSharableData<Complex>(); -} - -void tst_QList::setSharableInt() const -{ - runSetSharableTest<int>(); -} - -void tst_QList::setSharableComplex() const -{ - runSetSharableTest<Complex>(); -} - -void tst_QList::eraseValidIteratorsOnSharedList() const -{ - QList<int> a, b; - a.push_back(10); - a.push_back(20); - a.push_back(30); - QList<int>::iterator i = a.begin(); - ++i; - b = a; - a.erase(i); - QCOMPARE(b.size(), 3); - QCOMPARE(a.size(), 2); - QCOMPARE(a.at(0), 10); - QCOMPARE(a.at(1), 30); - - a.push_back(40); - a.push_back(50); - a.push_back(60); - QCOMPARE(a.size(), 5); - i = a.begin(); - b = a; - ++i; - QList<int>::iterator j = i; - ++j; - ++j; - a.erase(i, j); // remove 3 elements - QCOMPARE(b.size(), 5); - QCOMPARE(a.size(), 3); - QCOMPARE(a.at(0), 10); - QCOMPARE(a.at(1), 50); -} - -void tst_QList::insertWithValidIteratorsOnSharedList() const -{ - QList<int> a, b; - a.push_back(10); - a.push_back(20); - a.push_back(30); - QList<int>::iterator i = a.begin(); - ++i; - b = a; - a.insert(i, 15); - QCOMPARE(a.size(), b.size() + 1); - QCOMPARE(b.at(1), 20); - QCOMPARE(a.at(1), 15); -} - -template <typename T> -void tst_QList::qhash() const -{ - QList<T> l1, l2; - QCOMPARE(qHash(l1), qHash(l2)); - l1 << T_BAR; - l2 << T_BAR; - QCOMPARE(qHash(l1), qHash(l2)); -} - -void tst_QList::reserve() const -{ - // Note: - // This test depends on QList's current behavior that ints are stored in the array itself. - // This test would not work for QList<Complex>. - int capacity = 100; - QList<int> list; - list.reserve(capacity); - list << 0; - int *data = &list[0]; - - for (int i = 1; i < capacity; i++) { - list << i; - QCOMPARE(&list.at(0), data); - } - - QList<int> copy = list; - list.reserve(capacity / 2); - QCOMPARE(list.size(), capacity); // we didn't shrink the size! - - copy = list; - list.reserve(capacity * 2); - QCOMPARE(list.size(), capacity); - QVERIFY(&list.at(0) != data); -} - -QTEST_APPLESS_MAIN(tst_QList) -#include "tst_qlist.moc" diff --git a/tests/auto/corelib/tools/qlist_strictiterators/qlist_strictiterators.pro b/tests/auto/corelib/tools/qlist_strictiterators/qlist_strictiterators.pro deleted file mode 100644 index e39ad38919..0000000000 --- a/tests/auto/corelib/tools/qlist_strictiterators/qlist_strictiterators.pro +++ /dev/null @@ -1,3 +0,0 @@ -include(../qlist/qlist.pro) -TARGET = tst_qlist_strictiterators -DEFINES += QT_STRICT_ITERATORS tst_QList=tst_QList_StrictIterators diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index c3a8a88f0c..1638ebc992 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -68,7 +68,6 @@ private slots: void const_shared_null(); void equal_range(); - void setSharable(); void insert(); void insertMap(); @@ -1066,13 +1065,6 @@ void tst_QMap::qmultimap_specific() void tst_QMap::const_shared_null() { QMap<int, QString> map2; -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QMap<int, QString> map1; - map1.setSharable(false); - QVERIFY(map1.isDetached()); - - map2.setSharable(true); -#endif QVERIFY(!map2.isDetached()); } @@ -1161,61 +1153,6 @@ const T &const_(const T &t) return t; } -void tst_QMap::setSharable() -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QMap<int, QString> map; - - map.insert(1, "um"); - map.insert(2, "dois"); - map.insert(4, "quatro"); - map.insert(5, "cinco"); - - map.setSharable(true); - QCOMPARE(map.size(), 4); - QCOMPARE(const_(map)[4], QString("quatro")); - - { - QMap<int, QString> copy(map); - - QVERIFY(!map.isDetached()); - QVERIFY(copy.isSharedWith(map)); - sanityCheckTree(copy, __LINE__); - } - - map.setSharable(false); - sanityCheckTree(map, __LINE__); - QVERIFY(map.isDetached()); - QCOMPARE(map.size(), 4); - QCOMPARE(const_(map)[4], QString("quatro")); - - { - QMap<int, QString> copy(map); - - QVERIFY(map.isDetached()); - QVERIFY(copy.isDetached()); - - QCOMPARE(copy.size(), 4); - QCOMPARE(const_(copy)[4], QString("quatro")); - - QCOMPARE(map, copy); - sanityCheckTree(map, __LINE__); - sanityCheckTree(copy, __LINE__); - } - - map.setSharable(true); - QCOMPARE(map.size(), 4); - QCOMPARE(const_(map)[4], QString("quatro")); - - { - QMap<int, QString> copy(map); - - QVERIFY(!map.isDetached()); - QVERIFY(copy.isSharedWith(map)); - } -#endif -} - void tst_QMap::insert() { QMap<QString, float> map; @@ -1510,17 +1447,16 @@ void tst_QMap::testInsertMultiWithHint() { QMap<int, int> map; - typedef QMap<int, int>::const_iterator cite; // Hack since we define QT_STRICT_ITERATORS - map.insertMulti(cite(map.end()), 64, 65); + map.insertMulti(map.end(), 64, 65); map[128] = 129; map[256] = 257; sanityCheckTree(map, __LINE__); - map.insertMulti(cite(map.end()), 512, 513); - map.insertMulti(cite(map.end()), 512, 513 * 2); + map.insertMulti(map.end(), 512, 513); + map.insertMulti(map.end(), 512, 513 * 2); sanityCheckTree(map, __LINE__); QCOMPARE(map.size(), 5); - map.insertMulti(cite(map.end()), 256, 258); // wrong hint + map.insertMulti(map.end(), 256, 258); // wrong hint sanityCheckTree(map, __LINE__); QCOMPARE(map.size(), 6); @@ -1532,23 +1468,23 @@ void tst_QMap::testInsertMultiWithHint() sanityCheckTree(map, __LINE__); QCOMPARE(map.size(), 8); - j = map.insertMulti(cite(j), 68, 259); + j = map.insertMulti(j, 68, 259); sanityCheckTree(map, __LINE__); QCOMPARE(map.size(), 9); - j = map.insertMulti(cite(j), 67, 67); + j = map.insertMulti(j, 67, 67); sanityCheckTree(map, __LINE__); QCOMPARE(map.size(), 10); - i = map.insertMulti(cite(i), 256, 259); + i = map.insertMulti(i, 256, 259); sanityCheckTree(map, __LINE__); QCOMPARE(map.size(), 11); - i = map.insertMulti(cite(i), 256, 260); + i = map.insertMulti(i, 256, 260); sanityCheckTree(map, __LINE__); QCOMPARE(map.size(), 12); - map.insertMulti(cite(i), 64, 67); + map.insertMulti(i, 64, 67); sanityCheckTree(map, __LINE__); QCOMPARE(map.size(), 13); diff --git a/tests/auto/corelib/tools/qmap_strictiterators/qmap_strictiterators.pro b/tests/auto/corelib/tools/qmap_strictiterators/qmap_strictiterators.pro deleted file mode 100644 index 6c1f4727c1..0000000000 --- a/tests/auto/corelib/tools/qmap_strictiterators/qmap_strictiterators.pro +++ /dev/null @@ -1,3 +0,0 @@ -include(../qmap/qmap.pro) -TARGET = tst_qmap_strictiterators -DEFINES += QT_STRICT_ITERATORS tst_QMap=tst_QMap_StrictIterators diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index 8a545712a2..6638ad8b60 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -26,8 +26,6 @@ ** ****************************************************************************/ -//#define QT_STRICT_ITERATORS - #include <QtTest/QtTest> #include <qset.h> #include <qdebug.h> diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index a1d0100f96..6220cc766a 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -827,7 +827,7 @@ void tst_QVarLengthArray::operators() // +=: not provided, emulate //myvla += myvlatwo; - Q_FOREACH (const QString &s, myvlatwo) + for (const QString &s : qAsConst(myvlatwo)) myvla.push_back(s); QCOMPARE(myvla, combined); diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 08d5a8cd50..7a69e844d4 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -104,7 +104,7 @@ private: static void check(const State state1, const State state2) { - QCOMPARE(state1, state2); + QCOMPARE(int(state1), int(state2)); } }; @@ -174,7 +174,7 @@ private: { // check if c object has been moved QCOMPARE(c, c->that); - QCOMPARE(c->state, Constructed); + QCOMPARE(int(c->state), int(Constructed)); } }; QAtomicInt Custom::counter = 0; @@ -307,22 +307,11 @@ private slots: void reserve(); void reserveZero(); - void reallocAfterCopy_data(); - void reallocAfterCopy(); void initializeListInt(); void initializeListMovable(); void initializeListCustom(); void const_shared_null(); -#if 1 - // ### Qt6 remove this section - void setSharableInt_data(); - void setSharableInt(); - void setSharableMovable_data(); - void setSharableMovable(); - void setSharableCustom_data(); - void setSharableCustom(); -#endif void detachInt() const; void detachMovable() const; @@ -358,8 +347,6 @@ private: template<typename T> void size() const; template<typename T> void swap() const; template<typename T> void initializeList(); - template<typename T> void setSharable_data() const; - template<typename T> void setSharable() const; template<typename T> void detach() const; template<typename T> void detachThreadSafety() const; }; @@ -467,24 +454,6 @@ void tst_QVector::copyConstructor() const QVector<T> v2(v1); QCOMPARE(v1, v2); } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - { - QVector<T> v1; - v1.setSharable(false); - QVector<T> v2(v1); - QVERIFY(!v1.isSharedWith(v2)); - QCOMPARE(v1, v2); - } - { - QVector<T> v1; - v1 << value1 << value2 << value3 << value4; - v1.setSharable(false); - QVector<T> v2(v1); - QVERIFY(!v1.isSharedWith(v2)); - QCOMPARE(v1, v2); - } -#endif } void tst_QVector::copyConstructorInt() const @@ -665,17 +634,6 @@ void tst_QVector::append() const QVERIFY(v.size() == 3); QCOMPARE(v.at(v.size() - 1), SimpleValue<T>::at(0)); } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - { - QVector<T> v(2); - v.reserve(12); - v.setSharable(false); - v.append(SimpleValue<T>::at(0)); - QVERIFY(v.size() == 3); - QCOMPARE(v.last(), SimpleValue<T>::at(0)); - } -#endif { QVector<int> v; v << 1 << 2 << 3; @@ -766,16 +724,12 @@ void tst_QVector::capacity() const myvec.remove(3); myvec.remove(3); myvec.remove(3); - // TODO: is this a safe assumption? presumably it won't release memory until shrink(), but can we asser that is true? - QVERIFY(myvec.capacity() >= 6); myvec.squeeze(); QVERIFY(myvec.capacity() >= 3); myvec.remove(0); myvec.remove(0); myvec.remove(0); - // TODO: as above note - QVERIFY(myvec.capacity() >= 3); myvec.squeeze(); QVERIFY(myvec.capacity() == 0); } @@ -1019,20 +973,9 @@ void tst_QVector::endsWith() const template<typename T> void tst_QVector::eraseEmpty() const { - { - QVector<T> v; - v.erase(v.begin(), v.end()); - QCOMPARE(v.size(), 0); - } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - { - QVector<T> v; - v.setSharable(false); - v.erase(v.begin(), v.end()); - QCOMPARE(v.size(), 0); - } -#endif + QVector<T> v; + v.erase(v.begin(), v.end()); + QCOMPARE(v.size(), 0); } void tst_QVector::eraseEmptyInt() const @@ -1057,22 +1000,10 @@ void tst_QVector::eraseEmptyCustom() const template<typename T> void tst_QVector::eraseEmptyReserved() const { - { - QVector<T> v; - v.reserve(10); - v.erase(v.begin(), v.end()); - QCOMPARE(v.size(), 0); - } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - { - QVector<T> v; - v.reserve(10); - v.setSharable(false); - v.erase(v.begin(), v.end()); - QCOMPARE(v.size(), 0); - } -#endif + QVector<T> v; + v.reserve(10); + v.erase(v.begin(), v.end()); + QCOMPARE(v.size(), 0); } void tst_QVector::eraseEmptyReservedInt() const @@ -1179,21 +1110,6 @@ void tst_QVector::erase(bool shared) const if (shared) QCOMPARE(SimpleValue<T>::vector(12), *svc.copy); } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - { - QVector<T> v = SimpleValue<T>::vector(10); - SharedVectorChecker<T> svc(v, shared); - v.setSharable(false); - SharedVectorChecker<T> svc2(v, shared); - v.erase(v.begin() + 3); - QCOMPARE(v.size(), 9); - v.erase(v.begin(), v.end() - 1); - QCOMPARE(v.size(), 1); - if (shared) - QCOMPARE(SimpleValue<T>::vector(10), *svc.copy); - } -#endif } void tst_QVector::eraseInt() const @@ -1266,18 +1182,6 @@ template<typename T> void tst_QVector::eraseReserved() const v.erase(v.begin() + 1, v.end() - 1); QCOMPARE(v.size(), 2); } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - { - QVector<T> v(10); - v.reserve(16); - v.setSharable(false); - v.erase(v.begin() + 3); - QCOMPARE(v.size(), 9); - v.erase(v.begin(), v.end() - 1); - QCOMPARE(v.size(), 1); - } -#endif } void tst_QVector::eraseReservedInt() const @@ -2019,33 +1923,6 @@ void tst_QVector::resizePOD_data() const QTest::newRow("emptyReserved") << emptyReserved << 10; QTest::newRow("nonEmpty") << nonEmpty << 10; QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10; - -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - QVector<int> nullNotShared; - QVector<int> emptyNotShared(0, 5); - QVector<int> emptyReservedNotShared; - QVector<int> nonEmptyNotShared; - QVector<int> nonEmptyReservedNotShared; - - emptyReservedNotShared.reserve(10); - nonEmptyReservedNotShared.reserve(15); - nonEmptyNotShared << 0 << 1 << 2 << 3 << 4; - nonEmptyReservedNotShared << 0 << 1 << 2 << 3 << 4 << 5 << 6; - QVERIFY(emptyReservedNotShared.capacity() >= 10); - QVERIFY(nonEmptyReservedNotShared.capacity() >= 15); - - emptyNotShared.setSharable(false); - emptyReservedNotShared.setSharable(false); - nonEmptyNotShared.setSharable(false); - nonEmptyReservedNotShared.setSharable(false); - - QTest::newRow("nullNotShared") << nullNotShared << 10; - QTest::newRow("emptyNotShared") << emptyNotShared << 10; - QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10; - QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10; - QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10; -#endif } void tst_QVector::resizePOD() const @@ -2094,33 +1971,6 @@ void tst_QVector::resizeComplexMovable_data() const QTest::newRow("emptyReserved") << emptyReserved << 10; QTest::newRow("nonEmpty") << nonEmpty << 10; QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10; - -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - QVector<Movable> nullNotShared; - QVector<Movable> emptyNotShared(0, 'Q'); - QVector<Movable> emptyReservedNotShared; - QVector<Movable> nonEmptyNotShared; - QVector<Movable> nonEmptyReservedNotShared; - - emptyReservedNotShared.reserve(10); - nonEmptyReservedNotShared.reserve(15); - nonEmptyNotShared << '0' << '1' << '2' << '3' << '4'; - nonEmptyReservedNotShared << '0' << '1' << '2' << '3' << '4' << '5' << '6'; - QVERIFY(emptyReservedNotShared.capacity() >= 10); - QVERIFY(nonEmptyReservedNotShared.capacity() >= 15); - - emptyNotShared.setSharable(false); - emptyReservedNotShared.setSharable(false); - nonEmptyNotShared.setSharable(false); - nonEmptyReservedNotShared.setSharable(false); - - QTest::newRow("nullNotShared") << nullNotShared << 10; - QTest::newRow("emptyNotShared") << emptyNotShared << 10; - QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10; - QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10; - QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10; -#endif } void tst_QVector::resizeComplexMovable() const @@ -2173,33 +2023,6 @@ void tst_QVector::resizeComplex_data() const QTest::newRow("emptyReserved") << emptyReserved << 10; QTest::newRow("nonEmpty") << nonEmpty << 10; QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10; - -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - QVector<Custom> nullNotShared; - QVector<Custom> emptyNotShared(0, '0'); - QVector<Custom> emptyReservedNotShared; - QVector<Custom> nonEmptyNotShared; - QVector<Custom> nonEmptyReservedNotShared; - - emptyReservedNotShared.reserve(10); - nonEmptyReservedNotShared.reserve(15); - nonEmptyNotShared << '0' << '1' << '2' << '3' << '4'; - nonEmptyReservedNotShared << '0' << '1' << '2' << '3' << '4' << '5' << '6'; - QVERIFY(emptyReservedNotShared.capacity() >= 10); - QVERIFY(nonEmptyReservedNotShared.capacity() >= 15); - - emptyNotShared.setSharable(false); - emptyReservedNotShared.setSharable(false); - nonEmptyNotShared.setSharable(false); - nonEmptyReservedNotShared.setSharable(false); - - QTest::newRow("nullNotShared") << nullNotShared << 10; - QTest::newRow("emptyNotShared") << emptyNotShared << 10; - QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10; - QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10; - QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10; -#endif } void tst_QVector::resizeComplex() const @@ -2512,87 +2335,6 @@ void tst_QVector::reserveZero() QVERIFY(vec.capacity() >= 1); } -// This is a regression test for QTBUG-11763, where memory would be reallocated -// soon after copying a QVector. -void tst_QVector::reallocAfterCopy_data() -{ - QTest::addColumn<int>("capacity"); - QTest::addColumn<int>("fill_size"); - QTest::addColumn<int>("func_id"); - QTest::addColumn<int>("result1"); - QTest::addColumn<int>("result2"); - QTest::addColumn<int>("result3"); - QTest::addColumn<int>("result4"); - - int result1, result2, result3, result4; - int fill_size; - for (int i = 70; i <= 100; i += 10) { - const QByteArray prefix = "reallocAfterCopy:" + QByteArray::number(i) + ','; - fill_size = i - 20; - for (int j = 0; j <= 3; j++) { - if (j == 0) { // append - result1 = i; - result2 = i; - result3 = i - 19; - result4 = i - 20; - } else if (j == 1) { // insert(0) - result1 = i; - result2 = i; - result3 = i - 19; - result4 = i - 20; - } else if (j == 2) { // insert(20) - result1 = i; - result2 = i; - result3 = i - 19; - result4 = i - 20; - } else if (j == 3) { // insert(0, 10) - result1 = i; - result2 = i; - result3 = i - 10; - result4 = i - 20; - } - QTest::newRow((prefix + QByteArray::number(j)).constData()) - << i << fill_size << j << result1 << result2 << result3 << result4; - } - } -} - -void tst_QVector::reallocAfterCopy() -{ - QFETCH(int, capacity); - QFETCH(int, fill_size); - QFETCH(int, func_id); - QFETCH(int, result1); - QFETCH(int, result2); - QFETCH(int, result3); - QFETCH(int, result4); - - QVector<qreal> v1; - QVector<qreal> v2; - - v1.reserve(capacity); - v1.resize(0); - v1.fill(qreal(1.0), fill_size); - - v2 = v1; - - // no need to test begin() and end(), there is a detach() in them - if (func_id == 0) { - v1.append(qreal(1.0)); //push_back is same as append - } else if (func_id == 1) { - v1.insert(0, qreal(1.0)); //push_front is same as prepend, insert(0) - } else if (func_id == 2) { - v1.insert(20, qreal(1.0)); - } else if (func_id == 3) { - v1.insert(0, 10, qreal(1.0)); - } - - QCOMPARE(v1.capacity(), result1); - QCOMPARE(v2.capacity(), result2); - QCOMPARE(v1.size(), result3); - QCOMPARE(v2.size(), result4); -} - template<typename T> void tst_QVector::initializeList() { @@ -2636,154 +2378,9 @@ void tst_QVector::initializeListCustom() void tst_QVector::const_shared_null() { QVector<int> v2; -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - // ### Qt6 remove this section - QVector<int> v1; - v1.setSharable(false); - QVERIFY(v1.isDetached()); - - v2.setSharable(true); -#endif QVERIFY(!v2.isDetached()); } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) -// ### Qt6 remove this section -template<typename T> -void tst_QVector::setSharable_data() const -{ - QTest::addColumn<QVector<T> >("vector"); - QTest::addColumn<int>("size"); - QTest::addColumn<int>("capacity"); - QTest::addColumn<bool>("isCapacityReserved"); - - QVector<T> null; - QVector<T> empty(0, SimpleValue<T>::at(1)); - QVector<T> emptyReserved; - QVector<T> nonEmpty; - QVector<T> nonEmptyReserved; - - emptyReserved.reserve(10); - nonEmptyReserved.reserve(15); - - nonEmpty << SimpleValue<T>::at(0) << SimpleValue<T>::at(1) << SimpleValue<T>::at(2) << SimpleValue<T>::at(3) << SimpleValue<T>::at(4); - nonEmptyReserved << SimpleValue<T>::at(0) << SimpleValue<T>::at(1) << SimpleValue<T>::at(2) << SimpleValue<T>::at(3) << SimpleValue<T>::at(4) << SimpleValue<T>::at(5) << SimpleValue<T>::at(6); - - QVERIFY(emptyReserved.capacity() >= 10); - QVERIFY(nonEmptyReserved.capacity() >= 15); - - QTest::newRow("null") << null << 0 << 0 << false; - QTest::newRow("empty") << empty << 0 << 0 << false; - QTest::newRow("empty, Reserved") << emptyReserved << 0 << 10 << true; - QTest::newRow("non-empty") << nonEmpty << 5 << 0 << false; - QTest::newRow("non-empty, Reserved") << nonEmptyReserved << 7 << 15 << true; -} - -template<typename T> -void tst_QVector::setSharable() const -{ - QFETCH(QVector<T>, vector); - QFETCH(int, size); - QFETCH(int, capacity); - QFETCH(bool, isCapacityReserved); - - QVERIFY(!vector.isDetached()); // Shared with QTest - - vector.setSharable(true); - - QCOMPARE(vector.size(), size); - if (isCapacityReserved) - QVERIFY2(vector.capacity() >= capacity, - qPrintable(QString("Capacity is %1, expected at least %2.") - .arg(vector.capacity()) - .arg(capacity))); - - { - QVector<T> copy(vector); - - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(vector)); - } - - vector.setSharable(false); - QVERIFY(vector.isDetached() || vector.isSharedWith(QVector<T>())); - - { - QVector<T> copy(vector); - - QVERIFY(copy.isDetached() || copy.isEmpty() || copy.isSharedWith(QVector<T>())); - QCOMPARE(copy.size(), size); - if (isCapacityReserved) - QVERIFY2(copy.capacity() >= capacity, - qPrintable(QString("Capacity is %1, expected at least %2.") - .arg(copy.capacity()) - .arg(capacity))); - QCOMPARE(copy, vector); - } - - vector.setSharable(true); - - { - QVector<T> copy(vector); - - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(vector)); - } - - for (int i = 0; i < vector.size(); ++i) - QCOMPARE(vector[i], SimpleValue<T>::at(i)); - - QCOMPARE(vector.size(), size); - if (isCapacityReserved) - QVERIFY2(vector.capacity() >= capacity, - qPrintable(QString("Capacity is %1, expected at least %2.") - .arg(vector.capacity()) - .arg(capacity))); -} -#else -template<typename T> void tst_QVector::setSharable_data() const -{ -} - -template<typename T> void tst_QVector::setSharable() const -{ -} -#endif - -void tst_QVector::setSharableInt_data() -{ - setSharable_data<int>(); -} - -void tst_QVector::setSharableMovable_data() -{ - setSharable_data<Movable>(); -} - -void tst_QVector::setSharableCustom_data() -{ - setSharable_data<Custom>(); -} - -void tst_QVector::setSharableInt() -{ - setSharable<int>(); -} - -void tst_QVector::setSharableMovable() -{ - const int instancesCount = Movable::counter.loadAcquire(); - setSharable<Movable>(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QVector::setSharableCustom() -{ - const int instancesCount = Custom::counter.loadAcquire(); - setSharable<Custom>(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template<typename T> void tst_QVector::detach() const { @@ -2791,7 +2388,7 @@ void tst_QVector::detach() const // detach an empty vector QVector<T> v; v.detach(); - QVERIFY(v.isDetached()); + QVERIFY(!v.isDetached()); QCOMPARE(v.size(), 0); QCOMPARE(v.capacity(), 0); } @@ -2801,7 +2398,7 @@ void tst_QVector::detach() const QVector<T> ref(v); QVERIFY(!v.isDetached()); v.detach(); - QVERIFY(v.isDetached()); + QVERIFY(!v.isDetached()); QCOMPARE(v.size(), 0); QCOMPARE(v.capacity(), 0); } diff --git a/tests/auto/corelib/tools/qvector_strictiterators/qvector_strictiterators.pro b/tests/auto/corelib/tools/qvector_strictiterators/qvector_strictiterators.pro deleted file mode 100644 index d6cad86aac..0000000000 --- a/tests/auto/corelib/tools/qvector_strictiterators/qvector_strictiterators.pro +++ /dev/null @@ -1,3 +0,0 @@ -include(../qvector/qvector.pro) -TARGET = tst_qvector_strictiterators -DEFINES += QT_STRICT_ITERATORS=1 tst_QVector=tst_QVector_StrictIterators diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index 49b2a1f075..be195ea037 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -4,7 +4,6 @@ SUBDIRS=\ containerapisymmetry \ qalgorithms \ qarraydata \ - qarraydata_strictiterators \ qbitarray \ qcache \ qcommandlineparser \ @@ -12,17 +11,14 @@ SUBDIRS=\ qcryptographichash \ qeasingcurve \ qexplicitlyshareddatapointer \ + qflatmap \ qfreelist \ qhash \ - qhash_strictiterators \ qhashfunctions \ qline \ qlinkedlist \ - qlist \ - qlist_strictiterators \ qmakearray \ qmap \ - qmap_strictiterators \ qmargins \ qmessageauthenticationcode \ qoffsetstringarray \ @@ -43,7 +39,6 @@ SUBDIRS=\ qtimeline \ qvarlengtharray \ qvector \ - qvector_strictiterators \ qversionnumber darwin: SUBDIRS += qmacautoreleasepool |