winspool/tests: (EnumPorts #4) Add tests for EnumPorts

Detlef Riekenberg wine.dev at web.de
Fri Nov 3 17:28:08 CST 2006


Last Patch in this Set.


Changelog:
 winspool/tests: (EnumPorts #4) Add tests for EnumPorts


-- 
 
By by ... Detlef

-------------- next part --------------
>From 5d3e47fe641c60f8e2c68dde8c8f974611889509 Mon Sep 17 00:00:00 2001
From: Detlef Riekenberg <wine.dev at web.de>
Date: Sat, 4 Nov 2006 00:20:04 +0100
Subject: [PATCH] winspool/tests: (EnumPorts #4) 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();
-- 
1.4.1



More information about the wine-patches mailing list