aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest/doc/snippets/testApp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmltest/doc/snippets/testApp')
-rw-r--r--src/qmltest/doc/snippets/testApp/CMakeLists.txt46
-rw-r--r--src/qmltest/doc/snippets/testApp/MyModule/CMakeLists.txt32
-rw-r--r--src/qmltest/doc/snippets/testApp/MyModule/MyButton.qml12
-rw-r--r--src/qmltest/doc/snippets/testApp/tests/CMakeLists.txt29
-rw-r--r--src/qmltest/doc/snippets/testApp/tests/main.cpp9
-rw-r--r--src/qmltest/doc/snippets/testApp/tests/setup.cpp21
-rw-r--r--src/qmltest/doc/snippets/testApp/tests/setup.h24
-rw-r--r--src/qmltest/doc/snippets/testApp/tests/tst_testqml.qml31
8 files changed, 204 insertions, 0 deletions
diff --git a/src/qmltest/doc/snippets/testApp/CMakeLists.txt b/src/qmltest/doc/snippets/testApp/CMakeLists.txt
new file mode 100644
index 0000000000..cdf7b9555e
--- /dev/null
+++ b/src/qmltest/doc/snippets/testApp/CMakeLists.txt
@@ -0,0 +1,46 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.20)
+
+project(MyApplication VERSION 0.1 LANGUAGES CXX)
+
+qt_standard_project_setup(REQUIRES 6.6)
+
+find_package(Qt6 COMPONENTS REQUIRED Quick QuickControls2)
+
+#! [project-cmake]
+add_subdirectory(MyModule)
+add_subdirectory(tests)
+
+qt_add_executable(MyApplication
+ src/main.cpp
+)
+
+qt_add_qml_module(MyApplication
+ URI MyApplication
+ QML_FILES main.qml
+)
+#! [project-cmake]
+
+set_target_properties(MyApplication PROPERTIES
+ MACOSX_BUNDLE_GUI_IDENTIFIER my.demoapp.com
+ MACOSX_BUNDLE TRUE
+ WIN32_EXECUTABLE TRUE
+)
+
+target_include_directories(MyApplication
+ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
+)
+
+target_link_libraries(MyApplication
+ PRIVATE
+ Qt6::Quick
+ Qt6::QuickControls2
+ MyModule
+)
+
+install(TARGETS MyApplication
+ BUNDLE DESTINATION .
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
diff --git a/src/qmltest/doc/snippets/testApp/MyModule/CMakeLists.txt b/src/qmltest/doc/snippets/testApp/MyModule/CMakeLists.txt
new file mode 100644
index 0000000000..4d293c27d8
--- /dev/null
+++ b/src/qmltest/doc/snippets/testApp/MyModule/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.20)
+
+project(${MODULE_NAME} LANGUAGES CXX)
+
+qt_standard_project_setup(REQUIRES 6.6)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
+
+#! [add library]
+qt_add_library(MyModule STATIC)
+
+qt6_add_qml_module(MyModule
+ URI MyModule
+ QML_FILES MyButton.qml
+)
+#! [add library]
+
+set_target_properties(MyModule PROPERTIES
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(MyModule PRIVATE
+ Qt::Core
+ Qt::Gui
+ Qt::Qml
+ Qt::Quick
+)
+
+target_include_directories(MyModule PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/src/qmltest/doc/snippets/testApp/MyModule/MyButton.qml b/src/qmltest/doc/snippets/testApp/MyModule/MyButton.qml
new file mode 100644
index 0000000000..47e32c3b6c
--- /dev/null
+++ b/src/qmltest/doc/snippets/testApp/MyModule/MyButton.qml
@@ -0,0 +1,12 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+//! [define]
+import QtQuick
+import QtQuick.Controls
+
+Button {
+ width: 50
+ height: 50
+ onClicked: width = 100
+}
+//! [define]
diff --git a/src/qmltest/doc/snippets/testApp/tests/CMakeLists.txt b/src/qmltest/doc/snippets/testApp/tests/CMakeLists.txt
new file mode 100644
index 0000000000..5533403bdc
--- /dev/null
+++ b/src/qmltest/doc/snippets/testApp/tests/CMakeLists.txt
@@ -0,0 +1,29 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.2)
+
+project(TestMyApplication LANGUAGES CXX)
+
+enable_testing()
+
+find_package(Qt6 REQUIRED COMPONENTS QuickTest Qml)
+
+qt_standard_project_setup(REQUIRES 6.6)
+
+add_definitions(-DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
+
+#! [link against library]
+add_executable(TestMyApplication main.cpp
+ setup.cpp setup.h)
+
+add_test(NAME TestMyApplication COMMAND TestMyApplication)
+
+target_link_libraries(TestMyApplication
+ PRIVATE
+ Qt6::QuickTest
+ Qt6::Qml
+ MyModule
+ MyModuleplugin
+)
+#! [link against library]
diff --git a/src/qmltest/doc/snippets/testApp/tests/main.cpp b/src/qmltest/doc/snippets/testApp/tests/main.cpp
new file mode 100644
index 0000000000..cf68ddb5de
--- /dev/null
+++ b/src/qmltest/doc/snippets/testApp/tests/main.cpp
@@ -0,0 +1,9 @@
+// # Copyright (C) 2023 The Qt Company Ltd.
+// # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [main]
+#include <QtQuickTest/quicktest.h>
+#include "setup.h"
+
+QUICK_TEST_MAIN_WITH_SETUP(TestQML, Setup)
+//! [main]
diff --git a/src/qmltest/doc/snippets/testApp/tests/setup.cpp b/src/qmltest/doc/snippets/testApp/tests/setup.cpp
new file mode 100644
index 0000000000..4ecac48d35
--- /dev/null
+++ b/src/qmltest/doc/snippets/testApp/tests/setup.cpp
@@ -0,0 +1,21 @@
+// # Copyright (C) 2023 The Qt Company Ltd.
+// # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [setup]
+#include "setup.h"
+
+void Setup::applicationAvailable()
+{
+ // custom code that doesn't require QQmlEngine
+}
+
+void Setup::qmlEngineAvailable(QQmlEngine *engine)
+{
+ // add import paths
+}
+
+void Setup::cleanupTestCase()
+{
+ // custom code to clean up before destruction starts
+}
+//! [setup]
diff --git a/src/qmltest/doc/snippets/testApp/tests/setup.h b/src/qmltest/doc/snippets/testApp/tests/setup.h
new file mode 100644
index 0000000000..ea6a699f2f
--- /dev/null
+++ b/src/qmltest/doc/snippets/testApp/tests/setup.h
@@ -0,0 +1,24 @@
+// # Copyright (C) 2023 The Qt Company Ltd.
+// # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [setup]
+#ifndef SETUP_H
+#define SETUP_H
+
+#include <QObject>
+#include <QQmlEngine>
+
+class Setup : public QObject
+{
+ Q_OBJECT
+public:
+ Setup() = default;
+
+public slots:
+ void applicationAvailable();
+ void qmlEngineAvailable(QQmlEngine *engine);
+ void cleanupTestCase();
+};
+
+#endif // SETUP_H
+//! [setup]
diff --git a/src/qmltest/doc/snippets/testApp/tests/tst_testqml.qml b/src/qmltest/doc/snippets/testApp/tests/tst_testqml.qml
new file mode 100644
index 0000000000..5973a31ebb
--- /dev/null
+++ b/src/qmltest/doc/snippets/testApp/tests/tst_testqml.qml
@@ -0,0 +1,31 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+//! [import]
+import QtQuick
+import QtQuick.Controls
+
+import QtTest
+import MyModule
+
+Item {
+ width: 800
+ height: 600
+
+ MyButton {
+ id: myButton
+ anchors.centerIn: parent
+ }
+
+ TestCase {
+ name: "MyButton"
+ when: windowShown
+
+ function test_clickToExpand() {
+ const widthBeforeClick = myButton.width;
+ mouseClick(myButton);
+ const widthAfterClick = myButton.width;
+ verify(widthBeforeClick < widthAfterClick);
+ }
+ }
+}
+//! [import]