summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-03-05 06:08:26 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-03-05 06:08:26 (GMT)
commit769a11719ca85e9cdac4c0f1d0fcffe6145d6972 (patch)
tree8cf89cdceff0e832ff2cdf9f7ee96ea230403125 /tests
parent48fd47f64f3f73e82016161d82cdf67908a9c653 (diff)
downloadQt-769a11719ca85e9cdac4c0f1d0fcffe6145d6972.zip
Qt-769a11719ca85e9cdac4c0f1d0fcffe6145d6972.tar.gz
Qt-769a11719ca85e9cdac4c0f1d0fcffe6145d6972.tar.bz2
Don't assume documents are in UTF-8.
Task-number: QTBUG-7719
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml28
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.xmlbin0 -> 154 bytes
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp25
3 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml
new file mode 100644
index 0000000..63165ab
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.qml
@@ -0,0 +1,28 @@
+import Qt 4.6
+
+QtObject {
+ property bool dataOK: false
+
+ property string responseText
+ property string responseXmlRootNodeValue
+
+ Component.onCompleted: {
+ var x = new XMLHttpRequest;
+
+ x.open("GET", "utf16.xml");
+
+ // Test to the end
+ x.onreadystatechange = function() {
+ if (x.readyState == XMLHttpRequest.DONE) {
+
+ responseText = x.responseText
+ if (x.responseXML)
+ responseXmlRootNodeValue = x.responseXML.documentElement.childNodes[0].nodeValue
+
+ dataOK = true;
+ }
+ }
+ x.send()
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.xml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.xml
new file mode 100644
index 0000000..0fbb126
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/utf16.xml
Binary files differ
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
index 01f07ab..13ed959 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
@@ -104,6 +104,7 @@ private slots:
void responseXML_invalid();
void invalidMethodUsage();
void redirects();
+ void nonUtf8();
// Attributes
void document();
@@ -917,6 +918,30 @@ void tst_qdeclarativexmlhttprequest::responseText_data()
QTest::newRow("Not Found") << TEST_FILE("status.404.reply") << TEST_FILE("testdocument.html") << "";
}
+void tst_qdeclarativexmlhttprequest::nonUtf8()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("utf16.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QString uc;
+ uc.resize(3);
+ uc[0] = QChar(0x10e3);
+ uc[1] = QChar(' ');
+ uc[2] = QChar(0x03a3);
+ QString xml = "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone='yes'?>\n<root>\n" + uc + "\n</root>\n";
+
+ TRY_WAIT(object->property("dataOK").toBool() == true);
+
+ QString responseText = object->property("responseText").toString();
+ QCOMPARE(responseText, xml);
+
+ QString responseXmlText = object->property("responseXmlRootNodeValue").toString();
+ QCOMPARE(responseXmlText, '\n' + uc + '\n');
+
+ delete object;
+}
+
// Test that calling hte XMLHttpRequest methods on a non-XMLHttpRequest object
// throws an exception
void tst_qdeclarativexmlhttprequest::invalidMethodUsage()