ReactOS  0.4.15-dev-1207-g698a8e6
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
 

Functions

unsigned int cdecl ___lc_codepage_func (void)
 
 START_TEST (wctomb)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file wctomb.c.

Function Documentation

◆ ___lc_codepage_func()

unsigned int cdecl ___lc_codepage_func ( void  )

Definition at line 627 of file locale.c.

628 {
629  return __lc_codepage;
630 }
unsigned int __lc_codepage
Definition: locale.c:34

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( wctomb  )

Definition at line 19 of file wctomb.c.

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