ReactOS 0.4.15-dev-5896-g3f5bcf5
EnumPrintProcessorDatatypes.c
Go to the documentation of this file.
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 EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW
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 <winspool.h>
15
17{
18 DWORD cbNeeded;
19 DWORD cbTemp;
20 DWORD dwReturned;
21 PDATATYPES_INFO_1W pDatatypesInfo1;
22
23 // Try with an invalid level, this needs to be caught first.
24 SetLastError(0xDEADBEEF);
25 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 0, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
26 ok(GetLastError() == ERROR_INVALID_LEVEL, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
27
28 // Now try with valid level, but no pcbNeeded and no pcReturned.
29 SetLastError(0xDEADBEEF);
30 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
31 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
32
33 // Now try with pcbNeeded and pcReturned, but give no Print Processor.
34 SetLastError(0xDEADBEEF);
35 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
36 ok(GetLastError() == ERROR_UNKNOWN_PRINTPROCESSOR, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
37
38 // Same error has to occur when looking for an invalid Print Processor.
39 SetLastError(0xDEADBEEF);
40 ok(!EnumPrintProcessorDatatypesW(NULL, L"invalid", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
41 ok(GetLastError() == ERROR_UNKNOWN_PRINTPROCESSOR, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
42
43 // Now get the required buffer size by supplying all information. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
44 // This also verifies that the function is really doing a case-insensitive lookup.
45 SetLastError(0xDEADBEEF);
46 ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
47 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
48 ok(cbNeeded > 0, "cbNeeded is 0!\n");
49 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
50
51 // Same error has to occur with a size to small.
52 SetLastError(0xDEADBEEF);
53 ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, 1, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
54 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintersW returns error %lu!\n", GetLastError());
55 ok(cbNeeded > 0, "cbNeeded is 0!\n");
56 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
57
58 // Now provide the demanded size, but no buffer.
59 SetLastError(0xDEADBEEF);
60 ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
61 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
62 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
63 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
64
65 // This also has to fail the same way when no Print Processor was given at all.
66 SetLastError(0xDEADBEEF);
67 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
68 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
69 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
70 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
71
72 // Finally use the function as intended and aim for success!
73 pDatatypesInfo1 = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
74 SetLastError(0xDEADBEEF);
75 ok(EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, (PBYTE)pDatatypesInfo1, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns FALSE!\n");
76 ok(GetLastError() == ERROR_SUCCESS, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
77 HeapFree(GetProcessHeap(), 0, pDatatypesInfo1);
78}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#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
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
#define ERROR_INVALID_USER_BUFFER
Definition: winerror.h:1091
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
#define ERROR_UNKNOWN_PRINTPROCESSOR
Definition: winerror.h:1105
WINBOOL WINAPI EnumPrintProcessorDatatypesW(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
#define EnumPrintProcessorDatatypes
Definition: winspool.h:939