localspl/tests: Add tests for EnumPorts

Detlef Riekenberg wine.dev at web.de
Fri Oct 27 12:20:13 CDT 2006


Changelog:
localspl/tests: Add tests for EnumPorts


Tested with localspl.dll from XP_home, w2k, NT4, wine


-- 
 
By by ... Detlef

-------------- next part --------------
>From fd0329ff7af2cc537d22ace78c199b5713e3736b Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Fri, 27 Oct 2006 17:37:05 +0200
Subject: [PATCH] localspl/tests: Add Test for EnumPorts
---
 dlls/localspl/tests/localmon.c |   92 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/dlls/localspl/tests/localmon.c b/dlls/localspl/tests/localmon.c
index d71fb64..8cacf31 100644
--- a/dlls/localspl/tests/localmon.c
+++ b/dlls/localspl/tests/localmon.c
@@ -59,6 +59,7 @@ static DWORD (WINAPI *pXcvDataPort)(HAND
 static BOOL  (WINAPI *pXcvClosePort)(HANDLE);
 
 static WCHAR emptyW[] = {0};
+static WCHAR invalid_serverW[] = {'\\','\\','i','n','v','a','l','i','d','_','s','e','r','v','e','r',0};
 static WCHAR Monitors_LocalPortW[] = { \
                                 'S','y','s','t','e','m','\\',
                                 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
@@ -69,6 +70,96 @@ static WCHAR Monitors_LocalPortW[] = { \
                                        
 /* ##### */
 
+static void test_EnumPorts(void)
+{
+    DWORD   res;
+    DWORD   level;
+    LPBYTE  buffer;
+    DWORD   cbBuf;
+    DWORD   pcbNeeded;
+    DWORD   pcReturned;
+
+    if (!pEnumPorts) return;
+
+    /* valid levels are 1 and 2 */
+    for(level = 0; level < 4; level++) {
+
+        cbBuf = 0xdeadbeef;
+        pcReturned = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pEnumPorts(NULL, level, NULL, 0, &cbBuf, &pcReturned);
+
+        /* use only a short test, when we test with an invalid level */
+        if(!level || (level > 2)) {
+            /* NT4 fails with ERROR_INVALID_LEVEL (as expected)
+               XP succeeds with ERROR_SUCCESS () */
+            ok( (cbBuf == 0) && (pcReturned == 0),
+                "(%d) returned %d with %d and %d, %d (expected 0, 0)\n",
+                level, res, GetLastError(), cbBuf, pcReturned);
+            continue;
+        }        
+
+        ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
+            "(%d) returned %d with %d and %d, %d (expected '0' with " \
+            "ERROR_INSUFFICIENT_BUFFER)\n",
+            level, res, GetLastError(), cbBuf, pcReturned);
+
+        buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf * 2);
+        if (buffer == NULL) continue;
+
+        pcbNeeded = 0xdeadbeef;
+        pcReturned = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pEnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
+        ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
+            level, res, GetLastError(), cbBuf, pcReturned);
+        /* We can compare the returned Data with the Registry / "win.ini",[Ports] here */
+
+        pcbNeeded = 0xdeadbeef;
+        pcReturned = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pEnumPorts(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
+        ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
+            level, res, GetLastError(), cbBuf, pcReturned);
+
+        pcbNeeded = 0xdeadbeef;
+        pcReturned = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pEnumPorts(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
+        ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
+            "(%d) returned %d with %d and %d, %d (expected '0' with " \
+            "ERROR_INSUFFICIENT_BUFFER)\n",
+            level, res, GetLastError(), cbBuf, pcReturned);
+
+#if 0
+        /* The following tests crash this app with native localmon/localspl */
+        res = pEnumPorts(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
+        res = pEnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
+        res = pEnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
+#endif
+
+        /* The Servername is ignored */
+        pcbNeeded = 0xdeadbeef;
+        pcReturned = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pEnumPorts(emptyW, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
+        ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
+            level, res, GetLastError(), cbBuf, pcReturned);
+
+        pcbNeeded = 0xdeadbeef;
+        pcReturned = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pEnumPorts(invalid_serverW, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
+        ok( res, "(%d) returned %d with %d and %d, %d (expected '!= 0')\n",
+            level, res, GetLastError(), cbBuf, pcReturned);
+
+        HeapFree(GetProcessHeap(), 0, buffer);
+    }
+}
+
+/* ########################### */
+
+
 static void test_InitializePrintMonitor(void)
 {
     LPMONITOREX res;
@@ -150,4 +241,5 @@ START_TEST(localmon)
         GET_MONITOR_FUNC(XcvClosePort);
     }
     test_InitializePrintMonitor();
+    test_EnumPorts();
 }
-- 
1.4.1



More information about the wine-patches mailing list