| 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: test3.c |
| 8 | ** |
| 9 | ** Purpose: Tests that MultiByteToWideChar correctly handles the following |
| 10 | ** error conditions: insufficient buffer space, invalid code pages, |
| 11 | ** and invalid flags. |
| 12 | ** |
| 13 | ** |
| 14 | **==========================================================================*/ |
| 15 | |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | |
| 19 | int __cdecl main(int argc, char *argv[]) |
| 20 | { |
| 21 | char mbStr[128]; |
| 22 | WCHAR wideStr[128]; |
| 23 | int ret; |
| 24 | int i; |
| 25 | |
| 26 | if (PAL_Initialize(argc, argv)) |
| 27 | { |
| 28 | return FAIL; |
| 29 | } |
| 30 | |
| 31 | for (i=0; i<128; i++) |
| 32 | { |
| 33 | mbStr[i] = 'a'; |
| 34 | wideStr[i] = 0; |
| 35 | } |
| 36 | |
| 37 | mbStr[127] = 0; |
| 38 | |
| 39 | /* try with insufficient buffer space */ |
| 40 | ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 10); |
| 41 | if (ret != 0) |
| 42 | { |
| 43 | Fail("MultiByteToWideChar did not return an error!\n" |
| 44 | "Expected return of 0, got %d" , ret); |
| 45 | } |
| 46 | |
| 47 | ret = GetLastError(); |
| 48 | if (ret != ERROR_INSUFFICIENT_BUFFER) |
| 49 | { |
| 50 | Fail("MultiByteToWideChar did not set the last error to " |
| 51 | "ERROR_INSUFFICIENT_BUFFER!\n" ); |
| 52 | } |
| 53 | |
| 54 | /* try with a wacky code page */ |
| 55 | ret = MultiByteToWideChar(-1, 0, mbStr, -1, wideStr, 128); |
| 56 | if (ret != 0) |
| 57 | { |
| 58 | Fail("MultiByteToWideChar did not return an error!\n" |
| 59 | "Expected return of 0, got %d" , ret); |
| 60 | } |
| 61 | |
| 62 | ret = GetLastError(); |
| 63 | if (ret != ERROR_INVALID_PARAMETER) |
| 64 | { |
| 65 | Fail("MultiByteToWideChar did not set the last error to " |
| 66 | "ERROR_INVALID_PARAMETER!\n" ); |
| 67 | } |
| 68 | |
| 69 | PAL_Terminate(); |
| 70 | |
| 71 | return PASS; |
| 72 | } |
| 73 | |
| 74 | |