Time to commit some Work-In-Progress stuff before my diff gets too large..
[reactos.git] / rostests / apitests / winspool / EnumPrintProcessorDatatypes.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 EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW
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(EnumPrintProcessorDatatypes)
17 {
18 DWORD cbNeeded;
19 DWORD dwReturned;
20 PDATATYPES_INFO_1W pDatatypesInfo1;
21
22 // Try with an invalid level, this needs to be caught first.
23 SetLastError(0xDEADBEEF);
24 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 0, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
25 ok(GetLastError() == ERROR_INVALID_LEVEL, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
26
27 // Now try with valid level, but no pcbNeeded and no pcReturned.
28 SetLastError(0xDEADBEEF);
29 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
30 ok(GetLastError() == RPC_X_NULL_REF_POINTER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
31
32 // Now try with pcbNeeded and pcReturned, but give no Print Processor.
33 SetLastError(0xDEADBEEF);
34 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
35 ok(GetLastError() == ERROR_UNKNOWN_PRINTPROCESSOR, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
36
37 // Same error has to occur when looking for an invalid Print Processor.
38 SetLastError(0xDEADBEEF);
39 ok(!EnumPrintProcessorDatatypesW(NULL, L"invalid", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
40 ok(GetLastError() == ERROR_UNKNOWN_PRINTPROCESSOR, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
41
42 // Now get the required buffer size by supplying all information. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
43 // This also verifies that the function is really doing a case-insensitive lookup.
44 SetLastError(0xDEADBEEF);
45 ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
46 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
47 ok(cbNeeded > 0, "cbNeeded is 0!\n");
48 ok(dwReturned > 0, "dwReturned is 0!\n");
49
50 // Now provide the demanded size, but no buffer.
51 SetLastError(0xDEADBEEF);
52 ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
53 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
54
55 // This also has to fail the same way when no Print Processor was given at all.
56 SetLastError(0xDEADBEEF);
57 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
58 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
59
60 // Same error has to occur with a valid Print Processor, but a size too small.
61 SetLastError(0xDEADBEEF);
62 ok(!EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, NULL, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
63 ok(GetLastError() == ERROR_INVALID_USER_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
64
65 // Finally use the function as intended and aim for success!
66 pDatatypesInfo1 = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
67 SetLastError(0xDEADBEEF);
68 ok(EnumPrintProcessorDatatypesW(NULL, L"wInPrInT", 1, (PBYTE)pDatatypesInfo1, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns FALSE!\n");
69 ok(GetLastError() == ERROR_SUCCESS, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
70 HeapFree(GetProcessHeap(), 0, pDatatypesInfo1);
71 }