Use spaces for indentation, not tabs.
[gnulib.git] / tests / test-mbmemcasecoll.c
1 /* Test of case-insensitive memory area comparison function.
2    Copyright (C) 2007-2009 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
18
19 #include <config.h>
20
21 #include "mbmemcasecoll.h"
22
23 #include <locale.h>
24 #include <stdbool.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
30 #define ASSERT(expr) \
31   do                                                                         \
32     {                                                                        \
33       if (!(expr))                                                           \
34         {                                                                    \
35           fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
36           fflush (stderr);                                                   \
37           abort ();                                                          \
38         }                                                                    \
39     }                                                                        \
40   while (0)
41
42 #include "test-mbmemcasecmp.h"
43
44 static int
45 mbmemcasecoll_hard (const char *s1, size_t s1len, const char *s2, size_t s2len)
46 {
47   return mbmemcasecoll (s1, s1len, s2, s2len, true);
48 }
49
50 int
51 main (int argc, char *argv[])
52 {
53   /* configure should already have checked that the locale is supported.  */
54   if (setlocale (LC_ALL, "") == NULL)
55     return 1;
56
57   test_ascii (mbmemcasecoll_hard);
58
59   if (argc > 1)
60     switch (argv[1][0])
61       {
62       case '1':
63         /* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
64         test_iso_8859_1 (mbmemcasecoll_hard, false);
65         return 0;
66
67       case '2':
68         /* Locale encoding is UTF-8, locale is not Turkish.  */
69         test_utf_8 (mbmemcasecoll_hard, false);
70         return 0;
71
72       case '3':
73         /* Locale encoding is UTF-8, locale is Turkish.  */
74         test_utf_8 (mbmemcasecoll_hard, true);
75         return 0;
76       }
77
78   return 1;
79 }