aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickfontloader_static/tst_qquickfontloader_static.cpp
blob: ed692fcdd0fb682b2a06b45b56ced720a140fa42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlComponent>
#include <QtQuickTestUtils/private/qmlutils_p.h>
#include <qtest.h>

QByteArray qmltemplate("import QtQuick 2.0\n"
"\n"
"Rectangle {\n"
"    width: 400\n"
"    height: 400\n"
"    color: \"red\"\n"
"    FontLoader { id: fixedFont; source: \"%1\" }\n"
"    Text {\n"
"        text: \"hello world\"\n"
"        anchors.centerIn: parent\n"
"        font.family: fixedFont.name\n"
"    }\n"
"}\n");

int actualTest(int argc, char **argv)
{
    for (int i = 0; i < 3; i++) {
        QGuiApplication app(argc, argv);
        QQmlDataTest dataTest(QT_QMLTEST_DATADIR);
        dataTest.initTestCase();
        QQuickView window;
        QQmlComponent component (window.engine());
        QUrl current = QUrl::fromLocalFile("");
        qmltemplate.replace("%1", dataTest.testFileUrl("font.ttf").toString().toLocal8Bit());
        component.setData(qmltemplate, current);
        window.setContent(current, &component, component.create());
        window.show();
        if (!QTest::qWaitForWindowActive(&window))
            return EXIT_FAILURE;
    }
    return 0;
}

// we need the QTestLib infrastructure to create a log file
struct FontLoaderStaticTester : public QObject
{
    Q_OBJECT

public:
    int result = -1;
private slots:
    void verify() {  QCOMPARE(result, 0); }
};

int main(int argc, char **argv)
{
    int result = actualTest(argc, argv);
    QCoreApplication app(argc, argv);
    FontLoaderStaticTester tester;
    tester.result = result;
    QTest::qExec(&tester, argc, argv);
}

#include "tst_qquickfontloader_static.moc"