diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-22 01:18:07 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-22 01:18:07 (GMT) |
commit | 141b48584633189c0fa83e9ca04f017048a5c5ff (patch) | |
tree | d3659b5fe6af575a9a996885ba8bcebcf93d2fe8 /tests/auto/declarative/qdeclarativeengine | |
parent | 8d467e0ab02abfae1e0ac851c236485231aa682f (diff) | |
download | Qt-141b48584633189c0fa83e9ca04f017048a5c5ff.zip Qt-141b48584633189c0fa83e9ca04f017048a5c5ff.tar.gz Qt-141b48584633189c0fa83e9ca04f017048a5c5ff.tar.bz2 |
Autotest
Diffstat (limited to 'tests/auto/declarative/qdeclarativeengine')
-rw-r--r-- | tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp index 5d8a52d..ee320aa 100644 --- a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp +++ b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp @@ -63,6 +63,8 @@ private slots: void contextForObject(); void offlineStoragePath(); void clearComponentCache(); + void outputWarningsToStandardError(); + void objectOwnership(); }; void tst_qdeclarativeengine::rootContext() @@ -101,6 +103,7 @@ void tst_qdeclarativeengine::networkAccessManager() engine = new QDeclarativeEngine; NetworkAccessManagerFactory factory; engine->setNetworkAccessManagerFactory(&factory); + QVERIFY(engine->networkAccessManagerFactory() == &factory); QVERIFY(engine->networkAccessManager() == factory.manager); delete engine; } @@ -235,6 +238,89 @@ void tst_qdeclarativeengine::clearComponentCache() } } +static QStringList warnings; +static void msgHandler(QtMsgType, const char *warning) +{ + warnings << QString::fromUtf8(warning); +} + +void tst_qdeclarativeengine::outputWarningsToStandardError() +{ + QDeclarativeEngine engine; + + QCOMPARE(engine.outputWarningsToStandardError(), true); + + QDeclarativeComponent c(&engine); + c.setData("import Qt 4.7; QtObject { property int a: undefined }", QUrl()); + + QVERIFY(c.isReady() == true); + + warnings.clear(); + QtMsgHandler old = qInstallMsgHandler(msgHandler); + + QObject *o = c.create(); + + qInstallMsgHandler(old); + + QVERIFY(o != 0); + delete o; + + QCOMPARE(warnings.count(), 1); + QCOMPARE(warnings.at(0), QLatin1String("<Unknown File>:1: Unable to assign [undefined] to int")); + warnings.clear(); + + + engine.setOutputWarningsToStandardError(false); + QCOMPARE(engine.outputWarningsToStandardError(), false); + + + old = qInstallMsgHandler(msgHandler); + + o = c.create(); + + qInstallMsgHandler(old); + + QVERIFY(o != 0); + delete o; + + QCOMPARE(warnings.count(), 0); +} + +void tst_qdeclarativeengine::objectOwnership() +{ + { + QCOMPARE(QDeclarativeEngine::objectOwnership(0), QDeclarativeEngine::CppOwnership); + QDeclarativeEngine::setObjectOwnership(0, QDeclarativeEngine::JavaScriptOwnership); + QCOMPARE(QDeclarativeEngine::objectOwnership(0), QDeclarativeEngine::CppOwnership); + } + + { + QObject o; + QCOMPARE(QDeclarativeEngine::objectOwnership(&o), QDeclarativeEngine::CppOwnership); + QDeclarativeEngine::setObjectOwnership(&o, QDeclarativeEngine::JavaScriptOwnership); + QCOMPARE(QDeclarativeEngine::objectOwnership(&o), QDeclarativeEngine::JavaScriptOwnership); + QDeclarativeEngine::setObjectOwnership(&o, QDeclarativeEngine::CppOwnership); + QCOMPARE(QDeclarativeEngine::objectOwnership(&o), QDeclarativeEngine::CppOwnership); + } + + { + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine); + c.setData("import Qt 4.7; QtObject { property QtObject object: QtObject {} }", QUrl()); + + QObject *o = c.create(); + QVERIFY(o != 0); + + QCOMPARE(QDeclarativeEngine::objectOwnership(o), QDeclarativeEngine::CppOwnership); + + QObject *o2 = qvariant_cast<QObject *>(o->property("object")); + QCOMPARE(QDeclarativeEngine::objectOwnership(o2), QDeclarativeEngine::JavaScriptOwnership); + + delete o; + } + +} + QTEST_MAIN(tst_qdeclarativeengine) #include "tst_qdeclarativeengine.moc" |