Skip to content

Commit

Permalink
Add tests for mempcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin committed Jun 22, 2023
1 parent b714dbd commit 79447cb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ TARGETS=test_memcpy_static_write \
test_memcpy_dynamic_write \
test_memcpy_static_read \
test_memcpy_dynamic_read \
test_mempcpy_static_write \
test_mempcpy_dynamic_write \
test_mempcpy_static_read \
test_mempcpy_dynamic_read \
test_memmove_static_write \
test_memmove_dynamic_write \
test_memmove_static_read \
Expand Down
17 changes: 17 additions & 0 deletions tests/test_mempcpy_dynamic_read.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "common.h"

#define _GNU_SOURCE
#include <string.h>

int main(int argc, char** argv) {
char buffer[12] = {0};
mempcpy(buffer, "1234567890", sizeof(buffer) - 1);
puts(buffer);

CHK_FAIL_START
mempcpy(buffer, "123456", argc);
CHK_FAIL_END

puts(buffer);
return ret;
}
17 changes: 17 additions & 0 deletions tests/test_mempcpy_dynamic_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "common.h"

#define _GNU_SOURCE
#include <string.h>

int main(int argc, char** argv) {
char buffer[8] = {0};
mempcpy(buffer, "1234567890", sizeof(buffer) - 1);
puts(buffer);

CHK_FAIL_START
mempcpy(buffer, "1234567890", argc);
CHK_FAIL_END

puts(buffer);
return ret;
}
17 changes: 17 additions & 0 deletions tests/test_mempcpy_static_read.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "common.h"

#define _GNU_SOURCE
#include <string.h>

int main(int argc, char** argv) {
char buffer[8] = {0};
mempcpy(buffer, "123456", 4);
puts(buffer);

CHK_FAIL_START
mempcpy(buffer, "123456", sizeof(buffer));
CHK_FAIL_END

puts(buffer);
return ret;
}
17 changes: 17 additions & 0 deletions tests/test_mempcpy_static_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "common.h"

#define _GNU_SOURCE
#include <string.h>

int main(int argc, char** argv) {
char buffer[8] = {0};
mempcpy(buffer, "1234567890", sizeof(buffer) - 1);
puts(buffer);

CHK_FAIL_START
mempcpy(buffer, "1234567890", sizeof(buffer) + 1);
CHK_FAIL_END

puts(buffer);
return ret;
}

0 comments on commit 79447cb

Please sign in to comment.