Jeremy White : twain_32: Add the ability to thoroughly test basic capability types, and add that test for the one capability Wine supports, ICAP_XFERMECH.

Alexandre Julliard julliard at winehq.org
Tue Feb 3 09:13:27 CST 2009


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

Author: Jeremy White <jwhite at winehq.org>
Date:   Mon Feb  2 16:12:44 2009 -0600

twain_32: Add the ability to thoroughly test basic capability types, and add that test for the one capability Wine supports, ICAP_XFERMECH.

---

 dlls/twain_32/tests/dsm.c |  211 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 211 insertions(+), 0 deletions(-)

diff --git a/dlls/twain_32/tests/dsm.c b/dlls/twain_32/tests/dsm.c
index 278ea7c..cf9acef 100644
--- a/dlls/twain_32/tests/dsm.c
+++ b/dlls/twain_32/tests/dsm.c
@@ -57,6 +57,214 @@ static void get_condition_code(TW_IDENTITY *appid, TW_IDENTITY *source, TW_STATU
     ok(rc == TWRC_SUCCESS, "Condition code not available, rc %d\n", rc);
 }
 
+static BOOL get_onevalue(TW_HANDLE hcontainer, TW_UINT32 *ret, TW_UINT16 *type)
+{
+    TW_ONEVALUE *onev;
+    onev = GlobalLock(hcontainer);
+    if (onev)
+    {
+        *ret = onev->Item;
+        if (type)
+            *type = onev->ItemType;
+        GlobalUnlock(hcontainer);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+static TW_HANDLE alloc_and_set_onevalue(TW_UINT32 val, TW_UINT16 type)
+{
+    TW_HANDLE hcontainer;
+    TW_ONEVALUE *onev;
+    hcontainer = GlobalAlloc(0, sizeof(*onev));
+    if (hcontainer)
+    {
+        onev = GlobalLock(hcontainer);
+        if (onev)
+        {
+            onev->ItemType = type;
+            onev->Item = val;
+            GlobalUnlock(hcontainer);
+        }
+        else
+            hcontainer = 0;
+    }
+    return hcontainer;
+}
+
+static void check_get(TW_CAPABILITY *pCapability,
+                TW_UINT32 orig_value, TW_UINT32 default_value, TW_UINT32 *suggested_set_value)
+{
+    void *p;
+    if (suggested_set_value)
+        *suggested_set_value = orig_value + 1;
+    p = GlobalLock(pCapability->hContainer);
+    if (p)
+    {
+        if (pCapability->ConType == TWON_ONEVALUE)
+        {
+            TW_ONEVALUE *onev = (TW_ONEVALUE *) p;
+            ok(onev->Item == orig_value, "MSG_GET of 0x%x returned 0x%x, expecting 0x%x\n",
+                pCapability->Cap, onev->Item, orig_value);
+        }
+        else if (pCapability->ConType == TWON_ENUMERATION)
+        {
+            int i;
+            TW_UINT8 *p8;
+            TW_UINT16 *p16;
+            TW_UINT32 *p32;
+            TW_ENUMERATION *enumv = (TW_ENUMERATION *) p;
+            p8 = enumv->ItemList;
+            p16 = (TW_UINT16 *) p8;
+            p32 = (TW_UINT32 *) p8;
+            trace("MSG_GET of 0x%x returned %d items:\n", pCapability->Cap, enumv->NumItems);
+            for (i = 0; i < enumv->NumItems; i++)
+            {
+                if (enumv->ItemType == TWTY_UINT8 || enumv->ItemType == TWTY_INT8)
+                    trace("  %d: 0x%x\n", i, p8[i]);
+                if (enumv->ItemType == TWTY_UINT16 || enumv->ItemType == TWTY_INT16)
+                    trace("  %d: 0x%x\n", i, p16[i]);
+                if (enumv->ItemType == TWTY_UINT32 || enumv->ItemType == TWTY_INT32)
+                    trace("  %d: 0x%x\n", i, p32[i]);
+            }
+            if (enumv->ItemType == TWTY_UINT16 || enumv->ItemType == TWTY_INT16)
+            {
+                ok(p16[enumv->CurrentIndex] == orig_value,
+                    "Type 0x%x, values from MSG_GET (0x%x) and MSG_GETCURRENT (0x%x) do not match.\n",
+                    pCapability->Cap, p16[enumv->CurrentIndex], orig_value);
+                ok(p16[enumv->DefaultIndex] == default_value,
+                    "Type 0x%x, values from MSG_GET (0x%x) and MSG_GETDEFAULT (0x%x) do not match.\n",
+                    pCapability->Cap, p16[enumv->DefaultIndex], default_value);
+                if (suggested_set_value)
+                    *suggested_set_value = p16[(enumv->CurrentIndex + 1) % enumv->NumItems];
+            }
+            if (enumv->ItemType == TWTY_UINT32 || enumv->ItemType == TWTY_INT32)
+            {
+                ok(p32[enumv->CurrentIndex] == orig_value,
+                    "Type 0x%x, values from MSG_GET (0x%x) and MSG_GETCURRENT (0x%x) do not match.\n",
+                    pCapability->Cap, p32[enumv->CurrentIndex], orig_value);
+                ok(p32[enumv->DefaultIndex] == default_value,
+                    "Type 0x%x, values from MSG_GET (0x%x) and MSG_GETDEFAULT (0x%x) do not match.\n",
+                    pCapability->Cap, p32[enumv->DefaultIndex], default_value);
+                if (suggested_set_value)
+                    *suggested_set_value = p32[(enumv->CurrentIndex + 1) % enumv->NumItems];
+            }
+        }
+        else
+            trace("MSG_GET on type 0x%x returned type 0x%x, which we didn't check.\n", pCapability->Cap, pCapability->ConType);
+        GlobalUnlock(pCapability->hContainer);
+    }
+}
+
+static void test_onevalue_cap(TW_IDENTITY *appid, TW_IDENTITY *source, TW_UINT16 captype, TW_UINT16 type, TW_INT32 expected_support)
+{
+    TW_UINT16 rc;
+    TW_UINT16 rtype;
+    TW_STATUS status;
+    TW_CAPABILITY cap;
+    TW_UINT32 orig_value = 0;
+    TW_UINT32 new_value;
+    TW_UINT32 default_value = 0;
+    TW_INT32 actual_support;
+
+    memset(&cap, 0, sizeof(cap));
+    cap.Cap = captype;
+    cap.ConType = TWON_DONTCARE16;
+
+    rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_QUERYSUPPORT, &cap);
+    get_condition_code(appid, source, &status);
+    ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
+            "Error [rc %d|cc %d] doing MSG_QUERYSUPPORT for type 0x%x\n", rc, status.ConditionCode, captype);
+    if (rc != TWRC_SUCCESS)
+        return;
+    ok(get_onevalue(cap.hContainer, (TW_UINT32 *) &actual_support, NULL), "Returned cap.hContainer invalid for QuerySupport on type 0x%x", captype);
+    ok(actual_support == expected_support,
+            "Error:  expected support 0x%x for type 0x%x, got 0x%x\n", expected_support,
+            captype, actual_support);
+
+
+    if (actual_support & TWQC_GETCURRENT)
+    {
+        memset(&cap, 0, sizeof(cap));
+        cap.Cap = captype;
+        cap.ConType = TWON_DONTCARE16;
+
+        rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETCURRENT, &cap);
+        get_condition_code(appid, source, &status);
+        ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
+                "Error [rc %d|cc %d] doing MSG_GETCURRENT for type 0x%x\n", rc, status.ConditionCode, captype);
+        if (rc == TWRC_SUCCESS)
+        {
+            ok(get_onevalue(cap.hContainer, &orig_value, &rtype), "Returned cap.hContainer invalid for GETCURRENT on type 0x%x", captype);
+            ok(rtype == type, "Returned GETCURRENT type 0x%x for cap 0x%x is not expected 0x%x\n", rtype, captype, type);
+            GlobalFree(cap.hContainer);
+        }
+    }
+
+    if (actual_support & TWQC_GETDEFAULT)
+    {
+        memset(&cap, 0, sizeof(cap));
+        cap.Cap = captype;
+        cap.ConType = TWON_DONTCARE16;
+
+        rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GETDEFAULT, &cap);
+        get_condition_code(appid, source, &status);
+        ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
+                "Error [rc %d|cc %d] doing MSG_GETDEFAULT for type 0x%x\n", rc, status.ConditionCode, captype);
+        if (rc == TWRC_SUCCESS)
+        {
+            ok(get_onevalue(cap.hContainer, &default_value, &rtype), "Returned cap.hContainer invalid for GETDEFAULT on type 0x%x", captype);
+            ok(rtype == type, "Returned GETDEFAULT type 0x%x for cap 0x%x is not expected 0x%x\n", rtype, captype, type);
+            GlobalFree(cap.hContainer);
+        }
+    }
+
+    new_value = orig_value;
+    if (actual_support & TWQC_GET)
+    {
+        memset(&cap, 0, sizeof(cap));
+        cap.Cap = captype;
+        cap.ConType = TWON_DONTCARE16;
+
+        rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_GET, &cap);
+        get_condition_code(appid, source, &status);
+        ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
+                "Error [rc %d|cc %d] doing MSG_GET for type 0x%x\n", rc, status.ConditionCode, captype);
+        check_get(&cap, orig_value, default_value, &new_value);
+        if (rc == TWRC_SUCCESS)
+            GlobalFree(cap.hContainer);
+    }
+
+    if (actual_support & TWQC_SET)
+    {
+        memset(&cap, 0, sizeof(cap));
+        cap.Cap = captype;
+        cap.ConType = TWON_ONEVALUE;
+        cap.hContainer = alloc_and_set_onevalue(new_value, type);
+
+        rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_SET, &cap);
+        get_condition_code(appid, source, &status);
+        ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
+                "Error [rc %d|cc %d] doing MSG_SET for type 0x%x\n", rc, status.ConditionCode, captype);
+        GlobalFree(cap.hContainer);
+    }
+
+    if (actual_support & TWQC_RESET)
+    {
+        memset(&cap, 0, sizeof(cap));
+        cap.Cap = captype;
+        cap.ConType = TWON_DONTCARE16;
+
+        rc = pDSM_Entry(appid, source, DG_CONTROL, DAT_CAPABILITY, MSG_RESET, &cap);
+        get_condition_code(appid, source, &status);
+        ok(rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS,
+                "Error [rc %d|cc %d] doing MSG_RESET for type 0x%x\n", rc, status.ConditionCode, captype);
+        if (rc == TWRC_SUCCESS)
+            GlobalFree(cap.hContainer);
+    }
+}
+
+
 static void test_single_source(TW_IDENTITY *appid, TW_IDENTITY *source)
 {
     TW_UINT16 rc;
@@ -133,6 +341,9 @@ static void test_single_source(TW_IDENTITY *appid, TW_IDENTITY *source)
         todo_wine
         ok(capabilities[ICAP_UNITS], "ICAP_UNITS not supported\n");
         ok(capabilities[ICAP_XFERMECH], "ICAP_XFERMECH not supported\n");
+        if (capabilities[ICAP_XFERMECH])
+            test_onevalue_cap(appid, source, ICAP_XFERMECH, TWTY_UINT16,
+                TWQC_GET | TWQC_SET | TWQC_GETDEFAULT | TWQC_GETCURRENT | TWQC_RESET);
         todo_wine
         ok(capabilities[ICAP_XRESOLUTION], "ICAP_XRESOLUTION not supported\n");
         todo_wine




More information about the wine-cvs mailing list