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 #628, Update UtAssert macros with dynamic string formatting #629

Merged
merged 1 commit into from
Nov 3, 2020
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
39 changes: 20 additions & 19 deletions ut_assert/inc/utassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,49 +90,50 @@ typedef struct
#define UtAssert_True(Expression, ...) UtAssertEx(Expression, UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Evaluates a expression as either true or false. true means the test passed, false means the test failed. */
#define UtAssert_Bool(Expression, Description) UtAssert(Expression, Description, __FILE__, __LINE__)
#define UtAssert_Bool(Expression, ...) \
UtAssertEx(Expression, UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Asserts a test failure */
#define UtAssert_Failed(...) UtAssertEx(false, UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares two integers and determines if they are equal within a specified absolute tolerance. */
#define UtAssert_IntegerCmpAbs(x, y, Tolerance, Description) \
UtAssert((abs((x) - (y)) <= (Tolerance)), Description, __FILE__, __LINE__)
#define UtAssert_IntegerCmpAbs(x, y, Tolerance, ...) \
UtAssertEx((abs((x) - (y)) <= (Tolerance)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares two floating point numbers and determines if they are equal within a specified absolute tolerance. */
#define UtAssert_DoubleCmpAbs(x, y, Tolerance, Description) \
UtAssert((fabs((x) - (y)) <= (Tolerance)), Description, __FILE__, __LINE__)
#define UtAssert_DoubleCmpAbs(x, y, Tolerance, ...) \
UtAssertEx((fabs((x) - (y)) <= (Tolerance)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares two floating point numbers and determines if they are equal within a specified relative tolerance. */
#define UtAssert_DoubleCmpRel(x, y, Ratio, Description) \
UtAssert((fabs((x) - (y)) / (x) <= (Ratio)), Description, __FILE__, __LINE__)
#define UtAssert_DoubleCmpRel(x, y, Ratio, ...) \
UtAssertEx((fabs((x) - (y))/(x) <= (Ratio)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares two strings and determines if they are equal. */
#define UtAssert_StrCmp(String1, String2, Description) \
UtAssert((strcmp(String1, String2) == 0), Description, __FILE__, __LINE__)
#define UtAssert_StrCmp(String1, String2, ...) \
UtAssertEx((strcmp(String1, String2) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares at most Length characters of two strings and determines if they are equal. */
#define UtAssert_StrnCmp(String1, String2, Length, Description) \
UtAssert((strncmp(String1, String2, Length) == 0), Description, __FILE__, __LINE__)
#define UtAssert_StrnCmp(String1, String2, Length, ...) \
UtAssertEx((strncmp(String1, String2, Length) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares two regions of memory and determines if they are equal. */
#define UtAssert_MemCmp(Memory1, Memory2, Length, Description) \
UtAssert((memcmp(Memory1, Memory2, Length) == 0), Description, __FILE__, __LINE__)
#define UtAssert_MemCmp(Memory1, Memory2, Length, ...) \
UtAssertEx((memcmp(Memory1, Memory2, Length) == 0), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares a region of memory to a static pattern and determines if they are equal. Note: Use UtMemSet to
* fill a region of memory with a static pattern. */
#define UtAssert_MemCmpValue(Memory, Value, Length, Description) \
UtAssert((UtMemCmpValue(Memory, Value, Length)), Description, __FILE__, __LINE__)
#define UtAssert_MemCmpValue(Memory, Value, Length, ...) \
UtAssertEx((UtMemCmpValue(Memory, Value, Length)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares a region of memory to a byte count pattern and determines if they are equal. Note: Use UtMemFill to
* fill a region of memory with a byte count pattern. */
#define UtAssert_MemCmpCount(Memory, Length, Description) \
UtAssert((UtMemCmpCount(Memory, Length)), Description, __FILE__, __LINE__)
#define UtAssert_MemCmpCount(Memory, Length, ...) \
UtAssertEx((UtMemCmpCount(Memory, Length)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* Compares a region of memory with the contents of a binary file and determines if they are equal. Note: Use
* UtMem2BinFile to copy a region of memory to a binary file. */
#define UtAssert_Mem2BinFileCmp(Memory, Filename, Description) \
UtAssert((UtMem2BinFileCmp(Memory, Filename)), Description, __FILE__, __LINE__)
#define UtAssert_Mem2BinFileCmp(Memory, Filename, ...) \
UtAssertEx((UtMem2BinFileCmp(Memory, Filename)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)

/* A wrapper around UtAssertEx that allows the user to specify the failure type and a more descriptive message */
#define UtAssert_Type(Type, Expression, ...) \
Expand Down