summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-04-22 03:18:13 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-04-22 03:18:13 (GMT)
commitfb94bfda66ac8767c96cb521a1f77c6b8be5bb95 (patch)
treeb4fdd4165ff33ed78d9485c089afb2e11b526e18 /tests/auto/declarative
parent6b03492619243a1ede75ba324b8422304c662231 (diff)
parente6b5d2a4df73aa26812e26daa3199443bd84cc90 (diff)
downloadQt-fb94bfda66ac8767c96cb521a1f77c6b8be5bb95.zip
Qt-fb94bfda66ac8767c96cb521a1f77c6b8be5bb95.tar.gz
Qt-fb94bfda66ac8767c96cb521a1f77c6b8be5bb95.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp86
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.errors.txt1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.qml3
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp1
-rw-r--r--tests/auto/declarative/qdeclarativeqt/data/atob.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeqt/data/btoa.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp83
7 files changed, 163 insertions, 24 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"
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.errors.txt
new file mode 100644
index 0000000..dfa7a36
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.errors.txt
@@ -0,0 +1 @@
+1:1:module "Test" version 0.1 is not installed
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.qml b/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.qml
new file mode 100644
index 0000000..18514b1
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/importNonExistOlder.qml
@@ -0,0 +1,3 @@
+import Test 0.1
+
+MyTypeObject { }
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index c1397de..c39e6f7 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -277,6 +277,7 @@ void tst_qdeclarativelanguage::errors_data()
QTest::newRow("importVersionMissing (builtin)") << "importVersionMissingBuiltIn.qml" << "importVersionMissingBuiltIn.errors.txt" << false;
QTest::newRow("importVersionMissing (installed)") << "importVersionMissingInstalled.qml" << "importVersionMissingInstalled.errors.txt" << false;
QTest::newRow("importNonExist (installed)") << "importNonExist.qml" << "importNonExist.errors.txt" << false;
+ QTest::newRow("importNonExistOlder (installed)") << "importNonExistOlder.qml" << "importNonExistOlder.errors.txt" << false;
QTest::newRow("importNewerVersion (installed)") << "importNewerVersion.qml" << "importNewerVersion.errors.txt" << false;
QTest::newRow("invalidImportID") << "invalidImportID.qml" << "invalidImportID.errors.txt" << false;
diff --git a/tests/auto/declarative/qdeclarativeqt/data/atob.qml b/tests/auto/declarative/qdeclarativeqt/data/atob.qml
new file mode 100644
index 0000000..8355fa5
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeqt/data/atob.qml
@@ -0,0 +1,7 @@
+import Qt 4.7
+
+QtObject {
+ property string test1: Qt.atob()
+ property string test2: Qt.atob("SGVsbG8gd29ybGQh")
+}
+
diff --git a/tests/auto/declarative/qdeclarativeqt/data/btoa.qml b/tests/auto/declarative/qdeclarativeqt/data/btoa.qml
new file mode 100644
index 0000000..c2993ff
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeqt/data/btoa.qml
@@ -0,0 +1,6 @@
+import Qt 4.7
+
+QtObject {
+ property string test1: Qt.btoa()
+ property string test2: Qt.btoa("Hello world!")
+}
diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
index 727d74c..f5d5926 100644
--- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
+++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
@@ -74,6 +74,8 @@ private slots:
void consoleLog();
void formatting();
void isQtObject();
+ void btoa();
+ void atob();
private:
QDeclarativeEngine engine;
@@ -102,8 +104,8 @@ void tst_qdeclarativeqt::rgba()
{
QDeclarativeComponent component(&engine, TEST_FILE("rgba.qml"));
- QString warning1 = component.url().toString() + ":6: Error: expected 3 or 4 parameters";
- QString warning2 = component.url().toString() + ":7: Error: expected 3 or 4 parameters";
+ QString warning1 = component.url().toString() + ":6: Error: Qt.rgba(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":7: Error: Qt.rgba(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -125,8 +127,8 @@ void tst_qdeclarativeqt::hsla()
{
QDeclarativeComponent component(&engine, TEST_FILE("hsla.qml"));
- QString warning1 = component.url().toString() + ":6: Error: expected 3 or 4 parameters";
- QString warning2 = component.url().toString() + ":7: Error: expected 3 or 4 parameters";
+ QString warning1 = component.url().toString() + ":6: Error: Qt.hsla(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":7: Error: Qt.hsla(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -147,8 +149,8 @@ void tst_qdeclarativeqt::rect()
{
QDeclarativeComponent component(&engine, TEST_FILE("rect.qml"));
- QString warning1 = component.url().toString() + ":6: Error: expected 4 parameters";
- QString warning2 = component.url().toString() + ":7: Error: expected 4 parameters";
+ QString warning1 = component.url().toString() + ":6: Error: Qt.rect(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":7: Error: Qt.rect(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -168,8 +170,8 @@ void tst_qdeclarativeqt::point()
{
QDeclarativeComponent component(&engine, TEST_FILE("point.qml"));
- QString warning1 = component.url().toString() + ":6: Error: expected 2 parameters";
- QString warning2 = component.url().toString() + ":7: Error: expected 2 parameters";
+ QString warning1 = component.url().toString() + ":6: Error: Qt.point(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":7: Error: Qt.point(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -188,8 +190,8 @@ void tst_qdeclarativeqt::size()
{
QDeclarativeComponent component(&engine, TEST_FILE("size.qml"));
- QString warning1 = component.url().toString() + ":7: Error: expected 2 parameters";
- QString warning2 = component.url().toString() + ":8: Error: expected 2 parameters";
+ QString warning1 = component.url().toString() + ":7: Error: Qt.size(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":8: Error: Qt.size(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -209,8 +211,8 @@ void tst_qdeclarativeqt::vector()
{
QDeclarativeComponent component(&engine, TEST_FILE("vector.qml"));
- QString warning1 = component.url().toString() + ":6: Error: expected 3 parameters";
- QString warning2 = component.url().toString() + ":7: Error: expected 3 parameters";
+ QString warning1 = component.url().toString() + ":6: Error: Qt.vector(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":7: Error: Qt.vector(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -229,8 +231,8 @@ void tst_qdeclarativeqt::lighter()
{
QDeclarativeComponent component(&engine, TEST_FILE("lighter.qml"));
- QString warning1 = component.url().toString() + ":5: Error: expected 1 parameter";
- QString warning2 = component.url().toString() + ":6: Error: expected 1 parameter";
+ QString warning1 = component.url().toString() + ":5: Error: Qt.lighter(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":6: Error: Qt.lighter(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -251,8 +253,8 @@ void tst_qdeclarativeqt::darker()
{
QDeclarativeComponent component(&engine, TEST_FILE("darker.qml"));
- QString warning1 = component.url().toString() + ":5: Error: expected 1 parameter";
- QString warning2 = component.url().toString() + ":6: Error: expected 1 parameter";
+ QString warning1 = component.url().toString() + ":5: Error: Qt.darker(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":6: Error: Qt.darker(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -273,8 +275,8 @@ void tst_qdeclarativeqt::tint()
{
QDeclarativeComponent component(&engine, TEST_FILE("tint.qml"));
- QString warning1 = component.url().toString() + ":7: Error: expected 2 parameters";
- QString warning2 = component.url().toString() + ":8: Error: expected 2 parameters";
+ QString warning1 = component.url().toString() + ":7: Error: Qt.tint(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":8: Error: Qt.tint(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -322,10 +324,13 @@ void tst_qdeclarativeqt::openUrlExternally()
void tst_qdeclarativeqt::md5()
{
QDeclarativeComponent component(&engine, TEST_FILE("md5.qml"));
+
+ QString warning1 = component.url().toString() + ":4: Error: Qt.md5(): Invalid arguments";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+
QObject *object = component.create();
QVERIFY(object != 0);
- QCOMPARE(object->property("test1").toString(), QLatin1String(QCryptographicHash::hash(QByteArray(), QCryptographicHash::Md5).toHex()));
QCOMPARE(object->property("test2").toString(), QLatin1String(QCryptographicHash::hash("Hello World", QCryptographicHash::Md5).toHex()));
delete object;
@@ -335,8 +340,8 @@ void tst_qdeclarativeqt::createComponent()
{
QDeclarativeComponent component(&engine, TEST_FILE("createComponent.qml"));
- QString warning1 = component.url().toString() + ":9: Error: expected 1 parameter";
- QString warning2 = component.url().toString() + ":10: Error: expected 1 parameter";
+ QString warning1 = component.url().toString() + ":9: Error: Qt.createComponent(): Invalid arguments";
+ QString warning2 = component.url().toString() + ":10: Error: Qt.createComponent(): Invalid arguments";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
@@ -353,11 +358,11 @@ void tst_qdeclarativeqt::createQmlObject()
{
QDeclarativeComponent component(&engine, TEST_FILE("createQmlObject.qml"));
- QString warning1 = component.url().toString() + ":7: Error: expected 2 or 3 parameters";
+ QString warning1 = component.url().toString() + ":7: Error: Qt.createQmlObject(): Invalid arguments";
QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject() failed to create object: " + TEST_FILE("inline").toString() + ":2:10: Blah is not a type\n";
QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject() failed to create object: " + TEST_FILE("main.qml").toString() + ":4:1: Duplicate property name\n";
- QString warning4 = component.url().toString()+ ":9: Error: parent object not found";
- QString warning5 = component.url().toString()+ ":8: Error: expected 2 or 3 parameters";
+ QString warning4 = component.url().toString()+ ":9: Error: Qt.createQmlObject(): Missing parent object";
+ QString warning5 = component.url().toString()+ ":8: Error: Qt.createQmlObject(): Invalid arguments";
QString warning6 = "RunTimeError: Qt.createQmlObject() failed to create object: " + TEST_FILE("inline").toString() + ":3: Cannot assign object type QObject with no default method\n";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
@@ -433,6 +438,36 @@ void tst_qdeclarativeqt::isQtObject()
delete object;
}
+void tst_qdeclarativeqt::btoa()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("btoa.qml"));
+
+ QString warning1 = component.url().toString() + ":4: Error: Qt.btoa(): Invalid arguments";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test2").toString(), QString("SGVsbG8gd29ybGQh"));
+
+ delete object;
+}
+
+void tst_qdeclarativeqt::atob()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("atob.qml"));
+
+ QString warning1 = component.url().toString() + ":4: Error: Qt.atob(): Invalid arguments";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test2").toString(), QString("Hello world!"));
+
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativeqt)
#include "tst_qdeclarativeqt.moc"