Branch data Line data Source code
1 : : /* tst_strerror.c --- Self tests for *_strerror().
2 : : * Copyright (C) 2004-2012 Simon Josefsson
3 : : *
4 : : * This file is part of GNU Libidn.
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 : : */
20 : :
21 : : #ifdef HAVE_CONFIG_H
22 : : # include "config.h"
23 : : #endif
24 : :
25 : : #include <stdio.h>
26 : : #include <stdlib.h>
27 : : #include <stdarg.h>
28 : : #include <string.h>
29 : :
30 : : #include <idna.h>
31 : : #include <pr29.h>
32 : : #include <punycode.h>
33 : : #include <stringprep.h>
34 : : #include <tld.h>
35 : :
36 : : #include "utils.h"
37 : :
38 : : #define SUCCESS "Success"
39 : : #define UNKNOWN "Unknown error"
40 : :
41 : : void
42 : 1 : doit (void)
43 : : {
44 : : const char *p;
45 : :
46 : : /* Test success. */
47 : :
48 : 1 : p = idna_strerror (0);
49 [ - + ]: 1 : if (strcmp (p, SUCCESS) != 0)
50 : 0 : fail ("idna_strerror (0) failed: %s\n", p);
51 [ - + ]: 1 : if (debug)
52 : 0 : printf ("idna_strerror (0) OK\n");
53 : :
54 : 1 : p = pr29_strerror (0);
55 [ - + ]: 1 : if (strcmp (p, SUCCESS) != 0)
56 : 0 : fail ("pr29_strerror (0) failed: %s\n", p);
57 [ - + ]: 1 : if (debug)
58 : 0 : printf ("pr29_strerror (0) OK\n");
59 : :
60 : 1 : p = punycode_strerror (0);
61 [ - + ]: 1 : if (strcmp (p, SUCCESS) != 0)
62 : 0 : fail ("punycode_strerror (0) failed: %s\n", p);
63 [ - + ]: 1 : if (debug)
64 : 0 : printf ("punycode_strerror (0) OK\n");
65 : :
66 : 1 : p = stringprep_strerror (0);
67 [ - + ]: 1 : if (strcmp (p, SUCCESS) != 0)
68 : 0 : fail ("stringprep_strerror (0) failed: %s\n", p);
69 [ - + ]: 1 : if (debug)
70 : 0 : printf ("stringprep_strerror (0) OK\n");
71 : :
72 : 1 : p = tld_strerror (0);
73 [ - + ]: 1 : if (strcmp (p, SUCCESS) != 0)
74 : 0 : fail ("tld_strerror (0) failed: %s\n", p);
75 [ - + ]: 1 : if (debug)
76 : 0 : printf ("tld_strerror (0) OK\n");
77 : :
78 : : /* Test unknown error. */
79 : :
80 : 1 : p = idna_strerror (42);
81 [ - + ]: 1 : if (strcmp (p, UNKNOWN) != 0)
82 : 0 : fail ("idna_strerror (42) failed: %s\n", p);
83 [ - + ]: 1 : if (debug)
84 : 0 : printf ("idna_strerror (42) OK\n");
85 : :
86 : 1 : p = pr29_strerror (42);
87 [ - + ]: 1 : if (strcmp (p, UNKNOWN) != 0)
88 : 0 : fail ("pr29_strerror (42) failed: %s\n", p);
89 [ - + ]: 1 : if (debug)
90 : 0 : printf ("pr29_strerror (42) OK\n");
91 : :
92 : 1 : p = punycode_strerror (42);
93 [ - + ]: 1 : if (strcmp (p, UNKNOWN) != 0)
94 : 0 : fail ("punycode_strerror (42) failed: %s\n", p);
95 [ - + ]: 1 : if (debug)
96 : 0 : printf ("punycode_strerror (42) OK\n");
97 : :
98 : 1 : p = stringprep_strerror (42);
99 [ - + ]: 1 : if (strcmp (p, UNKNOWN) != 0)
100 : 0 : fail ("stringprep_strerror (42) failed: %s\n", p);
101 [ - + ]: 1 : if (debug)
102 : 0 : printf ("stringprep_strerror (42) OK\n");
103 : :
104 : 1 : p = tld_strerror (42);
105 [ - + ]: 1 : if (strcmp (p, UNKNOWN) != 0)
106 : 0 : fail ("tld_strerror (42) failed: %s\n", p);
107 [ - + ]: 1 : if (debug)
108 : 0 : printf ("tld_strerror (42) OK\n");
109 : :
110 : : /* Iterate through all error codes. */
111 : :
112 : : {
113 : : size_t i;
114 : 1 : const char *last_p = NULL;
115 : :
116 : 1 : for (i = 0;; i++)
117 : : {
118 : 16 : p = idna_strerror (i);
119 [ + + ]: 16 : if (p == last_p)
120 : : {
121 [ + + ]: 2 : if (i == 11)
122 : : {
123 : 1 : i = 200;
124 : 1 : continue;
125 : : }
126 : 1 : break;
127 : : }
128 [ - + ]: 14 : if (debug)
129 : 0 : printf ("idna %ld: %s\n", i, p);
130 : 14 : last_p = p;
131 : 15 : }
132 : : }
133 : :
134 : : {
135 : : size_t i;
136 : 1 : const char *last_p = NULL;
137 : :
138 : 1 : for (i = 0;; i++)
139 : : {
140 : 5 : p = pr29_strerror (i);
141 [ + + ]: 5 : if (p == last_p)
142 : 1 : break;
143 [ - + ]: 4 : if (debug)
144 : 0 : printf ("pr29 %ld: %s\n", i, p);
145 : 4 : last_p = p;
146 : 4 : }
147 : : }
148 : :
149 : : {
150 : : size_t i;
151 : 1 : const char *last_p = NULL;
152 : :
153 : 1 : for (i = 0;; i++)
154 : : {
155 : 6 : p = punycode_strerror (i);
156 [ + + ]: 6 : if (p == last_p)
157 : 1 : break;
158 [ - + ]: 5 : if (debug)
159 : 0 : printf ("punycode %ld: %s\n", i, p);
160 : 5 : last_p = p;
161 : 5 : }
162 : : }
163 : :
164 : : {
165 : : size_t i;
166 : 1 : const char *last_p = NULL;
167 : :
168 : 1 : for (i = 0;; i++)
169 : : {
170 : 18 : p = stringprep_strerror (i);
171 [ + + ]: 18 : if (p == last_p)
172 : : {
173 [ + + ]: 3 : if (i == 7)
174 : : {
175 : 1 : i = 99;
176 : 1 : continue;
177 : : }
178 [ + + ]: 2 : else if (i == 105)
179 : : {
180 : 1 : i = 199;
181 : 1 : continue;
182 : : }
183 : 1 : break;
184 : : }
185 [ - + ]: 15 : if (debug)
186 : 0 : printf ("stringprep %ld: %s\n", i, p);
187 : 15 : last_p = p;
188 : 17 : }
189 : : }
190 : :
191 : : {
192 : : size_t i;
193 : 1 : const char *last_p = NULL;
194 : :
195 : 1 : for (i = 0;; i++)
196 : : {
197 : 8 : p = tld_strerror (i);
198 [ + + ]: 8 : if (p == last_p)
199 : 1 : break;
200 [ - + ]: 7 : if (debug)
201 : 0 : printf ("tld %ld: %s\n", i, p);
202 : 7 : last_p = p;
203 : 7 : }
204 : : }
205 : 1 : }
|