2 * Unit test suite for localspl API functions: local print monitor
4 * Copyright 2006 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
31 #include "ddk/winsplp.h"
33 #include "wine/test.h"
39 static HMODULE hlocalmon;
40 static LPMONITOREX (WINAPI *pInitializePrintMonitor)(LPWSTR);
42 static LPMONITOREX pm;
43 static BOOL (WINAPI *pEnumPorts)(LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD);
44 static BOOL (WINAPI *pOpenPort)(LPWSTR, PHANDLE);
45 static BOOL (WINAPI *pOpenPortEx)(LPWSTR, LPWSTR, PHANDLE, struct _MONITOR *);
46 static BOOL (WINAPI *pStartDocPort)(HANDLE, LPWSTR, DWORD, DWORD, LPBYTE);
47 static BOOL (WINAPI *pWritePort)(HANDLE hPort, LPBYTE, DWORD, LPDWORD);
48 static BOOL (WINAPI *pReadPort)(HANDLE hPort, LPBYTE, DWORD, LPDWORD);
49 static BOOL (WINAPI *pEndDocPort)(HANDLE);
50 static BOOL (WINAPI *pClosePort)(HANDLE);
51 static BOOL (WINAPI *pAddPort)(LPWSTR, HWND, LPWSTR);
52 static BOOL (WINAPI *pAddPortEx)(LPWSTR, DWORD, LPBYTE, LPWSTR);
53 static BOOL (WINAPI *pConfigurePort)(LPWSTR, HWND, LPWSTR);
54 static BOOL (WINAPI *pDeletePort)(LPWSTR, HWND, LPWSTR);
55 static BOOL (WINAPI *pGetPrinterDataFromPort)(HANDLE, DWORD, LPWSTR, LPWSTR, DWORD, LPWSTR, DWORD, LPDWORD);
56 static BOOL (WINAPI *pSetPortTimeOuts)(HANDLE, LPCOMMTIMEOUTS, DWORD);
57 static BOOL (WINAPI *pXcvOpenPort)(HANDLE, LPCWSTR, ACCESS_MASK, PHANDLE phXcv);
58 static DWORD (WINAPI *pXcvDataPort)(HANDLE, LPCWSTR, PBYTE, DWORD, PBYTE, DWORD, PDWORD);
59 static BOOL (WINAPI *pXcvClosePort)(HANDLE);
61 static WCHAR emptyW[] = {0};
62 static WCHAR invalid_serverW[] = {'\\','\\','i','n','v','a','l','i','d','_','s','e','r','v','e','r',0};
63 static WCHAR Monitors_LocalPortW[] = { \
64 'S','y','s','t','e','m','\\',
65 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
66 'C','o','n','t','r','o','l','\\',
67 'P','r','i','n','t','\\',
68 'M','o','n','i','t','o','r','s','\\',
69 'L','o','c','a','l',' ','P','o','r','t',0};
71 static WCHAR portname_com1W[] = {'C','O','M','1',':',0};
72 static WCHAR portname_fileW[] = {'F','I','L','E',':',0};
73 static WCHAR portname_lpt1W[] = {'L','P','T','1',':',0};
75 /* ########################### */
77 static void test_ConfigurePort(void)
81 if (!pConfigurePort) return;
84 /* NT4 crash on this test */
85 res = pConfigurePort(NULL, 0, NULL);
88 /* Testing-Results (localmon.dll from NT4.0):
89 - Case of Portname is ignored
90 - "COM1:" and "COM01:" are the same (Compared by value)
91 - Portname without ":" => Dialog "Nothing to configure" comes up; Success
92 - "LPT1:", "LPT0:" and "LPT:" are the same (Numbers in "LPT:" are ignored)
93 - Empty Servername (LPT1:) => Dialog comes up (Servername is ignored)
94 - "FILE:" => Dialog "Nothing to configure" comes up; Success
95 - Empty Portname => => Dialog "Nothing to configure" comes up; Success
96 - Port "does_not_exist" => Dialog "Nothing to configure" comes up; Success
98 if (winetest_interactive > 0) {
100 SetLastError(0xdeadbeef);
101 res = pConfigurePort(NULL, 0, portname_com1W);
102 trace("returned %d with %d\n", res, GetLastError());
104 SetLastError(0xdeadbeef);
105 res = pConfigurePort(NULL, 0, portname_lpt1W);
106 trace("returned %d with %d\n", res, GetLastError());
108 SetLastError(0xdeadbeef);
109 res = pConfigurePort(NULL, 0, portname_fileW);
110 trace("returned %d with %d\n", res, GetLastError());
114 /* ########################### */
116 static void test_EnumPorts(void)
125 if (!pEnumPorts) return;
127 /* valid levels are 1 and 2 */
128 for(level = 0; level < 4; level++) {
131 pcReturned = 0xdeadbeef;
132 SetLastError(0xdeadbeef);
133 res = pEnumPorts(NULL, level, NULL, 0, &cbBuf, &pcReturned);
135 /* use only a short test, when we test with an invalid level */
136 if(!level || (level > 2)) {
137 /* NT4 fails with ERROR_INVALID_LEVEL (as expected)
138 XP succeeds with ERROR_SUCCESS () */
139 ok( (cbBuf == 0) && (pcReturned == 0),
140 "(%d) returned %d with %d and %d, %d (expected 0, 0)\n",
141 level, res, GetLastError(), cbBuf, pcReturned);
145 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
146 "(%d) returned %d with %d and %d, %d (expected '0' with " \
147 "ERROR_INSUFFICIENT_BUFFER)\n",
148 level, res, GetLastError(), cbBuf, pcReturned);
150 buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf * 2);
151 if (buffer == NULL) continue;
153 pcbNeeded = 0xdeadbeef;
154 pcReturned = 0xdeadbeef;
155 SetLastError(0xdeadbeef);
156 res = pEnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
157 ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
158 level, res, GetLastError(), cbBuf, pcReturned);
159 /* We can compare the returned Data with the Registry / "win.ini",[Ports] here */
161 pcbNeeded = 0xdeadbeef;
162 pcReturned = 0xdeadbeef;
163 SetLastError(0xdeadbeef);
164 res = pEnumPorts(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
165 ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
166 level, res, GetLastError(), cbBuf, pcReturned);
168 pcbNeeded = 0xdeadbeef;
169 pcReturned = 0xdeadbeef;
170 SetLastError(0xdeadbeef);
171 res = pEnumPorts(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
172 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
173 "(%d) returned %d with %d and %d, %d (expected '0' with " \
174 "ERROR_INSUFFICIENT_BUFFER)\n",
175 level, res, GetLastError(), cbBuf, pcReturned);
178 /* The following tests crash this app with native localmon/localspl */
179 res = pEnumPorts(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
180 res = pEnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
181 res = pEnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
184 /* The Servername is ignored */
185 pcbNeeded = 0xdeadbeef;
186 pcReturned = 0xdeadbeef;
187 SetLastError(0xdeadbeef);
188 res = pEnumPorts(emptyW, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
189 ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
190 level, res, GetLastError(), cbBuf, pcReturned);
192 pcbNeeded = 0xdeadbeef;
193 pcReturned = 0xdeadbeef;
194 SetLastError(0xdeadbeef);
195 res = pEnumPorts(invalid_serverW, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
196 ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
197 level, res, GetLastError(), cbBuf, pcReturned);
199 HeapFree(GetProcessHeap(), 0, buffer);
203 /* ########################### */
206 static void test_InitializePrintMonitor(void)
210 SetLastError(0xdeadbeef);
211 res = pInitializePrintMonitor(NULL);
212 /* The Parameter was unchecked before w2k */
213 ok( res || (GetLastError() == ERROR_INVALID_PARAMETER),
214 "returned %p with %d\n (expected '!= NULL' or: NULL with " \
215 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
217 SetLastError(0xdeadbeef);
218 res = pInitializePrintMonitor(emptyW);
219 ok( res || (GetLastError() == ERROR_INVALID_PARAMETER),
220 "returned %p with %d\n (expected '!= NULL' or: NULL with " \
221 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
224 /* Every call with a non-empty string returns the same Pointer */
225 SetLastError(0xdeadbeef);
226 res = pInitializePrintMonitor(Monitors_LocalPortW);
228 "returned %p with %d (expected %p)\n", res, GetLastError(), pm);
231 /* ########################### */
233 #define GET_MONITOR_FUNC(name) \
234 if(numentries > 0) { \
236 p##name = (void *) pm->Monitor.pfn##name ; \
242 /* This DLL does not exists on Win9x */
243 hdll = LoadLibraryA("localspl.dll");
246 pInitializePrintMonitor = (void *) GetProcAddress(hdll, "InitializePrintMonitor");
247 if (!pInitializePrintMonitor) {
248 /* The Monitor for "Local Ports" was in a seperate dll before w2k */
249 hlocalmon = LoadLibraryA("localmon.dll");
251 pInitializePrintMonitor = (void *) GetProcAddress(hlocalmon, "InitializePrintMonitor");
254 if (!pInitializePrintMonitor) return;
256 /* Native localmon.dll / localspl.dll need a vaild Port-Entry in:
257 a) since xp: HKLM\Software\Microsoft\Windows NT\CurrentVersion\Ports
258 b) up to w2k: Section "Ports" in win.ini
259 or InitializePrintMonitor fails. */
260 pm = pInitializePrintMonitor(Monitors_LocalPortW);
263 numentries = (pm->dwMonitorSize ) / sizeof(VOID *);
264 /* NT4: 14, since w2k: 17 */
265 ok( numentries == 14 || numentries == 17,
266 "dwMonitorSize (%d) => %d Functions\n", pm->dwMonitorSize, numentries);
268 GET_MONITOR_FUNC(EnumPorts);
269 GET_MONITOR_FUNC(OpenPort);
270 GET_MONITOR_FUNC(OpenPortEx);
271 GET_MONITOR_FUNC(StartDocPort);
272 GET_MONITOR_FUNC(WritePort);
273 GET_MONITOR_FUNC(ReadPort);
274 GET_MONITOR_FUNC(EndDocPort);
275 GET_MONITOR_FUNC(ClosePort);
276 GET_MONITOR_FUNC(AddPort);
277 GET_MONITOR_FUNC(AddPortEx);
278 GET_MONITOR_FUNC(ConfigurePort);
279 GET_MONITOR_FUNC(DeletePort);
280 GET_MONITOR_FUNC(GetPrinterDataFromPort);
281 GET_MONITOR_FUNC(SetPortTimeOuts);
282 GET_MONITOR_FUNC(XcvOpenPort);
283 GET_MONITOR_FUNC(XcvDataPort);
284 GET_MONITOR_FUNC(XcvClosePort);
286 test_InitializePrintMonitor();
288 test_ConfigurePort();