Skip to content

Commit cc92069

Browse files
pdgendtfabiobaltieri
authored andcommitted
tests: unit: util: Add tests for IF_DISABLED
Add a testcase for the IF_DISABLED macro. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent b4cd9c4 commit cc92069

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/unit/util/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ ZTEST(util_cxx, test_IF_ENABLED) {
3838
run_IF_ENABLED();
3939
}
4040

41+
ZTEST(util_cxx, test_IF_DISABLED) {
42+
run_IF_DISABLED();
43+
}
44+
4145
ZTEST(util_cxx, test_LISTIFY) {
4246
run_LISTIFY();
4347
}
@@ -186,6 +190,10 @@ ZTEST(util_cc, test_IF_ENABLED) {
186190
run_IF_ENABLED();
187191
}
188192

193+
ZTEST(util_cc, test_IF_DISABLED) {
194+
run_IF_DISABLED();
195+
}
196+
189197
ZTEST(util_cc, test_LISTIFY) {
190198
run_LISTIFY();
191199
}

tests/unit/util/test.inc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,28 @@ skipped:
162162
#undef test_IF_ENABLED_FLAG_B
163163
}
164164

165+
void run_IF_DISABLED(void)
166+
{
167+
#define test_IF_DISABLED_FLAG_A 0
168+
#define test_IF_DISABLED_FLAG_B 1
169+
170+
IF_DISABLED(test_IF_DISABLED_FLAG_A, (goto skipped_a;))
171+
/* location should be skipped if IF_DISABLED macro is correct. */
172+
zassert_false(true, "location A should be skipped");
173+
skipped_a:
174+
IF_DISABLED(test_IF_DISABLED_FLAG_B, (zassert_false(true, "");))
175+
176+
IF_DISABLED(test_IF_DISABLED_FLAG_C, (goto skipped_c;))
177+
/* location should be skipped if IF_DISABLED macro is correct. */
178+
zassert_false(true, "location C should be skipped");
179+
skipped_c:
180+
181+
zassert_true(true, "");
182+
183+
#undef test_IF_DISABLED_FLAG_A
184+
#undef test_IF_DISABLED_FLAG_B
185+
}
186+
165187
void run_LISTIFY(void)
166188
{
167189
int ab0 = 1;

0 commit comments

Comments
 (0)