2 * PROJECT: ReactOS Local Spooler API Tests Injected DLL
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Main functions
5 * COPYRIGHT: Copyright 2015-2016 Colin Finck <colin@reactos.org>
13 #define WIN32_NO_STATUS
22 #include "../localspl_apitest.h"
28 extern void func_fpEnumPrinters(void);
29 extern void func_fpGetPrintProcessorDirectory(void);
31 const struct test winetest_testlist
[] =
33 { "fpEnumPrinters", func_fpEnumPrinters
},
34 { "fpGetPrintProcessorDirectory", func_fpGetPrintProcessorDirectory
},
39 GetLocalsplFuncs(LPPRINTPROVIDOR pp
)
42 PInitializePrintProvidor pfnInitializePrintProvidor
;
44 // Get us a handle to the loaded localspl.dll.
45 hLocalspl
= GetModuleHandleW(L
"localspl");
48 skip("GetModuleHandleW failed with error %u!\n", GetLastError());
52 // Get a pointer to its InitializePrintProvidor function.
53 pfnInitializePrintProvidor
= (PInitializePrintProvidor
)GetProcAddress(hLocalspl
, "InitializePrintProvidor");
54 if (!pfnInitializePrintProvidor
)
56 skip("GetProcAddress failed with error %u!\n", GetLastError());
60 // Get localspl's function pointers.
61 if (!pfnInitializePrintProvidor(pp
, sizeof(PRINTPROVIDOR
), NULL
))
63 skip("pfnInitializePrintProvidor failed with error %u!\n", GetLastError());
71 GetSpoolssFunc(const char* FunctionName
)
75 // Get us a handle to the loaded spoolss.dll.
76 hSpoolss
= GetModuleHandleW(L
"spoolss");
79 skip("GetModuleHandleW failed with error %u!\n", GetLastError());
83 return GetProcAddress(hSpoolss
, FunctionName
);
86 // Running the tests from the injected DLL and redirecting their output to the pipe.
88 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
96 // We only want to run our test once when the DLL is injected to the process.
97 if (fdwReason
!= DLL_PROCESS_ATTACH
)
100 // Read the test to run from the command pipe.
101 hCommandPipe
= CreateFileW(COMMAND_PIPE_NAME
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
102 if (hCommandPipe
== INVALID_HANDLE_VALUE
)
104 DPRINT("DLL: CreateFileW failed for the command pipe with error %lu!\n", GetLastError());
108 if (!ReadFile(hCommandPipe
, szTestName
, sizeof(szTestName
), &cbRead
, NULL
))
110 DPRINT("DLL: ReadFile failed for the command pipe with error %lu!\n", GetLastError());
114 CloseHandle(hCommandPipe
);
116 // Check if the test name is valid.
117 if (!find_test(szTestName
))
119 DPRINT("DLL: Got invalid test name \"%s\"!\n", szTestName
);
123 // Backup our current stdout and set it to the output pipe.
124 iOldStdout
= _dup(_fileno(stdout
));
125 fpStdout
= _wfreopen(OUTPUT_PIPE_NAME
, L
"w", stdout
);
126 setbuf(stdout
, NULL
);
129 run_test(szTestName
);
131 // Restore stdout to the previous value.
133 _dup2(iOldStdout
, _fileno(stdout
));
135 // Return FALSE so that our DLL is immediately unloaded.