diff options
-rw-r--r-- | _stdio.d | 13 | ||||
-rw-r--r-- | _stdio.h | 39 | ||||
-rw-r--r-- | _wchar.d | 4 | ||||
-rw-r--r-- | _wchar.h | 12 | ||||
-rw-r--r-- | _wctype.d | 1 | ||||
-rw-r--r-- | _wctype.h | 3 | ||||
-rw-r--r-- | string.c | 61 |
7 files changed, 133 insertions, 0 deletions
diff --git a/_stdio.d b/_stdio.d new file mode 100644 index 0000000..b6b7396 --- /dev/null +++ b/_stdio.d @@ -0,0 +1,13 @@ +NULL +_IOFBF +_IOLBF +_IONBF +BUFSIZ +EOF +FILENAME_MAX +FOPEN_MAX +L_tmpnam +SEEK_CUR +SEEK_END +SEEK_SET +TMP_MAX diff --git a/_stdio.h b/_stdio.h new file mode 100644 index 0000000..bc96470 --- /dev/null +++ b/_stdio.h @@ -0,0 +1,39 @@ +#ifndef NULL +#error NULL not defined +#endif +#ifndef _IOFBF +#error _IOFBF not defined +#endif +#ifndef _IOLBF +#error _IOLBF not defined +#endif +#ifndef _IONBF +#error _IONBF not defined +#endif +#ifndef BUFSIZ +#error BUFSIZ not defined +#endif +#ifndef EOF +#error EOF not defined +#endif +#ifndef FILENAME_MAX +#error FILENAME_MAX not defined +#endif +#ifndef FOPEN_MAX +#error FOPEN_MAX not defined +#endif +#ifndef L_tmpnam +#error L_tmpnam not defined +#endif +#ifndef SEEK_CUR +#error SEEK_CUR not defined +#endif +#ifndef SEEK_END +#error SEEK_END not defined +#endif +#ifndef SEEK_SET +#error SEEK_SET not defined +#endif +#ifndef TMP_MAX +#error TMP_MAX not defined +#endif diff --git a/_wchar.d b/_wchar.d new file mode 100644 index 0000000..0c79f3a --- /dev/null +++ b/_wchar.d @@ -0,0 +1,4 @@ +NULL +WCHAR_MAX +WCHAR_MIN +WEOF diff --git a/_wchar.h b/_wchar.h new file mode 100644 index 0000000..1ea3fce --- /dev/null +++ b/_wchar.h @@ -0,0 +1,12 @@ +#ifndef NULL +#error NULL not defined +#endif +#ifndef WCHAR_MAX +#error WCHAR_MAX not defined +#endif +#ifndef WCHAR_MIN +#error WCHAR_MIN not defined +#endif +#ifndef WEOF +#error WEOF not defined +#endif diff --git a/_wctype.d b/_wctype.d new file mode 100644 index 0000000..8751e5a --- /dev/null +++ b/_wctype.d @@ -0,0 +1 @@ +WEOF diff --git a/_wctype.h b/_wctype.h new file mode 100644 index 0000000..5709c5d --- /dev/null +++ b/_wctype.h @@ -0,0 +1,3 @@ +#ifndef WEOF +#error WEOF not defined +#endif @@ -4,10 +4,71 @@ void test_string_h(void) { size_t size; + char dst[64] = { 0 }; + char less[] = "a"; + char more[] = "b"; + char haystack[] = "the five boxing wizards jump quickly"; testing_header("string.h"); test_true(NULL == 0); + test_string(memcpy(dst + 1, "foo", 3), "foo"); + test_string(memmove(dst, dst + 1, 3), "fooo"); + + test_string(strcpy(dst, "foo"), "foo"); + memset(dst, '\0', sizeof(dst)); + test_string(strncpy(dst, "foo", 1), "f"); + test_string(strcat(dst, "oo"), "foo"); + test_string(strncat(dst, "barf", 3), "foobar"); + + test_int_equals(memcmp(less, less, 2), 0); + test_true(memcmp(less, more, 2) < 0); + test_true(memcmp(more, less, 2) > 0); + + test_int_equals(strcmp(less, less), 0); + test_true(strcmp(less, more) < 0); + test_true(strcmp(more, less) > 0); + + test_int_equals(strcoll(less, less), 0); + test_true(strcoll(less, more) < 0); + test_true(strcoll(more, less) > 0); + + test_int_equals(strncmp(less, less, 2), 0); + test_true(strncmp(less, more, 2) < 0); + test_true(strncmp(more, less, 2) > 0); + + /* TODO: strxfrm */ + + test_true(memchr(haystack, '1', sizeof(haystack)) == NULL); + test_true(memchr(haystack, 'f', sizeof(haystack)) == haystack + 4); + + test_true(strchr(haystack, '1') == NULL); + test_true(strchr(haystack, 'f') == haystack + 4); + + test_true(strcspn(haystack, " abcd") == 3); + test_true(strcspn(haystack, "eht") == 0); + test_true(strcspn(haystack, "12345") == sizeof(haystack) - 1); + + test_true(strpbrk(haystack, "12345") == NULL); + test_true(strpbrk(haystack, "abcd") == haystack + 9); + + test_true(strrchr(haystack, '1') == NULL); + test_true(strrchr(haystack, 'f') == haystack + 4); + + test_true(strspn(haystack, "12345") == 0); + test_true(strspn(haystack, "eht") == 3); + + test_true(strstr(haystack, "wizard") == haystack + 16); + test_true(strstr(haystack, "rogue") == NULL); + + /* TODO: strtok */ + + /* TODO: memset */ + + /* TODO: strerror */ + + test_true(strlen(haystack) == sizeof(haystack) - 1); + testing_end(); } |