mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-07-15 00:52:46 +08:00
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:
extras/fixture/test
@ -79,6 +79,7 @@ TEST(UnityFixture, ReallocLargerNeeded)
|
|||||||
{
|
{
|
||||||
void* m1 = malloc(10);
|
void* m1 = malloc(10);
|
||||||
void* m2;
|
void* m2;
|
||||||
|
CHECK(m1);
|
||||||
strcpy((char*)m1, "123456789");
|
strcpy((char*)m1, "123456789");
|
||||||
m2 = realloc(m1, 15);
|
m2 = realloc(m1, 15);
|
||||||
CHECK(m1 != m2);
|
CHECK(m1 != m2);
|
||||||
@ -104,6 +105,7 @@ TEST(UnityFixture, CallocFillsWithZero)
|
|||||||
{
|
{
|
||||||
void* m = calloc(3, sizeof(char));
|
void* m = calloc(3, sizeof(char));
|
||||||
char* s = (char*)m;
|
char* s = (char*)m;
|
||||||
|
CHECK(m);
|
||||||
TEST_ASSERT_BYTES_EQUAL(0, s[0]);
|
TEST_ASSERT_BYTES_EQUAL(0, s[0]);
|
||||||
TEST_ASSERT_BYTES_EQUAL(0, s[1]);
|
TEST_ASSERT_BYTES_EQUAL(0, s[1]);
|
||||||
TEST_ASSERT_BYTES_EQUAL(0, s[2]);
|
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");
|
TEST_IGNORE_MESSAGE("Build with '-D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar' to enable tests");
|
||||||
#else
|
#else
|
||||||
void* m = malloc(10);
|
void* m = malloc(10);
|
||||||
|
TEST_ASSERT_NOT_NULL(m);
|
||||||
UnityOutputCharSpy_Enable(1);
|
UnityOutputCharSpy_Enable(1);
|
||||||
EXPECT_ABORT_BEGIN
|
EXPECT_ABORT_BEGIN
|
||||||
UnityMalloc_EndTest();
|
UnityMalloc_EndTest();
|
||||||
@ -341,6 +344,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree)
|
|||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
void* m = malloc(10);
|
void* m = malloc(10);
|
||||||
|
TEST_ASSERT_NOT_NULL(m);
|
||||||
char* s = (char*)m;
|
char* s = (char*)m;
|
||||||
s[10] = (char)0xFF;
|
s[10] = (char)0xFF;
|
||||||
UnityOutputCharSpy_Enable(1);
|
UnityOutputCharSpy_Enable(1);
|
||||||
@ -360,6 +364,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringRealloc)
|
|||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
void* m = malloc(10);
|
void* m = malloc(10);
|
||||||
|
TEST_ASSERT_NOT_NULL(m);
|
||||||
char* s = (char*)m;
|
char* s = (char*)m;
|
||||||
s[10] = (char)0xFF;
|
s[10] = (char)0xFF;
|
||||||
UnityOutputCharSpy_Enable(1);
|
UnityOutputCharSpy_Enable(1);
|
||||||
|
@ -23,6 +23,7 @@ void UnityOutputCharSpy_Create(int s)
|
|||||||
count = 0;
|
count = 0;
|
||||||
spy_enable = 0;
|
spy_enable = 0;
|
||||||
buffer = UNITY_FIXTURE_MALLOC(size);
|
buffer = UNITY_FIXTURE_MALLOC(size);
|
||||||
|
TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__);
|
||||||
memset(buffer, 0, size);
|
memset(buffer, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user