[WINSPOOL_APITEST]

- Add tests for EnumPrinters
- Fix a test for EnumPrintProcessorDatatypes

svn path=/branches/colins-printing-for-freedom/; revision=68007
This commit is contained in:
Colin Finck 2015-06-04 12:19:06 +00:00
parent 99b62ed313
commit af0a3b64a9
4 changed files with 103 additions and 7 deletions

View file

@ -1,6 +1,7 @@
list(APPEND SOURCE
ClosePrinter.c
EnumPrinters.c
EnumPrintProcessorDatatypes.c
GetPrintProcessorDirectory.c
OpenPrinter.c

View file

@ -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);

View file

@ -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 <colin@reactos.org>
*/
#include <apitest.h>
#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winspool.h>
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);
}
}

View file

@ -11,6 +11,7 @@
#include <apitest.h>
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 },