1 /* $Id: test.c,v 1.3 2006/11/10 17:38:33 christos Exp $ */
4 * Copyright (c)2004 Citrus Project,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 typedef size_t wcrtomb_t(char *, wchar_t, mbstate_t *);
39 void dotest1(const char *, wcrtomb_t
, wchar_t *, mbstate_t *);
42 _wctomb(char *s
, wchar_t wc
, mbstate_t *ps
)
49 main(int argc
, char *argv
[])
51 wchar_t wcs
[teststring_wclen
+ 2];
56 if (setlocale(LC_CTYPE
, teststring_loc
) == NULL
)
60 wcs
[teststring_wclen
] = L
'X'; /* poison */
61 sz
= mbsrtowcs(wcs
, &pcs
, teststring_wclen
+ 2, NULL
);
62 if (sz
!= teststring_wclen
)
64 if (wcs
[teststring_wclen
])
67 dotest1("wctomb", _wctomb
, wcs
, NULL
);
68 memset(&st
, 0, sizeof(st
));
69 dotest1("wcrtomb", wcrtomb
, wcs
, &st
);
70 dotest1("wcrtomb (internal state)", wcrtomb
, wcs
, NULL
);
76 dotest1(const char *text
, wcrtomb_t fn
, wchar_t *wcs
, mbstate_t *stp
)
82 cs
= malloc(MB_CUR_MAX
);
85 printf("testing %s\n", text
);
87 for (i
= 0; i
< teststring_wclen
+ 1; i
++) {
88 ret
= fn(cs
, wcs
[i
], stp
);
89 if (ret
!= teststring_mblen
[i
]) {
90 printf("\t[%d] %d != %d BAD\n",
91 i
, ret
, teststring_mblen
[i
]);
95 printf("\t[%d] %d ok\n", i
, ret
);