Skip to content

Commit 6f0a0b3

Browse files
committed
tests: unit: util: Add tests for COND_CASE_1
Add test cases for the COND_CASE_1 macro. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 2cd54d9 commit 6f0a0b3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/unit/util/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,38 @@ ZTEST(util, test_COND_CODE_0) {
165165
zassert_true((y3 == 1));
166166
}
167167

168+
ZTEST(util, test_COND_CASE_1) {
169+
/* Intentionally undefined symbols used to verify that only the selected
170+
* branch expands.
171+
*/
172+
#define CASE_TRUE 1
173+
#define CASE_FALSE 0
174+
175+
int prioritized = COND_CASE_1(
176+
CASE_TRUE, (42),
177+
CASE_TRUE, (COND_CASE_1_SHOULD_NOT_REACH_SECOND_TRUE_CASE),
178+
(0));
179+
zexpect_equal(prioritized, 42);
180+
181+
int selected = COND_CASE_1(
182+
CASE_FALSE, (COND_CASE_1_SHOULD_NOT_USE_FIRST_CASE),
183+
CASE_TRUE, (7),
184+
(11));
185+
zexpect_equal(selected, 7);
186+
187+
int fallback = COND_CASE_1(
188+
CASE_FALSE, (COND_CASE_1_SHOULD_NOT_USE_SECOND_CASE),
189+
CASE_FALSE, (COND_CASE_1_SHOULD_NOT_USE_THIRD_CASE),
190+
(5));
191+
zexpect_equal(fallback, 5);
192+
193+
int only_default = COND_CASE_1((9));
194+
zexpect_equal(only_default, 9);
195+
196+
#undef CASE_TRUE
197+
#undef CASE_FALSE
198+
}
199+
168200
#undef ZERO
169201
#undef SEVEN
170202
#undef A_BUILD_ERROR

0 commit comments

Comments
 (0)