From e2ad88b9c073261e911d293447708f9a3a7453ba Mon Sep 17 00:00:00 2001 From: jsalling Date: Sun, 31 Jan 2016 22:44:45 -0600 Subject: [PATCH] Add checks for NULL return value to Fixture tests and spy Help failures in the spy by adding filename and message to output --- extras/fixture/test/unity_fixture_Test.c | 5 +++++ extras/fixture/test/unity_output_Spy.c | 1 + 2 files changed, 6 insertions(+) diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index 667f1f1..5c44627 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -79,6 +79,7 @@ TEST(UnityFixture, ReallocLargerNeeded) { void* m1 = malloc(10); void* m2; + CHECK(m1); strcpy((char*)m1, "123456789"); m2 = realloc(m1, 15); CHECK(m1 != m2); @@ -104,6 +105,7 @@ TEST(UnityFixture, CallocFillsWithZero) { void* m = calloc(3, sizeof(char)); char* s = (char*)m; + CHECK(m); TEST_ASSERT_BYTES_EQUAL(0, s[0]); TEST_ASSERT_BYTES_EQUAL(0, s[1]); TEST_ASSERT_BYTES_EQUAL(0, s[2]); @@ -323,6 +325,7 @@ TEST(LeakDetection, DetectsLeak) TEST_IGNORE_MESSAGE("Build with '-D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar' to enable tests"); #else void* m = malloc(10); + TEST_ASSERT_NOT_NULL(m); UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN UnityMalloc_EndTest(); @@ -341,6 +344,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree) TEST_IGNORE(); #else void* m = malloc(10); + TEST_ASSERT_NOT_NULL(m); char* s = (char*)m; s[10] = (char)0xFF; UnityOutputCharSpy_Enable(1); @@ -360,6 +364,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringRealloc) TEST_IGNORE(); #else void* m = malloc(10); + TEST_ASSERT_NOT_NULL(m); char* s = (char*)m; s[10] = (char)0xFF; UnityOutputCharSpy_Enable(1); diff --git a/extras/fixture/test/unity_output_Spy.c b/extras/fixture/test/unity_output_Spy.c index 68188e5..767471a 100644 --- a/extras/fixture/test/unity_output_Spy.c +++ b/extras/fixture/test/unity_output_Spy.c @@ -23,6 +23,7 @@ void UnityOutputCharSpy_Create(int s) count = 0; spy_enable = 0; buffer = UNITY_FIXTURE_MALLOC(size); + TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__); memset(buffer, 0, size); } -- GitLab