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 
START_TEST(FormatMessage)14 START_TEST(FormatMessage)
15 {
16     PWSTR Buffer;
17     DWORD Written;
18 
19     Buffer = NULL;
20     Written = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER,
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);
30     LocalFree(Buffer);
31 
32     Buffer = NULL;
33     Written = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER,
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);
43     LocalFree(Buffer);
44 
45     Buffer = NULL;
46     Written = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER,
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 }
52