2 * Unit test suite for the Spooler Setup API (Printing)
4 * Copyright 2007 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
35 static HANDLE (WINAPI *pPSetupCreateMonitorInfo)(LPVOID, LPVOID, LPVOID);
36 static VOID (WINAPI *pPSetupDestroyMonitorInfo)(HANDLE);
37 static BOOL (WINAPI *pPSetupEnumMonitor)(HANDLE, DWORD, LPWSTR, LPDWORD);
39 /* ########################### */
41 static LPCSTR load_functions(void)
46 hdll = LoadLibraryA(ptr);
47 if (!hdll) return ptr;
49 ptr = "PSetupCreateMonitorInfo";
50 pPSetupCreateMonitorInfo = (VOID *) GetProcAddress(hdll, ptr);
51 if (!pPSetupCreateMonitorInfo) return ptr;
53 ptr = "PSetupDestroyMonitorInfo";
54 pPSetupDestroyMonitorInfo = (VOID *) GetProcAddress(hdll, ptr);
55 if (!pPSetupDestroyMonitorInfo) return ptr;
57 ptr = "PSetupEnumMonitor";
58 pPSetupEnumMonitor = (VOID *) GetProcAddress(hdll, ptr);
59 if (!pPSetupEnumMonitor) return ptr;
64 /* ########################### */
66 static void test_PSetupCreateMonitorInfo(VOID)
71 SetLastError(0xdeadbeef);
72 mi = pPSetupCreateMonitorInfo(NULL, NULL, NULL);
73 ok( mi != NULL, "got %p with %u (expected '!= NULL')\n", mi, GetLastError());
74 if (mi) pPSetupDestroyMonitorInfo(mi);
77 memset(buffer, 0, sizeof(buffer));
78 SetLastError(0xdeadbeef);
79 mi = pPSetupCreateMonitorInfo(buffer, NULL, NULL);
80 ok( mi != NULL, "got %p with %u (expected '!= NULL')\n", mi, GetLastError());
81 if (mi) pPSetupDestroyMonitorInfo(mi);
85 /* ########################### */
87 static void test_PSetupDestroyMonitorInfo(VOID)
92 SetLastError(0xdeadbeef);
93 pPSetupDestroyMonitorInfo(NULL);
94 /* lasterror is returned */
95 trace("returned with %u\n", GetLastError());
97 SetLastError(0xdeadbeef);
98 mi = pPSetupCreateMonitorInfo(NULL, NULL, NULL);
99 ok( mi != NULL, "got %p with %u (expected '!= NULL')\n", mi, GetLastError());
103 SetLastError(0xdeadbeef);
104 pPSetupDestroyMonitorInfo(mi);
105 /* lasterror is returned */
106 trace("returned with %u\n", GetLastError());
108 /* Try to destroy the handle twice crash with native ntprint.dll */
110 SetLastError(0xdeadbeef);
111 pPSetupDestroyMonitorInfo(mi);
112 trace(" with %u\n", GetLastError());
117 /* ########################### */
119 static void test_PSetupEnumMonitor(VOID)
122 WCHAR buffer[MAX_PATH+2];
128 SetLastError(0xdeadbeef);
129 mi = pPSetupCreateMonitorInfo(NULL, NULL, NULL);
131 skip("PSetupCreateMonitorInfo\n");
136 SetLastError(0xdeadbeef);
137 res = pPSetupEnumMonitor(mi, 0, NULL, &minsize);
138 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (minsize > 0),
139 "got %u with %u and %u (expected '0' with ERROR_INSUFFICIENT_BUFFER "
140 "and '> 0')\n", res, GetLastError(), minsize);
143 size = sizeof(buffer) / sizeof(buffer[0]);
144 if ((minsize + 1) > size) {
145 skip("overflow: %u\n", minsize);
146 pPSetupDestroyMonitorInfo(mi);
151 /* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
152 SetLastError(0xdeadbeef);
153 size = sizeof(buffer) / sizeof(buffer[0]);
154 res = pPSetupEnumMonitor(NULL, 0, buffer, &size);
155 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
156 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
157 res, GetLastError());
161 /* XP: Crash, w2k: Success (how can that work?) */
162 SetLastError(0xdeadbeef);
163 size = sizeof(buffer) / sizeof(buffer[0]);
164 res = pPSetupEnumMonitor(mi, 0, NULL, &size);
165 trace("got %u with %u and %u\n", res, GetLastError(), size);
169 /* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
170 SetLastError(0xdeadbeef);
171 res = pPSetupEnumMonitor(mi, 0, buffer, NULL);
172 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
173 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
174 res, GetLastError());
177 SetLastError(0xdeadbeef);
179 res = pPSetupEnumMonitor(mi, 0, buffer, &size);
180 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
181 "got %u with %u and %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
182 res, GetLastError(), size);
185 SetLastError(0xdeadbeef);
187 res = pPSetupEnumMonitor(mi, 0, buffer, &size);
188 ok( res, "got %u with %u and %u (expected '!= 0')\n",
189 res, GetLastError(), size);
191 SetLastError(0xdeadbeef);
193 res = pPSetupEnumMonitor(mi, 0, buffer, &size);
194 ok( res, "got %u with %u and %u (expected '!= 0')\n",
195 res, GetLastError(), size);
197 /* try max. 20 monitors */
198 while (res && (index < 20)) {
199 SetLastError(0xdeadbeef);
201 size = sizeof(buffer) / sizeof(buffer[0]);
202 res = pPSetupEnumMonitor(mi, index, buffer, &size);
203 ok( res || (GetLastError() == ERROR_NO_MORE_ITEMS),
204 "(%u) got %u with %u and %u (expected '!=0' or: '0' with "
205 "ERROR_NO_MORE_ITEMS)\n", index, res, GetLastError(), size);
209 pPSetupDestroyMonitorInfo(mi);
213 /* ########################### */
219 test_PSetupCreateMonitorInfo();
220 test_PSetupDestroyMonitorInfo();
221 test_PSetupEnumMonitor();