Superseded patch 146217.
Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/riched20/tests/txtsrv.c | 87 ++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 51 deletions(-)
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c index 88b5adf13c..8893fa6bf5 100644 --- a/dlls/riched20/tests/txtsrv.c +++ b/dlls/riched20/tests/txtsrv.c @@ -697,81 +697,66 @@ static void test_TxSetText(void) ITextHost_Release(host); }
+#define CHECK_TXGETNATURALSIZE(res,width,height,max_width,min_width,expected_height) \ + _check_txgetnaturalsize(res, width, height, max_width, min_width, expected_height, __LINE__) +static void _check_txgetnaturalsize(HRESULT res, LONG width, LONG height, LONG max_width, + LONG min_width, LONG expected_height, int line) +{ + ok_(__FILE__,line)(res == S_OK, "TxGetNaturalSize failed: 0x%08x.\n", res); + ok_(__FILE__,line)(width >= min_width && width <= max_width, + "got wrong width: %d, expected: %d <= width <= %d.\n", + width, min_width, max_width); + ok_(__FILE__,line)(height == expected_height || + height == 18 /* Japanese win7 */, "got wrong height: %d, expected: %d.\n", + height, expected_height); +} + static void test_TxGetNaturalSize(void) { ITextServices *txtserv; ITextHost *host; HRESULT result; - BOOL ret; - - /* This value is used when calling TxGetNaturalSize. MSDN says - 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 */ + SIZEL psizelExtent = {-1,-1}; + static const WCHAR test_text[] = {'T','e','s','t','S','o','m','e','T','e','x','t',0}; + LONG width, height; HDC hdcDraw; - - /* Variables with the text metric information */ - INT charwidth_caps_text[26]; - TEXTMETRICA tmInfo_text; + HWND hwnd; + RECT rect;
if (!init_texthost(&txtserv, &host)) return;
- hdcDraw = GetDC(NULL); - SaveDC(hdcDraw); - - /* Populate the metric strucs */ + hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_VISIBLE, + 0, 0, 100, 100, 0, 0, 0, NULL); + hdcDraw = GetDC(hwnd); SetMapMode(hdcDraw,MM_TEXT); - GetTextMetricsA(hdcDraw, &tmInfo_text); - 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 */ - SetMapMode(hdcDraw,MM_TEXT); - xdim = 0; ydim = 0;
- result = ITextServices_TxSetText(txtserv, oneA); + result = ITextServices_TxSetText(txtserv, test_text); ok(result == S_OK, "ITextServices_TxSetText failed (result = %x)\n", result); if (result != S_OK) { skip("Could not set text\n"); goto cleanup; }
- SetLastError(0xdeadbeef); + GetClientRect(hwnd, &rect); + + psizelExtent.cx = -1; psizelExtent.cy = -1; + width = rect.right - rect.left; + height = 0; result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT, hdcDraw, NULL, NULL, TXTNS_FITTOCONTENT, &psizelExtent, - &xdim, &ydim); - todo_wine ok(result == S_OK || broken(result == E_FAIL), /* WINXP Arabic Language */ - "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()); + &width, &height); + if (result == E_FAIL) + { + win_skip("ITextServices_TxGetNaturalSize isn't available on this platform.\n"); + goto cleanup; + } + todo_wine CHECK_TXGETNATURALSIZE(result, width, height, 95, 74, 16);
cleanup: - RestoreDC(hdcDraw,1); ReleaseDC(NULL,hdcDraw); + DestroyWindow(hwnd); ITextServices_Release(txtserv); ITextHost_Release(host); }
On Tue, May 22, 2018 at 04:31:57PM +0800, Jactry Zeng wrote:
Superseded patch 146217.
Signed-off-by: Jactry Zeng jzeng@codeweavers.com
dlls/riched20/tests/txtsrv.c | 87 ++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 51 deletions(-)
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c index 88b5adf13c..8893fa6bf5 100644 --- a/dlls/riched20/tests/txtsrv.c +++ b/dlls/riched20/tests/txtsrv.c @@ -697,81 +697,66 @@ static void test_TxSetText(void) ITextHost_Release(host); }
+#define CHECK_TXGETNATURALSIZE(res,width,height,max_width,min_width,expected_height) \
- _check_txgetnaturalsize(res, width, height, max_width, min_width, expected_height, __LINE__)
+static void _check_txgetnaturalsize(HRESULT res, LONG width, LONG height, LONG max_width,
LONG min_width, LONG expected_height, int line)
+{
- ok_(__FILE__,line)(res == S_OK, "TxGetNaturalSize failed: 0x%08x.\n", res);
- ok_(__FILE__,line)(width >= min_width && width <= max_width,
"got wrong width: %d, expected: %d <= width <= %d.\n",
width, min_width, max_width);
- ok_(__FILE__,line)(height == expected_height ||
height == 18 /* Japanese win7 */, "got wrong height: %d, expected: %d.\n",
height, expected_height);
+}
static void test_TxGetNaturalSize(void) { ITextServices *txtserv; ITextHost *host; HRESULT result;
- BOOL ret;
- /* This value is used when calling TxGetNaturalSize. MSDN says
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 */
- SIZEL psizelExtent = {-1,-1};
- static const WCHAR test_text[] = {'T','e','s','t','S','o','m','e','T','e','x','t',0};
- LONG width, height; HDC hdcDraw;
- /* Variables with the text metric information */
- INT charwidth_caps_text[26];
- TEXTMETRICA tmInfo_text;
HWND hwnd;
RECT rect;
if (!init_texthost(&txtserv, &host)) return;
- hdcDraw = GetDC(NULL);
- SaveDC(hdcDraw);
- /* Populate the metric strucs */
- hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_VISIBLE,
0, 0, 100, 100, 0, 0, 0, NULL);
- hdcDraw = GetDC(hwnd); SetMapMode(hdcDraw,MM_TEXT);
GetTextMetricsA(hdcDraw, &tmInfo_text);
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 */
SetMapMode(hdcDraw,MM_TEXT);
xdim = 0; ydim = 0;
result = ITextServices_TxSetText(txtserv, oneA);
- result = ITextServices_TxSetText(txtserv, test_text); ok(result == S_OK, "ITextServices_TxSetText failed (result = %x)\n", result); if (result != S_OK) { skip("Could not set text\n"); goto cleanup; }
- SetLastError(0xdeadbeef);
- GetClientRect(hwnd, &rect);
- psizelExtent.cx = -1; psizelExtent.cy = -1;
- width = rect.right - rect.left;
- height = 0; result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT, hdcDraw, NULL, NULL, TXTNS_FITTOCONTENT, &psizelExtent,
&xdim, &ydim);
- todo_wine ok(result == S_OK || broken(result == E_FAIL), /* WINXP Arabic Language */
"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());
&width, &height);
- if (result == E_FAIL)
- {
win_skip("ITextServices_TxGetNaturalSize isn't available on this platform.\n");
goto cleanup;
- }
- todo_wine CHECK_TXGETNATURALSIZE(result, width, height, 95, 74, 16);
cleanup:
- RestoreDC(hdcDraw,1); ReleaseDC(NULL,hdcDraw);
- DestroyWindow(hwnd); ITextServices_Release(txtserv); ITextHost_Release(host);
}
While the original test isn't great, it does at least compare the returned size to font metrics. You'll need to figure out the algorithm rather than just hardcoding a (very large) range.
Huw.
Hi Huw,
Thanks for review.
Huw Davies huw@codeweavers.com 于2018年5月23日周三 下午4:34写道:
While the original test isn't great, it does at least compare the returned size to font metrics. You'll need to figure out the algorithm rather than just hardcoding a (very large) range.
That range looks large is because that the Japanese Windows testbot has a different font. And That minimum is for the Japanese testbot. Can I just skip these tests in Japanese testbot and supplement some more tests for comparing the returned size to font metrics?
Huw.
-- Regards, Jactry Zeng
On Wed, May 23, 2018 at 04:43:58PM +0800, Jactry Zeng wrote:
Hi Huw,
Thanks for review.
Huw Davies huw@codeweavers.com 于2018年5月23日周三 下午4:34写道:
While the original test isn't great, it does at least compare the returned size to font metrics. You'll need to figure out the algorithm rather than just hardcoding a (very large) range.
That range looks large is because that the Japanese Windows testbot has a different font. And That minimum is for the Japanese testbot. Can I just skip these tests in Japanese testbot and supplement some more tests for comparing the returned size to font metrics?
No, it's good to have the test run with multiple fonts. You'll have to figure out how to get the natural size from the font metrics.
Huw.