maint: update copyright
[gnulib.git] / tests / test-memcoll.c
1 /*
2  * Copyright (C) 2008-2014 Free Software Foundation, Inc.
3  * Written by Simon Josefsson and Bruno Haible
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 3 of the License, or
8  * (at your option) 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, see <http://www.gnu.org/licenses/>.  */
17
18 #include <config.h>
19
20 #include "memcoll.h"
21
22 #include <string.h>
23
24 #include "macros.h"
25
26 int
27 main (void)
28 {
29   /* Test equal / not equal distinction.  */
30   ASSERT (memcoll0 ("", 1, "", 1) == 0);
31   ASSERT (memcoll0 ("fo", 3, "fo", 3) == 0);
32   ASSERT (memcoll0 ("foo", 4, "foo", 4) == 0);
33   ASSERT (memcoll0 ("foo\0", 5, "foob", 5) != 0);
34   ASSERT (memcoll0 ("f", 2, "b", 2) != 0);
35   ASSERT (memcoll0 ("foo", 4, "bar", 4) != 0);
36
37   /* Test less / equal / greater distinction.  */
38   ASSERT (memcoll0 ("foo\0", 5, "moo\0", 5) < 0);
39   ASSERT (memcoll0 ("moo\0", 5, "foo\0", 5) > 0);
40   ASSERT (memcoll0 ("oom", 4, "oop", 4) < 0);
41   ASSERT (memcoll0 ("oop", 4, "oom", 4) > 0);
42   ASSERT (memcoll0 ("foo\0", 5, "foob", 5) < 0);
43   ASSERT (memcoll0 ("foob", 5, "foo\0", 5) > 0);
44
45   /* Test embedded NULs.  */
46   ASSERT (memcoll0 ("1\0", 3, "2\0", 3) < 0);
47   ASSERT (memcoll0 ("2\0", 3, "1\0", 3) > 0);
48   ASSERT (memcoll0 ("x\0""1", 4, "x\0""2", 4) < 0);
49   ASSERT (memcoll0 ("x\0""2", 4, "x\0""1", 4) > 0);
50
51   return 0;
52 }