Skip to content

Commit 4948e93

Browse files
asgibsonastrogeco
authored andcommitted
Fix nasa#628, Update UtAssert macros with dynamic string formatting
1 parent 0d706ca commit 4948e93

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

ut_assert/inc/utassert.h

+20-19
Original file line numberDiff line numberDiff line change
@@ -90,49 +90,50 @@ typedef struct
9090
#define UtAssert_True(Expression, ...) UtAssertEx(Expression, UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)
9191

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)