From e976877fa5de037afbd74b7383448072bb036969 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Wed, 18 Jun 2008 18:52:33 +0900 Subject: [PATCH] gdi32: Add a test for combined mapping mode/world transform changes. --- dlls/gdi32/tests/mapping.c | 145 ++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 2 deletions(-) diff --git a/dlls/gdi32/tests/mapping.c b/dlls/gdi32/tests/mapping.c index 91e487a6468..210f78341b8 100644 --- a/dlls/gdi32/tests/mapping.c +++ b/dlls/gdi32/tests/mapping.c @@ -2,6 +2,7 @@ * Unit tests for mapping functions * * Copyright (c) 2005 Huw Davies + * Copyright (c) 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 @@ -28,6 +29,146 @@ #include "winuser.h" #include "winerror.h" +#define rough_match(got, expected) (abs((got) - (expected)) <= 5) + +#define expect_LPtoDP(_hdc, _x, _y) \ +{ \ + POINT _pt = { 1000, 1000 }; \ + LPtoDP(_hdc, &_pt, 1); \ + ok(rough_match(_pt.x, _x), "expected x %d, got %d\n", (_x), _pt.x); \ + ok(rough_match(_pt.y, _y), "expected y %d, got %d\n", (_y), _pt.y); \ +} + +#define expect_world_trasform(_hdc, _em11, _em22) \ +{ \ + BOOL _ret; \ + XFORM _xform; \ + SetLastError(0xdeadbeef); \ + _ret = GetWorldTransform(_hdc, &_xform); \ + if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) \ + { \ + ok(_ret, "GetWorldTransform error %u\n", GetLastError()); \ + ok(_xform.eM11 == (_em11), "expected %f, got %f\n", (_em11), _xform.eM11); \ + ok(_xform.eM12 == 0.0, "expected 0.0, got %f\n", _xform.eM12); \ + ok(_xform.eM21 == 0.0, "expected 0.0, got %f\n", _xform.eM21); \ + ok(_xform.eM22 == (_em22), "expected %f, got %f\n", (_em22), _xform.eM22); \ + ok(_xform.eDx == 0.0, "expected 0.0, got %f\n", _xform.eDx); \ + ok(_xform.eDy == 0.0, "expected 0.0, got %f\n", _xform.eDy); \ + } \ +} + +#define expect_dc_ext(_func, _hdc, _cx, _cy) \ +{ \ + BOOL _ret; \ + SIZE _size; \ + SetLastError(0xdeadbeef); \ + _ret = _func(_hdc, &_size); \ + ok(_ret, #_func " error %u\n", GetLastError()); \ + ok(_size.cx == (_cx), "expected cx %d, got %d\n", (_cx), _size.cx); \ + ok(_size.cy == (_cy), "expected cy %d, got %d\n", (_cy), _size.cy); \ +} + +#define expect_viewport_ext(_hdc, _cx, _cy) expect_dc_ext(GetViewportExtEx, _hdc, _cx, _cy) +#define expect_window_ext(_hdc, _cx, _cy) expect_dc_ext(GetWindowExtEx, _hdc, _cx, _cy) + +static void test_world_transform(void) +{ + BOOL is_win9x; + HDC hdc; + INT ret, size_cx, size_cy, res_x, res_y; + XFORM xform; + + SetLastError(0xdeadbeef); + GetWorldTransform(0, NULL); + is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED; + + hdc = CreateCompatibleDC(0); + + size_cx = GetDeviceCaps(hdc, HORZSIZE); + size_cy = GetDeviceCaps(hdc, VERTSIZE); + res_x = GetDeviceCaps(hdc, HORZRES); + res_y = GetDeviceCaps(hdc, VERTRES); + trace("dc size %d x %d, resolution %d x %d\n", size_cx, size_cy, res_x, res_y); + + expect_viewport_ext(hdc, 1, 1); + expect_window_ext(hdc, 1, 1); + expect_world_trasform(hdc, 1.0, 1.0); + expect_LPtoDP(hdc, 1000, 1000); + + SetLastError(0xdeadbeef); + ret = SetMapMode(hdc, MM_LOMETRIC); + ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret); + + if (is_win9x) + { + expect_viewport_ext(hdc, 96, 96); + expect_window_ext(hdc, 254, -254); + } + else + { + expect_viewport_ext(hdc, res_x, -res_y); + expect_window_ext(hdc, size_cx * 10, size_cy * 10); + } + expect_world_trasform(hdc, 1.0, 1.0); + expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy)); + + SetLastError(0xdeadbeef); + ret = SetMapMode(hdc, MM_TEXT); + ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret); + + expect_viewport_ext(hdc, 1, 1); + expect_window_ext(hdc, 1, 1); + expect_world_trasform(hdc, 1.0, 1.0); + expect_LPtoDP(hdc, 1000, 1000); + + ret = SetGraphicsMode(hdc, GM_ADVANCED); + if (!ret) + { + DeleteDC(hdc); + skip("GM_ADVANCED is not supported on this platform\n"); + return; + } + + expect_viewport_ext(hdc, 1, 1); + expect_window_ext(hdc, 1, 1); + expect_world_trasform(hdc, 1.0, 1.0); + expect_LPtoDP(hdc, 1000, 1000); + + xform.eM11 = 20.0f; + xform.eM12 = 0.0f; + xform.eM21 = 0.0f; + xform.eM22 = 20.0f; + xform.eDx = 0.0f; + xform.eDy = 0.0f; + SetLastError(0xdeadbeef); + ret = SetWorldTransform(hdc, &xform); + ok(ret, "SetWorldTransform error %u\n", GetLastError()); + + expect_viewport_ext(hdc, 1, 1); + expect_window_ext(hdc, 1, 1); + expect_world_trasform(hdc, 20.0, 20.0); + expect_LPtoDP(hdc, 20000, 20000); + + SetLastError(0xdeadbeef); + ret = SetMapMode(hdc, MM_LOMETRIC); + ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret); + + expect_viewport_ext(hdc, res_x, -res_y); + expect_window_ext(hdc, size_cx * 10, size_cy * 10); + expect_world_trasform(hdc, 20.0, 20.0); + expect_LPtoDP(hdc, MulDiv(1000 * 2, res_x, size_cx), -MulDiv(1000 * 2, res_y, size_cy)); + + SetLastError(0xdeadbeef); + ret = SetMapMode(hdc, MM_TEXT); + ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret); + + expect_viewport_ext(hdc, 1, 1); + expect_window_ext(hdc, 1, 1); + expect_world_trasform(hdc, 20.0, 20.0); + expect_LPtoDP(hdc, 20000, 20000); + + DeleteDC(hdc); +} static void test_modify_world_transform(void) { @@ -38,6 +179,7 @@ static void test_modify_world_transform(void) if(!ret) /* running in win9x so quit */ { ReleaseDC(0, hdc); + skip("GM_ADVANCED is not supported on this platform\n"); return; } @@ -53,8 +195,6 @@ static void test_modify_world_transform(void) ReleaseDC(0, hdc); } -#define rough_match(got, expected) ((got >= expected - 2) && (got <= expected + 2)) - static void test_SetWindowExt(HDC hdc, LONG cx, LONG cy, LONG expected_vp_cx, LONG expected_vp_cy) { SIZE windowExt, viewportExt; @@ -158,5 +298,6 @@ static void test_isotropic_mapping(void) START_TEST(mapping) { test_modify_world_transform(); + test_world_transform(); test_isotropic_mapping(); }