Skip to content

Commit a7a37c3

Browse files
authored
Merge pull request #54 from stefano-p/feature/ptr-macros-variadic-support
Add variadic macro support to pointer assertion macros
2 parents 05e0ec0 + 49f9277 commit a7a37c3

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

tau/tau.h

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -809,32 +809,33 @@ static void tauPrintHexBufCmp(const void* const buff, const void* const ref, con
809809
tauColouredPrintf(TAU_COLOUR_CYAN_,">");
810810
}
811811

812-
#define __TAUCMP_PTR__(actual, expected, cond, space, macroName, failOrAbort) \
813-
do { \
814-
if(!((void*)(actual)cond(void*)(expected))) { \
815-
tauPrintf("%s:%u: ", __FILE__, __LINE__); \
816-
tauColouredPrintf(TAU_COLOUR_BRIGHTRED_, "FAILED\n"); \
817-
if(tauShouldDecomposeMacro(#actual, #expected, 0)) { \
818-
tauColouredPrintf(TAU_COLOUR_BRIGHTCYAN_, " In macro : "); \
819-
tauColouredPrintf(TAU_COLOUR_BRIGHTCYAN_, "%s( %s, %s )\n", \
820-
#macroName, \
821-
#actual, #expected); \
822-
} \
823-
tauPrintf(" Expected : %s", #actual); \
824-
printf(" %s ", #cond space); \
825-
printf("%p", (void*)expected); \
826-
tauPrintf("\n"); \
827-
\
828-
tauPrintf(" Actual : %s", #actual); \
829-
printf(" == "); \
830-
printf("%p", (void*)actual); \
831-
tauPrintf("\n"); \
832-
failOrAbort; \
833-
if(shouldAbortTest) { \
834-
return; \
835-
} \
836-
} \
837-
} \
812+
#define __TAUCMP_PTR__(actual, expected, cond, space, macroName, failOrAbort, ...) \
813+
do { \
814+
if(!((void*)(actual)cond(void*)(expected))) { \
815+
tauPrintf("%s:%u: ", __FILE__, __LINE__); \
816+
tauColouredPrintf(TAU_COLOUR_BRIGHTRED_, __VA_ARGS__); \
817+
printf("\n"); \
818+
if(tauShouldDecomposeMacro(#actual, #expected, 0)) { \
819+
tauColouredPrintf(TAU_COLOUR_BRIGHTCYAN_, " In macro : "); \
820+
tauColouredPrintf(TAU_COLOUR_BRIGHTCYAN_, "%s( %s, %s )\n", \
821+
#macroName, \
822+
#actual, #expected); \
823+
} \
824+
tauPrintf(" Expected : %s", #actual); \
825+
printf(" %s ", #cond space); \
826+
printf("%p", (void*)expected); \
827+
tauPrintf("\n"); \
828+
\
829+
tauPrintf(" Actual : %s", #actual); \
830+
printf(" == "); \
831+
printf("%p", (void*)actual); \
832+
tauPrintf("\n"); \
833+
failOrAbort; \
834+
if(shouldAbortTest) { \
835+
return; \
836+
} \
837+
} \
838+
} \
838839
while(0)
839840

840841
#define __TAUCMP_BUF__(actual, expected, len, cond, ifCondFailsThenPrint, actualPrint, macroName, failOrAbort, ...) \
@@ -949,10 +950,10 @@ static void tauPrintHexBufCmp(const void* const buff, const void* const ref, con
949950
#define REQUIRE_BUF_NE_(actual, expected, n, ...) __TAUCMP_BUF__(actual, expected, n, ==, !=, equal, REQUIRE_BUF_NE, TAU_ABORT_IF_INSIDE_TESTSUITE, __VA_ARGS__)
950951

951952
// Pointers Checks
952-
#define CHECK_PTR_EQ(actual, expected) __TAUCMP_PTR__(actual, expected, ==, "", CHECK_PTR_EQ, TAU_FAIL_IF_INSIDE_TESTSUITE)
953-
#define CHECK_PTR_NE(actual, expected) __TAUCMP_PTR__(actual, expected, !=, "", CHECK_PTR_NE, TAU_FAIL_IF_INSIDE_TESTSUITE)
954-
#define REQUIRE_PTR_EQ(actual, expected) __TAUCMP_PTR__(actual, expected, ==, "", REQUIRE_PTR_EQ, TAU_ABORT_IF_INSIDE_TESTSUITE)
955-
#define REQUIRE_PTR_NE(actual, expected) __TAUCMP_PTR__(actual, expected, !=, "", REQUIRE_PTR_NE, TAU_ABORT_IF_INSIDE_TESTSUITE)
953+
#define CHECK_PTR_EQ_(actual, expected, ...) __TAUCMP_PTR__(actual, expected, ==, "", CHECK_PTR_EQ, TAU_FAIL_IF_INSIDE_TESTSUITE, __VA_ARGS__)
954+
#define CHECK_PTR_NE_(actual, expected, ...) __TAUCMP_PTR__(actual, expected, !=, "", CHECK_PTR_NE, TAU_FAIL_IF_INSIDE_TESTSUITE, __VA_ARGS__)
955+
#define REQUIRE_PTR_EQ_(actual, expected, ...) __TAUCMP_PTR__(actual, expected, ==, "", REQUIRE_PTR_EQ, TAU_ABORT_IF_INSIDE_TESTSUITE, __VA_ARGS__)
956+
#define REQUIRE_PTR_NE_(actual, expected, ...) __TAUCMP_PTR__(actual, expected, !=, "", REQUIRE_PTR_NE, TAU_ABORT_IF_INSIDE_TESTSUITE, __VA_ARGS__)
956957

957958
// Note: The negate sign `!` must be there for {CHECK|REQUIRE}_TRUE
958959
// Do not remove it
@@ -991,6 +992,11 @@ static void tauPrintHexBufCmp(const void* const buff, const void* const ref, con
991992
#define REQUIRE_BUF_EQ(...) FIXED3_CHOOSER(__VA_ARGS__)(REQUIRE_BUF_EQ, __VA_ARGS__)
992993
#define REQUIRE_BUF_NE(...) FIXED3_CHOOSER(__VA_ARGS__)(REQUIRE_BUF_NE, __VA_ARGS__)
993994

995+
#define CHECK_PTR_EQ(...) FIXED2_CHOOSER(__VA_ARGS__)(CHECK_PTR_EQ, __VA_ARGS__)
996+
#define CHECK_PTR_NE(...) FIXED2_CHOOSER(__VA_ARGS__)(CHECK_PTR_NE, __VA_ARGS__)
997+
#define REQUIRE_PTR_EQ(...) FIXED2_CHOOSER(__VA_ARGS__)(REQUIRE_PTR_EQ, __VA_ARGS__)
998+
#define REQUIRE_PTR_NE(...) FIXED2_CHOOSER(__VA_ARGS__)(REQUIRE_PTR_NE, __VA_ARGS__)
999+
9941000
#define CHECK_TRUE(...) FIXED1_CHOOSER(__VA_ARGS__)(CHECK_TRUE, __VA_ARGS__)
9951001
#define CHECK_FALSE(...) FIXED1_CHOOSER(__VA_ARGS__)(CHECK_FALSE, __VA_ARGS__)
9961002
#define REQUIRE_TRUE(...) FIXED1_CHOOSER(__VA_ARGS__)(REQUIRE_TRUE, __VA_ARGS__)

0 commit comments

Comments
 (0)