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 : test.c |
8 | ** |
9 | ** Purpose: Test for FormatMessageW() function |
10 | ** |
11 | ** |
12 | **=========================================================*/ |
13 | |
14 | |
15 | #define UNICODE |
16 | #include <palsuite.h> |
17 | |
18 | int __cdecl main(int argc, char *argv[]) { |
19 | |
20 | WCHAR * TheString; |
21 | LPWSTR OutBuffer; |
22 | WCHAR* TheArray[3]; |
23 | int ReturnResult; |
24 | |
25 | /* |
26 | * Initialize the PAL and return FAILURE if this fails |
27 | */ |
28 | |
29 | if(0 != (PAL_Initialize(argc, argv))) |
30 | { |
31 | return FAIL; |
32 | } |
33 | |
34 | TheString = convert("Pal %1 %2 %3 Testing" ); |
35 | TheArray[0] = convert("Foo" ); |
36 | TheArray[1] = convert("Bar" ); |
37 | TheArray[2] = convert("FooBar" ); |
38 | |
39 | /* OutBuffer will be allocated in the function, if the flag |
40 | is working properly. |
41 | */ |
42 | |
43 | ReturnResult = FormatMessage( |
44 | FORMAT_MESSAGE_FROM_STRING | |
45 | FORMAT_MESSAGE_ARGUMENT_ARRAY | |
46 | FORMAT_MESSAGE_ALLOCATE_BUFFER, /* source and processing options */ |
47 | TheString, /* message source */ |
48 | 0, /* message identifier */ |
49 | 0, /* language identifier */ |
50 | (LPWSTR)&OutBuffer, /* message buffer */ |
51 | 0, /* maximum size of message buffer */ |
52 | (va_list *) TheArray /* array of message inserts */ |
53 | ); |
54 | |
55 | if(ReturnResult == 0) |
56 | { |
57 | Fail("ERROR: The return value was 0, which indicates failure. " |
58 | "The function failed when trying to Format a simple string, " |
59 | "using the ALLOCATE_BUFFER flag." ); |
60 | } |
61 | |
62 | if(memcmp(OutBuffer, |
63 | convert("Pal Foo Bar FooBar Testing" ), |
64 | wcslen(OutBuffer)*2+2) != 0) |
65 | { |
66 | Fail("ERROR: Since the FORMAT_MESSAGE_ALLOCATE_BUFFER flag was set, " |
67 | "the result should have been 'Pal Foo Bar FooBar Testing' but " |
68 | "was really '%s'." ,convertC(OutBuffer)); |
69 | } |
70 | |
71 | PAL_Terminate(); |
72 | return PASS; |
73 | |
74 | } |
75 | |
76 | |
77 | |