diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2010-09-17 05:34:44 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2010-09-17 05:36:06 (GMT) |
commit | eef26bc8521da62db0dced6796eceb7c27f64160 (patch) | |
tree | d057b1d8056c297ea76556ef2af6cb9ecb80a04f /tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp | |
parent | af29c555a29ebcdb1d962176912478212c9c7e65 (diff) | |
download | Qt-eef26bc8521da62db0dced6796eceb7c27f64160.zip Qt-eef26bc8521da62db0dced6796eceb7c27f64160.tar.gz Qt-eef26bc8521da62db0dced6796eceb7c27f64160.tar.bz2 |
Autotest and small fix for QDeclarativeFontLoader.
Diffstat (limited to 'tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
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" |