Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #502, Add extra assert macros #503

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions ut_assert/inc/utassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,84 @@ typedef struct
#define UtAssert_Type(Type,Expression,...) \
UtAssertEx(Expression, UTASSERT_CASETYPE_##Type, __FILE__, __LINE__, __VA_ARGS__)

/**
* \brief Compare two values for equality with an auto-generated description message
* Values will be compared in an "int32" type context.
*/
#define UtAssert_INT32_EQ(actual,expect) do \
{ \
int32 rcexp = (int32)(expect); \
int32 rcact = (int32)(actual); \
UtAssert_True(rcact == rcexp, "%s (%ld) == %s (%ld)", \
#actual, (long)rcact, \
#expect, (long)rcexp); \
} while(0)

/**
* \brief Compare two values for equality with an auto-generated description message
* Values will be compared in an "uint32" type context.
*/
#define UtAssert_UINT32_EQ(actual,expect) do \
{ \
uint32 rcexp = (uint32)(expect); \
uint32 rcact = (uint32)(actual); \
UtAssert_True(rcact == rcexp, "%s (%lu) == %s (%lu)", \
#actual, (unsigned long)rcact, \
#expect, (unsigned long)rcexp); \
} while(0)

/**
* \brief Confirm a pointer value is not NULL
*/
#define UtAssert_NOT_NULL(actual) do \
{ \
void* ptr = (void*)(actual); \
UtAssert_True(ptr != NULL, "%s (%p) != NULL", \
#actual, ptr); \
} while(0)

/**
* \brief Confirm a pointer value is NULL
*/
#define UtAssert_NULL(actual) do \
{ \
void* ptr = (void*)(actual); \
UtAssert_True(ptr == NULL, "%s (%p) == NULL", \
#actual, ptr); \
} while(0)

/**
* \brief Confirm an integer value is nonzero
*/
#define UtAssert_NONZERO(actual) do \
{ \
long val = (long)(actual); \
UtAssert_True(val != 0, "%s (%ld) != 0", \
#actual, val); \
} while(0)

/**
* \brief Confirm an integer value is nonzero
*/
#define UtAssert_ZERO(actual) do \
{ \
long val = (long)(actual); \
UtAssert_True(val == 0, "%s (%ld) == 0", \
#actual, val); \
} while(0)

/**
* \brief Confirm that a stub function has been invoked the expected number of times
*/
#define UtAssert_STUB_COUNT(stub,expected) do \
{ \
uint32 expval = (uint32)(expected); \
uint32 actval = UT_GetStubCount(UT_KEY(stub)); \
UtAssert_True(actval == expval, "%s() count (%lu) == %s (%lu)", \
#stub, (unsigned long)actval, \
#expected, (unsigned long)expval); \
} while(0)

/*
* Exported Functions
*/
Expand Down