summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlexei Rousskikh <ext-alexei.rousskikh@nokia.com>2012-02-27 17:02:10 -0500
committerAndrew Christian <andrew.christian@nokia.com>2012-02-28 11:54:52 +0100
commit5d54f9ea2bcf97be6990cae0245b046ffe3bcb0f (patch)
treec26582206d3b8f83329a59d4d96fb762716b41fe /tests
parent77263148f5dc5460329577aac1a9aa26f2521ed3 (diff)
implemented array in 'items' attribute; 'additionalItems' attribute
Change-Id: Id6e040041253907f1e19f4bfa6c6b4d75dd4d3a4 Reviewed-by: Andrew Christian <andrew.christian@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/jsonschema/tst_jsonschema.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/tests/auto/jsonschema/tst_jsonschema.cpp b/tests/auto/jsonschema/tst_jsonschema.cpp
index c11e001..522fb00 100644
--- a/tests/auto/jsonschema/tst_jsonschema.cpp
+++ b/tests/auto/jsonschema/tst_jsonschema.cpp
@@ -60,7 +60,8 @@ private slots:
void testAdditionalPropertiesValidation();
// 5.5 items
void testItemsValidation();
- // TODO: 5.6 additionalItems
+ // 5.6 additionalItems
+ void testAdditionalItems();
// 5.7
void testRequiredValidation();
// TODO: 5.8 dependencies
@@ -228,17 +229,17 @@ void tst_JsonSchema::testAdditionalPropertiesValidation()
array.append(QLatin1String("foo"));
array.append(QLatin1String("two")); //["foo", "two"]
QVERIFY(validate(array, "{ \"items\" : { \"type\" : \"string\" }, \"additionalProperties\" : false }"));
-#ifdef FIX
QVERIFY(validate(array, "{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" } ], \"additionalProperties\" : false }"));
array.append(3); // ["foo", "two", 3]
QVERIFY(validate(array,
"{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" } ], \"additionalProperties\" : { \"type\" : \"number\" } }"));
+ QVERIFY(!validate(array,
+ "{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" } ], \"additionalProperties\" : { \"type\" : \"string\" } }"));
array[2] = QLatin1String("three"); // ["foo", "two", "three"]
QVERIFY(validate(array,
"{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" }, { \"type\" : \"string\" } ], \"additionalProperties\" : { \"type\" : \"number\" } }"));
-#endif
}
// 5.5 items
@@ -254,7 +255,7 @@ void tst_JsonSchema::testItemsValidation()
array.append(2); // ["foo", 2]
QVERIFY(!validate(array, "{ \"type\" : \"array\", \"items\" : { \"type\" : \"string\" } }")); // INVALID
QVERIFY(!validate(array, "{ \"type\" : \"array\", \"items\" : { \"type\" : \"number\" } }")); // INVALID
-//fix QVERIFY(validate(array, "{ \"type\" : \"array\", \"items\" : [{ \"type\" : \"string\" }, { \"type\" : \"number\" }] }"));
+ QVERIFY(validate(array, "{ \"type\" : \"array\", \"items\" : [{ \"type\" : \"string\" }, { \"type\" : \"number\" }] }"));
array.removeAt(0); // [2]
QVERIFY(!validate(array, "{ \"type\" : \"array\", \"items\" : { \"type\" : \"string\" } }")); // INVALID
@@ -263,7 +264,38 @@ void tst_JsonSchema::testItemsValidation()
array.append(QLatin1String("foo"));
array.append(QLatin1String("two")); //["foo", "two"]
// should fail!!!!!
-//fix QVERIFY(!validate(array, "{ \"type\" : \"array\", \"items\" : [{ \"type\" : \"string\" }, { \"type\" : \"number\" }] }"));
+ QVERIFY(!validate(array, "{ \"type\" : \"array\", \"items\" : [{ \"type\" : \"string\" }, { \"type\" : \"number\" }] }"));
+}
+
+// 5.6 additionalItems
+void tst_JsonSchema::testAdditionalItems()
+{
+ //array tests
+ QJsonArray array;
+ array.append(1); // [1]
+ array.append(2); // [1, 2]
+ array.append(3); // [1, 2, 3]
+
+ QVERIFY(validate(array, "{ \"additionalItems\" : true }"));
+ QVERIFY(validate(array, "{ \"additionalItems\" : { \"type\" : \"number\" } }"));
+ QVERIFY(!validate(array, "{ \"additionalItems\" : false }"));
+ QVERIFY(!validate(array, "{ \"additionalItems\" : { \"type\" : \"string\" } }"));
+
+ array = QJsonArray();
+ array.append(QLatin1String("1")); // ['1']
+ array.append(QLatin1String("2")); // ['1','2']
+
+ QVERIFY(validate(array, "{ \"items\" : { \"type\" : \"string\" }, \"additionalItems\" : false }"));
+ QVERIFY(validate(array, "{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" } ], \"additionalItems\" : false }"));
+
+ array.append(3); // ['1', '2', 3]
+ QVERIFY(validate(array, "{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" } ], \"additionalItems\" : { \"type\" : \"number\" } }"));
+
+ array[2] = QLatin1String("3"); // ['1', '2', '3']
+ QVERIFY(validate(array, "{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" }, { \"type\" : \"string\" } ], \"additionalItems\": { \"type\" : \"number\" } }"));
+
+ QVERIFY(!validate(array, "{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" } ],\"additionalItems\": false }"));
+ QVERIFY(!validate(array, "{ \"items\" : [ { \"type\" : \"string\" }, { \"type\" : \"string\" } ],\"additionalItems\": { \"type\" : \"number\" } }"));
}
// 5.7