diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-03-04 15:21:40 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-03-06 09:50:35 +0100 |
commit | 249a2e3271c3cc36edb88c993d277d93de2cf1c0 (patch) | |
tree | 1ccbc0c79da459d8ada8a399129b92c3589f2b97 /tests/auto/corelib/serialization | |
parent | 1a9c29289a76454e8b361430dd7f025f8fdc3061 (diff) |
Disable warnings for the deprecated QLinkedList
QLinkedList has been deprecated, but we still need to test it. Suppress
the warnings for QLinkedList used in tests. Note, that I had to move
some of the test code, to avoid repeating
QT_WARNING_PUSH/QT_WARNING_POP everywhere.
Change-Id: I4203b3ef50045c4f45475a08638dbdc60f68761d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/corelib/serialization')
-rw-r--r-- | tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp | 87 |
1 files changed, 73 insertions, 14 deletions
diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index aed84cb14e..ff2e98e730 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -3064,39 +3064,45 @@ void tst_QDataStream::status_QHash_QMap() } \ } \ { \ - LinkedList expectedLinkedList; \ + Vector expectedVector; \ for (int i = 0; i < expectedList.count(); ++i) \ - expectedLinkedList << expectedList.at(i); \ + expectedVector << expectedList.at(i); \ QByteArray ba = byteArray; \ QDataStream stream(&ba, QIODevice::ReadOnly); \ if (inTransaction) \ stream.startTransaction(); \ stream.setStatus(initialStatus); \ - stream >> linkedList; \ + stream >> vector; \ QCOMPARE((int)stream.status(), (int)expectedStatus); \ if (!inTransaction || stream.commitTransaction()) { \ - QCOMPARE(linkedList.size(), expectedLinkedList.size()); \ - QCOMPARE(linkedList, expectedLinkedList); \ + QCOMPARE(vector.size(), expectedVector.size()); \ + QCOMPARE(vector, expectedVector); \ } else { \ - QVERIFY(linkedList.isEmpty()); \ + QVERIFY(vector.isEmpty()); \ } \ } \ + if (inTransaction) \ + break; \ + } + +#define LINKED_LIST_TEST(byteArray, initialStatus, expectedStatus, expectedList) \ + for (bool inTransaction = false;; inTransaction = true) { \ { \ - Vector expectedVector; \ + LinkedList expectedLinkedList; \ for (int i = 0; i < expectedList.count(); ++i) \ - expectedVector << expectedList.at(i); \ + expectedLinkedList << expectedList.at(i); \ QByteArray ba = byteArray; \ QDataStream stream(&ba, QIODevice::ReadOnly); \ if (inTransaction) \ stream.startTransaction(); \ stream.setStatus(initialStatus); \ - stream >> vector; \ + stream >> linkedList; \ QCOMPARE((int)stream.status(), (int)expectedStatus); \ if (!inTransaction || stream.commitTransaction()) { \ - QCOMPARE(vector.size(), expectedVector.size()); \ - QCOMPARE(vector, expectedVector); \ + QCOMPARE(linkedList.size(), expectedLinkedList.size()); \ + QCOMPARE(linkedList, expectedLinkedList); \ } else { \ - QVERIFY(vector.isEmpty()); \ + QVERIFY(linkedList.isEmpty()); \ } \ } \ if (inTransaction) \ @@ -3105,10 +3111,8 @@ void tst_QDataStream::status_QHash_QMap() void tst_QDataStream::status_QLinkedList_QList_QVector() { - typedef QLinkedList<QString> LinkedList; typedef QList<QString> List; typedef QVector<QString> Vector; - LinkedList linkedList; List list; Vector vector; @@ -3155,6 +3159,61 @@ void tst_QDataStream::status_QLinkedList_QList_QVector() LIST_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::ReadCorruptData, QDataStream::ReadCorruptData, List()); LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, List()); } + +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + // The same as above with QLinkedList + + typedef QLinkedList<QString> LinkedList; + LinkedList linkedList; + + // ok + { + List listWithEmptyString; + listWithEmptyString.append(""); + + List someList; + someList.append("J"); + someList.append("MN"); + + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x00", 4), QDataStream::Ok, QDataStream::Ok, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00", 8), QDataStream::Ok, QDataStream::Ok, listWithEmptyString); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x02\x00J" + "\x00\x00\x00\x04\x00M\x00N", 18), QDataStream::Ok, QDataStream::Ok, someList); + } + + // past end + { + LINKED_LIST_TEST(QByteArray(), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LINKED_LIST_TEST(QByteArray("\x00", 1), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00", 2), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00", 3), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + for (int i = 4; i < 12; ++i) { + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", i), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + } + } + + // corrupt data + { + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::Ok, QDataStream::ReadCorruptData, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x01\x00J" + "\x00\x00\x00\x02\x00M\x00N", 18), QDataStream::Ok, QDataStream::ReadCorruptData, List()); + } + + // test the previously latched error status is not affected by reading + { + List listWithEmptyString; + listWithEmptyString.append(""); + + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, listWithEmptyString); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::ReadCorruptData, QDataStream::ReadCorruptData, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, List()); + } + +QT_WARNING_POP +#endif } void tst_QDataStream::streamToAndFromQByteArray() |