1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #include "plstr.h"
|
---|
39 | #include "nspr.h"
|
---|
40 |
|
---|
41 | #include <stdio.h>
|
---|
42 |
|
---|
43 | /* PL_strlen */
|
---|
44 | PRBool test_001(void)
|
---|
45 | {
|
---|
46 | static struct
|
---|
47 | {
|
---|
48 | const char *str;
|
---|
49 | PRUint32 len;
|
---|
50 | } array[] =
|
---|
51 | {
|
---|
52 | { (const char *)0, 0 },
|
---|
53 | { "", 0 },
|
---|
54 | { "a", 1 },
|
---|
55 | { "abcdefg", 7 },
|
---|
56 | { "abcdefg\0hijk", 7 }
|
---|
57 | };
|
---|
58 |
|
---|
59 | int i;
|
---|
60 |
|
---|
61 | printf("Test 001 (PL_strlen) ..."); fflush(stdout);
|
---|
62 |
|
---|
63 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
64 | {
|
---|
65 | if( PL_strlen(array[i].str) != array[i].len )
|
---|
66 | {
|
---|
67 | printf("FAIL (%d: %s->%d, %d)\n", i,
|
---|
68 | array[i].str ? array[i].str : "(null)",
|
---|
69 | PL_strlen(array[i].str), array[i].len);
|
---|
70 | return PR_FALSE;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | printf("PASS\n");
|
---|
75 | return PR_TRUE;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* PL_strnlen */
|
---|
79 | PRBool test_002(void)
|
---|
80 | {
|
---|
81 | static struct
|
---|
82 | {
|
---|
83 | const char *str;
|
---|
84 | PRUint32 max;
|
---|
85 | PRUint32 len;
|
---|
86 | } array[] =
|
---|
87 | {
|
---|
88 | { (const char *)0, 0, 0 },
|
---|
89 | { (const char *)0, 12, 0 },
|
---|
90 | { "", 0, 0 },
|
---|
91 | { "", 12, 0 },
|
---|
92 | { "a", 0, 0 },
|
---|
93 | { "a", 1, 1 },
|
---|
94 | { "a", 12, 1 },
|
---|
95 | { "abcdefg", 0, 0 },
|
---|
96 | { "abcdefg", 1, 1 },
|
---|
97 | { "abcdefg", 7, 7 },
|
---|
98 | { "abcdefg", 12, 7 },
|
---|
99 | { "abcdefg\0hijk", 0, 0 },
|
---|
100 | { "abcdefg\0hijk", 1, 1 },
|
---|
101 | { "abcdefg\0hijk", 7, 7 },
|
---|
102 | { "abcdefg\0hijk", 12, 7 },
|
---|
103 | };
|
---|
104 |
|
---|
105 | int i;
|
---|
106 |
|
---|
107 | printf("Test 002 (PL_strnlen) ..."); fflush(stdout);
|
---|
108 |
|
---|
109 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
110 | {
|
---|
111 | if( PL_strnlen(array[i].str, array[i].max) != array[i].len )
|
---|
112 | {
|
---|
113 | printf("FAIL (%d: %s,%d->%d, %d)\n", i,
|
---|
114 | array[i].str ? array[i].str : "(null)", array[i].max,
|
---|
115 | PL_strnlen(array[i].str, array[i].max), array[i].len);
|
---|
116 | return PR_FALSE;
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | printf("PASS\n");
|
---|
121 | return PR_TRUE;
|
---|
122 | }
|
---|
123 |
|
---|
124 | /* PL_strcpy */
|
---|
125 | PRBool test_003(void)
|
---|
126 | {
|
---|
127 | static char buffer[ 1024 ];
|
---|
128 |
|
---|
129 | static struct
|
---|
130 | {
|
---|
131 | const char *str;
|
---|
132 | char *dest;
|
---|
133 | char *rv;
|
---|
134 | PRBool comp;
|
---|
135 | } array[] =
|
---|
136 | {
|
---|
137 | { (const char *)0, (char *)0, (char *)0, PR_FALSE },
|
---|
138 | { (const char *)0, buffer, (char *)0, PR_FALSE },
|
---|
139 | { "", (char *)0, (char *)0, PR_FALSE },
|
---|
140 | { "", buffer, buffer, PR_TRUE },
|
---|
141 | { "a", (char *)0, (char *)0, PR_FALSE },
|
---|
142 | { "a", buffer, buffer, PR_TRUE },
|
---|
143 | { "abcdefg", (char *)0, (char *)0, PR_FALSE },
|
---|
144 | { "abcdefg", buffer, buffer, PR_TRUE },
|
---|
145 | { "wxyz\0abcdefg", (char *)0, (char *)0, PR_FALSE },
|
---|
146 | { "wxyz\0abcdefg", buffer, buffer, PR_TRUE }
|
---|
147 | };
|
---|
148 |
|
---|
149 | int i;
|
---|
150 |
|
---|
151 | printf("Test 003 (PL_strcpy) ..."); fflush(stdout);
|
---|
152 |
|
---|
153 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
154 | {
|
---|
155 | char *rv;
|
---|
156 | const char *a = array[i].str;
|
---|
157 | const char *b = (const char *)array[i].dest;
|
---|
158 |
|
---|
159 | rv = PL_strcpy(array[i].dest, array[i].str);
|
---|
160 | if( array[i].rv != rv )
|
---|
161 | {
|
---|
162 | printf("FAIL %d: (0x%x, %s)->0x%x\n", i, array[i].dest,
|
---|
163 | array[i].str ? array[i].str : "(null)", rv);
|
---|
164 | return PR_FALSE;
|
---|
165 | }
|
---|
166 |
|
---|
167 | if( array[i].comp )
|
---|
168 | {
|
---|
169 | while( 1 )
|
---|
170 | {
|
---|
171 | if( *a != *b )
|
---|
172 | {
|
---|
173 | printf("FAIL %d: %s->%.32s\n", i,
|
---|
174 | array[i].str ? array[i].str : "(null)",
|
---|
175 | array[i].dest ? array[i].dest : "(null)");
|
---|
176 | return PR_FALSE;
|
---|
177 | }
|
---|
178 |
|
---|
179 | if( (char)0 == *a ) break;
|
---|
180 |
|
---|
181 | a++;
|
---|
182 | b++;
|
---|
183 | }
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | printf("PASS\n");
|
---|
188 | return PR_TRUE;
|
---|
189 | }
|
---|
190 |
|
---|
191 | /* PL_strncpy */
|
---|
192 | PRBool test_004(void)
|
---|
193 | {
|
---|
194 | static char buffer[ 1024 ];
|
---|
195 |
|
---|
196 | static struct
|
---|
197 | {
|
---|
198 | const char *str;
|
---|
199 | PRUint32 len;
|
---|
200 | char *dest;
|
---|
201 | char *rv;
|
---|
202 | PRBool comp;
|
---|
203 | const char *result;
|
---|
204 | PRBool nulled;
|
---|
205 | } array[] =
|
---|
206 | {
|
---|
207 | { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
208 | { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
209 | { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
210 | { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
211 | { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
212 | { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
213 | { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
214 | { "", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
215 | { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
216 | { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
217 | { "", 1, buffer, buffer, PR_TRUE, "", PR_TRUE },
|
---|
218 | { "", 7, buffer, buffer, PR_TRUE, "", PR_TRUE },
|
---|
219 | { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
220 | { "a", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
221 | { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
222 | { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
223 | { "b", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
|
---|
224 | { "c", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
|
---|
225 | { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
226 | { "de", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
227 | { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
228 | { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
229 | { "fg", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
|
---|
230 | { "hi", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
|
---|
231 | { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
232 | { "jklmnopq", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
233 | { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
234 | { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
235 | { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
|
---|
236 | { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
|
---|
237 | { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
238 | { "a\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
239 | { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
240 | { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
241 | { "b\0XXX", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
|
---|
242 | { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
|
---|
243 | { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
244 | { "de\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
245 | { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
246 | { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
247 | { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
|
---|
248 | { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
|
---|
249 | { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
250 | { "jklmnopq\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
251 | { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
252 | { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
|
---|
253 | { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
|
---|
254 | { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
|
---|
255 | };
|
---|
256 |
|
---|
257 | int i;
|
---|
258 |
|
---|
259 | printf("Test 004 (PL_strncpy) ..."); fflush(stdout);
|
---|
260 |
|
---|
261 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
262 | {
|
---|
263 | char *rv;
|
---|
264 | int j;
|
---|
265 |
|
---|
266 | for( j = 0; j < sizeof(buffer); j++ )
|
---|
267 | buffer[j] = '-';
|
---|
268 |
|
---|
269 | rv = PL_strncpy(array[i].dest, array[i].str, array[i].len);
|
---|
270 | if( array[i].rv != rv )
|
---|
271 | {
|
---|
272 | printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest,
|
---|
273 | array[i].str ? array[i].str : "(null)", array[i].len, rv);
|
---|
274 | return PR_FALSE;
|
---|
275 | }
|
---|
276 |
|
---|
277 | if( array[i].comp )
|
---|
278 | {
|
---|
279 | const char *a = array[i].result;
|
---|
280 | const char *b = array[i].dest;
|
---|
281 |
|
---|
282 | while( *a )
|
---|
283 | {
|
---|
284 | if( *a != *b )
|
---|
285 | {
|
---|
286 | printf("FAIL %d: %s != %.32s\n", i,
|
---|
287 | array[i].result, array[i].dest);
|
---|
288 | return PR_FALSE;
|
---|
289 | }
|
---|
290 |
|
---|
291 | a++;
|
---|
292 | b++;
|
---|
293 | }
|
---|
294 |
|
---|
295 | if( array[i].nulled )
|
---|
296 | {
|
---|
297 | if( *b != '\0' )
|
---|
298 | {
|
---|
299 | printf("FAIL %d: not terminated\n", i);
|
---|
300 | return PR_FALSE;
|
---|
301 | }
|
---|
302 | }
|
---|
303 | else
|
---|
304 | {
|
---|
305 | if( *b != '-' )
|
---|
306 | {
|
---|
307 | printf("FAIL %d: overstepped\n", i);
|
---|
308 | return PR_FALSE;
|
---|
309 | }
|
---|
310 | }
|
---|
311 | }
|
---|
312 | }
|
---|
313 |
|
---|
314 | printf("PASS\n");
|
---|
315 | return PR_TRUE;
|
---|
316 | }
|
---|
317 |
|
---|
318 | /* PL_strncpyz */
|
---|
319 | PRBool test_005(void)
|
---|
320 | {
|
---|
321 | static char buffer[ 1024 ];
|
---|
322 |
|
---|
323 | static struct
|
---|
324 | {
|
---|
325 | const char *str;
|
---|
326 | PRUint32 len;
|
---|
327 | char *dest;
|
---|
328 | char *rv;
|
---|
329 | PRBool comp;
|
---|
330 | const char *result;
|
---|
331 | } array[] =
|
---|
332 | {
|
---|
333 | { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
334 | { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
335 | { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
336 | { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
337 | { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
338 | { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
339 | { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
340 | { "", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
341 | { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
342 | { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
343 | { "", 1, buffer, buffer, PR_TRUE, "" },
|
---|
344 | { "", 7, buffer, buffer, PR_TRUE, "" },
|
---|
345 | { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
346 | { "a", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
347 | { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
348 | { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
349 | { "b", 1, buffer, buffer, PR_TRUE, "" },
|
---|
350 | { "c", 7, buffer, buffer, PR_TRUE, "c" },
|
---|
351 | { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
352 | { "de", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
353 | { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
354 | { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
355 | { "fg", 1, buffer, buffer, PR_TRUE, "" },
|
---|
356 | { "hi", 7, buffer, buffer, PR_TRUE, "hi" },
|
---|
357 | { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
358 | { "jklmnopq", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
359 | { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
360 | { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
361 | { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "" },
|
---|
362 | { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDE" },
|
---|
363 | { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
364 | { "a\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
365 | { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
366 | { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
367 | { "b\0XXX", 1, buffer, buffer, PR_TRUE, "" },
|
---|
368 | { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c" },
|
---|
369 | { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
370 | { "de\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
371 | { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
372 | { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
373 | { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "" },
|
---|
374 | { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi" },
|
---|
375 | { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
376 | { "jklmnopq\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
|
---|
377 | { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
378 | { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
|
---|
379 | { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "" },
|
---|
380 | { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDE" },
|
---|
381 | };
|
---|
382 |
|
---|
383 | int i;
|
---|
384 |
|
---|
385 | printf("Test 005 (PL_strncpyz) ..."); fflush(stdout);
|
---|
386 |
|
---|
387 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
388 | {
|
---|
389 | char *rv;
|
---|
390 | int j;
|
---|
391 |
|
---|
392 | for( j = 0; j < sizeof(buffer); j++ )
|
---|
393 | buffer[j] = '-';
|
---|
394 |
|
---|
395 | rv = PL_strncpyz(array[i].dest, array[i].str, array[i].len);
|
---|
396 | if( array[i].rv != rv )
|
---|
397 | {
|
---|
398 | printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest,
|
---|
399 | array[i].str ? array[i].str : "(null)", array[i].len, rv);
|
---|
400 | return PR_FALSE;
|
---|
401 | }
|
---|
402 |
|
---|
403 | if( array[i].comp )
|
---|
404 | {
|
---|
405 | const char *a = array[i].result;
|
---|
406 | const char *b = array[i].dest;
|
---|
407 |
|
---|
408 | while( 1 )
|
---|
409 | {
|
---|
410 | if( *a != *b )
|
---|
411 | {
|
---|
412 | printf("FAIL %d: %s != %.32s\n", i,
|
---|
413 | array[i].result, array[i].dest);
|
---|
414 | return PR_FALSE;
|
---|
415 | }
|
---|
416 |
|
---|
417 | if( (char)0 == *a ) break;
|
---|
418 |
|
---|
419 | a++;
|
---|
420 | b++;
|
---|
421 | }
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | printf("PASS\n");
|
---|
426 | return PR_TRUE;
|
---|
427 | }
|
---|
428 |
|
---|
429 | /* PL_strdup */
|
---|
430 | PRBool test_006(void)
|
---|
431 | {
|
---|
432 | static const char *array[] =
|
---|
433 | {
|
---|
434 | (const char *)0,
|
---|
435 | "",
|
---|
436 | "a",
|
---|
437 | "abcdefg"
|
---|
438 | };
|
---|
439 |
|
---|
440 | int i;
|
---|
441 |
|
---|
442 | printf("Test 006 (PL_strdup) ..."); fflush(stdout);
|
---|
443 |
|
---|
444 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
445 | {
|
---|
446 | char *rv = PL_strdup(array[i]);
|
---|
447 |
|
---|
448 | if( (char *)0 == rv )
|
---|
449 | {
|
---|
450 | printf("FAIL %d: 0x%x -> 0\n", i, array[i]);
|
---|
451 | return PR_FALSE;
|
---|
452 | }
|
---|
453 |
|
---|
454 | if( (const char *)0 == array[i] )
|
---|
455 | {
|
---|
456 | if( (char)0 != *rv )
|
---|
457 | {
|
---|
458 | printf("FAIL %d: (const char *)0 -> %.32s\n", i, rv);
|
---|
459 | return PR_FALSE;
|
---|
460 | }
|
---|
461 | }
|
---|
462 | else
|
---|
463 | {
|
---|
464 | const char *a = array[i];
|
---|
465 | const char *b = (const char *)rv;
|
---|
466 |
|
---|
467 | while( 1 )
|
---|
468 | {
|
---|
469 | if( *a != *b )
|
---|
470 | {
|
---|
471 | printf("FAIL %d: %s != %.32s\n", i, array[i], rv);
|
---|
472 | return PR_FALSE;
|
---|
473 | }
|
---|
474 |
|
---|
475 | if( (char)0 == *a ) break;
|
---|
476 |
|
---|
477 | a++;
|
---|
478 | b++;
|
---|
479 | }
|
---|
480 |
|
---|
481 | }
|
---|
482 | PL_strfree(rv);
|
---|
483 | }
|
---|
484 |
|
---|
485 | printf("PASS\n");
|
---|
486 | return PR_TRUE;
|
---|
487 | }
|
---|
488 |
|
---|
489 | /* PL_strndup */
|
---|
490 | PRBool test_007(void)
|
---|
491 | {
|
---|
492 | static struct
|
---|
493 | {
|
---|
494 | const char *str;
|
---|
495 | PRUint32 len;
|
---|
496 | const char *result;
|
---|
497 | } array[] =
|
---|
498 | {
|
---|
499 | { (const char *)0, 0, "" },
|
---|
500 | { (const char *)0, 1, "" },
|
---|
501 | { (const char *)0, 7, "" },
|
---|
502 | { "", 0, "" },
|
---|
503 | { "", 1, "" },
|
---|
504 | { "", 7, "" },
|
---|
505 | { "a", 0, "" },
|
---|
506 | { "a", 1, "a" },
|
---|
507 | { "a", 7, "a" },
|
---|
508 | { "ab", 0, "" },
|
---|
509 | { "ab", 1, "a" },
|
---|
510 | { "ab", 7, "ab" },
|
---|
511 | { "abcdefg", 0, "" },
|
---|
512 | { "abcdefg", 1, "a" },
|
---|
513 | { "abcdefg", 7, "abcdefg" },
|
---|
514 | { "abcdefghijk", 0, "" },
|
---|
515 | { "abcdefghijk", 1, "a" },
|
---|
516 | { "abcdefghijk", 7, "abcdefg" },
|
---|
517 | { "abcdef\0ghijk", 0, "" },
|
---|
518 | { "abcdef\0ghijk", 1, "a" },
|
---|
519 | { "abcdef\0ghijk", 7, "abcdef" }
|
---|
520 | };
|
---|
521 |
|
---|
522 | int i;
|
---|
523 |
|
---|
524 | printf("Test 007 (PL_strndup) ..."); fflush(stdout);
|
---|
525 |
|
---|
526 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
527 | {
|
---|
528 | char *rv = PL_strndup(array[i].str, array[i].len);
|
---|
529 | const char *a;
|
---|
530 | const char *b;
|
---|
531 |
|
---|
532 | if( (char *)0 == rv )
|
---|
533 | {
|
---|
534 | printf("FAIL %d: %s,%lu -> 0\n", i,
|
---|
535 | array[i].str ? array[i].str : "(null)", array[i].len);
|
---|
536 | return PR_FALSE;
|
---|
537 | }
|
---|
538 |
|
---|
539 | a = array[i].result;
|
---|
540 | b = (const char *)rv;
|
---|
541 |
|
---|
542 | while( 1 )
|
---|
543 | {
|
---|
544 | if( *a != *b )
|
---|
545 | {
|
---|
546 | printf("FAIL %d: %s != %.32s\n", i, array[i].result, rv);
|
---|
547 | return PR_FALSE;
|
---|
548 | }
|
---|
549 |
|
---|
550 | if( (char)0 == *a ) break;
|
---|
551 |
|
---|
552 | a++;
|
---|
553 | b++;
|
---|
554 | }
|
---|
555 |
|
---|
556 | free(rv);
|
---|
557 | }
|
---|
558 |
|
---|
559 | printf("PASS\n");
|
---|
560 | return PR_TRUE;
|
---|
561 | }
|
---|
562 |
|
---|
563 | /* PL_strcat */
|
---|
564 | PRBool test_008(void)
|
---|
565 | {
|
---|
566 | static struct
|
---|
567 | {
|
---|
568 | const char *first;
|
---|
569 | const char *second;
|
---|
570 | const char *result;
|
---|
571 | } array[] =
|
---|
572 | {
|
---|
573 | { (const char *)0, (const char *)0, (const char *)0 },
|
---|
574 | { (const char *)0, "xyz", (const char *)0 },
|
---|
575 | { "", (const char *)0, "" },
|
---|
576 | { "", "", "" },
|
---|
577 | { "ab", "", "ab" },
|
---|
578 | { "cd", "ef", "cdef" },
|
---|
579 | { "gh\0X", "", "gh" },
|
---|
580 | { "ij\0X", "kl", "ijkl" },
|
---|
581 | { "mn\0X", "op\0X", "mnop" },
|
---|
582 | { "qr", "st\0X", "qrst" },
|
---|
583 | { "uv\0X", "wx\0X", "uvwx" }
|
---|
584 | };
|
---|
585 |
|
---|
586 | int i;
|
---|
587 |
|
---|
588 | printf("Test 008 (PL_strcat) ..."); fflush(stdout);
|
---|
589 |
|
---|
590 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
591 | {
|
---|
592 | char buffer[ 1024 ];
|
---|
593 | int j;
|
---|
594 | char *rv;
|
---|
595 |
|
---|
596 | for( j = 0; j < sizeof(buffer); j++ )
|
---|
597 | buffer[j] = '-';
|
---|
598 |
|
---|
599 | if( (const char *)0 != array[i].first )
|
---|
600 | (void)PL_strcpy(buffer, array[i].first);
|
---|
601 |
|
---|
602 | rv = PL_strcat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
|
---|
603 | array[i].second);
|
---|
604 |
|
---|
605 | if( (const char *)0 == array[i].result )
|
---|
606 | {
|
---|
607 | if( (char *)0 != rv )
|
---|
608 | {
|
---|
609 | printf("FAIL %d: %s+%s -> %.32s, not zero\n", i,
|
---|
610 | array[i].first ? array[i].first : "(null)",
|
---|
611 | array[i].second ? array[i].second : "(null)",
|
---|
612 | rv);
|
---|
613 | return PR_FALSE;
|
---|
614 | }
|
---|
615 | }
|
---|
616 | else
|
---|
617 | {
|
---|
618 | if( (char *)0 == rv )
|
---|
619 | {
|
---|
620 | printf("FAIL %d: %s+%s -> null, not %s\n", i,
|
---|
621 | array[i].first ? array[i].first : "(null)",
|
---|
622 | array[i].second ? array[i].second : "(null)",
|
---|
623 | array[i].result);
|
---|
624 | return PR_FALSE;
|
---|
625 | }
|
---|
626 | else
|
---|
627 | {
|
---|
628 | const char *a = array[i].result;
|
---|
629 | const char *b = (const char *)rv;
|
---|
630 |
|
---|
631 | while( 1 )
|
---|
632 | {
|
---|
633 | if( *a != *b )
|
---|
634 | {
|
---|
635 | printf("FAIL %d: %s+%s -> %.32s, not %s\n", i,
|
---|
636 | array[i].first ? array[i].first : "(null)",
|
---|
637 | array[i].second ? array[i].second : "(null)",
|
---|
638 | rv, array[i].result);
|
---|
639 | return PR_FALSE;
|
---|
640 | }
|
---|
641 |
|
---|
642 | if( (char)0 == *a ) break;
|
---|
643 |
|
---|
644 | a++;
|
---|
645 | b++;
|
---|
646 | }
|
---|
647 | }
|
---|
648 | }
|
---|
649 | }
|
---|
650 |
|
---|
651 | printf("PASS\n");
|
---|
652 | return PR_TRUE;
|
---|
653 | }
|
---|
654 |
|
---|
655 | /* PL_strncat */
|
---|
656 | PRBool test_009(void)
|
---|
657 | {
|
---|
658 | static struct
|
---|
659 | {
|
---|
660 | const char *first;
|
---|
661 | const char *second;
|
---|
662 | PRUint32 length;
|
---|
663 | PRBool nulled;
|
---|
664 | const char *result;
|
---|
665 | } array[] =
|
---|
666 | {
|
---|
667 | { (const char *)0, (const char *)0, 0, PR_FALSE, (const char *)0 },
|
---|
668 | { (const char *)0, (const char *)0, 1, PR_FALSE, (const char *)0 },
|
---|
669 | { (const char *)0, (const char *)0, 7, PR_FALSE, (const char *)0 },
|
---|
670 | { (const char *)0, "", 0, PR_FALSE, (const char *)0 },
|
---|
671 | { (const char *)0, "", 1, PR_FALSE, (const char *)0 },
|
---|
672 | { (const char *)0, "", 7, PR_FALSE, (const char *)0 },
|
---|
673 | { (const char *)0, "stuff", 0, PR_FALSE, (const char *)0 },
|
---|
674 | { (const char *)0, "stuff", 1, PR_FALSE, (const char *)0 },
|
---|
675 | { (const char *)0, "stuff", 7, PR_FALSE, (const char *)0 },
|
---|
676 | { "", (const char *)0, 0, PR_TRUE, "" },
|
---|
677 | { "", (const char *)0, 1, PR_TRUE, "" },
|
---|
678 | { "", (const char *)0, 7, PR_TRUE, "" },
|
---|
679 | { "", "", 0, PR_TRUE, "" },
|
---|
680 | { "", "", 1, PR_TRUE, "" },
|
---|
681 | { "", "", 7, PR_TRUE, "" },
|
---|
682 | { "", "abcdefgh", 0, PR_TRUE, "" },
|
---|
683 | { "", "abcdefgh", 1, PR_FALSE, "a" },
|
---|
684 | { "", "abcdefgh", 7, PR_FALSE, "abcdefg" },
|
---|
685 | { "xyz", (const char *)0, 0, PR_TRUE, "xyz" },
|
---|
686 | { "xyz", (const char *)0, 1, PR_TRUE, "xyz" },
|
---|
687 | { "xyz", (const char *)0, 7, PR_TRUE, "xyz" },
|
---|
688 | { "xyz", "", 0, PR_TRUE, "xyz" },
|
---|
689 | { "xyz", "", 1, PR_TRUE, "xyz" },
|
---|
690 | { "xyz", "", 7, PR_TRUE, "xyz" },
|
---|
691 | { "xyz", "abcdefgh", 0, PR_TRUE, "xyz" },
|
---|
692 | { "xyz", "abcdefgh", 1, PR_FALSE, "xyza" },
|
---|
693 | { "xyz", "abcdefgh", 7, PR_FALSE, "xyzabcdefg" }
|
---|
694 | };
|
---|
695 |
|
---|
696 | int i;
|
---|
697 |
|
---|
698 | printf("Test 009 (PL_strncat) ..."); fflush(stdout);
|
---|
699 |
|
---|
700 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
701 | {
|
---|
702 | char buffer[ 1024 ];
|
---|
703 | int j;
|
---|
704 | char *rv;
|
---|
705 |
|
---|
706 | for( j = 0; j < sizeof(buffer); j++ )
|
---|
707 | buffer[j] = '-';
|
---|
708 |
|
---|
709 | if( (const char *)0 != array[i].first )
|
---|
710 | (void)PL_strcpy(buffer, array[i].first);
|
---|
711 |
|
---|
712 | rv = PL_strncat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
|
---|
713 | array[i].second, array[i].length);
|
---|
714 |
|
---|
715 | if( (const char *)0 == array[i].result )
|
---|
716 | {
|
---|
717 | if( (char *)0 != rv )
|
---|
718 | {
|
---|
719 | printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i,
|
---|
720 | array[i].first ? array[i].first : "(null)",
|
---|
721 | array[i].second ? array[i].second : "(null)",
|
---|
722 | array[i].length, rv);
|
---|
723 | return PR_FALSE;
|
---|
724 | }
|
---|
725 | }
|
---|
726 | else
|
---|
727 | {
|
---|
728 | if( (char *)0 == rv )
|
---|
729 | {
|
---|
730 | printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i,
|
---|
731 | array[i].first ? array[i].first : "(null)",
|
---|
732 | array[i].second ? array[i].second : "(null)",
|
---|
733 | array[i].length, array[i].result);
|
---|
734 | return PR_FALSE;
|
---|
735 | }
|
---|
736 | else
|
---|
737 | {
|
---|
738 | const char *a = array[i].result;
|
---|
739 | const char *b = (const char *)rv;
|
---|
740 |
|
---|
741 | while( *a )
|
---|
742 | {
|
---|
743 | if( *a != *b )
|
---|
744 | {
|
---|
745 | printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i,
|
---|
746 | array[i].first ? array[i].first : "(null)",
|
---|
747 | array[i].second ? array[i].second : "(null)",
|
---|
748 | array[i].length, rv, array[i].result);
|
---|
749 | return PR_FALSE;
|
---|
750 | }
|
---|
751 |
|
---|
752 | a++;
|
---|
753 | b++;
|
---|
754 | }
|
---|
755 |
|
---|
756 | if( array[i].nulled )
|
---|
757 | {
|
---|
758 | if( (char)0 != *b )
|
---|
759 | {
|
---|
760 | printf("FAIL %d: %s+%s/%lu -> not nulled\n", i,
|
---|
761 | array[i].first ? array[i].first : "(null)",
|
---|
762 | array[i].second ? array[i].second : "(null)",
|
---|
763 | array[i].length);
|
---|
764 | return PR_FALSE;
|
---|
765 | }
|
---|
766 | }
|
---|
767 | else
|
---|
768 | {
|
---|
769 | if( (char)0 == *b )
|
---|
770 | {
|
---|
771 | printf("FAIL %d: %s+%s/%lu -> overrun\n", i,
|
---|
772 | array[i].first ? array[i].first : "(null)",
|
---|
773 | array[i].second ? array[i].second : "(null)",
|
---|
774 | array[i].length);
|
---|
775 | return PR_FALSE;
|
---|
776 | }
|
---|
777 | }
|
---|
778 | }
|
---|
779 | }
|
---|
780 | }
|
---|
781 |
|
---|
782 | printf("PASS\n");
|
---|
783 | return PR_TRUE;
|
---|
784 | }
|
---|
785 |
|
---|
786 | /* PL_strcatn */
|
---|
787 | PRBool test_010(void)
|
---|
788 | {
|
---|
789 | static struct
|
---|
790 | {
|
---|
791 | const char *first;
|
---|
792 | const char *second;
|
---|
793 | PRUint32 length;
|
---|
794 | const char *result;
|
---|
795 | } array[] =
|
---|
796 | {
|
---|
797 | { (const char *)0, (const char *)0, 0, (const char *)0 },
|
---|
798 | { (const char *)0, (const char *)0, 1, (const char *)0 },
|
---|
799 | { (const char *)0, (const char *)0, 7, (const char *)0 },
|
---|
800 | { (const char *)0, "", 0, (const char *)0 },
|
---|
801 | { (const char *)0, "", 1, (const char *)0 },
|
---|
802 | { (const char *)0, "", 7, (const char *)0 },
|
---|
803 | { (const char *)0, "stuff", 0, (const char *)0 },
|
---|
804 | { (const char *)0, "stuff", 1, (const char *)0 },
|
---|
805 | { (const char *)0, "stuff", 7, (const char *)0 },
|
---|
806 | { "", (const char *)0, 0, "" },
|
---|
807 | { "", (const char *)0, 1, "" },
|
---|
808 | { "", (const char *)0, 7, "" },
|
---|
809 | { "", "", 0, "" },
|
---|
810 | { "", "", 1, "" },
|
---|
811 | { "", "", 7, "" },
|
---|
812 | { "", "abcdefgh", 0, "" },
|
---|
813 | { "", "abcdefgh", 1, "" },
|
---|
814 | { "", "abcdefgh", 7, "abcdef" },
|
---|
815 | { "xyz", (const char *)0, 0, "xyz" },
|
---|
816 | { "xyz", (const char *)0, 1, "xyz" },
|
---|
817 | { "xyz", (const char *)0, 7, "xyz" },
|
---|
818 | { "xyz", "", 0, "xyz" },
|
---|
819 | { "xyz", "", 1, "xyz" },
|
---|
820 | { "xyz", "", 7, "xyz" },
|
---|
821 | { "xyz", "abcdefgh", 0, "xyz" },
|
---|
822 | { "xyz", "abcdefgh", 1, "xyz" },
|
---|
823 | { "xyz", "abcdefgh", 7, "xyzabc" }
|
---|
824 | };
|
---|
825 |
|
---|
826 | int i;
|
---|
827 |
|
---|
828 | printf("Test 010 (PL_strcatn) ..."); fflush(stdout);
|
---|
829 |
|
---|
830 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
831 | {
|
---|
832 | char buffer[ 1024 ];
|
---|
833 | int j;
|
---|
834 | char *rv;
|
---|
835 |
|
---|
836 | for( j = 0; j < sizeof(buffer); j++ )
|
---|
837 | buffer[j] = '-';
|
---|
838 |
|
---|
839 | if( (const char *)0 != array[i].first )
|
---|
840 | (void)PL_strcpy(buffer, array[i].first);
|
---|
841 |
|
---|
842 | rv = PL_strcatn(((const char *)0 == array[i].first) ? (char *)0 : buffer,
|
---|
843 | array[i].length, array[i].second);
|
---|
844 |
|
---|
845 | if( (const char *)0 == array[i].result )
|
---|
846 | {
|
---|
847 | if( (char *)0 != rv )
|
---|
848 | {
|
---|
849 | printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i,
|
---|
850 | array[i].first ? array[i].first : "(null)",
|
---|
851 | array[i].second ? array[i].second : "(null)",
|
---|
852 | array[i].length, rv);
|
---|
853 | return PR_FALSE;
|
---|
854 | }
|
---|
855 | }
|
---|
856 | else
|
---|
857 | {
|
---|
858 | if( (char *)0 == rv )
|
---|
859 | {
|
---|
860 | printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i,
|
---|
861 | array[i].first ? array[i].first : "(null)",
|
---|
862 | array[i].second ? array[i].second : "(null)",
|
---|
863 | array[i].length, array[i].result);
|
---|
864 | return PR_FALSE;
|
---|
865 | }
|
---|
866 | else
|
---|
867 | {
|
---|
868 | const char *a = array[i].result;
|
---|
869 | const char *b = (const char *)rv;
|
---|
870 |
|
---|
871 | while( 1 )
|
---|
872 | {
|
---|
873 | if( *a != *b )
|
---|
874 | {
|
---|
875 | printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i,
|
---|
876 | array[i].first ? array[i].first : "(null)",
|
---|
877 | array[i].second ? array[i].second : "(null)",
|
---|
878 | array[i].length, rv, array[i].result);
|
---|
879 | return PR_FALSE;
|
---|
880 | }
|
---|
881 |
|
---|
882 | if( (char)0 == *a ) break;
|
---|
883 |
|
---|
884 | a++;
|
---|
885 | b++;
|
---|
886 | }
|
---|
887 | }
|
---|
888 | }
|
---|
889 | }
|
---|
890 |
|
---|
891 | printf("PASS\n");
|
---|
892 | return PR_TRUE;
|
---|
893 | }
|
---|
894 |
|
---|
895 | /* PL_strcmp */
|
---|
896 | PRBool test_011(void)
|
---|
897 | {
|
---|
898 | static struct
|
---|
899 | {
|
---|
900 | const char *one;
|
---|
901 | const char *two;
|
---|
902 | PRIntn sign;
|
---|
903 | } array[] =
|
---|
904 | {
|
---|
905 | { (const char *)0, (const char *)0, 0 },
|
---|
906 | { (const char *)0, "word", -1 },
|
---|
907 | { "word", (const char *)0, 1 },
|
---|
908 | { "word", "word", 0 },
|
---|
909 | { "aZYXVUT", "bZYXVUT", -1 },
|
---|
910 | { "aZYXVUT", "bAAAAAA", -1 },
|
---|
911 | { "a", "aa", -1 },
|
---|
912 | { "a", "a", 0 },
|
---|
913 | { "a", "A", 1 },
|
---|
914 | { "aaaaa", "baaaa", -1 },
|
---|
915 | { "aaaaa", "abaaa", -1 },
|
---|
916 | { "aaaaa", "aabaa", -1 },
|
---|
917 | { "aaaaa", "aaaba", -1 },
|
---|
918 | { "aaaaa", "aaaab", -1 },
|
---|
919 | { "bZYXVUT", "aZYXVUT", 1 },
|
---|
920 | { "bAAAAAA", "aZYXVUT", 1 },
|
---|
921 | { "aa", "a", 1 },
|
---|
922 | { "A", "a", -1 },
|
---|
923 | { "baaaa", "aaaaa", 1 },
|
---|
924 | { "abaaa", "aaaaa", 1 },
|
---|
925 | { "aabaa", "aaaaa", 1 },
|
---|
926 | { "aaaba", "aaaaa", 1 },
|
---|
927 | { "aaaab", "aaaaa", 1 },
|
---|
928 | { "word", "Word", 1 },
|
---|
929 | { "word", "wOrd", 1 },
|
---|
930 | { "word", "woRd", 1 },
|
---|
931 | { "word", "worD", 1 },
|
---|
932 | { "WORD", "wORD", -1 },
|
---|
933 | { "WORD", "WoRD", -1 },
|
---|
934 | { "WORD", "WOrD", -1 },
|
---|
935 | { "WORD", "WORd", -1 }
|
---|
936 | };
|
---|
937 |
|
---|
938 | int i;
|
---|
939 |
|
---|
940 | printf("Test 011 (PL_strcmp) ..."); fflush(stdout);
|
---|
941 |
|
---|
942 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
943 | {
|
---|
944 | PRIntn rv = PL_strcmp(array[i].one, array[i].two);
|
---|
945 |
|
---|
946 | switch( array[i].sign )
|
---|
947 | {
|
---|
948 | case -1:
|
---|
949 | if( rv < 0 ) continue;
|
---|
950 | break;
|
---|
951 | case 1:
|
---|
952 | if( rv > 0 ) continue;
|
---|
953 | break;
|
---|
954 | case 0:
|
---|
955 | if( 0 == rv ) continue;
|
---|
956 | break;
|
---|
957 | default:
|
---|
958 | PR_NOT_REACHED("static data inconsistancy");
|
---|
959 | break;
|
---|
960 | }
|
---|
961 |
|
---|
962 | printf("FAIL %d: %s-%s -> %d, not %d\n", i,
|
---|
963 | array[i].one ? array[i].one : "(null)",
|
---|
964 | array[i].two ? array[i].two : "(null)",
|
---|
965 | rv, array[i].sign);
|
---|
966 | return PR_FALSE;
|
---|
967 | }
|
---|
968 |
|
---|
969 | printf("PASS\n");
|
---|
970 | return PR_TRUE;
|
---|
971 | }
|
---|
972 |
|
---|
973 | /* PL_strncmp */
|
---|
974 | PRBool test_012(void)
|
---|
975 | {
|
---|
976 | static struct
|
---|
977 | {
|
---|
978 | const char *one;
|
---|
979 | const char *two;
|
---|
980 | PRUint32 max;
|
---|
981 | PRIntn sign;
|
---|
982 | } array[] =
|
---|
983 | {
|
---|
984 | { (const char *)0, (const char *)0, 0, 0 },
|
---|
985 | { (const char *)0, (const char *)0, 1, 0 },
|
---|
986 | { (const char *)0, (const char *)0, 4, 0 },
|
---|
987 | { (const char *)0, "word", 0, -1 },
|
---|
988 | { (const char *)0, "word", 1, -1 },
|
---|
989 | { (const char *)0, "word", 4, -1 },
|
---|
990 | { "word", (const char *)0, 0, 1 },
|
---|
991 | { "word", (const char *)0, 1, 1 },
|
---|
992 | { "word", (const char *)0, 4, 1 },
|
---|
993 | { "word", "word", 0, 0 },
|
---|
994 | { "word", "word", 1, 0 },
|
---|
995 | { "word", "word", 3, 0 },
|
---|
996 | { "word", "word", 5, 0 },
|
---|
997 | { "aZYXVUT", "bZYXVUT", 0, 0 },
|
---|
998 | { "aZYXVUT", "bZYXVUT", 1, -1 },
|
---|
999 | { "aZYXVUT", "bZYXVUT", 4, -1 },
|
---|
1000 | { "aZYXVUT", "bZYXVUT", 9, -1 },
|
---|
1001 | { "aZYXVUT", "bAAAAAA", 0, 0 },
|
---|
1002 | { "aZYXVUT", "bAAAAAA", 1, -1 },
|
---|
1003 | { "aZYXVUT", "bAAAAAA", 4, -1 },
|
---|
1004 | { "aZYXVUT", "bAAAAAA", 5, -1 },
|
---|
1005 | { "a", "aa", 0, 0 },
|
---|
1006 | { "a", "aa", 1, 0 },
|
---|
1007 | { "a", "aa", 4, -1 },
|
---|
1008 | { "a", "a", 0, 0 },
|
---|
1009 | { "a", "a", 1, 0 },
|
---|
1010 | { "a", "a", 4, 0 },
|
---|
1011 | { "a", "A", 0, 0 },
|
---|
1012 | { "a", "A", 1, 1 },
|
---|
1013 | { "a", "A", 4, 1 },
|
---|
1014 | { "aaaaa", "baaaa", 0, 0 },
|
---|
1015 | { "aaaaa", "baaaa", 1, -1 },
|
---|
1016 | { "aaaaa", "baaaa", 4, -1 },
|
---|
1017 | { "aaaaa", "abaaa", 0, 0 },
|
---|
1018 | { "aaaaa", "abaaa", 1, 0 },
|
---|
1019 | { "aaaaa", "abaaa", 4, -1 },
|
---|
1020 | { "aaaaa", "aabaa", 0, 0 },
|
---|
1021 | { "aaaaa", "aabaa", 1, 0 },
|
---|
1022 | { "aaaaa", "aabaa", 4, -1 },
|
---|
1023 | { "aaaaa", "aaaba", 0, 0 },
|
---|
1024 | { "aaaaa", "aaaba", 1, 0 },
|
---|
1025 | { "aaaaa", "aaaba", 4, -1 },
|
---|
1026 | { "aaaaa", "aaaab", 0, 0 },
|
---|
1027 | { "aaaaa", "aaaab", 1, 0 },
|
---|
1028 | { "aaaaa", "aaaab", 4, 0 },
|
---|
1029 | { "bZYXVUT", "aZYXVUT", 0, 0 },
|
---|
1030 | { "bZYXVUT", "aZYXVUT", 1, 1 },
|
---|
1031 | { "bZYXVUT", "aZYXVUT", 4, 1 },
|
---|
1032 | { "bAAAAAA", "aZYXVUT", 0, 0 },
|
---|
1033 | { "bAAAAAA", "aZYXVUT", 1, 1 },
|
---|
1034 | { "bAAAAAA", "aZYXVUT", 4, 1 },
|
---|
1035 | { "aa", "a", 0, 0 },
|
---|
1036 | { "aa", "a", 1, 0 },
|
---|
1037 | { "aa", "a", 4, 1 },
|
---|
1038 | { "A", "a", 0, 0 },
|
---|
1039 | { "A", "a", 1, -1 },
|
---|
1040 | { "A", "a", 4, -1 },
|
---|
1041 | { "baaaa", "aaaaa", 0, 0 },
|
---|
1042 | { "baaaa", "aaaaa", 1, 1 },
|
---|
1043 | { "baaaa", "aaaaa", 4, 1 },
|
---|
1044 | { "abaaa", "aaaaa", 0, 0 },
|
---|
1045 | { "abaaa", "aaaaa", 1, 0 },
|
---|
1046 | { "abaaa", "aaaaa", 4, 1 },
|
---|
1047 | { "aabaa", "aaaaa", 0, 0 },
|
---|
1048 | { "aabaa", "aaaaa", 1, 0 },
|
---|
1049 | { "aabaa", "aaaaa", 4, 1 },
|
---|
1050 | { "aaaba", "aaaaa", 0, 0 },
|
---|
1051 | { "aaaba", "aaaaa", 1, 0 },
|
---|
1052 | { "aaaba", "aaaaa", 4, 1 },
|
---|
1053 | { "aaaab", "aaaaa", 0, 0 },
|
---|
1054 | { "aaaab", "aaaaa", 1, 0 },
|
---|
1055 | { "aaaab", "aaaaa", 4, 0 },
|
---|
1056 | { "word", "Word", 0, 0 },
|
---|
1057 | { "word", "Word", 1, 1 },
|
---|
1058 | { "word", "Word", 3, 1 },
|
---|
1059 | { "word", "wOrd", 0, 0 },
|
---|
1060 | { "word", "wOrd", 1, 0 },
|
---|
1061 | { "word", "wOrd", 3, 1 },
|
---|
1062 | { "word", "woRd", 0, 0 },
|
---|
1063 | { "word", "woRd", 1, 0 },
|
---|
1064 | { "word", "woRd", 3, 1 },
|
---|
1065 | { "word", "worD", 0, 0 },
|
---|
1066 | { "word", "worD", 1, 0 },
|
---|
1067 | { "word", "worD", 3, 0 },
|
---|
1068 | { "WORD", "wORD", 0, 0 },
|
---|
1069 | { "WORD", "wORD", 1, -1 },
|
---|
1070 | { "WORD", "wORD", 3, -1 },
|
---|
1071 | { "WORD", "WoRD", 0, 0 },
|
---|
1072 | { "WORD", "WoRD", 1, 0 },
|
---|
1073 | { "WORD", "WoRD", 3, -1 },
|
---|
1074 | { "WORD", "WOrD", 0, 0 },
|
---|
1075 | { "WORD", "WOrD", 1, 0 },
|
---|
1076 | { "WORD", "WOrD", 3, -1 },
|
---|
1077 | { "WORD", "WORd", 0, 0 },
|
---|
1078 | { "WORD", "WORd", 1, 0 },
|
---|
1079 | { "WORD", "WORd", 3, 0 }
|
---|
1080 |
|
---|
1081 | };
|
---|
1082 |
|
---|
1083 | int i;
|
---|
1084 |
|
---|
1085 | printf("Test 012 (PL_strncmp) ..."); fflush(stdout);
|
---|
1086 |
|
---|
1087 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1088 | {
|
---|
1089 | PRIntn rv = PL_strncmp(array[i].one, array[i].two, array[i].max);
|
---|
1090 |
|
---|
1091 | switch( array[i].sign )
|
---|
1092 | {
|
---|
1093 | case -1:
|
---|
1094 | if( rv < 0 ) continue;
|
---|
1095 | break;
|
---|
1096 | case 1:
|
---|
1097 | if( rv > 0 ) continue;
|
---|
1098 | break;
|
---|
1099 | case 0:
|
---|
1100 | if( 0 == rv ) continue;
|
---|
1101 | break;
|
---|
1102 | default:
|
---|
1103 | PR_NOT_REACHED("static data inconsistancy");
|
---|
1104 | break;
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,
|
---|
1108 | array[i].one ? array[i].one : "(null)",
|
---|
1109 | array[i].two ? array[i].two : "(null)",
|
---|
1110 | array[i].max, rv, array[i].sign);
|
---|
1111 | return PR_FALSE;
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | printf("PASS\n");
|
---|
1115 | return PR_TRUE;
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | /* PL_strcasecmp */
|
---|
1119 | PRBool test_013(void)
|
---|
1120 | {
|
---|
1121 | static struct
|
---|
1122 | {
|
---|
1123 | const char *one;
|
---|
1124 | const char *two;
|
---|
1125 | PRIntn sign;
|
---|
1126 | } array[] =
|
---|
1127 | {
|
---|
1128 | { (const char *)0, (const char *)0, 0 },
|
---|
1129 | { (const char *)0, "word", -1 },
|
---|
1130 | { "word", (const char *)0, 1 },
|
---|
1131 | { "word", "word", 0 },
|
---|
1132 | { "aZYXVUT", "bZYXVUT", -1 },
|
---|
1133 | { "aZYXVUT", "bAAAAAA", -1 },
|
---|
1134 | { "a", "aa", -1 },
|
---|
1135 | { "a", "a", 0 },
|
---|
1136 | { "a", "A", 0 },
|
---|
1137 | { "aaaaa", "baaaa", -1 },
|
---|
1138 | { "aaaaa", "abaaa", -1 },
|
---|
1139 | { "aaaaa", "aabaa", -1 },
|
---|
1140 | { "aaaaa", "aaaba", -1 },
|
---|
1141 | { "aaaaa", "aaaab", -1 },
|
---|
1142 | { "bZYXVUT", "aZYXVUT", 1 },
|
---|
1143 | { "bAAAAAA", "aZYXVUT", 1 },
|
---|
1144 | { "aa", "a", 1 },
|
---|
1145 | { "A", "a", 0 },
|
---|
1146 | { "baaaa", "aaaaa", 1 },
|
---|
1147 | { "abaaa", "aaaaa", 1 },
|
---|
1148 | { "aabaa", "aaaaa", 1 },
|
---|
1149 | { "aaaba", "aaaaa", 1 },
|
---|
1150 | { "aaaab", "aaaaa", 1 },
|
---|
1151 | { "word", "Word", 0 },
|
---|
1152 | { "word", "wOrd", 0 },
|
---|
1153 | { "word", "woRd", 0 },
|
---|
1154 | { "word", "worD", 0 },
|
---|
1155 | { "WORD", "wORD", 0 },
|
---|
1156 | { "WORD", "WoRD", 0 },
|
---|
1157 | { "WORD", "WOrD", 0 },
|
---|
1158 | { "WORD", "WORd", 0 }
|
---|
1159 | };
|
---|
1160 |
|
---|
1161 | int i;
|
---|
1162 |
|
---|
1163 | printf("Test 013 (PL_strcasecmp) ..."); fflush(stdout);
|
---|
1164 |
|
---|
1165 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1166 | {
|
---|
1167 | PRIntn rv = PL_strcasecmp(array[i].one, array[i].two);
|
---|
1168 |
|
---|
1169 | switch( array[i].sign )
|
---|
1170 | {
|
---|
1171 | case -1:
|
---|
1172 | if( rv < 0 ) continue;
|
---|
1173 | break;
|
---|
1174 | case 1:
|
---|
1175 | if( rv > 0 ) continue;
|
---|
1176 | break;
|
---|
1177 | case 0:
|
---|
1178 | if( 0 == rv ) continue;
|
---|
1179 | break;
|
---|
1180 | default:
|
---|
1181 | PR_NOT_REACHED("static data inconsistancy");
|
---|
1182 | break;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | printf("FAIL %d: %s-%s -> %d, not %d\n", i,
|
---|
1186 | array[i].one ? array[i].one : "(null)",
|
---|
1187 | array[i].two ? array[i].two : "(null)",
|
---|
1188 | rv, array[i].sign);
|
---|
1189 | return PR_FALSE;
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | printf("PASS\n");
|
---|
1193 | return PR_TRUE;
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | /* PL_strncasecmp */
|
---|
1197 | PRBool test_014(void)
|
---|
1198 | {
|
---|
1199 | static struct
|
---|
1200 | {
|
---|
1201 | const char *one;
|
---|
1202 | const char *two;
|
---|
1203 | PRUint32 max;
|
---|
1204 | PRIntn sign;
|
---|
1205 | } array[] =
|
---|
1206 | {
|
---|
1207 | { (const char *)0, (const char *)0, 0, 0 },
|
---|
1208 | { (const char *)0, (const char *)0, 1, 0 },
|
---|
1209 | { (const char *)0, (const char *)0, 4, 0 },
|
---|
1210 | { (const char *)0, "word", 0, -1 },
|
---|
1211 | { (const char *)0, "word", 1, -1 },
|
---|
1212 | { (const char *)0, "word", 4, -1 },
|
---|
1213 | { "word", (const char *)0, 0, 1 },
|
---|
1214 | { "word", (const char *)0, 1, 1 },
|
---|
1215 | { "word", (const char *)0, 4, 1 },
|
---|
1216 | { "word", "word", 0, 0 },
|
---|
1217 | { "word", "word", 1, 0 },
|
---|
1218 | { "word", "word", 3, 0 },
|
---|
1219 | { "word", "word", 5, 0 },
|
---|
1220 | { "aZYXVUT", "bZYXVUT", 0, 0 },
|
---|
1221 | { "aZYXVUT", "bZYXVUT", 1, -1 },
|
---|
1222 | { "aZYXVUT", "bZYXVUT", 4, -1 },
|
---|
1223 | { "aZYXVUT", "bZYXVUT", 9, -1 },
|
---|
1224 | { "aZYXVUT", "bAAAAAA", 0, 0 },
|
---|
1225 | { "aZYXVUT", "bAAAAAA", 1, -1 },
|
---|
1226 | { "aZYXVUT", "bAAAAAA", 4, -1 },
|
---|
1227 | { "aZYXVUT", "bAAAAAA", 5, -1 },
|
---|
1228 | { "a", "aa", 0, 0 },
|
---|
1229 | { "a", "aa", 1, 0 },
|
---|
1230 | { "a", "aa", 4, -1 },
|
---|
1231 | { "a", "a", 0, 0 },
|
---|
1232 | { "a", "a", 1, 0 },
|
---|
1233 | { "a", "a", 4, 0 },
|
---|
1234 | { "a", "A", 0, 0 },
|
---|
1235 | { "a", "A", 1, 0 },
|
---|
1236 | { "a", "A", 4, 0 },
|
---|
1237 | { "aaaaa", "baaaa", 0, 0 },
|
---|
1238 | { "aaaaa", "baaaa", 1, -1 },
|
---|
1239 | { "aaaaa", "baaaa", 4, -1 },
|
---|
1240 | { "aaaaa", "abaaa", 0, 0 },
|
---|
1241 | { "aaaaa", "abaaa", 1, 0 },
|
---|
1242 | { "aaaaa", "abaaa", 4, -1 },
|
---|
1243 | { "aaaaa", "aabaa", 0, 0 },
|
---|
1244 | { "aaaaa", "aabaa", 1, 0 },
|
---|
1245 | { "aaaaa", "aabaa", 4, -1 },
|
---|
1246 | { "aaaaa", "aaaba", 0, 0 },
|
---|
1247 | { "aaaaa", "aaaba", 1, 0 },
|
---|
1248 | { "aaaaa", "aaaba", 4, -1 },
|
---|
1249 | { "aaaaa", "aaaab", 0, 0 },
|
---|
1250 | { "aaaaa", "aaaab", 1, 0 },
|
---|
1251 | { "aaaaa", "aaaab", 4, 0 },
|
---|
1252 | { "bZYXVUT", "aZYXVUT", 0, 0 },
|
---|
1253 | { "bZYXVUT", "aZYXVUT", 1, 1 },
|
---|
1254 | { "bZYXVUT", "aZYXVUT", 4, 1 },
|
---|
1255 | { "bAAAAAA", "aZYXVUT", 0, 0 },
|
---|
1256 | { "bAAAAAA", "aZYXVUT", 1, 1 },
|
---|
1257 | { "bAAAAAA", "aZYXVUT", 4, 1 },
|
---|
1258 | { "aa", "a", 0, 0 },
|
---|
1259 | { "aa", "a", 1, 0 },
|
---|
1260 | { "aa", "a", 4, 1 },
|
---|
1261 | { "A", "a", 0, 0 },
|
---|
1262 | { "A", "a", 1, 0 },
|
---|
1263 | { "A", "a", 4, 0 },
|
---|
1264 | { "baaaa", "aaaaa", 0, 0 },
|
---|
1265 | { "baaaa", "aaaaa", 1, 1 },
|
---|
1266 | { "baaaa", "aaaaa", 4, 1 },
|
---|
1267 | { "abaaa", "aaaaa", 0, 0 },
|
---|
1268 | { "abaaa", "aaaaa", 1, 0 },
|
---|
1269 | { "abaaa", "aaaaa", 4, 1 },
|
---|
1270 | { "aabaa", "aaaaa", 0, 0 },
|
---|
1271 | { "aabaa", "aaaaa", 1, 0 },
|
---|
1272 | { "aabaa", "aaaaa", 4, 1 },
|
---|
1273 | { "aaaba", "aaaaa", 0, 0 },
|
---|
1274 | { "aaaba", "aaaaa", 1, 0 },
|
---|
1275 | { "aaaba", "aaaaa", 4, 1 },
|
---|
1276 | { "aaaab", "aaaaa", 0, 0 },
|
---|
1277 | { "aaaab", "aaaaa", 1, 0 },
|
---|
1278 | { "aaaab", "aaaaa", 4, 0 },
|
---|
1279 | { "word", "Word", 0, 0 },
|
---|
1280 | { "word", "Word", 1, 0 },
|
---|
1281 | { "word", "Word", 3, 0 },
|
---|
1282 | { "word", "wOrd", 0, 0 },
|
---|
1283 | { "word", "wOrd", 1, 0 },
|
---|
1284 | { "word", "wOrd", 3, 0 },
|
---|
1285 | { "word", "woRd", 0, 0 },
|
---|
1286 | { "word", "woRd", 1, 0 },
|
---|
1287 | { "word", "woRd", 3, 0 },
|
---|
1288 | { "word", "worD", 0, 0 },
|
---|
1289 | { "word", "worD", 1, 0 },
|
---|
1290 | { "word", "worD", 3, 0 },
|
---|
1291 | { "WORD", "wORD", 0, 0 },
|
---|
1292 | { "WORD", "wORD", 1, 0 },
|
---|
1293 | { "WORD", "wORD", 3, 0 },
|
---|
1294 | { "WORD", "WoRD", 0, 0 },
|
---|
1295 | { "WORD", "WoRD", 1, 0 },
|
---|
1296 | { "WORD", "WoRD", 3, 0 },
|
---|
1297 | { "WORD", "WOrD", 0, 0 },
|
---|
1298 | { "WORD", "WOrD", 1, 0 },
|
---|
1299 | { "WORD", "WOrD", 3, 0 },
|
---|
1300 | { "WORD", "WORd", 0, 0 },
|
---|
1301 | { "WORD", "WORd", 1, 0 },
|
---|
1302 | { "WORD", "WORd", 3, 0 }
|
---|
1303 | };
|
---|
1304 |
|
---|
1305 | int i;
|
---|
1306 |
|
---|
1307 | printf("Test 014 (PL_strncasecmp) ..."); fflush(stdout);
|
---|
1308 |
|
---|
1309 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1310 | {
|
---|
1311 | PRIntn rv = PL_strncasecmp(array[i].one, array[i].two, array[i].max);
|
---|
1312 |
|
---|
1313 | switch( array[i].sign )
|
---|
1314 | {
|
---|
1315 | case -1:
|
---|
1316 | if( rv < 0 ) continue;
|
---|
1317 | break;
|
---|
1318 | case 1:
|
---|
1319 | if( rv > 0 ) continue;
|
---|
1320 | break;
|
---|
1321 | case 0:
|
---|
1322 | if( 0 == rv ) continue;
|
---|
1323 | break;
|
---|
1324 | default:
|
---|
1325 | PR_NOT_REACHED("static data inconsistancy");
|
---|
1326 | break;
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,
|
---|
1330 | array[i].one ? array[i].one : "(null)",
|
---|
1331 | array[i].two ? array[i].two : "(null)",
|
---|
1332 | array[i].max, rv, array[i].sign);
|
---|
1333 | return PR_FALSE;
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | printf("PASS\n");
|
---|
1337 | return PR_TRUE;
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | /* PL_strchr */
|
---|
1341 | PRBool test_015(void)
|
---|
1342 | {
|
---|
1343 | static struct
|
---|
1344 | {
|
---|
1345 | const char *str;
|
---|
1346 | char chr;
|
---|
1347 | PRBool ret;
|
---|
1348 | PRUint32 off;
|
---|
1349 | } array[] =
|
---|
1350 | {
|
---|
1351 | { (const char *)0, 'a', PR_FALSE, 0 },
|
---|
1352 | { (const char *)0, '\0', PR_FALSE, 0 },
|
---|
1353 | { "abcdefg", 'a', PR_TRUE, 0 },
|
---|
1354 | { "abcdefg", 'b', PR_TRUE, 1 },
|
---|
1355 | { "abcdefg", 'c', PR_TRUE, 2 },
|
---|
1356 | { "abcdefg", 'd', PR_TRUE, 3 },
|
---|
1357 | { "abcdefg", 'e', PR_TRUE, 4 },
|
---|
1358 | { "abcdefg", 'f', PR_TRUE, 5 },
|
---|
1359 | { "abcdefg", 'g', PR_TRUE, 6 },
|
---|
1360 | { "abcdefg", 'h', PR_FALSE, 0 },
|
---|
1361 | { "abcdefg", '\0', PR_TRUE, 7 },
|
---|
1362 | { "abcdefg", 'A', PR_FALSE, 0 },
|
---|
1363 | { "abcdefg", 'B', PR_FALSE, 0 },
|
---|
1364 | { "abcdefg", 'C', PR_FALSE, 0 },
|
---|
1365 | { "abcdefg", 'D', PR_FALSE, 0 },
|
---|
1366 | { "abcdefg", 'E', PR_FALSE, 0 },
|
---|
1367 | { "abcdefg", 'F', PR_FALSE, 0 },
|
---|
1368 | { "abcdefg", 'G', PR_FALSE, 0 },
|
---|
1369 | { "abcdefg", 'H', PR_FALSE, 0 },
|
---|
1370 | { "abcdefgabcdefg", 'a', PR_TRUE, 0 },
|
---|
1371 | { "abcdefgabcdefg", 'b', PR_TRUE, 1 },
|
---|
1372 | { "abcdefgabcdefg", 'c', PR_TRUE, 2 },
|
---|
1373 | { "abcdefgabcdefg", 'd', PR_TRUE, 3 },
|
---|
1374 | { "abcdefgabcdefg", 'e', PR_TRUE, 4 },
|
---|
1375 | { "abcdefgabcdefg", 'f', PR_TRUE, 5 },
|
---|
1376 | { "abcdefgabcdefg", 'g', PR_TRUE, 6 },
|
---|
1377 | { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
|
---|
1378 | { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
|
---|
1379 | };
|
---|
1380 |
|
---|
1381 | int i;
|
---|
1382 |
|
---|
1383 | printf("Test 015 (PL_strchr) ..."); fflush(stdout);
|
---|
1384 |
|
---|
1385 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1386 | {
|
---|
1387 | char *rv = PL_strchr(array[i].str, array[i].chr);
|
---|
1388 |
|
---|
1389 | if( PR_FALSE == array[i].ret )
|
---|
1390 | {
|
---|
1391 | if( (char *)0 != rv )
|
---|
1392 | {
|
---|
1393 | printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,
|
---|
1394 | array[i].chr, rv);
|
---|
1395 | return PR_FALSE;
|
---|
1396 | }
|
---|
1397 | }
|
---|
1398 | else
|
---|
1399 | {
|
---|
1400 | if( (char *)0 == rv )
|
---|
1401 | {
|
---|
1402 | printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,
|
---|
1403 | array[i].chr, array[i].off);
|
---|
1404 | return PR_FALSE;
|
---|
1405 | }
|
---|
1406 |
|
---|
1407 | if( &array[i].str[ array[i].off ] != rv )
|
---|
1408 | {
|
---|
1409 | printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
|
---|
1410 | array[i].chr, rv, array[i].str, array[i].off);
|
---|
1411 | return PR_FALSE;
|
---|
1412 | }
|
---|
1413 | }
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | printf("PASS\n");
|
---|
1417 | return PR_TRUE;
|
---|
1418 | }
|
---|
1419 |
|
---|
1420 | /* PL_strrchr */
|
---|
1421 | PRBool test_016(void)
|
---|
1422 | {
|
---|
1423 | static struct
|
---|
1424 | {
|
---|
1425 | const char *str;
|
---|
1426 | char chr;
|
---|
1427 | PRBool ret;
|
---|
1428 | PRUint32 off;
|
---|
1429 | } array[] =
|
---|
1430 | {
|
---|
1431 | { (const char *)0, 'a', PR_FALSE, 0 },
|
---|
1432 | { (const char *)0, '\0', PR_FALSE, 0 },
|
---|
1433 | { "abcdefg", 'a', PR_TRUE, 0 },
|
---|
1434 | { "abcdefg", 'b', PR_TRUE, 1 },
|
---|
1435 | { "abcdefg", 'c', PR_TRUE, 2 },
|
---|
1436 | { "abcdefg", 'd', PR_TRUE, 3 },
|
---|
1437 | { "abcdefg", 'e', PR_TRUE, 4 },
|
---|
1438 | { "abcdefg", 'f', PR_TRUE, 5 },
|
---|
1439 | { "abcdefg", 'g', PR_TRUE, 6 },
|
---|
1440 | { "abcdefg", 'h', PR_FALSE, 0 },
|
---|
1441 | { "abcdefg", '\0', PR_TRUE, 7 },
|
---|
1442 | { "abcdefg", 'A', PR_FALSE, 0 },
|
---|
1443 | { "abcdefg", 'B', PR_FALSE, 0 },
|
---|
1444 | { "abcdefg", 'C', PR_FALSE, 0 },
|
---|
1445 | { "abcdefg", 'D', PR_FALSE, 0 },
|
---|
1446 | { "abcdefg", 'E', PR_FALSE, 0 },
|
---|
1447 | { "abcdefg", 'F', PR_FALSE, 0 },
|
---|
1448 | { "abcdefg", 'G', PR_FALSE, 0 },
|
---|
1449 | { "abcdefg", 'H', PR_FALSE, 0 },
|
---|
1450 | { "abcdefgabcdefg", 'a', PR_TRUE, 7 },
|
---|
1451 | { "abcdefgabcdefg", 'b', PR_TRUE, 8 },
|
---|
1452 | { "abcdefgabcdefg", 'c', PR_TRUE, 9 },
|
---|
1453 | { "abcdefgabcdefg", 'd', PR_TRUE, 10 },
|
---|
1454 | { "abcdefgabcdefg", 'e', PR_TRUE, 11 },
|
---|
1455 | { "abcdefgabcdefg", 'f', PR_TRUE, 12 },
|
---|
1456 | { "abcdefgabcdefg", 'g', PR_TRUE, 13 },
|
---|
1457 | { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
|
---|
1458 | { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
|
---|
1459 | };
|
---|
1460 |
|
---|
1461 | int i;
|
---|
1462 |
|
---|
1463 | printf("Test 016 (PL_strrchr) ..."); fflush(stdout);
|
---|
1464 |
|
---|
1465 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1466 | {
|
---|
1467 | char *rv = PL_strrchr(array[i].str, array[i].chr);
|
---|
1468 |
|
---|
1469 | if( PR_FALSE == array[i].ret )
|
---|
1470 | {
|
---|
1471 | if( (char *)0 != rv )
|
---|
1472 | {
|
---|
1473 | printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,
|
---|
1474 | array[i].chr, rv);
|
---|
1475 | return PR_FALSE;
|
---|
1476 | }
|
---|
1477 | }
|
---|
1478 | else
|
---|
1479 | {
|
---|
1480 | if( (char *)0 == rv )
|
---|
1481 | {
|
---|
1482 | printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,
|
---|
1483 | array[i].chr, array[i].off);
|
---|
1484 | return PR_FALSE;
|
---|
1485 | }
|
---|
1486 |
|
---|
1487 | if( &array[i].str[ array[i].off ] != rv )
|
---|
1488 | {
|
---|
1489 | printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
|
---|
1490 | array[i].chr, rv, array[i].str, array[i].off);
|
---|
1491 | return PR_FALSE;
|
---|
1492 | }
|
---|
1493 | }
|
---|
1494 | }
|
---|
1495 |
|
---|
1496 | printf("PASS\n");
|
---|
1497 | return PR_TRUE;
|
---|
1498 | }
|
---|
1499 |
|
---|
1500 | /* PL_strnchr */
|
---|
1501 | PRBool test_017(void)
|
---|
1502 | {
|
---|
1503 | static struct
|
---|
1504 | {
|
---|
1505 | const char *str;
|
---|
1506 | char chr;
|
---|
1507 | PRUint32 max;
|
---|
1508 | PRBool ret;
|
---|
1509 | PRUint32 off;
|
---|
1510 | } array[] =
|
---|
1511 | {
|
---|
1512 | { (const char *)0, 'a', 2, PR_FALSE, 0 },
|
---|
1513 | { (const char *)0, '\0', 2, PR_FALSE, 0 },
|
---|
1514 | { "abcdefg", 'a', 5, PR_TRUE, 0 },
|
---|
1515 | { "abcdefg", 'b', 5, PR_TRUE, 1 },
|
---|
1516 | { "abcdefg", 'c', 5, PR_TRUE, 2 },
|
---|
1517 | { "abcdefg", 'd', 5, PR_TRUE, 3 },
|
---|
1518 | { "abcdefg", 'e', 5, PR_TRUE, 4 },
|
---|
1519 | { "abcdefg", 'f', 5, PR_FALSE, 0 },
|
---|
1520 | { "abcdefg", 'g', 5, PR_FALSE, 0 },
|
---|
1521 | { "abcdefg", 'h', 5, PR_FALSE, 0 },
|
---|
1522 | { "abcdefg", '\0', 5, PR_FALSE, 0 },
|
---|
1523 | { "abcdefg", '\0', 15, PR_TRUE, 7 },
|
---|
1524 | { "abcdefg", 'A', 5, PR_FALSE, 0 },
|
---|
1525 | { "abcdefg", 'B', 5, PR_FALSE, 0 },
|
---|
1526 | { "abcdefg", 'C', 5, PR_FALSE, 0 },
|
---|
1527 | { "abcdefg", 'D', 5, PR_FALSE, 0 },
|
---|
1528 | { "abcdefg", 'E', 5, PR_FALSE, 0 },
|
---|
1529 | { "abcdefg", 'F', 5, PR_FALSE, 0 },
|
---|
1530 | { "abcdefg", 'G', 5, PR_FALSE, 0 },
|
---|
1531 | { "abcdefg", 'H', 5, PR_FALSE, 0 },
|
---|
1532 | { "abcdefgabcdefg", 'a', 10, PR_TRUE, 0 },
|
---|
1533 | { "abcdefgabcdefg", 'b', 10, PR_TRUE, 1 },
|
---|
1534 | { "abcdefgabcdefg", 'c', 10, PR_TRUE, 2 },
|
---|
1535 | { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
|
---|
1536 | { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
|
---|
1537 | { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
|
---|
1538 | { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
|
---|
1539 | { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
|
---|
1540 | { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
|
---|
1541 | { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
|
---|
1542 | { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
|
---|
1543 | };
|
---|
1544 |
|
---|
1545 | int i;
|
---|
1546 |
|
---|
1547 | printf("Test 017 (PL_strnchr) ..."); fflush(stdout);
|
---|
1548 |
|
---|
1549 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1550 | {
|
---|
1551 | char *rv = PL_strnchr(array[i].str, array[i].chr, array[i].max);
|
---|
1552 |
|
---|
1553 | if( PR_FALSE == array[i].ret )
|
---|
1554 | {
|
---|
1555 | if( (char *)0 != rv )
|
---|
1556 | {
|
---|
1557 | printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,
|
---|
1558 | array[i].chr, array[i].max, rv);
|
---|
1559 | return PR_FALSE;
|
---|
1560 | }
|
---|
1561 | }
|
---|
1562 | else
|
---|
1563 | {
|
---|
1564 | if( (char *)0 == rv )
|
---|
1565 | {
|
---|
1566 | printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,
|
---|
1567 | array[i].chr, array[i].max, array[i].off);
|
---|
1568 | return PR_FALSE;
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | if( &array[i].str[ array[i].off ] != rv )
|
---|
1572 | {
|
---|
1573 | printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
|
---|
1574 | array[i].chr, array[i].max, rv, array[i].str, array[i].off);
|
---|
1575 | return PR_FALSE;
|
---|
1576 | }
|
---|
1577 | }
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | printf("PASS\n");
|
---|
1581 | return PR_TRUE;
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | /* PL_strnrchr */
|
---|
1585 | PRBool test_018(void)
|
---|
1586 | {
|
---|
1587 | static struct
|
---|
1588 | {
|
---|
1589 | const char *str;
|
---|
1590 | char chr;
|
---|
1591 | PRUint32 max;
|
---|
1592 | PRBool ret;
|
---|
1593 | PRUint32 off;
|
---|
1594 | } array[] =
|
---|
1595 | {
|
---|
1596 | { (const char *)0, 'a', 2, PR_FALSE, 0 },
|
---|
1597 | { (const char *)0, '\0', 2, PR_FALSE, 0 },
|
---|
1598 | { "abcdefg", 'a', 5, PR_TRUE, 0 },
|
---|
1599 | { "abcdefg", 'b', 5, PR_TRUE, 1 },
|
---|
1600 | { "abcdefg", 'c', 5, PR_TRUE, 2 },
|
---|
1601 | { "abcdefg", 'd', 5, PR_TRUE, 3 },
|
---|
1602 | { "abcdefg", 'e', 5, PR_TRUE, 4 },
|
---|
1603 | { "abcdefg", 'f', 5, PR_FALSE, 0 },
|
---|
1604 | { "abcdefg", 'g', 5, PR_FALSE, 0 },
|
---|
1605 | { "abcdefg", 'h', 5, PR_FALSE, 0 },
|
---|
1606 | { "abcdefg", '\0', 5, PR_FALSE, 0 },
|
---|
1607 | { "abcdefg", '\0', 15, PR_TRUE, 7 },
|
---|
1608 | { "abcdefg", 'A', 5, PR_FALSE, 0 },
|
---|
1609 | { "abcdefg", 'B', 5, PR_FALSE, 0 },
|
---|
1610 | { "abcdefg", 'C', 5, PR_FALSE, 0 },
|
---|
1611 | { "abcdefg", 'D', 5, PR_FALSE, 0 },
|
---|
1612 | { "abcdefg", 'E', 5, PR_FALSE, 0 },
|
---|
1613 | { "abcdefg", 'F', 5, PR_FALSE, 0 },
|
---|
1614 | { "abcdefg", 'G', 5, PR_FALSE, 0 },
|
---|
1615 | { "abcdefg", 'H', 5, PR_FALSE, 0 },
|
---|
1616 | { "abcdefgabcdefg", 'a', 10, PR_TRUE, 7 },
|
---|
1617 | { "abcdefgabcdefg", 'b', 10, PR_TRUE, 8 },
|
---|
1618 | { "abcdefgabcdefg", 'c', 10, PR_TRUE, 9 },
|
---|
1619 | { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
|
---|
1620 | { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
|
---|
1621 | { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
|
---|
1622 | { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
|
---|
1623 | { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
|
---|
1624 | { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
|
---|
1625 | { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
|
---|
1626 | { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
|
---|
1627 | };
|
---|
1628 |
|
---|
1629 | int i;
|
---|
1630 |
|
---|
1631 | printf("Test 018 (PL_strnrchr) ..."); fflush(stdout);
|
---|
1632 |
|
---|
1633 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1634 | {
|
---|
1635 | char *rv = PL_strnrchr(array[i].str, array[i].chr, array[i].max);
|
---|
1636 |
|
---|
1637 | if( PR_FALSE == array[i].ret )
|
---|
1638 | {
|
---|
1639 | if( (char *)0 != rv )
|
---|
1640 | {
|
---|
1641 | printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,
|
---|
1642 | array[i].chr, array[i].max, rv);
|
---|
1643 | return PR_FALSE;
|
---|
1644 | }
|
---|
1645 | }
|
---|
1646 | else
|
---|
1647 | {
|
---|
1648 | if( (char *)0 == rv )
|
---|
1649 | {
|
---|
1650 | printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,
|
---|
1651 | array[i].chr, array[i].max, array[i].off);
|
---|
1652 | return PR_FALSE;
|
---|
1653 | }
|
---|
1654 |
|
---|
1655 | if( &array[i].str[ array[i].off ] != rv )
|
---|
1656 | {
|
---|
1657 | printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
|
---|
1658 | array[i].chr, array[i].max, rv, array[i].str, array[i].off);
|
---|
1659 | return PR_FALSE;
|
---|
1660 | }
|
---|
1661 | }
|
---|
1662 | }
|
---|
1663 |
|
---|
1664 | printf("PASS\n");
|
---|
1665 | return PR_TRUE;
|
---|
1666 | }
|
---|
1667 |
|
---|
1668 | /* PL_strpbrk */
|
---|
1669 | PRBool test_019(void)
|
---|
1670 | {
|
---|
1671 | static struct
|
---|
1672 | {
|
---|
1673 | const char *str;
|
---|
1674 | const char *chrs;
|
---|
1675 | PRBool ret;
|
---|
1676 | PRUint32 off;
|
---|
1677 | } array[] =
|
---|
1678 | {
|
---|
1679 | { (const char *)0, (const char *)0, PR_FALSE, 0 },
|
---|
1680 | { (const char *)0, "abc", PR_FALSE, 0 },
|
---|
1681 | { "abc", (const char *)0, PR_FALSE, 0 },
|
---|
1682 | { "abcdefg", "", PR_FALSE, 0 },
|
---|
1683 | { "", "aeiou", PR_FALSE, 0 },
|
---|
1684 | { "abcdefg", "ae", PR_TRUE, 0 },
|
---|
1685 | { "abcdefg", "ei", PR_TRUE, 4 },
|
---|
1686 | { "abcdefg", "io", PR_FALSE, 0 },
|
---|
1687 | { "abcdefg", "bcd", PR_TRUE, 1 },
|
---|
1688 | { "abcdefg", "cbd", PR_TRUE, 1 },
|
---|
1689 | { "abcdefg", "dbc", PR_TRUE, 1 },
|
---|
1690 | { "abcdefg", "ghi", PR_TRUE, 6 },
|
---|
1691 | { "abcdefg", "AE", PR_FALSE, 0 },
|
---|
1692 | { "abcdefg", "EI", PR_FALSE, 0 },
|
---|
1693 | { "abcdefg", "IO", PR_FALSE, 0 },
|
---|
1694 | { "abcdefg", "BCD", PR_FALSE, 0 },
|
---|
1695 | { "abcdefg", "CBD", PR_FALSE, 0 },
|
---|
1696 | { "abcdefg", "DBC", PR_FALSE, 0 },
|
---|
1697 | { "abcdefg", "GHI", PR_FALSE, 0 },
|
---|
1698 | { "abcdefgabcdefg", "ae", PR_TRUE, 0 },
|
---|
1699 | { "abcdefgabcdefg", "ei", PR_TRUE, 4 },
|
---|
1700 | { "abcdefgabcdefg", "io", PR_FALSE, 0 },
|
---|
1701 | { "abcdefgabcdefg", "bcd", PR_TRUE, 1 },
|
---|
1702 | { "abcdefgabcdefg", "cbd", PR_TRUE, 1 },
|
---|
1703 | { "abcdefgabcdefg", "dbc", PR_TRUE, 1 },
|
---|
1704 | { "abcdefgabcdefg", "ghi", PR_TRUE, 6 },
|
---|
1705 | { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
|
---|
1706 | { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
|
---|
1707 | { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
|
---|
1708 | { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
|
---|
1709 | { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
|
---|
1710 | { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
|
---|
1711 | { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
|
---|
1712 | };
|
---|
1713 |
|
---|
1714 | int i;
|
---|
1715 |
|
---|
1716 | printf("Test 019 (PL_strpbrk) ..."); fflush(stdout);
|
---|
1717 |
|
---|
1718 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1719 | {
|
---|
1720 | char *rv = PL_strpbrk(array[i].str, array[i].chrs);
|
---|
1721 |
|
---|
1722 | if( PR_FALSE == array[i].ret )
|
---|
1723 | {
|
---|
1724 | if( (char *)0 != rv )
|
---|
1725 | {
|
---|
1726 | printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
|
---|
1727 | array[i].str ? array[i].str : "(null)",
|
---|
1728 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1729 | rv);
|
---|
1730 | return PR_FALSE;
|
---|
1731 | }
|
---|
1732 | }
|
---|
1733 | else
|
---|
1734 | {
|
---|
1735 | if( (char *)0 == rv )
|
---|
1736 | {
|
---|
1737 | printf("FAIL %d: %s,%s -> null, not +%lu\n", i,
|
---|
1738 | array[i].str ? array[i].str : "(null)",
|
---|
1739 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1740 | array[i].off);
|
---|
1741 | return PR_FALSE;
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | if( &array[i].str[ array[i].off ] != rv )
|
---|
1745 | {
|
---|
1746 | printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
|
---|
1747 | array[i].str ? array[i].str : "(null)",
|
---|
1748 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1749 | rv, array[i].str, array[i].off);
|
---|
1750 | return PR_FALSE;
|
---|
1751 | }
|
---|
1752 | }
|
---|
1753 | }
|
---|
1754 |
|
---|
1755 | printf("PASS\n");
|
---|
1756 | return PR_TRUE;
|
---|
1757 | }
|
---|
1758 |
|
---|
1759 | /* PL_strprbrk */
|
---|
1760 | PRBool test_020(void)
|
---|
1761 | {
|
---|
1762 | static struct
|
---|
1763 | {
|
---|
1764 | const char *str;
|
---|
1765 | const char *chrs;
|
---|
1766 | PRBool ret;
|
---|
1767 | PRUint32 off;
|
---|
1768 | } array[] =
|
---|
1769 | {
|
---|
1770 | { (const char *)0, (const char *)0, PR_FALSE, 0 },
|
---|
1771 | { (const char *)0, "abc", PR_FALSE, 0 },
|
---|
1772 | { "abc", (const char *)0, PR_FALSE, 0 },
|
---|
1773 | { "abcdefg", "", PR_FALSE, 0 },
|
---|
1774 | { "", "aeiou", PR_FALSE, 0 },
|
---|
1775 | { "abcdefg", "ae", PR_TRUE, 4 },
|
---|
1776 | { "abcdefg", "ei", PR_TRUE, 4 },
|
---|
1777 | { "abcdefg", "io", PR_FALSE, 0 },
|
---|
1778 | { "abcdefg", "bcd", PR_TRUE, 3 },
|
---|
1779 | { "abcdefg", "cbd", PR_TRUE, 3 },
|
---|
1780 | { "abcdefg", "dbc", PR_TRUE, 3 },
|
---|
1781 | { "abcdefg", "ghi", PR_TRUE, 6 },
|
---|
1782 | { "abcdefg", "AE", PR_FALSE, 0 },
|
---|
1783 | { "abcdefg", "EI", PR_FALSE, 0 },
|
---|
1784 | { "abcdefg", "IO", PR_FALSE, 0 },
|
---|
1785 | { "abcdefg", "BCD", PR_FALSE, 0 },
|
---|
1786 | { "abcdefg", "CBD", PR_FALSE, 0 },
|
---|
1787 | { "abcdefg", "DBC", PR_FALSE, 0 },
|
---|
1788 | { "abcdefg", "GHI", PR_FALSE, 0 },
|
---|
1789 | { "abcdefgabcdefg", "ae", PR_TRUE, 11 },
|
---|
1790 | { "abcdefgabcdefg", "ei", PR_TRUE, 11 },
|
---|
1791 | { "abcdefgabcdefg", "io", PR_FALSE, 0 },
|
---|
1792 | { "abcdefgabcdefg", "bcd", PR_TRUE, 10 },
|
---|
1793 | { "abcdefgabcdefg", "cbd", PR_TRUE, 10 },
|
---|
1794 | { "abcdefgabcdefg", "dbc", PR_TRUE, 10 },
|
---|
1795 | { "abcdefgabcdefg", "ghi", PR_TRUE, 13 },
|
---|
1796 | { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
|
---|
1797 | { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
|
---|
1798 | { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
|
---|
1799 | { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
|
---|
1800 | { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
|
---|
1801 | { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
|
---|
1802 | { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
|
---|
1803 | };
|
---|
1804 |
|
---|
1805 | int i;
|
---|
1806 |
|
---|
1807 | printf("Test 020 (PL_strprbrk) ..."); fflush(stdout);
|
---|
1808 |
|
---|
1809 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1810 | {
|
---|
1811 | char *rv = PL_strprbrk(array[i].str, array[i].chrs);
|
---|
1812 |
|
---|
1813 | if( PR_FALSE == array[i].ret )
|
---|
1814 | {
|
---|
1815 | if( (char *)0 != rv )
|
---|
1816 | {
|
---|
1817 | printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
|
---|
1818 | array[i].str ? array[i].str : "(null)",
|
---|
1819 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1820 | rv);
|
---|
1821 | return PR_FALSE;
|
---|
1822 | }
|
---|
1823 | }
|
---|
1824 | else
|
---|
1825 | {
|
---|
1826 | if( (char *)0 == rv )
|
---|
1827 | {
|
---|
1828 | printf("FAIL %d: %s,%s -> null, not +%lu\n", i,
|
---|
1829 | array[i].str ? array[i].str : "(null)",
|
---|
1830 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1831 | array[i].off);
|
---|
1832 | return PR_FALSE;
|
---|
1833 | }
|
---|
1834 |
|
---|
1835 | if( &array[i].str[ array[i].off ] != rv )
|
---|
1836 | {
|
---|
1837 | printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
|
---|
1838 | array[i].str ? array[i].str : "(null)",
|
---|
1839 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1840 | rv, array[i].str, array[i].off);
|
---|
1841 | return PR_FALSE;
|
---|
1842 | }
|
---|
1843 | }
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | printf("PASS\n");
|
---|
1847 | return PR_TRUE;
|
---|
1848 | }
|
---|
1849 |
|
---|
1850 | /* PL_strnpbrk */
|
---|
1851 | PRBool test_021(void)
|
---|
1852 | {
|
---|
1853 | static struct
|
---|
1854 | {
|
---|
1855 | const char *str;
|
---|
1856 | const char *chrs;
|
---|
1857 | PRUint32 max;
|
---|
1858 | PRBool ret;
|
---|
1859 | PRUint32 off;
|
---|
1860 | } array[] =
|
---|
1861 | {
|
---|
1862 | { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
|
---|
1863 | { (const char *)0, "abc", 3, PR_FALSE, 0 },
|
---|
1864 | { "abc", (const char *)0, 3, PR_FALSE, 0 },
|
---|
1865 | { "abcdefg", "", 3, PR_FALSE, 0 },
|
---|
1866 | { "", "aeiou", 3, PR_FALSE, 0 },
|
---|
1867 | { "abcdefg", "ae", 0, PR_FALSE, 0 },
|
---|
1868 | { "abcdefg", "ae", 1, PR_TRUE, 0 },
|
---|
1869 | { "abcdefg", "ae", 4, PR_TRUE, 0 },
|
---|
1870 | { "abcdefg", "ae", 5, PR_TRUE, 0 },
|
---|
1871 | { "abcdefg", "ae", 6, PR_TRUE, 0 },
|
---|
1872 | { "abcdefg", "ei", 4, PR_FALSE, 0 },
|
---|
1873 | { "abcdefg", "io", 10, PR_FALSE, 0 },
|
---|
1874 | { "abcdefg", "bcd", 2, PR_TRUE, 1 },
|
---|
1875 | { "abcdefg", "cbd", 2, PR_TRUE, 1 },
|
---|
1876 | { "abcdefg", "dbc", 2, PR_TRUE, 1 },
|
---|
1877 | { "abcdefg", "ghi", 6, PR_FALSE, 0 },
|
---|
1878 | { "abcdefg", "ghi", 7, PR_TRUE, 6 },
|
---|
1879 | { "abcdefg", "AE", 9, PR_FALSE, 0 },
|
---|
1880 | { "abcdefg", "EI", 9, PR_FALSE, 0 },
|
---|
1881 | { "abcdefg", "IO", 9, PR_FALSE, 0 },
|
---|
1882 | { "abcdefg", "BCD", 9, PR_FALSE, 0 },
|
---|
1883 | { "abcdefg", "CBD", 9, PR_FALSE, 0 },
|
---|
1884 | { "abcdefg", "DBC", 9, PR_FALSE, 0 },
|
---|
1885 | { "abcdefg", "GHI", 9, PR_FALSE, 0 },
|
---|
1886 | { "abcdefgabcdefg", "ae", 10, PR_TRUE, 0 },
|
---|
1887 | { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
|
---|
1888 | { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
|
---|
1889 | { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 1 },
|
---|
1890 | { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 1 },
|
---|
1891 | { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 1 },
|
---|
1892 | { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
|
---|
1893 | { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
|
---|
1894 | { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
|
---|
1895 | { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
|
---|
1896 | { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
|
---|
1897 | { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
|
---|
1898 | { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
|
---|
1899 | { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
|
---|
1900 | };
|
---|
1901 |
|
---|
1902 | int i;
|
---|
1903 |
|
---|
1904 | printf("Test 021 (PL_strnpbrk) ..."); fflush(stdout);
|
---|
1905 |
|
---|
1906 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
1907 | {
|
---|
1908 | char *rv = PL_strnpbrk(array[i].str, array[i].chrs, array[i].max);
|
---|
1909 |
|
---|
1910 | if( PR_FALSE == array[i].ret )
|
---|
1911 | {
|
---|
1912 | if( (char *)0 != rv )
|
---|
1913 | {
|
---|
1914 | printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
|
---|
1915 | array[i].str ? array[i].str : "(null)",
|
---|
1916 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1917 | array[i].max, rv);
|
---|
1918 | return PR_FALSE;
|
---|
1919 | }
|
---|
1920 | }
|
---|
1921 | else
|
---|
1922 | {
|
---|
1923 | if( (char *)0 == rv )
|
---|
1924 | {
|
---|
1925 | printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i,
|
---|
1926 | array[i].str ? array[i].str : "(null)",
|
---|
1927 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1928 | array[i].max, array[i].off);
|
---|
1929 | return PR_FALSE;
|
---|
1930 | }
|
---|
1931 |
|
---|
1932 | if( &array[i].str[ array[i].off ] != rv )
|
---|
1933 | {
|
---|
1934 | printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
|
---|
1935 | array[i].str ? array[i].str : "(null)",
|
---|
1936 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
1937 | array[i].max, rv, array[i].str, array[i].off);
|
---|
1938 | return PR_FALSE;
|
---|
1939 | }
|
---|
1940 | }
|
---|
1941 | }
|
---|
1942 |
|
---|
1943 | printf("PASS\n");
|
---|
1944 | return PR_TRUE;
|
---|
1945 | }
|
---|
1946 |
|
---|
1947 | /* PL_strnprbrk */
|
---|
1948 | PRBool test_022(void)
|
---|
1949 | {
|
---|
1950 | static struct
|
---|
1951 | {
|
---|
1952 | const char *str;
|
---|
1953 | const char *chrs;
|
---|
1954 | PRUint32 max;
|
---|
1955 | PRBool ret;
|
---|
1956 | PRUint32 off;
|
---|
1957 | } array[] =
|
---|
1958 | {
|
---|
1959 | { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
|
---|
1960 | { (const char *)0, "abc", 3, PR_FALSE, 0 },
|
---|
1961 | { "abc", (const char *)0, 3, PR_FALSE, 0 },
|
---|
1962 | { "abcdefg", "", 3, PR_FALSE, 0 },
|
---|
1963 | { "", "aeiou", 3, PR_FALSE, 0 },
|
---|
1964 | { "abcdefg", "ae", 0, PR_FALSE, 0 },
|
---|
1965 | { "abcdefg", "ae", 1, PR_TRUE, 0 },
|
---|
1966 | { "abcdefg", "ae", 4, PR_TRUE, 0 },
|
---|
1967 | { "abcdefg", "ae", 5, PR_TRUE, 4 },
|
---|
1968 | { "abcdefg", "ae", 6, PR_TRUE, 4 },
|
---|
1969 | { "abcdefg", "ei", 4, PR_FALSE, 0 },
|
---|
1970 | { "abcdefg", "io", 10, PR_FALSE, 0 },
|
---|
1971 | { "abcdefg", "bcd", 2, PR_TRUE, 1 },
|
---|
1972 | { "abcdefg", "cbd", 2, PR_TRUE, 1 },
|
---|
1973 | { "abcdefg", "dbc", 2, PR_TRUE, 1 },
|
---|
1974 | { "abcdefg", "bcd", 3, PR_TRUE, 2 },
|
---|
1975 | { "abcdefg", "cbd", 3, PR_TRUE, 2 },
|
---|
1976 | { "abcdefg", "dbc", 3, PR_TRUE, 2 },
|
---|
1977 | { "abcdefg", "bcd", 5, PR_TRUE, 3 },
|
---|
1978 | { "abcdefg", "cbd", 5, PR_TRUE, 3 },
|
---|
1979 | { "abcdefg", "dbc", 5, PR_TRUE, 3 },
|
---|
1980 | { "abcdefg", "bcd", 15, PR_TRUE, 3 },
|
---|
1981 | { "abcdefg", "cbd", 15, PR_TRUE, 3 },
|
---|
1982 | { "abcdefg", "dbc", 15, PR_TRUE, 3 },
|
---|
1983 | { "abcdefg", "ghi", 6, PR_FALSE, 0 },
|
---|
1984 | { "abcdefg", "ghi", 7, PR_TRUE, 6 },
|
---|
1985 | { "abcdefg", "AE", 9, PR_FALSE, 0 },
|
---|
1986 | { "abcdefg", "EI", 9, PR_FALSE, 0 },
|
---|
1987 | { "abcdefg", "IO", 9, PR_FALSE, 0 },
|
---|
1988 | { "abcdefg", "BCD", 9, PR_FALSE, 0 },
|
---|
1989 | { "abcdefg", "CBD", 9, PR_FALSE, 0 },
|
---|
1990 | { "abcdefg", "DBC", 9, PR_FALSE, 0 },
|
---|
1991 | { "abcdefg", "GHI", 9, PR_FALSE, 0 },
|
---|
1992 | { "abcdefgabcdefg", "ae", 10, PR_TRUE, 7 },
|
---|
1993 | { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
|
---|
1994 | { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
|
---|
1995 | { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 9 },
|
---|
1996 | { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 9 },
|
---|
1997 | { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 9 },
|
---|
1998 | { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
|
---|
1999 | { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
|
---|
2000 | { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
|
---|
2001 | { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
|
---|
2002 | { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
|
---|
2003 | { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
|
---|
2004 | { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
|
---|
2005 | { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
|
---|
2006 | };
|
---|
2007 |
|
---|
2008 | int i;
|
---|
2009 |
|
---|
2010 | printf("Test 022 (PL_strnprbrk) ..."); fflush(stdout);
|
---|
2011 |
|
---|
2012 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2013 | {
|
---|
2014 | char *rv = PL_strnprbrk(array[i].str, array[i].chrs, array[i].max);
|
---|
2015 |
|
---|
2016 | if( PR_FALSE == array[i].ret )
|
---|
2017 | {
|
---|
2018 | if( (char *)0 != rv )
|
---|
2019 | {
|
---|
2020 | printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
|
---|
2021 | array[i].str ? array[i].str : "(null)",
|
---|
2022 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
2023 | array[i].max, rv);
|
---|
2024 | return PR_FALSE;
|
---|
2025 | }
|
---|
2026 | }
|
---|
2027 | else
|
---|
2028 | {
|
---|
2029 | if( (char *)0 == rv )
|
---|
2030 | {
|
---|
2031 | printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i,
|
---|
2032 | array[i].str ? array[i].str : "(null)",
|
---|
2033 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
2034 | array[i].max, array[i].off);
|
---|
2035 | return PR_FALSE;
|
---|
2036 | }
|
---|
2037 |
|
---|
2038 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2039 | {
|
---|
2040 | printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2041 | array[i].str ? array[i].str : "(null)",
|
---|
2042 | array[i].chrs ? array[i].chrs : "(null)",
|
---|
2043 | array[i].max, rv, array[i].str, array[i].off);
|
---|
2044 | return PR_FALSE;
|
---|
2045 | }
|
---|
2046 | }
|
---|
2047 | }
|
---|
2048 |
|
---|
2049 | printf("PASS\n");
|
---|
2050 | return PR_TRUE;
|
---|
2051 | }
|
---|
2052 |
|
---|
2053 | /* PL_strstr */
|
---|
2054 | PRBool test_023(void)
|
---|
2055 | {
|
---|
2056 | static struct
|
---|
2057 | {
|
---|
2058 | const char *str;
|
---|
2059 | const char *sub;
|
---|
2060 | PRBool ret;
|
---|
2061 | PRUint32 off;
|
---|
2062 | } array[] =
|
---|
2063 | {
|
---|
2064 | { (const char *)0, (const char *)0, PR_FALSE, 0 },
|
---|
2065 | { (const char *)0, "blah", PR_FALSE, 0 },
|
---|
2066 | { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
|
---|
2067 | { "blah-de-blah", "blah", PR_TRUE, 0 },
|
---|
2068 | { "", "blah", PR_FALSE, 0 },
|
---|
2069 | { "blah-de-blah", "", PR_FALSE, 0 },
|
---|
2070 | { "abcdefg", "a", PR_TRUE, 0 },
|
---|
2071 | { "abcdefg", "c", PR_TRUE, 2 },
|
---|
2072 | { "abcdefg", "e", PR_TRUE, 4 },
|
---|
2073 | { "abcdefg", "g", PR_TRUE, 6 },
|
---|
2074 | { "abcdefg", "i", PR_FALSE, 0 },
|
---|
2075 | { "abcdefg", "ab", PR_TRUE, 0 },
|
---|
2076 | { "abcdefg", "cd", PR_TRUE, 2 },
|
---|
2077 | { "abcdefg", "ef", PR_TRUE, 4 },
|
---|
2078 | { "abcdefg", "gh", PR_FALSE, 0 },
|
---|
2079 | { "abcdabc", "bc", PR_TRUE, 1 },
|
---|
2080 | { "abcdefg", "abcdefg", PR_TRUE, 0 },
|
---|
2081 | { "abcdefgabcdefg", "a", PR_TRUE, 0 },
|
---|
2082 | { "abcdefgabcdefg", "c", PR_TRUE, 2 },
|
---|
2083 | { "abcdefgabcdefg", "e", PR_TRUE, 4 },
|
---|
2084 | { "abcdefgabcdefg", "g", PR_TRUE, 6 },
|
---|
2085 | { "abcdefgabcdefg", "i", PR_FALSE, 0 },
|
---|
2086 | { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
|
---|
2087 | { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
|
---|
2088 | { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
|
---|
2089 | { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
|
---|
2090 | { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
|
---|
2091 | { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
|
---|
2092 | { "ABCDEFG", "a", PR_FALSE, 0 },
|
---|
2093 | { "ABCDEFG", "c", PR_FALSE, 0 },
|
---|
2094 | { "ABCDEFG", "e", PR_FALSE, 0 },
|
---|
2095 | { "ABCDEFG", "g", PR_FALSE, 0 },
|
---|
2096 | { "ABCDEFG", "i", PR_FALSE, 0 },
|
---|
2097 | { "ABCDEFG", "ab", PR_FALSE, 0 },
|
---|
2098 | { "ABCDEFG", "cd", PR_FALSE, 0 },
|
---|
2099 | { "ABCDEFG", "ef", PR_FALSE, 0 },
|
---|
2100 | { "ABCDEFG", "gh", PR_FALSE, 0 },
|
---|
2101 | { "ABCDABC", "bc", PR_FALSE, 0 },
|
---|
2102 | { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
|
---|
2103 | { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
|
---|
2104 | { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
|
---|
2105 | { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
|
---|
2106 | { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
|
---|
2107 | { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
|
---|
2108 | { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
|
---|
2109 | { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
|
---|
2110 | { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
|
---|
2111 | { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
|
---|
2112 | { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
|
---|
2113 | { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
|
---|
2114 | };
|
---|
2115 |
|
---|
2116 | int i;
|
---|
2117 |
|
---|
2118 | printf("Test 023 (PL_strstr) ..."); fflush(stdout);
|
---|
2119 |
|
---|
2120 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2121 | {
|
---|
2122 | char *rv = PL_strstr(array[i].str, array[i].sub);
|
---|
2123 |
|
---|
2124 | if( PR_FALSE == array[i].ret )
|
---|
2125 | {
|
---|
2126 | if( (char *)0 != rv )
|
---|
2127 | {
|
---|
2128 | printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
|
---|
2129 | array[i].str ? array[i].str : "(null)",
|
---|
2130 | array[i].sub ? array[i].sub : "(null)",
|
---|
2131 | rv);
|
---|
2132 | return PR_FALSE;
|
---|
2133 | }
|
---|
2134 | }
|
---|
2135 | else
|
---|
2136 | {
|
---|
2137 | if( (char *)0 == rv )
|
---|
2138 | {
|
---|
2139 | printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
|
---|
2140 | array[i].str ? array[i].str : "(null)",
|
---|
2141 | array[i].sub ? array[i].sub : "(null)",
|
---|
2142 | array[i].str, array[i].off);
|
---|
2143 | return PR_FALSE;
|
---|
2144 | }
|
---|
2145 |
|
---|
2146 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2147 | {
|
---|
2148 | printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2149 | array[i].str ? array[i].str : "(null)",
|
---|
2150 | array[i].sub ? array[i].sub : "(null)",
|
---|
2151 | rv, array[i].str, array[i].off);
|
---|
2152 | return PR_FALSE;
|
---|
2153 | }
|
---|
2154 | }
|
---|
2155 | }
|
---|
2156 |
|
---|
2157 | printf("PASS\n");
|
---|
2158 | return PR_TRUE;
|
---|
2159 | }
|
---|
2160 |
|
---|
2161 | /* PL_strrstr */
|
---|
2162 | PRBool test_024(void)
|
---|
2163 | {
|
---|
2164 | static struct
|
---|
2165 | {
|
---|
2166 | const char *str;
|
---|
2167 | const char *sub;
|
---|
2168 | PRBool ret;
|
---|
2169 | PRUint32 off;
|
---|
2170 | } array[] =
|
---|
2171 | {
|
---|
2172 | { (const char *)0, (const char *)0, PR_FALSE, 0 },
|
---|
2173 | { (const char *)0, "blah", PR_FALSE, 0 },
|
---|
2174 | { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
|
---|
2175 | { "blah-de-blah", "blah", PR_TRUE, 8 },
|
---|
2176 | { "", "blah", PR_FALSE, 0 },
|
---|
2177 | { "blah-de-blah", "", PR_FALSE, 0 },
|
---|
2178 | { "abcdefg", "a", PR_TRUE, 0 },
|
---|
2179 | { "abcdefg", "c", PR_TRUE, 2 },
|
---|
2180 | { "abcdefg", "e", PR_TRUE, 4 },
|
---|
2181 | { "abcdefg", "g", PR_TRUE, 6 },
|
---|
2182 | { "abcdefg", "i", PR_FALSE, 0 },
|
---|
2183 | { "abcdefg", "ab", PR_TRUE, 0 },
|
---|
2184 | { "abcdefg", "cd", PR_TRUE, 2 },
|
---|
2185 | { "abcdefg", "ef", PR_TRUE, 4 },
|
---|
2186 | { "abcdefg", "gh", PR_FALSE, 0 },
|
---|
2187 | { "abcdabc", "bc", PR_TRUE, 5 },
|
---|
2188 | { "abcdefg", "abcdefg", PR_TRUE, 0 },
|
---|
2189 | { "abcdefgabcdefg", "a", PR_TRUE, 7 },
|
---|
2190 | { "abcdefgabcdefg", "c", PR_TRUE, 9 },
|
---|
2191 | { "abcdefgabcdefg", "e", PR_TRUE, 11 },
|
---|
2192 | { "abcdefgabcdefg", "g", PR_TRUE, 13 },
|
---|
2193 | { "abcdefgabcdefg", "i", PR_FALSE, 0 },
|
---|
2194 | { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
|
---|
2195 | { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
|
---|
2196 | { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
|
---|
2197 | { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
|
---|
2198 | { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
|
---|
2199 | { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
|
---|
2200 | { "ABCDEFG", "a", PR_FALSE, 0 },
|
---|
2201 | { "ABCDEFG", "c", PR_FALSE, 0 },
|
---|
2202 | { "ABCDEFG", "e", PR_FALSE, 0 },
|
---|
2203 | { "ABCDEFG", "g", PR_FALSE, 0 },
|
---|
2204 | { "ABCDEFG", "i", PR_FALSE, 0 },
|
---|
2205 | { "ABCDEFG", "ab", PR_FALSE, 0 },
|
---|
2206 | { "ABCDEFG", "cd", PR_FALSE, 0 },
|
---|
2207 | { "ABCDEFG", "ef", PR_FALSE, 0 },
|
---|
2208 | { "ABCDEFG", "gh", PR_FALSE, 0 },
|
---|
2209 | { "ABCDABC", "bc", PR_FALSE, 0 },
|
---|
2210 | { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
|
---|
2211 | { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
|
---|
2212 | { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
|
---|
2213 | { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
|
---|
2214 | { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
|
---|
2215 | { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
|
---|
2216 | { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
|
---|
2217 | { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
|
---|
2218 | { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
|
---|
2219 | { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
|
---|
2220 | { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
|
---|
2221 | { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
|
---|
2222 | };
|
---|
2223 |
|
---|
2224 | int i;
|
---|
2225 |
|
---|
2226 | printf("Test 024 (PL_strrstr) ..."); fflush(stdout);
|
---|
2227 |
|
---|
2228 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2229 | {
|
---|
2230 | char *rv = PL_strrstr(array[i].str, array[i].sub);
|
---|
2231 |
|
---|
2232 | if( PR_FALSE == array[i].ret )
|
---|
2233 | {
|
---|
2234 | if( (char *)0 != rv )
|
---|
2235 | {
|
---|
2236 | printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
|
---|
2237 | array[i].str ? array[i].str : "(null)",
|
---|
2238 | array[i].sub ? array[i].sub : "(null)",
|
---|
2239 | rv);
|
---|
2240 | return PR_FALSE;
|
---|
2241 | }
|
---|
2242 | }
|
---|
2243 | else
|
---|
2244 | {
|
---|
2245 | if( (char *)0 == rv )
|
---|
2246 | {
|
---|
2247 | printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
|
---|
2248 | array[i].str ? array[i].str : "(null)",
|
---|
2249 | array[i].sub ? array[i].sub : "(null)",
|
---|
2250 | array[i].str, array[i].off);
|
---|
2251 | return PR_FALSE;
|
---|
2252 | }
|
---|
2253 |
|
---|
2254 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2255 | {
|
---|
2256 | printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2257 | array[i].str ? array[i].str : "(null)",
|
---|
2258 | array[i].sub ? array[i].sub : "(null)",
|
---|
2259 | rv, array[i].str, array[i].off);
|
---|
2260 | return PR_FALSE;
|
---|
2261 | }
|
---|
2262 | }
|
---|
2263 | }
|
---|
2264 |
|
---|
2265 | printf("PASS\n");
|
---|
2266 | return PR_TRUE;
|
---|
2267 | }
|
---|
2268 |
|
---|
2269 | /* PL_strnstr */
|
---|
2270 | PRBool test_025(void)
|
---|
2271 | {
|
---|
2272 | static struct
|
---|
2273 | {
|
---|
2274 | const char *str;
|
---|
2275 | const char *sub;
|
---|
2276 | PRUint32 max;
|
---|
2277 | PRBool ret;
|
---|
2278 | PRUint32 off;
|
---|
2279 | } array[] =
|
---|
2280 | {
|
---|
2281 | { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
|
---|
2282 | { (const char *)0, "blah", 12, PR_FALSE, 0 },
|
---|
2283 | { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
|
---|
2284 | { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
|
---|
2285 | { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
|
---|
2286 | { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
|
---|
2287 | { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
|
---|
2288 | { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
|
---|
2289 | { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
|
---|
2290 | { "", "blah", 12, PR_FALSE, 0 },
|
---|
2291 | { "blah-de-blah", "", 12, PR_FALSE, 0 },
|
---|
2292 | { "abcdefg", "a", 5, PR_TRUE, 0 },
|
---|
2293 | { "abcdefg", "c", 5, PR_TRUE, 2 },
|
---|
2294 | { "abcdefg", "e", 5, PR_TRUE, 4 },
|
---|
2295 | { "abcdefg", "g", 5, PR_FALSE, 0 },
|
---|
2296 | { "abcdefg", "i", 5, PR_FALSE, 0 },
|
---|
2297 | { "abcdefg", "ab", 5, PR_TRUE, 0 },
|
---|
2298 | { "abcdefg", "cd", 5, PR_TRUE, 2 },
|
---|
2299 | { "abcdefg", "ef", 5, PR_FALSE, 0 },
|
---|
2300 | { "abcdefg", "gh", 5, PR_FALSE, 0 },
|
---|
2301 | { "abcdabc", "bc", 5, PR_TRUE, 1 },
|
---|
2302 | { "abcdabc", "bc", 6, PR_TRUE, 1 },
|
---|
2303 | { "abcdabc", "bc", 7, PR_TRUE, 1 },
|
---|
2304 | { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2305 | { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2306 | { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
|
---|
2307 | { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
|
---|
2308 | { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
|
---|
2309 | { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
|
---|
2310 | { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
|
---|
2311 | { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
|
---|
2312 | { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
|
---|
2313 | { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
|
---|
2314 | { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
|
---|
2315 | { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
|
---|
2316 | { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
|
---|
2317 | { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
|
---|
2318 | { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
|
---|
2319 | { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2320 | { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2321 | { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
|
---|
2322 | { "ABCDEFG", "a", 5, PR_FALSE, 0 },
|
---|
2323 | { "ABCDEFG", "c", 5, PR_FALSE, 0 },
|
---|
2324 | { "ABCDEFG", "e", 5, PR_FALSE, 0 },
|
---|
2325 | { "ABCDEFG", "g", 5, PR_FALSE, 0 },
|
---|
2326 | { "ABCDEFG", "i", 5, PR_FALSE, 0 },
|
---|
2327 | { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
|
---|
2328 | { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
|
---|
2329 | { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
|
---|
2330 | { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
|
---|
2331 | { "ABCDABC", "bc", 5, PR_FALSE, 0 },
|
---|
2332 | { "ABCDABC", "bc", 6, PR_FALSE, 0 },
|
---|
2333 | { "ABCDABC", "bc", 7, PR_FALSE, 0 },
|
---|
2334 | { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2335 | { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
|
---|
2336 | { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
|
---|
2337 | { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
|
---|
2338 | { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
|
---|
2339 | { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
|
---|
2340 | { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
|
---|
2341 | { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
|
---|
2342 | { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
|
---|
2343 | { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
|
---|
2344 | { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
|
---|
2345 | { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
|
---|
2346 | { "ABCDABCABCDABC", "bc", 5, PR_FALSE, 0 },
|
---|
2347 | { "ABCDABCABCDABC", "bc", 6, PR_FALSE, 0 },
|
---|
2348 | { "ABCDABCABCDABC", "bc", 7, PR_FALSE, },
|
---|
2349 | { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2350 | { "ABCDEFGABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
|
---|
2351 | { "ABCDEFGABCDEFG", "abcdefg", 8, PR_FALSE, 0 }
|
---|
2352 | };
|
---|
2353 |
|
---|
2354 | int i;
|
---|
2355 |
|
---|
2356 | printf("Test 025 (PL_strnstr) ..."); fflush(stdout);
|
---|
2357 |
|
---|
2358 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2359 | {
|
---|
2360 | char *rv = PL_strnstr(array[i].str, array[i].sub, array[i].max);
|
---|
2361 |
|
---|
2362 | if( PR_FALSE == array[i].ret )
|
---|
2363 | {
|
---|
2364 | if( (char *)0 != rv )
|
---|
2365 | {
|
---|
2366 | printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
|
---|
2367 | array[i].str ? array[i].str : "(null)",
|
---|
2368 | array[i].sub ? array[i].sub : "(null)",
|
---|
2369 | array[i].max, rv);
|
---|
2370 | return PR_FALSE;
|
---|
2371 | }
|
---|
2372 | }
|
---|
2373 | else
|
---|
2374 | {
|
---|
2375 | if( (char *)0 == rv )
|
---|
2376 | {
|
---|
2377 | printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
|
---|
2378 | array[i].str ? array[i].str : "(null)",
|
---|
2379 | array[i].sub ? array[i].sub : "(null)",
|
---|
2380 | array[i].max, array[i].str, array[i].off);
|
---|
2381 | return PR_FALSE;
|
---|
2382 | }
|
---|
2383 |
|
---|
2384 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2385 | {
|
---|
2386 | printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2387 | array[i].str ? array[i].str : "(null)",
|
---|
2388 | array[i].sub ? array[i].sub : "(null)",
|
---|
2389 | array[i].max, rv, array[i].str, array[i].off);
|
---|
2390 | return PR_FALSE;
|
---|
2391 | }
|
---|
2392 | }
|
---|
2393 | }
|
---|
2394 |
|
---|
2395 | printf("PASS\n");
|
---|
2396 | return PR_TRUE;
|
---|
2397 | }
|
---|
2398 |
|
---|
2399 | /* PL_strnrstr */
|
---|
2400 | PRBool test_026(void)
|
---|
2401 | {
|
---|
2402 | static struct
|
---|
2403 | {
|
---|
2404 | const char *str;
|
---|
2405 | const char *sub;
|
---|
2406 | PRUint32 max;
|
---|
2407 | PRBool ret;
|
---|
2408 | PRUint32 off;
|
---|
2409 | } array[] =
|
---|
2410 | {
|
---|
2411 | { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
|
---|
2412 | { (const char *)0, "blah", 12, PR_FALSE, 0 },
|
---|
2413 | { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
|
---|
2414 | { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
|
---|
2415 | { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
|
---|
2416 | { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
|
---|
2417 | { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
|
---|
2418 | { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
|
---|
2419 | { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
|
---|
2420 | { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
|
---|
2421 | { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
|
---|
2422 | { "", "blah", 12, PR_FALSE, 0 },
|
---|
2423 | { "blah-de-blah", "", 12, PR_FALSE, 0 },
|
---|
2424 | { "abcdefg", "a", 5, PR_TRUE, 0 },
|
---|
2425 | { "abcdefg", "c", 5, PR_TRUE, 2 },
|
---|
2426 | { "abcdefg", "e", 5, PR_TRUE, 4 },
|
---|
2427 | { "abcdefg", "g", 5, PR_FALSE, 0 },
|
---|
2428 | { "abcdefg", "i", 5, PR_FALSE, 0 },
|
---|
2429 | { "abcdefg", "ab", 5, PR_TRUE, 0 },
|
---|
2430 | { "abcdefg", "cd", 5, PR_TRUE, 2 },
|
---|
2431 | { "abcdefg", "ef", 5, PR_FALSE, 0 },
|
---|
2432 | { "abcdefg", "gh", 5, PR_FALSE, 0 },
|
---|
2433 | { "abcdabc", "bc", 5, PR_TRUE, 1 },
|
---|
2434 | { "abcdabc", "bc", 6, PR_TRUE, 1 },
|
---|
2435 | { "abcdabc", "bc", 7, PR_TRUE, 5 },
|
---|
2436 | { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2437 | { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2438 | { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
|
---|
2439 | { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
|
---|
2440 | { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
|
---|
2441 | { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
|
---|
2442 | { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
|
---|
2443 | { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
|
---|
2444 | { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
|
---|
2445 | { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
|
---|
2446 | { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
|
---|
2447 | { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
|
---|
2448 | { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
|
---|
2449 | { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
|
---|
2450 | { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
|
---|
2451 | { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
|
---|
2452 | { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
|
---|
2453 | { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
|
---|
2454 | { "ABCDEFG", "a", 5, PR_FALSE, 0 },
|
---|
2455 | { "ABCDEFG", "c", 5, PR_FALSE, 0 },
|
---|
2456 | { "ABCDEFG", "e", 5, PR_FALSE, 0 },
|
---|
2457 | { "ABCDEFG", "g", 5, PR_FALSE, 0 },
|
---|
2458 | { "ABCDEFG", "i", 5, PR_FALSE, 0 },
|
---|
2459 | { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
|
---|
2460 | { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
|
---|
2461 | { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
|
---|
2462 | { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
|
---|
2463 | { "ABCDABC", "bc", 5, PR_FALSE, 0 },
|
---|
2464 | { "ABCDABC", "bc", 6, PR_FALSE, 0 },
|
---|
2465 | { "ABCDABC", "bc", 7, PR_FALSE, 0 },
|
---|
2466 | { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2467 | { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
|
---|
2468 | { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
|
---|
2469 | { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
|
---|
2470 | { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
|
---|
2471 | { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
|
---|
2472 | { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
|
---|
2473 | { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
|
---|
2474 | { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
|
---|
2475 | { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
|
---|
2476 | { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
|
---|
2477 | { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
|
---|
2478 | { "ABCDABCABCDABC", "bc", 12, PR_FALSE, 0 },
|
---|
2479 | { "ABCDABCABCDABC", "bc", 13, PR_FALSE, 0 },
|
---|
2480 | { "ABCDABCABCDABC", "bc", 14, PR_FALSE, 0 },
|
---|
2481 | { "ABCDEFGABCDEFG", "abcdefg", 13, PR_FALSE, 0 },
|
---|
2482 | { "ABCDEFGABCDEFG", "abcdefg", 14, PR_FALSE, 0 },
|
---|
2483 | { "ABCDEFGABCDEFG", "abcdefg", 15, PR_FALSE, 0 }
|
---|
2484 | };
|
---|
2485 |
|
---|
2486 | int i;
|
---|
2487 |
|
---|
2488 | printf("Test 026 (PL_strnrstr) ..."); fflush(stdout);
|
---|
2489 |
|
---|
2490 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2491 | {
|
---|
2492 | char *rv = PL_strnrstr(array[i].str, array[i].sub, array[i].max);
|
---|
2493 |
|
---|
2494 | if( PR_FALSE == array[i].ret )
|
---|
2495 | {
|
---|
2496 | if( (char *)0 != rv )
|
---|
2497 | {
|
---|
2498 | printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
|
---|
2499 | array[i].str ? array[i].str : "(null)",
|
---|
2500 | array[i].sub ? array[i].sub : "(null)",
|
---|
2501 | array[i].max, rv);
|
---|
2502 | return PR_FALSE;
|
---|
2503 | }
|
---|
2504 | }
|
---|
2505 | else
|
---|
2506 | {
|
---|
2507 | if( (char *)0 == rv )
|
---|
2508 | {
|
---|
2509 | printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
|
---|
2510 | array[i].str ? array[i].str : "(null)",
|
---|
2511 | array[i].sub ? array[i].sub : "(null)",
|
---|
2512 | array[i].max, array[i].str, array[i].off);
|
---|
2513 | return PR_FALSE;
|
---|
2514 | }
|
---|
2515 |
|
---|
2516 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2517 | {
|
---|
2518 | printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2519 | array[i].str ? array[i].str : "(null)",
|
---|
2520 | array[i].sub ? array[i].sub : "(null)",
|
---|
2521 | array[i].max, rv, array[i].str, array[i].off);
|
---|
2522 | return PR_FALSE;
|
---|
2523 | }
|
---|
2524 | }
|
---|
2525 | }
|
---|
2526 |
|
---|
2527 | printf("PASS\n");
|
---|
2528 | return PR_TRUE;
|
---|
2529 | }
|
---|
2530 |
|
---|
2531 | /* PL_strcasestr */
|
---|
2532 | PRBool test_027(void)
|
---|
2533 | {
|
---|
2534 | static struct
|
---|
2535 | {
|
---|
2536 | const char *str;
|
---|
2537 | const char *sub;
|
---|
2538 | PRBool ret;
|
---|
2539 | PRUint32 off;
|
---|
2540 | } array[] =
|
---|
2541 | {
|
---|
2542 | { (const char *)0, (const char *)0, PR_FALSE, 0 },
|
---|
2543 | { (const char *)0, "blah", PR_FALSE, 0 },
|
---|
2544 | { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
|
---|
2545 | { "blah-de-blah", "blah", PR_TRUE, 0 },
|
---|
2546 | { "", "blah", PR_FALSE, 0 },
|
---|
2547 | { "blah-de-blah", "", PR_FALSE, 0 },
|
---|
2548 | { "abcdefg", "a", PR_TRUE, 0 },
|
---|
2549 | { "abcdefg", "c", PR_TRUE, 2 },
|
---|
2550 | { "abcdefg", "e", PR_TRUE, 4 },
|
---|
2551 | { "abcdefg", "g", PR_TRUE, 6 },
|
---|
2552 | { "abcdefg", "i", PR_FALSE, 0 },
|
---|
2553 | { "abcdefg", "ab", PR_TRUE, 0 },
|
---|
2554 | { "abcdefg", "cd", PR_TRUE, 2 },
|
---|
2555 | { "abcdefg", "ef", PR_TRUE, 4 },
|
---|
2556 | { "abcdefg", "gh", PR_FALSE, 0 },
|
---|
2557 | { "abcdabc", "bc", PR_TRUE, 1 },
|
---|
2558 | { "abcdefg", "abcdefg", PR_TRUE, 0 },
|
---|
2559 | { "abcdefgabcdefg", "a", PR_TRUE, 0 },
|
---|
2560 | { "abcdefgabcdefg", "c", PR_TRUE, 2 },
|
---|
2561 | { "abcdefgabcdefg", "e", PR_TRUE, 4 },
|
---|
2562 | { "abcdefgabcdefg", "g", PR_TRUE, 6 },
|
---|
2563 | { "abcdefgabcdefg", "i", PR_FALSE, 0 },
|
---|
2564 | { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
|
---|
2565 | { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
|
---|
2566 | { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
|
---|
2567 | { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
|
---|
2568 | { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
|
---|
2569 | { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
|
---|
2570 | { "ABCDEFG", "a", PR_TRUE, 0 },
|
---|
2571 | { "ABCDEFG", "c", PR_TRUE, 2 },
|
---|
2572 | { "ABCDEFG", "e", PR_TRUE, 4 },
|
---|
2573 | { "ABCDEFG", "g", PR_TRUE, 6 },
|
---|
2574 | { "ABCDEFG", "i", PR_FALSE, 0 },
|
---|
2575 | { "ABCDEFG", "ab", PR_TRUE, 0 },
|
---|
2576 | { "ABCDEFG", "cd", PR_TRUE, 2 },
|
---|
2577 | { "ABCDEFG", "ef", PR_TRUE, 4 },
|
---|
2578 | { "ABCDEFG", "gh", PR_FALSE, 0 },
|
---|
2579 | { "ABCDABC", "bc", PR_TRUE, 1 },
|
---|
2580 | { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
|
---|
2581 | { "ABCDEFGABCDEFG", "a", PR_TRUE, 0 },
|
---|
2582 | { "ABCDEFGABCDEFG", "c", PR_TRUE, 2 },
|
---|
2583 | { "ABCDEFGABCDEFG", "e", PR_TRUE, 4 },
|
---|
2584 | { "ABCDEFGABCDEFG", "g", PR_TRUE, 6 },
|
---|
2585 | { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
|
---|
2586 | { "ABCDEFGABCDEFG", "ab", PR_TRUE, 0 },
|
---|
2587 | { "ABCDEFGABCDEFG", "cd", PR_TRUE, 2 },
|
---|
2588 | { "ABCDEFGABCDEFG", "ef", PR_TRUE, 4 },
|
---|
2589 | { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
|
---|
2590 | { "ABCDABCABCDABC", "bc", PR_TRUE, 1 },
|
---|
2591 | { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 0 }
|
---|
2592 | };
|
---|
2593 |
|
---|
2594 | int i;
|
---|
2595 |
|
---|
2596 | printf("Test 027 (PL_strcasestr) ..."); fflush(stdout);
|
---|
2597 |
|
---|
2598 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2599 | {
|
---|
2600 | char *rv = PL_strcasestr(array[i].str, array[i].sub);
|
---|
2601 |
|
---|
2602 | if( PR_FALSE == array[i].ret )
|
---|
2603 | {
|
---|
2604 | if( (char *)0 != rv )
|
---|
2605 | {
|
---|
2606 | printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
|
---|
2607 | array[i].str ? array[i].str : "(null)",
|
---|
2608 | array[i].sub ? array[i].sub : "(null)",
|
---|
2609 | rv);
|
---|
2610 | return PR_FALSE;
|
---|
2611 | }
|
---|
2612 | }
|
---|
2613 | else
|
---|
2614 | {
|
---|
2615 | if( (char *)0 == rv )
|
---|
2616 | {
|
---|
2617 | printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
|
---|
2618 | array[i].str ? array[i].str : "(null)",
|
---|
2619 | array[i].sub ? array[i].sub : "(null)",
|
---|
2620 | array[i].str, array[i].off);
|
---|
2621 | return PR_FALSE;
|
---|
2622 | }
|
---|
2623 |
|
---|
2624 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2625 | {
|
---|
2626 | printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2627 | array[i].str ? array[i].str : "(null)",
|
---|
2628 | array[i].sub ? array[i].sub : "(null)",
|
---|
2629 | rv, array[i].str, array[i].off);
|
---|
2630 | return PR_FALSE;
|
---|
2631 | }
|
---|
2632 | }
|
---|
2633 | }
|
---|
2634 |
|
---|
2635 | printf("PASS\n");
|
---|
2636 | return PR_TRUE;
|
---|
2637 | }
|
---|
2638 |
|
---|
2639 | /* PL_strcaserstr */
|
---|
2640 | PRBool test_028(void)
|
---|
2641 | {
|
---|
2642 | static struct
|
---|
2643 | {
|
---|
2644 | const char *str;
|
---|
2645 | const char *sub;
|
---|
2646 | PRBool ret;
|
---|
2647 | PRUint32 off;
|
---|
2648 | } array[] =
|
---|
2649 | {
|
---|
2650 | { (const char *)0, (const char *)0, PR_FALSE, 0 },
|
---|
2651 | { (const char *)0, "blah", PR_FALSE, 0 },
|
---|
2652 | { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
|
---|
2653 | { "blah-de-blah", "blah", PR_TRUE, 8 },
|
---|
2654 | { "", "blah", PR_FALSE, 0 },
|
---|
2655 | { "blah-de-blah", "", PR_FALSE, 0 },
|
---|
2656 | { "abcdefg", "a", PR_TRUE, 0 },
|
---|
2657 | { "abcdefg", "c", PR_TRUE, 2 },
|
---|
2658 | { "abcdefg", "e", PR_TRUE, 4 },
|
---|
2659 | { "abcdefg", "g", PR_TRUE, 6 },
|
---|
2660 | { "abcdefg", "i", PR_FALSE, 0 },
|
---|
2661 | { "abcdefg", "ab", PR_TRUE, 0 },
|
---|
2662 | { "abcdefg", "cd", PR_TRUE, 2 },
|
---|
2663 | { "abcdefg", "ef", PR_TRUE, 4 },
|
---|
2664 | { "abcdefg", "gh", PR_FALSE, 0 },
|
---|
2665 | { "abcdabc", "bc", PR_TRUE, 5 },
|
---|
2666 | { "abcdefg", "abcdefg", PR_TRUE, 0 },
|
---|
2667 | { "abcdefgabcdefg", "a", PR_TRUE, 7 },
|
---|
2668 | { "abcdefgabcdefg", "c", PR_TRUE, 9 },
|
---|
2669 | { "abcdefgabcdefg", "e", PR_TRUE, 11 },
|
---|
2670 | { "abcdefgabcdefg", "g", PR_TRUE, 13 },
|
---|
2671 | { "abcdefgabcdefg", "i", PR_FALSE, 0 },
|
---|
2672 | { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
|
---|
2673 | { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
|
---|
2674 | { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
|
---|
2675 | { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
|
---|
2676 | { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
|
---|
2677 | { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
|
---|
2678 | { "ABCDEFG", "a", PR_TRUE, 0 },
|
---|
2679 | { "ABCDEFG", "c", PR_TRUE, 2 },
|
---|
2680 | { "ABCDEFG", "e", PR_TRUE, 4 },
|
---|
2681 | { "ABCDEFG", "g", PR_TRUE, 6 },
|
---|
2682 | { "ABCDEFG", "i", PR_FALSE, 0 },
|
---|
2683 | { "ABCDEFG", "ab", PR_TRUE, 0 },
|
---|
2684 | { "ABCDEFG", "cd", PR_TRUE, 2 },
|
---|
2685 | { "ABCDEFG", "ef", PR_TRUE, 4 },
|
---|
2686 | { "ABCDEFG", "gh", PR_FALSE, 0 },
|
---|
2687 | { "ABCDABC", "bc", PR_TRUE, 5 },
|
---|
2688 | { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
|
---|
2689 | { "ABCDEFGABCDEFG", "a", PR_TRUE, 7 },
|
---|
2690 | { "ABCDEFGABCDEFG", "c", PR_TRUE, 9 },
|
---|
2691 | { "ABCDEFGABCDEFG", "e", PR_TRUE, 11 },
|
---|
2692 | { "ABCDEFGABCDEFG", "g", PR_TRUE, 13 },
|
---|
2693 | { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
|
---|
2694 | { "ABCDEFGABCDEFG", "ab", PR_TRUE, 7 },
|
---|
2695 | { "ABCDEFGABCDEFG", "cd", PR_TRUE, 9 },
|
---|
2696 | { "ABCDEFGABCDEFG", "ef", PR_TRUE, 11 },
|
---|
2697 | { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
|
---|
2698 | { "ABCDABCABCDABC", "bc", PR_TRUE, 12 },
|
---|
2699 | { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 7 }
|
---|
2700 | };
|
---|
2701 |
|
---|
2702 | int i;
|
---|
2703 |
|
---|
2704 | printf("Test 028 (PL_strcaserstr) ..."); fflush(stdout);
|
---|
2705 |
|
---|
2706 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2707 | {
|
---|
2708 | char *rv = PL_strcaserstr(array[i].str, array[i].sub);
|
---|
2709 |
|
---|
2710 | if( PR_FALSE == array[i].ret )
|
---|
2711 | {
|
---|
2712 | if( (char *)0 != rv )
|
---|
2713 | {
|
---|
2714 | printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
|
---|
2715 | array[i].str ? array[i].str : "(null)",
|
---|
2716 | array[i].sub ? array[i].sub : "(null)",
|
---|
2717 | rv);
|
---|
2718 | return PR_FALSE;
|
---|
2719 | }
|
---|
2720 | }
|
---|
2721 | else
|
---|
2722 | {
|
---|
2723 | if( (char *)0 == rv )
|
---|
2724 | {
|
---|
2725 | printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
|
---|
2726 | array[i].str ? array[i].str : "(null)",
|
---|
2727 | array[i].sub ? array[i].sub : "(null)",
|
---|
2728 | array[i].str, array[i].off);
|
---|
2729 | return PR_FALSE;
|
---|
2730 | }
|
---|
2731 |
|
---|
2732 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2733 | {
|
---|
2734 | printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2735 | array[i].str ? array[i].str : "(null)",
|
---|
2736 | array[i].sub ? array[i].sub : "(null)",
|
---|
2737 | rv, array[i].str, array[i].off);
|
---|
2738 | return PR_FALSE;
|
---|
2739 | }
|
---|
2740 | }
|
---|
2741 | }
|
---|
2742 |
|
---|
2743 | printf("PASS\n");
|
---|
2744 | return PR_TRUE;
|
---|
2745 | }
|
---|
2746 |
|
---|
2747 | /* PL_strncasestr */
|
---|
2748 | PRBool test_029(void)
|
---|
2749 | {
|
---|
2750 | static struct
|
---|
2751 | {
|
---|
2752 | const char *str;
|
---|
2753 | const char *sub;
|
---|
2754 | PRUint32 max;
|
---|
2755 | PRBool ret;
|
---|
2756 | PRUint32 off;
|
---|
2757 | } array[] =
|
---|
2758 | {
|
---|
2759 | { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
|
---|
2760 | { (const char *)0, "blah", 12, PR_FALSE, 0 },
|
---|
2761 | { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
|
---|
2762 | { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
|
---|
2763 | { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
|
---|
2764 | { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
|
---|
2765 | { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
|
---|
2766 | { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
|
---|
2767 | { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
|
---|
2768 | { "", "blah", 12, PR_FALSE, 0 },
|
---|
2769 | { "blah-de-blah", "", 12, PR_FALSE, 0 },
|
---|
2770 | { "abcdefg", "a", 5, PR_TRUE, 0 },
|
---|
2771 | { "abcdefg", "c", 5, PR_TRUE, 2 },
|
---|
2772 | { "abcdefg", "e", 5, PR_TRUE, 4 },
|
---|
2773 | { "abcdefg", "g", 5, PR_FALSE, 0 },
|
---|
2774 | { "abcdefg", "i", 5, PR_FALSE, 0 },
|
---|
2775 | { "abcdefg", "ab", 5, PR_TRUE, 0 },
|
---|
2776 | { "abcdefg", "cd", 5, PR_TRUE, 2 },
|
---|
2777 | { "abcdefg", "ef", 5, PR_FALSE, 0 },
|
---|
2778 | { "abcdefg", "gh", 5, PR_FALSE, 0 },
|
---|
2779 | { "abcdabc", "bc", 5, PR_TRUE, 1 },
|
---|
2780 | { "abcdabc", "bc", 6, PR_TRUE, 1 },
|
---|
2781 | { "abcdabc", "bc", 7, PR_TRUE, 1 },
|
---|
2782 | { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2783 | { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2784 | { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
|
---|
2785 | { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
|
---|
2786 | { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
|
---|
2787 | { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
|
---|
2788 | { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
|
---|
2789 | { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
|
---|
2790 | { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
|
---|
2791 | { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
|
---|
2792 | { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
|
---|
2793 | { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
|
---|
2794 | { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
|
---|
2795 | { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
|
---|
2796 | { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
|
---|
2797 | { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2798 | { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2799 | { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
|
---|
2800 | { "ABCDEFG", "a", 5, PR_TRUE, 0 },
|
---|
2801 | { "ABCDEFG", "c", 5, PR_TRUE, 2 },
|
---|
2802 | { "ABCDEFG", "e", 5, PR_TRUE, 4 },
|
---|
2803 | { "ABCDEFG", "g", 5, PR_FALSE, 0 },
|
---|
2804 | { "ABCDEFG", "i", 5, PR_FALSE, 0 },
|
---|
2805 | { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
|
---|
2806 | { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
|
---|
2807 | { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
|
---|
2808 | { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
|
---|
2809 | { "ABCDABC", "bc", 5, PR_TRUE, 1 },
|
---|
2810 | { "ABCDABC", "bc", 6, PR_TRUE, 1 },
|
---|
2811 | { "ABCDABC", "bc", 7, PR_TRUE, 1 },
|
---|
2812 | { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2813 | { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2814 | { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
|
---|
2815 | { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 0 },
|
---|
2816 | { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 2 },
|
---|
2817 | { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 4 },
|
---|
2818 | { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
|
---|
2819 | { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
|
---|
2820 | { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 0 },
|
---|
2821 | { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 2 },
|
---|
2822 | { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
|
---|
2823 | { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
|
---|
2824 | { "ABCDABCABCDABC", "bc", 5, PR_TRUE, 1 },
|
---|
2825 | { "ABCDABCABCDABC", "bc", 6, PR_TRUE, 1 },
|
---|
2826 | { "ABCDABCABCDABC", "bc", 7, PR_TRUE, 1 },
|
---|
2827 | { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2828 | { "ABCDEFGABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2829 | { "ABCDEFGABCDEFG", "abcdefg", 8, PR_TRUE, 0 }
|
---|
2830 | };
|
---|
2831 |
|
---|
2832 | int i;
|
---|
2833 |
|
---|
2834 | printf("Test 029 (PL_strncasestr) ..."); fflush(stdout);
|
---|
2835 |
|
---|
2836 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2837 | {
|
---|
2838 | char *rv = PL_strncasestr(array[i].str, array[i].sub, array[i].max);
|
---|
2839 |
|
---|
2840 | if( PR_FALSE == array[i].ret )
|
---|
2841 | {
|
---|
2842 | if( (char *)0 != rv )
|
---|
2843 | {
|
---|
2844 | printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
|
---|
2845 | array[i].str ? array[i].str : "(null)",
|
---|
2846 | array[i].sub ? array[i].sub : "(null)",
|
---|
2847 | array[i].max, rv);
|
---|
2848 | return PR_FALSE;
|
---|
2849 | }
|
---|
2850 | }
|
---|
2851 | else
|
---|
2852 | {
|
---|
2853 | if( (char *)0 == rv )
|
---|
2854 | {
|
---|
2855 | printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
|
---|
2856 | array[i].str ? array[i].str : "(null)",
|
---|
2857 | array[i].sub ? array[i].sub : "(null)",
|
---|
2858 | array[i].max, array[i].str, array[i].off);
|
---|
2859 | return PR_FALSE;
|
---|
2860 | }
|
---|
2861 |
|
---|
2862 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2863 | {
|
---|
2864 | printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2865 | array[i].str ? array[i].str : "(null)",
|
---|
2866 | array[i].sub ? array[i].sub : "(null)",
|
---|
2867 | array[i].max, rv, array[i].str, array[i].off);
|
---|
2868 | return PR_FALSE;
|
---|
2869 | }
|
---|
2870 | }
|
---|
2871 | }
|
---|
2872 |
|
---|
2873 | printf("PASS\n");
|
---|
2874 | return PR_TRUE;
|
---|
2875 | }
|
---|
2876 |
|
---|
2877 | /* PL_strncaserstr */
|
---|
2878 | PRBool test_030(void)
|
---|
2879 | {
|
---|
2880 | static struct
|
---|
2881 | {
|
---|
2882 | const char *str;
|
---|
2883 | const char *sub;
|
---|
2884 | PRUint32 max;
|
---|
2885 | PRBool ret;
|
---|
2886 | PRUint32 off;
|
---|
2887 | } array[] =
|
---|
2888 | {
|
---|
2889 | { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
|
---|
2890 | { (const char *)0, "blah", 12, PR_FALSE, 0 },
|
---|
2891 | { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
|
---|
2892 | { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
|
---|
2893 | { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
|
---|
2894 | { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
|
---|
2895 | { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
|
---|
2896 | { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
|
---|
2897 | { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
|
---|
2898 | { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
|
---|
2899 | { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
|
---|
2900 | { "", "blah", 12, PR_FALSE, 0 },
|
---|
2901 | { "blah-de-blah", "", 12, PR_FALSE, 0 },
|
---|
2902 | { "abcdefg", "a", 5, PR_TRUE, 0 },
|
---|
2903 | { "abcdefg", "c", 5, PR_TRUE, 2 },
|
---|
2904 | { "abcdefg", "e", 5, PR_TRUE, 4 },
|
---|
2905 | { "abcdefg", "g", 5, PR_FALSE, 0 },
|
---|
2906 | { "abcdefg", "i", 5, PR_FALSE, 0 },
|
---|
2907 | { "abcdefg", "ab", 5, PR_TRUE, 0 },
|
---|
2908 | { "abcdefg", "cd", 5, PR_TRUE, 2 },
|
---|
2909 | { "abcdefg", "ef", 5, PR_FALSE, 0 },
|
---|
2910 | { "abcdefg", "gh", 5, PR_FALSE, 0 },
|
---|
2911 | { "abcdabc", "bc", 5, PR_TRUE, 1 },
|
---|
2912 | { "abcdabc", "bc", 6, PR_TRUE, 1 },
|
---|
2913 | { "abcdabc", "bc", 7, PR_TRUE, 5 },
|
---|
2914 | { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2915 | { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2916 | { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
|
---|
2917 | { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
|
---|
2918 | { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
|
---|
2919 | { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
|
---|
2920 | { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
|
---|
2921 | { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
|
---|
2922 | { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
|
---|
2923 | { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
|
---|
2924 | { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
|
---|
2925 | { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
|
---|
2926 | { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
|
---|
2927 | { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
|
---|
2928 | { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
|
---|
2929 | { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
|
---|
2930 | { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
|
---|
2931 | { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
|
---|
2932 | { "ABCDEFG", "a", 5, PR_TRUE, 0 },
|
---|
2933 | { "ABCDEFG", "c", 5, PR_TRUE, 2 },
|
---|
2934 | { "ABCDEFG", "e", 5, PR_TRUE, 4 },
|
---|
2935 | { "ABCDEFG", "g", 5, PR_FALSE, 0 },
|
---|
2936 | { "ABCDEFG", "i", 5, PR_FALSE, 0 },
|
---|
2937 | { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
|
---|
2938 | { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
|
---|
2939 | { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
|
---|
2940 | { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
|
---|
2941 | { "ABCDABC", "bc", 5, PR_TRUE, 1 },
|
---|
2942 | { "ABCDABC", "bc", 6, PR_TRUE, 1 },
|
---|
2943 | { "ABCDABC", "bc", 7, PR_TRUE, 5 },
|
---|
2944 | { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
|
---|
2945 | { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
|
---|
2946 | { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
|
---|
2947 | { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 7 },
|
---|
2948 | { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 9 },
|
---|
2949 | { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 11 },
|
---|
2950 | { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
|
---|
2951 | { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
|
---|
2952 | { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 7 },
|
---|
2953 | { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 9 },
|
---|
2954 | { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
|
---|
2955 | { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
|
---|
2956 | { "ABCDABCABCDABC", "bc", 12, PR_TRUE, 8 },
|
---|
2957 | { "ABCDABCABCDABC", "bc", 13, PR_TRUE, 8 },
|
---|
2958 | { "ABCDABCABCDABC", "bc", 14, PR_TRUE, 12 },
|
---|
2959 | { "ABCDEFGABCDEFG", "abcdefg", 13, PR_TRUE, 0 },
|
---|
2960 | { "ABCDEFGABCDEFG", "abcdefg", 14, PR_TRUE, 7 },
|
---|
2961 | { "ABCDEFGABCDEFG", "abcdefg", 15, PR_TRUE, 7 }
|
---|
2962 | };
|
---|
2963 |
|
---|
2964 | int i;
|
---|
2965 |
|
---|
2966 | printf("Test 030 (PL_strncaserstr)..."); fflush(stdout);
|
---|
2967 |
|
---|
2968 | for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
|
---|
2969 | {
|
---|
2970 | char *rv = PL_strncaserstr(array[i].str, array[i].sub, array[i].max);
|
---|
2971 |
|
---|
2972 | if( PR_FALSE == array[i].ret )
|
---|
2973 | {
|
---|
2974 | if( (char *)0 != rv )
|
---|
2975 | {
|
---|
2976 | printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
|
---|
2977 | array[i].str ? array[i].str : "(null)",
|
---|
2978 | array[i].sub ? array[i].sub : "(null)",
|
---|
2979 | array[i].max, rv);
|
---|
2980 | return PR_FALSE;
|
---|
2981 | }
|
---|
2982 | }
|
---|
2983 | else
|
---|
2984 | {
|
---|
2985 | if( (char *)0 == rv )
|
---|
2986 | {
|
---|
2987 | printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
|
---|
2988 | array[i].str ? array[i].str : "(null)",
|
---|
2989 | array[i].sub ? array[i].sub : "(null)",
|
---|
2990 | array[i].max, array[i].str, array[i].off);
|
---|
2991 | return PR_FALSE;
|
---|
2992 | }
|
---|
2993 |
|
---|
2994 | if( &array[i].str[ array[i].off ] != rv )
|
---|
2995 | {
|
---|
2996 | printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
|
---|
2997 | array[i].str ? array[i].str : "(null)",
|
---|
2998 | array[i].sub ? array[i].sub : "(null)",
|
---|
2999 | array[i].max, rv, array[i].str, array[i].off);
|
---|
3000 | return PR_FALSE;
|
---|
3001 | }
|
---|
3002 | }
|
---|
3003 | }
|
---|
3004 |
|
---|
3005 | printf("PASS\n");
|
---|
3006 | return PR_TRUE;
|
---|
3007 | }
|
---|
3008 |
|
---|
3009 | /* PL_strtok_r */
|
---|
3010 | PRBool test_031(void)
|
---|
3011 | {
|
---|
3012 | static const char *tokens[] = {
|
---|
3013 | "wtc", "relyea", "nelsonb", "jpierre", "nicolson",
|
---|
3014 | "ian.mcgreer", "kirk.erickson", "sonja.mirtitsch", "mhein"
|
---|
3015 | };
|
---|
3016 |
|
---|
3017 | static const char *seps[] = {
|
---|
3018 | ", ", ",", " ", "\t", ",,,", " ,", " ", " \t\t", ","
|
---|
3019 | };
|
---|
3020 |
|
---|
3021 | static const char s2[] = ", \t";
|
---|
3022 |
|
---|
3023 | char string[ 1024 ];
|
---|
3024 | char *s1;
|
---|
3025 | char *token;
|
---|
3026 | char *lasts;
|
---|
3027 | unsigned int i;
|
---|
3028 |
|
---|
3029 | printf("Test 031 (PL_strtok_r) ..."); fflush(stdout);
|
---|
3030 |
|
---|
3031 | /* Build the string. */
|
---|
3032 | string[0] = '\0';
|
---|
3033 | for( i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++ )
|
---|
3034 | {
|
---|
3035 | PL_strcat(string, tokens[i]);
|
---|
3036 | PL_strcat(string, seps[i]);
|
---|
3037 | }
|
---|
3038 |
|
---|
3039 | /* Scan the string for tokens. */
|
---|
3040 | i = 0;
|
---|
3041 | s1 = string;
|
---|
3042 | while( (token = PL_strtok_r(s1, s2, &lasts)) != NULL)
|
---|
3043 | {
|
---|
3044 | if( PL_strcmp(token, tokens[i]) != 0 )
|
---|
3045 | {
|
---|
3046 | printf("FAIL wrong token scanned\n");
|
---|
3047 | return PR_FALSE;
|
---|
3048 | }
|
---|
3049 | i++;
|
---|
3050 | s1 = NULL;
|
---|
3051 | }
|
---|
3052 | if( i != sizeof(tokens)/sizeof(tokens[0]) )
|
---|
3053 | {
|
---|
3054 | printf("FAIL wrong number of tokens scanned\n");
|
---|
3055 | return PR_FALSE;
|
---|
3056 | }
|
---|
3057 |
|
---|
3058 | printf("PASS\n");
|
---|
3059 | return PR_TRUE;
|
---|
3060 | }
|
---|
3061 |
|
---|
3062 | int
|
---|
3063 | main
|
---|
3064 | (
|
---|
3065 | int argc,
|
---|
3066 | char *argv[]
|
---|
3067 | )
|
---|
3068 | {
|
---|
3069 | printf("Testing the Portable Library string functions:\n");
|
---|
3070 |
|
---|
3071 | if( 1
|
---|
3072 | && test_001()
|
---|
3073 | && test_001()
|
---|
3074 | && test_002()
|
---|
3075 | && test_003()
|
---|
3076 | && test_004()
|
---|
3077 | && test_005()
|
---|
3078 | && test_006()
|
---|
3079 | && test_007()
|
---|
3080 | && test_008()
|
---|
3081 | && test_009()
|
---|
3082 | && test_010()
|
---|
3083 | && test_011()
|
---|
3084 | && test_012()
|
---|
3085 | && test_013()
|
---|
3086 | && test_014()
|
---|
3087 | && test_015()
|
---|
3088 | && test_016()
|
---|
3089 | && test_017()
|
---|
3090 | && test_018()
|
---|
3091 | && test_019()
|
---|
3092 | && test_020()
|
---|
3093 | && test_021()
|
---|
3094 | && test_022()
|
---|
3095 | && test_023()
|
---|
3096 | && test_024()
|
---|
3097 | && test_025()
|
---|
3098 | && test_026()
|
---|
3099 | && test_027()
|
---|
3100 | && test_028()
|
---|
3101 | && test_029()
|
---|
3102 | && test_030()
|
---|
3103 | && test_031()
|
---|
3104 | )
|
---|
3105 | {
|
---|
3106 | printf("Suite passed.\n");
|
---|
3107 | return 0;
|
---|
3108 | }
|
---|
3109 | else
|
---|
3110 | {
|
---|
3111 | printf("Suite failed.\n");
|
---|
3112 | return 1;
|
---|
3113 | }
|
---|
3114 |
|
---|
3115 | /*NOTREACHED*/
|
---|
3116 | }
|
---|