summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/json/tst_qtjson.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/json/tst_qtjson.cpp')
-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]);
}
}