1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for ScrollWindowEx
5  * PROGRAMMERS:     Timo Kreuzer
6  *                  Katayama Hirofumi MZ
7  */
8 
9 #include "precomp.h"
10 
11 void
12 Test_ScrollWindowEx()
13 {
14     HWND hWnd, hChild1, hChild2;
15     HRGN hrgn;
16     int Result;
17     RECT rc, rcChild1, rcChild2;
18     INT x1, y1, x2, y2, dx, dy;
19     DWORD style;
20 
21     /* Create a window */
22     style = WS_POPUP | SS_WHITERECT | WS_VISIBLE;
23     hWnd = CreateWindowW(L"STATIC", L"TestWindow", style, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL, 0, 0);
24     ok(hWnd != NULL, "hWnd was NULL.\n");
25     UpdateWindow(hWnd);
26 
27     /* Assert that no update region is there */
28     hrgn = CreateRectRgn(0, 0, 0, 0);
29     Result = GetUpdateRgn(hWnd, hrgn, FALSE);
30     ok(Result == NULLREGION, "Result = %d\n", Result);
31 
32     Result = ScrollWindowEx(hWnd, 20, 0, NULL, NULL, NULL, NULL, 0);
33     ok(Result == SIMPLEREGION, "Result = %d\n", Result);
34     Result = GetUpdateRgn(hWnd, hrgn, FALSE);
35     ok(Result == NULLREGION, "Result = %d\n", Result);
36 
37     Result = ScrollWindowEx(hWnd, 20, 0, NULL, NULL, NULL, NULL, SW_INVALIDATE);
38     ok(Result == SIMPLEREGION, "Result = %d\n", Result);
39     Result = GetUpdateRgn(hWnd, hrgn, FALSE);
40     ok(Result == SIMPLEREGION, "Result = %d\n", Result);
41     UpdateWindow(hWnd);
42 
43     // test invalid update region
44     DeleteObject(hrgn);
45     Result = ScrollWindowEx(hWnd, 20, 0, NULL, NULL, hrgn, NULL, SW_INVALIDATE);
46     ok(Result == ERROR, "Result = %d\n", Result);
47     hrgn = CreateRectRgn(0, 0, 0, 0);
48     UpdateWindow(hWnd);
49 
50     // Test invalid updaterect pointer
51     Result = ScrollWindowEx(hWnd, 20, 0, NULL, NULL, NULL, (LPRECT)1, SW_INVALIDATE);
52     ok(Result == ERROR, "Result = %d\n", Result);
53     Result = GetUpdateRgn(hWnd, hrgn, FALSE);
54     ok(Result == SIMPLEREGION, "Result = %d\n", Result);
55 
56     /* create child window 1 */
57     x1 = 1;
58     y1 = 3;
59     style = WS_CHILD | WS_VISIBLE | SS_BLACKRECT;
60     hChild1 = CreateWindowW(L"STATIC", L"Child1", style, x1, y1, 10, 10, hWnd, NULL, 0, 0);
61     ok(hChild1 != NULL, "hChild1 was NULL.\n");
62     UpdateWindow(hChild1);
63 
64     /* create child window 2 */
65     x2 = 5;
66     y2 = 7;
67     style = WS_CHILD | WS_VISIBLE | SS_WHITERECT;
68     hChild2 = CreateWindowW(L"STATIC", L"Child2", style, x2, y2, 10, 10, hWnd, NULL, 0, 0);
69     ok(hChild2 != NULL, "hChild2 was NULL.\n");
70     UpdateWindow(hChild2);
71 
72     /* scroll with child windows */
73     dx = 3;
74     dy = 8;
75     ScrollWindowEx(hWnd, dx, dy, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
76     UpdateWindow(hWnd);
77 
78     /* check the positions */
79     GetWindowRect(hWnd, &rc);
80     GetWindowRect(hChild1, &rcChild1);
81     GetWindowRect(hChild2, &rcChild2);
82     ok_long(rcChild1.left - rc.left, x1 + dx);
83     ok_long(rcChild2.left - rc.left, x2 + dx);
84     ok_long(rcChild1.top - rc.top, y1 + dy);
85     ok_long(rcChild2.top - rc.top, y2 + dy);
86 
87     /* update */
88     x1 += dx;
89     y1 += dy;
90     x2 += dx;
91     y2 += dy;
92 
93     /* scroll with child windows */
94     dx = 9;
95     dy = -2;
96     ScrollWindowEx(hWnd, dx, dy, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
97     UpdateWindow(hWnd);
98 
99     /* check the positions */
100     GetWindowRect(hWnd, &rc);
101     GetWindowRect(hChild1, &rcChild1);
102     GetWindowRect(hChild2, &rcChild2);
103     ok_long(rcChild1.left - rc.left, x1 + dx);
104     ok_long(rcChild2.left - rc.left, x2 + dx);
105     ok_long(rcChild1.top - rc.top, y1 + dy);
106     ok_long(rcChild2.top - rc.top, y2 + dy);
107 
108     DestroyWindow(hChild1);
109     DestroyWindow(hChild2);
110     DeleteObject(hrgn);
111     DestroyWindow(hWnd);
112 }
113 
114 START_TEST(ScrollWindowEx)
115 {
116     Test_ScrollWindowEx();
117 }
118