Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeqt / tst_qdeclarativeqt.cpp
index b6cebf4..c88e564 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
 ** This file is part of the test suite of the Qt Toolkit.
 **
@@ -35,6 +34,7 @@
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
 #include <QDir>
 #include <QVector3D>
 #include <QCryptographicHash>
-#include <QQuickItem>
+#include <QtQuick/QQuickItem>
 #include <QSignalSpy>
-#include "../shared/util.h"
+#include "../../shared/util.h"
 
-class tst_qdeclarativeqt : public QObject
+class tst_qdeclarativeqt : public QDeclarativeDataTest
 {
     Q_OBJECT
 public:
@@ -78,7 +78,6 @@ private slots:
     void createComponent();
     void createComponent_pragmaLibrary();
     void createQmlObject();
-    void consoleLog();
     void dateTimeConversion();
     void dateTimeFormatting();
     void dateTimeFormatting_data();
@@ -95,14 +94,9 @@ private:
     QDeclarativeEngine engine;
 };
 
-inline QUrl TEST_FILE(const QString &filename)
-{
-    return QUrl::fromLocalFile(TESTDATA(filename));
-}
-
 void tst_qdeclarativeqt::enums()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("enums.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("enums.qml"));
     QObject *object = component.create();
     QVERIFY(object != 0);
 
@@ -116,7 +110,7 @@ void tst_qdeclarativeqt::enums()
 
 void tst_qdeclarativeqt::rgba()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("rgba.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("rgba.qml"));
 
     QString warning1 = component.url().toString() + ":6: Error: Qt.rgba(): Invalid arguments";
     QString warning2 = component.url().toString() + ":7: Error: Qt.rgba(): Invalid arguments";
@@ -139,7 +133,7 @@ void tst_qdeclarativeqt::rgba()
 
 void tst_qdeclarativeqt::hsla()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("hsla.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("hsla.qml"));
 
     QString warning1 = component.url().toString() + ":6: Error: Qt.hsla(): Invalid arguments";
     QString warning2 = component.url().toString() + ":7: Error: Qt.hsla(): Invalid arguments";
@@ -161,7 +155,7 @@ void tst_qdeclarativeqt::hsla()
 
 void tst_qdeclarativeqt::rect()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("rect.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("rect.qml"));
 
     QString warning1 = component.url().toString() + ":6: Error: Qt.rect(): Invalid arguments";
     QString warning2 = component.url().toString() + ":7: Error: Qt.rect(): Invalid arguments";
@@ -182,7 +176,7 @@ void tst_qdeclarativeqt::rect()
 
 void tst_qdeclarativeqt::point()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("point.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("point.qml"));
 
     QString warning1 = component.url().toString() + ":6: Error: Qt.point(): Invalid arguments";
     QString warning2 = component.url().toString() + ":7: Error: Qt.point(): Invalid arguments";
@@ -202,7 +196,7 @@ void tst_qdeclarativeqt::point()
 
 void tst_qdeclarativeqt::size()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("size.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("size.qml"));
 
     QString warning1 = component.url().toString() + ":7: Error: Qt.size(): Invalid arguments";
     QString warning2 = component.url().toString() + ":8: Error: Qt.size(): Invalid arguments";
@@ -223,7 +217,7 @@ void tst_qdeclarativeqt::size()
 
 void tst_qdeclarativeqt::vector()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("vector.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("vector.qml"));
 
     QString warning1 = component.url().toString() + ":6: Error: Qt.vector(): Invalid arguments";
     QString warning2 = component.url().toString() + ":7: Error: Qt.vector(): Invalid arguments";
@@ -243,7 +237,7 @@ void tst_qdeclarativeqt::vector()
 
 void tst_qdeclarativeqt::vector4d()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("vector4.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("vector4.qml"));
 
     QString warning1 = component.url().toString() + ":6: Error: Qt.vector4d(): Invalid arguments";
     QString warning2 = component.url().toString() + ":7: Error: Qt.vector4d(): Invalid arguments";
@@ -263,7 +257,7 @@ void tst_qdeclarativeqt::vector4d()
 
 void tst_qdeclarativeqt::lighter()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("lighter.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("lighter.qml"));
 
     QString warning1 = component.url().toString() + ":5: Error: Qt.lighter(): Invalid arguments";
     QString warning2 = component.url().toString() + ":10: Error: Qt.lighter(): Invalid arguments";
@@ -285,7 +279,7 @@ void tst_qdeclarativeqt::lighter()
 
 void tst_qdeclarativeqt::darker()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("darker.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("darker.qml"));
 
     QString warning1 = component.url().toString() + ":5: Error: Qt.darker(): Invalid arguments";
     QString warning2 = component.url().toString() + ":10: Error: Qt.darker(): Invalid arguments";
@@ -307,7 +301,7 @@ void tst_qdeclarativeqt::darker()
 
 void tst_qdeclarativeqt::tint()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("tint.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("tint.qml"));
 
     QString warning1 = component.url().toString() + ":7: Error: Qt.tint(): Invalid arguments";
     QString warning2 = component.url().toString() + ":8: Error: Qt.tint(): Invalid arguments";
@@ -347,7 +341,7 @@ void tst_qdeclarativeqt::openUrlExternally()
     QDesktopServices::setUrlHandler("test", &handler, "noteCall");
     QDesktopServices::setUrlHandler("file", &handler, "noteCall");
 
-    QDeclarativeComponent component(&engine, TEST_FILE("openUrlExternally.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("openUrlExternally.qml"));
     QObject *object = component.create();
     QVERIFY(object != 0);
     QCOMPARE(handler.called,1);
@@ -356,7 +350,7 @@ void tst_qdeclarativeqt::openUrlExternally()
     object->setProperty("testFile", true);
 
     QCOMPARE(handler.called,2);
-    QCOMPARE(handler.last, TEST_FILE("test.html"));
+    QCOMPARE(handler.last, testFileUrl("test.html"));
 
     QDesktopServices::unsetUrlHandler("test");
     QDesktopServices::unsetUrlHandler("file");
@@ -369,7 +363,7 @@ void tst_qdeclarativeqt::openUrlExternally_pragmaLibrary()
     QDesktopServices::setUrlHandler("test", &handler, "noteCall");
     QDesktopServices::setUrlHandler("file", &handler, "noteCall");
 
-    QDeclarativeComponent component(&engine, TEST_FILE("openUrlExternally_lib.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("openUrlExternally_lib.qml"));
     QObject *object = component.create();
     QVERIFY(object != 0);
     QCOMPARE(handler.called,1);
@@ -378,7 +372,7 @@ void tst_qdeclarativeqt::openUrlExternally_pragmaLibrary()
     object->setProperty("testFile", true);
 
     QCOMPARE(handler.called,2);
-    QCOMPARE(handler.last, TEST_FILE("test.html"));
+    QCOMPARE(handler.last, testFileUrl("test.html"));
 
     QDesktopServices::unsetUrlHandler("test");
     QDesktopServices::unsetUrlHandler("file");
@@ -386,7 +380,7 @@ void tst_qdeclarativeqt::openUrlExternally_pragmaLibrary()
 
 void tst_qdeclarativeqt::md5()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("md5.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("md5.qml"));
 
     QString warning1 = component.url().toString() + ":4: Error: Qt.md5(): Invalid arguments";
     QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
@@ -401,7 +395,7 @@ void tst_qdeclarativeqt::md5()
 
 void tst_qdeclarativeqt::createComponent()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("createComponent.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("createComponent.qml"));
 
     QString warning1 = component.url().toString() + ":9: Error: Qt.createComponent(): Invalid arguments";
     QString warning2 = component.url().toString() + ":10: Error: Qt.createComponent(): Invalid arguments";
@@ -412,7 +406,7 @@ void tst_qdeclarativeqt::createComponent()
     QVERIFY(object != 0);
 
     QCOMPARE(object->property("absoluteUrl").toString(), QString("http://www.example.com/test.qml"));
-    QCOMPARE(object->property("relativeUrl").toString(), TEST_FILE("createComponentData.qml").toString());
+    QCOMPARE(object->property("relativeUrl").toString(), testFileUrl("createComponentData.qml").toString());
 
     delete object;
 }
@@ -420,7 +414,7 @@ void tst_qdeclarativeqt::createComponent()
 void tst_qdeclarativeqt::createComponent_pragmaLibrary()
 {
     // Currently, just loading createComponent_lib.qml causes crash on some platforms
-    QDeclarativeComponent component(&engine, TEST_FILE("createComponent_lib.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("createComponent_lib.qml"));
     QObject *object = component.create();
     QVERIFY(object != 0);
     QCOMPARE(object->property("status").toInt(), int(QDeclarativeComponent::Ready));
@@ -430,15 +424,14 @@ void tst_qdeclarativeqt::createComponent_pragmaLibrary()
 
 void tst_qdeclarativeqt::createQmlObject()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("createQmlObject.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("createQmlObject.qml"));
 
     QString warning1 = component.url().toString() + ":7: Error: Qt.createQmlObject(): Invalid arguments";
-    QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject(): failed to create object: \n    " + TEST_FILE("inline").toString() + ":2:10: Blah is not a type";
-    QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject(): failed to create object: \n    " + TEST_FILE("main.qml").toString() + ":4:1: Duplicate property name";
+    QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject(): failed to create object: \n    " + testFileUrl("inline").toString() + ":2:10: Blah is not a type";
+    QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject(): failed to create object: \n    " + testFileUrl("main.qml").toString() + ":4:14: Duplicate property name";
     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: \n    " + TEST_FILE("inline").toString() + ":3: Cannot assign object type QObject with no default method";
-
+    QString warning6 = "RunTimeError:  Qt.createQmlObject(): failed to create object: \n    " + testFileUrl("inline").toString() + ":3: Cannot assign object type QObject with no default method";
     QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
     QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
     QTest::ignoreMessage(QtWarningMsg, qPrintable(warning3));
@@ -459,29 +452,22 @@ void tst_qdeclarativeqt::createQmlObject()
     delete object;
 }
 
-void tst_qdeclarativeqt::consoleLog()
-{
-    QTest::ignoreMessage(QtDebugMsg, "completed ok");
-    QTest::ignoreMessage(QtDebugMsg, "completed ok");
-    QDeclarativeComponent component(&engine, TEST_FILE("consoleLog.qml"));
-    QObject *object = component.create();
-    QVERIFY(object != 0);
-    delete object;
-}
 
 void tst_qdeclarativeqt::dateTimeConversion()
 {
     QDate date(2008,12,24);
     QTime time(14,15,38,200);
     QDateTime dateTime(date, time);
+    //Note that when converting Date to QDateTime they can argue over historical DST data when converting to local time.
+    //Tests should use UTC or recent dates.
     QDateTime dateTime2(QDate(2852,12,31), QTime(23,59,59,500));
-    QDateTime dateTime3(QDate(1970,1,1), QTime(0,0,0,0));
-    QDateTime dateTime4(QDate(1586,2,2), QTime(0,0,0,0));
-    QDateTime dateTime5(QDate(955,1,1), QTime(0,0,0,0));
-    QDateTime dateTime6(QDate(113,2,24), QTime(14,15,38,200));
+    QDateTime dateTime3(QDate(2000,1,1), QTime(0,0,0,0));
+    QDateTime dateTime4(QDate(2001,2,2), QTime(0,0,0,0));
+    QDateTime dateTime5(QDate(1999,1,1), QTime(2,3,4,0));
+    QDateTime dateTime6(QDate(2008,2,24), QTime(14,15,38,200));
 
     QDeclarativeEngine eng;
-    QDeclarativeComponent component(&eng, TEST_FILE("dateTimeConversion.qml"));
+    QDeclarativeComponent component(&eng, testFileUrl("dateTimeConversion.qml"));
     QObject *obj = component.create();
 
     QCOMPARE(obj->property("qdate").toDate(), date);
@@ -510,7 +496,7 @@ void tst_qdeclarativeqt::dateTimeFormatting()
     eng.rootContext()->setContextProperty("qtime", time);
     eng.rootContext()->setContextProperty("qdatetime", dateTime);
 
-    QDeclarativeComponent component(&eng, TEST_FILE("formatting.qml"));
+    QDeclarativeComponent component(&eng, testFileUrl("formatting.qml"));
 
     QStringList warnings;
     warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Invalid date format"
@@ -583,7 +569,7 @@ void tst_qdeclarativeqt::dateTimeFormattingVariants()
 
     QDeclarativeEngine eng;
     eng.rootContext()->setContextProperty("qvariant", variant);
-    QDeclarativeComponent component(&eng, TEST_FILE("formatting.qml"));
+    QDeclarativeComponent component(&eng, testFileUrl("formatting.qml"));
 
     QStringList warnings;
     warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Invalid date format"
@@ -657,7 +643,7 @@ void tst_qdeclarativeqt::dateTimeFormattingVariants_data()
 
 void tst_qdeclarativeqt::isQtObject()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("isQtObject.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("isQtObject.qml"));
     QObject *object = component.create();
     QVERIFY(object != 0);
 
@@ -672,7 +658,7 @@ void tst_qdeclarativeqt::isQtObject()
 
 void tst_qdeclarativeqt::btoa()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("btoa.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("btoa.qml"));
 
     QString warning1 = component.url().toString() + ":4: Error: Qt.btoa(): Invalid arguments";
     QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
@@ -687,7 +673,7 @@ void tst_qdeclarativeqt::btoa()
 
 void tst_qdeclarativeqt::atob()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("atob.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("atob.qml"));
 
     QString warning1 = component.url().toString() + ":4: Error: Qt.atob(): Invalid arguments";
     QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
@@ -702,7 +688,7 @@ void tst_qdeclarativeqt::atob()
 
 void tst_qdeclarativeqt::fontFamilies()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("fontFamilies.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("fontFamilies.qml"));
 
     QString warning1 = component.url().toString() + ":4: Error: Qt.fontFamilies(): Invalid arguments";
     QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
@@ -718,7 +704,7 @@ void tst_qdeclarativeqt::fontFamilies()
 
 void tst_qdeclarativeqt::quit()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("quit.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("quit.qml"));
 
     QSignalSpy spy(&engine, SIGNAL(quit()));
     QObject *object = component.create();
@@ -730,7 +716,7 @@ void tst_qdeclarativeqt::quit()
 
 void tst_qdeclarativeqt::resolvedUrl()
 {
-    QDeclarativeComponent component(&engine, TEST_FILE("resolvedUrl.qml"));
+    QDeclarativeComponent component(&engine, testFileUrl("resolvedUrl.qml"));
 
     QObject *object = component.create();
     QVERIFY(object != 0);