From 82d60cae3f53317dc7a3e84de00656bdd03a504a Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 24 Jun 2015 13:20:19 +1000 Subject: add tests for libc memchr Signed-off-by: Stewart Smith --- libc/test/run-memops-test.c | 6 ++++++ libc/test/run-memops.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/libc/test/run-memops-test.c b/libc/test/run-memops-test.c index 429cfdc..7212d76 100644 --- a/libc/test/run-memops-test.c +++ b/libc/test/run-memops-test.c @@ -44,6 +44,7 @@ #include int test_memset(char* buf, int c, size_t s); +int test_memchr(const void *ptr, int c, size_t n, void* expected); int test_memset(char* buf, int c, size_t s) { @@ -57,3 +58,8 @@ int test_memset(char* buf, int c, size_t s) return r; } + +int test_memchr(const void *ptr, int c, size_t n, void* expected) +{ + return(expected == memchr(ptr, c, n)); +} diff --git a/libc/test/run-memops.c b/libc/test/run-memops.c index 80822df..cc107f7 100644 --- a/libc/test/run-memops.c +++ b/libc/test/run-memops.c @@ -22,6 +22,7 @@ #include int test_memset(char* buf, int c, size_t s); +int test_memchr(const void *ptr, int c, size_t n, void* expected); int main(void) { @@ -40,5 +41,11 @@ int main(void) assert(test_memset(buf, 0, 1024) == 0); free(buf); + buf = malloc(20); + strncpy(buf, "Hello World!", 20); + assert(test_memchr(buf, 'o', strlen(buf), buf+4)); + assert(test_memchr(buf, 'a', strlen(buf), NULL)); + free(buf); + return 0; } -- cgit v1.1