void TestCuSuiteDetails_SingleFail(CuTest* tc) { CuSuite ts; CuTest tc1, tc2; CuString details; const char* front; const char* back; CuSuiteInit(&ts); CuTestInit(&tc1, "TestPasses", TestPasses); CuTestInit(&tc2, "TestFails", zTestFails); CuStringInit(&details); CuSuiteAdd(&ts, &tc1); CuSuiteAdd(&ts, &tc2); CuSuiteRun(&ts); CuSuiteDetails(&ts, &details); CuAssertTrue(tc, ts.count == 2); CuAssertTrue(tc, ts.failCount == 1); front = "There was 1 failure:\n" "1) TestFails: "; back = "test should fail\n" "\n!!!FAILURES!!!\n" "Runs: 2 Passes: 1 Fails: 1\n"; CuAssertStrEquals(tc, back, details.buffer + strlen(details.buffer) - strlen(back)); details.buffer[strlen(front)] = 0; CuAssertStrEquals(tc, front, details.buffer); }
void TestCuSuiteDetails_MultiplePasses(CuTest* tc) { CuSuite ts; CuTest tc1, tc2; CuString details; const char* expected; CuSuiteInit(&ts); CuTestInit(&tc1, "TestPasses", TestPasses); CuTestInit(&tc2, "TestPasses", TestPasses); CuStringInit(&details); CuSuiteAdd(&ts, &tc1); CuSuiteAdd(&ts, &tc2); CuSuiteRun(&ts); CuSuiteDetails(&ts, &details); CuAssertTrue(tc, ts.count == 2); CuAssertTrue(tc, ts.failCount == 0); expected = "OK (2 tests)\n"; CuAssertStrEquals(tc, expected, details.buffer); }
void TestCustomProgressCallback(CuTest* tc) { CuSuite ts; CuTest tc1, tc2, tc3, tc4; customProgressCallbackCounter = 0; cuPreferences.progressCallback = CustomProgressCallback; CuSuiteInit(&ts); CuTestInit(&tc1, "TestPasses", TestPasses); CuTestInit(&tc2, "TestPasses", TestPasses); CuTestInit(&tc3, "TestFails", zTestFails); CuTestInit(&tc4, "TestPasses", TestPasses); CuSuiteAdd(&ts, &tc1); CuSuiteAdd(&ts, &tc2); CuSuiteAdd(&ts, &tc3); CuSuiteAdd(&ts, &tc4); CuAssertTrue(tc, ts.count == 4); CuSuiteRun(&ts); CuAssertTrue(tc, ts.count - ts.failCount == 3); CuAssertTrue(tc, ts.failCount == 1); CuAssertTrue(tc, customProgressCallbackCounter == 4); cuPreferences.progressCallback = NULL; }
CuTest* CuTestNew(const char* name, TestFunction function) { CuTest* tc = NULL; if (ALLOC(tc) < 0) die_oom(); CuTestInit(tc, name, function); return tc; }
CuTest* CuTestNew(const char* name, TestFunction function, TestSetupFunction setup, TestTeardownFunction teardown) { CuTest* tc = CU_ALLOC(CuTest); if (tc != NULL) CuTestInit(tc, name, function, setup, teardown); else fprintf(stderr, "%s: %s%s\n", CU_FAIL_HEADER, "Error initializing test case: ", name); return tc; }
void TestCuAssertPtrNotNull_Failure(CuTest* tc) { CuTest tc2; CuTestInit(&tc2, "MyTest", TestPasses); /* test failing case */ CuAssertPtrNotNull(&tc2, NULL); CuAssertTrue(tc, tc2.failed); CompareAsserts(tc, "CuAssertPtrNotNull failed", "null pointer unexpected", tc2.message); }
void TestCuTestRun(CuTest* tc) { CuTest tc2; CuTestInit(&tc2, "MyTest", zTestFails); CuTestRun(&tc2); CuAssertStrEquals(tc, "MyTest", tc2.name); CuAssertTrue(tc, tc2.failed); CuAssertTrue(tc, tc2.ran); CompareAsserts(tc, "TestRun failed", "test should fail", tc2.message); }
void TestCuTestInit(CuTest *tc) { CuTest tc2; CuTestInit(&tc2, "MyTest", TestPasses); CuAssertStrEquals(tc, "MyTest", tc2.name); CuAssertTrue(tc, !tc2.failed); CuAssertTrue(tc, tc2.message == NULL); CuAssertTrue(tc, tc2.function == TestPasses); CuAssertTrue(tc, tc2.ran == 0); CuAssertTrue(tc, tc2.jumpBuf == NULL); }
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2) { int i; for (i = 0 ; i < testSuite2->count ; ++i) { CuTest* testCase = testSuite2->list[i]; CuTest* newTest = CU_ALLOC(CuTest); CuTestInit(newTest, testCase->name, testCase->function); CuSuiteAdd(testSuite, newTest); } }
void TestCuAssertPtrNotNull_Success(CuTest* tc) { CuTest tc2; int x; CuTestInit(&tc2, "MyTest", TestPasses); /* test success case */ CuAssertPtrNotNull(&tc2, &x); CuAssertTrue(tc, ! tc2.failed); CuAssertTrue(tc, NULL == tc2.message); }
void TestCuSuiteSummary(CuTest* tc) { CuSuite ts; CuTest tc1, tc2; CuString summary; CuSuiteInit(&ts); CuTestInit(&tc1, "TestPasses", TestPasses); CuTestInit(&tc2, "TestFails", zTestFails); CuStringInit(&summary); CuSuiteAdd(&ts, &tc1); CuSuiteAdd(&ts, &tc2); CuSuiteRun(&ts); CuSuiteSummary(&ts, &summary); CuAssertTrue(tc, ts.count == 2); CuAssertTrue(tc, ts.failCount == 1); CuAssertStrEquals(tc, ".F\n\n", summary.buffer); }
void TestCuSuiteRun(CuTest* tc) { CuSuite ts; CuTest tc1, tc2, tc3, tc4; CuSuiteInit(&ts); CuTestInit(&tc1, "TestPasses", TestPasses); CuTestInit(&tc2, "TestPasses", TestPasses); CuTestInit(&tc3, "TestFails", zTestFails); CuTestInit(&tc4, "TestFails", zTestFails); CuSuiteAdd(&ts, &tc1); CuSuiteAdd(&ts, &tc2); CuSuiteAdd(&ts, &tc3); CuSuiteAdd(&ts, &tc4); CuAssertTrue(tc, ts.count == 4); CuSuiteRun(&ts); CuAssertTrue(tc, ts.count - ts.failCount == 2); CuAssertTrue(tc, ts.failCount == 2); }
void TestCuSuiteAddTest(CuTest* tc) { CuSuite ts; CuTest tc2; CuSuiteInit(&ts); CuTestInit(&tc2, "MyTest", zTestFails); CuSuiteAdd(&ts, &tc2); CuAssertTrue(tc, ts.count == 1); CuAssertStrEquals(tc, "MyTest", ts.list[0]->name); }
void TestCuSuiteDetails_MultipleFails_gcclike(CuTest* tc) { CuSuite ts; CuTest tc1, tc2; CuString details; const char* front; const char* mid; const char* back; cuPreferences.outputFormat = CuOutputFormat_gcclike; CuSuiteInit(&ts); CuTestInit(&tc1, "TestFails1", zTestFails); CuTestInit(&tc2, "TestFails2", zTestFails); CuStringInit(&details); CuSuiteAdd(&ts, &tc1); CuSuiteAdd(&ts, &tc2); CuSuiteRun(&ts); CuSuiteDetails(&ts, &details); CuAssertTrue(tc, ts.count == 2); CuAssertTrue(tc, ts.failCount == 2); front = "There were 2 failures:\n" __FILE__ ":"; mid = "test should fail\n" __FILE__ ":"; back = "test should fail\n" "\n!!!FAILURES!!!\n" "Runs: 2 Passes: 0 Fails: 2\n"; CuAssertStrEquals(tc, back, details.buffer + strlen(details.buffer) - strlen(back)); CuAssert(tc, "Couldn't find middle", strstr(details.buffer, mid) != NULL); details.buffer[strlen(front)] = 0; CuAssertStrEquals(tc, front, details.buffer); }
void TestCuAssertPtrEquals_Failure(CuTest* tc) { CuTest tc2; int x; int* nullPtr = NULL; char expected_message[STRING_MAX]; CuTestInit(&tc2, "MyTest", TestPasses); /* test failing case */ sprintf(expected_message, "expected pointer <0x%p> but was <0x%p>", nullPtr, &x); CuAssertPtrEquals(&tc2, NULL, &x); CuAssertTrue(tc, tc2.failed); CompareAsserts(tc, "CuAssertPtrEquals failed", expected_message, tc2.message); }
void TestCuAssert(CuTest* tc) { CuTest tc2; CuTestInit(&tc2, "MyTest", TestPasses); CuAssert(&tc2, "test 1", 5 == 4 + 1); CuAssertTrue(tc, !tc2.failed); CuAssertTrue(tc, tc2.message == NULL); CuAssert(&tc2, "test 2", 0); CuAssertTrue(tc, tc2.failed); CompareAsserts(tc, "CuAssert didn't fail", "test 2", tc2.message); CuAssert(&tc2, "test 3", 1); CuAssertTrue(tc, tc2.failed); CompareAsserts(tc, "CuAssert didn't fail", "test 2", tc2.message); CuAssert(&tc2, "test 4", 0); CuAssertTrue(tc, tc2.failed); CompareAsserts(tc, "CuAssert didn't fail", "test 4", tc2.message); }
void TestAssertDblEquals(CuTest* tc) { jmp_buf buf; double x = 3.33; double y = 10.0 / 3.0; CuTest *tc2 = CuTestNew("TestAssertDblEquals", zTestFails); char expected[STRING_MAX]; char expectedMsg[STRING_MAX]; sprintf(expected, "expected <%lf> but was <%lf>", x, y); sprintf(expectedMsg, "some text: expected <%lf> but was <%lf>", x, y); CuTestInit(tc2, "TestAssertDblEquals", TestPasses); CuAssertDblEquals(tc2, x, x, 0.0); CuAssertTrue(tc, ! tc2->failed); CuAssertTrue(tc, NULL == tc2->message); CuAssertDblEquals(tc2, x, y, 0.01); CuAssertTrue(tc, ! tc2->failed); CuAssertTrue(tc, NULL == tc2->message); tc2->jumpBuf = &buf; if (setjmp(buf) == 0) { CuAssertDblEquals(tc2, x, y, 0.001); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertDblEquals failed", expected, tc2->message); tc2->jumpBuf = &buf; if (setjmp(buf) == 0) { CuAssertDblEquals_Msg(tc2, "some text", x, y, 0.001); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertDblEquals failed", expectedMsg, tc2->message); }
CuTest* CuTestNew(const char* name, TestFunction function) { CuTest* tc = CU_ALLOC(CuTest); CuTestInit(tc, name, function); return tc; }