winspool/tests: Add tests for EnumPorts.
This commit is contained in:
parent
ecce2d898b
commit
d3a1737dac
|
@ -619,6 +619,105 @@ static void test_EnumMonitors(void)
|
||||||
} /* for(level ... */
|
} /* for(level ... */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ########################### */
|
||||||
|
|
||||||
|
static void test_EnumPorts(void)
|
||||||
|
{
|
||||||
|
DWORD res;
|
||||||
|
DWORD level;
|
||||||
|
LPBYTE buffer;
|
||||||
|
DWORD cbBuf;
|
||||||
|
DWORD pcbNeeded;
|
||||||
|
DWORD pcReturned;
|
||||||
|
|
||||||
|
/* valid levels are 1 and 2 */
|
||||||
|
for(level = 0; level < 4; level++) {
|
||||||
|
|
||||||
|
cbBuf = 0xdeadbeef;
|
||||||
|
pcReturned = 0xdeadbeef;
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
res = EnumPortsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
|
||||||
|
RETURN_ON_DEACTIVATED_SPOOLER(res)
|
||||||
|
|
||||||
|
/* use only a short test, when we test with an invalid level */
|
||||||
|
if(!level || (level > 2)) {
|
||||||
|
/* NT: ERROR_INVALID_LEVEL, 9x: success */
|
||||||
|
ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
|
||||||
|
(res && (pcReturned == 0)),
|
||||||
|
"(%d) returned %d with %d and 0x%08x (expected '0' with " \
|
||||||
|
"ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
|
||||||
|
level, res, GetLastError(), pcReturned);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Level 2 is not supported on NT 3.x */
|
||||||
|
if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
|
||||||
|
trace("Level %d not supported, skipping tests\n", level);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
|
||||||
|
"(%d) returned %d with %d (expected '0' with " \
|
||||||
|
"ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
|
||||||
|
|
||||||
|
buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
|
||||||
|
if (buffer == NULL) continue;
|
||||||
|
|
||||||
|
pcbNeeded = 0xdeadbeef;
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
|
||||||
|
ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
|
||||||
|
ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
|
||||||
|
/* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
|
||||||
|
|
||||||
|
pcbNeeded = 0xdeadbeef;
|
||||||
|
pcReturned = 0xdeadbeef;
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
res = EnumPortsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
|
||||||
|
ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
|
||||||
|
ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
|
||||||
|
|
||||||
|
pcbNeeded = 0xdeadbeef;
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
res = EnumPortsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
|
||||||
|
ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
|
||||||
|
"(%d) returned %d with %d (expected '0' with " \
|
||||||
|
"ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
|
||||||
|
ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Do not add this test:
|
||||||
|
res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
|
||||||
|
w2k+: RPC_X_NULL_REF_POINTER
|
||||||
|
NT3.5: ERROR_INVALID_USER_BUFFER
|
||||||
|
win9x: crash in winspool.drv
|
||||||
|
*/
|
||||||
|
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
res = EnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
|
||||||
|
/* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
|
||||||
|
ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
|
||||||
|
( res && (GetLastError() == ERROR_SUCCESS) ),
|
||||||
|
"(%d) returned %d with %d (expected '0' with " \
|
||||||
|
"RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
|
||||||
|
level, res, GetLastError());
|
||||||
|
|
||||||
|
|
||||||
|
SetLastError(0xdeadbeef);
|
||||||
|
res = EnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
|
||||||
|
/* NT: RPC_X_NULL_REF_POINTER (1780), 9x: success */
|
||||||
|
ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
|
||||||
|
( res && (GetLastError() == ERROR_SUCCESS) ),
|
||||||
|
"(%d) returned %d with %d (expected '0' with " \
|
||||||
|
"RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
|
||||||
|
level, res, GetLastError());
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ########################### */
|
||||||
|
|
||||||
static void test_GetDefaultPrinter(void)
|
static void test_GetDefaultPrinter(void)
|
||||||
{
|
{
|
||||||
|
@ -1413,6 +1512,7 @@ START_TEST(info)
|
||||||
test_EnumForms(NULL);
|
test_EnumForms(NULL);
|
||||||
if (default_printer) test_EnumForms(default_printer);
|
if (default_printer) test_EnumForms(default_printer);
|
||||||
test_EnumMonitors();
|
test_EnumMonitors();
|
||||||
|
test_EnumPorts();
|
||||||
test_GetDefaultPrinter();
|
test_GetDefaultPrinter();
|
||||||
test_GetPrinterDriverDirectory();
|
test_GetPrinterDriverDirectory();
|
||||||
test_GetPrintProcessorDirectory();
|
test_GetPrintProcessorDirectory();
|
||||||
|
|
Loading…
Reference in New Issue