From 5f19daab6baba7d09853058355a66090a3781430 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 13:04:03 +1000 Subject: Support Visual (interactive) tests without using images for confirmation. --- .../selftest_noimages/data/selftest_noimages.qml | 470 +++++++++++++++++++++ .../visual/selftest_noimages/selftest_noimages.qml | 9 + tests/auto/declarative/visual/tst_visual.cpp | 64 +-- tools/qmlviewer/main.cpp | 5 +- tools/qmlviewer/qfxtester.cpp | 21 +- tools/qmlviewer/qmlviewer.h | 7 +- 6 files changed, 541 insertions(+), 35 deletions(-) create mode 100644 tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml create mode 100644 tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml diff --git a/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml new file mode 100644 index 0000000..3104906 --- /dev/null +++ b/tests/auto/declarative/visual/selftest_noimages/data/selftest_noimages.qml @@ -0,0 +1,470 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + } + Frame { + msec: 32 + } + Frame { + msec: 48 + } + Frame { + msec: 64 + } + Frame { + msec: 80 + } + Frame { + msec: 96 + } + Frame { + msec: 112 + } + Frame { + msec: 128 + } + Frame { + msec: 144 + } + Frame { + msec: 160 + } + Frame { + msec: 176 + } + Frame { + msec: 192 + } + Frame { + msec: 208 + } + Frame { + msec: 224 + } + Frame { + msec: 240 + } + Frame { + msec: 256 + } + Frame { + msec: 272 + } + Frame { + msec: 288 + } + Frame { + msec: 304 + } + Frame { + msec: 320 + } + Frame { + msec: 336 + } + Frame { + msec: 352 + } + Frame { + msec: 368 + } + Frame { + msec: 384 + } + Frame { + msec: 400 + } + Frame { + msec: 416 + } + Frame { + msec: 432 + } + Frame { + msec: 448 + } + Frame { + msec: 464 + } + Frame { + msec: 480 + } + Frame { + msec: 496 + } + Frame { + msec: 512 + } + Frame { + msec: 528 + } + Frame { + msec: 544 + } + Frame { + msec: 560 + } + Frame { + msec: 576 + } + Frame { + msec: 592 + } + Frame { + msec: 608 + } + Frame { + msec: 624 + } + Frame { + msec: 640 + } + Frame { + msec: 656 + } + Frame { + msec: 672 + } + Frame { + msec: 688 + } + Frame { + msec: 704 + } + Frame { + msec: 720 + } + Frame { + msec: 736 + } + Frame { + msec: 752 + } + Frame { + msec: 768 + } + Frame { + msec: 784 + } + Frame { + msec: 800 + } + Frame { + msec: 816 + } + Frame { + msec: 832 + } + Frame { + msec: 848 + } + Frame { + msec: 864 + } + Frame { + msec: 880 + } + Frame { + msec: 896 + } + Frame { + msec: 912 + } + Frame { + msec: 928 + } + Frame { + msec: 944 + } + Frame { + msec: 960 + } + Frame { + msec: 976 + } + Frame { + msec: 992 + } + Frame { + msec: 1008 + } + Frame { + msec: 1024 + } + Frame { + msec: 1040 + } + Frame { + msec: 1056 + } + Frame { + msec: 1072 + } + Frame { + msec: 1088 + } + Frame { + msec: 1104 + } + Frame { + msec: 1120 + } + Frame { + msec: 1136 + } + Frame { + msec: 1152 + } + Frame { + msec: 1168 + } + Frame { + msec: 1184 + } + Frame { + msec: 1200 + } + Frame { + msec: 1216 + } + Frame { + msec: 1232 + } + Frame { + msec: 1248 + } + Frame { + msec: 1264 + } + Frame { + msec: 1280 + } + Frame { + msec: 1296 + } + Frame { + msec: 1312 + } + Frame { + msec: 1328 + } + Frame { + msec: 1344 + } + Frame { + msec: 1360 + } + Mouse { + type: 2 + button: 1 + buttons: 1 + x: 77; y: 7 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1376 + } + Frame { + msec: 1392 + } + Frame { + msec: 1408 + } + Frame { + msec: 1424 + } + Frame { + msec: 1440 + } + Mouse { + type: 3 + button: 1 + buttons: 0 + x: 77; y: 7 + modifiers: 0 + sendToViewport: true + } + Frame { + msec: 1456 + } + Frame { + msec: 1472 + } + Frame { + msec: 1488 + } + Frame { + msec: 1504 + } + Frame { + msec: 1520 + } + Frame { + msec: 1536 + } + Frame { + msec: 1552 + } + Frame { + msec: 1568 + } + Frame { + msec: 1584 + } + Frame { + msec: 1600 + } + Frame { + msec: 1616 + } + Frame { + msec: 1632 + } + Frame { + msec: 1648 + } + Frame { + msec: 1664 + } + Frame { + msec: 1680 + } + Frame { + msec: 1696 + } + Frame { + msec: 1712 + } + Frame { + msec: 1728 + } + Frame { + msec: 1744 + } + Frame { + msec: 1760 + } + Frame { + msec: 1776 + } + Frame { + msec: 1792 + } + Frame { + msec: 1808 + } + Frame { + msec: 1824 + } + Frame { + msec: 1840 + } + Frame { + msec: 1856 + } + Frame { + msec: 1872 + } + Frame { + msec: 1888 + } + Frame { + msec: 1904 + } + Frame { + msec: 1920 + } + Frame { + msec: 1936 + } + Frame { + msec: 1952 + } + Frame { + msec: 1968 + } + Frame { + msec: 1984 + } + Frame { + msec: 2000 + } + Frame { + msec: 2016 + } + Frame { + msec: 2032 + } + Frame { + msec: 2048 + } + Frame { + msec: 2064 + } + Frame { + msec: 2080 + } + Frame { + msec: 2096 + } + Frame { + msec: 2112 + } + Frame { + msec: 2128 + } + Frame { + msec: 2144 + } + Frame { + msec: 2160 + } + Frame { + msec: 2176 + } + Frame { + msec: 2192 + } + Frame { + msec: 2208 + } + Frame { + msec: 2224 + } + Frame { + msec: 2240 + } + Frame { + msec: 2256 + } + Frame { + msec: 2272 + } + Frame { + msec: 2288 + } + Frame { + msec: 2304 + } + Frame { + msec: 2320 + } + Frame { + msec: 2336 + } + Frame { + msec: 2352 + } + Frame { + msec: 2368 + } + Frame { + msec: 2384 + } +} diff --git a/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml new file mode 100644 index 0000000..21a19bc --- /dev/null +++ b/tests/auto/declarative/visual/selftest_noimages/selftest_noimages.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +Text { + property string error: "not pressed" + text: (new Date()).valueOf() + MouseRegion { + anchors.fill: parent + onPressed: error="" + } +} diff --git a/tests/auto/declarative/visual/tst_visual.cpp b/tests/auto/declarative/visual/tst_visual.cpp index a79b6f9..0cd712b 100644 --- a/tests/auto/declarative/visual/tst_visual.cpp +++ b/tests/auto/declarative/visual/tst_visual.cpp @@ -47,7 +47,7 @@ #include #include -enum Mode { Record, Play, TestVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; +enum Mode { Record, RecordNoVisuals, Play, TestVisuals, RemoveVisuals, UpdateVisuals, UpdatePlatformVisuals, Test }; static QString testdir; class tst_visual : public QObject @@ -115,7 +115,7 @@ void tst_visual::visual() QStringList arguments; arguments << "-script" << testdata - << "-scriptopts" << "play,testimages,exitoncomplete,exitonfailure" + << "-scriptopts" << "play,testimages,testerror,exitoncomplete,exitonfailure" << file; QProcess p; p.start(qmlviewer, arguments); @@ -208,38 +208,44 @@ void action(Mode mode, const QString &file) QString testdata = tst_visual::toTestScript(file,mode); - if (Record == mode) { - QStringList arguments; - arguments << "-script" << testdata + QStringList arguments; + switch (mode) { + case Test: + // Don't run qmlviewer + break; + case Record: + arguments << "-script" << testdata + << "-scriptopts" << "record,testimages,saveonexit" + << file; + break; + case RecordNoVisuals: + arguments << "-script" << testdata << "-scriptopts" << "record,saveonexit" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (Play == mode) { - QStringList arguments; - arguments << "-script" << testdata - << "-scriptopts" << "play,testimages,exitoncomplete" + break; + case Play: + arguments << "-script" << testdata + << "-scriptopts" << "play,testimages,testerror,exitoncomplete" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (TestVisuals == mode) { - QStringList arguments; + break; + case TestVisuals: arguments << "-script" << testdata << "-scriptopts" << "play" << file; - QProcess p; - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(tst_visual::viewer(), arguments); - p.waitForFinished(); - } else if (UpdateVisuals == mode || UpdatePlatformVisuals == mode) { - QStringList arguments; - arguments << "-script" << testdata + break; + case UpdateVisuals: + case UpdatePlatformVisuals: + arguments << "-script" << testdata + << "-scriptopts" << "play,record,testimages,exitoncomplete,saveonexit" + << file; + break; + case RemoveVisuals: + arguments << "-script" << testdata << "-scriptopts" << "play,record,exitoncomplete,saveonexit" << file; + break; + } + if (!arguments.isEmpty()) { QProcess p; p.setProcessChannelMode(QProcess::ForwardedChannels); p.start(tst_visual::viewer(), arguments); @@ -278,9 +284,15 @@ int main(int argc, char **argv) } else if (arg == "-record" && (ii + 1) < argc) { mode = Record; file = argv[++ii]; + } else if (arg == "-recordnovisuals" && (ii + 1) < argc) { + mode = RecordNoVisuals; + file = argv[++ii]; } else if (arg == "-testvisuals" && (ii + 1) < argc) { mode = TestVisuals; file = argv[++ii]; + } else if (arg == "-removevisuals" && (ii + 1) < argc) { + mode = RemoveVisuals; + file = argv[++ii]; } else if (arg == "-updatevisuals" && (ii + 1) < argc) { mode = UpdateVisuals; file = argv[++ii]; diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index 23194b2..ac0d732 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -87,7 +87,8 @@ void scriptOptsUsage() qWarning(" options:"); qWarning(" record ................................... record a new script"); qWarning(" play ..................................... playback an existing script"); - qWarning(" testimages ............................... compare images on playback"); + qWarning(" testimages ............................... record images or compare images on playback"); + qWarning(" testerror ................................ test 'error' property of root item on playback"); qWarning(" exitoncomplete ........................... cleanly exit the viewer on script completion"); qWarning(" exitonfailure ............................ immediately exit the viewer on script failure"); qWarning(" saveonexit ............................... save recording on viewer exit"); @@ -235,6 +236,8 @@ int main(int argc, char ** argv) scriptOptions |= QmlViewer::Record; } else if (option == QLatin1String("testimages")) { scriptOptions |= QmlViewer::TestImages; + } else if (option == QLatin1String("testerror")) { + scriptOptions |= QmlViewer::TestErrorProperty; } else if (option == QLatin1String("exitoncomplete")) { scriptOptions |= QmlViewer::ExitOnComplete; } else if (option == QLatin1String("exitonfailure")) { diff --git a/tools/qmlviewer/qfxtester.cpp b/tools/qmlviewer/qfxtester.cpp index 77e8124..287771b 100644 --- a/tools/qmlviewer/qfxtester.cpp +++ b/tools/qmlviewer/qfxtester.cpp @@ -146,6 +146,13 @@ void QmlGraphicsTester::imagefailure() void QmlGraphicsTester::complete() { + if ((options & QmlViewer::TestErrorProperty) && !hasFailed) { + QString e = m_view->root()->property("error").toString(); + if (!e.isEmpty()) { + qWarning() << "Test failed:" << e; + hasFailed = true; + } + } if (options & QmlViewer::ExitOnComplete) QApplication::exit(hasFailed?-1:0); @@ -240,13 +247,15 @@ void QmlGraphicsTester::updateCurrentTime(int msec) QImage img(m_view->width(), m_view->height(), QImage::Format_RGB32); - QPainter p(&img); - m_view->render(&p); + if (options & QmlViewer::TestImages) { + QPainter p(&img); + m_view->render(&p); + } FrameEvent fe; fe.msec = msec; - if (msec == 0) { - // Skip first frame + if (msec == 0 || !(options & QmlViewer::TestImages)) { + // Skip first frame, skip if not doing images } else if (0 == (m_savedFrameEvents.count() % 60)) { fe.image = img; } else { @@ -297,6 +306,8 @@ void QmlGraphicsTester::updateCurrentTime(int msec) QObject *event = testscript->event(testscriptidx); if (QmlGraphicsVisualTestFrame *frame = qobject_cast(event)) { + if ((options & QmlViewer::TestImages) && (options & QmlViewer::Record)) + break; // recording and playing, no point "testing" results if (frame->msec() < msec) { if (options & QmlViewer::TestImages) { qWarning() << "QmlGraphicsTester: Extra frame. Seen:" @@ -304,7 +315,7 @@ void QmlGraphicsTester::updateCurrentTime(int msec) imagefailure(); } } else if (frame->msec() == msec) { - if (frame->hash().toUtf8() != fe.hash.toHex()) { + if (!frame->hash().isEmpty() && frame->hash().toUtf8() != fe.hash.toHex()) { if (options & QmlViewer::TestImages) { qWarning() << "QmlGraphicsTester: Mismatched frame hash. Seen:" << fe.hash.toHex() << "Expected:" diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index a63b938..b366401 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -66,9 +66,10 @@ public: Play = 0x00000001, Record = 0x00000002, TestImages = 0x00000004, - SaveOnExit = 0x00000008, - ExitOnComplete = 0x00000010, - ExitOnFailure = 0x00000020 + TestErrorProperty = 0x00000008, + SaveOnExit = 0x00000010, + ExitOnComplete = 0x00000020, + ExitOnFailure = 0x00000040 }; Q_DECLARE_FLAGS(ScriptOptions, ScriptOption) void setScript(const QString &s) { m_script = s; } -- cgit v0.12 From 0cf756891d94bcfef52c7c18ce4e3e3f7e64e2d7 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Nov 2009 16:10:53 +1000 Subject: Add more Behavior autotests. --- tests/auto/declarative/behaviors/data/simple.qml | 5 ++- tests/auto/declarative/behaviors/tst_behaviors.cpp | 43 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/auto/declarative/behaviors/data/simple.qml b/tests/auto/declarative/behaviors/data/simple.qml index a715f7b..37c3915 100644 --- a/tests/auto/declarative/behaviors/data/simple.qml +++ b/tests/auto/declarative/behaviors/data/simple.qml @@ -6,7 +6,10 @@ Rectangle { id: rect objectName: "MyRect" width: 100; height: 100; color: "green" - x: Behavior { NumberAnimation { duration: 200; } } + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { duration: 200; } + } } MouseRegion { id: clicker diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 9803a9d..7bdc82e 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include class tst_behaviors : public QObject @@ -60,6 +61,9 @@ private slots: void replaceBinding(); //void transitionOverrides(); void group(); + void emptyBehavior(); + void nonSelectingBehavior(); + void reassignedAnimation(); }; void tst_behaviors::simpleBehavior() @@ -68,6 +72,7 @@ void tst_behaviors::simpleBehavior() QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/simple.qml")); QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); + QVERIFY(qobject_cast(rect->findChild("MyBehavior"))->animation()); rect->setState("moved"); QTest::qWait(100); @@ -189,6 +194,44 @@ void tst_behaviors::group() } } +void tst_behaviors::emptyBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/empty.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::nonSelectingBehavior() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately +} + +void tst_behaviors::reassignedAnimation() +{ + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/reassignedAnimation.qml")); + QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior."); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QTest::qWait(200 + 100); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QVERIFY(x > 0 && x < 200); //i.e. the right behavior has been triggered +} + QTEST_MAIN(tst_behaviors) #include "tst_behaviors.moc" -- cgit v0.12 From 57dadc8606eb0c864ef27e550f9a8ae109de5293 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Nov 2009 16:12:57 +1000 Subject: Fix test. --- tests/auto/declarative/behaviors/tst_behaviors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 7bdc82e..29c631d 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -229,7 +229,7 @@ void tst_behaviors::reassignedAnimation() rect->setState("moved"); QTest::qWait(200 + 100); qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QVERIFY(x > 0 && x < 200); //i.e. the right behavior has been triggered + QCOMPARE(x, qreal(200)); //i.e. the right behavior has been triggered } QTEST_MAIN(tst_behaviors) -- cgit v0.12 From 6f033b6a46ae5cf3dcfed9a2e17182ae58108a00 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 3 Nov 2009 16:20:41 +1000 Subject: Declare typeinfo for key navigation. --- src/declarative/graphicsitems/qmlgraphicsitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 0e741c4..5083f43 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -2918,5 +2918,5 @@ QML_DECLARE_TYPE(QmlGraphicsKeysAttached) QML_DECLARE_TYPEINFO(QmlGraphicsKeysAttached, QML_HAS_ATTACHED_PROPERTIES) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QmlGraphicsKeysAttached) QML_DECLARE_TYPE(QmlGraphicsKeyNavigationAttached) +QML_DECLARE_TYPEINFO(QmlGraphicsKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QmlGraphicsKeyNavigationAttached) - -- cgit v0.12 From 7bc853890bbd8653c3d058d50811ae6dfaad1fd1 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 3 Nov 2009 16:43:50 +1000 Subject: Don't trigger if we've been stopped. Task-number: QT-2423 --- src/declarative/util/qmltimer.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index 268d5ec..2e844be 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -57,12 +57,12 @@ public: : interval(1000), running(false), repeating(false), triggeredOnStart(false) , classBegun(false), componentComplete(false) {} int interval; - bool running; - bool repeating; - bool triggeredOnStart; QPauseAnimation pause; - bool classBegun; - bool componentComplete; + bool running : 1; + bool repeating : 1; + bool triggeredOnStart : 1; + bool classBegun : 1; + bool componentComplete : 1; }; /*! @@ -82,6 +82,9 @@ public: } \endqml + QmlTimer is synchronized with the animation timer. Since the animation + timer is usually set to 60fps, the resolution of QmlTimer will be + at best 16ms. */ QmlTimer::QmlTimer(QObject *parent) @@ -89,7 +92,6 @@ QmlTimer::QmlTimer(QObject *parent) { Q_D(QmlTimer); connect(&d->pause, SIGNAL(currentLoopChanged(int)), this, SLOT(ticked())); - connect(&d->pause, SIGNAL(finished()), this, SLOT(ticked())); connect(&d->pause, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)) , this, SLOT(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State))); d->pause.setLoopCount(1); @@ -259,7 +261,9 @@ void QmlTimer::componentComplete() */ void QmlTimer::ticked() { - emit triggered(); + Q_D(QmlTimer); + if (d->running) + emit triggered(); } void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State state) @@ -267,6 +271,7 @@ void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State Q_D(QmlTimer); if (d->running && state != QAbstractAnimation::Running) { d->running = false; + emit triggered(); emit runningChanged(); } } -- cgit v0.12 From ed82a5dbe57fcc80b9d6244c73295f4b0b6e2835 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 16:45:59 +1000 Subject: Allow example-specific test. Allow examples to report failure via error property. Workaround QTBUG-5296 by running webbrowser demo for longer. --- tests/auto/declarative/examples/data/webbrowser/webbrowser.qml | 6 ++++++ tests/auto/declarative/examples/tst_examples.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/examples/data/webbrowser/webbrowser.qml diff --git a/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml b/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml new file mode 100644 index 0000000..bdf3290 --- /dev/null +++ b/tests/auto/declarative/examples/data/webbrowser/webbrowser.qml @@ -0,0 +1,6 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { msec: 0 } + Frame { msec: 1000 } +} diff --git a/tests/auto/declarative/examples/tst_examples.cpp b/tests/auto/declarative/examples/tst_examples.cpp index ac12204..d758101 100644 --- a/tests/auto/declarative/examples/tst_examples.cpp +++ b/tests/auto/declarative/examples/tst_examples.cpp @@ -42,6 +42,7 @@ #include #include #include +#include class tst_examples : public QObject { @@ -179,9 +180,12 @@ void tst_examples::examples() { QFETCH(QString, file); + QFileInfo fi(file); + QFileInfo dir(fi.path()); + QFileInfo testdata("data/"+dir.baseName()+"/"+fi.baseName()); QStringList arguments; - arguments << "-script" << "data/dummytest" - << "-scriptopts" << "play,exitoncomplete,exitonfailure" + arguments << "-script" << (testdata.exists() ? testdata.filePath() : QLatin1String("data/dummytest")) + << "-scriptopts" << "play,testerror,exitoncomplete,exitonfailure" << file; QProcess p; p.start(qmlviewer, arguments); -- cgit v0.12 From 79d35acae62bf28c37022b763b04e94f5e67bf6f Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 3 Nov 2009 16:47:55 +1000 Subject: Define and document deletion of QmlEngine QNetworkAccessManager --- src/declarative/qml/qmlengine.cpp | 14 +++++++------- tools/qmlviewer/qmlviewer.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 7242a1d..c562e02 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -181,8 +181,6 @@ QmlEnginePrivate::~QmlEnginePrivate() typeNameClass = 0; delete listClass; listClass = 0; - delete networkAccessManager; - networkAccessManager = 0; delete nodeListClass; nodeListClass = 0; delete namedNodeMapClass; @@ -336,14 +334,16 @@ QmlContext *QmlEngine::rootContext() Sets the common QNetworkAccessManager, \a network, used by all QML elements instantiated by this engine. - Any previously set manager is deleted and \a network is owned by the - QmlEngine. This method should only be called before any QmlComponents are - instantiated. + If the parent of \a network is this engine, the engine takes ownership and + will delete it as needed. Otherwise, ownership remains with the caller. + + This method should only be called before any QmlComponents are instantiated. */ void QmlEngine::setNetworkAccessManager(QNetworkAccessManager *network) { Q_D(QmlEngine); - delete d->networkAccessManager; + if (d->networkAccessManager && d->networkAccessManager->parent() == this) + delete d->networkAccessManager; d->networkAccessManager = network; } @@ -358,7 +358,7 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const { Q_D(const QmlEngine); if (!d->networkAccessManager) - d->networkAccessManager = new QNetworkAccessManager; + d->networkAccessManager = new QNetworkAccessManager(const_cast(this)); return d->networkAccessManager; } diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 248ff24..b9f3e67 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -249,7 +249,7 @@ private: class ConfiguredNetworkAccessManager : public QNetworkAccessManager { public: - ConfiguredNetworkAccessManager() { } + ConfiguredNetworkAccessManager(QObject *parent) : QNetworkAccessManager(parent) { } QNetworkReply *createRequest (Operation op, const QNetworkRequest &req, QIODevice * outgoingData) { @@ -334,7 +334,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) canvas->setAttribute(Qt::WA_OpaquePaintEvent); canvas->setAttribute(Qt::WA_NoSystemBackground); canvas->setContentResizable(!skin || !scaleSkin); - canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager); + canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager(canvas->engine())); canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); -- cgit v0.12 From 447fea7eb02972f189a468782aa1f48ab796611a Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 16:56:54 +1000 Subject: add some QmlGraphicsText tests --- tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 67 ++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp index 173a3b4..49fc757 100644 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp @@ -64,6 +64,7 @@ private slots: void font(); void style(); void color(); + void smooth(); private: QStringList standard; @@ -211,30 +212,34 @@ void tst_qfxtext::wrap() { // XXX Poor coverage - should at least be testing an expected height. + int textHeight = 0; // for specified width and wrap set true { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\"; wrap: true; width: 300 }", QUrl("file://")); + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + textHeight = textObject->height(); QCOMPARE(textObject->width(), 300.); } for (int i = 0; i < standard.size(); i++) { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); } for (int i = 0; i < richText.size(); i++) { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); } } @@ -317,7 +322,6 @@ void tst_qfxtext::verticalAlignment() QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); } } @@ -339,7 +343,7 @@ void tst_qfxtext::verticalAlignment() void tst_qfxtext::font() { //test size, then bold, then italic, then family - { + { QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); @@ -349,6 +353,16 @@ void tst_qfxtext::font() QCOMPARE(textObject->font().italic(), false); } + { + QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pixelSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + { QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -391,12 +405,12 @@ void tst_qfxtext::style() //test style for (int i = 0; i < styles.size(); i++) { - QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; text: \"Hello World\" }"; + QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); QCOMPARE((int)textObject->style(), (int)styles.at(i)); - QCOMPARE(textObject->styleColor(), QColor()); + QCOMPARE(textObject->styleColor(), QColor("white")); } } @@ -448,6 +462,41 @@ void tst_qfxtext::color() QCOMPARE(textObject->color(), testColor); } } + +void tst_qfxtext::smooth() +{ + for (int i = 0; i < standard.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } + for (int i = 0; i < richText.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } +} + QTEST_MAIN(tst_qfxtext) #include "tst_qfxtext.moc" -- cgit v0.12 From 8dbea8ec48084b27c56f7d263c38c84ff03ebc3d Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 17:08:45 +1000 Subject: qmlgraphicstext tests --- tests/auto/declarative/qfxtext/qfxtext.pro | 5 - tests/auto/declarative/qfxtext/tst_qfxtext.cpp | 502 --------------------- .../qmlgraphicstext/qmlgraphicstext.pro | 5 + .../qmlgraphicstext/tst_qmlgraphicstext.cpp | 500 ++++++++++++++++++++ 4 files changed, 505 insertions(+), 507 deletions(-) delete mode 100644 tests/auto/declarative/qfxtext/qfxtext.pro delete mode 100644 tests/auto/declarative/qfxtext/tst_qfxtext.cpp create mode 100644 tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro create mode 100644 tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp diff --git a/tests/auto/declarative/qfxtext/qfxtext.pro b/tests/auto/declarative/qfxtext/qfxtext.pro deleted file mode 100644 index 1f3fe37..0000000 --- a/tests/auto/declarative/qfxtext/qfxtext.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative gui -macx:CONFIG -= app_bundle - -SOURCES += tst_qfxtext.cpp diff --git a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp b/tests/auto/declarative/qfxtext/tst_qfxtext.cpp deleted file mode 100644 index 49fc757..0000000 --- a/tests/auto/declarative/qfxtext/tst_qfxtext.cpp +++ /dev/null @@ -1,502 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include - -class tst_qfxtext : public QObject - -{ - Q_OBJECT -public: - tst_qfxtext(); - -private slots: - void text(); - void width(); - void wrap(); - void elide(); - - // ### these tests may be trivial - void horizontalAlignment(); - void verticalAlignment(); - void font(); - void style(); - void color(); - void smooth(); - -private: - QStringList standard; - QStringList richText; - - QStringList horizontalAlignmentmentStrings; - QStringList verticalAlignmentmentStrings; - - QList verticalAlignmentments; - QList horizontalAlignmentments; - - QStringList styleStrings; - QList styles; - - QStringList colorStrings; - - QmlEngine engine; -}; - -tst_qfxtext::tst_qfxtext() -{ - standard << "the quick brown fox jumped over the lazy dog" - << "the quick brown fox\n jumped over the lazy dog"; - - richText << "the quick brown fox jumped over the lazy dog" - << "the quick brown fox
jumped over the lazy dog
"; - - horizontalAlignmentmentStrings << "AlignLeft" - << "AlignRight" - << "AlignHCenter"; - - verticalAlignmentmentStrings << "AlignTop" - << "AlignBottom" - << "AlignVCenter"; - - horizontalAlignmentments << Qt::AlignLeft - << Qt::AlignRight - << Qt::AlignHCenter; - - verticalAlignmentments << Qt::AlignTop - << Qt::AlignBottom - << Qt::AlignVCenter; - - styleStrings << "Normal" - << "Outline" - << "Raised" - << "Sunken"; - - styles << QmlGraphicsText::Normal - << QmlGraphicsText::Outline - << QmlGraphicsText::Raised - << QmlGraphicsText::Sunken; - - colorStrings << "aliceblue" - << "antiquewhite" - << "aqua" - << "darkkhaki" - << "darkolivegreen" - << "dimgray" - << "palevioletred" - << "lightsteelblue" - << "#000000" - << "#AAAAAA" - << "#FFFFFF" - << "#2AC05F"; - // - // need a different test to do alpha channel test - // << "#AA0011DD" - // << "#00F16B11"; - // -} - -void tst_qfxtext::text() -{ - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->text(), QString("")); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QCOMPARE(textObject->text(), standard.at(i)); - } - - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QVERIFY(textObject != 0); - QString expected = richText.at(i); - QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); - } -} - -void tst_qfxtext::width() -{ - // uses Font metrics to find the width for standard and document to find the width for rich - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 0.); - } - - for (int i = 0; i < standard.size(); i++) - { - QFont f; - QFontMetrics fm(f); - int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); - - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), qreal(metricWidth)); - } - - for (int i = 0; i < richText.size(); i++) - { - QTextDocument document; - document.setHtml(richText.at(i)); - document.setDocumentMargin(0); - - int documentWidth = document.idealWidth(); - - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), qreal(documentWidth)); - } -} - -void tst_qfxtext::wrap() -{ - // XXX Poor coverage - should at least be testing an expected height. - - int textHeight = 0; - // for specified width and wrap set true - { - QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - textHeight = textObject->height(); - - QCOMPARE(textObject->width(), 300.); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 30.); - QVERIFY(textObject->height() > textHeight); - } - - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 30.); - QVERIFY(textObject->height() > textHeight); - } - -} - -void tst_qfxtext::elide() -{ - for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { - const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; - QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; - - // XXX Poor coverage. - - { - QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - - for (int i = 0; i < standard.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - - // richtext - does nothing - for (int i = 0; i < richText.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->width(), 300.); - } - } -} - -//the alignment tests may be trivial o.oa -void tst_qfxtext::horizontalAlignment() -{ - //test one align each, and then test if two align fails. - - for (int i = 0; i < standard.size(); i++) - { - for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); - } - } - - for (int i = 0; i < richText.size(); i++) - { - for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); - } - } - -} - -void tst_qfxtext::verticalAlignment() -{ - //test one align each, and then test if two align fails. - - for (int i = 0; i < standard.size(); i++) - { - for (int j=0; j < verticalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); - } - } - - for (int i = 0; i < richText.size(); i++) - { - for (int j=0; j < verticalAlignmentmentStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); - } - } - -} - -void tst_qfxtext::font() -{ - //test size, then bold, then italic, then family - { - QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().pointSize(), 40); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().pixelSize(), 40); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().bold(), true); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.italic: true; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().italic(), true); - QCOMPARE(textObject->font().bold(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.family: \"Helvetica\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().family(), QString("Helvetica")); - QCOMPARE(textObject->font().bold(), false); - QCOMPARE(textObject->font().italic(), false); - } - - { - QString componentStr = "import Qt 4.6\nText { font.family: \"\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->font().family(), QString("")); - } -} - -void tst_qfxtext::style() -{ - //test style - for (int i = 0; i < styles.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE((int)textObject->style(), (int)styles.at(i)); - QCOMPARE(textObject->styleColor(), QColor("white")); - } -} - -void tst_qfxtext::color() -{ - //test style - for (int i = 0; i < colorStrings.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); - QCOMPARE(textObject->styleColor(), QColor()); - } - - for (int i = 0; i < colorStrings.size(); i++) - { - QString componentStr = "import Qt 4.6\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); - // default color to black? - QCOMPARE(textObject->color(), QColor("black")); - } - - for (int i = 0; i < colorStrings.size(); i++) - { - for (int j = 0; j < colorStrings.size(); j++) - { - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); - QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j))); - } - } - { - QString colorStr = "#AA001234"; - QColor testColor("#001234"); - testColor.setAlpha(170); - - QString componentStr = "import Qt 4.6\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - - QCOMPARE(textObject->color(), testColor); - } -} - -void tst_qfxtext::smooth() -{ - for (int i = 0; i < standard.size(); i++) - { - { - QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); - } - { - QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); - } - } - for (int i = 0; i < richText.size(); i++) - { - { - QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); - } - { - QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; - QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); - QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); - } - } -} - -QTEST_MAIN(tst_qfxtext) - -#include "tst_qfxtext.moc" diff --git a/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro b/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro new file mode 100644 index 0000000..1d8c59f --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstext/qmlgraphicstext.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicstext.cpp diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp new file mode 100644 index 0000000..d53de59 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -0,0 +1,500 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include + +class tst_qmlgraphicstext : public QObject + +{ + Q_OBJECT +public: + tst_qmlgraphicstext(); + +private slots: + void text(); + void width(); + void wrap(); + void elide(); + + // ### these tests may be trivial + void horizontalAlignment(); + void verticalAlignment(); + void font(); + void style(); + void color(); + void smooth(); + +private: + QStringList standard; + QStringList richText; + + QStringList horizontalAlignmentmentStrings; + QStringList verticalAlignmentmentStrings; + + QList verticalAlignmentments; + QList horizontalAlignmentments; + + QStringList styleStrings; + QList styles; + + QStringList colorStrings; + + QmlEngine engine; +}; + +tst_qmlgraphicstext::tst_qmlgraphicstext() +{ + standard << "the quick brown fox jumped over the lazy dog" + << "the quick brown fox\n jumped over the lazy dog"; + + richText << "the quick brown fox jumped over the lazy dog" + << "the quick brown fox
jumped over the lazy dog
"; + + horizontalAlignmentmentStrings << "AlignLeft" + << "AlignRight" + << "AlignHCenter"; + + verticalAlignmentmentStrings << "AlignTop" + << "AlignBottom" + << "AlignVCenter"; + + horizontalAlignmentments << Qt::AlignLeft + << Qt::AlignRight + << Qt::AlignHCenter; + + verticalAlignmentments << Qt::AlignTop + << Qt::AlignBottom + << Qt::AlignVCenter; + + styleStrings << "Normal" + << "Outline" + << "Raised" + << "Sunken"; + + styles << QmlGraphicsText::Normal + << QmlGraphicsText::Outline + << QmlGraphicsText::Raised + << QmlGraphicsText::Sunken; + + colorStrings << "aliceblue" + << "antiquewhite" + << "aqua" + << "darkkhaki" + << "darkolivegreen" + << "dimgray" + << "palevioletred" + << "lightsteelblue" + << "#000000" + << "#AAAAAA" + << "#FFFFFF" + << "#2AC05F"; + // + // need a different test to do alpha channel test + // << "#AA0011DD" + // << "#00F16B11"; + // +} + +void tst_qmlgraphicstext::text() +{ + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QCOMPARE(textObject->text(), QString("")); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QCOMPARE(textObject->text(), standard.at(i)); + } + + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QVERIFY(textObject != 0); + QString expected = richText.at(i); + QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); + } +} + +void tst_qmlgraphicstext::width() +{ + // uses Font metrics to find the width for standard and document to find the width for rich + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 0.); + } + + for (int i = 0; i < standard.size(); i++) + { + QFont f; + QFontMetrics fm(f); + int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width(); + + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), qreal(metricWidth)); + } + + for (int i = 0; i < richText.size(); i++) + { + QTextDocument document; + document.setHtml(richText.at(i)); + document.setDocumentMargin(0); + + int documentWidth = document.idealWidth(); + + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), qreal(documentWidth)); + } +} + +void tst_qmlgraphicstext::wrap() +{ + int textHeight = 0; + // for specified width and wrap set true + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + textHeight = textObject->height(); + + QCOMPARE(textObject->width(), 300.); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); + } + + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 30.); + QVERIFY(textObject->height() > textHeight); + } + +} + +void tst_qmlgraphicstext::elide() +{ + for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { + const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; + QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; + + // XXX Poor coverage. + + { + QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + + for (int i = 0; i < standard.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + + // richtext - does nothing + for (int i = 0; i < richText.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->width(), 300.); + } + } +} + +//the alignment tests may be trivial o.oa +void tst_qmlgraphicstext::horizontalAlignment() +{ + //test one align each, and then test if two align fails. + + for (int i = 0; i < standard.size(); i++) + { + for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); + } + } + + for (int i = 0; i < richText.size(); i++) + { + for (int j=0; j < horizontalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j)); + } + } + +} + +void tst_qmlgraphicstext::verticalAlignment() +{ + //test one align each, and then test if two align fails. + + for (int i = 0; i < standard.size(); i++) + { + for (int j=0; j < verticalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); + } + } + + for (int i = 0; i < richText.size(); i++) + { + for (int j=0; j < verticalAlignmentmentStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j)); + } + } + +} + +void tst_qmlgraphicstext::font() +{ + //test size, then bold, then italic, then family + { + QString componentStr = "import Qt 4.6\nText { font.pointSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pointSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.pixelSize: 40; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().pixelSize(), 40); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.bold: true; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().bold(), true); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.italic: true; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().italic(), true); + QCOMPARE(textObject->font().bold(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.family: \"Helvetica\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().family(), QString("Helvetica")); + QCOMPARE(textObject->font().bold(), false); + QCOMPARE(textObject->font().italic(), false); + } + + { + QString componentStr = "import Qt 4.6\nText { font.family: \"\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->font().family(), QString("")); + } +} + +void tst_qmlgraphicstext::style() +{ + //test style + for (int i = 0; i < styles.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE((int)textObject->style(), (int)styles.at(i)); + QCOMPARE(textObject->styleColor(), QColor("white")); + } +} + +void tst_qmlgraphicstext::color() +{ + //test style + for (int i = 0; i < colorStrings.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); + QCOMPARE(textObject->styleColor(), QColor()); + } + + for (int i = 0; i < colorStrings.size(); i++) + { + QString componentStr = "import Qt 4.6\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i))); + // default color to black? + QCOMPARE(textObject->color(), QColor("black")); + } + + for (int i = 0; i < colorStrings.size(); i++) + { + for (int j = 0; j < colorStrings.size(); j++) + { + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStrings.at(i) + "\"; styleColor: \"" + colorStrings.at(j) + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), QColor(colorStrings.at(i))); + QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j))); + } + } + { + QString colorStr = "#AA001234"; + QColor testColor("#001234"); + testColor.setAlpha(170); + + QString componentStr = "import Qt 4.6\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + + QCOMPARE(textObject->color(), testColor); + } +} + +void tst_qmlgraphicstext::smooth() +{ + for (int i = 0; i < standard.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } + for (int i = 0; i < richText.size(); i++) + { + { + QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), true); + } + { + QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast(textComponent.create()); + QCOMPARE(textObject->smoothTransform(), false); + } + } +} + +QTEST_MAIN(tst_qmlgraphicstext) + +#include "tst_qmlgraphicstext.moc" -- cgit v0.12 From 3550d1b22b3a5f8f974ca2ba17a3d4f5d52b3743 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 3 Nov 2009 17:50:26 +1000 Subject: QmlFontLoader tests --- .../declarative/qmlfontloader/data/Fontin-Bold.ttf | Bin 0 -> 30916 bytes .../declarative/qmlfontloader/qmlfontloader.pro | 5 ++ .../qmlfontloader/tst_qmlfontloader.cpp | 89 +++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf create mode 100644 tests/auto/declarative/qmlfontloader/qmlfontloader.pro create mode 100644 tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp diff --git a/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf new file mode 100644 index 0000000..f6a33b0 Binary files /dev/null and b/tests/auto/declarative/qmlfontloader/data/Fontin-Bold.ttf differ diff --git a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro new file mode 100644 index 0000000..0ecfde0 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlfontloader.cpp diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp new file mode 100644 index 0000000..a65ecf4 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include + +class tst_qmlfontloader : public QObject + +{ + Q_OBJECT +public: + tst_qmlfontloader(); + +private slots: + void namedfont(); + void localfont(); + +private slots: + +private: + QmlEngine engine; +}; + +tst_qmlfontloader::tst_qmlfontloader() +{ +} + +void tst_qmlfontloader::namedfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("Helvetica")); +} + +void tst_qmlfontloader::localfont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"data/Fontin-Bold.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast(component.create()); + + QVERIFY(fontObject != 0); + QCOMPARE(fontObject->name(), QString("Fontin")); +} + +QTEST_MAIN(tst_qmlfontloader) + +#include "tst_qmlfontloader.moc" -- cgit v0.12