ReactOS  0.4.13-dev-52-g0efcfec
mbstowcs_s.c File Reference
#include <apitest.h>
#include <stdio.h>
#include <stdlib.h>
#include <specstrings.h>
Include dependency graph for mbstowcs_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_wchar(x, y)   ok_int(x,y)
 
#define MSVCRT_INVALID_PMT(x)   _invalid_parameterA(#x, __FUNCTION__, __FILE__, __LINE__, 0)
 
#define MSVCRT_CHECK_PMT(x)   ((x) || (MSVCRT_INVALID_PMT(x),0))
 

Functions

errno_t mbstowcs_s (size_t *cchConverted, wchar_t *widechar, size_t charoutct, const char *multibyte, size_t count)
 
void _test_invalid_parameter (const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned int line, uintptr_t pReserved)
 
 START_TEST (mbstowcs_s)
 

Variables

wchar_t g_expression [64]
 
wchar_t g_function [64]
 
wchar_t g_file [128]
 
unsigned int g_line
 
uintptr_t g_pReserved
 

Macro Definition Documentation

◆ MSVCRT_CHECK_PMT

#define MSVCRT_CHECK_PMT (   x)    ((x) || (MSVCRT_INVALID_PMT(x),0))

Definition at line 26 of file mbstowcs_s.c.

◆ MSVCRT_INVALID_PMT

#define MSVCRT_INVALID_PMT (   x)    _invalid_parameterA(#x, __FUNCTION__, __FILE__, __LINE__, 0)

Definition at line 25 of file mbstowcs_s.c.

◆ ok_errno

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

Definition at line 14 of file mbstowcs_s.c.

◆ ok_wchar

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

Definition at line 15 of file mbstowcs_s.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file mbstowcs_s.c.

Function Documentation

◆ _test_invalid_parameter()

void _test_invalid_parameter ( const wchar_t expression,
const wchar_t function,
const wchar_t file,
unsigned int  line,
uintptr_t  pReserved 
)

Definition at line 35 of file mbstowcs_s.c.

41 {
42  wcsncpy(g_expression, expression, sizeof(g_expression) / sizeof(wchar_t));
43  wcsncpy(g_function, function, sizeof(g_function) / sizeof(wchar_t));
44  wcsncpy(g_file, file, sizeof(g_file) / sizeof(wchar_t));
45  g_line = line;
46  g_pReserved = pReserved;
47 }
uintptr_t g_pReserved
Definition: mbstowcs_s.c:32
wchar_t g_expression[64]
Definition: mbstowcs_s.c:28
char line[200]
Definition: main.c:97
wchar_t g_file[128]
Definition: mbstowcs_s.c:30
wchar_t g_function[64]
Definition: mbstowcs_s.c:29
unsigned int g_line
Definition: mbstowcs_s.c:31
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
Definition: fci.c:126

◆ mbstowcs_s()

errno_t mbstowcs_s ( size_t cchConverted,
wchar_t widechar,
size_t  charoutct,
const char multibyte,
size_t  count 
)

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( mbstowcs_s  )

Definition at line 49 of file mbstowcs_s.c.

