From f2999157f9f7aad84c2030fb84875d616d5c6ec2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnther=20Deschner?= Date: Fri, 15 Jan 2010 16:36:25 +0100 Subject: [PATCH] testprogs: add tests for GetPrinterData{Ex} and EnumPrinterDataEx. Guenther --- testprogs/win32/spoolss/error.c | 2 + testprogs/win32/spoolss/printlib.c | 83 ++++++++++--- testprogs/win32/spoolss/printlib_proto.h | 1 + testprogs/win32/spoolss/spoolss.c | 193 +++++++++++++++++++++++++++++++ 4 files changed, 261 insertions(+), 18 deletions(-) diff --git a/testprogs/win32/spoolss/error.c b/testprogs/win32/spoolss/error.c index 6296f07c358..837cce9705e 100644 --- a/testprogs/win32/spoolss/error.c +++ b/testprogs/win32/spoolss/error.c @@ -113,6 +113,8 @@ const char *errstr(DWORD error) return "ERROR_CANCELLED"; case RPC_S_SERVER_UNAVAILABLE: return "RPC_S_SERVER_UNAVAILABLE"; + case RPC_S_INVALID_NET_ADDR: + return "RPC_S_INVALID_NET_ADDR"; default: break; } diff --git a/testprogs/win32/spoolss/printlib.c b/testprogs/win32/spoolss/printlib.c index 9fc9d046f23..e458e144b53 100644 --- a/testprogs/win32/spoolss/printlib.c +++ b/testprogs/win32/spoolss/printlib.c @@ -21,6 +21,7 @@ #include #include +#include void print_devmode(DEVMODE *pDevModeIn) { @@ -588,35 +589,81 @@ void print_doc_info_1(PDOC_INFO_1 info) return; } -void print_printer_enum_values(PRINTER_ENUM_VALUES *info) +void print_printer_keys(LPSTR buffer) { - DWORD i = 0; + LPSTR p = NULL; - printf("\tValue Name\t= %s [0x%x]\n", info->pValueName, info->cbValueName); - printf("\tType\t\t= 0x%x\n", info->dwType); - printf("\tSize\t\t= 0x%x\n", info->cbData); + p = buffer; - while (i < info->cbData) { - printf("\t0x%x", *(info->pData++)); - if (i%4 == 3) - printf("\n"); - i++; + while (p && *p) { + printf("%s\n", p); + for (; *p; p = CharNext(p)) { + p = CharNext(p); + } } - printf("\n"); +} - return; +static LPSTR reg_type_str(DWORD type) +{ + switch (type) { + case REG_DWORD: + return "REG_DWORD"; + case REG_SZ: + return "REG_SZ"; + case REG_MULTI_SZ: + return "REG_MULTI_SZ"; + case REG_BINARY: + return "REG_BINARY"; + default: + return NULL; + } } -void print_printer_keys(LPSTR buffer) +void print_printer_data(LPSTR keyname, LPSTR valuename, DWORD size, LPBYTE buffer, DWORD type) { + DWORD i = 0; LPSTR p = NULL; - p = buffer; + if (keyname) { + printf("\tKey Name:\t%s\n", keyname); + } - while (p && *p) { - printf("%s\n", p); - for (; *p; p = CharNext(p)) { - p = CharNext(p); + printf("\tValue Name:\t%s\n", valuename); + printf("\tSize: 0x%x (%d)\n", size, size); + printf("\tType:\t\t%s\n", reg_type_str(type)); + + switch (type) { + case REG_SZ: + printf("\t\t%s\n", (LPSTR)buffer); + break; + case REG_MULTI_SZ: + p = (LPSTR)buffer; + while (p && *p) { + printf("%s\n", p); + for (; *p; p = CharNext(p)) { + p = CharNext(p); + } } + break; + case REG_DWORD: + assert(size == 4); + printf("\t\t0x%08x\n", (DWORD)*buffer); + break; + case REG_BINARY: + for (i=0; i < size; i++) { + printf("\t0x%x", buffer[i]); + if (i%4 == 3) { + printf("\n"); + } + } + break; + default: + break; } } + +void print_printer_enum_values(PRINTER_ENUM_VALUES *info) +{ + print_printer_data(NULL, info->pValueName, info->cbData, info->pData, info->dwType); +} + diff --git a/testprogs/win32/spoolss/printlib_proto.h b/testprogs/win32/spoolss/printlib_proto.h index d408523ac47..44cadbce157 100644 --- a/testprogs/win32/spoolss/printlib_proto.h +++ b/testprogs/win32/spoolss/printlib_proto.h @@ -40,6 +40,7 @@ void print_driver_info_6 (PDRIVER_INFO_6 info); void print_doc_info_1 (PDOC_INFO_1 info); void print_printer_enum_values (PRINTER_ENUM_VALUES *info); void print_printer_keys(LPSTR buffer); +void print_printer_data(LPSTR keyname, LPSTR valuename, DWORD size, LPBYTE buffer, DWORD type); #undef _PRINTF_ATTRIBUTE #define _PRINTF_ATTRIBUTE(a1, a2) diff --git a/testprogs/win32/spoolss/spoolss.c b/testprogs/win32/spoolss/spoolss.c index 85a746d46fb..73713c62bb4 100644 --- a/testprogs/win32/spoolss/spoolss.c +++ b/testprogs/win32/spoolss/spoolss.c @@ -632,6 +632,58 @@ static BOOL test_EnumJobs(struct torture_context *tctx, /**************************************************************************** ****************************************************************************/ +static BOOL test_EnumPrinterDataEx(struct torture_context *tctx, + LPSTR servername, + LPSTR keyname, + HANDLE handle, + LPBYTE *buffer_p, + DWORD *returned_p) +{ + LPBYTE buffer = NULL; + DWORD needed = 0; + DWORD returned = 0; + DWORD err = 0; + char tmp[1024]; + + torture_comment(tctx, "Testing EnumPrinterDataEx(%s)", keyname); + + err = EnumPrinterDataEx(handle, keyname, NULL, 0, &needed, &returned); + if (err == ERROR_MORE_DATA) { + buffer = malloc(needed); + torture_assert(tctx, buffer, "malloc failed"); + err = EnumPrinterDataEx(handle, keyname, buffer, needed, &needed, &returned); + } + if (err) { + sprintf(tmp, "EnumPrinterDataEx(%s) failed on [%s] (buffer size = %d), error: %s\n", + keyname, servername, needed, errstr(err)); + torture_fail(tctx, tmp); + } + + if (tctx->print) { + DWORD i; + LPPRINTER_ENUM_VALUES v = (LPPRINTER_ENUM_VALUES)buffer; + for (i=0; i < returned; i++) { + print_printer_enum_values(&v[i]); + } + } + + if (returned_p) { + *returned_p = returned; + } + + if (buffer_p) { + *buffer_p = buffer; + } else { + free(buffer); + } + + return TRUE; +} + + +/**************************************************************************** +****************************************************************************/ + static BOOL test_OnePrinter(struct torture_context *tctx, LPSTR printername, LPSTR architecture, @@ -649,6 +701,7 @@ static BOOL test_OnePrinter(struct torture_context *tctx, ret &= test_EnumJobs(tctx, printername, handle); ret &= test_EnumPrinterKey(tctx, printername, handle, ""); ret &= test_EnumPrinterKey(tctx, printername, handle, "PrinterDriverData"); + ret &= test_EnumPrinterDataEx(tctx, printername, "PrinterDriverData", handle, NULL, NULL); ret &= test_ClosePrinter(tctx, handle); return ret; @@ -792,6 +845,145 @@ static BOOL test_GetPrinterDriverDirectory(struct torture_context *tctx, return TRUE; } +/**************************************************************************** +****************************************************************************/ + +static BOOL test_GetPrinterData(struct torture_context *tctx, + LPSTR servername, + LPSTR valuename, + HANDLE handle, + DWORD *type_p, + LPBYTE *buffer_p, + DWORD *size_p) +{ + LPBYTE buffer = NULL; + DWORD needed = 0; + DWORD type; + DWORD err = 0; + char tmp[1024]; + + torture_comment(tctx, "Testing GetPrinterData(%s)", valuename); + + err = GetPrinterData(handle, valuename, &type, NULL, 0, &needed); + if (err == ERROR_MORE_DATA) { + buffer = (LPBYTE)malloc(needed); + torture_assert(tctx, buffer, "malloc failed"); + err = GetPrinterData(handle, valuename, &type, buffer, needed, &needed); + } + if (err) { + sprintf(tmp, "GetPrinterData(%s) failed on [%s] (buffer size = %d), error: %s\n", + valuename, servername, needed, errstr(err)); + torture_fail(tctx, tmp); + } + + if (tctx->print) { + print_printer_data("PrinterDriverData", valuename, needed, buffer, type); + } + + if (type_p) { + *type_p = type; + } + + if (size_p) { + *size_p = needed; + } + + if (buffer_p) { + *buffer_p = buffer; + } else { + free(buffer); + } + + return TRUE; +} + +/**************************************************************************** +****************************************************************************/ + +static BOOL test_GetPrinterDataEx(struct torture_context *tctx, + LPSTR servername, + LPSTR keyname, + LPSTR valuename, + HANDLE handle, + DWORD *type_p, + LPBYTE *buffer_p, + DWORD *size_p) +{ + LPBYTE buffer = NULL; + DWORD needed = 0; + DWORD type; + DWORD err = 0; + char tmp[1024]; + + torture_comment(tctx, "Testing GetPrinterDataEx(%s - %s)", keyname, valuename); + + err = GetPrinterDataEx(handle, keyname, valuename, &type, NULL, 0, &needed); + if (err == ERROR_MORE_DATA) { + buffer = (LPBYTE)malloc(needed); + torture_assert(tctx, buffer, "malloc failed"); + err = GetPrinterDataEx(handle, keyname, valuename, &type, buffer, needed, &needed); + } + if (err) { + sprintf(tmp, "GetPrinterDataEx(%s) failed on [%s] (buffer size = %d), error: %s\n", + valuename, servername, needed, errstr(err)); + torture_fail(tctx, tmp); + } + + if (tctx->print) { + print_printer_data(keyname, valuename, needed, buffer, type); + } + + if (type_p) { + *type_p = type; + } + + if (size_p) { + *size_p = needed; + } + + if (buffer_p) { + *buffer_p = buffer; + } else { + free(buffer); + } + + return TRUE; +} + +/**************************************************************************** +****************************************************************************/ + +static BOOL test_PrinterData(struct torture_context *tctx, + LPSTR servername, + HANDLE handle) +{ + BOOL ret = TRUE; + DWORD i; + DWORD type, type_ex; + LPBYTE buffer, buffer_ex; + DWORD size, size_ex; + LPSTR valuenames[] = { + SPLREG_DEFAULT_SPOOL_DIRECTORY, + SPLREG_MAJOR_VERSION, + SPLREG_MINOR_VERSION, + SPLREG_DS_PRESENT, + SPLREG_DNS_MACHINE_NAME, + SPLREG_ARCHITECTURE, + SPLREG_OS_VERSION + }; + + for (i=0; i < ARRAY_SIZE(valuenames); i++) { + ret &= test_GetPrinterData(tctx, servername, valuenames[i], handle, &type, &buffer, &size); + ret &= test_GetPrinterDataEx(tctx, servername, "random", valuenames[i], handle, &type_ex, &buffer_ex, &size_ex); + torture_assert_int_equal(tctx, type, type_ex, "type mismatch"); + torture_assert_int_equal(tctx, size, size_ex, "size mismatch"); + torture_assert_mem_equal(tctx, buffer, buffer_ex, size, "buffer mismatch"); + free(buffer); + free(buffer_ex); + } + + return ret; +} /**************************************************************************** ****************************************************************************/ @@ -837,6 +1029,7 @@ int main(int argc, char *argv[]) ret &= test_EnumDrivers(tctx, servername, architecture); ret &= test_OpenPrinter(tctx, servername, NULL, &server_handle); /* ret &= test_EnumPrinterKey(tctx, servername, server_handle, ""); */ + ret &= test_PrinterData(tctx, servername, server_handle); ret &= test_EnumForms(tctx, servername, server_handle); ret &= test_ClosePrinter(tctx, server_handle); ret &= test_EnumPorts(tctx, servername); -- 2.11.4.GIT