mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-05-20 08:57:52 +08:00
Add assertion for checking empty null-terminated arrays. This is particularly useful for check c strings.
This commit is contained in:
@ -236,6 +236,15 @@ conditional statements.
|
||||
|
||||
##### `TEST_ASSERT_NOT_NULL (pointer)`
|
||||
|
||||
Verify if a pointer is or is not NULL.
|
||||
|
||||
##### `TEST_ASSERT_EMPTY (pointer)`
|
||||
|
||||
##### `TEST_ASSERT_NOT_EMPTY (pointer)`
|
||||
|
||||
Verify if the first element dereferenced from a pointer is or is not zero. This
|
||||
is particularly useful for checking for empty (or non-empty) null-terminated
|
||||
C strings, but can be just as easily used for other null-terminated arrays.
|
||||
|
||||
### Signed and Unsigned Integers (of all sizes)
|
||||
|
||||
|
@ -128,6 +128,8 @@ void verifyTest(void);
|
||||
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
|
||||
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
|
||||
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
|
||||
#define TEST_ASSERT_EMPTY(pointer) UNITY_TEST_ASSERT_EMPTY( (pointer), __LINE__, " Expected Empty")
|
||||
#define TEST_ASSERT_NOT_EMPTY(pointer) UNITY_TEST_ASSERT_NOT_EMPTY((pointer), __LINE__, " Expected Non-Empty")
|
||||
|
||||
/* Integers (of all sizes) */
|
||||
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
@ -376,6 +378,8 @@ void verifyTest(void);
|
||||
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, (message))
|
||||
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, (message))
|
||||
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, (message))
|
||||
#define TEST_ASSERT_EMPTY_MESSAGE(pointer, message) UNITY_TEST_ASSERT_EMPTY( (pointer), __LINE__, (message))
|
||||
#define TEST_ASSERT_NOT_EMPTY_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_EMPTY((pointer), __LINE__, (message))
|
||||
|
||||
/* Integers (of all sizes) */
|
||||
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, (message))
|
||||
|
@ -761,6 +761,8 @@ int UnityTestMatches(void);
|
||||
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), (message));}
|
||||
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)(line), (message))
|
||||
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)(line), (message))
|
||||
#define UNITY_TEST_ASSERT_EMPTY(pointer, line, message) UNITY_TEST_ASSERT(((pointer[0]) == 0), (UNITY_LINE_TYPE)(line), (message))
|
||||
#define UNITY_TEST_ASSERT_NOT_EMPTY(pointer, line, message) UNITY_TEST_ASSERT(((pointer[0]) != 0), (UNITY_LINE_TYPE)(line), (message))
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT8 )(expected), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8)
|
||||
|
@ -258,6 +258,33 @@ void testNotNullShouldFailIfNULL(void)
|
||||
VERIFY_FAILS_END
|
||||
}
|
||||
|
||||
void testIsEmpty(void)
|
||||
{
|
||||
const char* ptr1 = "\0";
|
||||
const char* ptr2 = "hello";
|
||||
|
||||
TEST_ASSERT_EMPTY(ptr1);
|
||||
TEST_ASSERT_NOT_EMPTY(ptr2);
|
||||
}
|
||||
|
||||
void testIsEmptyShouldFailIfNot(void)
|
||||
{
|
||||
const char* ptr1 = "hello";
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_EMPTY(ptr1);
|
||||
VERIFY_FAILS_END
|
||||
}
|
||||
|
||||
void testNotEmptyShouldFailIfEmpty(void)
|
||||
{
|
||||
const char* ptr1 = "\0";
|
||||
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_NOT_EMPTY(ptr1);
|
||||
VERIFY_FAILS_END
|
||||
}
|
||||
|
||||
void testIgnore(void)
|
||||
{
|
||||
EXPECT_ABORT_BEGIN
|
||||
|
Reference in New Issue
Block a user