0e638b5a197fdfb57def0008f7dbba8d915fd84f
[platform/upstream/diffutils.git] / gnulib-tests / test-strtoumax.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /*
4  * Copyright (C) 2011 Free Software Foundation, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #include <config.h>
20
21 #include <inttypes.h>
22
23 #include "signature.h"
24 #ifndef strtoumax
25 SIGNATURE_CHECK (strtoumax, uintmax_t, (const char *, char **, int));
26 #endif
27
28 #include <errno.h>
29
30 #include "macros.h"
31
32 int
33 main (void)
34 {
35   /* Subject sequence empty or invalid.  */
36   {
37     const char input[] = "";
38     char *ptr;
39     uintmax_t result;
40     errno = 0;
41     result = strtoumax (input, &ptr, 10);
42     ASSERT (result == 0);
43     ASSERT (ptr == input);
44     ASSERT (errno == 0 || errno == EINVAL);
45   }
46   {
47     const char input[] = " ";
48     char *ptr;
49     uintmax_t result;
50     errno = 0;
51     result = strtoumax (input, &ptr, 10);
52     ASSERT (result == 0);
53     ASSERT (ptr == input);
54     ASSERT (errno == 0 || errno == EINVAL);
55   }
56   {
57     const char input[] = " +";
58     char *ptr;
59     uintmax_t result;
60     errno = 0;
61     result = strtoumax (input, &ptr, 10);
62     ASSERT (result == 0);
63     ASSERT (ptr == input);
64     ASSERT (errno == 0 || errno == EINVAL);
65   }
66   {
67     const char input[] = " -";
68     char *ptr;
69     uintmax_t result;
70     errno = 0;
71     result = strtoumax (input, &ptr, 10);
72     ASSERT (result == 0);
73     ASSERT (ptr == input);
74     ASSERT (errno == 0 || errno == EINVAL);
75   }
76
77   /* Simple integer values.  */
78   {
79     const char input[] = "0";
80     char *ptr;
81     uintmax_t result;
82     errno = 0;
83     result = strtoumax (input, &ptr, 10);
84     ASSERT (result == 0);
85     ASSERT (ptr == input + 1);
86     ASSERT (errno == 0);
87   }
88   {
89     const char input[] = "+0";
90     char *ptr;
91     uintmax_t result;
92     errno = 0;
93     result = strtoumax (input, &ptr, 10);
94     ASSERT (result == 0);
95     ASSERT (ptr == input + 2);
96     ASSERT (errno == 0);
97   }
98   {
99     const char input[] = "-0";
100     char *ptr;
101     uintmax_t result;
102     errno = 0;
103     result = strtoumax (input, &ptr, 10);
104     ASSERT (result == 0);
105     ASSERT (ptr == input + 2);
106     ASSERT (errno == 0);
107   }
108   {
109     const char input[] = "23";
110     char *ptr;
111     uintmax_t result;
112     errno = 0;
113     result = strtoumax (input, &ptr, 10);
114     ASSERT (result == 23);
115     ASSERT (ptr == input + 2);
116     ASSERT (errno == 0);
117   }
118   {
119     const char input[] = " 23";
120     char *ptr;
121     uintmax_t result;
122     errno = 0;
123     result = strtoumax (input, &ptr, 10);
124     ASSERT (result == 23);
125     ASSERT (ptr == input + 3);
126     ASSERT (errno == 0);
127   }
128   {
129     const char input[] = "+23";
130     char *ptr;
131     uintmax_t result;
132     errno = 0;
133     result = strtoumax (input, &ptr, 10);
134     ASSERT (result == 23);
135     ASSERT (ptr == input + 3);
136     ASSERT (errno == 0);
137   }
138   {
139     const char input[] = "-23";
140     char *ptr;
141     uintmax_t result;
142     errno = 0;
143     result = strtoumax (input, &ptr, 10);
144     ASSERT (result == - (uintmax_t) 23);
145     ASSERT (ptr == input + 3);
146     ASSERT (errno == 0);
147   }
148
149   return 0;
150 }