mirror of
https://github.com/espressif/openthread.git
synced 2026-08-04 09:57:47 +00:00
[code-utils] enhance 'VerifyOrExit' to make action optional (#5659)
This commit uses the newly added macros from `arg_macros.hpp` to enhance `VerifyOfExit()` enabling `aAction` argument to be optional.
This commit is contained in:
committed by
Jonathan Hui
parent
8691e90d55
commit
c9c0cf404d
@@ -116,9 +116,59 @@ void TestMacros(void)
|
||||
VerifyOrQuit(OT_SECOND_ARG(1, 2) == 2, "OT_SECOND_ARG() failed");
|
||||
}
|
||||
|
||||
void TestVerifyOrExitSuccessNoAction(void)
|
||||
{
|
||||
bool reachedEnd = false;
|
||||
|
||||
VerifyOrExit(true);
|
||||
reachedEnd = true;
|
||||
|
||||
exit:
|
||||
VerifyOrQuit(reachedEnd, "VerifyOrExit() failed");
|
||||
}
|
||||
|
||||
void TestVerifyOrExitFailureNoAction(void)
|
||||
{
|
||||
bool reachedEnd = false;
|
||||
|
||||
VerifyOrExit(false);
|
||||
reachedEnd = true;
|
||||
|
||||
exit:
|
||||
VerifyOrQuit(!reachedEnd, "VerifyOrExit() failed");
|
||||
}
|
||||
|
||||
void TestVerifyOrExitSuccessWithAction(void)
|
||||
{
|
||||
bool didAction = false;
|
||||
bool reachedEnd = false;
|
||||
|
||||
VerifyOrExit(true, didAction = true);
|
||||
reachedEnd = true;
|
||||
|
||||
exit:
|
||||
VerifyOrQuit(reachedEnd && !didAction, "VerifyOrExit() failed");
|
||||
}
|
||||
|
||||
void TestVerifyOrExitFailureWithAction(void)
|
||||
{
|
||||
bool didAction = false;
|
||||
bool reachedEnd = false;
|
||||
|
||||
VerifyOrExit(false, didAction = true);
|
||||
reachedEnd = true;
|
||||
|
||||
exit:
|
||||
VerifyOrQuit(!reachedEnd && didAction, "VerifyOrExit() failed");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestMacros();
|
||||
TestVerifyOrExitSuccessNoAction();
|
||||
TestVerifyOrExitFailureNoAction();
|
||||
TestVerifyOrExitSuccessWithAction();
|
||||
TestVerifyOrExitFailureWithAction();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user