Skip to content

Commit a9a377f

Browse files
authored
Merge pull request #46 from stefano-p/feature/pointer-comparison-macros
Add dedicated macros for pointer comparisons
2 parents 27de906 + 79e8038 commit a9a377f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tau/tau.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,33 @@ static void tauPrintHexBufCmp(const void* const buff, const void* const ref, con
659659
tauColouredPrintf(TAU_COLOUR_CYAN_,">");
660660
}
661661

662+
#define __TAUCMP_PTR__(actual, expected, cond, space, macroName, failOrAbort) \
663+
do { \
664+
if(!((void*)(actual)cond(void*)(expected))) { \
665+
tauPrintf("%s:%u: ", __FILE__, __LINE__); \
666+
tauColouredPrintf(TAU_COLOUR_BRIGHTRED_, "FAILED\n"); \
667+
if(tauShouldDecomposeMacro(#actual, #expected, 0)) { \
668+
tauColouredPrintf(TAU_COLOUR_BRIGHTCYAN_, " In macro : "); \
669+
tauColouredPrintf(TAU_COLOUR_BRIGHTCYAN_, "%s( %s, %s )\n", \
670+
#macroName, \
671+
#actual, #expected); \
672+
} \
673+
tauPrintf(" Expected : %s", #actual); \
674+
printf(" %s ", #cond space); \
675+
printf("%p", (void*)expected); \
676+
tauPrintf("\n"); \
677+
\
678+
tauPrintf(" Actual : %s", #actual); \
679+
printf(" == "); \
680+
printf("%p", (void*)actual); \
681+
tauPrintf("\n"); \
682+
failOrAbort; \
683+
if(shouldAbortTest) { \
684+
return; \
685+
} \
686+
} \
687+
} \
688+
while(0)
662689

663690
#define __TAUCMP_BUF__(actual, expected, len, cond, ifCondFailsThenPrint, actualPrint, macroName, failOrAbort) \
664691
do { \
@@ -768,6 +795,12 @@ static void tauPrintHexBufCmp(const void* const buff, const void* const ref, con
768795
#define REQUIRE_BUF_EQ(actual, expected, n) __TAUCMP_BUF__(actual, expected, n, !=, ==, not equal, REQUIRE_BUF_EQ, TAU_ABORT_IF_INSIDE_TESTSUITE)
769796
#define REQUIRE_BUF_NE(actual, expected, n) __TAUCMP_BUF__(actual, expected, n, ==, !=, equal, REQUIRE_BUF_NE, TAU_ABORT_IF_INSIDE_TESTSUITE)
770797

798+
// Pointers Checks
799+
#define CHECK_PTR_EQ(actual, expected) __TAUCMP_PTR__(actual, expected, ==, "", CHECK_PTR_EQ, TAU_FAIL_IF_INSIDE_TESTSUITE)
800+
#define CHECK_PTR_NE(actual, expected) __TAUCMP_PTR__(actual, expected, !=, "", CHECK_PTR_NE, TAU_FAIL_IF_INSIDE_TESTSUITE)
801+
#define REQUIRE_PTR_EQ(actual, expected) __TAUCMP_PTR__(actual, expected, ==, "", REQUIRE_PTR_EQ, TAU_ABORT_IF_INSIDE_TESTSUITE)
802+
#define REQUIRE_PTR_NE(actual, expected) __TAUCMP_PTR__(actual, expected, !=, "", REQUIRE_PTR_NE, TAU_ABORT_IF_INSIDE_TESTSUITE)
803+
771804
// Note: The negate sign `!` must be there for {CHECK|REQUIRE}_TRUE
772805
// Do not remove it
773806
#define CHECK_TRUE(cond) __TAUCMP_TF(cond, false, true, !, CHECK_TRUE, TAU_FAIL_IF_INSIDE_TESTSUITE)

0 commit comments

Comments
 (0)