|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <qtest.h> |
|
42 #include <QtDeclarative/qdeclarativeengine.h> |
|
43 #include <QtDeclarative/qdeclarativecomponent.h> |
|
44 #include <private/qdeclarativefontloader_p.h> |
|
45 #include "../../../shared/util.h" |
|
46 #include "../shared/testhttpserver.h" |
|
47 |
|
48 #define SERVER_PORT 14448 |
|
49 |
|
50 class tst_qdeclarativefontloader : public QObject |
|
51 |
|
52 { |
|
53 Q_OBJECT |
|
54 public: |
|
55 tst_qdeclarativefontloader(); |
|
56 |
|
57 private slots: |
|
58 void noFont(); |
|
59 void namedFont(); |
|
60 void localFont(); |
|
61 void failLocalFont(); |
|
62 void webFont(); |
|
63 void redirWebFont(); |
|
64 void failWebFont(); |
|
65 |
|
66 private slots: |
|
67 |
|
68 private: |
|
69 QDeclarativeEngine engine; |
|
70 TestHTTPServer server; |
|
71 }; |
|
72 |
|
73 tst_qdeclarativefontloader::tst_qdeclarativefontloader() : |
|
74 server(SERVER_PORT) |
|
75 { |
|
76 server.serveDirectory(SRCDIR "/data"); |
|
77 Q_ASSERT(server.isValid()); |
|
78 } |
|
79 |
|
80 void tst_qdeclarativefontloader::noFont() |
|
81 { |
|
82 QString componentStr = "import Qt 4.7\nFontLoader { }"; |
|
83 QDeclarativeComponent component(&engine); |
|
84 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); |
|
85 QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(component.create()); |
|
86 |
|
87 QVERIFY(fontObject != 0); |
|
88 QCOMPARE(fontObject->name(), QString("")); |
|
89 QCOMPARE(fontObject->source(), QUrl("")); |
|
90 QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Null); |
|
91 |
|
92 delete fontObject; |
|
93 } |
|
94 |
|
95 void tst_qdeclarativefontloader::namedFont() |
|
96 { |
|
97 QString componentStr = "import Qt 4.7\nFontLoader { name: \"Helvetica\" }"; |
|
98 QDeclarativeComponent component(&engine); |
|
99 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); |
|
100 QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(component.create()); |
|
101 |
|
102 QVERIFY(fontObject != 0); |
|
103 QCOMPARE(fontObject->source(), QUrl("")); |
|
104 QCOMPARE(fontObject->name(), QString("Helvetica")); |
|
105 QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready); |
|
106 } |
|
107 |
|
108 void tst_qdeclarativefontloader::localFont() |
|
109 { |
|
110 QString componentStr = "import Qt 4.7\nFontLoader { source: \"" SRCDIR "/data/tarzeau_ocr_a.ttf\" }"; |
|
111 QDeclarativeComponent component(&engine); |
|
112 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); |
|
113 QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(component.create()); |
|
114 |
|
115 QVERIFY(fontObject != 0); |
|
116 QVERIFY(fontObject->source() != QUrl("")); |
|
117 QTRY_COMPARE(fontObject->name(), QString("OCRA")); |
|
118 QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready); |
|
119 } |
|
120 |
|
121 void tst_qdeclarativefontloader::failLocalFont() |
|
122 { |
|
123 QString componentStr = "import Qt 4.7\nFontLoader { source: \"" + QUrl::fromLocalFile(SRCDIR "/data/dummy.ttf").toString() + "\" }"; |
|
124 QTest::ignoreMessage(QtWarningMsg, QString("file::2:1: QML FontLoader: Cannot load font: \"" + QUrl::fromLocalFile(SRCDIR "/data/dummy.ttf").toString() + "\"").toUtf8().constData()); |
|
125 QDeclarativeComponent component(&engine); |
|
126 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); |
|
127 QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(component.create()); |
|
128 |
|
129 QVERIFY(fontObject != 0); |
|
130 QVERIFY(fontObject->source() != QUrl("")); |
|
131 QTRY_COMPARE(fontObject->name(), QString("")); |
|
132 QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Error); |
|
133 } |
|
134 |
|
135 void tst_qdeclarativefontloader::webFont() |
|
136 { |
|
137 QString componentStr = "import Qt 4.7\nFontLoader { source: \"http://localhost:14448/tarzeau_ocr_a.ttf\" }"; |
|
138 QDeclarativeComponent component(&engine); |
|
139 |
|
140 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); |
|
141 QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(component.create()); |
|
142 |
|
143 QVERIFY(fontObject != 0); |
|
144 QVERIFY(fontObject->source() != QUrl("")); |
|
145 QTRY_COMPARE(fontObject->name(), QString("OCRA")); |
|
146 QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready); |
|
147 } |
|
148 |
|
149 void tst_qdeclarativefontloader::redirWebFont() |
|
150 { |
|
151 server.addRedirect("olddir/oldname.ttf","../tarzeau_ocr_a.ttf"); |
|
152 |
|
153 QString componentStr = "import Qt 4.7\nFontLoader { source: \"http://localhost:14448/olddir/oldname.ttf\" }"; |
|
154 QDeclarativeComponent component(&engine); |
|
155 |
|
156 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); |
|
157 QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(component.create()); |
|
158 |
|
159 QVERIFY(fontObject != 0); |
|
160 QVERIFY(fontObject->source() != QUrl("")); |
|
161 QTRY_COMPARE(fontObject->name(), QString("OCRA")); |
|
162 QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Ready); |
|
163 } |
|
164 |
|
165 void tst_qdeclarativefontloader::failWebFont() |
|
166 { |
|
167 QString componentStr = "import Qt 4.7\nFontLoader { source: \"http://localhost:14448/nonexist.ttf\" }"; |
|
168 QTest::ignoreMessage(QtWarningMsg, "file::2:1: QML FontLoader: Cannot load font: \"http://localhost:14448/nonexist.ttf\""); |
|
169 QDeclarativeComponent component(&engine); |
|
170 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); |
|
171 QDeclarativeFontLoader *fontObject = qobject_cast<QDeclarativeFontLoader*>(component.create()); |
|
172 |
|
173 QVERIFY(fontObject != 0); |
|
174 QVERIFY(fontObject->source() != QUrl("")); |
|
175 QTRY_COMPARE(fontObject->name(), QString("")); |
|
176 QTRY_VERIFY(fontObject->status() == QDeclarativeFontLoader::Error); |
|
177 } |
|
178 |
|
179 QTEST_MAIN(tst_qdeclarativefontloader) |
|
180 |
|
181 #include "tst_qdeclarativefontloader.moc" |