a71eac329197639bf10a69426e8b0531b422e1a5
[reactos.git] / rostests / apitests / winspool / IsValidDevmode.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 IsValidDevmodeA/IsValidDevmodeW
5 * COPYRIGHT: Copyright 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 // With very high probability, this is everything you can test for IsValidDevmode.
17 // For your own testing, you can fill a DevMode structure with random bytes multiple times,
18 // always set dmSize and dmDriverExtra appropriately and feed it to IsValidDevmode.
19 // The function will always succeed.
20 // I'm not doing that here, because I don't want to introduce randomness.
21
22 START_TEST(IsValidDevmodeA)
23 {
24 DEVMODEA DevMode;
25
26 // Give no Devmode at all, this has to fail without crashing.
27 SetLastError(0xDEADBEEF);
28 ok(!IsValidDevmodeA(NULL, sizeof(DEVMODEA)), "IsValidDevmodeA returns TRUE!\n");
29 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeA returns error %lu!\n", GetLastError());
30
31 // Give a zeroed Devmode, this has to fail, because dmSize isn't set.
32 ZeroMemory(&DevMode, sizeof(DEVMODEA));
33 SetLastError(0xDEADBEEF);
34 ok(!IsValidDevmodeA(&DevMode, sizeof(DEVMODEA)), "IsValidDevmodeA returns TRUE!\n");
35 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeA returns error %lu!\n", GetLastError());
36
37 // Now set only the dmSize member, IsValidDevmodeA should return TRUE now. The Last Error isn't touched again.
38 ZeroMemory(&DevMode, sizeof(DEVMODEA));
39 DevMode.dmSize = sizeof(DEVMODEA);
40 SetLastError(0xDEADBEEF);
41 ok(IsValidDevmodeA(&DevMode, sizeof(DEVMODEA)), "IsValidDevmodeA returns FALSE!\n");
42 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeA returns error %lu!\n", GetLastError());
43
44 // IsValidDevmodeA should also succeed if the DevMode appears to be larger.
45 ZeroMemory(&DevMode, sizeof(DEVMODEA));
46 DevMode.dmSize = sizeof(DEVMODEA) + 1;
47 SetLastError(0xDEADBEEF);
48 ok(IsValidDevmodeA(&DevMode, sizeof(DEVMODEA) + 1), "IsValidDevmodeA returns FALSE!\n");
49 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeA returns error %lu!\n", GetLastError());
50
51 // The DevmodeSize parameter may be larger than dmSize, but not the other way round!
52 ZeroMemory(&DevMode, sizeof(DEVMODEA));
53 DevMode.dmSize = sizeof(DEVMODEA);
54 SetLastError(0xDEADBEEF);
55 ok(IsValidDevmodeA(&DevMode, sizeof(DEVMODEA) + 1), "IsValidDevmodeA returns FALSE!\n");
56 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeA returns error %lu!\n", GetLastError());
57
58 ZeroMemory(&DevMode, sizeof(DEVMODEA));
59 DevMode.dmSize = sizeof(DEVMODEA) + 1;
60 SetLastError(0xDEADBEEF);
61 ok(!IsValidDevmodeA(&DevMode, sizeof(DEVMODEA)), "IsValidDevmodeA returns TRUE!\n");
62 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeA returns error %lu!\n", GetLastError());
63
64 // dmDriverExtra is also taken into account.
65 ZeroMemory(&DevMode, sizeof(DEVMODEA));
66 DevMode.dmSize = sizeof(DEVMODEA);
67 DevMode.dmDriverExtra = 1;
68 SetLastError(0xDEADBEEF);
69 ok(!IsValidDevmodeA(&DevMode, sizeof(DEVMODEA)), "IsValidDevmodeA returns TRUE!\n");
70 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeA returns error %lu!\n", GetLastError());
71
72 SetLastError(0xDEADBEEF);
73 ok(IsValidDevmodeA(&DevMode, sizeof(DEVMODEA) + 1), "IsValidDevmodeA returns FALSE!\n");
74 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeA returns error %lu!\n", GetLastError());
75 }
76
77 START_TEST(IsValidDevmodeW)
78 {
79 DEVMODEW DevMode;
80
81 // Give no Devmode at all, this has to fail without crashing.
82 SetLastError(0xDEADBEEF);
83 ok(!IsValidDevmodeW(NULL, sizeof(DEVMODEW)), "IsValidDevmodeW returns TRUE!\n");
84 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeW returns error %lu!\n", GetLastError());
85
86 // Give a zeroed Devmode, this has to fail, because dmSize isn't set.
87 ZeroMemory(&DevMode, sizeof(DEVMODEW));
88 SetLastError(0xDEADBEEF);
89 ok(!IsValidDevmodeW(&DevMode, sizeof(DEVMODEW)), "IsValidDevmodeW returns TRUE!\n");
90 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeW returns error %lu!\n", GetLastError());
91
92 // Now set only the dmSize member, IsValidDevmodeW should return TRUE now. The Last Error isn't touched again.
93 ZeroMemory(&DevMode, sizeof(DEVMODEW));
94 DevMode.dmSize = sizeof(DEVMODEW);
95 SetLastError(0xDEADBEEF);
96 ok(IsValidDevmodeW(&DevMode, sizeof(DEVMODEW)), "IsValidDevmodeW returns FALSE!\n");
97 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeW returns error %lu!\n", GetLastError());
98
99 // IsValidDevmodeW should also succeed if the DevMode appears to be larger.
100 ZeroMemory(&DevMode, sizeof(DEVMODEW));
101 DevMode.dmSize = sizeof(DEVMODEW) + 1;
102 SetLastError(0xDEADBEEF);
103 ok(IsValidDevmodeW(&DevMode, sizeof(DEVMODEW) + 1), "IsValidDevmodeW returns FALSE!\n");
104 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeW returns error %lu!\n", GetLastError());
105
106 // The DevmodeSize parameter may be larger than dmSize, but not the other way round!
107 ZeroMemory(&DevMode, sizeof(DEVMODEW));
108 DevMode.dmSize = sizeof(DEVMODEW);
109 SetLastError(0xDEADBEEF);
110 ok(IsValidDevmodeW(&DevMode, sizeof(DEVMODEW) + 1), "IsValidDevmodeW returns FALSE!\n");
111 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeW returns error %lu!\n", GetLastError());
112
113 ZeroMemory(&DevMode, sizeof(DEVMODEW));
114 DevMode.dmSize = sizeof(DEVMODEW) + 1;
115 SetLastError(0xDEADBEEF);
116 ok(!IsValidDevmodeW(&DevMode, sizeof(DEVMODEW)), "IsValidDevmodeW returns TRUE!\n");
117 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeW returns error %lu!\n", GetLastError());
118
119 // dmDriverExtra is also taken into account.
120 ZeroMemory(&DevMode, sizeof(DEVMODEW));
121 DevMode.dmSize = sizeof(DEVMODEW);
122 DevMode.dmDriverExtra = 1;
123 SetLastError(0xDEADBEEF);
124 ok(!IsValidDevmodeW(&DevMode, sizeof(DEVMODEW)), "IsValidDevmodeW returns TRUE!\n");
125 ok(GetLastError() == ERROR_INVALID_DATA, "IsValidDevmodeW returns error %lu!\n", GetLastError());
126
127 SetLastError(0xDEADBEEF);
128 ok(IsValidDevmodeW(&DevMode, sizeof(DEVMODEW) + 1), "IsValidDevmodeW returns FALSE!\n");
129 ok(GetLastError() == 0xDEADBEEF, "IsValidDevmodeW returns error %lu!\n", GetLastError());
130 }