diff options
Diffstat (limited to 'tests/auto/corelib/global')
7 files changed, 233 insertions, 29 deletions
diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 2f1b56629a..72b086350e 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -39,6 +39,7 @@ private slots: void classEnum(); void initializerLists(); void testSetFlags(); + void adl(); }; void tst_QFlags::testFlag() const @@ -120,7 +121,7 @@ void tst_QFlags::constExpr() QVERIFY(verifyConstExpr<uint(Qt::MouseButtons(Qt::RightButton) & 0xff)>(Qt::RightButton)); QVERIFY(verifyConstExpr<uint(Qt::MouseButtons(Qt::RightButton) | 0xff)>(0xff)); - QVERIFY(!verifyConstExpr<Qt::RightButton>(!Qt::MouseButtons(Qt::LeftButton))); + QVERIFY(!verifyConstExpr<Qt::RightButton>(~Qt::MouseButtons(Qt::LeftButton))); #if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304 QVERIFY(verifyConstExpr<uint(testRelaxedConstExpr())>(Qt::MiddleButton)); @@ -304,6 +305,27 @@ void tst_QFlags::testSetFlags() QVERIFY(!flags.testFlag(MyStrictEnum::StrictFour)); } +namespace SomeNS { +enum Foo { Foo_A = 1 << 0, Foo_B = 1 << 1, Foo_C = 1 << 2 }; + +Q_DECLARE_FLAGS(Foos, Foo) +Q_DECLARE_OPERATORS_FOR_FLAGS(Foos); + +Qt::Alignment alignment() +{ + // Checks that the operator| works, despite there is another operator| in this namespace. + return Qt::AlignLeft | Qt::AlignTop; +} +} + +void tst_QFlags::adl() +{ + SomeNS::Foos fl = SomeNS::Foo_B | SomeNS::Foo_C; + QVERIFY(fl & SomeNS::Foo_B); + QVERIFY(!(fl & SomeNS::Foo_A)); + QCOMPARE(SomeNS::alignment(), Qt::AlignLeft | Qt::AlignTop); +} + // (statically) check QTypeInfo for QFlags instantiations: enum MyEnum { Zero, One, Two, Four=4 }; Q_DECLARE_FLAGS( MyFlags, MyEnum ) diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp index f02e902468..544cb1bf07 100644 --- a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp +++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp @@ -160,8 +160,10 @@ void tst_QGetPutEnv::intValue_data() // some repetition from what is tested in getSetCheck() QTest::newRow("empty") << QByteArray() << 0 << false; - QTest::newRow("spaces-heading") << QByteArray(" 1") << 1 << true; - QTest::newRow("spaces-trailing") << QByteArray("1 ") << 0 << false; + QTest::newRow("spaces-heading") << QByteArray(" \n\r\t1") << 1 << true; + QTest::newRow("spaces-trailing") << QByteArray("1 \n\r\t") << 1 << true; + QTest::newRow("junk-heading") << QByteArray("x1") << 0 << false; + QTest::newRow("junk-trailing") << QByteArray("1x") << 0 << false; #define ROW(x, i, b) \ QTest::newRow(#x) << QByteArray(#x) << (i) << (b) diff --git a/tests/auto/corelib/global/qlogging/app/app.pro b/tests/auto/corelib/global/qlogging/app/app.pro index 30751d89ec..b90b685749 100644 --- a/tests/auto/corelib/global/qlogging/app/app.pro +++ b/tests/auto/corelib/global/qlogging/app/app.pro @@ -1,6 +1,15 @@ TEMPLATE = app -TARGET = app +debug_and_release { + CONFIG(debug, debug|release) { + TARGET = ../debug/helper + } else { + TARGET = ../release/helper + } +} else { + TARGET = ../helper +} + QT = core DESTDIR = ./ diff --git a/tests/auto/corelib/global/qlogging/test/test.pro b/tests/auto/corelib/global/qlogging/test/test.pro index b48bf82cf9..91896d4494 100644 --- a/tests/auto/corelib/global/qlogging/test/test.pro +++ b/tests/auto/corelib/global/qlogging/test/test.pro @@ -1,11 +1,21 @@ CONFIG += testcase -CONFIG -= debug_and_release_target qtConfig(c++11): CONFIG += c++11 qtConfig(c++14): CONFIG += c++14 -TARGET = ../tst_qlogging +debug_and_release { + CONFIG(debug, debug|release) { + TARGET = ../../debug/tst_qlogging + !android:!winrt: TEST_HELPER_INSTALLS = ../debug/helper + } else { + TARGET = ../../release/tst_qlogging + !android:!winrt: TEST_HELPER_INSTALLS = ../release/helper + } +} else { + TARGET = ../tst_qlogging + !android:!winrt: TEST_HELPER_INSTALLS = ../helper +} + QT = core testlib SOURCES = ../tst_qlogging.cpp DEFINES += QT_MESSAGELOGCONTEXT -!android:!winrt: TEST_HELPER_INSTALLS = ../app/app DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index e7a3748c30..d3ed1a6d0d 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -64,7 +64,6 @@ private slots: void formatLogMessage(); private: - QString m_appDir; QStringList m_baseEnvironment; }; @@ -101,14 +100,6 @@ tst_qmessagehandler::tst_qmessagehandler() void tst_qmessagehandler::initTestCase() { #if QT_CONFIG(process) -# ifdef Q_OS_ANDROID - m_appDir = QCoreApplication::applicationDirPath(); -# else // !android - m_appDir = QFINDTESTDATA("app"); -# endif - QVERIFY2(!m_appDir.isEmpty(), qPrintable( - QString::fromLatin1("Couldn't find helper app dir starting from %1.").arg(QDir::currentPath()))); - m_baseEnvironment = QProcess::systemEnvironment(); for (int i = 0; i < m_baseEnvironment.count(); ++i) { if (m_baseEnvironment.at(i).startsWith("QT_MESSAGE_PATTERN=")) { @@ -806,7 +797,7 @@ void tst_qmessagehandler::qMessagePattern_data() #ifndef QT_NO_DEBUG QTest::newRow("backtrace") << "[%{backtrace}] %{message}" << true << (QList<QByteArray>() // MyClass::qt_static_metacall is explicitly marked as hidden in the Q_OBJECT macro - << "[MyClass::myFunction|MyClass::mySlot1|?app?|" QT_NAMESPACE_STR "QMetaMethod::invoke|" QT_NAMESPACE_STR "QMetaObject::invokeMethod] from_a_function 34"); + << "[MyClass::myFunction|MyClass::mySlot1|?helper?|" QT_NAMESPACE_STR "QMetaMethod::invoke|" QT_NAMESPACE_STR "QMetaObject::invokeMethod] from_a_function 34"); #endif QTest::newRow("backtrace depth,separator") << "[%{backtrace depth=2 separator=\"\n\"}] %{message}" << true << (QList<QByteArray>() @@ -830,10 +821,10 @@ void tst_qmessagehandler::qMessagePattern() QFETCH(QList<QByteArray>, expected); QProcess process; -#ifdef Q_OS_ANDROID - const QString appExe = m_appDir + "/libapp.so"; -#else // !android - const QString appExe = m_appDir + "/app"; +#ifndef Q_OS_ANDROID + const QString appExe(QLatin1String("helper")); +#else + const QString appExe(QCoreApplication::applicationDirPath() + QLatin1String("/libhelper.so")); #endif // @@ -880,10 +871,10 @@ void tst_qmessagehandler::setMessagePattern() // QProcess process; -#ifdef Q_OS_ANDROID - const QString appExe = m_appDir + "/libapp.so"; -#else // !android - const QString appExe = m_appDir + "/app"; +#ifndef Q_OS_ANDROID + const QString appExe(QLatin1String("helper")); +#else + const QString appExe(QCoreApplication::applicationDirPath() + QLatin1String("/libhelper.so")); #endif // make sure there is no QT_MESSAGE_PATTERN in the environment diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp index 7a6842d144..7c04611823 100644 --- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp +++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp @@ -52,7 +52,7 @@ // values chosen at random static const quint32 RandomValue32 = 0x4d1169f1U; static const quint64 RandomValue64 = Q_UINT64_C(0x3ce63161b998aa91); -static const double RandomValueFP = double(0.3010463714599609f); +static const double RandomValueFP = double(0.3010463714599609); static void setRNGControl(uint v) { diff --git a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp index 6934818dcf..2345bb39c1 100644 --- a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp +++ b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp @@ -39,9 +39,17 @@ class tst_QtEndian: public QObject private slots: void fromBigEndian(); void fromLittleEndian(); + void fromBigEndianRegion_data(); + void fromBigEndianRegion(); + void fromLittleEndianRegion_data() { fromBigEndianRegion_data(); } + void fromLittleEndianRegion(); void toBigEndian(); void toLittleEndian(); + void toBigEndianRegion_data() { fromBigEndianRegion_data(); } + void toBigEndianRegion(); + void toLittleEndianRegion_data() { fromBigEndianRegion_data(); } + void toLittleEndianRegion(); void endianIntegers_data(); void endianIntegers(); @@ -56,18 +64,58 @@ struct TestData quint16 data16; quint8 data8; + float dataFloat; + double dataDouble; + quint8 reserved; }; +template <typename T> T getData(const TestData &d); +template <> quint8 getData(const TestData &d) { return d.data8; } +template <> quint16 getData(const TestData &d) { return d.data16; } +template <> quint32 getData(const TestData &d) { return d.data32; } +template <> quint64 getData(const TestData &d) { return d.data64; } +template <> float getData(const TestData &d) { return d.dataFloat; } + union RawTestData { uchar rawData[sizeof(TestData)]; TestData data; }; -static const TestData inNativeEndian = { Q_UINT64_C(0x0123456789abcdef), 0x00c0ffee, 0xcafe, 0xcf, '\0' }; -static const RawTestData inBigEndian = { "\x01\x23\x45\x67\x89\xab\xcd\xef" "\x00\xc0\xff\xee" "\xca\xfe" "\xcf" }; -static const RawTestData inLittleEndian = { "\xef\xcd\xab\x89\x67\x45\x23\x01" "\xee\xff\xc0\x00" "\xfe\xca" "\xcf" }; +template <typename Float> +Float int2Float(typename QIntegerForSizeof<Float>::Unsigned i) +{ + Float result = 0; + memcpy(reinterpret_cast<char *>(&result), reinterpret_cast<const char *>(&i), sizeof (Float)); + return result; +} + +static const TestData inNativeEndian = { + Q_UINT64_C(0x0123456789abcdef), + 0x00c0ffee, + 0xcafe, + 0xcf, + int2Float<float>(0x00c0ffeeU), + int2Float<double>(Q_UINT64_C(0x0123456789abcdef)), + '\0' +}; +static const RawTestData inBigEndian = { + "\x01\x23\x45\x67\x89\xab\xcd\xef" + "\x00\xc0\xff\xee" + "\xca\xfe" + "\xcf" + "\x00\xc0\xff\xee" + "\x01\x23\x45\x67\x89\xab\xcd\xef" +}; +static const RawTestData inLittleEndian = { + "\xef\xcd\xab\x89\x67\x45\x23\x01" + "\xee\xff\xc0\x00" + "\xfe\xca" + "\xcf" + "\xee\xff\xc0\x00" + "\xef\xcd\xab\x89\x67\x45\x23\x01" +}; #define EXPAND_ENDIAN_TEST(endian) \ do { \ @@ -108,6 +156,106 @@ void tst_QtEndian::fromLittleEndian() #undef ENDIAN_TEST +template <typename T> +void transformRegion_template(T (*transformOne)(T), void (*transformRegion)(const void *, qsizetype, void *)) +{ + enum { Size = 64 }; + T source[Size]; + T dest[Size]; + T expected = transformOne(getData<T>(inNativeEndian)); + std::fill_n(source, +Size, getData<T>(inNativeEndian)); + memset(dest, 0, sizeof(dest)); + + auto checkBounds = [&](int from) { + for ( ; from < Size; ++from) + QCOMPARE(dest[from], T(0)); + }; + + transformRegion(source, 1, dest); + QCOMPARE(dest[0], expected); + checkBounds(1); + memset(dest, 0, sizeof(T)); + + transformRegion(source, 2, dest); + QCOMPARE(dest[0], expected); + QCOMPARE(dest[1], expected); + checkBounds(2); + memset(dest, 0, sizeof(T) * 2); + + transformRegion(source, 3, dest); + QCOMPARE(dest[0], expected); + QCOMPARE(dest[1], expected); + QCOMPARE(dest[2], expected); + checkBounds(3); + memset(dest, 0, sizeof(T) * 3); + + transformRegion(source, 4, dest); + QCOMPARE(dest[0], expected); + QCOMPARE(dest[1], expected); + QCOMPARE(dest[2], expected); + QCOMPARE(dest[3], expected); + checkBounds(4); + memset(dest, 0, sizeof(T) * 4); + + transformRegion(source, 8, dest); + for (int i = 0; i < 8; ++i) + QCOMPARE(dest[i], expected); + checkBounds(8); + memset(dest, 0, sizeof(T) * 8); + + transformRegion(source, 16, dest); + for (int i = 0; i < 16; ++i) + QCOMPARE(dest[i], expected); + checkBounds(16); + memset(dest, 0, sizeof(T) * 16); + + transformRegion(source, 32, dest); + for (int i = 0; i < 32; ++i) + QCOMPARE(dest[i], expected); + checkBounds(32); + memset(dest, 0, sizeof(T) * 32); + + transformRegion(source, 64, dest); + for (int i = 0; i < 64; ++i) + QCOMPARE(dest[i], expected); + + // check transforming in-place + memcpy(dest, source, sizeof(dest)); + transformRegion(dest, 64, dest); + for (int i = 0; i < 64; ++i) + QCOMPARE(dest[i], expected); +} + +void tst_QtEndian::fromBigEndianRegion_data() +{ + QTest::addColumn<int>("size"); + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("4") << 4; + QTest::newRow("8") << 8; +} + +void tst_QtEndian::fromBigEndianRegion() +{ + QFETCH(int, size); + switch (size) { + case 1: return transformRegion_template<quint8>(qFromBigEndian<quint8>, qFromBigEndian<quint8>); + case 2: return transformRegion_template<quint16>(qFromBigEndian<quint16>, qFromBigEndian<quint16>); + case 4: return transformRegion_template<quint32>(qFromBigEndian<quint32>, qFromBigEndian<quint32>); + case 8: return transformRegion_template<quint64>(qFromBigEndian<quint64>, qFromBigEndian<quint64>); + } +} + +void tst_QtEndian::fromLittleEndianRegion() +{ + QFETCH(int, size); + switch (size) { + case 1: return transformRegion_template<quint8>(qFromLittleEndian<quint8>, qFromLittleEndian<quint8>); + case 2: return transformRegion_template<quint16>(qFromLittleEndian<quint16>, qFromLittleEndian<quint16>); + case 4: return transformRegion_template<quint32>(qFromLittleEndian<quint32>, qFromLittleEndian<quint32>); + case 8: return transformRegion_template<quint64>(qFromLittleEndian<quint64>, qFromLittleEndian<quint64>); + } +} #define ENDIAN_TEST(endian, type, size) \ do { \ @@ -135,6 +283,28 @@ void tst_QtEndian::toLittleEndian() #undef ENDIAN_TEST +void tst_QtEndian::toBigEndianRegion() +{ + QFETCH(int, size); + switch (size) { + case 1: return transformRegion_template<quint8>(qToBigEndian<quint8>, qToBigEndian<quint8>); + case 2: return transformRegion_template<quint16>(qToBigEndian<quint16>, qToBigEndian<quint16>); + case 4: return transformRegion_template<quint32>(qToBigEndian<quint32>, qToBigEndian<quint32>); + case 8: return transformRegion_template<quint64>(qToBigEndian<quint64>, qToBigEndian<quint64>); + } +} + +void tst_QtEndian::toLittleEndianRegion() +{ + QFETCH(int, size); + switch (size) { + case 1: return transformRegion_template<quint8>(qToLittleEndian<quint8>, qToLittleEndian<quint8>); + case 2: return transformRegion_template<quint16>(qToLittleEndian<quint16>, qToLittleEndian<quint16>); + case 4: return transformRegion_template<quint32>(qToLittleEndian<quint32>, qToLittleEndian<quint32>); + case 8: return transformRegion_template<quint64>(qToLittleEndian<quint64>, qToLittleEndian<quint64>); + } +} + void tst_QtEndian::endianIntegers_data() { QTest::addColumn<int>("val"); |