ReactOS 0.4.15-dev-8138-g1e75ea8
GetPrinterData.c File Reference
#include <apitest.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winspool.h>
#include <winreg.h>
Include dependency graph for GetPrinterData.c:

Go to the source code of this file.

Classes

struct  _SPLREG_VALUE
 

Macros

#define WIN32_NO_STATUS
 
#define MAX_PRINTER_NAME   220
 

Typedefs

typedef struct _SPLREG_VALUE SPLREG_VALUE
 
typedef struct _SPLREG_VALUEPSPLREG_VALUE
 

Functions

 START_TEST (GetPrinterData)
 

Variables

SPLREG_VALUE SplRegValues []
 

Macro Definition Documentation

◆ MAX_PRINTER_NAME

#define MAX_PRINTER_NAME   220

Definition at line 18 of file GetPrinterData.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file GetPrinterData.c.

Typedef Documentation

◆ PSPLREG_VALUE

◆ SPLREG_VALUE

Function Documentation

◆ START_TEST()

START_TEST ( GetPrinterData  )

Definition at line 66 of file GetPrinterData.c.

67{
68 DWORD cbNeeded;
69 DWORD cchDefaultPrinter;
70 DWORD dwReturnCode;
71 DWORD dwType;
72 HANDLE hPrinter;
73 PBYTE pDataA;
74 PBYTE pDataW;
76 WCHAR wszDefaultPrinter[MAX_PRINTER_NAME + 1];
77
78 // Don't supply any parameters, this has to fail with ERROR_INVALID_HANDLE!
79 dwReturnCode = GetPrinterDataExW(NULL, NULL, NULL, NULL, NULL, 0, NULL);
80 ok(dwReturnCode == ERROR_INVALID_HANDLE, "GetPrinterDataExW returns error %lu!\n", dwReturnCode);
81
82 // Open a handle to the local print server.
83 if (!OpenPrinterW(NULL, &hPrinter, NULL))
84 {
85 skip("Could not retrieve a handle to the local print server!\n");
86 return;
87 }
88
89 // Now try with valid handle, but leave remaining parameters NULL.
90 dwReturnCode = GetPrinterDataExW(hPrinter, NULL, NULL, NULL, NULL, 0, NULL);
91 ok(dwReturnCode == RPC_X_NULL_REF_POINTER, "GetPrinterDataExW returns error %lu!\n", dwReturnCode);
92
93 // Try all valid Print Server data values.
94 for (p = SplRegValues; p->pszName; p++)
95 {
96 // Try the ANSI version of the function.
97 dwType = 0xDEADBEEF;
98 dwReturnCode = GetPrinterDataExA(hPrinter, NULL, p->pszName, &dwType, NULL, 0, &cbNeeded);
99 ok(dwReturnCode == ERROR_MORE_DATA || dwReturnCode == ERROR_FILE_NOT_FOUND, "GetPrinterDataExA returns %lu for \"%s\"!\n", dwReturnCode, p->pszName);
100 if (dwReturnCode != ERROR_MORE_DATA)
101 continue;
102
103 ok(dwType == p->dwType, "dwType is %lu for \"%s\"!\n", dwType, p->pszName);
104
105 if (p->cbNeededA < 0xFFFFFFFF)
106 ok(cbNeeded == p->cbNeededA, "cbNeeded is %lu for \"%s\", but expected %lu!\n", cbNeeded, p->pszName, p->cbNeededA);
107 else
108 ok(cbNeeded > 0, "cbNeeded is 0 for \"%s\"!\n", p->pszName);
109
110 pDataA = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
111 dwReturnCode = GetPrinterDataExA(hPrinter, NULL, p->pszName, NULL, pDataA, cbNeeded, &cbNeeded);
112 ok(dwReturnCode == ERROR_SUCCESS, "GetPrinterDataExA returns %lu for \"%s\"!\n", dwReturnCode, p->pszName);
113
114 // Try the Unicode version of the function too.
115 dwType = 0xDEADBEEF;
116 dwReturnCode = GetPrinterDataExW(hPrinter, NULL, p->pwszName, &dwType, NULL, 0, &cbNeeded);
117 ok(dwReturnCode == ERROR_MORE_DATA, "GetPrinterDataExW returns %lu for \"%s\"!\n", dwReturnCode, p->pszName);
118 ok(dwType == p->dwType, "dwType is %lu for \"%s\"!\n", dwType, p->pszName);
119
120 pDataW = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
121 dwReturnCode = GetPrinterDataExW(hPrinter, NULL, p->pwszName, NULL, pDataW, cbNeeded, &cbNeeded);
122 ok(dwReturnCode == ERROR_SUCCESS, "GetPrinterDataExW returns %lu for \"%s\"!\n", dwReturnCode, p->pszName);
123
124 // Verify that OSVERSIONINFO structures are correctly returned.
125 if (strcmp(p->pszName, "OSVersion") == 0)
126 {
127 POSVERSIONINFOA pOSVersionInfoA = (POSVERSIONINFOA)pDataA;
128 POSVERSIONINFOW pOSVersionInfoW = (POSVERSIONINFOW)pDataW;
129 ok(pOSVersionInfoA->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA), "dwOSVersionInfoSize is %lu!\n", pOSVersionInfoA->dwOSVersionInfoSize);
130 ok(pOSVersionInfoW->dwOSVersionInfoSize == sizeof(OSVERSIONINFOW), "dwOSVersionInfoSize is %lu!\n", pOSVersionInfoW->dwOSVersionInfoSize);
131 }
132 else if (strcmp(p->pszName, "OSVersionEx") == 0)
133 {
134 POSVERSIONINFOEXA pOSVersionInfoA = (POSVERSIONINFOEXA)pDataA;
135 POSVERSIONINFOEXW pOSVersionInfoW = (POSVERSIONINFOEXW)pDataW;
136 ok(pOSVersionInfoA->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA), "dwOSVersionInfoSize is %lu!\n", pOSVersionInfoA->dwOSVersionInfoSize);
137 ok(pOSVersionInfoW->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW), "dwOSVersionInfoSize is %lu!\n", pOSVersionInfoW->dwOSVersionInfoSize);
138 }
139
140 // Shortly test SetPrinterDataExW by setting the same data we just retrieved.
141 if (p->bSettable)
142 {
143 dwReturnCode = SetPrinterDataExW(hPrinter, NULL, p->pwszName, dwType, pDataW, cbNeeded);
144 ok(dwReturnCode == ERROR_SUCCESS, "SetPrinterDataExW returns %lu for \"%s\"!\n", dwReturnCode, p->pszName);
145 }
146
147 HeapFree(GetProcessHeap(), 0, pDataA);
148 HeapFree(GetProcessHeap(), 0, pDataW);
149 }
150
151 // Try an invalid one.
152 dwReturnCode = GetPrinterDataExW(hPrinter, NULL, L"Invalid", NULL, NULL, 0, &cbNeeded);
153 ok(dwReturnCode == ERROR_INVALID_PARAMETER, "GetPrinterDataExW returns %lu!\n", dwReturnCode);
154
155 ClosePrinter(hPrinter);
156
157 // Open a handle to the default printer.
158 cchDefaultPrinter = _countof(wszDefaultPrinter);
159 ok(GetDefaultPrinterW(wszDefaultPrinter, &cchDefaultPrinter), "GetDefaultPrinterW returns FALSE and requires %lu characters!\n", cchDefaultPrinter);
160 if (!OpenPrinterW(wszDefaultPrinter, &hPrinter, NULL))
161 {
162 skip("Could not retrieve a handle to the default printer!\n");
163 return;
164 }
165
166 // Using NULL or L"" for pKeyName on a Printer handle yields ERROR_INVALID_PARAMETER.
167 dwReturnCode = GetPrinterDataExW(hPrinter, NULL, L"Name", NULL, NULL, 0, &cbNeeded);
168 ok(dwReturnCode == ERROR_INVALID_PARAMETER, "GetPrinterDataExW returns %lu!\n", dwReturnCode);
169 dwReturnCode = GetPrinterDataExW(hPrinter, L"", L"Name", NULL, NULL, 0, &cbNeeded);
170 ok(dwReturnCode == ERROR_INVALID_PARAMETER, "GetPrinterDataExW returns %lu!\n", dwReturnCode);
171
172 // Using L"\\" allows us to examine the contents of the main printer key anyway.
173 dwReturnCode = GetPrinterDataExW(hPrinter, L"\\", L"Name", &dwType, NULL, 0, &cbNeeded);
174 ok(dwReturnCode == ERROR_MORE_DATA, "GetPrinterDataExW returns %lu!\n", dwReturnCode);
175 ok(dwType == REG_SZ, "dwType is %lu!\n", dwType);
176 ok(cbNeeded > 0, "cbNeeded is 0!\n");
177
178 pDataW = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
179 dwReturnCode = GetPrinterDataExW(hPrinter, L"\\", L"Name", NULL, pDataW, cbNeeded, &cbNeeded);
180 ok(dwReturnCode == ERROR_SUCCESS, "GetPrinterDataExW returns %lu!\n", dwReturnCode);
181
182 // The following test fails if the default printer is a remote printer.
183 ok(wcscmp((PWSTR)pDataW, wszDefaultPrinter) == 0, "pDataW is \"%S\", default printer is \"%S\"!\n", (PWSTR)pDataW, wszDefaultPrinter);
184
185 // SetPrinterDataExW should return ERROR_ACCESS_DENIED when attempting to set the Name.
186 dwReturnCode = SetPrinterDataExW(hPrinter, L"\\", L"Name", REG_SZ, pDataW, cbNeeded);
187 ok(dwReturnCode == ERROR_ACCESS_DENIED, "SetPrinterDataExW returns %lu!\n", dwReturnCode);
188
189 HeapFree(GetProcessHeap(), 0, pDataW);
190}
#define MAX_PRINTER_NAME
SPLREG_VALUE SplRegValues[]
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat GLfloat p
Definition: glext.h:8902
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define _countof(array)
Definition: sndvol32.h:70
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:255
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
uint16_t * PWSTR
Definition: typedefs.h:56
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
DWORD WINAPI GetPrinterDataExA(HANDLE hPrinter, LPCSTR pKeyName, LPCSTR pValueName, LPDWORD pType, LPBYTE pData, DWORD nSize, LPDWORD pcbNeeded)
Definition: printerdata.c:333
WINBOOL WINAPI GetDefaultPrinterW(LPWSTR pszBuffer, LPDWORD pcchBuffer)
Definition: printers.c:1971
DWORD WINAPI SetPrinterDataExW(HANDLE hPrinter, LPCWSTR pKeyName, LPCWSTR pValueName, DWORD Type, LPBYTE pData, DWORD cbData)
Definition: printerdata.c:128
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2653
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176
DWORD WINAPI GetPrinterDataExW(HANDLE hPrinter, LPCWSTR pKeyName, LPCWSTR pValueName, LPDWORD pType, LPBYTE pData, DWORD nSize, LPDWORD pcbNeeded)
Definition: printerdata.c:101
struct _OSVERSIONINFOEXW * POSVERSIONINFOEXW
struct _OSVERSIONINFOW * POSVERSIONINFOW
struct _OSVERSIONINFOEXA * POSVERSIONINFOEXA
struct _OSVERSIONINFOA * POSVERSIONINFOA
__wchar_t WCHAR
Definition: xmlstorage.h:180

