Commit b13c498c authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

winspool: Add a test for GetPrinterDriver, make it pass under Wine.

parent 590f6fae
...@@ -575,7 +575,7 @@ void WINSPOOL_LoadSystemPrinters(void) ...@@ -575,7 +575,7 @@ void WINSPOOL_LoadSystemPrinters(void)
WCHAR PrinterName[256]; WCHAR PrinterName[256];
BOOL done = FALSE; BOOL done = FALSE;
di3a.cVersion = 0x400; di3a.cVersion = (GetVersion() & 0x80000000) ? 0 : 3; /* FIXME: add 1, 2 */
di3a.pName = "PS Driver"; di3a.pName = "PS Driver";
di3a.pEnvironment = NULL; /* NULL means auto */ di3a.pEnvironment = NULL; /* NULL means auto */
di3a.pDriverPath = "wineps16"; di3a.pDriverPath = "wineps16";
...@@ -2589,7 +2589,13 @@ static BOOL WINSPOOL_GetStringFromReg(HKEY hkey, LPCWSTR ValueName, LPBYTE ptr, ...@@ -2589,7 +2589,13 @@ static BOOL WINSPOOL_GetStringFromReg(HKEY hkey, LPCWSTR ValueName, LPBYTE ptr,
*needed = 0; *needed = 0;
return FALSE; return FALSE;
} }
/* add space for terminating '\0' */
sz += unicode ? sizeof(WCHAR) : 1;
*needed = sz; *needed = sz;
if (ptr)
TRACE("%s: %s\n", debugstr_w(ValueName), unicode ? debugstr_w((LPCWSTR)ptr) : debugstr_a((LPCSTR)ptr));
return TRUE; return TRUE;
} }
...@@ -3326,7 +3332,8 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3326,7 +3332,8 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
DWORD cbBuf, /* size of string buffer */ DWORD cbBuf, /* size of string buffer */
LPDWORD pcbNeeded, /* space needed for str. */ LPDWORD pcbNeeded, /* space needed for str. */
BOOL unicode) /* type of strings */ BOOL unicode) /* type of strings */
{ DWORD dw, size, tmp, type; {
DWORD size, tmp;
HKEY hkeyDriver; HKEY hkeyDriver;
LPBYTE strPtr = pDriverStrings; LPBYTE strPtr = pDriverStrings;
...@@ -3351,7 +3358,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3351,7 +3358,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
return TRUE; return TRUE;
} else { } else {
if(ptr) if(ptr)
((PDRIVER_INFO_3W) ptr)->pName = (LPWSTR) strPtr; ((PDRIVER_INFO_2W) ptr)->pName = (LPWSTR) strPtr;
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL; strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
} }
...@@ -3361,12 +3368,8 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3361,12 +3368,8 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
return FALSE; return FALSE;
} }
size = sizeof(dw); if(ptr)
if(RegQueryValueExA(hkeyDriver, "Version", 0, &type, (PBYTE)&dw, &size) != ((PDRIVER_INFO_2A) ptr)->cVersion = (GetVersion() & 0x80000000) ? 0 : 3; /* FIXME: add 1, 2 */
ERROR_SUCCESS)
WARN("Can't get Version\n");
else if(ptr)
((PDRIVER_INFO_3A) ptr)->cVersion = dw;
if(!pEnvironment) if(!pEnvironment)
pEnvironment = (LPWSTR)DefaultEnvironmentW; pEnvironment = (LPWSTR)DefaultEnvironmentW;
...@@ -3383,7 +3386,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3383,7 +3386,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
WideCharToMultiByte(CP_ACP, 0, pEnvironment, -1, WideCharToMultiByte(CP_ACP, 0, pEnvironment, -1,
(LPSTR)strPtr, size, NULL, NULL); (LPSTR)strPtr, size, NULL, NULL);
if(ptr) if(ptr)
((PDRIVER_INFO_3W) ptr)->pEnvironment = (LPWSTR)strPtr; ((PDRIVER_INFO_2W) ptr)->pEnvironment = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL; strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
} }
...@@ -3394,7 +3397,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3394,7 +3397,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
WINSPOOL_GetStringFromReg(hkeyDriver, DriverW, strPtr, size, &tmp, WINSPOOL_GetStringFromReg(hkeyDriver, DriverW, strPtr, size, &tmp,
unicode); unicode);
if(ptr) if(ptr)
((PDRIVER_INFO_3W) ptr)->pDriverPath = (LPWSTR)strPtr; ((PDRIVER_INFO_2W) ptr)->pDriverPath = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL; strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
} }
...@@ -3405,7 +3408,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3405,7 +3408,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
WINSPOOL_GetStringFromReg(hkeyDriver, Data_FileW, strPtr, size, WINSPOOL_GetStringFromReg(hkeyDriver, Data_FileW, strPtr, size,
&tmp, unicode); &tmp, unicode);
if(ptr) if(ptr)
((PDRIVER_INFO_3W) ptr)->pDataFile = (LPWSTR)strPtr; ((PDRIVER_INFO_2W) ptr)->pDataFile = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
...@@ -3416,7 +3419,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3416,7 +3419,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
WINSPOOL_GetStringFromReg(hkeyDriver, Configuration_FileW, strPtr, WINSPOOL_GetStringFromReg(hkeyDriver, Configuration_FileW, strPtr,
size, &tmp, unicode); size, &tmp, unicode);
if(ptr) if(ptr)
((PDRIVER_INFO_3W) ptr)->pConfigFile = (LPWSTR)strPtr; ((PDRIVER_INFO_2W) ptr)->pConfigFile = (LPWSTR)strPtr;
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
...@@ -3426,7 +3429,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3426,7 +3429,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
return TRUE; return TRUE;
} }
if(WINSPOOL_GetStringFromReg(hkeyDriver, Help_FileW, strPtr, 0, &size, if (Level != 5 && WINSPOOL_GetStringFromReg(hkeyDriver, Help_FileW, strPtr, 0, &size,
unicode)) { unicode)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
...@@ -3437,7 +3440,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3437,7 +3440,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
if(WINSPOOL_GetStringFromReg(hkeyDriver, Dependent_FilesW, strPtr, 0, if (Level != 5 && WINSPOOL_GetStringFromReg(hkeyDriver, Dependent_FilesW, strPtr, 0,
&size, unicode)) { &size, unicode)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
...@@ -3448,7 +3451,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3448,7 +3451,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
if(WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr, 0, &size, if (Level != 5 && WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr, 0, &size,
unicode)) { unicode)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
...@@ -3459,7 +3462,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg( ...@@ -3459,7 +3462,7 @@ static BOOL WINSPOOL_GetDriverInfoFromReg(
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL; strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
} }
if(WINSPOOL_GetStringFromReg(hkeyDriver, DatatypeW, strPtr, 0, &size, if (Level != 5 && WINSPOOL_GetStringFromReg(hkeyDriver, DatatypeW, strPtr, 0, &size,
unicode)) { unicode)) {
*pcbNeeded += size; *pcbNeeded += size;
if(*pcbNeeded <= cbBuf) if(*pcbNeeded <= cbBuf)
...@@ -3498,7 +3501,7 @@ static BOOL WINSPOOL_GetPrinterDriver(HANDLE hPrinter, LPWSTR pEnvironment, ...@@ -3498,7 +3501,7 @@ static BOOL WINSPOOL_GetPrinterDriver(HANDLE hPrinter, LPWSTR pEnvironment,
SetLastError(ERROR_INVALID_HANDLE); SetLastError(ERROR_INVALID_HANDLE);
return FALSE; return FALSE;
} }
if(Level < 1 || Level > 3) { if(Level < 1 || Level > 6) {
SetLastError(ERROR_INVALID_LEVEL); SetLastError(ERROR_INVALID_LEVEL);
return FALSE; return FALSE;
} }
...@@ -3541,6 +3544,15 @@ static BOOL WINSPOOL_GetPrinterDriver(HANDLE hPrinter, LPWSTR pEnvironment, ...@@ -3541,6 +3544,15 @@ static BOOL WINSPOOL_GetPrinterDriver(HANDLE hPrinter, LPWSTR pEnvironment,
case 3: case 3:
size = sizeof(DRIVER_INFO_3W); size = sizeof(DRIVER_INFO_3W);
break; break;
case 4:
size = sizeof(DRIVER_INFO_4W);
break;
case 5:
size = sizeof(DRIVER_INFO_5W);
break;
case 6:
size = sizeof(DRIVER_INFO_6W);
break;
default: default:
ERR("Invalid level\n"); ERR("Invalid level\n");
return FALSE; return FALSE;
......
/* /*
* Copyright (C) 2003, 2004 Stefan Leichter * Copyright (C) 2003, 2004 Stefan Leichter
* Copyright (C) 2005, 2006 Detlef Riekenberg * Copyright (C) 2005, 2006 Detlef Riekenberg
* Copyright (C) 2006 Dmitry Timoshkov
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -911,6 +912,92 @@ static void test_SetDefaultPrinter(void) ...@@ -911,6 +912,92 @@ static void test_SetDefaultPrinter(void)
} }
static void test_GetPrinterDriver(void)
{
LPSTR default_printer;
HANDLE hprn;
BOOL ret;
BYTE *buf;
INT level;
DWORD needed, filled;
default_printer = find_default_printer();
if (!default_printer)
{
trace("There is no default printer installed, skiping the test\n");
return;
}
hprn = 0;
ret = OpenPrinter(default_printer, &hprn, NULL);
if (!ret)
{
trace("There is no printers installed, skiping the test\n");
return;
}
ok(hprn != 0, "wrong hprn %p\n", hprn);
for (level = -1; level <= 7; level++)
{
SetLastError(0xdeadbeef);
needed = (DWORD)-1;
ret = GetPrinterDriver(hprn, NULL, level, NULL, 0, &needed);
ok(!ret, "level %d: GetPrinterDriver should fail\n", level);
if (level >= 1 && level <= 6)
{
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error %ld\n", GetLastError());
ok(needed > 0,"not expected needed buffer size %ld\n", needed);
}
else
{
ok(GetLastError() == ERROR_INVALID_LEVEL, "wrong error %ld\n", GetLastError());
ok(needed == (DWORD)-1,"not expected needed buffer size %ld\n", needed);
continue;
}
buf = HeapAlloc(GetProcessHeap(), 0, needed);
SetLastError(0xdeadbeef);
filled = -1;
ret = GetPrinterDriver(hprn, NULL, level, buf, needed, &filled);
ok(ret, "level %d: GetPrinterDriver error %ld\n", level, GetLastError());
ok(needed == filled, "needed %ld != filled %ld\n", needed, filled);
if (level == 2)
{
DRIVER_INFO_2 *di_2 = (DRIVER_INFO_2 *)buf;
DWORD calculated = sizeof(*di_2);
ok(di_2->cVersion >= 0 && di_2->cVersion <= 3, "di_2->cVersion = %ld\n", di_2->cVersion);
ok(di_2->pName != NULL, "not expected NULL ptr\n");
ok(di_2->pEnvironment != NULL, "not expected NULL ptr\n");
ok(di_2->pDriverPath != NULL, "not expected NULL ptr\n");
ok(di_2->pDataFile != NULL, "not expected NULL ptr\n");
ok(di_2->pConfigFile != NULL, "not expected NULL ptr\n");
trace("cVersion %ld\n", di_2->cVersion);
trace("pName %s\n", di_2->pName);
calculated += strlen(di_2->pName) + 1;
trace("pEnvironment %s\n", di_2->pEnvironment);
calculated += strlen(di_2->pEnvironment) + 1;
trace("pDriverPath %s\n", di_2->pDriverPath);
calculated += strlen(di_2->pDriverPath) + 1;
trace("pDataFile %s\n", di_2->pDataFile);
calculated += strlen(di_2->pDataFile) + 1;
trace("pConfigFile %s\n", di_2->pConfigFile);
calculated += strlen(di_2->pConfigFile) + 1;
/* XP allocates memory for both ANSI and unicode names */
ok(filled >= calculated,"calculated %ld != filled %ld\n", calculated, filled);
}
HeapFree(GetProcessHeap(), 0, buf);
}
SetLastError(0xdeadbeef);
ret = ClosePrinter(hprn);
ok(ret, "ClosePrinter error %ld\n", GetLastError());
}
START_TEST(info) START_TEST(info)
{ {
...@@ -925,5 +1012,6 @@ START_TEST(info) ...@@ -925,5 +1012,6 @@ START_TEST(info)
test_GetDefaultPrinter(); test_GetDefaultPrinter();
test_GetPrinterDriverDirectory(); test_GetPrinterDriverDirectory();
test_OpenPrinter(); test_OpenPrinter();
test_GetPrinterDriver();
test_SetDefaultPrinter(); test_SetDefaultPrinter();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment