ReactOS  0.4.15-dev-1386-g5cb9f87
localui.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wingdi.h"
#include "winnls.h"
#include "winreg.h"
#include "winspool.h"
#include "ddk/winsplp.h"
#include "wine/test.h"
Include dependency graph for localui.c:

Go to the source code of this file.

Functions

static PMONITORUI (WINAPI *pInitializePrintMonitorUI)(VOID)
 
static BOOL (WINAPI *pAddPortUI)(PCWSTR
 
static PORT_INFO_2Wfind_portinfo2 (LPCWSTR pPort)
 
static LPCSTR load_functions (void)
 
static LPWSTR strdupW (LPCWSTR strW)
 
static void test_AddPortUI (void)
 
static void test_ConfigurePortUI (void)
 
 START_TEST (localui)
 

Variables

static HMODULE hdll
 
static PMONITORUI pui
 
static HWND
 
static PCWSTR
 
static const WCHAR does_not_existW [] = {'d','o','e','s','_','n','o','t','_','e','x','i','s','t',0}
 
static const WCHAR emptyW [] = {0}
 
static const CHAR fmt_comA [] = {'C','O','M','%','u',':',0}
 
static const CHAR fmt_lptA [] = {'L','P','T','%','u',':',0}
 
static const WCHAR localportW [] = {'L','o','c','a','l',' ','P','o','r','t',0}
 
static const WCHAR portname_fileW [] = {'F','I','L','E',':',0}
 
static LPBYTE pi_buffer
 
static DWORD pi_numports
 
static DWORD pi_needed
 
static PORT_INFO_2Wlpt_present
 
static PORT_INFO_2Wcom_present
 
static PORT_INFO_2Wfile_present
 
static LPWSTR lpt_absent
 
static LPWSTR com_absent
 

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pAddPortUI)
static

◆ find_portinfo2()

static PORT_INFO_2W* find_portinfo2 ( LPCWSTR  pPort)
static

Definition at line 67 of file localui.c.

