ReactOS 0.4.15-dev-5666-gc548b97
GetPrinter.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Print Spooler DLL API Tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Tests for GetPrinterA/GetPrinterW
5 * COPYRIGHT: Copyright 2017 Colin Finck (colin@reactos.org)
6 */
7
8#include <apitest.h>
9
10#define WIN32_NO_STATUS
11#include <windef.h>
12#include <winbase.h>
13#include <wingdi.h>
14#include <winspool.h>
15
16/* From printing/include/spoolss.h */
17#define MAX_PRINTER_NAME 220
18
20{
21 DWORD cbNeeded;
22 DWORD cbTemp;
23 DWORD cchDefaultPrinter;
25 HANDLE hPrinter;
26 PVOID pMem;
27 WCHAR wszDefaultPrinter[MAX_PRINTER_NAME + 1];
28
29 // Open a handle to the default printer.
30 cchDefaultPrinter = _countof(wszDefaultPrinter);
31 ok(GetDefaultPrinterW(wszDefaultPrinter, &cchDefaultPrinter), "GetDefaultPrinterW returns FALSE and requires %lu characters!\n", cchDefaultPrinter);
32 if (!OpenPrinterW(wszDefaultPrinter, &hPrinter, NULL))
33 {
34 skip("Could not retrieve a handle to the default printer!\n");
35 return;
36 }
37
38 // Try for all levels. Level 0 is valid here and returns the PRINTER_INFO_STRESS structure (documented in MS-RPRN).
39 for (Level = 0; Level <= 9; Level++)
40 {
41 // Try with no valid arguments at all.
42 SetLastError(0xDEADBEEF);
43 ok(!GetPrinterW(NULL, Level, NULL, 0, NULL), "GetPrinterW returns TRUE for Level %lu!\n", Level);
44 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetPrinterW returns error %lu for Level %lu!\n", GetLastError(), Level);
45
46 // Now supply at least a handle.
47 SetLastError(0xDEADBEEF);
48 ok(!GetPrinterW(hPrinter, Level, NULL, 0, NULL), "GetPrinterW returns TRUE for Level %lu!\n", Level);
49 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrinterW returns error %lu for Level %lu!\n", GetLastError(), Level);
50
51 // Now get the buffer size.
52 SetLastError(0xDEADBEEF);
53 ok(!GetPrinterW(hPrinter, Level, NULL, 0, &cbNeeded), "GetPrinterW returns TRUE for Level %lu!\n", Level);
54 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrinterW returns error %lu for Level %lu!\n", GetLastError(), Level);
55
56 // Finally use the function as intended and aim for success!
57 pMem = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
58 SetLastError(0xDEADBEEF);
59 ok(GetPrinterW(hPrinter, Level, pMem, cbNeeded, &cbTemp), "GetPrinterW returns FALSE for Level %lu!\n", Level);
60 ok(cbNeeded == cbTemp, "cbNeeded is %lu, reference size is %lu for Level %lu!\n", cbNeeded, cbTemp, Level);
61 HeapFree(GetProcessHeap(), 0, pMem);
62 }
63
64 ClosePrinter(hPrinter);
65}
#define MAX_PRINTER_NAME
Definition: GetPrinter.c:17
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _countof(array)
Definition: sndvol32.h:68
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
WINBOOL WINAPI GetDefaultPrinterW(LPWSTR pszBuffer, LPDWORD pcchBuffer)
Definition: printers.c:1942
WINBOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
Definition: printers.c:2504
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2624
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176
#define GetPrinter
Definition: winspool.h:928
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180