107640a9aSBișoc George /*
207640a9aSBișoc George * PROJECT: ReactOS API tests
307640a9aSBișoc George * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
407640a9aSBișoc George * PURPOSE: Tests for mbtowc
5*b00ecdcaSGeorge Bișoc * COPYRIGHT: Copyright 2020 George Bișoc <george.bisoc@reactos.org>
607640a9aSBișoc George */
707640a9aSBișoc George
807640a9aSBișoc George #include <apitest.h>
907640a9aSBișoc George #include <apitest_guard.h>
1007640a9aSBișoc George
1107640a9aSBișoc George #define WIN32_NO_STATUS
1207640a9aSBișoc George #include <stdio.h>
1307640a9aSBișoc George #include <stdlib.h>
1407640a9aSBișoc George
START_TEST(mbtowc)1507640a9aSBișoc George START_TEST(mbtowc)
1607640a9aSBișoc George {
1707640a9aSBișoc George int Length;
1807640a9aSBișoc George wchar_t BufferDest[3];
1907640a9aSBișoc George char *ch;
2007640a9aSBișoc George
2107640a9aSBișoc George ch = AllocateGuarded(sizeof(ch));
2207640a9aSBișoc George if (!ch)
2307640a9aSBișoc George {
2407640a9aSBișoc George skip("Buffer allocation failed!\n");
2507640a9aSBișoc George return;
2607640a9aSBișoc George }
2707640a9aSBișoc George
2807640a9aSBișoc George /* Assign a character for tests */
2907640a9aSBișoc George *ch = 'A';
3007640a9aSBișoc George
3107640a9aSBișoc George /* Everything is NULL */
3207640a9aSBișoc George Length = mbtowc(NULL, NULL, 0);
3307640a9aSBișoc George ok(Length == 0, "Expected 0 characters to be converted as everything is NULL but got %u.\n", Length);
3407640a9aSBișoc George
3507640a9aSBișoc George /* Don't examine the number of bytes pointed by multibyte parameter */
3607640a9aSBișoc George Length = mbtowc(BufferDest, ch, 0);
3707640a9aSBișoc George ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
3807640a9aSBișoc George
3907640a9aSBișoc George /* Wide character argument is invalid */
4007640a9aSBișoc George Length = mbtowc(NULL, ch, 0);
4107640a9aSBișoc George ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
4207640a9aSBișoc George
4307640a9aSBișoc George /* The multibyte argument is invalid */
4407640a9aSBișoc George Length = mbtowc(BufferDest, NULL, 0);
4507640a9aSBișoc George ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
4607640a9aSBișoc George
4707640a9aSBișoc George /* The multibyte argument is invalid but count number for examination is correct */
4807640a9aSBișoc George Length = mbtowc(BufferDest, NULL, MB_CUR_MAX);
4907640a9aSBișoc George ok(Length == 0, "Expected 0 characters to be converted but got %u.\n", Length);
5007640a9aSBișoc George
5107640a9aSBișoc George /* Don't give the output but the count character inspection argument is valid */
5207640a9aSBișoc George Length = mbtowc(NULL, ch, MB_CUR_MAX);
5307640a9aSBișoc George ok(Length == 1, "The number of bytes to check should be 1 but got %u.\n", Length);
5407640a9aSBișoc George
5507640a9aSBișoc George /* Convert the character and validate the output that we should get */
5607640a9aSBișoc George Length = mbtowc(BufferDest, ch, MB_CUR_MAX);
5707640a9aSBișoc George ok(Length == 1, "Expected 1 character to be converted but got %u.\n", Length);
5807640a9aSBișoc George ok_int(BufferDest[0], L'A');
5907640a9aSBișoc George
6007640a9aSBișoc George FreeGuarded(ch);
6107640a9aSBișoc George }
62