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
19int __cdecl main(int argc, char *argv[]) {
20
21
22 LPWSTR OutBuffer;
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
35 /* This is testing the use of FROM_SYSTEM. We can't check to ensure
36 the error message it extracts is correct, only that it does place some
37 information into the buffer when it is called.
38 */
39
40 /*
41
42 ERROR_SUCCESS (0L) is normally returned by GetLastError,
43 But, the ERROR_SUCCESS is removed from messages for Unix based Systems
44 To ensure that we have some information into the buffer we are using the message
45 identifier value 2L (ERROR_FILE_NOT_FOUND)
46 */
47 ReturnResult = FormatMessage(
48 FORMAT_MESSAGE_FROM_SYSTEM |
49 FORMAT_MESSAGE_ALLOCATE_BUFFER, /* source and processing options */
50 NULL, /* message source */
51 2L, /* message identifier */
52 0, /* language identifier */
53 (LPWSTR)&OutBuffer, /* message buffer */
54 0, /* maximum size of message buffer */
55 NULL /* array of message inserts */
56 );
57
58 if(ReturnResult == 0)
59 {
60 Fail("ERROR: The return value was 0, which indicates failure. The "
61 "function failed when trying to Format a FROM_SYSTEM message.");
62 }
63
64 if(wcslen(OutBuffer) <= 0)
65 {
66 Fail("ERROR: There are no characters in the buffer, and when the "
67 "FORMAT_MESSAGE_FROM_SYSTEM flag is used with ERROR_FILE_NOT_FOUND error, "
68 "something should be put into the buffer.");
69 }
70
71 LocalFree(OutBuffer);
72
73 PAL_Terminate();
74 return PASS;
75
76}
77
78
79