Variable Documentation

◆ SplRegValues

SPLREG_VALUE SplRegValues[]
Initial value:
= {
{ "DefaultSpoolDirectory", L"DefaultSpoolDirectory", REG_SZ, 0xFFFFFFFF, TRUE },
{ "PortThreadPriorityDefault", L"PortThreadPriorityDefault", REG_NONE, 4, FALSE },
{ "PortThreadPriority", L"PortThreadPriority", REG_DWORD, 4, TRUE },
{ "SchedulerThreadPriorityDefault", L"SchedulerThreadPriorityDefault", REG_NONE, 4, FALSE },
{ "SchedulerThreadPriority", L"SchedulerThreadPriority", REG_DWORD, 4, TRUE },
{ "BeepEnabled", L"BeepEnabled", REG_DWORD, 4, TRUE },
{ "EventLog", L"EventLog", REG_DWORD, 4, TRUE },
{ "MajorVersion", L"MajorVersion", REG_NONE, 4, FALSE },
{ "MinorVersion", L"MinorVersion", REG_NONE, 4, FALSE },
{ "Architecture", L"Architecture", REG_NONE, 0xFFFFFFFF, FALSE },
{ "OSVersion", L"OSVersion", REG_NONE, sizeof(OSVERSIONINFOA), FALSE },
{ "OSVersionEx", L"OSVersionEx", REG_NONE, sizeof(OSVERSIONINFOEXA), FALSE },
{ "RemoteFax", L"RemoteFax", REG_NONE, 4, FALSE },
{ "RestartJobOnPoolError", L"RestartJobOnPoolError", REG_DWORD, 4, TRUE },
{ "RestartJobOnPoolEnabled", L"RestartJobOnPoolEnabled", REG_DWORD, 4, TRUE },
{ "AllowUserManageForms", L"AllowUserManageForms", REG_DWORD, 4, TRUE },
{ NULL, NULL, 0, 0, FALSE }
}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define REG_NONE
Definition: nt_native.h:1492
#define REG_DWORD
Definition: sdbapi.c:596
struct _OSVERSIONINFOA OSVERSIONINFOA
struct _OSVERSIONINFOEXA OSVERSIONINFOEXA

Definition at line 30 of file GetPrinterData.c.

Referenced by START_TEST().