From 5f0608396ca9b3227d9eecede31cf80992313386 Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Mon, 11 May 2020 15:33:38 +0800 Subject: [PATCH] ddraw/tests: Test window position. Signed-off-by: Zhiyi Zhang Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/ddraw/tests/ddraw1.c | 62 +++++++++++++++++++++++++++++++++++++++ dlls/ddraw/tests/ddraw2.c | 62 +++++++++++++++++++++++++++++++++++++++ dlls/ddraw/tests/ddraw4.c | 62 +++++++++++++++++++++++++++++++++++++++ dlls/ddraw/tests/ddraw7.c | 62 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 248 insertions(+) diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c index f74d12d9fda..49223cde289 100644 --- a/dlls/ddraw/tests/ddraw1.c +++ b/dlls/ddraw/tests/ddraw1.c @@ -13633,6 +13633,67 @@ static void test_vtbl_protection(void) DestroyWindow(window); } +static BOOL CALLBACK test_window_position_cb(HMONITOR monitor, HDC hdc, RECT *monitor_rect, + LPARAM lparam) +{ + RECT primary_rect, window_rect; + IDirectDraw *ddraw; + HWND window; + HRESULT hr; + BOOL ret; + + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + window = CreateWindowA("static", "ddraw_test", WS_POPUP | WS_VISIBLE, monitor_rect->left, + monitor_rect->top, monitor_rect->right - monitor_rect->left, + monitor_rect->bottom - monitor_rect->top, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); + flush_events(); + + hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); + ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#x.\n", hr); + flush_events(); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + SetRect(&primary_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + /* Window activation should restore the window to fit the whole primary monitor */ + ret = SetWindowPos(window, 0, monitor_rect->left, monitor_rect->top, 0, 0, + SWP_NOZORDER | SWP_NOSIZE); + ok(ret, "SetWindowPos failed, error %#x.\n", GetLastError()); + ret = SetForegroundWindow(GetDesktopWindow()); + ok(ret, "Failed to set foreground window.\n"); + flush_events(); + ret = ShowWindow(window, SW_RESTORE); + ok(ret, "Failed to restore window, error %#x.\n", GetLastError()); + flush_events(); + ret = SetForegroundWindow(window); + ok(ret, "SetForegroundWindow failed, error %#x.\n", GetLastError()); + flush_events(); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#x.\n", hr); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + DestroyWindow(window); + IDirectDraw_Release(ddraw); + return TRUE; +} + +static void test_window_position(void) +{ + EnumDisplayMonitors(NULL, NULL, test_window_position_cb, 0); +} + START_TEST(ddraw1) { DDDEVICEIDENTIFIER identifier; @@ -13747,4 +13808,5 @@ START_TEST(ddraw1) test_d32_support(); test_cursor_clipping(); test_vtbl_protection(); + test_window_position(); } diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index d4e681c0164..c4549d95e7c 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -14405,6 +14405,67 @@ done: DestroyWindow(window); } +static BOOL CALLBACK test_window_position_cb(HMONITOR monitor, HDC hdc, RECT *monitor_rect, + LPARAM lparam) +{ + RECT primary_rect, window_rect; + IDirectDraw2 *ddraw; + HWND window; + HRESULT hr; + BOOL ret; + + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + window = CreateWindowA("static", "ddraw_test", WS_POPUP | WS_VISIBLE, monitor_rect->left, + monitor_rect->top, monitor_rect->right - monitor_rect->left, + monitor_rect->bottom - monitor_rect->top, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); + flush_events(); + + hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); + ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#x.\n", hr); + flush_events(); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + SetRect(&primary_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + /* Window activation should restore the window to fit the whole primary monitor */ + ret = SetWindowPos(window, 0, monitor_rect->left, monitor_rect->top, 0, 0, + SWP_NOZORDER | SWP_NOSIZE); + ok(ret, "SetWindowPos failed, error %#x.\n", GetLastError()); + ret = SetForegroundWindow(GetDesktopWindow()); + ok(ret, "Failed to set foreground window.\n"); + flush_events(); + ret = ShowWindow(window, SW_RESTORE); + ok(ret, "Failed to restore window, error %#x.\n", GetLastError()); + flush_events(); + ret = SetForegroundWindow(window); + ok(ret, "SetForegroundWindow failed, error %#x.\n", GetLastError()); + flush_events(); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#x.\n", hr); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + DestroyWindow(window); + IDirectDraw2_Release(ddraw); + return TRUE; +} + +static void test_window_position(void) +{ + EnumDisplayMonitors(NULL, NULL, test_window_position_cb, 0); +} + START_TEST(ddraw2) { DDDEVICEIDENTIFIER identifier; @@ -14525,4 +14586,5 @@ START_TEST(ddraw2) test_caps(); test_d32_support(); test_cursor_clipping(); + test_window_position(); } diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index f50fc1cb53b..09fe7e1e92b 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -17432,6 +17432,67 @@ done: DestroyWindow(window); } +static BOOL CALLBACK test_window_position_cb(HMONITOR monitor, HDC hdc, RECT *monitor_rect, + LPARAM lparam) +{ + RECT primary_rect, window_rect; + IDirectDraw4 *ddraw; + HWND window; + HRESULT hr; + BOOL ret; + + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + window = CreateWindowA("static", "ddraw_test", WS_POPUP | WS_VISIBLE, monitor_rect->left, + monitor_rect->top, monitor_rect->right - monitor_rect->left, + monitor_rect->bottom - monitor_rect->top, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); + flush_events(); + + hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); + ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#x.\n", hr); + flush_events(); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + SetRect(&primary_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + /* Window activation should restore the window to fit the whole primary monitor */ + ret = SetWindowPos(window, 0, monitor_rect->left, monitor_rect->top, 0, 0, + SWP_NOZORDER | SWP_NOSIZE); + ok(ret, "SetWindowPos failed, error %#x.\n", GetLastError()); + ret = SetForegroundWindow(GetDesktopWindow()); + ok(ret, "Failed to set foreground window.\n"); + flush_events(); + ret = ShowWindow(window, SW_RESTORE); + ok(ret, "Failed to restore window, error %#x.\n", GetLastError()); + flush_events(); + ret = SetForegroundWindow(window); + ok(ret, "SetForegroundWindow failed, error %#x.\n", GetLastError()); + flush_events(); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#x.\n", hr); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + DestroyWindow(window); + IDirectDraw4_Release(ddraw); + return TRUE; +} + +static void test_window_position(void) +{ + EnumDisplayMonitors(NULL, NULL, test_window_position_cb, 0); +} + START_TEST(ddraw4) { DDDEVICEIDENTIFIER identifier; @@ -17568,4 +17629,5 @@ START_TEST(ddraw4) test_d32_support(); test_surface_format_conversion_alpha(); test_cursor_clipping(); + test_window_position(); } diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index 1ddd3cdb0e2..5cf197998eb 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -17667,6 +17667,67 @@ done: DestroyWindow(window); } +static BOOL CALLBACK test_window_position_cb(HMONITOR monitor, HDC hdc, RECT *monitor_rect, + LPARAM lparam) +{ + RECT primary_rect, window_rect; + IDirectDraw7 *ddraw; + HWND window; + HRESULT hr; + BOOL ret; + + ddraw = create_ddraw(); + ok(!!ddraw, "Failed to create a ddraw object.\n"); + window = CreateWindowA("static", "ddraw_test", WS_POPUP | WS_VISIBLE, monitor_rect->left, + monitor_rect->top, monitor_rect->right - monitor_rect->left, + monitor_rect->bottom - monitor_rect->top, NULL, NULL, NULL, NULL); + ok(!!window, "Failed to create a window.\n"); + flush_events(); + + hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); + ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#x.\n", hr); + flush_events(); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + SetRect(&primary_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + /* Window activation should restore the window to fit the whole primary monitor */ + ret = SetWindowPos(window, 0, monitor_rect->left, monitor_rect->top, 0, 0, + SWP_NOZORDER | SWP_NOSIZE); + ok(ret, "SetWindowPos failed, error %#x.\n", GetLastError()); + ret = SetForegroundWindow(GetDesktopWindow()); + ok(ret, "Failed to set foreground window.\n"); + flush_events(); + ret = ShowWindow(window, SW_RESTORE); + ok(ret, "Failed to restore window, error %#x.\n", GetLastError()); + flush_events(); + ret = SetForegroundWindow(window); + ok(ret, "SetForegroundWindow failed, error %#x.\n", GetLastError()); + flush_events(); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(hr == DD_OK, "SetCooperativeLevel failed, hr %#x.\n", hr); + ret = GetWindowRect(window, &window_rect); + ok(ret, "GetWindowRect failed, error %#x.\n", GetLastError()); + ok(EqualRect(&window_rect, &primary_rect), "Expect window rect %s, got %s.\n", + wine_dbgstr_rect(&primary_rect), wine_dbgstr_rect(&window_rect)); + + DestroyWindow(window); + IDirectDraw7_Release(ddraw); + return TRUE; +} + +static void test_window_position(void) +{ + EnumDisplayMonitors(NULL, NULL, test_window_position_cb, 0); +} + START_TEST(ddraw7) { DDDEVICEIDENTIFIER2 identifier; @@ -17818,4 +17879,5 @@ START_TEST(ddraw7) test_surface_format_conversion_alpha(); test_compressed_surface_stretch(); test_cursor_clipping(); + test_window_position(); }