68 {
69  PORT_INFO_2W * pi;
70  DWORD res;
71 
72  if (!pi_buffer) {
74  if (!res && (GetLastError() == RPC_S_SERVER_UNAVAILABLE)) {
75  win_skip("The service 'Spooler' is required for many tests\n");
76  return NULL;
77  }
78  ok(!res, "EnumPorts succeeded: got %d\n", res);
81  ok(res == 1, "EnumPorts failed: got %d\n", res);
82  }
83  if (pi_buffer) {
85  res = 0;
86  while (pi_numports > res) {
87  if (lstrcmpiW(pi->pPortName, pPort) == 0) {
88  return pi;
89  }
90  pi++;
91  res++;
92  }
93  }
94  return NULL;
95 }
static DWORD pi_needed
Definition: localui.c:56
#define RPC_S_SERVER_UNAVAILABLE
Definition: winerror.h:1033
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
static LPBYTE pi_buffer
Definition: localui.c:54
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static refpint_t pi[]
Definition: server.c:96
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
GLuint res
Definition: glext.h:9613
WINBOOL WINAPI EnumPortsW(LPWSTR pName, DWORD Level, LPBYTE pPorts, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
static DWORD pi_numports
Definition: localui.c:55
#define win_skip
Definition: test.h:149

Referenced by START_TEST().

◆ load_functions()

static LPCSTR load_functions ( void  )
static

Definition at line 100 of file localui.c.

101 {
102  LPCSTR ptr;
103 
104  ptr = "localui.dll";
105  hdll = LoadLibraryA(ptr);
106  if (!hdll) return ptr;
107 
108  ptr = "InitializePrintMonitorUI";
109  pInitializePrintMonitorUI = (VOID *) GetProcAddress(hdll, ptr);
110  if (!pInitializePrintMonitorUI) return ptr;
111 
112  return NULL;
113 }
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static PVOID ptr
Definition: dispmode.c:27
const char * LPCSTR
Definition: xmlstorage.h:183
static HMODULE hdll
Definition: localui.c:40
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:612

Referenced by START_TEST().

◆ PMONITORUI()

static PMONITORUI ( WINAPI pInitializePrintMonitorUI)
static

◆ START_TEST()

START_TEST ( localui  )

Definition at line 271 of file localui.c.

272 {
273  LPCSTR ptr;
274  DWORD numentries;
275  PORT_INFO_2W * pi2;
276  WCHAR bufferW[16];
277  CHAR bufferA[16];
278  DWORD id;
279 
280  /* localui.dll does not exist before w2k */
281  ptr = load_functions();
282  if (ptr) {
283  skip("%s not found\n", ptr);
284  return;
285  }
286 
287  pui = pInitializePrintMonitorUI();
288  if (pui) {
289  numentries = (pui->dwMonitorUISize - sizeof(DWORD)) / sizeof(VOID *);
290  ok( numentries == 3,
291  "dwMonitorUISize (%d) => %d Functions\n", pui->dwMonitorUISize, numentries);
292 
293  if (numentries > 2) {
294  pAddPortUI = pui->pfnAddPortUI;
295  pConfigurePortUI = pui->pfnConfigurePortUI;
296  pDeletePortUI = pui->pfnDeletePortUI;
297  }
298  }
299 
300  /* find installed ports */
301 
302  /* "FILE:" */
304 
305  if (!pi_numports) /* Nothing to test without a port */
306  return;
307 
308  id = 0;
309  /* "LPT1:" - "LPT9:" */
310  while (((lpt_present == NULL) || (lpt_absent == NULL)) && id < 9) {
311  id++;
312  sprintf(bufferA, fmt_lptA, id);
313  MultiByteToWideChar( CP_ACP, 0, bufferA, -1, bufferW, ARRAY_SIZE(bufferW));
314  pi2 = find_portinfo2(bufferW);
315  if (pi2 && (lpt_present == NULL)) lpt_present = pi2;
316  if (!pi2 && (lpt_absent == NULL)) lpt_absent = strdupW(bufferW);
317  }
318 
319  id = 0;
320  /* "COM1:" - "COM9:" */
321  while (((com_present == NULL) || (com_absent == NULL)) && id < 9) {
322  id++;
323  sprintf(bufferA, fmt_comA, id);
324  MultiByteToWideChar( CP_ACP, 0, bufferA, -1, bufferW, ARRAY_SIZE(bufferW));
325  pi2 = find_portinfo2(bufferW);
326  if (pi2 && (com_present == NULL)) com_present = pi2;
327  if (!pi2 && (com_absent == NULL)) com_absent = strdupW(bufferW);
328  }
329 
330  test_AddPortUI();
332 
333  /* cleanup */
337 }
static PORT_INFO_2W * file_present
Definition: localui.c:60
#define CP_ACP
Definition: compat.h:109
char CHAR
Definition: xmlstorage.h:175
static void test_ConfigurePortUI(void)
Definition: localui.c:190
static LPWSTR lpt_absent
Definition: localui.c:62
static PORT_INFO_2W * find_portinfo2(LPCWSTR pPort)
Definition: localui.c:67
static void test_AddPortUI(void)
Definition: localui.c:132
#define DWORD
Definition: nt_native.h:44
static LPCSTR load_functions(void)
Definition: localui.c:100
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static LPBYTE pi_buffer
Definition: localui.c:54
static PVOID ptr
Definition: dispmode.c:27
const char * LPCSTR
Definition: xmlstorage.h:183
static PORT_INFO_2W * com_present
Definition: localui.c:59
#define GetProcessHeap()
Definition: compat.h:595
__wchar_t WCHAR
Definition: xmlstorage.h:180
static PORT_INFO_2W * lpt_present
Definition: localui.c:58
unsigned long DWORD
Definition: ntddk_ex.h:95
static LPWSTR strdupW(LPCWSTR strW)
Definition: localui.c:119
#define ARRAY_SIZE(a)
Definition: main.h:24
static PMONITORUI pui
Definition: localui.c:42
#define ok(value,...)
Definition: atltest.h:57
DWORD dwMonitorUISize
Definition: winsplp.h:1017
#define NULL
Definition: types.h:112
#define MultiByteToWideChar
Definition: compat.h:110
#define skip(...)
Definition: atltest.h:64
GLenum GLuint id
Definition: glext.h:5579
static DWORD pi_numports
Definition: localui.c:55
static LPWSTR com_absent
Definition: localui.c:63
#define HeapFree(x, y, z)
Definition: compat.h:594
static const CHAR fmt_lptA[]
Definition: localui.c:50
static const WCHAR portname_fileW[]
Definition: localui.c:52
static const CHAR fmt_comA[]
Definition: localui.c:49

◆ strdupW()

static LPWSTR strdupW ( LPCWSTR  strW)
static

Definition at line 119 of file localui.c.

120 {
121  LPWSTR ptr;
122 
123  ptr = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(strW) + 1) * sizeof(WCHAR));
124  if (ptr) {
125  lstrcpyW(ptr, strW);
126  }
127  return ptr;
128 }
#define lstrlenW
Definition: compat.h:609
WCHAR strW[12]
Definition: clipboard.c:2029
static PVOID ptr
Definition: dispmode.c:27
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define lstrcpyW
Definition: compat.h:608
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by START_TEST().

