ReactOS 0.4.15-dev-5669-g09dde2c
wctomb.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for wctomb
5 * COPYRIGHT: Copyright 2020 George Bișoc <george.bisoc@reactos.org>
6 */
7
8#include <apitest.h>
9#include <apitest_guard.h>
10
11#define WIN32_NO_STATUS
12#include <stdio.h>
13#include <stdlib.h>
14#include <errno.h>
15#include <locale.h>
16
18{
19 int Length;
20 char *chDest;
21 char *loc;
22 unsigned int codepage = ___lc_codepage_func();
23 wchar_t wchSrc[2] = {L'R', 0414}; // 0414 corresponds to a Russian character in Windows-1251
24
25 chDest = AllocateGuarded(sizeof(*chDest));
26 if (!chDest)
27 {
28 skip("Buffer allocation failed!\n");
29 return;
30 }
31
32 /* Output the current locale of the system and codepage for comparison between ReactOS and Windows */
33 loc = setlocale(LC_ALL, NULL);
34 printf("The current codepage of your system tested is (%u) and locale (%s).\n\n", codepage, loc);
35
36 /* Do not give output to the caller */
37 Length = wctomb(NULL, 0);
38 ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
39
40 /* Do the same but expect a valid wide character argument this time */
41 Length = wctomb(NULL, wchSrc[0]);
42 ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
43
44 /* Don't return anything to the output even if conversion is impossible */
45 Length = wctomb(NULL, wchSrc[1]);
46 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);
47 ok(Length == 0, "Expected no characters to be converted (because the output argument is refused) but got %d.\n", Length);
48
49 /* Attempt to convert a character not possible in current locale */
50 Length = wctomb(chDest, wchSrc[1]);
51 ok(Length == -1, "The conversion is not possible in current locale but got %d as returned value.\n", Length);
52 ok(errno == EILSEQ, "EILSEQ is expected in an illegal sequence conversion but got %d.\n", errno);
53
54 /* Return a null wide character to the destination argument */
55 Length = wctomb(chDest, 0);
56 ok(Length == 1, "Expected one character to be converted (the null character) but got %d.\n", Length);
57 ok_int(chDest[0], '\0');
58
59 /* Get the converted output and validate what we should get */
60 Length = wctomb(chDest, wchSrc[0]);
61 ok(Length == 1, "Expected one character to be converted but got %d.\n", Length);
62 ok_int(chDest[0], 'R');
63
64 FreeGuarded(chDest);
65}
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 START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define NULL
Definition: types.h:112
#define printf
Definition: freeldr.h:94
#define LC_ALL
Definition: locale.h:17
_CRTIMP unsigned int __cdecl ___lc_codepage_func(void)
Definition: locale.c:627
_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