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