[WINSPOOL_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 ok(!GetPrintProcessorDirectoryA(NULL, "invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n");
35 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
36 ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded);
37
38 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
39 // Note for GetPrintProcessorDirectoryA: cbNeeded will be the same as for GetPrintProcessorDirectoryW, even though the ANSI string only needs half of it!
40 SetLastError(0xDEADBEEF);
41 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryA returns TRUE!\n");
42 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
43 ok(cbNeeded > 0, "cbNeeded is 0!\n");
44
45 // Now provide the demanded size, but no buffer.
46 SetLastError(0xDEADBEEF);
47 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n");
48 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
49 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
50
51 // Same error has to occur with a size too small.
52 SetLastError(0xDEADBEEF);
53 ok(!GetPrintProcessorDirectoryA(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryA returns TRUE!\n");
54 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
55 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
56
57 // Finally use the function as intended and aim for success!
58 pszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded);
59 SetLastError(0xDEADBEEF);
60 ok(GetPrintProcessorDirectoryA(NULL, NULL, 1, (PBYTE)pszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryA returns FALSE!\n");
61 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryA returns error %lu!\n", GetLastError());
62
63 // Note for GetPrintProcessorDirectoryA: cbNeeded is the same as for GetPrintProcessorDirectoryW!
64 ok(strlen(pszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryA string is %Iu characters long, but %lu characters expected!\n", strlen(pszBuffer), cbNeeded / sizeof(WCHAR) - 1);
65 HeapFree(GetProcessHeap(), 0, pszBuffer);
66 }
67
68 START_TEST(GetPrintProcessorDirectoryW)
69 {
70 DWORD cbNeeded;
71 DWORD cbTemp;
72 PWSTR pwszBuffer;
73
74 // Try with an invalid level, this needs to be caught first.
75 SetLastError(0xDEADBEEF);
76 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 0, NULL, 0, NULL), "GetPrintProcessorDirectoryW returns TRUE!\n");
77 ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
78
79 // Now try with valid level, but no pcbNeeded.
80 SetLastError(0xDEADBEEF);
81 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryW returns TRUE!\n");
82 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
83
84 // Try with an invalid environment as well.
85 SetLastError(0xDEADBEEF);
86 ok(!GetPrintProcessorDirectoryW(NULL, L"invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
87 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
88 ok(cbNeeded == 0, "cbNeeded is %lu!\n", cbNeeded);
89
90 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
91 SetLastError(0xDEADBEEF);
92 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
93 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
94 ok(cbNeeded > 0, "cbNeeded is 0!\n");
95
96 // Now provide the demanded size, but no buffer.
97 SetLastError(0xDEADBEEF);
98 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns TRUE!\n");
99 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
100 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
101
102 // Same error has to occur with a size too small.
103 SetLastError(0xDEADBEEF);
104 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 1, &cbTemp), "GetPrintProcessorDirectoryW returns TRUE!\n");
105 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
106 ok(cbTemp == 0, "cbTemp is %lu!\n", cbTemp);
107
108 // Finally use the function as intended and aim for success!
109 pwszBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded);
110 SetLastError(0xDEADBEEF);
111 ok(GetPrintProcessorDirectoryW(NULL, NULL, 1, (PBYTE)pwszBuffer, cbNeeded, &cbTemp), "GetPrintProcessorDirectoryW returns FALSE!\n");
112 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
113 ok(wcslen(pwszBuffer) == cbNeeded / sizeof(WCHAR) - 1, "GetPrintProcessorDirectoryW string is %Iu characters long, but %lu characters expected!\n", wcslen(pwszBuffer), cbNeeded / sizeof(WCHAR) - 1);
114 HeapFree(GetProcessHeap(), 0, pwszBuffer);
115 }