annotate tests/test-wcsrtombs.c @ 40196:e63f5d3edab5

relocatable-prog: Update documentation. * doc/relocatable-maint.texi (Supporting Relocation): Update to match the recent changes.
author Bruno Haible <bruno@clisp.org>
date Sun, 24 Feb 2019 01:49:15 +0100
parents b06060465f09
children
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.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2008-2019 Free Software Foundation, Inc.
10942
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
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
10942
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
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
23 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
24 SIGNATURE_CHECK (wcsrtombs, size_t, (char *, wchar_t const **, size_t,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
25 mbstate_t *));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
26
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <locale.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <stdlib.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <string.h>
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
31 #include "macros.h"
10942
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 int
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 main (int argc, char *argv[])
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 /* configure should already have checked that the locale is supported. */
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 if (setlocale (LC_ALL, "") == NULL)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 return 1;
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 if (argc > 1)
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 wchar_t input[10];
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 size_t n;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 const wchar_t *src;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 #define BUFSIZE 20
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 char buf[BUFSIZE];
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 size_t ret;
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 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
50 size_t i;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
51 for (i = 0; i < BUFSIZE; i++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
52 buf[i] = '_';
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 }
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 switch (argv[1][0])
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
56 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
57 case '1':
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
58 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
59 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
60 const char original[] = "B\374\337er"; /* "Büßer" */
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
62 ret = mbstowcs (input, original, 10);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
63 ASSERT (ret == 5);
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
65 for (n = 0; n < 10; n++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
66 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
67 src = input;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
68 ret = wcsrtombs (NULL, &src, n, NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
69 ASSERT (ret == 5);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
70 ASSERT (src == input);
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
72 src = input;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
73 ret = wcsrtombs (buf, &src, n, NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
74 ASSERT (ret == (n <= 5 ? n : 5));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
75 ASSERT (src == (n <= 5 ? input + n : NULL));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
76 ASSERT (memcmp (buf, original, ret) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
77 if (src == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
78 ASSERT (buf[ret] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
79 ASSERT (buf[ret + (src == NULL) + 0] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
80 ASSERT (buf[ret + (src == NULL) + 1] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
81 ASSERT (buf[ret + (src == NULL) + 2] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
82 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
83 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
84 break;
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
86 case '2':
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
87 /* Locale encoding is UTF-8. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
88 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
89 const char original[] = "B\303\274\303\237er"; /* "Büßer" */
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
91 ret = mbstowcs (input, original, 10);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
92 ASSERT (ret == 5);
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
94 for (n = 0; n < 10; n++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
95 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
96 src = input;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
97 ret = wcsrtombs (NULL, &src, n, NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
98 ASSERT (ret == 7);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
99 ASSERT (src == input);
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
101 src = input;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
102 ret = wcsrtombs (buf, &src, n, NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
103 ASSERT (ret == (n < 1 ? n :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
104 n < 3 ? 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
105 n < 5 ? 3 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
106 n <= 7 ? n : 7));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
107 ASSERT (src == (n < 1 ? input + n :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
108 n < 3 ? input + 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
109 n < 5 ? input + 2 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
110 n <= 7 ? input + (n - 2) : NULL));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
111 ASSERT (memcmp (buf, original, ret) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
112 if (src == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
113 ASSERT (buf[ret] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
114 ASSERT (buf[ret + (src == NULL) + 0] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
115 ASSERT (buf[ret + (src == NULL) + 1] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
116 ASSERT (buf[ret + (src == NULL) + 2] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
117 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
118 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
119 break;
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
121 case '3':
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
122 /* Locale encoding is EUC-JP. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
123 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
124 const char original[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
126 ret = mbstowcs (input, original, 10);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
127 ASSERT (ret == 5);
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
129 for (n = 0; n < 10; n++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
130 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
131 src = input;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
132 ret = wcsrtombs (NULL, &src, n, NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
133 ASSERT (ret == 8);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
134 ASSERT (src == input);
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
136 src = input;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
137 ret = wcsrtombs (buf, &src, n, NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
138 ASSERT (ret == (n < 1 ? n :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
139 n < 3 ? 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
140 n < 5 ? 3 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
141 n < 7 ? 5 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
142 n <= 8 ? n : 8));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
143 ASSERT (src == (n < 1 ? input + n :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
144 n < 3 ? input + 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
145 n < 5 ? input + 2 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
146 n < 7 ? input + 3 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
147 n <= 8 ? input + (n - 3) : NULL));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
148 ASSERT (memcmp (buf, original, ret) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
149 if (src == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
150 ASSERT (buf[ret] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
151 ASSERT (buf[ret + (src == NULL) + 0] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
152 ASSERT (buf[ret + (src == NULL) + 1] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
153 ASSERT (buf[ret + (src == NULL) + 2] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
154 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
155 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
156 break;
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
159 case '4':
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
160 /* Locale encoding is GB18030. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
161 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
162 const char original[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
164 ret = mbstowcs (input, original, 10);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
165 ASSERT (ret == 5);
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
167 for (n = 0; n < 10; n++)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
168 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
169 src = input;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
170 ret = wcsrtombs (NULL, &src, n, NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
171 ASSERT (ret == 9);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
172 ASSERT (src == input);
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
174 src = input;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
175 ret = wcsrtombs (buf, &src, n, NULL);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
176 ASSERT (ret == (n < 1 ? n :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
177 n < 3 ? 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
178 n < 7 ? 3 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
179 n <= 9 ? n : 9));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
180 ASSERT (src == (n < 1 ? input + n :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
181 n < 3 ? input + 1 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
182 n < 7 ? input + 2 :
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
183 n <= 9 ? input + (n - 4) : NULL));
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
184 ASSERT (memcmp (buf, original, ret) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
185 if (src == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
186 ASSERT (buf[ret] == '\0');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
187 ASSERT (buf[ret + (src == NULL) + 0] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
188 ASSERT (buf[ret + (src == NULL) + 1] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
189 ASSERT (buf[ret + (src == NULL) + 2] == '_');
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
190 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
191 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
192 break;
10942
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
194 default:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
195 return 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10942
diff changeset
196 }
10942
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 return 0;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 }
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 return 1;
d3a1e8911dfa Tests for module 'wcsrtombs'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 }