TEST(TestMemoryAllocatorTest, TryingToAllocateTooMuchFailsTest) { TestTestingFixture fixture; fixture.setTestFunction(&failTryingToAllocateTooMuchMemory); fixture.runAllTests(); fixture.assertPrintContains("malloc returned null pointer"); }
TEST(MockCallTest, mockExpectationShouldIncreaseNumberOfChecks) { TestTestingFixture fixture; fixture.setTestFunction(mocksAreCountedAsChecksTestFunction_); fixture.runAllTests(); LONGS_EQUAL(5, fixture.getCheckCount()); }
TEST(MockSupport_c, NoExceptionsAreThrownWhenAMock_cCallFailed) { TestTestingFixture fixture; fixture.setTestFunction(failedCallToMockC); fixture.runAllTests(); LONGS_EQUAL(1, fixture.getFailureCount()); CHECK(!destructorWasCalled); }
MSC_SWITCHED_TEST(MockSupport_c, NoExceptionsAreThrownWhenAMock_cCallFailed) { TestTestingFixture fixture; fixture.setTestFunction(failedCallToMockC); fixture.runAllTests(); LONGS_EQUAL(1, fixture.getFailureCount()); // Odd behavior in Visual C++, destructor still gets called here CHECK(!destructorWasCalled); }
TEST(BasicBehavior, deleteWillNotThrowAnExceptionWhenDeletingUnallocatedMemoryButCanStillCauseTestFailures) { /* * Test failure might cause an exception. But according to C++ standard, you aren't allowed * to throw exceptions in the delete function. If you do that, it will call std::terminate. * Therefore, the delete will need to fail without exceptions. */ MemoryLeakFailure* defaultReporter = MemoryLeakWarningPlugin::getGlobalFailureReporter(); TestTestingFixture fixture; fixture.setTestFunction(deleteUnallocatedMemory); fixture.runAllTests(); LONGS_EQUAL(1, fixture.getFailureCount()); POINTERS_EQUAL(defaultReporter, MemoryLeakWarningPlugin::getGlobalFailureReporter()); }