ReactOS 0.4.15-dev-7958-gcd0bb1a
EnumPrintProcessorDatatypesW.c File Reference
#include <apitest.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winspool.h>
Include dependency graph for EnumPrintProcessorDatatypesW.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef BOOL(WINAPIPEnumPrintProcessorDatatypesW) (LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD)
 

Functions

PVOID GetWinprintFunc (const char *FunctionName)
 
 START_TEST (EnumPrintProcessorDatatypesW)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file EnumPrintProcessorDatatypesW.c.

Typedef Documentation

◆ PEnumPrintProcessorDatatypesW

typedef BOOL(WINAPI * PEnumPrintProcessorDatatypesW) (LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD)

Definition at line 16 of file EnumPrintProcessorDatatypesW.c.

Function Documentation

◆ GetWinprintFunc()

PVOID GetWinprintFunc ( const char FunctionName)

Definition at line 17 of file main.c.

18{
19 DWORD cbNeeded;
20 HMODULE hWinprint;
21 PVOID pFunc;
22 WCHAR wszWinprintPath[MAX_PATH];
23
24 // Build the path to the default Print Processor winprint.dll in the Print Processor directory.
25 if (!GetPrintProcessorDirectoryW(NULL, NULL, 1, (LPBYTE)wszWinprintPath, sizeof(wszWinprintPath), &cbNeeded))
26 {
27 skip("Could not determine the path to the Print Processor directory, last error is %lu!\n", GetLastError());
28 return NULL;
29 }
30
31 wcscat(wszWinprintPath, L"\\winprint.dll");
32
33 // Try loading it.
34 hWinprint = LoadLibraryW(wszWinprintPath);
35 if (!hWinprint)
36 {
38 {
39 skip("LoadLibraryW failed for %S with error %lu!\n", wszWinprintPath, GetLastError());
40 return NULL;
41 }
42
43 // winprint.dll does not exist prior to NT6.
44 // The default Print Processor is implemented in localspl.dll instead.
45 hWinprint = LoadLibraryW(L"localspl.dll");
46 if (!hWinprint)
47 {
48 skip("LoadLibraryW failed for localspl.dll with error %lu!\n", GetLastError());
49 return NULL;
50 }
51 }
52
53 // Get the function we are looking for.
54 pFunc = GetProcAddress(hWinprint, FunctionName);
55 if (!pFunc)
56 {
57 skip("GetProcAddress failed for %s with error %lu!\n", FunctionName, GetLastError());
58 return NULL;
59 }
60
61 return pFunc;
62}
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:1279
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define ERROR_MOD_NOT_FOUND
Definition: compat.h:104
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
unsigned long DWORD
Definition: ntddk_ex.h:95
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
unsigned char * LPBYTE
Definition: typedefs.h:53
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
WINBOOL WINAPI GetPrintProcessorDirectoryW(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( EnumPrintProcessorDatatypesW  )

Definition at line 19 of file EnumPrintProcessorDatatypesW.c.

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}
BOOL(WINAPI * PEnumPrintProcessorDatatypesW)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD)
PVOID GetWinprintFunc(const char *FunctionName)
Definition: main.c:17
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
BYTE * PBYTE
Definition: pedump.c:66