aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/doc/how-tos/how-to-cpp-button/tst_how-to-cpp-button.cpp
blob: a983dd9dfd293a902091d99fd1f185c52281eaf0 (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
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include <QtCore/qregularexpression.h>
#include <QtTest/QtTest>
#include <QtQml/qqmlapplicationengine.h>
#include <QtQuick/qquickwindow.h>
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include <QtQuickControlsTestUtils/private/controlstestutils_p.h>

QT_BEGIN_NAMESPACE

using namespace QQuickControlsTestUtils;

class tst_HowToCppButton : public QObject
{
    Q_OBJECT

public:
    tst_HowToCppButton();

private slots:
    void example();
};

tst_HowToCppButton::tst_HowToCppButton()
{
}

void tst_HowToCppButton::example()
{
    QTest::failOnWarning(QRegularExpression(QStringLiteral(".?")));

    QQmlApplicationEngine engine;
    engine.loadFromModule("MyModule", "Main");
    QCOMPARE(engine.rootObjects().size(), 1);

    auto *window = qobject_cast<QQuickWindow*>(engine.rootObjects().at(0));
    window->show();
    QVERIFY(QTest::qWaitForWindowExposed(window));

    auto *button = window->findChild<QQuickButton*>();
    QVERIFY(button);
    QCOMPARE(button->text(), "Click me");
    QTest::ignoreMessage(QtDebugMsg, "Did stuff!");
    QVERIFY(clickButton(button));
}

QT_END_NAMESPACE

QTEST_MAIN(tst_HowToCppButton)

#include "tst_how-to-cpp-button.moc"