2007-08-06 Simon Josefsson <simon@josefsson.org>
[gnulib.git] / tests / test-memmem.c
1 /*
2  * Copyright (C) 2004, 2007 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 #include <config.h>
21
22 #include <stdio.h>
23 #include <string.h>
24
25 int
26 main (int argc, char *argv[])
27 {
28   const char *big = "foo-bar-baz";
29   char *p;
30
31   p = memmem (big, "foo", strlen (big));
32   if (p != big)
33     {
34       fprintf (stderr, "memmem FAILURE 1\n");
35       return 1;
36     }
37
38   p = memmem (big, "baz", strlen (big));
39   if (p != big + strlen (big) - 3)
40     {
41       fprintf (stderr, "memmem FAILURE 2\n");
42       return 1;
43
44   p = memmem (big, "-", strlen (big));
45   if (p != big + 3)
46     {
47       fprintf (stderr, "memmem FAILURE 3\n");
48       return 1;
49     }
50
51   p = memmem (big, "baz", strlen (big) - 1);
52   if (p != NULL)
53     {
54       fprintf (stderr, "memmem FAILURE 4\n");
55       return 1;
56     }
57
58   return 0;
59 }