From df163ff8f591fa77b1275f134a1bdafbe29d81af Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 3 Jul 2026 09:29:04 -0400 Subject: [PATCH] Fill in missing tests and documentation. --- docs/UnityAssertionsReference.md | 21 +++++++++-- test/tests/test_unity_integers.c | 34 +++++++++++++++++ test/tests/test_unity_memory.c | 29 +++++++++++++++ test/tests/test_unity_strings.c | 64 ++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 4 deletions(-) diff --git a/docs/UnityAssertionsReference.md b/docs/UnityAssertionsReference.md index 81cd062..4243a3e 100644 --- a/docs/UnityAssertionsReference.md +++ b/docs/UnityAssertionsReference.md @@ -422,7 +422,9 @@ Asserts that the pointers point to the same memory location. #### `TEST_ASSERT_NOT_EQUAL_PTR (expected, actual)` -Asserts that the pointers DO NOT point to the same memory location. +Asserts that the pointers DO NOT point to the same memory location. Two NULL +pointers are considered equal and will cause this assertion to fail. A NULL +pointer and a non-NULL pointer are considered not equal and will pass. #### `TEST_ASSERT_EQUAL_STRING (expected, actual)` @@ -433,7 +435,10 @@ equivalent. #### `TEST_ASSERT_NOT_EQUAL_STRING (expected, actual)` -Asserts that the null terminated (`’\0’`) strings are NOT identical. +Asserts that the null terminated (`’\0’`) strings are NOT identical. The +assertion passes if the strings differ in length or content at any point before +their null terminators. A NULL pointer and a non-NULL string are considered not +equal and will pass. Two NULL pointers are considered equal and will fail. #### `TEST_ASSERT_EQUAL_STRING_LEN (expected, actual, len)` @@ -442,7 +447,11 @@ It checks only the first `len` characters, not the entire string. #### `TEST_ASSERT_NOT_EQUAL_STRING_LEN (expected, actual, len)` -Asserts that the null terminated (`’\0’`) strings are NOT identical up to the specified length. +Asserts that the null terminated (`’\0’`) strings are NOT identical within the +first `len` characters. The assertion passes if the strings differ at any +position within the specified length. A NULL pointer and a non-NULL string are +considered not equal and will pass. Two NULL pointers are considered equal and +will fail. Specifying a `len` of zero is considered pointless and will fail. #### `TEST_ASSERT_EQUAL_MEMORY (expected, actual, len)` @@ -453,7 +462,11 @@ the `len` parameter. #### `TEST_ASSERT_NOT_EQUAL_MEMORY (expected, actual, len)` Asserts that the contents of the memory specified by the `expected` and `actual` -pointers is NOT identical. +pointers is NOT identical within the first `len` bytes. The assertion passes if +any byte differs within that range. A NULL pointer and a non-NULL pointer are +considered not equal and will pass. Two NULL pointers (or the same pointer) are +considered equal and will fail. Specifying a `len` of zero is considered +pointless and will fail. ### Arrays diff --git a/test/tests/test_unity_integers.c b/test/tests/test_unity_integers.c index 495d87d..5fc42e3 100644 --- a/test/tests/test_unity_integers.c +++ b/test/tests/test_unity_integers.c @@ -700,6 +700,40 @@ void testNotEqualPointers(void) VERIFY_FAILS_END } +void testNotEqualPtr(void) +{ + int v0, v1; + int *p0, *p1; + + v0 = 19467; + v1 = 18271; + p0 = &v0; + p1 = &v1; + + TEST_ASSERT_NOT_EQUAL_PTR(p0, p1); + TEST_ASSERT_NOT_EQUAL_PTR(&v0, &v1); + TEST_ASSERT_NOT_EQUAL_PTR(p0, &v1); + TEST_ASSERT_NOT_EQUAL_PTR(NULL, &v0); + TEST_ASSERT_NOT_EQUAL_PTR(&v0, NULL); +} + +void testNotNotEqualPointers(void) +{ + int v0; + int *p0 = &v0; + + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_PTR(p0, p0); + VERIFY_FAILS_END +} + +void testNotNotEqualPointers_BothNull(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_PTR(NULL, NULL); + VERIFY_FAILS_END +} + void testIntsWithinDelta(void) { TEST_ASSERT_INT_WITHIN(1, 5000, 5001); diff --git a/test/tests/test_unity_memory.c b/test/tests/test_unity_memory.c index 7ee48d2..b1067ca 100644 --- a/test/tests/test_unity_memory.c +++ b/test/tests/test_unity_memory.c @@ -80,3 +80,32 @@ void testNotEqualMemoryLengthZero(void) TEST_ASSERT_EQUAL_MEMORY(NULL, NULL, 0); VERIFY_FAILS_END } + +void testNotEqualMemory(void) +{ + TEST_ASSERT_NOT_EQUAL_MEMORY("foo", "bar", 3); + TEST_ASSERT_NOT_EQUAL_MEMORY_MESSAGE("fool", "food", 4, "fool should not equal food"); + TEST_ASSERT_NOT_EQUAL_MEMORY(NULL, "food", 4); + TEST_ASSERT_NOT_EQUAL_MEMORY("fool", NULL, 4); +} + +void testNotNotEqualMemory1(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_MEMORY("foo", "foo", 3); + VERIFY_FAILS_END +} + +void testNotNotEqualMemory2(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_MEMORY(NULL, NULL, 1); + VERIFY_FAILS_END +} + +void testNotNotEqualMemoryLengthZero(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_MEMORY("foo", "bar", 0); + VERIFY_FAILS_END +} diff --git a/test/tests/test_unity_strings.c b/test/tests/test_unity_strings.c index bb38ecb..798f6c6 100644 --- a/test/tests/test_unity_strings.c +++ b/test/tests/test_unity_strings.c @@ -173,6 +173,70 @@ void testNotEqualString_ActualStringIsLonger(void) VERIFY_FAILS_END } +void testNotEqualStrings(void) +{ + TEST_ASSERT_NOT_EQUAL_STRING("foo", "bar"); + TEST_ASSERT_NOT_EQUAL_STRING_MESSAGE("foo", "bar", "foo should not equal bar"); + TEST_ASSERT_NOT_EQUAL_STRING("foo", ""); + TEST_ASSERT_NOT_EQUAL_STRING("", "bar"); + TEST_ASSERT_NOT_EQUAL_STRING("foo", "foo2"); + TEST_ASSERT_NOT_EQUAL_STRING("foo2", "foo"); + TEST_ASSERT_NOT_EQUAL_STRING(NULL, "bar"); + TEST_ASSERT_NOT_EQUAL_STRING("foo", NULL); +} + +void testNotNotEqualString1(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_STRING("foo", "foo"); + VERIFY_FAILS_END +} + +void testNotNotEqualString2(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_STRING(NULL, NULL); + VERIFY_FAILS_END +} + +void testNotEqualStringsLen(void) +{ + TEST_ASSERT_NOT_EQUAL_STRING_LEN("foobar", "foobaz", 6); + TEST_ASSERT_NOT_EQUAL_STRING_LEN_MESSAGE("foo", "bar", 3, "foo should not equal bar"); + TEST_ASSERT_NOT_EQUAL_STRING_LEN("foo", "", 3); + TEST_ASSERT_NOT_EQUAL_STRING_LEN("", "bar", 3); + TEST_ASSERT_NOT_EQUAL_STRING_LEN(NULL, "bar", 3); + TEST_ASSERT_NOT_EQUAL_STRING_LEN("foo", NULL, 3); +} + +void testNotNotEqualStringLen1(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_STRING_LEN("foobar", "foobaz", 5); + VERIFY_FAILS_END +} + +void testNotNotEqualStringLen2(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_STRING_LEN("foo", "foo", 3); + VERIFY_FAILS_END +} + +void testNotNotEqualStringLen3(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_STRING_LEN(NULL, NULL, 3); + VERIFY_FAILS_END +} + +void testNotNotEqualStringLenZero(void) +{ + EXPECT_ABORT_BEGIN + TEST_ASSERT_NOT_EQUAL_STRING_LEN("foo", "bar", 0); + VERIFY_FAILS_END +} + void testEqualStringArrays(void) { const char *testStrings[] = { "foo", "boo", "woo", "moo" };