1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for GetClipBox 5 * PROGRAMMERS: Timo Kreuzer 6 */ 7 8 #include "precomp.h" 9 10 void Test_GetClipBox() 11 { 12 HWND hWnd; 13 HDC hdc; 14 RECT rect; 15 HRGN hrgn, hrgn2; 16 int ret; 17 18 /* Create a window */ 19 hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 20 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, 21 NULL, NULL, 0, 0); 22 ok(hWnd != NULL, "CreateWindowW failed\n"); 23 if (hWnd == NULL) 24 { 25 return; 26 } 27 28 hdc = GetDC(hWnd); 29 30 /* Test invalid DC */ 31 SetLastError(ERROR_SUCCESS); 32 ret = GetClipBox((HDC)0x12345, &rect); 33 ok(ret == ERROR, "Expected ERROR, got %d\n", ret); 34 ok((GetLastError() == 0) || (GetLastError() == ERROR_INVALID_HANDLE), "Expected 0, got %ld\n", GetLastError()); 35 36 //ret = GetClipBox(hdc, &rect); 37 //ok_int(ret, SIMPLEREGION); 38 //ok_rect(&rect, 0, 0, 132, 68); 39 40 /* Create a clip region */ 41 hrgn = CreateRectRgn(5, 7, 50, 50); 42 SelectClipRgn(hdc, hrgn); 43 DeleteObject(hrgn); 44 ret = GetClipBox(hdc, &rect); 45 ok_int(ret, SIMPLEREGION); 46 ok_rect(&rect, 5, 7, 50, 50); 47 48 /* Set clip region as meta region */ 49 SetMetaRgn(hdc); 50 51 /* Create a new clip region */ 52 hrgn = CreateRectRgn(10, 10, 100, 100); 53 SelectClipRgn(hdc, hrgn); 54 DeleteObject(hrgn); 55 ret = GetClipBox(hdc, &rect); 56 ok_int(ret, SIMPLEREGION); 57 ok_rect(&rect, 10, 10, 50, 50); 58 59 /* Create an empty clip region */ 60 hrgn = CreateRectRgn(10, 10, 10, 30); 61 SelectClipRgn(hdc, hrgn); 62 DeleteObject(hrgn); 63 ret = GetClipBox(hdc, &rect); 64 ok_int(ret, NULLREGION); 65 ok_rect(&rect, 0, 0, 0, 0); 66 67 /* Create a complex region */ 68 hrgn = CreateRectRgn(10, 10, 30, 30); 69 hrgn2 = CreateRectRgn(20, 20, 60, 60); 70 ok_int(CombineRgn(hrgn, hrgn, hrgn2, RGN_OR), COMPLEXREGION); 71 SelectClipRgn(hdc, hrgn); 72 DeleteObject(hrgn2); 73 ret = GetClipBox(hdc, &rect); 74 ok_int(ret, COMPLEXREGION); 75 ok_rect(&rect, 10, 10, 50, 50); 76 77 /* Set scaling but keep the mapping mode (viewport should not be changed) */ 78 ok_int(SetViewportExtEx(hdc, 1000, 1000, NULL), 1); 79 ret = GetClipBox(hdc, &rect); 80 ok_int(ret, COMPLEXREGION); 81 ok_rect(&rect, 10, 10, 50, 50); 82 83 /* Set unisotropic mode, ClipBox should be unchanged */ 84 ok_int(SetMapMode(hdc, MM_ANISOTROPIC), 1); 85 ret = GetClipBox(hdc, &rect); 86 ok_int(ret, COMPLEXREGION); 87 ok_rect(&rect, 10, 10, 50, 50); 88 89 /* Now set viewport again */ 90 ok_int(SetViewportExtEx(hdc, 200, 400, NULL), 1); 91 ret = GetClipBox(hdc, &rect); 92 ok_int(ret, COMPLEXREGION); // obviously some special secret feature... 93 ok_rect(&rect, 0, 0, 0, 0); 94 95 /* Reset clip region */ 96 SelectClipRgn(hdc, NULL); 97 SetMetaRgn(hdc); 98 ret = GetClipBox(hdc, &rect); 99 ok_int(ret, SIMPLEREGION); 100 ok_rect(&rect, 0, 0, 0, 0); 101 102 hrgn = CreateRectRgn(10, 10, 190, 190); 103 SelectClipRgn(hdc, hrgn); 104 ret = GetClipBox(hdc, &rect); 105 ok_int(ret, SIMPLEREGION); 106 ok_rect(&rect, 0, 0, 0, 0); 107 108 /* Now also set the window extension */ 109 ok_int(SetWindowExtEx(hdc, 400, 600, NULL), 1); 110 ret = GetClipBox(hdc, &rect); 111 ok_int(ret, SIMPLEREGION); 112 ok_rect(&rect, 20, 15, 100, 75); 113 114 hrgn = CreateRectRgn(30, 30, 300, 300); 115 SelectClipRgn(hdc, hrgn); 116 SetMetaRgn(hdc); 117 ret = GetClipBox(hdc, &rect); 118 ok_int(ret, SIMPLEREGION); 119 ok_rect(&rect, 60, 45, 100, 75); 120 121 ReleaseDC(hWnd, hdc); 122 DestroyWindow(hWnd); 123 } 124 125 START_TEST(GetClipBox) 126 { 127 Test_GetClipBox(); 128 } 129 130