yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
test_recorder.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_TESTING_TEST_RECORDER_H_
2#define YAZE_APP_CORE_TESTING_TEST_RECORDER_H_
3
4#include <map>
5#include <string>
6#include <vector>
7
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
10#include "absl/synchronization/mutex.h"
11#include "absl/time/time.h"
13
14namespace yaze {
15namespace test {
16
17class TestManager;
18
19// Recorder responsible for capturing GUI automation RPCs and exporting them as
20// replayable JSON test scripts.
22 public:
23 enum class ActionType {
25 kClick,
26 kType,
27 kWait,
28 kAssert,
30 };
31
33 std::string output_path;
34 std::string session_name;
35 std::string description;
36 };
37
38 struct RecordedStep {
40 std::string target;
41 std::string widget_key;
42 std::string text;
43 std::string condition;
44 std::string click_type;
45 std::string region;
46 std::string format;
47 int timeout_ms = 0;
48 bool clear_first = false;
49 bool success = false;
51 std::string message;
52 std::string test_id;
53 std::vector<std::string> assertion_failures;
54 std::string expected_value;
55 std::string actual_value;
56#if defined(YAZE_WITH_GRPC)
57 HarnessTestStatus final_status = HarnessTestStatus::kUnspecified;
58#endif
60 std::map<std::string, int32_t> metrics;
61 absl::Time captured_at = absl::InfinitePast();
62 };
63
65 bool saved = false;
66 std::string output_path;
67 int step_count = 0;
68 absl::Duration duration = absl::ZeroDuration();
69 };
70
72 public:
73 ScopedSuspension(TestRecorder* recorder, bool active);
77
78 private:
80 bool active_ = false;
81 };
82
83 explicit TestRecorder(TestManager* test_manager);
84
85 absl::StatusOr<std::string> Start(const RecordingOptions& options);
86 absl::StatusOr<StopRecordingSummary> Stop(const std::string& recording_id,
87 bool discard);
88
89 void RecordStep(const RecordedStep& step);
90
91 bool IsRecording() const;
92 std::string CurrentRecordingId() const;
93
95
96 private:
97 absl::StatusOr<std::string> StartLocked(const RecordingOptions& options)
98 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
99 absl::StatusOr<StopRecordingSummary> StopLocked(
100 const std::string& recording_id, bool discard)
101 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
102 void RecordStepLocked(const RecordedStep& step)
103 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
104
105 absl::Status PopulateFinalStatusLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
106
107 static std::string GenerateRecordingId();
108 static const char* ActionTypeToString(ActionType type);
109
110 mutable absl::Mutex mu_;
111 TestManager* const test_manager_; // Not owned
112 bool recording_ ABSL_GUARDED_BY(mu_) = false;
113 bool suspended_ ABSL_GUARDED_BY(mu_) = false;
114 std::string recording_id_ ABSL_GUARDED_BY(mu_);
116 absl::Time started_at_ ABSL_GUARDED_BY(mu_) = absl::InfinitePast();
117 std::vector<RecordedStep> steps_ ABSL_GUARDED_BY(mu_);
118};
119
120} // namespace test
121} // namespace yaze
122
123#endif // YAZE_APP_CORE_TESTING_TEST_RECORDER_H_
ScopedSuspension(const ScopedSuspension &)=delete
ScopedSuspension(TestRecorder *recorder, bool active)
ScopedSuspension & operator=(const ScopedSuspension &)=delete
void RecordStepLocked(const RecordedStep &step) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
static std::string GenerateRecordingId()
absl::StatusOr< StopRecordingSummary > StopLocked(const std::string &recording_id, bool discard) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
absl::Status PopulateFinalStatusLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
TestManager *const test_manager_
TestRecorder(TestManager *test_manager)
absl::StatusOr< std::string > Start(const RecordingOptions &options)
absl::StatusOr< StopRecordingSummary > Stop(const std::string &recording_id, bool discard)
bool recording_ ABSL_GUARDED_BY(mu_)
ScopedSuspension Suspend()
static const char * ActionTypeToString(ActionType type)
absl::StatusOr< std::string > StartLocked(const RecordingOptions &options) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
void RecordStep(const RecordedStep &step)
std::string CurrentRecordingId() const
std::vector< std::string > assertion_failures
std::map< std::string, int32_t > metrics