forked from rerun-io/rerun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_check.hpp
More file actions
41 lines (33 loc) · 1.25 KB
/
error_check.hpp
File metadata and controls
41 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once
#include <catch2/catch_test_macros.hpp>
#include <rerun/error.hpp>
/// Checks if the given operation logs the expected status code.
template <typename Op>
auto check_logged_error(
Op operation, rerun::ErrorCode expected_status_code = rerun::ErrorCode::Ok
) {
static rerun::Error last_logged_status;
// Set to Ok since nothing logged indicates success for most methods.
last_logged_status.code = rerun::ErrorCode::Ok;
rerun::Error::set_log_handler(
[](const rerun::Error& status, void* userdata) {
*static_cast<rerun::Error*>(userdata) = status;
},
&last_logged_status
);
struct CheckOnDestruct {
rerun::ErrorCode expected_status_code;
~CheckOnDestruct() {
CHECK(last_logged_status.code == expected_status_code);
if (expected_status_code != rerun::ErrorCode::Ok) {
CHECK(last_logged_status.description.length() > 0);
} else {
CHECK(last_logged_status.description == "");
}
rerun::Error::set_log_handler(nullptr);
}
} check = {expected_status_code};
// `auto result = operation();` won't compile for void
// but `return operation();` is just fine.
return operation();
}