summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2010-09-17 05:34:44 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2010-09-23 07:25:24 (GMT)
commit30848f7eaac221e9c8a3e0c73ce268c12ae801e5 (patch)
treea0362d0ea14490d45561ffb49098429c357af03d /tests/auto/declarative
parent6d524881d5f1125d7396b9a6e23ed65ce0a5c5eb (diff)
downloadQt-30848f7eaac221e9c8a3e0c73ce268c12ae801e5.zip
Qt-30848f7eaac221e9c8a3e0c73ce268c12ae801e5.tar.gz
Qt-30848f7eaac221e9c8a3e0c73ce268c12ae801e5.tar.bz2
Autotest and small fix for QDeclarativeFontLoader.
(cherry picked from commit eef26bc8521da62db0dced6796eceb7c27f64160)
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qdeclarativefontloader/data/daniel.ttfbin0 -> 51984 bytes
-rw-r--r--tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp42
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativefontloader/data/daniel.ttf b/tests/auto/declarative/qdeclarativefontloader/data/daniel.ttf
new file mode 100644
index 0000000..aae50d5
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativefontloader/data/daniel.ttf
Binary files differ
diff --git a/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp b/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp
index ae23017..8765426 100644
--- a/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp
+++ b/tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp
@@ -39,8 +39,10 @@
**
****************************************************************************/
#include <qtest.h>
+#include <QtTest/QSignalSpy>
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtDeclarative/qdeclarativecontext.h>
#include <private/qdeclarativefontloader_p.h>
#include "../../../shared/util.h"
#include "../shared/testhttpserver.h"
@@ -67,6 +69,7 @@ private slots:
void webFont();
void redirWebFont();
void failWebFont();
+ void changeFont();
private slots:
@@ -181,6 +184,45 @@ void tst_qdeclarativefontloader::failWebFont()
QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Error);
}
+void tst_qdeclarativefontloader::changeFont()
+{
+ QString componentStr = "import Qt 4.7\nFontLoader { source: font }";
+ QDeclarativeContext *ctxt = engine.rootContext();
+ ctxt->setContextProperty("font", QUrl::fromLocalFile(SRCDIR "/data/tarzeau_ocr_a.ttf"));
+ QDeclarativeComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+
+ QSignalSpy nameSpy(fontObject, SIGNAL(nameChanged()));
+ QSignalSpy statusSpy(fontObject, SIGNAL(statusChanged()));
+
+ QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready);
+ QCOMPARE(nameSpy.count(), 0);
+ QCOMPARE(statusSpy.count(), 0);
+ QTRY_COMPARE(fontObject->name(), QString("OCRA"));
+
+ ctxt->setContextProperty("font", "http://localhost:14448/daniel.ttf");
+ QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Loading);
+ QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready);
+ QCOMPARE(nameSpy.count(), 1);
+ QCOMPARE(statusSpy.count(), 2);
+ QTRY_COMPARE(fontObject->name(), QString("Daniel"));
+
+ ctxt->setContextProperty("font", QUrl::fromLocalFile(SRCDIR "/data/tarzeau_ocr_a.ttf"));
+ QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready);
+ QCOMPARE(nameSpy.count(), 2);
+ QCOMPARE(statusSpy.count(), 2);
+ QTRY_COMPARE(fontObject->name(), QString("OCRA"));
+
+ ctxt->setContextProperty("font", "http://localhost:14448/daniel.ttf");
+ QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready);
+ QCOMPARE(nameSpy.count(), 3);
+ QCOMPARE(statusSpy.count(), 2);
+ QTRY_COMPARE(fontObject->name(), QString("Daniel"));
+}
+
QTEST_MAIN(tst_qdeclarativefontloader)
#include "tst_qdeclarativefontloader.moc"