ReactOS 0.4.16-dev-1946-g52006dd
main.c File Reference
#include <apitest.h>
#include <io.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winreg.h>
#include <winspool.h>
#include <winsplp.h>
#include "../localspl_apitest.h"
#include <debug.h>
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define STANDALONE
 
#define WIN32_NO_STATUS
 

Functions

void func_fpEnumPrinters (void)
 
void func_fpGetPrintProcessorDirectory (void)
 
void func_fpSetJob (void)
 
PWSTR GetDefaultPrinterFromRegistry (VOID)
 
BOOL GetLocalsplFuncs (LPPRINTPROVIDOR pp)
 
PVOID GetSpoolssFunc (const char *FunctionName)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

const struct test winetest_testlist []
 

Macro Definition Documentation

◆ STANDALONE

#define STANDALONE

Definition at line 8 of file main.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file main.c.

Function Documentation

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 157 of file main.c.

158{
159 char szTestName[150];
160 DWORD cbRead;
161 FILE* fpStdout;
162 HANDLE hCommandPipe;
163 int iOldStdout;
164
165 // We only want to run our test once when the DLL is injected to the process.
167 return TRUE;
168
169 // Read the test to run from the command pipe.
171 if (hCommandPipe == INVALID_HANDLE_VALUE)
172 {
173 DPRINT("DLL: CreateFileW failed for the command pipe with error %lu!\n", GetLastError());
174 return FALSE;
175 }
176
177 if (!ReadFile(hCommandPipe, szTestName, sizeof(szTestName), &cbRead, NULL))
178 {
179 DPRINT("DLL: ReadFile failed for the command pipe with error %lu!\n", GetLastError());
180 return FALSE;
181 }
182
183 CloseHandle(hCommandPipe);
184
185 // Check if the test name is valid.
186 if (!find_test(szTestName))
187 {
188 DPRINT("DLL: Got invalid test name \"%s\"!\n", szTestName);
189 return FALSE;
190 }
191
192 // Backup our current stdout and set it to the output pipe.
193 iOldStdout = _dup(_fileno(stdout));
194 fpStdout = _wfreopen(OUTPUT_PIPE_NAME, L"w", stdout);
196
197 // Run the test.
198 run_test(szTestName);
199
200 // Restore stdout to the previous value.
201 fclose(fpStdout);
202 _dup2(iOldStdout, _fileno(stdout));
203
204 // Return FALSE so that our DLL is immediately unloaded.
205 return FALSE;
206}
static DWORD const fdwReason
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
#define stdout
Definition: stdio.h:99
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl _wfreopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode, _Inout_ FILE *_OldFile)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_CRTIMP void __cdecl setbuf(_Inout_ FILE *_File, _Inout_updates_opt_(BUFSIZ) _Post_readable_size_(0) char *_Buffer)
#define COMMAND_PIPE_NAME
#define OUTPUT_PIPE_NAME
#define run_test(test)
Definition: ms_seh.c:71
_Check_return_ _CRTIMP int __cdecl _dup2(_In_ int _FileHandleSrc, _In_ int _FileHandleDst)
_Check_return_ _CRTIMP int __cdecl _dup(_In_ int _FileHandle)
#define DPRINT
Definition: sndvol32.h:73
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ func_fpEnumPrinters()

void func_fpEnumPrinters ( void  )

◆ func_fpGetPrintProcessorDirectory()

void func_fpGetPrintProcessorDirectory ( void  )

◆ func_fpSetJob()

void func_fpSetJob ( void  )

◆ GetDefaultPrinterFromRegistry()

PWSTR GetDefaultPrinterFromRegistry ( VOID  )

We don't link against winspool, so we don't have GetDefaultPrinterW. We can easily implement a similar function ourselves though.

Definition at line 43 of file main.c.

