aboutsummaryrefslogtreecommitdiffstats
path: root/memstarts.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-12 21:35:12 +0200
committerMattias Andrée <maandree@kth.se>2018-08-12 21:35:12 +0200
commit93b8428b5812191177c790ea9ffb9158d5a296b4 (patch)
tree8e43220208a7e3b4780a49b8278e731f3b5fcbbf /memstarts.c
parentAdd DONT_DEFINE_CLOCK_MONOTONIC_RAW (diff)
downloadlibsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.gz
libsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.bz2
libsimple-93b8428b5812191177c790ea9ffb9158d5a296b4.tar.xz
Add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'memstarts.c')
-rw-r--r--memstarts.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/memstarts.c b/memstarts.c
index 1dd1e6a..05c8b39 100644
--- a/memstarts.c
+++ b/memstarts.c
@@ -12,3 +12,46 @@ libsimple_memstarts(const void *s_, size_t n, const void *t_, size_t m)
while (i < m && s[i] == t[i]) i++;
return i == m;
}
+
+
+#ifdef TEST
+#include <assert.h>
+
+int
+main(void)
+{
+ assert(libsimple_memstarts("", 0, "", 0) == 1);
+ assert(libsimple_memstarts("test", 4, "", 0) == 1);
+ assert(libsimple_memstarts("", 0, "test", 4) == 0);
+ assert(libsimple_memstarts("test", 4, "test", 4) == 1);
+ assert(libsimple_memstarts("test", 4, "test", 5) == 0);
+ assert(libsimple_memstarts("test", 4, "testx", 5) == 0);
+ assert(libsimple_memstarts("test", 4, "tes", 3) == 1);
+ assert(libsimple_memstarts("test", 4, "te", 2) == 1);
+ assert(libsimple_memstarts("test", 4, "t", 1) == 1);
+ assert(libsimple_memstarts("test", 4, "x", 1) == 0);
+ assert(libsimple_memstarts("test", 4, "xx", 2) == 0);
+
+ assert(libsimple_memstarts("TEST", 4, "", 0) == 1;
+ assert(libsimple_memstarts("TEST", 4, "test", 4) == 0);
+ assert(libsimple_memstarts("TEST", 4, "test", 5) == 0);
+ assert(libsimple_memstarts("TEST", 4, "testx", 5) == 0);
+ assert(libsimple_memstarts("TEST", 4, "tes", 3) == 0);
+ assert(libsimple_memstarts("TEST", 4, "te", 2) == 0);
+ assert(libsimple_memstarts("TEST", 4, "t", 1) == 0);
+ assert(libsimple_memstarts("TEST", 4, "x", 1) == 0);
+ assert(libsimple_memstarts("TEST", 4, "xx", 2) == 0);
+
+ assert(libsimple_memstarts("", 0, "TEST", 4) == 0);
+ assert(libsimple_memstarts("test", 4, "TEST", 4) == 0);
+ assert(libsimple_memstarts("test", 4, "TEST", 5) == 0);
+ assert(libsimple_memstarts("test", 4, "TESTX", 5) == 0);
+ assert(libsimple_memstarts("test", 4, "TES", 3) == 0);
+ assert(libsimple_memstarts("test", 4, "TE", 2) == 0);
+ assert(libsimple_memstarts("test", 4, "T", 1) == 0);
+ assert(libsimple_memstarts("test", 4, "X", 1) == 0);
+ assert(libsimple_memstarts("test", 4, "XX", 2) == 0);
+ return 0;
+}
+
+#endif