diff options
Diffstat (limited to 'tests/auto/qml')
19 files changed, 318 insertions, 129 deletions
diff --git a/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp b/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp index 1791407934..ff295c5409 100644 --- a/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp +++ b/tests/auto/qml/animation/qpauseanimationjob/tst_qpauseanimationjob.cpp @@ -392,8 +392,10 @@ void tst_QPauseAnimationJob::multipleSequentialGroups() #ifdef Q_OS_WIN if (group.state() != QAbstractAnimationJob::Stopped) QEXPECT_FAIL("", winTimerError, Abort); -#endif + QCOMPARE(group.state(), QAbstractAnimationJob::Stopped); +#else QTRY_COMPARE(group.state(), QAbstractAnimationJob::Stopped); +#endif #ifdef Q_OS_WIN if (subgroup1.state() != QAbstractAnimationJob::Stopped) diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index 40e19d375d..8c30a82317 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -45,6 +45,7 @@ #include <QtQml/qqmlcomponent.h> #include <QtQml/qqmlexpression.h> #include <QtQml/qqmlproperty.h> +#include <QtQml/qqmlincubator.h> #include <QtQuick/qquickitem.h> #include <QtNetwork/qhostaddress.h> @@ -136,6 +137,7 @@ private slots: void regression_QTCREATORBUG_7451(); void queryObjectWithNonStreamableTypes(); + void asynchronousCreate(); }; QmlDebugObjectReference tst_QQmlEngineDebugService::findRootObject( @@ -1220,6 +1222,32 @@ void tst_QQmlEngineDebugService::queryObjectTree() QCOMPARE(findProperty(animation.properties,"duration").value.toInt(), 100); } +void tst_QQmlEngineDebugService::asynchronousCreate() { + QmlDebugObjectReference object; + auto connection = connect(m_dbg, &QQmlEngineDebugClient::newObject, this, [&](int objectId) { + object.debugId = objectId; + }); + + QByteArray asynchronousComponent = "import QtQuick 2.5\n" + "Rectangle { id: asyncRect }"; + QQmlComponent component(m_engine); + component.setData(asynchronousComponent, QUrl::fromLocalFile("")); + QVERIFY(component.isReady()); // fails if bad syntax + QQmlIncubator incubator(QQmlIncubator::Asynchronous); + component.create(incubator); + + QVERIFY(m_dbg->object().idString != QLatin1String("asyncRect")); + + QTRY_VERIFY(object.debugId != -1); + disconnect(connection); + + bool success = false; + m_dbg->queryObject(object, &success); + QVERIFY(success); + + QTRY_COMPARE(m_dbg->object().idString, QLatin1String("asyncRect")); +} + int main(int argc, char *argv[]) { int _argc = argc + 1; diff --git a/tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml b/tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml index f44c653840..f43cff15e4 100644 --- a/tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml +++ b/tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml @@ -29,16 +29,15 @@ Rectangle { } var milliDelta = millis - prevHit; - if (milliDelta < 0) + if (milliDelta <= 0) milliDelta += 1000; - console.log(milliDelta, "milliseconds "); prevHit = millis; var delta = parent.rotation - prevRotation; if (delta < 0) delta += 360 prevRotation = parent.rotation - console.log(delta, "degrees "); + console.log(milliDelta, delta, "ms/degrees "); } } } diff --git a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp index f55fef232e..9461922eff 100644 --- a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp +++ b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp @@ -102,29 +102,46 @@ void tst_QQmlInspector::startQmlProcess(const QString &qmlFile, bool restrictSer void tst_QQmlInspector::checkAnimationSpeed(int targetMillisPerDegree) { - QString degreesString = QStringLiteral("degrees"); - QString millisecondsString = QStringLiteral("milliseconds"); - for (int i = 0; i < 2; ++i) { // skip one period; the change might have happened inside it - int position = m_process->output().length(); - while (!m_process->output().mid(position).contains(degreesString) || - !m_process->output().mid(position).contains(millisecondsString)) { + const QString markerString = QStringLiteral("ms/degrees"); + + // Funny things can happen with time and VMs. Also the change might take a while to propagate. + // Thus, we wait until we either have 3 passes or 3 failures in a row, or 10 loops have passed. + + int numFailures = 0; + int numPasses = 0; + + for (int i = 0; i < 10; ++i) { + QString output = m_process->output(); + int position = output.length(); + do { QVERIFY(QQmlDebugTest::waitForSignal(m_process.data(), SIGNAL(readyReadStandardOutput()))); + output = m_process->output(); + } while (!output.mid(position).contains(markerString)); + + + QStringList words = output.split(QLatin1Char(' ')); + const int marker = words.lastIndexOf(markerString); + QVERIFY(marker > 1); + const double degrees = words[marker - 1].toDouble(); + const int milliseconds = words[marker - 2].toInt(); + const double millisecondsPerDegree = milliseconds / degrees; + + if (millisecondsPerDegree > targetMillisPerDegree - 3 + || millisecondsPerDegree < targetMillisPerDegree + 3) { + if (++numPasses == 3) + return; // pass + numFailures = 0; + } else { + QVERIFY2(++numFailures < 3, + QString("3 consecutive failures when checking for %1 milliseconds per degree") + .arg(targetMillisPerDegree).toLocal8Bit().constData()); + numPasses = 0; } } - QStringList words = m_process->output().split(QLatin1Char(' ')); - int degreesMarker = words.lastIndexOf(degreesString); - QVERIFY(degreesMarker > 1); - double degrees = words[degreesMarker - 1].toDouble(); - int millisecondsMarker = words.lastIndexOf(millisecondsString); - QVERIFY(millisecondsMarker > 1); - int milliseconds = words[millisecondsMarker - 1].toInt(); - - double millisecondsPerDegree = milliseconds / degrees; - QVERIFY(millisecondsPerDegree > targetMillisPerDegree - 3); - QVERIFY(millisecondsPerDegree < targetMillisPerDegree + 3); - + QFAIL(QString("Animation speed won't settle to %1 milliseconds per degree") + .arg(targetMillisPerDegree).toLocal8Bit().constData()); } void tst_QQmlInspector::cleanup() diff --git a/tests/auto/qml/debugger/shared/qqmlenginedebugclient.cpp b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.cpp index 3ad7beb7ff..3e27951d78 100644 --- a/tests/auto/qml/debugger/shared/qqmlenginedebugclient.cpp +++ b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.cpp @@ -489,7 +489,9 @@ void QQmlEngineDebugClient::messageReceived(const QByteArray &data) return; } else if (type == "OBJECT_CREATED") { - emit newObjects(); + int engineId, objectId, parentId; + ds >> engineId >> objectId >> parentId; + emit newObject(objectId); return; } else if (type == "SET_BINDING_R") { ds >> m_valid; diff --git a/tests/auto/qml/debugger/shared/qqmlenginedebugclient.h b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.h index a64a77e13e..5d74f2d43c 100644 --- a/tests/auto/qml/debugger/shared/qqmlenginedebugclient.h +++ b/tests/auto/qml/debugger/shared/qqmlenginedebugclient.h @@ -213,7 +213,7 @@ public: bool valid() { return m_valid; } signals: - void newObjects(); + void newObject(int objectId); void valueChanged(QByteArray,QVariant); void result(); diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp index 8af446173d..b265607fd1 100644 --- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp +++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp @@ -53,6 +53,7 @@ private slots: void registerImportForImplicitComponent(); void basicVersionChecks(); void recompileAfterChange(); + void recompileAfterDirectoryChange(); void fileSelectors(); void localAliases(); void cacheResources(); @@ -95,11 +96,17 @@ struct TestCompiler TestCompiler(QQmlEngine *engine) : engine(engine) , tempDir() - , testFilePath(tempDir.path() + QStringLiteral("/test.qml")) - , cacheFilePath(tempDir.path() + QStringLiteral("/test.qmlc")) - , mappedFile(cacheFilePath) , currentMapping(nullptr) { + init(tempDir.path()); + } + + void init(const QString &baseDirectory) + { + closeMapping(); + testFilePath = baseDirectory + QStringLiteral("/test.qml"); + cacheFilePath = baseDirectory + QStringLiteral("/test.qmlc"); + mappedFile.setFileName(cacheFilePath); } bool compile(const QByteArray &contents) @@ -187,8 +194,8 @@ struct TestCompiler QQmlEngine *engine; const QTemporaryDir tempDir; - const QString testFilePath; - const QString cacheFilePath; + QString testFilePath; + QString cacheFilePath; QString lastErrorString; QFile mappedFile; uchar *currentMapping; @@ -441,6 +448,47 @@ void tst_qmldiskcache::recompileAfterChange() } } +void tst_qmldiskcache::recompileAfterDirectoryChange() +{ + QQmlEngine engine; + TestCompiler testCompiler(&engine); + + QVERIFY(testCompiler.tempDir.isValid()); + + QVERIFY(QDir(testCompiler.tempDir.path()).mkdir("source1")); + testCompiler.init(testCompiler.tempDir.path() + QLatin1String("/source1")); + + { + const QByteArray contents = QByteArrayLiteral("import QtQml 2.0\n" + "QtObject {\n" + " property int blah: 42;\n" + "}"); + + testCompiler.clearCache(); + QVERIFY2(testCompiler.compile(contents), qPrintable(testCompiler.lastErrorString)); + QVERIFY2(testCompiler.verify(), qPrintable(testCompiler.lastErrorString)); + testCompiler.closeMapping(); + } + + const QDateTime initialCacheTimeStamp = QFileInfo(testCompiler.cacheFilePath).lastModified(); + + QDir(testCompiler.tempDir.path()).rename(QStringLiteral("source1"), QStringLiteral("source2")); + waitForFileSystem(); + + testCompiler.init(testCompiler.tempDir.path() + QLatin1String("/source2")); + + { + CleanlyLoadingComponent component(&engine, testCompiler.testFilePath); + QScopedPointer<QObject> obj(component.create()); + QVERIFY(!obj.isNull()); + QCOMPARE(obj->property("blah").toInt(), 42); + } + + QFile cacheFile(testCompiler.cacheFilePath); + QVERIFY2(cacheFile.exists(), qPrintable(cacheFile.fileName())); + QVERIFY(QFileInfo(testCompiler.cacheFilePath).lastModified() > initialCacheTimeStamp); +} + void tst_qmldiskcache::fileSelectors() { QQmlEngine engine; diff --git a/tests/auto/qml/qqmlapplicationengine/data/LocalComponent.qml b/tests/auto/qml/qqmlapplicationengine/data/LocalComponent.qml new file mode 100644 index 0000000000..ece4f45b4a --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/data/LocalComponent.qml @@ -0,0 +1,6 @@ +import QtQml 2.0 + +// used in nonResolvedLocal +QtObject { + +} diff --git a/tests/auto/qml/qqmlapplicationengine/data/nonResolvedLocal.qml b/tests/auto/qml/qqmlapplicationengine/data/nonResolvedLocal.qml new file mode 100644 index 0000000000..45a235346d --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/data/nonResolvedLocal.qml @@ -0,0 +1,9 @@ +import QtQml 2.0 + +QtObject { + property bool success: true + + property QtObject local: LocalComponent { + } +} + diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index 98b92e5fab..74add85cb0 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -42,6 +42,7 @@ public: private slots: void initTestCase(); void basicLoading(); + void testNonResolvedPath(); void application(); void applicationProperties(); private: @@ -83,6 +84,29 @@ void tst_qqmlapplicationengine::basicLoading() delete test; } +// make sure we resolve a relative URL to an absolute one, otherwise things +// will break. +void tst_qqmlapplicationengine::testNonResolvedPath() +{ + { + // NOTE NOTE NOTE! Missing testFileUrl is *WANTED* here! We want a + // non-resolved URL. + QQmlApplicationEngine test("data/nonResolvedLocal.qml"); + QCOMPARE(test.rootObjects().size(), 1); + QVERIFY(test.rootObjects()[0]); + QVERIFY(test.rootObjects()[0]->property("success").toBool()); + } + { + QQmlApplicationEngine test; + // NOTE NOTE NOTE! Missing testFileUrl is *WANTED* here! We want a + // non-resolved URL. + test.load("data/nonResolvedLocal.qml"); + QCOMPARE(test.rootObjects().size(), 1); + QVERIFY(test.rootObjects()[0]); + QVERIFY(test.rootObjects()[0]->property("success").toBool()); + } +} + void tst_qqmlapplicationengine::application() { /* This test batches together some tests about running an external application diff --git a/tests/auto/qml/qqmldirparser/data/classname/qmldir b/tests/auto/qml/qqmldirparser/data/classname/qmldir new file mode 100644 index 0000000000..8167e813df --- /dev/null +++ b/tests/auto/qml/qqmldirparser/data/classname/qmldir @@ -0,0 +1,5 @@ +module QtQuick +plugin qtquick2plugin +classname QtQuick2Plugin +typeinfo plugins.qmltypes +designersupported diff --git a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp index 7d154d0ea6..3643ca65c6 100644 --- a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp +++ b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp @@ -325,6 +325,15 @@ void tst_qqmldirparser::parse_data() << QStringList() << (QStringList() << "bar||1|0|true") << false; + + QTest::newRow("classname") + << "classname/qmldir" + << QStringList() + << (QStringList() << "qtquick2plugin|") + << QStringList() + << QStringList() + << QStringList() + << true; } void tst_qqmldirparser::parse() diff --git a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml index 4fc2dab943..54d29dfc94 100644 --- a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml +++ b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml @@ -15,4 +15,12 @@ MyQmlObject onMySignal: { intProperty = a; realProperty = b; colorProperty = c; variantProperty = d; enumProperty = e; qtEnumProperty = f; } onBasicSignal: root.mySignal(10, 19.2, Qt.rgba(1, 1, 0, 1), Qt.rgba(1, 0, 1, 1), MyQmlObject.EnumValue3, Qt.LeftButton) + + property bool emittedQjsValueWasUndefined + property int emittedQjsValueAsInt + + onQjsValueEmittingSignal: { + emittedQjsValueWasUndefined = value === undefined; + emittedQjsValueAsInt = value + } } diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index 47fb2a56e7..1f7f3344ef 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -244,6 +244,7 @@ signals: void signalWithGlobalName(int parseInt); void intChanged(); void qjsvalueChanged(); + void qjsValueEmittingSignal(QJSValue value); public slots: void deleteMe() { delete this; } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 88a8886ecb..89dac33671 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -331,6 +331,8 @@ private slots: void qtbug_54589(); void qtbug_54687(); void stringify_qtbug_50592(); + void instanceof_data(); + void instanceof(); private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -1418,6 +1420,12 @@ void tst_qqmlecmascript::signalParameterTypes() QVERIFY(object->property("enumProperty") == MyQmlObject::EnumValue3); QVERIFY(object->property("qtEnumProperty") == Qt::LeftButton); + emit object->qjsValueEmittingSignal(QJSValue()); + QVERIFY(object->property("emittedQjsValueWasUndefined").toBool()); + emit object->qjsValueEmittingSignal(QJSValue(42)); + QVERIFY(!object->property("emittedQjsValueWasUndefined").toBool()); + QCOMPARE(object->property("emittedQjsValueAsInt").value<int>(), 42); + delete object; } @@ -8113,6 +8121,68 @@ void tst_qqmlecmascript::stringify_qtbug_50592() QCOMPARE(obj->property("source").toString(), QString::fromLatin1("http://example.org/some_nonexistant_image.png")); } +void tst_qqmlecmascript::instanceof_data() +{ + QTest::addColumn<QString>("setupCode"); + QTest::addColumn<QVariant>("expectedValue"); + + // so the way this works is that the name of the test tag defines the test + // to run. the code in setupCode defines code run before the actual test + // (e.g. to create vars). + // + // the expectedValue is either a boolean true or false for whether the two + // operands are indeed an instanceof each other, or a string for the + // expected error message. + QTest::newRow("String instanceof String") + << "" + << QVariant(false); + QTest::newRow("s instanceof String") + << "var s = \"hello\"" + << QVariant(false); + QTest::newRow("objectString instanceof String") + << "var objectString = new String(\"hello\")" + << QVariant(true); + QTest::newRow("o instanceof Object") + << "var o = new Object()" + << QVariant(true); + QTest::newRow("o instanceof String") + << "var o = new Object()" + << QVariant(false); + QTest::newRow("true instanceof true") + << "" + << QVariant("TypeError: Type error"); + QTest::newRow("1 instanceof Math") + << "" + << QVariant("TypeError: Type error"); + QTest::newRow("date instanceof Date") + << "var date = new Date" + << QVariant(true); + QTest::newRow("date instanceof Object") + << "var date = new Date" + << QVariant(true); + QTest::newRow("date instanceof String") + << "var date = new Date" + << QVariant(false); +} + +void tst_qqmlecmascript::instanceof() +{ + QFETCH(QString, setupCode); + QFETCH(QVariant, expectedValue); + + QJSEngine engine; + QJSValue ret = engine.evaluate(setupCode + ";\n" + QTest::currentDataTag()); + + if (expectedValue.type() == QMetaType::Bool) { + bool returnValue = ret.toBool(); + QVERIFY2(!ret.isError(), qPrintable(ret.toString())); + QCOMPARE(returnValue, expectedValue.toBool()); + } else { + QVERIFY2(ret.isError(), qPrintable(ret.toString())); + QCOMPARE(ret.toString(), expectedValue.toString()); + } +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" diff --git a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp index acda06c8d8..3f6c200027 100644 --- a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp +++ b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp @@ -49,6 +49,7 @@ private slots: void nonQmlContextedObject(); void types(); void chaining(); + void messageTypes(); private: QQmlEngine engine; @@ -62,14 +63,14 @@ void tst_qqmlinfo::qmlObject() QVERIFY(object != 0); QString message = component.url().toString() + ":3:1: QML QtObject: Test Message"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(message)); + QTest::ignoreMessage(QtInfoMsg, qPrintable(message)); qmlInfo(object) << "Test Message"; QObject *nested = qvariant_cast<QObject *>(object->property("nested")); QVERIFY(nested != 0); message = component.url().toString() + ":6:13: QML QtObject: Second Test Message"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(message)); + QTest::ignoreMessage(QtInfoMsg, qPrintable(message)); qmlInfo(nested) << "Second Test Message"; } @@ -86,11 +87,11 @@ void tst_qqmlinfo::nestedQmlObject() QVERIFY(nested2 != 0); QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(message)); + QTest::ignoreMessage(QtInfoMsg, qPrintable(message)); qmlInfo(nested) << "Outer Object"; message = testFileUrl("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(message)); + QTest::ignoreMessage(QtInfoMsg, qPrintable(message)); qmlInfo(nested2) << "Inner Object"; } @@ -107,28 +108,28 @@ void tst_qqmlinfo::nestedComponent() QVERIFY(nested2 != 0); QString message = component.url().toString() + ":10:9: QML NestedObject: Complex Object"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(message)); + QTest::ignoreMessage(QtInfoMsg, qPrintable(message)); qmlInfo(nested) << "Complex Object"; message = component.url().toString() + ":16:9: QML Image: Simple Object"; - QTest::ignoreMessage(QtWarningMsg, qPrintable(message)); + QTest::ignoreMessage(QtInfoMsg, qPrintable(message)); qmlInfo(nested2) << "Simple Object"; } void tst_qqmlinfo::nonQmlObject() { QObject object; - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: QML QtObject: Test Message"); qmlInfo(&object) << "Test Message"; QTimer nonQmlObject; - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QTimer: Test Message"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: QML QTimer: Test Message"); qmlInfo(&nonQmlObject) << "Test Message"; } void tst_qqmlinfo::nullObject() { - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: Null Object Test Message"); qmlInfo(0) << "Null Object Test Message"; } @@ -137,50 +138,50 @@ void tst_qqmlinfo::nonQmlContextedObject() QObject object; QQmlContext context(&engine); QQmlEngine::setContextForObject(&object, &context); - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: QML QtObject: Test Message"); qmlInfo(&object) << "Test Message"; } void tst_qqmlinfo::types() { - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: false"); qmlInfo(0) << false; - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: 1.1"); qmlInfo(0) << 1.1; - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: 1.2"); qmlInfo(0) << 1.2f; - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: 15"); qmlInfo(0) << 15; - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: 'b'"); qmlInfo(0) << QChar('b'); - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\""); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: \"Qt\""); qmlInfo(0) << QByteArray("Qt"); - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: true"); qmlInfo(0) << bool(true); //### do we actually want QUrl to show up in the output? //### why the extra space at the end? - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QUrl(\"http://www.qt-project.org\") "); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: QUrl(\"http://www.qt-project.org\") "); qmlInfo(0) << QUrl("http://www.qt-project.org"); //### should this be quoted? - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: hello"); qmlInfo(0) << QLatin1String("hello"); //### should this be quoted? - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: World"); QString str("Hello World"); QStringRef ref(&str, 6, 5); qmlInfo(0) << ref; //### should this be quoted? - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick"); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: Quick"); qmlInfo(0) << QString ("Quick"); } @@ -188,7 +189,7 @@ void tst_qqmlinfo::chaining() { QString str("Hello World"); QStringRef ref(&str, 6, 5); - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' World \"Qt\" true Quick QUrl(\"http://www.qt-project.org\") "); + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' World \"Qt\" true Quick QUrl(\"http://www.qt-project.org\") "); qmlInfo(0) << false << ' ' << 1.1 << ' ' << 1.2f << ' ' @@ -202,6 +203,19 @@ void tst_qqmlinfo::chaining() << QUrl("http://www.qt-project.org"); } +// Ensure that messages of different types are sent with the correct QtMsgType. +void tst_qqmlinfo::messageTypes() +{ + QTest::ignoreMessage(QtDebugMsg, "<Unknown File>: debug"); + qmlDebug(0) << QLatin1String("debug"); + + QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: info"); + qmlInfo(0) << QLatin1String("info"); + + QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: warning"); + qmlWarning(0) << QLatin1String("warning"); +} + QTEST_MAIN(tst_qqmlinfo) #include "tst_qqmlinfo.moc" diff --git a/tests/auto/qml/qqmllocale/data/date.qml b/tests/auto/qml/qqmllocale/data/date.qml index 3f58497d22..d8cd043cdf 100644 --- a/tests/auto/qml/qqmllocale/data/date.qml +++ b/tests/auto/qml/qqmllocale/data/date.qml @@ -7,6 +7,7 @@ QtObject { locale = Qt.locale(l) } + // Month number 9 is October: JS Date()'s month range is 0 to 11. function toLocaleString(fmt) { var d = new Date(2011, 9, 7, 18, 53, 48, 345); if (fmt < 0) diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp index 4d2cae1523..d0ce83b997 100644 --- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp +++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp @@ -640,9 +640,7 @@ void tst_qqmllocale::dateToLocaleString() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11 - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); @@ -701,9 +699,7 @@ void tst_qqmllocale::dateToLocaleStringFormatted() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11 - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); @@ -732,9 +728,7 @@ void tst_qqmllocale::dateToLocaleDateString() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11 - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); @@ -793,9 +787,7 @@ void tst_qqmllocale::dateToLocaleDateStringFormatted() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11 - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); @@ -824,9 +816,7 @@ void tst_qqmllocale::dateToLocaleTimeString() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11 - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); @@ -885,9 +875,7 @@ void tst_qqmllocale::dateToLocaleTimeStringFormatted() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11 - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); @@ -927,21 +915,20 @@ void tst_qqmllocale::dateFromLocaleString() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); QLocale l(locale); + const QString localeText(l.toString(dt, format)); QVariant val; QMetaObject::invokeMethod(obj, "fromLocaleString", Qt::DirectConnection, Q_RETURN_ARG(QVariant, val), - Q_ARG(QVariant, QVariant(l.toString(dt, format))), + Q_ARG(QVariant, QVariant(localeText)), Q_ARG(QVariant, QVariant(format))); - QDateTime pd = l.toDateTime(l.toString(dt, format), format); + QDateTime pd = l.toDateTime(localeText, format); QCOMPARE(val.toDateTime(), pd); } @@ -971,21 +958,20 @@ void tst_qqmllocale::dateFromLocaleDateString() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); QLocale l(locale); + const QString localeText(l.toString(dt, format)); QVariant val; QMetaObject::invokeMethod(obj, "fromLocaleDateString", Qt::DirectConnection, Q_RETURN_ARG(QVariant, val), - Q_ARG(QVariant, QVariant(l.toString(dt, format))), + Q_ARG(QVariant, QVariant(localeText)), Q_ARG(QVariant, QVariant(format))); - QDate pd = l.toDate(l.toString(dt, format), format); + QDate pd = l.toDate(localeText, format); QCOMPARE(val.toDate(), pd); } @@ -1015,21 +1001,20 @@ void tst_qqmllocale::dateFromLocaleTimeString() QObject *obj = c.create(); QVERIFY(obj); - QDateTime dt; - dt.setDate(QDate(2011, 10, 7)); - dt.setTime(QTime(18, 53, 48, 345)); + const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345)); QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(locale))); QLocale l(locale); + const QString localeText(l.toString(dt, format)); QVariant val; QMetaObject::invokeMethod(obj, "fromLocaleTimeString", Qt::DirectConnection, Q_RETURN_ARG(QVariant, val), - Q_ARG(QVariant, QVariant(l.toString(dt, format))), + Q_ARG(QVariant, QVariant(localeText)), Q_ARG(QVariant, QVariant(format))); - QTime pd = l.toTime(l.toString(dt, format), format); + QTime pd = l.toTime(localeText, format); QCOMPARE(val.toTime(), pd); } @@ -1267,7 +1252,10 @@ QString DateFormatter::getLocalizedForm(const QString &isoTimestamp) // which will require linking to a different library to access that API. static void setTimeZone(const QByteArray &tz) { - qputenv("TZ", tz); + if (tz.isEmpty()) + qunsetenv("TZ"); + else + qputenv("TZ", tz); ::tzset(); // following left for future reference, see comment above @@ -1291,7 +1279,7 @@ void tst_qqmllocale::timeZoneUpdated() QQmlComponent c(&e, testFileUrl("timeZoneUpdated.qml")); QScopedPointer<QObject> obj(c.create()); QVERIFY(obj); - QCOMPARE(obj->property("success").toBool(), true); + QVERIFY(obj->property("success").toBool()); // Change to Indian time setTimeZone(QByteArray("IST-05:30")); @@ -1302,7 +1290,7 @@ void tst_qqmllocale::timeZoneUpdated() setTimeZone(original); QMetaObject::invokeMethod(obj.data(), "resetTimeZone"); - QCOMPARE(obj->property("success").toBool(), true); + QVERIFY(obj->property("success").toBool()); } #endif diff --git a/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp b/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp index e16bfb08a2..3b982d1ab7 100644 --- a/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp +++ b/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp @@ -31,12 +31,6 @@ #include <QtQuick/private/qquicktext_p.h> #include <private/qqmlengine_p.h> #include <QtCore/qcryptographichash.h> -/* -#include <QtWebKit/qwebpage.h> -#include <QtWebKit/qwebframe.h> -#include <QtWebKit/qwebdatabase.h> -#include <QtWebKit/qwebsecurityorigin.h> -*/ #include <QtSql/qsqldatabase.h> #include <QtCore/qdir.h> #include <QtCore/qfile.h> @@ -150,42 +144,6 @@ void tst_qqmlsqldatabase::testQml_data() // test - in which case increment total_databases_created_by_tests above. } -/* -class QWebPageWithJavaScriptConsoleMessages : public QWebPage { -public: - void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) - { - qWarning() << sourceID << ":" << lineNumber << ":" << message; - } -}; - -void tst_qqmlsqldatabase::validateAgainstWebkit() -{ - // Validates tests against WebKit (HTML5) support. - // - QFETCH(QString, jsfile); - QFETCH(QString, result); - QFETCH(int, databases); - - QFile f(jsfile); - QVERIFY(f.open(QIODevice::ReadOnly)); - QString js=f.readAll(); - - QWebPageWithJavaScriptConsoleMessages webpage; - webpage.settings()->setOfflineStoragePath(dbDir()); - webpage.settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); - - QEXPECT_FAIL("","WebKit doesn't support openDatabaseSync yet", Continue); - QCOMPARE(webpage.mainFrame()->evaluateJavaScript(js).toString(),result); - - QTest::qWait(100); // WebKit crashes if you quit it too fast - - QWebSecurityOrigin origin = webpage.mainFrame()->securityOrigin(); - QList<QWebDatabase> dbs = origin.databases(); - QCOMPARE(dbs.count(), databases); -} -*/ - void tst_qqmlsqldatabase::testQml() { if (engine->offlineStoragePath().isEmpty()) |