[KERNEL32_APITEST]
authorPierre Schweitzer <pierre@reactos.org>
Fri, 25 Sep 2015 14:44:38 +0000 (14:44 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Fri, 25 Sep 2015 14:44:38 +0000 (14:44 +0000)
Add a test for CORE-10188 (which was fixed by Thomas in r69236).
It is based on Nikita Pechenkin's patch with a few modifications by me to avoid race condition on start (and avoid flappy test) and to match more closely our coding style

ROSTESTS-190 #resolve #comment Committed in r69351. Thanks!

svn path=/trunk/; revision=69351

rostests/apitests/kernel32/CMakeLists.txt
rostests/apitests/kernel32/Mailslot.c [new file with mode: 0644]
rostests/apitests/kernel32/testlist.c

index f329e3c..b0569cf 100644 (file)
@@ -13,7 +13,8 @@ list(APPEND SOURCE
     SetUnhandledExceptionFilter.c
     TerminateProcess.c
     TunnelCache.c
     SetUnhandledExceptionFilter.c
     TerminateProcess.c
     TunnelCache.c
-    testlist.c)
+    testlist.c
+    Mailslot.c)
 
 add_executable(kernel32_apitest ${SOURCE})
 target_link_libraries(kernel32_apitest wine ${PSEH_LIB})
 
 add_executable(kernel32_apitest ${SOURCE})
 target_link_libraries(kernel32_apitest wine ${PSEH_LIB})
diff --git a/rostests/apitests/kernel32/Mailslot.c b/rostests/apitests/kernel32/Mailslot.c
new file mode 100644 (file)
index 0000000..4cd701f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         GNU GPLv2 only as published by the Free Software Foundation
+ * PURPOSE:         Test for mailslot (CORE-10188)
+ * PROGRAMMER:      Nikita Pechenkin (n.pechenkin@mail.ru)
+ */
+
+#include <apitest.h>
+
+#define WIN32_NO_STATUS
+#include <stdio.h>
+
+#define LMS TEXT("\\\\.\\mailslot\\rostest_slot")
+#define MSG (0x50DA)
+
+static DWORD dInMsg  = MSG;
+static DWORD dOutMsg = 0x0;
+
+DWORD
+WINAPI
+MailSlotWriter(
+        LPVOID lpParam)
+{
+    DWORD cbWritten;
+    HANDLE hMailslot;
+
+    hMailslot = CreateFile(LMS, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+            NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+    ok(hMailslot != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n");
+    if (hMailslot != INVALID_HANDLE_VALUE)
+    {
+        Sleep(1000);
+        ok(WriteFile(hMailslot, &dInMsg, sizeof(dInMsg), &cbWritten, (LPOVERLAPPED) NULL), "Slot write failed\n");
+        CloseHandle(hMailslot);
+    }
+    return 0;
+}
+
+DWORD
+WINAPI
+MailSlotReader(
+        LPVOID lpParam)
+{
+    HANDLE hMailslotClient;
+    DWORD cbRead;
+    HANDLE hThread;
+
+    hMailslotClient = CreateMailslot(LMS, 0L, MAILSLOT_WAIT_FOREVER, (LPSECURITY_ATTRIBUTES) NULL);
+    ok(hMailslotClient != INVALID_HANDLE_VALUE, "CreateMailslot failed\n");
+    if (hMailslotClient != INVALID_HANDLE_VALUE)
+    {
+        hThread = CreateThread(NULL,0, MailSlotWriter, NULL, 0, NULL);
+        ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n");
+        if (hThread != INVALID_HANDLE_VALUE)
+        {
+            ok(ReadFile(hMailslotClient, &dOutMsg, sizeof(dOutMsg), &cbRead, NULL), "Slot read failed\n");
+            WaitForSingleObject(hThread, INFINITE);
+            CloseHandle(hThread);
+        }
+        CloseHandle(hMailslotClient);
+    }
+    return 0;
+}
+
+VOID
+StartTestCORE10188(VOID)
+{
+    HANDLE  hThread;
+
+    hThread = CreateThread(NULL,0, MailSlotReader, NULL, 0, NULL);
+    ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n");
+    if (hThread != INVALID_HANDLE_VALUE)
+    {
+        WaitForSingleObject(hThread, INFINITE);
+        CloseHandle(hThread);
+    }
+    ok(dInMsg == dOutMsg, "Transfer data failed\n");
+}
+
+START_TEST(Mailslot)
+{
+    StartTestCORE10188();
+}
index a4c0416..178e1e6 100644 (file)
@@ -10,6 +10,7 @@ extern void func_GetDriveType(void);
 extern void func_GetModuleFileName(void);
 extern void func_interlck(void);
 extern void func_lstrcpynW(void);
 extern void func_GetModuleFileName(void);
 extern void func_interlck(void);
 extern void func_lstrcpynW(void);
+extern void func_Mailslot(void);
 extern void func_MultiByteToWideChar(void);
 extern void func_PrivMoveFileIdentityW(void);
 extern void func_SetCurrentDirectory(void);
 extern void func_MultiByteToWideChar(void);
 extern void func_PrivMoveFileIdentityW(void);
 extern void func_SetCurrentDirectory(void);
@@ -26,6 +27,7 @@ const struct test winetest_testlist[] =
     { "GetModuleFileName",           func_GetModuleFileName },
     { "interlck",                    func_interlck },
     { "lstrcpynW",                   func_lstrcpynW },
     { "GetModuleFileName",           func_GetModuleFileName },
     { "interlck",                    func_interlck },
     { "lstrcpynW",                   func_lstrcpynW },
+    { "Mailslot",                    func_Mailslot },
     { "MultiByteToWideChar",         func_MultiByteToWideChar },
     { "PrivMoveFileIdentityW",       func_PrivMoveFileIdentityW },
     { "SetCurrentDirectory",         func_SetCurrentDirectory },
     { "MultiByteToWideChar",         func_MultiByteToWideChar },
     { "PrivMoveFileIdentityW",       func_PrivMoveFileIdentityW },
     { "SetCurrentDirectory",         func_SetCurrentDirectory },