mirror of
https://github.com/reactos/reactos.git
synced 2024-11-04 13:52:30 +00:00
af0a3b64a9
- Add tests for EnumPrinters - Fix a test for EnumPrintProcessorDatatypes svn path=/branches/colins-printing-for-freedom/; revision=68007
93 lines
5.5 KiB
C
93 lines
5.5 KiB
C
/*
|
|
* 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);
|
|
}
|
|
}
|