[KMTESTS:MM]
[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-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 typedef BOOL (WINAPI *PEnumPrintProcessorDatatypesW)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD);
17 extern PVOID GetWinprintFunc(const char* FunctionName);
18
19 START_TEST(EnumPrintProcessorDatatypesW)
20 {
21 DWORD cbNeeded;
22 DWORD cbTemp;
23 DWORD dwReturned;
24 PDATATYPES_INFO_1W pDatatypesInfo1;
25 PEnumPrintProcessorDatatypesW pEnumPrintProcessorDatatypesW;
26
27 // Get the function we want to test from one of the possible Print Processor DLLs.
28 pEnumPrintProcessorDatatypesW = (PEnumPrintProcessorDatatypesW)GetWinprintFunc("EnumPrintProcessorDatatypesW");
29 if (!pEnumPrintProcessorDatatypesW)
30 return;
31
32 // Try with an invalid level. The error needs to be set by winspool, but not by the Print Processor.
33 SetLastError(0xDEADBEEF);
34 ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 0, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
35 ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
36
37 // Now try with valid level, but no pcbNeeded and no pcReturned. The error needs to be set by RPC.
38 SetLastError(0xDEADBEEF);
39 ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, NULL, NULL), "EnumPrintProcessorDatatypesW returns TRUE!\n");
40 ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
41
42 // Now try with pcbNeeded and pcReturned, but give no Print Processor. Show that winprint actually ignores the given Print Processor.
43 SetLastError(0xDEADBEEF);
44 ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
45 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
46 ok(cbNeeded > 0, "cbNeeded is 0!\n");
47 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
48
49 // Same error has to occur when looking for an invalid Print Processor.
50 SetLastError(0xDEADBEEF);
51 ok(!pEnumPrintProcessorDatatypesW(NULL, L"invalid", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
52 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
53 ok(cbNeeded > 0, "cbNeeded is 0!\n");
54 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
55
56 // Now get the required buffer size by supplying all information. This needs to fail with ERROR_INSUFFICIENT_BUFFER.
57 SetLastError(0xDEADBEEF);
58 ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 0, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
59 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
60 ok(cbNeeded > 0, "cbNeeded is 0!\n");
61 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
62
63 // Same error has to occur with a size to small.
64 SetLastError(0xDEADBEEF);
65 ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, 1, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
66 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "EnumPrintersW returns error %lu!\n", GetLastError());
67 ok(cbNeeded > 0, "cbNeeded is 0!\n");
68 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
69
70 // Now provide the demanded size, but no buffer. Show that winprint returns a different error than the same function in winspool.
71 SetLastError(0xDEADBEEF);
72 ok(!pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
73 ok(GetLastError() == ERROR_INVALID_PARAMETER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
74 ok(cbTemp == cbNeeded, "cbTemp is %lu!\n", cbTemp);
75 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
76
77 // This also has to fail the same way when no Print Processor was given at all.
78 SetLastError(0xDEADBEEF);
79 ok(!pEnumPrintProcessorDatatypesW(NULL, NULL, 1, NULL, cbNeeded, &cbTemp, &dwReturned), "EnumPrintProcessorDatatypesW returns TRUE!\n");
80 ok(GetLastError() == ERROR_INVALID_PARAMETER, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
81 ok(cbTemp == cbNeeded, "cbTemp is %lu!\n", cbTemp);
82 ok(dwReturned == 0, "dwReturned is %lu!\n", dwReturned);
83
84 // Finally use the function as intended and aim for success! Show that winprint doesn't modify the error code at all.
85 pDatatypesInfo1 = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
86 SetLastError(0xDEADBEEF);
87 ok(pEnumPrintProcessorDatatypesW(NULL, L"winprint", 1, (PBYTE)pDatatypesInfo1, cbNeeded, &cbNeeded, &dwReturned), "EnumPrintProcessorDatatypesW returns FALSE!\n");
88 ok(GetLastError() == 0xDEADBEEF, "EnumPrintProcessorDatatypesW returns error %lu!\n", GetLastError());
89 HeapFree(GetProcessHeap(), 0, pDatatypesInfo1);
90 }