summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/json
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-05-23 21:27:07 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-05-23 21:27:07 +0200
commitd3a8bc803cd7c4ce106038bfc4b37cdd6bb8e177 (patch)
tree3b6db0d4869f334d0eb4559c5ae457995cbe913e /tests/auto/corelib/json
parentd934ddc297f6db94dbc548fe01da64350f13577d (diff)
parent47a7628023610904c6ac52e23fa289f75f349b4e (diff)
Merge remote-tracking branch 'origin/stable' into dev
Conflicts: src/corelib/io/qdatastream.cpp src/corelib/io/qdatastream.h src/corelib/json/qjsonwriter.cpp src/plugins/platforms/cocoa/qcocoawindow.mm src/plugins/platforms/xcb/qxcbkeyboard.cpp Change-Id: I46fef1455f5a9f2ce1ec394a3c65881093c51b62
Diffstat (limited to 'tests/auto/corelib/json')
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp77
1 files changed, 65 insertions, 12 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index 543226978c..010c8acb5f 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -234,9 +234,54 @@ void tst_QtJson::testNumbers()
QJsonArray array;
for (int i = 0; i < n; ++i)
array.append((double)numbers[i]);
+
+ QByteArray serialized = QJsonDocument(array).toJson();
+ QJsonDocument json = QJsonDocument::fromJson(serialized);
+ QJsonArray array2 = json.array();
+
+ QCOMPARE(array.size(), array2.size());
+ for (int i = 0; i < array.size(); ++i) {
+ QCOMPARE(array.at(i).type(), QJsonValue::Double);
+ QCOMPARE(array.at(i).toDouble(), (double)numbers[i]);
+ QCOMPARE(array2.at(i).type(), QJsonValue::Double);
+ QCOMPARE(array2.at(i).toDouble(), (double)numbers[i]);
+ }
+ }
+
+ {
+ qint64 numbers[] = {
+ 0,
+ -1,
+ 1,
+ (1UL<<54),
+ (1UL<<55),
+ (1UL<<56),
+ -(1UL<<54),
+ -(1UL<<55),
+ -(1UL<<56),
+ (1UL<<54) - 1,
+ (1UL<<55) - 1,
+ (1UL<<56) - 1,
+ -((1UL<<54) - 1),
+ -((1UL<<55) - 1),
+ -((1UL<<56) - 1)
+ };
+ int n = sizeof(numbers)/sizeof(qint64);
+
+ QJsonArray array;
+ for (int i = 0; i < n; ++i)
+ array.append((double)numbers[i]);
+
+ QByteArray serialized = QJsonDocument(array).toJson();
+ QJsonDocument json = QJsonDocument::fromJson(serialized);
+ QJsonArray array2 = json.array();
+
+ QCOMPARE(array.size(), array2.size());
for (int i = 0; i < array.size(); ++i) {
QCOMPARE(array.at(i).type(), QJsonValue::Double);
QCOMPARE(array.at(i).toDouble(), (double)numbers[i]);
+ QCOMPARE(array2.at(i).type(), QJsonValue::Double);
+ QCOMPARE(array2.at(i).toDouble(), (double)numbers[i]);
}
}
@@ -245,18 +290,18 @@ void tst_QtJson::testNumbers()
0,
-1,
1,
- (1<<26),
- (1<<27),
- (1<<28),
- -(1<<26),
- -(1<<27),
- -(1<<28),
- (1<<26) - 1,
- (1<<27) - 1,
- (1<<28) - 1,
- -((1<<26) - 1),
- -((1<<27) - 1),
- -((1<<28) - 1),
+ (1UL<<54),
+ (1UL<<55),
+ (1UL<<56),
+ -(1UL<<54),
+ -(1UL<<55),
+ -(1UL<<56),
+ (1UL<<54) - 1,
+ (1UL<<55) - 1,
+ (1UL<<56) - 1,
+ -((1UL<<54) - 1),
+ -((1UL<<55) - 1),
+ -((1UL<<56) - 1),
1.1,
0.1,
-0.1,
@@ -269,9 +314,17 @@ void tst_QtJson::testNumbers()
QJsonArray array;
for (int i = 0; i < n; ++i)
array.append(numbers[i]);
+
+ QByteArray serialized = QJsonDocument(array).toJson();
+ QJsonDocument json = QJsonDocument::fromJson(serialized);
+ QJsonArray array2 = json.array();
+
+ QCOMPARE(array.size(), array2.size());
for (int i = 0; i < array.size(); ++i) {
QCOMPARE(array.at(i).type(), QJsonValue::Double);
QCOMPARE(array.at(i).toDouble(), numbers[i]);
+ QCOMPARE(array2.at(i).type(), QJsonValue::Double);
+ QCOMPARE(array2.at(i).toDouble(), numbers[i]);
}
}