From: Akihiro Sagawa Subject: [PATCH 1/5] comctl32/tests: Move the default margin size tests into a separate function. Message-Id: <20190424214102.599E.375B48EC@gmail.com> Date: Wed, 24 Apr 2019 21:42:11 +0900 Signed-off-by: Akihiro Sagawa --- dlls/comctl32/tests/edit.c | 93 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/dlls/comctl32/tests/edit.c b/dlls/comctl32/tests/edit.c index 70cb94e..2a333c2 100644 --- a/dlls/comctl32/tests/edit.c +++ b/dlls/comctl32/tests/edit.c @@ -1501,7 +1501,6 @@ static void test_margins_usefontinfo(UINT charset) HDC hdc; TEXTMETRICW tm; SIZE size; - BOOL cjk_charset; LOGFONTA lf; HFONT hfont; RECT rect; @@ -1536,29 +1535,14 @@ static void test_margins_usefontinfo(UINT charset) return; } expect = MAKELONG(size.cx / 2, size.cx / 2); - cjk_charset = is_cjk_charset(hdc); - hfont = SelectObject(hdc, hfont); ReleaseDC(hwnd, hdc); margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0); ok(margins == 0, "got %x\n", margins); - SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins); SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0)); - margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0); - if (!cjk_charset) - ok(margins == expect, "%d: got %d, %d\n", charset, HIWORD(margins), LOWORD(margins)); - SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins); SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO)); - margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0); - if (!cjk_charset) - ok(margins == expect, "%d: got %d, %d\n", charset, HIWORD(margins), LOWORD(margins)); - else - { - ok(HIWORD(margins) <= HIWORD(expect), "%d: got %d\n", charset, HIWORD(margins)); - ok(LOWORD(margins) <= LOWORD(expect), "%d: got %d\n", charset, LOWORD(margins)); - expect = margins; - } + expect = SendMessageA(hwnd, EM_GETMARGINS, 0, 0); DestroyWindow(hwnd); threshold = HIWORD(expect) + LOWORD(expect) + size.cx * 2; @@ -1615,6 +1599,74 @@ static void test_margins_usefontinfo(UINT charset) DeleteObject(hfont); } +static void test_margins_default(UINT charset) +{ + HWND hwnd; + HDC hdc; + TEXTMETRICW tm; + SIZE size; + BOOL cjk_charset; + LOGFONTA lf; + HFONT hfont; + RECT rect; + INT margins, expect; + const UINT small_margins = MAKELONG(1, 5); + + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = -11; + lf.lfWeight = FW_NORMAL; + lf.lfCharSet = charset; + strcpy(lf.lfFaceName, "Tahoma"); + + hfont = CreateFontIndirectA(&lf); + ok(hfont != NULL, "got %p\n", hfont); + + /* Big window rectangle */ + hwnd = CreateWindowExA(0, "Edit", "A", WS_POPUP, 0, 0, 5000, 1000, NULL, NULL, NULL, NULL); + ok(hwnd != NULL, "got %p\n", hwnd); + GetClientRect(hwnd, &rect); + ok(!IsRectEmpty(&rect), "got rect %s\n", wine_dbgstr_rect(&rect)); + + hdc = GetDC(hwnd); + hfont = SelectObject(hdc, hfont); + size.cx = GdiGetCharDimensions( hdc, &tm, &size.cy ); + if ((charset != tm.tmCharSet && charset != DEFAULT_CHARSET) || + !(tm.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR))) { + skip("%s for charset %d isn't available\n", lf.lfFaceName, charset); + hfont = SelectObject(hdc, hfont); + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); + DeleteObject(hfont); + return; + } + expect = MAKELONG(size.cx / 2, size.cx / 2); + cjk_charset = is_cjk_charset(hdc); + + hfont = SelectObject(hdc, hfont); + ReleaseDC(hwnd, hdc); + + margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0); + ok(margins == 0, "got %x\n", margins); + SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins); + SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0)); + margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0); + if (!cjk_charset) + ok(margins == expect, "%d: got %d, %d\n", charset, HIWORD(margins), LOWORD(margins)); + SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins); + SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO)); + margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0); + if (!cjk_charset) + ok(margins == expect, "%d: got %d, %d\n", charset, HIWORD(margins), LOWORD(margins)); + else + { + ok(HIWORD(margins) <= HIWORD(expect), "%d: got %d\n", charset, HIWORD(margins)); + ok(LOWORD(margins) <= LOWORD(expect), "%d: got %d\n", charset, LOWORD(margins)); + } + DestroyWindow(hwnd); + + DeleteObject(hfont); +} + static void test_margins(void) { DWORD old_margins, new_margins; @@ -1689,6 +1741,13 @@ static void test_margins(void) but not by < Win 8 and Win 10. */ test_margins_usefontinfo(DEFAULT_CHARSET); + + test_margins_default(ANSI_CHARSET); + test_margins_default(EASTEUROPE_CHARSET); + + test_margins_default(SHIFTJIS_CHARSET); + test_margins_default(HANGUL_CHARSET); + test_margins_default(CHINESEBIG5_CHARSET); } static INT CALLBACK find_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm, DWORD type, LPARAM lParam)