1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/qtest.h>
30#include <QtQml/qqmlengine.h>
31#include <QtQml/qqmlcontext.h>
32#include <QtQuick/qquickitem.h>
33#include <QQuickView>
34#include <QtQuickTest/quicktest.h>
35
36#include "../../shared/util.h"
37
38class CustomItem : public QQuickItem
39{
40 Q_OBJECT
41
42public:
43 CustomItem() {}
44
45 void updatePolish() override
46 {
47 updatePolishCalled = true;
48 }
49
50 bool updatePolishCalled = false;
51};
52
53class tst_Polish : public QQmlDataTest
54{
55 Q_OBJECT
56
57public:
58 tst_Polish();
59
60private slots:
61 void testPolish();
62};
63
64tst_Polish::tst_Polish()
65{
66 qmlRegisterType<CustomItem>(uri: "Test", versionMajor: 1, versionMinor: 0, qmlName: "CustomItem");
67}
68
69void tst_Polish::testPolish()
70{
71 QQuickView view;
72 view.setSource(testFileUrl(fileName: "polish.qml"));
73 view.show();
74 QVERIFY(QTest::qWaitForWindowExposed(&view));
75
76 CustomItem *item = qobject_cast<CustomItem*>(object: view.rootObject());
77 QVERIFY(item);
78
79 item->polish();
80 QVERIFY(QQuickTest::qIsPolishScheduled(item));
81 QVERIFY(!item->updatePolishCalled);
82 QVERIFY(QQuickTest::qWaitForItemPolished(item));
83 QVERIFY(item->updatePolishCalled);
84}
85
86QTEST_MAIN(tst_Polish)
87
88#include "tst_polish.moc"
89

source code of qtdeclarative/tests/auto/quicktest/polish/tst_polish.cpp