Paul Vriens : usp10: Fix return codes of ScriptGetFontProperties + tests.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Apr 21 05:02:35 CDT 2006


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

Author: Paul Vriens <Paul.Vriens at xs4all.nl>
Date:   Fri Apr 21 08:00:14 2006 +0200

usp10: Fix return codes of ScriptGetFontProperties + tests.

---

 dlls/usp10/tests/usp10.c |   79 +++++++++++++++++++++++++++++++++++++++++++++-
 dlls/usp10/usp10.c       |   22 +++++++------
 2 files changed, 90 insertions(+), 11 deletions(-)

diff --git a/dlls/usp10/tests/usp10.c b/dlls/usp10/tests/usp10.c
index 12907dc..f411ce8 100644
--- a/dlls/usp10/tests/usp10.c
+++ b/dlls/usp10/tests/usp10.c
@@ -32,6 +32,82 @@ #include <winuser.h>
 #include <winerror.h>
 #include <usp10.h>
 
+void test_ScriptGetFontProperties(void)
+{
+    HRESULT         hr;
+    HDC             hdc;
+    HWND            hwnd;
+    SCRIPT_CACHE    psc,old_psc;
+    SCRIPT_FONTPROPERTIES sfp;
+
+    /* Only do the bare minumum to get a valid hdc */
+    hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
+    assert(hwnd != 0);
+
+    hdc = GetDC(hwnd);
+    ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
+
+    /* Some sanity checks for ScriptGetFontProperties */
+
+    hr = ScriptGetFontProperties(NULL,NULL,NULL);
+    ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", (unsigned int)hr);
+
+    hr = ScriptGetFontProperties(NULL,NULL,&sfp);
+    ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", (unsigned int)hr);
+
+    /* Set psc to NULL, to be able to check if a pointer is returned in psc */
+    psc = NULL;
+    hr = ScriptGetFontProperties(NULL,&psc,NULL);
+    ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", (unsigned int)hr);
+    ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
+
+    /* Set psc to NULL, to be able to check if a pointer is returned in psc */
+    psc = NULL;
+    hr = ScriptGetFontProperties(NULL,&psc,&sfp);
+    ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", (unsigned int)hr);
+    ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
+
+    hr = ScriptGetFontProperties(hdc,NULL,NULL);
+    ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", (unsigned int)hr);
+
+    hr = ScriptGetFontProperties(hdc,NULL,&sfp);
+    ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", (unsigned int)hr);
+
+    /* Set psc to NULL, to be able to check if a pointer is returned in psc */
+    psc = NULL;
+    hr = ScriptGetFontProperties(hdc,&psc,NULL);
+    ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", (unsigned int)hr);
+    ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
+
+    /* Pass an uninitialized sfp */
+    psc = NULL;
+    hr = ScriptGetFontProperties(hdc,&psc,&sfp);
+    ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) partly uninitialized, expected E_INVALIDARG, got %08x\n", (unsigned int)hr);
+    ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
+    ScriptFreeCache(&psc);
+    ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
+
+    /* Give it the correct cBytes, we don't care about what's coming back */
+    sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
+    psc = NULL;
+    hr = ScriptGetFontProperties(hdc,&psc,&sfp);
+    ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", (unsigned int)hr);
+    ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
+
+    /* Save the psc pointer */
+    old_psc = psc;
+    /* Now a NULL hdc again */
+    hr = ScriptGetFontProperties(NULL,&psc,&sfp);
+    ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", (unsigned int)hr);
+    ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
+    ScriptFreeCache(&psc);
+    ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
+
+    /* Cleanup */
+    ReleaseDC(hwnd, hdc);
+    DestroyWindow(hwnd);
+}
+
 START_TEST(usp10)
 {
     HRESULT         hr;
@@ -211,5 +287,6 @@ START_TEST(usp10)
     DeleteObject(hrgn);
     ReleaseDC(hwnd, hdc);
     DestroyWindow(hwnd);
-    return;
+    
+    test_ScriptGetFontProperties();
 }
diff --git a/dlls/usp10/usp10.c b/dlls/usp10/usp10.c
index d1be349..efb942e 100644
--- a/dlls/usp10/usp10.c
+++ b/dlls/usp10/usp10.c
@@ -126,6 +126,10 @@ HRESULT WINAPI ScriptGetFontProperties(H
     TEXTMETRICW ptm;
 
     TRACE("%p,%p,%p\n", hdc, psc, sfp);
+
+    if (!psc || !sfp)
+        return E_INVALIDARG;
+
     if  (!hdc && !*psc) {
         TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
 	return E_PENDING;
@@ -145,16 +149,14 @@ HRESULT WINAPI ScriptGetFontProperties(H
         return E_INVALIDARG;
 
     /* return something sensible? */
-    if (NULL != sfp) {
-        sfp->wgBlank       = 0;
-        if  (GetTextMetricsW(phdc, &ptm)) 
-            sfp->wgDefault = ptm.tmDefaultChar;
-        else
-            sfp->wgDefault = 0;
-        sfp->wgInvalid     = 0;
-        sfp->wgKashida     = 0xffff;
-        sfp->iKashidaWidth = 0;
-    }
+    sfp->wgBlank       = 0;
+    if  (GetTextMetricsW(phdc, &ptm)) 
+        sfp->wgDefault = ptm.tmDefaultChar;
+    else
+        sfp->wgDefault = 0;
+    sfp->wgInvalid     = 0;
+    sfp->wgKashida     = 0xffff;
+    sfp->iKashidaWidth = 0;
     return 0;
 }
 




More information about the wine-cvs mailing list