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: Tests for fpGetPrintProcessorDirectory
5 * COPYRIGHT: Copyright 2016 Colin Finck <colin@reactos.org>
10 #define WIN32_NO_STATUS
18 #include "../localspl_apitest.h"
21 typedef BOOL (WINAPI
*PGetPrintProcessorDirectoryW
)(LPWSTR
, LPWSTR
, DWORD
, LPBYTE
, DWORD
, LPDWORD
);
22 extern BOOL
GetLocalsplFuncs(LPPRINTPROVIDOR pp
);
23 extern PVOID
GetSpoolssFunc(const char* FunctionName
);
25 START_TEST(fpGetPrintProcessorDirectory
)
30 PGetPrintProcessorDirectoryW pGetPrintProcessorDirectoryW
;
34 if (!GetLocalsplFuncs(&pp
))
37 pGetPrintProcessorDirectoryW
= GetSpoolssFunc("GetPrintProcessorDirectoryW");
38 if (!pGetPrintProcessorDirectoryW
)
41 // In contrast to GetPrintProcessorDirectoryW, fpGetPrintProcessorDirectory needs an environment and doesn't just accept NULL.
42 SetLastError(0xDEADBEEF);
43 ok(!pp
.fpGetPrintProcessorDirectory(NULL
, NULL
, 0, NULL
, 0, NULL
), "fpGetPrintProcessorDirectory returns TRUE!\n");
44 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT
, "fpGetPrintProcessorDirectory returns error %lu!\n", GetLastError());
46 // Try with an invalid environment as well.
47 SetLastError(0xDEADBEEF);
48 ok(!pp
.fpGetPrintProcessorDirectory(NULL
, L
"invalid", 0, NULL
, 0, NULL
), "fpGetPrintProcessorDirectory returns TRUE!\n");
49 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT
, "fpGetPrintProcessorDirectory returns error %lu!\n", GetLastError());
51 // Now provide a valid environment and prove that it is checked case-insensitively.
52 // In contrast to GetPrintProcessorDirectoryW, the level isn't the next thing checked here, but fpGetPrintProcessorDirectory
53 // already tries to access the non-supplied pcbNeeded variable.
57 pp
.fpGetPrintProcessorDirectory(NULL
, L
"wIndows nt x86", 0, NULL
, 0, NULL
);
59 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
61 dwReturned
= _SEH2_GetExceptionCode();
65 ok(dwReturned
== EXCEPTION_ACCESS_VIOLATION
, "dwReturned is %lu!\n", dwReturned
);
67 // fpGetPrintProcessorDirectory doesn't care about the supplied level at all. Prove this here.
68 // With no buffer given, this needs to fail with ERROR_INSUFFICIENT_BUFFER.
69 SetLastError(0xDEADBEEF);
71 ok(!pp
.fpGetPrintProcessorDirectory(NULL
, L
"wIndows nt x86", 1337, NULL
, 0, &cbNeeded
), "fpGetPrintProcessorDirectory returns TRUE!\n");
72 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "fpGetPrintProcessorDirectory returns error %lu!\n", GetLastError());
73 ok(cbNeeded
> 0, "cbNeeded is %lu!\n", cbNeeded
);
75 // Now provide the demanded size, but no buffer.
76 // Unlike GetPrintProcessorDirectoryW, fpGetPrintProcessorDirectory doesn't check for this case and tries to access the buffer.
80 pp
.fpGetPrintProcessorDirectory(NULL
, L
"wIndows nt x86", 1, NULL
, cbNeeded
, &cbTemp
);
82 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
84 dwReturned
= _SEH2_GetExceptionCode();
88 ok(dwReturned
== EXCEPTION_ACCESS_VIOLATION
, "dwReturned is %lu!\n", dwReturned
);
90 // Prove that this check is implemented in spoolss' GetPrintProcessorDirectoryW instead.
91 // In contrast to winspool's GetPrintProcessorDirectoryW, cbTemp is left untouched though. This comes from the fact that RPC isn't involved here.
92 SetLastError(0xDEADBEEF);
94 ok(!pGetPrintProcessorDirectoryW(NULL
, L
"wIndows nt x86", 1, NULL
, cbNeeded
, &cbTemp
), "pGetPrintProcessorDirectoryW returns TRUE!\n");
95 ok(GetLastError() == ERROR_INVALID_USER_BUFFER
, "pGetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
96 ok(cbTemp
== 0xDEADBEEF, "cbTemp is %lu!\n", cbTemp
);
98 // Finally use the function as intended and aim for success!
99 // We only check success by the boolean return value though. GetLastError doesn't return anything meaningful here.
100 pwszBuffer
= DllAllocSplMem(cbNeeded
);
101 SetLastError(0xDEADBEEF);
102 ok(pp
.fpGetPrintProcessorDirectory(NULL
, L
"wIndows nt x86", 1, (PBYTE
)pwszBuffer
, cbNeeded
, &cbTemp
), "fpGetPrintProcessorDirectory returns FALSE!\n");
103 ok(wcslen(pwszBuffer
) == cbNeeded
/ sizeof(WCHAR
) - 1, "fpGetPrintProcessorDirectory string is %Iu characters long, but %lu characters expected!\n", wcslen(pwszBuffer
), cbNeeded
/ sizeof(WCHAR
) - 1);
104 DllFreeSplMem(pwszBuffer
);