Add checks for NULL return value to Fixture tests and spy

Help failures in the spy by adding filename and message to output
This commit is contained in:
jsalling
2016-01-31 22:44:45 -06:00
parent 63a0b98faf
commit e2ad88b9c0
2 changed files with 6 additions and 0 deletions

View File

@ -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);

View File

@ -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);
}