Detlef Riekenberg : winspool/tests: Add tests for EnumPorts.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Nov 6 08:48:51 CST 2006


Module: wine
Branch: master
Commit: d3a1737dac0afdf9cedde6672e5d91f17648e09c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d3a1737dac0afdf9cedde6672e5d91f17648e09c

Author: Detlef Riekenberg <wine.dev at web.de>
Date:   Sat Nov  4 00:28:08 2006 +0100

winspool/tests: Add tests for EnumPorts.

---

 dlls/winspool.drv/tests/info.c |  100 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/dlls/winspool.drv/tests/info.c b/dlls/winspool.drv/tests/info.c
index bf77e89..ed11765 100644
--- a/dlls/winspool.drv/tests/info.c
+++ b/dlls/winspool.drv/tests/info.c
@@ -619,6 +619,105 @@ static void test_EnumMonitors(void)
     } /* for(level ... */
 }
 
+/* ########################### */
+
+static void test_EnumPorts(void)
+{
+    DWORD   res;
+    DWORD   level;
+    LPBYTE  buffer;
+    DWORD   cbBuf;
+    DWORD   pcbNeeded;
+    DWORD   pcReturned;
+
+    /* valid levels are 1 and 2 */
+    for(level = 0; level < 4; level++) {
+
+        cbBuf = 0xdeadbeef;
+        pcReturned = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = EnumPortsA(NULL, level, NULL, 0, &cbBuf, &pcReturned);
+        RETURN_ON_DEACTIVATED_SPOOLER(res)
+
+        /* use only a short test, when we test with an invalid level */
+        if(!level || (level > 2)) {
+            /* NT: ERROR_INVALID_LEVEL, 9x: success */
+            ok( (!res && (GetLastError() == ERROR_INVALID_LEVEL)) ||
+                (res && (pcReturned == 0)),
+                "(%d) returned %d with %d and 0x%08x (expected '0' with " \
+                "ERROR_INVALID_LEVEL or '!=0' and 0x0)\n",
+                level, res, GetLastError(), pcReturned);
+            continue;
+        }        
+
+        
+        /* Level 2 is not supported on NT 3.x */
+        if (!res && (GetLastError() == ERROR_INVALID_LEVEL)) {
+            trace("Level %d not supported, skipping tests\n", level);
+            continue;
+        }
+
+        ok((!res) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
+            "(%d) returned %d with %d (expected '0' with " \
+            "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
+
+        buffer = HeapAlloc(GetProcessHeap(), 0, cbBuf *2);
+        if (buffer == NULL) continue;
+
+        pcbNeeded = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = EnumPortsA(NULL, level, buffer, cbBuf, &pcbNeeded, &pcReturned);
+        ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
+        ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
+        /* ToDo: Compare the returned Data with the Registry / "win.ini",[Ports] here */
+
+        pcbNeeded = 0xdeadbeef;
+        pcReturned = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = EnumPortsA(NULL, level, buffer, cbBuf+1, &pcbNeeded, &pcReturned);
+        ok(res, "(%d) returned %d with %d (expected '!=0')\n", level, res, GetLastError());
+        ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
+
+        pcbNeeded = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = EnumPortsA(NULL, level, buffer, cbBuf-1, &pcbNeeded, &pcReturned);
+        ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
+            "(%d) returned %d with %d (expected '0' with " \
+            "ERROR_INSUFFICIENT_BUFFER)\n", level, res, GetLastError());
+        ok(pcbNeeded == cbBuf, "(%d) returned %d (expected %d)\n", level, pcbNeeded, cbBuf);
+
+        /*
+          Do not add this test:
+          res = EnumPortsA(NULL, level, NULL, cbBuf, &pcbNeeded, &pcReturned);
+          w2k+:  RPC_X_NULL_REF_POINTER 
+          NT3.5: ERROR_INVALID_USER_BUFFER
+          win9x: crash in winspool.drv
+         */
+
+        SetLastError(0xdeadbeef);
+        res = EnumPorts(NULL, level, buffer, cbBuf, NULL, &pcReturned);
+        /* NT: RPC_X_NULL_REF_POINTER (1780),  9x: success */
+        ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
+            ( res && (GetLastError() == ERROR_SUCCESS) ),
+            "(%d) returned %d with %d (expected '0' with " \
+            "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
+            level, res, GetLastError());
+
+
+        SetLastError(0xdeadbeef);
+        res = EnumPorts(NULL, level, buffer, cbBuf, &pcbNeeded, NULL);
+        /* NT: RPC_X_NULL_REF_POINTER (1780),  9x: success */
+        ok( (!res && (GetLastError() == RPC_X_NULL_REF_POINTER) ) ||
+            ( res && (GetLastError() == ERROR_SUCCESS) ),
+            "(%d) returned %d with %d (expected '0' with " \
+            "RPC_X_NULL_REF_POINTER or '!=0' with NO_ERROR)\n",
+            level, res, GetLastError());
+
+        HeapFree(GetProcessHeap(), 0, buffer);
+    }
+}
+
+/* ########################### */
 
 static void test_GetDefaultPrinter(void)
 {
@@ -1413,6 +1512,7 @@ START_TEST(info)
     test_EnumForms(NULL);
     if (default_printer) test_EnumForms(default_printer);
     test_EnumMonitors(); 
+    test_EnumPorts();
     test_GetDefaultPrinter();
     test_GetPrinterDriverDirectory();
     test_GetPrintProcessorDirectory();




More information about the wine-cvs mailing list