1/*
2 * Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de
3 * Distributed under the terms of the MIT License.
4 */
5
6#define _GNU_SOURCE
7	// for wmempcpy() and wcschrnul()
8
9#include <errno.h>
10#include <locale.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <time.h>
15#include <wchar.h>
16
17
18static int sign (int a)
19{
20	if (a < 0)
21		return -1;
22	if (a > 0)
23		return 1;
24	return 0;
25}
26
27
28// #pragma mark - wcslen -------------------------------------------------------
29
30
31void
32test_wcslen()
33{
34	printf("wcslen()/wcsnlen()\n");
35
36	int problemCount = 0;
37	errno = 0;
38
39	{
40		const wchar_t* string = L"";
41		size_t result = wcslen(string);
42		size_t expected = 0;
43		if (result != expected || errno != 0) {
44			printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu),"
45					" errno = %x (expected %x)\n", string, result, expected,
46				errno, 0);
47			problemCount++;
48		}
49	}
50
51	{
52		const wchar_t* string = L"test";
53		size_t result = wcslen(string);
54		size_t expected = 4;
55		if (result != expected || errno != 0) {
56			printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu),"
57					" errno = %x (expected %x)\n", string, result, expected,
58				errno, 0);
59			problemCount++;
60		}
61	}
62
63	{
64		const wchar_t* string = L"t\xE4st";
65		size_t result = wcslen(string);
66		size_t expected = 4;
67		if (result != expected || errno != 0) {
68			printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu),"
69					" errno = %x (expected %x)\n", string, result, expected,
70				errno, 0);
71			problemCount++;
72		}
73	}
74
75	{
76		const wchar_t* string = L"te\x00st";
77		size_t result = wcslen(string);
78		size_t expected = 2;
79		if (result != expected || errno != 0) {
80			printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu),"
81					" errno = %x (expected %x)\n", string, result, expected,
82				errno, 0);
83			problemCount++;
84		}
85	}
86
87	{
88		const wchar_t* string = L"test";
89		size_t result = wcsnlen(string, 0);
90		size_t expected = 0;
91		if (result != expected || errno != 0) {
92			printf("\tPROBLEM: result for wcsnlen(\"%ls\", 0) = %lu "
93					"(expected %lu), errno = %x (expected %x)\n",
94				string, result, expected, errno, 0);
95			problemCount++;
96		}
97	}
98
99	{
100		const wchar_t* string = L"test";
101		size_t result = wcsnlen(string, 4);
102		size_t expected = 4;
103		if (result != expected || errno != 0) {
104			printf("\tPROBLEM: result for wcsnlen(\"%ls\", 4) = %lu "
105					"(expected %lu), errno = %x (expected %x)\n",
106				string, result, expected, errno, 0);
107			problemCount++;
108		}
109	}
110
111	{
112		const wchar_t* string = L"test";
113		size_t result = wcsnlen(string, 6);
114		size_t expected = 4;
115		if (result != expected || errno != 0) {
116			printf("\tPROBLEM: result for wcsnlen(\"%ls\", 6) = %lu "
117					"(expected %lu), errno = %x (expected %x)\n",
118				string, result, expected, errno, 0);
119			problemCount++;
120		}
121	}
122
123	if (problemCount)
124		printf("\t%d problem(s) found!\n", problemCount);
125	else
126		printf("\tall fine\n");
127}
128
129
130// #pragma mark - wcscmp -------------------------------------------------------
131
132
133void
134test_wcscmp()
135{
136	printf("wcscmp()/wcsncmp()\n");
137
138	int problemCount = 0;
139	errno = 0;
140
141	{
142		const wchar_t* a = L"";
143		const wchar_t* b = L"";
144		int result = sign(wcscmp(a, b));
145		int expected = 0;
146		if (result != expected || errno != 0) {
147			printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d "
148					"(expected %d), errno = %x (expected 0)\n", a, b, result,
149				expected, errno);
150			problemCount++;
151		}
152	}
153
154	{
155		const wchar_t* a = L"a";
156		const wchar_t* b = L"b";
157		int result = sign(wcscmp(a, b));
158		int expected = -1;
159		if (result != expected || errno != 0) {
160			printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d "
161					"(expected %d), errno = %x (expected 0)\n", a, b, result,
162				expected, errno);
163			problemCount++;
164		}
165	}
166
167	{
168		const wchar_t* a = L"b";
169		const wchar_t* b = L"a";
170		int result = sign(wcscmp(a, b));
171		int expected = 1;
172		if (result != expected || errno != 0) {
173			printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d "
174					"(expected %d), errno = %x (expected 0)\n", a, b, result,
175				expected, errno);
176			problemCount++;
177		}
178	}
179
180	{
181		const wchar_t* a = L"a";
182		const wchar_t* b = L"A";
183		int result = sign(wcscmp(a, b));
184		int expected = 1;
185		if (result != expected || errno != 0) {
186			printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d "
187					"(expected %d), errno = %x (expected 0)\n", a, b, result,
188				expected, errno);
189			problemCount++;
190		}
191	}
192
193	{
194		const wchar_t* a = L"t��st";
195		const wchar_t* b = L"t��st";
196		int result = sign(wcscmp(a, b));
197		int expected = 0;
198		if (result != expected || errno != 0) {
199			printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d "
200					"(expected %d), errno = %x (expected 0)\n", a, b, result,
201				expected, errno);
202			problemCount++;
203		}
204	}
205
206	{
207		const wchar_t* a = L"t��st";
208		const wchar_t* b = L"t��st ";
209		int result = sign(wcscmp(a, b));
210		int expected = -1;
211		if (result != expected || errno != 0) {
212			printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d "
213					"(expected %d), errno = %x (expected 0)\n", a, b, result,
214				expected, errno);
215			problemCount++;
216		}
217	}
218
219	{
220		const wchar_t* a = L"t��St";
221		const wchar_t* b = L"t��s";
222		int result = sign(wcscmp(a, b));
223		int expected = -1;
224		if (result != expected || errno != 0) {
225			printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d "
226					"(expected %d), errno = %x (expected 0)\n", a, b, result,
227				expected, errno);
228			problemCount++;
229		}
230	}
231
232	{
233		const wchar_t* a = L"t��st1";
234		const wchar_t* b = L"t��st0";
235		int result = sign(wcsncmp(a, b, 0));
236		int expected = 0;
237		if (result != expected || errno != 0) {
238			printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 0) = %d "
239					"(expected %d), errno = %x (expected 0)\n", a, b, result,
240				expected, errno);
241			problemCount++;
242		}
243	}
244
245	{
246		const wchar_t* a = L"t��st1";
247		const wchar_t* b = L"t��st0";
248		int result = sign(wcsncmp(a, b, 4));
249		int expected = 0;
250		if (result != expected || errno != 0) {
251			printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 4) = %d "
252					"(expected %d), errno = %x (expected 0)\n", a, b, result,
253				expected, errno);
254			problemCount++;
255		}
256	}
257
258	{
259		const wchar_t* a = L"t��st1";
260		const wchar_t* b = L"t��st0";
261		int result = sign(wcsncmp(a, b, 5));
262		int expected = 1;
263		if (result != expected || errno != 0) {
264			printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 5) = %d "
265					"(expected %d), errno = %x (expected 0)\n", a, b, result,
266				expected, errno);
267			problemCount++;
268		}
269	}
270
271	{
272		const wchar_t* a = L"t��s";
273		const wchar_t* b = L"t��st123";
274		int result = sign(wcsncmp(a, b, (size_t)-1));
275		int expected = -1;
276		if (result != expected || errno != 0) {
277			printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", -1) = %d "
278					"(expected %d), errno = %x (expected 0)\n", a, b, result,
279				expected, errno);
280			problemCount++;
281		}
282	}
283
284	if (problemCount)
285		printf("\t%d problem(s) found!\n", problemCount);
286	else
287		printf("\tall fine\n");
288}
289
290
291// #pragma mark - wcscasecmp ---------------------------------------------------
292
293
294void
295test_wcscasecmp()
296{
297	printf("wcscasecmp()/wcsncasecmp()\n");
298
299	int problemCount = 0;
300	errno = 0;
301
302	{
303		const wchar_t* a = L"";
304		const wchar_t* b = L"";
305		int result = sign(wcscasecmp(a, b));
306		int expected = 0;
307		if (result != expected || errno != 0) {
308			printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d "
309					"(expected %d), errno = %x (expected 0)\n", a, b, result,
310				expected, errno);
311			problemCount++;
312		}
313	}
314
315	{
316		const wchar_t* a = L"a";
317		const wchar_t* b = L"b";
318		int result = sign(wcscasecmp(a, b));
319		int expected = -1;
320		if (result != expected || errno != 0) {
321			printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d "
322					"(expected %d), errno = %x (expected 0)\n", a, b, result,
323				expected, errno);
324			problemCount++;
325		}
326	}
327
328	{
329		const wchar_t* a = L"B";
330		const wchar_t* b = L"a";
331		int result = sign(wcscasecmp(a, b));
332		int expected = 1;
333		if (result != expected || errno != 0) {
334			printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d "
335					"(expected %d), errno = %x (expected 0)\n", a, b, result,
336				expected, errno);
337			problemCount++;
338		}
339	}
340
341	{
342		const wchar_t* a = L"a";
343		const wchar_t* b = L"A";
344		int result = sign(wcscasecmp(a, b));
345		int expected = 0;
346		if (result != expected || errno != 0) {
347			printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d "
348					"(expected %d), errno = %x (expected 0)\n", a, b, result,
349				expected, errno);
350			problemCount++;
351		}
352	}
353
354	{
355		const wchar_t* a = L"T��ST";
356		const wchar_t* b = L"t��st";
357		int result = sign(wcscasecmp(a, b));
358		int expected = 0;
359		if (result != expected || errno != 0) {
360			printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d "
361					"(expected %d), errno = %x (expected 0)\n", a, b, result,
362				expected, errno);
363			problemCount++;
364		}
365	}
366
367	{
368		const wchar_t* a = L"t��st";
369		const wchar_t* b = L"t��st ";
370		int result = sign(wcscasecmp(a, b));
371		int expected = -1;
372		if (result != expected || errno != 0) {
373			printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d "
374					"(expected %d), errno = %x (expected 0)\n", a, b, result,
375				expected, errno);
376			problemCount++;
377		}
378	}
379
380	{
381		const wchar_t* a = L"T��St";
382		const wchar_t* b = L"t��s";
383		int result = sign(wcscasecmp(a, b));
384		int expected = 1;
385		if (result != expected || errno != 0) {
386			printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d "
387					"(expected %d), errno = %x (expected 0)\n", a, b, result,
388				expected, errno);
389			problemCount++;
390		}
391	}
392
393	{
394		const wchar_t* a = L"t��st1";
395		const wchar_t* b = L"t��st0";
396		int result = sign(wcsncasecmp(a, b, 0));
397		int expected = 0;
398		if (result != expected || errno != 0) {
399			printf("\tPROBLEM: result for wcscasencmp(\"%ls\", \"%ls\", 0) = %d"
400					" (expected %d), errno = %x (expected 0)\n", a, b, result,
401				expected, errno);
402			problemCount++;
403		}
404	}
405
406	{
407		const wchar_t* a = L"t��st1";
408		const wchar_t* b = L"t��St0";
409		int result = sign(wcsncasecmp(a, b, 4));
410		int expected = 0;
411		if (result != expected || errno != 0) {
412			printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", 4) = %d"
413					" (expected %d), errno = %x (expected 0)\n", a, b, result,
414				expected, errno);
415			problemCount++;
416		}
417	}
418
419	{
420		const wchar_t* a = L"t��sT1";
421		const wchar_t* b = L"t��st0";
422		int result = sign(wcsncasecmp(a, b, 5));
423		int expected = 1;
424		if (result != expected || errno != 0) {
425			printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", 5) = %d"
426					" (expected %d), errno = %x (expected 0)\n", a, b, result,
427				expected, errno);
428			problemCount++;
429		}
430	}
431
432	{
433		const wchar_t* a = L"t��s";
434		const wchar_t* b = L"t��St123";
435		int result = sign(wcsncasecmp(a, b, (size_t)-1));
436		int expected = -1;
437		if (result != expected || errno != 0) {
438			printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", -1) = "
439					"%d (expected %d), errno = %x (expected 0)\n", a, b, result,
440				expected, errno);
441			problemCount++;
442		}
443	}
444
445	if (problemCount)
446		printf("\t%d problem(s) found!\n", problemCount);
447	else
448		printf("\tall fine\n");
449}
450
451
452// #pragma mark - wcschr -------------------------------------------------------
453
454
455void
456test_wcschr()
457{
458	printf("wcschr()/wcschrnul()/wcsrchr()\n");
459
460	int problemCount = 0;
461	errno = 0;
462
463	{
464		const wchar_t* string = L"";
465		const wchar_t ch = L' ';
466		const wchar_t* result = wcschr(string, ch);
467		const wchar_t* expected = NULL;
468		if (result != expected || errno != 0) {
469			printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p "
470					"(expected %p), errno = %x (expected 0)\n", string, ch,
471				result, expected, errno);
472			problemCount++;
473		}
474	}
475
476	{
477		const wchar_t* string = L"";
478		const wchar_t ch = L'\0';
479		const wchar_t* result = wcschr(string, ch);
480		const wchar_t* expected = string;
481		if (result != expected || errno != 0) {
482			printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p "
483					"(expected %p), errno = %x (expected 0)\n", string, ch,
484				result, expected, errno);
485			problemCount++;
486		}
487	}
488
489	{
490		const wchar_t* string = L"sometext";
491		const wchar_t ch = L' ';
492		const wchar_t* result = wcschr(string, ch);
493		const wchar_t* expected = NULL;
494		if (result != expected || errno != 0) {
495			printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p "
496					"(expected %p), errno = %x (expected 0)\n", string, ch,
497				result, expected, errno);
498			problemCount++;
499		}
500	}
501
502	{
503		const wchar_t* string = L"some more text";
504		const wchar_t ch = L' ';
505		const wchar_t* result = wcschr(string, ch);
506		const wchar_t* expected = string + 4;
507		if (result != expected || errno != 0) {
508			printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p "
509					"(expected %p), errno = %x (expected 0)\n", string, ch,
510				result, expected, errno);
511			problemCount++;
512		}
513	}
514
515	{
516		const wchar_t* string = L"some more text";
517		const wchar_t ch = L's';
518		const wchar_t* result = wcschr(string, ch);
519		const wchar_t* expected = string;
520		if (result != expected || errno != 0) {
521			printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p "
522					"(expected %p), errno = %x (expected 0)\n", string, ch,
523				result, expected, errno);
524			problemCount++;
525		}
526	}
527
528	{
529		const wchar_t* string = L"some more text";
530		const wchar_t ch = L'S';
531		const wchar_t* result = wcschr(string, ch);
532		const wchar_t* expected = NULL;
533		if (result != expected || errno != 0) {
534			printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p "
535					"(expected %p), errno = %x (expected 0)\n", string, ch,
536				result, expected, errno);
537			problemCount++;
538		}
539	}
540
541	{
542		const wchar_t* string = L"some more text";
543		const wchar_t ch = L'\0';
544		const wchar_t* result = wcschr(string, ch);
545		const wchar_t* expected = string + 14;
546		if (result != expected || errno != 0) {
547			printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p "
548					"(expected %p), errno = %x (expected 0)\n", string, ch,
549				result, expected, errno);
550			problemCount++;
551		}
552	}
553
554	{
555		const wchar_t* string = L"";
556		const wchar_t ch = L' ';
557		const wchar_t* result = wcschrnul(string, ch);
558		const wchar_t* expected = string;
559		if (result != expected || errno != 0) {
560			printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p "
561					"(expected %p), errno = %x (expected 0)\n", string, ch,
562				result, expected, errno);
563			problemCount++;
564		}
565	}
566
567	{
568		const wchar_t* string = L"";
569		const wchar_t ch = L'\0';
570		const wchar_t* result = wcschrnul(string, ch);
571		const wchar_t* expected = string;
572		if (result != expected || errno != 0) {
573			printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p "
574					"(expected %p), errno = %x (expected 0)\n", string, ch,
575				result, expected, errno);
576			problemCount++;
577		}
578	}
579
580	{
581		const wchar_t* string = L"sometext";
582		const wchar_t ch = L' ';
583		const wchar_t* result = wcschrnul(string, ch);
584		const wchar_t* expected = string + wcslen(string);
585		if (result != expected || errno != 0) {
586			printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p "
587					"(expected %p), errno = %x (expected 0)\n", string, ch,
588				result, expected, errno);
589			problemCount++;
590		}
591	}
592
593	{
594		const wchar_t* string = L"some more text";
595		const wchar_t ch = L' ';
596		const wchar_t* result = wcschrnul(string, ch);
597		const wchar_t* expected = string + 4;
598		if (result != expected || errno != 0) {
599			printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p "
600					"(expected %p), errno = %x (expected 0)\n", string, ch,
601				result, expected, errno);
602			problemCount++;
603		}
604	}
605
606	{
607		const wchar_t* string = L"some more text";
608		const wchar_t ch = L's';
609		const wchar_t* result = wcschrnul(string, ch);
610		const wchar_t* expected = string;
611		if (result != expected || errno != 0) {
612			printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p "
613					"(expected %p), errno = %x (expected 0)\n", string, ch,
614				result, expected, errno);
615			problemCount++;
616		}
617	}
618
619	{
620		const wchar_t* string = L"some more text";
621		const wchar_t ch = L'S';
622		const wchar_t* result = wcschrnul(string, ch);
623		const wchar_t* expected = string + wcslen(string);
624		if (result != expected || errno != 0) {
625			printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p "
626					"(expected %p), errno = %x (expected 0)\n", string, ch,
627				result, expected, errno);
628			problemCount++;
629		}
630	}
631
632	{
633		const wchar_t* string = L"some more text";
634		const wchar_t ch = L'\0';
635		const wchar_t* result = wcschrnul(string, ch);
636		const wchar_t* expected = string + 14;
637		if (result != expected || errno != 0) {
638			printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p "
639					"(expected %p), errno = %x (expected 0)\n", string, ch,
640				result, expected, errno);
641			problemCount++;
642		}
643	}
644
645	{
646		const wchar_t* string = L"";
647		const wchar_t ch = L' ';
648		const wchar_t* result = wcsrchr(string, ch);
649		const wchar_t* expected = NULL;
650		if (result != expected || errno != 0) {
651			printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p "
652					"(expected %p), errno = %x (expected 0)\n", string, ch,
653				result, expected, errno);
654			problemCount++;
655		}
656	}
657
658	{
659		const wchar_t* string = L"";
660		const wchar_t ch = L'\0';
661		const wchar_t* result = wcsrchr(string, ch);
662		const wchar_t* expected = string;
663		if (result != expected || errno != 0) {
664			printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p "
665					"(expected %p), errno = %x (expected 0)\n", string, ch,
666				result, expected, errno);
667			problemCount++;
668		}
669	}
670
671	{
672		const wchar_t* string = L"sometext";
673		const wchar_t ch = L' ';
674		const wchar_t* result = wcsrchr(string, ch);
675		const wchar_t* expected = NULL;
676		if (result != expected || errno != 0) {
677			printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p "
678					"(expected %p), errno = %x (expected 0)\n", string, ch,
679				result, expected, errno);
680			problemCount++;
681		}
682	}
683
684	{
685		const wchar_t* string = L"some more text";
686		const wchar_t ch = L' ';
687		const wchar_t* result = wcsrchr(string, ch);
688		const wchar_t* expected = string + 9;
689		if (result != expected || errno != 0) {
690			printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p "
691					"(expected %p), errno = %x (expected 0)\n", string, ch,
692				result, expected, errno);
693			problemCount++;
694		}
695	}
696
697	{
698		const wchar_t* string = L"some more text";
699		const wchar_t ch = L's';
700		const wchar_t* result = wcsrchr(string, ch);
701		const wchar_t* expected = string;
702		if (result != expected || errno != 0) {
703			printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p "
704					"(expected %p), errno = %x (expected 0)\n", string, ch,
705				result, expected, errno);
706			problemCount++;
707		}
708	}
709
710	{
711		const wchar_t* string = L"some more text";
712		const wchar_t ch = L'S';
713		const wchar_t* result = wcsrchr(string, ch);
714		const wchar_t* expected = NULL;
715		if (result != expected || errno != 0) {
716			printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p "
717					"(expected %p), errno = %x (expected 0)\n", string, ch,
718				result, expected, errno);
719			problemCount++;
720		}
721	}
722
723	{
724		const wchar_t* string = L"some more text";
725		const wchar_t ch = L'\0';
726		const wchar_t* result = wcsrchr(string, ch);
727		const wchar_t* expected = string + 14;
728		if (result != expected || errno != 0) {
729			printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p "
730					"(expected %p), errno = %x (expected 0)\n", string, ch,
731				result, expected, errno);
732			problemCount++;
733		}
734	}
735
736	if (problemCount)
737		printf("\t%d problem(s) found!\n", problemCount);
738	else
739		printf("\tall fine\n");
740}
741
742
743// #pragma mark - wcsdup -------------------------------------------------------
744
745
746void
747test_wcsdup()
748{
749	printf("wcsdup()\n");
750
751	int problemCount = 0;
752	errno = 0;
753
754#ifdef __HAIKU__
755	{
756		const wchar_t* string = NULL;
757		wchar_t* result = wcsdup(string);
758		if (result != NULL || errno != 0) {
759			printf("\tPROBLEM: result for wcsdup(%p) = \"%ls\", errno = %x"
760					" (expected 0)\n", string, result, errno);
761			problemCount++;
762		}
763	}
764#endif
765
766	{
767		const wchar_t* string = L"";
768		wchar_t* result = wcsdup(string);
769		if (result == NULL || wcscmp(result, string) != 0 || errno != 0) {
770			printf("\tPROBLEM: result for wcsdup(\"%ls\") = \"%ls\", errno = %x"
771					" (expected 0)\n", string, result, errno);
772			problemCount++;
773		}
774	}
775
776	{
777		const wchar_t* string = L"t��stdata with some char��cters";
778		wchar_t* result = wcsdup(string);
779		if (result == NULL || wcscmp(result, string) != 0 || errno != 0) {
780			printf("\tPROBLEM: result for wcsdup(\"%ls\") = \"%ls\", errno = %x"
781					" (expected 0)\n", string, result, errno);
782			problemCount++;
783		}
784	}
785
786	if (problemCount)
787		printf("\t%d problem(s) found!\n", problemCount);
788	else
789		printf("\tall fine\n");
790}
791
792
793// #pragma mark - wcscpy -------------------------------------------------------
794
795
796void
797test_wcscpy()
798{
799	printf("wcscpy()/wcsncpy()\n");
800
801	int problemCount = 0;
802	errno = 0;
803
804	{
805		const wchar_t* source = L"";
806		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
807		wchar_t* result = wcscpy(destination, source);
808		if (result != destination) {
809			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, "
810					"expected %p\n", source, result, destination);
811			problemCount++;
812		}
813		if (errno != 0) {
814			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, "
815					"expected 0\n", source, errno);
816			problemCount++;
817		}
818		if (wcslen(destination) != 0) {
819			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
820					"wcslen(destination)=%lu, expected 0\n", source,
821				wcslen(destination));
822			problemCount++;
823		}
824		if (destination[0] != L'\0') {
825			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
826					"destination[0]=%x, expected %x\n", source, destination[0],
827				L'\0');
828			problemCount++;
829		}
830		if (destination[1] != L'X') {
831			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
832					"destination[1]=%x, expected %x\n", source, destination[1],
833				L'X');
834			problemCount++;
835		}
836	}
837
838	{
839		const wchar_t* source = L"test";
840		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
841		wchar_t* result = wcscpy(destination, source);
842		if (result != destination) {
843			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, "
844					"expected %p\n", source, result, destination);
845			problemCount++;
846		}
847		if (errno != 0) {
848			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, "
849					"expected 0\n", source, errno);
850			problemCount++;
851		}
852		if (wcslen(destination) != 4) {
853			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
854					"wcslen(destination)=%lu, expected 4\n", source,
855				wcslen(destination));
856			problemCount++;
857		}
858		if (destination[0] != L't') {
859			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
860					"destination[0]=%x, expected %x\n", source, destination[0],
861				L't');
862			problemCount++;
863		}
864		if (destination[1] != L'e') {
865			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
866					"destination[1]=%x, expected %x\n", source, destination[1],
867				L'e');
868			problemCount++;
869		}
870		if (destination[2] != L's') {
871			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
872					"destination[2]=%x, expected %x\n", source, destination[2],
873				L's');
874			problemCount++;
875		}
876		if (destination[3] != L't') {
877			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
878					"destination[3]=%x, expected %x\n", source, destination[3],
879				L't');
880			problemCount++;
881		}
882		if (destination[4] != L'\0') {
883			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
884					"destination[4]=%x, expected %x\n", source, destination[4],
885				L'\0');
886			problemCount++;
887		}
888		if (destination[5] != L'X') {
889			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
890					"destination[5]=%x, expected %x\n", source, destination[5],
891				L'X');
892			problemCount++;
893		}
894	}
895
896	{
897		const wchar_t* source = L"t\xE4st";
898		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
899		wchar_t* result = wcscpy(destination, source);
900		if (result != destination) {
901			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, "
902					"expected %p\n", source, result, destination);
903			problemCount++;
904		}
905		if (errno != 0) {
906			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, "
907					"expected 0\n", source, errno);
908			problemCount++;
909		}
910		if (wcslen(destination) != 4) {
911			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
912					"wcslen(destination)=%lu, expected 4\n", source,
913				wcslen(destination));
914			problemCount++;
915		}
916		if (destination[0] != L't') {
917			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
918					"destination[0]=%x, expected %x\n", source, destination[0],
919				L't');
920			problemCount++;
921		}
922		if (destination[1] != L'\xE4') {
923			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
924					"destination[1]=%x, expected %x\n", source, destination[1],
925				L'\xE4');
926			problemCount++;
927		}
928		if (destination[2] != L's') {
929			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
930					"destination[2]=%x, expected %x\n", source, destination[2],
931				L's');
932			problemCount++;
933		}
934		if (destination[3] != L't') {
935			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
936					"destination[3]=%x, expected %x\n", source, destination[3],
937				L't');
938			problemCount++;
939		}
940		if (destination[4] != L'\0') {
941			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
942					"destination[4]=%x, expected %x\n", source, destination[4],
943				L'\0');
944			problemCount++;
945		}
946		if (destination[5] != L'X') {
947			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
948					"destination[5]=%x, expected %x\n", source, destination[5],
949				L'X');
950			problemCount++;
951		}
952	}
953
954	{
955		const wchar_t* source = L"te\x00st";
956		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
957		wchar_t* result = wcscpy(destination, source);
958		if (result != destination) {
959			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, "
960					"expected %p\n", source, result, destination);
961			problemCount++;
962		}
963		if (errno != 0) {
964			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, "
965					"expected 0\n", source, errno);
966			problemCount++;
967		}
968		if (wcslen(destination) != 2) {
969			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
970					"wcslen(destination)=%lu, expected 2\n", source,
971				wcslen(destination));
972			problemCount++;
973		}
974		if (destination[0] != L't') {
975			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
976					"destination[0]=%x, expected %x\n", source, destination[0],
977				L't');
978			problemCount++;
979		}
980		if (destination[1] != L'e') {
981			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
982					"destination[1]=%x, expected %x\n", source, destination[1],
983				L'e');
984			problemCount++;
985		}
986		if (destination[2] != L'\0') {
987			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
988					"destination[2]=%x, expected %x\n", source, destination[2],
989				L'\0');
990			problemCount++;
991		}
992		if (destination[3] != L'X') {
993			printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> "
994					"destination[3]=%x, expected %x\n", source, destination[3],
995				L'X');
996			problemCount++;
997		}
998	}
999
1000	{
1001		const wchar_t* source = L"t\xE4st";
1002		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1003		wchar_t* result = wcsncpy(destination, source, 0);
1004		if (result != destination) {
1005			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> result=%p, "
1006					"expected %p\n", source, result, destination);
1007			problemCount++;
1008		}
1009		if (errno != 0) {
1010			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> errno=%d, "
1011					"expected 0\n", source, errno);
1012			problemCount++;
1013		}
1014		if (destination[0] != L'X') {
1015			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> "
1016					"destination[0]=%x, expected %x\n", source, destination[0],
1017				L'X');
1018			problemCount++;
1019		}
1020	}
1021
1022	{
1023		const wchar_t* source = L"t\xE4st";
1024		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1025		wchar_t* result = wcsncpy(destination, source, 2);
1026		if (result != destination) {
1027			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> result=%p, "
1028					"expected %p\n", source, result, destination);
1029			problemCount++;
1030		}
1031		if (errno != 0) {
1032			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> errno=%d, "
1033					"expected 0\n", source, errno);
1034			problemCount++;
1035		}
1036		if (destination[0] != L't') {
1037			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> "
1038					"destination[0]=%x, expected %x\n", source, destination[0],
1039				L't');
1040			problemCount++;
1041		}
1042		if (destination[1] != L'\xE4') {
1043			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> "
1044					"destination[1]=%x, expected %x\n", source, destination[1],
1045				L'\xE4');
1046			problemCount++;
1047		}
1048		if (destination[2] != L'X') {
1049			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> "
1050					"destination[2]=%x, expected %x\n", source, destination[2],
1051				L'X');
1052			problemCount++;
1053		}
1054	}
1055
1056	{
1057		const wchar_t* source = L"t\xE4st";
1058		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1059		wchar_t* result = wcsncpy(destination, source, 4);
1060		if (result != destination) {
1061			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> result=%p, "
1062					"expected %p\n", source, result, destination);
1063			problemCount++;
1064		}
1065		if (errno != 0) {
1066			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> errno=%d, "
1067					"expected 0\n", source, errno);
1068			problemCount++;
1069		}
1070		if (destination[0] != L't') {
1071			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> "
1072					"destination[0]=%x, expected %x\n", source, destination[0],
1073				L't');
1074			problemCount++;
1075		}
1076		if (destination[1] != L'\xE4') {
1077			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> "
1078					"destination[1]=%x, expected %x\n", source, destination[1],
1079				L'\xE4');
1080			problemCount++;
1081		}
1082		if (destination[2] != L's') {
1083			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> "
1084					"destination[2]=%x, expected %x\n", source, destination[2],
1085				L's');
1086			problemCount++;
1087		}
1088		if (destination[3] != L't') {
1089			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> "
1090					"destination[3]=%x, expected %x\n", source, destination[3],
1091				L't');
1092			problemCount++;
1093		}
1094		if (destination[4] != L'X') {
1095			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> "
1096					"destination[4]=%x, expected %x\n", source, destination[4],
1097				L'X');
1098			problemCount++;
1099		}
1100	}
1101
1102	{
1103		const wchar_t* source = L"t\xE4st";
1104		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1105		wchar_t* result = wcsncpy(destination, source, 8);
1106		if (result != destination) {
1107			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> result=%p, "
1108					"expected %p\n", source, result, destination);
1109			problemCount++;
1110		}
1111		if (errno != 0) {
1112			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> errno=%d, "
1113					"expected 0\n", source, errno);
1114			problemCount++;
1115		}
1116		if (wcslen(destination) != 4) {
1117			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1118					"wcslen(destination)=%lu, expected 4\n", source,
1119				wcslen(destination));
1120			problemCount++;
1121		}
1122		if (destination[0] != L't') {
1123			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1124					"destination[0]=%x, expected %x\n", source, destination[0],
1125				L't');
1126			problemCount++;
1127		}
1128		if (destination[1] != L'\xE4') {
1129			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1130					"destination[1]=%x, expected %x\n", source, destination[1],
1131				L'\xE4');
1132			problemCount++;
1133		}
1134		if (destination[2] != L's') {
1135			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1136					"destination[2]=%x, expected %x\n", source, destination[2],
1137				L's');
1138			problemCount++;
1139		}
1140		if (destination[3] != L't') {
1141			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1142					"destination[3]=%x, expected %x\n", source, destination[3],
1143				L't');
1144			problemCount++;
1145		}
1146		if (destination[4] != L'\0') {
1147			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1148					"destination[4]=%x, expected %x\n", source, destination[4],
1149				L'\0');
1150			problemCount++;
1151		}
1152		if (destination[5] != L'\0') {
1153			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1154					"destination[5]=%x, expected %x\n", source, destination[5],
1155				L'\0');
1156			problemCount++;
1157		}
1158		if (destination[6] != L'\0') {
1159			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1160					"destination[6]=%x, expected %x\n", source, destination[6],
1161				L'\0');
1162			problemCount++;
1163		}
1164		if (destination[7] != L'\0') {
1165			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1166					"destination[7]=%x, expected %x\n", source, destination[7],
1167				L'\0');
1168			problemCount++;
1169		}
1170		if (destination[8] != L'X') {
1171			printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> "
1172					"destination[8]=%x, expected %x\n", source, destination[8],
1173				L'X');
1174			problemCount++;
1175		}
1176	}
1177
1178	if (problemCount)
1179		printf("\t%d problem(s) found!\n", problemCount);
1180	else
1181		printf("\tall fine\n");
1182}
1183
1184
1185// #pragma mark - wcpcpy -------------------------------------------------------
1186
1187
1188void
1189test_wcpcpy()
1190{
1191	printf("wcpcpy()/wcpncpy()\n");
1192
1193	int problemCount = 0;
1194	errno = 0;
1195
1196	{
1197		const wchar_t* source = L"";
1198		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1199		wchar_t* result = wcpcpy(destination, source);
1200		if (result != destination) {
1201			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, "
1202					"expected %p\n", source, result, destination);
1203			problemCount++;
1204		}
1205		if (errno != 0) {
1206			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, "
1207					"expected 0\n", source, errno);
1208			problemCount++;
1209		}
1210		if (wcslen(destination) != 0) {
1211			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1212					"wcslen(destination)=%lu, expected 0\n", source,
1213				wcslen(destination));
1214			problemCount++;
1215		}
1216		if (destination[0] != L'\0') {
1217			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1218					"destination[0]=%x, expected %x\n", source, destination[0],
1219				L'\0');
1220			problemCount++;
1221		}
1222		if (destination[1] != L'X') {
1223			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1224					"destination[1]=%x, expected %x\n", source, destination[1],
1225				L'X');
1226			problemCount++;
1227		}
1228	}
1229
1230	{
1231		const wchar_t* source = L"test";
1232		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1233		wchar_t* result = wcpcpy(destination, source);
1234		if (result != destination + 4) {
1235			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, "
1236					"expected %p\n", source, result, destination + 4);
1237			problemCount++;
1238		}
1239		if (errno != 0) {
1240			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, "
1241					"expected 0\n", source, errno);
1242			problemCount++;
1243		}
1244		if (wcslen(destination) != 4) {
1245			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1246					"wcslen(destination)=%lu, expected 4\n", source,
1247				wcslen(destination));
1248			problemCount++;
1249		}
1250		if (destination[0] != L't') {
1251			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1252					"destination[0]=%x, expected %x\n", source, destination[0],
1253				L't');
1254			problemCount++;
1255		}
1256		if (destination[1] != L'e') {
1257			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1258					"destination[1]=%x, expected %x\n", source, destination[1],
1259				L'e');
1260			problemCount++;
1261		}
1262		if (destination[2] != L's') {
1263			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1264					"destination[2]=%x, expected %x\n", source, destination[2],
1265				L's');
1266			problemCount++;
1267		}
1268		if (destination[3] != L't') {
1269			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1270					"destination[3]=%x, expected %x\n", source, destination[3],
1271				L't');
1272			problemCount++;
1273		}
1274		if (destination[4] != L'\0') {
1275			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1276					"destination[4]=%x, expected %x\n", source, destination[4],
1277				L'\0');
1278			problemCount++;
1279		}
1280		if (destination[5] != L'X') {
1281			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1282					"destination[5]=%x, expected %x\n", source, destination[5],
1283				L'X');
1284			problemCount++;
1285		}
1286	}
1287
1288	{
1289		const wchar_t* source = L"t\xE4st";
1290		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1291		wchar_t* result = wcpcpy(destination, source);
1292		if (result != destination + 4) {
1293			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, "
1294					"expected %p\n", source, result, destination + 4);
1295			problemCount++;
1296		}
1297		if (errno != 0) {
1298			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, "
1299					"expected 0\n", source, errno);
1300			problemCount++;
1301		}
1302		if (wcslen(destination) != 4) {
1303			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1304					"wcslen(destination)=%lu, expected 4\n", source,
1305				wcslen(destination));
1306			problemCount++;
1307		}
1308		if (destination[0] != L't') {
1309			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1310					"destination[0]=%x, expected %x\n", source, destination[0],
1311				L't');
1312			problemCount++;
1313		}
1314		if (destination[1] != L'\xE4') {
1315			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1316					"destination[1]=%x, expected %x\n", source, destination[1],
1317				L'\xE4');
1318			problemCount++;
1319		}
1320		if (destination[2] != L's') {
1321			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1322					"destination[2]=%x, expected %x\n", source, destination[2],
1323				L's');
1324			problemCount++;
1325		}
1326		if (destination[3] != L't') {
1327			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1328					"destination[3]=%x, expected %x\n", source, destination[3],
1329				L't');
1330			problemCount++;
1331		}
1332		if (destination[4] != L'\0') {
1333			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1334					"destination[4]=%x, expected %x\n", source, destination[4],
1335				L'\0');
1336			problemCount++;
1337		}
1338		if (destination[5] != L'X') {
1339			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1340					"destination[5]=%x, expected %x\n", source, destination[5],
1341				L'X');
1342			problemCount++;
1343		}
1344	}
1345
1346	{
1347		const wchar_t* source = L"te\x00st";
1348		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1349		wchar_t* result = wcpcpy(destination, source);
1350		if (result != destination + 2) {
1351			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, "
1352					"expected %p\n", source, result, destination + 2);
1353			problemCount++;
1354		}
1355		if (errno != 0) {
1356			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, "
1357					"expected 0\n", source, errno);
1358			problemCount++;
1359		}
1360		if (wcslen(destination) != 2) {
1361			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1362					"wcslen(destination)=%lu, expected 2\n", source,
1363				wcslen(destination));
1364			problemCount++;
1365		}
1366		if (destination[0] != L't') {
1367			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1368					"destination[0]=%x, expected %x\n", source, destination[0],
1369				L't');
1370			problemCount++;
1371		}
1372		if (destination[1] != L'e') {
1373			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1374					"destination[1]=%x, expected %x\n", source, destination[1],
1375				L'e');
1376			problemCount++;
1377		}
1378		if (destination[2] != L'\0') {
1379			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1380					"destination[2]=%x, expected %x\n", source, destination[2],
1381				L'\0');
1382			problemCount++;
1383		}
1384		if (destination[3] != L'X') {
1385			printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> "
1386					"destination[3]=%x, expected %x\n", source, destination[3],
1387				L'X');
1388			problemCount++;
1389		}
1390	}
1391
1392	{
1393		const wchar_t* source = L"t\xE4st";
1394		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1395		wchar_t* result = wcpncpy(destination, source, 0);
1396		if (result != destination) {
1397			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> result=%p, "
1398					"expected %p\n", source, result, destination);
1399			problemCount++;
1400		}
1401		if (errno != 0) {
1402			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> errno=%d, "
1403					"expected 0\n", source, errno);
1404			problemCount++;
1405		}
1406		if (destination[0] != L'X') {
1407			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> "
1408					"destination[0]=%x, expected %x\n", source, destination[0],
1409				L'X');
1410			problemCount++;
1411		}
1412	}
1413
1414	{
1415		const wchar_t* source = L"t\xE4st";
1416		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1417		wchar_t* result = wcpncpy(destination, source, 2);
1418		if (result != destination + 2) {
1419			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> result=%p, "
1420					"expected %p\n", source, result, destination + 2);
1421			problemCount++;
1422		}
1423		if (errno != 0) {
1424			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> errno=%d, "
1425					"expected 0\n", source, errno);
1426			problemCount++;
1427		}
1428		if (destination[0] != L't') {
1429			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> "
1430					"destination[0]=%x, expected %x\n", source, destination[0],
1431				L't');
1432			problemCount++;
1433		}
1434		if (destination[1] != L'\xE4') {
1435			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> "
1436					"destination[1]=%x, expected %x\n", source, destination[1],
1437				L'\xE4');
1438			problemCount++;
1439		}
1440		if (destination[2] != L'X') {
1441			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> "
1442					"destination[2]=%x, expected %x\n", source, destination[2],
1443				L'X');
1444			problemCount++;
1445		}
1446	}
1447
1448	{
1449		const wchar_t* source = L"t\xE4st";
1450		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1451		wchar_t* result = wcpncpy(destination, source, 4);
1452		if (result != destination + 4) {
1453			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> result=%p, "
1454					"expected %p\n", source, result, destination + 4);
1455			problemCount++;
1456		}
1457		if (errno != 0) {
1458			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> errno=%d, "
1459					"expected 0\n", source, errno);
1460			problemCount++;
1461		}
1462		if (destination[0] != L't') {
1463			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> "
1464					"destination[0]=%x, expected %x\n", source, destination[0],
1465				L't');
1466			problemCount++;
1467		}
1468		if (destination[1] != L'\xE4') {
1469			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> "
1470					"destination[1]=%x, expected %x\n", source, destination[1],
1471				L'\xE4');
1472			problemCount++;
1473		}
1474		if (destination[2] != L's') {
1475			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> "
1476					"destination[2]=%x, expected %x\n", source, destination[2],
1477				L's');
1478			problemCount++;
1479		}
1480		if (destination[3] != L't') {
1481			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> "
1482					"destination[3]=%x, expected %x\n", source, destination[3],
1483				L't');
1484			problemCount++;
1485		}
1486		if (destination[4] != L'X') {
1487			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> "
1488					"destination[4]=%x, expected %x\n", source, destination[4],
1489				L'X');
1490			problemCount++;
1491		}
1492	}
1493
1494	{
1495		const wchar_t* source = L"t\xE4st";
1496		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
1497		wchar_t* result = wcpncpy(destination, source, 8);
1498		if (result != destination + 4) {
1499			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> result=%p, "
1500					"expected %p\n", source, result, destination + 4);
1501			problemCount++;
1502		}
1503		if (errno != 0) {
1504			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> errno=%d, "
1505					"expected 0\n", source, errno);
1506			problemCount++;
1507		}
1508		if (wcslen(destination) != 4) {
1509			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1510					"wcslen(destination)=%lu, expected 4\n", source,
1511				wcslen(destination));
1512			problemCount++;
1513		}
1514		if (destination[0] != L't') {
1515			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1516					"destination[0]=%x, expected %x\n", source, destination[0],
1517				L't');
1518			problemCount++;
1519		}
1520		if (destination[1] != L'\xE4') {
1521			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1522					"destination[1]=%x, expected %x\n", source, destination[1],
1523				L'\xE4');
1524			problemCount++;
1525		}
1526		if (destination[2] != L's') {
1527			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1528					"destination[2]=%x, expected %x\n", source, destination[2],
1529				L's');
1530			problemCount++;
1531		}
1532		if (destination[3] != L't') {
1533			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1534					"destination[3]=%x, expected %x\n", source, destination[3],
1535				L't');
1536			problemCount++;
1537		}
1538		if (destination[4] != L'\0') {
1539			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1540					"destination[4]=%x, expected %x\n", source, destination[4],
1541				L'\0');
1542			problemCount++;
1543		}
1544		if (destination[5] != L'\0') {
1545			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1546					"destination[5]=%x, expected %x\n", source, destination[5],
1547				L'\0');
1548			problemCount++;
1549		}
1550		if (destination[6] != L'\0') {
1551			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1552					"destination[6]=%x, expected %x\n", source, destination[6],
1553				L'\0');
1554			problemCount++;
1555		}
1556		if (destination[7] != L'\0') {
1557			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1558					"destination[7]=%x, expected %x\n", source, destination[7],
1559				L'\0');
1560			problemCount++;
1561		}
1562		if (destination[8] != L'X') {
1563			printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> "
1564					"destination[8]=%x, expected %x\n", source, destination[8],
1565				L'X');
1566			problemCount++;
1567		}
1568	}
1569
1570	if (problemCount)
1571		printf("\t%d problem(s) found!\n", problemCount);
1572	else
1573		printf("\tall fine\n");
1574}
1575
1576
1577// #pragma mark - wcscat -------------------------------------------------------
1578
1579
1580void
1581test_wcscat()
1582{
1583	printf("wcscat()/wcsncat()\n");
1584
1585	int problemCount = 0;
1586	errno = 0;
1587	wchar_t destination[] = L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
1588	destination[0] = L'\0';
1589	wchar_t backup[33];
1590
1591	{
1592		wcscpy(backup, destination);
1593		const wchar_t* source = L"";
1594		wchar_t* result = wcscat(destination, source);
1595		if (result != destination) {
1596			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, "
1597					"expected %p\n", backup, source, result, destination);
1598			problemCount++;
1599		}
1600		if (errno != 0) {
1601			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, "
1602					"expected 0\n", backup, source, errno);
1603			problemCount++;
1604		}
1605		if (wcslen(destination) != 0) {
1606			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> "
1607					"wcslen(destination)=%lu, expected 0\n", backup, source,
1608				wcslen(destination));
1609			problemCount++;
1610		}
1611		if (destination[0] != L'\0') {
1612			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, "
1613					"expected %x\n", backup, source, destination[0], L'\0');
1614			problemCount++;
1615		}
1616		if (destination[1] != L'X') {
1617			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, "
1618					"expected %x\n", backup, source, destination[1], L'X');
1619			problemCount++;
1620		}
1621	}
1622
1623	{
1624		wcscpy(backup, destination);
1625		const wchar_t* source = L"test";
1626		wchar_t* result = wcscat(destination, source);
1627		if (result != destination) {
1628			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, "
1629					"expected %p\n", backup, source, result, destination);
1630			problemCount++;
1631		}
1632		if (errno != 0) {
1633			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, "
1634					"expected 0\n", backup, source, errno);
1635			problemCount++;
1636		}
1637		if (wcslen(destination) != 4) {
1638			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> "
1639					"wcslen(destination)=%lu, expected 4\n", backup, source,
1640				wcslen(destination));
1641			problemCount++;
1642		}
1643		if (destination[0] != L't') {
1644			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, "
1645					"expected %x\n", backup, source, destination[0], L't');
1646			problemCount++;
1647		}
1648		if (destination[1] != L'e') {
1649			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, "
1650					"expected %x\n", backup, source, destination[1], L'e');
1651			problemCount++;
1652		}
1653		if (destination[2] != L's') {
1654			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, "
1655					"expected %x\n", backup, source, destination[2], L's');
1656			problemCount++;
1657		}
1658		if (destination[3] != L't') {
1659			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, "
1660					"expected %x\n", backup, source, destination[3], L't');
1661			problemCount++;
1662		}
1663		if (destination[4] != L'\0') {
1664			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, "
1665					"expected %x\n", backup, source, destination[4], L'\0');
1666			problemCount++;
1667		}
1668		if (destination[5] != L'X') {
1669			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, "
1670					"expected %x\n", backup, source, destination[5], L'X');
1671			problemCount++;
1672		}
1673	}
1674
1675	{
1676		wcscpy(backup, destination);
1677		const wchar_t* source = L"t\xE4st";
1678		wchar_t* result = wcscat(destination, source);
1679		if (result != destination) {
1680			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, "
1681					"expected %p\n", backup, source, result, destination);
1682			problemCount++;
1683		}
1684		if (errno != 0) {
1685			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, "
1686					"expected 0\n", backup, source, errno);
1687			problemCount++;
1688		}
1689		if (wcslen(destination) != 8) {
1690			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> "
1691					"wcslen(destination)=%lu, expected 8\n", backup, source,
1692				wcslen(destination));
1693			problemCount++;
1694		}
1695		if (destination[0] != L't') {
1696			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, "
1697					"expected %x\n", backup, source, destination[0], L't');
1698			problemCount++;
1699		}
1700		if (destination[1] != L'e') {
1701			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, "
1702					"expected %x\n", backup, source, destination[1], L'e');
1703			problemCount++;
1704		}
1705		if (destination[2] != L's') {
1706			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, "
1707					"expected %x\n", backup, source, destination[2], L's');
1708			problemCount++;
1709		}
1710		if (destination[3] != L't') {
1711			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, "
1712					"expected %x\n", backup, source, destination[3], L't');
1713			problemCount++;
1714		}
1715		if (destination[4] != L't') {
1716			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, "
1717					"expected %x\n", backup, source, destination[4], L't');
1718			problemCount++;
1719		}
1720		if (destination[5] != L'\xE4') {
1721			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, "
1722					"expected %x\n", backup, source, destination[5], L'\xE4');
1723			problemCount++;
1724		}
1725		if (destination[6] != L's') {
1726			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[6]=%x, "
1727					"expected %x\n", backup, source, destination[6], L's');
1728			problemCount++;
1729		}
1730		if (destination[7] != L't') {
1731			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[7]=%x, "
1732					"expected %x\n", backup, source, destination[7], L't');
1733			problemCount++;
1734		}
1735		if (destination[8] != L'\0') {
1736			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[8]=%x, "
1737					"expected %x\n", backup, source, destination[8], L'\0');
1738			problemCount++;
1739		}
1740		if (destination[9] != L'X') {
1741			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[9]=%x, "
1742					"expected %x\n", backup, source, destination[9], L'X');
1743			problemCount++;
1744		}
1745	}
1746
1747	{
1748		wcscpy(backup, destination);
1749		const wchar_t* source = L"te\x00st";
1750		wchar_t* result = wcscat(destination, source);
1751		if (result != destination) {
1752			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, "
1753					"expected %p\n", backup, source, result, destination);
1754			problemCount++;
1755		}
1756		if (errno != 0) {
1757			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, "
1758					"expected 0\n", backup, source, errno);
1759			problemCount++;
1760		}
1761		if (wcslen(destination) != 10) {
1762			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> "
1763					"wcslen(destination)=%lu, expected 10\n", backup, source,
1764				wcslen(destination));
1765			problemCount++;
1766		}
1767		if (destination[0] != L't') {
1768			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, "
1769					"expected %x\n", backup, source, destination[0], L't');
1770			problemCount++;
1771		}
1772		if (destination[1] != L'e') {
1773			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, "
1774					"expected %x\n", backup, source, destination[1], L'e');
1775			problemCount++;
1776		}
1777		if (destination[2] != L's') {
1778			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, "
1779					"expected %x\n", backup, source, destination[2], L's');
1780			problemCount++;
1781		}
1782		if (destination[3] != L't') {
1783			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, "
1784					"expected %x\n", backup, source, destination[3], L't');
1785			problemCount++;
1786		}
1787		if (destination[4] != L't') {
1788			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, "
1789					"expected %x\n", backup, source, destination[4], L't');
1790			problemCount++;
1791		}
1792		if (destination[5] != L'\xE4') {
1793			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, "
1794					"expected %x\n", backup, source, destination[5], L'\xE4');
1795			problemCount++;
1796		}
1797		if (destination[6] != L's') {
1798			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[6]=%x, "
1799					"expected %x\n", backup, source, destination[6], L's');
1800			problemCount++;
1801		}
1802		if (destination[7] != L't') {
1803			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[7]=%x, "
1804					"expected %x\n", backup, source, destination[7], L't');
1805			problemCount++;
1806		}
1807		if (destination[8] != L't') {
1808			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[8]=%x, "
1809					"expected %x\n", backup, source, destination[8], L't');
1810			problemCount++;
1811		}
1812		if (destination[9] != L'e') {
1813			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[9]=%x, "
1814					"expected %x\n", backup, source, destination[9], L'e');
1815			problemCount++;
1816		}
1817		if (destination[10] != L'\0') {
1818			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[10]=%x, "
1819					"expected %x\n", backup, source, destination[10], L'\0');
1820			problemCount++;
1821		}
1822		if (destination[11] != L'X') {
1823			printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[11]=%x, "
1824					"expected %x\n", backup, source, destination[11], L'X');
1825			problemCount++;
1826		}
1827	}
1828
1829	{
1830		wcscpy(destination, L"some");
1831		wcscpy(backup, destination);
1832		const wchar_t* source = L" other text";
1833		wchar_t* result = wcsncat(destination, source, 0);
1834		if (result != destination) {
1835			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> result=%p, "
1836					"expected %p\n", backup, source, result, destination);
1837			problemCount++;
1838		}
1839		if (errno != 0) {
1840			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> errno=%d, "
1841					"expected 0\n", backup, source, errno);
1842			problemCount++;
1843		}
1844		if (wcslen(destination) != 4) {
1845			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> "
1846					"wcslen(destination)=%lu, expected 4\n", backup, source,
1847				wcslen(destination));
1848			problemCount++;
1849		}
1850		if (wcscmp(destination, L"some") != 0) {
1851			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> \"%ls\"\n",
1852				backup, source, destination);
1853			problemCount++;
1854		}
1855	}
1856
1857	{
1858		wcscpy(destination, L"some");
1859		wcscpy(backup, destination);
1860		const wchar_t* source = L" other text";
1861		wchar_t* result = wcsncat(destination, source, 6);
1862		if (result != destination) {
1863			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> result=%p, "
1864					"expected %p\n", backup, source, result, destination);
1865			problemCount++;
1866		}
1867		if (errno != 0) {
1868			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> errno=%d, "
1869					"expected 0\n", backup, source, errno);
1870			problemCount++;
1871		}
1872		if (wcslen(destination) != 10) {
1873			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> "
1874					"wcslen(destination)=%lu, expected 10\n", backup, source,
1875				wcslen(destination));
1876			problemCount++;
1877		}
1878		if (wcscmp(destination, L"some other") != 0) {
1879			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> \"%ls\"\n",
1880				backup, source, destination);
1881			problemCount++;
1882		}
1883	}
1884
1885	{
1886		wcscpy(destination, L"some");
1887		wcscpy(backup, destination);
1888		const wchar_t* source = L" other text";
1889		wchar_t* result = wcsncat(destination, source, 20);
1890		if (result != destination) {
1891			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> result=%p, "
1892					"expected %p\n", backup, source, result, destination);
1893			problemCount++;
1894		}
1895		if (errno != 0) {
1896			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> errno=%d, "
1897					"expected 0\n", backup, source, errno);
1898			problemCount++;
1899		}
1900		if (wcslen(destination) != 15) {
1901			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> "
1902					"wcslen(destination)=%lu, expected 15\n", backup, source,
1903				wcslen(destination));
1904			problemCount++;
1905		}
1906		if (wcscmp(destination, L"some other text") != 0) {
1907			printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> \"%ls\"\n",
1908				backup, source, destination);
1909			problemCount++;
1910		}
1911	}
1912
1913	if (problemCount)
1914		printf("\t%d problem(s) found!\n", problemCount);
1915	else
1916		printf("\tall fine\n");
1917}
1918
1919
1920// #pragma mark - wcslcat ------------------------------------------------------
1921
1922
1923#ifdef __HAIKU__
1924
1925void
1926test_wcslcat()
1927{
1928	printf("wcslcat()\n");
1929
1930	int problemCount = 0;
1931	errno = 0;
1932	wchar_t destination[] = L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
1933	wchar_t backup[33];
1934
1935	{
1936		wcscpy(backup, destination);
1937		const wchar_t* source = L"";
1938		size_t result = wcslcat(destination, source, 0);
1939		size_t expectedResult = 0;
1940		if (result != expectedResult) {
1941			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> result=%ld, "
1942					"expected %ld\n", backup, source, result, expectedResult);
1943			problemCount++;
1944		}
1945		if (errno != 0) {
1946			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> errno=%d, "
1947					"expected 0\n", backup, source, errno);
1948			problemCount++;
1949		}
1950		if (wcslen(destination) != 32) {
1951			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> "
1952					"wcslen(destination)=%lu, expected 32\n", backup, source,
1953				wcslen(destination));
1954			problemCount++;
1955		}
1956		if (destination[0] != L'X') {
1957			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> destination[0]="
1958					"%x, expected %x\n", backup, source, destination[0], L'X');
1959			problemCount++;
1960		}
1961	}
1962
1963	{
1964		destination[0] = L'\0';
1965		wcscpy(backup, destination);
1966		const wchar_t* source = L"";
1967		size_t result = wcslcat(destination, source, 32);
1968		size_t expectedResult = 0;
1969		if (result != expectedResult) {
1970			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> result=%ld, "
1971					"expected %ld\n", backup, source, result, expectedResult);
1972			problemCount++;
1973		}
1974		if (errno != 0) {
1975			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> errno=%d, "
1976					"expected 0\n", backup, source, errno);
1977			problemCount++;
1978		}
1979		if (wcslen(destination) != 0) {
1980			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> "
1981					"wcslen(destination)=%lu, expected 0\n", backup, source,
1982				wcslen(destination));
1983			problemCount++;
1984		}
1985		if (destination[0] != L'\0') {
1986			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[0]="
1987					"%x, expected %x\n", backup, source, destination[0], L'\0');
1988			problemCount++;
1989		}
1990		if (destination[1] != L'X') {
1991			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[1]="
1992					"%x, expected %x\n", backup, source, destination[1], L'X');
1993			problemCount++;
1994		}
1995	}
1996
1997	{
1998		wcscpy(backup, destination);
1999		const wchar_t* source = L"test";
2000		size_t result = wcslcat(destination, source, 3);
2001		size_t expectedResult = 4;
2002		if (result != expectedResult) {
2003			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> result=%ld, "
2004					"expected %ld\n", backup, source, result, expectedResult);
2005			problemCount++;
2006		}
2007		if (errno != 0) {
2008			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> errno=%d, "
2009					"expected 0\n", backup, source, errno);
2010			problemCount++;
2011		}
2012		if (wcslen(destination) != 2) {
2013			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> "
2014					"wcslen(destination)=%lu, expected 2\n", backup, source,
2015				wcslen(destination));
2016			problemCount++;
2017		}
2018		if (destination[0] != L't') {
2019			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> destination[0]="
2020					"%x, expected %x\n", backup, source, destination[0], L't');
2021			problemCount++;
2022		}
2023		if (destination[1] != L'e') {
2024			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> destination[1]="
2025					"%x, expected %x\n", backup, source, destination[1], L'e');
2026			problemCount++;
2027		}
2028		if (destination[2] != L'\0') {
2029			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> destination[2]="
2030					"%x, expected %x\n", backup, source, destination[2], L'\0');
2031			problemCount++;
2032		}
2033		if (destination[3] != L'X') {
2034			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> destination[3]="
2035					"%x, expected %x\n", backup, source, destination[3], L'X');
2036			problemCount++;
2037		}
2038	}
2039
2040	{
2041		wcscpy(backup, destination);
2042		const wchar_t* source = L"st";
2043		size_t result = wcslcat(destination, source, 4);
2044		size_t expectedResult = 4;
2045		if (result != expectedResult) {
2046			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> result=%ld, "
2047					"expected %ld\n", backup, source, result, expectedResult);
2048			problemCount++;
2049		}
2050		if (errno != 0) {
2051			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> errno=%d, "
2052					"expected 0\n", backup, source, errno);
2053			problemCount++;
2054		}
2055		if (wcslen(destination) != 3) {
2056			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> "
2057					"wcslen(destination)=%lu, expected 3\n", backup, source,
2058				wcslen(destination));
2059			problemCount++;
2060		}
2061		if (destination[0] != L't') {
2062			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[0]="
2063					"%x, expected %x\n", backup, source, destination[0], L't');
2064			problemCount++;
2065		}
2066		if (destination[1] != L'e') {
2067			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[1]="
2068					"%x, expected %x\n", backup, source, destination[1], L'e');
2069			problemCount++;
2070		}
2071		if (destination[2] != L's') {
2072			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[2]="
2073					"%x, expected %x\n", backup, source, destination[2], L's');
2074			problemCount++;
2075		}
2076		if (destination[3] != L'\0') {
2077			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[3]="
2078					"%x, expected %x\n", backup, source, destination[3], L'\0');
2079			problemCount++;
2080		}
2081		if (destination[4] != L'X') {
2082			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[4]="
2083					"%x, expected %x\n", backup, source, destination[4], L'X');
2084			problemCount++;
2085		}
2086	}
2087
2088	{
2089		wcscpy(backup, destination);
2090		const wchar_t* source = L"t";
2091		size_t result = wcslcat(destination, source, 5);
2092		size_t expectedResult = 4;
2093		if (result != expectedResult) {
2094			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> result=%ld, "
2095					"expected %ld\n", backup, source, result, expectedResult);
2096			problemCount++;
2097		}
2098		if (errno != 0) {
2099			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> errno=%d, "
2100					"expected 0\n", backup, source, errno);
2101			problemCount++;
2102		}
2103		if (wcslen(destination) != 4) {
2104			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> "
2105					"wcslen(destination)=%lu, expected 4\n", backup, source,
2106				wcslen(destination));
2107			problemCount++;
2108		}
2109		if (destination[0] != L't') {
2110			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[0]="
2111					"%x, expected %x\n", backup, source, destination[0], L't');
2112			problemCount++;
2113		}
2114		if (destination[1] != L'e') {
2115			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[1]="
2116					"%x, expected %x\n", backup, source, destination[1], L'e');
2117			problemCount++;
2118		}
2119		if (destination[2] != L's') {
2120			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[2]="
2121					"%x, expected %x\n", backup, source, destination[2], L's');
2122			problemCount++;
2123		}
2124		if (destination[3] != L't') {
2125			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[3]="
2126					"%x, expected %x\n", backup, source, destination[3], L't');
2127			problemCount++;
2128		}
2129		if (destination[4] != L'\0') {
2130			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[4]="
2131					"%x, expected %x\n", backup, source, destination[4], L'\0');
2132			problemCount++;
2133		}
2134		if (destination[5] != L'X') {
2135			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[5]="
2136					"%x, expected %x\n", backup, source, destination[5], L'X');
2137			problemCount++;
2138		}
2139	}
2140
2141	{
2142		wcscpy(backup, destination);
2143		const wchar_t* source = L"t\xE4st";
2144		size_t result = wcslcat(destination, source, 32);
2145		size_t expectedResult = 8;
2146		if (result != expectedResult) {
2147			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> result=%ld, "
2148					"expected %ld\n", backup, source, result, expectedResult);
2149			problemCount++;
2150		}
2151		if (errno != 0) {
2152			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> errno=%d, "
2153					"expected 0\n", backup, source, errno);
2154			problemCount++;
2155		}
2156		if (wcslen(destination) != 8) {
2157			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> "
2158					"wcslen(destination)=%lu, expected 8\n", backup, source,
2159				wcslen(destination));
2160			problemCount++;
2161		}
2162		if (destination[0] != L't') {
2163			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[0]="
2164					"%x, expected %x\n", backup, source, destination[0], L't');
2165			problemCount++;
2166		}
2167		if (destination[1] != L'e') {
2168			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[1]="
2169					"%x, expected %x\n", backup, source, destination[1], L'e');
2170			problemCount++;
2171		}
2172		if (destination[2] != L's') {
2173			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[2]="
2174					"%x, expected %x\n", backup, source, destination[2], L's');
2175			problemCount++;
2176		}
2177		if (destination[3] != L't') {
2178			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[3]="
2179					"%x, expected %x\n", backup, source, destination[3], L't');
2180			problemCount++;
2181		}
2182		if (destination[4] != L't') {
2183			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[4]="
2184					"%x, expected %x\n", backup, source, destination[4], L't');
2185			problemCount++;
2186		}
2187		if (destination[5] != L'\xE4') {
2188			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[5]="
2189					"%x, expected %x\n", backup, source, destination[5],
2190				L'\xE4');
2191			problemCount++;
2192		}
2193		if (destination[6] != L's') {
2194			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[6]="
2195					"%x, expected %x\n", backup, source, destination[6], L's');
2196			problemCount++;
2197		}
2198		if (destination[7] != L't') {
2199			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[7]="
2200					"%x, expected %x\n", backup, source, destination[7], L't');
2201			problemCount++;
2202		}
2203		if (destination[8] != L'\0') {
2204			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[8]="
2205					"%x, expected %x\n", backup, source, destination[8], L'\0');
2206			problemCount++;
2207		}
2208		if (destination[9] != L'X') {
2209			printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[9]="
2210					"%x, expected %x\n", backup, source, destination[9], L'X');
2211			problemCount++;
2212		}
2213	}
2214
2215	if (problemCount)
2216		printf("\t%d problem(s) found!\n", problemCount);
2217	else
2218		printf("\tall fine\n");
2219}
2220
2221#endif
2222
2223
2224// #pragma mark - wcslcpy ------------------------------------------------------
2225
2226
2227#ifdef __HAIKU__
2228
2229void
2230test_wcslcpy()
2231{
2232	printf("wcslcpy()\n");
2233
2234	int problemCount = 0;
2235	errno = 0;
2236
2237	{
2238		const wchar_t* source = L"";
2239		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
2240
2241		size_t result = wcslcpy(destination, source, 0);
2242		size_t expectedResult = 0;
2243		if (result != expectedResult) {
2244			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 0) -> result=%ld, "
2245					"expected %ld\n", source, result, expectedResult);
2246			problemCount++;
2247		}
2248		if (errno != 0) {
2249			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 0) -> errno=%d, "
2250					"expected 0\n", source, errno);
2251			problemCount++;
2252		}
2253		if (wcslen(destination) != 16) {
2254			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 0) -> "
2255					"wcslen(destination)=%lu, expected 16\n", source,
2256				wcslen(destination));
2257			problemCount++;
2258		}
2259		if (destination[0] != L'X') {
2260			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 0) -> "
2261					"destination[0]=%x, expected %x\n", source, destination[0],
2262				L'X');
2263			problemCount++;
2264		}
2265	}
2266
2267	{
2268		const wchar_t* source = L"";
2269		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
2270		size_t result = wcslcpy(destination, source, 16);
2271		size_t expectedResult = 0;
2272		if (result != expectedResult) {
2273			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> result=%ld,"
2274					" expected %ld\n", source, result, expectedResult);
2275			problemCount++;
2276		}
2277		if (errno != 0) {
2278			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> errno=%d, "
2279					"expected 0\n", source, errno);
2280			problemCount++;
2281		}
2282		if (wcslen(destination) != 0) {
2283			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2284					"wcslen(destination)=%lu, expected 0\n", source,
2285				wcslen(destination));
2286			problemCount++;
2287		}
2288		if (destination[0] != L'\0') {
2289			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2290					"destination[0]=%x, expected %x\n", source, destination[0],
2291				L'\0');
2292			problemCount++;
2293		}
2294		if (destination[1] != L'X') {
2295			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2296					"destination[1]=%x, expected %x\n", source, destination[1],
2297				L'X');
2298			problemCount++;
2299		}
2300	}
2301
2302	{
2303		const wchar_t* source = L"test";
2304		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
2305		size_t result = wcslcpy(destination, source, 3);
2306		size_t expectedResult = 4;
2307		if (result != expectedResult) {
2308			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> result=%ld, "
2309					"expected %ld\n", source, result, expectedResult);
2310			problemCount++;
2311		}
2312		if (errno != 0) {
2313			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> errno=%d, "
2314					"expected 0\n", source, errno);
2315			problemCount++;
2316		}
2317		if (wcslen(destination) != 2) {
2318			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 2) -> "
2319					"wcslen(destination)=%lu, expected 3\n", source,
2320				wcslen(destination));
2321			problemCount++;
2322		}
2323		if (destination[0] != L't') {
2324			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> "
2325					"destination[0]=%x, expected %x\n", source, destination[0],
2326				L't');
2327			problemCount++;
2328		}
2329		if (destination[1] != L'e') {
2330			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> "
2331					"destination[1]=%x, expected %x\n", source, destination[1],
2332				L'e');
2333			problemCount++;
2334		}
2335		if (destination[2] != L'\0') {
2336			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> "
2337					"destination[2]=%x, expected %x\n", source, destination[2],
2338				L'\0');
2339			problemCount++;
2340		}
2341		if (destination[3] != L'X') {
2342			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> "
2343					"destination[3]=%x, expected %x\n", source, destination[3],
2344				L'X');
2345			problemCount++;
2346		}
2347	}
2348
2349	{
2350		const wchar_t* source = L"test";
2351		wchar_t destination[] = L"XXXXXXXXXXXXXXXX";
2352		size_t result = wcslcpy(destination, source, 16);
2353		size_t expectedResult = 4;
2354		if (result != expectedResult) {
2355			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> result=%ld, "
2356					"expected %ld\n", source, result, expectedResult);
2357			problemCount++;
2358		}
2359		if (errno != 0) {
2360			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> errno=%d, "
2361					"expected 0\n", source, errno);
2362			problemCount++;
2363		}
2364		if (wcslen(destination) != 4) {
2365			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2366					"wcslen(destination)=%lu, expected 4\n", source,
2367				wcslen(destination));
2368			problemCount++;
2369		}
2370		if (destination[0] != L't') {
2371			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2372					"destination[0]=%x, expected %x\n", source, destination[0],
2373				L't');
2374			problemCount++;
2375		}
2376		if (destination[1] != L'e') {
2377			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2378					"destination[1]=%x, expected %x\n", source, destination[1],
2379				L'e');
2380			problemCount++;
2381		}
2382		if (destination[2] != L's') {
2383			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2384					"destination[2]=%x, expected %x\n", source, destination[2],
2385				L's');
2386			problemCount++;
2387		}
2388		if (destination[3] != L't') {
2389			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2390					"destination[3]=%x, expected %x\n", source, destination[3],
2391				L't');
2392			problemCount++;
2393		}
2394		if (destination[4] != L'\0') {
2395			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2396					"destination[4]=%x, expected %x\n", source, destination[4],
2397				L'\0');
2398			problemCount++;
2399		}
2400		if (destination[5] != L'X') {
2401			printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> "
2402					"destination[5]=%x, expected %x\n", source, destination[5],
2403				L'X');
2404			problemCount++;
2405		}
2406	}
2407	if (problemCount)
2408		printf("\t%d problem(s) found!\n", problemCount);
2409	else
2410		printf("\tall fine\n");
2411}
2412
2413#endif
2414
2415
2416// #pragma mark - collation ----------------------------------------------------
2417
2418
2419struct coll_data {
2420	const wchar_t* a;
2421	const wchar_t* b;
2422	int result;
2423	int err;
2424};
2425
2426
2427void
2428test_coll(bool useWcsxfrm, const char* locale, const coll_data coll[])
2429{
2430	setlocale(LC_COLLATE, locale);
2431	printf("%s in %s locale\n", useWcsxfrm ? "wcsxfrm" : "wcscoll", locale);
2432
2433	int problemCount = 0;
2434	for (unsigned int i = 0; coll[i].a != NULL; ++i) {
2435		errno = 0;
2436		int result;
2437		char funcCall[256];
2438		if (useWcsxfrm) {
2439			wchar_t sortKeyA[100], sortKeyB[100];
2440			wcsxfrm(sortKeyA, coll[i].a, 100);
2441			wcsxfrm(sortKeyB, coll[i].b, 100);
2442			result = sign(wcscmp(sortKeyA, sortKeyB));
2443			sprintf(funcCall, "wcscmp(wcsxfrm(\"%ls\"), wcsxfrm(\"%ls\"))",
2444				coll[i].a, coll[i].b);
2445		} else {
2446			result = sign(wcscoll(coll[i].a, coll[i].b));
2447			sprintf(funcCall, "wcscoll(\"%ls\", \"%ls\")", coll[i].a,
2448				coll[i].b);
2449		}
2450
2451		if (result != coll[i].result || errno != coll[i].err) {
2452			printf(
2453				"\tPROBLEM: %s = %d (expected %d), errno = %x (expected %x)\n",
2454				funcCall, result, coll[i].result, errno, coll[i].err);
2455			problemCount++;
2456		}
2457	}
2458
2459	if (problemCount)
2460		printf("\t%d problem(s) found!\n", problemCount);
2461	else
2462		printf("\tall fine\n");
2463}
2464
2465
2466void
2467test_collation()
2468{
2469	const coll_data coll_posix[] = {
2470		{ L"", L"", 0, 0 },
2471		{ L"test", L"test", 0, 0 },
2472		{ L"tester", L"test", 1, 0 },
2473		{ L"tEst", L"teSt", -1, 0 },
2474		{ L"test", L"tester", -1, 0 },
2475		{ L"tast", L"t\xE4st", -1, EINVAL },
2476		{ L"t\xE6st", L"test", 1, EINVAL },
2477		{ NULL, NULL, 0, 0 }
2478	};
2479	test_coll(0, "POSIX", coll_posix);
2480	test_coll(1, "POSIX", coll_posix);
2481
2482	const coll_data coll_en[] = {
2483		{ L"", L"", 0, 0 },
2484		{ L"test", L"test", 0, 0 },
2485		{ L"tester", L"test", 1, 0 },
2486		{ L"tEst", L"test", 1, 0 },
2487		{ L"test", L"tester", -1, 0 },
2488		{ L"t\xE4st", L"t\xE4st", 0, 0 },
2489		{ L"tast", L"t\xE4st", -1, 0 },
2490		{ L"tbst", L"t\xE4st", 1, 0 },
2491		{ L"tbst", L"t\xE6st", 1, 0 },
2492		{ L"t\xE4st", L"t\xC4st", -1, 0 },
2493		{ L"tBst", L"t\xC4st", 1, 0 },
2494		{ L"tBst", L"t\xE4st", 1, 0 },
2495		{ L"taest", L"t\xE6st", -1, 0 },
2496		{ L"tafst", L"t\xE6st", 1, 0 },
2497		{ L"taa", L"t\xE4" L"a", -1, 0 },
2498		{ L"tab", L"t\xE4" L"b", -1, 0 },
2499		{ L"tad", L"t\xE4" L"d", -1, 0 },
2500		{ L"tae", L"t\xE4" L"e", -1, 0 },
2501		{ L"taf", L"t\xE4" L"f", -1, 0 },
2502		{ L"cote", L"cot\xE9", -1, 0 },
2503		{ L"cot\xE9", L"c\xF4te", -1, 0 },
2504		{ L"c\xF4te", L"c\xF4t\xE9", -1, 0 },
2505		{ NULL, NULL, 0, 0 }
2506	};
2507	test_coll(0, "en_US.UTF-8", coll_en);
2508	test_coll(1, "en_US.UTF-8", coll_en);
2509
2510	const coll_data coll_de[] = {
2511		{ L"", L"", 0, 0 },
2512		{ L"test", L"test", 0, 0 },
2513		{ L"tester", L"test", 1, 0 },
2514		{ L"tEst", L"test", 1, 0 },
2515		{ L"test", L"tester", -1, 0 },
2516		{ L"t\xE4st", L"t\xE4st", 0, 0 },
2517		{ L"tast", L"t\xE4st", -1, 0 },
2518		{ L"tbst", L"t\xE4st", 1, 0 },
2519		{ L"tbst", L"t\xE6st", 1, 0 },
2520		{ L"t\xE4st", L"t\xC4st", -1, 0 },
2521		{ L"tBst", L"t\xC4st", 1, 0 },
2522		{ L"tBst", L"t\xE4st", 1, 0 },
2523		{ L"taest", L"t\xE6st", -1, 0 },
2524		{ L"tafst", L"t\xE6st", 1, 0 },
2525		{ L"taa", L"t\xE4", 1, 0 },
2526		{ L"tab", L"t\xE4", 1, 0 },
2527		{ L"tad", L"t\xE4", 1, 0 },
2528		{ L"tae", L"t\xE4", 1, 0 },
2529		{ L"taf", L"t\xE4", 1, 0 },
2530		{ L"cote", L"cot\xE9", -1, 0 },
2531		{ L"cot\xE9", L"c\xF4te", -1, 0 },
2532		{ L"c\xF4te", L"c\xF4t\xE9", -1, 0 },
2533		{ NULL, NULL, 0, 0 }
2534	};
2535	test_coll(0, "de_DE.UTF-8", coll_de);
2536	test_coll(1, "de_DE.UTF-8", coll_de);
2537
2538	const coll_data coll_de_phonebook[] = {
2539		{ L"", L"", 0, 0 },
2540		{ L"test", L"test", 0, 0 },
2541		{ L"tester", L"test", 1, 0 },
2542		{ L"tEst", L"test", 1, 0 },
2543		{ L"test", L"tester", -1, 0 },
2544		{ L"t\xE4st", L"t\xE4st", 0, 0 },
2545		{ L"tast", L"t\xE4st", 1, 0 },
2546		{ L"tbst", L"t\xE4st", 1, 0 },
2547		{ L"tbst", L"t\xE6st", 1, 0 },
2548		{ L"t\xE4st", L"t\xC4st", -1, 0 },
2549		{ L"tBst", L"t\xC4st", 1, 0 },
2550		{ L"tBst", L"t\xE4st", 1, 0 },
2551		{ L"taest", L"t\xE6st", -1, 0 },
2552		{ L"tafst", L"t\xE6st", 1, 0 },
2553		{ L"taa", L"t\xE4", -1, 0 },
2554		{ L"tab", L"t\xE4", -1, 0 },
2555		{ L"tad", L"t\xE4", -1, 0 },
2556		{ L"tae", L"t\xE4", -1, 0 },
2557		{ L"taf", L"t\xE4", 1, 0 },
2558		{ L"cote", L"cot\xE9", -1, 0 },
2559		{ L"cot\xE9", L"c\xF4te", -1, 0 },
2560		{ L"c\xF4te", L"c\xF4t\xE9", -1, 0 },
2561		{ NULL, NULL, 0, 0 }
2562	};
2563	test_coll(0, "de_DE.UTF-8@collation=phonebook", coll_de_phonebook);
2564	test_coll(1, "de_DE.UTF-8@collation=phonebook", coll_de_phonebook);
2565
2566	const coll_data coll_fr[] = {
2567		{ L"", L"", 0, 0 },
2568		{ L"test", L"test", 0, 0 },
2569		{ L"tester", L"test", 1, 0 },
2570		{ L"tEst", L"test", 1, 0 },
2571		{ L"test", L"tester", -1, 0 },
2572		{ L"t\xE4st", L"t\xE4st", 0, 0 },
2573		{ L"tast", L"t\xE4st", -1, 0 },
2574		{ L"tbst", L"t\xE4st", 1, 0 },
2575		{ L"tbst", L"t\xE6st", 1, 0 },
2576		{ L"t\xE4st", L"t\xC4st", -1, 0 },
2577		{ L"tBst", L"t\xC4st", 1, 0 },
2578		{ L"tBst", L"t\xE4st", 1, 0 },
2579		{ L"taest", L"t\xE6st", -1, 0 },
2580		{ L"tafst", L"t\xE6st", 1, 0 },
2581		{ L"taa", L"t\xE4", 1, 0 },
2582		{ L"tab", L"t\xE4", 1, 0 },
2583		{ L"tad", L"t\xE4", 1, 0 },
2584		{ L"tae", L"t\xE4", 1, 0 },
2585		{ L"taf", L"t\xE4", 1, 0 },
2586		{ L"cote", L"cot\xE9", -1, 0 },
2587		{ L"cot\xE9", L"c\xF4te", 1, 0 },
2588		{ L"c\xF4te", L"c\xF4t\xE9", -1, 0 },
2589		{ NULL, NULL, 0, 0 }
2590	};
2591	// CLDR-1.9 has adjusted the defaults of fr_FR to no longer do reverse
2592	// ordering of secondary differences (accents), but fr_CA still does that
2593	// by default
2594	test_coll(0, "fr_CA.UTF-8", coll_fr);
2595	test_coll(1, "fr_CA.UTF-8", coll_fr);
2596}
2597
2598
2599// #pragma mark - wcsftime -----------------------------------------------------
2600
2601
2602struct wcsftime_data {
2603	const wchar_t* format;
2604	const wchar_t* result;
2605};
2606
2607
2608void
2609test_wcsftime(const char* locale, const wcsftime_data data[])
2610{
2611	setlocale(LC_TIME, locale);
2612	setlocale(LC_CTYPE, locale);
2613	printf("wcsftime for '%s'\n", locale);
2614
2615	time_t nowSecs = 1279391169;	// pure magic
2616	tm* now = localtime(&nowSecs);
2617	int problemCount = 0;
2618	for (int i = 0; data[i].format != NULL; ++i) {
2619		wchar_t buf[100];
2620		wcsftime(buf, 100, data[i].format, now);
2621		if (wcscmp(buf, data[i].result) != 0) {
2622			printf(
2623				"\tPROBLEM: wcsftime(\"%ls\") = \"%ls\" (expected \"%ls\")\n",
2624				data[i].format, buf, data[i].result);
2625			problemCount++;
2626		}
2627	}
2628	if (problemCount)
2629		printf("\t%d problem(s) found!\n", problemCount);
2630	else
2631		printf("\tall fine\n");
2632}
2633
2634
2635void
2636test_wcsftime()
2637{
2638	setenv("TZ", "GMT", 1);
2639
2640	const wcsftime_data wcsftime_posix[] = {
2641		{ L"%c", L"Sat Jul 17 18:26:09 2010" },
2642		{ L"%x", L"07/17/10" },
2643		{ L"%X", L"18:26:09" },
2644		{ L"%a", L"Sat" },
2645		{ L"%A", L"Saturday" },
2646		{ L"%b", L"Jul" },
2647		{ L"%B", L"July" },
2648		{ NULL, NULL }
2649	};
2650	test_wcsftime("POSIX", wcsftime_posix);
2651
2652	const wcsftime_data wcsftime_de[] = {
2653		{ L"%c", L"Samstag, 17. Juli 2010 18:26:09 GMT" },
2654		{ L"%x", L"17.07.2010" },
2655		{ L"%X", L"18:26:09" },
2656		{ L"%a", L"Sa." },
2657		{ L"%A", L"Samstag" },
2658		{ L"%b", L"Jul" },
2659		{ L"%B", L"Juli" },
2660		{ NULL, NULL }
2661	};
2662	test_wcsftime("de_DE.UTF-8", wcsftime_de);
2663
2664	const wcsftime_data wcsftime_hr[] = {
2665		{ L"%c", L"subota, 17. srpnja 2010. 18:26:09 GMT" },
2666		{ L"%x", L"17. 07. 2010." },
2667		{ L"%X", L"18:26:09" },
2668		{ L"%a", L"sub" },
2669		{ L"%A", L"subota" },
2670		{ L"%b", L"srp" },
2671		{ L"%B", L"srpnja" },
2672		{ NULL, NULL }
2673	};
2674	test_wcsftime("hr_HR.ISO8859-2", wcsftime_hr);
2675
2676	const wcsftime_data wcsftime_gu[] = {
2677		{ L"%c", L"������������������, 17 ���������������, 2010 06:26:09 PM GMT" },
2678		{ L"%x", L"17 ���������������, 2010" },
2679		{ L"%X", L"06:26:09 PM" },
2680		{ L"%a", L"���������" },
2681		{ L"%A", L"������������������" },
2682		{ L"%b", L"���������������" },
2683		{ L"%B", L"���������������" },
2684		{ NULL, NULL }
2685	};
2686	test_wcsftime("gu_IN", wcsftime_gu);
2687
2688	const wcsftime_data wcsftime_it[] = {
2689		{ L"%c", L"sabato 17 luglio 2010 18:26:09 GMT" },
2690		{ L"%x", L"17/lug/2010" },
2691		{ L"%X", L"18:26:09" },
2692		{ L"%a", L"sab" },
2693		{ L"%A", L"sabato" },
2694		{ L"%b", L"lug" },
2695		{ L"%B", L"luglio" },
2696		{ NULL, NULL }
2697	};
2698	test_wcsftime("it_IT", wcsftime_it);
2699
2700	const wcsftime_data wcsftime_nl[] = {
2701		{ L"%c", L"zaterdag 17 juli 2010 18:26:09 GMT" },
2702		{ L"%x", L"17 jul. 2010" },
2703		{ L"%X", L"18:26:09" },
2704		{ L"%a", L"za" },
2705		{ L"%A", L"zaterdag" },
2706		{ L"%b", L"jul." },
2707		{ L"%B", L"juli" },
2708		{ NULL, NULL }
2709	};
2710	test_wcsftime("nl_NL", wcsftime_nl);
2711
2712	const wcsftime_data wcsftime_nb[] = {
2713		{ L"%c", L"kl. 18:26:09 GMT l\xF8rdag 17. juli 2010" },
2714		{ L"%x", L"17. juli 2010" },
2715		{ L"%X", L"18:26:09" },
2716		{ L"%a", L"l��r." },
2717		{ L"%A", L"l��rdag" },
2718		{ L"%b", L"juli" },
2719		{ L"%B", L"juli" },
2720		{ NULL, NULL }
2721	};
2722	test_wcsftime("nb_NO", wcsftime_nb);
2723}
2724
2725
2726// #pragma mark - wcspbrk ------------------------------------------------------
2727
2728
2729void
2730test_wcspbrk()
2731{
2732	printf("wcspbrk()\n");
2733
2734	int problemCount = 0;
2735	errno = 0;
2736
2737	{
2738		const wchar_t* string = L"";
2739		const wchar_t* accept = L" ";
2740		const wchar_t* result = wcspbrk(string, accept);
2741		const wchar_t* expected = NULL;
2742		if (result != expected || errno != 0) {
2743			printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p "
2744					"(expected %p), errno = %x (expected 0)\n", string, accept,
2745				result, expected, errno);
2746			problemCount++;
2747		}
2748	}
2749
2750	{
2751		const wchar_t* string = L"sometext";
2752		const wchar_t* accept = L" ";
2753		const wchar_t* result = wcspbrk(string, accept);
2754		const wchar_t* expected = NULL;
2755		if (result != expected || errno != 0) {
2756			printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p "
2757					"(expected %p), errno = %x (expected 0)\n", string, accept,
2758				result, expected, errno);
2759			problemCount++;
2760		}
2761	}
2762
2763	{
2764		const wchar_t* string = L"some more text";
2765		const wchar_t* accept = L" ";
2766		const wchar_t* result = wcspbrk(string, accept);
2767		const wchar_t* expected = string + 4;
2768		if (result != expected || errno != 0) {
2769			printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p "
2770					"(expected %p), errno = %x (expected 0)\n", string, accept,
2771				result, expected, errno);
2772			problemCount++;
2773		}
2774	}
2775
2776	{
2777		const wchar_t* string = L"some more text";
2778		const wchar_t* accept = L"UY\xE4 ";
2779		const wchar_t* result = wcspbrk(string, accept);
2780		const wchar_t* expected = string + 4;
2781		if (result != expected || errno != 0) {
2782			printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p "
2783					"(expected %p), errno = %x (expected 0)\n", string, accept,
2784				result, expected, errno);
2785			problemCount++;
2786		}
2787	}
2788
2789	{
2790		const wchar_t* string = L"some more text";
2791		const wchar_t* accept = L" emorstx";
2792		const wchar_t* result = wcspbrk(string, accept);
2793		const wchar_t* expected = string;
2794		if (result != expected || errno != 0) {
2795			printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p "
2796					"(expected %p), errno = %x (expected 0)\n", string, accept,
2797				result, expected, errno);
2798			problemCount++;
2799		}
2800	}
2801
2802	{
2803		const wchar_t* string = L"some more text";
2804		const wchar_t* accept = L"EMORSTX\xA0";
2805		const wchar_t* result = wcspbrk(string, accept);
2806		const wchar_t* expected = NULL;
2807		if (result != expected || errno != 0) {
2808			printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p "
2809					"(expected %p), errno = %x (expected 0)\n", string, accept,
2810				result, expected, errno);
2811			problemCount++;
2812		}
2813	}
2814
2815	if (problemCount)
2816		printf("\t%d problem(s) found!\n", problemCount);
2817	else
2818		printf("\tall fine\n");
2819}
2820
2821
2822// #pragma mark - wcscspn -------------------------------------------------------
2823
2824
2825void
2826test_wcscspn()
2827{
2828	printf("wcscspn()\n");
2829
2830	int problemCount = 0;
2831	errno = 0;
2832
2833	{
2834		const wchar_t* string = L"";
2835		const wchar_t* reject = L" ";
2836		size_t result = wcscspn(string, reject);
2837		size_t expected = 0;
2838		if (result != expected || errno != 0) {
2839			printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld "
2840					"(expected %ld), errno = %x (expected 0)\n", string, reject,
2841				result, expected, errno);
2842			problemCount++;
2843		}
2844	}
2845
2846	{
2847		const wchar_t* string = L"sometext";
2848		const wchar_t* reject = L" ";
2849		size_t result = wcscspn(string, reject);
2850		size_t expected = 8;
2851		if (result != expected || errno != 0) {
2852			printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld "
2853					"(expected %ld), errno = %x (expected 0)\n", string, reject,
2854				result, expected, errno);
2855			problemCount++;
2856		}
2857	}
2858
2859	{
2860		const wchar_t* string = L"some more text";
2861		const wchar_t* reject = L" mos";
2862		size_t result = wcscspn(string, reject);
2863		size_t expected = 0;
2864		if (result != expected || errno != 0) {
2865			printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld "
2866					"(expected %ld), errno = %x (expected 0)\n", string, reject,
2867				result, expected, errno);
2868			problemCount++;
2869		}
2870	}
2871
2872	{
2873		const wchar_t* string = L"some more text";
2874		const wchar_t* reject = L"t";
2875		size_t result = wcscspn(string, reject);
2876		size_t expected = 10;
2877		if (result != expected || errno != 0) {
2878			printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld "
2879					"(expected %ld), errno = %x (expected 0)\n", string, reject,
2880				result, expected, errno);
2881			problemCount++;
2882		}
2883	}
2884
2885	{
2886		const wchar_t* string = L"some more text";
2887		const wchar_t* reject = L"abcdfghijklnpquvwyz\t";
2888		size_t result = wcscspn(string, reject);
2889		size_t expected = wcslen(string);
2890		if (result != expected || errno != 0) {
2891			printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld "
2892					"(expected %ld), errno = %x (expected 0)\n", string, reject,
2893				result, expected, errno);
2894			problemCount++;
2895		}
2896	}
2897
2898	{
2899		const wchar_t* string = L"some more text";
2900		const wchar_t* reject = L"";
2901		size_t result = wcscspn(string, reject);
2902		size_t expected = wcslen(string);
2903		if (result != expected || errno != 0) {
2904			printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld "
2905					"(expected %ld), errno = %x (expected 0)\n", string, reject,
2906				result, expected, errno);
2907			problemCount++;
2908		}
2909	}
2910
2911	if (problemCount)
2912		printf("\t%d problem(s) found!\n", problemCount);
2913	else
2914		printf("\tall fine\n");
2915}
2916
2917
2918// #pragma mark - wcsspn -------------------------------------------------------
2919
2920
2921void
2922test_wcsspn()
2923{
2924	printf("wcsspn()\n");
2925
2926	int problemCount = 0;
2927	errno = 0;
2928
2929	{
2930		const wchar_t* string = L"";
2931		const wchar_t* accept = L" ";
2932		size_t result = wcsspn(string, accept);
2933		size_t expected = 0;
2934		if (result != expected || errno != 0) {
2935			printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld "
2936					"(expected %ld), errno = %x (expected 0)\n", string, accept,
2937				result, expected, errno);
2938			problemCount++;
2939		}
2940	}
2941
2942	{
2943		const wchar_t* string = L"sometext";
2944		const wchar_t* accept = L" ";
2945		size_t result = wcsspn(string, accept);
2946		size_t expected = 0;
2947		if (result != expected || errno != 0) {
2948			printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld "
2949					"(expected %ld), errno = %x (expected 0)\n", string, accept,
2950				result, expected, errno);
2951			problemCount++;
2952		}
2953	}
2954
2955	{
2956		const wchar_t* string = L"some more text";
2957		const wchar_t* accept = L" emo";
2958		size_t result = wcsspn(string, accept);
2959		size_t expected = 0;
2960		if (result != expected || errno != 0) {
2961			printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld "
2962					"(expected %ld), errno = %x (expected 0)\n", string, accept,
2963				result, expected, errno);
2964			problemCount++;
2965		}
2966	}
2967
2968	{
2969		const wchar_t* string = L"some more text";
2970		const wchar_t* accept = L" emorstx";
2971		size_t result = wcsspn(string, accept);
2972		size_t expected = wcslen(string);
2973		if (result != expected || errno != 0) {
2974			printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld "
2975					"(expected %ld), errno = %x (expected 0)\n", string, accept,
2976				result, expected, errno);
2977			problemCount++;
2978		}
2979	}
2980
2981	{
2982		const wchar_t* string = L"some more text";
2983		const wchar_t* accept = L"";
2984		size_t result = wcsspn(string, accept);
2985		size_t expected = 0;
2986		if (result != expected || errno != 0) {
2987			printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld "
2988					"(expected %ld), errno = %x (expected 0)\n", string, accept,
2989				result, expected, errno);
2990			problemCount++;
2991		}
2992	}
2993
2994	if (problemCount)
2995		printf("\t%d problem(s) found!\n", problemCount);
2996	else
2997		printf("\tall fine\n");
2998}
2999
3000
3001// #pragma mark - wcsstr ------------------------------------------------------
3002
3003
3004void
3005test_wcsstr()
3006{
3007	printf("wcsstr()\n");
3008
3009	int problemCount = 0;
3010	errno = 0;
3011
3012	{
3013		const wchar_t* string = L"";
3014		const wchar_t* sought = L" ";
3015		const wchar_t* result = wcsstr(string, sought);
3016		const wchar_t* expected = NULL;
3017		if (result != expected || errno != 0) {
3018			printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p "
3019					"(expected %p), errno = %x (expected 0)\n", string, sought,
3020				result, expected, errno);
3021			problemCount++;
3022		}
3023	}
3024
3025	{
3026		const wchar_t* string = L"sometext";
3027		const wchar_t* sought = L"som ";
3028		const wchar_t* result = wcsstr(string, sought);
3029		const wchar_t* expected = NULL;
3030		if (result != expected || errno != 0) {
3031			printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p "
3032					"(expected %p), errno = %x (expected 0)\n", string, sought,
3033				result, expected, errno);
3034			problemCount++;
3035		}
3036	}
3037
3038	{
3039		const wchar_t* string = L"sometext";
3040		const wchar_t* sought = L"soMe";
3041		const wchar_t* result = wcsstr(string, sought);
3042		const wchar_t* expected = NULL;
3043		if (result != expected || errno != 0) {
3044			printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p "
3045					"(expected %p), errno = %x (expected 0)\n", string, sought,
3046				result, expected, errno);
3047			problemCount++;
3048		}
3049	}
3050
3051	{
3052		const wchar_t* string = L"some more text";
3053		const wchar_t* sought = L"some ";
3054		const wchar_t* result = wcsstr(string, sought);
3055		const wchar_t* expected = string;
3056		if (result != expected || errno != 0) {
3057			printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p "
3058					"(expected %p), errno = %x (expected 0)\n", string, sought,
3059				result, expected, errno);
3060			problemCount++;
3061		}
3062	}
3063
3064	{
3065		const wchar_t* string = L"some more text";
3066		const wchar_t* sought = L" more";
3067		const wchar_t* result = wcsstr(string, sought);
3068		const wchar_t* expected = string + 4;
3069		if (result != expected || errno != 0) {
3070			printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p "
3071					"(expected %p), errno = %x (expected 0)\n", string, sought,
3072				result, expected, errno);
3073			problemCount++;
3074		}
3075	}
3076
3077	{
3078		const wchar_t* string = L"some more text";
3079		const wchar_t* sought = L"some more text";
3080		const wchar_t* result = wcsstr(string, sought);
3081		const wchar_t* expected = string;
3082		if (result != expected || errno != 0) {
3083			printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p "
3084					"(expected %p), errno = %x (expected 0)\n", string, sought,
3085				result, expected, errno);
3086			problemCount++;
3087		}
3088	}
3089
3090	{
3091		const wchar_t* string = L"some more text";
3092		const wchar_t* sought = L"some more text ";
3093		const wchar_t* result = wcsstr(string, sought);
3094		const wchar_t* expected = NULL;
3095		if (result != expected || errno != 0) {
3096			printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p "
3097					"(expected %p), errno = %x (expected 0)\n", string, sought,
3098				result, expected, errno);
3099			problemCount++;
3100		}
3101	}
3102
3103	if (problemCount)
3104		printf("\t%d problem(s) found!\n", problemCount);
3105	else
3106		printf("\tall fine\n");
3107}
3108
3109
3110// #pragma mark - wcstok ------------------------------------------------------
3111
3112
3113void
3114test_wcstok()
3115{
3116	printf("wcstok()\n");
3117
3118	int problemCount = 0;
3119
3120	{
3121		wchar_t string[] = L"";
3122		const wchar_t* delim = L" \t\n";
3123		wchar_t* state;
3124		wchar_t* result = wcstok(string, delim, &state);
3125		wchar_t* expected = NULL;
3126		wchar_t* expectedState = NULL;
3127		if (result != expected || state != expectedState) {
3128			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3129					"(expected %p), state = %p (expected %p)\n", string, delim,
3130				&state, result, expected, state, expectedState);
3131			problemCount++;
3132		}
3133
3134		result = wcstok(NULL, delim, &state);
3135		expected = NULL;
3136		expectedState = NULL;
3137		if (result != expected || state != expectedState) {
3138			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3139					"(expected %p), state = %p (expected %p)\n", string, delim,
3140				&state, result, expected, state, expectedState);
3141			problemCount++;
3142		}
3143	}
3144
3145	{
3146		wchar_t string[] = L"\t\t\t\n   \t";
3147		const wchar_t* delim = L" \t\n";
3148		wchar_t* state;
3149		wchar_t* result = wcstok(string, delim, &state);
3150		wchar_t* expected = NULL;
3151		wchar_t* expectedState = NULL;
3152		if (result != expected || state != expectedState) {
3153			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3154					"(expected %p), state = %p (expected %p)\n", string, delim,
3155				&state, result, expected, state, expectedState);
3156			problemCount++;
3157		}
3158
3159		result = wcstok(NULL, delim, &state);
3160		expected = NULL;
3161		expectedState = NULL;
3162		if (result != expected || state != expectedState) {
3163			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3164					"(expected %p), state = %p (expected %p)\n", string, delim,
3165				&state, result, expected, state, expectedState);
3166			problemCount++;
3167		}
3168	}
3169
3170	{
3171		wchar_t string[] = L"just some text here!";
3172		const wchar_t* delim = L" ";
3173		wchar_t* state;
3174		wchar_t* result = wcstok(string, delim, &state);
3175		wchar_t* expected = string;
3176		wchar_t* expectedState = string + 5;
3177		if (result != expected || state != expectedState) {
3178			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3179					"(expected %p), state = %p (expected %p)\n", string, delim,
3180				&state, result, expected, state, expectedState);
3181			problemCount++;
3182		}
3183
3184		result = wcstok(NULL, delim, &state);
3185		expected = string + 5;
3186		expectedState = string + 10;
3187		if (result != expected || state != expectedState) {
3188			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3189					"(expected %p), state = %p (expected %p)\n", string, delim,
3190				&state, result, expected, state, expectedState);
3191			problemCount++;
3192		}
3193
3194		result = wcstok(NULL, delim, &state);
3195		expected = string + 10;
3196		expectedState = string + 15;
3197		if (result != expected || state != expectedState) {
3198			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3199					"(expected %p), state = %p (expected %p)\n", string, delim,
3200				&state, result, expected, state, expectedState);
3201			problemCount++;
3202		}
3203
3204		result = wcstok(NULL, delim, &state);
3205		expected = string + 15;
3206		expectedState = NULL;
3207		if (result != expected || state != expectedState) {
3208			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3209					"(expected %p), state = %p (expected %p)\n", string, delim,
3210				&state, result, expected, state, expectedState);
3211			problemCount++;
3212		}
3213
3214		result = wcstok(NULL, delim, &state);
3215		expected = NULL;
3216		expectedState = NULL;
3217		if (result != expected || state != expectedState) {
3218			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3219					"(expected %p), state = %p (expected %p)\n", string, delim,
3220				&state, result, expected, state, expectedState);
3221			problemCount++;
3222		}
3223	}
3224
3225	{
3226		wchar_t string[] = L" just \t\nsome\t\t\ttext\n\n\nhere!";
3227		const wchar_t* delim = L"\n\t ";
3228		wchar_t* state;
3229		wchar_t* result = wcstok(string, delim, &state);
3230		wchar_t* expected = string + 1;
3231		wchar_t* expectedState = string + 6;
3232		if (result != expected || state != expectedState) {
3233			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3234					"(expected %p), state = %p (expected %p)\n", string, delim,
3235				&state, result, expected, state, expectedState);
3236			problemCount++;
3237		}
3238		if (wcscmp(result, L"just") != 0) {
3239			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls "
3240					"(expected %ls)\n", string, delim, &state, result, L"just");
3241			problemCount++;
3242		}
3243
3244		result = wcstok(NULL, delim, &state);
3245		expected = string + 8;
3246		expectedState = string + 13;
3247		if (result != expected || state != expectedState) {
3248			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3249					"(expected %p), state = %p (expected %p)\n", string, delim,
3250				&state, result, expected, state, expectedState);
3251			problemCount++;
3252		}
3253		if (wcscmp(result, L"some") != 0) {
3254			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls "
3255					"(expected %ls)\n", string, delim, &state, result, L"some");
3256			problemCount++;
3257		}
3258
3259		result = wcstok(NULL, delim, &state);
3260		expected = string + 15;
3261		expectedState = string + 20;
3262		if (result != expected || state != expectedState) {
3263			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3264					"(expected %p), state = %p (expected %p)\n", string, delim,
3265				&state, result, expected, state, expectedState);
3266			problemCount++;
3267		}
3268		if (wcscmp(result, L"text") != 0) {
3269			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls "
3270					"(expected %ls)\n", string, delim, &state, result, L"text");
3271			problemCount++;
3272		}
3273
3274		result = wcstok(NULL, delim, &state);
3275		expected = string + 22;
3276		expectedState = NULL;
3277		if (result != expected || state != expectedState) {
3278			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3279					"(expected %p), state = %p (expected %p)\n", string, delim,
3280				&state, result, expected, state, expectedState);
3281			problemCount++;
3282		}
3283		if (wcscmp(result, L"here!") != 0) {
3284			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls "
3285					"(expected %ls)\n", string, delim, &state, result, L"here!");
3286			problemCount++;
3287		}
3288
3289		result = wcstok(NULL, delim, &state);
3290		expected = NULL;
3291		expectedState = NULL;
3292		if (result != expected || state != expectedState) {
3293			printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p "
3294					"(expected %p), state = %p (expected %p)\n", string, delim,
3295				&state, result, expected, state, expectedState);
3296			problemCount++;
3297		}
3298	}
3299
3300	if (problemCount)
3301		printf("\t%d problem(s) found!\n", problemCount);
3302	else
3303		printf("\tall fine\n");
3304}
3305
3306
3307// #pragma mark - wmemchr ------------------------------------------------------
3308
3309
3310void
3311test_wmemchr()
3312{
3313	printf("wmemchr()\n");
3314
3315	int problemCount = 0;
3316	errno = 0;
3317
3318	{
3319		const wchar_t* string = L"";
3320		const wchar_t ch = L' ';
3321		const wchar_t* result = wmemchr(string, ch, 0);
3322		const wchar_t* expected = NULL;
3323		if (result != expected || errno != 0) {
3324			printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 0) = %p "
3325					"(expected %p), errno = %x (expected 0)\n", string, ch,
3326				result, expected, errno);
3327			problemCount++;
3328		}
3329	}
3330
3331	{
3332		const wchar_t* string = L"";
3333		const wchar_t ch = L'\0';
3334		const wchar_t* result = wmemchr(string, ch, 0);
3335		const wchar_t* expected = NULL;
3336		if (result != expected || errno != 0) {
3337			printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 0) = %p "
3338					"(expected %p), errno = %x (expected 0)\n", string, ch,
3339				result, expected, errno);
3340			problemCount++;
3341		}
3342	}
3343
3344	{
3345		const wchar_t* string = L"";
3346		const wchar_t ch = L'\0';
3347		const wchar_t* result = wmemchr(string, ch, 1);
3348		const wchar_t* expected = string;
3349		if (result != expected || errno != 0) {
3350			printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p "
3351					"(expected %p), errno = %x (expected 0)\n", string, ch,
3352				result, expected, errno);
3353			problemCount++;
3354		}
3355	}
3356
3357	{
3358		const wchar_t* string = L"sometext";
3359		const wchar_t ch = L' ';
3360		const wchar_t* result = wmemchr(string, ch, 8);
3361		const wchar_t* expected = NULL;
3362		if (result != expected || errno != 0) {
3363			printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p "
3364					"(expected %p), errno = %x (expected 0)\n", string, ch,
3365				result, expected, errno);
3366			problemCount++;
3367		}
3368	}
3369
3370	{
3371		const wchar_t* string = L"some text";
3372		const wchar_t ch = L' ';
3373		const wchar_t* result = wmemchr(string, ch, 9);
3374		const wchar_t* expected = string + 4;
3375		if (result != expected || errno != 0) {
3376			printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p "
3377					"(expected %p), errno = %x (expected 0)\n", string, ch,
3378				result, expected, errno);
3379			problemCount++;
3380		}
3381	}
3382
3383	{
3384		const wchar_t* string = L"some text";
3385		const wchar_t ch = L'M';
3386		const wchar_t* result = wmemchr(string, ch, 9);
3387		const wchar_t* expected = NULL;
3388		if (result != expected || errno != 0) {
3389			printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p "
3390					"(expected %p), errno = %x (expected 0)\n", string, ch,
3391				result, expected, errno);
3392			problemCount++;
3393		}
3394	}
3395
3396	{
3397		const wchar_t* string = L"some\0text";
3398		const wchar_t ch = L't';
3399		const wchar_t* result = wmemchr(string, ch, 4);
3400		const wchar_t* expected = NULL;
3401		if (result != expected || errno != 0) {
3402			printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p "
3403					"(expected %p), errno = %x (expected 0)\n", string, ch,
3404				result, expected, errno);
3405			problemCount++;
3406		}
3407	}
3408
3409	{
3410		const wchar_t* string = L"some\0text";
3411		const wchar_t ch = L't';
3412		const wchar_t* result = wmemchr(string, ch, 9);
3413		const wchar_t* expected = string + 5;
3414		if (result != expected || errno != 0) {
3415			printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p "
3416					"(expected %p), errno = %x (expected 0)\n", string, ch,
3417				result, expected, errno);
3418			problemCount++;
3419		}
3420	}
3421
3422	if (problemCount)
3423		printf("\t%d problem(s) found!\n", problemCount);
3424	else
3425		printf("\tall fine\n");
3426}
3427
3428
3429// #pragma mark - wmemcmp ------------------------------------------------------
3430
3431
3432void
3433test_wmemcmp()
3434{
3435	printf("wmemcmp()\n");
3436
3437	int problemCount = 0;
3438	errno = 0;
3439
3440	{
3441		const wchar_t* a = L"";
3442		const wchar_t* b = L"";
3443		int result = sign(wmemcmp(a, b, 0));
3444		int expected = 0;
3445		if (result != expected || errno != 0) {
3446			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d "
3447					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3448				expected, errno);
3449			problemCount++;
3450		}
3451	}
3452
3453	{
3454		const wchar_t* a = L"";
3455		const wchar_t* b = L"";
3456		int result = sign(wmemcmp(a, b, 1));
3457		int expected = 0;
3458		if (result != expected || errno != 0) {
3459			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d "
3460					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3461				expected, errno);
3462			problemCount++;
3463		}
3464	}
3465
3466	{
3467		const wchar_t* a = L"a";
3468		const wchar_t* b = L"b";
3469		int result = sign(wmemcmp(a, b, 0));
3470		int expected = 0;
3471		if (result != expected || errno != 0) {
3472			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d "
3473					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3474				expected, errno);
3475			problemCount++;
3476		}
3477	}
3478
3479	{
3480		const wchar_t* a = L"a";
3481		const wchar_t* b = L"b";
3482		int result = sign(wmemcmp(a, b, 1));
3483		int expected = -1;
3484		if (result != expected || errno != 0) {
3485			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 1) = %d "
3486					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3487				expected, errno);
3488			problemCount++;
3489		}
3490	}
3491
3492	{
3493		const wchar_t* a = L"b";
3494		const wchar_t* b = L"a";
3495		int result = sign(wmemcmp(a, b, 2));
3496		int expected = 1;
3497		if (result != expected || errno != 0) {
3498			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d "
3499					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3500				expected, errno);
3501			problemCount++;
3502		}
3503	}
3504
3505	{
3506		const wchar_t* a = L"a";
3507		const wchar_t* b = L"A";
3508		int result = sign(wmemcmp(a, b, 2));
3509		int expected = 1;
3510		if (result != expected || errno != 0) {
3511			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d "
3512					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3513				expected, errno);
3514			problemCount++;
3515		}
3516	}
3517
3518	{
3519		const wchar_t* a = L"t��st";
3520		const wchar_t* b = L"t��st";
3521		int result = sign(wmemcmp(a, b, 5));
3522		int expected = 0;
3523		if (result != expected || errno != 0) {
3524			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 5) = %d "
3525					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3526				expected, errno);
3527			problemCount++;
3528		}
3529	}
3530
3531	{
3532		const wchar_t* a = L"t��st";
3533		const wchar_t* b = L"t��st ";
3534		int result = sign(wmemcmp(a, b, 5));
3535		int expected = -1;
3536		if (result != expected || errno != 0) {
3537			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 5) = %d "
3538					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3539				expected, errno);
3540			problemCount++;
3541		}
3542	}
3543
3544	{
3545		const wchar_t* a = L"t��St";
3546		const wchar_t* b = L"t��s";
3547		int result = sign(wmemcmp(a, b, 2));
3548		int expected = 0;
3549		if (result != expected || errno != 0) {
3550			printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d "
3551					"(expected %d), errno = %x (expected 0)\n", a, b, result,
3552				expected, errno);
3553			problemCount++;
3554		}
3555	}
3556
3557	if (problemCount)
3558		printf("\t%d problem(s) found!\n", problemCount);
3559	else
3560		printf("\tall fine\n");
3561}
3562
3563
3564// #pragma mark - wmemcpy ------------------------------------------------------
3565
3566
3567void
3568test_wmemcpy()
3569{
3570	printf("wmemcpy()\n");
3571
3572	int problemCount = 0;
3573	errno = 0;
3574
3575	{
3576		const wchar_t* source = L"";
3577		wchar_t destination[] = L"XXXX";
3578		wchar_t* result = wmemcpy(destination, source, 0);
3579		if (result != destination || errno != 0) {
3580			printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 0) = "
3581					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3582				result, destination, errno);
3583			problemCount++;
3584		}
3585		if (destination[0] != L'X') {
3586			printf("\tPROBLEM: wmemcpy(destination, \"%ls\", 0) -> "
3587					"destination[0]=%x, expected %x\n", source, destination[0],
3588				L'X');
3589			problemCount++;
3590		}
3591	}
3592
3593	{
3594		const wchar_t* source = L"";
3595		wchar_t destination[] = L"XXXX";
3596		wchar_t* result = wmemcpy(destination, source, 1);
3597		if (result != destination || wmemcmp(destination, source, 1) != 0
3598			|| errno != 0) {
3599			printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 1) = "
3600					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3601				result, destination, errno);
3602			problemCount++;
3603		}
3604		if (destination[1] != L'X') {
3605			printf("\tPROBLEM: wmemcpy(destination, \"%ls\", 1) -> "
3606					"destination[1]=%x, expected %x\n", source, destination[1],
3607				L'X');
3608			problemCount++;
3609		}
3610	}
3611
3612	{
3613		const wchar_t* source = L"t��stdata \0with some char��cters";
3614		wchar_t destination[64];
3615		wchar_t* result = wmemcpy(destination, source, 31);
3616		if (result != destination || wmemcmp(destination, source, 31) != 0
3617			|| errno != 0) {
3618			printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 31) = "
3619					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3620				result, destination, errno);
3621			problemCount++;
3622		}
3623	}
3624
3625	if (problemCount)
3626		printf("\t%d problem(s) found!\n", problemCount);
3627	else
3628		printf("\tall fine\n");
3629}
3630
3631
3632// #pragma mark - wmempcpy ------------------------------------------------------
3633
3634
3635void
3636test_wmempcpy()
3637{
3638	printf("wmempcpy()\n");
3639
3640	int problemCount = 0;
3641	errno = 0;
3642
3643	{
3644		const wchar_t* source = L"";
3645		wchar_t destination[] = L"XXXX";
3646		wchar_t* result = wmempcpy(destination, source, 0);
3647		if (result != destination || errno != 0) {
3648			printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 0) = "
3649					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3650				result, destination, errno);
3651			problemCount++;
3652		}
3653		if (destination[0] != L'X') {
3654			printf("\tPROBLEM: wmempcpy(destination, \"%ls\", 0) -> "
3655					"destination[0]=%x, expected %x\n", source, destination[0],
3656				L'X');
3657			problemCount++;
3658		}
3659	}
3660
3661	{
3662		const wchar_t* source = L"";
3663		wchar_t destination[] = L"XXXX";
3664		wchar_t* result = wmempcpy(destination, source, 1);
3665		if (result != destination + 1 || wmemcmp(destination, source, 1) != 0
3666			|| errno != 0) {
3667			printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 1) = "
3668					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3669				result, destination, errno);
3670			problemCount++;
3671		}
3672		if (destination[1] != L'X') {
3673			printf("\tPROBLEM: wmempcpy(destination, \"%ls\", 1) -> "
3674					"destination[1]=%x, expected %x\n", source, destination[1],
3675				L'X');
3676			problemCount++;
3677		}
3678	}
3679
3680	{
3681		const wchar_t* source = L"t��stdata \0with some char��cters";
3682		wchar_t destination[64];
3683		wchar_t* result = wmempcpy(destination, source, 31);
3684		if (result != destination + 31 || wmemcmp(destination, source, 31) != 0
3685			|| errno != 0) {
3686			printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 31) = "
3687					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3688				result, destination, errno);
3689			problemCount++;
3690		}
3691	}
3692
3693	if (problemCount)
3694		printf("\t%d problem(s) found!\n", problemCount);
3695	else
3696		printf("\tall fine\n");
3697}
3698
3699
3700// #pragma mark - wmemmove ------------------------------------------------------
3701
3702
3703void
3704test_wmemmove()
3705{
3706	printf("wmemmove()\n");
3707
3708	int problemCount = 0;
3709	errno = 0;
3710
3711	{
3712		const wchar_t* source = L"";
3713		wchar_t destination[] = L"XXXX";
3714		wchar_t* result = wmemmove(destination, source, 0);
3715		if (result != destination || errno != 0) {
3716			printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 0) = "
3717					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3718				result, destination, errno);
3719			problemCount++;
3720		}
3721		if (destination[0] != L'X') {
3722			printf("\tPROBLEM: wmemmove(destination, \"%ls\", 0) -> "
3723					"destination[0]=%x, expected %x\n", source, destination[0],
3724				L'X');
3725			problemCount++;
3726		}
3727	}
3728
3729	{
3730		const wchar_t* source = L"";
3731		wchar_t destination[] = L"XXXX";
3732		wchar_t* result = wmemmove(destination, source, 1);
3733		if (result != destination || wmemcmp(destination, source, 1) != 0
3734			|| errno != 0) {
3735			printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 1) = "
3736					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3737				result, destination, errno);
3738			problemCount++;
3739		}
3740		if (destination[1] != L'X') {
3741			printf("\tPROBLEM: wmemmove(destination, \"%ls\", 1) -> "
3742					"destination[1]=%x, expected %x\n", source, destination[1],
3743				L'X');
3744			problemCount++;
3745		}
3746	}
3747
3748	{
3749		const wchar_t* source = L"t��stdata \0with some char��cters";
3750		wchar_t destination[64];
3751		wmemcpy(destination, source, 31);
3752		wchar_t* result = wmemmove(destination, destination + 4, 27);
3753		if (result != destination || wmemcmp(destination, source + 4, 27) != 0
3754			|| errno != 0) {
3755			printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 27) = "
3756					"\"%ls\" (expected %p), errno = %x (expected 0)\n",
3757				source + 4, result, destination, errno);
3758			problemCount++;
3759		}
3760	}
3761
3762	{
3763		const wchar_t* source = L"t��stdata \0with some char��cters";
3764		wchar_t destination[64];
3765		wmemcpy(destination, source, 31);
3766		wchar_t* result = wmemmove(destination + 2, destination, 8);
3767		if (result != destination + 2
3768			|| wmemcmp(destination, L"t��t��stdatawith some char��cters", 31) != 0
3769			|| errno != 0) {
3770			printf("\tPROBLEM: result for wmemmove(destination + 9, \"%ls\", 8)"
3771					" = \"%ls\" (expected %p), errno = %x (expected 0)\n",
3772				source, result, destination, errno);
3773			problemCount++;
3774		}
3775	}
3776
3777	if (problemCount)
3778		printf("\t%d problem(s) found!\n", problemCount);
3779	else
3780		printf("\tall fine\n");
3781}
3782
3783
3784// #pragma mark - wmemset ------------------------------------------------------
3785
3786
3787void
3788test_wmemset()
3789{
3790	printf("wmemset()\n");
3791
3792	int problemCount = 0;
3793	errno = 0;
3794
3795	{
3796		wchar_t source = L'\0';
3797		wchar_t destination[] = L"XXXX";
3798		wchar_t* result = wmemset(destination, source, 0);
3799		if (result != destination || errno != 0) {
3800			printf("\tPROBLEM: result for wmemset(destination, '%lc', 0) = "
3801					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3802				result, destination, errno);
3803			problemCount++;
3804		}
3805		if (destination[0] != L'X') {
3806			printf("\tPROBLEM: wmemset(destination, '%lc', 0) -> "
3807					"destination[0]=%x, expected %x\n", source, destination[0],
3808				L'X');
3809			problemCount++;
3810		}
3811	}
3812
3813	{
3814		wchar_t source = L'M';
3815		wchar_t destination[] = L"some text";
3816		wchar_t* result = wmemset(destination, source, 1);
3817		if (result != destination || errno != 0) {
3818			printf("\tPROBLEM: result for wmemset(destination, '%lc', 1) = "
3819					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3820				result, destination, errno);
3821			problemCount++;
3822		}
3823		if (destination[0] != L'M') {
3824			printf("\tPROBLEM: wmemset(destination, '%lc', 1) -> "
3825					"destination[0]=%x, expected %x\n", source, destination[0],
3826				L'M');
3827			problemCount++;
3828		}
3829		if (destination[1] != L'o') {
3830			printf("\tPROBLEM: wmemset(destination, '%lc', 1) -> "
3831					"destination[1]=%x, expected %x\n", source, destination[1],
3832				L'o');
3833			problemCount++;
3834		}
3835	}
3836
3837	{
3838		wchar_t source = L'M';
3839		wchar_t destination[] = L"some text";
3840		wchar_t* result = wmemset(destination, source, 9);
3841		if (result != destination || errno != 0) {
3842			printf("\tPROBLEM: result for wmemset(destination, '%lc', 9) = "
3843					"\"%ls\" (expected %p), errno = %x (expected 0)\n", source,
3844				result, destination, errno);
3845			problemCount++;
3846		}
3847		for (int i = 0; i < 9; ++i) {
3848			if (destination[i] != L'M') {
3849				printf("\tPROBLEM: wmemset(destination, '%lc', 9) -> "
3850						"destination[%d]=%x, expected %x\n", source, i,
3851					destination[i], L'M');
3852				problemCount++;
3853			}
3854		}
3855	}
3856
3857	if (problemCount)
3858		printf("\t%d problem(s) found!\n", problemCount);
3859	else
3860		printf("\tall fine\n");
3861}
3862
3863
3864// #pragma mark - sprintf ------------------------------------------------------
3865
3866
3867struct sprintf_data {
3868	const char* format;
3869	const void* value;
3870	const char* result;
3871};
3872
3873
3874void
3875test_sprintf(const char* locale, const sprintf_data data[])
3876{
3877	setlocale(LC_ALL, locale);
3878	printf("sprintf for '%s'\n", locale);
3879
3880	int problemCount = 0;
3881	for (int i = 0; data[i].format != NULL; ++i) {
3882		char buf[100];
3883		if (strstr(data[i].format, "%ls") != NULL)
3884			sprintf(buf, data[i].format, (wchar_t*)data[i].value);
3885		else if (strstr(data[i].format, "%s") != NULL)
3886			sprintf(buf, data[i].format, (char*)data[i].value);
3887		if (strcmp(buf, data[i].result) != 0) {
3888			printf("\tPROBLEM: sprintf(\"%s\") = \"%s\" (expected \"%s\")\n",
3889				data[i].format, buf, data[i].result);
3890			problemCount++;
3891		}
3892	}
3893	if (problemCount)
3894		printf("\t%d problem(s) found!\n", problemCount);
3895	else
3896		printf("\tall fine\n");
3897}
3898
3899
3900void
3901test_sprintf()
3902{
3903	const sprintf_data sprintf_posix[] = {
3904		{ "%s", (const void*)"test", "test" },
3905		{ "%ls", (const void*)L"test", "test" },
3906		{ NULL, NULL, NULL }
3907	};
3908	test_sprintf("POSIX", sprintf_posix);
3909
3910	const sprintf_data sprintf_de[] = {
3911		{ "%s", "test", "test" },
3912		{ "%ls", L"test", "test" },
3913		{ "%s", "t\xC3\xA4st", "t\xC3\xA4st" },
3914		{ "%ls", L"t\xE4st", "t\xC3\xA4st" },
3915		{ NULL, NULL, NULL }
3916	};
3917	test_sprintf("de_DE.UTF-8", sprintf_de);
3918
3919	const sprintf_data sprintf_de_iso[] = {
3920		{ "%s", "test", "test" },
3921		{ "%ls", L"test", "test" },
3922		{ "%s", "t\xC3\xA4st", "t\xC3\xA4st" },
3923		{ "%s", "t\xE4st", "t\xE4st" },
3924		{ "%ls", L"t\xE4st", "t\xE4st" },
3925		{ NULL, NULL, NULL }
3926	};
3927	test_sprintf("de_DE.ISO8859-1", sprintf_de_iso);
3928}
3929
3930
3931// #pragma mark - swprintf ----------------------------------------------------
3932
3933
3934struct swprintf_data {
3935	const wchar_t* format;
3936	const void* value;
3937	const wchar_t* result;
3938};
3939
3940
3941void
3942test_swprintf(const char* locale, const swprintf_data data[])
3943{
3944	setlocale(LC_ALL, locale);
3945	printf("swprintf for '%s'\n", locale);
3946
3947	int problemCount = 0;
3948	for (int i = 0; data[i].format != NULL; ++i) {
3949		wchar_t buf[100];
3950		if (wcsstr(data[i].format, L"%ls") != NULL)
3951			swprintf(buf, 100, data[i].format, (wchar_t*)data[i].value);
3952		else if (wcsstr(data[i].format, L"%s") != NULL)
3953			swprintf(buf, 100, data[i].format, (char*)data[i].value);
3954		if (wcscmp(buf, data[i].result) != 0) {
3955			printf("\tPROBLEM: swprintf(\"%ls\") = \"%ls\" (expected \"%ls\")\n",
3956				data[i].format, buf, data[i].result);
3957			problemCount++;
3958		}
3959	}
3960	if (problemCount)
3961		printf("\t%d problem(s) found!\n", problemCount);
3962	else
3963		printf("\tall fine\n");
3964}
3965
3966
3967void
3968test_swprintf()
3969{
3970	const swprintf_data swprintf_posix[] = {
3971		{ L"%s", (const void*)"test", L"test" },
3972		{ L"%ls", (const void*)L"test", L"test" },
3973		{ NULL, NULL, NULL }
3974	};
3975	test_swprintf("POSIX", swprintf_posix);
3976
3977	const swprintf_data swprintf_de[] = {
3978		{ L"%s", "test", L"test" },
3979		{ L"%ls", L"test", L"test" },
3980		{ L"%s", "t\xC3\xA4st", L"t\xE4st" },
3981		{ L"%ls", L"t\xE4st", L"t\xE4st" },
3982		{ NULL, NULL, NULL }
3983	};
3984	test_swprintf("de_DE.UTF-8", swprintf_de);
3985
3986	const swprintf_data swprintf_de_iso[] = {
3987		{ L"%s", "test", L"test" },
3988		{ L"%ls", L"test", L"test" },
3989		{ L"%s", "t\xC3\xA4st", L"t\xC3\xA4st" },
3990		{ L"%s", "t\xE4st", L"t\xE4st" },
3991		{ L"%ls", L"t\xE4st", L"t\xE4st" },
3992		{ NULL, NULL, NULL }
3993	};
3994	test_swprintf("de_DE.ISO8859-1", swprintf_de_iso);
3995}
3996
3997
3998// #pragma mark - main ---------------------------------------------------------
3999
4000
4001/*
4002 * Test several different aspects of the wchar-string functions.
4003 */
4004int
4005main(void)
4006{
4007	setlocale(LC_ALL, "de_DE");
4008
4009	test_collation();
4010
4011	test_sprintf();
4012	test_swprintf();
4013
4014	test_wcsftime();
4015
4016	test_wcpcpy();
4017	test_wcscasecmp();
4018	test_wcscat();
4019	test_wcschr();
4020	test_wcscmp();
4021	test_wcscpy();
4022	test_wcscspn();
4023	test_wcsdup();
4024#ifdef __HAIKU__
4025	test_wcslcat();
4026	test_wcslcpy();
4027#endif
4028	test_wcslen();
4029	test_wcspbrk();
4030	test_wcsspn();
4031	test_wcsstr();
4032	test_wcstok();
4033
4034	test_wmemchr();
4035	test_wmemcmp();
4036	test_wmemcpy();
4037	test_wmemmove();
4038	test_wmempcpy();
4039	test_wmemset();
4040
4041	return 0;
4042}
4043