| 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 | #define UNICODE | 
|---|
| 15 | #include <palsuite.h> | 
|---|
| 16 |  | 
|---|
| 17 | WCHAR OutBuffer[1024]; | 
|---|
| 18 |  | 
|---|
| 19 | int __cdecl main(int argc, char *argv[]) | 
|---|
| 20 | { | 
|---|
| 21 |  | 
|---|
| 22 | WCHAR *  TheString; | 
|---|
| 23 | WCHAR * CorrectString; | 
|---|
| 24 | int ReturnResult; | 
|---|
| 25 |  | 
|---|
| 26 | /* | 
|---|
| 27 | * Initialize the PAL and return FAILURE if this fails | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | if(0 != (PAL_Initialize(argc, argv))) | 
|---|
| 31 | { | 
|---|
| 32 | return FAIL; | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | TheString = convert( "Pal %1!u! %2!i! %3!s! Testing"); | 
|---|
| 36 |  | 
|---|
| 37 | /* The resulting value in the buffer shouldn't be formatted at all, | 
|---|
| 38 | because the inserts are being ignored. | 
|---|
| 39 | */ | 
|---|
| 40 |  | 
|---|
| 41 | ReturnResult = FormatMessage( | 
|---|
| 42 | FORMAT_MESSAGE_FROM_STRING | | 
|---|
| 43 | FORMAT_MESSAGE_IGNORE_INSERTS,    /* source and processing options */ | 
|---|
| 44 | TheString,                       /* message source */ | 
|---|
| 45 | 0,                               /* message identifier */ | 
|---|
| 46 | 0,                               /* language identifier */ | 
|---|
| 47 | OutBuffer,                       /* message buffer */ | 
|---|
| 48 | 1024,                            /* maximum size of message buffer */ | 
|---|
| 49 | NULL                             /* array of message inserts */ | 
|---|
| 50 | ); | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 |  | 
|---|
| 54 | if(ReturnResult == 0) | 
|---|
| 55 | { | 
|---|
| 56 | free(TheString); | 
|---|
| 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 IGNORE_INSERTS flag.\n"); | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 |  | 
|---|
| 63 | /* Note: Since 's' is the default insert, when this function is called | 
|---|
| 64 | with ignore inserts, it strips %3!s! down to just %3 -- as they're | 
|---|
| 65 | equal. | 
|---|
| 66 | */ | 
|---|
| 67 | if(memcmp(OutBuffer, | 
|---|
| 68 | (CorrectString = convert( "Pal %1!u! %2!i! %3 Testing")), | 
|---|
| 69 | wcslen(OutBuffer)*2+2) != 0) | 
|---|
| 70 | { | 
|---|
| 71 | free(TheString); | 
|---|
| 72 | free(CorrectString); | 
|---|
| 73 | Fail( "ERROR:  Since the IGNORE_INSERTS flag was set, the result " | 
|---|
| 74 | "should have been 'Pal %%1!u! %%2!i! %%3 Testing' but was " | 
|---|
| 75 | "really '%S'.\n",OutBuffer); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | free(TheString); | 
|---|
| 79 | free(CorrectString); | 
|---|
| 80 | PAL_Terminate(); | 
|---|
| 81 | return PASS; | 
|---|
| 82 |  | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 |  | 
|---|
| 86 |  | 
|---|