https://git.reactos.org/?p=reactos.git;a=commitdiff;h=72094e637d788448f4e1f…
commit 72094e637d788448f4e1f3c121e1881343e17c07
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sat Dec 16 19:39:37 2017 +0100
[KERNEL32_APITEST] Add a test for FormatMessage backed with MC file.
---
modules/rostests/apitests/kernel32/CMakeLists.txt | 6 ++-
modules/rostests/apitests/kernel32/FormatMessage.c | 51 ++++++++++++++++++++++
.../rostests/apitests/kernel32/FormatMessage.mc | 14 ++++++
.../rostests/apitests/kernel32/kernel32_apitest.rc | 6 +++
modules/rostests/apitests/kernel32/testlist.c | 2 +
5 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/modules/rostests/apitests/kernel32/CMakeLists.txt
b/modules/rostests/apitests/kernel32/CMakeLists.txt
index 06edd1b9c3..c329031929 100644
--- a/modules/rostests/apitests/kernel32/CMakeLists.txt
+++ b/modules/rostests/apitests/kernel32/CMakeLists.txt
@@ -1,6 +1,8 @@
add_subdirectory(redirptest)
+add_message_headers(ANSI FormatMessage.mc)
+
list(APPEND SOURCE
Console.c
CreateProcess.c
@@ -9,6 +11,7 @@ list(APPEND SOURCE
dosdev.c
FindActCtxSectionStringW.c
FindFiles.c
+ FormatMessage.c
GetComputerNameEx.c
GetCurrentDirectory.c
GetDriveType.c
@@ -30,11 +33,12 @@ list(APPEND SOURCE
WideCharToMultiByte.c
precomp.h)
-add_executable(kernel32_apitest ${SOURCE} testlist.c)
+add_executable(kernel32_apitest ${SOURCE} testlist.c kernel32_apitest.rc)
target_link_libraries(kernel32_apitest wine ${PSEH_LIB})
set_module_type(kernel32_apitest win32cui)
add_delay_importlibs(kernel32_apitest advapi32 shlwapi)
add_importlibs(kernel32_apitest msvcrt kernel32 ntdll)
+add_dependencies(kernel32_apitest FormatMessage)
add_pch(kernel32_apitest precomp.h SOURCE)
add_rostests_file(TARGET kernel32_apitest)
diff --git a/modules/rostests/apitests/kernel32/FormatMessage.c
b/modules/rostests/apitests/kernel32/FormatMessage.c
new file mode 100644
index 0000000000..ed2284daa1
--- /dev/null
+++ b/modules/rostests/apitests/kernel32/FormatMessage.c
@@ -0,0 +1,51 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: GPLv2+ - See COPYING in the top level directory
+ * PURPOSE: Test for FormatMessage and resources
+ * PROGRAMMERS: Pierre Schweitzer
+ */
+
+#include <apitest.h>
+#include <FormatMessage.h>
+
+WCHAR First[] = L"This is a test message.\r\n";
+WCHAR Second[] = L"This is a second test message.\r\n";
+
+START_TEST(FormatMessage)
+{
+ PWSTR Buffer;
+ DWORD Written;
+
+ Buffer = NULL;
+ Written = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ NULL, MSG_FIRST_MESSAGE, 0, (LPWSTR)&Buffer, 0, NULL);
+ ok(Written != 0, "Unexpected error: %lx\n", GetLastError());
+ ok(Buffer != NULL, "No buffer allocated\n");
+ ok(Written == (sizeof(First) - sizeof(UNICODE_NULL)) / sizeof(WCHAR),
+ "Invalid size: %ld (expected: %d)\n",
+ Written, (sizeof(First) - sizeof(UNICODE_NULL)) / sizeof(WCHAR));
+ ok(RtlCompareMemory(Buffer, First, sizeof(First) - sizeof(UNICODE_NULL)) ==
+ sizeof(First) - sizeof(UNICODE_NULL),
+ "Mismatching string: %S (expected : %S)\n", Buffer, First);
+ LocalFree(Buffer);
+
+ Buffer = NULL;
+ Written = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ NULL, MSG_SECOND_MESSAGE, 0, (LPWSTR)&Buffer, 0, NULL);
+ ok(Written != 0, "Unexpected error: %lx\n", GetLastError());
+ ok(Buffer != NULL, "No buffer allocated\n");
+ ok(Written == (sizeof(Second) - sizeof(UNICODE_NULL)) / sizeof(WCHAR),
+ "Invalid size: %ld (expected: %d)\n",
+ Written, (sizeof(Second) - sizeof(UNICODE_NULL)) / sizeof(WCHAR));
+ ok(RtlCompareMemory(Buffer, Second, sizeof(Second) - sizeof(UNICODE_NULL)) ==
+ sizeof(Second) - sizeof(UNICODE_NULL),
+ "Mismatching string: %S (expected: %S)\n", Buffer, Second);
+ LocalFree(Buffer);
+
+ Buffer = NULL;
+ Written = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ NULL, MSG_SECOND_MESSAGE + 1, 0, (LPWSTR)&Buffer, 0,
NULL);
+ ok(Written == 0, "Unexpected success: %ld\n", Written);
+ ok(Buffer == NULL, "Unexpected success: %p\n", Buffer);
+ ok(GetLastError() == 0x13d, "Unexpected error: %lx\n", GetLastError());
+}
diff --git a/modules/rostests/apitests/kernel32/FormatMessage.mc
b/modules/rostests/apitests/kernel32/FormatMessage.mc
new file mode 100644
index 0000000000..f13ba1269e
--- /dev/null
+++ b/modules/rostests/apitests/kernel32/FormatMessage.mc
@@ -0,0 +1,14 @@
+MessageIdTypedef=DWORD
+LanguageNames=(English=0x409:MSG0409)
+
+MessageId=
+SymbolicName=MSG_FIRST_MESSAGE
+Language=English
+This is a test message.
+.
+
+MessageId=
+SymbolicName=MSG_SECOND_MESSAGE
+Language=English
+This is a second test message.
+.
diff --git a/modules/rostests/apitests/kernel32/kernel32_apitest.rc
b/modules/rostests/apitests/kernel32/kernel32_apitest.rc
new file mode 100644
index 0000000000..ea373085bc
--- /dev/null
+++ b/modules/rostests/apitests/kernel32/kernel32_apitest.rc
@@ -0,0 +1,6 @@
+#define REACTOS_STR_FILE_DESCRIPTION "Kernel32 Regtests"
+#define REACTOS_STR_INTERNAL_NAME "kernel32_apitest"
+#define REACTOS_STR_ORIGINAL_FILENAME "kernel32_apitest.exe"
+#include <reactos/version.rc>
+
+#include <FormatMessage.rc>
diff --git a/modules/rostests/apitests/kernel32/testlist.c
b/modules/rostests/apitests/kernel32/testlist.c
index f00b9e99a6..0bf5e424dc 100644
--- a/modules/rostests/apitests/kernel32/testlist.c
+++ b/modules/rostests/apitests/kernel32/testlist.c
@@ -10,6 +10,7 @@ extern void func_DeviceIoControl(void);
extern void func_dosdev(void);
extern void func_FindActCtxSectionStringW(void);
extern void func_FindFiles(void);
+extern void func_FormatMessage(void);
extern void func_GetComputerNameEx(void);
extern void func_GetCurrentDirectory(void);
extern void func_GetDriveType(void);
@@ -39,6 +40,7 @@ const struct test winetest_testlist[] =
{ "dosdev", func_dosdev },
{ "FindActCtxSectionStringW", func_FindActCtxSectionStringW },
{ "FindFiles", func_FindFiles },
+ { "FormatMessage", func_FormatMessage },
{ "GetComputerNameEx", func_GetComputerNameEx },
{ "GetCurrentDirectory", func_GetCurrentDirectory },
{ "GetDriveType", func_GetDriveType },