ReactOS  0.4.14-dev-583-g2a1ba2c
FormatMessage.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Test for FormatMessage and resources
5  * PROGRAMMERS: Pierre Schweitzer
6  */
7 
8 #include <apitest.h>
9 #include <FormatMessage.h>
10 
11 WCHAR First[] = L"This is a test message.\r\n";
12 WCHAR Second[] = L"This is a second test message.\r\n";
13 
15 {
16  PWSTR Buffer;
17  DWORD Written;
18 
19  Buffer = NULL;
21  NULL, MSG_FIRST_MESSAGE, 0, (LPWSTR)&Buffer, 0, NULL);
22  ok(Written != 0, "Unexpected error: %lx\n", GetLastError());
23  ok(Buffer != NULL, "No buffer allocated\n");
24  ok(Written == (sizeof(First) - sizeof(UNICODE_NULL)) / sizeof(WCHAR),
25  "Invalid size: %ld (expected: %d)\n",
26  Written, (sizeof(First) - sizeof(UNICODE_NULL)) / sizeof(WCHAR));
27  ok(RtlCompareMemory(Buffer, First, sizeof(First) - sizeof(UNICODE_NULL)) ==
28  sizeof(First) - sizeof(UNICODE_NULL),
29  "Mismatching string: %S (expected : %S)\n", Buffer, First);
31 
32  Buffer = NULL;
34  NULL, MSG_SECOND_MESSAGE, 0, (LPWSTR)&Buffer, 0, NULL);
35  ok(Written != 0, "Unexpected error: %lx\n", GetLastError());
36  ok(Buffer != NULL, "No buffer allocated\n");
37  ok(Written == (sizeof(Second) - sizeof(UNICODE_NULL)) / sizeof(WCHAR),
38  "Invalid size: %ld (expected: %d)\n",
39  Written, (sizeof(Second) - sizeof(UNICODE_NULL)) / sizeof(WCHAR));
40  ok(RtlCompareMemory(Buffer, Second, sizeof(Second) - sizeof(UNICODE_NULL)) ==
41  sizeof(Second) - sizeof(UNICODE_NULL),
42  "Mismatching string: %S (expected: %S)\n", Buffer, Second);
44 
45  Buffer = NULL;
47  NULL, MSG_SECOND_MESSAGE + 1, 0, (LPWSTR)&Buffer, 0, NULL);
48  ok(Written == 0, "Unexpected success: %ld\n", Written);
49  ok(Buffer == NULL, "Unexpected success: %p\n", Buffer);
50  ok(GetLastError() == 0x13d, "Unexpected error: %lx\n", GetLastError());
51 }
uint16_t * PWSTR
Definition: typedefs.h:54
WCHAR Second[]
Definition: FormatMessage.c:12
START_TEST(FormatMessage)
Definition: FormatMessage.c:14
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
WCHAR First[]
Definition: FormatMessage.c:11
#define UNICODE_NULL
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FormatMessage
Definition: winbase.h:3629
static const WCHAR L[]
Definition: oid.c:1250
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define ok(value,...)
Definition: atltest.h:57
WCHAR * LPWSTR
Definition: xmlstorage.h:184
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465