TEST(LeakDetection, DetectsLeak) { void* m = malloc(10); UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN UnityMalloc_EndTest(); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); CHECK(strstr(UnityOutputCharSpy_Get(), "This test leaks!")); free(m); Unity.CurrentTestFailed = 0; }
TEST(LeakDetection, BufferOverrunFoundDuringRealloc) { void* m = malloc(10); char* s = (char*)m; s[10] = (char)0xFF; UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN m = realloc(m, 100); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()")); Unity.CurrentTestFailed = 0; }
TEST(LeakDetection, PointerSettingMax) { #ifndef USING_OUTPUT_SPY TEST_IGNORE(); #else int i; for (i = 0; i < 50; i++) UT_PTR_SET(pointer1, &int1); UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN UT_PTR_SET(pointer1, &int1); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); Unity.CurrentTestFailed = 0; CHECK(strstr(UnityOutputCharSpy_Get(), "Too many pointers set")); #endif }
TEST(LeakDetection, DetectsLeak) { #ifndef USING_OUTPUT_SPY 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(); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); Unity.CurrentTestFailed = 0; CHECK(strstr(UnityOutputCharSpy_Get(), "This test leaks!")); free(m); #endif }
TEST(LeakDetection, BufferGuardWriteFoundDuringRealloc) { #ifndef USING_OUTPUT_SPY TEST_IGNORE(); #else void* m = malloc(10); char* s = (char*)m; TEST_ASSERT_NOT_NULL(m); s[-1] = (char)0x0A; UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN m = realloc(m, 100); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); Unity.CurrentTestFailed = 0; CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()")); #endif }
TEST(LeakDetection, BufferOverrunFoundDuringFree) { #ifndef USING_OUTPUT_SPY TEST_IGNORE(); #else void* m = malloc(10); char* s = (char*)m; TEST_ASSERT_NOT_NULL(m); s[10] = (char)0xFF; UnityOutputCharSpy_Enable(1); EXPECT_ABORT_BEGIN free(m); EXPECT_ABORT_END UnityOutputCharSpy_Enable(0); Unity.CurrentTestFailed = 0; CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()")); #endif }