user32: Add a test for monitor work area, fix some failures
Dmitry Timoshkov
dmitry at codeweavers.com
Tue Aug 19 06:12:42 CDT 2008
Hello,
this test passes under Win98 and XP SP3.
Changelog:
user32: Add a test for monitor work area, fix some failures.
---
dlls/user32/tests/monitor.c | 187 +++++++++++++++++++++++++++++++++++++++---
dlls/user32/winpos.c | 6 +-
dlls/winex11.drv/xinerama.c | 6 +-
3 files changed, 181 insertions(+), 18 deletions(-)
diff --git a/dlls/user32/tests/monitor.c b/dlls/user32/tests/monitor.c
index 0de9bff..1b2faa5 100644
--- a/dlls/user32/tests/monitor.c
+++ b/dlls/user32/tests/monitor.c
@@ -2,6 +2,7 @@
* Unit tests for monitor APIs
*
* Copyright 2005 Huw Davies
+ * Copyright 2008 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -52,6 +53,22 @@ static void init_function_pointers(void)
#undef GET_PROC
}
+static void flush_events( BOOL remove_messages )
+{
+ MSG msg;
+ int diff = 200;
+ int min_timeout = 50;
+ DWORD time = GetTickCount() + diff;
+
+ while (diff > 0)
+ {
+ if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
+ if (remove_messages)
+ while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
+ diff = time - GetTickCount();
+ }
+}
+
static BOOL CALLBACK monitor_enum_proc(HMONITOR hmon, HDC hdc, LPRECT lprc,
LPARAM lparam)
{
@@ -61,7 +78,7 @@ static BOOL CALLBACK monitor_enum_proc(HMONITOR hmon, HDC hdc, LPRECT lprc,
mi.cbSize = sizeof(mi);
ok(pGetMonitorInfoA(hmon, (MONITORINFO*)&mi), "GetMonitorInfo failed\n");
- if(mi.dwFlags == MONITORINFOF_PRIMARY)
+ if (mi.dwFlags & MONITORINFOF_PRIMARY)
strcpy(primary, mi.szDevice);
return TRUE;
@@ -73,9 +90,15 @@ static void test_enumdisplaydevices(void)
char primary_device_name[32];
char primary_monitor_device_name[32];
DWORD primary_num = -1, num = 0;
+ BOOL ret;
+
+ if (!pEnumDisplayDevicesA)
+ {
+ skip("EnumDisplayDevicesA is not available\n");
+ return;
+ }
dd.cb = sizeof(dd);
- if(pEnumDisplayDevicesA == NULL) return;
while(1)
{
BOOL ret;
@@ -99,14 +122,18 @@ static void test_enumdisplaydevices(void)
}
ok(primary_num != -1, "Didn't get the primary device\n");
- if(pEnumDisplayMonitors && pGetMonitorInfoA) {
- ok(pEnumDisplayMonitors(NULL, NULL, monitor_enum_proc, (LPARAM)primary_monitor_device_name),
- "EnumDisplayMonitors failed\n");
-
- ok(!strcmp(primary_monitor_device_name, primary_device_name),
- "monitor device name %s, device name %s\n", primary_monitor_device_name,
- primary_device_name);
+ if (!pEnumDisplayMonitors || !pGetMonitorInfoA)
+ {
+ skip("EnumDisplayMonitors or GetMonitorInfoA are not available\n");
+ return;
}
+
+ primary_monitor_device_name[0] = 0;
+ ret = pEnumDisplayMonitors(NULL, NULL, monitor_enum_proc, (LPARAM)primary_monitor_device_name);
+ ok(ret, "EnumDisplayMonitors failed\n");
+ ok(!strcmp(primary_monitor_device_name, primary_device_name),
+ "monitor device name %s, device name %s\n", primary_monitor_device_name,
+ primary_device_name);
}
struct vid_mode
@@ -267,6 +294,12 @@ static void test_monitors(void)
HMONITOR monitor, primary;
POINT pt;
+ if (!pMonitorFromPoint || !pMonitorFromWindow)
+ {
+ skip("MonitorFromPoint or MonitorFromWindow are not available\n");
+ return;
+ }
+
pt.x = pt.y = 0;
primary = pMonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY );
ok( primary != 0, "couldn't get primary monitor\n" );
@@ -279,15 +312,141 @@ static void test_monitors(void)
ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTONEAREST\n", monitor, primary );
}
+static BOOL CALLBACK find_primary_mon(HMONITOR hmon, HDC hdc, LPRECT rc, LPARAM lp)
+{
+ MONITORINFO mi;
+ BOOL ret;
+
+ mi.cbSize = sizeof(mi);
+ ret = pGetMonitorInfoA(hmon, &mi);
+ ok(ret, "GetMonitorInfo failed\n");
+ if (mi.dwFlags & MONITORINFOF_PRIMARY)
+ {
+ *(HMONITOR *)lp = hmon;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void test_work_area(void)
+{
+ HMONITOR hmon;
+ MONITORINFO mi;
+ RECT rc_work, rc_normal, rc_max;
+ HWND hwnd;
+ WINDOWPLACEMENT wp;
+ INT border;
+ BOOL ret;
+
+ if (!pEnumDisplayMonitors || !pGetMonitorInfoA)
+ {
+ skip("EnumDisplayMonitors or GetMonitorInfoA are not available\n");
+ return;
+ }
+
+ hmon = 0;
+ ret = pEnumDisplayMonitors(NULL, NULL, find_primary_mon, (LPARAM)&hmon);
+ ok(!ret && hmon != 0, "Failed to find primary monitor\n");
+
+ mi.cbSize = sizeof(mi);
+ SetLastError(0xdeadbeef);
+ ret = pGetMonitorInfoA(hmon, &mi);
+ ok(ret, "GetMonitorInfo error %u\n", GetLastError());
+ ok(mi.dwFlags & MONITORINFOF_PRIMARY, "not a primary monitor\n");
+
+ SetLastError(0xdeadbeef);
+ ret = SystemParametersInfo(SPI_GETWORKAREA, 0, &rc_work, 0);
+ ok(ret, "SystemParametersInfo error %u\n", GetLastError());
+ trace("work area (%d,%d-%d,%d)\n", rc_work.left, rc_work.top, rc_work.right, rc_work.bottom);
+ ok(EqualRect(&rc_work, &mi.rcWork), "work area is different\n");
+
+ hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD|WS_OVERLAPPEDWINDOW|WS_VISIBLE,100,100,10,10,GetDesktopWindow(),0,0,NULL);
+ ok(hwnd != 0, "CreateWindowEx failed\n");
+ flush_events( TRUE );
+ ret = GetWindowRect(hwnd, &rc_normal);
+ trace("normal (%d,%d-%d,%d)\n", rc_normal.left, rc_normal.top, rc_normal.right, rc_normal.bottom);
+ ShowWindow(hwnd, SW_MAXIMIZE);
+ flush_events( TRUE );
+ ret = GetWindowRect(hwnd, &rc_max);
+ ok(ret, "GetWindowRect failed\n");
+ trace("maximized (%d,%d-%d,%d)\n", rc_max.left, rc_max.top, rc_max.right, rc_max.bottom);
+ border = min(rc_max.left, rc_max.top);
+ InflateRect(&rc_max, border, border);
+todo_wine
+ ok(EqualRect(&rc_work, &rc_max), "maximized/work area is different\n");
+ wp.length = sizeof(wp);
+ ret = GetWindowPlacement(hwnd, &wp);
+ ok(ret, "GetWindowPlacement failed\n");
+ trace("min: %d,%d max %d,%d normal %d,%d-%d,%d\n",
+ wp.ptMinPosition.x, wp.ptMinPosition.y,
+ wp.ptMaxPosition.x, wp.ptMaxPosition.y,
+ wp.rcNormalPosition.left, wp.rcNormalPosition.top,
+ wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
+ ok(wp.ptMinPosition.x == -1, "expected -1, got %d\n", wp.ptMinPosition.x);
+ ok(wp.ptMinPosition.y == -1, "expected -1, got %d\n", wp.ptMinPosition.y);
+ ok(wp.ptMaxPosition.x == -1, "expected -1, got %d\n", wp.ptMaxPosition.x);
+ ok(wp.ptMaxPosition.y == -1, "expected -1, got %d\n", wp.ptMaxPosition.y);
+ OffsetRect(&rc_normal, -rc_work.left, -rc_work.top);
+ ok(EqualRect(&rc_normal, &wp.rcNormalPosition), "normal pos is different\n");
+ DestroyWindow(hwnd);
+
+ hwnd = CreateWindowEx(0, "static", NULL, WS_OVERLAPPEDWINDOW|WS_VISIBLE,100,100,10,10,0,0,0,NULL);
+ ok(hwnd != 0, "CreateWindowEx failed\n");
+ flush_events( TRUE );
+ ret = GetWindowRect(hwnd, &rc_normal);
+ trace("normal (%d,%d-%d,%d)\n", rc_normal.left, rc_normal.top, rc_normal.right, rc_normal.bottom);
+ ShowWindow(hwnd, SW_MAXIMIZE);
+ flush_events( TRUE );
+ ret = GetWindowRect(hwnd, &rc_max);
+ ok(ret, "GetWindowRect failed\n");
+ trace("maximized (%d,%d-%d,%d)\n", rc_max.left, rc_max.top, rc_max.right, rc_max.bottom);
+ border = min(rc_max.left, rc_max.top);
+ InflateRect(&rc_max, border, border);
+todo_wine
+ ok(EqualRect(&rc_work, &rc_max), "maximized/work area is different\n");
+ wp.length = sizeof(wp);
+ ret = GetWindowPlacement(hwnd, &wp);
+ ok(ret, "GetWindowPlacement failed\n");
+ trace("min: %d,%d max %d,%d normal %d,%d-%d,%d\n",
+ wp.ptMinPosition.x, wp.ptMinPosition.y,
+ wp.ptMaxPosition.x, wp.ptMaxPosition.y,
+ wp.rcNormalPosition.left, wp.rcNormalPosition.top,
+ wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
+ OffsetRect(&rc_normal, -rc_work.left, -rc_work.top);
+ ok(EqualRect(&rc_normal, &wp.rcNormalPosition), "normal pos is different\n");
+ DestroyWindow(hwnd);
+
+ hwnd = CreateWindowEx(WS_EX_TOOLWINDOW, "static", NULL, WS_OVERLAPPEDWINDOW|WS_VISIBLE,100,100,10,10,0,0,0,NULL);
+ ok(hwnd != 0, "CreateWindowEx failed\n");
+ flush_events( TRUE );
+ ret = GetWindowRect(hwnd, &rc_normal);
+ trace("normal (%d,%d-%d,%d)\n", rc_normal.left, rc_normal.top, rc_normal.right, rc_normal.bottom);
+ ShowWindow(hwnd, SW_MAXIMIZE);
+ flush_events( TRUE );
+ ret = GetWindowRect(hwnd, &rc_max);
+ ok(ret, "GetWindowRect failed\n");
+ trace("maximized (%d,%d-%d,%d)\n", rc_max.left, rc_max.top, rc_max.right, rc_max.bottom);
+ border = min(rc_max.left, rc_max.top);
+ InflateRect(&rc_max, border, border);
+todo_wine
+ ok(EqualRect(&rc_work, &rc_max), "maximized/work area is different\n");
+ wp.length = sizeof(wp);
+ ret = GetWindowPlacement(hwnd, &wp);
+ ok(ret, "GetWindowPlacement failed\n");
+ trace("min: %d,%d max %d,%d normal %d,%d-%d,%d\n",
+ wp.ptMinPosition.x, wp.ptMinPosition.y,
+ wp.ptMaxPosition.x, wp.ptMaxPosition.y,
+ wp.rcNormalPosition.left, wp.rcNormalPosition.top,
+ wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
+ ok(EqualRect(&rc_normal, &wp.rcNormalPosition), "normal pos is different\n");
+ DestroyWindow(hwnd);
+}
START_TEST(monitor)
{
init_function_pointers();
test_enumdisplaydevices();
test_ChangeDisplaySettingsEx();
-
- if (pMonitorFromPoint && pMonitorFromWindow)
- test_monitors();
- else
- skip("MonitorFromPoint and/or MonitorFromWindow are not available\n");
+ test_monitors();
+ test_work_area();
}
diff --git a/dlls/user32/winpos.c b/dlls/user32/winpos.c
index 2bbaab9..dc1ea24 100644
--- a/dlls/user32/winpos.c
+++ b/dlls/user32/winpos.c
@@ -1211,8 +1211,10 @@ BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
wndpl->flags = WPF_RESTORETOMAXIMIZED;
else
wndpl->flags = 0;
- wndpl->ptMinPosition = pWnd->min_pos;
- wndpl->ptMaxPosition = pWnd->max_pos;
+ wndpl->ptMinPosition.x = -1;
+ wndpl->ptMinPosition.y = -1;
+ wndpl->ptMaxPosition.x = -1;
+ wndpl->ptMaxPosition.y = -1;
wndpl->rcNormalPosition = pWnd->normal_rect;
WIN_ReleasePtr( pWnd );
diff --git a/dlls/winex11.drv/xinerama.c b/dlls/winex11.drv/xinerama.c
index ee735e6..f68cf2a 100644
--- a/dlls/winex11.drv/xinerama.c
+++ b/dlls/winex11.drv/xinerama.c
@@ -218,7 +218,8 @@ BOOL X11DRV_EnumDisplayMonitors( HDC hdc, LPRECT rect, MONITORENUMPROC proc, LPA
RECT monrect = monitors[i].rcMonitor;
OffsetRect( &monrect, -origin.x, -origin.y );
if (IntersectRect( &monrect, &monrect, &limit ))
- if (!proc( index_to_monitor(i), hdc, &monrect, lp )) break;
+ if (!proc( index_to_monitor(i), hdc, &monrect, lp ))
+ return FALSE;
}
}
else
@@ -227,7 +228,8 @@ BOOL X11DRV_EnumDisplayMonitors( HDC hdc, LPRECT rect, MONITORENUMPROC proc, LPA
{
RECT unused;
if (!rect || IntersectRect( &unused, &monitors[i].rcMonitor, rect ))
- if (!proc( index_to_monitor(i), 0, &monitors[i].rcMonitor, lp )) break;
+ if (!proc( index_to_monitor(i), 0, &monitors[i].rcMonitor, lp ))
+ return FALSE;
}
}
return TRUE;
--
1.5.6.4
More information about the wine-patches
mailing list