diff options
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions/propertylist.qbs | 65 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 13 |
2 files changed, 77 insertions, 1 deletions
diff --git a/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs b/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs index 5b80eeafb..8790629c2 100644 --- a/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs +++ b/tests/auto/blackbox/testdata/jsextensions/propertylist.qbs @@ -55,10 +55,75 @@ Product { jsontextfile.write(propertyList.toJSONString()); jsontextfile.close(); + propertyList.writeToFile("test2.json", "json-compact"); + propertyList.writeToFile("test3.json", "json-pretty"); + process = new Process(); process.exec("plutil", ["-convert", "json", "test.xml"]); process.close(); + propertyList = new PropertyList(); + propertyList.readFromFile("test.xml"); + if (propertyList.format() !== "json") { // yes, JSON -- ignore the file extension + throw "expected property list format json but got " + propertyList.format(); + } + + if (propertyList.isEmpty()) { + throw "PropertyList was 'empty' after being loaded with data"; + } + + var opensteptextfile = new TextFile("test.openstep.plist", TextFile.WriteOnly); + opensteptextfile.write('{ rootObject = ( "val1", "val3", "val5", /* comment */ "val7", "val9", ); }'); + opensteptextfile.close(); + + propertyList = new PropertyList(); + propertyList.readFromFile("test.openstep.plist"); + if (propertyList.format() !== "openstep") { + throw "expected property list format openstep but got " + propertyList.format(); + } + + var jsonObj = JSON.parse(propertyList.toJSONString()); + if (jsonObj["rootObject"].length != 5) { + throw "going from OpenStep to a JSON string to a JSON object somehow broke"; + } + + propertyList.clear(); + propertyList.readFromString('<dict><key>foo</key><string>barz</string></dict>'); + jsonObj = JSON.parse(propertyList.toJSONString()); + if (jsonObj["foo"] !== "barz") { + throw "the XML plist did not get parsed properly"; + } + + propertyList.writeToFile("woof.xml", "xml1"); + propertyList.readFromFile("woof.xml"); + if (propertyList.format() !== "xml1") { + throw "round trip writing and reading XML failed"; + } + + propertyList.writeToFile("woof.plist", "binary1"); + propertyList.readFromFile("woof.plist"); + if (propertyList.format() !== "binary1") { + throw "round trip writing and reading binary failed"; + } + + if (jsonObj["foo"] !== "barz") { + throw "the binary plist did not get parsed properly"; + } + + if (propertyList.toString("json") !== propertyList.toString("json-compact") || + propertyList.toJSONString() !== propertyList.toJSONString("compact")) { + throw "json and json-compact formats were not equivalent"; + } + + if (propertyList.toString("json") === propertyList.toString("json-pretty") || + propertyList.toJSONString() === propertyList.toJSONString("pretty")) { + throw "json and json-pretty formats were not different"; + } + + if (propertyList.toString("xml1") !== propertyList.toXMLString()) { + throw 'toString("xml1") and toXMLString() were not equivalent'; + } + return "Pineapple Steve"; } } diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 394557390..db0928e4d 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -1597,7 +1597,18 @@ void TestBlackbox::jsExtensionsPropertyList() QFile file2("test.xml"); QVERIFY(file2.exists()); QVERIFY(file2.open(QIODevice::ReadOnly)); - QCOMPARE(file1.readAll(), file2.readAll()); + QFile file3("test2.json"); + QVERIFY(file3.exists()); + QVERIFY(file3.open(QIODevice::ReadOnly)); + QByteArray file1Contents = file1.readAll(); + QCOMPARE(file3.readAll(), file1Contents); + QCOMPARE(file1Contents, file2.readAll()); + QFile file4("test.openstep.plist"); + QVERIFY(file4.exists()); + QFile file5("test3.json"); + QVERIFY(file5.exists()); + QVERIFY(file5.open(QIODevice::ReadOnly)); + QVERIFY(file1Contents != file5.readAll()); } void TestBlackbox::jsExtensionsTextFile() |