ReactOS  0.4.15-dev-2344-g8ddbfde
mbtowc.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 mbtowc
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 
16 {
17  int Length;
18  wchar_t BufferDest[3];
19  char *ch;
20 
21  ch = AllocateGuarded(sizeof(ch));
22  if (!ch)
23  {
24  skip("Buffer allocation failed!\n");
25  return;
26  }
27 
28  /* Assign a character for tests */
29  *ch = 'A';
30 
31  /* Everything is NULL */
32  Length = mbtowc(NULL, NULL, 0);
33  ok(Length == 0, "Expected 0 characters to be converted as everything is NULL but got %u.\n", Length);
34 
35  /* Don't examine the number of bytes pointed by multibyte parameter */
36  Length = mbtowc(BufferDest, ch, 0);
37  ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
38 
39  /* Wide character argument is invalid */
40  Length = mbtowc(NULL, ch, 0);
41  ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
42 
43  /* The multibyte argument is invalid */
44  Length = mbtowc(BufferDest, NULL, 0);
45  ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
46 
47  /* The multibyte argument is invalid but count number for examination is correct */
48  Length = mbtowc(BufferDest, NULL, MB_CUR_MAX);
49  ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
50 
51  /* Don't give the output but the count character inspection argument is valid */
52  Length = mbtowc(NULL, ch, MB_CUR_MAX);
53  ok(Length == 1, "The number of bytes to check should be 1 but got %u.\n", Length);
54 
55  /* Convert the character and validate the output that we should get */
56  Length = mbtowc(BufferDest, ch, MB_CUR_MAX);
57  ok(Length == 1, "Expected 1 character to be converted but got %u.\n", Length);
58  ok_int(BufferDest[0], L'A');
59 
60  FreeGuarded(ch);
61 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
START_TEST(mbtowc)
Definition: mbtowc.c:15
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
#define ok_int(expression, result)
Definition: atltest.h:134
int CDECL mbtowc(wchar_t *dst, const char *str, size_t n)
Definition: mbtowc.c:53
static const WCHAR L[]
Definition: oid.c:1250
#define MB_CUR_MAX
Definition: ctype.h:624
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64