yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
imgui_test_harness_service.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_SERVICE_IMGUI_TEST_HARNESS_SERVICE_H_
2#define YAZE_APP_CORE_SERVICE_IMGUI_TEST_HARNESS_SERVICE_H_
3
4#ifdef YAZE_WITH_GRPC
5
6#include <chrono>
7#include <memory>
8#include <string>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
15
17
18// Include grpcpp headers for gRPC service/server types used in the interface.
19#include <grpcpp/impl/service_type.h>
20#include <grpcpp/server.h>
21
22namespace yaze {
23namespace util {
24class UiThreadQueue;
25}
26namespace test {
27
28// Forward declare TestManager
29class TestManager;
30
31// Forward declare proto types
32class PingRequest;
33class PingResponse;
34class ClickRequest;
35class TypeRequest;
36class TypeResponse;
37class WaitRequest;
38class WaitResponse;
39class AssertRequest;
40class AssertResponse;
41class FlushUiActionsRequest;
42class FlushUiActionsResponse;
43class WaitForIdleRequest;
44class WaitForIdleResponse;
45class GetUiSyncStateRequest;
46class GetUiSyncStateResponse;
47class ScreenshotRequest;
48class ScreenshotResponse;
49class GetTestStatusRequest;
50class GetTestStatusResponse;
51class ListTestsRequest;
52class ListTestsResponse;
53class GetTestResultsRequest;
54class GetTestResultsResponse;
55class DiscoverWidgetsRequest;
56class DiscoverWidgetsResponse;
57class StartRecordingRequest;
58class StartRecordingResponse;
59class StopRecordingResponse;
60class StopRecordingRequest;
61class ReplayTestRequest;
62class ReplayTestResponse;
63
64// Implementation of ImGuiTestHarness gRPC service
65// This class provides the actual RPC handlers for automated GUI testing
66class ImGuiTestHarnessServiceImpl {
67 public:
68 // Constructor now takes TestManager reference for ImGuiTestEngine access
69 explicit ImGuiTestHarnessServiceImpl(
70 TestManager* test_manager,
71 util::UiThreadQueue* ui_thread_queue = nullptr);
72 ~ImGuiTestHarnessServiceImpl() = default;
73
74 // Disable copy and move
75 ImGuiTestHarnessServiceImpl(const ImGuiTestHarnessServiceImpl&) = delete;
76 ImGuiTestHarnessServiceImpl& operator=(const ImGuiTestHarnessServiceImpl&) =
77 delete;
78
79 // RPC Handlers - implemented in imgui_test_harness_service.cc
80
81 // Health check - verifies the service is running
82 absl::Status Ping(const PingRequest* request, PingResponse* response);
83
84 // Click a button or interactive element
85 absl::Status Click(const ClickRequest* request, ClickResponse* response);
86
87 // Type text into an input field
88 absl::Status Type(const TypeRequest* request, TypeResponse* response);
89
90 // Wait for a condition to be true
91 absl::Status Wait(const WaitRequest* request, WaitResponse* response);
92
93 // Assert that a condition is true
94 absl::Status Assert(const AssertRequest* request, AssertResponse* response);
95
96 // Deterministic UI synchronization helpers
97 absl::Status FlushUiActions(const FlushUiActionsRequest* request,
98 FlushUiActionsResponse* response);
99 absl::Status WaitForIdle(const WaitForIdleRequest* request,
100 WaitForIdleResponse* response);
101 absl::Status GetUiSyncState(const GetUiSyncStateRequest* request,
102 GetUiSyncStateResponse* response);
103
104 // Capture a screenshot
105 absl::Status Screenshot(const ScreenshotRequest* request,
106 ScreenshotResponse* response);
107
108 // Test introspection APIs
109 absl::Status GetTestStatus(const GetTestStatusRequest* request,
110 GetTestStatusResponse* response);
111 absl::Status ListTests(const ListTestsRequest* request,
112 ListTestsResponse* response);
113 absl::Status GetTestResults(const GetTestResultsRequest* request,
114 GetTestResultsResponse* response);
115 absl::Status DiscoverWidgets(const DiscoverWidgetsRequest* request,
116 DiscoverWidgetsResponse* response);
117 absl::Status StartRecording(const StartRecordingRequest* request,
118 StartRecordingResponse* response);
119 absl::Status StopRecording(const StopRecordingRequest* request,
120 StopRecordingResponse* response);
121 absl::Status ReplayTest(const ReplayTestRequest* request,
122 ReplayTestResponse* response);
123
124 private:
125 TestManager* test_manager_; // Non-owning pointer to access ImGuiTestEngine
126 util::UiThreadQueue*
127 ui_thread_queue_; // Non-owning; defaults to Controller's queue.
128 WidgetDiscoveryService widget_discovery_service_;
129 TestRecorder test_recorder_;
130};
131
137std::unique_ptr<::grpc::Service> CreateImGuiTestHarnessServiceGrpc(
138 ImGuiTestHarnessServiceImpl* impl);
139
149absl::StatusOr<ScreenshotArtifact> CaptureScreenshotOnRenderThread(
150 const std::string& preferred_path = "",
151 const std::string& window_title = "",
153 std::chrono::milliseconds timeout = std::chrono::seconds(5));
154
155// Singleton server managing the gRPC service
156// This class manages the lifecycle of the gRPC server
157class ImGuiTestHarnessServer {
158 public:
159 // Get the singleton instance
160 static ImGuiTestHarnessServer& Instance();
161
162 // Start the gRPC server on the specified port
163 // @param port The port to listen on (default 50051)
164 // @param test_manager Pointer to TestManager for ImGuiTestEngine access
165 // @return OK status if server started successfully, error otherwise
166 absl::Status Start(int port, TestManager* test_manager);
167
168 // Shutdown the server gracefully
169 void Shutdown();
170
171 // Check if the server is currently running
172 bool IsRunning() const { return server_ != nullptr; }
173
174 // Get the port the server is listening on (0 if not running)
175 int Port() const { return port_; }
176
177 private:
178 ImGuiTestHarnessServer() = default;
179 ~ImGuiTestHarnessServer(); // Defined in .cc file to allow incomplete type
180 // deletion
181
182 // Disable copy and move
183 ImGuiTestHarnessServer(const ImGuiTestHarnessServer&) = delete;
184 ImGuiTestHarnessServer& operator=(const ImGuiTestHarnessServer&) = delete;
185
186 std::unique_ptr<::grpc::Server> server_;
187 std::unique_ptr<ImGuiTestHarnessServiceImpl> service_;
188 std::unique_ptr<::grpc::Service> grpc_service_;
189 int port_ = 0;
190};
191
192} // namespace test
193} // namespace yaze
194
195#endif // YAZE_WITH_GRPC
196#endif // YAZE_APP_CORE_SERVICE_IMGUI_TEST_HARNESS_SERVICE_H_