X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-memmem.c;h=da0d1be37218bf162314a090c17d4bee8fc2e44b;hb=a4f38ec6be21630e9640cf8ead742c3a8d733fc2;hp=75a2505b7a4c908343689a69b7caacab21080fa7;hpb=6948250861edce048d7bb3c6b47d13fa3649905e;p=gnulib.git diff --git a/tests/test-memmem.c b/tests/test-memmem.c index 75a2505b7..da0d1be37 100644 --- a/tests/test-memmem.c +++ b/tests/test-memmem.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2007-2009 Free Software Foundation + * Copyright (C) 2004, 2007-2010 Free Software Foundation, Inc. * Written by Bruno Haible and Eric Blake * * This program is free software: you can redistribute it and/or modify @@ -19,24 +19,15 @@ #include +#include "signature.h" +SIGNATURE_CHECK (memmem, void *, (void const *, size_t, void const *, size_t)); + #include -#include #include #include #include "zerosize-ptr.h" - -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "macros.h" static void * null_ptr (void) @@ -98,12 +89,31 @@ main (int argc, char *argv[]) ASSERT (result == input); } + /* Check that a long periodic needle does not cause false positives. */ + { + const char input[] = ("F_BD_CE_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD" + "_C3_88_20_EF_BF_BD_EF_BF_BD_EF_BF_BD" + "_C3_A7_20_EF_BF_BD"); + const char need[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD"; + const char *result = memmem (input, strlen (input), need, strlen (need)); + ASSERT (result == NULL); + } + { + const char input[] = ("F_BD_CE_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD" + "_C3_88_20_EF_BF_BD_EF_BF_BD_EF_BF_BD" + "_C3_A7_20_EF_BF_BD_DA_B5_C2_A6_20" + "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD"); + const char need[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD"; + const char *result = memmem (input, strlen (input), need, strlen (need)); + ASSERT (result == input + 115); + } + /* Check that a very long haystack is handled quickly if the needle is short and occurs near the beginning. */ { size_t repeat = 10000; size_t m = 1000000; - char *needle = + const char *needle = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; size_t n = strlen (needle); @@ -127,7 +137,7 @@ main (int argc, char *argv[]) { size_t repeat = 10000; size_t m = 1000000; - char *haystack = + const char *haystack = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"; size_t n = strlen (haystack);