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