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 LPMONITOREX (WINAPI *pInitializePrintMonitor)(LPWSTR);
41 static LPMONITOREX pm;
42 static BOOL (WINAPI *pEnumPorts)(LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD);
43 static BOOL (WINAPI *pOpenPort)(LPWSTR, PHANDLE);
44 static BOOL (WINAPI *pOpenPortEx)(LPWSTR, LPWSTR, PHANDLE, struct _MONITOR *);
45 static BOOL (WINAPI *pStartDocPort)(HANDLE, LPWSTR, DWORD, DWORD, LPBYTE);
46 static BOOL (WINAPI *pWritePort)(HANDLE hPort, LPBYTE, DWORD, LPDWORD);
47 static BOOL (WINAPI *pReadPort)(HANDLE hPort, LPBYTE, DWORD, LPDWORD);
48 static BOOL (WINAPI *pEndDocPort)(HANDLE);
49 static BOOL (WINAPI *pClosePort)(HANDLE);
50 static BOOL (WINAPI *pAddPort)(LPWSTR, HWND, LPWSTR);
51 static BOOL (WINAPI *pAddPortEx)(LPWSTR, DWORD, LPBYTE, LPWSTR);
52 static BOOL (WINAPI *pConfigurePort)(LPWSTR, HWND, LPWSTR);
53 static BOOL (WINAPI *pDeletePort)(LPWSTR, HWND, LPWSTR);
54 static BOOL (WINAPI *pGetPrinterDataFromPort)(HANDLE, DWORD, LPWSTR, LPWSTR, DWORD, LPWSTR, DWORD, LPDWORD);
55 static BOOL (WINAPI *pSetPortTimeOuts)(HANDLE, LPCOMMTIMEOUTS, DWORD);
56 static BOOL (WINAPI *pXcvOpenPort)(HANDLE, LPCWSTR, ACCESS_MASK, PHANDLE phXcv);
57 static DWORD (WINAPI *pXcvDataPort)(HANDLE, LPCWSTR, PBYTE, DWORD, PBYTE, DWORD, PDWORD);
58 static BOOL (WINAPI *pXcvClosePort)(HANDLE);
60 static WCHAR emptyW[] = {0};
61 static WCHAR Monitors_LocalPortW[] = { \
62 'S','y','s','t','e','m','\\',
63 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
64 'C','o','n','t','r','o','l','\\',
65 'P','r','i','n','t','\\',
66 'M','o','n','i','t','o','r','s','\\',
67 'L','o','c','a','l',' ','P','o','r','t',0};
71 static void test_InitializePrintMonitor(void)
75 SetLastError(0xdeadbeef);
76 res = pInitializePrintMonitor(NULL);
77 ok( (res == NULL) && (GetLastError() == ERROR_INVALID_PARAMETER),
78 "returned %p with %d\n (expected NULL with " \
79 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
81 SetLastError(0xdeadbeef);
82 res = pInitializePrintMonitor(emptyW);
83 ok( (res == NULL) && (GetLastError() == ERROR_INVALID_PARAMETER),
84 "returned %p with %d\n (expected NULL with " \
85 "ERROR_INVALID_PARAMETER)\n", res, GetLastError());
87 /* Every call with a non-empty string returns the same Pointer */
88 SetLastError(0xdeadbeef);
89 res = pInitializePrintMonitor(Monitors_LocalPortW);
91 "returned %p with %d (expected %p)\n", res, GetLastError(), pm);
94 /* ########################### */
96 #define GET_MONITOR_FUNC(name) \
97 if(numentries > 0) { \
99 p##name = (void *) pm->Monitor.pfn##name ; \
105 /* This DLL does not exists on Win9x */
106 hdll = LoadLibraryA("localspl.dll");
109 pInitializePrintMonitor = (void *) GetProcAddress(hdll, "InitializePrintMonitor");
110 if (!pInitializePrintMonitor) return;
112 /* Native localmon.dll / localspl.dll need a vaild Port-Entry in:
113 a) since xp: HKLM\Software\Microsoft\Windows NT\CurrentVersion\Ports
114 b) upto w2k: Section "Ports" in win.ini
115 or InitializePrintMonitor fails. */
116 pm = pInitializePrintMonitor(Monitors_LocalPortW);
119 numentries = (pm->dwMonitorSize ) / sizeof(VOID *);
120 /* NT4: 14, since w2k: 17 */
121 ok( numentries == 14 || numentries == 17,
122 "dwMonitorSize (%d) => %d Functions\n", pm->dwMonitorSize, numentries);
124 GET_MONITOR_FUNC(EnumPorts);
125 GET_MONITOR_FUNC(OpenPort);
126 GET_MONITOR_FUNC(OpenPortEx);
127 GET_MONITOR_FUNC(StartDocPort);
128 GET_MONITOR_FUNC(WritePort);
129 GET_MONITOR_FUNC(ReadPort);
130 GET_MONITOR_FUNC(EndDocPort);
131 GET_MONITOR_FUNC(ClosePort);
132 GET_MONITOR_FUNC(AddPort);
133 GET_MONITOR_FUNC(AddPortEx);
134 GET_MONITOR_FUNC(ConfigurePort);
135 GET_MONITOR_FUNC(DeletePort);
136 GET_MONITOR_FUNC(GetPrinterDataFromPort);
137 GET_MONITOR_FUNC(SetPortTimeOuts);
138 GET_MONITOR_FUNC(XcvOpenPort);
139 GET_MONITOR_FUNC(XcvDataPort);
140 GET_MONITOR_FUNC(XcvClosePort);
142 test_InitializePrintMonitor();