@@ -9,15 +9,12 @@ * the packaging of this file. */ #import "config.h" -#define _ISOC99_SOURCE - #import #import -#import #import "OFXMLFactory.h" #define NUM_TESTS 10 @@ -24,40 +21,20 @@ static int i; inline void check_result(char *result, const char *should) { - /* Use wprintf here so we don't mix printf and wprintf! */ - i++; - - if (!strcmp(result, should)) { - wprintf(L"\r\033[1;%dmchar* tests successful: %2d/%d\033[0m", - (i == NUM_TESTS ? 32 : 33), i, NUM_TESTS); - fflush(stdout); - } else { - wprintf(L"\r\033[K\033[1;31mchar* test %d/%d failed!\033[0m\n", - i, NUM_TESTS); - wprintf(L"%s is NOT expected result!\n", result); - exit(1); - } - - free(result); -} - -inline void -check_result_wide(wchar_t *result, const wchar_t *should) -{ - i++; - - if (!wcscmp(result, should)) { - wprintf(L"\r\033[1;%dmwchar_t* tests successful: %2d/%d\033[0m", - (i == NUM_TESTS ? 32 : 33), i, NUM_TESTS); - fflush(stdout); - } else { - wprintf(L"\r\033[K\033[1;31mwchar_t* test %d/%d failed!\033[0m" - "\n", i, NUM_TESTS); - wprintf(L"%s is NOT expected result!\n", result); + i++; + + if (!strcmp(result, should)) { + printf("\r\033[1;%dmTests successful: %2d/%d\033[0m", + (i == NUM_TESTS ? 32 : 33), i, NUM_TESTS); + fflush(stdout); + } else { + printf("\r\033[K\033[1;31mTest %d/%d failed!\033[0m\n", + i, NUM_TESTS); + printf("%s is NOT expected result!\n", result); exit(1); } free(result); } @@ -85,35 +62,10 @@ check_result([OFXMLFactory concatAndFreeCStrings: strs], "bar"); } -inline void -test_concat_wide() -{ - const wchar_t *c1 = L"", *c2 = L"bar", *c3 = L""; - wchar_t *s1, *s2, *s3; - wchar_t *strs[4]; - - if ((s1 = malloc((wcslen(c1) + 1) * sizeof(wchar_t))) == NULL || - (s2 = malloc((wcslen(c2) + 1) * sizeof(wchar_t))) == NULL || - (s3 = malloc((wcslen(c3) + 1) * sizeof(wchar_t))) == NULL) - exit(1); - - wcsncpy(s1, c1, wcslen(c1) + 1); - wcsncpy(s2, c2, wcslen(c2) + 1); - wcsncpy(s3, c3, wcslen(c3) + 1); - - strs[0] = s1; - strs[1] = s2; - strs[2] = s3; - strs[3] = NULL; - - check_result_wide([OFXMLFactory concatAndFreeWideCStrings: strs], - L"bar"); -} - inline void test_create_stanza() { check_result([OFXMLFactory createStanza: "foo" withCloseTag: NO @@ -165,92 +117,22 @@ "a", "b", NULL], "bar"); } -inline void -test_create_stanza_wide() -{ - check_result_wide([OFXMLFactory createWideStanza: L"foo" - withCloseTag: NO - andData: NULL, - NULL], - L""); - - check_result_wide([OFXMLFactory createWideStanza: L"foo" - withCloseTag: NO - andData: NULL, - L"bar", L"baz", - L"blub", L"asd", - NULL], - L""); - check_result_wide([OFXMLFactory createWideStanza: L"foo" - withCloseTag: YES - andData: NULL, - NULL], - L""); - check_result_wide([OFXMLFactory createWideStanza: L"foo" - withCloseTag: YES - andData: L"bar", - NULL], - L"bar"); - check_result_wide([OFXMLFactory createWideStanza: L"foo" - withCloseTag: YES - andData: NULL, - L"bar", L"b&az", - NULL], - L""); - check_result_wide([OFXMLFactory createWideStanza: L"foo" - withCloseTag: YES - andData: L"bar", - L"bar", L"b'az", - NULL], - L"bar"); - check_result_wide([OFXMLFactory createWideStanza: L"foo" - withCloseTag: YES - andData: NULL, - L"bar", L"b&az", - L"x", L"asd\"", - NULL], - L""); - check_result_wide([OFXMLFactory createWideStanza: L"foo" - withCloseTag: YES - andData: L"bar", - L"bar", L"b'az", - L"x", L"y", - L"a", L"b", - NULL], - L"bar"); -} - inline void test_escape() { check_result([OFXMLFactory escapeCString: " &welt'\"!&"], "<hallo> &welt'"!&"); } - -inline void -test_escape_wide() -{ - check_result_wide( - [OFXMLFactory escapeWideCString: L" &welt'\"!&"], - L"<hallo> &welt'"!&"); -} - int main() { i = 0; test_escape(); test_create_stanza(); test_concat(); - wprintf(L"\n"); - - i = 0; - test_escape_wide(); - test_create_stanza_wide(); - test_concat_wide(); - wprintf(L"\n"); + puts(""); return 0; }