diff --git a/src/unity_internals.h b/src/unity_internals.h index 4cf2b0136d43fb50692a5b569a83f941e243853e..ec2668cf422edf8fe996fe69b2a3f36821ec3578 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -180,8 +180,8 @@ void UnityAssertFloatsWithin(const _UF delta, //------------------------------------------------------- #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), message, (UNITY_LINE_TYPE)line) -#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), message, (UNITY_LINE_TYPE)line) +#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_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) #define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((long)(expected), (long)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) diff --git a/test/testunity.c b/test/testunity.c index a8f0d5398f6f2ea185bb9cd0ee8ed37e72af7878..bd574161f5e1ab2afed7f8d3a62c742a3580fe4e 100644 --- a/test/testunity.c +++ b/test/testunity.c @@ -134,6 +134,47 @@ void testFail(void) TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures); } +void testIsNull(void) +{ + char* ptr1 = NULL; + char* ptr2 = "hello"; + + TEST_ASSERT_NULL(ptr1); + TEST_ASSERT_NOT_NULL(ptr2); +} + +void testIsNullShouldFailIfNot(void) +{ + int failed; + char* ptr1 = "hello"; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_NULL(ptr1); + EXPECT_ABORT_END + + failed = Unity.CurrentTestFailed; + Unity.CurrentTestFailed = 0; + + TEST_ASSERT_EQUAL_INT(1U, failed); + TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures); +} + +void testNotNullShouldFailIfNULL(void) +{ + int failed; + char* ptr1 = NULL; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_NULL(ptr1); + EXPECT_ABORT_END + + failed = Unity.CurrentTestFailed; + Unity.CurrentTestFailed = 0; + + TEST_ASSERT_EQUAL_INT(1U, failed); + TEST_ASSERT_EQUAL_INT(0U, Unity.TestFailures); +} + void testIgnore(void) { int ignored; @@ -192,7 +233,6 @@ void testNotEqualBits(void) TEST_ASSERT_MESSAGE(1U == failed, "This is expected"); } - void testNotEqualUInts(void) { int failed;