Add basic test for M_DEFAULT_ARGS
Print hint to developper in case of incorrect usage
This commit is contained in:
1 parent
8544a7f289
commit
dafe4bcec5
2 files changed
+27
-1
No files matched your search
@@ -2453,7 +2453,7 @@ done
|
||||
#define M_DEFAULTI_ARGS2(numArgs, numExpected, value, ...) \
|
||||
__VA_ARGS__ \
|
||||
M_IF(M_NOTEQUAL(numArgs, numExpected))(M_DEFERRED_COMMA, ) \
|
||||
M_REVERSE(M_KEEP_ARGS(M_SUB(numExpected, numArgs), M_REVERSE value, nothing))
|
||||
M_REVERSE(M_KEEP_ARGS(M_SUB(numExpected, numArgs), M_REVERSE value, M_LIB_ERROR_MISSING_MANDATORY_ARGUMENT))
|
||||
#define M_DEFAULTI_ARGS_EVAL(...) __VA_ARGS__
|
||||
#define M_DEFAULT_ARGS(expected, value, ...) \
|
||||
M_DEFAULTI_ARGS_EVAL(M_DEFAULTI_ARGS2(M_NARGS(__VA_ARGS__), expected, value, __VA_ARGS__))
|
||||
|
||||
@@ -980,6 +980,31 @@ static void test_generic_api(void)
|
||||
|
||||
}
|
||||
|
||||
static void f_default(int a, int b, int c)
|
||||
{
|
||||
assert( a == 1 );
|
||||
assert( b == 2 );
|
||||
assert( c == 3 );
|
||||
}
|
||||
|
||||
static void test_default(void)
|
||||
{
|
||||
|
||||
#define f11(...) f_default(M_DEFAULT_ARGS(3, (1, 2, 3), __VA_ARGS__))
|
||||
f11(1, 2, 3);
|
||||
f11(1, 2);
|
||||
f11(1);
|
||||
|
||||
#define f12(...) f_default(M_DEFAULT_ARGS(3, (2, 3), __VA_ARGS__))
|
||||
f12(1, 2, 3);
|
||||
f12(1, 2);
|
||||
f12(1);
|
||||
|
||||
#define f13(...) f_default(M_DEFAULT_ARGS(3, (3), __VA_ARGS__))
|
||||
f13(1, 2, 3);
|
||||
f13(1, 2);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_cat();
|
||||
@@ -1006,6 +1031,7 @@ int main(void)
|
||||
test_M_CSTR();
|
||||
test_properties();
|
||||
test_generic_api();
|
||||
test_default();
|
||||
testobj_final_check();
|
||||
exit(0);
|
||||
}
|
||||
Reference in new issue
Block a user