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