diff options
author | Mattias Andrée <maandree@kth.se> | 2022-06-12 20:13:23 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-06-12 20:13:23 +0200 |
commit | 3d6482b0949159c33d6ac2972a69868bdda766f2 (patch) | |
tree | 722cf9ab069d75af63664eeae0c35c63aa73c51c | |
parent | Fix warnings (diff) | |
download | libsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.gz libsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.bz2 libsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.xz |
Move some test code to newline created .c files
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | envaligned_allocn.c | 2 | ||||
-rw-r--r-- | envcallocn.c | 2 | ||||
-rw-r--r-- | envmallocn.c | 2 | ||||
-rw-r--r-- | envmemalignn.c | 2 | ||||
-rw-r--r-- | envmemalignzn.c | 2 | ||||
-rw-r--r-- | envvallocn.c | 2 | ||||
-rw-r--r-- | evaligned_allocn.c | 2 | ||||
-rw-r--r-- | evaligned_alloczn.c | 2 | ||||
-rw-r--r-- | evaligned_reallocn.c | 2 | ||||
-rw-r--r-- | evcallocn.c | 2 | ||||
-rw-r--r-- | evmallocn.c | 2 | ||||
-rw-r--r-- | evmalloczn.c | 2 | ||||
-rw-r--r-- | evmemalignn.c | 2 | ||||
-rw-r--r-- | evmemalignzn.c | 2 | ||||
-rw-r--r-- | evvallocn.c | 2 | ||||
-rw-r--r-- | inchrcaseset.c | 2 | ||||
-rw-r--r-- | inchrset.c | 7 | ||||
-rw-r--r-- | libsimple.c | 790 | ||||
-rw-r--r-- | memisutf8.c | 4 | ||||
-rw-r--r-- | stpmove.c | 20 | ||||
-rw-r--r-- | stpnmove.c | 74 | ||||
-rw-r--r-- | stpnset.c | 21 | ||||
-rw-r--r-- | stpntolower.c | 34 | ||||
-rw-r--r-- | stpntoupper.c | 34 | ||||
-rw-r--r-- | stpset.c | 11 | ||||
-rw-r--r-- | stptolower.c | 9 | ||||
-rw-r--r-- | stptoupper.c | 9 | ||||
-rw-r--r-- | strcasecmpnul.c | 17 | ||||
-rw-r--r-- | strcaseeq.c | 10 | ||||
-rw-r--r-- | strcaseeqnul.c | 15 | ||||
-rw-r--r-- | strcasestarts.c | 2 | ||||
-rw-r--r-- | strccpy.c | 22 | ||||
-rw-r--r-- | strcmpnul.c | 17 | ||||
-rw-r--r-- | strend.c | 1 | ||||
-rw-r--r-- | streq.c | 10 | ||||
-rw-r--r-- | streqnul.c | 15 | ||||
-rw-r--r-- | strisutf8.c | 56 | ||||
-rw-r--r-- | strmove.c | 20 | ||||
-rw-r--r-- | strncasecmpnul.c | 40 | ||||
-rw-r--r-- | strncaseeq.c | 30 | ||||
-rw-r--r-- | strncaseeqnul.c | 45 | ||||
-rw-r--r-- | strnccpy.c | 70 | ||||
-rw-r--r-- | strncmpnul.c | 40 | ||||
-rw-r--r-- | strneq.c | 30 | ||||
-rw-r--r-- | strneqnul.c | 45 | ||||
-rw-r--r-- | strnisutf8.c | 60 | ||||
-rw-r--r-- | strnmove.c | 74 | ||||
-rw-r--r-- | strnreplace.c | 26 | ||||
-rw-r--r-- | strnset.c | 21 | ||||
-rw-r--r-- | strntolower.c | 39 | ||||
-rw-r--r-- | strntoupper.c | 39 | ||||
-rw-r--r-- | strrcaseeqlen.c | 21 | ||||
-rw-r--r-- | strreplace.c | 6 | ||||
-rw-r--r-- | strreqlen.c | 19 | ||||
-rw-r--r-- | strrncaseeqlen.c | 26 | ||||
-rw-r--r-- | strrneqlen.c | 24 | ||||
-rw-r--r-- | strset.c | 11 | ||||
-rw-r--r-- | strtolower.c | 12 | ||||
-rw-r--r-- | strtoupper.c | 12 | ||||
-rw-r--r-- | valigned_allocn.c | 2 | ||||
-rw-r--r-- | valigned_reallocfn.c | 4 | ||||
-rw-r--r-- | vcallocn.c | 2 | ||||
-rw-r--r-- | vmallocn.c | 2 | ||||
-rw-r--r-- | vmemalignn.c | 2 | ||||
-rw-r--r-- | vmemalignzn.c | 2 | ||||
-rw-r--r-- | vvallocn.c | 2 |
66 files changed, 1033 insertions, 903 deletions
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 @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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 @@ -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; } @@ -12,6 +12,7 @@ extern inline char *libsimple_strend(const char *); int main(void) { + assert(strcmpnul(libsimple_strend("abc\0xyz"), "xyz")); return 0; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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 @@ -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 @@ -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 @@ -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 |