revert unwanted commit
[gnulib.git] / tests / test-memmem.c
1 /*
2  * Copyright (C) 2004 Free Software Foundation
3  * Written by Simon Josefsson
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.  */
19
20 #if HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <stdio.h>
25 #include <string.h>
26 #include "memmem.h"
27
28 int
29 main (int argc, char *argv[])
30 {
31   const char *big = "foo-bar-baz";
32   char *p;
33
34   p = memmem (big, "foo", strlen (big));
35   if (p != big)
36     {
37       fprintf (stderr, "memmem FAILURE 1\n");
38       return 1;
39     }
40
41   p = memmem (big, "baz", strlen (big));
42   if (p != big + strlen (big) - 3)
43     {
44       fprintf (stderr, "memmem FAILURE 2\n");
45       return 1;
46
47   p = memmem (big, "-", strlen (big));
48   if (p != big + 3)
49     {
50       fprintf (stderr, "memmem FAILURE 3\n");
51       return 1;
52     }
53
54   p = memmem (big, "baz", strlen (big) - 1);
55   if (p != NULL)
56     {
57       fprintf (stderr, "memmem FAILURE 4\n");
58       return 1;
59     }
60
61   return 0;
62 }