[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / kernel32 / Mailslot.c
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 <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <stdio.h>
12
13 #define LMS TEXT("\\\\.\\mailslot\\rostest_slot")
14 #define MSG (0x50DA)
15
16 static DWORD dInMsg = MSG;
17 static DWORD dOutMsg = 0x0;
18
19 DWORD
20 WINAPI
21 MailSlotWriter(
22 LPVOID lpParam)
23 {
24 DWORD cbWritten;
25 HANDLE hMailslot;
26
27 hMailslot = CreateFile(LMS, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
28 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
29 ok(hMailslot != INVALID_HANDLE_VALUE, "CreateFile failed, results might not be accurate\n");
30 if (hMailslot != INVALID_HANDLE_VALUE)
31 {
32 Sleep(1000);
33 ok(WriteFile(hMailslot, &dInMsg, sizeof(dInMsg), &cbWritten, (LPOVERLAPPED) NULL), "Slot write failed\n");
34 CloseHandle(hMailslot);
35 }
36 return 0;
37 }
38
39 DWORD
40 WINAPI
41 MailSlotReader(
42 LPVOID lpParam)
43 {
44 HANDLE hMailslotClient;
45 DWORD cbRead;
46 HANDLE hThread;
47
48 hMailslotClient = CreateMailslot(LMS, 0L, MAILSLOT_WAIT_FOREVER, (LPSECURITY_ATTRIBUTES) NULL);
49 ok(hMailslotClient != INVALID_HANDLE_VALUE, "CreateMailslot failed\n");
50 if (hMailslotClient != INVALID_HANDLE_VALUE)
51 {
52 hThread = CreateThread(NULL,0, MailSlotWriter, NULL, 0, NULL);
53 ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n");
54 if (hThread != INVALID_HANDLE_VALUE)
55 {
56 ok(ReadFile(hMailslotClient, &dOutMsg, sizeof(dOutMsg), &cbRead, NULL), "Slot read failed\n");
57 WaitForSingleObject(hThread, INFINITE);
58 CloseHandle(hThread);
59 }
60 CloseHandle(hMailslotClient);
61 }
62 return 0;
63 }
64
65 VOID
66 StartTestCORE10188(VOID)
67 {
68 HANDLE hThread;
69
70 hThread = CreateThread(NULL,0, MailSlotReader, NULL, 0, NULL);
71 ok(hThread != INVALID_HANDLE_VALUE, "CreateThread failed\n");
72 if (hThread != INVALID_HANDLE_VALUE)
73 {
74 WaitForSingleObject(hThread, INFINITE);
75 CloseHandle(hThread);
76 }
77 ok(dInMsg == dOutMsg, "Transfer data failed\n");
78 }
79
80 START_TEST(Mailslot)
81 {
82 StartTestCORE10188();
83 }