1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
41 #include <private/qqmlengine_p.h>
46 #include <QFontDatabase>
48 #include <QQmlComponent>
49 #include <QDesktopServices>
52 #include <QCryptographicHash>
53 #include <QtQuick/QQuickItem>
55 #include "../../shared/util.h"
57 class tst_qqmlqt : public QQmlDataTest
75 void openUrlExternally();
76 void openUrlExternally_pragmaLibrary();
78 void createComponent();
79 void createComponent_pragmaLibrary();
80 void createQmlObject();
81 void dateTimeConversion();
82 void dateTimeFormatting();
83 void dateTimeFormatting_data();
84 void dateTimeFormattingVariants();
85 void dateTimeFormattingVariants_data();
97 void tst_qqmlqt::enums()
99 QQmlComponent component(&engine, testFileUrl("enums.qml"));
100 QObject *object = component.create();
101 QVERIFY(object != 0);
103 QCOMPARE(object->property("test1").toInt(), (int)Qt::Key_Escape);
104 QCOMPARE(object->property("test2").toInt(), (int)Qt::DescendingOrder);
105 QCOMPARE(object->property("test3").toInt(), (int)Qt::ElideMiddle);
106 QCOMPARE(object->property("test4").toInt(), (int)Qt::AlignRight);
111 void tst_qqmlqt::rgba()
113 QQmlComponent component(&engine, testFileUrl("rgba.qml"));
115 QString warning1 = component.url().toString() + ":6: Error: Qt.rgba(): Invalid arguments";
116 QString warning2 = component.url().toString() + ":7: Error: Qt.rgba(): Invalid arguments";
117 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
118 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
120 QObject *object = component.create();
121 QVERIFY(object != 0);
124 QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0, 0, 0.8));
125 QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromRgbF(1, 0.5, 0.3, 1));
126 QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor());
127 QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor());
128 QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor::fromRgbF(1, 1, 1, 1));
129 QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor::fromRgbF(0, 0, 0, 0));
134 void tst_qqmlqt::hsla()
136 QQmlComponent component(&engine, testFileUrl("hsla.qml"));
138 QString warning1 = component.url().toString() + ":6: Error: Qt.hsla(): Invalid arguments";
139 QString warning2 = component.url().toString() + ":7: Error: Qt.hsla(): Invalid arguments";
140 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
141 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
143 QObject *object = component.create();
144 QVERIFY(object != 0);
146 QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromHslF(1, 0, 0, 0.8));
147 QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromHslF(1, 0.5, 0.3, 1));
148 QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor());
149 QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor());
150 QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor::fromHslF(1, 1, 1, 1));
151 QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor::fromHslF(0, 0, 0, 0));
156 void tst_qqmlqt::rect()
158 QQmlComponent component(&engine, testFileUrl("rect.qml"));
160 QString warning1 = component.url().toString() + ":6: Error: Qt.rect(): Invalid arguments";
161 QString warning2 = component.url().toString() + ":7: Error: Qt.rect(): Invalid arguments";
162 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
163 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
165 QObject *object = component.create();
166 QVERIFY(object != 0);
168 QCOMPARE(qvariant_cast<QRectF>(object->property("test1")), QRectF(10, 13, 100, 109));
169 QCOMPARE(qvariant_cast<QRectF>(object->property("test2")), QRectF(-10, 13, 100, 109.6));
170 QCOMPARE(qvariant_cast<QRectF>(object->property("test3")), QRectF());
171 QCOMPARE(qvariant_cast<QRectF>(object->property("test4")), QRectF());
172 QCOMPARE(qvariant_cast<QRectF>(object->property("test5")), QRectF(10, 13, 100, -109));
177 void tst_qqmlqt::point()
179 QQmlComponent component(&engine, testFileUrl("point.qml"));
181 QString warning1 = component.url().toString() + ":6: Error: Qt.point(): Invalid arguments";
182 QString warning2 = component.url().toString() + ":7: Error: Qt.point(): Invalid arguments";
183 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
184 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
186 QObject *object = component.create();
187 QVERIFY(object != 0);
189 QCOMPARE(qvariant_cast<QPointF>(object->property("test1")), QPointF(19, 34));
190 QCOMPARE(qvariant_cast<QPointF>(object->property("test2")), QPointF(-3, 109.2));
191 QCOMPARE(qvariant_cast<QPointF>(object->property("test3")), QPointF());
192 QCOMPARE(qvariant_cast<QPointF>(object->property("test4")), QPointF());
197 void tst_qqmlqt::size()
199 QQmlComponent component(&engine, testFileUrl("size.qml"));
201 QString warning1 = component.url().toString() + ":7: Error: Qt.size(): Invalid arguments";
202 QString warning2 = component.url().toString() + ":8: Error: Qt.size(): Invalid arguments";
203 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
204 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
206 QObject *object = component.create();
207 QVERIFY(object != 0);
209 QCOMPARE(qvariant_cast<QSizeF>(object->property("test1")), QSizeF(19, 34));
210 QCOMPARE(qvariant_cast<QSizeF>(object->property("test2")), QSizeF(3, 109.2));
211 QCOMPARE(qvariant_cast<QSizeF>(object->property("test3")), QSizeF(-3, 10));
212 QCOMPARE(qvariant_cast<QSizeF>(object->property("test4")), QSizeF());
213 QCOMPARE(qvariant_cast<QSizeF>(object->property("test5")), QSizeF());
218 void tst_qqmlqt::vector()
220 QQmlComponent component(&engine, testFileUrl("vector.qml"));
222 QString warning1 = component.url().toString() + ":6: Error: Qt.vector(): Invalid arguments";
223 QString warning2 = component.url().toString() + ":7: Error: Qt.vector(): Invalid arguments";
224 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
225 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
227 QObject *object = component.create();
228 QVERIFY(object != 0);
230 QCOMPARE(qvariant_cast<QVector3D>(object->property("test1")), QVector3D(1, 0, 0.9));
231 QCOMPARE(qvariant_cast<QVector3D>(object->property("test2")), QVector3D(102, -10, -982.1));
232 QCOMPARE(qvariant_cast<QVector3D>(object->property("test3")), QVector3D());
233 QCOMPARE(qvariant_cast<QVector3D>(object->property("test4")), QVector3D());
238 void tst_qqmlqt::vector4d()
240 QQmlComponent component(&engine, testFileUrl("vector4.qml"));
242 QString warning1 = component.url().toString() + ":6: Error: Qt.vector4d(): Invalid arguments";
243 QString warning2 = component.url().toString() + ":7: Error: Qt.vector4d(): Invalid arguments";
244 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
245 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
247 QObject *object = component.create();
248 QVERIFY(object != 0);
250 QCOMPARE(qvariant_cast<QVector4D>(object->property("test1")), QVector4D(1, 0, 0.9, 0.6));
251 QCOMPARE(qvariant_cast<QVector4D>(object->property("test2")), QVector4D(102, -10, -982.1, 10));
252 QCOMPARE(qvariant_cast<QVector4D>(object->property("test3")), QVector4D());
253 QCOMPARE(qvariant_cast<QVector4D>(object->property("test4")), QVector4D());
258 void tst_qqmlqt::lighter()
260 QQmlComponent component(&engine, testFileUrl("lighter.qml"));
262 QString warning1 = component.url().toString() + ":5: Error: Qt.lighter(): Invalid arguments";
263 QString warning2 = component.url().toString() + ":10: Error: Qt.lighter(): Invalid arguments";
264 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
265 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
267 QObject *object = component.create();
268 QVERIFY(object != 0);
270 QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).lighter());
271 QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor());
272 QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor::fromRgbF(1, 0.8, 0.3).lighter(180));
273 QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor("red").lighter());
274 QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor());
275 QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor());
280 void tst_qqmlqt::darker()
282 QQmlComponent component(&engine, testFileUrl("darker.qml"));
284 QString warning1 = component.url().toString() + ":5: Error: Qt.darker(): Invalid arguments";
285 QString warning2 = component.url().toString() + ":10: Error: Qt.darker(): Invalid arguments";
286 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
287 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
289 QObject *object = component.create();
290 QVERIFY(object != 0);
292 QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(1, 0.8, 0.3).darker());
293 QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor());
294 QCOMPARE(qvariant_cast<QColor>(object->property("test3")), QColor::fromRgbF(1, 0.8, 0.3).darker(280));
295 QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor("red").darker());
296 QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor());
297 QCOMPARE(qvariant_cast<QColor>(object->property("test6")), QColor());
302 void tst_qqmlqt::tint()
304 QQmlComponent component(&engine, testFileUrl("tint.qml"));
306 QString warning1 = component.url().toString() + ":7: Error: Qt.tint(): Invalid arguments";
307 QString warning2 = component.url().toString() + ":8: Error: Qt.tint(): Invalid arguments";
309 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
310 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
312 QObject *object = component.create();
313 QVERIFY(object != 0);
315 QCOMPARE(qvariant_cast<QColor>(object->property("test1")), QColor::fromRgbF(0, 0, 1));
316 QCOMPARE(qvariant_cast<QColor>(object->property("test2")), QColor::fromRgbF(1, 0, 0));
317 QColor test3 = qvariant_cast<QColor>(object->property("test3"));
318 QCOMPARE(test3.rgba(), 0xFF7F0080);
319 QCOMPARE(qvariant_cast<QColor>(object->property("test4")), QColor());
320 QCOMPARE(qvariant_cast<QColor>(object->property("test5")), QColor());
325 class MyUrlHandler : public QObject
329 MyUrlHandler() : called(0) { }
334 void noteCall(const QUrl &url) { called++; last = url; }
337 void tst_qqmlqt::openUrlExternally()
339 MyUrlHandler handler;
341 QDesktopServices::setUrlHandler("test", &handler, "noteCall");
342 QDesktopServices::setUrlHandler("file", &handler, "noteCall");
344 QQmlComponent component(&engine, testFileUrl("openUrlExternally.qml"));
345 QObject *object = component.create();
346 QVERIFY(object != 0);
347 QCOMPARE(handler.called,1);
348 QCOMPARE(handler.last, QUrl("test:url"));
350 object->setProperty("testFile", true);
352 QCOMPARE(handler.called,2);
353 QCOMPARE(handler.last, testFileUrl("test.html"));
355 QDesktopServices::unsetUrlHandler("test");
356 QDesktopServices::unsetUrlHandler("file");
359 void tst_qqmlqt::openUrlExternally_pragmaLibrary()
361 MyUrlHandler handler;
363 QDesktopServices::setUrlHandler("test", &handler, "noteCall");
364 QDesktopServices::setUrlHandler("file", &handler, "noteCall");
366 QQmlComponent component(&engine, testFileUrl("openUrlExternally_lib.qml"));
367 QObject *object = component.create();
368 QVERIFY(object != 0);
369 QCOMPARE(handler.called,1);
370 QCOMPARE(handler.last, QUrl("test:url"));
372 object->setProperty("testFile", true);
374 QCOMPARE(handler.called,2);
375 QCOMPARE(handler.last, testFileUrl("test.html"));
377 QDesktopServices::unsetUrlHandler("test");
378 QDesktopServices::unsetUrlHandler("file");
381 void tst_qqmlqt::md5()
383 QQmlComponent component(&engine, testFileUrl("md5.qml"));
385 QString warning1 = component.url().toString() + ":4: Error: Qt.md5(): Invalid arguments";
386 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
388 QObject *object = component.create();
389 QVERIFY(object != 0);
391 QCOMPARE(object->property("test2").toString(), QLatin1String(QCryptographicHash::hash("Hello World", QCryptographicHash::Md5).toHex()));
396 void tst_qqmlqt::createComponent()
399 QQmlComponent component(&engine, testFileUrl("createComponent.qml"));
401 QString warning1 = component.url().toString() + ":9: Error: Qt.createComponent(): Invalid arguments";
402 QString warning2 = component.url().toString() + ":10: Error: Qt.createComponent(): Invalid arguments";
403 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
404 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
406 QObject *object = component.create();
407 QVERIFY(object != 0);
409 QCOMPARE(object->property("absoluteUrl").toString(), QString("http://www.example.com/test.qml"));
410 QCOMPARE(object->property("relativeUrl").toString(), testFileUrl("createComponentData.qml").toString());
412 QTRY_VERIFY(object->property("asyncResult").toBool());
417 // simultaneous sync and async compilation
419 QQmlComponent component(&engine, testFileUrl("createComponent.2.qml"));
420 QObject *object = component.create();
421 QVERIFY(object != 0);
422 QTRY_VERIFY(object->property("success").toBool());
427 void tst_qqmlqt::createComponent_pragmaLibrary()
429 // Currently, just loading createComponent_lib.qml causes crash on some platforms
430 QQmlComponent component(&engine, testFileUrl("createComponent_lib.qml"));
431 QObject *object = component.create();
432 QVERIFY(object != 0);
433 QCOMPARE(object->property("status").toInt(), int(QQmlComponent::Ready));
434 QCOMPARE(object->property("readValue").toInt(), int(1913));
438 void tst_qqmlqt::createQmlObject()
440 QQmlComponent component(&engine, testFileUrl("createQmlObject.qml"));
442 QString warning1 = component.url().toString() + ":7: Error: Qt.createQmlObject(): Invalid arguments";
443 QString warning2 = component.url().toString()+ ":10: Error: Qt.createQmlObject(): failed to create object: \n " + testFileUrl("inline").toString() + ":2:10: Blah is not a type";
444 QString warning3 = component.url().toString()+ ":11: Error: Qt.createQmlObject(): failed to create object: \n " + testFileUrl("main.qml").toString() + ":4:14: Duplicate property name";
445 QString warning4 = component.url().toString()+ ":9: Error: Qt.createQmlObject(): Missing parent object";
446 QString warning5 = component.url().toString()+ ":8: Error: Qt.createQmlObject(): Invalid arguments";
447 QString warning6 = "RunTimeError: Qt.createQmlObject(): failed to create object: \n " + testFileUrl("inline").toString() + ":3: Cannot assign object type QObject with no default method";
448 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
449 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
450 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning3));
451 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning4));
452 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning5));
453 QTest::ignoreMessage(QtDebugMsg, qPrintable(warning6));
455 QObject *object = component.create();
456 QVERIFY(object != 0);
458 QCOMPARE(object->property("emptyArg").toBool(), true);
459 QCOMPARE(object->property("success").toBool(), true);
461 QQuickItem *item = qobject_cast<QQuickItem *>(object);
463 QVERIFY(item->childItems().count() == 1);
469 void tst_qqmlqt::dateTimeConversion()
471 QDate date(2008,12,24);
472 QTime time(14,15,38,200);
473 QDateTime dateTime(date, time);
474 //Note that when converting Date to QDateTime they can argue over historical DST data when converting to local time.
475 //Tests should use UTC or recent dates.
476 QDateTime dateTime2(QDate(2852,12,31), QTime(23,59,59,500));
477 QDateTime dateTime3(QDate(2000,1,1), QTime(0,0,0,0));
478 QDateTime dateTime4(QDate(2001,2,2), QTime(0,0,0,0));
479 QDateTime dateTime5(QDate(1999,1,1), QTime(2,3,4,0));
480 QDateTime dateTime6(QDate(2008,2,24), QTime(14,15,38,200));
483 QQmlComponent component(&eng, testFileUrl("dateTimeConversion.qml"));
484 QObject *obj = component.create();
486 QCOMPARE(obj->property("qdate").toDate(), date);
487 QCOMPARE(obj->property("qtime").toTime(), time);
488 QCOMPARE(obj->property("qdatetime").toDateTime(), dateTime);
489 QCOMPARE(obj->property("qdatetime2").toDateTime(), dateTime2);
490 QCOMPARE(obj->property("qdatetime3").toDateTime(), dateTime3);
491 QCOMPARE(obj->property("qdatetime4").toDateTime(), dateTime4);
492 QCOMPARE(obj->property("qdatetime5").toDateTime(), dateTime5);
493 QCOMPARE(obj->property("qdatetime6").toDateTime(), dateTime6);
496 void tst_qqmlqt::dateTimeFormatting()
498 QFETCH(QString, method);
499 QFETCH(QStringList, inputProperties);
500 QFETCH(QStringList, expectedResults);
502 QDate date(2008,12,24);
503 QTime time(14,15,38,200);
504 QDateTime dateTime(date, time);
508 eng.rootContext()->setContextProperty("qdate", date);
509 eng.rootContext()->setContextProperty("qtime", time);
510 eng.rootContext()->setContextProperty("qdatetime", dateTime);
512 QQmlComponent component(&eng, testFileUrl("formatting.qml"));
514 QStringList warnings;
515 warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Invalid date format"
516 << component.url().toString() + ":36: Error: Qt.formatDate(): Invalid arguments"
517 << component.url().toString() + ":40: Error: Qt.formatTime(): Invalid time format"
518 << component.url().toString() + ":39: Error: Qt.formatTime(): Invalid arguments"
519 << component.url().toString() + ":43: Error: Qt.formatDateTime(): Invalid datetime format"
520 << component.url().toString() + ":42: Error: Qt.formatDateTime(): Invalid arguments";
522 foreach (const QString &warning, warnings)
523 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
525 QObject *object = component.create();
526 QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString()));
527 QVERIFY(object != 0);
529 QVERIFY(inputProperties.count() > 0);
531 foreach(const QString &prop, inputProperties) {
532 QVERIFY(QMetaObject::invokeMethod(object, method.toUtf8().constData(),
533 Q_RETURN_ARG(QVariant, result),
534 Q_ARG(QVariant, prop)));
535 QStringList output = result.toStringList();
536 QCOMPARE(output.size(), expectedResults.size());
537 for (int i=0; i<output.count(); i++)
538 QCOMPARE(output[i], expectedResults[i]);
544 void tst_qqmlqt::dateTimeFormatting_data()
546 QTest::addColumn<QString>("method");
547 QTest::addColumn<QStringList>("inputProperties");
548 QTest::addColumn<QStringList>("expectedResults");
550 QDate date(2008,12,24);
551 QTime time(14,15,38,200);
552 QDateTime dateTime(date, time);
554 QTest::newRow("formatDate")
556 << (QStringList() << "dateFromString" << "jsdate" << "qdate" << "qdatetime")
557 << (QStringList() << date.toString(Qt::DefaultLocaleShortDate)
558 << date.toString(Qt::DefaultLocaleLongDate)
559 << date.toString("ddd MMMM d yy"));
561 QTest::newRow("formatTime")
563 << (QStringList() << "jsdate" << "qtime" << "qdatetime")
564 << (QStringList() << time.toString(Qt::DefaultLocaleShortDate)
565 << time.toString(Qt::DefaultLocaleLongDate)
566 << time.toString("H:m:s a")
567 << time.toString("hh:mm:ss.zzz"));
569 QTest::newRow("formatDateTime")
571 << (QStringList() << "jsdate" << "qdatetime")
572 << (QStringList() << dateTime.toString(Qt::DefaultLocaleShortDate)
573 << dateTime.toString(Qt::DefaultLocaleLongDate)
574 << dateTime.toString("M/d/yy H:m:s a"));
577 void tst_qqmlqt::dateTimeFormattingVariants()
579 QFETCH(QString, method);
580 QFETCH(QVariant, variant);
581 QFETCH(QStringList, expectedResults);
584 eng.rootContext()->setContextProperty("qvariant", variant);
585 QQmlComponent component(&eng, testFileUrl("formatting.qml"));
587 QStringList warnings;
588 warnings << component.url().toString() + ":37: Error: Qt.formatDate(): Invalid date format"
589 << component.url().toString() + ":36: Error: Qt.formatDate(): Invalid arguments"
590 << component.url().toString() + ":40: Error: Qt.formatTime(): Invalid time format"
591 << component.url().toString() + ":39: Error: Qt.formatTime(): Invalid arguments"
592 << component.url().toString() + ":43: Error: Qt.formatDateTime(): Invalid datetime format"
593 << component.url().toString() + ":42: Error: Qt.formatDateTime(): Invalid arguments";
595 foreach (const QString &warning, warnings)
596 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
598 QObject *object = component.create();
599 QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString()));
600 QVERIFY(object != 0);
603 QVERIFY(QMetaObject::invokeMethod(object, method.toUtf8().constData(),
604 Q_RETURN_ARG(QVariant, result),
605 Q_ARG(QVariant, QString(QLatin1String("qvariant")))));
606 QStringList output = result.toStringList();
607 QCOMPARE(output, expectedResults);
612 void tst_qqmlqt::dateTimeFormattingVariants_data()
614 QTest::addColumn<QString>("method");
615 QTest::addColumn<QVariant>("variant");
616 QTest::addColumn<QStringList>("expectedResults");
620 QTime time(11, 16, 39, 755);
621 temporary = QDateTime(QDate(1970,1,1), time);
622 QTest::newRow("formatDate, qtime") << "formatDate" << QVariant::fromValue(time) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
623 QTest::newRow("formatDateTime, qtime") << "formatDateTime" << QVariant::fromValue(time) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
624 QTest::newRow("formatTime, qtime") << "formatTime" << QVariant::fromValue(time) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
626 QDate date(2011,5,31);
627 temporary = QDateTime(date);
628 QTest::newRow("formatDate, qdate") << "formatDate" << QVariant::fromValue(date) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
629 QTest::newRow("formatDateTime, qdate") << "formatDateTime" << QVariant::fromValue(date) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
630 QTest::newRow("formatTime, qdate") << "formatTime" << QVariant::fromValue(date) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
632 QDateTime dateTime(date, time);
633 temporary = dateTime;
634 QTest::newRow("formatDate, qdatetime") << "formatDate" << QVariant::fromValue(dateTime) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
635 QTest::newRow("formatDateTime, qdatetime") << "formatDateTime" << QVariant::fromValue(dateTime) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
636 QTest::newRow("formatTime, qdatetime") << "formatTime" << QVariant::fromValue(dateTime) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
638 QString string(QLatin1String("2011/05/31 11:16:39.755"));
639 temporary = QDateTime::fromString(string, "yyyy/MM/dd HH:mm:ss.zzz");
640 QTest::newRow("formatDate, qstring") << "formatDate" << QVariant::fromValue(string) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
641 QTest::newRow("formatDateTime, qstring") << "formatDateTime" << QVariant::fromValue(string) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
642 QTest::newRow("formatTime, qstring") << "formatTime" << QVariant::fromValue(string) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
644 QColor color(Qt::red);
645 temporary = QVariant::fromValue(color).toDateTime();
646 QTest::newRow("formatDate, qcolor") << "formatDate" << QVariant::fromValue(color) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
647 QTest::newRow("formatDateTime, qcolor") << "formatDateTime" << QVariant::fromValue(color) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
648 QTest::newRow("formatTime, qcolor") << "formatTime" << QVariant::fromValue(color) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
651 temporary = QVariant::fromValue(integer).toDateTime();
652 QTest::newRow("formatDate, int") << "formatDate" << QVariant::fromValue(integer) << (QStringList() << temporary.date().toString(Qt::DefaultLocaleShortDate) << temporary.date().toString(Qt::DefaultLocaleLongDate) << temporary.date().toString("ddd MMMM d yy"));
653 QTest::newRow("formatDateTime, int") << "formatDateTime" << QVariant::fromValue(integer) << (QStringList() << temporary.toString(Qt::DefaultLocaleShortDate) << temporary.toString(Qt::DefaultLocaleLongDate) << temporary.toString("M/d/yy H:m:s a"));
654 QTest::newRow("formatTime, int") << "formatTime" << QVariant::fromValue(integer) << (QStringList() << temporary.time().toString(Qt::DefaultLocaleShortDate) << temporary.time().toString(Qt::DefaultLocaleLongDate) << temporary.time().toString("H:m:s a") << temporary.time().toString("hh:mm:ss.zzz"));
657 void tst_qqmlqt::isQtObject()
659 QQmlComponent component(&engine, testFileUrl("isQtObject.qml"));
660 QObject *object = component.create();
661 QVERIFY(object != 0);
663 QCOMPARE(object->property("test1").toBool(), true);
664 QCOMPARE(object->property("test2").toBool(), false);
665 QCOMPARE(object->property("test3").toBool(), false);
666 QCOMPARE(object->property("test4").toBool(), false);
667 QCOMPARE(object->property("test5").toBool(), false);
672 void tst_qqmlqt::btoa()
674 QQmlComponent component(&engine, testFileUrl("btoa.qml"));
676 QString warning1 = component.url().toString() + ":4: Error: Qt.btoa(): Invalid arguments";
677 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
679 QObject *object = component.create();
680 QVERIFY(object != 0);
682 QCOMPARE(object->property("test2").toString(), QString("SGVsbG8gd29ybGQh"));
687 void tst_qqmlqt::atob()
689 QQmlComponent component(&engine, testFileUrl("atob.qml"));
691 QString warning1 = component.url().toString() + ":4: Error: Qt.atob(): Invalid arguments";
692 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
694 QObject *object = component.create();
695 QVERIFY(object != 0);
697 QCOMPARE(object->property("test2").toString(), QString("Hello world!"));
702 void tst_qqmlqt::fontFamilies()
704 QQmlComponent component(&engine, testFileUrl("fontFamilies.qml"));
706 QString warning1 = component.url().toString() + ":4: Error: Qt.fontFamilies(): Invalid arguments";
707 QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
709 QObject *object = component.create();
710 QVERIFY(object != 0);
712 QFontDatabase database;
713 QCOMPARE(object->property("test2"), QVariant::fromValue(database.families()));
718 void tst_qqmlqt::quit()
720 QQmlComponent component(&engine, testFileUrl("quit.qml"));
722 QSignalSpy spy(&engine, SIGNAL(quit()));
723 QObject *object = component.create();
724 QVERIFY(object != 0);
725 QCOMPARE(spy.count(), 1);
730 void tst_qqmlqt::resolvedUrl()
732 QQmlComponent component(&engine, testFileUrl("resolvedUrl.qml"));
734 QObject *object = component.create();
735 QVERIFY(object != 0);
737 QCOMPARE(object->property("result").toString(), component.url().toString());
738 QCOMPARE(object->property("isString").toBool(), true);
743 QTEST_MAIN(tst_qqmlqt)
745 #include "tst_qqmlqt.moc"