[LOCALSPL_APITEST]
[reactos.git] / rostests / apitests / winspool / GetPrintProcessorDirectory.c
1 /*
2 * PROJECT: ReactOS Print Spooler DLL API Tests
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Tests for GetPrintProcessorDirectoryA/GetPrintProcessorDirectoryW
5 * COPYRIGHT: Copyright 2015-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 <winspool.h>
15
16 START_TEST(GetPrintProcessorDirectoryA)
17 {
18 DWORD cbNeeded;
19 DWORD cbTemp;
20 PSTR pszBuffer;
21
22 // Try with an invalid level, this needs to be caught first.
23 SetLastError(0xDEADBEEF);
24 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 0, NULL, 0, NULL), "GetPrintProcessorDirectoryA returns TRUE!\n");
25 ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
26
27 // Now try with valid level, but no pcbNeeded.
28 SetLastError(0xDEADBEEF);
29 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryA returns TRUE!\n");
30 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
31
32 // Try with an invalid environment as well.
33 SetLastError(0xDEADBEEF);
34 cbNeeded = 0xDEADBEEF;
35 ok(!GetPrintProcessorDirectoryA(NULL, "invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n");
36 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
37 ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded);
38
39 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
40 // Note for GetPrintProcessorDirectoryA: cbNeeded will be the same as for GetPrintProcessorDirectoryW, even though the ANSI string only needs half of it!
41 SetLastError(0xDEADBEEF);
42 cbNeeded = 0;
43 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n");
44 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
45 ok(cbNeeded > 0, "cbNeeded is 0!\n");
46
47 // Now provide the demanded size, but no buffer.
48 SetLastError(0xDEADBEEF);
49 cbTemp = 0xDEADBEEF;
50 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n");
51 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
52 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
53
54 // Same error has to occur with a size too small.
55 SetLastError(0xDEADBEEF);
56 cbTemp = 0xDEADBEEF;
57 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n");
58 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
59 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
60
61 // Finally use the function as intended and aim for success!
62 pszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded);
63 SetLastError(0xDEADBEEF);
64 ok(GetPrintProcessorDirectoryA(NULL, NULL, 1, (PBYTE)pszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns FALSE!\n");
65 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
66
67 // Note for GetPrintProcessorDirectoryA: cbNeeded is the same as for GetPrintProcessorDirectoryW!
68 ok(strlen(pszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryA string is %Iu characters long, but %lu characters expected!\n", strlen(pszBuffer), cbNeeded / sizeof(WCHAR) - 1);
69 HeapFree(GetProcessHeap(), 0, pszBuffer);
70 }
71
72 START_TEST(GetPrintProcessorDirectoryW)
73 {
74 DWORD cbNeeded;
75 DWORD cbTemp;
76 PWSTR pwszBuffer;
77
78 // Try with an invalid level, this needs to be caught first.
79 SetLastError(0xDEADBEEF);
80 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 0, NULL, 0, NULL), "GetPrintProcessorDirectoryW returns TRUE!\n");
81 ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
82
83 // Now try with valid level, but no pcbNeeded.
84 SetLastError(0xDEADBEEF);
85 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryW returns TRUE!\n");
86 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
87
88 // Try with an invalid environment as well.
89 SetLastError(0xDEADBEEF);
90 cbNeeded = 0xDEADBEEF;
91 ok(!GetPrintProcessorDirectoryW(NULL, L"invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
92 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
93 ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded);
94
95 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
96 SetLastError(0xDEADBEEF);
97 cbNeeded = 0;
98 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
99 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
100 ok(cbNeeded > 0, "cbNeeded is 0!\n");
101
102 // Now provide the demanded size, but no buffer.
103 SetLastError(0xDEADBEEF);
104 cbTemp = 0xDEADBEEF;
105 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns TRUE!\n");
106 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
107 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
108
109 // Same error has to occur with a size too small.
110 SetLastError(0xDEADBEEF);
111 cbTemp = 0xDEADBEEF;
112 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryW returns TRUE!\n");
113 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
114 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
115
116 // Finally use the function as intended and aim for success!
117 pwszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded);
118 SetLastError(0xDEADBEEF);
119 ok(GetPrintProcessorDirectoryW(NULL, NULL, 1, (PBYTE)pwszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns FALSE!\n");
120 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
121 ok(wcslen(pwszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryW string is %Iu characters long, but %lu characters expected!\n", wcslen(pwszBuffer), cbNeeded / sizeof(WCHAR) - 1);
122 HeapFree(GetProcessHeap(), 0, pwszBuffer);
123 }