From b1c35c95f1384747b53cb5bdd8d5030068a39602 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 5 Jul 2023 15:38:56 +0200 Subject: Add tests for bcopy --- tests/Makefile | 4 ++++ tests/test_bcopy_dynamic_read.c | 18 ++++++++++++++++++ tests/test_bcopy_dynamic_write.c | 18 ++++++++++++++++++ tests/test_bcopy_static_read.c | 18 ++++++++++++++++++ tests/test_bcopy_static_write.c | 18 ++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 tests/test_bcopy_dynamic_read.c create mode 100644 tests/test_bcopy_dynamic_write.c create mode 100644 tests/test_bcopy_static_read.c create mode 100644 tests/test_bcopy_static_write.c diff --git a/tests/Makefile b/tests/Makefile index 4cae588..e14fced 100644 --- 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 new file mode 100644 index 0000000..5455ddb --- /dev/null +++ b/tests/test_bcopy_dynamic_read.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include + +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 new file mode 100644 index 0000000..1f0fa9b --- /dev/null +++ b/tests/test_bcopy_dynamic_write.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include + +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 new file mode 100644 index 0000000..e7a3c74 --- /dev/null +++ b/tests/test_bcopy_static_read.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include + +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 new file mode 100644 index 0000000..47e737a --- /dev/null +++ b/tests/test_bcopy_static_write.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE + +#include "common.h" + +#include + +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; +} -- cgit v1.3