diff options
| author | jvoisin | 2023-07-05 15:38:56 +0200 |
|---|---|---|
| committer | jvoisin | 2023-07-05 15:38:56 +0200 |
| commit | b1c35c95f1384747b53cb5bdd8d5030068a39602 (patch) | |
| tree | 696437aab0aee79e02dbe1f255cf3a18a4c765c5 | |
| parent | a8f6f7a21f687dd99175591ff5b3a1d708f67cbe (diff) | |
Add tests for bcopy
| -rw-r--r-- | tests/Makefile | 4 | ||||
| -rw-r--r-- | tests/test_bcopy_dynamic_read.c | 18 | ||||
| -rw-r--r-- | tests/test_bcopy_dynamic_write.c | 18 | ||||
| -rw-r--r-- | tests/test_bcopy_static_read.c | 18 | ||||
| -rw-r--r-- | tests/test_bcopy_static_write.c | 18 |
5 files changed, 76 insertions, 0 deletions
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 | |||
| 2 | 2 | ||
| 3 | TARGETS= \ | 3 | TARGETS= \ |
| 4 | test_fgets \ | 4 | test_fgets \ |
| 5 | test_bcopy_static_write \ | ||
| 6 | test_bcopy_dynamic_write \ | ||
| 7 | test_bcopy_static_read \ | ||
| 8 | test_bcopy_dynamic_read \ | ||
| 5 | test_memcpy_static_write \ | 9 | test_memcpy_static_write \ |
| 6 | test_memcpy_dynamic_write \ | 10 | test_memcpy_dynamic_write \ |
| 7 | test_memcpy_static_read \ | 11 | 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 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include "common.h" | ||
| 4 | |||
| 5 | #include <strings.h> | ||
| 6 | |||
| 7 | int main(int argc, char** argv) { | ||
| 8 | char buffer[12] = {0}; | ||
| 9 | bcopy("1234567890", buffer, sizeof(buffer) - 1); | ||
| 10 | puts(buffer); | ||
| 11 | |||
| 12 | CHK_FAIL_START | ||
| 13 | bcopy("123456", buffer, argc); | ||
| 14 | CHK_FAIL_END | ||
| 15 | |||
| 16 | puts(buffer); | ||
| 17 | return ret; | ||
| 18 | } | ||
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 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include "common.h" | ||
| 4 | |||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | int main(int argc, char** argv) { | ||
| 8 | char buffer[8] = {0}; | ||
| 9 | bcopy("1234567890", buffer, sizeof(buffer) - 1); | ||
| 10 | puts(buffer); | ||
| 11 | |||
| 12 | CHK_FAIL_START | ||
| 13 | bcopy("1234567890", buffer, argc); | ||
| 14 | CHK_FAIL_END | ||
| 15 | |||
| 16 | puts(buffer); | ||
| 17 | return ret; | ||
| 18 | } | ||
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 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include "common.h" | ||
| 4 | |||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | int main(int argc, char** argv) { | ||
| 8 | char buffer[8] = {0}; | ||
| 9 | bcopy("123456", buffer, 4); | ||
| 10 | puts(buffer); | ||
| 11 | |||
| 12 | CHK_FAIL_START | ||
| 13 | bcopy("123456", buffer, sizeof(buffer)); | ||
| 14 | CHK_FAIL_END | ||
| 15 | |||
| 16 | puts(buffer); | ||
| 17 | return ret; | ||
| 18 | } | ||
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 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include "common.h" | ||
| 4 | |||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | int main(int argc, char** argv) { | ||
| 8 | char buffer[8] = {0}; | ||
| 9 | bcopy("1234567890", buffer, sizeof(buffer) - 1); | ||
| 10 | puts(buffer); | ||
| 11 | |||
| 12 | CHK_FAIL_START | ||
| 13 | bcopy("1234567890", buffer, sizeof(buffer) + 1); | ||
| 14 | CHK_FAIL_END | ||
| 15 | |||
| 16 | puts(buffer); | ||
| 17 | return ret; | ||
| 18 | } | ||
