X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-memrchr.c;h=426228e00b370cd5898f9c5b1c004431bae69be7;hb=69770559f5bf198928150ac8162734d7f6b99c82;hp=84f6c5b8b2769f8a01d4a7693953f596bbd188b2;hpb=189c069657b361e15d8f1407b5eb410ddc2ee693;p=gnulib.git diff --git a/tests/test-memrchr.c b/tests/test-memrchr.c index 84f6c5b8b..426228e00 100644 --- a/tests/test-memrchr.c +++ b/tests/test-memrchr.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Free Software Foundation + * Copyright (C) 2008-2013 Free Software Foundation, Inc. * Written by Eric Blake and Bruno Haible * * This program is free software: you can redistribute it and/or modify @@ -19,27 +19,20 @@ #include -#include +#include "signature.h" +SIGNATURE_CHECK (memrchr, void *, (void const *, int, size_t)); + #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "zerosize-ptr.h" +#include "macros.h" /* Calculating void * + int is not portable, so this wrapper converts to char * to make the tests easier to write. */ #define MEMRCHR (char *) memrchr int -main () +main (void) { size_t n = 0x100000; char *input = malloc (n); @@ -56,7 +49,7 @@ main () ASSERT (MEMRCHR (input, 'a', n) == input + n - 1); ASSERT (MEMRCHR (input, 'a', 0) == NULL); - ASSERT (MEMRCHR (NULL, 'a', 0) == NULL); + ASSERT (MEMRCHR (zerosize_ptr (), 'a', 0) == NULL); ASSERT (MEMRCHR (input, 'b', n) == input + n - 2); ASSERT (MEMRCHR (input, 'c', n) == input + n - 3); @@ -74,7 +67,7 @@ main () size_t repeat = 10000; for (; repeat > 0; repeat--) { - ASSERT (MEMRCHR (input, 'c', n) == input + n - 3); + ASSERT (MEMRCHR (input, 'c', n) == input + n - 3); } } @@ -83,12 +76,12 @@ main () int i, j; for (i = 0; i < 32; i++) { - for (j = 0; j < 256; j++) - input[i + j] = j; - for (j = 0; j < 256; j++) - { - ASSERT (MEMRCHR (input + i, j, 256) == input + i + j); - } + for (j = 0; j < 256; j++) + input[i + j] = j; + for (j = 0; j < 256; j++) + { + ASSERT (MEMRCHR (input + i, j, 256) == input + i + j); + } } }