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 GetDefaultPrinterA/GetDefaultPrinterW/SetDefaultPrinterA/SetDefaultPrinterW
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
START_TEST(GetDefaultPrinterA)16 START_TEST(GetDefaultPrinterA)
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 }
52
START_TEST(GetDefaultPrinterW)53 START_TEST(GetDefaultPrinterW)
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 }
89