ReactOS 0.4.16-dev-336-gb667d82
wctomb.c File Reference
#include <apitest.h>
#include <apitest_guard.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <locale.h>
Include dependency graph for wctomb.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define todo_static
 

Functions

 START_TEST (wctomb)
 

Macro Definition Documentation

◆ todo_static

#define todo_static

Definition at line 20 of file wctomb.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file wctomb.c.

Function Documentation

◆ START_TEST()

START_TEST ( wctomb  )

Definition at line 23 of file wctomb.c.

24{
25 int Length;
26 char *chDest;
27 char *loc;
28 unsigned int codepage = ___lc_codepage_func();
29 wchar_t wchSrc[2] = {L'R', 0414}; // 0414 corresponds to a Russian character in Windows-1251
30
31 chDest = AllocateGuarded(sizeof(*chDest));
32 if (!chDest)
33 {
34 skip("Buffer allocation failed!\n");
35 return;
36 }
37
38 /* Output the current locale of the system and codepage for comparison between ReactOS and Windows */
39 loc = setlocale(LC_ALL, NULL);
40 printf("The current codepage of your system tested is (%u) and locale (%s).\n\n", codepage, loc);
41
42 /* Do not give output to the caller */
43 Length = wctomb(NULL, 0);
44 todo_static ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
45
46 /* Do the same but expect a valid wide character argument this time */
47 Length = wctomb(NULL, wchSrc[0]);
48 todo_static ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
49
50 /* Don't return anything to the output even if conversion is impossible */
51 Length = wctomb(NULL, wchSrc[1]);
52 ok(errno == 0, "The error number (errno) should be 0 even though an invalid character in current locale is given but got %d.\n", errno);
53 todo_static ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
54
55 /* Attempt to convert a character not possible in current locale */
56 Length = wctomb(chDest, wchSrc[1]);
57 todo_static ok(Length == -1, "The conversion is not possible in current locale but got %d as returned value.\n", Length);
58 todo_static ok(errno == EILSEQ, "EILSEQ is expected in an illegal sequence conversion but got %d.\n", errno);
59
60 /* Return a null wide character to the destination argument */
61 Length = wctomb(chDest, 0);
62 ok(Length == 1, "Expected one character to be converted (the null character) but got %d.\n", Length);
63 ok_int(chDest[0], '\0');
64
65 /* Get the converted output and validate what we should get */
66 Length = wctomb(chDest, wchSrc[0]);
67 ok(Length == 1, "Expected one character to be converted but got %d.\n", Length);
68 ok_int(chDest[0], 'R');
69
70 FreeGuarded(chDest);
71}
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define ok_int(expression, result)
Definition: atltest.h:134
#define NULL
Definition: types.h:112
#define printf
Definition: freeldr.h:97
#define LC_ALL
Definition: locale.h:17
_CRTIMP unsigned int __cdecl ___lc_codepage_func(void)
Definition: locale.c:629
#define todo_static
Definition: wctomb.c:20
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
#define errno
Definition: errno.h:18
#define EILSEQ
Definition: errno.h:109
#define setlocale(n, s)
Definition: locale.h:46
#define wctomb(cp, wc)
Definition: wchar.h:161
int codepage
Definition: win_iconv.c:156