[LOCALSPL_APITEST]
[reactos.git] / rostests / apitests / localspl / dll / fpGetPrintProcessorDirectory.c
1 /*
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>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <windef.h>
12 #include <winbase.h>
13 #include <wingdi.h>
14 #include <winreg.h>
15 #include <winspool.h>
16 #include <winsplp.h>
17
18 #include "../localspl_apitest.h"
19 #include <spoolss.h>
20
21 extern BOOL GetLocalsplFuncs(LPPRINTPROVIDOR pp);
22
23 START_TEST(fpGetPrintProcessorDirectory)
24 {
25 DWORD cbNeeded;
26 DWORD cbTemp;
27 DWORD dwReturned;
28 PRINTPROVIDOR pp;
29 PWSTR pwszBuffer;
30
31 if (!GetLocalsplFuncs(&pp))
32 return;
33
34 // In contrast to GetPrintProcessorDirectoryW, fpGetPrintProcessorDirectory needs an environment and doesn't just accept NULL.
35 SetLastError(0xDEADBEEF);
36 ok(!pp.fpGetPrintProcessorDirectory(NULL, NULL, 0, NULL, 0, NULL), "fpGetPrintProcessorDirectory returns TRUE!\n");
37 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "fpGetPrintProcessorDirectory returns error %lu!\n", GetLastError());
38
39 // Try with an invalid environment as well.
40 SetLastError(0xDEADBEEF);
41 ok(!pp.fpGetPrintProcessorDirectory(NULL, L"invalid", 0, NULL, 0, NULL), "fpGetPrintProcessorDirectory returns TRUE!\n");
42 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "fpGetPrintProcessorDirectory returns error %lu!\n", GetLastError());
43
44 // Now provide a valid environment and prove that it is checked case-insensitively.
45 // In contrast to GetPrintProcessorDirectoryW, the level isn't the next thing checked here, but fpGetPrintProcessorDirectory
46 // already tries to access the non-supplied pcbNeeded variable.
47 _SEH2_TRY
48 {
49 dwReturned = 0;
50 pp.fpGetPrintProcessorDirectory(NULL, L"wIndows nt x86", 0, NULL, 0, NULL);
51 }
52 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
53 {
54 dwReturned = _SEH2_GetExceptionCode();
55 }
56 _SEH2_END;
57
58 ok(dwReturned == EXCEPTION_ACCESS_VIOLATION, "dwReturned is %lu!\n", dwReturned);
59
60 // fpGetPrintProcessorDirectory doesn't care about the supplied level at all. Prove this here.
61 // With no buffer given, this needs to fail with ERROR_INSUFFICIENT_BUFFER.
62 SetLastError(0xDEADBEEF);
63 cbNeeded = 0;
64 ok(!pp.fpGetPrintProcessorDirectory(NULL, L"wIndows nt x86", 1337, NULL, 0, &cbNeeded), "fpGetPrintProcessorDirectory returns TRUE!\n");
65 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "fpGetPrintProcessorDirectory returns error %lu!\n", GetLastError());
66 ok(cbNeeded > 0, "cbNeeded is %lu!\n", cbNeeded);
67
68 // Now provide the demanded size, but no buffer.
69 // Unlike GetPrintProcessorDirectoryW, fpGetPrintProcessorDirectory doesn't check for this case and tries to access the buffer.
70 _SEH2_TRY
71 {
72 dwReturned = 0;
73 pp.fpGetPrintProcessorDirectory(NULL, L"wIndows nt x86", 1, NULL, cbNeeded, &cbTemp);
74 }
75 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
76 {
77 dwReturned = _SEH2_GetExceptionCode();
78 }
79 _SEH2_END;
80
81 ok(dwReturned == EXCEPTION_ACCESS_VIOLATION, "dwReturned is %lu!\n", dwReturned);
82
83 // Finally use the function as intended and aim for success!
84 // We only check success by the boolean return value though. GetLastError doesn't return anything meaningful here.
85 pwszBuffer = DllAllocSplMem(cbNeeded);
86 SetLastError(0xDEADBEEF);
87 ok(pp.fpGetPrintProcessorDirectory(NULL, L"wIndows nt x86", 1, (PBYTE)pwszBuffer, cbNeeded, &cbTemp), "fpGetPrintProcessorDirectory returns FALSE!\n");
88 ok(wcslen(pwszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "fpGetPrintProcessorDirectory string is %Iu characters long, but %lu characters expected!\n", wcslen(pwszBuffer), cbNeeded / sizeof(WCHAR) - 1);
89 DllFreeSplMem(pwszBuffer);
90 }