ReactOS 0.4.16-dev-297-gc569aee
GetPrinter.c File Reference
#include <apitest.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winspool.h>
Include dependency graph for GetPrinter.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define MAX_PRINTER_NAME   220
 

Functions

 START_TEST (GetPrinter)
 

Macro Definition Documentation

◆ MAX_PRINTER_NAME

#define MAX_PRINTER_NAME   220

Definition at line 17 of file GetPrinter.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file GetPrinter.c.

Function Documentation

◆ START_TEST()

START_TEST ( GetPrinter  )

Definition at line 19 of file GetPrinter.c.

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 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:70
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
WINBOOL WINAPI GetDefaultPrinterW(LPWSTR pszBuffer, LPDWORD pcchBuffer)
Definition: printers.c:1971
WINBOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
Definition: printers.c:2533
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2653
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180