◆ test_AddPortUI()

static void test_AddPortUI ( void  )
static

Definition at line 132 of file localui.c.

133 {
134  DWORD res;
135  LPWSTR new_portname;
136 
137  /* not present before w2k */
138  if (!pAddPortUI) {
139  skip("AddPortUI not found\n");
140  return;
141  }
142 
143  SetLastError(0xdeadbeef);
144  res = pAddPortUI(NULL, NULL, NULL, NULL);
145  ok( !res &&
147  "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
148  "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
149 
150  SetLastError(0xdeadbeef);
151  res = pAddPortUI(NULL, NULL, emptyW, NULL);
152  ok( !res &&
154  "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
155  "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
156 
157  SetLastError(0xdeadbeef);
158  res = pAddPortUI(NULL, NULL, does_not_existW, NULL);
159  ok( !res &&
161  "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
162  "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
163 
164  if (winetest_interactive) {
165  SetLastError(0xdeadbeef);
166  new_portname = NULL;
167  /*
168  * - On MSDN, you can read that no dialog should be displayed when hWnd
169  * is NULL, but native localui does not care
170  * - When the new port already exists,
171  * TRUE is returned, but new_portname is NULL
172  * - When the new port starts with "COM" or "LPT",
173  * FALSE is returned with ERROR_NOT_SUPPORTED on windows
174  */
175  res = pAddPortUI(NULL, NULL, localportW, &new_portname);
176  ok( res ||
177  (GetLastError() == ERROR_CANCELLED) ||
180  "got %d with %u and %p (expected '!= 0' or '0' with: "
181  "ERROR_CANCELLED, ERROR_ACCESS_DENIED or ERROR_NOT_SUPPORTED)\n",
182  res, GetLastError(), new_portname);
183 
184  GlobalFree(new_portname);
185  }
186 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
int winetest_interactive
static const WCHAR localportW[]
Definition: localui.c:51
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define ERROR_UNKNOWN_PORT
Definition: winerror.h:1103
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define SetLastError(x)
Definition: compat.h:611
#define ERROR_INVALID_PRINTER_NAME
Definition: winerror.h:1108
static const WCHAR does_not_existW[]
Definition: localui.c:47
#define ERROR_CANCELLED
Definition: winerror.h:726
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
GLuint res
Definition: glext.h:9613
static const WCHAR emptyW[]
Definition: localui.c:48
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by START_TEST().

◆ test_ConfigurePortUI()

static void test_ConfigurePortUI ( void  )
static

Definition at line 190 of file localui.c.

191 {
192  DWORD res;
193 
194  /* not present before w2k */
195  if (!pConfigurePortUI) {
196  skip("ConfigurePortUI not found\n");
197  return;
198  }
199 
200  SetLastError(0xdeadbeef);
201  res = pConfigurePortUI(NULL, NULL, NULL);
202  ok( !res &&
204  "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
205  "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
206 
207  SetLastError(0xdeadbeef);
208  res = pConfigurePortUI(NULL, NULL, emptyW);
209  ok( !res &&
211  "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
212  "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
213 
214 
215  SetLastError(0xdeadbeef);
216  res = pConfigurePortUI(NULL, NULL, does_not_existW);
217  ok( !res &&
219  "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
220  "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
221 
223  SetLastError(0xdeadbeef);
224  res = pConfigurePortUI(NULL, NULL, lpt_present->pPortName);
225  ok( res ||
227  "got %d with %u (expected '!= 0' or '0' with: ERROR_CANCELLED or "
228  "ERROR_ACCESS_DENIED)\n", res, GetLastError());
229  }
230 
231  if (lpt_absent) {
232  SetLastError(0xdeadbeef);
233  res = pConfigurePortUI(NULL, NULL, lpt_absent);
234  ok( !res &&
236  "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
237  "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
238  }
239 
241  SetLastError(0xdeadbeef);
242  res = pConfigurePortUI(NULL, NULL, com_present->pPortName);
243  ok( res ||
245  "got %d with %u (expected '!= 0' or '0' with: ERROR_CANCELLED or "
246  "ERROR_ACCESS_DENIED)\n", res, GetLastError());
247  }
248 
249  if (com_absent) {
250  SetLastError(0xdeadbeef);
251  res = pConfigurePortUI(NULL, NULL, com_absent);
252  ok( !res &&
254  "got %d with %u (expected '0' with: ERROR_UNKNOWN_PORT or "
255  "ERROR_INVALID_PRINTER_NAME)\n", res, GetLastError());
256 
257  }
258 
260  SetLastError(0xdeadbeef);
261  res = pConfigurePortUI(NULL, NULL, portname_fileW);
262  ok( !res &&
264  "got %d with %u (expected '0' with: ERROR_CANCELLED or "
265  "ERROR_ACCESS_DENIED)\n", res, GetLastError());
266  }
267 }
static PORT_INFO_2W * file_present
Definition: localui.c:60
LPWSTR pPortName
Definition: winspool.h:765
static LPWSTR lpt_absent
Definition: localui.c:62
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
int winetest_interactive
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define ERROR_UNKNOWN_PORT
Definition: winerror.h:1103
static PORT_INFO_2W * com_present
Definition: localui.c:59
static PORT_INFO_2W * lpt_present
Definition: localui.c:58
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
#define ERROR_INVALID_PRINTER_NAME
Definition: winerror.h:1108
static const WCHAR does_not_existW[]
Definition: localui.c:47
#define ERROR_CANCELLED
Definition: winerror.h:726
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
GLuint res
Definition: glext.h:9613
static const WCHAR emptyW[]
Definition: localui.c:48
static LPWSTR com_absent
Definition: localui.c:63
static const WCHAR portname_fileW[]
Definition: localui.c:52

Referenced by START_TEST().

Variable Documentation

◆ com_absent

LPWSTR com_absent
static

Definition at line 63 of file localui.c.

Referenced by START_TEST(), and test_ConfigurePortUI().

◆ com_present

PORT_INFO_2W* com_present
static

Definition at line 59 of file localui.c.

Referenced by START_TEST(), and test_ConfigurePortUI().

◆ does_not_existW

const WCHAR does_not_existW[] = {'d','o','e','s','_','n','o','t','_','e','x','i','s','t',0}
static

Definition at line 47 of file localui.c.

Referenced by test_AddPortUI(), and test_ConfigurePortUI().

◆ emptyW

const WCHAR emptyW[] = {0}
static

Definition at line 48 of file localui.c.

Referenced by test_AddPortUI(), and test_ConfigurePortUI().

◆ file_present

PORT_INFO_2W* file_present
static

Definition at line 60 of file localui.c.

Referenced by START_TEST(), and test_ConfigurePortUI().

◆ fmt_comA

const CHAR fmt_comA[] = {'C','O','M','%','u',':',0}
static

Definition at line 49 of file localui.c.

Referenced by START_TEST().

◆ fmt_lptA

const CHAR fmt_lptA[] = {'L','P','T','%','u',':',0}
static

Definition at line 50 of file localui.c.

Referenced by START_TEST().

◆ hdll

HMODULE hdll
static

Definition at line 40 of file localui.c.

Referenced by load_functions().

◆ HWND

Definition at line 43 of file localui.c.

◆ localportW

const WCHAR localportW[] = {'L','o','c','a','l',' ','P','o','r','t',0}
static

Definition at line 51 of file localui.c.

Referenced by test_AddPortUI().

◆ lpt_absent

LPWSTR lpt_absent
static

Definition at line 62 of file localui.c.

Referenced by START_TEST(), and test_ConfigurePortUI().

◆ lpt_present

PORT_INFO_2W* lpt_present
static

Definition at line 58 of file localui.c.

Referenced by START_TEST(), and test_ConfigurePortUI().

◆ PCWSTR

Definition at line 43 of file localui.c.

◆ pi_buffer

LPBYTE pi_buffer
static

Definition at line 54 of file localui.c.

Referenced by find_portinfo2(), and START_TEST().

◆ pi_needed

DWORD pi_needed
static

Definition at line 56 of file localui.c.

Referenced by find_portinfo2().

◆ pi_numports

DWORD pi_numports
static

Definition at line 55 of file localui.c.

Referenced by find_portinfo2(), and START_TEST().

◆ portname_fileW

const WCHAR portname_fileW[] = {'F','I','L','E',':',0}
static

Definition at line 52 of file localui.c.

Referenced by START_TEST(), and test_ConfigurePortUI().

◆ pui

PMONITORUI pui
static

Definition at line 42 of file localui.c.

Referenced by START_TEST().