localspl/tests: Open the default Xcv-channel only once.

This commit is contained in:
Detlef Riekenberg 2007-03-19 00:09:31 +01:00 committed by Alexandre Julliard
parent c5da6019d3
commit fd37d30a26
1 changed files with 12 additions and 72 deletions

View File

@ -65,6 +65,7 @@ static BOOL (WINAPI *pAddPortUI)(PCWSTR, HWND, PCWSTR, PWSTR *);
static BOOL (WINAPI *pConfigurePortUI)(PCWSTR, HWND, PCWSTR); static BOOL (WINAPI *pConfigurePortUI)(PCWSTR, HWND, PCWSTR);
static BOOL (WINAPI *pDeletePortUI)(PCWSTR, HWND, PCWSTR); static BOOL (WINAPI *pDeletePortUI)(PCWSTR, HWND, PCWSTR);
static HANDLE hXcv;
static HANDLE hXcv_noaccess; static HANDLE hXcv_noaccess;
/* ########################### */ /* ########################### */
@ -382,15 +383,8 @@ static void test_XcvClosePort(void)
static void test_XcvDataPort_AddPort(void) static void test_XcvDataPort_AddPort(void)
{ {
DWORD res; DWORD res;
HANDLE hXcv;
hXcv = (HANDLE) 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pXcvOpenPort(emptyW, SERVER_ALL_ACCESS, &hXcv);
ok(res, "hXcv: %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv);
if (!res) return;
/* /*
* The following tests crash with native localspl.dll on w2k and xp, * The following tests crash with native localspl.dll on w2k and xp,
* but it works, when the native dll (w2k and xp) is used in wine. * but it works, when the native dll (w2k and xp) is used in wine.
@ -427,7 +421,6 @@ static void test_XcvDataPort_AddPort(void)
res = pXcvDataPort(hXcv, cmd_DeletePortW, (PBYTE) tempfileW, (lstrlenW(tempfileW) + 1) * sizeof(WCHAR), NULL, 0, NULL); res = pXcvDataPort(hXcv, cmd_DeletePortW, (PBYTE) tempfileW, (lstrlenW(tempfileW) + 1) * sizeof(WCHAR), NULL, 0, NULL);
} }
pXcvClosePort(hXcv);
} }
/* ########################### */ /* ########################### */
@ -437,28 +430,19 @@ static void test_XcvDataPort_ConfigureLPTPortCommandOK(void)
CHAR org_value[16]; CHAR org_value[16];
CHAR buffer[16]; CHAR buffer[16];
HKEY hroot = NULL; HKEY hroot = NULL;
HANDLE hXcv;
DWORD res; DWORD res;
DWORD needed; DWORD needed;
hXcv = (HANDLE) 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pXcvOpenPort(emptyW, SERVER_ACCESS_ADMINISTER, &hXcv);
ok(res, "hXcv: %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv);
if (!res) return;
/* Read the original value from the registry */ /* Read the original value from the registry */
res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, WinNT_CV_WindowsA, 0, KEY_ALL_ACCESS, &hroot); res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, WinNT_CV_WindowsA, 0, KEY_ALL_ACCESS, &hroot);
if (res == ERROR_ACCESS_DENIED) { if (res == ERROR_ACCESS_DENIED) {
pXcvClosePort(hXcv);
skip("ACCESS_DENIED\n"); skip("ACCESS_DENIED\n");
return; return;
} }
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
/* unable to open the registry: skip the test */ /* unable to open the registry: skip the test */
pXcvClosePort(hXcv);
skip("got %d\n", res); skip("got %d\n", res);
return; return;
} }
@ -476,7 +460,6 @@ static void test_XcvDataPort_ConfigureLPTPortCommandOK(void)
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
res = pXcvDataPort(hXcv, cmd_ConfigureLPTPortCommandOKW, (PBYTE) num_0W, sizeof(num_0W), NULL, 0, &needed); res = pXcvDataPort(hXcv, cmd_ConfigureLPTPortCommandOKW, (PBYTE) num_0W, sizeof(num_0W), NULL, 0, &needed);
if (res == ERROR_INVALID_PARAMETER) { if (res == ERROR_INVALID_PARAMETER) {
pXcvClosePort(hXcv);
skip("'ConfigureLPTPortCommandOK' not supported\n"); skip("'ConfigureLPTPortCommandOK' not supported\n");
return; return;
} }
@ -533,7 +516,6 @@ static void test_XcvDataPort_ConfigureLPTPortCommandOK(void)
} }
RegCloseKey(hroot); RegCloseKey(hroot);
pXcvClosePort(hXcv);
} }
@ -542,16 +524,9 @@ static void test_XcvDataPort_ConfigureLPTPortCommandOK(void)
static void test_XcvDataPort_DeletePort(void) static void test_XcvDataPort_DeletePort(void)
{ {
DWORD res; DWORD res;
HANDLE hXcv;
DWORD needed; DWORD needed;
hXcv = (HANDLE) 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pXcvOpenPort(emptyW, SERVER_ALL_ACCESS, &hXcv);
ok(res, "hXcv: %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv);
if (!res) return;
/* cleanup: just to make sure */ /* cleanup: just to make sure */
needed = (DWORD) 0xdeadbeef; needed = (DWORD) 0xdeadbeef;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
@ -574,7 +549,6 @@ static void test_XcvDataPort_DeletePort(void)
/* emptyW as Portname: ERROR_FILE_NOT_FOUND is returned */ /* emptyW as Portname: ERROR_FILE_NOT_FOUND is returned */
/* NULL as Portname: Native localspl.dll crashed */ /* NULL as Portname: Native localspl.dll crashed */
pXcvClosePort(hXcv);
} }
/* ########################### */ /* ########################### */
@ -583,25 +557,17 @@ static void test_XcvDataPort_GetTransmissionRetryTimeout(void)
{ {
CHAR org_value[16]; CHAR org_value[16];
HKEY hroot = NULL; HKEY hroot = NULL;
HANDLE hXcv;
DWORD buffer[2]; DWORD buffer[2];
DWORD res; DWORD res;
DWORD needed; DWORD needed;
DWORD len; DWORD len;
hXcv = (HANDLE) 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pXcvOpenPort(emptyW, SERVER_ACCESS_ADMINISTER, &hXcv);
ok(res, "hXcv: %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv);
if (!res) return;
/* ask for needed size */ /* ask for needed size */
needed = (DWORD) 0xdeadbeef; needed = (DWORD) 0xdeadbeef;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
res = pXcvDataPort(hXcv, cmd_GetTransmissionRetryTimeoutW, NULL, 0, NULL, 0, &needed); res = pXcvDataPort(hXcv, cmd_GetTransmissionRetryTimeoutW, NULL, 0, NULL, 0, &needed);
if (res == ERROR_INVALID_PARAMETER) { if (res == ERROR_INVALID_PARAMETER) {
pXcvClosePort(hXcv);
skip("'GetTransmissionRetryTimeout' not supported\n"); skip("'GetTransmissionRetryTimeout' not supported\n");
return; return;
} }
@ -614,14 +580,12 @@ static void test_XcvDataPort_GetTransmissionRetryTimeout(void)
/* Read the original value from the registry */ /* Read the original value from the registry */
res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, WinNT_CV_WindowsA, 0, KEY_ALL_ACCESS, &hroot); res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, WinNT_CV_WindowsA, 0, KEY_ALL_ACCESS, &hroot);
if (res == ERROR_ACCESS_DENIED) { if (res == ERROR_ACCESS_DENIED) {
pXcvClosePort(hXcv);
skip("ACCESS_DENIED\n"); skip("ACCESS_DENIED\n");
return; return;
} }
if (res != ERROR_SUCCESS) { if (res != ERROR_SUCCESS) {
/* unable to open the registry: skip the test */ /* unable to open the registry: skip the test */
pXcvClosePort(hXcv);
skip("got %d\n", res); skip("got %d\n", res);
return; return;
} }
@ -700,7 +664,6 @@ static void test_XcvDataPort_GetTransmissionRetryTimeout(void)
} }
RegCloseKey(hroot); RegCloseKey(hroot);
pXcvClosePort(hXcv);
} }
/* ########################### */ /* ########################### */
@ -708,24 +671,16 @@ static void test_XcvDataPort_GetTransmissionRetryTimeout(void)
static void test_XcvDataPort_MonitorUI(void) static void test_XcvDataPort_MonitorUI(void)
{ {
DWORD res; DWORD res;
HANDLE hXcv;
BYTE buffer[MAX_PATH + 2]; BYTE buffer[MAX_PATH + 2];
DWORD needed; DWORD needed;
DWORD len; DWORD len;
hXcv = (HANDLE) 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pXcvOpenPort(emptyW, SERVER_ACCESS_ADMINISTER, &hXcv);
ok(res, "returned %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv);
if (!res) return;
/* ask for needed size */ /* ask for needed size */
needed = (DWORD) 0xdeadbeef; needed = (DWORD) 0xdeadbeef;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
res = pXcvDataPort(hXcv, cmd_MonitorUIW, NULL, 0, NULL, 0, &needed); res = pXcvDataPort(hXcv, cmd_MonitorUIW, NULL, 0, NULL, 0, &needed);
if (res == ERROR_INVALID_PARAMETER) { if (res == ERROR_INVALID_PARAMETER) {
pXcvClosePort(hXcv);
skip("'MonitorUI' nor supported\n"); skip("'MonitorUI' nor supported\n");
return; return;
} }
@ -734,7 +689,6 @@ static void test_XcvDataPort_MonitorUI(void)
" and '<= MAX_PATH')\n", res, GetLastError(), needed); " and '<= MAX_PATH')\n", res, GetLastError(), needed);
if (needed > MAX_PATH) { if (needed > MAX_PATH) {
pXcvClosePort(hXcv);
skip("buffer overflow (%u)\n", needed); skip("buffer overflow (%u)\n", needed);
return; return;
} }
@ -796,9 +750,6 @@ static void test_XcvDataPort_MonitorUI(void)
"(expected 'ERROR_SUCCESS')\n", res, GetLastError(), needed); "(expected 'ERROR_SUCCESS')\n", res, GetLastError(), needed);
pXcvClosePort(hXcv);
/* small check without access-rights: */ /* small check without access-rights: */
if (!hXcv_noaccess) return; if (!hXcv_noaccess) return;
@ -816,22 +767,13 @@ static void test_XcvDataPort_MonitorUI(void)
static void test_XcvDataPort_PortIsValid(void) static void test_XcvDataPort_PortIsValid(void)
{ {
DWORD res; DWORD res;
HANDLE hXcv;
DWORD needed; DWORD needed;
hXcv = (HANDLE) 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pXcvOpenPort(emptyW, SERVER_ACCESS_ADMINISTER, &hXcv);
ok(res, "hXcv: %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv);
if (!res) return;
/* normal use: "LPT1:" */ /* normal use: "LPT1:" */
needed = (DWORD) 0xdeadbeef; needed = (DWORD) 0xdeadbeef;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
res = pXcvDataPort(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, &needed); res = pXcvDataPort(hXcv, cmd_PortIsValidW, (PBYTE) portname_lpt1W, sizeof(portname_lpt1W), NULL, 0, &needed);
if (res == ERROR_INVALID_PARAMETER) { if (res == ERROR_INVALID_PARAMETER) {
pXcvClosePort(hXcv);
skip("'PostIsValid' not supported\n"); skip("'PostIsValid' not supported\n");
return; return;
} }
@ -948,8 +890,6 @@ static void test_XcvDataPort_PortIsValid(void)
"returned %d with %u and 0x%x (expected ERROR_SUCCESS)\n", "returned %d with %u and 0x%x (expected ERROR_SUCCESS)\n",
res, GetLastError(), needed); res, GetLastError(), needed);
pXcvClosePort(hXcv);
/* small check without access-rights: */ /* small check without access-rights: */
if (!hXcv_noaccess) return; if (!hXcv_noaccess) return;
@ -1076,26 +1016,24 @@ START_TEST(localmon)
GET_MONITOR_FUNC(XcvClosePort); GET_MONITOR_FUNC(XcvClosePort);
if ((pXcvOpenPort) && (pXcvDataPort) && (pXcvClosePort)) { if ((pXcvOpenPort) && (pXcvDataPort) && (pXcvClosePort)) {
SetLastError(0xdeadbeef);
res = pXcvOpenPort(emptyW, 0, &hXcv);
ok(res, "hXcv: %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv);
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
res = pXcvOpenPort(emptyW, 0, &hXcv_noaccess); res = pXcvOpenPort(emptyW, 0, &hXcv_noaccess);
ok(res, "hXcv_noaccess: %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv_noaccess); ok(res, "hXcv_noaccess: %d with %u and %p (expected '!= 0')\n", res, GetLastError(), hXcv_noaccess);
} }
} }
if ((!pInitializePrintMonitorUI) && (pXcvOpenPort) && (pXcvDataPort) && (pXcvClosePort)) { if ((!pInitializePrintMonitorUI) && (hXcv)) {
/* The user interface for "Local Ports" is in a separate dll since w2k */ /* The user interface for "Local Ports" is in a separate dll since w2k */
BYTE buffer[MAX_PATH]; BYTE buffer[MAX_PATH];
DWORD res;
DWORD len; DWORD len;
HANDLE hXcv;
res = pXcvOpenPort(emptyW, SERVER_ACCESS_ADMINISTER, &hXcv); res = pXcvDataPort(hXcv, cmd_MonitorUIW, NULL, 0, buffer, MAX_PATH, &len);
if (res) { if (res == ERROR_SUCCESS) hlocalui = LoadLibraryW( (LPWSTR) buffer);
res = pXcvDataPort(hXcv, cmd_MonitorUIW, NULL, 0, buffer, MAX_PATH, &len); if (hlocalui) pInitializePrintMonitorUI = (void *) GetProcAddress(hlocalui, "InitializePrintMonitorUI");
if (res == ERROR_SUCCESS) hlocalui = LoadLibraryW( (LPWSTR) buffer);
if (hlocalui) pInitializePrintMonitorUI = (void *) GetProcAddress(hlocalui, "InitializePrintMonitorUI");
pXcvClosePort(hXcv);
}
} }
if (pInitializePrintMonitorUI) { if (pInitializePrintMonitorUI) {
@ -1119,7 +1057,7 @@ START_TEST(localmon)
test_ConfigurePort(); test_ConfigurePort();
test_DeletePort(); test_DeletePort();
test_EnumPorts(); test_EnumPorts();
if ((pXcvOpenPort == NULL) || (pXcvDataPort == NULL) || (pXcvClosePort == NULL)) { if ( !hXcv ) {
skip("Xcv not supported\n"); skip("Xcv not supported\n");
} }
else else
@ -1132,6 +1070,8 @@ START_TEST(localmon)
test_XcvDataPort_MonitorUI(); test_XcvDataPort_MonitorUI();
test_XcvDataPort_PortIsValid(); test_XcvDataPort_PortIsValid();
test_XcvOpenPort(); test_XcvOpenPort();
pXcvClosePort(hXcv);
} }
if (hXcv_noaccess) pXcvClosePort(hXcv_noaccess); if (hXcv_noaccess) pXcvClosePort(hXcv_noaccess);