yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
common.cc
Go to the documentation of this file.
2
3#include "absl/strings/ascii.h"
4#include "absl/strings/str_cat.h"
5#include "absl/strings/str_format.h"
6#include "absl/strings/str_replace.h"
7
8namespace yaze {
9namespace cli {
10namespace agent {
11
12std::string HarnessAddress(const std::string& host, int port) {
13 return absl::StrFormat("%s:%d", host, port);
14}
15
16std::string JsonEscape(absl::string_view value) {
17 std::string out;
18 out.reserve(value.size() + 8);
19 for (unsigned char c : value) {
20 switch (c) {
21 case '\\':
22 out += "\\\\";
23 break;
24 case '"':
25 out += "\\\"";
26 break;
27 case '\b':
28 out += "\\b";
29 break;
30 case '\f':
31 out += "\\f";
32 break;
33 case '\n':
34 out += "\\n";
35 break;
36 case '\r':
37 out += "\\r";
38 break;
39 case '\t':
40 out += "\\t";
41 break;
42 default:
43 if (c < 0x20) {
44 absl::StrAppend(&out,
45 absl::StrFormat("\\u%04X", static_cast<int>(c)));
46 } else {
47 out.push_back(static_cast<char>(c));
48 }
49 }
50 }
51 return out;
52}
53
54std::string YamlQuote(absl::string_view value) {
55 std::string escaped(value);
56 absl::StrReplaceAll({{"\\", "\\\\"}, {"\"", "\\\""}}, &escaped);
57 return absl::StrCat("\"", escaped, "\"");
58}
59
60std::string FormatOptionalTime(const std::optional<absl::Time>& time) {
61 if (!time.has_value()) {
62 return "n/a";
63 }
64 return absl::FormatTime("%Y-%m-%dT%H:%M:%SZ", *time, absl::UTCTimeZone());
65}
66
67std::string OptionalTimeToIso(const std::optional<absl::Time>& time) {
68 if (!time.has_value()) {
69 return "";
70 }
71 return absl::FormatTime("%Y-%m-%dT%H:%M:%SZ", *time, absl::UTCTimeZone());
72}
73
74std::string OptionalTimeToJson(const std::optional<absl::Time>& time) {
75 std::string iso = OptionalTimeToIso(time);
76 if (iso.empty()) {
77 return "null";
78 }
79 return absl::StrCat("\"", JsonEscape(iso), "\"");
80}
81
82std::string OptionalTimeToYaml(const std::optional<absl::Time>& time) {
83 std::string iso = OptionalTimeToIso(time);
84 if (iso.empty()) {
85 return "null";
86 }
87 return iso;
88}
89
90#ifdef YAZE_WITH_GRPC
91const char* TestRunStatusToString(TestRunStatus status) {
92 switch (status) {
94 return "QUEUED";
96 return "RUNNING";
98 return "PASSED";
100 return "FAILED";
102 return "TIMEOUT";
104 default:
105 return "UNKNOWN";
106 }
107}
108
109bool IsTerminalStatus(TestRunStatus status) {
110 switch (status) {
113 return false;
118 default:
119 return true;
120 }
121}
122
123std::optional<TestRunStatus> ParseStatusFilter(absl::string_view value) {
124 std::string lower = std::string(absl::AsciiStrToLower(value));
125 if (lower == "queued")
127 if (lower == "running")
129 if (lower == "passed")
131 if (lower == "failed")
133 if (lower == "timeout")
135 if (lower == "unknown")
137 return std::nullopt;
138}
139
140std::optional<WidgetTypeFilter> ParseWidgetTypeFilter(absl::string_view value) {
141 std::string lower = std::string(absl::AsciiStrToLower(value));
142 if (lower.empty() || lower == "unspecified" || lower == "any") {
144 }
145 if (lower == "all") {
147 }
148 if (lower == "button" || lower == "buttons") {
150 }
151 if (lower == "input" || lower == "textbox" || lower == "field") {
153 }
154 if (lower == "menu" || lower == "menuitem" || lower == "menu-item") {
156 }
157 if (lower == "tab" || lower == "tabs") {
159 }
160 if (lower == "checkbox" || lower == "toggle") {
162 }
163 if (lower == "slider" || lower == "drag" || lower == "sliderfloat") {
165 }
166 if (lower == "canvas" || lower == "viewport") {
168 }
169 if (lower == "selectable" || lower == "list-item") {
171 }
172 if (lower == "other") {
174 }
175 return std::nullopt;
176}
177#endif // YAZE_WITH_GRPC
178
179} // namespace agent
180} // namespace cli
181} // namespace yaze
std::string FormatOptionalTime(const std::optional< absl::Time > &time)
Definition common.cc:60
std::string YamlQuote(absl::string_view value)
Definition common.cc:54
std::string OptionalTimeToYaml(const std::optional< absl::Time > &time)
Definition common.cc:82
std::string HarnessAddress(const std::string &host, int port)
Definition common.cc:12
std::string JsonEscape(absl::string_view value)
Definition common.cc:16
std::string OptionalTimeToJson(const std::optional< absl::Time > &time)
Definition common.cc:74
std::string OptionalTimeToIso(const std::optional< absl::Time > &time)
Definition common.cc:67
TestRunStatus
Execution status codes returned by the harness.