44{
45 static const WCHAR wszWindowsKey[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows";
46 static const WCHAR wszDeviceValue[] = L"Device";
47
48 DWORD cbNeeded;
49 DWORD dwErrorCode;
50 HKEY hWindowsKey = NULL;
51 PWSTR pwszDevice;
52 PWSTR pwszComma;
53 PWSTR pwszReturnValue = NULL;
54
55 // Open the registry key where the default printer for the current user is stored.
56 dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_CURRENT_USER, wszWindowsKey, 0, KEY_READ, &hWindowsKey);
57 if (dwErrorCode != ERROR_SUCCESS)
58 {
59 skip("RegOpenKeyExW failed with status %u!\n", dwErrorCode);
60 goto Cleanup;
61 }
62
63 // Determine the size of the required buffer.
64 dwErrorCode = (DWORD)RegQueryValueExW(hWindowsKey, wszDeviceValue, NULL, NULL, NULL, &cbNeeded);
65 if (dwErrorCode != ERROR_SUCCESS)
66 {
67 skip("RegQueryValueExW failed with status %u!\n", dwErrorCode);
68 goto Cleanup;
69 }
70
71 // Allocate it.
72 pwszDevice = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
73 if (!pwszDevice)
74 {
75 skip("HeapAlloc failed!\n");
76 goto Cleanup;
77 }
78
79 // Now get the actual value.
80 dwErrorCode = RegQueryValueExW(hWindowsKey, wszDeviceValue, NULL, NULL, (PBYTE)pwszDevice, &cbNeeded);
81 if (dwErrorCode != ERROR_SUCCESS)
82 {
83 skip("RegQueryValueExW failed with status %u!\n", dwErrorCode);
84 goto Cleanup;
85 }
86
87 // We get a string "<Printer Name>,winspool,<Port>:".
88 // Extract the printer name from it.
89 pwszComma = wcschr(pwszDevice, L',');
90 if (!pwszComma)
91 {
92 skip("Found no or invalid default printer: %S!\n", pwszDevice);
93 goto Cleanup;
94 }
95
96 // Return the default printer.
97 *pwszComma = 0;
98 pwszReturnValue = pwszDevice;
99
100Cleanup:
101 if (hWindowsKey)
102 RegCloseKey(hWindowsKey);
103
104 return pwszReturnValue;
105}
#define skip(...)
Definition: atltest.h:64
static const WCHAR wszWindowsKey[]
Definition: printers.c:61
static const WCHAR wszDeviceValue[]
Definition: printers.c:62
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
static const WCHAR Cleanup[]
Definition: register.c:80
#define KEY_READ
Definition: nt_native.h:1026
#define DWORD
Definition: nt_native.h:44
BYTE * PBYTE
Definition: pedump.c:66
uint16_t * PWSTR
Definition: typedefs.h:56
#define HKEY_CURRENT_USER
Definition: winreg.h:11
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ GetLocalsplFuncs()

BOOL GetLocalsplFuncs ( LPPRINTPROVIDOR  pp)

Definition at line 108 of file main.c.

109{
110 HMODULE hLocalspl;
111 PInitializePrintProvidor pfnInitializePrintProvidor;
112
113 // Get us a handle to the loaded localspl.dll.
114 hLocalspl = GetModuleHandleW(L"localspl");
115 if (!hLocalspl)
116 {
117 skip("GetModuleHandleW failed with error %u!\n", GetLastError());
118 return FALSE;
119 }
120
121 // Get a pointer to its InitializePrintProvidor function.
122 pfnInitializePrintProvidor = (PInitializePrintProvidor)GetProcAddress(hLocalspl, "InitializePrintProvidor");
123 if (!pfnInitializePrintProvidor)
124 {
125 skip("GetProcAddress failed with error %u!\n", GetLastError());
126 return FALSE;
127 }
128
129 // Get localspl's function pointers.
130 if (!pfnInitializePrintProvidor(pp, sizeof(PRINTPROVIDOR), NULL))
131 {
132 skip("pfnInitializePrintProvidor failed with error %u!\n", GetLastError());
133 return FALSE;
134 }
135
136 return TRUE;
137}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
BOOL(WINAPI * PInitializePrintProvidor)(LPPRINTPROVIDOR, DWORD, LPWSTR)

Referenced by START_TEST().

◆ GetSpoolssFunc()

PVOID GetSpoolssFunc ( const char FunctionName)

Definition at line 140 of file main.c.

141{
142 HMODULE hSpoolss;
143
144 // Get us a handle to the loaded spoolss.dll.
145 hSpoolss = GetModuleHandleW(L"spoolss");
146 if (!hSpoolss)
147 {
148 skip("GetModuleHandleW failed with error %u!\n", GetLastError());
149 return FALSE;
150 }
151
152 return GetProcAddress(hSpoolss, FunctionName);
153}
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

Referenced by START_TEST().

Variable Documentation

◆ winetest_testlist

const struct test winetest_testlist[]
Initial value:
=
{
{ "fpEnumPrinters", func_fpEnumPrinters },
{ "fpGetPrintProcessorDirectory", func_fpGetPrintProcessorDirectory },
{ "fpSetJob", func_fpSetJob },
{ 0, 0 }
}
void func_fpGetPrintProcessorDirectory(void)
void func_fpSetJob(void)
void func_fpEnumPrinters(void)

Definition at line 30 of file main.c.