From f7120fd6aa436597e7568f562a44183048835b3c Mon Sep 17 00:00:00 2001 From: Giannis Adamopoulos Date: Mon, 27 Feb 2017 10:53:59 +0000 Subject: [PATCH] [COMCTL32_APITEST]: -Add tests for BCM_GETIDEALSIZE for non themed v6 buttons. svn path=/trunk/; revision=73994 --- rostests/apitests/comctl32/CMakeLists.txt | 2 +- rostests/apitests/comctl32/button.c | 156 +++++++++++++++++- .../apitests/comctl32/comctl32_apitest.rc | 2 + rostests/apitests/comctl32/test.bmp | Bin 0 -> 58 bytes 4 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 rostests/apitests/comctl32/test.bmp diff --git a/rostests/apitests/comctl32/CMakeLists.txt b/rostests/apitests/comctl32/CMakeLists.txt index addee1b5f18..3087700042d 100644 --- a/rostests/apitests/comctl32/CMakeLists.txt +++ b/rostests/apitests/comctl32/CMakeLists.txt @@ -2,5 +2,5 @@ add_executable(comctl32_apitest button.c testlist.c comctl32_apitest.rc) target_link_libraries(comctl32_apitest wine) set_module_type(comctl32_apitest win32cui) -add_importlibs(comctl32_apitest user32 msvcrt kernel32 ntdll) +add_importlibs(comctl32_apitest uxtheme comctl32 user32 gdi32 msvcrt kernel32 ntdll) add_rostests_file(TARGET comctl32_apitest) diff --git a/rostests/apitests/comctl32/button.c b/rostests/apitests/comctl32/button.c index ae9407a55b3..99c0841dbea 100644 --- a/rostests/apitests/comctl32/button.c +++ b/rostests/apitests/comctl32/button.c @@ -8,8 +8,10 @@ #include "wine/test.h" #include #include +#include #define ok_rect(rc, l,r,t,b) ok((rc.left == (l)) && (rc.right == (r)) && (rc.top == (t)) && (rc.bottom == (b)), "Wrong rect. expected %d, %d, %d, %d got %ld, %ld, %ld, %ld\n", l,t,r,b, rc.left, rc.top, rc.right, rc.bottom) +#define ok_size(s, width, height) ok((s.cx == (width) && s.cy == (height)), "Expected size (%lu,%lu) got (%lu,%lu)\n", width, height, s.cx, s.cy) void Test_TextMargin() { @@ -72,7 +74,7 @@ void Test_Imagelist() imlData.himl = (HIMAGELIST)0xdead; ret = SendMessageW(hwnd1, BCM_SETIMAGELIST, 0, (LPARAM)&imlData); - ok (ret == TRUE, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */ + ok (ret == TRUE, "Expected BCM_SETIMAGELIST to fail\n"); ret = SendMessageW(hwnd1, BCM_GETIMAGELIST, 0, (LPARAM)&imlData); ok (ret == TRUE, "Expected BCM_GETIMAGELIST to succeed\n"); @@ -83,6 +85,157 @@ void Test_Imagelist() imlData.himl = 0; ret = SendMessageW(hwnd1, BCM_SETIMAGELIST, 0, (LPARAM)&imlData); ok (ret == FALSE, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */ + + DestroyWindow(hwnd1); +} + +void Test_GetIdealSizeNoThemes() +{ + HWND hwnd1; + BOOL ret; + SIZE s, textent; + HFONT font; + HDC hdc; + WINDOWINFO wi; + HANDLE hbmp; + HIMAGELIST himl; + BUTTON_IMAGELIST imlData; + RECT rc; + + hwnd1 = CreateWindowW(L"Button", L" ", 0, 10, 10, 100, 100, 0, NULL, NULL, NULL); + ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n"); + SetWindowTheme(hwnd1, L"", L""); + + font = (HFONT)SendMessageW(hwnd1, WM_GETFONT, 0, 0); + hdc = GetDC(hwnd1); + SelectObject(hdc, font); + GetTextExtentPoint32W(hdc, L" ", 1, &textent); + + memset(&wi, 0, sizeof(wi)); + GetWindowInfo(hwnd1, &wi); + + memset(&s, 0, sizeof(s)); + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok_size(s, textent.cx + 2 * wi.cxWindowBorders - 1 + 2, + textent.cy + 2 * wi.cyWindowBorders + 1 + 2); /* the last +2 is the text margin */ + + DestroyWindow(hwnd1); + + hwnd1 = CreateWindowW(L"Button", L"", 0, 10, 10, 100, 100, 0, NULL, NULL, NULL); + ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n"); + SetWindowTheme(hwnd1, L"", L""); + + memset(&s, 0, sizeof(s)); + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok (s.cx > 80, "Expected big cx\n"); + ok (s.cy > 80, "Expected big cy\n"); + + s.cx = 1; + s.cy = 1; + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok (s.cx > 80, "Expected big cx\n"); + ok (s.cy > 80, "Expected big cy\n"); + + hbmp = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(5), IMAGE_BITMAP, 0, 0, 0); + ok (hbmp != 0, "Expected LoadImage to succeed\n"); + + SendMessageW(hwnd1, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp); + + memset(&s, 0, sizeof(s)); + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok (s.cx > 80, "Expected big cx\n"); + ok (s.cy > 80, "Expected big cy\n"); + + himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(5), 1, 1, 0, IMAGE_BITMAP, 0); + ok (himl != 0, "Expected ImageList_LoadImage to succeed\n"); + + memset(&imlData, 0, sizeof(imlData)); + imlData.himl = himl; + ret = SendMessageW(hwnd1, BCM_SETIMAGELIST, 0, (LPARAM)&imlData); + ok (ret == TRUE, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */ + + memset(&s, 0, sizeof(s)); + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok (s.cx > 80, "Expected big cx\n"); + ok (s.cy > 80, "Expected big cy\n"); + + DestroyWindow(hwnd1); + + hwnd1 = CreateWindowW(L"Button", L" ", 0, 10, 10, 100, 100, 0, NULL, NULL, NULL); + ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n"); + SetWindowTheme(hwnd1, L"", L""); + + SetRect(&rc, 0,0,0,0); + ret = SendMessageW(hwnd1, BCM_SETTEXTMARGIN, 0, (LPARAM)&rc); + ok (ret == TRUE, "Expected BCM_SETTEXTMARGIN to succeed\n"); + + memset(&s, 0, sizeof(s)); + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok_size(s, textent.cx + 2 * wi.cxWindowBorders - 1, + textent.cy + 2 * wi.cyWindowBorders + 1); + + SetRect(&rc, 50,50,50,50); + ret = SendMessageW(hwnd1, BCM_SETTEXTMARGIN, 0, (LPARAM)&rc); + ok (ret == TRUE, "Expected BCM_SETTEXTMARGIN to succeed\n"); + + memset(&s, 0, sizeof(s)); + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok_size(s, textent.cx + 2 * wi.cxWindowBorders - 1 + 100, + textent.cy + 2 * wi.cyWindowBorders + 1 + 100); + + SetRect(&rc, 0,0,0,0); + ret = SendMessageW(hwnd1, BCM_SETTEXTMARGIN, 0, (LPARAM)&rc); + ok (ret == TRUE, "Expected BCM_SETTEXTMARGIN to succeed\n"); + + ret = SendMessageW(hwnd1, BCM_SETIMAGELIST, 0, (LPARAM)&imlData); + ok (ret == TRUE, "Expected BCM_SETIMAGELIST to fail\n"); /* This works in win10 */ + + memset(&s, 0, sizeof(s)); + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok_size(s, textent.cx + 2 * wi.cxWindowBorders, /* we get an extra pixel due to the iml */ + textent.cy + 2 * wi.cyWindowBorders + 1); + + s.cx = 1; + s.cy = 1; + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok_size(s, textent.cx + 2 * wi.cxWindowBorders, + textent.cy + 2 * wi.cyWindowBorders + 1); + + s.cx = 100; + s.cy = 100; + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok_size(s, textent.cx + 2 * wi.cxWindowBorders, + textent.cy + 2 * wi.cyWindowBorders + 1); + + DestroyWindow(hwnd1); + + /* Test again with some real text to see if the formula is correct */ + hwnd1 = CreateWindowW(L"Button", L"Some test text", 0, 10, 10, 100, 100, 0, NULL, NULL, NULL); + ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n"); + SetWindowTheme(hwnd1, L"", L""); + + font = (HFONT)SendMessageW(hwnd1, WM_GETFONT, 0, 0); + hdc = GetDC(hwnd1); + SelectObject(hdc, font); + GetTextExtentPoint32W(hdc, L"Some test text", 14, &textent); + + memset(&s, 0, sizeof(s)); + ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s); + ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n"); + ok_size(s, textent.cx + 2 * wi.cxWindowBorders - 1 + 2, /* the last +2 is the text margin */ + textent.cy + 2 * wi.cyWindowBorders + 1 + 2); + + DestroyWindow(hwnd1); } START_TEST(button) @@ -90,5 +243,6 @@ START_TEST(button) LoadLibraryW(L"comctl32.dll"); /* same as statically linking to comctl32 and doing InitCommonControls */ Test_TextMargin(); Test_Imagelist(); + Test_GetIdealSizeNoThemes(); } diff --git a/rostests/apitests/comctl32/comctl32_apitest.rc b/rostests/apitests/comctl32/comctl32_apitest.rc index 375af3a24f2..8cfe8183739 100644 --- a/rostests/apitests/comctl32/comctl32_apitest.rc +++ b/rostests/apitests/comctl32/comctl32_apitest.rc @@ -5,3 +5,5 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL #include + +5 BITMAP "test.bmp" diff --git a/rostests/apitests/comctl32/test.bmp b/rostests/apitests/comctl32/test.bmp new file mode 100644 index 0000000000000000000000000000000000000000..b26c0eb8cd047a78af4484cfe480ae7167c933dd GIT binary patch literal 58 fcmZ?rwPJt(Ga#h_#Eft(0hV9^lc>c1|Nj{PN|ppf literal 0 HcmV?d00001 -- 2.17.1