Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | #include "app.hpp" | ||
3 | #include "result.hpp" | ||
4 | #include "testing.hpp" | ||
5 | |||
6 | 1 | bool test_result() | |
7 | { | ||
8 | { | ||
9 | // test error | ||
10 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | const std::string err_msg("error message"); |
11 | |||
12 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const cpp::result::error err(err_msg); |
13 | |||
14 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (err.msg() != err_msg) |
15 | ✗ | return false; | |
16 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | } |
17 | |||
18 | { | ||
19 | // test error | ||
20 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | const std::string err_msg("error message"); |
21 | |||
22 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const cpp::result::error err("error message"); |
23 | |||
24 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (err.msg() != err_msg) |
25 | ✗ | return false; | |
26 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | } |
27 | |||
28 | { | ||
29 | 1 | const auto ref = 123; | |
30 | 1 | const cpp::result::result<int> res{ref}; | |
31 | |||
32 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!res.valid()) |
33 | ✗ | return false; | |
34 | |||
35 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (res.error()) |
36 | ✗ | return false; | |
37 | |||
38 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const auto value = res.value(); |
39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (value != ref) |
40 | ✗ | return false; | |
41 | |||
42 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | const auto err_msg = res.err_msg(); |
43 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (err_msg != cpp::result::msg_invalid_call) |
44 | ✗ | return false; | |
45 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | } |
46 | |||
47 | { | ||
48 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | const std::string ref{"error message"}; |
49 | |||
50 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const cpp::result::error err{ref}; |
51 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const cpp::result::result<int> res{err}; |
52 | |||
53 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (res.valid()) |
54 | ✗ | return false; | |
55 | |||
56 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!res.error()) |
57 | ✗ | return false; | |
58 | |||
59 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | const auto err_msg = res.err_msg(); |
60 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (err_msg == cpp::result::msg_invalid_call) |
61 | ✗ | return false; | |
62 | |||
63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (err_msg != ref) |
64 | ✗ | return false; | |
65 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
1 | } |
66 | |||
67 | { | ||
68 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!cpp::result::SUCCESS.valid()) |
69 | ✗ | return false; | |
70 | |||
71 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (cpp::result::SUCCESS.error()) |
72 | ✗ | return false; | |
73 | |||
74 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | const auto err_msg = cpp::result::SUCCESS.err_msg(); |
75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (err_msg != cpp::result::msg_invalid_call) |
76 | ✗ | return false; | |
77 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | } |
78 | |||
79 | { | ||
80 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | const std::string ref{"error message"}; |
81 | |||
82 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const cpp::result::error err{ref}; |
83 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | cpp::result::result_void res_err{err}; |
84 | |||
85 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (res_err.valid()) |
86 | ✗ | return false; | |
87 | |||
88 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!res_err.error()) |
89 | ✗ | return false; | |
90 | |||
91 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | const auto err_msg = res_err.err_msg(); |
92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (err_msg != ref) |
93 | ✗ | return false; | |
94 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
1 | } |
95 | |||
96 | 1 | return true; | |
97 | } | ||
98 | |||
99 | 2 | cpp::result::result_void test_case(bool success) | |
100 | { | ||
101 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (success) |
102 | 1 | return cpp::result::SUCCESS; | |
103 | |||
104 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | return cpp::result::report_error("Expected Failure"); |
105 | } | ||
106 | |||
107 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | cpp::result::result_void test_case_check(bool success) |
108 | { | ||
109 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return cpp::testing::check("Test Case Check", success == true); |
110 | } | ||
111 | |||
112 | 2 | cpp::result::result_void test_case_check_macro(bool success) | |
113 | { | ||
114 |
4/6✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
3 | CHECK_("Test Case Macro", success == true); |
115 | |||
116 | 1 | return cpp::result::SUCCESS; | |
117 | } | ||
118 | |||
119 | 1 | bool test_testing() | |
120 | { | ||
121 | { | ||
122 | 1 | auto alias = std::bind(test_case, true); | |
123 | |||
124 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | const auto res = cpp::testing::run_test("test_case() success", alias); |
125 | |||
126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!res) |
127 | ✗ | return false; | |
128 | } | ||
129 | |||
130 | { | ||
131 | 1 | auto alias = std::bind(test_case, false); | |
132 | |||
133 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | const auto res = cpp::testing::run_test("test_case() failure", alias); |
134 | |||
135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (res) |
136 | ✗ | return false; | |
137 | } | ||
138 | |||
139 | { | ||
140 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const auto res = cpp::testing::check("Base Check", true); |
141 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (res.error()) |
142 | ✗ | return false; | |
143 | |||
144 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!res.valid()) |
145 | ✗ | return true; | |
146 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | } |
147 | |||
148 | { | ||
149 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const auto res = cpp::testing::check("Base Check", false); |
150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!res.error()) |
151 | ✗ | return false; | |
152 | |||
153 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (res.valid()) |
154 | ✗ | return true; | |
155 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | } |
156 | |||
157 | { | ||
158 | 1 | auto alias = std::bind(test_case_check, true); | |
159 | |||
160 | const auto res = | ||
161 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | cpp::testing::run_test("test_case_check() success", alias); |
162 | |||
163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!res) |
164 | ✗ | return false; | |
165 | } | ||
166 | |||
167 | { | ||
168 | 1 | auto alias = std::bind(test_case_check, false); | |
169 | |||
170 | const auto res = | ||
171 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | cpp::testing::run_test("test_case_check() failure", alias); |
172 | |||
173 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (res) |
174 | ✗ | return false; | |
175 | } | ||
176 | |||
177 | { | ||
178 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const auto res = test_case_check_macro(true); |
179 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (res.error()) |
180 | ✗ | return false; | |
181 | |||
182 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!res.valid()) |
183 | ✗ | return true; | |
184 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | } |
185 | |||
186 | { | ||
187 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const auto res = test_case_check_macro(false); |
188 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!res.error()) |
189 | ✗ | return false; | |
190 | |||
191 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (res.valid()) |
192 | ✗ | return true; | |
193 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | } |
194 | |||
195 | 1 | return true; | |
196 | } | ||
197 | |||
198 | 1 | int main() | |
199 | { | ||
200 | { | ||
201 | 1 | const auto res = test_result(); | |
202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!res) |
203 | ✗ | return cpp::app::FAILURE; | |
204 | } | ||
205 | |||
206 | { | ||
207 | 1 | const auto res = test_testing(); | |
208 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!res) |
209 | ✗ | return cpp::app::FAILURE; | |
210 | } | ||
211 | |||
212 | 1 | return cpp::app::SUCCESS; | |
213 | } | ||
214 |