X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest-strcasestr.c;h=8ecd3a9ad36b0de7ab26ce874bacd044aa5473de;hb=dcfa509347541cf4a44f7e5be5fc74398d8a8199;hp=a674719916f05e914bf133af57db69d9ac946ccb;hpb=7dd49d2811431dceac40473f3d65d13f6552cce4;p=gnulib.git diff --git a/tests/test-strcasestr.c b/tests/test-strcasestr.c index a67471991..8ecd3a9ad 100644 --- a/tests/test-strcasestr.c +++ b/tests/test-strcasestr.c @@ -20,19 +20,21 @@ #include +#include #include #include #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -41,8 +43,9 @@ main () #if HAVE_DECL_ALARM /* Declare failure if test takes too long, by using default abort caused by SIGALRM. All known platforms that lack alarm also lack - memmem, and the replacement memmem is known to not take too + strcasestr, and the replacement strcasestr is known to not take too long. */ + signal (SIGALRM, SIG_DFL); alarm (50); #endif @@ -88,16 +91,16 @@ main () char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = 'B'; - haystack[m] = '\0'; + memset (haystack, 'A', m); + haystack[0] = 'B'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (strcasestr (haystack, needle) == haystack + 1); - } + for (; repeat > 0; repeat--) + { + ASSERT (strcasestr (haystack, needle) == haystack + 1); + } - free (haystack); + free (haystack); } } @@ -112,15 +115,15 @@ main () char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (strcasestr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (strcasestr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -131,18 +134,18 @@ main () char *needle = (char *) malloc (m + 2); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = '\0'; - memset (needle, 'a', m); - needle[m] = 'B'; - needle[m + 1] = '\0'; + memset (needle, 'a', m); + needle[m] = 'B'; + needle[m + 1] = '\0'; - result = strcasestr (haystack, needle); - ASSERT (result == haystack + m); + result = strcasestr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack);