summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-02-17 13:08:21 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-22 00:03:53 +0100
commitf60588237b230923c6a27f60669fa0230138f1ca (patch)
tree7fa24633c22c7aa06dcb395fab499c8abb8f9b6a /tests/auto
parenta73ad904c9a4ad188604de6c64a6c91cd514dc1b (diff)
Implement String.localeCompare() using QString::localeAwareCompare()
v8's localeCompare() implementation is not locale aware, so we use Qt's locale aware compare. Change-Id: Ia9092b3d6754545bb797adac26080ac7a29dcd92 Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativelocale/data/localeCompare.qml7
-rw-r--r--tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp41
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativelocale/data/localeCompare.qml b/tests/auto/declarative/qdeclarativelocale/data/localeCompare.qml
new file mode 100644
index 0000000000..6851af6ef9
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelocale/data/localeCompare.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0
+
+QtObject {
+ property var string1: "a"
+ property var string2: "a"
+ property var comparison: string1.localeCompare(string2)
+}
diff --git a/tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp b/tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp
index 5afc2354a6..bf5c8c7af4 100644
--- a/tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp
+++ b/tests/auto/declarative/qdeclarativelocale/tst_qdeclarativelocale.cpp
@@ -106,6 +106,9 @@ private slots:
void numberFromLocaleString();
void numberConstToLocaleString();
+ void stringLocaleCompare_data();
+ void stringLocaleCompare();
+
private:
void addPropertyData(const QString &l);
QVariant getProperty(QObject *obj, const QString &locale, const QString &property);
@@ -1137,6 +1140,44 @@ void tst_qdeclarativelocale::numberConstToLocaleString()
QCOMPARE(obj->property("const2").toString(), l.toString(1234., 'f', 2));
}
+void tst_qdeclarativelocale::stringLocaleCompare_data()
+{
+ QTest::addColumn<QString>("string1");
+ QTest::addColumn<QString>("string2");
+
+ QTest::newRow("before") << "a" << "b";
+ QTest::newRow("equal") << "a" << "a";
+ QTest::newRow("after") << "b" << "a";
+
+ // Copied from QString::localeAwareCompare tests
+ // We don't actually change locale - we just care that String.localeCompare()
+ // matches QString::localeAwareCompare();
+ QTest::newRow("swedish1") << QString("\xe5") << QString("\xe4");
+ QTest::newRow("swedish2") << QString("\xe4") << QString("\xf6");
+ QTest::newRow("swedish3") << QString("\xe5") << QString("\xf6");
+ QTest::newRow("swedish4") << QString("z") << QString("\xe5");
+
+ QTest::newRow("german1") << QString("z") << QString("\xe4");
+ QTest::newRow("german2") << QString("\xe4") << QString("\xf6");
+ QTest::newRow("german3") << QString("z") << QString("\xf6");
+}
+
+void tst_qdeclarativelocale::stringLocaleCompare()
+{
+ QFETCH(QString, string1);
+ QFETCH(QString, string2);
+
+ QDeclarativeComponent c(&engine, testFileUrl("localeCompare.qml"));
+
+ QObject *obj = c.create();
+ QVERIFY(obj);
+
+ obj->setProperty("string1", string1);
+ obj->setProperty("string2", string2);
+
+ QCOMPARE(obj->property("comparison").toInt(), QString::localeAwareCompare(string1, string2));
+}
+
QTEST_MAIN(tst_qdeclarativelocale)
#include "tst_qdeclarativelocale.moc"