2 #include <QtTest/QtTest> 3 #include <QJsonDocument> 10 void TestSerialisers::testJSONSerialiser(
void)
12 QByteArray array(
"[\"number\",\"name\"]");
13 QJsonDocument doc = QJsonDocument::fromJson(array);
14 QVariant map = doc.toVariant();
16 QVERIFY(jsonserialiser);
19 delete jsonserialiser;
20 QJsonDocument doc2 = QJsonDocument::fromJson(data);
21 QByteArray array2 = doc2.toJson(QJsonDocument::Compact).trimmed();
23 QVERIFY(array.size() == array2.size());
24 QVERIFY(qstrcmp(array.constData(), array2.constData()) == 0);
26 QVERIFY(array2 == array);
29 void TestSerialisers::doTestXMLSerialiser(QByteArray &Data)
33 QVERIFY(reader.IsValid(error));
34 QVariantMap map = reader.GetResult();
36 QVERIFY(xmlserialiser);
40 QVERIFY(Data.size() == array2.size());
43 void TestSerialisers::testXMLSerialiser(
void)
45 QMap<QString,QByteArray> tests;
46 tests.insert(
"Simple1",
"<list><value>name</value><value>number</value></list>");
47 tests.insert(
"Simple2",
"<people><person><name>Jon</name><age>12</age></person></people>");
48 tests.insert(
"Simple3",
"<list><value>1</value><value>2</value><value>3</value></list>");
49 tests.insert(
"Simple4",
"<person>me</person><person>you</person>");
51 QMap<QString,QByteArray>::iterator it = tests.begin();
52 for ( ; it != tests.end(); ++it)
54 QByteArray t =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + it.value() +
"\n";
55 doTestXMLSerialiser(t);
void Serialise(QByteArray &Dest, const QVariant &Data, const QString &Type=QString())
static TorcSerialiser * GetSerialiser(const QString &MimeType)