From: Colin Finck Date: Thu, 4 Jun 2015 12:19:06 +0000 (+0000) Subject: [WINSPOOL_APITEST] X-Git-Tag: backups/colins-printing-for-freedom@73041~62 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=af0a3b64a9b0073ec82551c09d3ca9d03625b662 [WINSPOOL_APITEST] - Add tests for EnumPrinters - Fix a test for EnumPrintProcessorDatatypes svn path=/branches/colins-printing-for-freedom/; revision=68007 --- diff --git a/rostests/apitests/winspool/CMakeLists.txt b/rostests/apitests/winspool/CMakeLists.txt index 6e4484dcb4a..b7a356b7316 100644 --- a/rostests/apitests/winspool/CMakeLists.txt +++ b/rostests/apitests/winspool/CMakeLists.txt @@ -1,6 +1,7 @@ list(APPEND SOURCE ClosePrinter.c + EnumPrinters.c EnumPrintProcessorDatatypes.c GetPrintProcessorDirectory.c OpenPrinter.c diff --git a/rostests/apitests/winspool/EnumPrintProcessorDatatypes.c b/rostests/apitests/winspool/EnumPrintProcessorDatatypes.c index f2005c73b52..4259ea56cb7 100644 --- a/rostests/apitests/winspool/EnumPrintProcessorDatatypes.c +++ b/rostests/apitests/winspool/EnumPrintProcessorDatatypes.c @@ -48,6 +48,13 @@ START_TEST(EnumPrintProcessorDatatypes) ok(cbNeeded > 0, "cbNeeded is 0!\n"); ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); + // Same error has to occur with a size to small. + SetLastError(0xDEADBEEF); + ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, 1, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintersW returns error %lu!\n", GetLastError()); + ok(cbNeeded > 0, "cbNeeded is 0!\n"); + ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); + // Now provide the demanded size, but no buffer. SetLastError(0xDEADBEEF); ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); @@ -62,13 +69,6 @@ START_TEST(EnumPrintProcessorDatatypes) ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp); ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); - // Same error has to occur with a valid Print Processor, but a size too small. - SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); - ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); - ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp); - ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); - // Finally use the function as intended and aim for success! pDatatypesInfo1 = HeapAlloc(GetProcessHeap(), 0, cbNeeded); SetLastError(0xDEADBEEF); diff --git a/rostests/apitests/winspool/EnumPrinters.c b/rostests/apitests/winspool/EnumPrinters.c new file mode 100644 index 00000000000..f199f60abad --- /dev/null +++ b/rostests/apitests/winspool/EnumPrinters.c @@ -0,0 +1,93 @@ +/* + * PROJECT: ReactOS Print Spooler DLL API Tests + * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation + * PURPOSE: Tests for EnumPrintersA/EnumPrintersW + * COPYRIGHT: Copyright 2015 Colin Finck + */ + +#include + +#define WIN32_NO_STATUS +#include +#include +#include +#include + +START_TEST(EnumPrinters) +{ + DWORD cbNeeded; + DWORD cbTemp; + DWORD dwReturned; + PVOID pMem; + DWORD i; + DWORD dwValidLevels[] = { 0, 1, 2, 4, 5 }; + + // Level 5 is the highest supported under Windows Server 2003. Higher levels need to fail and leave the variables untouched! + cbNeeded = 0xDEADBEEF; + dwReturned = 0xDEADBEEF; + SetLastError(0xDEADBEEF); + ok(!EnumPrintersW(0, NULL, 6, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintersW returns TRUE!\n"); + ok(GetLastError() == ERROR_INVALID_LEVEL, "EnumPrintersW returns error %lu!\n", GetLastError()); + ok(cbNeeded == 0xDEADBEEF, "cbNeeded is %lu!\n", cbNeeded); + ok(dwReturned == 0xDEADBEEF, "dwReturned is %lu!\n", dwReturned); + + // Same goes for level 3. + cbNeeded = 0xDEADBEEF; + dwReturned = 0xDEADBEEF; + SetLastError(0xDEADBEEF); + ok(!EnumPrintersW(0, NULL, 3, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintersW returns TRUE!\n"); + ok(GetLastError() == ERROR_INVALID_LEVEL, "EnumPrintersW returns error %lu!\n", GetLastError()); + ok(cbNeeded == 0xDEADBEEF, "cbNeeded is %lu!\n", cbNeeded); + ok(dwReturned == 0xDEADBEEF, "dwReturned is %lu!\n", dwReturned); + + // Try for all valid levels. Level 0 is valid here and returns the PRINTER_INFO_STRESS structure (documented in MS-RPRN). + for (i = 0; i < sizeof(dwValidLevels) / sizeof(DWORD); i++) + { + // Try with no valid arguments at all. + SetLastError(0xDEADBEEF); + ok(!EnumPrintersW(0, NULL, dwValidLevels[i], NULL, 0, NULL, NULL), "EnumPrintersW returns TRUE for Level %lu!\n", dwValidLevels[i]); + ok(GetLastError() == RPC_X_NULL_REF_POINTER, "EnumPrintersW returns error %lu for Level %lu!\n", GetLastError(), dwValidLevels[i]); + + // It has to succeed if we supply the required pointers and query no information. + SetLastError(0xDEADBEEF); + ok(EnumPrintersW(0, NULL, dwValidLevels[i], NULL, 0, &cbNeeded, &dwReturned), "EnumPrintersW returns FALSE for Level %lu!\n", dwValidLevels[i]); + ok(GetLastError() == ERROR_SUCCESS, "EnumPrintersW returns error %lu for Level %lu!\n", GetLastError(), dwValidLevels[i]); + ok(cbNeeded == 0, "cbNeeded is %lu for Level %lu!\n", cbNeeded, dwValidLevels[i]); + ok(dwReturned == 0, "dwReturned is %lu for Level %lu!\n", dwReturned, dwValidLevels[i]); + + // This constant is from Windows 9x/ME times and mustn't work anymore. + SetLastError(0xDEADBEEF); + ok(EnumPrintersW(PRINTER_ENUM_DEFAULT, NULL, dwValidLevels[i], NULL, 0, &cbNeeded, &dwReturned), "EnumPrintersW returns FALSE for Level %lu!\n", dwValidLevels[i]); + ok(GetLastError() == ERROR_SUCCESS, "EnumPrintersW returns error %lu for Level %lu!\n", GetLastError(), dwValidLevels[i]); + ok(cbNeeded == 0, "cbNeeded is %lu for Level %lu!\n", cbNeeded, dwValidLevels[i]); + ok(dwReturned == 0, "dwReturned is %lu for Level %lu!\n", dwReturned, dwValidLevels[i]); + + // Now things get interesting. Let's query the buffer size for information about the local printers. + SetLastError(0xDEADBEEF); + ok(!EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, dwValidLevels[i], NULL, 0, &cbNeeded, &dwReturned), "EnumPrintersW returns TRUE for Level %lu!\n", dwValidLevels[i]); + ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintersW returns error %lu for Level %lu!\n", GetLastError(), dwValidLevels[i]); + ok(cbNeeded > 0, "cbNeeded is 0 for Level %lu!\n", dwValidLevels[i]); + ok(dwReturned == 0, "dwReturned is %lu for Level %lu!\n", dwReturned, dwValidLevels[i]); + + // Same error has to occur with a size to small. + SetLastError(0xDEADBEEF); + ok(!EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, dwValidLevels[i], NULL, 1, &cbNeeded, &dwReturned), "EnumPrintersW returns TRUE for Level %lu!\n", dwValidLevels[i]); + ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintersW returns error %lu for Level %lu!\n", GetLastError(), dwValidLevels[i]); + ok(cbNeeded > 0, "cbNeeded is 0 for Level %lu!\n", dwValidLevels[i]); + ok(dwReturned == 0, "dwReturned is %lu for Level %lu!\n", dwReturned, dwValidLevels[i]); + + // Now provide the demanded size, but no buffer. + SetLastError(0xDEADBEEF); + ok(!EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, dwValidLevels[i], NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintersW returns TRUE for Level %lu!\n", dwValidLevels[i]); + ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "EnumPrintersW returns error %lu for Level %lu!\n", GetLastError(), dwValidLevels[i]); + ok(cbTemp == 0, "cbTemp is %lu for Level %lu!\n", cbTemp, dwValidLevels[i]); + ok(dwReturned == 0, "dwReturned is %lu for Level %lu!\n", dwReturned, dwValidLevels[i]); + + // Finally use the function as intended and aim for success! + pMem = HeapAlloc(GetProcessHeap(), 0, cbNeeded); + SetLastError(0xDEADBEEF); + ok(EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, dwValidLevels[i], pMem, cbNeeded, &cbTemp, &dwReturned), "EnumPrintersW returns FALSE for Level %lu!\n", dwValidLevels[i]); + ok(GetLastError() == ERROR_SUCCESS, "EnumPrintersW returns error %lu for Level %lu!\n", GetLastError(), dwValidLevels[i]); + HeapFree(GetProcessHeap(), 0, pMem); + } +} diff --git a/rostests/apitests/winspool/testlist.c b/rostests/apitests/winspool/testlist.c index 1193c3a7382..0581c50e536 100644 --- a/rostests/apitests/winspool/testlist.c +++ b/rostests/apitests/winspool/testlist.c @@ -11,6 +11,7 @@ #include extern void func_ClosePrinter(void); +extern void func_EnumPrinters(void); extern void func_EnumPrintProcessorDatatypes(void); extern void func_GetPrintProcessorDirectory(void); extern void func_OpenPrinter(void); @@ -19,6 +20,7 @@ extern void func_StartDocPrinter(void); const struct test winetest_testlist[] = { { "ClosePrinter", func_ClosePrinter }, + { "EnumPrinters", func_EnumPrinters }, { "EnumPrintProcessorDatatypes", func_EnumPrintProcessorDatatypes }, { "GetPrintProcessorDirectory", func_GetPrintProcessorDirectory }, { "OpenPrinter", func_OpenPrinter },