提交 0dddf498 编写于 作者: M Mark VanderVoord

also update strings to support each element of an array.

上级 a11a1375
......@@ -1016,13 +1016,17 @@ void UnityAssertEqualStringLen(const char* expected,
}
/*-----------------------------------------------*/
void UnityAssertEqualStringArray(const char** expected,
void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected,
const char** actual,
const UNITY_UINT32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber)
const UNITY_LINE_TYPE lineNumber,
const UNITY_FLAGS_T flags)
{
UNITY_UINT32 i, j = 0;
UNITY_UINT32 i = 0;
UNITY_UINT32 j = 0;
const char* exp;
const char* act;
RETURN_IF_FAIL_OR_IGNORE;
......@@ -1032,18 +1036,35 @@ void UnityAssertEqualStringArray(const char** expected,
UnityPrintPointlessAndBail();
}
if (expected == actual) return; /* Both are NULL or same pointer */
if ((const char**)expected == actual)
{
return; /* Both are NULL or same pointer */
}
if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg))
{
UNITY_FAIL_AND_BAIL;
}
if (flags != UNITY_ARRAY_TO_ARRAY)
{
exp = (const char*)expected;
}
do
{
act = actual[j];
if (flags == UNITY_ARRAY_TO_ARRAY)
{
exp = ((const char**)expected)[j];
}
/* if both pointers not null compare the strings */
if (expected[j] && actual[j])
if (exp && act)
{
for (i = 0; expected[j][i] || actual[j][i]; i++)
for (i = 0; exp[i] || act[i]; i++)
{
if (expected[j][i] != actual[j][i])
if (exp[i] != act[i])
{
Unity.CurrentTestFailed = 1;
break;
......@@ -1052,7 +1073,7 @@ void UnityAssertEqualStringArray(const char** expected,
}
else
{ /* handle case of one pointers being null (if both null, test should pass) */
if (expected[j] != actual[j])
if (exp != act)
{
Unity.CurrentTestFailed = 1;
}
......@@ -1066,7 +1087,7 @@ void UnityAssertEqualStringArray(const char** expected,
UnityPrint(UnityStrElement);
UnityPrintNumberUnsigned(j);
}
UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
UnityPrintExpectedAndActualStrings(exp, act);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
......
......@@ -174,7 +174,7 @@ void tearDown(void);
#define TEST_ASSERT_EACH_EQUAL_HEX32(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, NULL)
#define TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX64((expected), (actual), (num_elements), __LINE__, NULL)
#define TEST_ASSERT_EACH_EQUAL_PTR(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_PTR((expected), (actual), (num_elements), __LINE__, NULL)
//#define TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_STRING((expected), (actual), (num_elements), __LINE__, NULL)
#define TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_STRING((expected), (actual), (num_elements), __LINE__, NULL)
#define TEST_ASSERT_EACH_EQUAL_MEMORY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY((expected), (actual), (len), (num_elements), __LINE__, NULL)
/* Floating Point (If Enabled) */
......@@ -301,7 +301,7 @@ void tearDown(void);
#define TEST_ASSERT_EACH_EQUAL_HEX32_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, (message))
#define TEST_ASSERT_EACH_EQUAL_HEX64_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX64((expected), (actual), (num_elements), __LINE__, (message))
#define TEST_ASSERT_EACH_EQUAL_PTR_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_PTR((expected), (actual), (num_elements), __LINE__, (message))
//#define TEST_ASSERT_EACH_EQUAL_STRING_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_STRING((expected), (actual), (num_elements), __LINE__, (message))
#define TEST_ASSERT_EACH_EQUAL_STRING_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_STRING((expected), (actual), (num_elements), __LINE__, (message))
#define TEST_ASSERT_EACH_EQUAL_MEMORY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY((expected), (actual), (len), (num_elements), __LINE__, (message))
/* Floating Point (If Enabled) */
......
......@@ -480,11 +480,12 @@ void UnityAssertEqualStringLen(const char* expected,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
void UnityAssertEqualStringArray( const char** expected,
void UnityAssertEqualStringArray( UNITY_INTERNAL_PTR expected,
const char** actual,
const UNITY_UINT32 num_elements,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
const UNITY_LINE_TYPE lineNumber,
const UNITY_FLAGS_T flags);
void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected,
UNITY_INTERNAL_PTR actual,
......@@ -680,7 +681,7 @@ int UnityTestMatches(void);
#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_ARRAY)
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_ARRAY)
#define UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER, UNITY_ARRAY_TO_ARRAY)
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line))
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((UNITY_INTERNAL_PTR)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY)
#define UNITY_TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) expected, sizeof(int)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_VAL)
......@@ -695,7 +696,7 @@ int UnityTestMatches(void);
#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )expected, 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_VAL)
#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )expected, 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_VAL)
#define UNITY_TEST_ASSERT_EACH_EQUAL_PTR(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) expected, sizeof(int*)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER, UNITY_ARRAY_TO_VAL)
#define UNITY_TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line))
#define UNITY_TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((UNITY_INTERNAL_PTR)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL)
#define UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL)
#ifdef UNITY_SUPPORT_64
......
......@@ -1519,6 +1519,61 @@ void testNotEqualStringArrayLengthZero(void)
VERIFY_FAILS_END
}
void testEqualStringEachEqual(void)
{
const char *testStrings1[] = { "foo", "foo", "foo", "foo" };
const char *testStrings2[] = { "boo", "boo", "boo", "zoo" };
const char *testStrings3[] = { "", "", "", "" };
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings1, 4);
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings1, 1);
TEST_ASSERT_EACH_EQUAL_STRING("boo", testStrings2, 3);
TEST_ASSERT_EACH_EQUAL_STRING("", testStrings3, 4);
}
void testNotEqualStringEachEqual1(void)
{
const char *testStrings[] = { "foo", "foo", "foo", "moo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringEachEqual2(void)
{
const char *testStrings[] = { "boo", "foo", "foo", "foo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringEachEqual3(void)
{
const char *testStrings[] = { "foo", "foo", "foo", NULL };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringEachEqual4(void)
{
const char *testStrings[] = { "foo", "foo", "woo", "foo" };
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", testStrings, 4);
VERIFY_FAILS_END
}
void testNotEqualStringEachEqual5(void)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_STRING("foo", NULL, 1);
VERIFY_FAILS_END
}
void testEqualMemory(void)
{
const char *testString = "whatever";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册