aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/doc/how-tos/how-to-cpp-button/tst_how-to-cpp-button.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/doc/how-tos/how-to-cpp-button/tst_how-to-cpp-button.cpp')
-rw-r--r--tests/auto/quick/doc/how-tos/how-to-cpp-button/tst_how-to-cpp-button.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/quick/doc/how-tos/how-to-cpp-button/tst_how-to-cpp-button.cpp b/tests/auto/quick/doc/how-tos/how-to-cpp-button/tst_how-to-cpp-button.cpp
new file mode 100644
index 0000000000..792f84ffc2
--- /dev/null
+++ b/tests/auto/quick/doc/how-tos/how-to-cpp-button/tst_how-to-cpp-button.cpp
@@ -0,0 +1,53 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#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"