localui/tests: Add tests for ConfigurePortUI
Detlef Riekenberg
wine.dev at web.de
Sun May 20 16:05:32 CDT 2007
Changelog:
localui/tests: Add tests for ConfigurePortUI
--
By by ... Detlef
-------------- next part --------------
>From f16102b4a889e96e2a0d2bcea3c0bc0a8e9fccdc Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Sun, 20 May 2007 23:02:45 +0200
Subject: [PATCH] localui/tests: Add tests for ConfigurePortUI
---
dlls/localui/tests/Makefile.in | 2
dlls/localui/tests/localui.c | 171 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 171 insertions(+), 2 deletions(-)
diff --git a/dlls/localui/tests/Makefile.in b/dlls/localui/tests/Makefile.in
index 191a312..634060b 100644
--- a/dlls/localui/tests/Makefile.in
+++ b/dlls/localui/tests/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../../..
SRCDIR = @srcdir@
VPATH = @srcdir@
TESTDLL = localui.dll
-IMPORTS = kernel32
+IMPORTS = kernel32 msvcrt winspool
CTESTS = \
localui.c
diff --git a/dlls/localui/tests/localui.c b/dlls/localui/tests/localui.c
index e3a1813..d099697 100644
--- a/dlls/localui/tests/localui.c
+++ b/dlls/localui/tests/localui.c
@@ -20,6 +20,7 @@
*/
#include <stdarg.h>
+#include "stdio.h"
#include "windef.h"
#include "winbase.h"
@@ -42,6 +43,51 @@ static BOOL (WINAPI *pAddPortUI)(PCWSTR
static BOOL (WINAPI *pConfigurePortUI)(PCWSTR, HWND, PCWSTR);
static BOOL (WINAPI *pDeletePortUI)(PCWSTR, HWND, PCWSTR);
+static WCHAR does_not_existW[] = {'d','o','e','s','_','n','o','t','_','e','x','i','s','t',0};
+static WCHAR emptyW[] = {0};
+static WCHAR fmt_comW[] = {'C','O','M','%','u',':',0};
+static WCHAR fmt_lptW[] = {'L','P','T','%','u',':',0};
+static WCHAR portname_fileW[] = {'F','I','L','E',':',0};
+
+static LPBYTE pi_buffer;
+static DWORD numports;
+static DWORD needed;
+
+static PORT_INFO_2W * lpt_present;
+static PORT_INFO_2W * com_present;
+static PORT_INFO_2W * file_present;
+
+static LPWSTR lpt_absent;
+static LPWSTR com_absent;
+
+/* ########################### */
+
+static PORT_INFO_2W * find_portinfo2(LPWSTR pPort)
+{
+ PORT_INFO_2W * pi;
+ DWORD res;
+
+ if (!pi_buffer) {
+ res = EnumPortsW(NULL, 2, NULL, 0, &needed, &numports);
+ pi_buffer = HeapAlloc(GetProcessHeap(), 0, needed);
+ SetLastError(0xdeadbeef);
+ res = EnumPortsW(NULL, 2, pi_buffer, needed, &needed, &numports);
+ }
+ if (pi_buffer) {
+ pi = (PORT_INFO_2W *) pi_buffer;
+ res = 0;
+ while (numports > res) {
+ if (lstrcmpiW(pi->pPortName, pPort) == 0) {
+ return pi;
+ }
+ pi++;
+ res++;
+ }
+ }
+ return NULL;
+}
+
+
/* ########################### */
static LPCSTR load_functions(void)
@@ -59,6 +105,96 @@ static LPCSTR load_functions(void)
return NULL;
}
+/* ###########################
+ * strdupW [internal]
+ */
+
+static LPWSTR strdupW(LPCWSTR strW)
+{
+ LPWSTR ptr;
+
+ ptr = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(strW) + 1) * sizeof(WCHAR));
+ if (ptr) {
+ lstrcpyW(ptr, strW);
+ }
+ return ptr;
+}
+
+/* ########################### */
+
+static void test_ConfigurePortUI(void)
+{
+ DWORD res;
+
+ /* not present before w2k */
+ if (!pConfigurePortUI) {
+ skip("ConfigurePortUI not found\n");
+ return;
+ }
+
+ SetLastError(0xdeadbeef);
+ res = pConfigurePortUI(NULL, NULL, NULL);
+ ok( !res && (GetLastError() == ERROR_UNKNOWN_PORT),
+ "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
+ res, GetLastError());
+
+
+ SetLastError(0xdeadbeef);
+ res = pConfigurePortUI(NULL, NULL, emptyW);
+ ok( !res && (GetLastError() == ERROR_UNKNOWN_PORT),
+ "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
+ res, GetLastError());
+
+
+ SetLastError(0xdeadbeef);
+ res = pConfigurePortUI(NULL, NULL, does_not_existW);
+ ok( !res && (GetLastError() == ERROR_UNKNOWN_PORT),
+ "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
+ res, GetLastError());
+
+
+ if (winetest_interactive && lpt_present) {
+ SetLastError(0xdeadbeef);
+ res = pConfigurePortUI(NULL, NULL, lpt_present->pPortName);
+ ok( res ||
+ (GetLastError() == ERROR_CANCELLED) || (GetLastError() == ERROR_ACCESS_DENIED),
+ "got %d with %u (expected '!= 0' or '0' with: ERROR_CANCELLED or "
+ "ERROR_ACCESS_DENIED)\n", res, GetLastError());
+ }
+
+ if (lpt_absent) {
+ SetLastError(0xdeadbeef);
+ res = pConfigurePortUI(NULL, NULL, lpt_absent);
+ ok( !res && (GetLastError() == ERROR_UNKNOWN_PORT),
+ "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
+ res, GetLastError());
+ }
+
+ if (winetest_interactive && com_present) {
+ SetLastError(0xdeadbeef);
+ res = pConfigurePortUI(NULL, NULL, com_present->pPortName);
+ ok( res ||
+ (GetLastError() == ERROR_CANCELLED) || (GetLastError() == ERROR_ACCESS_DENIED),
+ "got %d with %u (expected '!= 0' or '0' with: ERROR_CANCELLED or "
+ "ERROR_ACCESS_DENIED)\n", res, GetLastError());
+ }
+
+ if (com_absent) {
+ SetLastError(0xdeadbeef);
+ res = pConfigurePortUI(NULL, NULL, com_absent);
+ ok( !res && (GetLastError() == ERROR_UNKNOWN_PORT),
+ "got %d with %u (expected '0' with ERROR_UNKNOWN_PORT)\n",
+ res, GetLastError());
+ }
+
+ if (winetest_interactive && file_present) {
+ SetLastError(0xdeadbeef);
+ res = pConfigurePortUI(NULL, NULL, portname_fileW);
+ ok( !res && (GetLastError() == ERROR_CANCELLED),
+ "got %d with %u (expected '0' with ERROR_CANCELLED)\n",
+ res, GetLastError());
+ }
+}
/* ########################### */
@@ -66,7 +202,9 @@ START_TEST(localui)
{
LPCSTR ptr;
DWORD numentries;
-
+ PORT_INFO_2W * pi2;
+ WCHAR buffer[16];
+ DWORD id;
/* localui.dll does not exist before w2k */
ptr = load_functions();
@@ -88,4 +226,35 @@ START_TEST(localui)
}
}
+ /* find installed Ports */
+
+ id = 0;
+ /* "LPT1:" - "LPT9:" */
+ while (((lpt_present == NULL) || (lpt_absent == NULL)) && id < 9) {
+ id++;
+ swprintf(buffer, fmt_lptW, id);
+ pi2 = find_portinfo2(buffer);
+ if (pi2 && (lpt_present == NULL)) lpt_present = pi2;
+ if (!pi2 && (lpt_absent == NULL)) lpt_absent = strdupW(buffer);
+ }
+
+ id = 0;
+ /* "COM1:" - "COM9:" */
+ while (((com_present == NULL) || (com_absent == NULL)) && id < 9) {
+ id++;
+ swprintf(buffer, fmt_comW, id);
+ pi2 = find_portinfo2(buffer);
+ if (pi2 && (com_present == NULL)) com_present = pi2;
+ if (!pi2 && (com_absent == NULL)) com_absent = strdupW(buffer);
+ }
+
+ /* "FILE:" */
+ file_present = find_portinfo2(portname_fileW);
+
+ test_ConfigurePortUI();
+
+ /* cleanup */
+ HeapFree(GetProcessHeap(), 0, lpt_absent);
+ HeapFree(GetProcessHeap(), 0, com_absent);
+ HeapFree(GetProcessHeap(), 0, pi_buffer);
}
--
1.4.1
More information about the wine-patches
mailing list