summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2016-06-17 15:07:26 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2016-07-20 06:52:43 +0000
commit902a5e7aaa0ec156d19b5a7988eff1809a6a2046 (patch)
tree6fb8b610878f92bab90a430dac95a3be9805a06f /tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
parent9467bdc9093d9b02e249c6cce508b9df3ff8b2f4 (diff)
QDataStream: adjust containers' deserialization in transaction mode
If an error occurs during the transaction, we should prevent the containers from being successfully read. So, check the status of the stream before reading the container, because the deserialization procedure temporarily resets it on entry. Task-number: QTBUG-54022 Change-Id: Ie955c2fa3e449374f0f8403f00e487efa2bfdaf3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp')
-rw-r--r--tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp144
1 files changed, 91 insertions, 53 deletions
diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
index b7e7344b16..447cf2845e 100644
--- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
+++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
@@ -2750,27 +2750,43 @@ void tst_QDataStream::status_QBitArray()
}
#define MAP_TEST(byteArray, initialStatus, expectedStatus, expectedHash) \
- { \
- QByteArray ba = byteArray; \
- QDataStream stream(&ba, QIODevice::ReadOnly); \
- stream.setStatus(initialStatus); \
- stream >> hash; \
- QCOMPARE((int)stream.status(), (int)expectedStatus); \
- QCOMPARE(hash.size(), expectedHash.size()); \
- QCOMPARE(hash, expectedHash); \
- } \
- { \
- QByteArray ba = byteArray; \
- StringMap expectedMap; \
- StringHash::const_iterator it = expectedHash.constBegin(); \
- for (; it != expectedHash.constEnd(); ++it) \
- expectedMap.insert(it.key(), it.value()); \
- QDataStream stream(&ba, QIODevice::ReadOnly); \
- stream.setStatus(initialStatus); \
- stream >> map; \
- QCOMPARE((int)stream.status(), (int)expectedStatus); \
- QCOMPARE(map.size(), expectedMap.size()); \
- QCOMPARE(map, expectedMap); \
+ for (bool inTransaction = false;; inTransaction = true) { \
+ { \
+ QByteArray ba = byteArray; \
+ QDataStream stream(&ba, QIODevice::ReadOnly); \
+ if (inTransaction) \
+ stream.startTransaction(); \
+ stream.setStatus(initialStatus); \
+ stream >> hash; \
+ QCOMPARE((int)stream.status(), (int)expectedStatus); \
+ if (!inTransaction || stream.commitTransaction()) { \
+ QCOMPARE(hash.size(), expectedHash.size()); \
+ QCOMPARE(hash, expectedHash); \
+ } else { \
+ QVERIFY(hash.isEmpty()); \
+ } \
+ } \
+ { \
+ QByteArray ba = byteArray; \
+ StringMap expectedMap; \
+ StringHash::const_iterator it = expectedHash.constBegin(); \
+ for (; it != expectedHash.constEnd(); ++it) \
+ expectedMap.insert(it.key(), it.value()); \
+ QDataStream stream(&ba, QIODevice::ReadOnly); \
+ if (inTransaction) \
+ stream.startTransaction(); \
+ stream.setStatus(initialStatus); \
+ stream >> map; \
+ QCOMPARE((int)stream.status(), (int)expectedStatus); \
+ if (!inTransaction || stream.commitTransaction()) { \
+ QCOMPARE(map.size(), expectedMap.size()); \
+ QCOMPARE(map, expectedMap); \
+ } else { \
+ QVERIFY(map.isEmpty()); \
+ } \
+ } \
+ if (inTransaction) \
+ break; \
}
void tst_QDataStream::status_QHash_QMap()
@@ -2815,38 +2831,60 @@ void tst_QDataStream::status_QHash_QMap()
}
#define LIST_TEST(byteArray, initialStatus, expectedStatus, expectedList) \
- { \
- QByteArray ba = byteArray; \
- QDataStream stream(&ba, QIODevice::ReadOnly); \
- stream.setStatus(initialStatus); \
- stream >> list; \
- QCOMPARE((int)stream.status(), (int)expectedStatus); \
- QCOMPARE(list.size(), expectedList.size()); \
- QCOMPARE(list, expectedList); \
- } \
- { \
- LinkedList expectedLinkedList; \
- for (int i = 0; i < expectedList.count(); ++i) \
- expectedLinkedList << expectedList.at(i); \
- QByteArray ba = byteArray; \
- QDataStream stream(&ba, QIODevice::ReadOnly); \
- stream.setStatus(initialStatus); \
- stream >> linkedList; \
- QCOMPARE((int)stream.status(), (int)expectedStatus); \
- QCOMPARE(linkedList.size(), expectedLinkedList.size()); \
- QCOMPARE(linkedList, expectedLinkedList); \
- } \
- { \
- Vector expectedVector; \
- for (int i = 0; i < expectedList.count(); ++i) \
- expectedVector << expectedList.at(i); \
- QByteArray ba = byteArray; \
- QDataStream stream(&ba, QIODevice::ReadOnly); \
- stream.setStatus(initialStatus); \
- stream >> vector; \
- QCOMPARE((int)stream.status(), (int)expectedStatus); \
- QCOMPARE(vector.size(), expectedVector.size()); \
- QCOMPARE(vector, expectedVector); \
+ for (bool inTransaction = false;; inTransaction = true) { \
+ { \
+ QByteArray ba = byteArray; \
+ QDataStream stream(&ba, QIODevice::ReadOnly); \
+ if (inTransaction) \
+ stream.startTransaction(); \
+ stream.setStatus(initialStatus); \
+ stream >> list; \
+ QCOMPARE((int)stream.status(), (int)expectedStatus); \
+ if (!inTransaction || stream.commitTransaction()) { \
+ QCOMPARE(list.size(), expectedList.size()); \
+ QCOMPARE(list, expectedList); \
+ } else { \
+ QVERIFY(list.isEmpty()); \
+ } \
+ } \
+ { \
+ LinkedList expectedLinkedList; \
+ for (int i = 0; i < expectedList.count(); ++i) \
+ expectedLinkedList << expectedList.at(i); \
+ QByteArray ba = byteArray; \
+ QDataStream stream(&ba, QIODevice::ReadOnly); \
+ if (inTransaction) \
+ stream.startTransaction(); \
+ stream.setStatus(initialStatus); \
+ stream >> linkedList; \
+ QCOMPARE((int)stream.status(), (int)expectedStatus); \
+ if (!inTransaction || stream.commitTransaction()) { \
+ QCOMPARE(linkedList.size(), expectedLinkedList.size()); \
+ QCOMPARE(linkedList, expectedLinkedList); \
+ } else { \
+ QVERIFY(linkedList.isEmpty()); \
+ } \
+ } \
+ { \
+ Vector expectedVector; \
+ for (int i = 0; i < expectedList.count(); ++i) \
+ expectedVector << expectedList.at(i); \
+ QByteArray ba = byteArray; \
+ QDataStream stream(&ba, QIODevice::ReadOnly); \
+ if (inTransaction) \
+ stream.startTransaction(); \
+ stream.setStatus(initialStatus); \
+ stream >> vector; \
+ QCOMPARE((int)stream.status(), (int)expectedStatus); \
+ if (!inTransaction || stream.commitTransaction()) { \
+ QCOMPARE(vector.size(), expectedVector.size()); \
+ QCOMPARE(vector, expectedVector); \
+ } else { \
+ QVERIFY(vector.isEmpty()); \
+ } \
+ } \
+ if (inTransaction) \
+ break; \
}
void tst_QDataStream::status_QLinkedList_QList_QVector()