summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.cpp
blob: 81f58a532c59869b1904c85056103331540daf9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================================
**
** Source: test1.c
**
** Purpose: Tests MultiByteToWideChar with all the ASCII characters (0-127).
**          Also tests that WideCharToMultiByte handles different buffer
**          lengths correctly (0, -1, and a valid length)
**
**
**==========================================================================*/

#include <palsuite.h>

/*
 * For now, it is assumed that MultiByteToWideChar will only be used in the PAL
 * with CP_ACP, and that dwFlags will be 0.
 */

int __cdecl main(int argc, char *argv[])
{    
    char mbStr[128];
    WCHAR wideStr[128];
    int ret;
    int i;

    if (PAL_Initialize(argc, argv))
    {
        return FAIL;
    }

    for (i=0; i<128; i++)
    {
        mbStr[i] = 127 - i;
        wideStr[i] = 0;
    }


    ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0);
    if (ret != 128)
    {
        Fail("MultiByteToWideChar did not return correct string length!\n"
            "Got %d, expected %d\n", ret, 128);
    }

    /* Make sure the ASCII set (0-127) gets translated correctly */
    ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 128);
    if (ret != 128)
    {
        Fail("MultiByteToWideChar did not return correct string length!\n"
            "Got %d, expected %d\n", ret, 128);
    }

    for (i=0; i<128; i++)
    {
        if (wideStr[i] != (WCHAR)(127 - i))
        {
            Fail("MultiByteToWideChar failed to translate correctly!\n"
                "Expected character %d to be %c (%x), got %c (%x)\n",
                i, 127 - i, 127 - i,wideStr[i], wideStr[i]);
        }
    }


    /* try a 0 length string */
    mbStr[0] = 0;
    ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0);
    if (ret != 1)
    {
        Fail("MultiByteToWideChar did not return correct string length!\n"
            "Got %d, expected %d\n", ret, 1);
    }

    PAL_Terminate();

    return PASS;
}