1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE:         Test for SetScrollInfo
5  * PROGRAMMERS:     Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
START_TEST(SetScrollInfo)10 START_TEST(SetScrollInfo)
11 {
12     struct
13     {
14         int nMin;
15         int nMax;
16         UINT nPage;
17         int nPos;
18         int nMinResult;
19         int nMaxResult;
20         UINT nPageResult;
21         int nPosResult;
22     } tests[] =
23     {
24             /* min max pg  pos          min max pg  pos */
25  /* [0] */  {  0,  0,  0,  0,           0,  0,  0,  0 },
26             {  0,  0,  1,  1,           0,  0,  1,  0 },
27 
28             /* vary nPage only */
29             {  5, 10,  0,  0,           5, 10,  0,  5 },
30             {  5, 10,  1,  0,           5, 10,  1,  5 },
31             {  5, 10,  4,  0,           5, 10,  4,  5 },
32  /* [5] */  {  5, 10,  5,  0,           5, 10,  5,  5 },
33             {  5, 10,  6,  0,           5, 10,  6,  5 },
34             {  5, 10,  7,  0,           5, 10,  6,  5 },
35             {  5, 10, 10,  0,           5, 10,  6,  5 },
36             {  5, 10, 11,  0,           5, 10,  6,  5 },
37  /* [10] */ {  5, 10, 0xffffffff,  0,   5, 10,  6,  5 },
38 
39             /* vary nPos only */
40             {  5, 10,  0,  4,           5, 10,  0,  5 },
41             {  5, 10,  0,  5,           5, 10,  0,  5 },
42             {  5, 10,  0, 10,           5, 10,  0, 10 },
43             {  5, 10,  0, 11,           5, 10,  0, 10 },
44  /* [15] */ {  5, 10,  0, -1,           5, 10,  0,  5 },
45             {  5, 10,  0, 0x80000000,   5, 10,  0,  5 },
46             {  5, 10,  0, 0x7fffffff,   5, 10,  0, 10 },
47 
48             /* maximum nPos depends on nPage */
49             {  5, 10,  0,  9,           5, 10,  0,  9 },
50             {  5, 10,  0, 10,           5, 10,  0, 10 },
51  /* [20] */ {  5, 10,  0, 11,           5, 10,  0, 10 },
52             {  5, 10,  1,  9,           5, 10,  1,  9 },
53             {  5, 10,  1, 10,           5, 10,  1, 10 },
54             {  5, 10,  1, 11,           5, 10,  1, 10 },
55             {  5, 10,  2,  9,           5, 10,  2,  9 },
56  /* [25] */ {  5, 10,  2, 10,           5, 10,  2,  9 },
57             {  5, 10,  2, 11,           5, 10,  2,  9 },
58             {  5, 10,  3,  9,           5, 10,  3,  8 },
59             {  5, 10,  3, 10,           5, 10,  3,  8 },
60             {  5, 10,  3, 11,           5, 10,  3,  8 },
61 
62             /* relation between min and max? */
63             /* min max pg  pos                           min max pg  pos */
64  /* [30] */ {  5,  6,  0,  0,                            5,  6,  0,  5 },
65             {  5,  5,  0,  0,                            5,  5,  0,  5 },
66             {  6,  5,  0,  0,                            6,  6,  0,  6 },
67             {  7,  5,  0,  0,                            7,  7,  0,  7 },
68             { -2,  0,  0,  0,                           -2,  0,  0,  0 },
69  /* [35] */ { -2, -1,  0,  0,                           -2, -1,  0, -1 },
70             { -1,  0,  0,  0,                           -1,  0,  0,  0 },
71             { -1, -1,  0,  0,                           -1, -1,  0, -1 },
72             {  0, -1,  0,  0,                            0,  0,  0,  0 },
73             {  1, -1,  0,  0,                            1,  1,  0,  1 },
74  /* [40] */ { 0x80000000, 0x7fffffff,  0,  0,           0x80000000, 0x7fffffff,  0,  0 },
75             { 0x80000001, 0x7fffffff,  0,  0,           0x80000001, 0x7fffffff,  0,  0 },
76             { 0x80000000, 0x7ffffffe,  0,  0,           0x80000000, 0x7ffffffe,  0,  0 },
77             { 0x7fffffff, 0x80000000,  0,  0,           0x7fffffff, 0x7fffffff,  0, 0x7fffffff },
78             {  0, 0x7fffffff,  0,  0,                    0, 0x7fffffff,  0,  0 },
79  /* [45] */ { -1, 0x7fffffff,  0,  0,                   -1, 0x7fffffff,  0,  0 },
80             { -2, 0x7fffffff,  0,  0,                   -2, 0x7fffffff,  0,  0 },
81 
82             /* What happens to nPage when we have a large range? */
83             { 0x80000000, 0x7fffffff,  1,  5,           0x80000000, 0x7fffffff,  1,  5 },
84             { 0x80000000, 0x7fffffff,  2,  5,           0x80000000, 0x7fffffff,  2,  5 },
85             { 0x80000000, 0x7fffffff,  3,  5,           0x80000000, 0x7fffffff,  2,  5 },
86  /* [50] */ { 0x80000000, 0x7fffffff, 0x7fffffff,  5,   0x80000000, 0x7fffffff,  2,  5 },
87             { 0x80000000, 0x7fffffff, 0x80000000,  5,   0x80000000, 0x7fffffff,  2,  5 },
88             { 0x80000000, 0x7fffffff, 0x80000001,  5,   0x80000000, 0x7fffffff,  2,  5 },
89             { 0x80000000, 0x7fffffff, 0xffffffff,  5,   0x80000000, 0x7fffffff,  2,  5 },
90             { 0x80000001, 0x7fffffff,  1,  5,           0x80000001, 0x7fffffff,  1,  5 },
91  /* [55] */ { 0x80000001, 0x7fffffff,  2,  5,           0x80000001, 0x7fffffff,  2,  5 },
92             { 0x80000001, 0x7fffffff,  3,  5,           0x80000001, 0x7fffffff,  3,  5 },
93             { 0x80000001, 0x7fffffff,  4,  5,           0x80000001, 0x7fffffff,  3,  5 },
94             { 0x80000000, 0x7ffffffe,  1,  5,           0x80000000, 0x7ffffffe,  1,  5 },
95             { 0x80000000, 0x7ffffffe,  2,  5,           0x80000000, 0x7ffffffe,  2,  5 },
96  /* [60] */ { 0x80000000, 0x7ffffffe,  3,  5,           0x80000000, 0x7ffffffe,  3,  5 },
97             { 0x80000000, 0x7ffffffe,  4,  5,           0x80000000, 0x7ffffffe,  3,  5 },
98             {  0, 0x7fffffff, 0x7fffffff,  5,            0, 0x7fffffff, 0x7fffffff,  1 },
99             {  0, 0x7fffffff, 0x80000000,  5,            0, 0x7fffffff, 0x80000000,  0 },
100             {  0, 0x7fffffff, 0x80000001,  5,            0, 0x7fffffff, 0x80000000,  0 },
101  /* [65] */ {  0, 0x7fffffff, 0x80000002,  5,            0, 0x7fffffff, 0x80000000,  0 },
102             { -1, 0x7fffffff, 0x7fffffff,  5,           -1, 0x7fffffff, 0x7fffffff,  1 },
103             { -1, 0x7fffffff, 0x80000000,  5,           -1, 0x7fffffff, 0x80000000,  0 },
104             { -1, 0x7fffffff, 0x80000001,  5,           -1, 0x7fffffff, 0x80000001, -1 },
105             { -1, 0x7fffffff, 0x80000002,  5,           -1, 0x7fffffff, 0x80000001, -1 },
106  /* [70] */ { -1, 0x7fffffff, 0x80000003,  5,           -1, 0x7fffffff, 0x80000001, -1 },
107             { -2, 0x7fffffff, 0x80000000,  5,           -2, 0x7fffffff, 0x80000000, 0 },
108             { -2, 0x7fffffff, 0x80000001,  5,           -2, 0x7fffffff, 0x80000000, 0 },
109             { 0xf0000000, 0x7fffffff, 0x90000000,  5,   0xf0000000, 0x7fffffff, 0x70000002,  5 },
110             { 0xf0000000, 0x7fffffff, 0x90000001,  5,   0xf0000000, 0x7fffffff, 0x70000002,  5 },
111     };
112     unsigned i;
113     HWND hScroll;
114     SCROLLINFO si;
115     BOOL success;
116     int ret;
117 
118     hScroll = CreateWindowExW(0, L"SCROLLBAR", NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
119     ok(hScroll != NULL, "\n");
120     if (!hScroll)
121     {
122         skip("No scroll bar\n");
123         return;
124     }
125 
126     si.cbSize = sizeof(si);
127     si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
128     success = GetScrollInfo(hScroll, SB_CTL, &si);
129     ok(success == TRUE, "GetScrollInfo returned %d\n", success);
130     ok(si.nMin == 0, "nMin = %d\n", si.nMin);
131     ok(si.nMax == 0, "nMax = %d\n", si.nMax);
132     ok(si.nPage == 0, "nPage = %u\n", si.nPage);
133     ok(si.nPos == 0, "nPos = %d\n", si.nPos);
134 
135     for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
136     {
137         si.cbSize = sizeof(si);
138         si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
139         si.nMin = tests[i].nMin;
140         si.nMax = tests[i].nMax;
141         si.nPage = tests[i].nPage;
142         si.nPos = tests[i].nPos;
143         ret = SetScrollInfo(hScroll, SB_CTL, &si, FALSE);
144         ok(ret == tests[i].nPosResult, "[%d] ret = %d, expected %d\n", i, ret, tests[i].nPosResult);
145 
146         FillMemory(&si, sizeof(si), 0x55);
147         si.cbSize = sizeof(si);
148         si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
149         success = GetScrollInfo(hScroll, SB_CTL, &si);
150         ok(success == TRUE, "[%d] GetScrollInfo returned %d\n", i, success);
151         ok(si.nMin == tests[i].nMinResult, "[%d] nMin = %d, expected %d\n", i, si.nMin, tests[i].nMinResult);
152         ok(si.nMax == tests[i].nMaxResult, "[%d] nMax = %d, expected %d\n", i, si.nMax, tests[i].nMaxResult);
153         ok(si.nPage == tests[i].nPageResult, "[%d] nPage = %u, expected %u\n", i, si.nPage, tests[i].nPageResult);
154         ok(si.nPos == tests[i].nPosResult, "[%d] nPos = %d, expected %d\n", i, si.nPos, tests[i].nPosResult);
155     }
156     DestroyWindow(hScroll);
157 }
158