commit c43717c93453db5e25ba33dcbdad7112f7cb5b0c
parent 137a215d6fa95f0030a02cbb3e2880ae8d19da61
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 11 Sep 2018 08:33:53 +0100
[tests/libc] Add tests for strcat, strchr and strcmp
Diffstat:
5 files changed, 108 insertions(+), 0 deletions(-)
diff --git a/tests/libc/execute/0009-stdarg.c b/tests/libc/execute/0009-stdarg.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
/*
+TODO: Test va_copy, new c99 extension.
output:
test 1
test 2
diff --git a/tests/libc/execute/0011-strcat.c b/tests/libc/execute/0011-strcat.c
@@ -0,0 +1,36 @@
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+/*
+output:
+testing
+ok
+end:
+*/
+
+int
+main(void)
+{
+ char *s, buf[40];
+
+ puts("testing");
+ strcpy(buf, "case1:");
+ s = strcat(buf, "ok");
+ assert(s == buf);
+ assert(!strcmp(s, "case1:ok"));
+
+ strcpy(buf, "");
+ s = strcat(buf, "ok");
+ assert(s == buf);
+ assert(!strcmp(s, "ok"));
+
+ strcpy(buf, "case1:");
+ strcat(buf, "");
+ assert(s == buf);
+ assert(!strcmp(s, "case1:"));
+
+ puts("ok");
+
+ return 0;
+}
diff --git a/tests/libc/execute/0012-strchr.c b/tests/libc/execute/0012-strchr.c
@@ -0,0 +1,40 @@
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+/*
+output:
+testing
+done
+end:
+*/
+
+int
+main()
+{
+ char *p, buf[] = "abcad";
+
+ puts("testing");
+
+ p = strchr(buf, 'a');
+ assert(p == buf);
+ assert(*p == 'a');
+
+ p = strchr(buf, 'd');
+ assert(p == buf+4);
+ assert(*p == 'd');
+
+ p = strchr(buf, 'c');
+ assert(p == buf+2);
+ assert(*p == 'c');
+
+ p = strchr(buf, 'h');
+ assert(p == NULL);
+
+ p = strchr("", 'a');
+ assert(p == NULL);
+
+ puts("done");
+
+ return 0;
+}
diff --git a/tests/libc/execute/0013-strcmp.c b/tests/libc/execute/0013-strcmp.c
@@ -0,0 +1,28 @@
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+/*
+output:
+testing
+done
+end:
+*/
+
+int
+main()
+{
+ puts("testing");
+
+ assert(strcmp("abcd", "abcd") == 0);
+ assert(strcmp("abcd", "a") > 0);
+ assert(strcmp("a", "abcd") < 0);
+ assert(strcmp("aa", "ab") < 0);
+ assert(strcmp("ab", "aa") > 0);
+ assert(strcmp("", "a") < 0);
+ assert(strcmp("a", "") > 0);
+
+ puts("done");
+
+ return 0;
+}
diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
@@ -8,3 +8,6 @@
0008-longjmp
0009-stdarg [TODO]
0010-stddef
+0011-strcat
+0012-strchr
+0013-strcmp