2005-09-28 12:17:13 +02:00
|
|
|
/*
|
|
|
|
* Unit tests for monitor APIs
|
|
|
|
*
|
|
|
|
* Copyright 2005 Huw Davies
|
|
|
|
*
|
|
|
|
* 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-09-28 12:17:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
|
2005-10-11 22:27:27 +02:00
|
|
|
static HMODULE hdll;
|
2005-11-17 12:04:01 +01:00
|
|
|
static BOOL (WINAPI *pEnumDisplayDevicesA)(LPCSTR,DWORD,LPDISPLAY_DEVICEA,DWORD);
|
2005-10-11 22:27:27 +02:00
|
|
|
static BOOL (WINAPI *pEnumDisplayMonitors)(HDC,LPRECT,MONITORENUMPROC,LPARAM);
|
|
|
|
static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
|
2006-12-17 13:10:03 +01:00
|
|
|
static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
|
|
|
|
static HMONITOR (WINAPI *pMonitorFromWindow)(HWND,DWORD);
|
2005-10-11 22:27:27 +02:00
|
|
|
|
|
|
|
static void init_function_pointers(void)
|
|
|
|
{
|
|
|
|
hdll = GetModuleHandleA("user32.dll");
|
2007-03-28 10:00:28 +02:00
|
|
|
pEnumDisplayDevicesA = (void*)GetProcAddress(hdll, "EnumDisplayDevicesA");
|
|
|
|
pEnumDisplayMonitors = (void*)GetProcAddress(hdll, "EnumDisplayMonitors");
|
|
|
|
pGetMonitorInfoA = (void*)GetProcAddress(hdll, "GetMonitorInfoA");
|
|
|
|
pMonitorFromPoint = (void*)GetProcAddress(hdll, "MonitorFromPoint");
|
|
|
|
pMonitorFromWindow = (void*)GetProcAddress(hdll, "MonitorFromWindow");
|
2005-10-11 22:27:27 +02:00
|
|
|
}
|
|
|
|
|
2005-09-28 12:17:13 +02:00
|
|
|
static BOOL CALLBACK monitor_enum_proc(HMONITOR hmon, HDC hdc, LPRECT lprc,
|
|
|
|
LPARAM lparam)
|
|
|
|
{
|
|
|
|
MONITORINFOEXA mi;
|
|
|
|
char *primary = (char *)lparam;
|
|
|
|
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
|
2005-10-11 22:27:27 +02:00
|
|
|
ok(pGetMonitorInfoA(hmon, (MONITORINFO*)&mi), "GetMonitorInfo failed\n");
|
2005-09-28 12:17:13 +02:00
|
|
|
if(mi.dwFlags == MONITORINFOF_PRIMARY)
|
|
|
|
strcpy(primary, mi.szDevice);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_enumdisplaydevices(void)
|
|
|
|
{
|
|
|
|
DISPLAY_DEVICEA dd;
|
|
|
|
char primary_device_name[32];
|
|
|
|
char primary_monitor_device_name[32];
|
|
|
|
DWORD primary_num = -1, num = 0;
|
|
|
|
|
|
|
|
dd.cb = sizeof(dd);
|
2005-11-17 12:04:01 +01:00
|
|
|
if(pEnumDisplayDevicesA == NULL) return;
|
2005-09-28 12:17:13 +02:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
2006-01-03 12:05:54 +01:00
|
|
|
HDC dc;
|
2005-11-17 12:04:01 +01:00
|
|
|
ret = pEnumDisplayDevicesA(NULL, num, &dd, 0);
|
2005-09-28 12:17:13 +02:00
|
|
|
ok(ret || num != 0, "EnumDisplayDevices fails with num == 0\n");
|
|
|
|
if(!ret) break;
|
|
|
|
if(dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
|
|
|
{
|
|
|
|
strcpy(primary_device_name, dd.DeviceName);
|
|
|
|
primary_num = num;
|
|
|
|
}
|
2006-01-03 12:05:54 +01:00
|
|
|
if(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
|
|
|
|
{
|
|
|
|
/* test creating DC */
|
|
|
|
dc = CreateDCA(dd.DeviceName, NULL, NULL, NULL);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(dc != NULL, "Failed to CreateDC(\"%s\") err=%d\n", dd.DeviceName, GetLastError());
|
2006-01-03 12:05:54 +01:00
|
|
|
DeleteDC(dc);
|
|
|
|
}
|
2005-09-28 12:17:13 +02:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
ok(primary_num != -1, "Didn't get the primary device\n");
|
|
|
|
|
2005-10-11 22:27:27 +02:00
|
|
|
if(pEnumDisplayMonitors && pGetMonitorInfoA) {
|
|
|
|
ok(pEnumDisplayMonitors(NULL, NULL, monitor_enum_proc, (LPARAM)primary_monitor_device_name),
|
|
|
|
"EnumDisplayMonitors failed\n");
|
2005-09-28 12:17:13 +02:00
|
|
|
|
2005-10-11 22:27:27 +02:00
|
|
|
ok(!strcmp(primary_monitor_device_name, primary_device_name),
|
|
|
|
"monitor device name %s, device name %s\n", primary_monitor_device_name,
|
|
|
|
primary_device_name);
|
|
|
|
}
|
2005-09-28 12:17:13 +02:00
|
|
|
}
|
|
|
|
|
2006-07-26 07:31:22 +02:00
|
|
|
struct vid_mode
|
|
|
|
{
|
|
|
|
DWORD w, h, bpp, freq, fields;
|
2007-02-22 12:43:06 +01:00
|
|
|
LONG success;
|
2006-07-26 07:31:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct vid_mode vid_modes_test[] = {
|
2007-02-22 12:43:06 +01:00
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY, 1},
|
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY, 1},
|
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL , 1},
|
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT , 1},
|
|
|
|
{640, 480, 0, 0, DM_BITSPERPEL , 1},
|
|
|
|
{640, 480, 0, 0, DM_DISPLAYFREQUENCY, 1},
|
|
|
|
|
|
|
|
{0, 0, 0, 0, DM_PELSWIDTH, 1},
|
|
|
|
{0, 0, 0, 0, DM_PELSHEIGHT, 1},
|
|
|
|
|
|
|
|
{640, 480, 0, 0, DM_PELSWIDTH, 0},
|
|
|
|
{640, 480, 0, 0, DM_PELSHEIGHT, 0},
|
|
|
|
{ 0, 480, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
|
|
|
|
{640, 0, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
|
|
|
|
|
|
|
|
{0, 0, 0, 0, DM_DISPLAYFREQUENCY, 0},
|
2006-07-26 07:31:22 +02:00
|
|
|
};
|
|
|
|
#define vid_modes_cnt (sizeof(vid_modes_test) / sizeof(vid_modes_test[0]))
|
|
|
|
|
|
|
|
static void test_ChangeDisplaySettingsEx(void)
|
|
|
|
{
|
|
|
|
DEVMODE dm;
|
|
|
|
LONG res;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset(&dm, 0, sizeof(dm));
|
|
|
|
dm.dmSize = sizeof(dm);
|
|
|
|
|
|
|
|
for (i = 0; i < vid_modes_cnt; i++)
|
|
|
|
{
|
|
|
|
dm.dmPelsWidth = vid_modes_test[i].w;
|
|
|
|
dm.dmPelsHeight = vid_modes_test[i].h;
|
|
|
|
dm.dmBitsPerPel = vid_modes_test[i].bpp;
|
|
|
|
dm.dmDisplayFrequency = vid_modes_test[i].freq;
|
|
|
|
dm.dmFields = vid_modes_test[i].fields;
|
|
|
|
res = ChangeDisplaySettingsEx(NULL, &dm, NULL, CDS_FULLSCREEN, NULL);
|
2007-02-22 12:43:06 +01:00
|
|
|
ok(vid_modes_test[i].success ?
|
|
|
|
(res == DISP_CHANGE_SUCCESSFUL) :
|
|
|
|
(res == DISP_CHANGE_BADMODE || res == DISP_CHANGE_BADPARAM),
|
|
|
|
"Unexpected ChangeDisplaySettingsEx() return code for resolution[%d]: %d\n", i, res);
|
2006-12-14 18:33:51 +01:00
|
|
|
|
|
|
|
if (res == DISP_CHANGE_SUCCESSFUL)
|
|
|
|
{
|
|
|
|
RECT r, r1, virt;
|
|
|
|
|
|
|
|
SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
|
|
|
|
OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
|
|
|
|
|
|
|
|
/* Resolution change resets clip rect */
|
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
|
|
|
ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
|
|
|
|
|
|
|
ok(ClipCursor(NULL), "ClipCursor() failed\n");
|
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
|
|
|
ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
|
|
|
|
|
|
|
/* This should always work. Primary monitor is at (0,0) */
|
|
|
|
SetRect(&r1, 10, 10, 20, 20);
|
|
|
|
ok(ClipCursor(&r1), "ClipCursor() failed\n");
|
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
|
|
|
ok(EqualRect(&r, &r1), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
|
|
|
|
|
|
|
SetRect(&r1, virt.left - 10, virt.top - 10, virt.right + 20, virt.bottom + 20);
|
|
|
|
ok(ClipCursor(&r1), "ClipCursor() failed\n");
|
|
|
|
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
|
|
|
|
ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n", r.left, r.top, r.right, r.bottom);
|
|
|
|
}
|
2006-07-26 07:31:22 +02:00
|
|
|
}
|
|
|
|
res = ChangeDisplaySettingsEx(NULL, NULL, NULL, CDS_RESET, NULL);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(res == DISP_CHANGE_SUCCESSFUL, "Failed to reset default resolution: %d\n", res);
|
2006-07-26 07:31:22 +02:00
|
|
|
}
|
|
|
|
|
2006-10-23 18:03:16 +02:00
|
|
|
static void test_monitors(void)
|
|
|
|
{
|
|
|
|
HMONITOR monitor, primary;
|
|
|
|
POINT pt;
|
|
|
|
|
|
|
|
pt.x = pt.y = 0;
|
2006-12-17 13:10:03 +01:00
|
|
|
primary = pMonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY );
|
2006-10-23 18:03:16 +02:00
|
|
|
ok( primary != 0, "couldn't get primary monitor\n" );
|
|
|
|
|
2006-12-17 13:10:03 +01:00
|
|
|
monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTONULL );
|
2006-10-23 18:03:16 +02:00
|
|
|
ok( !monitor, "got %p, should not get a monitor for an invalid window\n", monitor );
|
2006-12-17 13:10:03 +01:00
|
|
|
monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY );
|
2006-10-23 18:03:16 +02:00
|
|
|
ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTOPRIMARY\n", monitor, primary );
|
2006-12-17 13:10:03 +01:00
|
|
|
monitor = pMonitorFromWindow( 0, MONITOR_DEFAULTTONEAREST );
|
2006-10-23 18:03:16 +02:00
|
|
|
ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTONEAREST\n", monitor, primary );
|
|
|
|
}
|
|
|
|
|
2005-09-28 12:17:13 +02:00
|
|
|
|
|
|
|
START_TEST(monitor)
|
|
|
|
{
|
2005-10-11 22:27:27 +02:00
|
|
|
init_function_pointers();
|
2005-09-28 12:17:13 +02:00
|
|
|
test_enumdisplaydevices();
|
2006-11-10 15:23:39 +01:00
|
|
|
if (winetest_interactive)
|
|
|
|
test_ChangeDisplaySettingsEx();
|
2006-12-17 13:10:03 +01:00
|
|
|
if (pMonitorFromPoint && pMonitorFromWindow)
|
|
|
|
test_monitors();
|
2005-09-28 12:17:13 +02:00
|
|
|
}
|