551bfb937781e806c575dccf9b80295b958ad151
[reactos.git] / rostests / apitests / winprint / EnumPrintProcessorDatatypesW.c
1 /*
2 * PROJECT: ReactOS Standard Print Processor API Tests
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Tests for 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(EnumPrintProcessorDatatypesW)
17 {
18 DWORD cbNeeded;
19 DWORD cbTemp;
20 DWORD dwReturned;
21 PDATATYPES_INFO_1W pDatatypesInfo1;
22
23 // Try with an invalid level. The error needs to be set by winspool, but not by the Print Processor.
24 SetLastError(0xDEADBEEF);
25 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 0, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
26 ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
27
28 // Now try with valid level, but no pcbNeeded and no pcReturned. The error needs to be set by RPC.
29 SetLastError(0xDEADBEEF);
30 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
31 ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
32
33 // Now try with pcbNeeded and pcReturned, but give no Print Processor. Show that winprint actually ignores the given Print Processor.
34 SetLastError(0xDEADBEEF);
35 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
36 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
37 ok(cbNeeded > 0, "cbNeeded is 0!\n");
38 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
39
40 // Same error has to occur when looking for an invalid Print Processor.
41 SetLastError(0xDEADBEEF);
42 ok(!EnumPrintProcessorDatatypesW(NULL, L"invalid", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
43 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
44 ok(cbNeeded > 0, "cbNeeded is 0!\n");
45 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
46
47 // Now get the required buffer size by supplying all information. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
48 SetLastError(0xDEADBEEF);
49 ok(!EnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
50 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
51 ok(cbNeeded > 0, "cbNeeded is 0!\n");
52 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
53
54 // Same error has to occur with a size to small.
55 SetLastError(0xDEADBEEF);
56 ok(!EnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 1, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
57 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintersW returns error %lu!\n", GetLastError());
58 ok(cbNeeded > 0, "cbNeeded is 0!\n");
59 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
60
61 // Now provide the demanded size, but no buffer. Show that winprint returns a different error than the same function in winspool.
62 SetLastError(0xDEADBEEF);
63 ok(!EnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
64 ok(GetLastError() == ERROR_INVALID_PARAMETER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
65 ok(cbTemp == cbNeeded, "cbTemp is %lu!\n", cbTemp);
66 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
67
68 // This also has to fail the same way when no Print Processor was given at all.
69 SetLastError(0xDEADBEEF);
70 ok(!EnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
71 ok(GetLastError() == ERROR_INVALID_PARAMETER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
72 ok(cbTemp == cbNeeded, "cbTemp is %lu!\n", cbTemp);
73 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
74
75 // Finally use the function as intended and aim for success! Show that winprint doesn't modify the error code at all.
76 pDatatypesInfo1 = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
77 SetLastError(0xDEADBEEF);
78 ok(EnumPrintProcessorDatatypesW(NULL, L"winprint", 1, (PBYTE)pDatatypesInfo1, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns FALSE!\n");
79 ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
80 HeapFree(GetProcessHeap(), 0, pDatatypesInfo1);
81 }