localspl/tests: Get function pointers from the monitor.
[wine] / dlls / localspl / tests / localmon.c
1 /* 
2  * Unit test suite for localspl API functions: local print monitor
3  *
4  * Copyright 2006 Detlef Riekenberg
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wingdi.h"
28 #include "winreg.h"
29
30 #include "winspool.h"
31 #include "ddk/winsplp.h"
32
33 #include "wine/test.h"
34
35
36 /* ##### */
37
38 static HMODULE  hdll;
39 static LPMONITOREX (WINAPI *pInitializePrintMonitor)(LPWSTR);
40
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);
59
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};
68                                        
69 /* ##### */
70
71 static void test_InitializePrintMonitor(void)
72 {
73     LPMONITOREX res;
74
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());
80
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());
86
87     /* Every call with a non-empty string returns the same Pointer */
88     SetLastError(0xdeadbeef);
89     res = pInitializePrintMonitor(Monitors_LocalPortW);
90     ok( res == pm,
91         "returned %p with %d (expected %p)\n", res, GetLastError(), pm);
92 }
93
94 /* ########################### */
95
96 #define GET_MONITOR_FUNC(name) \
97             if(numentries > 0) { \
98                 numentries--; \
99                 p##name = (void *) pm->Monitor.pfn##name ;  \
100             }
101
102
103 START_TEST(localmon)
104 {
105     /* This DLL does not exists on Win9x */
106     hdll = LoadLibraryA("localspl.dll");
107     if (!hdll) return;
108
109     pInitializePrintMonitor = (void *) GetProcAddress(hdll, "InitializePrintMonitor");
110     if (!pInitializePrintMonitor) return;
111
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);
117     if (pm) {
118         DWORD   numentries;
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);
123
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);
141     }
142     test_InitializePrintMonitor();
143 }