localspl/tests: Add tests for EnumPorts.
This commit is contained in:
parent
bffcdd0d3a
commit
74a09f90ca
|
@ -59,6 +59,7 @@ static DWORD (WINAPI *pXcvDataPort)(HANDLE, LPCWSTR, PBYTE, DWORD, PBYTE, DWORD,
|
|||
static BOOL (WINAPI *pXcvClosePort)(HANDLE);
|
||||
|
||||
static WCHAR emptyW[] = {0};
|
||||
static WCHAR invalid_serverW[] = {'\\','\\','i','n','v','a','l','i','d','_','s','e','r','v','e','r',0};
|
||||
static WCHAR Monitors_LocalPortW[] = { \
|
||||
'S','y','s','t','e','m','\\',
|
||||
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
||||
|
@ -69,6 +70,96 @@ static WCHAR Monitors_LocalPortW[] = { \
|
|||
|
||||
/* ##### */
|
||||
|
||||
static void test_EnumPorts(void)
|
||||
{
|
||||
DWORD res;
|
||||
DWORD level;
|
||||
LPBYTE buffer;
|
||||
DWORD cbBuf;
|
||||
DWORD pcbNeeded;
|
||||
DWORD pcReturned;
|
||||
|
||||
if (!pEnumPorts) return;
|
||||
|
||||
/* valid levels are 1 and 2 */
|
||||
for(level = 0; level < 4; level++) {
|
||||
|
||||
cbBuf = 0xdeadbeef;
|
||||
pcReturned = 0xdeadbeef;
|
||||
SetLastError(0xdeadbeef);
|
||||
res = pEnumPorts(NULL, level, NULL, 0, &cbBuf, &pcReturned);
|
||||
|
||||
/* use only a short test, when we test with an invalid level */
|
||||
if(!level || (level > 2)) {
|
||||
/* NT4 fails with ERROR_INVALID_LEVEL (as expected)
|
||||
XP succeeds with ERROR_SUCCESS () */
|
||||
ok( (cbBuf == 0) && (pcReturned == 0),
|
||||
"(%d) returned %d with %d and %d, %d (expected 0, 0)\n",
|
||||
level, res, GetLastError(), cbBuf, pcReturned);
|
||||
continue;
|
||||
}
|
||||
|
||||
ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
|
||||
"(%d) returned %d with %d and %d, %d (expected '0' with " \
|
||||
"ERROR_INSUFFICIENT_BUFFER)\n",
|
||||
level, res, GetLastError(), cbBuf, pcReturned);
|
||||
|
||||
buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf * 2);
|
||||
if (buffer == NULL) continue;
|
||||
|
||||
pcbNeeded = 0xdeadbeef;
|
||||
pcReturned = 0xdeadbeef;
|
||||
SetLastError(0xdeadbeef);
|
||||
res = pEnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
|
||||
ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
|
||||
level, res, GetLastError(), cbBuf, pcReturned);
|
||||
/* We can compare the returned Data with the Registry / "win.ini",[Ports] here */
|
||||
|
||||
pcbNeeded = 0xdeadbeef;
|
||||
pcReturned = 0xdeadbeef;
|
||||
SetLastError(0xdeadbeef);
|
||||
res = pEnumPorts(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
|
||||
ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
|
||||
level, res, GetLastError(), cbBuf, pcReturned);
|
||||
|
||||
pcbNeeded = 0xdeadbeef;
|
||||
pcReturned = 0xdeadbeef;
|
||||
SetLastError(0xdeadbeef);
|
||||
res = pEnumPorts(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
|
||||
ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
|
||||
"(%d) returned %d with %d and %d, %d (expected '0' with " \
|
||||
"ERROR_INSUFFICIENT_BUFFER)\n",
|
||||
level, res, GetLastError(), cbBuf, pcReturned);
|
||||
|
||||
#if 0
|
||||
/* The following tests crash this app with native localmon/localspl */
|
||||
res = pEnumPorts(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
|
||||
res = pEnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
|
||||
res = pEnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
|
||||
#endif
|
||||
|
||||
/* The Servername is ignored */
|
||||
pcbNeeded = 0xdeadbeef;
|
||||
pcReturned = 0xdeadbeef;
|
||||
SetLastError(0xdeadbeef);
|
||||
res = pEnumPorts(emptyW, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
|
||||
ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
|
||||
level, res, GetLastError(), cbBuf, pcReturned);
|
||||
|
||||
pcbNeeded = 0xdeadbeef;
|
||||
pcReturned = 0xdeadbeef;
|
||||
SetLastError(0xdeadbeef);
|
||||
res = pEnumPorts(invalid_serverW, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
|
||||
ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
|
||||
level, res, GetLastError(), cbBuf, pcReturned);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/* ########################### */
|
||||
|
||||
|
||||
static void test_InitializePrintMonitor(void)
|
||||
{
|
||||
LPMONITOREX res;
|
||||
|
@ -150,4 +241,5 @@ START_TEST(localmon)
|
|||
GET_MONITOR_FUNC(XcvClosePort);
|
||||
}
|
||||
test_InitializePrintMonitor();
|
||||
test_EnumPorts();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue