ref: bdcf59621848c43fda1bf636ba03ed8007fdb924
parent: 7ec9f2612f4ac5e4e15922369c7536753e68fc26
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Sep 11 04:33:53 EDT 2018
[tests/libc] Add tests for strcat, strchr and strcmp
--- 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
--- /dev/null
+++ b/tests/libc/execute/0011-strcat.c
@@ -1,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;
+}
--- /dev/null
+++ b/tests/libc/execute/0012-strchr.c
@@ -1,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;
+}
--- /dev/null
+++ b/tests/libc/execute/0013-strcmp.c
@@ -1,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;
+}
--- 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