657dbd7a85e0f7fd5ab9ad07b574c12886660464
[reactos.git] / rostests / apitests / localspl / dll / fpEnumPrinters.c
1 /*
2 * PROJECT: ReactOS Local Spooler API Tests Injected DLL
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Tests for fpEnumPrinters
5 * COPYRIGHT: Copyright 2015 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 <winreg.h>
15 #include <winspool.h>
16 #include <winsplp.h>
17
18 #include "../localspl_apitest.h"
19
20 START_TEST(fpEnumPrinters)
21 {
22 DWORD cbNeeded;
23 DWORD dwReturned;
24 HMODULE hLocalspl;
25 PInitializePrintProvidor pfnInitializePrintProvidor;
26 PRINTPROVIDOR pp;
27 PPRINTER_INFO_1W pPrinterInfo1;
28
29 // Get us a handle to the loaded localspl.dll.
30 hLocalspl = GetModuleHandleW(L"localspl");
31 if (!hLocalspl)
32 {
33 skip("GetModuleHandleW failed with error %lu!\n", GetLastError());
34 return;
35 }
36
37 // Get a pointer to its InitializePrintProvidor function.
38 pfnInitializePrintProvidor = (PInitializePrintProvidor)GetProcAddress(hLocalspl, "InitializePrintProvidor");
39 if (!pfnInitializePrintProvidor)
40 {
41 skip("GetProcAddress failed with error %lu!\n", GetLastError());
42 return;
43 }
44
45 // Get localspl's function pointers.
46 if (!pfnInitializePrintProvidor(&pp, sizeof(pp), NULL))
47 {
48 skip("pfnInitializePrintProvidor failed with error %lu!\n", GetLastError());
49 return;
50 }
51
52 // Verify that localspl only returns information about a single print provider (namely itself).
53 cbNeeded = 0xDEADBEEF;
54 dwReturned = 0xDEADBEEF;
55 SetLastError(0xDEADBEEF);
56 ok(!pp.fpEnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_NAME, NULL, 1, NULL, 0, &cbNeeded, &dwReturned), "fpEnumPrinters returns TRUE\n");
57 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "fpEnumPrinters returns error %lu!\n", GetLastError());
58 ok(cbNeeded > 0, "cbNeeded is 0!\n");
59 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
60
61 SetLastError(0xDEADBEEF);
62 pPrinterInfo1 = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
63 ok(pp.fpEnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_NAME, NULL, 1, (PBYTE)pPrinterInfo1, cbNeeded, &cbNeeded, &dwReturned), "fpEnumPrinters returns FALSE\n");
64 ok(GetLastError() == ERROR_SUCCESS, "fpEnumPrinters returns error %lu!\n", GetLastError());
65 ok(cbNeeded > 0, "cbNeeded is 0!\n");
66 ok(dwReturned == 1, "dwReturned is %lu!\n", dwReturned);
67
68 // Verify the actual strings returned.
69 ok(wcscmp(pPrinterInfo1->pName, L"Windows NT Local Print Providor") == 0, "pPrinterInfo1->pName is \"%S\"!\n", pPrinterInfo1->pName);
70 ok(wcscmp(pPrinterInfo1->pDescription, L"Windows NT Local Printers") == 0, "pPrinterInfo1->pDescription is \"%S\"!\n", pPrinterInfo1->pDescription);
71 ok(wcscmp(pPrinterInfo1->pComment, L"Locally connected Printers") == 0, "pPrinterInfo1->pComment is \"%S\"!\n", pPrinterInfo1->pComment);
72 }