ReactOS 0.4.16-dev-205-g7b2bb7e
GetPrintProcessorDirectory.c File Reference
#include <apitest.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winspool.h>
Include dependency graph for GetPrintProcessorDirectory.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

 START_TEST (GetPrintProcessorDirectoryA)
 
 START_TEST (GetPrintProcessorDirectoryW)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file GetPrintProcessorDirectory.c.

Function Documentation

◆ START_TEST() [1/2]

START_TEST ( GetPrintProcessorDirectoryA  )

Definition at line 16 of file GetPrintProcessorDirectory.c.

17{
18 DWORD cbNeeded;
19 DWORD cbTemp;
20 PSTR pszBuffer;
21
22 // Try with an invalid level, this needs to be caught first.
23 SetLastError(0xDEADBEEF);
24 cbNeeded = 0xDEADBEEF;
25 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 0, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n");
26 ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
27 ok(cbNeeded == 0xDEADBEEF, "cbNeeded is %lu!\n", cbNeeded);
28
29 // Now try with valid level, but no pcbNeeded.
30 SetLastError(0xDEADBEEF);
31 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryA returns TRUE!\n");
32 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
33
34 // Try with an invalid environment as well.
35 SetLastError(0xDEADBEEF);
36 cbNeeded = 0xDEADBEEF;
37 ok(!GetPrintProcessorDirectoryA(NULL, "invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n");
38 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
39 ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded);
40
41 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
42 // Note for GetPrintProcessorDirectoryA: cbNeeded will be the same as for GetPrintProcessorDirectoryW, even though the ANSI string only needs half of it!
43 SetLastError(0xDEADBEEF);
44 cbNeeded = 0;
45 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n");
46 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
47 ok(cbNeeded > 0, "cbNeeded is 0!\n");
48
49 // Now provide the demanded size, but no buffer.
50 SetLastError(0xDEADBEEF);
51 cbTemp = 0xDEADBEEF;
52 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n");
53 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
54 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
55
56 // Same error has to occur with a size too small.
57 SetLastError(0xDEADBEEF);
58 cbTemp = 0xDEADBEEF;
59 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n");
60 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
61 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
62
63 // Finally use the function as intended and aim for success!
64 pszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded);
65 SetLastError(0xDEADBEEF);
66 ok(GetPrintProcessorDirectoryA(NULL, NULL, 1, (PBYTE)pszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns FALSE!\n");
67 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
68
69 // Note for GetPrintProcessorDirectoryA: cbNeeded is the same as for GetPrintProcessorDirectoryW!
70 ok(strlen(pszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryA string is %Iu characters long, but %lu characters expected!\n", strlen(pszBuffer), cbNeeded / sizeof(WCHAR) - 1);
71 HeapFree(GetProcessHeap(), 0, pszBuffer);
72}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok(value,...)
Definition: atltest.h:57
#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
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned long DWORD
Definition: ntddk_ex.h:95
BYTE * PBYTE
Definition: pedump.c:66
char * PSTR
Definition: typedefs.h:51
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
#define ERROR_INVALID_USER_BUFFER
Definition: winerror.h:1091
#define ERROR_INVALID_ENVIRONMENT
Definition: winerror.h:1112
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
WINBOOL WINAPI GetPrintProcessorDirectoryA(LPSTR pName, LPSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded)
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ START_TEST() [2/2]

START_TEST ( GetPrintProcessorDirectoryW  )

Definition at line 74 of file GetPrintProcessorDirectory.c.

75{
76 DWORD cbNeeded;
77 DWORD cbTemp;
78 PWSTR pwszBuffer;
79
80 // Try with an invalid level, this needs to be caught first.
81 SetLastError(0xDEADBEEF);
82 cbNeeded = 0xDEADBEEF;
83 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 0, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
84 ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
85 ok(cbNeeded == 0xDEADBEEF, "cbNeeded is %lu!\n", cbNeeded);
86
87 // Now try with valid level, but no pcbNeeded.
88 SetLastError(0xDEADBEEF);
89 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryW returns TRUE!\n");
90 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
91
92 // Try with an invalid environment as well.
93 SetLastError(0xDEADBEEF);
94 cbNeeded = 0xDEADBEEF;
95 ok(!GetPrintProcessorDirectoryW(NULL, L"invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
96 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
97 ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded);
98
99 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
100 SetLastError(0xDEADBEEF);
101 cbNeeded = 0;
102 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
103 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
104 ok(cbNeeded > 0, "cbNeeded is 0!\n");
105
106 // Now provide the demanded size, but no buffer.
107 SetLastError(0xDEADBEEF);
108 cbTemp = 0xDEADBEEF;
109 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns TRUE!\n");
110 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
111 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
112
113 // Same error has to occur with a size too small.
114 SetLastError(0xDEADBEEF);
115 cbTemp = 0xDEADBEEF;
116 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryW returns TRUE!\n");
117 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
118 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
119
120 // Finally use the function as intended and aim for success!
121 pwszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded);
122 SetLastError(0xDEADBEEF);
123 ok(GetPrintProcessorDirectoryW(NULL, NULL, 1, (PBYTE)pwszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns FALSE!\n");
124 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
125 ok(wcslen(pwszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryW string is %Iu characters long, but %lu characters expected!\n", wcslen(pwszBuffer), cbNeeded / sizeof(WCHAR) - 1);
126 HeapFree(GetProcessHeap(), 0, pwszBuffer);
127}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define L(x)
Definition: ntvdm.h:50
uint16_t * PWSTR
Definition: typedefs.h:56
WINBOOL WINAPI GetPrintProcessorDirectoryW(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded)