2005-08-23 12:02:25 +02:00
|
|
|
/* Unit tests for the progress bar control.
|
|
|
|
*
|
|
|
|
* Copyright 2005 Michael Kaufmann
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-23 12:02:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "commctrl.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2018-02-28 06:57:53 +01:00
|
|
|
#include "v6util.h"
|
2005-08-23 12:02:25 +02:00
|
|
|
|
2018-02-28 06:57:53 +01:00
|
|
|
static HWND hProgressParentWnd;
|
2006-01-24 14:00:32 +01:00
|
|
|
static const char progressTestClass[] = "ProgressBarTestClass";
|
2018-01-24 13:47:09 +01:00
|
|
|
static BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
|
2005-08-23 12:02:25 +02:00
|
|
|
|
2013-05-25 18:12:12 +02:00
|
|
|
static HWND create_progress(DWORD style)
|
|
|
|
{
|
|
|
|
return CreateWindowExA(0, PROGRESS_CLASSA, "", WS_VISIBLE | style,
|
|
|
|
0, 0, 100, 20, NULL, NULL, GetModuleHandleA(NULL), 0);
|
|
|
|
}
|
2005-08-23 12:02:25 +02:00
|
|
|
|
2007-11-06 14:39:41 +01:00
|
|
|
/* try to make sure pending X events have been processed before continuing */
|
|
|
|
static void flush_events(void)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
int diff = 100;
|
|
|
|
DWORD time = GetTickCount() + diff;
|
|
|
|
|
|
|
|
while (diff > 0)
|
|
|
|
{
|
|
|
|
if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
|
2013-10-19 17:04:23 +02:00
|
|
|
while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
|
2007-11-06 14:39:41 +01:00
|
|
|
diff = time - GetTickCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-19 17:04:23 +02:00
|
|
|
static LRESULT CALLBACK progress_test_wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2005-08-23 12:02:25 +02:00
|
|
|
{
|
|
|
|
switch(msg) {
|
2006-12-11 21:22:02 +01:00
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
case WM_DESTROY:
|
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProcA(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
2006-01-11 12:12:06 +01:00
|
|
|
static WNDPROC progress_wndproc;
|
|
|
|
static BOOL erased;
|
|
|
|
static RECT last_paint_rect;
|
|
|
|
|
2013-10-19 17:04:23 +02:00
|
|
|
static LRESULT CALLBACK progress_subclass_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2006-01-11 12:12:06 +01:00
|
|
|
{
|
|
|
|
if (msg == WM_PAINT)
|
|
|
|
{
|
|
|
|
GetUpdateRect(hWnd, &last_paint_rect, FALSE);
|
|
|
|
}
|
|
|
|
else if (msg == WM_ERASEBKGND)
|
|
|
|
{
|
|
|
|
erased = TRUE;
|
|
|
|
}
|
2013-10-19 17:04:23 +02:00
|
|
|
return CallWindowProcA(progress_wndproc, hWnd, msg, wParam, lParam);
|
2006-01-11 12:12:06 +01:00
|
|
|
}
|
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
|
|
|
|
static void update_window(HWND hWnd)
|
|
|
|
{
|
|
|
|
UpdateWindow(hWnd);
|
|
|
|
ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void init(void)
|
|
|
|
{
|
|
|
|
WNDCLASSA wc;
|
|
|
|
RECT rect;
|
2014-02-13 09:31:48 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = GetModuleHandleA(NULL);
|
|
|
|
wc.hIcon = NULL;
|
2013-10-19 17:04:23 +02:00
|
|
|
wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
|
2005-08-23 12:02:25 +02:00
|
|
|
wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = progressTestClass;
|
2013-10-19 17:04:23 +02:00
|
|
|
wc.lpfnWndProc = progress_test_wnd_proc;
|
2005-08-23 12:02:25 +02:00
|
|
|
RegisterClassA(&wc);
|
2016-04-08 13:38:03 +02:00
|
|
|
|
|
|
|
SetRect(&rect, 0, 0, 400, 20);
|
2014-02-13 09:31:48 +01:00
|
|
|
ret = AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
|
|
|
|
ok(ret, "got %d\n", ret);
|
2005-08-23 12:02:25 +02:00
|
|
|
|
|
|
|
hProgressParentWnd = CreateWindowExA(0, progressTestClass, "Progress Bar Test", WS_OVERLAPPEDWINDOW,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandleA(NULL), 0);
|
2014-02-13 09:31:48 +01:00
|
|
|
ok(hProgressParentWnd != NULL, "failed to create parent wnd\n");
|
2006-01-11 12:12:06 +01:00
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup(void)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
PostMessageA(hProgressParentWnd, WM_CLOSE, 0, 0);
|
|
|
|
while (GetMessageA(&msg,0,0,0)) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageA(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnregisterClassA(progressTestClass, GetModuleHandleA(NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tests if a progress bar repaints itself immediately when it receives
|
|
|
|
* some specific messages.
|
|
|
|
*/
|
|
|
|
static void test_redraw(void)
|
|
|
|
{
|
2018-02-28 06:57:53 +01:00
|
|
|
RECT client_rect, rect;
|
|
|
|
HWND hProgressWnd;
|
2009-12-22 14:23:46 +01:00
|
|
|
LRESULT ret;
|
2006-01-11 12:12:06 +01:00
|
|
|
|
2018-02-28 06:57:53 +01:00
|
|
|
GetClientRect(hProgressParentWnd, &rect);
|
|
|
|
hProgressWnd = CreateWindowExA(0, PROGRESS_CLASSA, "", WS_CHILD | WS_VISIBLE,
|
|
|
|
0, 0, rect.right, rect.bottom, hProgressParentWnd, NULL, GetModuleHandleA(NULL), 0);
|
|
|
|
ok(hProgressWnd != NULL, "Failed to create progress bar.\n");
|
|
|
|
progress_wndproc = (WNDPROC)SetWindowLongPtrA(hProgressWnd, GWLP_WNDPROC, (LPARAM)progress_subclass_proc);
|
|
|
|
|
|
|
|
ShowWindow(hProgressParentWnd, SW_SHOWNORMAL);
|
|
|
|
ok(GetUpdateRect(hProgressParentWnd, NULL, FALSE), "GetUpdateRect: There should be a region that needs to be updated\n");
|
|
|
|
flush_events();
|
|
|
|
update_window(hProgressParentWnd);
|
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
SendMessageA(hProgressWnd, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
|
|
|
|
SendMessageA(hProgressWnd, PBM_SETPOS, 10, 0);
|
|
|
|
SendMessageA(hProgressWnd, PBM_SETSTEP, 20, 0);
|
|
|
|
update_window(hProgressWnd);
|
|
|
|
|
|
|
|
/* PBM_SETPOS */
|
|
|
|
ok(SendMessageA(hProgressWnd, PBM_SETPOS, 50, 0) == 10, "PBM_SETPOS must return the previous position\n");
|
|
|
|
ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
|
2018-02-28 06:57:53 +01:00
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
/* PBM_DELTAPOS */
|
|
|
|
ok(SendMessageA(hProgressWnd, PBM_DELTAPOS, 15, 0) == 50, "PBM_DELTAPOS must return the previous position\n");
|
|
|
|
ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_DELTAPOS: The progress bar should be redrawn immediately\n");
|
2018-02-28 06:57:53 +01:00
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
/* PBM_SETPOS */
|
|
|
|
ok(SendMessageA(hProgressWnd, PBM_SETPOS, 80, 0) == 65, "PBM_SETPOS must return the previous position\n");
|
|
|
|
ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_SETPOS: The progress bar should be redrawn immediately\n");
|
2018-02-28 06:57:53 +01:00
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
/* PBM_STEPIT */
|
|
|
|
ok(SendMessageA(hProgressWnd, PBM_STEPIT, 0, 0) == 80, "PBM_STEPIT must return the previous position\n");
|
|
|
|
ok(!GetUpdateRect(hProgressWnd, NULL, FALSE), "PBM_STEPIT: The progress bar should be redrawn immediately\n");
|
2009-12-22 14:23:46 +01:00
|
|
|
ret = SendMessageA(hProgressWnd, PBM_GETPOS, 0, 0);
|
|
|
|
if (ret == 0)
|
|
|
|
win_skip("PBM_GETPOS needs comctl32 > 4.70\n");
|
|
|
|
else
|
|
|
|
ok(ret == 100, "PBM_GETPOS returned a wrong position : %d\n", (UINT)ret);
|
2018-02-28 06:57:53 +01:00
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
/* PBM_SETRANGE and PBM_SETRANGE32:
|
|
|
|
Usually the progress bar doesn't repaint itself immediately. If the
|
|
|
|
position is not in the new range, it does.
|
|
|
|
Don't test this, it may change in future Windows versions. */
|
2006-01-11 12:12:06 +01:00
|
|
|
|
2013-10-19 17:04:23 +02:00
|
|
|
SendMessageA(hProgressWnd, PBM_SETPOS, 0, 0);
|
2006-01-11 12:12:06 +01:00
|
|
|
update_window(hProgressWnd);
|
|
|
|
|
|
|
|
/* increase to 10 - no background erase required */
|
|
|
|
erased = FALSE;
|
|
|
|
SetRectEmpty(&last_paint_rect);
|
2013-10-19 17:04:23 +02:00
|
|
|
SendMessageA(hProgressWnd, PBM_SETPOS, 10, 0);
|
2006-01-11 12:12:06 +01:00
|
|
|
GetClientRect(hProgressWnd, &client_rect);
|
2016-06-08 12:28:46 +02:00
|
|
|
ok(EqualRect(&last_paint_rect, &client_rect), "last_paint_rect was %s instead of %s\n",
|
|
|
|
wine_dbgstr_rect(&last_paint_rect), wine_dbgstr_rect(&client_rect));
|
2006-01-11 12:12:06 +01:00
|
|
|
update_window(hProgressWnd);
|
|
|
|
ok(!erased, "Progress bar shouldn't have erased the background\n");
|
|
|
|
|
|
|
|
/* decrease to 0 - background erase will be required */
|
|
|
|
erased = FALSE;
|
|
|
|
SetRectEmpty(&last_paint_rect);
|
2013-10-19 17:04:23 +02:00
|
|
|
SendMessageA(hProgressWnd, PBM_SETPOS, 0, 0);
|
2006-01-11 12:12:06 +01:00
|
|
|
GetClientRect(hProgressWnd, &client_rect);
|
2016-06-08 12:28:46 +02:00
|
|
|
ok(EqualRect(&last_paint_rect, &client_rect), "last_paint_rect was %s instead of %s\n",
|
|
|
|
wine_dbgstr_rect(&last_paint_rect), wine_dbgstr_rect(&client_rect));
|
2006-01-11 12:12:06 +01:00
|
|
|
update_window(hProgressWnd);
|
|
|
|
ok(erased, "Progress bar should have erased the background\n");
|
2018-02-28 06:57:53 +01:00
|
|
|
|
|
|
|
DestroyWindow(hProgressWnd);
|
2005-08-23 12:02:25 +02:00
|
|
|
}
|
|
|
|
|
2013-05-25 18:12:12 +02:00
|
|
|
static void test_setcolors(void)
|
|
|
|
{
|
|
|
|
HWND progress;
|
|
|
|
COLORREF clr;
|
|
|
|
|
|
|
|
progress = create_progress(PBS_SMOOTH);
|
|
|
|
|
|
|
|
clr = SendMessageA(progress, PBM_SETBARCOLOR, 0, 0);
|
|
|
|
ok(clr == CLR_DEFAULT, "got %x\n", clr);
|
|
|
|
|
|
|
|
clr = SendMessageA(progress, PBM_SETBARCOLOR, 0, RGB(0, 255, 0));
|
|
|
|
ok(clr == 0, "got %x\n", clr);
|
|
|
|
|
|
|
|
clr = SendMessageA(progress, PBM_SETBARCOLOR, 0, CLR_DEFAULT);
|
|
|
|
ok(clr == RGB(0, 255, 0), "got %x\n", clr);
|
|
|
|
|
|
|
|
clr = SendMessageA(progress, PBM_SETBKCOLOR, 0, 0);
|
|
|
|
ok(clr == CLR_DEFAULT, "got %x\n", clr);
|
|
|
|
|
|
|
|
clr = SendMessageA(progress, PBM_SETBKCOLOR, 0, RGB(255, 0, 0));
|
|
|
|
ok(clr == 0, "got %x\n", clr);
|
|
|
|
|
|
|
|
clr = SendMessageA(progress, PBM_SETBKCOLOR, 0, CLR_DEFAULT);
|
|
|
|
ok(clr == RGB(255, 0, 0), "got %x\n", clr);
|
|
|
|
|
|
|
|
DestroyWindow(progress);
|
|
|
|
}
|
2005-08-23 12:02:25 +02:00
|
|
|
|
2018-02-27 11:43:13 +01:00
|
|
|
static void test_PBM_STEPIT(void)
|
|
|
|
{
|
|
|
|
struct stepit_test
|
|
|
|
{
|
|
|
|
int min;
|
|
|
|
int max;
|
|
|
|
int step;
|
|
|
|
} stepit_tests[] =
|
|
|
|
{
|
|
|
|
{ 3, 15, 5 },
|
|
|
|
{ 3, 15, -5 },
|
|
|
|
{ 3, 15, 50 },
|
2019-01-23 06:25:42 +01:00
|
|
|
{ -15, 15, 5 },
|
|
|
|
{ -3, -2, -5 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 5, 5, 1 },
|
|
|
|
{ 0, 0, -1 },
|
|
|
|
{ 5, 5, -1 },
|
|
|
|
{ 10, 5, 2 },
|
2018-02-27 11:43:13 +01:00
|
|
|
};
|
|
|
|
HWND progress;
|
|
|
|
int i, j;
|
|
|
|
|
2018-06-06 20:36:15 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(stepit_tests); i++)
|
2018-02-27 11:43:13 +01:00
|
|
|
{
|
|
|
|
struct stepit_test *test = &stepit_tests[i];
|
2019-01-23 06:25:42 +01:00
|
|
|
PBRANGE range;
|
2018-02-27 11:43:13 +01:00
|
|
|
LRESULT ret;
|
|
|
|
|
|
|
|
progress = create_progress(0);
|
|
|
|
|
|
|
|
ret = SendMessageA(progress, PBM_SETRANGE32, test->min, test->max);
|
|
|
|
ok(ret != 0, "Unexpected return value.\n");
|
|
|
|
|
2019-01-23 06:25:42 +01:00
|
|
|
SendMessageA(progress, PBM_GETRANGE, 0, (LPARAM)&range);
|
|
|
|
ok(range.iLow == test->min && range.iHigh == test->max, "Unexpected range.\n");
|
|
|
|
|
2018-02-27 11:43:13 +01:00
|
|
|
SendMessageA(progress, PBM_SETPOS, test->min, 0);
|
|
|
|
SendMessageA(progress, PBM_SETSTEP, test->step, 0);
|
|
|
|
|
|
|
|
for (j = 0; j < test->max; j++)
|
|
|
|
{
|
|
|
|
int pos = SendMessageA(progress, PBM_GETPOS, 0, 0);
|
|
|
|
int current;
|
|
|
|
|
|
|
|
pos += test->step;
|
2019-01-23 06:25:42 +01:00
|
|
|
if (test->min != test->max)
|
|
|
|
{
|
|
|
|
if (pos > test->max)
|
|
|
|
pos = (pos - test->min) % (test->max - test->min) + test->min;
|
|
|
|
if (pos < test->min)
|
|
|
|
pos = (pos - test->min) % (test->max - test->min) + test->max;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pos = test->min;
|
2018-02-27 11:43:13 +01:00
|
|
|
|
|
|
|
SendMessageA(progress, PBM_STEPIT, 0, 0);
|
|
|
|
|
|
|
|
current = SendMessageA(progress, PBM_GETPOS, 0, 0);
|
2019-01-23 06:25:42 +01:00
|
|
|
ok(current == pos, "%u: unexpected position %d, expected %d.\n", i, current, pos);
|
2018-02-27 11:43:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(progress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:47:09 +01:00
|
|
|
static void init_functions(void)
|
|
|
|
{
|
|
|
|
HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
|
|
|
|
|
|
|
|
#define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
|
|
|
|
X(InitCommonControlsEx);
|
|
|
|
#undef X
|
|
|
|
}
|
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
START_TEST(progress)
|
|
|
|
{
|
2018-01-24 13:47:09 +01:00
|
|
|
INITCOMMONCONTROLSEX iccex;
|
2018-02-28 06:57:53 +01:00
|
|
|
ULONG_PTR ctx_cookie;
|
|
|
|
HANDLE hCtx;
|
2018-01-24 13:47:09 +01:00
|
|
|
|
|
|
|
init_functions();
|
|
|
|
|
|
|
|
iccex.dwSize = sizeof(iccex);
|
|
|
|
iccex.dwICC = ICC_PROGRESS_CLASS;
|
|
|
|
pInitCommonControlsEx(&iccex);
|
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
init();
|
2018-02-28 06:57:53 +01:00
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
test_redraw();
|
2013-05-25 18:12:12 +02:00
|
|
|
test_setcolors();
|
2018-02-27 11:43:13 +01:00
|
|
|
test_PBM_STEPIT();
|
2013-05-25 18:12:12 +02:00
|
|
|
|
2018-02-28 06:57:53 +01:00
|
|
|
if (!load_v6_module(&ctx_cookie, &hCtx))
|
|
|
|
return;
|
|
|
|
|
|
|
|
test_setcolors();
|
|
|
|
test_PBM_STEPIT();
|
|
|
|
|
|
|
|
unload_v6_module(ctx_cookie, hCtx);
|
|
|
|
|
2005-08-23 12:02:25 +02:00
|
|
|
cleanup();
|
|
|
|
}
|