From 5fd422387080ffd8029b3199cf68e00089cdfd26 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Thu, 17 Nov 2016 21:24:07 +0000 Subject: [PATCH] [WINPRINT_APITEST] Load all functions to test dynamically from either winprint.dll in the Print Processor Directory (for ReactOS and NT6) or localspl.dll in the system path (for NT5). Should fix winprint_apitest on ReactOS and Windows Server 2003. svn path=/trunk/; revision=73247 --- rostests/apitests/winprint/CMakeLists.txt | 3 +- .../winprint/EnumPrintProcessorDatatypesW.c | 29 ++++++--- rostests/apitests/winprint/main.c | 62 +++++++++++++++++++ rostests/apitests/winprint/testlist.c | 5 +- 4 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 rostests/apitests/winprint/main.c diff --git a/rostests/apitests/winprint/CMakeLists.txt b/rostests/apitests/winprint/CMakeLists.txt index 68fa7d959b2..d9fd329bbec 100644 --- a/rostests/apitests/winprint/CMakeLists.txt +++ b/rostests/apitests/winprint/CMakeLists.txt @@ -1,10 +1,11 @@ list(APPEND SOURCE EnumPrintProcessorDatatypesW.c + main.c testlist.c) add_executable(winprint_apitest ${SOURCE}) target_link_libraries(winprint_apitest wine ${PSEH_LIB}) set_module_type(winprint_apitest win32cui) -add_importlibs(winprint_apitest winprint msvcrt kernel32 ntdll) +add_importlibs(winprint_apitest winspool msvcrt kernel32 ntdll) add_cd_file(TARGET winprint_apitest DESTINATION reactos/bin FOR all) diff --git a/rostests/apitests/winprint/EnumPrintProcessorDatatypesW.c b/rostests/apitests/winprint/EnumPrintProcessorDatatypesW.c index 551bfb93778..639615d3acd 100644 --- a/rostests/apitests/winprint/EnumPrintProcessorDatatypesW.c +++ b/rostests/apitests/winprint/EnumPrintProcessorDatatypesW.c @@ -2,7 +2,7 @@ * PROJECT: ReactOS Standard Print Processor API Tests * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation * PURPOSE: Tests for EnumPrintProcessorDatatypesW - * COPYRIGHT: Copyright 2015 Colin Finck + * COPYRIGHT: Copyright 2015-2016 Colin Finck */ #include @@ -13,61 +13,70 @@ #include #include +typedef BOOL (WINAPI *PEnumPrintProcessorDatatypesW)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD); +extern PVOID GetWinprintFunc(const char* FunctionName); + START_TEST(EnumPrintProcessorDatatypesW) { DWORD cbNeeded; DWORD cbTemp; DWORD dwReturned; PDATATYPES_INFO_1W pDatatypesInfo1; + PEnumPrintProcessorDatatypesW pEnumPrintProcessorDatatypesW; + + // Get the function we want to test from one of the possible Print Processor DLLs. + pEnumPrintProcessorDatatypesW = (PEnumPrintProcessorDatatypesW)GetWinprintFunc("EnumPrintProcessorDatatypesW"); + if (!pEnumPrintProcessorDatatypesW) + return; // Try with an invalid level. The error needs to be set by winspool, but not by the Print Processor. SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 0, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 0, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n"); ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); // Now try with valid level, but no pcbNeeded and no pcReturned. The error needs to be set by RPC. SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n"); ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); // Now try with pcbNeeded and pcReturned, but give no Print Processor. Show that winprint actually ignores the given Print Processor. SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); ok(cbNeeded > 0, "cbNeeded is 0!\n"); ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); // Same error has to occur when looking for an invalid Print Processor. SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, L"invalid", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(!pEnumPrintProcessorDatatypesW(NULL, L"invalid", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); ok(cbNeeded > 0, "cbNeeded is 0!\n"); ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); // Now get the required buffer size by supplying all information. This needs to fail with ERROR_INSUFFICIENT_BUFFER. SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); ok(cbNeeded > 0, "cbNeeded is 0!\n"); ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); // Same error has to occur with a size to small. SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 1, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 1, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintersW returns error %lu!\n", GetLastError()); ok(cbNeeded > 0, "cbNeeded is 0!\n"); ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); // Now provide the demanded size, but no buffer. Show that winprint returns a different error than the same function in winspool. SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); ok(cbTemp == cbNeeded, "cbTemp is %lu!\n", cbTemp); ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); // This also has to fail the same way when no Print Processor was given at all. SetLastError(0xDEADBEEF); - ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); + ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); ok(cbTemp == cbNeeded, "cbTemp is %lu!\n", cbTemp); ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned); @@ -75,7 +84,7 @@ START_TEST(EnumPrintProcessorDatatypesW) // Finally use the function as intended and aim for success! Show that winprint doesn't modify the error code at all. pDatatypesInfo1 = HeapAlloc(GetProcessHeap(), 0, cbNeeded); SetLastError(0xDEADBEEF); - ok(EnumPrintProcessorDatatypesW(NULL, L"winprint", 1, (PBYTE)pDatatypesInfo1, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns FALSE!\n"); + ok(pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, (PBYTE)pDatatypesInfo1, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns FALSE!\n"); ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError()); HeapFree(GetProcessHeap(), 0, pDatatypesInfo1); } diff --git a/rostests/apitests/winprint/main.c b/rostests/apitests/winprint/main.c new file mode 100644 index 00000000000..117b319521b --- /dev/null +++ b/rostests/apitests/winprint/main.c @@ -0,0 +1,62 @@ +/* + * PROJECT: ReactOS Standard Print Processor API Tests + * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation + * PURPOSE: Main functions + * COPYRIGHT: Copyright 2016 Colin Finck + */ + +#include + +#define WIN32_NO_STATUS +#include +#include +#include +#include + +PVOID +GetWinprintFunc(const char* FunctionName) +{ + DWORD cbNeeded; + HMODULE hWinprint; + PVOID pFunc; + WCHAR wszWinprintPath[MAX_PATH]; + + // Build the path to the default Print Processor winprint.dll in the Print Processor directory. + if (!GetPrintProcessorDirectoryW(NULL, NULL, 1, (LPBYTE)wszWinprintPath, sizeof(wszWinprintPath), &cbNeeded)) + { + skip("Could not determine the path to the Print Processor directory, last error is %lu!\n", GetLastError()); + return NULL; + } + + wcscat(wszWinprintPath, L"\\winprint.dll"); + + // Try loading it. + hWinprint = LoadLibraryW(wszWinprintPath); + if (!hWinprint) + { + if (GetLastError() != ERROR_MOD_NOT_FOUND) + { + skip("LoadLibraryW failed for %S with error %lu!\n", wszWinprintPath, GetLastError()); + return NULL; + } + + // winprint.dll does not exist prior to NT6. + // The default Print Processor is implemented in localspl.dll instead. + hWinprint = LoadLibraryW(L"localspl.dll"); + if (!hWinprint) + { + skip("LoadLibraryW failed for localspl.dll with error %lu!\n", GetLastError()); + return NULL; + } + } + + // Get the function we are looking for. + pFunc = GetProcAddress(hWinprint, FunctionName); + if (!pFunc) + { + skip("GetProcAddress failed for %s with error %lu!\n", FunctionName, GetLastError()); + return NULL; + } + + return pFunc; +} diff --git a/rostests/apitests/winprint/testlist.c b/rostests/apitests/winprint/testlist.c index 1ad91aba8c9..057823a8b22 100644 --- a/rostests/apitests/winprint/testlist.c +++ b/rostests/apitests/winprint/testlist.c @@ -2,7 +2,7 @@ * PROJECT: ReactOS Standard Print Processor API Tests * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation * PURPOSE: Test list - * COPYRIGHT: Copyright 2015 Colin Finck + * COPYRIGHT: Copyright 2015-2016 Colin Finck */ /* @@ -10,9 +10,6 @@ * While ReactOS implements the Standard Print Processor in a separate module winprint.dll, * Windows Server 2003 puts it into the Local Print Spooler localspl.dll. * - * To test against Windows, simply run these tests under Windows Server 2003, but copy its - * localspl.dll to winprint.dll in advance. - * * winspool.drv also provides functions that go into winprint.dll, but as these tests show, * they behave slightly different in terms of error codes due to the involved RPC and routing. */