[CRT_APITEST] Add testcase for mbtowc() (#2652)

This commit is contained in:
Bișoc George 2020-04-26 12:18:41 +02:00 committed by GitHub
parent ab4b001e94
commit 07640a9a21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 2 deletions

View file

@ -425,7 +425,7 @@ list(APPEND SOURCE_CRTDLL
# malloc.c
# mblen.c
mbstowcs.c
# mbtowc.c
mbtowc.c
# memchr.c
# memcmp.c
# memcpy.c

View file

@ -0,0 +1,61 @@
/*
* PROJECT: ReactOS API tests
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Tests for mbtowc
* COPYRIGHT: Copyright 2020 Bișoc George <fraizeraust99 at gmail dot com>
*/
#include <apitest.h>
#include <apitest_guard.h>
#define WIN32_NO_STATUS
#include <stdio.h>
#include <stdlib.h>
START_TEST(mbtowc)
{
int Length;
wchar_t BufferDest[3];
char *ch;
ch = AllocateGuarded(sizeof(ch));
if (!ch)
{
skip("Buffer allocation failed!\n");
return;
}
/* Assign a character for tests */
*ch = 'A';
/* Everything is NULL */
Length = mbtowc(NULL, NULL, 0);
ok(Length == 0, "Expected 0 characters to be converted as everything is NULL but got %u.\n", Length);
/* Don't examine the number of bytes pointed by multibyte parameter */
Length = mbtowc(BufferDest, ch, 0);
ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
/* Wide character argument is invalid */
Length = mbtowc(NULL, ch, 0);
ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
/* The multibyte argument is invalid */
Length = mbtowc(BufferDest, NULL, 0);
ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
/* The multibyte argument is invalid but count number for examination is correct */
Length = mbtowc(BufferDest, NULL, MB_CUR_MAX);
ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
/* Don't give the output but the count character inspection argument is valid */
Length = mbtowc(NULL, ch, MB_CUR_MAX);
ok(Length == 1, "The number of bytes to check should be 1 but got %u.\n", Length);
/* Convert the character and validate the output that we should get */
Length = mbtowc(BufferDest, ch, MB_CUR_MAX);
ok(Length == 1, "Expected 1 character to be converted but got %u.\n", Length);
ok_int(BufferDest[0], L'A');
FreeGuarded(ch);
}

View file

@ -1119,7 +1119,7 @@ list(APPEND SOURCE_MSVCRT
# mbsrtowcs_s
mbstowcs.c
# mbstowcs_s Not exported in 2k3 Sp1
# mbtowc.c
mbtowc.c
# memchr.c
# memcmp.c
# memcpy.c

View file

@ -72,6 +72,7 @@ list(APPEND SOURCE_NTDLL
# labs.c
# log.c
mbstowcs.c
mbtowc.c
# memchr.c
# memcmp.c
# memcpy == memmove

View file

@ -17,6 +17,7 @@ extern void func__snwprintf(void);
extern void func__vsnprintf(void);
extern void func__vsnwprintf(void);
extern void func_mbstowcs(void);
extern void func_mbtowc(void);
extern void func_sprintf(void);
extern void func_strcpy(void);
extern void func_strlen(void);
@ -35,6 +36,7 @@ const struct test winetest_testlist[] =
{ "_vsnprintf", func__vsnprintf },
{ "_vsnwprintf", func__vsnwprintf },
{ "mbstowcs", func_mbstowcs },
{ "mbtowc", func_mbtowc },
{ "_snprintf", func__snprintf },
{ "_snwprintf", func__snwprintf },
{ "sprintf", func_sprintf },