Test for changing font via states
authorDamian Jansen <damian.jansen@nokia.com>
Mon, 24 Oct 2011 05:50:38 +0000 (15:50 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 26 Oct 2011 01:41:53 +0000 (03:41 +0200)
Change-Id: I1bc4bfefb5b4892be53b261d65a50a0cfd5a7d00
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
tests/auto/declarative/qdeclarativefontloader/data/qtbug-20268.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp

diff --git a/tests/auto/declarative/qdeclarativefontloader/data/qtbug-20268.qml b/tests/auto/declarative/qdeclarativefontloader/data/qtbug-20268.qml
new file mode 100644 (file)
index 0000000..0eafdfa
--- /dev/null
@@ -0,0 +1,27 @@
+import QtQuick 2.0
+
+Rectangle {
+    id: test
+    property variant fontloader: fontloaderelement
+    height: 100; width: 100
+    property bool usename: false
+    property int statenum: 1
+    property alias name: fontloaderelement.name
+    property alias source: fontloaderelement.source
+    property alias status: fontloaderelement.status
+
+    FontLoader {
+        id: fontloaderelement
+    }
+
+    states: [
+        State { name: "start"; when: !usename
+            PropertyChanges { target: fontloaderelement; source: "tarzeau_ocr_a.ttf" }
+        },
+        State { name: "changefont"; when: usename
+            PropertyChanges { target: fontloaderelement; name: "Tahoma" }
+        }
+    ]
+
+    Text { id: textelement; text: fontloaderelement.name; color: "black" }
+}
index 67a040d..9831ac1 100644 (file)
@@ -46,6 +46,8 @@
 #include <QtDeclarative/private/qdeclarativefontloader_p.h>
 #include "../shared/util.h"
 #include "../../declarative/shared/testhttpserver.h"
+#include <QQuickView>
+#include <QQuickItem>
 
 #define SERVER_PORT 14448
 
@@ -65,6 +67,7 @@ private slots:
     void redirWebFont();
     void failWebFont();
     void changeFont();
+    void changeFontSourceViaState();
 
 private:
     QDeclarativeEngine engine;
@@ -220,6 +223,26 @@ void tst_qdeclarativefontloader::changeFont()
     QTRY_COMPARE(fontObject->name(), QString("Daniel"));
 }
 
+void tst_qdeclarativefontloader::changeFontSourceViaState()
+{
+    QQuickView canvas(QUrl::fromLocalFile(TESTDATA("qtbug-20268.qml")));
+    canvas.show();
+    canvas.requestActivateWindow();
+    QTest::qWaitForWindowShown(&canvas);
+    QTRY_COMPARE(&canvas, qGuiApp->focusWindow());
+
+    QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(qvariant_cast<QObject *>(canvas.rootObject()->property("fontloader")));
+    QVERIFY(fontObject != 0);
+    QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready);
+    QVERIFY(fontObject->source() != QUrl(""));
+    QTRY_COMPARE(fontObject->name(), QString("OCRA"));
+
+    canvas.rootObject()->setProperty("usename", true);
+    QEXPECT_FAIL("", "QTBUG-20268", Abort);
+    QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready);
+    QCOMPARE(canvas.rootObject()->property("name").toString(), QString("Tahoma"));
+}
+
 QTEST_MAIN(tst_qdeclarativefontloader)
 
 #include "tst_qdeclarativefontloader.moc"