/****************************************************************************
**
-** 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.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QDir>
#include <QVector3D>
#include <QCryptographicHash>
-#include <QSGItem>
+#include <QtQuick/QQuickItem>
#include <QSignalSpy>
+#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:
void createComponent();
void createComponent_pragmaLibrary();
void createQmlObject();
- void consoleLog();
void dateTimeConversion();
void dateTimeFormatting();
void dateTimeFormatting_data();
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);
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";
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";
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";
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";
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";
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";
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";
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";
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";
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";
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);
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");
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);
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");
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));
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";
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;
}
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));
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));
QCOMPARE(object->property("emptyArg").toBool(), true);
QCOMPARE(object->property("success").toBool(), true);
- QSGItem *item = qobject_cast<QSGItem *>(object);
+ QQuickItem *item = qobject_cast<QQuickItem *>(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);
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"
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"
void tst_qdeclarativeqt::isQtObject()
{
- QDeclarativeComponent component(&engine, TEST_FILE("isQtObject.qml"));
+ QDeclarativeComponent component(&engine, testFileUrl("isQtObject.qml"));
QObject *object = component.create();
QVERIFY(object != 0);
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));
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));
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));
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();
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"