From f2f040ae1c4fe48bff68bb45b2e20308fa895c50 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Tue, 2 Oct 2018 12:36:04 +0200 Subject: Improve support for QImages in QDataStream read transactions QImage's operator>>(QDataStream&) did not set an error mode on the stream on read failures. That would break QDataStream transactions. Since the current QImage serialization cannot differentiate between truncated and corrupted data, we set the ReadPastEnd error as expected by the transaction system. Also specify the expected file format on decoding QImage from stream, to avoid all the format handlers' canRead() being invoked. This is necessary since some of them may call ungetChar(), which fails when the stream is in a transaction. Also add testing of this feature to the QDataStram transaction autotest. That required a slight rewrite of the fake sequential QIODevice subclass. The previous implementation had incorrect behavior of peek(), which is required by QImage decoders. Task-number: QTBUG-70875 Change-Id: If3f1ca7186ad1e6ca0e6e8ea81d2b2fbece6ea01 Reviewed-by: Alex Trotsenko Reviewed-by: Thiago Macieira --- .../serialization/qdatastream/tst_qdatastream.cpp | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index c6faf8c7d5..011a0e1a85 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -2211,25 +2211,22 @@ void tst_QDataStream::setVersion() } } -class SequentialBuffer : public QBuffer +class SequentialBuffer : public QIODevice { public: - SequentialBuffer(QByteArray *data) : QBuffer(data) { offset = 0; } + SequentialBuffer(QByteArray *data) : QIODevice() { buf.setBuffer(data); } - bool isSequential() const { return true; } - bool seek(qint64 pos) { offset = pos; return QBuffer::seek(pos); } - qint64 pos() const { return qint64(offset); } + bool isSequential() const override { return true; } + bool open(OpenMode mode) override { return buf.open(mode) && QIODevice::open(mode | QIODevice::Unbuffered); } + void close() override { buf.close(); QIODevice::close(); } + qint64 bytesAvailable() const override { return QIODevice::bytesAvailable() + buf.bytesAvailable(); } protected: - qint64 readData(char *data, qint64 maxSize) - { - qint64 ret = QBuffer::readData(data, maxSize); - offset += ret; - return ret; - } + qint64 readData(char *data, qint64 maxSize) override { return buf.read(data, maxSize); } + qint64 writeData(const char *data, qint64 maxSize) override { return buf.write(data, maxSize); } private: - int offset; + QBuffer buf; }; void tst_QDataStream::skipRawData_data() @@ -3329,15 +3326,21 @@ void tst_QDataStream::transaction_data() QTest::addColumn("bData"); QTest::addColumn("fData"); QTest::addColumn("dData"); + QTest::addColumn("imgData"); QTest::addColumn("strData"); QTest::addColumn("rawData"); + QImage img1(open_xpm); + QImage img2; + QImage img3(50, 50, QImage::Format_ARGB32); + img3.fill(qRgba(12, 34, 56, 78)); + QTest::newRow("1") << qint8(1) << qint16(2) << qint32(3) << qint64(4) << true << 5.0f - << double(6.0) << QByteArray("Hello world!") << QByteArray("Qt rocks!"); + << double(6.0) << img1 << QByteArray("Hello world!") << QByteArray("Qt rocks!"); QTest::newRow("2") << qint8(1 << 6) << qint16(1 << 14) << qint32(1 << 30) << qint64Data(3) << false << 123.0f - << double(234.0) << stringData(5).toUtf8() << stringData(6).toUtf8(); + << double(234.0) << img2 << stringData(5).toUtf8() << stringData(6).toUtf8(); QTest::newRow("3") << qint8(-1) << qint16(-2) << qint32(-3) << qint64(-4) << true << -123.0f - << double(-234.0) << stringData(3).toUtf8() << stringData(4).toUtf8(); + << double(-234.0) << img3 << stringData(3).toUtf8() << stringData(4).toUtf8(); } void tst_QDataStream::transaction() @@ -3351,6 +3354,7 @@ void tst_QDataStream::transaction() QFETCH(bool, bData); QFETCH(float, fData); QFETCH(double, dData); + QFETCH(QImage, imgData); QFETCH(QByteArray, strData); QFETCH(QByteArray, rawData); @@ -3358,12 +3362,13 @@ void tst_QDataStream::transaction() QDataStream stream(&testBuffer, QIODevice::WriteOnly); stream << i8Data << i16Data << i32Data << i64Data - << bData << fData << dData << strData.constData(); + << bData << fData << dData << imgData << strData.constData(); stream.writeRawData(rawData.constData(), rawData.size()); } for (int splitPos = 0; splitPos <= testBuffer.size(); ++splitPos) { QByteArray readBuffer(testBuffer.left(splitPos)); + SequentialBuffer dev(&readBuffer); dev.open(QIODevice::ReadOnly); QDataStream stream(&dev); @@ -3375,12 +3380,13 @@ void tst_QDataStream::transaction() bool b; float f; double d; + QImage img; char *str; QByteArray raw(rawData.size(), 0); forever { stream.startTransaction(); - stream >> i8 >> i16 >> i32 >> i64 >> b >> f >> d >> str; + stream >> i8 >> i16 >> i32 >> i64 >> b >> f >> d >> img >> str; stream.readRawData(raw.data(), raw.size()); if (stream.commitTransaction()) @@ -3402,6 +3408,7 @@ void tst_QDataStream::transaction() QCOMPARE(b, bData); QCOMPARE(f, fData); QCOMPARE(d, dData); + QCOMPARE(img, imgData); QVERIFY(strData == str); delete [] str; QCOMPARE(raw, rawData); -- cgit v1.2.3 From 497f43c90f7160c1b198d829eab21c8c010fc7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Wed, 24 Oct 2018 12:46:04 +0200 Subject: tst_QCborValue: Disable support for spaceship operator Spaceship operator was disabled for QCborValue, but not the test. Change-Id: Icb91da689f62ef6de9f4fa926346505c5e50e9eb Reviewed-by: Thiago Macieira --- tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index 38b26e7de4..4b753eab6b 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -330,7 +330,7 @@ void tst_QCborValue::copyCompare() QCOMPARE(v, other); QVERIFY(!(v != other)); QVERIFY(!(v < other)); -#if QT_HAS_INCLUDE() +#if 0 && QT_HAS_INCLUDE() QVERIFY(v <= other); QVERIFY(v >= other); QVERIFY(!(v > other)); -- cgit v1.2.3 From 779a73762de6addb2a2e3fee5b98d00d64101b92 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 14 Sep 2018 14:59:21 +0200 Subject: Fully support operator[] on QCborValue and QCborValueRef Added operator[] to QCborValueRef and mutating operator[] both there and in QCborValue. If the value (referenced) is not a container, it is replaced with a map and a reference into the result is returned. If the value is an array and the key is a string, negative, or more than 0xffff, the array is first converted to a map. Change-Id: Ibbc9e480fb25eb3d05547c8a1b99e762b2a68b68 Reviewed-by: Thiago Macieira --- .../serialization/qcborvalue/tst_qcborvalue.cpp | 59 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index c609aa6621..f69ce4120d 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -384,11 +384,17 @@ void tst_QCborValue::arrayDefaultInitialization() QVERIFY(v.isArray()); QVERIFY(!v.isMap()); QVERIFY(!v.isTag()); - QVERIFY(v[0].isUndefined()); QCborArray a2 = v.toArray(); QVERIFY(a2.isEmpty()); QCOMPARE(a2, a); + auto front = v[0]; + QVERIFY(front.isUndefined()); + front = 1; + QCOMPARE(v[0], 1); + QVERIFY(a2.isEmpty()); + a2 = v.toArray(); + QCOMPARE(a2.size(), 1); } void tst_QCborValue::mapDefaultInitialization() @@ -425,7 +431,7 @@ void tst_QCborValue::mapDefaultInitialization() QVERIFY(m == QCborMap{}); QVERIFY(QCborMap{} == m); - QCborValue v(m); + const QCborValue v(m); QVERIFY(v.isMap()); QVERIFY(!v.isArray()); QVERIFY(!v.isTag()); @@ -727,6 +733,31 @@ void tst_QCborValue::arrayMutation() QCOMPARE(a.at(1), QCborValue(-1)); QCOMPARE(a2.at(1), QCborValue(nullptr)); QCOMPARE(++it, end); + + // Array accessed via value: + QCborValue val(a); + val[2] = QCborArray{2, 3, 5, 7}; + QCOMPARE(a.size(), 2); // Unchanged + QVERIFY(val.isArray()); + QCOMPARE(val.toArray().size(), 3); + val[2][4] = 17; + QVERIFY(val.isArray()); + QVERIFY(val[2].isArray()); + QCOMPARE(val[2].toArray().size(), 5); + QCOMPARE(val[2][4], 17); + QCOMPARE(val.toArray().size(), 3); + val[3] = 42; + QVERIFY(val.isArray()); + QCOMPARE(val.toArray().size(), 4); + QCOMPARE(val[3], 42); + + // Coerce to map on string key: + const QLatin1String any("any"); + val[any] = any; + QVERIFY(val.isMap()); + QCOMPARE(val.toMap().size(), 5); + QVERIFY(val[2].isArray()); + QCOMPARE(val[2].toArray().size(), 5); } void tst_QCborValue::mapMutation() @@ -782,6 +813,30 @@ void tst_QCborValue::mapMutation() QCOMPARE((m.end() - 1)->toInteger(), -1); QVERIFY((m2.end() - 1)->isNull()); QCOMPARE(++it, end); + + // Map accessed via value: + QCborValue val(m); + val[7] = QCborMap({{0, 2}, {1, 3}, {2, 5}}); + QCOMPARE(m.size(), 2); // Unchanged + QVERIFY(val.isMap()); + QCOMPARE(val.toMap().size(), 3); + val[7][3] = 11; + QVERIFY(val.isMap()); + QVERIFY(val[7].isMap()); + QCOMPARE(val[7].toMap().size(), 4); + val[14] = 42; + QVERIFY(val.isMap()); + QCOMPARE(val.toMap().size(), 4); + + const QLatin1String any("any"); + const QString hello(QStringLiteral("Hello World")); + val[any][3][hello] = any; + QVERIFY(val.isMap()); + QCOMPARE(val.toMap().size(), 5); + QVERIFY(val[any].isMap()); + QCOMPARE(val[any].toMap().size(), 1); + QVERIFY(val[any][3].isMap()); + QCOMPARE(val[any][3].toMap().size(), 1); } void tst_QCborValue::arrayPrepend() -- cgit v1.2.3 From e7998dc187cf8f1218711ac963c441afbea1577c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 27 Oct 2018 19:43:09 -0700 Subject: QCborStreamReader: make sure setDevice() clears the last error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unit tests weren't running into this problem because the every setDevice() was preceded by the object being initialized with the exact same data, so there was never a previous error state. I've only changed a couple of tests, left the other setDevice() unchanged so we test both behaviors. Fixes: QTBUG-71426 Change-Id: I1bd327aeaf73421a8ec5fffd1561a590e3933376 Reviewed-by: Nils Jeisecke Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Edward Welbourne --- .../corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp b/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp index 24d9c7409e..3dd4b5114c 100644 --- a/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp +++ b/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp @@ -269,7 +269,7 @@ void tst_QCborStreamReader::integers() quint64 absolute = (isNegative ? expectedRaw + 1 : expectedRaw); QBuffer buffer(&data); - QCborStreamReader reader(data); + QCborStreamReader reader(useDevice ? QByteArray() : data); if (useDevice) { buffer.open(QIODevice::ReadOnly); reader.setDevice(&buffer); @@ -605,7 +605,7 @@ void tst_QCborStreamReader::fixed() removeIndicators(expected); QBuffer buffer(&data); - QCborStreamReader reader(data); + QCborStreamReader reader(useDevice ? QByteArray() : data); if (useDevice) { buffer.open(QIODevice::ReadOnly); reader.setDevice(&buffer); -- cgit v1.2.3 From 71bd06d516a2410ae0ea698e79dcb94aba9bc5b4 Mon Sep 17 00:00:00 2001 From: Sami Nurmenniemi Date: Wed, 13 Jun 2018 16:35:40 +0300 Subject: Make developer build tests pass for boot2qt Some tests were fixed and others were skipped/blacklisted. Task-number: QTBUG-63152 Change-Id: Ica7df555f8d152ee589865911130525101d4b941 Reviewed-by: Liang Qi --- tests/auto/corelib/serialization/qtextstream/test/test.pro | 2 ++ tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qtextstream/test/test.pro b/tests/auto/corelib/serialization/qtextstream/test/test.pro index 3dcfa0b414..0f289a5ce1 100644 --- a/tests/auto/corelib/serialization/qtextstream/test/test.pro +++ b/tests/auto/corelib/serialization/qtextstream/test/test.pro @@ -3,6 +3,8 @@ TARGET = ../tst_qtextstream QT = core network testlib SOURCES = ../tst_qtextstream.cpp RESOURCES += ../qtextstream.qrc +INCLUDEPATH += ../../../../../shared/ +HEADERS += ../../../../../shared/emulationdetector.h win32 { CONFIG(debug, debug|release) { diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index df8746e518..77675b8e44 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -44,7 +44,7 @@ # include #endif #include "../../../network-settings.h" - +#include "emulationdetector.h" QT_BEGIN_NAMESPACE template<> struct QMetaTypeId @@ -1459,6 +1459,9 @@ void tst_QTextStream::pos2() // ------------------------------------------------------------------------------ void tst_QTextStream::pos3LargeFile() { + if (EmulationDetector::isRunningArmOnX86()) + QSKIP("Running QTextStream::pos() in tight loop is too slow on emulator"); + { QFile file(testFileName); file.open(QIODevice::WriteOnly | QIODevice::Text); -- cgit v1.2.3 From 8fe36801930872ef4a57e2ff7d7f935de12a33e9 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 1 Feb 2019 15:16:00 +0100 Subject: Add cmdline feature to qmake [ChangeLog][qmake] A new feature "cmdline" was added that implies "CONFIG += console" and "CONFIG -= app_bundle". Task-number: QTBUG-27079 Change-Id: I6e52b07c9341c904bb1424fc717057432f9360e1 Reviewed-by: Oswald Buddenhagen --- .../qtextstream/readAllStdinProcess/readAllStdinProcess.pro | 3 +-- .../qtextstream/readLineStdinProcess/readLineStdinProcess.pro | 3 +-- .../corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/readAllStdinProcess.pro b/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/readAllStdinProcess.pro index 4a4c091dcb..f2b5aa619f 100644 --- a/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/readAllStdinProcess.pro +++ b/tests/auto/corelib/serialization/qtextstream/readAllStdinProcess/readAllStdinProcess.pro @@ -1,7 +1,6 @@ SOURCES += main.cpp QT = core -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline DESTDIR = ./ # This app is testdata for tst_qtextstream diff --git a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/readLineStdinProcess.pro b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/readLineStdinProcess.pro index 4a4c091dcb..f2b5aa619f 100644 --- a/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/readLineStdinProcess.pro +++ b/tests/auto/corelib/serialization/qtextstream/readLineStdinProcess/readLineStdinProcess.pro @@ -1,7 +1,6 @@ SOURCES += main.cpp QT = core -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline DESTDIR = ./ # This app is testdata for tst_qtextstream diff --git a/tests/auto/corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro b/tests/auto/corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro index 4a4c091dcb..f2b5aa619f 100644 --- a/tests/auto/corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro +++ b/tests/auto/corelib/serialization/qtextstream/stdinProcess/stdinProcess.pro @@ -1,7 +1,6 @@ SOURCES += main.cpp QT = core -CONFIG += console -CONFIG -= app_bundle +CONFIG += cmdline DESTDIR = ./ # This app is testdata for tst_qtextstream -- cgit v1.2.3 From 85a9009f258e130a7bd4aaaa252724ea5fb58e79 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 15 Mar 2019 11:01:31 +0100 Subject: QPixmap: More safe failing if qApp is not a QGuiApplication It can happen that QDataStream is fed a QVariant that contains a QPixmap representation, that will make the application crash when trying to restore it This is specially important for cases in which applications expose dbus interfaces with QVariantMaps Change-Id: Ife4feaef30f30e7e27d88464bd6b2a247f743123 Reported-by: Fabian Vogt Reviewed-by: Fabian Vogt Reviewed-by: Mitch Curtis Reviewed-by: Thiago Macieira --- .../qdatastream_core_pixmap.pro | 4 ++ .../tst_qdatastream_core_pixmap.cpp | 68 ++++++++++++++++++++++ tests/auto/corelib/serialization/serialization.pro | 1 + 3 files changed, 73 insertions(+) create mode 100644 tests/auto/corelib/serialization/qdatastream_core_pixmap/qdatastream_core_pixmap.pro create mode 100644 tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qdatastream_core_pixmap/qdatastream_core_pixmap.pro b/tests/auto/corelib/serialization/qdatastream_core_pixmap/qdatastream_core_pixmap.pro new file mode 100644 index 0000000000..7e003304af --- /dev/null +++ b/tests/auto/corelib/serialization/qdatastream_core_pixmap/qdatastream_core_pixmap.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qdatastream_core_pixmap +QT += testlib +SOURCES = tst_qdatastream_core_pixmap.cpp diff --git a/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp b/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp new file mode 100644 index 0000000000..c931016a61 --- /dev/null +++ b/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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 +#include +#include +#include +#include +#include +#include +#include + +class tst_QDataStream : public QObject +{ +Q_OBJECT + +private slots: + void stream_with_pixmap(); + +}; + +void tst_QDataStream::stream_with_pixmap() +{ + // This is a QVariantMap with a 3x3 red QPixmap and two strings inside + const QByteArray ba = QByteArray::fromBase64("AAAAAwAAAAIAegAAAAoAAAAACgB0AGgAZQByAGUAAAACAHAAAABBAAAAAAGJUE5HDQoaCgAAAA1JSERSAAAAAwAAAAMIAgAAANlKIugAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAQSURBVAiZY/zPAAVMDJgsAB1bAQXZn5ieAAAAAElFTkSuQmCCAAAAAgBhAAAACgAAAAAKAGgAZQBsAGwAbw=="); + QImage dummy; // Needed to make sure qtGui is loaded + + QTest::ignoreMessage(QtWarningMsg, "QPixmap::fromImageInPlace: QPixmap cannot be created without a QGuiApplication"); + + QVariantMap map; + QDataStream d(ba); + d.setVersion(QDataStream::Qt_5_12); + d >> map; + + QCOMPARE(map["a"].toString(), QString("hello")); + QCOMPARE(map["p"].value(), QPixmap()); // the pixmap is null because this is not a QGuiApplication + QCOMPARE(map["z"].toString(), QString("there")); +} + +QTEST_GUILESS_MAIN(tst_QDataStream) + +#include "tst_qdatastream_core_pixmap.moc" + diff --git a/tests/auto/corelib/serialization/serialization.pro b/tests/auto/corelib/serialization/serialization.pro index 9187de1bc5..9638178cdc 100644 --- a/tests/auto/corelib/serialization/serialization.pro +++ b/tests/auto/corelib/serialization/serialization.pro @@ -6,6 +6,7 @@ SUBDIRS = \ qcborvalue \ qcborvalue_json \ qdatastream \ + qdatastream_core_pixmap \ qtextstream \ qxmlstream -- cgit v1.2.3 From 461e89ee1a53f7669e0215f9015380c4a9d62371 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 24 Oct 2018 16:49:45 +0200 Subject: Clean up QTextStream functions They are the only Qt symbols neither prefixed with q or with the Qt namespace. This changes preserves source and binary compatibility while making it possible to define conflicting symbols. Change-Id: I6d4181206e63faa922fa0c8b644e0a4b88826a97 Reviewed-by: Ulf Hermann --- .../serialization/qtextstream/tst_qtextstream.cpp | 97 +++++++++++----------- 1 file changed, 50 insertions(+), 47 deletions(-) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 8bb35554c8..af97d4a003 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -1102,7 +1102,7 @@ void tst_QTextStream::hexTest() QByteArray array; QTextStream stream(&array); - stream << showbase << hex << number; + stream << Qt::showbase << Qt::hex << number; stream.flush(); QCOMPARE(array, data); } @@ -1132,7 +1132,7 @@ void tst_QTextStream::binTest() QByteArray array; QTextStream stream(&array); - stream << showbase << bin << number; + stream << Qt::showbase << Qt::bin << number; stream.flush(); QCOMPARE(array.constData(), data.constData()); } @@ -1155,7 +1155,7 @@ void tst_QTextStream::octTest() QByteArray array; QTextStream stream(&array); - stream << showbase << oct << number; + stream << Qt::showbase << Qt::oct << number; stream.flush(); QCOMPARE(array, data); } @@ -1196,7 +1196,7 @@ void tst_QTextStream::ws_manipulator() QTextStream stream(&string); char a, b, c, d; - stream >> a >> ws >> b >> ws >> c >> ws >> d; + stream >> a >> Qt::ws >> b >> Qt::ws >> c >> Qt::ws >> d; QCOMPARE(a, 'a'); QCOMPARE(b, 'b'); QCOMPARE(c, 'c'); @@ -1623,18 +1623,18 @@ void tst_QTextStream::forcePoint() { QString str; QTextStream stream(&str); - stream << fixed << forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; + stream << Qt::fixed << Qt::forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; QCOMPARE(str, QString("1.000000 1 0 -1.000000 -1")); str.clear(); stream.seek(0); - stream << scientific << forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; + stream << Qt::scientific << Qt::forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; QCOMPARE(str, QString("1.000000e+00 1 0 -1.000000e+00 -1")); str.clear(); stream.seek(0); stream.setRealNumberNotation(QTextStream::SmartNotation); - stream << forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; + stream << Qt::forcepoint << 1.0 << ' ' << 1 << ' ' << 0 << ' ' << -1.0 << ' ' << -1; QCOMPARE(str, QString("1.00000 1 0 -1.00000 -1")); } @@ -1644,7 +1644,7 @@ void tst_QTextStream::forceSign() { QString str; QTextStream stream(&str); - stream << forcesign << 1.2 << ' ' << -1.2 << ' ' << 0; + stream << Qt::forcesign << 1.2 << ' ' << -1.2 << ' ' << 0; QCOMPARE(str, QString("+1.2 -1.2 +0")); } @@ -1663,19 +1663,22 @@ void tst_QTextStream::read0d0d0a() Q_DECLARE_METATYPE(QTextStreamFunction); +// Also tests that we can have namespaces that conflict with our QTextStream constants. +namespace ws { QTextStream &noop(QTextStream &s) { return s; } +} void tst_QTextStream::numeralCase_data() { - QTextStreamFunction noop_ = noop; - QTextStreamFunction bin_ = bin; - QTextStreamFunction oct_ = oct; - QTextStreamFunction hex_ = hex; - QTextStreamFunction base = showbase; - QTextStreamFunction ucb = uppercasebase; - QTextStreamFunction lcb = lowercasebase; - QTextStreamFunction ucd = uppercasedigits; - QTextStreamFunction lcd = lowercasedigits; + QTextStreamFunction noop_ = ws::noop; + QTextStreamFunction bin = Qt::bin; + QTextStreamFunction oct = Qt::oct; + QTextStreamFunction hex = Qt::hex; + QTextStreamFunction base = Qt::showbase; + QTextStreamFunction ucb = Qt::uppercasebase; + QTextStreamFunction lcb = Qt::lowercasebase; + QTextStreamFunction ucd = Qt::uppercasedigits; + QTextStreamFunction lcd = Qt::lowercasedigits; QTest::addColumn("func1"); QTest::addColumn("func2"); @@ -1686,30 +1689,30 @@ void tst_QTextStream::numeralCase_data() QTest::newRow("dec 1") << noop_ << noop_ << noop_ << noop_ << 31 << "31"; QTest::newRow("dec 2") << noop_ << base << noop_ << noop_ << 31 << "31"; - QTest::newRow("hex 1") << hex_ << noop_ << noop_ << noop_ << 31 << "1f"; - QTest::newRow("hex 2") << hex_ << noop_ << noop_ << lcd << 31 << "1f"; - QTest::newRow("hex 3") << hex_ << noop_ << ucb << noop_ << 31 << "1f"; - QTest::newRow("hex 4") << hex_ << noop_ << noop_ << ucd << 31 << "1F"; - QTest::newRow("hex 5") << hex_ << noop_ << lcb << ucd << 31 << "1F"; - QTest::newRow("hex 6") << hex_ << noop_ << ucb << ucd << 31 << "1F"; - QTest::newRow("hex 7") << hex_ << base << noop_ << noop_ << 31 << "0x1f"; - QTest::newRow("hex 8") << hex_ << base << lcb << lcd << 31 << "0x1f"; - QTest::newRow("hex 9") << hex_ << base << ucb << noop_ << 31 << "0X1f"; - QTest::newRow("hex 10") << hex_ << base << ucb << lcd << 31 << "0X1f"; - QTest::newRow("hex 11") << hex_ << base << noop_ << ucd << 31 << "0x1F"; - QTest::newRow("hex 12") << hex_ << base << lcb << ucd << 31 << "0x1F"; - QTest::newRow("hex 13") << hex_ << base << ucb << ucd << 31 << "0X1F"; - - QTest::newRow("bin 1") << bin_ << noop_ << noop_ << noop_ << 31 << "11111"; - QTest::newRow("bin 2") << bin_ << base << noop_ << noop_ << 31 << "0b11111"; - QTest::newRow("bin 3") << bin_ << base << lcb << noop_ << 31 << "0b11111"; - QTest::newRow("bin 4") << bin_ << base << ucb << noop_ << 31 << "0B11111"; - QTest::newRow("bin 5") << bin_ << base << noop_ << ucd << 31 << "0b11111"; - QTest::newRow("bin 6") << bin_ << base << lcb << ucd << 31 << "0b11111"; - QTest::newRow("bin 7") << bin_ << base << ucb << ucd << 31 << "0B11111"; - - QTest::newRow("oct 1") << oct_ << noop_ << noop_ << noop_ << 31 << "37"; - QTest::newRow("oct 2") << oct_ << base << noop_ << noop_ << 31 << "037"; + QTest::newRow("hex 1") << hex << noop_ << noop_ << noop_ << 31 << "1f"; + QTest::newRow("hex 2") << hex << noop_ << noop_ << lcd << 31 << "1f"; + QTest::newRow("hex 3") << hex << noop_ << ucb << noop_ << 31 << "1f"; + QTest::newRow("hex 4") << hex << noop_ << noop_ << ucd << 31 << "1F"; + QTest::newRow("hex 5") << hex << noop_ << lcb << ucd << 31 << "1F"; + QTest::newRow("hex 6") << hex << noop_ << ucb << ucd << 31 << "1F"; + QTest::newRow("hex 7") << hex << base << noop_ << noop_ << 31 << "0x1f"; + QTest::newRow("hex 8") << hex << base << lcb << lcd << 31 << "0x1f"; + QTest::newRow("hex 9") << hex << base << ucb << noop_ << 31 << "0X1f"; + QTest::newRow("hex 10") << hex << base << ucb << lcd << 31 << "0X1f"; + QTest::newRow("hex 11") << hex << base << noop_ << ucd << 31 << "0x1F"; + QTest::newRow("hex 12") << hex << base << lcb << ucd << 31 << "0x1F"; + QTest::newRow("hex 13") << hex << base << ucb << ucd << 31 << "0X1F"; + + QTest::newRow("bin 1") << bin << noop_ << noop_ << noop_ << 31 << "11111"; + QTest::newRow("bin 2") << bin << base << noop_ << noop_ << 31 << "0b11111"; + QTest::newRow("bin 3") << bin << base << lcb << noop_ << 31 << "0b11111"; + QTest::newRow("bin 4") << bin << base << ucb << noop_ << 31 << "0B11111"; + QTest::newRow("bin 5") << bin << base << noop_ << ucd << 31 << "0b11111"; + QTest::newRow("bin 6") << bin << base << lcb << ucd << 31 << "0b11111"; + QTest::newRow("bin 7") << bin << base << ucb << ucd << 31 << "0B11111"; + + QTest::newRow("oct 1") << oct << noop_ << noop_ << noop_ << 31 << "37"; + QTest::newRow("oct 2") << oct << base << noop_ << noop_ << 31 << "037"; } void tst_QTextStream::numeralCase() @@ -1782,9 +1785,9 @@ void tst_QTextStream::nanInf() QString s; QTextStream out(&s); out << qInf() << ' ' << -qInf() << ' ' << qQNaN() - << uppercasedigits << ' ' + << Qt::uppercasedigits << ' ' << qInf() << ' ' << -qInf() << ' ' << qQNaN() - << flush; + << Qt::flush; QCOMPARE(s, QString("inf -inf nan INF -INF NAN")); } @@ -1859,9 +1862,9 @@ void tst_QTextStream::writeSeekWriteNoBOM() int number = 0; QString sizeStr = QLatin1String("Size=") + QString::number(number).rightJustified(10, QLatin1Char('0')); - stream << sizeStr << endl; - stream << "Version=" << QString::number(14) << endl; - stream << "blah blah blah" << endl; + stream << sizeStr << Qt::endl; + stream << "Version=" << QString::number(14) << Qt::endl; + stream << "blah blah blah" << Qt::endl; stream.flush(); QCOMPARE(out.buffer().constData(), "Size=0000000000\nVersion=14\nblah blah blah\n"); @@ -1871,7 +1874,7 @@ void tst_QTextStream::writeSeekWriteNoBOM() stream.seek(0); sizeStr = QLatin1String("Size=") + QString::number(number).rightJustified(10, QLatin1Char('0')); - stream << sizeStr << endl; + stream << sizeStr << Qt::endl; stream.flush(); // Check buffer is still OK -- cgit v1.2.3 From 6b66108c1ffc48ee1dc06c4e25d9210bf2d41084 Mon Sep 17 00:00:00 2001 From: Paolo Dastoli Date: Sat, 16 Feb 2019 15:23:31 +0100 Subject: Add serializer/deserializer for Enumeration Enum class are serialized using the declared size. [ChangeLog][QtCore][QDataStream] Enumerations can now be serialized through QDataStream without the need of manually defining streaming operators. Change-Id: Iae9a63eb62b5a5615b657766a3c4c66ba4d98d0e Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Paolo Dastoli Reviewed-by: Thiago Macieira --- .../serialization/qdatastream/tst_qdatastream.cpp | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index d204727bbd..19cdd42a74 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -181,6 +181,8 @@ private slots: void streamRealDataTypes(); + void enumTest(); + void floatingPointPrecision(); void compatibility_Qt3(); @@ -3409,6 +3411,90 @@ void tst_QDataStream::floatingPointNaN() } } +void tst_QDataStream::enumTest() +{ + QByteArray ba; + + enum class E1 : qint8 + { + A, + B, + C + }; + { + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << E1::A; + QCOMPARE(ba.size(), int(sizeof(E1))); + } + { + QDataStream stream(ba); + E1 e; + stream >> e; + QCOMPARE(e, E1::A); + } + ba.clear(); + + enum class E2 : qint16 + { + A, + B, + C + }; + { + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << E2::B; + QCOMPARE(ba.size(), int(sizeof(E2))); + } + { + QDataStream stream(ba); + E2 e; + stream >> e; + QCOMPARE(e, E2::B); + } + ba.clear(); + + enum class E4 : qint32 + { + A, + B, + C + }; + { + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << E4::C; + QCOMPARE(ba.size(), int(sizeof(E4))); + } + { + QDataStream stream(ba); + E4 e; + stream >> e; + QCOMPARE(e, E4::C); + } + ba.clear(); + + + enum E + { + A, + B, + C, + D + }; + { + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << E::D; + QCOMPARE(ba.size(), 4); + } + { + QDataStream stream(ba); + E e; + stream >> e; + QCOMPARE(e, E::D); + } + ba.clear(); + +} + void tst_QDataStream::floatingPointPrecision() { QByteArray ba; -- cgit v1.2.3 From 95f787bfdc890c259e8b347bdad9123d534efe0f Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 9 Apr 2019 13:33:15 +0200 Subject: Replace Q_DECL_NOTHROW with noexcept the remaining places The first replacement had missed objective-C++ code some places ourside the src dir. In C-files Q_DECL_NOTHROW is replaced with Q_DECL_NOEXCEPT as we still need to turn it off when compiled in C mode, but can get rid of the old NOTHROW moniker. Change-Id: I6370f57066679c5120d0265a69e7e378e09d4759 Reviewed-by: Thiago Macieira --- tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/corelib/serialization') diff --git a/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp index 8fdf91b090..e4d50607b7 100644 --- a/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp @@ -253,7 +253,7 @@ public: qFatal("%s: aId must not be an empty string", Q_FUNC_INFO); } - void swap(MissedBaseline &other) Q_DECL_NOTHROW + void swap(MissedBaseline &other) noexcept { qSwap(id, other.id); qSwap(expected, other.expected); -- cgit v1.2.3