提交 07d2848d 编写于 作者: M mvandervoord

- 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
上级 f44a5832
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册