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 text;
42 std::string condition;
43 std::string click_type;
44 std::string region;
45 std::string format;
46 int timeout_ms = 0;
47 bool clear_first = false;
48 bool success = false;
50 std::string message;
51 std::string test_id;
52 std::vector<std::string> assertion_failures;
53 std::string expected_value;
54 std::string actual_value;
55#if defined(YAZE_WITH_GRPC)
56 HarnessTestStatus final_status = HarnessTestStatus::kUnspecified;
57#endif
59 std::map<std::string, int32_t> metrics;
60 absl::Time captured_at = absl::InfinitePast();
61 };
62
64 bool saved = false;
65 std::string output_path;
66 int step_count = 0;
67 absl::Duration duration = absl::ZeroDuration();
68 };
69
71 public:
72 ScopedSuspension(TestRecorder* recorder, bool active);
76
77 private:
79 bool active_ = false;
80 };
81
82 explicit TestRecorder(TestManager* test_manager);
83
84 absl::StatusOr<std::string> Start(const RecordingOptions& options);
85 absl::StatusOr<StopRecordingSummary> Stop(const std::string& recording_id,
86 bool discard);
87
88 void RecordStep(const RecordedStep& step);
89
90 bool IsRecording() const;
91 std::string CurrentRecordingId() const;
92
94
95 private:
96 absl::StatusOr<std::string> StartLocked(const RecordingOptions& options)
97 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
98 absl::StatusOr<StopRecordingSummary> StopLocked(const std::string& recording_id,
99 bool discard)
100 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
101 void RecordStepLocked(const RecordedStep& step)
102 ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
103
104 absl::Status PopulateFinalStatusLocked()
105 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 & 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_
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
Main namespace for the application.
std::vector< std::string > assertion_failures
std::map< std::string, int32_t > metrics