ReactOS  0.4.13-dev-100-gc8611ae
wcstombs_s.c File Reference
#include <apitest.h>
#include <stdio.h>
#include <stdlib.h>
#include <specstrings.h>
Include dependency graph for wcstombs_s.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define ok_errno(x)   ok_hex(errno, (x))
 
#define ok_char(x, y)   ok_int((unsigned)(unsigned char)(x),(unsigned)(unsigned char)(y))
 
#define ok_wchar(x, y)   ok_int((unsigned)(unsigned short)(x),(unsigned)(unsigned short)(y))
 

Functions

_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)
 
 START_TEST (wcstombs_s)
 

Macro Definition Documentation

◆ ok_char

#define ok_char (   x,
  y 
)    ok_int((unsigned)(unsigned char)(x),(unsigned)(unsigned char)(y))

Definition at line 17 of file wcstombs_s.c.

◆ ok_errno

#define ok_errno (   x)    ok_hex(errno, (x))

Definition at line 14 of file wcstombs_s.c.

◆ ok_wchar

#define ok_wchar (   x,
  y 
)    ok_int((unsigned)(unsigned short)(x),(unsigned)(unsigned short)(y))

Definition at line 18 of file wcstombs_s.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file wcstombs_s.c.

Function Documentation

◆ START_TEST()

START_TEST ( wcstombs_s  )

Definition at line 33 of file wcstombs_s.c.

34 {
35  errno_t ret;
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);
67  ok_long(ret, ERANGE);
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);
86  ok_long(ret, ERANGE);
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);
98  ok_long(ret, EINVAL);
100 
101  *_errno() = 0;
102  cchConverted = 0xf00bac;
103  ret = wcstombs_s(&cchConverted, 0, 0, 0, 0);
104  ok_long(ret, EINVAL);
105  ok_size_t(cchConverted, 0);
106  ok_errno(EINVAL);
107 
108  *_errno() = 0;
109  mbsbuffer[0] = L'x';
110  ret = wcstombs_s(0, mbsbuffer, 0, 0, 0);
111  ok_long(ret, EINVAL);
112  ok_char(mbsbuffer[0], L'x');
113  ok_errno(EINVAL);
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);
122  ok_long(ret, EINVAL);
123  ok_errno(EINVAL);
124 
125  *_errno() = 0;
126  cchConverted = 0xf00bac;
127  ret = wcstombs_s(&cchConverted, 0, 10, L"hallo", 5);
128  ok_long(ret, EINVAL);
129  ok_size_t(cchConverted, 0xf00bac);
130  ok_errno(EINVAL);
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);
142  ok_long(ret, EINVAL);
143  ok_size_t(cchConverted, 0);
144  ok_errno(EINVAL);
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 ok_str(x, y)
Definition: sprintf.c:18
Definition: arc.h:39
#define STRUNCATE
Definition: errno.h:66
_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)
int errno_t
Definition: crtdefs.h:353
#define _TRUNCATE
Definition: crtdefs.h:241
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define ok_wchar(x, y)
Definition: wcstombs_s.c:18
#define ERANGE
Definition: acclib.h:92
#define ok_errno(x)
Definition: wcstombs_s.c:14
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define ok_size_t(expression, result)
Definition: test.h:780
#define ok_long(expression, result)
Definition: test.h:798
#define ok_char(x, y)
Definition: wcstombs_s.c:17

◆ wcstombs_s()

_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 
)

Referenced by START_TEST().