comctl32/tests: Tests default margin size with various font face and charset.

Signed-off-by: Akihiro Sagawa <sagawa.aki@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Akihiro Sagawa 2019-04-24 21:42:15 +09:00 committed by Alexandre Julliard
parent 5012c1b18b
commit 95f7ad03e3
1 changed files with 66 additions and 34 deletions

View File

@ -1485,13 +1485,17 @@ static void test_edit_control_scroll(void)
DestroyWindow (hwEdit);
}
static BOOL is_cjk_charset(HDC dc)
static BOOL is_cjk(HDC dc)
{
const DWORD FS_DBCS_MASK = FS_JISJAPAN|FS_CHINESESIMP|FS_WANSUNG|FS_CHINESETRAD|FS_JOHAB;
FONTSIGNATURE fs;
switch (GdiGetCodePage(dc)) {
case 932: case 936: case 949: case 950: case 1361:
return TRUE;
default:
return FALSE;
return (GetTextCharsetInfo(dc, &fs, 0) != DEFAULT_CHARSET &&
(fs.fsCsb[0] & FS_DBCS_MASK));
}
}
@ -1599,13 +1603,13 @@ static void test_margins_usefontinfo(UINT charset)
DeleteObject(hfont);
}
static void test_margins_default(UINT charset)
static void test_margins_default(const char* facename, UINT charset)
{
HWND hwnd;
HDC hdc;
TEXTMETRICW tm;
SIZE size;
BOOL cjk_charset;
BOOL cjk;
LOGFONTA lf;
HFONT hfont;
RECT rect;
@ -1617,7 +1621,7 @@ static void test_margins_default(UINT charset)
lf.lfHeight = -11;
lf.lfWeight = FW_NORMAL;
lf.lfCharSet = charset;
strcpy(lf.lfFaceName, "Tahoma");
strcpy(lf.lfFaceName, facename);
hfont = CreateFontIndirectA(&lf);
ok(hfont != NULL, "got %p\n", hfont);
@ -1641,7 +1645,7 @@ static void test_margins_default(UINT charset)
return;
}
expect = MAKELONG(size.cx / 2, size.cx / 2);
cjk_charset = is_cjk_charset(hdc);
cjk = is_cjk(hdc);
hfont = SelectObject(hdc, hfont);
ReleaseDC(hwnd, hdc);
@ -1651,17 +1655,17 @@ static void test_margins_default(UINT charset)
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));
if (!cjk)
ok(margins == expect, "%s:%d: got %d, %d\n", facename, 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));
if (!cjk)
ok(margins == expect, "%s:%d: got %d, %d\n", facename, 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));
ok(HIWORD(margins) <= HIWORD(expect), "%s:%d: got %d\n", facename, charset, HIWORD(margins));
ok(LOWORD(margins) <= LOWORD(expect), "%s:%d: got %d\n", facename, charset, LOWORD(margins));
}
DestroyWindow(hwnd);
@ -1676,23 +1680,40 @@ static void test_margins_default(UINT charset)
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));
if (!cjk)
ok(margins == expect, "%s:%d: got %d, %d\n", facename, 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));
if (!cjk)
ok(margins == expect, "%s:%d: got %d, %d\n", facename, 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));
ok(HIWORD(margins) <= HIWORD(expect), "%s:%d: got %d\n", facename, charset, HIWORD(margins));
ok(LOWORD(margins) <= LOWORD(expect), "%s:%d: got %d\n", facename, charset, LOWORD(margins));
}
DestroyWindow(hwnd);
DeleteObject(hfont);
}
static INT CALLBACK find_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm, DWORD type, LPARAM lParam)
{
return 0;
}
static BOOL is_font_installed(const char*name)
{
HDC hdc = GetDC(NULL);
BOOL ret = FALSE;
if (!EnumFontFamiliesA(hdc, name, find_font_proc, 0))
ret = TRUE;
ReleaseDC(NULL, hdc);
return ret;
}
static void test_margins(void)
{
DWORD old_margins, new_margins;
@ -1768,33 +1789,44 @@ static void test_margins(void)
test_margins_usefontinfo(DEFAULT_CHARSET);
test_margins_default(ANSI_CHARSET);
test_margins_default(EASTEUROPE_CHARSET);
test_margins_default("Tahoma", ANSI_CHARSET);
test_margins_default("Tahoma", EASTEUROPE_CHARSET);
test_margins_default(SHIFTJIS_CHARSET);
test_margins_default(HANGUL_CHARSET);
test_margins_default(CHINESEBIG5_CHARSET);
}
test_margins_default("Tahoma", HANGUL_CHARSET);
test_margins_default("Tahoma", CHINESEBIG5_CHARSET);
static INT CALLBACK find_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm, DWORD type, LPARAM lParam)
{
return 0;
if (is_font_installed("MS PGothic")) {
test_margins_default("MS PGothic", SHIFTJIS_CHARSET);
test_margins_default("MS PGothic", GREEK_CHARSET);
}
else
skip("MS PGothic is not available, skipping some margin tests\n");
if (is_font_installed("Ume P Gothic")) {
test_margins_default("Ume P Gothic", SHIFTJIS_CHARSET);
test_margins_default("Ume P Gothic", GREEK_CHARSET);
}
else
skip("Ume P Gothic is not available, skipping some margin tests\n");
if (is_font_installed("SimSun")) {
test_margins_default("SimSun", GB2312_CHARSET);
test_margins_default("SimSun", ANSI_CHARSET);
}
else
skip("SimSun is not available, skipping some margin tests\n");
}
static void test_margins_font_change(void)
{
DWORD margins, font_margins, ret;
DWORD margins, font_margins;
HFONT hfont, hfont2;
HWND hwEdit;
LOGFONTA lf;
HDC hdc;
hdc = GetDC(0);
ret = EnumFontFamiliesA(hdc, "Arial", find_font_proc, 0);
ReleaseDC(0, hdc);
if (ret)
if (!is_font_installed("Arial"))
{
trace("Arial not found - skipping font change margin tests\n");
skip("Arial not found - skipping font change margin tests\n");
return;
}