Fix TEST_ASSERT_EACH_EQUAL_MEMORY to take a single value, not a pointer. Add tests to verify.

This commit is contained in:
Mark VanderVoord
2026-07-06 16:53:09 -04:00
parent 41d6933b39
commit ff41c2d2a4
2 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -1169,7 +1169,7 @@ int UnityTestMatches(void);
#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_PTR_TO_INT) (expected), (UNITY_POINTER_WIDTH / 8)), (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((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)
#define UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory( UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL)
#define UNITY_TEST_ASSERT_EACH_EQUAL_CHAR(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_CHAR, UNITY_ARRAY_TO_VAL)
#ifdef UNITY_SUPPORT_64
+39
View File
@@ -109,3 +109,42 @@ void testNotNotEqualMemoryLengthZero(void)
TEST_ASSERT_NOT_EQUAL_MEMORY("foo", "bar", 0);
VERIFY_FAILS_END
}
void testEachEqualMemory(void)
{
unsigned char p0[] = {0xAB, 0xAB, 0xAB, 0xAB};
unsigned char p1[] = {0x12, 0x12, 0x12, 0xFF};
unsigned char p2[] = {0x00, 0x00, 0xFF, 0xFF};
unsigned char p3[] = {0x5A, 0x01, 0x02, 0x03};
TEST_ASSERT_EACH_EQUAL_MEMORY(0xAB, p0, 1, 1);
TEST_ASSERT_EACH_EQUAL_MEMORY(0xAB, p0, 1, 4);
TEST_ASSERT_EACH_EQUAL_MEMORY(0x12, p1, 1, 3);
TEST_ASSERT_EACH_EQUAL_MEMORY(0x00, p2, 1, 2);
TEST_ASSERT_EACH_EQUAL_MEMORY(0x5A, p3, 1, 1);
}
void testNotEachEqualMemory(void)
{
unsigned char p0[] = {0xAB, 0xAB, 0x00, 0xAB};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_MEMORY(0xAB, p0, 1, 4);
VERIFY_FAILS_END
}
void testEachEqualMemoryWithMessage(void)
{
unsigned char p0[] = {0x42, 0x42, 0x42};
TEST_ASSERT_EACH_EQUAL_MEMORY_MESSAGE(0x42, p0, 1, 3, "all bytes should be 0x42");
}
void testNotEachEqualMemoryWithMessage(void)
{
unsigned char p0[] = {0x42, 0x42, 0x01};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EACH_EQUAL_MEMORY_MESSAGE(0x42, p0, 1, 3, "mismatch expected");
VERIFY_FAILS_END
}