commit b1c35c95f1384747b53cb5bdd8d5030068a39602
parent a8f6f7a21f687dd99175591ff5b3a1d708f67cbe
Author: jvoisin <julien.voisin@dustri.org>
Date: Wed, 5 Jul 2023 15:38:56 +0200
Add tests for bcopy
Diffstat:
5 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
@@ -2,6 +2,10 @@ CFLAGS=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2
TARGETS= \
test_fgets \
+ test_bcopy_static_write \
+ test_bcopy_dynamic_write \
+ test_bcopy_static_read \
+ test_bcopy_dynamic_read \
test_memcpy_static_write \
test_memcpy_dynamic_write \
test_memcpy_static_read \
diff --git a/tests/test_bcopy_dynamic_read.c b/tests/test_bcopy_dynamic_read.c
@@ -0,0 +1,18 @@
+#define _GNU_SOURCE
+
+#include "common.h"
+
+#include <strings.h>
+
+int main(int argc, char** argv) {
+ char buffer[12] = {0};
+ bcopy("1234567890", buffer, sizeof(buffer) - 1);
+ puts(buffer);
+
+ CHK_FAIL_START
+ bcopy("123456", buffer, argc);
+ CHK_FAIL_END
+
+ puts(buffer);
+ return ret;
+}
diff --git a/tests/test_bcopy_dynamic_write.c b/tests/test_bcopy_dynamic_write.c
@@ -0,0 +1,18 @@
+#define _GNU_SOURCE
+
+#include "common.h"
+
+#include <string.h>
+
+int main(int argc, char** argv) {
+ char buffer[8] = {0};
+ bcopy("1234567890", buffer, sizeof(buffer) - 1);
+ puts(buffer);
+
+ CHK_FAIL_START
+ bcopy("1234567890", buffer, argc);
+ CHK_FAIL_END
+
+ puts(buffer);
+ return ret;
+}
diff --git a/tests/test_bcopy_static_read.c b/tests/test_bcopy_static_read.c
@@ -0,0 +1,18 @@
+#define _GNU_SOURCE
+
+#include "common.h"
+
+#include <string.h>
+
+int main(int argc, char** argv) {
+ char buffer[8] = {0};
+ bcopy("123456", buffer, 4);
+ puts(buffer);
+
+ CHK_FAIL_START
+ bcopy("123456", buffer, sizeof(buffer));
+ CHK_FAIL_END
+
+ puts(buffer);
+ return ret;
+}
diff --git a/tests/test_bcopy_static_write.c b/tests/test_bcopy_static_write.c
@@ -0,0 +1,18 @@
+#define _GNU_SOURCE
+
+#include "common.h"
+
+#include <string.h>
+
+int main(int argc, char** argv) {
+ char buffer[8] = {0};
+ bcopy("1234567890", buffer, sizeof(buffer) - 1);
+ puts(buffer);
+
+ CHK_FAIL_START
+ bcopy("1234567890", buffer, sizeof(buffer) + 1);
+ CHK_FAIL_END
+
+ puts(buffer);
+ return ret;
+}