diff options
author | Mattias Andrée <maandree@kth.se> | 2018-08-26 21:11:33 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-08-26 21:11:33 +0200 |
commit | bfcf92f37e96808539a319ce0b79ef194bf0de31 (patch) | |
tree | a5c18b92ecbe68464cdbdb94784e2b4465d4d66c | |
parent | Fixes and tests (diff) | |
download | libsimple-bfcf92f37e96808539a319ce0b79ef194bf0de31.tar.gz libsimple-bfcf92f37e96808539a319ce0b79ef194bf0de31.tar.bz2 libsimple-bfcf92f37e96808539a319ce0b79ef194bf0de31.tar.xz |
Add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | libsimple.h | 8 | ||||
-rw-r--r-- | strncasestr.c | 64 | ||||
-rw-r--r-- | strnstr.c | 64 | ||||
-rw-r--r-- | strrncasestr.c | 64 | ||||
-rw-r--r-- | strrnstr.c | 64 |
6 files changed, 264 insertions, 4 deletions
@@ -80,8 +80,12 @@ TESTS =\ strcaseends.test\ strcasestr.test\ strends.test\ + strncasestr.test\ strndup.test\ + strnstr.test\ strrcasestr.test\ + strrncasestr.test\ + strrnstr.test\ strrstr.test\ strstarts.test\ sumtimespec.test\ diff --git a/libsimple.h b/libsimple.h index 4e21e68..dd30563 100644 --- a/libsimple.h +++ b/libsimple.h @@ -710,28 +710,28 @@ char *libsimple_strrstr(const char *, const char *); _LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -char *libsimple_strrnstr(const char *, const char *, size_t); /* TODO test */ +char *libsimple_strrnstr(const char *, const char *, size_t); #ifndef strrnstr # define strrnstr libsimple_strrnstr #endif _LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -char *libsimple_strnstr(const char *, const char *, size_t); /* TODO test */ +char *libsimple_strnstr(const char *, const char *, size_t); #ifndef strnstr # define strnstr libsimple_strnstr #endif _LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -char *libsimple_strrncasestr(const char *, const char *, size_t); /* TODO test */ +char *libsimple_strrncasestr(const char *, const char *, size_t); #ifndef strrncasestr # define strrncasestr libsimple_strrncasestr #endif _LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__))) -char *libsimple_strncasestr(const char *, const char *, size_t); /* TODO test */ +char *libsimple_strncasestr(const char *, const char *, size_t); #ifndef strncasestr # define strncasestr libsimple_strncasestr #endif diff --git a/strncasestr.c b/strncasestr.c index cd7fd8a..08adaf2 100644 --- a/strncasestr.c +++ b/strncasestr.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "libsimple.h" +#ifndef TEST char * @@ -15,3 +16,66 @@ libsimple_strncasestr(const char *h_, const char *n, size_t len) return h; return NULL; } + + +#else +#include "test.h" + +int +main(void) +{ + assert(!strcmpnul(libsimple_strncasestr("", "", 10), "")); + assert(!strcmpnul(libsimple_strncasestr("test", "", 10), "test")); + assert(!libsimple_strncasestr("", "test", 10)); + assert(!libsimple_strncasestr("t", "test", 10)); + assert(!strcmpnul(libsimple_strncasestr("test", "t", 10), "test")); + assert(!strcmpnul(libsimple_strncasestr("test", "e", 10), "est")); + assert(!strcmpnul(libsimple_strncasestr("test", "s", 10), "st")); + assert(!libsimple_strncasestr("test", "x", 10)); + assert(!strcmpnul(libsimple_strncasestr("test", "te", 10), "test")); + assert(!strcmpnul(libsimple_strncasestr("test", "es", 10), "est")); + assert(!strcmpnul(libsimple_strncasestr("test", "st", 10), "st")); + assert(!libsimple_strncasestr("test", "xx", 10)); + assert(!strcmpnul(libsimple_strncasestr("abc", "c", 10), "c")); + assert(!strcmpnul(libsimple_strncasestr("abc", "bc", 10), "bc")); + assert(!strcmpnul(libsimple_strncasestr("abc", "abc", 10), "abc")); + assert(!strcmpnul(libsimple_strncasestr("abcabc", "bc", 10), "bcabc")); + + assert(!strcmpnul(libsimple_strncasestr("TEST", "", 10), "TEST")); + assert(!libsimple_strncasestr("T", "test", 10)); + assert(!strcmpnul(libsimple_strncasestr("TEST", "t", 10), "TEST")); + assert(!strcmpnul(libsimple_strncasestr("TEST", "e", 10), "EST")); + assert(!strcmpnul(libsimple_strncasestr("TEST", "s", 10), "ST")); + assert(!libsimple_strncasestr("TEST", "x", 10)); + assert(!strcmpnul(libsimple_strncasestr("TEST", "te", 10), "TEST")); + assert(!strcmpnul(libsimple_strncasestr("TEST", "es", 10), "EST")); + assert(!strcmpnul(libsimple_strncasestr("TEST", "st", 10), "ST")); + assert(!libsimple_strncasestr("TEST", "xx", 10)); + assert(!strcmpnul(libsimple_strncasestr("ABC", "c", 10), "C")); + assert(!strcmpnul(libsimple_strncasestr("ABC", "bc", 10), "BC")); + assert(!strcmpnul(libsimple_strncasestr("ABC", "abc", 10), "ABC")); + assert(!strcmpnul(libsimple_strncasestr("ABCABC", "bc", 10), "BCABC")); + + assert(!libsimple_strncasestr("", "TEST", 10)); + assert(!libsimple_strncasestr("t", "TEST", 10)); + assert(!strcmpnul(libsimple_strncasestr("test", "T", 10), "test")); + assert(!strcmpnul(libsimple_strncasestr("test", "E", 10), "est")); + assert(!strcmpnul(libsimple_strncasestr("test", "S", 10), "st")); + assert(!libsimple_strncasestr("test", "X", 10)); + assert(!strcmpnul(libsimple_strncasestr("test", "TE", 10), "test")); + assert(!strcmpnul(libsimple_strncasestr("test", "ES", 10), "est")); + assert(!strcmpnul(libsimple_strncasestr("test", "ST", 10), "st")); + assert(!libsimple_strncasestr("test", "XX", 10)); + assert(!strcmpnul(libsimple_strncasestr("abc", "C", 10), "c")); + assert(!strcmpnul(libsimple_strncasestr("abc", "BC", 10), "bc")); + assert(!strcmpnul(libsimple_strncasestr("abc", "ABC", 10), "abc")); + assert(!strcmpnul(libsimple_strncasestr("abcabc", "BC", 10), "bcabc")); + + assert(!libsimple_strncasestr("abcdefgh", "def", 2)); + assert(!libsimple_strncasestr("abcdefgh", "DEF", 2)); + assert(!libsimple_strncasestr("ABCDEFGH", "def", 2)); + + return 0; +} + +#endif @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "libsimple.h" +#ifndef TEST char * @@ -15,3 +16,66 @@ libsimple_strnstr(const char *h_, const char *n, size_t len) return h; return NULL; } + + +#else +#include "test.h" + +int +main(void) +{ + assert(!strcmpnul(libsimple_strnstr("", "", 10), "")); + assert(!strcmpnul(libsimple_strnstr("test", "", 10), "test")); + assert(!libsimple_strnstr("", "test", 10)); + assert(!libsimple_strnstr("t", "test", 10)); + assert(!strcmpnul(libsimple_strnstr("test", "t", 10), "test")); + assert(!strcmpnul(libsimple_strnstr("test", "e", 10), "est")); + assert(!strcmpnul(libsimple_strnstr("test", "s", 10), "st")); + assert(!libsimple_strnstr("test", "x", 10)); + assert(!strcmpnul(libsimple_strnstr("test", "te", 10), "test")); + assert(!strcmpnul(libsimple_strnstr("test", "es", 10), "est")); + assert(!strcmpnul(libsimple_strnstr("test", "st", 10), "st")); + assert(!libsimple_strnstr("test", "xx", 10)); + assert(!strcmpnul(libsimple_strnstr("abc", "c", 10), "c")); + assert(!strcmpnul(libsimple_strnstr("abc", "bc", 10), "bc")); + assert(!strcmpnul(libsimple_strnstr("abc", "abc", 10), "abc")); + assert(!strcmpnul(libsimple_strnstr("abcabc", "bc", 10), "bcabc")); + + assert(!strcmpnul(libsimple_strnstr("TEST", "", 10), "TEST")); + assert(!libsimple_strnstr("T", "test", 10)); + assert(!libsimple_strnstr("TEST", "t", 10)); + assert(!libsimple_strnstr("TEST", "e", 10)); + assert(!libsimple_strnstr("TEST", "s", 10)); + assert(!libsimple_strnstr("TEST", "x", 10)); + assert(!libsimple_strnstr("TEST", "te", 10)); + assert(!libsimple_strnstr("TEST", "es", 10)); + assert(!libsimple_strnstr("TEST", "st", 10)); + assert(!libsimple_strnstr("TEST", "xx", 10)); + assert(!libsimple_strnstr("ABC", "c", 10)); + assert(!libsimple_strnstr("ABC", "bc", 10)); + assert(!libsimple_strnstr("ABC", "abc", 10)); + assert(!libsimple_strnstr("ABCABC", "bc", 10)); + + assert(!libsimple_strnstr("", "TEST", 10)); + assert(!libsimple_strnstr("t", "TEST", 10)); + assert(!libsimple_strnstr("test", "T", 10)); + assert(!libsimple_strnstr("test", "E", 10)); + assert(!libsimple_strnstr("test", "S", 10)); + assert(!libsimple_strnstr("test", "X", 10)); + assert(!libsimple_strnstr("test", "TE", 10)); + assert(!libsimple_strnstr("test", "ES", 10)); + assert(!libsimple_strnstr("test", "ST", 10)); + assert(!libsimple_strnstr("test", "XX", 10)); + assert(!libsimple_strnstr("abc", "C", 10)); + assert(!libsimple_strnstr("abc", "BC", 10)); + assert(!libsimple_strnstr("abc", "ABC", 10)); + assert(!libsimple_strnstr("abcabc", "BC", 10)); + + assert(!libsimple_strncasestr("abcdefgh", "def", 2)); + assert(!libsimple_strncasestr("abcdefgh", "DEF", 2)); + assert(!libsimple_strncasestr("ABCDEFGH", "def", 2)); + + return 0; +} + +#endif diff --git a/strrncasestr.c b/strrncasestr.c index 8fb0778..f1874c7 100644 --- a/strrncasestr.c +++ b/strrncasestr.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "libsimple.h" +#ifndef TEST char * @@ -21,3 +22,66 @@ libsimple_strrncasestr(const char *h_, const char *n, size_t len) return h; return NULL; } + + +#else +#include "test.h" + +int +main(void) +{ + assert(!strcmpnul(libsimple_strrncasestr("", "", 10), "")); + assert(!strcmpnul(libsimple_strrncasestr("test", "", 10), "")); + assert(!libsimple_strrncasestr("", "test", 10)); + assert(!libsimple_strrncasestr("t", "test", 10)); + assert(!strcmpnul(libsimple_strrncasestr("test", "t", 10), "t")); + assert(!strcmpnul(libsimple_strrncasestr("test", "e", 10), "est")); + assert(!strcmpnul(libsimple_strrncasestr("test", "s", 10), "st")); + assert(!libsimple_strrncasestr("test", "x", 10)); + assert(!strcmpnul(libsimple_strrncasestr("test", "te", 10), "test")); + assert(!strcmpnul(libsimple_strrncasestr("test", "es", 10), "est")); + assert(!strcmpnul(libsimple_strrncasestr("test", "st", 10), "st")); + assert(!libsimple_strrncasestr("test", "xx", 10)); + assert(!strcmpnul(libsimple_strrncasestr("abc", "c", 10), "c")); + assert(!strcmpnul(libsimple_strrncasestr("abc", "bc", 10), "bc")); + assert(!strcmpnul(libsimple_strrncasestr("abc", "abc", 10), "abc")); + assert(!strcmpnul(libsimple_strrncasestr("abcabc", "bc", 10), "bc")); + + assert(!strcmpnul(libsimple_strrncasestr("TEST", "", 10), "")); + assert(!libsimple_strrncasestr("T", "test", 10)); + assert(!strcmpnul(libsimple_strrncasestr("TEST", "t", 10), "T")); + assert(!strcmpnul(libsimple_strrncasestr("TEST", "e", 10), "EST")); + assert(!strcmpnul(libsimple_strrncasestr("TEST", "s", 10), "ST")); + assert(!libsimple_strrncasestr("TEST", "x", 10)); + assert(!strcmpnul(libsimple_strrncasestr("TEST", "te", 10), "TEST")); + assert(!strcmpnul(libsimple_strrncasestr("TEST", "es", 10), "EST")); + assert(!strcmpnul(libsimple_strrncasestr("TEST", "st", 10), "ST")); + assert(!libsimple_strrncasestr("TEST", "xx", 10)); + assert(!strcmpnul(libsimple_strrncasestr("ABC", "c", 10), "C")); + assert(!strcmpnul(libsimple_strrncasestr("ABC", "bc", 10), "BC")); + assert(!strcmpnul(libsimple_strrncasestr("ABC", "abc", 10), "ABC")); + assert(!strcmpnul(libsimple_strrncasestr("ABCABC", "bc", 10), "BC")); + + assert(!libsimple_strrncasestr("", "TEST", 10)); + assert(!libsimple_strrncasestr("t", "TEST", 10)); + assert(!strcmpnul(libsimple_strrncasestr("test", "T", 10), "t")); + assert(!strcmpnul(libsimple_strrncasestr("test", "E", 10), "est")); + assert(!strcmpnul(libsimple_strrncasestr("test", "S", 10), "st")); + assert(!libsimple_strrncasestr("test", "X", 10)); + assert(!strcmpnul(libsimple_strrncasestr("test", "TE", 10), "test")); + assert(!strcmpnul(libsimple_strrncasestr("test", "ES", 10), "est")); + assert(!strcmpnul(libsimple_strrncasestr("test", "ST", 10), "st")); + assert(!libsimple_strrncasestr("test", "XX", 10)); + assert(!strcmpnul(libsimple_strrncasestr("abc", "C", 10), "c")); + assert(!strcmpnul(libsimple_strrncasestr("abc", "BC", 10), "bc")); + assert(!strcmpnul(libsimple_strrncasestr("abc", "ABC", 10), "abc")); + assert(!strcmpnul(libsimple_strrncasestr("abcabc", "BC", 10), "bc")); + + assert(!libsimple_strrncasestr("abcdefgh", "def", 2)); + assert(!libsimple_strrncasestr("abcdefgh", "DEF", 2)); + assert(!libsimple_strrncasestr("ABCDEFGH", "def", 2)); + + return 0; +} + +#endif @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "libsimple.h" +#ifndef TEST char * @@ -21,3 +22,66 @@ libsimple_strrnstr(const char *h_, const char *n, size_t len) return h; return NULL; } + + +#else +#include "test.h" + +int +main(void) +{ + assert(!strcmpnul(libsimple_strrnstr("", "", 10), "")); + assert(!strcmpnul(libsimple_strrnstr("test", "", 10), "")); + assert(!libsimple_strrnstr("", "test", 10)); + assert(!libsimple_strrnstr("t", "test", 10)); + assert(!strcmpnul(libsimple_strrnstr("test", "t", 10), "t")); + assert(!strcmpnul(libsimple_strrnstr("test", "e", 10), "est")); + assert(!strcmpnul(libsimple_strrnstr("test", "s", 10), "st")); + assert(!libsimple_strrnstr("test", "x", 10)); + assert(!strcmpnul(libsimple_strrnstr("test", "te", 10), "test")); + assert(!strcmpnul(libsimple_strrnstr("test", "es", 10), "est")); + assert(!strcmpnul(libsimple_strrnstr("test", "st", 10), "st")); + assert(!libsimple_strrnstr("test", "xx", 10)); + assert(!strcmpnul(libsimple_strrnstr("abc", "c", 10), "c")); + assert(!strcmpnul(libsimple_strrnstr("abc", "bc", 10), "bc")); + assert(!strcmpnul(libsimple_strrnstr("abc", "abc", 10), "abc")); + assert(!strcmpnul(libsimple_strrnstr("abcabc", "bc", 10), "bc")); + + assert(!strcmpnul(libsimple_strrnstr("TEST", "", 10), "")); + assert(!libsimple_strrnstr("T", "test", 10)); + assert(!libsimple_strrnstr("TEST", "t", 10)); + assert(!libsimple_strrnstr("TEST", "e", 10)); + assert(!libsimple_strrnstr("TEST", "s", 10)); + assert(!libsimple_strrnstr("TEST", "x", 10)); + assert(!libsimple_strrnstr("TEST", "te", 10)); + assert(!libsimple_strrnstr("TEST", "es", 10)); + assert(!libsimple_strrnstr("TEST", "st", 10)); + assert(!libsimple_strrnstr("TEST", "xx", 10)); + assert(!libsimple_strrnstr("ABC", "c", 10)); + assert(!libsimple_strrnstr("ABC", "bc", 10)); + assert(!libsimple_strrnstr("ABC", "abc", 10)); + assert(!libsimple_strrnstr("ABCABC", "bc", 10)); + + assert(!libsimple_strrnstr("", "TEST", 10)); + assert(!libsimple_strrnstr("t", "TEST", 10)); + assert(!libsimple_strrnstr("test", "T", 10)); + assert(!libsimple_strrnstr("test", "E", 10)); + assert(!libsimple_strrnstr("test", "S", 10)); + assert(!libsimple_strrnstr("test", "X", 10)); + assert(!libsimple_strrnstr("test", "TE", 10)); + assert(!libsimple_strrnstr("test", "ES", 10)); + assert(!libsimple_strrnstr("test", "ST", 10)); + assert(!libsimple_strrnstr("test", "XX", 10)); + assert(!libsimple_strrnstr("abc", "C", 10)); + assert(!libsimple_strrnstr("abc", "BC", 10)); + assert(!libsimple_strrnstr("abc", "ABC", 10)); + assert(!libsimple_strrnstr("abcabc", "BC", 10)); + + assert(!libsimple_strncasestr("abcdefgh", "def", 2)); + assert(!libsimple_strncasestr("abcdefgh", "DEF", 2)); + assert(!libsimple_strncasestr("ABCDEFGH", "def", 2)); + + return 0; +} + +#endif |