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 15 START_TEST(mbtowc) 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 } 62