ReactOS 0.4.16-dev-1946-g52006dd
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
 
#define wctomb   p_wctomb
 

Typedefs

typedef int(__cdeclPFN_wctomb) (char *mbchar, wchar_t wchar)
 

Functions

static BOOL Init (void)
 
 START_TEST (wctomb)
 

Variables

static PFN_wctomb p_wctomb
 

Macro Definition Documentation

◆ todo_static

#define todo_static

Definition at line 20 of file wctomb.c.

◆ wctomb

#define wctomb   p_wctomb

Definition at line 31 of file wctomb.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file wctomb.c.

Typedef Documentation

◆ PFN_wctomb

typedef int(__cdecl * PFN_wctomb) (char *mbchar, wchar_t wchar)

Definition at line 21 of file wctomb.c.

Function Documentation

◆ Init()

static BOOL Init ( void  )
static

Definition at line 24 of file wctomb.c.

25{
28 ok(p_wctomb != NULL, "Failed to load wctomb from %s\n", TEST_DLL_NAME);
29 return (p_wctomb != NULL);
30}
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static PFN_wctomb p_wctomb
Definition: wctomb.c:22
int(__cdecl * PFN_wctomb)(char *mbchar, wchar_t wchar)
Definition: wctomb.c:21
#define TEST_DLL_NAME
Definition: wsprintf.c:3
static PVOID hdll
Definition: shimdbg.c:126

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( wctomb  )

Definition at line 34 of file wctomb.c.

35{
36 int Length;
37 char *chDest;
38 char *loc;
39 unsigned int codepage = ___lc_codepage_func();
40 wchar_t wchSrc[2] = {L'R', 0414}; // 0414 corresponds to a Russian character in Windows-1251
41
42#ifndef TEST_STATIC_CRT
43 if (!Init())
44 {
45 skip("Skipping tests, because wctomb is not available\n");
46 return;
47 }
48#endif
49
50 chDest = AllocateGuarded(sizeof(*chDest));
51 if (!chDest)
52 {
53 skip("Buffer allocation failed!\n");
54 return;
55 }
56
57 /* Output the current locale of the system and codepage for comparison between ReactOS and Windows */
58 loc = setlocale(LC_ALL, NULL);
59 printf("The current codepage of your system tested is (%u) and locale (%s).\n\n", codepage, loc);
60
61 /* Do not give output to the caller */
62 Length = wctomb(NULL, 0);
63 todo_static ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
64
65 /* Do the same but expect a valid wide character argument this time */
66 Length = wctomb(NULL, wchSrc[0]);
67 todo_static ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
68
69 /* Don't return anything to the output even if conversion is impossible */
70 Length = wctomb(NULL, wchSrc[1]);
71 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);
72 todo_static ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
73
74 /* Attempt to convert a character not possible in current locale */
75 Length = wctomb(chDest, wchSrc[1]);
76 todo_static ok(Length == -1, "The conversion is not possible in current locale but got %d as returned value.\n", Length);
77 todo_static ok(errno == EILSEQ, "EILSEQ is expected in an illegal sequence conversion but got %d.\n", errno);
78
79 /* Return a null wide character to the destination argument */
80 Length = wctomb(chDest, 0);
81 ok(Length == 1, "Expected one character to be converted (the null character) but got %d.\n", Length);
82 ok_int(chDest[0], '\0');
83
84 /* Get the converted output and validate what we should get */
85 Length = wctomb(chDest, wchSrc[0]);
86 ok(Length == 1, "Expected one character to be converted but got %d.\n", Length);
87 ok_int(chDest[0], 'R');
88
89 FreeGuarded(chDest);
90}
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
#define skip(...)
Definition: atltest.h:64
#define ok_int(expression, result)
Definition: atltest.h:134
#define L(x)
Definition: resources.c:13
#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 wctomb
Definition: wctomb.c:31
static BOOL Init(void)
Definition: wctomb.c:24
#define todo_static
Definition: wctomb.c:20
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define errno
Definition: errno.h:18
#define EILSEQ
Definition: errno.h:109
#define setlocale(n, s)
Definition: locale.h:46
int codepage
Definition: win_iconv.c:156

Variable Documentation

◆ p_wctomb

PFN_wctomb p_wctomb
static

Definition at line 22 of file wctomb.c.

Referenced by Init().