1*3b93ba0fSColin Finck /*
2*3b93ba0fSColin Finck  * PROJECT:     ReactOS Local Spooler API Tests Injected DLL
3*3b93ba0fSColin Finck  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4*3b93ba0fSColin Finck  * PURPOSE:     Tests for fpSetJob
5*3b93ba0fSColin Finck  * COPYRIGHT:   Copyright 2017 Colin Finck (colin@reactos.org)
6*3b93ba0fSColin Finck  */
7*3b93ba0fSColin Finck 
8*3b93ba0fSColin Finck #include <apitest.h>
9*3b93ba0fSColin Finck 
10*3b93ba0fSColin Finck #define WIN32_NO_STATUS
11*3b93ba0fSColin Finck #include <windef.h>
12*3b93ba0fSColin Finck #include <winbase.h>
13*3b93ba0fSColin Finck #include <wingdi.h>
14*3b93ba0fSColin Finck #include <winreg.h>
15*3b93ba0fSColin Finck #include <winspool.h>
16*3b93ba0fSColin Finck #include <winsplp.h>
17*3b93ba0fSColin Finck 
18*3b93ba0fSColin Finck #include "../localspl_apitest.h"
19*3b93ba0fSColin Finck #include <spoolss.h>
20*3b93ba0fSColin Finck 
21*3b93ba0fSColin Finck extern PWSTR GetDefaultPrinterFromRegistry(VOID);
22*3b93ba0fSColin Finck extern BOOL GetLocalsplFuncs(LPPRINTPROVIDOR pp);
23*3b93ba0fSColin Finck 
24*3b93ba0fSColin Finck /* From printing/include/spoolss.h */
25*3b93ba0fSColin Finck #define MAX_PRINTER_NAME        220
26*3b93ba0fSColin Finck 
START_TEST(fpSetJob)27*3b93ba0fSColin Finck START_TEST(fpSetJob)
28*3b93ba0fSColin Finck {
29*3b93ba0fSColin Finck     HANDLE hPrinter = NULL;
30*3b93ba0fSColin Finck     PRINTPROVIDOR pp;
31*3b93ba0fSColin Finck     PWSTR pwszDefaultPrinter = NULL;
32*3b93ba0fSColin Finck 
33*3b93ba0fSColin Finck     if (!GetLocalsplFuncs(&pp))
34*3b93ba0fSColin Finck         goto Cleanup;
35*3b93ba0fSColin Finck 
36*3b93ba0fSColin Finck     // Verify that fpSetJob returns ERROR_INVALID_HANDLE when nothing is provided.
37*3b93ba0fSColin Finck     ok(!pp.fpSetJob(NULL, 0, 0, NULL, 0), "fpSetJob returns TRUE\n");
38*3b93ba0fSColin Finck     ok(GetLastError() == ERROR_INVALID_HANDLE, "fpSetJob returns error %lu!\n", GetLastError());
39*3b93ba0fSColin Finck 
40*3b93ba0fSColin Finck     // Get the default printer.
41*3b93ba0fSColin Finck     pwszDefaultPrinter = GetDefaultPrinterFromRegistry();
42*3b93ba0fSColin Finck     if (!pwszDefaultPrinter)
43*3b93ba0fSColin Finck     {
44*3b93ba0fSColin Finck         skip("Could not determine the default printer!\n");
45*3b93ba0fSColin Finck         goto Cleanup;
46*3b93ba0fSColin Finck     }
47*3b93ba0fSColin Finck 
48*3b93ba0fSColin Finck     if (!pp.fpOpenPrinter(pwszDefaultPrinter, &hPrinter, NULL))
49*3b93ba0fSColin Finck     {
50*3b93ba0fSColin Finck         skip("Could not open a handle to the default printer, last error is %lu!\n", GetLastError());
51*3b93ba0fSColin Finck         goto Cleanup;
52*3b93ba0fSColin Finck     }
53*3b93ba0fSColin Finck 
54*3b93ba0fSColin Finck     // Verify that fpSetJob returns ERROR_INVALID_PARAMETER if only a printer handle is provided.
55*3b93ba0fSColin Finck     ok(!pp.fpSetJob(hPrinter, 0, 0, NULL, 0), "fpSetJob returns TRUE\n");
56*3b93ba0fSColin Finck     ok(GetLastError() == ERROR_INVALID_PARAMETER, "fpSetJob returns error %lu!\n", GetLastError());
57*3b93ba0fSColin Finck 
58*3b93ba0fSColin Finck Cleanup:
59*3b93ba0fSColin Finck     if (pwszDefaultPrinter)
60*3b93ba0fSColin Finck         HeapFree(GetProcessHeap(), 0, pwszDefaultPrinter);
61*3b93ba0fSColin Finck 
62*3b93ba0fSColin Finck     if (hPrinter)
63*3b93ba0fSColin Finck         pp.fpClosePrinter(hPrinter);
64*3b93ba0fSColin Finck }
65