bece06e8bb7a3e45203e202e4e40c41ba1ff37bb
[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 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(GetPrintProcessorDirectory)
17 {
18 DWORD cbNeeded;
19 PWSTR pwszBuffer;
20
21 // Try with an invalid level, this needs to be caught first.
22 SetLastError(0xDEADBEEF);
23 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 0, NULL, 0, NULL), "GetPrintProcessorDirectoryW returns TRUE!\n");
24 ok(GetLastError() == ERROR_INVALID_LEVEL, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
25
26 // Now try with valid level, but no pcbNeeded.
27 SetLastError(0xDEADBEEF);
28 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, NULL), "GetPrintProcessorDirectoryW returns TRUE!\n");
29 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
30
31 // Now get the required buffer size by supplying pcbNeeded. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
32 SetLastError(0xDEADBEEF);
33 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
34 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
35 ok(cbNeeded > 0, "cbNeeded is 0!\n");
36
37 // Now provide the demanded size, but no buffer.
38 SetLastError(0xDEADBEEF);
39 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, cbNeeded, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
40 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
41
42 // Same error has to occur with a size too small.
43 SetLastError(0xDEADBEEF);
44 ok(!GetPrintProcessorDirectoryW(NULL, NULL, 1, NULL, 1, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
45 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
46
47 // Try with an invalid environment as well.
48 SetLastError(0xDEADBEEF);
49 ok(!GetPrintProcessorDirectoryW(NULL, L"invalid", 1, NULL, 0, &cbNeeded), "GetPrintProcessorDirectoryW returns TRUE!\n");
50 ok(GetLastError() == ERROR_INVALID_ENVIRONMENT, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
51
52 // Finally use the function as intended and aim for success!
53 pwszBuffer = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
54 SetLastError(0xDEADBEEF);
55 ok(GetPrintProcessorDirectoryW(NULL, NULL, 1, (PBYTE)pwszBuffer, cbNeeded, &cbNeeded), "GetPrintProcessorDirectoryW returns FALSE!\n");
56 ok(GetLastError() == ERROR_SUCCESS, "GetPrintProcessorDirectoryW returns error %lu!\n", GetLastError());
57 HeapFree(GetProcessHeap(), 0, pwszBuffer);
58 }