1 /* Unit test suite for list boxes.
3 * Copyright 2003 Ferenc Wagner
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/test.h"
26 #define WAIT Sleep (1000)
27 #define REDRAW RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)
34 create_listbox (DWORD add_style
)
36 HWND handle
=CreateWindow ("LISTBOX", "TestList",
37 (LBS_STANDARD
& ~LBS_SORT
) | add_style
,
42 SendMessage (handle
, LB_ADDSTRING
, 0, (LPARAM
) (LPCTSTR
) "First added");
43 SendMessage (handle
, LB_ADDSTRING
, 0, (LPARAM
) (LPCTSTR
) "Second added");
44 SendMessage (handle
, LB_ADDSTRING
, 0, (LPARAM
) (LPCTSTR
) "Third added");
47 ShowWindow (handle
, SW_SHOW
);
59 int selected
, anchor
, caret
, selcount
;
63 struct listbox_prop prop
;
64 struct listbox_stat init
, init_todo
;
65 struct listbox_stat click
, click_todo
;
66 struct listbox_stat step
, step_todo
;
70 listbox_query (HWND handle
, struct listbox_stat
*results
)
72 results
->selected
= SendMessage (handle
, LB_GETCURSEL
, 0, 0);
73 results
->anchor
= SendMessage (handle
, LB_GETANCHORINDEX
, 0, 0);
74 results
->caret
= SendMessage (handle
, LB_GETCARETINDEX
, 0, 0);
75 results
->selcount
= SendMessage (handle
, LB_GETSELCOUNT
, 0, 0);
79 buttonpress (HWND handle
, WORD x
, WORD y
)
84 SendMessage (handle
, WM_LBUTTONDOWN
, (WPARAM
) MK_LBUTTON
, lp
);
85 SendMessage (handle
, WM_LBUTTONUP
, (WPARAM
) 0 , lp
);
90 keypress (HWND handle
, WPARAM keycode
, BYTE scancode
, BOOL extended
)
92 LPARAM lp
=1+(scancode
<<16)+(extended
?KEYEVENTF_EXTENDEDKEY
:0);
95 SendMessage (handle
, WM_KEYDOWN
, keycode
, lp
);
96 SendMessage (handle
, WM_KEYUP
, keycode
, lp
| 0xc000000);
100 #define listbox_field_ok(t, s, f, got) \
101 ok (t.s.f==got.f, "style %#x, step " #s ", field " #f \
102 ": expected %d, got %d", (unsigned int)t.prop.add_style, \
105 #define listbox_todo_field_ok(t, s, f, got) \
106 if (t.s##_todo.f) todo_wine { listbox_field_ok(t, s, f, got); } \
107 else listbox_field_ok(t, s, f, got)
109 #define listbox_ok(t, s, got) \
110 listbox_todo_field_ok(t, s, selected, got); \
111 listbox_todo_field_ok(t, s, anchor, got); \
112 listbox_todo_field_ok(t, s, caret, got); \
113 listbox_todo_field_ok(t, s, selcount, got)
116 check (const struct listbox_test test
)
118 struct listbox_stat answer
;
119 HWND hLB
=create_listbox (test
.prop
.add_style
);
122 listbox_query (hLB
, &answer
);
123 listbox_ok (test
, init
, answer
);
125 SendMessage (hLB
, LB_GETITEMRECT
, (WPARAM
) 1, (LPARAM
) &second_item
);
126 buttonpress(hLB
, (WORD
)second_item
.left
, (WORD
)second_item
.top
);
128 listbox_query (hLB
, &answer
);
129 listbox_ok (test
, click
, answer
);
131 keypress (hLB
, VK_DOWN
, 0x50, TRUE
);
133 listbox_query (hLB
, &answer
);
134 listbox_ok (test
, step
, answer
);
142 const struct listbox_test SS
=
145 {LB_ERR
, LB_ERR
, 0, LB_ERR
}, {0,0,0,0},
146 { 1, 1, 1, LB_ERR
}, {0,1,0,0},
147 { 2, 2, 2, LB_ERR
}, {0,1,0,0}};
148 /* {selected, anchor, caret, selcount}{TODO fields} */
149 const struct listbox_test SS_NS
=
151 {LB_ERR
, LB_ERR
, 0, LB_ERR
}, {0,0,0,0},
152 { 1, 1, 1, LB_ERR
}, {1,1,0,0},
153 { 2, 2, 2, LB_ERR
}, {1,1,1,0}};
154 const struct listbox_test MS
=
156 { 0, LB_ERR
, 0, 0}, {0,0,0,0},
157 { 1, 1, 1, 1}, {0,1,0,0},
158 { 2, 1, 2, 1}, {0,1,0,1}};
159 const struct listbox_test MS_NS
=
160 {{LBS_MULTIPLESEL
| LBS_NOSEL
},
161 {LB_ERR
, LB_ERR
, 0, LB_ERR
}, {1,0,0,1},
162 { 1, 1, 1, LB_ERR
}, {0,1,0,1},
163 { 2, 2, 2, LB_ERR
}, {0,1,0,1}};
165 trace (" Testing single selection...\n");
167 trace (" ... with NOSEL\n");
169 trace (" Testing multiple selection...\n");
171 trace (" ... with NOSEL\n");