ReactOS  0.4.15-dev-3717-g292e6a4
EnumPrintProcessorDatatypesW.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Standard Print Processor API Tests
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Tests for EnumPrintProcessorDatatypesW
5  * COPYRIGHT: Copyright 2015-2016 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 extern PVOID GetWinprintFunc(const char* FunctionName);
18 
20 {
21  DWORD cbNeeded;
22  DWORD cbTemp;
23  DWORD dwReturned;
24  PDATATYPES_INFO_1W pDatatypesInfo1;
25  PEnumPrintProcessorDatatypesW pEnumPrintProcessorDatatypesW;
26 
27  // Get the function we want to test from one of the possible Print Processor DLLs.
28  pEnumPrintProcessorDatatypesW = (PEnumPrintProcessorDatatypesW)GetWinprintFunc("EnumPrintProcessorDatatypesW");
29  if (!pEnumPrintProcessorDatatypesW)
30  return;
31 
32  // Try with an invalid level. The error needs to be set by winspool, but not by the Print Processor.
33  SetLastError(0xDEADBEEF);
34  ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 0, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
35  ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
36 
37  // Now try with valid level, but no pcbNeeded and no pcReturned. The error needs to be set by RPC.
38  SetLastError(0xDEADBEEF);
39  ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
40  ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
41 
42  // Now try with pcbNeeded and pcReturned, but give no Print Processor. Show that winprint actually ignores the given Print Processor.
43  SetLastError(0xDEADBEEF);
44  ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
45  ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
46  ok(cbNeeded > 0, "cbNeeded is 0!\n");
47  ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
48 
49  // Same error has to occur when looking for an invalid Print Processor.
50  SetLastError(0xDEADBEEF);
51  ok(!pEnumPrintProcessorDatatypesW(NULL, L"invalid", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
52  ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
53  ok(cbNeeded > 0, "cbNeeded is 0!\n");
54  ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
55 
56  // Now get the required buffer size by supplying all information. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
57  SetLastError(0xDEADBEEF);
58  ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
59  ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
60  ok(cbNeeded > 0, "cbNeeded is 0!\n");
61  ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
62 
63  // Same error has to occur with a size to small.
64  SetLastError(0xDEADBEEF);
65  ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 1, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
66  ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintersW returns error %lu!\n", GetLastError());
67  ok(cbNeeded > 0, "cbNeeded is 0!\n");
68  ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
69 
70  // Now provide the demanded size, but no buffer. Show that winprint returns a different error than the same function in winspool.
71  SetLastError(0xDEADBEEF);
72  ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
73  ok(GetLastError() == ERROR_INVALID_PARAMETER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
74  ok(cbTemp == cbNeeded, "cbTemp is %lu!\n", cbTemp);
75  ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
76 
77  // This also has to fail the same way when no Print Processor was given at all.
78  SetLastError(0xDEADBEEF);
79  ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
80  ok(GetLastError() == ERROR_INVALID_PARAMETER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
81  ok(cbTemp == cbNeeded, "cbTemp is %lu!\n", cbTemp);
82  ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
83 
84  // Finally use the function as intended and aim for success! Show that winprint doesn't modify the error code at all.
85  pDatatypesInfo1 = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
86  SetLastError(0xDEADBEEF);
87  ok(pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, (PBYTE)pDatatypesInfo1, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns FALSE!\n");
88  ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
89  HeapFree(GetProcessHeap(), 0, pDatatypesInfo1);
90 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
START_TEST(EnumPrintProcessorDatatypesW)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
unsigned char * LPBYTE
Definition: typedefs.h:53
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
WINBOOL WINAPI EnumPrintProcessorDatatypesW(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
#define LPDWORD
Definition: nt_native.h:46
BOOL(WINAPI * PEnumPrintProcessorDatatypesW)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD)
#define ok(value,...)
Definition: atltest.h:57
PVOID GetWinprintFunc(const char *FunctionName)
Definition: main.c:17
#define NULL
Definition: types.h:112
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1274
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BYTE * PBYTE
Definition: pedump.c:66
#define HeapFree(x, y, z)
Definition: compat.h:594
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10