2003-10-31 00:24:12 +01:00
|
|
|
/*
|
|
|
|
* Mailslot regression test
|
|
|
|
*
|
|
|
|
* Copyright 2003 Mike McCormack
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-10-31 00:24:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2004-05-04 06:13:05 +02:00
|
|
|
static const char szmspath[] = "\\\\.\\mailslot\\wine_mailslot_test";
|
2003-10-31 00:24:12 +01:00
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static int mailslot_test(void)
|
2003-10-31 00:24:12 +01:00
|
|
|
{
|
|
|
|
HANDLE hSlot, hSlot2, hWriter, hWriter2;
|
|
|
|
unsigned char buffer[16];
|
|
|
|
DWORD count, dwMax, dwNext, dwMsgCount, dwTimeout;
|
2008-11-20 21:59:26 +01:00
|
|
|
BOOL ret;
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* sanity check on GetMailslotInfo */
|
|
|
|
dwMax = dwNext = dwMsgCount = dwTimeout = 0;
|
|
|
|
ok( !GetMailslotInfo( INVALID_HANDLE_VALUE, &dwMax, &dwNext,
|
2004-02-06 06:24:34 +01:00
|
|
|
&dwMsgCount, &dwTimeout ), "getmailslotinfo succeeded\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* open a mailslot that doesn't exist */
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter = CreateFileA(szmspath, GENERIC_READ|GENERIC_WRITE,
|
2003-10-31 00:24:12 +01:00
|
|
|
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
2005-02-10 20:19:35 +01:00
|
|
|
ok( hWriter == INVALID_HANDLE_VALUE, "nonexistent mailslot\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* open a mailslot without the right name */
|
2013-10-21 10:02:11 +02:00
|
|
|
hSlot = CreateMailslotA( "blah", 0, 0, NULL );
|
2003-10-31 00:24:12 +01:00
|
|
|
ok( hSlot == INVALID_HANDLE_VALUE,
|
2004-02-06 06:24:34 +01:00
|
|
|
"Created mailslot with invalid name\n");
|
2005-03-28 12:03:56 +02:00
|
|
|
ok( GetLastError() == ERROR_INVALID_NAME,
|
|
|
|
"error should be ERROR_INVALID_NAME\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* open a mailslot with a null name */
|
2013-10-21 10:02:11 +02:00
|
|
|
hSlot = CreateMailslotA( NULL, 0, 0, NULL );
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( hSlot == INVALID_HANDLE_VALUE, "Created mailslot with invalid name\n");
|
|
|
|
ok( GetLastError() == ERROR_PATH_NOT_FOUND, "error should be ERROR_PATH_NOT_FOUND\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* valid open, but with wacky parameters ... then check them */
|
2013-10-21 10:02:11 +02:00
|
|
|
hSlot = CreateMailslotA( szmspath, -1, -1, NULL );
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( hSlot != INVALID_HANDLE_VALUE , "mailslot with valid name failed\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
dwMax = dwNext = dwMsgCount = dwTimeout = 0;
|
|
|
|
ok( GetMailslotInfo( hSlot, &dwMax, &dwNext, &dwMsgCount, &dwTimeout ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
2005-09-13 17:00:32 +02:00
|
|
|
ok( dwMax == ~0U, "dwMax incorrect\n");
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( dwNext == MAILSLOT_NO_MESSAGE, "dwNext incorrect\n");
|
|
|
|
ok( dwMsgCount == 0, "dwMsgCount incorrect\n");
|
2005-09-13 17:00:32 +02:00
|
|
|
ok( dwTimeout == ~0U, "dwTimeout incorrect\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
ok( GetMailslotInfo( hSlot, NULL, NULL, NULL, NULL ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
|
|
|
ok( CloseHandle(hSlot), "failed to close mailslot\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* now open it for real */
|
2013-10-21 10:02:11 +02:00
|
|
|
hSlot = CreateMailslotA( szmspath, 0, 0, NULL );
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( hSlot != INVALID_HANDLE_VALUE , "valid mailslot failed\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* try and read/write to it */
|
2013-09-18 08:53:50 +02:00
|
|
|
count = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadFile(INVALID_HANDLE_VALUE, buffer, 0, &count, NULL);
|
|
|
|
ok(!ret, "ReadFile should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError());
|
|
|
|
ok(count == 0, "expected 0, got %u\n", count);
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadFile(hSlot, buffer, 0, &count, NULL);
|
|
|
|
ok(!ret, "ReadFile should fail\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_SEM_TIMEOUT, "wrong error %u\n", GetLastError());
|
|
|
|
ok(count == 0, "expected 0, got %u\n", count);
|
|
|
|
|
2003-10-31 00:24:12 +01:00
|
|
|
count = 0;
|
|
|
|
memset(buffer, 0, sizeof buffer);
|
2008-11-20 21:59:26 +01:00
|
|
|
ret = ReadFile( hSlot, buffer, sizeof buffer, &count, NULL);
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( !ret, "slot read\n");
|
2008-11-20 21:59:26 +01:00
|
|
|
if (!ret) ok( GetLastError() == ERROR_SEM_TIMEOUT, "wrong error %u\n", GetLastError() );
|
|
|
|
else ok( count == 0, "wrong count %u\n", count );
|
2003-10-31 00:24:12 +01:00
|
|
|
ok( !WriteFile( hSlot, buffer, sizeof buffer, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"slot write\n");
|
2007-04-02 20:25:08 +02:00
|
|
|
ok( GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u\n", GetLastError() );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
2008-11-20 21:59:26 +01:00
|
|
|
/* now try and open the client, but with the wrong sharing mode */
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter = CreateFileA(szmspath, GENERIC_WRITE,
|
2003-10-31 00:24:12 +01:00
|
|
|
0, NULL, OPEN_EXISTING, 0, NULL);
|
2008-11-17 23:36:47 +01:00
|
|
|
ok( hWriter != INVALID_HANDLE_VALUE /* vista */ || GetLastError() == ERROR_SHARING_VIOLATION,
|
2008-11-20 21:59:26 +01:00
|
|
|
"error should be ERROR_SHARING_VIOLATION got %p / %u\n", hWriter, GetLastError());
|
2008-11-17 23:36:47 +01:00
|
|
|
if (hWriter != INVALID_HANDLE_VALUE) CloseHandle( hWriter );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* now open the client with the correct sharing mode */
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter = CreateFileA(szmspath, GENERIC_READ|GENERIC_WRITE,
|
2003-10-31 00:24:12 +01:00
|
|
|
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
2008-11-20 21:59:26 +01:00
|
|
|
ok( hWriter != INVALID_HANDLE_VALUE, "existing mailslot err %u\n", GetLastError());
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* opening a client should make no difference to
|
|
|
|
* whether we can read or write the mailslot
|
|
|
|
*/
|
2008-11-20 21:59:26 +01:00
|
|
|
ret = ReadFile( hSlot, buffer, sizeof buffer/2, &count, NULL);
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( !ret, "slot read\n");
|
2008-11-20 21:59:26 +01:00
|
|
|
if (!ret) ok( GetLastError() == ERROR_SEM_TIMEOUT, "wrong error %u\n", GetLastError() );
|
|
|
|
else ok( count == 0, "wrong count %u\n", count );
|
2003-10-31 00:24:12 +01:00
|
|
|
ok( !WriteFile( hSlot, buffer, sizeof buffer/2, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"slot write\n");
|
2007-04-02 20:25:08 +02:00
|
|
|
ok( GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u\n", GetLastError() );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we can't read from this client,
|
|
|
|
* but we should be able to write to it
|
|
|
|
*/
|
|
|
|
ok( !ReadFile( hWriter, buffer, sizeof buffer/2, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"can read client\n");
|
2008-11-20 21:59:26 +01:00
|
|
|
ok( GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ACCESS_DENIED,
|
|
|
|
"wrong error %u\n", GetLastError() );
|
2003-10-31 00:24:12 +01:00
|
|
|
ok( WriteFile( hWriter, buffer, sizeof buffer/2, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"can't write client\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
ok( !ReadFile( hWriter, buffer, sizeof buffer/2, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"can read client\n");
|
2008-11-20 21:59:26 +01:00
|
|
|
ok( GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_ACCESS_DENIED,
|
|
|
|
"wrong error %u\n", GetLastError() );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* seeing as there's something in the slot,
|
|
|
|
* we should be able to read it once
|
|
|
|
*/
|
|
|
|
ok( ReadFile( hSlot, buffer, sizeof buffer, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"slot read\n");
|
|
|
|
ok( count == (sizeof buffer/2), "short read\n" );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* but not again */
|
2008-11-20 21:59:26 +01:00
|
|
|
ret = ReadFile( hSlot, buffer, sizeof buffer, &count, NULL);
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( !ret, "slot read\n");
|
2008-11-20 21:59:26 +01:00
|
|
|
if (!ret) ok( GetLastError() == ERROR_SEM_TIMEOUT, "wrong error %u\n", GetLastError() );
|
|
|
|
else ok( count == 0, "wrong count %u\n", count );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* now try open another writer... should fail */
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter2 = CreateFileA(szmspath, GENERIC_READ|GENERIC_WRITE,
|
2003-10-31 00:24:12 +01:00
|
|
|
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
2008-11-17 23:36:47 +01:00
|
|
|
/* succeeds on vista, don't test */
|
|
|
|
if (hWriter2 != INVALID_HANDLE_VALUE) CloseHandle( hWriter2 );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* now try open another as a reader ... also fails */
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter2 = CreateFileA(szmspath, GENERIC_READ,
|
2003-10-31 00:24:12 +01:00
|
|
|
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
2008-11-17 23:36:47 +01:00
|
|
|
/* succeeds on vista, don't test */
|
|
|
|
if (hWriter2 != INVALID_HANDLE_VALUE) CloseHandle( hWriter2 );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* now try open another as a writer ... still fails */
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter2 = CreateFileA(szmspath, GENERIC_WRITE,
|
2003-10-31 00:24:12 +01:00
|
|
|
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
2008-11-17 23:36:47 +01:00
|
|
|
/* succeeds on vista, don't test */
|
|
|
|
if (hWriter2 != INVALID_HANDLE_VALUE) CloseHandle( hWriter2 );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* now open another one */
|
2013-10-21 10:02:11 +02:00
|
|
|
hSlot2 = CreateMailslotA( szmspath, 0, 0, NULL );
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( hSlot2 == INVALID_HANDLE_VALUE , "opened two mailslots\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* close the client again */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( CloseHandle( hWriter ), "closing the client\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now try reopen it with slightly different permissions ...
|
|
|
|
* shared writing
|
|
|
|
*/
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter = CreateFileA(szmspath, GENERIC_WRITE,
|
2003-10-31 00:24:12 +01:00
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( hWriter != INVALID_HANDLE_VALUE, "sharing writer\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now try open another as a writer ...
|
|
|
|
* but don't share with the first ... fail
|
|
|
|
*/
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter2 = CreateFileA(szmspath, GENERIC_WRITE,
|
2003-10-31 00:24:12 +01:00
|
|
|
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
2008-11-17 23:36:47 +01:00
|
|
|
/* succeeds on vista, don't test */
|
|
|
|
if (hWriter2 != INVALID_HANDLE_VALUE) CloseHandle( hWriter2 );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* now try open another as a writer ... and share with the first */
|
2013-10-21 10:02:11 +02:00
|
|
|
hWriter2 = CreateFileA(szmspath, GENERIC_WRITE,
|
2003-10-31 00:24:12 +01:00
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( hWriter2 != INVALID_HANDLE_VALUE, "2nd sharing writer\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* check the mailslot info */
|
|
|
|
dwMax = dwNext = dwMsgCount = dwTimeout = 0;
|
|
|
|
ok( GetMailslotInfo( hSlot, &dwMax, &dwNext, &dwMsgCount, &dwTimeout ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
|
|
|
ok( dwNext == MAILSLOT_NO_MESSAGE, "dwNext incorrect\n");
|
|
|
|
ok( dwMax == 0, "dwMax incorrect\n");
|
|
|
|
ok( dwMsgCount == 0, "dwMsgCount incorrect\n");
|
|
|
|
ok( dwTimeout == 0, "dwTimeout incorrect\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* check there's still no data */
|
2008-11-20 21:59:26 +01:00
|
|
|
ret = ReadFile( hSlot, buffer, sizeof buffer, &count, NULL);
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( !ret, "slot read\n");
|
2008-11-20 21:59:26 +01:00
|
|
|
if (!ret) ok( GetLastError() == ERROR_SEM_TIMEOUT, "wrong error %u\n", GetLastError() );
|
|
|
|
else ok( count == 0, "wrong count %u\n", count );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* write two messages */
|
|
|
|
buffer[0] = 'a';
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( WriteFile( hWriter, buffer, 1, &count, NULL), "1st write failed\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* check the mailslot info */
|
|
|
|
dwNext = dwMsgCount = 0;
|
|
|
|
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
|
|
|
ok( dwNext == 1, "dwNext incorrect\n");
|
|
|
|
ok( dwMsgCount == 1, "dwMsgCount incorrect\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
buffer[0] = 'b';
|
|
|
|
buffer[1] = 'c';
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( WriteFile( hWriter2, buffer, 2, &count, NULL), "2nd write failed\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* check the mailslot info */
|
|
|
|
dwNext = dwMsgCount = 0;
|
|
|
|
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
|
|
|
ok( dwNext == 1, "dwNext incorrect\n");
|
2005-04-11 18:11:32 +02:00
|
|
|
todo_wine {
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( dwMsgCount == 2, "dwMsgCount incorrect\n");
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* write a 3rd message with zero size */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( WriteFile( hWriter2, buffer, 0, &count, NULL), "3rd write failed\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* check the mailslot info */
|
|
|
|
dwNext = dwMsgCount = 0;
|
|
|
|
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
|
|
|
ok( dwNext == 1, "dwNext incorrect\n");
|
2008-11-20 21:59:26 +01:00
|
|
|
todo_wine
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( dwMsgCount == 3, "dwMsgCount incorrect %u\n", dwMsgCount);
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
buffer[0]=buffer[1]=0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* then check that they come out with the correct order and size,
|
|
|
|
* then the slot is empty
|
|
|
|
*/
|
|
|
|
ok( ReadFile( hSlot, buffer, sizeof buffer, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"1st slot read failed\n");
|
|
|
|
ok( count == 1, "failed to get 1st message\n");
|
|
|
|
ok( buffer[0] == 'a', "1st message wrong\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* check the mailslot info */
|
|
|
|
dwNext = dwMsgCount = 0;
|
|
|
|
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
|
|
|
ok( dwNext == 2, "dwNext incorrect\n");
|
2005-04-11 18:11:32 +02:00
|
|
|
todo_wine {
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( dwMsgCount == 2, "dwMsgCount incorrect %u\n", dwMsgCount);
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* read the second message */
|
|
|
|
ok( ReadFile( hSlot, buffer, sizeof buffer, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"2nd slot read failed\n");
|
|
|
|
ok( count == 2, "failed to get 2nd message\n");
|
|
|
|
ok( ( buffer[0] == 'b' ) && ( buffer[1] == 'c' ), "2nd message wrong\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* check the mailslot info */
|
|
|
|
dwNext = dwMsgCount = 0;
|
|
|
|
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( dwNext == 0, "dwNext incorrect %u\n", dwNext);
|
2007-04-09 12:21:24 +02:00
|
|
|
todo_wine {
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( dwMsgCount == 1, "dwMsgCount incorrect %u\n", dwMsgCount);
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* read the 3rd (zero length) message */
|
2005-03-30 21:02:15 +02:00
|
|
|
todo_wine {
|
2003-10-31 00:24:12 +01:00
|
|
|
ok( ReadFile( hSlot, buffer, sizeof buffer, &count, NULL),
|
2004-02-06 06:24:34 +01:00
|
|
|
"3rd slot read failed\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
}
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( count == 0, "failed to get 3rd message\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now there should be no more messages
|
|
|
|
* check the mailslot info
|
|
|
|
*/
|
|
|
|
dwNext = dwMsgCount = 0;
|
|
|
|
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
|
2004-02-06 06:24:34 +01:00
|
|
|
"getmailslotinfo failed\n");
|
|
|
|
ok( dwNext == MAILSLOT_NO_MESSAGE, "dwNext incorrect\n");
|
|
|
|
ok( dwMsgCount == 0, "dwMsgCount incorrect\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* check that reads fail */
|
2008-11-20 21:59:26 +01:00
|
|
|
ret = ReadFile( hSlot, buffer, sizeof buffer, &count, NULL);
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( !ret, "3rd slot read succeeded\n");
|
2008-11-20 21:59:26 +01:00
|
|
|
if (!ret) ok( GetLastError() == ERROR_SEM_TIMEOUT, "wrong error %u\n", GetLastError() );
|
|
|
|
else ok( count == 0, "wrong count %u\n", count );
|
2003-10-31 00:24:12 +01:00
|
|
|
|
|
|
|
/* finally close the mailslot and its client */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok( CloseHandle( hWriter2 ), "closing 2nd client\n");
|
|
|
|
ok( CloseHandle( hWriter ), "closing the client\n");
|
|
|
|
ok( CloseHandle( hSlot ), "closing the mailslot\n");
|
2003-10-31 00:24:12 +01:00
|
|
|
|
2007-04-02 20:25:08 +02:00
|
|
|
/* test timeouts */
|
2013-10-21 10:02:11 +02:00
|
|
|
hSlot = CreateMailslotA( szmspath, 0, 1000, NULL );
|
2007-04-02 20:25:08 +02:00
|
|
|
ok( hSlot != INVALID_HANDLE_VALUE , "valid mailslot failed\n");
|
|
|
|
count = 0;
|
|
|
|
memset(buffer, 0, sizeof buffer);
|
|
|
|
dwTimeout = GetTickCount();
|
|
|
|
ok( !ReadFile( hSlot, buffer, sizeof buffer, &count, NULL), "slot read\n");
|
2011-07-27 03:07:18 +02:00
|
|
|
ok( GetLastError() == ERROR_SEM_TIMEOUT, "wrong error %u\n", GetLastError() );
|
2007-04-02 20:25:08 +02:00
|
|
|
dwTimeout = GetTickCount() - dwTimeout;
|
2007-04-06 12:35:21 +02:00
|
|
|
ok( dwTimeout >= 990, "timeout too short %u\n", dwTimeout );
|
2007-04-02 20:25:08 +02:00
|
|
|
ok( CloseHandle( hSlot ), "closing the mailslot\n");
|
|
|
|
|
2003-10-31 00:24:12 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(mailslot)
|
|
|
|
{
|
|
|
|
mailslot_test();
|
|
|
|
}
|