2003-04-26 04:09:43 +02:00
/* Unit test suite for list boxes.
*
* Copyright 2003 Ferenc Wagner
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
2006-05-18 14:49:52 +02:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2003-04-26 04:09:43 +02:00
*/
# include <assert.h>
2005-07-29 16:42:19 +02:00
# include <stdarg.h>
# include <stdio.h>
# include "windef.h"
# include "winbase.h"
# include "wingdi.h"
# include "winuser.h"
# include "winnls.h"
2003-04-26 04:09:43 +02:00
# include "wine/test.h"
# ifdef VISIBLE
# define WAIT Sleep (1000)
# define REDRAW RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)
# else
# define WAIT
# define REDRAW
# endif
2005-07-29 16:42:19 +02:00
static const char * const strings [ 4 ] = {
2005-03-10 18:17:22 +01:00
" First added " ,
" Second added " ,
" Third added " ,
" Fourth added which is very long because at some time we only had a 256 byte character buffer and that was overflowing in one of those applications that had a common dialog file open box and tried to add a 300 characters long custom filter string which of course the code did not like and crashed. Just make sure this string is longer than 256 characters. "
} ;
2005-06-15 12:20:53 +02:00
static HWND
2005-07-29 16:42:19 +02:00
create_listbox ( DWORD add_style , HWND parent )
2003-04-26 04:09:43 +02:00
{
2005-08-08 13:02:54 +02:00
HWND handle ;
int ctl_id = 0 ;
if ( parent )
ctl_id = 1 ;
handle = CreateWindow ( " LISTBOX " , " TestList " ,
2003-04-26 04:09:43 +02:00
( LBS_STANDARD & ~ LBS_SORT ) | add_style ,
0 , 0 , 100 , 100 ,
2005-08-08 13:02:54 +02:00
parent , ( HMENU ) ctl_id , NULL , 0 ) ;
2003-04-26 04:09:43 +02:00
assert ( handle ) ;
2005-03-10 18:17:22 +01:00
SendMessage ( handle , LB_ADDSTRING , 0 , ( LPARAM ) ( LPCTSTR ) strings [ 0 ] ) ;
SendMessage ( handle , LB_ADDSTRING , 0 , ( LPARAM ) ( LPCTSTR ) strings [ 1 ] ) ;
SendMessage ( handle , LB_ADDSTRING , 0 , ( LPARAM ) ( LPCTSTR ) strings [ 2 ] ) ;
SendMessage ( handle , LB_ADDSTRING , 0 , ( LPARAM ) ( LPCTSTR ) strings [ 3 ] ) ;
2003-04-26 04:09:43 +02:00
# ifdef VISIBLE
ShowWindow ( handle , SW_SHOW ) ;
# endif
REDRAW ;
return handle ;
}
struct listbox_prop {
DWORD add_style ;
} ;
struct listbox_stat {
int selected , anchor , caret , selcount ;
} ;
struct listbox_test {
struct listbox_prop prop ;
struct listbox_stat init , init_todo ;
struct listbox_stat click , click_todo ;
struct listbox_stat step , step_todo ;
2005-02-02 20:10:59 +01:00
struct listbox_stat sel , sel_todo ;
2003-04-26 04:09:43 +02:00
} ;
2005-06-15 12:20:53 +02:00
static void
2003-04-26 04:09:43 +02:00
listbox_query ( HWND handle , struct listbox_stat * results )
{
results - > selected = SendMessage ( handle , LB_GETCURSEL , 0 , 0 ) ;
results - > anchor = SendMessage ( handle , LB_GETANCHORINDEX , 0 , 0 ) ;
results - > caret = SendMessage ( handle , LB_GETCARETINDEX , 0 , 0 ) ;
results - > selcount = SendMessage ( handle , LB_GETSELCOUNT , 0 , 0 ) ;
}
2005-06-15 12:20:53 +02:00
static void
2003-04-26 04:09:43 +02:00
buttonpress ( HWND handle , WORD x , WORD y )
{
LPARAM lp = x + ( y < < 16 ) ;
WAIT ;
SendMessage ( handle , WM_LBUTTONDOWN , ( WPARAM ) MK_LBUTTON , lp ) ;
SendMessage ( handle , WM_LBUTTONUP , ( WPARAM ) 0 , lp ) ;
REDRAW ;
}
2005-06-15 12:20:53 +02:00
static void
2003-04-26 04:09:43 +02:00
keypress ( HWND handle , WPARAM keycode , BYTE scancode , BOOL extended )
{
LPARAM lp = 1 + ( scancode < < 16 ) + ( extended ? KEYEVENTF_EXTENDEDKEY : 0 ) ;
WAIT ;
SendMessage ( handle , WM_KEYDOWN , keycode , lp ) ;
SendMessage ( handle , WM_KEYUP , keycode , lp | 0xc000000 ) ;
REDRAW ;
}
# define listbox_field_ok(t, s, f, got) \
ok ( t . s . f = = got . f , " style %#x, step " # s " , field " # f \
2004-01-23 21:50:35 +01:00
" : expected %d, got %d \n " , ( unsigned int ) t . prop . add_style , \
2003-04-26 04:09:43 +02:00
t . s . f , got . f )
# define listbox_todo_field_ok(t, s, f, got) \
if ( t . s # # _todo . f ) todo_wine { listbox_field_ok ( t , s , f , got ) ; } \
else listbox_field_ok ( t , s , f , got )
# define listbox_ok(t, s, got) \
listbox_todo_field_ok ( t , s , selected , got ) ; \
listbox_todo_field_ok ( t , s , anchor , got ) ; \
listbox_todo_field_ok ( t , s , caret , got ) ; \
listbox_todo_field_ok ( t , s , selcount , got )
2005-06-15 12:20:53 +02:00
static void
2003-04-26 04:09:43 +02:00
check ( const struct listbox_test test )
{
struct listbox_stat answer ;
2005-07-29 16:42:19 +02:00
HWND hLB = create_listbox ( test . prop . add_style , 0 ) ;
2003-04-26 04:09:43 +02:00
RECT second_item ;
2005-03-10 18:17:22 +01:00
int i ;
2005-08-27 11:24:14 +02:00
int res ;
2003-04-26 04:09:43 +02:00
listbox_query ( hLB , & answer ) ;
listbox_ok ( test , init , answer ) ;
SendMessage ( hLB , LB_GETITEMRECT , ( WPARAM ) 1 , ( LPARAM ) & second_item ) ;
buttonpress ( hLB , ( WORD ) second_item . left , ( WORD ) second_item . top ) ;
listbox_query ( hLB , & answer ) ;
listbox_ok ( test , click , answer ) ;
keypress ( hLB , VK_DOWN , 0x50 , TRUE ) ;
listbox_query ( hLB , & answer ) ;
listbox_ok ( test , step , answer ) ;
2005-02-02 20:10:59 +01:00
DestroyWindow ( hLB ) ;
2005-07-29 16:42:19 +02:00
hLB = create_listbox ( test . prop . add_style , 0 ) ;
2005-02-02 20:10:59 +01:00
SendMessage ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 1 , 2 ) ) ;
listbox_query ( hLB , & answer ) ;
listbox_ok ( test , sel , answer ) ;
2005-03-10 18:17:22 +01:00
for ( i = 0 ; i < 4 ; i + + ) {
DWORD size = SendMessage ( hLB , LB_GETTEXTLEN , i , 0 ) ;
CHAR * txt ;
WCHAR * txtw ;
txt = HeapAlloc ( GetProcessHeap ( ) , 0 , size + 1 ) ;
SendMessageA ( hLB , LB_GETTEXT , i , ( LPARAM ) txt ) ;
ok ( ! strcmp ( txt , strings [ i ] ) , " returned string for item %d does not match %s vs %s \n " , i , txt , strings [ i ] ) ;
txtw = HeapAlloc ( GetProcessHeap ( ) , 0 , 2 * size + 2 ) ;
SendMessageW ( hLB , LB_GETTEXT , i , ( LPARAM ) txtw ) ;
WideCharToMultiByte ( CP_ACP , 0 , txtw , - 1 , txt , size , NULL , NULL ) ;
ok ( ! strcmp ( txt , strings [ i ] ) , " returned string for item %d does not match %s vs %s \n " , i , txt , strings [ i ] ) ;
HeapFree ( GetProcessHeap ( ) , 0 , txtw ) ;
HeapFree ( GetProcessHeap ( ) , 0 , txt ) ;
}
2005-02-02 20:10:59 +01:00
2005-08-27 11:24:14 +02:00
/* Confirm the count of items, and that an invalid delete does not remove anything */
res = SendMessage ( hLB , LB_GETCOUNT , 0 , 0 ) ;
ok ( ( res = = 4 ) , " Expected 4 items, got %d \n " , res ) ;
res = SendMessage ( hLB , LB_DELETESTRING , - 1 , 0 ) ;
ok ( ( res = = LB_ERR ) , " Expected LB_ERR items, got %d \n " , res ) ;
res = SendMessage ( hLB , LB_DELETESTRING , 4 , 0 ) ;
ok ( ( res = = LB_ERR ) , " Expected LB_ERR items, got %d \n " , res ) ;
res = SendMessage ( hLB , LB_GETCOUNT , 0 , 0 ) ;
ok ( ( res = = 4 ) , " Expected 4 items, got %d \n " , res ) ;
2003-04-26 04:09:43 +02:00
WAIT ;
DestroyWindow ( hLB ) ;
}
2005-06-15 12:20:53 +02:00
static void check_item_height ( void )
2005-01-03 15:40:13 +01:00
{
HWND hLB ;
HDC hdc ;
HFONT font ;
2005-07-29 16:42:19 +02:00
TEXTMETRIC tm ;
2005-01-03 15:40:13 +01:00
INT itemHeight ;
2005-07-29 16:42:19 +02:00
hLB = create_listbox ( 0 , 0 ) ;
2005-01-03 15:40:13 +01:00
ok ( ( hdc = GetDCEx ( hLB , 0 , DCX_CACHE ) ) ! = 0 , " Can't get hdc \n " ) ;
ok ( ( font = GetCurrentObject ( hdc , OBJ_FONT ) ) ! = 0 , " Can't get the current font \n " ) ;
2005-07-29 16:42:19 +02:00
ok ( GetTextMetrics ( hdc , & tm ) , " Can't read font metrics \n " ) ;
2005-01-03 15:40:13 +01:00
ReleaseDC ( hLB , hdc ) ;
2005-07-29 16:42:19 +02:00
ok ( SendMessage ( hLB , WM_SETFONT , ( WPARAM ) font , 0 ) = = 0 , " Can't set font \n " ) ;
2005-01-03 15:40:13 +01:00
2005-07-29 16:42:19 +02:00
itemHeight = SendMessage ( hLB , LB_GETITEMHEIGHT , 0 , 0 ) ;
2006-10-07 21:45:11 +02:00
ok ( itemHeight = = tm . tmHeight , " Item height wrong, got %d, expecting %d \n " , itemHeight , tm . tmHeight ) ;
2005-02-02 20:10:59 +01:00
DestroyWindow ( hLB ) ;
2006-12-05 15:32:02 +01:00
hLB = CreateWindow ( " LISTBOX " , " TestList " , LBS_OWNERDRAWVARIABLE ,
0 , 0 , 100 , 100 , NULL , NULL , NULL , 0 ) ;
itemHeight = SendMessage ( hLB , LB_GETITEMHEIGHT , 0 , 0 ) ;
ok ( itemHeight = = tm . tmHeight , " itemHeight %d \n " , itemHeight ) ;
itemHeight = SendMessage ( hLB , LB_GETITEMHEIGHT , 5 , 0 ) ;
ok ( itemHeight = = tm . tmHeight , " itemHeight %d \n " , itemHeight ) ;
itemHeight = SendMessage ( hLB , LB_GETITEMHEIGHT , - 5 , 0 ) ;
ok ( itemHeight = = tm . tmHeight , " itemHeight %d \n " , itemHeight ) ;
DestroyWindow ( hLB ) ;
2005-01-03 15:40:13 +01:00
}
2005-07-29 16:42:19 +02:00
static LRESULT WINAPI main_window_proc ( HWND hwnd , UINT msg , WPARAM wparam , LPARAM lparam )
{
switch ( msg )
{
case WM_DRAWITEM :
{
RECT rc_item , rc_client , rc_clip ;
DRAWITEMSTRUCT * dis = ( DRAWITEMSTRUCT * ) lparam ;
2007-05-24 16:41:17 +02:00
trace ( " %p WM_DRAWITEM %08lx %08lx \n " , hwnd , wparam , lparam ) ;
2005-07-29 16:42:19 +02:00
2007-05-24 16:41:17 +02:00
ok ( wparam = = dis - > CtlID , " got wParam=%08lx instead of %08x \n " ,
2005-08-08 13:02:54 +02:00
wparam , dis - > CtlID ) ;
2005-07-29 16:42:19 +02:00
ok ( dis - > CtlType = = ODT_LISTBOX , " wrong CtlType %04x \n " , dis - > CtlType ) ;
GetClientRect ( dis - > hwndItem , & rc_client ) ;
2006-10-07 21:45:11 +02:00
trace ( " hwndItem %p client rect (%d,%d-%d,%d) \n " , dis - > hwndItem ,
2005-07-29 16:42:19 +02:00
rc_client . left , rc_client . top , rc_client . right , rc_client . bottom ) ;
GetClipBox ( dis - > hDC , & rc_clip ) ;
2006-10-07 21:45:11 +02:00
trace ( " clip rect (%d,%d-%d,%d) \n " , rc_clip . left , rc_clip . top , rc_clip . right , rc_clip . bottom ) ;
2005-07-29 16:42:19 +02:00
ok ( EqualRect ( & rc_client , & rc_clip ) , " client rect of the listbox should be equal to the clip box \n " ) ;
2006-10-07 21:45:11 +02:00
trace ( " rcItem (%d,%d-%d,%d) \n " , dis - > rcItem . left , dis - > rcItem . top ,
2005-07-29 16:42:19 +02:00
dis - > rcItem . right , dis - > rcItem . bottom ) ;
SendMessage ( dis - > hwndItem , LB_GETITEMRECT , dis - > itemID , ( LPARAM ) & rc_item ) ;
2006-10-07 21:45:11 +02:00
trace ( " item rect (%d,%d-%d,%d) \n " , rc_item . left , rc_item . top , rc_item . right , rc_item . bottom ) ;
2005-07-29 16:42:19 +02:00
ok ( EqualRect ( & dis - > rcItem , & rc_item ) , " item rects are not equal \n " ) ;
break ;
}
default :
break ;
}
return DefWindowProc ( hwnd , msg , wparam , lparam ) ;
}
static void test_ownerdraw ( void )
{
WNDCLASS cls ;
HWND parent , hLB ;
INT ret ;
RECT rc ;
cls . style = 0 ;
cls . lpfnWndProc = main_window_proc ;
cls . cbClsExtra = 0 ;
cls . cbWndExtra = 0 ;
cls . hInstance = GetModuleHandle ( 0 ) ;
cls . hIcon = 0 ;
cls . hCursor = LoadCursor ( 0 , ( LPSTR ) IDC_ARROW ) ;
cls . hbrBackground = GetStockObject ( WHITE_BRUSH ) ;
cls . lpszMenuName = NULL ;
cls . lpszClassName = " main_window_class " ;
assert ( RegisterClass ( & cls ) ) ;
parent = CreateWindowEx ( 0 , " main_window_class " , NULL ,
WS_POPUP | WS_VISIBLE ,
100 , 100 , 400 , 400 ,
GetDesktopWindow ( ) , 0 ,
GetModuleHandle ( 0 ) , NULL ) ;
assert ( parent ) ;
hLB = create_listbox ( LBS_OWNERDRAWFIXED | WS_CHILD | WS_VISIBLE , parent ) ;
assert ( hLB ) ;
UpdateWindow ( hLB ) ;
/* make height short enough */
SendMessage ( hLB , LB_GETITEMRECT , 0 , ( LPARAM ) & rc ) ;
SetWindowPos ( hLB , 0 , 0 , 0 , 100 , rc . bottom - rc . top + 1 ,
SWP_NOZORDER | SWP_NOMOVE ) ;
/* make 0 item invisible */
SendMessage ( hLB , LB_SETTOPINDEX , 1 , 0 ) ;
ret = SendMessage ( hLB , LB_GETTOPINDEX , 0 , 0 ) ;
ok ( ret = = 1 , " wrong top index %d \n " , ret ) ;
SendMessage ( hLB , LB_GETITEMRECT , 0 , ( LPARAM ) & rc ) ;
2006-10-07 21:45:11 +02:00
trace ( " item 0 rect (%d,%d-%d,%d) \n " , rc . left , rc . top , rc . right , rc . bottom ) ;
2005-07-29 16:42:19 +02:00
ok ( ! IsRectEmpty ( & rc ) , " empty item rect \n " ) ;
2006-10-07 21:45:11 +02:00
ok ( rc . top < 0 , " rc.top is not negative (%d) \n " , rc . top ) ;
2005-07-29 16:42:19 +02:00
DestroyWindow ( hLB ) ;
DestroyWindow ( parent ) ;
}
2005-12-01 11:12:34 +01:00
# define listbox_test_query(exp, got) \
ok ( exp . selected = = got . selected , " expected selected %d, got %d \n " , exp . selected , got . selected ) ; \
ok ( exp . anchor = = got . anchor , " expected anchor %d, got %d \n " , exp . anchor , got . anchor ) ; \
ok ( exp . caret = = got . caret , " expected caret %d, got %d \n " , exp . caret , got . caret ) ; \
ok ( exp . selcount = = got . selcount , " expected selcount %d, got %d \n " , exp . selcount , got . selcount ) ;
static void test_selection ( void )
{
static const struct listbox_stat test_nosel = { 0 , LB_ERR , 0 , 0 } ;
static const struct listbox_stat test_1 = { 0 , LB_ERR , 0 , 2 } ;
static const struct listbox_stat test_2 = { 0 , LB_ERR , 0 , 3 } ;
static const struct listbox_stat test_3 = { 0 , LB_ERR , 0 , 4 } ;
HWND hLB ;
struct listbox_stat answer ;
INT ret ;
trace ( " testing LB_SELITEMRANGE \n " ) ;
hLB = create_listbox ( LBS_EXTENDEDSEL , 0 ) ;
assert ( hLB ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
ret = SendMessage ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 1 , 2 ) ) ;
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_1 , answer ) ;
SendMessage ( hLB , LB_SETSEL , FALSE , ( LPARAM ) - 1 ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
ret = SendMessage ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 0 , 4 ) ) ;
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_3 , answer ) ;
SendMessage ( hLB , LB_SETSEL , FALSE , ( LPARAM ) - 1 ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
ret = SendMessage ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( - 5 , 5 ) ) ;
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
SendMessage ( hLB , LB_SETSEL , FALSE , ( LPARAM ) - 1 ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
ret = SendMessage ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 2 , 10 ) ) ;
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_1 , answer ) ;
SendMessage ( hLB , LB_SETSEL , FALSE , ( LPARAM ) - 1 ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
ret = SendMessage ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 4 , 10 ) ) ;
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
SendMessage ( hLB , LB_SETSEL , FALSE , ( LPARAM ) - 1 ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
ret = SendMessage ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 10 , 1 ) ) ;
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_2 , answer ) ;
SendMessage ( hLB , LB_SETSEL , FALSE , ( LPARAM ) - 1 ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
ret = SendMessage ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 1 , - 1 ) ) ;
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_2 , answer ) ;
DestroyWindow ( hLB ) ;
}
2006-03-09 06:22:30 +01:00
static void test_listbox_height ( void )
{
HWND hList ;
int r , id ;
hList = CreateWindow ( " ListBox " , " list test " , 0 ,
1 , 1 , 600 , 100 , NULL , NULL , NULL , NULL ) ;
ok ( hList ! = NULL , " failed to create listbox \n " ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi " ) ;
ok ( id = = 0 , " item id wrong \n " ) ;
r = SendMessage ( hList , LB_SETITEMHEIGHT , 0 , MAKELPARAM ( 20 , 0 ) ) ;
ok ( r = = 0 , " send message failed \n " ) ;
r = SendMessage ( hList , LB_GETITEMHEIGHT , 0 , 0 ) ;
ok ( r = = 20 , " height wrong \n " ) ;
r = SendMessage ( hList , LB_SETITEMHEIGHT , 0 , MAKELPARAM ( 0 , 30 ) ) ;
ok ( r = = - 1 , " send message failed \n " ) ;
r = SendMessage ( hList , LB_GETITEMHEIGHT , 0 , 0 ) ;
ok ( r = = 20 , " height wrong \n " ) ;
r = SendMessage ( hList , LB_SETITEMHEIGHT , 0 , MAKELPARAM ( 0x100 , 0 ) ) ;
ok ( r = = - 1 , " send message failed \n " ) ;
r = SendMessage ( hList , LB_GETITEMHEIGHT , 0 , 0 ) ;
ok ( r = = 20 , " height wrong \n " ) ;
r = SendMessage ( hList , LB_SETITEMHEIGHT , 0 , MAKELPARAM ( 0xff , 0 ) ) ;
ok ( r = = 0 , " send message failed \n " ) ;
r = SendMessage ( hList , LB_GETITEMHEIGHT , 0 , 0 ) ;
ok ( r = = 0xff , " height wrong \n " ) ;
DestroyWindow ( hList ) ;
}
2006-10-27 17:22:02 +02:00
static void test_itemfrompoint ( void )
{
HWND hList = CreateWindow ( " ListBox " , " list test " , 0 ,
1 , 1 , 600 , 100 , NULL , NULL , NULL , NULL ) ;
LONG r , id ;
RECT rc ;
/* For an empty listbox win2k returns 0x1ffff, win98 returns 0x10000 */
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( /* x */ 30 , /* y */ 30 ) ) ;
ok ( r = = 0x1ffff | | r = = 0x10000 , " ret %x \n " , r ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 700 , 30 ) ) ;
ok ( r = = 0x1ffff | | r = = 0x10000 , " ret %x \n " , r ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 30 , 300 ) ) ;
ok ( r = = 0x1ffff | | r = = 0x10000 , " ret %x \n " , r ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi " ) ;
ok ( id = = 0 , " item id wrong \n " ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi1 " ) ;
ok ( id = = 1 , " item id wrong \n " ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( /* x */ 30 , /* y */ 30 ) ) ;
ok ( r = = 0x1 , " ret %x \n " , r ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( /* x */ 30 , /* y */ 37 ) ) ;
ok ( r = = 0x10001 , " ret %x \n " , r ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi2 " ) ;
ok ( id = = 2 , " item id wrong \n " ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi3 " ) ;
ok ( id = = 3 , " item id wrong \n " ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi4 " ) ;
ok ( id = = 4 , " item id wrong \n " ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi5 " ) ;
ok ( id = = 5 , " item id wrong \n " ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi6 " ) ;
ok ( id = = 6 , " item id wrong \n " ) ;
id = SendMessage ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi7 " ) ;
ok ( id = = 7 , " item id wrong \n " ) ;
/* Set the listbox up so that id 1 is at the top, this leaves 5
partially visible at the bottom and 6 , 7 are invisible */
SendMessage ( hList , LB_SETTOPINDEX , 1 , 0 ) ;
r = SendMessage ( hList , LB_GETTOPINDEX , 0 , 0 ) ;
ok ( r = = 1 , " top %d \n " , r ) ;
r = SendMessage ( hList , LB_GETITEMRECT , 5 , ( LPARAM ) & rc ) ;
ok ( r = = 1 , " ret %x \n " , r ) ;
r = SendMessage ( hList , LB_GETITEMRECT , 6 , ( LPARAM ) & rc ) ;
ok ( r = = 0 , " ret %x \n " , r ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( /* x */ 10 , /* y */ 10 ) ) ;
ok ( r = = 1 , " ret %x \n " , r ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 1000 , 10 ) ) ;
ok ( r = = 0x10001 , " ret %x \n " , r ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 10 , - 10 ) ) ;
ok ( r = = 0x10001 , " ret %x \n " , r ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 10 , 100 ) ) ;
ok ( r = = 0x10005 , " item %x \n " , r ) ;
r = SendMessage ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 10 , 200 ) ) ;
ok ( r = = 0x10005 , " item %x \n " , r ) ;
DestroyWindow ( hList ) ;
}
2003-04-26 04:09:43 +02:00
START_TEST ( listbox )
{
const struct listbox_test SS =
/* {add_style} */
{ { 0 } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2004-10-06 00:31:00 +02:00
{ 1 , 1 , 1 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2005-02-02 20:10:59 +01:00
{ 2 , 2 , 2 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } } ;
2003-04-26 04:09:43 +02:00
/* {selected, anchor, caret, selcount}{TODO fields} */
const struct listbox_test SS_NS =
{ { LBS_NOSEL } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2004-10-06 00:31:00 +02:00
{ 1 , 1 , 1 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2005-02-02 20:10:59 +01:00
{ 2 , 2 , 2 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } } ;
2003-04-26 04:09:43 +02:00
const struct listbox_test MS =
{ { LBS_MULTIPLESEL } ,
{ 0 , LB_ERR , 0 , 0 } , { 0 , 0 , 0 , 0 } ,
2004-10-06 00:31:00 +02:00
{ 1 , 1 , 1 , 1 } , { 0 , 0 , 0 , 0 } ,
2005-02-02 20:10:59 +01:00
{ 2 , 1 , 2 , 1 } , { 0 , 0 , 0 , 0 } ,
{ 0 , LB_ERR , 0 , 2 } , { 0 , 0 , 0 , 0 } } ;
2003-04-26 04:09:43 +02:00
const struct listbox_test MS_NS =
{ { LBS_MULTIPLESEL | LBS_NOSEL } ,
2004-10-06 00:31:00 +02:00
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
{ 1 , 1 , 1 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2005-02-02 20:10:59 +01:00
{ 2 , 2 , 2 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } } ;
2005-01-10 17:22:33 +01:00
const struct listbox_test ES =
{ { LBS_EXTENDEDSEL } ,
{ 0 , LB_ERR , 0 , 0 } , { 0 , 0 , 0 , 0 } ,
{ 1 , 1 , 1 , 1 } , { 0 , 0 , 0 , 0 } ,
2005-02-02 20:10:59 +01:00
{ 2 , 2 , 2 , 1 } , { 0 , 0 , 0 , 0 } ,
{ 0 , LB_ERR , 0 , 2 } , { 0 , 0 , 0 , 0 } } ;
2005-01-10 17:22:33 +01:00
const struct listbox_test ES_NS =
{ { LBS_EXTENDEDSEL | LBS_NOSEL } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
{ 1 , 1 , 1 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2005-02-02 20:10:59 +01:00
{ 2 , 2 , 2 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } } ;
2005-01-10 17:22:33 +01:00
const struct listbox_test EMS =
{ { LBS_EXTENDEDSEL | LBS_MULTIPLESEL } ,
{ 0 , LB_ERR , 0 , 0 } , { 0 , 0 , 0 , 0 } ,
{ 1 , 1 , 1 , 1 } , { 0 , 0 , 0 , 0 } ,
2005-02-02 20:10:59 +01:00
{ 2 , 2 , 2 , 1 } , { 0 , 0 , 0 , 0 } ,
{ 0 , LB_ERR , 0 , 2 } , { 0 , 0 , 0 , 0 } } ;
2005-01-10 17:22:33 +01:00
const struct listbox_test EMS_NS =
{ { LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_NOSEL } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
{ 1 , 1 , 1 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2005-02-02 20:10:59 +01:00
{ 2 , 2 , 2 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
{ LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } } ;
2003-04-26 04:09:43 +02:00
trace ( " Testing single selection... \n " ) ;
check ( SS ) ;
trace ( " ... with NOSEL \n " ) ;
check ( SS_NS ) ;
trace ( " Testing multiple selection... \n " ) ;
check ( MS ) ;
trace ( " ... with NOSEL \n " ) ;
check ( MS_NS ) ;
2005-01-10 17:22:33 +01:00
trace ( " Testing extended selection... \n " ) ;
check ( ES ) ;
trace ( " ... with NOSEL \n " ) ;
check ( ES_NS ) ;
trace ( " Testing extended and multiple selection... \n " ) ;
check ( EMS ) ;
trace ( " ... with NOSEL \n " ) ;
check ( EMS_NS ) ;
2005-01-03 15:40:13 +01:00
check_item_height ( ) ;
2005-07-29 16:42:19 +02:00
test_ownerdraw ( ) ;
2005-12-01 11:12:34 +01:00
test_selection ( ) ;
2006-03-09 06:22:30 +01:00
test_listbox_height ( ) ;
2006-10-27 17:22:02 +02:00
test_itemfrompoint ( ) ;
2003-04-26 04:09:43 +02:00
}