void Test_iniparser_strstrip(CuTest *tc) { /* First element in the array is the expected stripping result */ const char *strings_empty[] = { "", " " }; const char *strings_test[] = { "test", "test ", "test ", " test", " test ", "\ttest\t", "\ttest\n" }; const char *test_with_spaces = "I am a test with\tspaces."; char stripped[ASCIILINESZ+1]; char error_msg[128]; unsigned i; /* NULL ptr as input */ CuAssertPtrEquals(tc, NULL, strstrip(NULL, NULL, 0)); CuAssertPtrEquals(tc, NULL, strstrip(NULL, stripped, sizeof (stripped))); CuAssertPtrEquals(tc, NULL, strstrip("", NULL, sizeof (stripped))); CuAssertPtrEquals(tc, NULL, strstrip("", stripped, 0)); CuAssertPtrEquals(tc, NULL, strstrip(NULL, NULL, 0)); /* empty string */ for (i = 0 ; i < sizeof (strings_empty) / sizeof (char *) ; ++i) { CuAssertPtrNotNull(tc, strstrip(strings_empty[i], stripped, sizeof(stripped))); sprintf(error_msg, "Bad stripping : strstrip(\"%s\") ==> \"%s\"", strings_empty[i], stripped); CuAssertStrEquals_Msg(tc, error_msg, stripped, strings_empty[0]); } /* test string */ for (i = 0 ; i < sizeof (strings_test) / sizeof (char *) ; ++i) { CuAssertPtrNotNull(tc, strstrip(strings_test[i], stripped, sizeof(stripped))); sprintf(error_msg, "Bad stripping : strstrip(\"%s\") ==> \"%s\"", strings_test[i], stripped); CuAssertStrEquals_Msg(tc, error_msg, strings_test[0], stripped); } CuAssertPtrNotNull(tc, strstrip(".", stripped, sizeof(stripped))); CuAssertStrEquals(tc, ".", stripped); /* string containing spaces */ CuAssertPtrNotNull(tc, strstrip(test_with_spaces, stripped, sizeof(stripped))); CuAssertStrEquals(tc, test_with_spaces, stripped); /* test a overflowing string */ CuAssertPtrNotNull(tc, strstrip(" Overflowing_string<--here", stripped, 19)); CuAssertStrEquals(tc, "Overflowing_string", stripped); /* test using same buffer as input and output */ strcpy(stripped, " STRIP_ME_! "); CuAssertPtrNotNull(tc, strstrip(stripped, stripped, sizeof(stripped))); CuAssertStrEquals(tc, "STRIP_ME_!", stripped); }
void Test_iniparser_strstrip(CuTest *tc) { /* First element in the array is the expected stripping result */ const char *strings_empty[] = { "", " ", "\n\n\n\n", "\t\t\t\t", "\n \t\n\t\n " }; const char *strings_test[] = { "test", "test ", "test ", " test", " test ", "\ttest\t", "\ttest\n" }; const char *test_with_spaces = "I am a test with\tspaces."; char stripped[ASCIILINESZ+1]; char error_msg[128]; unsigned i; /* NULL ptr as input */ strstrip(NULL); /* empty string */ for (i = 0 ; i < sizeof (strings_empty) / sizeof (char *) ; ++i) { strcpy(stripped, strings_empty[i]); strstrip(stripped); sprintf(error_msg, "Bad stripping : strstrip(\"%s\") ==> \"%s\"", strings_empty[i], stripped); CuAssertStrEquals_Msg(tc, error_msg, stripped, strings_empty[0]); } /* test string */ for (i = 0 ; i < sizeof (strings_test) / sizeof (char *) ; ++i) { strcpy(stripped, strings_test[i]); strstrip(stripped); sprintf(error_msg, "Bad stripping : strstrip(\"%s\") ==> \"%s\"", strings_test[i], stripped); CuAssertStrEquals_Msg(tc, error_msg, strings_test[0], stripped); } strcpy(stripped, "."); strstrip(stripped); CuAssertStrEquals(tc, ".", stripped); /* string containing spaces */ strcpy(stripped, test_with_spaces); strstrip(stripped); CuAssertStrEquals(tc, test_with_spaces, stripped); }
static void check_path(CuTest *tc, struct altera_syscons_parser *parser, const char *input, const char *cable, int expected_result, const char *expected_path) { const char *begin, *end; CuAssertPtrNotNull(tc, parser); CuAssertPtrNotNull(tc, parser->parse_service_path); int ret = parser->parse_service_path(input, strlen(input), cable, &begin, &end); CuAssertIntEquals_Msg(tc, cable, expected_result, ret); if (expected_result == BERI_DEBUG_SUCCESS) { CuAssertPtrNotNullMsg(tc, "parsed NULL 'begin'", begin); CuAssertPtrNotNullMsg(tc, "parsed NULL 'end'", end); CuAssert(tc, "begin > end", (begin <= end)); char result[end - begin + 1]; strncpy(result, begin, end - begin); result[end - begin] = '\0'; CuAssertStrEquals_Msg(tc, "unexpected path", expected_path, result); } }
static void parse_response(CuTest *tc, struct altera_syscons_parser *parser, const char *input, const char *expected_result) { CuAssertPtrNotNull(tc, parser); CuAssertPtrNotNull(tc, parser->parse_response); const char *begin, *end; int ret = parser->parse_response(input, strlen(input), &begin, &end); CuAssertIntEquals_Msg(tc, "parse error", BERI_DEBUG_SUCCESS, ret); CuAssertPtrNotNullMsg(tc, "parsed NULL 'begin'", begin); CuAssertPtrNotNullMsg(tc, "parsed NULL 'end'", end); CuAssert(tc, "begin > end", (begin <= end)); char result[end - begin + 1]; strncpy(result, begin, end - begin); result[end - begin] = '\0'; CuAssertStrEquals_Msg(tc, "unexpected result", expected_result, result); }
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 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 TestAssertStrEquals(CuTest* tc) { jmp_buf buf; CuTest *tc2 = CuTestNew("TestAssertStrEquals", 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) { CuAssertStrEquals(tc2, "hello", "world"); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertStrEquals failed", expected, tc2); if (setjmp(buf) == 0) { CuAssertStrEquals_Msg(tc2, "some text", "hello", "world"); } CuAssertTrue(tc, tc2->failed); CompareAsserts(tc, "CuAssertStrEquals failed", expectedMsg, tc2); }