summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-05-22 09:53:39 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-23 22:00:46 +0200
commit7878eb6ba30a8b84199f3c8fba4cac739e8a788a (patch)
treecc09c8f30e666794794e3499b341717833d9a334 /tests
parentd2ec7e05eb26a7b877eef1d78f2b7acbfb20336e (diff)
Fix parsing of long latin strings in the json parser
Latin1 strings are usually stored as 8 bit data in the json binary format. But that data structure has a size limitation of 16bit, so we need to fall back to storing the string as 16 bit data if it is too long. Task-number: QTBUG-30946 Change-Id: I0069b1367030b0b2f819fd1f04e34c9e2534a2a3 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index fc4b3831c4..c19a42e4a6 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -128,6 +128,8 @@ private Q_SLOTS:
void bom();
void nesting();
+
+ void longStrings();
private:
QString testDataDir;
};
@@ -2118,5 +2120,48 @@ void tst_QtJson::nesting()
}
+void tst_QtJson::longStrings()
+{
+ // test around 15 and 16 bit boundaries, as these are limits
+ // in the data structures (for Latin1String in qjson_p.h)
+ QString s(0x7ff0, 'a');
+ for (int i = 0x7ff0; i < 0x8010; i++) {
+ s.append("c");
+
+ QMap <QString, QVariant> map;
+ map["key"] = s;
+
+ /* Create a QJsonDocument from the QMap ... */
+ QJsonDocument d1 = QJsonDocument::fromVariant(QVariant(map));
+ /* ... and a QByteArray from the QJsonDocument */
+ QByteArray a1 = d1.toJson();
+
+ /* Create a QJsonDocument from the QByteArray ... */
+ QJsonDocument d2 = QJsonDocument::fromJson(a1);
+ /* ... and a QByteArray from the QJsonDocument */
+ QByteArray a2 = d2.toJson();
+ QVERIFY(a1 == a2);
+ }
+
+ s = QString(0xfff0, 'a');
+ for (int i = 0xfff0; i < 0x10010; i++) {
+ s.append("c");
+
+ QMap <QString, QVariant> map;
+ map["key"] = s;
+
+ /* Create a QJsonDocument from the QMap ... */
+ QJsonDocument d1 = QJsonDocument::fromVariant(QVariant(map));
+ /* ... and a QByteArray from the QJsonDocument */
+ QByteArray a1 = d1.toJson();
+
+ /* Create a QJsonDocument from the QByteArray ... */
+ QJsonDocument d2 = QJsonDocument::fromJson(a1);
+ /* ... and a QByteArray from the QJsonDocument */
+ QByteArray a2 = d2.toJson();
+ QVERIFY(a1 == a2);
+ }
+}
+
QTEST_MAIN(tst_QtJson)
#include "tst_qtjson.moc"