ReactOS 0.4.16-dev-340-g0540c21
GetDefaultPrinter.c File Reference
#include <apitest.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winspool.h>
Include dependency graph for GetDefaultPrinter.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

 START_TEST (GetDefaultPrinterA)
 
 START_TEST (GetDefaultPrinterW)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file GetDefaultPrinter.c.

Function Documentation

◆ START_TEST() [1/2]

START_TEST ( GetDefaultPrinterA  )

Definition at line 16 of file GetDefaultPrinter.c.

17{
18 DWORD cchDefaultPrinter;
19 PSTR pszDefaultPrinter;
20
21 // Don't supply any parameters, this has to fail with ERROR_INVALID_PARAMETER.
22 SetLastError(0xDEADBEEF);
23 ok(!GetDefaultPrinterA(NULL, NULL), "GetDefaultPrinterA returns TRUE!\n");
24 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetDefaultPrinterA returns error %lu!\n", GetLastError());
25
26 // Determine the size of the required buffer. This has to bail out with ERROR_INSUFFICIENT_BUFFER.
27 cchDefaultPrinter = 0;
28 SetLastError(0xDEADBEEF);
29 ok(!GetDefaultPrinterA(NULL, &cchDefaultPrinter), "GetDefaultPrinterA returns TRUE!\n");
30 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetDefaultPrinterA returns error %lu!\n", GetLastError());
31
32 // Try with a buffer large enough.
33 pszDefaultPrinter = HeapAlloc(GetProcessHeap(), 0, cchDefaultPrinter);
34 SetLastError(0xDEADBEEF);
35 ok(GetDefaultPrinterA(pszDefaultPrinter, &cchDefaultPrinter), "GetDefaultPrinterA returns FALSE!\n");
36
37 // SetDefaultPrinterA with NULL needs to succeed and leave the default printer unchanged.
38 SetLastError(0xDEADBEEF);
39 ok(SetDefaultPrinterA(NULL), "SetDefaultPrinterA returns FALSE!\n");
40
41 // SetDefaultPrinterA with the previous default printer also needs to succeed.
42 SetLastError(0xDEADBEEF);
43 ok(SetDefaultPrinterA(pszDefaultPrinter), "SetDefaultPrinterA returns FALSE!\n");
44
45 // SetDefaultPrinterA with an invalid printer name needs to fail with ERROR_INVALID_PRINTER_NAME.
46 SetLastError(0xDEADBEEF);
47 ok(!SetDefaultPrinterA("INVALID PRINTER NAME!!!"), "SetDefaultPrinterA returns TRUE!\n");
48 ok(GetLastError() == ERROR_INVALID_PRINTER_NAME, "SetDefaultPrinterA returns error %lu!\n", GetLastError());
49
50 HeapFree(GetProcessHeap(), 0, pszDefaultPrinter);
51}
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned long DWORD
Definition: ntddk_ex.h:95
char * PSTR
Definition: typedefs.h:51
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_INVALID_PRINTER_NAME
Definition: winerror.h:1108
WINBOOL WINAPI SetDefaultPrinterA(LPCSTR pszPrinter)
Definition: printers.c:3005
WINBOOL WINAPI GetDefaultPrinterA(LPSTR pszBuffer, LPDWORD pcchBuffer)
Definition: printers.c:1925

◆ START_TEST() [2/2]

START_TEST ( GetDefaultPrinterW  )

Definition at line 53 of file GetDefaultPrinter.c.

54{
55 DWORD cchDefaultPrinter;
56 PWSTR pwszDefaultPrinter;
57
58 // Don't supply any parameters, this has to fail with ERROR_INVALID_PARAMETER.
59 SetLastError(0xDEADBEEF);
60 ok(!GetDefaultPrinterW(NULL, NULL), "GetDefaultPrinterW returns TRUE!\n");
61 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetDefaultPrinterW returns error %lu!\n", GetLastError());
62
63 // Determine the size of the required buffer. This has to bail out with ERROR_INSUFFICIENT_BUFFER.
64 cchDefaultPrinter = 0;
65 SetLastError(0xDEADBEEF);
66 ok(!GetDefaultPrinterW(NULL, &cchDefaultPrinter), "GetDefaultPrinterW returns TRUE!\n");
67 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetDefaultPrinterW returns error %lu!\n", GetLastError());
68
69 // Try with a buffer large enough.
70 pwszDefaultPrinter = HeapAlloc(GetProcessHeap(), 0, cchDefaultPrinter * sizeof(WCHAR));
71 SetLastError(0xDEADBEEF);
72 ok(GetDefaultPrinterW(pwszDefaultPrinter, &cchDefaultPrinter), "GetDefaultPrinterW returns FALSE!\n");
73
74 // SetDefaultPrinterW with NULL needs to succeed and leave the default printer unchanged.
75 SetLastError(0xDEADBEEF);
76 ok(SetDefaultPrinterW(NULL), "SetDefaultPrinterW returns FALSE!\n");
77
78 // SetDefaultPrinterW with the previous default printer also needs to succeed.
79 SetLastError(0xDEADBEEF);
80 ok(SetDefaultPrinterW(pwszDefaultPrinter), "SetDefaultPrinterW returns FALSE!\n");
81
82 // SetDefaultPrinterW with an invalid printer name needs to fail with ERROR_INVALID_PRINTER_NAME.
83 SetLastError(0xDEADBEEF);
84 ok(!SetDefaultPrinterW(L"INVALID PRINTER NAME!!!"), "SetDefaultPrinterW returns TRUE!\n");
85 ok(GetLastError() == ERROR_INVALID_PRINTER_NAME, "SetDefaultPrinterW returns error %lu!\n", GetLastError());
86
87 HeapFree(GetProcessHeap(), 0, pwszDefaultPrinter);
88}
#define L(x)
Definition: ntvdm.h:50
uint16_t * PWSTR
Definition: typedefs.h:56
WINBOOL WINAPI GetDefaultPrinterW(LPWSTR pszBuffer, LPDWORD pcchBuffer)
Definition: printers.c:1971
WINBOOL WINAPI SetDefaultPrinterW(LPCWSTR pszPrinter)
Definition: printers.c:3039
__wchar_t WCHAR
Definition: xmlstorage.h:180