From 176698a91d3b2256a093785967c6706328981af4 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 14 Oct 2009 15:05:18 +1000 Subject: Force QML files to be always UTF-8. Ensure test works in all locales. --- src/declarative/qml/qmlerror.cpp | 1 + src/declarative/qml/qmlscriptparser.cpp | 1 + tests/auto/declarative/declarative.pro | 3 --- .../declarative/qmllanguage/data/I18nType30.qml | 5 ++++ ...8n\303\201\303\242\303\243\303\244\303\245.qml" | 5 ---- .../auto/declarative/qmllanguage/data/i18nType.qml | 2 +- .../declarative/qmllanguage/tst_qmllanguage.cpp | 30 ++++++++++++++++++---- 7 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 tests/auto/declarative/qmllanguage/data/I18nType30.qml delete mode 100644 "tests/auto/declarative/qmllanguage/data/I18n\303\201\303\242\303\243\303\244\303\245.qml" diff --git a/src/declarative/qml/qmlerror.cpp b/src/declarative/qml/qmlerror.cpp index 5ee9144..514fe44 100644 --- a/src/declarative/qml/qmlerror.cpp +++ b/src/declarative/qml/qmlerror.cpp @@ -201,6 +201,7 @@ QDebug operator<<(QDebug debug, const QmlError &error) if (f.open(QIODevice::ReadOnly)) { QByteArray data = f.readAll(); QTextStream stream(data, QIODevice::ReadOnly); + stream.setCodec("UTF-8"); const QString code = stream.readAll(); const QStringList lines = code.split(QLatin1Char('\n')); diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 9cc12b3..6e5f315 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -870,6 +870,7 @@ bool QmlScriptParser::parse(const QByteArray &qmldata, const QUrl &url) const QString fileName = url.toString(); QTextStream stream(qmldata, QIODevice::ReadOnly); + stream.setCodec("UTF-8"); const QString code = stream.readAll(); data = new QmlScriptParserJsASTData(fileName); diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index eef9da7..b51e285 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -25,9 +25,6 @@ SUBDIRS += anchors \ states \ visual -SUBDIRS -= examples # Human-interactive - # Tests which should run in Pulse PULSE_TESTS = $$SUBDIRS -PULSE_TESTS -= visual # All except 'visual' tests, allegedly too flaky diff --git a/tests/auto/declarative/qmllanguage/data/I18nType30.qml b/tests/auto/declarative/qmllanguage/data/I18nType30.qml new file mode 100644 index 0000000..42dbc69 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/I18nType30.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + stringProperty: "Test áâãäå: 30" +} diff --git "a/tests/auto/declarative/qmllanguage/data/I18n\303\201\303\242\303\243\303\244\303\245.qml" "b/tests/auto/declarative/qmllanguage/data/I18n\303\201\303\242\303\243\303\244\303\245.qml" deleted file mode 100644 index 42dbc69..0000000 --- "a/tests/auto/declarative/qmllanguage/data/I18n\303\201\303\242\303\243\303\244\303\245.qml" +++ /dev/null @@ -1,5 +0,0 @@ -import Test 1.0 - -MyTypeObject { - stringProperty: "Test áâãäå: 30" -} diff --git a/tests/auto/declarative/qmllanguage/data/i18nType.qml b/tests/auto/declarative/qmllanguage/data/i18nType.qml index 11ef895..d7954ef 100644 --- a/tests/auto/declarative/qmllanguage/data/i18nType.qml +++ b/tests/auto/declarative/qmllanguage/data/i18nType.qml @@ -1 +1 @@ -I18nÁâãäå { } +I18nTypeÁâãäå { } diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index b99d040..b68d9bf 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -24,6 +24,8 @@ public: } private slots: + void initTestCase(); + void cleanupTestCase(); void errors_data(); void errors(); @@ -116,6 +118,24 @@ inline QUrl TEST_FILE(const char *filename) return TEST_FILE(QLatin1String(filename)); } +void tst_qmllanguage::initTestCase() +{ + // Create locale-specific file + // For POSIX, this will just be data/I18nType.qml, since POSIX is 7-bit + // For iso8859-1 locale, this will just be data/I18nType?????.qml where ????? is 5 8-bit characters + // For utf-8 locale, this will be data/I18nType??????????.qml where ?????????? is 5 8-bit characters, UTF-8 encoded + QFile in(TEST_FILE(QLatin1String("I18nType30.qml")).toLocalFile()); + QVERIFY(in.open(QIODevice::ReadOnly)); + QFile out(TEST_FILE(QString::fromUtf8("I18nType\303\241\303\242\303\243\303\244\303\245.qml")).toLocalFile()); + QVERIFY(out.open(QIODevice::WriteOnly)); + out.write(in.readAll()); +} + +void tst_qmllanguage::cleanupTestCase() +{ + QVERIFY(QFile::remove(TEST_FILE(QString::fromUtf8("I18nType\303\241\303\242\303\243\303\244\303\245.qml")).toLocalFile())); +} + void tst_qmllanguage::errors_data() { QTest::addColumn("file"); @@ -686,11 +706,11 @@ void tst_qmllanguage::i18n_data() { QTest::addColumn("file"); QTest::addColumn("stringProperty"); - QTest::newRow("i18nStrings") << "i18nStrings.qml" << QString::fromUtf8("Test áâãäå (5 accented 'a' letters)"); - QTest::newRow("i18nDeclaredPropertyNames") << "i18nDeclaredPropertyNames.qml" << QString::fromUtf8("Test áâãäå: 10"); - QTest::newRow("i18nDeclaredPropertyUse") << "i18nDeclaredPropertyUse.qml" << QString::fromUtf8("Test áâãäå: 15"); - QTest::newRow("i18nScript") << "i18nScript.qml" << QString::fromUtf8("Test áâãäå: 20"); - QTest::newRow("i18nType") << "i18nType.qml" << QString::fromUtf8("Test áâãäå: 30"); + QTest::newRow("i18nStrings") << "i18nStrings.qml" << QString::fromUtf8("Test \303\241\303\242\303\243\303\244\303\245 (5 accented 'a' letters)"); + QTest::newRow("i18nDeclaredPropertyNames") << "i18nDeclaredPropertyNames.qml" << QString::fromUtf8("Test \303\241\303\242\303\243\303\244\303\245: 10"); + QTest::newRow("i18nDeclaredPropertyUse") << "i18nDeclaredPropertyUse.qml" << QString::fromUtf8("Test \303\241\303\242\303\243\303\244\303\245: 15"); + QTest::newRow("i18nScript") << "i18nScript.qml" << QString::fromUtf8("Test \303\241\303\242\303\243\303\244\303\245: 20"); + QTest::newRow("i18nType") << "i18nType.qml" << QString::fromUtf8("Test \303\241\303\242\303\243\303\244\303\245: 30"); } void tst_qmllanguage::i18n() -- cgit v0.12