1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================================
6**
7** Source: test1.c
8**
9** Purpose: Tests MultiByteToWideChar with all the ASCII characters (0-127).
10** Also tests that WideCharToMultiByte handles different buffer
11** lengths correctly (0, -1, and a valid length)
12**
13**
14**==========================================================================*/
15
16#include <palsuite.h>
17
18/*
19 * For now, it is assumed that MultiByteToWideChar will only be used in the PAL
20 * with CP_ACP, and that dwFlags will be 0.
21 */
22
23int __cdecl main(int argc, char *argv[])
24{
25 char mbStr[128];
26 WCHAR wideStr[128];
27 int ret;
28 int i;
29
30 if (PAL_Initialize(argc, argv))
31 {
32 return FAIL;
33 }
34
35 for (i=0; i<128; i++)
36 {
37 mbStr[i] = 127 - i;
38 wideStr[i] = 0;
39 }
40
41
42 ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0);
43 if (ret != 128)
44 {
45 Fail("MultiByteToWideChar did not return correct string length!\n"
46 "Got %d, expected %d\n", ret, 128);
47 }
48
49 /* Make sure the ASCII set (0-127) gets translated correctly */
50 ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 128);
51 if (ret != 128)
52 {
53 Fail("MultiByteToWideChar did not return correct string length!\n"
54 "Got %d, expected %d\n", ret, 128);
55 }
56
57 for (i=0; i<128; i++)
58 {
59 if (wideStr[i] != (WCHAR)(127 - i))
60 {
61 Fail("MultiByteToWideChar failed to translate correctly!\n"
62 "Expected character %d to be %c (%x), got %c (%x)\n",
63 i, 127 - i, 127 - i,wideStr[i], wideStr[i]);
64 }
65 }
66
67
68 /* try a 0 length string */
69 mbStr[0] = 0;
70 ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0);
71 if (ret != 1)
72 {
73 Fail("MultiByteToWideChar did not return correct string length!\n"
74 "Got %d, expected %d\n", ret, 1);
75 }
76
77 PAL_Terminate();
78
79 return PASS;
80}
81
82