aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp2
-rw-r--r--tests/auto/qml/qqmlecmascript/data/sequenceSort.qml95
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.cpp42
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h2
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp44
5 files changed, 183 insertions, 2 deletions
diff --git a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
index 5f74f865ec..803c2d8720 100644
--- a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
+++ b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
@@ -1772,7 +1772,7 @@ void tst_QQmlDebugJS::getScripts()
QList<QVariant> scripts = value.value("body").toList();
- QCOMPARE(scripts.count(), 2);
+ QCOMPARE(scripts.count(), 3);
}
void tst_QQmlDebugJS::getSource()
diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceSort.qml b/tests/auto/qml/qqmlecmascript/data/sequenceSort.qml
new file mode 100644
index 0000000000..5e2892a31d
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/sequenceSort.qml
@@ -0,0 +1,95 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+
+ MyStringClass {
+ id: msc
+ }
+
+ function compare(a0, a1) {
+ var compareOk = a0.length === a1.length;
+
+ if (compareOk === true) {
+ for (var i=0 ; i < a0.length ; ++i) {
+ if (a0[i] != a1[i]) {
+ compareOk = false;
+ break;
+ }
+ }
+ }
+
+ return compareOk;
+ }
+
+ function compareStrings(a, b) {
+ return (a < b) ? 1 : -1;
+ }
+
+ function compareNumbers(a, b) {
+ return a - b;
+ }
+
+ function createExpected(list, sortFn) {
+ var expected = []
+ for (var i=0 ; i < list.length ; ++i)
+ expected.push(list[i]);
+ if (sortFn === null)
+ expected.sort();
+ else
+ expected.sort(sortFn);
+ return expected;
+ }
+
+ function checkResults(expected, actual, sortFn) {
+ if (sortFn === null)
+ actual.sort();
+ else
+ actual.sort(sortFn);
+ return compare(expected, actual);
+ }
+
+ function doStringTest(stringList, fn) {
+ var expected = createExpected(stringList, fn);
+ var actual = msc.strings(stringList);
+ return checkResults(expected, actual, fn);
+ }
+ function doIntTest(intList, fn) {
+ var expected = createExpected(intList, fn);
+ var actual = msc.integers(intList);
+ return checkResults(expected, actual, fn);
+ }
+ function doRealTest(realList, fn) {
+ var expected = createExpected(realList, fn);
+ var actual = msc.reals(realList);
+ return checkResults(expected, actual, fn);
+ }
+
+ function test_qtbug_25269(useCustomCompare) {
+ return doStringTest( [ "one", "two", "three" ], null );
+ }
+ function test_alphabet_insertionSort(useCustomCompare) {
+ var fn = useCustomCompare ? compareStrings : null;
+ return doStringTest( [ "z", "y", "M", "a", "c", "B" ], fn );
+ }
+ function test_alphabet_quickSort(useCustomCompare) {
+ var fn = useCustomCompare ? compareStrings : null;
+ return doStringTest( [ "z", "y", "m", "a", "c", "B", "gG", "u", "bh", "lk", "GW", "Z", "n", "nm", "oi", "njk", "f", "dd", "ooo", "3des", "num123", "ojh", "lkj", "a6^^", "bl!!", "!o" ], fn );
+ }
+ function test_numbers_insertionSort(useCustomCompare) {
+ var fn = useCustomCompare ? compareNumbers : null;
+ return doIntTest( [ 7, 3, 9, 1, 0, -1, 20, -11 ], fn );
+ }
+ function test_numbers_quickSort(useCustomCompare) {
+ var fn = useCustomCompare ? compareNumbers : null;
+ return doIntTest( [ 7, 3, 37, 9, 1, 0, -1, 20, -11, -300, -87, 1, 3, -2, 100, 108, 96, 9, 99999, 12, 11, 11, 12, 11, 13, -13, 10, 10, 10, 8, 12 ], fn );
+ }
+ function test_reals_insertionSort(useCustomCompare) {
+ var fn = useCustomCompare ? compareNumbers : null;
+ return doRealTest( [ -3.4, 1, 10, 4.23, -30.1, 4.24, 4.21, -1, -1 ], fn );
+ }
+ function test_reals_quickSort(useCustomCompare) {
+ var fn = useCustomCompare ? compareNumbers : null;
+ return doRealTest( [ -3.4, 1, 10, 4.23, -30.1, 4.24, 4.21, -1, -1, 12, -100, 87.4, 101.3, -8.88888, 7.76, 10.10, 1.1, -1.1, -0, 11, 12.8, 0.001, -11, -0.75, 99999.99, 11.12, 32.3, 3.333333, 9.876 ], fn );
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp
index b02e9963ab..77670f74da 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.cpp
+++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp
@@ -190,6 +190,46 @@ void MyWorkerObject::doIt()
new MyWorkerObjectThread(this);
}
+class MyStringClass : public QObject
+{
+ Q_OBJECT
+public:
+ Q_INVOKABLE QStringList strings(QStringList stringList) const
+ {
+ return stringList;
+ }
+ Q_INVOKABLE QList<int> integers(QVariant v) const
+ {
+ QList<int> intList;
+ QList<QVariant> vList = v.toList();
+ for (int i=0 ; i < vList.size() ; ++i) {
+ int iv = vList[i].toInt();
+ intList.append(iv);
+ }
+ return intList;
+ }
+ Q_INVOKABLE QList<qreal> reals(QVariant v) const
+ {
+ QList<qreal> realList;
+ QList<QVariant> vList = v.toList();
+ for (int i=0 ; i < vList.size() ; ++i) {
+ qreal fv = vList[i].toReal();
+ realList.append(fv);
+ }
+ return realList;
+ }
+ Q_INVOKABLE QList<bool> bools(QVariant v) const
+ {
+ QList<bool> boolList;
+ QList<QVariant> vList = v.toList();
+ for (int i=0 ; i < vList.size() ; ++i) {
+ bool bv = vList[i].toBool();
+ boolList.append(bv);
+ }
+ return boolList;
+ }
+};
+
void registerTypes()
{
qmlRegisterType<MyQmlObject>("Qt.test", 1,0, "MyQmlObjectAlias");
@@ -253,6 +293,8 @@ void registerTypes()
qmlRegisterType<FallbackBindingsTypeObject>("Qt.test.fallbackBindingsObject", 1, 0, "FallbackBindingsType");
qmlRegisterType<FallbackBindingsTypeDerived>("Qt.test.fallbackBindingsDerived", 1, 0, "FallbackBindingsType");
+
+ qmlRegisterType<MyStringClass>("Qt.test", 1, 0, "MyStringClass");
}
#include "testtypes.moc"
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index d857b64d80..eaecf71ba7 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -755,7 +755,7 @@ public:
Q_INVOKABLE void method_overload(const QJsonArray &a) { invoke(26); m_actuals << QVariant::fromValue(a); }
Q_INVOKABLE void method_overload(const QJsonValue &a) { invoke(27); m_actuals << QVariant::fromValue(a); }
- Q_INVOKABLE void method_unknown(MyInvokableObject *o) { invoke(28); }
+ Q_INVOKABLE void method_unknown(MyInvokableObject *) { invoke(28); }
private:
friend class MyInvokableBaseObject;
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 4e1638f516..f6ec475d40 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -186,6 +186,8 @@ private slots:
void sequenceConversionBindings();
void sequenceConversionCopy();
void assignSequenceTypes();
+ void sequenceSort_data();
+ void sequenceSort();
void qtbug_22464();
void qtbug_21580();
void singleV8BindingDestroyedDuringEvaluation();
@@ -7121,6 +7123,48 @@ void tst_qqmlecmascript::fallbackBindings()
QCOMPARE(object->property("success").toBool(), true);
}
+void tst_qqmlecmascript::sequenceSort_data()
+{
+ QTest::addColumn<QString>("function");
+ QTest::addColumn<bool>("useComparer");
+
+ QTest::newRow("qtbug_25269") << "test_qtbug_25269" << false;
+
+ const char *types[] = { "alphabet", "numbers", "reals" };
+ const char *sort[] = { "insertionSort", "quickSort" };
+
+ for (size_t t=0 ; t < sizeof(types)/sizeof(types[0]) ; ++t) {
+ for (size_t s=0 ; s < sizeof(sort)/sizeof(sort[0]) ; ++s) {
+ for (int c=0 ; c < 2 ; ++c) {
+ QString testName = QLatin1String(types[t]) + QLatin1String("_") + QLatin1String(sort[s]);
+ QString fnName = QLatin1String("test_") + testName;
+ bool useComparer = c != 0;
+ testName += useComparer ? QLatin1String("[custom]") : QLatin1String("[default]");
+ QTest::newRow(testName.toAscii().constData()) << fnName << useComparer;
+ }
+ }
+ }
+}
+
+void tst_qqmlecmascript::sequenceSort()
+{
+ QFETCH(QString, function);
+ QFETCH(bool, useComparer);
+
+ QQmlComponent component(&engine, testFileUrl("sequenceSort.qml"));
+
+ QObject *object = component.create();
+ if (object == 0)
+ qDebug() << component.errorString();
+ QVERIFY(object != 0);
+
+ QVariant q;
+ QMetaObject::invokeMethod(object, function.toAscii().constData(), Q_RETURN_ARG(QVariant, q), Q_ARG(QVariant, useComparer));
+ QVERIFY(q.toBool() == true);
+
+ delete object;
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"