aboutsummaryrefslogtreecommitdiffstats
path: root/libsimple.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-25 21:51:27 +0200
committerMattias Andrée <maandree@kth.se>2018-08-25 21:51:27 +0200
commita3ae98d66f1bf204f584bdbb69b5d3e994f35bca (patch)
treef2681c4a470c881872a684c8f366d4b2a116ebd1 /libsimple.c
parentUpdate readme (diff)
downloadlibsimple-a3ae98d66f1bf204f584bdbb69b5d3e994f35bca.tar.gz
libsimple-a3ae98d66f1bf204f584bdbb69b5d3e994f35bca.tar.bz2
libsimple-a3ae98d66f1bf204f584bdbb69b5d3e994f35bca.tar.xz
Add more tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libsimple.c302
1 files changed, 302 insertions, 0 deletions
diff --git a/libsimple.c b/libsimple.c
index 36cc690..03d7611 100644
--- a/libsimple.c
+++ b/libsimple.c
@@ -13,6 +13,8 @@ int
main(void)
{
char buf[1024];
+ int intarray[10];
+ size_t i, n;
assert(MIN(1, 3) == 1);
assert(MIN(1, 1) == 1);
@@ -213,6 +215,37 @@ main(void)
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);
@@ -229,6 +262,52 @@ main(void)
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);
@@ -240,6 +319,37 @@ main(void)
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);
@@ -256,6 +366,198 @@ main(void)
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);
+
+ for (i = 0, n = 10; i < n; i++)
+ buf[i] = i;
+ LIBSIMPLE_UNLIST(buf, 4, &n);
+ LIBSIMPLE_UNLIST(buf, 9 - 1, &n);
+ LIBSIMPLE_UNLIST(buf, 6 - 1, &n);
+ assert(n == 7);
+ assert(buf[0] == 0);
+ assert(buf[1] == 1);
+ assert(buf[2] == 2);
+ assert(buf[3] == 3);
+ assert(buf[4] == 5);
+ assert(buf[5] == 7);
+ assert(buf[6] == 8);
+
+ for (i = 0, n = 10; i < n; i++)
+ intarray[i] = i;
+ LIBSIMPLE_UNLIST(intarray, 4, &n);
+ LIBSIMPLE_UNLIST(intarray, 9 - 1, &n);
+ LIBSIMPLE_UNLIST(intarray, 6 - 1, &n);
+ assert(n == 7);
+ assert(intarray[0] == 0);
+ assert(intarray[1] == 1);
+ assert(intarray[2] == 2);
+ assert(intarray[3] == 3);
+ assert(intarray[4] == 5);
+ assert(intarray[5] == 7);
+ assert(intarray[6] == 8);
+
+ 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);
+
return 0;
}