aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickfontloader
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-02-16 14:43:03 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-24 04:51:31 +0100
commitb855240b782395f94315f43ea3e7e182299fac48 (patch)
treebc594c04449be8cd14cd0ab0bb72dafc2be0ffb2 /tests/auto/quick/qquickfontloader
parent6a42a6e0a9a1abdda0d07a5a20b4ac7e45348684 (diff)
Rename QDeclarative symbols to QQuick and QQml
Symbols beginning with QDeclarative are already exported by the quick1 module. Users can apply the bin/rename-qtdeclarative-symbols.sh script to modify client code using the previous names of the renamed symbols. Task-number: QTBUG-23737 Change-Id: Ifaa482663767634931e8711a8e9bf6e404859e66 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickfontloader')
-rw-r--r--tests/auto/quick/qquickfontloader/data/daniel.ttfbin0 -> 51984 bytes
-rw-r--r--tests/auto/quick/qquickfontloader/data/dummy.ttf0
-rw-r--r--tests/auto/quick/qquickfontloader/data/qtbug-20268.qml27
-rw-r--r--tests/auto/quick/qquickfontloader/data/tarzeau_ocr_a.ttfbin0 -> 24544 bytes
-rw-r--r--tests/auto/quick/qquickfontloader/qquickfontloader.pro17
-rw-r--r--tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp255
6 files changed, 299 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickfontloader/data/daniel.ttf b/tests/auto/quick/qquickfontloader/data/daniel.ttf
new file mode 100644
index 0000000000..aae50d5035
--- /dev/null
+++ b/tests/auto/quick/qquickfontloader/data/daniel.ttf
Binary files differ
diff --git a/tests/auto/quick/qquickfontloader/data/dummy.ttf b/tests/auto/quick/qquickfontloader/data/dummy.ttf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/quick/qquickfontloader/data/dummy.ttf
diff --git a/tests/auto/quick/qquickfontloader/data/qtbug-20268.qml b/tests/auto/quick/qquickfontloader/data/qtbug-20268.qml
new file mode 100644
index 0000000000..0eafdfa17b
--- /dev/null
+++ b/tests/auto/quick/qquickfontloader/data/qtbug-20268.qml
@@ -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" }
+}
diff --git a/tests/auto/quick/qquickfontloader/data/tarzeau_ocr_a.ttf b/tests/auto/quick/qquickfontloader/data/tarzeau_ocr_a.ttf
new file mode 100644
index 0000000000..cf93f9651f
--- /dev/null
+++ b/tests/auto/quick/qquickfontloader/data/tarzeau_ocr_a.ttf
Binary files differ
diff --git a/tests/auto/quick/qquickfontloader/qquickfontloader.pro b/tests/auto/quick/qquickfontloader/qquickfontloader.pro
new file mode 100644
index 0000000000..7c34c43d04
--- /dev/null
+++ b/tests/auto/quick/qquickfontloader/qquickfontloader.pro
@@ -0,0 +1,17 @@
+CONFIG += testcase
+TARGET = tst_qquickfontloader
+macx:CONFIG -= app_bundle
+
+HEADERS += ../../shared/testhttpserver.h
+SOURCES += tst_qquickfontloader.cpp \
+ ../../shared/testhttpserver.cpp
+
+include (../../shared/util.pri)
+
+testDataFiles.files = data
+testDataFiles.path = .
+DEPLOYMENT += testDataFiles
+
+CONFIG += parallel_test
+
+QT += core-private gui-private qml-private quick-private network testlib
diff --git a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp
new file mode 100644
index 0000000000..d8f368cf3e
--- /dev/null
+++ b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp
@@ -0,0 +1,255 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <QtTest/QSignalSpy>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQuick/private/qquickfontloader_p.h>
+#include "../../shared/util.h"
+#include "../../shared/testhttpserver.h"
+#include <QtQuick/QQuickView>
+#include <QtQuick/QQuickItem>
+
+#define SERVER_PORT 14448
+
+class tst_qquickfontloader : public QQmlDataTest
+{
+ Q_OBJECT
+public:
+ tst_qquickfontloader();
+
+private slots:
+ void initTestCase();
+ void noFont();
+ void namedFont();
+ void localFont();
+ void failLocalFont();
+ void webFont();
+ void redirWebFont();
+ void failWebFont();
+ void changeFont();
+ void changeFontSourceViaState();
+
+private:
+ QQmlEngine engine;
+ TestHTTPServer server;
+};
+
+tst_qquickfontloader::tst_qquickfontloader() :
+ server(SERVER_PORT)
+{
+}
+
+void tst_qquickfontloader::initTestCase()
+{
+ QQmlDataTest::initTestCase();
+ server.serveDirectory(dataDirectory());
+ QVERIFY(server.isValid());
+}
+
+void tst_qquickfontloader::noFont()
+{
+ QString componentStr = "import QtQuick 2.0\nFontLoader { }";
+ QQmlComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QCOMPARE(fontObject->name(), QString(""));
+ QCOMPARE(fontObject->source(), QUrl(""));
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Null);
+
+ delete fontObject;
+}
+
+void tst_qquickfontloader::namedFont()
+{
+ QString componentStr = "import QtQuick 2.0\nFontLoader { name: \"Helvetica\" }";
+ QQmlComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QCOMPARE(fontObject->source(), QUrl(""));
+ QCOMPARE(fontObject->name(), QString("Helvetica"));
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready);
+}
+
+void tst_qquickfontloader::localFont()
+{
+ QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" + testFile("tarzeau_ocr_a.ttf") + "\" }";
+ QQmlComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QVERIFY(fontObject->source() != QUrl(""));
+ QTRY_COMPARE(fontObject->name(), QString("OCRA"));
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready);
+}
+
+void tst_qquickfontloader::failLocalFont()
+{
+ QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" + testFileUrl("dummy.ttf").toString() + "\" }";
+ QTest::ignoreMessage(QtWarningMsg, QString("file::2:1: QML FontLoader: Cannot load font: \"" + testFileUrl("dummy.ttf").toString() + "\"").toUtf8().constData());
+ QQmlComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QVERIFY(fontObject->source() != QUrl(""));
+ QTRY_COMPARE(fontObject->name(), QString(""));
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Error);
+}
+
+void tst_qquickfontloader::webFont()
+{
+ QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"http://localhost:14448/tarzeau_ocr_a.ttf\" }";
+ QQmlComponent component(&engine);
+
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QVERIFY(fontObject->source() != QUrl(""));
+ QTRY_COMPARE(fontObject->name(), QString("OCRA"));
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready);
+}
+
+void tst_qquickfontloader::redirWebFont()
+{
+ server.addRedirect("olddir/oldname.ttf","../tarzeau_ocr_a.ttf");
+
+ QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"http://localhost:14448/olddir/oldname.ttf\" }";
+ QQmlComponent component(&engine);
+
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QVERIFY(fontObject->source() != QUrl(""));
+ QTRY_COMPARE(fontObject->name(), QString("OCRA"));
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready);
+}
+
+void tst_qquickfontloader::failWebFont()
+{
+ QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"http://localhost:14448/nonexist.ttf\" }";
+ QTest::ignoreMessage(QtWarningMsg, "file::2:1: QML FontLoader: Cannot load font: \"http://localhost:14448/nonexist.ttf\"");
+ QQmlComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+ QVERIFY(fontObject->source() != QUrl(""));
+ QTRY_COMPARE(fontObject->name(), QString(""));
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Error);
+}
+
+void tst_qquickfontloader::changeFont()
+{
+ QString componentStr = "import QtQuick 2.0\nFontLoader { source: font }";
+ QQmlContext *ctxt = engine.rootContext();
+ ctxt->setContextProperty("font", testFileUrl("tarzeau_ocr_a.ttf"));
+ QQmlComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
+
+ QVERIFY(fontObject != 0);
+
+ QSignalSpy nameSpy(fontObject, SIGNAL(nameChanged()));
+ QSignalSpy statusSpy(fontObject, SIGNAL(statusChanged()));
+
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::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() == QQuickFontLoader::Loading);
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready);
+ QCOMPARE(nameSpy.count(), 1);
+ QCOMPARE(statusSpy.count(), 2);
+ QTRY_COMPARE(fontObject->name(), QString("Daniel"));
+
+ ctxt->setContextProperty("font", testFileUrl("tarzeau_ocr_a.ttf"));
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::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() == QQuickFontLoader::Ready);
+ QCOMPARE(nameSpy.count(), 3);
+ QCOMPARE(statusSpy.count(), 2);
+ QTRY_COMPARE(fontObject->name(), QString("Daniel"));
+}
+
+void tst_qquickfontloader::changeFontSourceViaState()
+{
+ QQuickView canvas(testFileUrl("qtbug-20268.qml"));
+ canvas.show();
+ canvas.requestActivateWindow();
+ QTest::qWaitForWindowShown(&canvas);
+ QTRY_COMPARE(&canvas, qGuiApp->focusWindow());
+
+ QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(qvariant_cast<QObject *>(canvas.rootObject()->property("fontloader")));
+ QVERIFY(fontObject != 0);
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready);
+ QVERIFY(fontObject->source() != QUrl(""));
+ QTRY_COMPARE(fontObject->name(), QString("OCRA"));
+
+ canvas.rootObject()->setProperty("usename", true);
+
+ // This warning should probably not be printed once QTBUG-20268 is fixed
+ QString warning = QString(testFileUrl("qtbug-20268.qml").toString()) +
+ QLatin1String(":13:5: QML FontLoader: Cannot load font: \"\"");
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
+
+ QEXPECT_FAIL("", "QTBUG-20268", Abort);
+ QTRY_VERIFY(fontObject->status() == QQuickFontLoader::Ready);
+ QCOMPARE(canvas.rootObject()->property("name").toString(), QString("Tahoma"));
+}
+
+QTEST_MAIN(tst_qquickfontloader)
+
+#include "tst_qquickfontloader.moc"