Add testing of PeekNamedPipe, multiple writes, and message mode.

This commit is contained in:
Duane Clark 2004-04-26 23:30:51 +00:00 committed by Alexandre Julliard
parent f627aed58b
commit d6c537b43c
1 changed files with 167 additions and 16 deletions

View File

@ -50,18 +50,24 @@
#define PIPENAME "\\\\.\\PiPe\\tests_" __FILE__
void test_CreateNamedPipe(void)
void test_CreateNamedPipe(pipemode)
{
HANDLE hnp;
HANDLE hFile;
const char obuf[] = "Bit Bucket";
char ibuf[32];
const char obuf2[] = "More bits";
char ibuf[32], *pbuf;
DWORD written;
DWORD readden;
DWORD avail;
DWORD lpmode;
trace("test_CreateNamedPipe starting\n");
if (pipemode == PIPE_TYPE_BYTE)
trace("test_CreateNamedPipe starting in byte mode\n");
else
trace("test_CreateNamedPipe starting in message mode\n");
/* Bad parameter checks */
hnp = CreateNamedPipe("not a named pipe", PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT,
hnp = CreateNamedPipe("not a named pipe", PIPE_ACCESS_DUPLEX, pipemode | PIPE_WAIT,
/* nMaxInstances */ 1,
/* nOutBufSize */ 1024,
/* nInBufSize */ 1024,
@ -78,7 +84,7 @@ void test_CreateNamedPipe(void)
"CreateNamedPipe should fail if name doesn't start with \\\\.\\pipe\n");
hnp = CreateNamedPipe(NULL,
PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT,
PIPE_ACCESS_DUPLEX, pipemode | PIPE_WAIT,
1, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL);
ok(hnp == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PATH_NOT_FOUND,
"CreateNamedPipe should fail if name is NULL\n");
@ -90,7 +96,7 @@ void test_CreateNamedPipe(void)
/* Functional checks */
hnp = CreateNamedPipe(PIPENAME, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT,
hnp = CreateNamedPipe(PIPENAME, PIPE_ACCESS_DUPLEX, pipemode | PIPE_WAIT,
/* nMaxInstances */ 1,
/* nOutBufSize */ 1024,
/* nInBufSize */ 1024,
@ -108,17 +114,160 @@ void test_CreateNamedPipe(void)
/* Make sure we can read and write a few bytes in both directions */
memset(ibuf, 0, sizeof(ibuf));
ok(WriteFile(hnp, obuf, sizeof(obuf), &written, NULL), "WriteFile\n");
ok(written == sizeof(obuf), "write file len\n");
ok(ReadFile(hFile, ibuf, sizeof(obuf), &readden, NULL), "ReadFile\n");
ok(readden == sizeof(obuf), "read file len\n");
ok(memcmp(obuf, ibuf, written) == 0, "content check\n");
ok(written == sizeof(obuf), "write file len 1\n");
ok(PeekNamedPipe(hFile, NULL, 0, NULL, &readden, NULL), "Peek\n");
ok(readden == sizeof(obuf), "peek 1 got %ld bytes\n", readden);
ok(ReadFile(hFile, ibuf, sizeof(ibuf), &readden, NULL), "ReadFile\n");
ok(readden == sizeof(obuf), "read 1 got %ld bytes\n", readden);
ok(memcmp(obuf, ibuf, written) == 0, "content 1 check\n");
memset(ibuf, 0, sizeof(ibuf));
ok(WriteFile(hFile, obuf, sizeof(obuf), &written, NULL), "WriteFile\n");
ok(written == sizeof(obuf), "write file len\n");
ok(ReadFile(hnp, ibuf, sizeof(obuf), &readden, NULL), "ReadFile\n");
ok(readden == sizeof(obuf), "read file len\n");
ok(memcmp(obuf, ibuf, written) == 0, "content check\n");
ok(WriteFile(hFile, obuf2, sizeof(obuf2), &written, NULL), "WriteFile\n");
ok(written == sizeof(obuf2), "write file len 2\n");
ok(PeekNamedPipe(hnp, NULL, 0, NULL, &readden, NULL), "Peek\n");
ok(readden == sizeof(obuf2), "peek 2 got %ld bytes\n", readden);
ok(ReadFile(hnp, ibuf, sizeof(ibuf), &readden, NULL), "ReadFile\n");
ok(readden == sizeof(obuf2), "read 2 got %ld bytes\n", readden);
ok(memcmp(obuf2, ibuf, written) == 0, "content 2 check\n");
/* Test reading of multiple writes */
memset(ibuf, 0, sizeof(ibuf));
ok(WriteFile(hnp, obuf, sizeof(obuf), &written, NULL), "WriteFile3a\n");
ok(written == sizeof(obuf), "write file len 3a\n");
ok(WriteFile(hnp, obuf2, sizeof(obuf2), &written, NULL), " WriteFile3b\n");
ok(written == sizeof(obuf2), "write file len 3b\n");
ok(PeekNamedPipe(hFile, ibuf, sizeof(ibuf), &readden, &avail, NULL), "Peek3\n");
if (pipemode == PIPE_TYPE_BYTE) {
todo_wine {
/* should return all 23 bytes */
ok(readden == sizeof(obuf) + sizeof(obuf2), "peek3 got %ld bytes\n", readden);
}
}
else
ok(readden == sizeof(obuf), "peek3 got %ld bytes\n", readden);
todo_wine {
ok(avail == sizeof(obuf) + sizeof(obuf2), "peek3 got %ld bytes available\n", avail);
}
pbuf = ibuf;
ok(memcmp(obuf, pbuf, sizeof(obuf)) == 0, "pipe content 3a check\n");
if (pipemode == PIPE_TYPE_BYTE) {
todo_wine {
pbuf += sizeof(obuf);
ok(memcmp(obuf2, pbuf, sizeof(obuf2)) == 0, "pipe content 3b check\n");
}
}
ok(ReadFile(hFile, ibuf, sizeof(ibuf), &readden, NULL), "ReadFile\n");
ok(readden == sizeof(obuf) + sizeof(obuf2), "read 3 got %ld bytes\n", readden);
pbuf = ibuf;
ok(memcmp(obuf, pbuf, sizeof(obuf)) == 0, "content 3a check\n");
pbuf += sizeof(obuf);
ok(memcmp(obuf2, pbuf, sizeof(obuf2)) == 0, "content 3b check\n");
/* Multiple writes in the reverse direction */
memset(ibuf, 0, sizeof(ibuf));
ok(WriteFile(hFile, obuf, sizeof(obuf), &written, NULL), "WriteFile4a\n");
ok(written == sizeof(obuf), "write file len 4a\n");
ok(WriteFile(hFile, obuf2, sizeof(obuf2), &written, NULL), " WriteFile4b\n");
ok(written == sizeof(obuf2), "write file len 4b\n");
ok(PeekNamedPipe(hnp, ibuf, sizeof(ibuf), &readden, &avail, NULL), "Peek4\n");
if (pipemode == PIPE_TYPE_BYTE) {
todo_wine {
/* should return all 23 bytes */
ok(readden == sizeof(obuf) + sizeof(obuf2), "peek4 got %ld bytes\n", readden);
}
}
else
ok(readden == sizeof(obuf), "peek4 got %ld bytes\n", readden);
todo_wine {
ok(avail == sizeof(obuf) + sizeof(obuf2), "peek4 got %ld bytes available\n", avail);
}
pbuf = ibuf;
ok(memcmp(obuf, pbuf, sizeof(obuf)) == 0, "pipe content 4a check\n");
if (pipemode == PIPE_TYPE_BYTE) {
todo_wine {
pbuf += sizeof(obuf);
ok(memcmp(obuf2, pbuf, sizeof(obuf2)) == 0, "pipe content 4b check\n");
}
}
ok(ReadFile(hnp, ibuf, sizeof(ibuf), &readden, NULL), "ReadFile\n");
if (pipemode == PIPE_TYPE_BYTE) {
ok(readden == sizeof(obuf) + sizeof(obuf2), "read 4 got %ld bytes\n", readden);
}
else {
todo_wine {
ok(readden == sizeof(obuf), "read 4 got %ld bytes\n", readden);
}
}
pbuf = ibuf;
ok(memcmp(obuf, pbuf, sizeof(obuf)) == 0, "content 4a check\n");
if (pipemode == PIPE_TYPE_BYTE) {
pbuf += sizeof(obuf);
ok(memcmp(obuf2, pbuf, sizeof(obuf2)) == 0, "content 4b check\n");
}
/* Test reading of multiple writes after a mode change
(CreateFile always creates a byte mode pipe) */
lpmode = PIPE_READMODE_MESSAGE;
if (pipemode == PIPE_TYPE_BYTE) {
/* trying to change the client end of a byte pipe to message mode should fail */
ok(!SetNamedPipeHandleState(hFile, &lpmode, NULL, NULL), "Change mode\n");
}
else {
todo_wine {
ok(SetNamedPipeHandleState(hFile, &lpmode, NULL, NULL), "Change mode\n");
}
memset(ibuf, 0, sizeof(ibuf));
ok(WriteFile(hnp, obuf, sizeof(obuf), &written, NULL), "WriteFile5a\n");
ok(written == sizeof(obuf), "write file len 3a\n");
ok(WriteFile(hnp, obuf2, sizeof(obuf2), &written, NULL), " WriteFile5b\n");
ok(written == sizeof(obuf2), "write file len 3b\n");
ok(PeekNamedPipe(hFile, ibuf, sizeof(ibuf), &readden, &avail, NULL), "Peek5\n");
ok(readden == sizeof(obuf), "peek5 got %ld bytes\n", readden);
todo_wine {
ok(avail == sizeof(obuf) + sizeof(obuf2), "peek5 got %ld bytes available\n", avail);
}
pbuf = ibuf;
ok(memcmp(obuf, pbuf, sizeof(obuf)) == 0, "content 5a check\n");
ok(ReadFile(hFile, ibuf, sizeof(ibuf), &readden, NULL), "ReadFile\n");
todo_wine {
ok(readden == sizeof(obuf), "read 5 got %ld bytes\n", readden);
}
pbuf = ibuf;
ok(memcmp(obuf, pbuf, sizeof(obuf)) == 0, "content 5a check\n");
/* Multiple writes in the reverse direction */
/* the write of obuf2 from write4 should still be in the buffer */
ok(PeekNamedPipe(hnp, ibuf, sizeof(ibuf), &readden, &avail, NULL), "Peek6a\n");
todo_wine {
ok(readden == sizeof(obuf2), "peek6a got %ld bytes\n", readden);
ok(avail == sizeof(obuf2), "peek6a got %ld bytes available\n", avail);
}
if (avail > 0) {
ok(ReadFile(hnp, ibuf, sizeof(ibuf), &readden, NULL), "ReadFile\n");
ok(readden == sizeof(obuf2), "read 6a got %ld bytes\n", readden);
pbuf = ibuf;
ok(memcmp(obuf2, pbuf, sizeof(obuf2)) == 0, "content 6a check\n");
}
memset(ibuf, 0, sizeof(ibuf));
ok(WriteFile(hFile, obuf, sizeof(obuf), &written, NULL), "WriteFile6a\n");
ok(written == sizeof(obuf), "write file len 6a\n");
ok(WriteFile(hFile, obuf2, sizeof(obuf2), &written, NULL), " WriteFile6b\n");
ok(written == sizeof(obuf2), "write file len 6b\n");
ok(PeekNamedPipe(hnp, ibuf, sizeof(ibuf), &readden, &avail, NULL), "Peek6\n");
ok(readden == sizeof(obuf), "peek6 got %ld bytes\n", readden);
todo_wine {
ok(avail == sizeof(obuf) + sizeof(obuf2), "peek6b got %ld bytes available\n", avail);
}
pbuf = ibuf;
ok(memcmp(obuf, pbuf, sizeof(obuf)) == 0, "content 6a check\n");
ok(ReadFile(hnp, ibuf, sizeof(ibuf), &readden, NULL), "ReadFile\n");
todo_wine {
ok(readden == sizeof(obuf), "read 6b got %ld bytes\n", readden);
}
pbuf = ibuf;
ok(memcmp(obuf, pbuf, sizeof(obuf)) == 0, "content 6a check\n");
}
/* Picky conformance tests */
@ -596,6 +745,8 @@ START_TEST(pipe)
trace("test 3 of 4:\n");
test_NamedPipe_2();
trace("test 4 of 4:\n");
test_CreateNamedPipe();
test_CreateNamedPipe(PIPE_TYPE_BYTE);
trace("all tests done\n");
test_CreateNamedPipe(PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE);
trace("all tests done\n");
}