1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15
16 #include "pw_unit_test/framework_backend.h" // IWYU pragma: export
17 #include "pw_unit_test/status_macros.h" // IWYU pragma: export
18
19 // Check that the backend defined the following.
20
21 #ifndef GTEST_TEST
22 #error \
23 "The pw_unit_test framework backend must define " \
24 "GTEST_TEST(test_suite_name, test_name)"
25 #endif // GTEST_TEST
26
27 #ifndef TEST
28 #error \
29 "The pw_unit_test framework backend must define " \
30 "TEST(test_suite_name, test_name)"
31 #endif // TEST
32
33 #ifndef TEST_F
34 #error \
35 "The pw_unit_test framework backend must define " \
36 "TEST_F(test_fixture, test_name)"
37 #endif // TEST_F
38
39 #ifndef FRIEND_TEST
40 #error \
41 "The pw_unit_test framework backend must define " \
42 "FRIEND_TEST(test_suite_name, test_name)"
43 #endif // FRIEND_TEST
44
45 #ifndef EXPECT_TRUE
46 #error "The pw_unit_test framework backend must define EXPECT_TRUE(expr)"
47 #endif // EXPECT_TRUE
48
49 #ifndef EXPECT_FALSE
50 #error "The pw_unit_test framework backend must define EXPECT_FALSE(expr)"
51 #endif // EXPECT_FALSE
52
53 #ifndef EXPECT_EQ
54 #error "The pw_unit_test framework backend must define EXPECT_EQ(lhs, rhs)"
55 #endif // EXPECT_EQ
56
57 #ifndef EXPECT_NE
58 #error "The pw_unit_test framework backend must define EXPECT_NE(lhs, rhs)"
59 #endif // EXPECT_EQ
60
61 #ifndef EXPECT_GT
62 #error "The pw_unit_test framework backend must define EXPECT_GT(lhs, rhs)"
63 #endif // EXPECT_GT
64
65 #ifndef EXPECT_GE
66 #error "The pw_unit_test framework backend must define EXPECT_GE(lhs, rhs)"
67 #endif // EXPECT_GE
68
69 #ifndef EXPECT_LT
70 #error "The pw_unit_test framework backend must define EXPECT_LT(lhs, rhs)"
71 #endif // EXPECT_LT
72
73 #ifndef EXPECT_LE
74 #error "The pw_unit_test framework backend must define EXPECT_LE(lhs, rhs)"
75 #endif // EXPECT_LE
76
77 #ifndef EXPECT_NEAR
78 #error \
79 "The pw_unit_test framework backend must define " \
80 "EXPECT_NEAR(lhs, rhs, epsilon)"
81 #endif // EXPECT_NEAR
82
83 #ifndef EXPECT_FLOAT_EQ
84 #error \
85 "The pw_unit_test framework backend must define EXPECT_FLOAT_EQ(lhs, rhs)"
86 #endif // EXPECT_FLOAT_EQ
87
88 #ifndef EXPECT_DOUBLE_EQ
89 #error \
90 "The pw_unit_test framework backend must define EXPECT_DOUBLE_EQ(lhs, rhs)"
91 #endif // EXPECT_DOUBLE_EQ
92
93 #ifndef EXPECT_STREQ
94 #error "The pw_unit_test framework backend must define EXPECT_STREQ(lhs, rhs)"
95 #endif // EXPECT_STREQ
96
97 #ifndef EXPECT_STRNE
98 #error "The pw_unit_test framework backend must define EXPECT_STRNE(lhs, rhs)"
99 #endif // EXPECT_STRNE
100
101 #ifndef ASSERT_TRUE
102 #error "The pw_unit_test framework backend must define ASSERT_TRUE(expr)"
103 #endif // ASSERT_TRUE
104
105 #ifndef ASSERT_FALSE
106 #error "The pw_unit_test framework backend must define ASSERT_FALSE(expr)"
107 #endif // ASSERT_FALSE
108
109 #ifndef ASSERT_EQ
110 #error "The pw_unit_test framework backend must define ASSERT_EQ(lhs, rhs)"
111 #endif // ASSERT_EQ
112
113 #ifndef ASSERT_NE
114 #error "The pw_unit_test framework backend must define ASSERT_NE(lhs, rhs)"
115 #endif // ASSERT_NE
116
117 #ifndef ASSERT_GT
118 #error "The pw_unit_test framework backend must define ASSERT_GT(lhs, rhs)"
119 #endif // ASSERT_GT
120
121 #ifndef ASSERT_GE
122 #error "The pw_unit_test framework backend must define ASSERT_GE(lhs, rhs)"
123 #endif // ASSERT_GE
124
125 #ifndef ASSERT_LT
126 #error "The pw_unit_test framework backend must define ASSERT_LT(lhs, rhs)"
127 #endif // ASSERT_LT
128
129 #ifndef ASSERT_LE
130 #error "The pw_unit_test framework backend must define ASSERT_LE(lhs, rhs)"
131 #endif // ASSERT_LE
132
133 #ifndef ASSERT_NEAR
134 #error \
135 "The pw_unit_test framework backend must define "\
136 "ASSERT_NEAR(lhs, rhs, epsilon)"
137 #endif // ASSERT_NEAR
138
139 #ifndef ASSERT_FLOAT_EQ
140 #error \
141 "The pw_unit_test framework backend must define ASSERT_FLOAT_EQ(lhs, rhs)"
142 #endif // ASSERT_FLOAT_EQ
143
144 #ifndef ASSERT_DOUBLE_EQ
145 #error \
146 "The pw_unit_test framework backend must define ASSERT_DOUBLE_EQ(lhs, rhs)"
147 #endif // ASSERT_DOUBLE_EQ
148
149 #ifndef ASSERT_STREQ
150 #error "The pw_unit_test framework backend must define ASSERT_STREQ(lhs, rhs)"
151 #endif // ASSERT_STREQ
152
153 #ifndef ASSERT_STRNE
154 #error "The pw_unit_test framework backend must define ASSERT_STRNE(lhs, rhs)"
155 #endif // ASSERT_STRNE
156
157 #ifndef ADD_FAILURE
158 #error "The pw_unit_test framework backend must define ADD_FAILURE()"
159 #endif // ADD_FAILURE
160
161 #ifndef GTEST_FAIL
162 #error "The pw_unit_test framework backend must define GTEST_FAIL()"
163 #endif // GTEST_FAIL
164
165 #ifndef GTEST_SKIP
166 #error "The pw_unit_test framework backend must define GTEST_SKIP()"
167 #endif // GTEST_SKIP
168
169 #ifndef FAIL
170 #error "The pw_unit_test framework backend must define FAIL()"
171 #endif // FAIL
172
173 #ifndef GTEST_SUCCEED
174 #error "The pw_unit_test framework backend must define GTEST_SUCCEED()"
175 #endif // GTEST_SUCCEED
176
177 #ifndef SUCCEED
178 #error "The pw_unit_test framework backend must define SUCCEED()"
179 #endif // SUCCEED
180
181 static_assert(std::is_same_v<decltype(RUN_ALL_TESTS()), int>,
182 "The pw_unit_test framework backend must define the "
183 "int RUN_ALL_TESTS() function");
184
185 #ifndef GTEST_HAS_DEATH_TEST
186 #error "The pw_unit_test framework backend must define GTEST_HAS_DEATH_TEST"
187 #endif // GTEST_HAS_DEATH_TEST
188
189 #ifndef EXPECT_DEATH_IF_SUPPORTED
190 #error \
191 "The pw_unit_test framework backend must define "\
192 "EXPECT_DEATH_IF_SUPPORTED(statement, regex)"
193 #endif // EXPECT_DEATH_IF_SUPPORTED
194
195 #ifndef ASSERT_DEATH_IF_SUPPORTED
196 #error \
197 "The pw_unit_test framework backend must define " \
198 "ASSERT_DEATH_IF_SUPPORTED(statement, regex)"
199 #endif // ASSERT_DEATH_IF_SUPPORTED
200
201 namespace pw::test {
202
203 /// An opaque black-box function to prevent the optimizer from removing values.
204 /// See: https://youtu.be/nXaxk27zwlk?t=2441
205 template <typename T>
DoNotOptimize(const T & value)206 inline void DoNotOptimize(const T& value) {
207 asm volatile("" : : "r,m"(value) : "memory");
208 }
209
210 } // namespace pw::test
211