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
)(DWORD
, const WCHAR
*);
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
)
69 WCHAR buffer
[1024] = {'\\','\\'};
70 UINT len
= ARRAY_SIZE(buffer
) - 2;
71 GetComputerNameW(buffer
+ 2, &len
);
73 SetLastError(0xdeadbeef);
74 mi
= pPSetupCreateMonitorInfo(0, NULL
);
75 if (!mi
&& (GetLastError() == RPC_S_SERVER_UNAVAILABLE
)) {
76 win_skip("The service 'Spooler' is required for many tests\n");
79 ok( mi
!= NULL
, "got %p with %u (expected '!= NULL')\n", mi
, GetLastError());
80 if (mi
) pPSetupDestroyMonitorInfo(mi
);
82 SetLastError(0xdeadbeef);
83 mi
= pPSetupCreateMonitorInfo(0, buffer
);
84 ok( mi
!= NULL
, "got %p with %u (expected '!= NULL')\n", mi
, GetLastError());
85 if (mi
) pPSetupDestroyMonitorInfo(mi
);
87 SetLastError(0xdeadbeef);
88 mi
= pPSetupCreateMonitorInfo(0, buffer
+ 1);
90 ok( mi
== NULL
, "got %p\n", mi
);
91 ok( GetLastError() == ERROR_INVALID_NAME
, "got %d\n", GetLastError() );
93 if (mi
) pPSetupDestroyMonitorInfo(mi
);
96 /* ########################### */
98 static void test_PSetupDestroyMonitorInfo(VOID
)
103 SetLastError(0xdeadbeef);
104 pPSetupDestroyMonitorInfo(NULL
);
105 /* lasterror is returned */
106 trace("returned with %u\n", GetLastError());
108 SetLastError(0xdeadbeef);
109 mi
= pPSetupCreateMonitorInfo(0, NULL
);
110 if (!mi
&& (GetLastError() == RPC_S_SERVER_UNAVAILABLE
)) {
111 win_skip("The service 'Spooler' is required for many tests\n");
114 ok( mi
!= NULL
, "got %p with %u (expected '!= NULL')\n", mi
, GetLastError());
118 SetLastError(0xdeadbeef);
119 pPSetupDestroyMonitorInfo(mi
);
120 /* lasterror is returned */
121 trace("returned with %u\n", GetLastError());
123 /* Trying to destroy the handle twice crashes with native ntprint.dll */
125 SetLastError(0xdeadbeef);
126 pPSetupDestroyMonitorInfo(mi
);
127 trace(" with %u\n", GetLastError());
132 /* ########################### */
134 static void test_PSetupEnumMonitor(VOID
)
137 WCHAR buffer
[MAX_PATH
+2];
143 SetLastError(0xdeadbeef);
144 mi
= pPSetupCreateMonitorInfo(0, NULL
);
146 skip("PSetupCreateMonitorInfo\n");
151 SetLastError(0xdeadbeef);
152 res
= pPSetupEnumMonitor(mi
, 0, NULL
, &minsize
);
153 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
) && (minsize
> 0),
154 "got %u with %u and %u (expected '0' with ERROR_INSUFFICIENT_BUFFER "
155 "and '> 0')\n", res
, GetLastError(), minsize
);
158 size
= ARRAY_SIZE(buffer
);
159 if ((minsize
+ 1) > size
) {
160 skip("overflow: %u\n", minsize
);
161 pPSetupDestroyMonitorInfo(mi
);
166 /* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
167 SetLastError(0xdeadbeef);
168 size
= ARRAY_SIZE(buffer
);
169 res
= pPSetupEnumMonitor(NULL
, 0, buffer
, &size
);
170 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
171 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
172 res
, GetLastError());
176 /* XP: Crash, w2k: Success (how can that work?) */
177 SetLastError(0xdeadbeef);
178 size
= ARRAY_SIZE(buffer
);
179 res
= pPSetupEnumMonitor(mi
, 0, NULL
, &size
);
180 trace("got %u with %u and %u\n", res
, GetLastError(), size
);
184 /* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
185 SetLastError(0xdeadbeef);
186 res
= pPSetupEnumMonitor(mi
, 0, buffer
, NULL
);
187 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
188 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
189 res
, GetLastError());
192 SetLastError(0xdeadbeef);
194 res
= pPSetupEnumMonitor(mi
, 0, buffer
, &size
);
195 ok( !res
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
196 "got %u with %u and %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
197 res
, GetLastError(), size
);
200 SetLastError(0xdeadbeef);
202 res
= pPSetupEnumMonitor(mi
, 0, buffer
, &size
);
203 ok( res
, "got %u with %u and %u (expected '!= 0')\n",
204 res
, GetLastError(), size
);
206 SetLastError(0xdeadbeef);
208 res
= pPSetupEnumMonitor(mi
, 0, buffer
, &size
);
209 ok( res
, "got %u with %u and %u (expected '!= 0')\n",
210 res
, GetLastError(), size
);
212 /* try max. 20 monitors */
213 while (res
&& (index
< 20)) {
214 SetLastError(0xdeadbeef);
216 size
= ARRAY_SIZE(buffer
);
217 res
= pPSetupEnumMonitor(mi
, index
, buffer
, &size
);
218 ok( res
|| (GetLastError() == ERROR_NO_MORE_ITEMS
),
219 "(%u) got %u with %u and %u (expected '!=0' or: '0' with "
220 "ERROR_NO_MORE_ITEMS)\n", index
, res
, GetLastError(), size
);
224 pPSetupDestroyMonitorInfo(mi
);
228 /* ########################### */
234 test_PSetupCreateMonitorInfo();
235 test_PSetupDestroyMonitorInfo();
236 test_PSetupEnumMonitor();