1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GNU GPLv2 only as published by the Free Software Foundation 4 * PURPOSE: Test for mailslot (CORE-10188) 5 * PROGRAMMER: Nikita Pechenkin (n.pechenkin@mail.ru) 6 */ 7 8 #include "precomp.h" 9 10 #define LMS TEXT("\\\\.\\mailslot\\rostest_slot") 11 #define MSG (0x50DA) 12 13 static DWORD dInMsg = MSG; 14 static DWORD dOutMsg = 0x0; 15 16 DWORD 17 WINAPI 18 MailSlotWriter( 19 LPVOID lpParam) 20 { 21 DWORD cbWritten; 22 HANDLE hMailslot; 23 24 hMailslot = CreateFile(LMS, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 25 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 26 ok(hMailslot != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n"); 27 if (hMailslot != INVALID_HANDLE_VALUE) 28 { 29 Sleep(1000); 30 ok(WriteFile(hMailslot, &dInMsg, sizeof(dInMsg), &cbWritten, (LPOVERLAPPED) NULL), "Slot write failed\n"); 31 CloseHandle(hMailslot); 32 } 33 return 0; 34 } 35 36 DWORD 37 WINAPI 38 MailSlotReader( 39 LPVOID lpParam) 40 { 41 HANDLE hMailslotClient; 42 DWORD cbRead; 43 HANDLE hThread; 44 45 hMailslotClient = CreateMailslot(LMS, 0L, MAILSLOT_WAIT_FOREVER, (LPSECURITY_ATTRIBUTES) NULL); 46 ok(hMailslotClient != INVALID_HANDLE_VALUE, "CreateMailslot failed\n"); 47 if (hMailslotClient != INVALID_HANDLE_VALUE) 48 { 49 hThread = CreateThread(NULL,0, MailSlotWriter, NULL, 0, NULL); 50 ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n"); 51 if (hThread != INVALID_HANDLE_VALUE) 52 { 53 ok(ReadFile(hMailslotClient, &dOutMsg, sizeof(dOutMsg), &cbRead, NULL), "Slot read failed\n"); 54 WaitForSingleObject(hThread, INFINITE); 55 CloseHandle(hThread); 56 } 57 CloseHandle(hMailslotClient); 58 } 59 return 0; 60 } 61 62 VOID 63 StartTestCORE10188(VOID) 64 { 65 HANDLE hThread; 66 67 hThread = CreateThread(NULL,0, MailSlotReader, NULL, 0, NULL); 68 ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n"); 69 if (hThread != INVALID_HANDLE_VALUE) 70 { 71 WaitForSingleObject(hThread, INFINITE); 72 CloseHandle(hThread); 73 } 74 ok(dInMsg == dOutMsg, "Transfer data failed\n"); 75 } 76 77 START_TEST(Mailslot) 78 { 79 StartTestCORE10188(); 80 } 81