15#include <QtGui/QShortcut>
16#include <QtQml/QQmlComponent>
17#include <QtQml/QQmlEngine>
18#include <QtQuick/QQuickItem>
19#include <QtQuick/QQuickWindow>
20#include <QtTest/QTest>
21#include <QtWidgets/QApplication>
22#include <QtWidgets/QCheckBox>
23#include <QtWidgets/QLabel>
24#include <QtWidgets/QLineEdit>
25#include <QtWidgets/QListWidget>
26#include <QtWidgets/QPushButton>
27#include <QtWidgets/QSlider>
28#include <QtWidgets/QVBoxLayout>
29#include <QtWidgets/QWidget>
31#include <gtest/gtest.h>
53 form->activateWindow();
54 ASSERT_TRUE(QTest::qWaitForWindowExposed(
form.get()));
55 (void)QTest::qWaitForWindowActive(
form.get(), 1000);
73 QJsonObject
call(
const QString &tool,
const QJsonObject &args = { })
75 return client->callTool(tool, args);
78 QString
text(
const QString &tool,
const QJsonObject &args = { })
80 return client->callToolText(tool, args);
83 bool fails(
const QString &tool,
const QJsonObject &args = { })
85 return call(tool, args).value(QStringLiteral(
"isError")).toBool();
92 std::unique_ptr<QWidget>
form;
97 QListWidget *
list =
nullptr;
103 std::unique_ptr<QQuickWindow>
quick;
109 form = std::make_unique<QWidget>();
110 form->setObjectName(QStringLiteral(
"form"));
111 form->setWindowTitle(QStringLiteral(
"Form Window"));
112 auto *layout =
new QVBoxLayout(
form.get());
113 edit =
new QLineEdit;
114 edit->setObjectName(QStringLiteral(
"edit"));
115 button =
new QPushButton(QStringLiteral(
"&Press"));
116 button->setObjectName(QStringLiteral(
"button"));
118 check =
new QCheckBox(QStringLiteral(
"Check"));
119 check->setObjectName(QStringLiteral(
"check"));
120 slider =
new QSlider(Qt::Horizontal);
121 slider->setObjectName(QStringLiteral(
"slider"));
123 list =
new QListWidget;
124 list->setObjectName(QStringLiteral(
"list"));
125 for (
int i = 0; i < 200; ++i)
126 list->addItem(QStringLiteral(
"item %1").arg(i));
127 hiddenLabel =
new QLabel(QStringLiteral(
"secret"));
128 hiddenLabel->setObjectName(QStringLiteral(
"hiddenLabel"));
132 layout->addWidget(w);
133 auto *shortcut =
new QShortcut(QKeySequence(QStringLiteral(
"Ctrl+K")),
form.get());
134 shortcut->setContext(Qt::ApplicationShortcut);
135 QObject::connect(shortcut, &QShortcut::activated, [
this] { ++
shortcutHits; });
136 form->resize(320, 480);
145 QQmlComponent component(&
engine);
146 component.setData(R
"(
149 objectName: "quickWin"
150 title: "Quick Window"
151 width: 300; height: 200; x: 400; y: 10
153 property int clicks: 0
156 x: 10; y: 10; width: 100; height: 50
158 MouseArea { objectName: "boxArea"; anchors.fill: parent; onClicked: clicks++ }
160 TextInput { objectName: "input"; x: 10; y: 100; width: 200; height: 30 }
161 Rectangle { objectName: "invisible"; visible: false; width: 10; height: 10 }
162 Rectangle { objectName: "transparent"; x: 250; y: 150; width: 40; height: 40; opacity: 0 }
165 quick.reset(qobject_cast<QQuickWindow *>(component.create()));
166 ASSERT_TRUE(quick) << component.errorString().toStdString();
167 ASSERT_TRUE(QTest::qWaitForWindowExposed(quick.get()));
Fixture with a fully equipped server, a widget form and a QML window.
Definition guifixture.h:37
QString name
Local socket name of the server.
Definition guifixture.h:89
void SetUp() override
Installs integrations and tools, builds and shows both windows.
Definition guifixture.h:40
virtual bool withQuick() const
Whether this test needs the QML window (override to skip it).
Definition guifixture.h:70
bool fails(const QString &tool, const QJsonObject &args={ })
Calls a tool and reports whether it returned an error result.
Definition guifixture.h:83
int shortcutHits
Times the Ctrl+K shortcut fired.
Definition guifixture.h:100
std::unique_ptr< LocalClient > client
Initialized client.
Definition guifixture.h:90
void buildForm()
Builds the Qt Widgets form.
Definition guifixture.h:107
QLineEdit * edit
Line edit "edit" (has focus initially).
Definition guifixture.h:93
std::unique_ptr< QQuickWindow > quick
The Qt Quick window ("Quick Window").
Definition guifixture.h:103
QPushButton * button
Push button "button" ("&Press").
Definition guifixture.h:94
QJsonObject call(const QString &tool, const QJsonObject &args={ })
Calls a tool and returns its result.
Definition guifixture.h:73
void buildQuick()
Builds the Qt Quick window from inline QML.
Definition guifixture.h:143
QLabel * hiddenLabel
Hidden label "hiddenLabel".
Definition guifixture.h:98
Sonde::Server server
Server under test.
Definition guifixture.h:88
void TearDown() override
Destroys the windows (before the server).
Definition guifixture.h:62
int buttonClicks
Times button was clicked.
Definition guifixture.h:99
QSlider * slider
Horizontal slider "slider", 0-100.
Definition guifixture.h:96
QString text(const QString &tool, const QJsonObject &args={ })
Calls a tool and returns its text.
Definition guifixture.h:78
QCheckBox * check
Check box "check".
Definition guifixture.h:95
QListWidget * list
List "list" with 200 items (scrollable).
Definition guifixture.h:97
QQmlEngine engine
Engine of the QML window.
Definition guifixture.h:102
std::unique_ptr< QWidget > form
The widgets window ("Form Window").
Definition guifixture.h:92
An embeddable Model Context Protocol server.
Definition server.h:92
bool listenLocal(const QString &name)
Starts (or restarts) the local socket transport.
Definition server.cpp:563
void installQuickIntegration()
Teaches the GUI tools about Qt Quick.
Definition quickintegration.cpp:515
QmlTemplateTrust * installQmlTools(Server &server)
Registers qml_eval, qml_binding and the QML window tools (installQmlWindowTools()).
Definition qmltools.cpp:177
void installWidgetsIntegration()
Teaches the GUI tools about Qt Widgets.
Definition widgetsintegration.cpp:301
void installStandardTools(Server &server)
Registers everything above, the QObject introspection tools, a LogEventSource that feeds Qt log outpu...
Definition windowtools.cpp:715
Qt Quick support for the GUI tools.
Sonde::Server, the embeddable MCP server.
QString uniqueName(const QString &prefix)
Returns a process-unique name with the given prefix (for sockets).
Definition testsupport.cpp:49
Helpers shared by the Sonde unit tests: event-loop waiting and in-process MCP clients for the local-s...