mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-09-29 01:03:15 +08:00
- 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
This commit is contained in:
@ -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)
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user