Branch data Line data Source code
1 : : /* tst_pr29.c --- Self tests for pr29_*().
2 : : * Copyright (C) 2004-2013 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 <pr29.h>
31 : :
32 : : #include "utils.h"
33 : :
34 : : struct tv
35 : : {
36 : : const char *name;
37 : : size_t inlen;
38 : : uint32_t in[100];
39 : : int rc;
40 : : };
41 : :
42 : : static const struct tv tv[] = {
43 : : {
44 : : "Problem Sequence A",
45 : : 3,
46 : : {0x1100, 0x0300, 0x1161, 0},
47 : : PR29_PROBLEM},
48 : : {
49 : : "Test Case",
50 : : 3,
51 : : {0x0B47, 0x0300, 0x0B3E, 0},
52 : : PR29_PROBLEM},
53 : : {
54 : : "Instability Example",
55 : : 4,
56 : : {0x1100, 0x0300, 0x1161, 0x0323, 0},
57 : : PR29_PROBLEM},
58 : : {
59 : : "Not a problem sequence 1",
60 : : 3,
61 : : {0x1100, 0x1161, 0x0300, 0},
62 : : PR29_SUCCESS},
63 : : {
64 : : "Not a problem sequence 2",
65 : : 3,
66 : : {0x0300, 0x1100, 0x1161, 0},
67 : : PR29_SUCCESS},
68 : : {
69 : : "Not a problem sequence 3",
70 : : 3,
71 : : {0x1161, 0x1100, 0x0300, 0},
72 : : PR29_SUCCESS},
73 : : {
74 : : "Not a problem sequence 4",
75 : : 3,
76 : : {0x1161, 0x0300, 0x1100, 0},
77 : : PR29_SUCCESS},
78 : : {
79 : : "Not a problem sequence 5",
80 : : 3,
81 : : {0x1100, 0x00AA, 0x1161, 0},
82 : : PR29_SUCCESS},
83 : : {
84 : : /* http://lists.gnu.org/archive/html/help-libidn/2012-01/msg00008.html */
85 : : "Infloop",
86 : : 3,
87 : : {0x1100, 0x0300, 0x4711, 0},
88 : : PR29_SUCCESS}
89 : : };
90 : :
91 : : void
92 : 1 : doit (void)
93 : : {
94 : : size_t i;
95 : : int rc;
96 : :
97 [ + + ]: 10 : for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
98 : : {
99 [ - + ]: 9 : if (debug)
100 : : {
101 : : uint32_t *p, *q;
102 : :
103 : 0 : printf ("PR29 entry %ld: %s\n", i, tv[i].name);
104 : :
105 : 0 : printf ("in:\n");
106 : 0 : ucs4print (tv[i].in, tv[i].inlen);
107 : :
108 : 0 : printf ("nfkc:\n");
109 : 0 : p = stringprep_ucs4_nfkc_normalize (tv[i].in, tv[i].inlen);
110 : 0 : ucs4print (p, -1);
111 : :
112 : 0 : printf ("second nfkc:\n");
113 : 0 : q = stringprep_ucs4_nfkc_normalize (p, -1);
114 : 0 : ucs4print (q, -1);
115 : :
116 : 0 : free (p);
117 : 0 : free (q);
118 : : }
119 : :
120 : 9 : rc = pr29_4 (tv[i].in, tv[i].inlen);
121 [ - + ]: 9 : if (rc != tv[i].rc)
122 : : {
123 : 0 : fail ("PR29 entry %ld failed (expected %d): %d\n", i, tv[i].rc, rc);
124 [ # # ]: 0 : if (debug)
125 : 0 : printf ("FATAL\n");
126 : 0 : continue;
127 : : }
128 : :
129 : 9 : rc = pr29_4z (tv[i].in);
130 [ - + ]: 9 : if (rc != tv[i].rc)
131 : : {
132 : 0 : fail ("PR29 entry %ld failed (expected %d): %d\n", i, tv[i].rc, rc);
133 [ # # ]: 0 : if (debug)
134 : 0 : printf ("FATAL\n");
135 : 0 : continue;
136 : : }
137 : :
138 : : {
139 : : char *p;
140 : : size_t items_read, items_written;
141 : :
142 : 9 : p = stringprep_ucs4_to_utf8 (tv[i].in, (ssize_t) tv[i].inlen,
143 : : &items_read, &items_written);
144 [ - + ]: 9 : if (p == NULL)
145 : 0 : fail ("FAIL: stringprep_ucs4_to_utf8(tv[%ld]) == NULL\n", i);
146 [ - + ]: 9 : if (debug)
147 : 0 : hexprint (p, strlen (p));
148 : :
149 : 9 : rc = pr29_8z (p);
150 : 9 : free (p);
151 [ - + ]: 9 : if (rc != tv[i].rc)
152 : : {
153 : 0 : fail ("PR29 entry %ld failed (expected %d): %d\n",
154 : : i, tv[i].rc, rc);
155 [ # # ]: 0 : if (debug)
156 : 0 : printf ("FATAL\n");
157 : 0 : continue;
158 : : }
159 : : }
160 : :
161 [ - + ]: 9 : if (debug)
162 : : {
163 [ # # ]: 0 : if (tv[i].rc != PR29_SUCCESS)
164 : 0 : printf ("EXPECTED FAIL\n");
165 : : else
166 : 0 : printf ("OK\n");
167 : : }
168 : : }
169 : 1 : }
|