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 if (!mi
&& (GetLastError() == RPC_S_SERVER_UNAVAILABLE
)) {
74 win_skip("The service 'Spooler' is required for many tests\n");
77 ok( mi
!= NULL
, "got %p with %u (expected '!= NULL')\n", mi
, GetLastError());
78 if (mi
) pPSetupDestroyMonitorInfo(mi
);
81 memset(buffer
, 0, sizeof(buffer
));
82 SetLastError(0xdeadbeef);
83 mi
= pPSetupCreateMonitorInfo(buffer
, NULL
, NULL
);
84 ok( mi
!= NULL
, "got %p with %u (expected '!= NULL')\n", mi
, GetLastError());
85 if (mi
) pPSetupDestroyMonitorInfo(mi
);
89 /* ########################### */
91 static void test_PSetupDestroyMonitorInfo(VOID
)
96 SetLastError(0xdeadbeef);
97 pPSetupDestroyMonitorInfo(NULL
);
98 /* lasterror is returned */
99 trace("returned with %u\n", GetLastError());
101 SetLastError(0xdeadbeef);
102 mi
= pPSetupCreateMonitorInfo(NULL
, NULL
, NULL
);
103 if (!mi
&& (GetLastError() == RPC_S_SERVER_UNAVAILABLE
)) {
104 win_skip("The service 'Spooler' is required for many tests\n");
107 ok( mi
!= NULL
, "got %p with %u (expected '!= NULL')\n", mi
, GetLastError());
111 SetLastError(0xdeadbeef);
112 pPSetupDestroyMonitorInfo(mi
);
113 /* lasterror is returned */
114 trace("returned with %u\n", GetLastError());
116 /* Trying to destroy the handle twice crashes with native ntprint.dll */
118 SetLastError(0xdeadbeef);
119 pPSetupDestroyMonitorInfo(mi
);
120 trace(" with %u\n", GetLastError());
125 /* ########################### */
127 static void test_PSetupEnumMonitor(VOID
)
130 WCHAR buffer
[MAX_PATH
+2];
136 SetLastError(0xdeadbeef);
137 mi
= pPSetupCreateMonitorInfo(NULL
, NULL
, NULL
);
139 skip("PSetupCreateMonitorInfo\n");
144 SetLastError(0xdeadbeef);
145 res
= pPSetupEnumMonitor(mi
, 0, NULL
, &minsize
);
146 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
) && (minsize
> 0),
147 "got %u with %u and %u (expected '0' with ERROR_INSUFFICIENT_BUFFER "
148 "and '> 0')\n", res
, GetLastError(), minsize
);
151 size
= sizeof(buffer
) / sizeof(buffer
[0]);
152 if ((minsize
+ 1) > size
) {
153 skip("overflow: %u\n", minsize
);
154 pPSetupDestroyMonitorInfo(mi
);
159 /* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
160 SetLastError(0xdeadbeef);
161 size
= sizeof(buffer
) / sizeof(buffer
[0]);
162 res
= pPSetupEnumMonitor(NULL
, 0, buffer
, &size
);
163 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
164 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
165 res
, GetLastError());
169 /* XP: Crash, w2k: Success (how can that work?) */
170 SetLastError(0xdeadbeef);
171 size
= sizeof(buffer
) / sizeof(buffer
[0]);
172 res
= pPSetupEnumMonitor(mi
, 0, NULL
, &size
);
173 trace("got %u with %u and %u\n", res
, GetLastError(), size
);
177 /* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
178 SetLastError(0xdeadbeef);
179 res
= pPSetupEnumMonitor(mi
, 0, buffer
, NULL
);
180 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
181 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
182 res
, GetLastError());
185 SetLastError(0xdeadbeef);
187 res
= pPSetupEnumMonitor(mi
, 0, buffer
, &size
);
188 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
189 "got %u with %u and %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
190 res
, GetLastError(), size
);
193 SetLastError(0xdeadbeef);
195 res
= pPSetupEnumMonitor(mi
, 0, buffer
, &size
);
196 ok( res
, "got %u with %u and %u (expected '!= 0')\n",
197 res
, GetLastError(), size
);
199 SetLastError(0xdeadbeef);
201 res
= pPSetupEnumMonitor(mi
, 0, buffer
, &size
);
202 ok( res
, "got %u with %u and %u (expected '!= 0')\n",
203 res
, GetLastError(), size
);
205 /* try max. 20 monitors */
206 while (res
&& (index
< 20)) {
207 SetLastError(0xdeadbeef);
209 size
= sizeof(buffer
) / sizeof(buffer
[0]);
210 res
= pPSetupEnumMonitor(mi
, index
, buffer
, &size
);
211 ok( res
|| (GetLastError() == ERROR_NO_MORE_ITEMS
),
212 "(%u) got %u with %u and %u (expected '!=0' or: '0' with "
213 "ERROR_NO_MORE_ITEMS)\n", index
, res
, GetLastError(), size
);
217 pPSetupDestroyMonitorInfo(mi
);
221 /* ########################### */
227 test_PSetupCreateMonitorInfo();
228 test_PSetupDestroyMonitorInfo();
229 test_PSetupEnumMonitor();