usp10: Fix return codes of ScriptGetFontProperties + tests.

This commit is contained in:
Paul Vriens 2006-04-21 08:00:14 +02:00 committed by Alexandre Julliard
parent d2a59d86d9
commit e56f6a38b1
2 changed files with 90 additions and 11 deletions

View File

@ -32,6 +32,82 @@
#include <winerror.h> #include <winerror.h>
#include <usp10.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) START_TEST(usp10)
{ {
HRESULT hr; HRESULT hr;
@ -211,5 +287,6 @@ START_TEST(usp10)
DeleteObject(hrgn); DeleteObject(hrgn);
ReleaseDC(hwnd, hdc); ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd); DestroyWindow(hwnd);
return;
test_ScriptGetFontProperties();
} }

View File

@ -126,6 +126,10 @@ HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPR
TEXTMETRICW ptm; TEXTMETRICW ptm;
TRACE("%p,%p,%p\n", hdc, psc, sfp); TRACE("%p,%p,%p\n", hdc, psc, sfp);
if (!psc || !sfp)
return E_INVALIDARG;
if (!hdc && !*psc) { if (!hdc && !*psc) {
TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc); TRACE("No Script_Cache (psc) and no hdc. Ask for one. Hdc=%p, psc=%p\n", hdc, *psc);
return E_PENDING; return E_PENDING;
@ -145,16 +149,14 @@ HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPR
return E_INVALIDARG; return E_INVALIDARG;
/* return something sensible? */ /* return something sensible? */
if (NULL != sfp) { sfp->wgBlank = 0;
sfp->wgBlank = 0; if (GetTextMetricsW(phdc, &ptm))
if (GetTextMetricsW(phdc, &ptm)) sfp->wgDefault = ptm.tmDefaultChar;
sfp->wgDefault = ptm.tmDefaultChar; else
else sfp->wgDefault = 0;
sfp->wgDefault = 0; sfp->wgInvalid = 0;
sfp->wgInvalid = 0; sfp->wgKashida = 0xffff;
sfp->wgKashida = 0xffff; sfp->iKashidaWidth = 0;
sfp->iKashidaWidth = 0;
}
return 0; return 0;
} }