X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tests%2Fauto%2Fdeclarative%2Fqdeclarativeqt%2Ftst_qdeclarativeqt.cpp;h=c88e56476e7908804e8cacec341619b9b42716f0;hb=45b14259fc0cf704692df1c00da511527d1fba1d;hp=948307d955fbfc7ab6266ccc7c31ed47373d197d;hpb=430ec8741e6c42a9f618b7d5246838bd50edd292;p=profile%2Fivi%2Fqtdeclarative.git diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 948307d..c88e564 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -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$ ** ****************************************************************************/ @@ -50,15 +50,11 @@ #include #include #include -#include +#include #include +#include "../../shared/util.h" -#ifdef Q_OS_SYMBIAN -// In Symbian OS test data is located in applications private dir -#define SRCDIR "." -#endif - -class tst_qdeclarativeqt : public QObject +class tst_qdeclarativeqt : public QDeclarativeDataTest { Q_OBJECT public: @@ -72,6 +68,7 @@ private slots: void point(); void size(); void vector(); + void vector4d(); void lighter(); void darker(); void tint(); @@ -81,7 +78,6 @@ private slots: void createComponent(); void createComponent_pragmaLibrary(); void createQmlObject(); - void consoleLog(); void dateTimeConversion(); void dateTimeFormatting(); void dateTimeFormatting_data(); @@ -92,19 +88,15 @@ private slots: void atob(); void fontFamilies(); void quit(); + void resolvedUrl(); private: QDeclarativeEngine engine; }; -inline QUrl TEST_FILE(const QString &filename) -{ - return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + 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); @@ -118,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"; @@ -141,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"; @@ -163,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"; @@ -184,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"; @@ -204,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"; @@ -225,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,9 +235,29 @@ void tst_qdeclarativeqt::vector() delete object; } +void tst_qdeclarativeqt::vector4d() +{ + 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"; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QVector4D(1, 0, 0.9, 0.6)); + QCOMPARE(qvariant_cast(object->property("test2")), QVector4D(102, -10, -982.1, 10)); + QCOMPARE(qvariant_cast(object->property("test3")), QVector4D()); + QCOMPARE(qvariant_cast(object->property("test4")), QVector4D()); + + delete object; +} + 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"; @@ -267,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"; @@ -289,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"; @@ -329,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); @@ -338,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"); @@ -351,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); @@ -360,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"); @@ -368,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)); @@ -383,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"; @@ -394,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; } @@ -402,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)); @@ -412,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)); @@ -434,36 +445,29 @@ void tst_qdeclarativeqt::createQmlObject() QCOMPARE(object->property("emptyArg").toBool(), true); QCOMPARE(object->property("success").toBool(), true); - QDeclarativeItem *item = qobject_cast(object); + QQuickItem *item = qobject_cast(object); QVERIFY(item != 0); QVERIFY(item->childItems().count() == 1); 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); @@ -492,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" @@ -565,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" @@ -639,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); @@ -654,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)); @@ -669,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)); @@ -684,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)); @@ -700,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(); @@ -710,6 +714,19 @@ void tst_qdeclarativeqt::quit() delete object; } +void tst_qdeclarativeqt::resolvedUrl() +{ + QDeclarativeComponent component(&engine, testFileUrl("resolvedUrl.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("result").toString(), component.url().toString()); + QCOMPARE(object->property("isString").toBool(), true); + + delete object; +} + QTEST_MAIN(tst_qdeclarativeqt) #include "tst_qdeclarativeqt.moc"