commit f0305fb85796cc4dcc537123d6b9b3152cf0c4be
parent fea08b7aef9cd235d6ae384c1fd6e9578dc952c4
Author: jvoisin <julien.voisin@dustri.org>
Date: Sun, 20 Aug 2023 17:59:13 +0200
Add two tests for memchr
Diffstat:
3 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
@@ -32,6 +32,8 @@ TARGETS= \
test_getlogin_r_dynamic \
test_getlogin_r_static \
test_malloc \
+ test_memchr_dynamic_read \
+ test_memchr_static_read \
test_memcpy_dynamic_read \
test_memcpy_dynamic_write \
test_memcpy_overwrite_over \
diff --git a/tests/test_memchr_dynamic_read.c b/tests/test_memchr_dynamic_read.c
@@ -0,0 +1,16 @@
+#include "common.h"
+
+#include <string.h>
+
+int main(int argc, char** argv) {
+ const char* buffer = "12345";
+ memchr(buffer, (int)'4', strlen(buffer) - 1);
+ puts(buffer);
+
+ CHK_FAIL_START
+ memchr(buffer, (int)'A', argc);
+ CHK_FAIL_END
+
+ puts(buffer);
+ return ret;
+}
diff --git a/tests/test_memchr_static_read.c b/tests/test_memchr_static_read.c
@@ -0,0 +1,17 @@
+#include "common.h"
+
+#include <string.h>
+
+int main(int argc, char** argv) {
+ const char* buffer = "12345";
+ const char* padding = "ABCDEFGHIJKLMN";
+ memchr(buffer, (int)'4', strlen(buffer) - 1);
+ puts(buffer);
+
+ CHK_FAIL_START
+ memchr(buffer, (int)'A', strlen(buffer) + 4);
+ CHK_FAIL_END
+
+ puts(buffer);
+ return ret;
+}