50 {
51 // _set_invalid_parameter_handler(_test_invalid_parameter);
52 
53  errno_t ret;
54  size_t cchConverted;
55  wchar_t widechar[10];
56 
57  *_errno() = 0;
58  cchConverted = 0xf00bac;
59  widechar[5] = 0xFF;
60  ret = mbstowcs_s(&cchConverted, widechar, 6, "hallo", 5);
61  ok_long(ret, 0);
62  ok_size_t(cchConverted, 6);
63  ok_wchar(widechar[5], 0);
64  ok_wstr(widechar, L"hallo");
65  ok_errno(0);
66 
67  *_errno() = 0;
68  cchConverted = 0xf00bac;
69  widechar[0] = 0xFF;
70  ret = mbstowcs_s(&cchConverted, widechar, 1, "", 0);
71  ok_long(ret, 0);
72  ok_size_t(cchConverted, 1);
73  ok_wchar(widechar[0], 0);
74  ok_errno(0);
75 
76  *_errno() = 0;
77  cchConverted = 0xf00bac;
78  widechar[0] = 0xFF;
79  widechar[1] = 0xFF;
80  widechar[2] = 0xFF;
81  widechar[3] = 0xFF;
82  widechar[4] = 0xFF;
83  widechar[5] = 0xFF;
84  ret = mbstowcs_s(&cchConverted, widechar, 5, "hallo", 5);
85  ok_long(ret, ERANGE);
86  ok_size_t(cchConverted, 0);
87  ok_wchar(widechar[5], 0xFF);
88  ok_wchar(widechar[4], L'o');
89  ok_wchar(widechar[3], L'l');
90  ok_wchar(widechar[2], L'l');
91  ok_wchar(widechar[1], L'a');
92  ok_wchar(widechar[0], 0);
94 
95  *_errno() = 0;
96  cchConverted = 0xf00bac;
97  widechar[0] = 0xFF;
98  widechar[1] = 0xFF;
99  widechar[2] = 0xFF;
100  widechar[3] = 0xFF;
101  widechar[4] = 0xFF;
102  widechar[5] = 0xFF;
103  ret = mbstowcs_s(&cchConverted, widechar, 3, "hallo", 5);
104  ok_long(ret, ERANGE);
105  ok_size_t(cchConverted, 0);
106  ok_wchar(widechar[5], 0xFF);
107  ok_wchar(widechar[4], 0xFF);
108  ok_wchar(widechar[3], 0xFF);
109  ok_wchar(widechar[2], L'l');
110  ok_wchar(widechar[1], L'a');
111  ok_wchar(widechar[0], 0);
112  ok_errno(ERANGE);
113 
114  *_errno() = 0;
115  ret = mbstowcs_s(0, 0, 0, 0, 0);
116  ok_long(ret, EINVAL);
117  ok_errno(EINVAL);
118 
119  *_errno() = 0;
120  cchConverted = 0xf00bac;
121  ret = mbstowcs_s(&cchConverted, 0, 0, 0, 0);
122  ok_long(ret, EINVAL);
123  ok_size_t(cchConverted, 0);
124  ok_errno(EINVAL);
125 
126  *_errno() = 0;
127  widechar[0] = L'x';
128  ret = mbstowcs_s(0, widechar, 0, 0, 0);
129  ok_long(ret, EINVAL);
130  ok_wchar(widechar[0], L'x');
131  ok_errno(EINVAL);
132 
133  *_errno() = 0;
134  ret = mbstowcs_s(0, widechar, 10, "hallo", 5);
135  ok_long(ret, 0);
136  ok_errno(0);
137 
138  *_errno() = 0;
139  ret = mbstowcs_s(0, widechar, 0, "hallo", 5);
140  ok_long(ret, EINVAL);
141  ok_errno(EINVAL);
142 
143  *_errno() = 0;
144  cchConverted = 0xf00bac;
145  ret = mbstowcs_s(&cchConverted, 0, 10, "hallo", 5);
146  ok_long(ret, EINVAL);
147  ok_size_t(cchConverted, 0xf00bac);
148  ok_errno(EINVAL);
149 
150  *_errno() = 0;
151  cchConverted = 0xf00bac;
152  ret = mbstowcs_s(&cchConverted, 0, 0, "hallo", 5);
153  ok_long(ret, 0);
154  ok_size_t(cchConverted, 6);
155  ok_errno(0);
156 
157  *_errno() = 0;
158  cchConverted = 0xf00bac;
159  ret = mbstowcs_s(&cchConverted, widechar, 10, 0, 5);
160  ok_long(ret, EINVAL);
161  ok_size_t(cchConverted, 0);
162  ok_errno(EINVAL);
163 
164  *_errno() = 0;
165  cchConverted = 0xf00bac;
166  ret = mbstowcs_s(&cchConverted, widechar, 10, "hallo", 0);
167  ok_long(ret, 0);
168  ok_size_t(cchConverted, 1);
169  ok_errno(0);
170 
171  *_errno() = 0;
172  cchConverted = 0xf00bac;
173  widechar[0] = 0xABCD;
174  widechar[1] = 0xABCD;
175  widechar[2] = 0xABCD;
176  widechar[3] = 0xABCD;
177  widechar[4] = 0xABCD;
178  widechar[5] = 0xABCD;
179  ret = mbstowcs_s(&cchConverted, widechar, 10, "hallo", 2);
180  ok_long(ret, 0);
181  ok_size_t(cchConverted, 3);
182  ok_wchar(widechar[5], 0xABCD);
183  ok_wchar(widechar[4], 0xABCD);
184  ok_wchar(widechar[3], 0xABCD);
185  ok_wchar(widechar[2], 0);
186  ok_wchar(widechar[1], L'a');
187  ok_wchar(widechar[0], L'h');
188  ok_errno(0);
189 
190  *_errno() = 0;
191  cchConverted = 0xf00bac;
192  ret = mbstowcs_s(&cchConverted, widechar, 10, 0, 0);
193  ok_long(ret, 0);
194  ok_size_t(cchConverted, 1);
195  ok_errno(0);
196 
197  *_errno() = 0;
198  cchConverted = 0xf00bac;
199  ret = mbstowcs_s(&cchConverted, widechar, 10, "hallo", 7);
200  ok_long(ret, 0);
201  ok_size_t(cchConverted, 6);
202  ok_errno(0);
203 
204  *_errno() = 0;
205  cchConverted = 0xf00bac;
206  ret = mbstowcs_s(&cchConverted, 0, 0, "hallo", 7);
207  ok_long(ret, 0);
208  ok_size_t(cchConverted, 6);
209  ok_errno(0);
210 
211  *_errno() = 0;
212  cchConverted = 0xf00bac;
213  widechar[0] = 0xABCD;
214  widechar[1] = 0xABCD;
215  widechar[2] = 0xABCD;
216  widechar[3] = 0xABCD;
217  widechar[4] = 0xABCD;
218  widechar[5] = 0xABCD;
219  ret = mbstowcs_s(&cchConverted, widechar, 5, "hallo", _TRUNCATE);
221  ok_size_t(cchConverted, 5);
222  ok_wchar(widechar[5], 0xABCD);
223  ok_wchar(widechar[4], 0);
224  ok_wchar(widechar[3], L'l');
225  ok_wchar(widechar[2], L'l');
226  ok_wchar(widechar[1], L'a');
227  ok_wchar(widechar[0], L'h');
228  ok_errno(0);
229 
230  *_errno() = 0;
231  cchConverted = 0xf00bac;
232  ret = mbstowcs_s(&cchConverted, widechar, 10, "hallo", -1);
233  ok_long(ret, 0);
234  ok_size_t(cchConverted, 6);
235  ok_errno(0);
236 }
Definition: arc.h:39
#define ok_wchar(x, y)
Definition: mbstowcs_s.c:15
#define STRUNCATE
Definition: errno.h:66
#define ok_errno(x)
Definition: mbstowcs_s.c:14
#define ok_wstr(x, y)
Definition: test.h:795
int errno_t
Definition: crtdefs.h:353
#define _TRUNCATE
Definition: crtdefs.h:241
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
errno_t mbstowcs_s(size_t *cchConverted, wchar_t *widechar, size_t charoutct, const char *multibyte, size_t count)
#define ERANGE
Definition: acclib.h:92
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

Variable Documentation

◆ g_expression

wchar_t g_expression[64]

Definition at line 28 of file mbstowcs_s.c.

Referenced by _test_invalid_parameter().

◆ g_file

wchar_t g_file[128]

Definition at line 30 of file mbstowcs_s.c.

Referenced by _test_invalid_parameter().

◆ g_function

wchar_t g_function[64]

Definition at line 29 of file mbstowcs_s.c.

Referenced by _test_invalid_parameter().

◆ g_line

unsigned int g_line

Definition at line 31 of file mbstowcs_s.c.

Referenced by _test_invalid_parameter().

◆ g_pReserved

uintptr_t g_pReserved

Definition at line 32 of file mbstowcs_s.c.

Referenced by _test_invalid_parameter().