void TestAssertStrnEquals(CuTest *tc) { jmp_buf buf; CuTest *tc2 = CuTestNew("TestAssertStrnEquals", zTestFails); const char* expected = "expected <hello> but was <world>"; const char *expectedMsg = "some text: expected <hello> but was <world>"; tc2->jumpBuf = &buf; if (setjmp(buf) == 0) { CuAssertStrnEquals(tc2, "hello", 0, "world"); } CuAssertTrue(tc, !tc2->failed); if (setjmp(buf) == 0) { CuAssertStrnEquals_Msg(tc2, "some text", "hello", 0, "world"); } CuAssertTrue(tc, !tc2->failed); if (setjmp(buf) == 0) { CuAssertStrnEquals(tc2, "hello", 5, "world"); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertStrEquals failed", expected, tc2->message); if (setjmp(buf) == 0) { CuAssertStrnEquals_Msg(tc2, "some text", "hello", 5, "world"); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertStrEquals failed", expectedMsg, tc2->message); }
void TestCuSuiteAddSuite(CuTest* tc) { CuSuite* ts1 = CuSuiteNew(); CuSuite* ts2 = CuSuiteNew(); CuSuiteAdd(ts1, CuTestNew("TestFails1", zTestFails)); CuSuiteAdd(ts1, CuTestNew("TestFails2", zTestFails)); CuSuiteAdd(ts2, CuTestNew("TestFails3", zTestFails)); CuSuiteAdd(ts2, CuTestNew("TestFails4", zTestFails)); CuSuiteAddSuite(ts1, ts2); CuAssertIntEquals(tc, 4, ts1->count); CuAssertStrEquals(tc, "TestFails1", ts1->list[0]->name); CuAssertStrEquals(tc, "TestFails2", ts1->list[1]->name); CuAssertStrEquals(tc, "TestFails3", ts1->list[2]->name); CuAssertStrEquals(tc, "TestFails4", ts1->list[3]->name); }
void TestCuTestNew(CuTest* tc) { CuTest* tc2 = CuTestNew("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 TestFail(CuTest* tc) { jmp_buf buf; int pointReached = 0; CuTest* tc2 = CuTestNew("TestFails", zTestFails); tc2->jumpBuf = &buf; if (setjmp(buf) == 0) { CuFail(tc2, "hello world"); pointReached = 1; } CuAssert(tc, "point was not reached", pointReached == 0); }
void TestAssertStrEquals_NULL(CuTest* tc) { jmp_buf buf; CuTest *tc2 = CuTestNew("TestAssertStrEquals_NULL", zTestFails); tc2->jumpBuf = &buf; if (setjmp(buf) == 0) { CuAssertStrEquals(tc2, NULL, NULL); } CuAssertTrue(tc, !tc2->failed); CompareAsserts(tc, "CuAssertStrEquals_NULL failed", NULL, tc2->message); if (setjmp(buf) == 0) { CuAssertStrEquals_Msg(tc2, "some text", NULL, NULL); } CuAssertTrue(tc, !tc2->failed); CompareAsserts(tc, "CuAssertStrEquals_NULL failed", NULL, tc2->message); }
void TestAssertIntEquals(CuTest* tc) { jmp_buf buf; CuTest *tc2 = CuTestNew("TestAssertIntEquals", zTestFails); const char* expected = "expected <42> but was <32>"; const char* expectedMsg = "some text: expected <42> but was <32>"; tc2->jumpBuf = &buf; if (setjmp(buf) == 0) { CuAssertIntEquals(tc2, 42, 32); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertIntEquals failed", expected, tc2->message); if (setjmp(buf) == 0) { CuAssertIntEquals_Msg(tc2, "some text", 42, 32); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertStrEquals failed", expectedMsg, tc2->message); }
void TestAssertStrEquals_FailStrNULL(CuTest* tc) { jmp_buf buf; CuTest *tc2 = CuTestNew("TestAssertStrEquals_FailStrNULL", zTestFails); const char* expected = "expected <NULL> but was <hello>"; const char *expectedMsg = "some text: expected <NULL> but was <hello>"; tc2->jumpBuf = &buf; if (setjmp(buf) == 0) { CuAssertStrEquals(tc2, NULL, "hello"); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertStrEquals_FailStrNULL failed", expected, tc2->message); if (setjmp(buf) == 0) { CuAssertStrEquals_Msg(tc2, "some text", NULL, "hello"); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertStrEquals_FailStrNULL failed", expectedMsg, 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); }