diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-01-17 14:40:32 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-02-03 17:43:30 +0100 |
commit | 4681f1fc2cfabb64b6b4f1095e2d4f44d0cee903 (patch) | |
tree | 90949be2aba621bd0b4a337d83aa7d1f349094e1 /tests | |
parent | 10afe69c16e641909901159bfad5b233d641151a (diff) |
Separate streaming of QHash and QMultiHash/QMap and QMultiMap
Those classes will not have relations anymore in Qt6, so they need
separate streaming operators. Writing of multi maps/hashes requires some
additional care so that restoring keeps the order of how iteme have been
inserted.
Change-Id: If41d0c5c24962764a2cb81bd2de9e2fadf1a2b63
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index 877de3f95d..d1a77173c3 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -121,6 +121,9 @@ private slots: void stream_Map_data(); void stream_Map(); + void stream_MultiMap_data(); + void stream_MultiMap(); + void stream_Hash_data(); void stream_Hash(); @@ -233,6 +236,7 @@ private: void writeQRegularExpression(QDataStream *dev); #endif void writeMap(QDataStream* dev); + void writeMultiMap(QDataStream* dev); void writeHash(QDataStream* dev); void writeMultiHash(QDataStream* dev); void writeqint64(QDataStream *s); @@ -266,6 +270,7 @@ private: void readQRegularExpression(QDataStream *s); #endif void readMap(QDataStream *s); + void readMultiMap(QDataStream *s); void readHash(QDataStream *s); void readMultiHash(QDataStream *s); void readqint64(QDataStream *s); @@ -655,16 +660,10 @@ static Map MapData(int index) map.insert(2, "bbb"); map.insert(3, "cccccc"); break; - case 2: - map.insert(1, "a"); - map.insert(2, "one"); - map.insertMulti(2, "two"); - map.insertMulti(2, "three"); - map.insert(3, "cccccc"); } return map; } -#define MAX_MAP_DATA 3 +#define MAX_MAP_DATA 2 void tst_QDataStream::stream_Map_data() { @@ -694,6 +693,60 @@ void tst_QDataStream::readMap(QDataStream *s) QCOMPARE(S, test); } +typedef QMultiMap<int, QString> MultiMap; + +static MultiMap MultiMapData(int index) +{ + MultiMap map; + + switch (index) { + case 0: + default: + break; + case 1: + map.insert(1, "a"); + map.insert(2, "bbb"); + map.insert(3, "cccccc"); + break; + case 2: + map.insert(1, "a"); + map.insert(2, "one"); + map.insert(2, "two"); + map.insert(2, "three"); + map.insert(3, "cccccc"); + } + return map; +} +#define MAX_MULTIMAP_DATA 3 + +void tst_QDataStream::stream_MultiMap_data() +{ + stream_data(MAX_MULTIMAP_DATA); +} + +void tst_QDataStream::stream_MultiMap() +{ + STREAM_IMPL(MultiMap); +} + +void tst_QDataStream::writeMultiMap(QDataStream* s) +{ + MultiMap test(MultiMapData(dataIndex(QTest::currentDataTag()))); + *s << test; + *s << test; +} + +void tst_QDataStream::readMultiMap(QDataStream *s) +{ + MultiMap S; + MultiMap test(MultiMapData(dataIndex(QTest::currentDataTag()))); + + *s >> S; + QCOMPARE(S, test); + *s >> S; + QCOMPARE(S, test); +} + // ************************************ typedef QHash<int, QString> Hash; |