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