From 9b483673c0c8a52d81127a23788fa4c976f2b10f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 12 Jun 2022 18:48:26 +0200 Subject: Replace to last static inline's with line + extern inline, and fix warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- strccpy.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 strccpy.c (limited to 'strccpy.c') diff --git a/strccpy.c b/strccpy.c new file mode 100644 index 0000000..f4f7630 --- /dev/null +++ b/strccpy.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +extern inline char *libsimple_strccpy(char *restrict, const char *restrict, int); + + +#else +#include "test.h" + +int +main(void) +{ + return 0; +} + +#endif -- cgit v1.2.3-70-g09d2 From 3d6482b0949159c33d6ac2972a69868bdda766f2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 12 Jun 2022 20:13:23 +0200 Subject: Move some test code to newline created .c files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- envaligned_allocn.c | 2 +- envcallocn.c | 2 +- envmallocn.c | 2 +- envmemalignn.c | 2 +- envmemalignzn.c | 2 +- envvallocn.c | 2 +- evaligned_allocn.c | 2 +- evaligned_alloczn.c | 2 +- evaligned_reallocn.c | 2 +- evcallocn.c | 2 +- evmallocn.c | 2 +- evmalloczn.c | 2 +- evmemalignn.c | 2 +- evmemalignzn.c | 2 +- evvallocn.c | 2 +- inchrcaseset.c | 2 +- inchrset.c | 7 + libsimple.c | 790 +-------------------------------------------------- memisutf8.c | 4 - stpmove.c | 20 ++ stpnmove.c | 74 +++++ stpnset.c | 21 ++ stpntolower.c | 34 --- stpntoupper.c | 34 --- stpset.c | 11 + stptolower.c | 9 - stptoupper.c | 9 - strcasecmpnul.c | 17 ++ strcaseeq.c | 10 + strcaseeqnul.c | 15 + strcasestarts.c | 2 +- strccpy.c | 22 ++ strcmpnul.c | 17 ++ strend.c | 1 + streq.c | 10 + streqnul.c | 15 + strisutf8.c | 56 ++++ strmove.c | 20 ++ strncasecmpnul.c | 40 +++ strncaseeq.c | 30 ++ strncaseeqnul.c | 45 +++ strnccpy.c | 70 +++++ strncmpnul.c | 40 +++ strneq.c | 30 ++ strneqnul.c | 45 +++ strnisutf8.c | 60 ++++ strnmove.c | 74 +++++ strnreplace.c | 26 ++ strnset.c | 21 ++ strntolower.c | 39 +++ strntoupper.c | 39 +++ strrcaseeqlen.c | 21 ++ strreplace.c | 6 + strreqlen.c | 19 ++ strrncaseeqlen.c | 26 ++ strrneqlen.c | 24 ++ strset.c | 11 + strtolower.c | 12 + strtoupper.c | 12 + valigned_allocn.c | 2 +- valigned_reallocfn.c | 4 +- vcallocn.c | 2 +- vmallocn.c | 2 +- vmemalignn.c | 2 +- vmemalignzn.c | 2 +- vvallocn.c | 2 +- 66 files changed, 1033 insertions(+), 903 deletions(-) (limited to 'strccpy.c') diff --git a/envaligned_allocn.c b/envaligned_allocn.c index fbb97f2..2c8611a 100644 --- a/envaligned_allocn.c +++ b/envaligned_allocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_envaligned_allocn(int, size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_enaligned_allocn */ } #endif diff --git a/envcallocn.c b/envcallocn.c index 3c943ef..96aa31c 100644 --- a/envcallocn.c +++ b/envcallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_envcallocn(int, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_encallocn */ } #endif diff --git a/envmallocn.c b/envmallocn.c index 9b37db4..68b2ab6 100644 --- a/envmallocn.c +++ b/envmallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_envmallocn(int, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_enmallocn */ } #endif diff --git a/envmemalignn.c b/envmemalignn.c index 48a56fd..25f9142 100644 --- a/envmemalignn.c +++ b/envmemalignn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_envmemalignn(int, size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_enmemalignn */ } #endif diff --git a/envmemalignzn.c b/envmemalignzn.c index fb4b464..ca4e16d 100644 --- a/envmemalignzn.c +++ b/envmemalignzn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_envmemalignzn(int, int, size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_enmemalignzn */ } #endif diff --git a/envvallocn.c b/envvallocn.c index b351a14..9dc333f 100644 --- a/envvallocn.c +++ b/envvallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_envvallocn(int, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_envallocn */ } #endif diff --git a/evaligned_allocn.c b/evaligned_allocn.c index 2d14680..00dad49 100644 --- a/evaligned_allocn.c +++ b/evaligned_allocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evaligned_allocn(size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_ealigned_allocn */ } #endif diff --git a/evaligned_alloczn.c b/evaligned_alloczn.c index ec2d305..26b9e1f 100644 --- a/evaligned_alloczn.c +++ b/evaligned_alloczn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evaligned_alloczn(int, size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_ealigned_alloczn */ } #endif diff --git a/evaligned_reallocn.c b/evaligned_reallocn.c index 37e7133..e17545e 100644 --- a/evaligned_reallocn.c +++ b/evaligned_reallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evaligned_reallocn(void *, size_t, size_t, va_list int main(void) { - return 0; + return 0; /* Tested via libsimple_ealigned_reallocn */ } #endif diff --git a/evcallocn.c b/evcallocn.c index 25770bc..1fe842d 100644 --- a/evcallocn.c +++ b/evcallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evcallocn(size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_ecallocn */ } #endif diff --git a/evmallocn.c b/evmallocn.c index 67003f0..d61142d 100644 --- a/evmallocn.c +++ b/evmallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evmallocn(size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_emallocn */ } #endif diff --git a/evmalloczn.c b/evmalloczn.c index 7cf4abe..bae8f87 100644 --- a/evmalloczn.c +++ b/evmalloczn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evmalloczn(int, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_emalloczn */ } #endif diff --git a/evmemalignn.c b/evmemalignn.c index 5e1de37..99006ec 100644 --- a/evmemalignn.c +++ b/evmemalignn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evmemalignn(size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_ememalignn */ } #endif diff --git a/evmemalignzn.c b/evmemalignzn.c index 304d5b8..34d9495 100644 --- a/evmemalignzn.c +++ b/evmemalignzn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evmemalignzn(int, size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_ememalignzn */ } #endif diff --git a/evvallocn.c b/evvallocn.c index 5e52d4f..5776f63 100644 --- a/evvallocn.c +++ b/evvallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_evvallocn(size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_evallocn */ } #endif diff --git a/inchrcaseset.c b/inchrcaseset.c index bd50fa3..bd92cf5 100644 --- a/inchrcaseset.c +++ b/inchrcaseset.c @@ -3,7 +3,7 @@ #ifndef TEST -extern inline int libsimple_inchrcaseset(int, const char *); +extern inline int libsimple_inchrcaseset(int, const char *); /* TODO test */ #else diff --git a/inchrset.c b/inchrset.c index 7358ede..591c2e9 100644 --- a/inchrset.c +++ b/inchrset.c @@ -12,6 +12,13 @@ extern inline int libsimple_inchrset(int, const char *); int main(void) { + assert(libsimple_inchrset('a', "xyz") == 0); + assert(libsimple_inchrset('b', "xyz") == 0); + assert(libsimple_inchrset('c', "xyz") == 0); + assert(libsimple_inchrset('x', "xyz") == 1); + assert(libsimple_inchrset('y', "xyz") == 1); + assert(libsimple_inchrset('z', "xyz") == 1); + assert(libsimple_inchrset('\0', "xyz") == 0); return 0; } diff --git a/libsimple.c b/libsimple.c index 2cf7b62..2bb5139 100644 --- a/libsimple.c +++ b/libsimple.c @@ -92,9 +92,9 @@ main(void) void *ptr, *old; const char *cs; const wchar_t *cws; - char buf[1024], *s; + char *s; wchar_t *ws; - size_t i, j, n; + size_t i, n; DEFINE_PAGESIZE; DEFINE_CACHELINE; @@ -280,342 +280,6 @@ main(void) assert(TYPE_MIN(int64_t) == INT64_MIN); assert(TYPE_MIN(uint64_t) == 0); - assert(strcmpnul(libsimple_strend("abc\0xyz"), "xyz")); - - assert(libsimple_inchrset('a', "xyz") == 0); - assert(libsimple_inchrset('b', "xyz") == 0); - assert(libsimple_inchrset('c', "xyz") == 0); - assert(libsimple_inchrset('x', "xyz") == 1); - assert(libsimple_inchrset('y', "xyz") == 1); - assert(libsimple_inchrset('z', "xyz") == 1); - assert(libsimple_inchrset('\0', "xyz") == 0); - - assert(libsimple_streq("abc", "abc") == 1); - assert(libsimple_streq("abc", "ab") == 0); - assert(libsimple_streq("ab", "abc") == 0); - assert(libsimple_streq("ab", "xy") == 0); - assert(libsimple_streq("xy", "ab") == 0); - assert(libsimple_streq("", "1") == 0); - assert(libsimple_streq("1", "") == 0); - assert(libsimple_streq("", "") == 1); - assert(libsimple_streq("abc", "ABC") == 0); - assert(libsimple_streq("ABC", "abc") == 0); - - assert(libsimple_strneq("abc", "abc", 5) == 1); - assert(libsimple_strneq("abc", "ab", 5) == 0); - assert(libsimple_strneq("ab", "abc", 5) == 0); - assert(libsimple_strneq("ab", "xy", 5) == 0); - assert(libsimple_strneq("xy", "ab", 5) == 0); - assert(libsimple_strneq("", "1", 5) == 0); - assert(libsimple_strneq("1", "", 5) == 0); - assert(libsimple_strneq("", "", 5) == 1); - assert(libsimple_strneq("abc", "ABC", 5) == 0); - assert(libsimple_strneq("ABC", "abc", 5) == 0); - assert(libsimple_strneq("abc", "abc", 1) == 1); - assert(libsimple_strneq("abc", "ab", 1) == 1); - assert(libsimple_strneq("ab", "abc", 1) == 1); - assert(libsimple_strneq("ab", "xy", 1) == 0); - assert(libsimple_strneq("xy", "ab", 1) == 0); - assert(libsimple_strneq("", "1", 1) == 0); - assert(libsimple_strneq("1", "", 1) == 0); - assert(libsimple_strneq("", "", 1) == 1); - assert(libsimple_strneq("abc", "ABC", 1) == 0); - assert(libsimple_strneq("ABC", "abc", 1) == 0); - assert(libsimple_strneq("abc", "abc", 0) == 1); - assert(libsimple_strneq("abc", "ab", 0) == 1); - assert(libsimple_strneq("ab", "abc", 0) == 1); - assert(libsimple_strneq("ab", "xy", 0) == 1); - assert(libsimple_strneq("xy", "ab", 0) == 1); - assert(libsimple_strneq("", "1", 0) == 1); - assert(libsimple_strneq("1", "", 0) == 1); - assert(libsimple_strneq("", "", 0) == 1); - assert(libsimple_strneq("abc", "ABC", 0) == 1); - assert(libsimple_strneq("ABC", "abc", 0) == 1); - - assert(libsimple_streqnul("abc", "abc") == 1); - assert(libsimple_streqnul("abc", "ab") == 0); - assert(libsimple_streqnul("ab", "abc") == 0); - assert(libsimple_streqnul("ab", "xy") == 0); - assert(libsimple_streqnul("xy", "ab") == 0); - assert(libsimple_streqnul("", "1") == 0); - assert(libsimple_streqnul("1", "") == 0); - assert(libsimple_streqnul("", "") == 1); - assert(libsimple_streqnul("abc", "ABC") == 0); - assert(libsimple_streqnul("ABC", "abc") == 0); - assert(libsimple_streqnul("", NULL) == 0); - assert(libsimple_streqnul("1", NULL) == 0); - assert(libsimple_streqnul(NULL, "") == 0); - assert(libsimple_streqnul(NULL, "1") == 0); - assert(libsimple_streqnul(NULL, NULL) == 1); - - assert(libsimple_strneqnul("abc", "abc", 5) == 1); - assert(libsimple_strneqnul("abc", "ab", 5) == 0); - assert(libsimple_strneqnul("ab", "abc", 5) == 0); - assert(libsimple_strneqnul("ab", "xy", 5) == 0); - assert(libsimple_strneqnul("xy", "ab", 5) == 0); - assert(libsimple_strneqnul("", "1", 5) == 0); - assert(libsimple_strneqnul("1", "", 5) == 0); - assert(libsimple_strneqnul("", "", 5) == 1); - assert(libsimple_strneqnul("abc", "ABC", 5) == 0); - assert(libsimple_strneqnul("ABC", "abc", 5) == 0); - assert(libsimple_strneqnul("", NULL, 5) == 0); - assert(libsimple_strneqnul("1", NULL, 5) == 0); - assert(libsimple_strneqnul(NULL, "", 5) == 0); - assert(libsimple_strneqnul(NULL, "1", 5) == 0); - assert(libsimple_strneqnul(NULL, NULL, 5) == 1); - assert(libsimple_strneqnul("abc", "abc", 1) == 1); - assert(libsimple_strneqnul("abc", "ab", 1) == 1); - assert(libsimple_strneqnul("ab", "abc", 1) == 1); - assert(libsimple_strneqnul("ab", "xy", 1) == 0); - assert(libsimple_strneqnul("xy", "ab", 1) == 0); - assert(libsimple_strneqnul("", "1", 1) == 0); - assert(libsimple_strneqnul("1", "", 1) == 0); - assert(libsimple_strneqnul("", "", 1) == 1); - assert(libsimple_strneqnul("abc", "ABC", 1) == 0); - assert(libsimple_strneqnul("ABC", "abc", 1) == 0); - assert(libsimple_strneqnul("", NULL, 1) == 0); - assert(libsimple_strneqnul("1", NULL, 1) == 0); - assert(libsimple_strneqnul(NULL, "", 1) == 0); - assert(libsimple_strneqnul(NULL, "1", 1) == 0); - assert(libsimple_strneqnul(NULL, NULL, 1) == 1); - assert(libsimple_strneqnul("abc", "abc", 0) == 1); - assert(libsimple_strneqnul("abc", "ab", 0) == 1); - assert(libsimple_strneqnul("ab", "abc", 0) == 1); - assert(libsimple_strneqnul("ab", "xy", 0) == 1); - assert(libsimple_strneqnul("xy", "ab", 0) == 1); - assert(libsimple_strneqnul("", "1", 0) == 1); - assert(libsimple_strneqnul("1", "", 0) == 1); - assert(libsimple_strneqnul("", "", 0) == 1); - assert(libsimple_strneqnul("abc", "ABC", 0) == 1); - assert(libsimple_strneqnul("ABC", "abc", 0) == 1); - assert(libsimple_strneqnul("", NULL, 0) == 0); - assert(libsimple_strneqnul("1", NULL, 0) == 0); - assert(libsimple_strneqnul(NULL, "", 0) == 0); - assert(libsimple_strneqnul(NULL, "1", 0) == 0); - assert(libsimple_strneqnul(NULL, NULL, 0) == 1); - - assert(libsimple_strcaseeq("abc", "abc") == 1); - assert(libsimple_strcaseeq("abc", "ab") == 0); - assert(libsimple_strcaseeq("ab", "abc") == 0); - assert(libsimple_strcaseeq("ab", "xy") == 0); - assert(libsimple_strcaseeq("xy", "ab") == 0); - assert(libsimple_strcaseeq("", "1") == 0); - assert(libsimple_strcaseeq("1", "") == 0); - assert(libsimple_strcaseeq("", "") == 1); - assert(libsimple_strcaseeq("abc", "ABC") == 1); - assert(libsimple_strcaseeq("ABC", "abc") == 1); - - assert(libsimple_strncaseeq("abc", "abc", 5) == 1); - assert(libsimple_strncaseeq("abc", "ab", 5) == 0); - assert(libsimple_strncaseeq("ab", "abc", 5) == 0); - assert(libsimple_strncaseeq("ab", "xy", 5) == 0); - assert(libsimple_strncaseeq("xy", "ab", 5) == 0); - assert(libsimple_strncaseeq("", "1", 5) == 0); - assert(libsimple_strncaseeq("1", "", 5) == 0); - assert(libsimple_strncaseeq("", "", 5) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 5) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 5) == 1); - assert(libsimple_strncaseeq("abc", "abc", 1) == 1); - assert(libsimple_strncaseeq("abc", "ab", 1) == 1); - assert(libsimple_strncaseeq("ab", "abc", 1) == 1); - assert(libsimple_strncaseeq("ab", "xy", 1) == 0); - assert(libsimple_strncaseeq("xy", "ab", 1) == 0); - assert(libsimple_strncaseeq("", "1", 1) == 0); - assert(libsimple_strncaseeq("1", "", 1) == 0); - assert(libsimple_strncaseeq("", "", 1) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 1) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 1) == 1); - assert(libsimple_strncaseeq("abc", "abc", 0) == 1); - assert(libsimple_strncaseeq("abc", "ab", 0) == 1); - assert(libsimple_strncaseeq("ab", "abc", 0) == 1); - assert(libsimple_strncaseeq("ab", "xy", 0) == 1); - assert(libsimple_strncaseeq("xy", "ab", 0) == 1); - assert(libsimple_strncaseeq("", "1", 0) == 1); - assert(libsimple_strncaseeq("1", "", 0) == 1); - assert(libsimple_strncaseeq("", "", 0) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 0) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 0) == 1); - - assert(libsimple_strcaseeqnul("abc", "abc") == 1); - assert(libsimple_strcaseeqnul("abc", "ab") == 0); - assert(libsimple_strcaseeqnul("ab", "abc") == 0); - assert(libsimple_strcaseeqnul("ab", "xy") == 0); - assert(libsimple_strcaseeqnul("xy", "ab") == 0); - assert(libsimple_strcaseeqnul("", "1") == 0); - assert(libsimple_strcaseeqnul("1", "") == 0); - assert(libsimple_strcaseeqnul("", "") == 1); - assert(libsimple_strcaseeqnul("abc", "ABC") == 1); - assert(libsimple_strcaseeqnul("ABC", "abc") == 1); - assert(libsimple_strcaseeqnul("", NULL) == 0); - assert(libsimple_strcaseeqnul("1", NULL) == 0); - assert(libsimple_strcaseeqnul(NULL, "") == 0); - assert(libsimple_strcaseeqnul(NULL, "1") == 0); - assert(libsimple_strcaseeqnul(NULL, NULL) == 1); - - assert(libsimple_strncaseeqnul("abc", "abc", 5) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 5) == 0); - assert(libsimple_strncaseeqnul("ab", "abc", 5) == 0); - assert(libsimple_strncaseeqnul("ab", "xy", 5) == 0); - assert(libsimple_strncaseeqnul("xy", "ab", 5) == 0); - assert(libsimple_strncaseeqnul("", "1", 5) == 0); - assert(libsimple_strncaseeqnul("1", "", 5) == 0); - assert(libsimple_strncaseeqnul("", "", 5) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 5) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 5) == 1); - assert(libsimple_strncaseeqnul("", NULL, 5) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 5) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 5) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 5) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 5) == 1); - assert(libsimple_strncaseeqnul("abc", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 1) == 1); - assert(libsimple_strncaseeqnul("ab", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("ab", "xy", 1) == 0); - assert(libsimple_strncaseeqnul("xy", "ab", 1) == 0); - assert(libsimple_strncaseeqnul("", "1", 1) == 0); - assert(libsimple_strncaseeqnul("1", "", 1) == 0); - assert(libsimple_strncaseeqnul("", "", 1) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 1) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("", NULL, 1) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 1) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 1) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 1) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 1) == 1); - assert(libsimple_strncaseeqnul("abc", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 0) == 1); - assert(libsimple_strncaseeqnul("ab", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("ab", "xy", 0) == 1); - assert(libsimple_strncaseeqnul("xy", "ab", 0) == 1); - assert(libsimple_strncaseeqnul("", "1", 0) == 1); - assert(libsimple_strncaseeqnul("1", "", 0) == 1); - assert(libsimple_strncaseeqnul("", "", 0) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 0) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("", NULL, 0) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 0) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 0) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 0) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 0) == 1); - - assert(libsimple_strcmpnul(NULL, NULL) == 0); - assert(libsimple_strcmpnul(NULL, "") < 0); - assert(libsimple_strcmpnul("", NULL) > 0); - assert(libsimple_strcmpnul("", "") == 0); - assert(libsimple_strcmpnul(NULL, "x") < 0); - assert(libsimple_strcmpnul("x", NULL) > 0); - assert(libsimple_strcmpnul("x", "x") == 0); - assert(libsimple_strcmpnul("a", "b") < 0); - assert(libsimple_strcmpnul("b", "a") > 0); - assert(libsimple_strcmpnul("aa", "ab") < 0); - assert(libsimple_strcmpnul("ab", "aa") > 0); - assert(libsimple_strcmpnul("aa", "aa") == 0); - assert(libsimple_strcmpnul("A", "a") < 0); - assert(libsimple_strcmpnul("a", "A") > 0); - assert(libsimple_strcmpnul("AA", "Aa") < 0); - assert(libsimple_strcmpnul("Aa", "AA") > 0); - assert(libsimple_strcmpnul("AA", "AA") == 0); - - assert(libsimple_strcasecmpnul(NULL, NULL) == 0); - assert(libsimple_strcasecmpnul(NULL, "") < 0); - assert(libsimple_strcasecmpnul("", NULL) > 0); - assert(libsimple_strcasecmpnul("", "") == 0); - assert(libsimple_strcasecmpnul(NULL, "x") < 0); - assert(libsimple_strcasecmpnul("x", NULL) > 0); - assert(libsimple_strcasecmpnul("x", "x") == 0); - assert(libsimple_strcasecmpnul("a", "b") < 0); - assert(libsimple_strcasecmpnul("b", "a") > 0); - assert(libsimple_strcasecmpnul("aa", "ab") < 0); - assert(libsimple_strcasecmpnul("ab", "aa") > 0); - assert(libsimple_strcasecmpnul("aa", "aa") == 0); - assert(libsimple_strcasecmpnul("A", "a") == 0); - assert(libsimple_strcasecmpnul("a", "A") == 0); - assert(libsimple_strcasecmpnul("AA", "Aa") == 0); - assert(libsimple_strcasecmpnul("Aa", "AA") == 0); - assert(libsimple_strcasecmpnul("AA", "AA") == 0); - - assert(libsimple_strncmpnul(NULL, NULL, 5) == 0); - assert(libsimple_strncmpnul(NULL, "", 5) < 0); - assert(libsimple_strncmpnul("", NULL, 5) > 0); - assert(libsimple_strncmpnul("", "", 5) == 0); - assert(libsimple_strncmpnul(NULL, "x", 5) < 0); - assert(libsimple_strncmpnul("x", NULL, 5) > 0); - assert(libsimple_strncmpnul("x", "x", 5) == 0); - assert(libsimple_strncmpnul("a", "b", 5) < 0); - assert(libsimple_strncmpnul("b", "a", 5) > 0); - assert(libsimple_strncmpnul("aa", "ab", 5) < 0); - assert(libsimple_strncmpnul("ab", "aa", 5) > 0); - assert(libsimple_strncmpnul("aa", "aa", 5) == 0); - assert(libsimple_strncmpnul("A", "a", 5) < 0); - assert(libsimple_strncmpnul("a", "A", 5) > 0); - assert(libsimple_strncmpnul("AA", "Aa", 5) < 0); - assert(libsimple_strncmpnul("Aa", "AA", 5) > 0); - assert(libsimple_strncmpnul("AA", "AA", 5) == 0); - assert(libsimple_strncmpnul("aa", "ab", 1) == 0); - assert(libsimple_strncmpnul("ab", "aa", 1) == 0); - assert(libsimple_strncmpnul("aa", "aa", 1) == 0); - assert(libsimple_strncmpnul("AA", "Aa", 1) == 0); - assert(libsimple_strncmpnul("Aa", "AA", 1) == 0); - assert(libsimple_strncmpnul("AA", "AA", 1) == 0); - assert(libsimple_strncmpnul(NULL, NULL, 0) == 0); - assert(libsimple_strncmpnul(NULL, "", 0) < 0); - assert(libsimple_strncmpnul("", NULL, 0) > 0); - assert(libsimple_strncmpnul("", "", 0) == 0); - assert(libsimple_strncmpnul(NULL, "x", 0) < 0); - assert(libsimple_strncmpnul("x", NULL, 0) > 0); - assert(libsimple_strncmpnul("x", "x", 0) == 0); - assert(libsimple_strncmpnul("a", "b", 0) == 0); - assert(libsimple_strncmpnul("b", "a", 0) == 0); - assert(libsimple_strncmpnul("aa", "ab", 0) == 0); - assert(libsimple_strncmpnul("ab", "aa", 0) == 0); - assert(libsimple_strncmpnul("aa", "aa", 0) == 0); - assert(libsimple_strncmpnul("A", "a", 0) == 0); - assert(libsimple_strncmpnul("a", "A", 0) == 0); - assert(libsimple_strncmpnul("AA", "Aa", 0) == 0); - assert(libsimple_strncmpnul("Aa", "AA", 0) == 0); - assert(libsimple_strncmpnul("AA", "AA", 0) == 0); - - assert(libsimple_strncasecmpnul(NULL, NULL, 5) == 0); - assert(libsimple_strncasecmpnul(NULL, "", 5) < 0); - assert(libsimple_strncasecmpnul("", NULL, 5) > 0); - assert(libsimple_strncasecmpnul("", "", 5) == 0); - assert(libsimple_strncasecmpnul(NULL, "x", 5) < 0); - assert(libsimple_strncasecmpnul("x", NULL, 5) > 0); - assert(libsimple_strncasecmpnul("x", "x", 5) == 0); - assert(libsimple_strncasecmpnul("a", "b", 5) < 0); - assert(libsimple_strncasecmpnul("b", "a", 5) > 0); - assert(libsimple_strncasecmpnul("aa", "ab", 5) < 0); - assert(libsimple_strncasecmpnul("ab", "aa", 5) > 0); - assert(libsimple_strncasecmpnul("aa", "aa", 5) == 0); - assert(libsimple_strncasecmpnul("A", "a", 5) == 0); - assert(libsimple_strncasecmpnul("a", "A", 5) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 5) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 5) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 5) == 0); - assert(libsimple_strncasecmpnul("aa", "ab", 1) == 0); - assert(libsimple_strncasecmpnul("ab", "aa", 1) == 0); - assert(libsimple_strncasecmpnul("aa", "aa", 1) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 1) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 1) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 1) == 0); - assert(libsimple_strncasecmpnul(NULL, NULL, 0) == 0); - assert(libsimple_strncasecmpnul(NULL, "", 0) < 0); - assert(libsimple_strncasecmpnul("", NULL, 0) > 0); - assert(libsimple_strncasecmpnul("", "", 0) == 0); - assert(libsimple_strncasecmpnul(NULL, "x", 0) < 0); - assert(libsimple_strncasecmpnul("x", NULL, 0) > 0); - assert(libsimple_strncasecmpnul("x", "x", 0) == 0); - assert(libsimple_strncasecmpnul("a", "b", 0) == 0); - assert(libsimple_strncasecmpnul("b", "a", 0) == 0); - assert(libsimple_strncasecmpnul("aa", "ab", 0) == 0); - assert(libsimple_strncasecmpnul("ab", "aa", 0) == 0); - assert(libsimple_strncasecmpnul("aa", "aa", 0) == 0); - assert(libsimple_strncasecmpnul("A", "a", 0) == 0); - assert(libsimple_strncasecmpnul("a", "A", 0) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 0) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 0) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 0) == 0); - #ifdef libsimple_strdupa cs = ""; s = libsimple_strdupa(cs); @@ -1524,456 +1188,6 @@ main(void) fprintf(stderr, "warning: libsimple_vasprintfa missing\n"); #endif - { - char a[] = "abcdefgh", b[] = "abcdefgh"; - assert(libsimple_strreqlen("", "") == 0); - assert(libsimple_strreqlen("x", "") == 0); - assert(libsimple_strreqlen("x", "y") == 0); - assert(libsimple_strreqlen("", "y") == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - assert(libsimple_strreqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); - a[i] = b[j] = '\0'; - assert(libsimple_strreqlen(a, b) == (i == j ? i : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "abcdefgh"[j]; - } - } - assert(libsimple_strreqlen("abc", "ABC") == 0); - assert(libsimple_strreqlen("123", "123") == 3); - } - - { - char a[] = "abcdefgh", b[] = "ABCDEFGH"; - assert(libsimple_strrcaseeqlen("", "") == 0); - assert(libsimple_strrcaseeqlen("x", "") == 0); - assert(libsimple_strrcaseeqlen("x", "y") == 0); - assert(libsimple_strrcaseeqlen("", "y") == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - assert(libsimple_strrcaseeqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); - assert(libsimple_strrcaseeqlen(&b[i], &a[j]) == 8 - (i > j ? i : j)); - a[i] = b[j] = '\0'; - assert(libsimple_strrcaseeqlen(a, b) == (i == j ? i : 0)); - assert(libsimple_strrcaseeqlen(b, a) == (i == j ? i : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "ABCDEFGH"[j]; - } - } - assert(libsimple_strrcaseeqlen("abc", "abc") == 3); - assert(libsimple_strrcaseeqlen("123", "123") == 3); - } - - for (n = 0; n < 10; n++) { - char a[] = "abcdefgh", b[] = "abcdefgh"; - size_t I, J; - assert(libsimple_strrneqlen("", "", n) == 0); - assert(libsimple_strrneqlen("x", "", n) == 0); - assert(libsimple_strrneqlen("x", "y", n) == 0); - assert(libsimple_strrneqlen("", "y", n) == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - I = 8 - i; - J = 8 - j; - assert(libsimple_strrneqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - a[i] = b[j] = '\0'; - assert(libsimple_strrneqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "abcdefgh"[j]; - } - } - assert(libsimple_strrneqlen("abc", "ABC", n) == 0); - assert(libsimple_strrneqlen("123", "123", n) == MIN(3, n)); - } - - for (n = 0; n < 10; n++) { - char a[] = "abcdefgh", b[] = "ABCDEFGH"; - size_t I, J; - assert(libsimple_strrncaseeqlen("", "", n) == 0); - assert(libsimple_strrncaseeqlen("x", "", n) == 0); - assert(libsimple_strrncaseeqlen("x", "y", n) == 0); - assert(libsimple_strrncaseeqlen("", "y", n) == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - I = 8 - i; - J = 8 - j; - assert(libsimple_strrncaseeqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - assert(libsimple_strrncaseeqlen(&b[i], &a[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - a[i] = b[j] = '\0'; - assert(libsimple_strrncaseeqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - assert(libsimple_strrncaseeqlen(b, a, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "ABCDEFGH"[j]; - } - } - assert(libsimple_strrncaseeqlen("abc", "abc", n) == MIN(3, n)); - assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n)); - } - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strset(buf, 'x') == buf); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strset(buf, '\0') == buf); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpset(buf, 'x') == &buf[11]); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpset(buf, '\0') == &buf[11]); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, 'x', SIZE_MAX) == buf); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, '\0', SIZE_MAX) == buf); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, 'x', SIZE_MAX) == &buf[11]); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, '\0', SIZE_MAX) == &buf[11]); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, 'x', 5) == buf); - assert(!strcmp(buf, "xxxxx world")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, '\0', 5) == buf); - assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, 'x', 5) == &buf[5]); - assert(!strcmp(buf, "xxxxx world")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, '\0', 5) == &buf[5]); - assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strreplace(buf, 'o', 'x') == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', SIZE_MAX) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 12) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 11) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 6) == &buf[6]); - assert(!memcmp(buf, "hellx world\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 5) == &buf[5]); - assert(!memcmp(buf, "hellx world\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 4) == &buf[4]); - assert(!memcmp(buf, "hello world\0goodbye world", 26)); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(&buf[3], buf) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(buf, &buf[3]) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(buf, buf) == buf); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, SIZE_MAX) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], SIZE_MAX) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, SIZE_MAX) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 12) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 9) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 12) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 11) == &buf[3]); - assert(!strncmp(buf, "helhello worldx", 15)); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 8) == buf); - assert(!strcmp(buf, "lo worldrld")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 11) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 2) == &buf[3]); - assert(!strcmp(buf, "helhe world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 2) == buf); - assert(!strcmp(buf, "lollo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 2) == buf); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(&buf[3], buf) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(buf, &buf[3]) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(buf, buf) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, SIZE_MAX) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], SIZE_MAX) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, SIZE_MAX) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 12) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 9) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 12) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 11) == &buf[11 + 3]); - assert(!strncmp(buf, "helhello worldx", 15)); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 8) == &buf[8]); - assert(!strcmp(buf, "lo worldrld")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 11) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 2) == &buf[3 + 2]); - assert(!strcmp(buf, "helhe world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 2) == &buf[2]); - assert(!strcmp(buf, "lollo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 2) == &buf[2]); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", '\0') == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'o') == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'l') == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'x') == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 1024) == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 1024) == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 1024) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 1024) == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 6) == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 6) == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 6) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 6) == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 5) == NULL); - assert(!strncmp(buf, "hellox", 6)); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 5) == &buf[5]); - assert(!strncmp(buf, "hellox", 6)); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 5) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 5) == NULL); - assert(!strncmp(buf, "hellox", 6)); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 3) == NULL); - assert(!strncmp(buf, "helx", 4)); - if (!have_custom_malloc()) { stderr_real = 1; diff --git a/memisutf8.c b/memisutf8.c index c7ffbd8..b477ab8 100644 --- a/memisutf8.c +++ b/memisutf8.c @@ -91,10 +91,6 @@ main(void) assert(libsimple_memisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\ assert(libsimple_memisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\ assert(libsimple_memisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\ - assert(libsimple_strisutf8(STRING, i) == (GOOD));\ - assert(libsimple_strnisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\ - assert(libsimple_strnisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\ - assert(libsimple_strnisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\ } while (0) int i; diff --git a/stpmove.c b/stpmove.c index 5457c21..e691c23 100644 --- a/stpmove.c +++ b/stpmove.c @@ -12,6 +12,26 @@ extern inline char *libsimple_stpmove(char *, const char *); int main(void) { + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpmove(&buf[3], buf) == &buf[11 + 3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpmove(buf, &buf[3]) == &buf[11 - 3]); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpmove(buf, buf) == &buf[11]); + assert(!strcmp(buf, "hello world")); + return 0; } diff --git a/stpnmove.c b/stpnmove.c index 4f07cef..f96499e 100644 --- a/stpnmove.c +++ b/stpnmove.c @@ -12,6 +12,80 @@ extern inline char *libsimple_stpnmove(char *, const char *, size_t); int main(void) { + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(&buf[3], buf, SIZE_MAX) == &buf[11 + 3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, &buf[3], SIZE_MAX) == &buf[11 - 3]); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, buf, SIZE_MAX) == &buf[11]); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(&buf[3], buf, 12) == &buf[11 + 3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, &buf[3], 9) == &buf[11 - 3]); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, buf, 12) == &buf[11]); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(&buf[3], buf, 11) == &buf[11 + 3]); + assert(!strncmp(buf, "helhello worldx", 15)); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, &buf[3], 8) == &buf[8]); + assert(!strcmp(buf, "lo worldrld")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, buf, 11) == &buf[11]); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(&buf[3], buf, 2) == &buf[3 + 2]); + assert(!strcmp(buf, "helhe world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, &buf[3], 2) == &buf[2]); + assert(!strcmp(buf, "lollo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_stpnmove(buf, buf, 2) == &buf[2]); + assert(!strcmp(buf, "hello world")); + return 0; } diff --git a/stpnset.c b/stpnset.c index 59ce182..20da276 100644 --- a/stpnset.c +++ b/stpnset.c @@ -12,6 +12,27 @@ extern inline char *libsimple_stpnset(char *, int, size_t); int main(void) { + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpnset(buf, 'x', SIZE_MAX) == &buf[11]); + assert(!strcmp(buf, "xxxxxxxxxxx")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpnset(buf, '\0', SIZE_MAX) == &buf[11]); + assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); + + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpnset(buf, 'x', 5) == &buf[5]); + assert(!strcmp(buf, "xxxxx world")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpnset(buf, '\0', 5) == &buf[5]); + assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); + return 0; } diff --git a/stpntolower.c b/stpntolower.c index 90e38d0..de4e74e 100644 --- a/stpntolower.c +++ b/stpntolower.c @@ -47,15 +47,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345"); assert(!strcmpnul(libsimple_stpntolower(&buf[0], &buf[0], SIZE_MAX), "")); assert(!strcmp(buf, "abcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], SIZE_MAX), "abcdeabcde12345")); - assert(!strcmp(buf, "ABCabcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], SIZE_MAX), "deabcde12345")); - assert(!strcmp(buf, "deabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], SIZE_MAX), "abcdeabcde12345")); - assert(!strcmp(buf, "abcdeabcde12345")); memset(buf, 0, sizeof(buf)); stpcpy(buf, "ABCDEabcde12345"); @@ -70,19 +61,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345X"); assert(!strcmpnul(libsimple_stpntolower(&buf[0], &buf[0], 15), "X")); assert(!strcmp(buf, "abcdeabcde12345X")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - buf[18] = 'X'; - assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], 15), "abcdeabcde12345X")); - assert(!strcmp(buf, "ABCabcdeabcde12345X")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], 12), "deabcde12345345")); - assert(!strcmp(buf, "deabcde12345345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345X"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], 15), "abcdeabcde12345X")); - assert(!strcmp(buf, "abcdeabcde12345X")); memset(buf, 0, sizeof(buf)); stpcpy(buf, "ABCDEabcde12345"); @@ -96,18 +74,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345"); assert(!strcmpnul(libsimple_stpntolower(&buf[0], &buf[0], 0), "ABCDEabcde12345")); assert(!strcmp(buf, "ABCDEabcde12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], 0), "DEabcde12345")); - assert(!strcmp(buf, "ABCDEabcde12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], 0), "ABCDEabcde12345")); - assert(!strcmp(buf, "ABCDEabcde12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], 0), "ABCDEabcde12345")); - assert(!strcmp(buf, "ABCDEabcde12345")); return 0; } diff --git a/stpntoupper.c b/stpntoupper.c index 732a9d3..40552d7 100644 --- a/stpntoupper.c +++ b/stpntoupper.c @@ -47,15 +47,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345"); assert(!strcmpnul(libsimple_stpntoupper(&buf[0], &buf[0], SIZE_MAX), "")); assert(!strcmp(buf, "ABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], SIZE_MAX), "ABCDEABCDE12345")); - assert(!strcmp(buf, "abcABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], SIZE_MAX), "DEABCDE12345")); - assert(!strcmp(buf, "DEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], SIZE_MAX), "ABCDEABCDE12345")); - assert(!strcmp(buf, "ABCDEABCDE12345")); memset(buf, 0, sizeof(buf)); stpcpy(buf, "abcdeABCDE12345"); @@ -70,19 +61,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345x"); assert(!strcmpnul(libsimple_stpntoupper(&buf[0], &buf[0], 15), "x")); assert(!strcmp(buf, "ABCDEABCDE12345x")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - buf[18] = 'x'; - assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], 15), "ABCDEABCDE12345x")); - assert(!strcmp(buf, "abcABCDEABCDE12345x")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], 12), "DEABCDE12345345")); - assert(!strcmp(buf, "DEABCDE12345345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345x"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], 15), "ABCDEABCDE12345x")); - assert(!strcmp(buf, "ABCDEABCDE12345x")); memset(buf, 0, sizeof(buf)); stpcpy(buf, "abcdeABCDE12345"); @@ -96,18 +74,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345"); assert(!strcmpnul(libsimple_stpntoupper(&buf[0], &buf[0], 0), "abcdeABCDE12345")); assert(!strcmp(buf, "abcdeABCDE12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], 0), "deABCDE12345")); - assert(!strcmp(buf, "abcdeABCDE12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], 0), "abcdeABCDE12345")); - assert(!strcmp(buf, "abcdeABCDE12345")); - memset(buf, 0, sizeof(buf)); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], 0), "abcdeABCDE12345")); - assert(!strcmp(buf, "abcdeABCDE12345")); return 0; } diff --git a/stpset.c b/stpset.c index 4e5c134..08651fa 100644 --- a/stpset.c +++ b/stpset.c @@ -12,6 +12,17 @@ extern inline char *libsimple_stpset(char *, int); int main(void) { + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpset(buf, 'x') == &buf[11]); + assert(!strcmp(buf, "xxxxxxxxxxx")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_stpset(buf, '\0') == &buf[11]); + assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); + return 0; } diff --git a/stptolower.c b/stptolower.c index 7c21372..db63bf0 100644 --- a/stptolower.c +++ b/stptolower.c @@ -45,15 +45,6 @@ main(void) stpcpy(buf, "ABCDEabcde12345"); assert(!strcmpnul(libsimple_stptolower(&buf[0], &buf[0]), "")); assert(!strcmp(buf, "abcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strtolower(&buf[3], &buf[0]), "abcdeabcde12345")); - assert(!strcmp(buf, "ABCabcdeabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strtolower(&buf[0], &buf[3]), "deabcde12345")); - assert(!strcmp(buf, "deabcde12345")); - stpcpy(buf, "ABCDEabcde12345"); - assert(!strcmpnul(libsimple_strtolower(&buf[0], &buf[0]), "abcdeabcde12345")); - assert(!strcmp(buf, "abcdeabcde12345")); return 0; } diff --git a/stptoupper.c b/stptoupper.c index 3b5f008..cbfc184 100644 --- a/stptoupper.c +++ b/stptoupper.c @@ -45,15 +45,6 @@ main(void) stpcpy(buf, "abcdeABCDE12345"); assert(!strcmpnul(libsimple_stptoupper(&buf[0], &buf[0]), "")); assert(!strcmp(buf, "ABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strtoupper(&buf[3], &buf[0]), "ABCDEABCDE12345")); - assert(!strcmp(buf, "abcABCDEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strtoupper(&buf[0], &buf[3]), "DEABCDE12345")); - assert(!strcmp(buf, "DEABCDE12345")); - stpcpy(buf, "abcdeABCDE12345"); - assert(!strcmpnul(libsimple_strtoupper(&buf[0], &buf[0]), "ABCDEABCDE12345")); - assert(!strcmp(buf, "ABCDEABCDE12345")); return 0; } diff --git a/strcasecmpnul.c b/strcasecmpnul.c index b6a9b7a..e996e01 100644 --- a/strcasecmpnul.c +++ b/strcasecmpnul.c @@ -12,6 +12,23 @@ extern inline int libsimple_strcasecmpnul(const char *, const char *); int main(void) { + assert(libsimple_strcasecmpnul(NULL, NULL) == 0); + assert(libsimple_strcasecmpnul(NULL, "") < 0); + assert(libsimple_strcasecmpnul("", NULL) > 0); + assert(libsimple_strcasecmpnul("", "") == 0); + assert(libsimple_strcasecmpnul(NULL, "x") < 0); + assert(libsimple_strcasecmpnul("x", NULL) > 0); + assert(libsimple_strcasecmpnul("x", "x") == 0); + assert(libsimple_strcasecmpnul("a", "b") < 0); + assert(libsimple_strcasecmpnul("b", "a") > 0); + assert(libsimple_strcasecmpnul("aa", "ab") < 0); + assert(libsimple_strcasecmpnul("ab", "aa") > 0); + assert(libsimple_strcasecmpnul("aa", "aa") == 0); + assert(libsimple_strcasecmpnul("A", "a") == 0); + assert(libsimple_strcasecmpnul("a", "A") == 0); + assert(libsimple_strcasecmpnul("AA", "Aa") == 0); + assert(libsimple_strcasecmpnul("Aa", "AA") == 0); + assert(libsimple_strcasecmpnul("AA", "AA") == 0); return 0; } diff --git a/strcaseeq.c b/strcaseeq.c index 778c5b0..52e654c 100644 --- a/strcaseeq.c +++ b/strcaseeq.c @@ -12,6 +12,16 @@ extern inline int libsimple_strcaseeq(const char *, const char *); int main(void) { + assert(libsimple_strcaseeq("abc", "abc") == 1); + assert(libsimple_strcaseeq("abc", "ab") == 0); + assert(libsimple_strcaseeq("ab", "abc") == 0); + assert(libsimple_strcaseeq("ab", "xy") == 0); + assert(libsimple_strcaseeq("xy", "ab") == 0); + assert(libsimple_strcaseeq("", "1") == 0); + assert(libsimple_strcaseeq("1", "") == 0); + assert(libsimple_strcaseeq("", "") == 1); + assert(libsimple_strcaseeq("abc", "ABC") == 1); + assert(libsimple_strcaseeq("ABC", "abc") == 1); return 0; } diff --git a/strcaseeqnul.c b/strcaseeqnul.c index a40aaf7..bd900d6 100644 --- a/strcaseeqnul.c +++ b/strcaseeqnul.c @@ -12,6 +12,21 @@ extern inline int libsimple_strcaseeqnul(const char *, const char *); int main(void) { + assert(libsimple_strcaseeqnul("abc", "abc") == 1); + assert(libsimple_strcaseeqnul("abc", "ab") == 0); + assert(libsimple_strcaseeqnul("ab", "abc") == 0); + assert(libsimple_strcaseeqnul("ab", "xy") == 0); + assert(libsimple_strcaseeqnul("xy", "ab") == 0); + assert(libsimple_strcaseeqnul("", "1") == 0); + assert(libsimple_strcaseeqnul("1", "") == 0); + assert(libsimple_strcaseeqnul("", "") == 1); + assert(libsimple_strcaseeqnul("abc", "ABC") == 1); + assert(libsimple_strcaseeqnul("ABC", "abc") == 1); + assert(libsimple_strcaseeqnul("", NULL) == 0); + assert(libsimple_strcaseeqnul("1", NULL) == 0); + assert(libsimple_strcaseeqnul(NULL, "") == 0); + assert(libsimple_strcaseeqnul(NULL, "1") == 0); + assert(libsimple_strcaseeqnul(NULL, NULL) == 1); return 0; } diff --git a/strcasestarts.c b/strcasestarts.c index 7262f1e..df1fae3 100644 --- a/strcasestarts.c +++ b/strcasestarts.c @@ -3,7 +3,7 @@ #ifndef TEST -extern inline int libsimple_strcasestarts(const char *, const char *); +extern inline int libsimple_strcasestarts(const char *, const char *); /* TODO test */ #else diff --git a/strccpy.c b/strccpy.c index f4f7630..613ffbe 100644 --- a/strccpy.c +++ b/strccpy.c @@ -12,6 +12,28 @@ extern inline char *libsimple_strccpy(char *restrict, const char *restrict, int) int main(void) { + char buf[100]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strccpy(buf, "hello", '\0') == &buf[6]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strccpy(buf, "hello", 'o') == &buf[5]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strccpy(buf, "hello", 'l') == &buf[3]); + assert(!strcmp(buf, "hel")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strccpy(buf, "hello", 'x') == NULL); + assert(!strcmp(buf, "hello")); + return 0; } diff --git a/strcmpnul.c b/strcmpnul.c index 0a70610..d3d57fa 100644 --- a/strcmpnul.c +++ b/strcmpnul.c @@ -12,6 +12,23 @@ extern inline int libsimple_strcmpnul(const char *, const char *); int main(void) { + assert(libsimple_strcmpnul(NULL, NULL) == 0); + assert(libsimple_strcmpnul(NULL, "") < 0); + assert(libsimple_strcmpnul("", NULL) > 0); + assert(libsimple_strcmpnul("", "") == 0); + assert(libsimple_strcmpnul(NULL, "x") < 0); + assert(libsimple_strcmpnul("x", NULL) > 0); + assert(libsimple_strcmpnul("x", "x") == 0); + assert(libsimple_strcmpnul("a", "b") < 0); + assert(libsimple_strcmpnul("b", "a") > 0); + assert(libsimple_strcmpnul("aa", "ab") < 0); + assert(libsimple_strcmpnul("ab", "aa") > 0); + assert(libsimple_strcmpnul("aa", "aa") == 0); + assert(libsimple_strcmpnul("A", "a") < 0); + assert(libsimple_strcmpnul("a", "A") > 0); + assert(libsimple_strcmpnul("AA", "Aa") < 0); + assert(libsimple_strcmpnul("Aa", "AA") > 0); + assert(libsimple_strcmpnul("AA", "AA") == 0); return 0; } diff --git a/strend.c b/strend.c index 4754daf..ff5fa34 100644 --- a/strend.c +++ b/strend.c @@ -12,6 +12,7 @@ extern inline char *libsimple_strend(const char *); int main(void) { + assert(strcmpnul(libsimple_strend("abc\0xyz"), "xyz")); return 0; } diff --git a/streq.c b/streq.c index f54b8bb..2593238 100644 --- a/streq.c +++ b/streq.c @@ -12,6 +12,16 @@ extern inline int libsimple_streq(const char *, const char *); int main(void) { + assert(libsimple_streq("abc", "abc") == 1); + assert(libsimple_streq("abc", "ab") == 0); + assert(libsimple_streq("ab", "abc") == 0); + assert(libsimple_streq("ab", "xy") == 0); + assert(libsimple_streq("xy", "ab") == 0); + assert(libsimple_streq("", "1") == 0); + assert(libsimple_streq("1", "") == 0); + assert(libsimple_streq("", "") == 1); + assert(libsimple_streq("abc", "ABC") == 0); + assert(libsimple_streq("ABC", "abc") == 0); return 0; } diff --git a/streqnul.c b/streqnul.c index b557a9a..adee9f8 100644 --- a/streqnul.c +++ b/streqnul.c @@ -12,6 +12,21 @@ extern inline int libsimple_streqnul(const char *, const char *); int main(void) { + assert(libsimple_streqnul("abc", "abc") == 1); + assert(libsimple_streqnul("abc", "ab") == 0); + assert(libsimple_streqnul("ab", "abc") == 0); + assert(libsimple_streqnul("ab", "xy") == 0); + assert(libsimple_streqnul("xy", "ab") == 0); + assert(libsimple_streqnul("", "1") == 0); + assert(libsimple_streqnul("1", "") == 0); + assert(libsimple_streqnul("", "") == 1); + assert(libsimple_streqnul("abc", "ABC") == 0); + assert(libsimple_streqnul("ABC", "abc") == 0); + assert(libsimple_streqnul("", NULL) == 0); + assert(libsimple_streqnul("1", NULL) == 0); + assert(libsimple_streqnul(NULL, "") == 0); + assert(libsimple_streqnul(NULL, "1") == 0); + assert(libsimple_streqnul(NULL, NULL) == 1); return 0; } diff --git a/strisutf8.c b/strisutf8.c index ac0f4ca..c8244af 100644 --- a/strisutf8.c +++ b/strisutf8.c @@ -12,6 +12,62 @@ extern inline int libsimple_strisutf8(const char *, int); int main(void) { +#define ASSERT(STRING, GOOD)\ + assert(libsimple_strisutf8(STRING, i) == (GOOD)) + + int i; + for (i = 0; i < 2; i++) { + ASSERT("", 1); + ASSERT("a", 1); + ASSERT("abc", 1); + ASSERT("123", 1); + ASSERT("åäö", 1); + ASSERT("𝖆𝖇𝖈", 1); + ASSERT("\x1b", 1); + ASSERT("\n\r\t\f", 1); + ASSERT("\xFF", 0); + ASSERT("\x01", 1); + ASSERT("\x7F", 1); + ASSERT("\x80", 0); + ASSERT("\xC0", 0); + ASSERT("\xC0\x80", i); + ASSERT("\xC0\x81", 0); + ASSERT("\xCF", 0); + ASSERT("\xEF", 0); + ASSERT("\xEF\x8F", 0); + ASSERT("\xF7", 0); + ASSERT("\xF7\x8F", 0); + ASSERT("\xF7\x8F\x8F", 0); + ASSERT("\xFA", 0); + ASSERT("\xFA\x8F", 0); + ASSERT("\xFA\x8F\x8F", 0); + ASSERT("\xFA\x8F\x8F\x8F", 0); + ASSERT("\xFD", 0); + ASSERT("\xFD\x8F", 0); + ASSERT("\xFD\x8F\x8F", 0); + ASSERT("\xFD\x8F\x8F\x8F", 0); + ASSERT("\xFD\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFE", 0); + ASSERT("\xFE\x8F", 0); + ASSERT("\xFE\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF", 0); + ASSERT("\xFF\x8F", 0); + ASSERT("\xFF\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xC1\x80", 0); + ASSERT("\xC2\x80", 1); + ASSERT("\xE1\x80\x80\x80", 0); + ASSERT("\xE1\x80\xC0\x80", 0); + ASSERT("\xE1\x80\x00\x80", 0); + ASSERT("\xF1\x80\x80\x80", 1); + ASSERT("\xFF\x80\x80\x80\x80\x80\x80\x80", 0); + } return 0; } diff --git a/strmove.c b/strmove.c index bd1f89f..bdf3803 100644 --- a/strmove.c +++ b/strmove.c @@ -12,6 +12,26 @@ extern inline char *libsimple_strmove(char *, const char *); int main(void) { + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strmove(&buf[3], buf) == &buf[3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strmove(buf, &buf[3]) == buf); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strmove(buf, buf) == buf); + assert(!strcmp(buf, "hello world")); + return 0; } diff --git a/strncasecmpnul.c b/strncasecmpnul.c index e15bcfd..5df9e7d 100644 --- a/strncasecmpnul.c +++ b/strncasecmpnul.c @@ -12,6 +12,46 @@ extern inline int libsimple_strncasecmpnul(const char *, const char *, size_t); int main(void) { + assert(libsimple_strncasecmpnul(NULL, NULL, 5) == 0); + assert(libsimple_strncasecmpnul(NULL, "", 5) < 0); + assert(libsimple_strncasecmpnul("", NULL, 5) > 0); + assert(libsimple_strncasecmpnul("", "", 5) == 0); + assert(libsimple_strncasecmpnul(NULL, "x", 5) < 0); + assert(libsimple_strncasecmpnul("x", NULL, 5) > 0); + assert(libsimple_strncasecmpnul("x", "x", 5) == 0); + assert(libsimple_strncasecmpnul("a", "b", 5) < 0); + assert(libsimple_strncasecmpnul("b", "a", 5) > 0); + assert(libsimple_strncasecmpnul("aa", "ab", 5) < 0); + assert(libsimple_strncasecmpnul("ab", "aa", 5) > 0); + assert(libsimple_strncasecmpnul("aa", "aa", 5) == 0); + assert(libsimple_strncasecmpnul("A", "a", 5) == 0); + assert(libsimple_strncasecmpnul("a", "A", 5) == 0); + assert(libsimple_strncasecmpnul("AA", "Aa", 5) == 0); + assert(libsimple_strncasecmpnul("Aa", "AA", 5) == 0); + assert(libsimple_strncasecmpnul("AA", "AA", 5) == 0); + assert(libsimple_strncasecmpnul("aa", "ab", 1) == 0); + assert(libsimple_strncasecmpnul("ab", "aa", 1) == 0); + assert(libsimple_strncasecmpnul("aa", "aa", 1) == 0); + assert(libsimple_strncasecmpnul("AA", "Aa", 1) == 0); + assert(libsimple_strncasecmpnul("Aa", "AA", 1) == 0); + assert(libsimple_strncasecmpnul("AA", "AA", 1) == 0); + assert(libsimple_strncasecmpnul(NULL, NULL, 0) == 0); + assert(libsimple_strncasecmpnul(NULL, "", 0) < 0); + assert(libsimple_strncasecmpnul("", NULL, 0) > 0); + assert(libsimple_strncasecmpnul("", "", 0) == 0); + assert(libsimple_strncasecmpnul(NULL, "x", 0) < 0); + assert(libsimple_strncasecmpnul("x", NULL, 0) > 0); + assert(libsimple_strncasecmpnul("x", "x", 0) == 0); + assert(libsimple_strncasecmpnul("a", "b", 0) == 0); + assert(libsimple_strncasecmpnul("b", "a", 0) == 0); + assert(libsimple_strncasecmpnul("aa", "ab", 0) == 0); + assert(libsimple_strncasecmpnul("ab", "aa", 0) == 0); + assert(libsimple_strncasecmpnul("aa", "aa", 0) == 0); + assert(libsimple_strncasecmpnul("A", "a", 0) == 0); + assert(libsimple_strncasecmpnul("a", "A", 0) == 0); + assert(libsimple_strncasecmpnul("AA", "Aa", 0) == 0); + assert(libsimple_strncasecmpnul("Aa", "AA", 0) == 0); + assert(libsimple_strncasecmpnul("AA", "AA", 0) == 0); return 0; } diff --git a/strncaseeq.c b/strncaseeq.c index 4cec369..a0bfb02 100644 --- a/strncaseeq.c +++ b/strncaseeq.c @@ -12,6 +12,36 @@ extern inline int libsimple_strncaseeq(const char *, const char *, size_t); int main(void) { + assert(libsimple_strncaseeq("abc", "abc", 5) == 1); + assert(libsimple_strncaseeq("abc", "ab", 5) == 0); + assert(libsimple_strncaseeq("ab", "abc", 5) == 0); + assert(libsimple_strncaseeq("ab", "xy", 5) == 0); + assert(libsimple_strncaseeq("xy", "ab", 5) == 0); + assert(libsimple_strncaseeq("", "1", 5) == 0); + assert(libsimple_strncaseeq("1", "", 5) == 0); + assert(libsimple_strncaseeq("", "", 5) == 1); + assert(libsimple_strncaseeq("abc", "ABC", 5) == 1); + assert(libsimple_strncaseeq("ABC", "abc", 5) == 1); + assert(libsimple_strncaseeq("abc", "abc", 1) == 1); + assert(libsimple_strncaseeq("abc", "ab", 1) == 1); + assert(libsimple_strncaseeq("ab", "abc", 1) == 1); + assert(libsimple_strncaseeq("ab", "xy", 1) == 0); + assert(libsimple_strncaseeq("xy", "ab", 1) == 0); + assert(libsimple_strncaseeq("", "1", 1) == 0); + assert(libsimple_strncaseeq("1", "", 1) == 0); + assert(libsimple_strncaseeq("", "", 1) == 1); + assert(libsimple_strncaseeq("abc", "ABC", 1) == 1); + assert(libsimple_strncaseeq("ABC", "abc", 1) == 1); + assert(libsimple_strncaseeq("abc", "abc", 0) == 1); + assert(libsimple_strncaseeq("abc", "ab", 0) == 1); + assert(libsimple_strncaseeq("ab", "abc", 0) == 1); + assert(libsimple_strncaseeq("ab", "xy", 0) == 1); + assert(libsimple_strncaseeq("xy", "ab", 0) == 1); + assert(libsimple_strncaseeq("", "1", 0) == 1); + assert(libsimple_strncaseeq("1", "", 0) == 1); + assert(libsimple_strncaseeq("", "", 0) == 1); + assert(libsimple_strncaseeq("abc", "ABC", 0) == 1); + assert(libsimple_strncaseeq("ABC", "abc", 0) == 1); return 0; } diff --git a/strncaseeqnul.c b/strncaseeqnul.c index 6a4c42e..a8c5e01 100644 --- a/strncaseeqnul.c +++ b/strncaseeqnul.c @@ -12,6 +12,51 @@ extern inline int libsimple_strncaseeqnul(const char *, const char *, size_t); int main(void) { + assert(libsimple_strncaseeqnul("abc", "abc", 5) == 1); + assert(libsimple_strncaseeqnul("abc", "ab", 5) == 0); + assert(libsimple_strncaseeqnul("ab", "abc", 5) == 0); + assert(libsimple_strncaseeqnul("ab", "xy", 5) == 0); + assert(libsimple_strncaseeqnul("xy", "ab", 5) == 0); + assert(libsimple_strncaseeqnul("", "1", 5) == 0); + assert(libsimple_strncaseeqnul("1", "", 5) == 0); + assert(libsimple_strncaseeqnul("", "", 5) == 1); + assert(libsimple_strncaseeqnul("abc", "ABC", 5) == 1); + assert(libsimple_strncaseeqnul("ABC", "abc", 5) == 1); + assert(libsimple_strncaseeqnul("", NULL, 5) == 0); + assert(libsimple_strncaseeqnul("1", NULL, 5) == 0); + assert(libsimple_strncaseeqnul(NULL, "", 5) == 0); + assert(libsimple_strncaseeqnul(NULL, "1", 5) == 0); + assert(libsimple_strncaseeqnul(NULL, NULL, 5) == 1); + assert(libsimple_strncaseeqnul("abc", "abc", 1) == 1); + assert(libsimple_strncaseeqnul("abc", "ab", 1) == 1); + assert(libsimple_strncaseeqnul("ab", "abc", 1) == 1); + assert(libsimple_strncaseeqnul("ab", "xy", 1) == 0); + assert(libsimple_strncaseeqnul("xy", "ab", 1) == 0); + assert(libsimple_strncaseeqnul("", "1", 1) == 0); + assert(libsimple_strncaseeqnul("1", "", 1) == 0); + assert(libsimple_strncaseeqnul("", "", 1) == 1); + assert(libsimple_strncaseeqnul("abc", "ABC", 1) == 1); + assert(libsimple_strncaseeqnul("ABC", "abc", 1) == 1); + assert(libsimple_strncaseeqnul("", NULL, 1) == 0); + assert(libsimple_strncaseeqnul("1", NULL, 1) == 0); + assert(libsimple_strncaseeqnul(NULL, "", 1) == 0); + assert(libsimple_strncaseeqnul(NULL, "1", 1) == 0); + assert(libsimple_strncaseeqnul(NULL, NULL, 1) == 1); + assert(libsimple_strncaseeqnul("abc", "abc", 0) == 1); + assert(libsimple_strncaseeqnul("abc", "ab", 0) == 1); + assert(libsimple_strncaseeqnul("ab", "abc", 0) == 1); + assert(libsimple_strncaseeqnul("ab", "xy", 0) == 1); + assert(libsimple_strncaseeqnul("xy", "ab", 0) == 1); + assert(libsimple_strncaseeqnul("", "1", 0) == 1); + assert(libsimple_strncaseeqnul("1", "", 0) == 1); + assert(libsimple_strncaseeqnul("", "", 0) == 1); + assert(libsimple_strncaseeqnul("abc", "ABC", 0) == 1); + assert(libsimple_strncaseeqnul("ABC", "abc", 0) == 1); + assert(libsimple_strncaseeqnul("", NULL, 0) == 0); + assert(libsimple_strncaseeqnul("1", NULL, 0) == 0); + assert(libsimple_strncaseeqnul(NULL, "", 0) == 0); + assert(libsimple_strncaseeqnul(NULL, "1", 0) == 0); + assert(libsimple_strncaseeqnul(NULL, NULL, 0) == 1); return 0; } diff --git a/strnccpy.c b/strnccpy.c index 3d91c08..176c8a0 100644 --- a/strnccpy.c +++ b/strnccpy.c @@ -12,6 +12,76 @@ extern inline char *libsimple_strnccpy(char *restrict, const char *restrict, int int main(void) { + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", '\0', 1024) == &buf[6]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'o', 1024) == &buf[5]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'l', 1024) == &buf[3]); + assert(!strcmp(buf, "hel")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'x', 1024) == NULL); + assert(!strcmp(buf, "hello")); + + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", '\0', 6) == &buf[6]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'o', 6) == &buf[5]); + assert(!strcmp(buf, "hello")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'l', 6) == &buf[3]); + assert(!strcmp(buf, "hel")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'x', 6) == NULL); + assert(!strcmp(buf, "hello")); + + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", '\0', 5) == NULL); + assert(!strncmp(buf, "hellox", 6)); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'o', 5) == &buf[5]); + assert(!strncmp(buf, "hellox", 6)); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'l', 5) == &buf[3]); + assert(!strcmp(buf, "hel")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'x', 5) == NULL); + assert(!strncmp(buf, "hellox", 6)); + + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + assert(libsimple_strnccpy(buf, "hello", 'o', 3) == NULL); + assert(!strncmp(buf, "helx", 4)); + return 0; } diff --git a/strncmpnul.c b/strncmpnul.c index a5c9d7a..25fd49b 100644 --- a/strncmpnul.c +++ b/strncmpnul.c @@ -12,6 +12,46 @@ extern inline int libsimple_strncmpnul(const char *, const char *, size_t); int main(void) { + assert(libsimple_strncmpnul(NULL, NULL, 5) == 0); + assert(libsimple_strncmpnul(NULL, "", 5) < 0); + assert(libsimple_strncmpnul("", NULL, 5) > 0); + assert(libsimple_strncmpnul("", "", 5) == 0); + assert(libsimple_strncmpnul(NULL, "x", 5) < 0); + assert(libsimple_strncmpnul("x", NULL, 5) > 0); + assert(libsimple_strncmpnul("x", "x", 5) == 0); + assert(libsimple_strncmpnul("a", "b", 5) < 0); + assert(libsimple_strncmpnul("b", "a", 5) > 0); + assert(libsimple_strncmpnul("aa", "ab", 5) < 0); + assert(libsimple_strncmpnul("ab", "aa", 5) > 0); + assert(libsimple_strncmpnul("aa", "aa", 5) == 0); + assert(libsimple_strncmpnul("A", "a", 5) < 0); + assert(libsimple_strncmpnul("a", "A", 5) > 0); + assert(libsimple_strncmpnul("AA", "Aa", 5) < 0); + assert(libsimple_strncmpnul("Aa", "AA", 5) > 0); + assert(libsimple_strncmpnul("AA", "AA", 5) == 0); + assert(libsimple_strncmpnul("aa", "ab", 1) == 0); + assert(libsimple_strncmpnul("ab", "aa", 1) == 0); + assert(libsimple_strncmpnul("aa", "aa", 1) == 0); + assert(libsimple_strncmpnul("AA", "Aa", 1) == 0); + assert(libsimple_strncmpnul("Aa", "AA", 1) == 0); + assert(libsimple_strncmpnul("AA", "AA", 1) == 0); + assert(libsimple_strncmpnul(NULL, NULL, 0) == 0); + assert(libsimple_strncmpnul(NULL, "", 0) < 0); + assert(libsimple_strncmpnul("", NULL, 0) > 0); + assert(libsimple_strncmpnul("", "", 0) == 0); + assert(libsimple_strncmpnul(NULL, "x", 0) < 0); + assert(libsimple_strncmpnul("x", NULL, 0) > 0); + assert(libsimple_strncmpnul("x", "x", 0) == 0); + assert(libsimple_strncmpnul("a", "b", 0) == 0); + assert(libsimple_strncmpnul("b", "a", 0) == 0); + assert(libsimple_strncmpnul("aa", "ab", 0) == 0); + assert(libsimple_strncmpnul("ab", "aa", 0) == 0); + assert(libsimple_strncmpnul("aa", "aa", 0) == 0); + assert(libsimple_strncmpnul("A", "a", 0) == 0); + assert(libsimple_strncmpnul("a", "A", 0) == 0); + assert(libsimple_strncmpnul("AA", "Aa", 0) == 0); + assert(libsimple_strncmpnul("Aa", "AA", 0) == 0); + assert(libsimple_strncmpnul("AA", "AA", 0) == 0); return 0; } diff --git a/strneq.c b/strneq.c index 6946bef..f5ae440 100644 --- a/strneq.c +++ b/strneq.c @@ -12,6 +12,36 @@ extern inline int libsimple_strneq(const char *, const char *, size_t); int main(void) { + assert(libsimple_strneq("abc", "abc", 5) == 1); + assert(libsimple_strneq("abc", "ab", 5) == 0); + assert(libsimple_strneq("ab", "abc", 5) == 0); + assert(libsimple_strneq("ab", "xy", 5) == 0); + assert(libsimple_strneq("xy", "ab", 5) == 0); + assert(libsimple_strneq("", "1", 5) == 0); + assert(libsimple_strneq("1", "", 5) == 0); + assert(libsimple_strneq("", "", 5) == 1); + assert(libsimple_strneq("abc", "ABC", 5) == 0); + assert(libsimple_strneq("ABC", "abc", 5) == 0); + assert(libsimple_strneq("abc", "abc", 1) == 1); + assert(libsimple_strneq("abc", "ab", 1) == 1); + assert(libsimple_strneq("ab", "abc", 1) == 1); + assert(libsimple_strneq("ab", "xy", 1) == 0); + assert(libsimple_strneq("xy", "ab", 1) == 0); + assert(libsimple_strneq("", "1", 1) == 0); + assert(libsimple_strneq("1", "", 1) == 0); + assert(libsimple_strneq("", "", 1) == 1); + assert(libsimple_strneq("abc", "ABC", 1) == 0); + assert(libsimple_strneq("ABC", "abc", 1) == 0); + assert(libsimple_strneq("abc", "abc", 0) == 1); + assert(libsimple_strneq("abc", "ab", 0) == 1); + assert(libsimple_strneq("ab", "abc", 0) == 1); + assert(libsimple_strneq("ab", "xy", 0) == 1); + assert(libsimple_strneq("xy", "ab", 0) == 1); + assert(libsimple_strneq("", "1", 0) == 1); + assert(libsimple_strneq("1", "", 0) == 1); + assert(libsimple_strneq("", "", 0) == 1); + assert(libsimple_strneq("abc", "ABC", 0) == 1); + assert(libsimple_strneq("ABC", "abc", 0) == 1); return 0; } diff --git a/strneqnul.c b/strneqnul.c index b21fbe2..066d4e7 100644 --- a/strneqnul.c +++ b/strneqnul.c @@ -12,6 +12,51 @@ extern inline int libsimple_strneqnul(const char *, const char *, size_t); int main(void) { + assert(libsimple_strneqnul("abc", "abc", 5) == 1); + assert(libsimple_strneqnul("abc", "ab", 5) == 0); + assert(libsimple_strneqnul("ab", "abc", 5) == 0); + assert(libsimple_strneqnul("ab", "xy", 5) == 0); + assert(libsimple_strneqnul("xy", "ab", 5) == 0); + assert(libsimple_strneqnul("", "1", 5) == 0); + assert(libsimple_strneqnul("1", "", 5) == 0); + assert(libsimple_strneqnul("", "", 5) == 1); + assert(libsimple_strneqnul("abc", "ABC", 5) == 0); + assert(libsimple_strneqnul("ABC", "abc", 5) == 0); + assert(libsimple_strneqnul("", NULL, 5) == 0); + assert(libsimple_strneqnul("1", NULL, 5) == 0); + assert(libsimple_strneqnul(NULL, "", 5) == 0); + assert(libsimple_strneqnul(NULL, "1", 5) == 0); + assert(libsimple_strneqnul(NULL, NULL, 5) == 1); + assert(libsimple_strneqnul("abc", "abc", 1) == 1); + assert(libsimple_strneqnul("abc", "ab", 1) == 1); + assert(libsimple_strneqnul("ab", "abc", 1) == 1); + assert(libsimple_strneqnul("ab", "xy", 1) == 0); + assert(libsimple_strneqnul("xy", "ab", 1) == 0); + assert(libsimple_strneqnul("", "1", 1) == 0); + assert(libsimple_strneqnul("1", "", 1) == 0); + assert(libsimple_strneqnul("", "", 1) == 1); + assert(libsimple_strneqnul("abc", "ABC", 1) == 0); + assert(libsimple_strneqnul("ABC", "abc", 1) == 0); + assert(libsimple_strneqnul("", NULL, 1) == 0); + assert(libsimple_strneqnul("1", NULL, 1) == 0); + assert(libsimple_strneqnul(NULL, "", 1) == 0); + assert(libsimple_strneqnul(NULL, "1", 1) == 0); + assert(libsimple_strneqnul(NULL, NULL, 1) == 1); + assert(libsimple_strneqnul("abc", "abc", 0) == 1); + assert(libsimple_strneqnul("abc", "ab", 0) == 1); + assert(libsimple_strneqnul("ab", "abc", 0) == 1); + assert(libsimple_strneqnul("ab", "xy", 0) == 1); + assert(libsimple_strneqnul("xy", "ab", 0) == 1); + assert(libsimple_strneqnul("", "1", 0) == 1); + assert(libsimple_strneqnul("1", "", 0) == 1); + assert(libsimple_strneqnul("", "", 0) == 1); + assert(libsimple_strneqnul("abc", "ABC", 0) == 1); + assert(libsimple_strneqnul("ABC", "abc", 0) == 1); + assert(libsimple_strneqnul("", NULL, 0) == 0); + assert(libsimple_strneqnul("1", NULL, 0) == 0); + assert(libsimple_strneqnul(NULL, "", 0) == 0); + assert(libsimple_strneqnul(NULL, "1", 0) == 0); + assert(libsimple_strneqnul(NULL, NULL, 0) == 1); return 0; } diff --git a/strnisutf8.c b/strnisutf8.c index dc76fd5..8c775ee 100644 --- a/strnisutf8.c +++ b/strnisutf8.c @@ -12,6 +12,66 @@ extern inline int libsimple_strnisutf8(const char *, size_t, int); int main(void) { +#define ASSERT(STRING, GOOD)\ + do {\ + assert(libsimple_strnisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\ + assert(libsimple_strnisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\ + assert(libsimple_strnisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\ + } while (0) + + int i; + for (i = 0; i < 2; i++) { + ASSERT("", 1); + ASSERT("a", 1); + ASSERT("abc", 1); + ASSERT("123", 1); + ASSERT("åäö", 1); + ASSERT("𝖆𝖇𝖈", 1); + ASSERT("\x1b", 1); + ASSERT("\n\r\t\f", 1); + ASSERT("\xFF", 0); + ASSERT("\x01", 1); + ASSERT("\x7F", 1); + ASSERT("\x80", 0); + ASSERT("\xC0", 0); + ASSERT("\xC0\x80", i); + ASSERT("\xC0\x81", 0); + ASSERT("\xCF", 0); + ASSERT("\xEF", 0); + ASSERT("\xEF\x8F", 0); + ASSERT("\xF7", 0); + ASSERT("\xF7\x8F", 0); + ASSERT("\xF7\x8F\x8F", 0); + ASSERT("\xFA", 0); + ASSERT("\xFA\x8F", 0); + ASSERT("\xFA\x8F\x8F", 0); + ASSERT("\xFA\x8F\x8F\x8F", 0); + ASSERT("\xFD", 0); + ASSERT("\xFD\x8F", 0); + ASSERT("\xFD\x8F\x8F", 0); + ASSERT("\xFD\x8F\x8F\x8F", 0); + ASSERT("\xFD\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFE", 0); + ASSERT("\xFE\x8F", 0); + ASSERT("\xFE\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFE\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF", 0); + ASSERT("\xFF\x8F", 0); + ASSERT("\xFF\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xFF\x8F\x8F\x8F\x8F\x8F\x8F", 0); + ASSERT("\xC1\x80", 0); + ASSERT("\xC2\x80", 1); + ASSERT("\xE1\x80\x80\x80", 0); + ASSERT("\xE1\x80\xC0\x80", 0); + ASSERT("\xE1\x80\x00\x80", 0); + ASSERT("\xF1\x80\x80\x80", 1); + ASSERT("\xFF\x80\x80\x80\x80\x80\x80\x80", 0); + } return 0; } diff --git a/strnmove.c b/strnmove.c index d88c662..4bbcaa0 100644 --- a/strnmove.c +++ b/strnmove.c @@ -12,6 +12,80 @@ extern inline char *libsimple_strnmove(char *, const char *, size_t); int main(void) { + char buf[1024]; + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(&buf[3], buf, SIZE_MAX) == &buf[3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, &buf[3], SIZE_MAX) == buf); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, buf, SIZE_MAX) == buf); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(&buf[3], buf, 12) == &buf[3]); + assert(!strcmp(buf, "helhello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, &buf[3], 9) == buf); + assert(!strcmp(buf, "lo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, buf, 12) == buf); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(&buf[3], buf, 11) == &buf[3]); + assert(!strncmp(buf, "helhello worldx", 15)); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, &buf[3], 8) == buf); + assert(!strcmp(buf, "lo worldrld")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, buf, 11) == buf); + assert(!strcmp(buf, "hello world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(&buf[3], buf, 2) == &buf[3]); + assert(!strcmp(buf, "helhe world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, &buf[3], 2) == buf); + assert(!strcmp(buf, "lollo world")); + + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + strcpy(buf, "hello world"); + assert(libsimple_strnmove(buf, buf, 2) == buf); + assert(!strcmp(buf, "hello world")); + return 0; } diff --git a/strnreplace.c b/strnreplace.c index f8a2036..eb26ec9 100644 --- a/strnreplace.c +++ b/strnreplace.c @@ -12,6 +12,32 @@ extern inline char *libsimple_strnreplace(char *, int, int, size_t); int main(void) { + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', SIZE_MAX) == &buf[11]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 12) == &buf[11]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 11) == &buf[11]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 6) == &buf[6]); + assert(!memcmp(buf, "hellx world\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 5) == &buf[5]); + assert(!memcmp(buf, "hellx world\0goodbye world", 26)); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnreplace(buf, 'o', 'x', 4) == &buf[4]); + assert(!memcmp(buf, "hello world\0goodbye world", 26)); + return 0; } diff --git a/strnset.c b/strnset.c index 909222f..b2e1da4 100644 --- a/strnset.c +++ b/strnset.c @@ -12,6 +12,27 @@ extern inline char *libsimple_strnset(char *, int, size_t); int main(void) { + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnset(buf, 'x', SIZE_MAX) == buf); + assert(!strcmp(buf, "xxxxxxxxxxx")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnset(buf, '\0', SIZE_MAX) == buf); + assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); + + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnset(buf, 'x', 5) == buf); + assert(!strcmp(buf, "xxxxx world")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strnset(buf, '\0', 5) == buf); + assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); + return 0; } diff --git a/strntolower.c b/strntolower.c index 0dcad2a..33fdfa1 100644 --- a/strntolower.c +++ b/strntolower.c @@ -12,6 +12,45 @@ extern inline char *libsimple_strntolower(char *, const char *, size_t); int main(void) { + char buf[100]; + + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], SIZE_MAX), "abcdeabcde12345")); + assert(!strcmp(buf, "ABCabcdeabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], SIZE_MAX), "deabcde12345")); + assert(!strcmp(buf, "deabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], SIZE_MAX), "abcdeabcde12345")); + assert(!strcmp(buf, "abcdeabcde12345")); + + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + buf[18] = 'X'; + assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], 15), "abcdeabcde12345X")); + assert(!strcmp(buf, "ABCabcdeabcde12345X")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], 12), "deabcde12345345")); + assert(!strcmp(buf, "deabcde12345345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345X"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], 15), "abcdeabcde12345X")); + assert(!strcmp(buf, "abcdeabcde12345X")); + + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[3], &buf[0], 0), "DEabcde12345")); + assert(!strcmp(buf, "ABCDEabcde12345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[3], 0), "ABCDEabcde12345")); + assert(!strcmp(buf, "ABCDEabcde12345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strntolower(&buf[0], &buf[0], 0), "ABCDEabcde12345")); + assert(!strcmp(buf, "ABCDEabcde12345")); + return 0; } diff --git a/strntoupper.c b/strntoupper.c index 801a7f3..2959af8 100644 --- a/strntoupper.c +++ b/strntoupper.c @@ -12,6 +12,45 @@ extern inline char *libsimple_strntoupper(char *, const char *, size_t); int main(void) { + char buf[100]; + + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], SIZE_MAX), "ABCDEABCDE12345")); + assert(!strcmp(buf, "abcABCDEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], SIZE_MAX), "DEABCDE12345")); + assert(!strcmp(buf, "DEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], SIZE_MAX), "ABCDEABCDE12345")); + assert(!strcmp(buf, "ABCDEABCDE12345")); + + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + buf[18] = 'x'; + assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], 15), "ABCDEABCDE12345x")); + assert(!strcmp(buf, "abcABCDEABCDE12345x")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], 12), "DEABCDE12345345")); + assert(!strcmp(buf, "DEABCDE12345345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345x"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], 15), "ABCDEABCDE12345x")); + assert(!strcmp(buf, "ABCDEABCDE12345x")); + + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[3], &buf[0], 0), "deABCDE12345")); + assert(!strcmp(buf, "abcdeABCDE12345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[3], 0), "abcdeABCDE12345")); + assert(!strcmp(buf, "abcdeABCDE12345")); + memset(buf, 0, sizeof(buf)); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strntoupper(&buf[0], &buf[0], 0), "abcdeABCDE12345")); + assert(!strcmp(buf, "abcdeABCDE12345")); + return 0; } diff --git a/strrcaseeqlen.c b/strrcaseeqlen.c index d5176a1..351eaa6 100644 --- a/strrcaseeqlen.c +++ b/strrcaseeqlen.c @@ -12,6 +12,27 @@ extern inline size_t libsimple_strrcaseeqlen(const char *, const char *); int main(void) { + size_t i, j; + char a[] = "abcdefgh", b[] = "ABCDEFGH"; + + assert(libsimple_strrcaseeqlen("", "") == 0); + assert(libsimple_strrcaseeqlen("x", "") == 0); + assert(libsimple_strrcaseeqlen("x", "y") == 0); + assert(libsimple_strrcaseeqlen("", "y") == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + assert(libsimple_strrcaseeqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); + assert(libsimple_strrcaseeqlen(&b[i], &a[j]) == 8 - (i > j ? i : j)); + a[i] = b[j] = '\0'; + assert(libsimple_strrcaseeqlen(a, b) == (i == j ? i : 0)); + assert(libsimple_strrcaseeqlen(b, a) == (i == j ? i : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "ABCDEFGH"[j]; + } + } + assert(libsimple_strrcaseeqlen("abc", "abc") == 3); + assert(libsimple_strrcaseeqlen("123", "123") == 3); + return 0; } diff --git a/strreplace.c b/strreplace.c index f32da11..e427d7f 100644 --- a/strreplace.c +++ b/strreplace.c @@ -12,6 +12,12 @@ extern inline char *libsimple_strreplace(char *, int, int); int main(void) { + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strreplace(buf, 'o', 'x') == &buf[11]); + assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); + return 0; } diff --git a/strreqlen.c b/strreqlen.c index 29f85fc..5c7cece 100644 --- a/strreqlen.c +++ b/strreqlen.c @@ -12,6 +12,25 @@ extern inline size_t libsimple_strreqlen(const char *, const char *); int main(void) { + size_t i, j; + char a[] = "abcdefgh", b[] = "abcdefgh"; + + assert(libsimple_strreqlen("", "") == 0); + assert(libsimple_strreqlen("x", "") == 0); + assert(libsimple_strreqlen("x", "y") == 0); + assert(libsimple_strreqlen("", "y") == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + assert(libsimple_strreqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); + a[i] = b[j] = '\0'; + assert(libsimple_strreqlen(a, b) == (i == j ? i : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "abcdefgh"[j]; + } + } + assert(libsimple_strreqlen("abc", "ABC") == 0); + assert(libsimple_strreqlen("123", "123") == 3); + return 0; } diff --git a/strrncaseeqlen.c b/strrncaseeqlen.c index 5963afc..d904577 100644 --- a/strrncaseeqlen.c +++ b/strrncaseeqlen.c @@ -12,6 +12,32 @@ extern inline size_t libsimple_strrncaseeqlen(const char *, const char *, size_t int main(void) { + size_t i, j, n; + + for (n = 0; n < 10; n++) { + char a[] = "abcdefgh", b[] = "ABCDEFGH"; + size_t I, J; + assert(libsimple_strrncaseeqlen("", "", n) == 0); + assert(libsimple_strrncaseeqlen("x", "", n) == 0); + assert(libsimple_strrncaseeqlen("x", "y", n) == 0); + assert(libsimple_strrncaseeqlen("", "y", n) == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + I = 8 - i; + J = 8 - j; + assert(libsimple_strrncaseeqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + assert(libsimple_strrncaseeqlen(&b[i], &a[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + a[i] = b[j] = '\0'; + assert(libsimple_strrncaseeqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + assert(libsimple_strrncaseeqlen(b, a, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "ABCDEFGH"[j]; + } + } + assert(libsimple_strrncaseeqlen("abc", "abc", n) == MIN(3, n)); + assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n)); + } + return 0; } diff --git a/strrneqlen.c b/strrneqlen.c index b5f56b4..f76cac8 100644 --- a/strrneqlen.c +++ b/strrneqlen.c @@ -12,6 +12,30 @@ extern inline size_t libsimple_strrneqlen(const char *, const char *, size_t); int main(void) { + size_t i, j, n; + + for (n = 0; n < 10; n++) { + char a[] = "abcdefgh", b[] = "abcdefgh"; + size_t I, J; + assert(libsimple_strrneqlen("", "", n) == 0); + assert(libsimple_strrneqlen("x", "", n) == 0); + assert(libsimple_strrneqlen("x", "y", n) == 0); + assert(libsimple_strrneqlen("", "y", n) == 0); + for (i = 0; i <= 8; i++) { + for (j = 0; j <= 8; j++) { + I = 8 - i; + J = 8 - j; + assert(libsimple_strrneqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); + a[i] = b[j] = '\0'; + assert(libsimple_strrneqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); + a[i] = "abcdefgh"[i]; + b[j] = "abcdefgh"[j]; + } + } + assert(libsimple_strrneqlen("abc", "ABC", n) == 0); + assert(libsimple_strrneqlen("123", "123", n) == MIN(3, n)); + } + return 0; } diff --git a/strset.c b/strset.c index 2c62c0d..8d92f31 100644 --- a/strset.c +++ b/strset.c @@ -12,6 +12,17 @@ extern inline char *libsimple_strset(char *, int); int main(void) { + char buf[100]; + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strset(buf, 'x') == buf); + assert(!strcmp(buf, "xxxxxxxxxxx")); + assert(!strcmp(&buf[12], "goodbye world")); + + stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); + assert(libsimple_strset(buf, '\0') == buf); + assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); + return 0; } diff --git a/strtolower.c b/strtolower.c index 34006d7..7f72eb0 100644 --- a/strtolower.c +++ b/strtolower.c @@ -12,6 +12,18 @@ extern inline char *libsimple_strtolower(char *, const char *); int main(void) { + char buf[100]; + + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strtolower(&buf[3], &buf[0]), "abcdeabcde12345")); + assert(!strcmp(buf, "ABCabcdeabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strtolower(&buf[0], &buf[3]), "deabcde12345")); + assert(!strcmp(buf, "deabcde12345")); + stpcpy(buf, "ABCDEabcde12345"); + assert(!strcmpnul(libsimple_strtolower(&buf[0], &buf[0]), "abcdeabcde12345")); + assert(!strcmp(buf, "abcdeabcde12345")); + return 0; } diff --git a/strtoupper.c b/strtoupper.c index ce7c147..d22da79 100644 --- a/strtoupper.c +++ b/strtoupper.c @@ -12,6 +12,18 @@ extern inline char *libsimple_strtoupper(char *, const char *); int main(void) { + char buf[100]; + + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strtoupper(&buf[3], &buf[0]), "ABCDEABCDE12345")); + assert(!strcmp(buf, "abcABCDEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strtoupper(&buf[0], &buf[3]), "DEABCDE12345")); + assert(!strcmp(buf, "DEABCDE12345")); + stpcpy(buf, "abcdeABCDE12345"); + assert(!strcmpnul(libsimple_strtoupper(&buf[0], &buf[0]), "ABCDEABCDE12345")); + assert(!strcmp(buf, "ABCDEABCDE12345")); + return 0; } diff --git a/valigned_allocn.c b/valigned_allocn.c index 0fa84ac..a3625b8 100644 --- a/valigned_allocn.c +++ b/valigned_allocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_valigned_allocn(size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_aligned_allocn */ } #endif diff --git a/valigned_reallocfn.c b/valigned_reallocfn.c index 3c116b4..f74b07d 100644 --- a/valigned_reallocfn.c +++ b/valigned_reallocfn.c @@ -3,7 +3,7 @@ #ifndef TEST -extern inline void *libsimple_valigned_reallocfn(void *, size_t, size_t, va_list); /* TODO test (aligned_reallocfn) */ +extern inline void *libsimple_valigned_reallocfn(void *, size_t, size_t, va_list); #else @@ -12,7 +12,7 @@ extern inline void *libsimple_valigned_reallocfn(void *, size_t, size_t, va_list int main(void) { - return 0; + return 0; /* Tested via libsimple_aligned_reallocfn */ } #endif diff --git a/vcallocn.c b/vcallocn.c index 7007739..ab3850c 100644 --- a/vcallocn.c +++ b/vcallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_vcallocn(size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_callocn */ } #endif diff --git a/vmallocn.c b/vmallocn.c index ab3a340..1cdb61b 100644 --- a/vmallocn.c +++ b/vmallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_vmallocn(size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_mallocn */ } #endif diff --git a/vmemalignn.c b/vmemalignn.c index f0eae81..1c75088 100644 --- a/vmemalignn.c +++ b/vmemalignn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_vmemalignn(size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_memalignn */ } #endif diff --git a/vmemalignzn.c b/vmemalignzn.c index 8ae1831..46cfc25 100644 --- a/vmemalignzn.c +++ b/vmemalignzn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_vmemalignzn(int, size_t, size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_memalignzn */ } #endif diff --git a/vvallocn.c b/vvallocn.c index 84c0ef7..04b8d55 100644 --- a/vvallocn.c +++ b/vvallocn.c @@ -12,7 +12,7 @@ extern inline void *libsimple_vvallocn(size_t, va_list); int main(void) { - return 0; + return 0; /* Tested via libsimple_vallocn */ } #endif -- cgit v1.2.3-70-g09d2