annotate tests/test-wcsrtombs.c @ 11655:ed090c498dd0

version-etc: fix regression * lib/version-etc.h (ATTRIBUTE_SENTINEL): Define for new enough gcc. (version_etc): Use it, to catch bugs with trailing NULL. * lib/version-etc.c (version_etc_arn): Delete unused argument. (version_etc_va): Fix logic bug. * modules/version-etc-tests: Add test. * tests/test-version-etc.c: New file. * tests/test-version-etc.sh: Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Thu, 25 Jun 2009 12:13:35 -0600
parents d3a1e8911dfa
children e8d2c6fc33ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of conversion of wide string to string.
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2008 Free Software Foundation, Inc.
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2008. */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <wchar.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <locale.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdio.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdlib.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <string.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #define ASSERT(expr) \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 do \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 { \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 if (!(expr)) \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 { \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 fflush (stderr); \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 abort (); \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 } \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 } \
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 while (0)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 int
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 main (int argc, char *argv[])
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 /* configure should already have checked that the locale is supported. */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 if (setlocale (LC_ALL, "") == NULL)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 return 1;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 if (argc > 1)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 wchar_t input[10];
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 size_t n;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 const wchar_t *src;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 #define BUFSIZE 20
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 char buf[BUFSIZE];
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 size_t ret;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 size_t i;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 for (i = 0; i < BUFSIZE; i++)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 buf[i] = '_';
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 switch (argv[1][0])
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 case '1':
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 const char original[] = "B\374\337er"; /* "Büßer" */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 ret = mbstowcs (input, original, 10);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 ASSERT (ret == 5);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 for (n = 0; n < 10; n++)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 src = input;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 ret = wcsrtombs (NULL, &src, n, NULL);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 ASSERT (ret == 5);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 ASSERT (src == input);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 src = input;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 ret = wcsrtombs (buf, &src, n, NULL);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 ASSERT (ret == (n <= 5 ? n : 5));
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 ASSERT (src == (n <= 5 ? input + n : NULL));
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 ASSERT (memcmp (buf, original, ret) == 0);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 if (src == NULL)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 ASSERT (buf[ret] == '\0');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 ASSERT (buf[ret + (src == NULL) + 0] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 ASSERT (buf[ret + (src == NULL) + 1] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 ASSERT (buf[ret + (src == NULL) + 2] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 break;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 case '2':
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 /* Locale encoding is UTF-8. */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 const char original[] = "B\303\274\303\237er"; /* "Büßer" */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 ret = mbstowcs (input, original, 10);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 ASSERT (ret == 5);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 for (n = 0; n < 10; n++)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 src = input;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 ret = wcsrtombs (NULL, &src, n, NULL);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 ASSERT (ret == 7);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 ASSERT (src == input);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 src = input;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 ret = wcsrtombs (buf, &src, n, NULL);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 ASSERT (ret == (n < 1 ? n :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 n < 3 ? 1 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 n < 5 ? 3 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 n <= 7 ? n : 7));
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 ASSERT (src == (n < 1 ? input + n :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 n < 3 ? input + 1 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 n < 5 ? input + 2 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 n <= 7 ? input + (n - 2) : NULL));
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 ASSERT (memcmp (buf, original, ret) == 0);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 if (src == NULL)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 ASSERT (buf[ret] == '\0');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 ASSERT (buf[ret + (src == NULL) + 0] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 ASSERT (buf[ret + (src == NULL) + 1] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 ASSERT (buf[ret + (src == NULL) + 2] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 break;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 case '3':
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 /* Locale encoding is EUC-JP. */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 const char original[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 ret = mbstowcs (input, original, 10);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 ASSERT (ret == 5);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 for (n = 0; n < 10; n++)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 src = input;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 ret = wcsrtombs (NULL, &src, n, NULL);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 ASSERT (ret == 8);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 ASSERT (src == input);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 src = input;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 ret = wcsrtombs (buf, &src, n, NULL);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 ASSERT (ret == (n < 1 ? n :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 n < 3 ? 1 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 n < 5 ? 3 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 n < 7 ? 5 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 n <= 8 ? n : 8));
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 ASSERT (src == (n < 1 ? input + n :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 n < 3 ? input + 1 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 n < 5 ? input + 2 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 n < 7 ? input + 3 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 n <= 8 ? input + (n - 3) : NULL));
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 ASSERT (memcmp (buf, original, ret) == 0);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 if (src == NULL)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 ASSERT (buf[ret] == '\0');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 ASSERT (buf[ret + (src == NULL) + 0] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 ASSERT (buf[ret + (src == NULL) + 1] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 ASSERT (buf[ret + (src == NULL) + 2] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 break;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 case '4':
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 /* Locale encoding is GB18030. */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 const char original[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 ret = mbstowcs (input, original, 10);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 ASSERT (ret == 5);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 for (n = 0; n < 10; n++)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 src = input;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 ret = wcsrtombs (NULL, &src, n, NULL);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 ASSERT (ret == 9);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 ASSERT (src == input);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 src = input;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 ret = wcsrtombs (buf, &src, n, NULL);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 ASSERT (ret == (n < 1 ? n :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 n < 3 ? 1 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 n < 7 ? 3 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 n <= 9 ? n : 9));
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 ASSERT (src == (n < 1 ? input + n :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 n < 3 ? input + 1 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 n < 7 ? input + 2 :
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 n <= 9 ? input + (n - 4) : NULL));
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 ASSERT (memcmp (buf, original, ret) == 0);
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 if (src == NULL)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 ASSERT (buf[ret] == '\0');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 ASSERT (buf[ret + (src == NULL) + 0] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 ASSERT (buf[ret + (src == NULL) + 1] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 ASSERT (buf[ret + (src == NULL) + 2] == '_');
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 break;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 default:
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 return 1;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 return 0;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 return 1;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 }