[PRINTING]
[reactos.git] / rostests / apitests / winspool / GetDefaultPrinter.c
1 /*
2 * PROJECT: ReactOS Print Spooler DLL API Tests
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
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
16 START_TEST(GetDefaultPrinter)
17 {
18 DWORD cchDefaultPrinter;
19 PWSTR pwszDefaultPrinter;
20
21 // Don't supply any parameters, this has to fail with ERROR_INVALID_PARAMETER.
22 SetLastError(0xDEADBEEF);
23 ok(!GetDefaultPrinterW(NULL, NULL), "GetDefaultPrinterW returns TRUE!\n");
24 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetDefaultPrinterW 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(!GetDefaultPrinterW(NULL, &cchDefaultPrinter), "GetDefaultPrinterW returns TRUE!\n");
30 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetDefaultPrinterW returns error %lu!\n", GetLastError());
31
32 // Try with a buffer large enough.
33 pwszDefaultPrinter = HeapAlloc(GetProcessHeap(), 0, cchDefaultPrinter * sizeof(WCHAR));
34 SetLastError(0xDEADBEEF);
35 ok(GetDefaultPrinterW(pwszDefaultPrinter, &cchDefaultPrinter), "GetDefaultPrinterW returns FALSE!\n");
36 ok(GetLastError() == ERROR_SUCCESS, "GetDefaultPrinterW returns error %lu!\n", GetLastError());
37
38 // SetDefaultPrinterW with NULL needs to succeed and leave the default printer unchanged.
39 SetLastError(0xDEADBEEF);
40 ok(SetDefaultPrinterW(NULL), "SetDefaultPrinterW returns FALSE!\n");
41 ok(GetLastError() == ERROR_SUCCESS, "SetDefaultPrinterW returns error %lu!\n", GetLastError());
42
43 // SetDefaultPrinterW with the previous default printer also needs to succeed.
44 SetLastError(0xDEADBEEF);
45 ok(SetDefaultPrinterW(pwszDefaultPrinter), "SetDefaultPrinterW returns FALSE!\n");
46 ok(GetLastError() == ERROR_SUCCESS, "SetDefaultPrinterW returns error %lu!\n", GetLastError());
47
48 HeapFree(GetProcessHeap(), 0, pwszDefaultPrinter);
49 }