| 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: test2.c |
| 8 | ** |
| 9 | ** Purpose: Tests that MultiByteToWideChar respects the length of the wide |
| 10 | ** character string. |
| 11 | |
| 12 | ** |
| 13 | **==========================================================================*/ |
| 14 | |
| 15 | #include <palsuite.h> |
| 16 | |
| 17 | /* |
| 18 | * For now, it is assumed that MultiByteToWideChar will only be used in the PAL |
| 19 | * with CP_ACP, and that dwFlags will be 0. |
| 20 | */ |
| 21 | |
| 22 | int __cdecl main(int argc, char *argv[]) |
| 23 | { |
| 24 | char mbStr[128]; |
| 25 | WCHAR wideStr[128]; |
| 26 | int ret; |
| 27 | int i; |
| 28 | |
| 29 | if (PAL_Initialize(argc, argv)) |
| 30 | { |
| 31 | return FAIL; |
| 32 | } |
| 33 | |
| 34 | for (i=0; i<128; i++) |
| 35 | { |
| 36 | mbStr[i] = 'a'; |
| 37 | wideStr[i] = 0; |
| 38 | } |
| 39 | |
| 40 | mbStr[127] = 0; |
| 41 | |
| 42 | |
| 43 | ret = MultiByteToWideChar(CP_ACP, 0, mbStr, 10, wideStr, 0); |
| 44 | if (ret != 10) |
| 45 | { |
| 46 | Fail("MultiByteToWideChar did not return correct string length!\n" |
| 47 | "Got %d, expected %d\n" , ret, 10); |
| 48 | } |
| 49 | |
| 50 | wideStr[10] = (WCHAR) 'b'; |
| 51 | |
| 52 | ret = MultiByteToWideChar(CP_ACP, 0, mbStr, 10, wideStr, 128); |
| 53 | if (ret != 10) |
| 54 | { |
| 55 | Fail("MultiByteToWideChar did not return correct string length!\n" |
| 56 | "Got %d, expected %d\n" , ret, 10); |
| 57 | } |
| 58 | |
| 59 | if (wideStr[10] != 'b') |
| 60 | { |
| 61 | Fail("WideCharToMultiByte overflowed the destination buffer!\n" ); |
| 62 | } |
| 63 | |
| 64 | PAL_Terminate(); |
| 65 | |
| 66 | return PASS; |
| 67 | } |
| 68 | |
| 69 | |