From 4897c7b458e1b3cc0a70916540f7e61e74b0a7d5 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 21 Aug 2019 19:35:26 -0400 Subject: add string tests --- string.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/string.c b/string.c index 86a270c..fa44d78 100644 --- a/string.c +++ b/string.c @@ -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(); } -- cgit v1.2.1 From c9d408f4a83e8dd569699b0a8393d9311aafbcc3 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 21 Aug 2019 19:35:45 -0400 Subject: add missing files --- _stdio.d | 13 +++++++++++++ _stdio.h | 39 +++++++++++++++++++++++++++++++++++++++ _wchar.d | 4 ++++ _wchar.h | 12 ++++++++++++ _wctype.d | 1 + _wctype.h | 3 +++ 6 files changed, 72 insertions(+) create mode 100644 _stdio.d create mode 100644 _stdio.h create mode 100644 _wchar.d create mode 100644 _wchar.h create mode 100644 _wctype.d create mode 100644 _wctype.h 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 -- cgit v1.2.1