Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/tests/AP_gtest.h
9572 views
1
/*
2
* Utility header for unit tests with gtest.
3
*/
4
5
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
6
7
#include <gtest/gtest.h>
8
#include <gtest/gtest-spi.h>
9
10
11
#define AP_GTEST_PRINTATBLE_PARAM_MEMBER(class_name_, printable_member_) \
12
::std::ostream& operator<<(::std::ostream& os, const class_name_& param); \
13
::std::ostream& operator<<(::std::ostream& os, const class_name_& param) \
14
{ \
15
return os << param.printable_member_; \
16
}
17
18
/*
19
* Override the WEAK version of AP_HAL_SITL/system.cpp panic() instead of staying in an infinite loop
20
* This is used by the gtest suite to test for an exit signal caused by a test statement and continue testing
21
* Printing to stderr is required for gtest matching
22
*/
23
#define AP_GTEST_PANIC() \
24
void AP_HAL::panic(const char *errormsg, ...) \
25
{ \
26
va_list ap; \
27
auto outputs = {stdout, stderr}; \
28
for( auto output : outputs) { \
29
fflush(stdout); \
30
fprintf(output, "PANIC: "); \
31
va_start(ap, errormsg); \
32
vfprintf(output, errormsg, ap); \
33
va_end(ap); \
34
fprintf(output, "\n"); \
35
} \
36
abort(); \
37
}
38
39
#define AP_GTEST_MAIN() \
40
int main(int argc, char *argv[]) \
41
{ \
42
::testing::InitGoogleTest(&argc, argv); \
43
return RUN_ALL_TESTS(); \
44
}
45
46