ReactOS 0.4.16-dev-91-g764881a
wcstombs_s.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for wcstombs_s
5 */
6
7#include <apitest.h>
8
9#define WIN32_NO_STATUS
10#include <stdio.h>
11#include <stdlib.h>
12#include <specstrings.h>
13
14#define ok_errno(x) ok_hex(errno, (x))
15
16#undef ok_char
17#define ok_char(x,y) ok_int((unsigned)(unsigned char)(x),(unsigned)(unsigned char)(y))
18#define ok_wchar(x,y) ok_int((unsigned)(unsigned short)(x),(unsigned)(unsigned short)(y))
19
25 _Out_opt_ size_t * pcchConverted,
26 _Out_writes_bytes_to_opt_(cjDstSize, *pcchConverted)
27 char * pmbsDst,
28 _In_ size_t cjDstSize,
29 _In_z_ const wchar_t * pwszSrc,
30 _In_ size_t cjMaxCount);
31
32
34{
36 size_t cchConverted;
37 char mbsbuffer[10];
38
39 *_errno() = 0;
40 cchConverted = 0xf00bac;
41 mbsbuffer[5] = 0xFF;
42 ret = wcstombs_s(&cchConverted, mbsbuffer, 6, L"hallo", 5);
43 ok_long(ret, 0);
44 ok_size_t(cchConverted, 6);
45 ok_char(mbsbuffer[5], 0);
46 ok_str(mbsbuffer, "hallo");
47 ok_errno(0);
48
49 *_errno() = 0;
50 cchConverted = 0xf00bac;
51 mbsbuffer[0] = 0xFF;
52 ret = wcstombs_s(&cchConverted, mbsbuffer, 1, L"", 0);
53 ok_long(ret, 0);
54 ok_size_t(cchConverted, 1);
55 ok_wchar(mbsbuffer[0], 0);
56 ok_errno(0);
57
58 *_errno() = 0;
59 cchConverted = 0xf00bac;
60 mbsbuffer[0] = 0xFF;
61 mbsbuffer[1] = 0xFF;
62 mbsbuffer[2] = 0xFF;
63 mbsbuffer[3] = 0xFF;
64 mbsbuffer[4] = 0xFF;
65 mbsbuffer[5] = 0xFF;
66 ret = wcstombs_s(&cchConverted, mbsbuffer, 5, L"hallo", 5);
68 ok_size_t(cchConverted, 0);
69 ok_char(mbsbuffer[5], 0xFF);
70 ok_char(mbsbuffer[4], L'o');
71 ok_char(mbsbuffer[3], L'l');
72 ok_char(mbsbuffer[2], L'l');
73 ok_char(mbsbuffer[1], L'a');
74 ok_char(mbsbuffer[0], 0);
76
77 *_errno() = 0;
78 cchConverted = 0xf00bac;
79 mbsbuffer[0] = 0xFF;
80 mbsbuffer[1] = 0xFF;
81 mbsbuffer[2] = 0xFF;
82 mbsbuffer[3] = 0xFF;
83 mbsbuffer[4] = 0xFF;
84 mbsbuffer[5] = 0xFF;
85 ret = wcstombs_s(&cchConverted, mbsbuffer, 3, L"hallo", 5);
87 ok_size_t(cchConverted, 0);
88 ok_char(mbsbuffer[5], 0xFF);
89 ok_char(mbsbuffer[4], 0xFF);
90 ok_char(mbsbuffer[3], 0xFF);
91 ok_char(mbsbuffer[2], L'l');
92 ok_char(mbsbuffer[1], L'a');
93 ok_char(mbsbuffer[0], 0);
95
96 *_errno() = 0;
97 ret = wcstombs_s(0, 0, 0, 0, 0);
100
101 *_errno() = 0;
102 cchConverted = 0xf00bac;
103 ret = wcstombs_s(&cchConverted, 0, 0, 0, 0);
105 ok_size_t(cchConverted, 0);
107
108 *_errno() = 0;
109 mbsbuffer[0] = L'x';
110 ret = wcstombs_s(0, mbsbuffer, 0, 0, 0);
112 ok_char(mbsbuffer[0], L'x');
114
115 *_errno() = 0;
116 ret = wcstombs_s(0, mbsbuffer, 10, L"hallo", 5);
117 ok_long(ret, 0);
118 ok_errno(0);
119
120 *_errno() = 0;
121 ret = wcstombs_s(0, mbsbuffer, 0, L"hallo", 5);
124
125 *_errno() = 0;
126 cchConverted = 0xf00bac;
127 ret = wcstombs_s(&cchConverted, 0, 10, L"hallo", 5);
129 ok_size_t(cchConverted, 0xf00bac);
131
132 *_errno() = 0;
133 cchConverted = 0xf00bac;
134 ret = wcstombs_s(&cchConverted, 0, 0, L"hallo", 5);
135 ok_long(ret, 0);
136 ok_size_t(cchConverted, 6);
137 ok_errno(0);
138
139 *_errno() = 0;
140 cchConverted = 0xf00bac;
141 ret = wcstombs_s(&cchConverted, mbsbuffer, 10, 0, 5);
143 ok_size_t(cchConverted, 0);
145
146 *_errno() = 0;
147 cchConverted = 0xf00bac;
148 ret = wcstombs_s(&cchConverted, mbsbuffer, 10, L"hallo", 0);
149 ok_long(ret, 0);
150 ok_size_t(cchConverted, 1);
151 ok_errno(0);
152
153 *_errno() = 0;
154 cchConverted = 0xf00bac;
155 mbsbuffer[0] = 0xAB;
156 mbsbuffer[1] = 0xCD;
157 mbsbuffer[2] = 0xAB;
158 mbsbuffer[3] = 0xCD;
159 mbsbuffer[4] = 0xAB;
160 mbsbuffer[5] = 0xCD;
161 ret = wcstombs_s(&cchConverted, mbsbuffer, 10, L"hallo", 2);
162 ok_long(ret, 0);
163 ok_size_t(cchConverted, 3);
164 ok_char(mbsbuffer[5], 0xCD);
165 ok_char(mbsbuffer[4], 0xAB);
166 ok_char(mbsbuffer[3], 0xCD);
167 ok_char(mbsbuffer[2], 0);
168 ok_char(mbsbuffer[1], L'a');
169 ok_char(mbsbuffer[0], L'h');
170 ok_errno(0);
171
172 *_errno() = 0;
173 cchConverted = 0xf00bac;
174 ret = wcstombs_s(&cchConverted, mbsbuffer, 10, 0, 0);
175 ok_long(ret, 0);
176 ok_size_t(cchConverted, 1);
177 ok_errno(0);
178
179 *_errno() = 0;
180 cchConverted = 0xf00bac;
181 ret = wcstombs_s(&cchConverted, mbsbuffer, 10, L"hallo", 7);
182 ok_long(ret, 0);
183 ok_size_t(cchConverted, 6);
184 ok_errno(0);
185
186 *_errno() = 0;
187 cchConverted = 0xf00bac;
188 ret = wcstombs_s(&cchConverted, 0, 0, L"hallo", 7);
189 ok_long(ret, 0);
190 ok_size_t(cchConverted, 6);
191 ok_errno(0);
192
193 *_errno() = 0;
194 cchConverted = 0xf00bac;
195 mbsbuffer[0] = 0xAB;
196 mbsbuffer[1] = 0xCD;
197 mbsbuffer[2] = 0xAB;
198 mbsbuffer[3] = 0xCD;
199 mbsbuffer[4] = 0xAB;
200 mbsbuffer[5] = 0xCD;
201 ret = wcstombs_s(&cchConverted, mbsbuffer, 5, L"hallo", _TRUNCATE);
203 ok_size_t(cchConverted, 5);
204 ok_char(mbsbuffer[5], 0xCD);
205 ok_char(mbsbuffer[4], 0);
206 ok_char(mbsbuffer[3], L'l');
207 ok_char(mbsbuffer[2], L'l');
208 ok_char(mbsbuffer[1], L'a');
209 ok_char(mbsbuffer[0], L'h');
210 ok_errno(0);
211
212 *_errno() = 0;
213 cchConverted = 0xf00bac;
214 ret = wcstombs_s(&cchConverted, mbsbuffer, 10, L"hallo", -1);
215 ok_long(ret, 0);
216 ok_size_t(cchConverted, 6);
217 ok_errno(0);
218
219}
#define EINVAL
Definition: acclib.h:90
#define ERANGE
Definition: acclib.h:92
#define __cdecl
Definition: accygwin.h:79
#define ok_long(expression, result)
Definition: atltest.h:133
#define ok_str(x, y)
Definition: atltest.h:127
#define ok_size_t(expression, result)
Definition: atltest.h:115
#define START_TEST(x)
Definition: atltest.h:75
#define _TRUNCATE
Definition: crtdefs.h:262
#define _Check_return_wat_
Definition: crtdefs.h:462
#define _CRTIMP
Definition: crtdefs.h:72
int errno_t
Definition: crtdefs.h:374
#define ok_errno(x)
Definition: wcstombs_s.c:14
_Check_return_wat_ _CRTIMP errno_t __cdecl wcstombs_s(_Out_opt_ size_t *pcchConverted, _Out_writes_bytes_to_opt_(cjDstSize, *pcchConverted) char *pmbsDst, _In_ size_t cjDstSize, _In_z_ const wchar_t *pwszSrc, _In_ size_t cjMaxCount)
#define ok_wchar(x, y)
Definition: wcstombs_s.c:18
#define ok_char(x, y)
Definition: wcstombs_s.c:17
#define _Out_opt_
Definition: ms_sal.h:346
#define _In_z_
Definition: ms_sal.h:313
#define _Out_writes_bytes_to_opt_(size, count)
Definition: ms_sal.h:361
#define _In_
Definition: ms_sal.h:308
#define L(x)
Definition: ntvdm.h:50
#define STRUNCATE
Definition: errno.h:110
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:17
int ret