diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2013-09-05 07:55:49 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-17 08:07:25 +0200 |
commit | 89ef515177fd5a0b5d95dcffd5fd0b0669e3625a (patch) | |
tree | 0fb87c82c882168141c1194dabbc47915f10eb98 /tests/auto/tools/qmake/tst_qmake.cpp | |
parent | f47958fa148d6ea9ece0bec3ca9ba67d9c68ea19 (diff) |
Add JSON parsing support to qmake.
Add qjson* implementation files from corelib/json
to the qmake build. Add a read-only compile mode,
enabled by defining QT_JSON_READONLY.
Add qmake built-in function parseJson(file, into)
which parses a json file into the given variable.
qmake uses a flat key -> value-list implementation
for storing variables, which means that some hackery
is need to represent arbitrarily nested JSON. Use a
special "_KEYS_" variable for arrays and objects:
Arrays:
["item1", "item2"]
$${array._KEYS_} -> 0 1 2
$${array.0} -> "item1"
$${array.1} -> "item2"
Objects:
{ "key1" : "value1", "key2" : "value2" }
$${object._KEYS_} -> key1 key2
$${object.key1} -> value1
$${object.key2} -> value2
Change-Id: I0aa2e4e4ae14fa25be8242bc16d3cffce32504d2
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/tools/qmake/tst_qmake.cpp')
-rw-r--r-- | tests/auto/tools/qmake/tst_qmake.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/tools/qmake/tst_qmake.cpp b/tests/auto/tools/qmake/tst_qmake.cpp index cf5c75a66b..87e86406b8 100644 --- a/tests/auto/tools/qmake/tst_qmake.cpp +++ b/tests/auto/tools/qmake/tst_qmake.cpp @@ -92,6 +92,7 @@ private slots: void substitutes(); void project(); void proFileCache(); + void json(); private: TestCompiler test_compiler; @@ -556,5 +557,33 @@ void tst_qmake::proFileCache() QVERIFY( test_compiler.qmake( workDir, "pro_file_cache" )); } +void tst_qmake::json() +{ + QString workDir = base_path + "/testdata/json"; + QVERIFY( test_compiler.qmake( workDir, "json.pro" )); + QString output = test_compiler.commandOutput(); + + // all keys + QVERIFY(output.contains("json._KEYS_ array false null number object string true")); + // array + QVERIFY(output.contains("json.array._KEYS_ 0 1 2")); + QVERIFY(output.contains("json.array.0 arrayItem1")); + QVERIFY(output.contains("json.array.1 arrayItem2")); + QVERIFY(output.contains("json.array.2 arrayItem3")); + // object + QVERIFY(output.contains("json.object._KEYS_ key1 key2")); + QVERIFY(output.contains("json.object.key1 objectValue1")); + QVERIFY(output.contains("json.object.key1 objectValue1")); + // value types + QVERIFY(output.contains("json.string: test string")); + QVERIFY(output.contains("json.number: 999")); + QVERIFY(output.contains("json.true: true")); + QVERIFY(output.contains("json.false: false")); + QVERIFY(output.contains("json.null:")); + // functional booleans + QVERIFY(output.contains("json.true is true")); + QVERIFY(output.contains("json.false is false")); +} + QTEST_MAIN(tst_qmake) #include "tst_qmake.moc" |