From 07d2848dd4642da9d0a68462c896a09688800740 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Sat, 20 Mar 2010 21:22:28 +0000 Subject: [PATCH] - fixed mistake with NULL and NOT_NULL assertions. Added tests to keep that from happening again git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@64 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e --- src/unity_internals.h | 4 ++-- test/testunity.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index 4cf2b01..ec2668c 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 a8f0d53..bd57416 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; -- GitLab