riched20/tests: Rewrite tests for ITextServices_TxGetNaturalSize().

Signed-off-by: Jactry Zeng <jzeng@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jactry Zeng 2018-07-13 17:11:27 +08:00 committed by Alexandre Julliard
parent 56dfe6708b
commit 6e264bbd1d
1 changed files with 62 additions and 60 deletions

View File

@ -600,6 +600,21 @@ static void setup_thiscall_wrappers(void)
#endif /* __i386__ */ #endif /* __i386__ */
} }
static void hf_to_cf(HFONT hf, CHARFORMAT2W *cf)
{
LOGFONTW lf;
GetObjectW(hf, sizeof(lf), &lf);
lstrcpyW(cf->szFaceName, lf.lfFaceName);
cf->yHeight = MulDiv(abs(lf.lfHeight), 1440, GetDeviceCaps(GetDC(NULL), LOGPIXELSY));
if (lf.lfWeight > FW_NORMAL) cf->dwEffects |= CFE_BOLD;
if (lf.lfItalic) cf->dwEffects |= CFE_ITALIC;
if (lf.lfUnderline) cf->dwEffects |= CFE_UNDERLINE;
if (lf.lfStrikeOut) cf->dwEffects |= CFE_SUBSCRIPT;
cf->bPitchAndFamily = lf.lfPitchAndFamily;
cf->bCharSet = lf.lfCharSet;
}
/*************************************************************************/ /*************************************************************************/
/* Conformance test functions. */ /* Conformance test functions. */
@ -697,81 +712,68 @@ static void test_TxSetText(void)
ITextHost_Release(host); ITextHost_Release(host);
} }
#define CHECK_TXGETNATURALSIZE(res,width,height,hdc,rect,string) \
_check_txgetnaturalsize(res, width, height, hdc, rect, string, __LINE__)
static void _check_txgetnaturalsize(HRESULT res, LONG width, LONG height, HDC hdc, RECT rect, LPCWSTR string, int line)
{
RECT expected_rect = rect;
LONG expected_width, expected_height;
DrawTextW(hdc, string, -1, &expected_rect, DT_LEFT | DT_CALCRECT | DT_NOCLIP | DT_EDITCONTROL | DT_WORDBREAK);
expected_width = expected_rect.right - expected_rect.left;
expected_height = expected_rect.bottom - expected_rect.top;
ok_(__FILE__,line)(res == S_OK, "ITextServices_TxGetNaturalSize failed: 0x%08x.\n", res);
ok_(__FILE__,line)(width >= expected_width && width <= expected_width + 1,
"got wrong width: %d, expected: %d {+1}.\n", width, expected_width);
ok_(__FILE__,line)(height == expected_height, "got wrong height: %d, expected: %d.\n",
height, expected_height);
}
static void test_TxGetNaturalSize(void) static void test_TxGetNaturalSize(void)
{ {
ITextServices *txtserv; ITextServices *txtserv;
ITextHost *host; ITextHost *host;
HRESULT result; HRESULT result;
BOOL ret; SIZEL extent;
static const WCHAR test_text[] = {'T','e','s','t','S','o','m','e','T','e','x','t',0};
/* This value is used when calling TxGetNaturalSize. MSDN says LONG width, height;
that this is not supported however a null pointer cannot be
used as it will cause a segmentation violation. The values in
the structure being pointed to are required to be INT_MAX
otherwise calculations can give wrong values. */
const SIZEL psizelExtent = {INT_MAX,INT_MAX};
static const WCHAR oneA[] = {'A',0};
/* Results of measurements */
LONG xdim, ydim;
/* The device context to do the tests in */
HDC hdcDraw; HDC hdcDraw;
HWND hwnd;
/* Variables with the text metric information */ RECT rect;
INT charwidth_caps_text[26]; CHARFORMAT2W cf;
TEXTMETRICA tmInfo_text; LRESULT lresult;
HFONT hf;
if (!init_texthost(&txtserv, &host)) if (!init_texthost(&txtserv, &host))
return; return;
hdcDraw = GetDC(NULL); hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_VISIBLE,
SaveDC(hdcDraw); 0, 0, 100, 100, 0, 0, 0, NULL);
hdcDraw = GetDC(hwnd);
/* Populate the metric strucs */
SetMapMode(hdcDraw,MM_TEXT); SetMapMode(hdcDraw,MM_TEXT);
GetTextMetricsA(hdcDraw, &tmInfo_text); GetClientRect(hwnd, &rect);
SetLastError(0xdeadbeef);
ret = GetCharWidth32A(hdcDraw,'A','Z',charwidth_caps_text);
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
win_skip("GetCharWidth32 is not available\n");
goto cleanup;
}
/* Make measurements in MM_TEXT */ memset(&cf, 0, sizeof(cf));
SetMapMode(hdcDraw,MM_TEXT); cf.cbSize = sizeof(cf);
xdim = 0; ydim = 0; cf.dwMask = CFM_ALL2;
hf = GetStockObject(DEFAULT_GUI_FONT);
hf_to_cf(hf, &cf);
result = ITextServices_TxSendMessage(txtserv, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf, &lresult);
ok(result == S_OK, "ITextServices_TxSendMessage failed: 0x%08x.\n", result);
SelectObject(hdcDraw, hf);
result = ITextServices_TxSetText(txtserv, oneA); result = ITextServices_TxSetText(txtserv, test_text);
ok(result == S_OK, "ITextServices_TxSetText failed (result = %x)\n", result); ok(result == S_OK, "ITextServices_TxSetText failed: 0x%08x.\n", result);
if (result != S_OK) {
skip("Could not set text\n");
goto cleanup;
}
SetLastError(0xdeadbeef); extent.cx = -1; extent.cy = -1;
result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT, width = rect.right - rect.left;
hdcDraw, NULL, NULL, height = 0;
TXTNS_FITTOCONTENT, &psizelExtent, result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT, hdcDraw, NULL, NULL,
&xdim, &ydim); TXTNS_FITTOCONTENT, &extent, &width, &height);
todo_wine ok(result == S_OK || broken(result == E_FAIL), /* WINXP Arabic Language */ todo_wine CHECK_TXGETNATURALSIZE(result, width, height, hdcDraw, rect, test_text);
"TxGetNaturalSize gave unexpected return value (result = %x)\n", result);
if (result == S_OK) {
todo_wine ok(ydim == tmInfo_text.tmHeight,
"Height calculated incorrectly (expected %d, got %d)\n",
tmInfo_text.tmHeight, ydim);
/* The native DLL adds one pixel extra when calculating widths. */
todo_wine ok(xdim >= charwidth_caps_text[0] && xdim <= charwidth_caps_text[0] + 1,
"Width calculated incorrectly (expected %d {+1}, got %d)\n",
charwidth_caps_text[0], xdim);
} else
skip("TxGetNaturalSize measurements not performed (xdim = %d, ydim = %d, result = %x, error = %x)\n",
xdim, ydim, result, GetLastError());
cleanup: ReleaseDC(hwnd, hdcDraw);
RestoreDC(hdcDraw,1); DestroyWindow(hwnd);
ReleaseDC(NULL,hdcDraw);
ITextServices_Release(txtserv); ITextServices_Release(txtserv);
ITextHost_Release(host); ITextHost_Release(host);
} }