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. "
} ;
2008-09-24 15:39:03 +02:00
static const char BAD_EXTENSION [ ] = " *.badtxt " ;
2008-04-04 09:03:28 +02:00
2018-02-28 17:37:03 +01:00
static int strcmp_aw ( LPCWSTR strw , const char * stra )
{
WCHAR buf [ 1024 ] ;
if ( ! stra ) return 1 ;
2018-06-28 18:17:01 +02:00
MultiByteToWideChar ( CP_ACP , 0 , stra , - 1 , buf , ARRAY_SIZE ( buf ) ) ;
2018-02-28 17:37:03 +01:00
return lstrcmpW ( strw , buf ) ;
}
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 ;
2009-01-03 20:16:16 +01:00
INT_PTR ctl_id = 0 ;
2005-08-08 13:02:54 +02:00
if ( parent )
ctl_id = 1 ;
2013-10-23 07:53:49 +02:00
handle = CreateWindowA ( " 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 ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( handle , LB_ADDSTRING , 0 , ( LPARAM ) strings [ 0 ] ) ;
SendMessageA ( handle , LB_ADDSTRING , 0 , ( LPARAM ) strings [ 1 ] ) ;
SendMessageA ( handle , LB_ADDSTRING , 0 , ( LPARAM ) strings [ 2 ] ) ;
SendMessageA ( handle , LB_ADDSTRING , 0 , ( LPARAM ) 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_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 )
{
2013-10-23 07:53:49 +02:00
results - > selected = SendMessageA ( handle , LB_GETCURSEL , 0 , 0 ) ;
results - > anchor = SendMessageA ( handle , LB_GETANCHORINDEX , 0 , 0 ) ;
results - > caret = SendMessageA ( handle , LB_GETCARETINDEX , 0 , 0 ) ;
results - > selcount = SendMessageA ( handle , LB_GETSELCOUNT , 0 , 0 ) ;
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
buttonpress ( HWND handle , WORD x , WORD y )
{
LPARAM lp = x + ( y < < 16 ) ;
WAIT ;
2013-10-23 07:53:49 +02:00
SendMessageA ( handle , WM_LBUTTONDOWN , MK_LBUTTON , lp ) ;
SendMessageA ( handle , WM_LBUTTONUP , 0 , lp ) ;
2003-04-26 04:09:43 +02:00
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 ;
2013-10-23 07:53:49 +02:00
SendMessageA ( handle , WM_KEYDOWN , keycode , lp ) ;
SendMessageA ( handle , WM_KEYUP , keycode , lp | 0xc000000 ) ;
2003-04-26 04:09:43 +02:00
REDRAW ;
}
# define listbox_field_ok(t, s, f, got) \
ok ( t . s . f = = got . f , " style %#x, step " # s " , field " # f \
2018-11-15 10:46:13 +01:00
" : expected %d, got %d \n " , style , t . s . f , got . f )
2003-04-26 04:09:43 +02:00
# define listbox_todo_field_ok(t, s, f, got) \
2016-02-20 16:20:58 +01:00
todo_wine_if ( t . s # # _todo . f ) { listbox_field_ok ( t , s , f , got ) ; }
2003-04-26 04:09:43 +02:00
# 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
2018-11-15 10:46:13 +01:00
check ( DWORD style , const struct listbox_test test )
2003-04-26 04:09:43 +02:00
{
struct listbox_stat answer ;
RECT second_item ;
2005-03-10 18:17:22 +01:00
int i ;
2005-08-27 11:24:14 +02:00
int res ;
2018-11-15 10:46:13 +01:00
HWND hLB ;
hLB = create_listbox ( style , 0 ) ;
2003-04-26 04:09:43 +02:00
listbox_query ( hLB , & answer ) ;
listbox_ok ( test , init , answer ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_GETITEMRECT , 1 , ( LPARAM ) & second_item ) ;
2003-04-26 04:09:43 +02:00
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 ) ;
2018-11-15 10:46:13 +01:00
hLB = create_listbox ( style , 0 ) ;
2005-02-02 20:10:59 +01:00
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 1 , 2 ) ) ;
2005-02-02 20:10:59 +01:00
listbox_query ( hLB , & answer ) ;
listbox_ok ( test , sel , answer ) ;
2005-03-10 18:17:22 +01:00
2018-11-15 10:46:13 +01:00
for ( i = 0 ; i < 4 & & ! ( style & LBS_NODATA ) ; i + + ) {
2013-10-23 07:53:49 +02:00
DWORD size = SendMessageA ( hLB , LB_GETTEXTLEN , i , 0 ) ;
2005-03-10 18:17:22 +01:00
CHAR * txt ;
WCHAR * txtw ;
2007-11-07 16:36:53 +01:00
int resA , resW ;
2005-03-10 18:17:22 +01:00
2007-12-07 01:14:24 +01:00
txt = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , size + 1 ) ;
2007-11-07 16:36:53 +01:00
resA = SendMessageA ( hLB , LB_GETTEXT , i , ( LPARAM ) txt ) ;
2005-03-10 18:17:22 +01:00
ok ( ! strcmp ( txt , strings [ i ] ) , " returned string for item %d does not match %s vs %s \n " , i , txt , strings [ i ] ) ;
2007-12-07 01:14:24 +01:00
txtw = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , 2 * size + 2 ) ;
2007-11-07 16:36:53 +01:00
resW = SendMessageW ( hLB , LB_GETTEXT , i , ( LPARAM ) txtw ) ;
2018-11-15 10:46:13 +01:00
ok ( resA = = resW , " Unexpected text length. \n " ) ;
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 ] ) ;
2005-03-10 18:17:22 +01:00
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 */
2013-10-23 07:53:49 +02:00
res = SendMessageA ( hLB , LB_GETCOUNT , 0 , 0 ) ;
2005-08-27 11:24:14 +02:00
ok ( ( res = = 4 ) , " Expected 4 items, got %d \n " , res ) ;
2013-10-23 07:53:49 +02:00
res = SendMessageA ( hLB , LB_DELETESTRING , - 1 , 0 ) ;
2005-08-27 11:24:14 +02:00
ok ( ( res = = LB_ERR ) , " Expected LB_ERR items, got %d \n " , res ) ;
2013-10-23 07:53:49 +02:00
res = SendMessageA ( hLB , LB_DELETESTRING , 4 , 0 ) ;
2005-08-27 11:24:14 +02:00
ok ( ( res = = LB_ERR ) , " Expected LB_ERR items, got %d \n " , res ) ;
2013-10-23 07:53:49 +02:00
res = SendMessageA ( hLB , LB_GETCOUNT , 0 , 0 ) ;
2005-08-27 11:24:14 +02:00
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 ;
2013-10-23 07:53:49 +02:00
TEXTMETRICA 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 " ) ;
2013-10-23 07:53:49 +02:00
ok ( GetTextMetricsA ( hdc , & tm ) , " Can't read font metrics \n " ) ;
2005-01-03 15:40:13 +01:00
ReleaseDC ( hLB , hdc ) ;
2013-10-23 07:53:49 +02:00
ok ( SendMessageA ( hLB , WM_SETFONT , ( WPARAM ) font , 0 ) = = 0 , " Can't set font \n " ) ;
2005-01-03 15:40:13 +01:00
2013-10-23 07:53:49 +02:00
itemHeight = SendMessageA ( 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
2013-10-23 07:53:49 +02:00
hLB = CreateWindowA ( " LISTBOX " , " TestList " , LBS_OWNERDRAWVARIABLE ,
2006-12-05 15:32:02 +01:00
0 , 0 , 100 , 100 , NULL , NULL , NULL , 0 ) ;
2013-10-23 07:53:49 +02:00
itemHeight = SendMessageA ( hLB , LB_GETITEMHEIGHT , 0 , 0 ) ;
2006-12-05 15:32:02 +01:00
ok ( itemHeight = = tm . tmHeight , " itemHeight %d \n " , itemHeight ) ;
2013-10-23 07:53:49 +02:00
itemHeight = SendMessageA ( hLB , LB_GETITEMHEIGHT , 5 , 0 ) ;
2006-12-05 15:32:02 +01:00
ok ( itemHeight = = tm . tmHeight , " itemHeight %d \n " , itemHeight ) ;
2013-10-23 07:53:49 +02:00
itemHeight = SendMessageA ( hLB , LB_GETITEMHEIGHT , - 5 , 0 ) ;
2006-12-05 15:32:02 +01:00
ok ( itemHeight = = tm . tmHeight , " itemHeight %d \n " , itemHeight ) ;
DestroyWindow ( hLB ) ;
2005-01-03 15:40:13 +01:00
}
2014-02-20 12:35:18 +01:00
static int got_selchange ;
2005-07-29 16:42:19 +02:00
static LRESULT WINAPI main_window_proc ( HWND hwnd , UINT msg , WPARAM wparam , LPARAM lparam )
{
switch ( msg )
{
2018-02-28 17:37:03 +01:00
case WM_MEASUREITEM :
{
DWORD style = GetWindowLongA ( GetWindow ( hwnd , GW_CHILD ) , GWL_STYLE ) ;
MEASUREITEMSTRUCT * mi = ( void * ) lparam ;
ok ( wparam = = mi - > CtlID , " got wParam=%08lx, expected %08x \n " , wparam , mi - > CtlID ) ;
ok ( mi - > CtlType = = ODT_LISTBOX , " mi->CtlType = %u \n " , mi - > CtlType ) ;
ok ( mi - > CtlID = = 1 , " mi->CtlID = %u \n " , mi - > CtlID ) ;
ok ( mi - > itemHeight , " mi->itemHeight = 0 \n " ) ;
if ( mi - > itemID > 4 | | style & LBS_OWNERDRAWFIXED )
break ;
if ( style & LBS_HASSTRINGS )
{
ok ( ! strcmp_aw ( ( WCHAR * ) mi - > itemData , strings [ mi - > itemID ] ) ,
" mi->itemData = %s (%d) \n " , wine_dbgstr_w ( ( WCHAR * ) mi - > itemData ) , mi - > itemID ) ;
}
else
{
ok ( ( void * ) mi - > itemData = = strings [ mi - > itemID ] ,
" mi->itemData = %08lx, expected %p \n " , mi - > itemData , strings [ mi - > itemID ] ) ;
}
break ;
}
2005-07-29 16:42:19 +02:00
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 ) ;
2016-06-16 10:32:02 +02:00
trace ( " hwndItem %p client rect %s \n " , dis - > hwndItem , wine_dbgstr_rect ( & rc_client ) ) ;
2005-07-29 16:42:19 +02:00
GetClipBox ( dis - > hDC , & rc_clip ) ;
2016-06-16 10:32:02 +02:00
trace ( " clip rect %s \n " , wine_dbgstr_rect ( & rc_clip ) ) ;
2008-05-22 05:24:43 +02:00
ok ( EqualRect ( & rc_client , & rc_clip ) | | IsRectEmpty ( & rc_clip ) ,
" client rect of the listbox should be equal to the clip box, "
" or the clip box should be empty \n " ) ;
2005-07-29 16:42:19 +02:00
2016-06-16 10:32:02 +02:00
trace ( " rcItem %s \n " , wine_dbgstr_rect ( & dis - > rcItem ) ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( dis - > hwndItem , LB_GETITEMRECT , dis - > itemID , ( LPARAM ) & rc_item ) ;
2016-06-16 10:32:02 +02:00
trace ( " item rect %s \n " , wine_dbgstr_rect ( & rc_item ) ) ;
2005-07-29 16:42:19 +02:00
ok ( EqualRect ( & dis - > rcItem , & rc_item ) , " item rects are not equal \n " ) ;
break ;
}
2014-02-20 12:35:18 +01:00
case WM_COMMAND :
if ( HIWORD ( wparam ) = = LBN_SELCHANGE ) got_selchange + + ;
break ;
2005-07-29 16:42:19 +02:00
default :
break ;
}
2013-10-23 07:53:49 +02:00
return DefWindowProcA ( hwnd , msg , wparam , lparam ) ;
2005-07-29 16:42:19 +02:00
}
2013-03-28 11:21:22 +01:00
static HWND create_parent ( void )
2005-07-29 16:42:19 +02:00
{
2013-10-23 07:53:49 +02:00
WNDCLASSA cls ;
2013-03-28 11:21:22 +01:00
HWND parent ;
static ATOM class ;
2005-07-29 16:42:19 +02:00
2013-03-28 11:21:22 +01:00
if ( ! class )
{
cls . style = 0 ;
cls . lpfnWndProc = main_window_proc ;
cls . cbClsExtra = 0 ;
cls . cbWndExtra = 0 ;
2013-10-23 07:53:49 +02:00
cls . hInstance = GetModuleHandleA ( NULL ) ;
2013-03-28 11:21:22 +01:00
cls . hIcon = 0 ;
2013-10-23 07:53:49 +02:00
cls . hCursor = LoadCursorA ( 0 , ( LPCSTR ) IDC_ARROW ) ;
2013-03-28 11:21:22 +01:00
cls . hbrBackground = GetStockObject ( WHITE_BRUSH ) ;
cls . lpszMenuName = NULL ;
cls . lpszClassName = " main_window_class " ;
2013-10-23 07:53:49 +02:00
class = RegisterClassA ( & cls ) ;
2013-03-28 11:21:22 +01:00
}
2005-07-29 16:42:19 +02:00
2013-10-23 07:53:49 +02:00
parent = CreateWindowExA ( 0 , " main_window_class " , NULL ,
2005-07-29 16:42:19 +02:00
WS_POPUP | WS_VISIBLE ,
100 , 100 , 400 , 400 ,
GetDesktopWindow ( ) , 0 ,
2013-10-23 07:53:49 +02:00
GetModuleHandleA ( NULL ) , NULL ) ;
2013-03-28 11:21:22 +01:00
return parent ;
}
static void test_ownerdraw ( void )
{
HWND parent , hLB ;
INT ret ;
RECT rc ;
parent = create_parent ( ) ;
2005-07-29 16:42:19 +02:00
assert ( parent ) ;
hLB = create_listbox ( LBS_OWNERDRAWFIXED | WS_CHILD | WS_VISIBLE , parent ) ;
assert ( hLB ) ;
2009-10-12 09:21:25 +02:00
SetForegroundWindow ( hLB ) ;
2005-07-29 16:42:19 +02:00
UpdateWindow ( hLB ) ;
/* make height short enough */
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_GETITEMRECT , 0 , ( LPARAM ) & rc ) ;
2005-07-29 16:42:19 +02:00
SetWindowPos ( hLB , 0 , 0 , 0 , 100 , rc . bottom - rc . top + 1 ,
SWP_NOZORDER | SWP_NOMOVE ) ;
/* make 0 item invisible */
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_SETTOPINDEX , 1 , 0 ) ;
ret = SendMessageA ( hLB , LB_GETTOPINDEX , 0 , 0 ) ;
2005-07-29 16:42:19 +02:00
ok ( ret = = 1 , " wrong top index %d \n " , ret ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_GETITEMRECT , 0 , ( LPARAM ) & rc ) ;
2016-06-16 10:32:02 +02:00
trace ( " item 0 rect %s \n " , wine_dbgstr_rect ( & rc ) ) ;
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 ) ;
2018-11-15 10:46:12 +01:00
/* Both FIXED and VARIABLE, FIXED should override VARIABLE. */
hLB = CreateWindowA ( " listbox " , " TestList " , LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE , 0 , 0 , 100 , 100 ,
NULL , NULL , NULL , 0 ) ;
ok ( hLB ! = NULL , " last error 0x%08x \n " , GetLastError ( ) ) ;
2018-11-15 10:46:15 +01:00
ok ( GetWindowLongA ( hLB , GWL_STYLE ) & LBS_OWNERDRAWVARIABLE , " Unexpected window style. \n " ) ;
2018-11-15 10:46:12 +01:00
ret = SendMessageA ( hLB , LB_INSERTSTRING , - 1 , 0 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_INSERTSTRING , - 1 , 0 ) ;
ok ( ret = = 1 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_SETITEMHEIGHT , 0 , 13 ) ;
ok ( ret = = LB_OKAY , " Failed to set item height, %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_GETITEMHEIGHT , 0 , 0 ) ;
ok ( ret = = 13 , " Unexpected item height %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_SETITEMHEIGHT , 1 , 42 ) ;
ok ( ret = = LB_OKAY , " Failed to set item height, %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_GETITEMHEIGHT , 0 , 0 ) ;
ok ( ret = = 42 , " Unexpected item height %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_GETITEMHEIGHT , 1 , 0 ) ;
ok ( ret = = 42 , " Unexpected item height %d. \n " , ret ) ;
DestroyWindow ( hLB ) ;
2005-07-29 16:42:19 +02:00
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 ) ;
2015-07-16 11:30:30 +02:00
static void test_LB_SELITEMRANGE ( void )
2005-12-01 11:12:34 +01:00
{
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 ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 1 , 2 ) ) ;
2005-12-01 11:12:34 +01:00
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_1 , answer ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_SETSEL , FALSE , - 1 ) ;
2005-12-01 11:12:34 +01:00
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 0 , 4 ) ) ;
2005-12-01 11:12:34 +01:00
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_3 , answer ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_SETSEL , FALSE , - 1 ) ;
2005-12-01 11:12:34 +01:00
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( - 5 , 5 ) ) ;
2005-12-01 11:12:34 +01:00
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_SETSEL , FALSE , - 1 ) ;
2005-12-01 11:12:34 +01:00
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 2 , 10 ) ) ;
2005-12-01 11:12:34 +01:00
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_1 , answer ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_SETSEL , FALSE , - 1 ) ;
2005-12-01 11:12:34 +01:00
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 4 , 10 ) ) ;
2005-12-01 11:12:34 +01:00
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_SETSEL , FALSE , - 1 ) ;
2005-12-01 11:12:34 +01:00
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 10 , 1 ) ) ;
2005-12-01 11:12:34 +01:00
ok ( ret = = LB_OKAY , " LB_SELITEMRANGE returned %d instead of LB_OKAY \n " , ret ) ;
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_2 , answer ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hLB , LB_SETSEL , FALSE , - 1 ) ;
2005-12-01 11:12:34 +01:00
listbox_query ( hLB , & answer ) ;
listbox_test_query ( test_nosel , answer ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( hLB , LB_SELITEMRANGE , TRUE , MAKELPARAM ( 1 , - 1 ) ) ;
2005-12-01 11:12:34 +01:00
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 ) ;
}
2015-07-16 11:30:30 +02:00
static void test_LB_SETCURSEL ( void )
{
HWND parent , hLB ;
INT ret ;
trace ( " testing LB_SETCURSEL \n " ) ;
parent = create_parent ( ) ;
assert ( parent ) ;
hLB = create_listbox ( LBS_NOINTEGRALHEIGHT | WS_CHILD , parent ) ;
assert ( hLB ) ;
SendMessageA ( hLB , LB_SETITEMHEIGHT , 0 , 32 ) ;
2018-08-15 10:22:54 +02:00
ret = SendMessageA ( hLB , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
2015-07-16 11:30:30 +02:00
ret = SendMessageA ( hLB , LB_SETCURSEL , 2 , 0 ) ;
ok ( ret = = 2 , " LB_SETCURSEL returned %d instead of 2 \n " , ret ) ;
ret = GetScrollPos ( hLB , SB_VERT ) ;
ok ( ret = = 0 , " expected vscroll 0, got %d \n " , ret ) ;
2018-08-15 10:22:54 +02:00
ret = SendMessageA ( hLB , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
2015-07-16 11:30:30 +02:00
ret = SendMessageA ( hLB , LB_SETCURSEL , 3 , 0 ) ;
ok ( ret = = 3 , " LB_SETCURSEL returned %d instead of 3 \n " , ret ) ;
ret = GetScrollPos ( hLB , SB_VERT ) ;
ok ( ret = = 1 , " expected vscroll 1, got %d \n " , ret ) ;
2018-08-15 10:22:54 +02:00
ret = SendMessageA ( hLB , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
DestroyWindow ( hLB ) ;
hLB = create_listbox ( 0 , 0 ) ;
ok ( hLB ! = NULL , " Failed to create ListBox window. \n " ) ;
ret = SendMessageA ( hLB , LB_SETCURSEL , 1 , 0 ) ;
ok ( ret = = 1 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
DestroyWindow ( hLB ) ;
/* LBS_EXTENDEDSEL */
hLB = create_listbox ( LBS_EXTENDEDSEL , 0 ) ;
ok ( hLB ! = NULL , " Failed to create ListBox window. \n " ) ;
ret = SendMessageA ( hLB , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_SETCURSEL , 2 , 0 ) ;
ok ( ret = = - 1 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
DestroyWindow ( hLB ) ;
/* LBS_MULTIPLESEL */
hLB = create_listbox ( LBS_MULTIPLESEL , 0 ) ;
ok ( hLB ! = NULL , " Failed to create ListBox window. \n " ) ;
ret = SendMessageA ( hLB , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_SETCURSEL , 2 , 0 ) ;
ok ( ret = = - 1 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( hLB , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
2015-07-16 11:30:30 +02:00
DestroyWindow ( hLB ) ;
}
2018-08-15 10:22:54 +02:00
static void test_LB_SETSEL ( void )
{
HWND list ;
int ret ;
/* LBS_EXTENDEDSEL */
list = create_listbox ( LBS_EXTENDEDSEL , 0 ) ;
ok ( list ! = NULL , " Failed to create ListBox window. \n " ) ;
ret = SendMessageA ( list , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_SETSEL , TRUE , 0 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = 0 , " Unexpected anchor index %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_SETSEL , TRUE , 1 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = 1 , " Unexpected anchor index %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_SETSEL , FALSE , 1 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = 1 , " Unexpected anchor index %d. \n " , ret ) ;
DestroyWindow ( list ) ;
/* LBS_MULTIPLESEL */
list = create_listbox ( LBS_MULTIPLESEL , 0 ) ;
ok ( list ! = NULL , " Failed to create ListBox window. \n " ) ;
ret = SendMessageA ( list , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = - 1 , " Unexpected anchor index %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_SETSEL , TRUE , 0 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = 0 , " Unexpected anchor index %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_SETSEL , TRUE , 1 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = 1 , " Unexpected anchor index %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_SETSEL , FALSE , 1 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( list , LB_GETANCHORINDEX , 0 , 0 ) ;
ok ( ret = = 1 , " Unexpected anchor index %d. \n " , ret ) ;
DestroyWindow ( list ) ;
}
2006-03-09 06:22:30 +01:00
static void test_listbox_height ( void )
{
HWND hList ;
int r , id ;
2013-10-23 07:53:49 +02:00
hList = CreateWindowA ( " ListBox " , " list test " , 0 ,
2006-03-09 06:22:30 +01:00
1 , 1 , 600 , 100 , NULL , NULL , NULL , NULL ) ;
ok ( hList ! = NULL , " failed to create listbox \n " ) ;
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi " ) ;
2006-03-09 06:22:30 +01:00
ok ( id = = 0 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_SETITEMHEIGHT , 0 , MAKELPARAM ( 20 , 0 ) ) ;
2006-03-09 06:22:30 +01:00
ok ( r = = 0 , " send message failed \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_GETITEMHEIGHT , 0 , 0 ) ;
2006-03-09 06:22:30 +01:00
ok ( r = = 20 , " height wrong \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_SETITEMHEIGHT , 0 , MAKELPARAM ( 0 , 30 ) ) ;
2006-03-09 06:22:30 +01:00
ok ( r = = - 1 , " send message failed \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_GETITEMHEIGHT , 0 , 0 ) ;
2006-03-09 06:22:30 +01:00
ok ( r = = 20 , " height wrong \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_SETITEMHEIGHT , 0 , MAKELPARAM ( 0x100 , 0 ) ) ;
2006-03-09 06:22:30 +01:00
ok ( r = = - 1 , " send message failed \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_GETITEMHEIGHT , 0 , 0 ) ;
2006-03-09 06:22:30 +01:00
ok ( r = = 20 , " height wrong \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_SETITEMHEIGHT , 0 , MAKELPARAM ( 0xff , 0 ) ) ;
2006-03-09 06:22:30 +01:00
ok ( r = = 0 , " send message failed \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_GETITEMHEIGHT , 0 , 0 ) ;
2006-03-09 06:22:30 +01:00
ok ( r = = 0xff , " height wrong \n " ) ;
DestroyWindow ( hList ) ;
}
2006-10-27 17:22:02 +02:00
static void test_itemfrompoint ( void )
{
2007-11-07 16:34:55 +01:00
/* WS_POPUP is required in order to have a more accurate size calculation (
without caption ) . LBS_NOINTEGRALHEIGHT is required in order to test
behavior of partially - displayed item .
*/
2013-10-23 07:53:49 +02:00
HWND hList = CreateWindowA ( " ListBox " , " list test " ,
2007-11-07 16:34:55 +01:00
WS_VISIBLE | WS_POPUP | LBS_NOINTEGRALHEIGHT ,
2006-10-27 17:22:02 +02:00
1 , 1 , 600 , 100 , NULL , NULL , NULL , NULL ) ;
2008-09-24 15:39:03 +02:00
ULONG r , id ;
2006-10-27 17:22:02 +02:00
RECT rc ;
2008-09-24 15:39:03 +02:00
/* For an empty listbox win2k returns 0x1ffff, win98 returns 0x10000, nt4 returns 0xffffffff */
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( /* x */ 30 , /* y */ 30 ) ) ;
2008-09-24 15:39:03 +02:00
ok ( r = = 0x1ffff | | r = = 0x10000 | | r = = 0xffffffff , " ret %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 700 , 30 ) ) ;
2008-09-24 15:39:03 +02:00
ok ( r = = 0x1ffff | | r = = 0x10000 | | r = = 0xffffffff , " ret %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 30 , 300 ) ) ;
2008-09-24 15:39:03 +02:00
ok ( r = = 0x1ffff | | r = = 0x10000 | | r = = 0xffffffff , " ret %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi " ) ;
2006-10-27 17:22:02 +02:00
ok ( id = = 0 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi1 " ) ;
2006-10-27 17:22:02 +02:00
ok ( id = = 1 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( /* x */ 30 , /* y */ 30 ) ) ;
2006-10-27 17:22:02 +02:00
ok ( r = = 0x1 , " ret %x \n " , r ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( /* x */ 30 , /* y */ 601 ) ) ;
2008-09-24 15:39:03 +02:00
ok ( r = = 0x10001 | | broken ( r = = 1 ) , /* nt4 */
" ret %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
2007-11-07 16:34:55 +01:00
/* Resize control so that below assertions about sizes are valid */
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_GETITEMRECT , 0 , ( LPARAM ) & rc ) ;
2007-11-07 16:34:55 +01:00
ok ( r = = 1 , " ret %x \n " , r ) ;
r = MoveWindow ( hList , 1 , 1 , 600 , ( rc . bottom - rc . top + 1 ) * 9 / 2 , TRUE ) ;
ok ( r ! = 0 , " ret %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi2 " ) ;
2006-10-27 17:22:02 +02:00
ok ( id = = 2 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi3 " ) ;
2006-10-27 17:22:02 +02:00
ok ( id = = 3 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi4 " ) ;
2006-10-27 17:22:02 +02:00
ok ( id = = 4 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi5 " ) ;
2006-10-27 17:22:02 +02:00
ok ( id = = 5 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi6 " ) ;
2006-10-27 17:22:02 +02:00
ok ( id = = 6 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi7 " ) ;
2006-10-27 17:22:02 +02:00
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 */
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_SETTOPINDEX , 1 , 0 ) ;
r = SendMessageA ( hList , LB_GETTOPINDEX , 0 , 0 ) ;
2006-10-27 17:22:02 +02:00
ok ( r = = 1 , " top %d \n " , r ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_GETITEMRECT , 5 , ( LPARAM ) & rc ) ;
2006-10-27 17:22:02 +02:00
ok ( r = = 1 , " ret %x \n " , r ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_GETITEMRECT , 6 , ( LPARAM ) & rc ) ;
2006-10-27 17:22:02 +02:00
ok ( r = = 0 , " ret %x \n " , r ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( /* x */ 10 , /* y */ 10 ) ) ;
2006-10-27 17:22:02 +02:00
ok ( r = = 1 , " ret %x \n " , r ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 1000 , 10 ) ) ;
2008-09-24 15:39:03 +02:00
ok ( r = = 0x10001 | | broken ( r = = 1 ) , /* nt4 */
" ret %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 10 , - 10 ) ) ;
2008-09-24 15:39:03 +02:00
ok ( r = = 0x10001 | | broken ( r = = 1 ) , /* nt4 */
" ret %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 10 , 100 ) ) ;
2008-09-24 15:39:03 +02:00
ok ( r = = 0x10005 | | broken ( r = = 5 ) , /* nt4 */
" item %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_ITEMFROMPOINT , 0 , MAKELPARAM ( 10 , 200 ) ) ;
2008-09-24 15:39:03 +02:00
ok ( r = = 0x10005 | | broken ( r = = 5 ) , /* nt4 */
" item %x \n " , r ) ;
2006-10-27 17:22:02 +02:00
DestroyWindow ( hList ) ;
}
2007-08-14 18:35:18 +02:00
static void test_listbox_item_data ( void )
{
HWND hList ;
int r , id ;
2013-10-23 07:53:49 +02:00
hList = CreateWindowA ( " ListBox " , " list test " , 0 ,
2007-08-14 18:35:18 +02:00
1 , 1 , 600 , 100 , NULL , NULL , NULL , NULL ) ;
ok ( hList ! = NULL , " failed to create listbox \n " ) ;
2013-10-23 07:53:49 +02:00
id = SendMessageA ( hList , LB_ADDSTRING , 0 , ( LPARAM ) " hi " ) ;
2007-08-14 18:35:18 +02:00
ok ( id = = 0 , " item id wrong \n " ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_SETITEMDATA , 0 , MAKELPARAM ( 20 , 0 ) ) ;
2007-08-14 18:35:18 +02:00
ok ( r = = TRUE , " LB_SETITEMDATA returned %d instead of TRUE \n " , r ) ;
2013-10-23 07:53:49 +02:00
r = SendMessageA ( hList , LB_GETITEMDATA , 0 , 0 ) ;
2007-08-14 18:35:18 +02:00
ok ( r = = 20 , " get item data failed \n " ) ;
DestroyWindow ( hList ) ;
}
2008-11-20 19:52:03 +01:00
static void test_listbox_LB_DIR ( void )
2007-11-11 00:09:41 +01:00
{
2018-11-07 12:52:35 +01:00
char path [ MAX_PATH ] , curdir [ MAX_PATH ] ;
2007-11-11 00:09:41 +01:00
HWND hList ;
int res , itemCount ;
int itemCount_justFiles ;
int itemCount_justDrives ;
int itemCount_allFiles ;
2008-08-04 23:04:47 +02:00
int itemCount_allDirs ;
2007-11-11 00:09:41 +01:00
int i ;
char pathBuffer [ MAX_PATH ] ;
char * p ;
char driveletter ;
2009-02-13 13:01:12 +01:00
const char * wildcard = " * " ;
2008-02-08 09:45:31 +01:00
HANDLE file ;
2018-11-07 12:52:35 +01:00
BOOL ret ;
GetCurrentDirectoryA ( ARRAY_SIZE ( curdir ) , curdir ) ;
GetTempPathA ( ARRAY_SIZE ( path ) , path ) ;
ret = SetCurrentDirectoryA ( path ) ;
ok ( ret , " Failed to set current directory. \n " ) ;
ret = CreateDirectoryA ( " lb_dir_test " , NULL ) ;
ok ( ret , " Failed to create test directory. \n " ) ;
2008-02-08 09:45:31 +01:00
2008-03-07 21:34:13 +01:00
file = CreateFileA ( " wtest1.tmp.c " , GENERIC_READ | GENERIC_WRITE , 0 , NULL , CREATE_NEW , FILE_ATTRIBUTE_NORMAL , NULL ) ;
2008-02-10 00:30:21 +01:00
ok ( file ! = INVALID_HANDLE_VALUE , " Error creating the test file: %d \n " , GetLastError ( ) ) ;
2008-02-08 09:45:31 +01:00
CloseHandle ( file ) ;
2007-11-11 00:09:41 +01:00
/* NOTE: for this test to succeed, there must be no subdirectories
under the current directory . In addition , there must be at least
one file that fits the wildcard w * . c . Normally , the test
directory itself satisfies both conditions .
*/
2013-10-23 07:53:49 +02:00
hList = CreateWindowA ( " ListBox " , " list test " , WS_VISIBLE | WS_POPUP ,
2007-11-11 00:09:41 +01:00
1 , 1 , 600 , 100 , NULL , NULL , NULL , NULL ) ;
assert ( hList ) ;
/* Test for standard usage */
/* This should list all the files in the test directory. */
2009-02-13 13:01:12 +01:00
strcpy ( pathBuffer , wildcard ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , 0 , ( LPARAM ) pathBuffer ) ;
2008-09-24 15:39:03 +02:00
if ( res = = - 1 ) /* "*" wildcard doesn't work on win9x */
{
2009-02-13 13:01:12 +01:00
wildcard = " *.* " ;
strcpy ( pathBuffer , wildcard ) ;
2013-10-23 07:53:49 +02:00
res = SendMessageA ( hList , LB_DIR , 0 , ( LPARAM ) pathBuffer ) ;
2008-09-24 15:39:03 +02:00
}
2007-11-11 00:09:41 +01:00
ok ( res > = 0 , " SendMessage(LB_DIR, 0, *) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* There should be some content in the listbox */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:41 +01:00
ok ( itemCount > 0 , " SendMessage(LB_DIR) did NOT fill the listbox! \n " ) ;
itemCount_allFiles = itemCount ;
ok ( res + 1 = = itemCount ,
" SendMessage(LB_DIR, 0, *) returned incorrect index (expected %d got %d)! \n " ,
itemCount - 1 , res ) ;
2007-12-19 16:57:18 +01:00
/* This tests behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , 0 , ( LPARAM ) pathBuffer ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = - 1 , " SendMessage(LB_DIR, 0, %s) returned %d, expected -1 \n " , BAD_EXTENSION , res ) ;
2007-12-19 16:57:18 +01:00
/* There should be NO content in the listbox */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = 0 , " SendMessage(LB_DIR) DID fill the listbox! \n " ) ;
2007-11-11 00:09:41 +01:00
/* This should list all the w*.c files in the test directory
* As of this writing , this includes win . c , winstation . c , wsprintf . c
*/
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , 0 , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res > = 0 , " SendMessage(LB_DIR, 0, w*.c) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* Path specification does NOT converted to uppercase */
ok ( ! strcmp ( pathBuffer , " w*.c " ) ,
" expected no change to pathBuffer, got %s \n " , pathBuffer ) ;
/* There should be some content in the listbox */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:41 +01:00
ok ( itemCount > 0 , " SendMessage(LB_DIR) did NOT fill the listbox! \n " ) ;
itemCount_justFiles = itemCount ;
ok ( res + 1 = = itemCount ,
" SendMessage(LB_DIR, 0, w*.c) returned incorrect index (expected %d got %d)! \n " ,
itemCount - 1 , res ) ;
/* Every single item in the control should start with a w and end in .c */
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
p = pathBuffer + strlen ( pathBuffer ) ;
ok ( ( ( pathBuffer [ 0 ] = = ' w ' | | pathBuffer [ 0 ] = = ' W ' ) & &
( * ( p - 1 ) = = ' c ' | | * ( p - 1 ) = = ' C ' ) & &
( * ( p - 2 ) = = ' . ' ) ) , " Element %d (%s) does not fit requested w*.c \n " , i , pathBuffer ) ;
}
/* Test DDL_DIRECTORY */
2009-02-13 13:01:12 +01:00
strcpy ( pathBuffer , wildcard ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res > 0 , " SendMessage(LB_DIR, DDL_DIRECTORY, *) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* There should be some content in the listbox.
* All files plus " [..] "
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
itemCount_allDirs = itemCount - itemCount_allFiles ;
ok ( itemCount > itemCount_allFiles ,
" SendMessage(LB_DIR, DDL_DIRECTORY, *) filled with %d entries, expected > %d \n " ,
itemCount , itemCount_allFiles ) ;
2007-11-11 00:09:41 +01:00
ok ( res + 1 = = itemCount ,
" SendMessage(LB_DIR, DDL_DIRECTORY, *) returned incorrect index (expected %d got %d)! \n " ,
itemCount - 1 , res ) ;
2007-12-19 16:57:18 +01:00
/* This tests behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY , ( LPARAM ) pathBuffer ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = - 1 , " SendMessage(LB_DIR, DDL_DIRECTORY, %s) returned %d, expected -1 \n " , BAD_EXTENSION , res ) ;
2007-12-19 16:57:18 +01:00
/* There should be NO content in the listbox */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = 0 , " SendMessage(LB_DIR) DID fill the listbox! \n " ) ;
2007-11-11 00:09:41 +01:00
/* Test DDL_DIRECTORY */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res > = 0 , " SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* There should be some content in the listbox. Since the parent directory does not
* fit w * . c , there should be exactly the same number of items as without DDL_DIRECTORY
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:41 +01:00
ok ( itemCount = = itemCount_justFiles ,
" SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) filled with %d entries, expected %d \n " ,
itemCount , itemCount_justFiles ) ;
ok ( res + 1 = = itemCount ,
" SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) returned incorrect index (expected %d got %d)! \n " ,
itemCount - 1 , res ) ;
/* Every single item in the control should start with a w and end in .c. */
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
p = pathBuffer + strlen ( pathBuffer ) ;
ok (
( ( pathBuffer [ 0 ] = = ' w ' | | pathBuffer [ 0 ] = = ' W ' ) & &
( * ( p - 1 ) = = ' c ' | | * ( p - 1 ) = = ' C ' ) & &
( * ( p - 2 ) = = ' . ' ) ) , " Element %d (%s) does not fit requested w*.c \n " , i , pathBuffer ) ;
}
/* Test DDL_DRIVES|DDL_EXCLUSIVE */
2009-02-13 13:01:12 +01:00
strcpy ( pathBuffer , wildcard ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DRIVES | DDL_EXCLUSIVE , ( LPARAM ) pathBuffer ) ;
2008-11-20 19:52:03 +01:00
ok ( res > = 0 , " SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) failed - 0x%08x \n " , GetLastError ( ) ) ;
2007-11-11 00:09:41 +01:00
/* There should be some content in the listbox. In particular, there should
* be at least one element before , since the string " [-c-] " should
* have been added . Depending on the user setting , more drives might have
* been added .
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:41 +01:00
ok ( itemCount > = 1 ,
" SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) filled with %d entries, expected at least %d \n " ,
itemCount , 1 ) ;
itemCount_justDrives = itemCount ;
ok ( res + 1 = = itemCount , " SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) returned incorrect index! \n " ) ;
/* Every single item in the control should fit the format [-c-] */
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( strlen ( pathBuffer ) = = 5 , " Length of drive string is not 5 \n " ) ;
ok ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 , " Element %d (%s) does not fit [-X-] \n " , i , pathBuffer ) ;
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
if ( ! ( driveletter > = ' a ' & & driveletter < = ' z ' ) ) {
/* Correct after invalid entry is found */
trace ( " removing count of invalid entry %s \n " , pathBuffer ) ;
itemCount_justDrives - - ;
}
}
2007-12-19 16:57:18 +01:00
/* This tests behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DRIVES | DDL_EXCLUSIVE , ( LPARAM ) pathBuffer ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = itemCount_justDrives - 1 , " SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, %s) returned %d, expected %d \n " ,
BAD_EXTENSION , res , itemCount_justDrives - 1 ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = itemCount_justDrives , " SendMessage(LB_DIR) returned %d expected %d \n " ,
itemCount , itemCount_justDrives ) ;
2007-11-11 00:09:41 +01:00
trace ( " Files with w*.c: %d Mapped drives: %d Directories: 1 \n " ,
itemCount_justFiles , itemCount_justDrives ) ;
/* Test DDL_DRIVES. */
2009-02-13 13:01:12 +01:00
strcpy ( pathBuffer , wildcard ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DRIVES , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res > 0 , " SendMessage(LB_DIR, DDL_DRIVES, *) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* There should be some content in the listbox. In particular, there should
* be at least one element before , since the string " [-c-] " should
* have been added . Depending on the user setting , more drives might have
* been added .
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2009-02-13 13:01:12 +01:00
ok ( itemCount = = itemCount_justDrives + itemCount_allFiles ,
2008-11-20 19:52:03 +01:00
" SendMessage(LB_DIR, DDL_DRIVES, *) filled with %d entries, expected %d \n " ,
2007-11-11 00:09:41 +01:00
itemCount , itemCount_justDrives + itemCount_allFiles ) ;
2008-11-20 19:52:03 +01:00
ok ( res + 1 = = itemCount , " SendMessage(LB_DIR, DDL_DRIVES, *) returned incorrect index! \n " ) ;
2007-11-11 00:09:41 +01:00
2007-12-19 16:57:18 +01:00
/* This tests behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DRIVES , ( LPARAM ) pathBuffer ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = itemCount_justDrives - 1 , " SendMessage(LB_DIR, DDL_DRIVES, %s) returned %d, expected %d \n " ,
BAD_EXTENSION , res , itemCount_justDrives - 1 ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = res + 1 , " SendMessage(LB_DIR) returned %d expected %d \n " , itemCount , res + 1 ) ;
2007-11-11 00:09:41 +01:00
/* Test DDL_DRIVES. */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DRIVES , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res > 0 , " SendMessage(LB_DIR, DDL_DRIVES, w*.c) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* There should be some content in the listbox. In particular, there should
* be at least one element before , since the string " [-c-] " should
* have been added . Depending on the user setting , more drives might have
* been added .
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:41 +01:00
ok ( itemCount = = itemCount_justDrives + itemCount_justFiles ,
" SendMessage(LB_DIR, DDL_DRIVES, w*.c) filled with %d entries, expected %d \n " ,
itemCount , itemCount_justDrives + itemCount_justFiles ) ;
ok ( res + 1 = = itemCount , " SendMessage(LB_DIR, DDL_DRIVES, w*.c) returned incorrect index! \n " ) ;
/* Every single item in the control should fit the format [-c-], or w*.c */
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
p = pathBuffer + strlen ( pathBuffer ) ;
if ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 ) {
ok ( strlen ( pathBuffer ) = = 5 , " Length of drive string is not 5 \n " ) ;
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
} else {
ok (
( ( pathBuffer [ 0 ] = = ' w ' | | pathBuffer [ 0 ] = = ' W ' ) & &
( * ( p - 1 ) = = ' c ' | | * ( p - 1 ) = = ' C ' ) & &
( * ( p - 2 ) = = ' . ' ) ) , " Element %d (%s) does not fit requested w*.c \n " , i , pathBuffer ) ;
}
}
/* Test DDL_DIRECTORY|DDL_DRIVES. This does *not* imply DDL_EXCLUSIVE */
2009-02-13 13:01:12 +01:00
strcpy ( pathBuffer , wildcard ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_DRIVES , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res > 0 , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, *) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* There should be some content in the listbox. In particular, there should
* be exactly the number of plain files , plus the number of mapped drives .
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2009-02-13 13:01:12 +01:00
ok ( itemCount = = itemCount_allFiles + itemCount_justDrives + itemCount_allDirs ,
2007-11-11 00:09:41 +01:00
" SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d \n " ,
2008-08-04 23:04:47 +02:00
itemCount , itemCount_allFiles + itemCount_justDrives + itemCount_allDirs ) ;
2007-11-11 00:09:41 +01:00
ok ( res + 1 = = itemCount , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) returned incorrect index! \n " ) ;
/* Every single item in the control should start with a w and end in .c,
* except for the " [..] " string , which should appear exactly as it is ,
* and the mapped drives in the format " [-X-] " .
*/
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
if ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 ) {
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
}
}
2007-12-19 16:57:18 +01:00
/* This tests behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_DRIVES , ( LPARAM ) pathBuffer ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = itemCount_justDrives - 1 , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, %s) returned %d, expected %d \n " ,
BAD_EXTENSION , res , itemCount_justDrives - 1 ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = res + 1 , " SendMessage(LB_DIR) returned %d expected %d \n " , itemCount , res + 1 ) ;
2007-11-11 00:09:41 +01:00
/* Test DDL_DIRECTORY|DDL_DRIVES. */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_DRIVES , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res > 0 , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* There should be some content in the listbox. In particular, there should
* be exactly the number of plain files , plus the number of mapped drives .
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:41 +01:00
ok ( itemCount = = itemCount_justFiles + itemCount_justDrives ,
" SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d \n " ,
itemCount , itemCount_justFiles + itemCount_justDrives ) ;
ok ( res + 1 = = itemCount , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) returned incorrect index! \n " ) ;
/* Every single item in the control should start with a w and end in .c,
* except the mapped drives in the format " [-X-] " . The " [..] " directory
* should not appear .
*/
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
p = pathBuffer + strlen ( pathBuffer ) ;
if ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 ) {
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
} else {
ok (
( ( pathBuffer [ 0 ] = = ' w ' | | pathBuffer [ 0 ] = = ' W ' ) & &
( * ( p - 1 ) = = ' c ' | | * ( p - 1 ) = = ' C ' ) & &
( * ( p - 2 ) = = ' . ' ) ) , " Element %d (%s) does not fit requested w*.c \n " , i , pathBuffer ) ;
}
}
/* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
2009-02-13 13:01:12 +01:00
strcpy ( pathBuffer , wildcard ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_EXCLUSIVE , ( LPARAM ) pathBuffer ) ;
2008-08-04 23:04:47 +02:00
ok ( res ! = - 1 , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) failed err %u \n " , GetLastError ( ) ) ;
2007-11-11 00:09:41 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_allDirs ,
2007-11-11 00:09:41 +01:00
" SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d \n " ,
2008-08-04 23:04:47 +02:00
itemCount , itemCount_allDirs ) ;
2007-11-11 00:09:41 +01:00
ok ( res + 1 = = itemCount , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) returned incorrect index! \n " ) ;
2018-11-07 12:52:35 +01:00
if ( itemCount )
2008-11-20 19:52:03 +01:00
{
memset ( pathBuffer , 0 , MAX_PATH ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , 0 , ( LPARAM ) pathBuffer ) ;
2018-11-07 12:52:35 +01:00
ok ( ! strcmp ( pathBuffer , " [..] " ) , " First element is %s, not [..] \n " , pathBuffer ) ;
2008-11-20 19:52:03 +01:00
}
2007-11-11 00:09:41 +01:00
2007-12-19 16:57:18 +01:00
/* This tests behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_EXCLUSIVE , ( LPARAM ) pathBuffer ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = - 1 , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, %s) returned %d, expected %d \n " ,
BAD_EXTENSION , res , - 1 ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = res + 1 , " SendMessage(LB_DIR) returned %d expected %d \n " , itemCount , res + 1 ) ;
2007-11-11 00:09:41 +01:00
/* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_EXCLUSIVE , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res = = LB_ERR , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, w*.c) returned %d expected %d \n " , res , LB_ERR ) ;
/* There should be no elements, since "[..]" does not fit w*.c */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:41 +01:00
ok ( itemCount = = 0 ,
" SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d \n " ,
itemCount , 0 ) ;
/* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
2009-02-13 13:01:12 +01:00
strcpy ( pathBuffer , wildcard ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_DRIVES | DDL_EXCLUSIVE , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( res > 0 , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c,) failed - 0x%08x \n " , GetLastError ( ) ) ;
/* There should be no plain files on the listbox */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_justDrives + itemCount_allDirs ,
2007-11-11 00:09:41 +01:00
" SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) filled with %d entries, expected %d \n " ,
2008-08-04 23:04:47 +02:00
itemCount , itemCount_justDrives + itemCount_allDirs ) ;
2007-11-11 00:09:41 +01:00
ok ( res + 1 = = itemCount , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c) returned incorrect index! \n " ) ;
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
if ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 ) {
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
} else {
2008-08-04 23:04:47 +02:00
ok ( pathBuffer [ 0 ] = = ' [ ' & & pathBuffer [ strlen ( pathBuffer ) - 1 ] = = ' ] ' ,
" Element %d (%s) does not fit expected [...] \n " , i , pathBuffer ) ;
2007-11-11 00:09:41 +01:00
}
}
2007-12-19 16:57:18 +01:00
/* This tests behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_DRIVES | DDL_EXCLUSIVE , ( LPARAM ) pathBuffer ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = itemCount_justDrives - 1 , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, %s) returned %d, expected %d \n " ,
BAD_EXTENSION , res , itemCount_justDrives - 1 ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = res + 1 , " SendMessage(LB_DIR) returned %d expected %d \n " , itemCount , res + 1 ) ;
2007-11-11 00:09:41 +01:00
/* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_RESETCONTENT , 0 , 0 ) ;
res = SendMessageA ( hList , LB_DIR , DDL_DIRECTORY | DDL_DRIVES | DDL_EXCLUSIVE , ( LPARAM ) pathBuffer ) ;
2008-11-20 19:52:03 +01:00
ok ( res > = 0 , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c,) failed - 0x%08x \n " , GetLastError ( ) ) ;
2007-11-11 00:09:41 +01:00
/* There should be no plain files on the listbox, and no [..], since it does not fit w*.c */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( hList , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:41 +01:00
ok ( itemCount = = itemCount_justDrives ,
" SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) filled with %d entries, expected %d \n " ,
itemCount , itemCount_justDrives ) ;
ok ( res + 1 = = itemCount , " SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c) returned incorrect index! \n " ) ;
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( hList , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:41 +01:00
ok ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 , " Element %d (%s) does not fit [-X-] \n " , i , pathBuffer ) ;
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
}
DestroyWindow ( hList ) ;
2008-02-08 09:45:31 +01:00
DeleteFileA ( " wtest1.tmp.c " ) ;
2018-11-07 12:52:35 +01:00
RemoveDirectoryA ( " lb_dir_test " ) ;
SetCurrentDirectoryA ( curdir ) ;
2007-11-11 00:09:41 +01:00
}
2010-10-01 13:37:44 +02:00
static HWND g_listBox ;
static HWND g_label ;
2007-11-11 00:09:45 +01:00
# define ID_TEST_LABEL 1001
# define ID_TEST_LISTBOX 1002
2013-10-23 07:53:49 +02:00
static BOOL on_listbox_container_create ( HWND hwnd , LPCREATESTRUCTA lpcs )
2007-11-11 00:09:45 +01:00
{
2013-10-23 07:53:49 +02:00
g_label = CreateWindowA (
2007-11-11 00:09:45 +01:00
" Static " ,
" Contents of static control before DlgDirList. " ,
WS_CHILD | WS_VISIBLE ,
10 , 10 , 512 , 32 ,
hwnd , ( HMENU ) ID_TEST_LABEL , NULL , 0 ) ;
if ( ! g_label ) return FALSE ;
2013-10-23 07:53:49 +02:00
g_listBox = CreateWindowA (
2007-11-11 00:09:45 +01:00
" ListBox " ,
" DlgDirList test " ,
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_VSCROLL ,
10 , 60 , 256 , 256 ,
hwnd , ( HMENU ) ID_TEST_LISTBOX , NULL , 0 ) ;
if ( ! g_listBox ) return FALSE ;
return TRUE ;
}
static LRESULT CALLBACK listbox_container_window_procA (
HWND hwnd , UINT uiMsg , WPARAM wParam , LPARAM lParam )
{
LRESULT result = 0 ;
switch ( uiMsg ) {
case WM_DESTROY :
PostQuitMessage ( 0 ) ;
break ;
case WM_CREATE :
result = on_listbox_container_create ( hwnd , ( LPCREATESTRUCTA ) lParam )
? 0 : ( LRESULT ) - 1 ;
break ;
default :
result = DefWindowProcA ( hwnd , uiMsg , wParam , lParam ) ;
break ;
}
return result ;
}
static BOOL RegisterListboxWindowClass ( HINSTANCE hInst )
{
WNDCLASSA cls ;
cls . style = 0 ;
cls . cbClsExtra = 0 ;
cls . cbWndExtra = 0 ;
cls . hInstance = hInst ;
cls . hIcon = NULL ;
2013-10-23 07:53:49 +02:00
cls . hCursor = LoadCursorA ( NULL , ( LPCSTR ) IDC_ARROW ) ;
2007-11-11 00:09:45 +01:00
cls . hbrBackground = ( HBRUSH ) ( COLOR_WINDOW + 1 ) ;
cls . lpszMenuName = NULL ;
cls . lpfnWndProc = listbox_container_window_procA ;
cls . lpszClassName = " ListboxContainerClass " ;
if ( ! RegisterClassA ( & cls ) ) return FALSE ;
return TRUE ;
}
static void test_listbox_dlgdir ( void )
{
HINSTANCE hInst ;
HWND hWnd ;
int res , itemCount ;
2008-08-04 23:04:47 +02:00
int itemCount_allDirs ;
2007-11-11 00:09:45 +01:00
int itemCount_justFiles ;
int itemCount_justDrives ;
int i ;
char pathBuffer [ MAX_PATH ] ;
char itemBuffer [ MAX_PATH ] ;
char tempBuffer [ MAX_PATH ] ;
char * p ;
char driveletter ;
2008-02-08 09:45:31 +01:00
HANDLE file ;
2008-03-07 21:34:13 +01:00
file = CreateFileA ( " wtest1.tmp.c " , GENERIC_READ | GENERIC_WRITE , 0 , NULL , CREATE_NEW , FILE_ATTRIBUTE_NORMAL , NULL ) ;
2008-02-10 00:30:21 +01:00
ok ( file ! = INVALID_HANDLE_VALUE , " Error creating the test file: %d \n " , GetLastError ( ) ) ;
2008-02-08 09:45:31 +01:00
CloseHandle ( file ) ;
2007-11-11 00:09:45 +01:00
/* NOTE: for this test to succeed, there must be no subdirectories
under the current directory . In addition , there must be at least
one file that fits the wildcard w * . c . Normally , the test
directory itself satisfies both conditions .
*/
hInst = GetModuleHandleA ( 0 ) ;
if ( ! RegisterListboxWindowClass ( hInst ) ) assert ( 0 ) ;
2013-10-23 07:53:49 +02:00
hWnd = CreateWindowA ( " ListboxContainerClass " , " ListboxContainerClass " ,
2007-11-11 00:09:45 +01:00
WS_OVERLAPPEDWINDOW | WS_VISIBLE ,
CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT ,
NULL , NULL , hInst , 0 ) ;
assert ( hWnd ) ;
/* Test for standard usage */
/* The following should be overwritten by the directory path */
2013-10-23 07:53:49 +02:00
SendMessageA ( g_label , WM_SETTEXT , 0 , ( LPARAM ) " default contents " ) ;
2007-11-11 00:09:45 +01:00
/* This should list all the w*.c files in the test directory
* As of this writing , this includes win . c , winstation . c , wsprintf . c
*/
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( res = = 1 , " DlgDirList(*.c, 0) returned %d - expected 1 - 0x%08x \n " , res , GetLastError ( ) ) ;
2007-11-11 00:09:45 +01:00
/* Path specification gets converted to uppercase */
ok ( ! strcmp ( pathBuffer , " W*.C " ) ,
" expected conversion to uppercase, got %s \n " , pathBuffer ) ;
/* Loaded path should have overwritten the label text */
2013-10-23 07:53:49 +02:00
SendMessageA ( g_label , WM_GETTEXT , MAX_PATH , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:45 +01:00
trace ( " Static control after DlgDirList: %s \n " , pathBuffer ) ;
2007-11-20 13:47:10 +01:00
ok ( strcmp ( " default contents " , pathBuffer ) , " DlgDirList() did not modify static control! \n " ) ;
2007-11-11 00:09:45 +01:00
/* There should be some content in the listbox */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:45 +01:00
ok ( itemCount > 0 , " DlgDirList() did NOT fill the listbox! \n " ) ;
itemCount_justFiles = itemCount ;
/* Every single item in the control should start with a w and end in .c */
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:45 +01:00
p = pathBuffer + strlen ( pathBuffer ) ;
ok ( ( ( pathBuffer [ 0 ] = = ' w ' | | pathBuffer [ 0 ] = = ' W ' ) & &
( * ( p - 1 ) = = ' c ' | | * ( p - 1 ) = = ' C ' ) & &
( * ( p - 2 ) = = ' . ' ) ) , " Element %d (%s) does not fit requested w*.c \n " , i , pathBuffer ) ;
}
2007-12-19 16:57:18 +01:00
/* Test behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL , 0 ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = 1 , " DlgDirList(%s, 0) returned %d expected 1 \n " , BAD_EXTENSION , res ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = 0 , " DlgDirList() DID fill the listbox! \n " ) ;
2007-11-11 00:09:45 +01:00
/* Test DDL_DIRECTORY */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-11-11 00:09:45 +01:00
DDL_DIRECTORY ) ;
2007-12-19 16:57:18 +01:00
ok ( res = = 1 , " DlgDirList(*.c, DDL_DIRECTORY) failed - 0x%08x \n " , GetLastError ( ) ) ;
2007-11-11 00:09:45 +01:00
/* There should be some content in the listbox. In particular, there should
2008-08-04 23:04:47 +02:00
* be exactly more elements than before , since the directories should
2007-11-11 00:09:45 +01:00
* have been added .
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
itemCount_allDirs = itemCount - itemCount_justFiles ;
ok ( itemCount > = itemCount_justFiles ,
" DlgDirList(DDL_DIRECTORY) filled with %d entries, expected > %d \n " ,
itemCount , itemCount_justFiles ) ;
2007-11-11 00:09:45 +01:00
/* Every single item in the control should start with a w and end in .c,
* except for the " [..] " string , which should appear exactly as it is .
*/
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:45 +01:00
p = pathBuffer + strlen ( pathBuffer ) ;
2008-08-04 23:04:47 +02:00
ok ( ( pathBuffer [ 0 ] = = ' [ ' & & pathBuffer [ strlen ( pathBuffer ) - 1 ] = = ' ] ' ) | |
2007-11-11 00:09:45 +01:00
( ( pathBuffer [ 0 ] = = ' w ' | | pathBuffer [ 0 ] = = ' W ' ) & &
( * ( p - 1 ) = = ' c ' | | * ( p - 1 ) = = ' C ' ) & &
( * ( p - 2 ) = = ' . ' ) ) , " Element %d (%s) does not fit requested w*.c \n " , i , pathBuffer ) ;
}
2007-12-19 16:57:18 +01:00
/* Test behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-12-19 16:57:18 +01:00
DDL_DIRECTORY ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = 1 , " DlgDirList(%s, DDL_DIRECTORY) returned %d expected 1 \n " , BAD_EXTENSION , res ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_allDirs ,
" DlgDirList() incorrectly filled the listbox! (expected %d got %d) \n " ,
itemCount_allDirs , itemCount ) ;
2007-12-19 16:57:18 +01:00
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2008-08-04 23:04:47 +02:00
ok ( pathBuffer [ 0 ] = = ' [ ' & & pathBuffer [ strlen ( pathBuffer ) - 1 ] = = ' ] ' ,
" Element %d (%s) does not fit requested [...] \n " , i , pathBuffer ) ;
2007-12-19 16:57:18 +01:00
}
2007-11-11 00:09:45 +01:00
/* Test DDL_DRIVES. At least on WinXP-SP2, this implies DDL_EXCLUSIVE */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-11-11 00:09:45 +01:00
DDL_DRIVES ) ;
2007-12-19 16:57:18 +01:00
ok ( res = = 1 , " DlgDirList(*.c, DDL_DRIVES) failed - 0x%08x \n " , GetLastError ( ) ) ;
2007-11-11 00:09:45 +01:00
/* There should be some content in the listbox. In particular, there should
* be at least one element before , since the string " [-c-] " should
* have been added . Depending on the user setting , more drives might have
* been added .
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:45 +01:00
ok ( itemCount > = 1 ,
" DlgDirList(DDL_DRIVES) filled with %d entries, expected at least %d \n " ,
itemCount , 1 ) ;
itemCount_justDrives = itemCount ;
/* Every single item in the control should fit the format [-c-] */
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:45 +01:00
ok ( strlen ( pathBuffer ) = = 5 , " Length of drive string is not 5 \n " ) ;
ok ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 , " Element %d (%s) does not fit [-X-] \n " , i , pathBuffer ) ;
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
if ( ! ( driveletter > = ' a ' & & driveletter < = ' z ' ) ) {
/* Correct after invalid entry is found */
trace ( " removing count of invalid entry %s \n " , pathBuffer ) ;
itemCount_justDrives - - ;
}
}
2007-12-19 16:57:18 +01:00
/* Test behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-12-19 16:57:18 +01:00
DDL_DRIVES ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = 1 , " DlgDirList(%s, DDL_DRIVES) returned %d expected 1 \n " , BAD_EXTENSION , res ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2007-12-19 16:57:18 +01:00
ok ( itemCount = = itemCount_justDrives , " DlgDirList() incorrectly filled the listbox! \n " ) ;
2007-11-11 00:09:45 +01:00
/* Test DDL_DIRECTORY|DDL_DRIVES. This does *not* imply DDL_EXCLUSIVE */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-11-11 00:09:45 +01:00
DDL_DIRECTORY | DDL_DRIVES ) ;
2007-12-19 16:57:18 +01:00
ok ( res = = 1 , " DlgDirList(*.c, DDL_DIRECTORY|DDL_DRIVES) failed - 0x%08x \n " , GetLastError ( ) ) ;
2007-11-11 00:09:45 +01:00
/* There should be some content in the listbox. In particular, there should
* be exactly the number of plain files , plus the number of mapped drives ,
* plus one " [..] "
*/
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_justFiles + itemCount_justDrives + itemCount_allDirs ,
2007-11-11 00:09:45 +01:00
" DlgDirList(DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d \n " ,
2008-08-04 23:04:47 +02:00
itemCount , itemCount_justFiles + itemCount_justDrives + itemCount_allDirs ) ;
2007-11-11 00:09:45 +01:00
/* Every single item in the control should start with a w and end in .c,
* except for the " [..] " string , which should appear exactly as it is ,
* and the mapped drives in the format " [-X-] " .
*/
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:45 +01:00
p = pathBuffer + strlen ( pathBuffer ) ;
if ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 ) {
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
} else {
2008-08-04 23:04:47 +02:00
ok ( ( pathBuffer [ 0 ] = = ' [ ' & & pathBuffer [ strlen ( pathBuffer ) - 1 ] = = ' ] ' ) | |
2007-11-11 00:09:45 +01:00
( ( pathBuffer [ 0 ] = = ' w ' | | pathBuffer [ 0 ] = = ' W ' ) & &
( * ( p - 1 ) = = ' c ' | | * ( p - 1 ) = = ' C ' ) & &
( * ( p - 2 ) = = ' . ' ) ) , " Element %d (%s) does not fit requested w*.c \n " , i , pathBuffer ) ;
}
}
2007-12-19 16:57:18 +01:00
/* Test behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-12-19 16:57:18 +01:00
DDL_DIRECTORY | DDL_DRIVES ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = 1 , " DlgDirList(%s, DDL_DIRECTORY|DDL_DRIVES) returned %d expected 1 \n " , BAD_EXTENSION , res ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_justDrives + itemCount_allDirs ,
2007-12-19 16:57:18 +01:00
" DlgDirList() incorrectly filled the listbox! (expected %d got %d) \n " ,
2008-08-04 23:04:47 +02:00
itemCount_justDrives + itemCount_allDirs , itemCount ) ;
2007-12-19 16:57:18 +01:00
2007-11-11 00:09:45 +01:00
/* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-11-11 00:09:45 +01:00
DDL_DIRECTORY | DDL_EXCLUSIVE ) ;
2007-12-19 16:57:18 +01:00
ok ( res = = 1 , " DlgDirList(*.c, DDL_DIRECTORY|DDL_EXCLUSIVE) failed - 0x%08x \n " , GetLastError ( ) ) ;
2007-11-11 00:09:45 +01:00
/* There should be exactly one element: "[..]" */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_allDirs ,
2007-11-11 00:09:45 +01:00
" DlgDirList(DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d \n " ,
2008-08-04 23:04:47 +02:00
itemCount , itemCount_allDirs ) ;
2007-11-11 00:09:45 +01:00
2008-11-20 19:52:03 +01:00
if ( itemCount & & GetCurrentDirectoryA ( MAX_PATH , pathBuffer ) > 3 ) /* there's no [..] in drive root */
{
memset ( pathBuffer , 0 , MAX_PATH ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , 0 , ( LPARAM ) pathBuffer ) ;
2008-11-20 19:52:03 +01:00
ok ( ! strcmp ( pathBuffer , " [..] " ) , " First (and only) element is not [..] \n " ) ;
}
2007-12-19 16:57:18 +01:00
/* Test behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-12-19 16:57:18 +01:00
DDL_DIRECTORY | DDL_EXCLUSIVE ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = 1 , " DlgDirList(%s, DDL_DIRECTORY|DDL_EXCLUSIVE) returned %d expected 1 \n " , BAD_EXTENSION , res ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_allDirs , " DlgDirList() incorrectly filled the listbox! \n " ) ;
2007-12-19 16:57:18 +01:00
2007-11-11 00:09:45 +01:00
/* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
strcpy ( pathBuffer , " w*.c " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-11-11 00:09:45 +01:00
DDL_DIRECTORY | DDL_DRIVES | DDL_EXCLUSIVE ) ;
2007-12-19 16:57:18 +01:00
ok ( res = = 1 , " DlgDirList(*.c, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) failed - 0x%08x \n " , GetLastError ( ) ) ;
2007-11-11 00:09:45 +01:00
/* There should be no plain files on the listbox */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_justDrives + itemCount_allDirs ,
2007-11-11 00:09:45 +01:00
" DlgDirList(DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d \n " ,
2008-08-04 23:04:47 +02:00
itemCount , itemCount_justDrives + itemCount_allDirs ) ;
2007-11-11 00:09:45 +01:00
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( pathBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , i , ( LPARAM ) pathBuffer ) ;
2007-11-11 00:09:45 +01:00
if ( sscanf ( pathBuffer , " [-%c-] " , & driveletter ) = = 1 ) {
ok ( driveletter > = ' a ' & & driveletter < = ' z ' , " Drive letter not in range a..z, got ascii %d \n " , driveletter ) ;
} else {
2008-08-04 23:04:47 +02:00
ok ( pathBuffer [ 0 ] = = ' [ ' & & pathBuffer [ strlen ( pathBuffer ) - 1 ] = = ' ] ' ,
" Element %d (%s) does not fit expected [...] \n " , i , pathBuffer ) ;
2007-11-11 00:09:45 +01:00
}
}
2007-12-19 16:57:18 +01:00
/* Test behavior when no files match the wildcard */
2008-04-04 09:03:28 +02:00
strcpy ( pathBuffer , BAD_EXTENSION ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-12-19 16:57:18 +01:00
DDL_DIRECTORY | DDL_DRIVES | DDL_EXCLUSIVE ) ;
2008-04-04 09:03:28 +02:00
ok ( res = = 1 , " DlgDirList(%s, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) returned %d expected 1 \n " , BAD_EXTENSION , res ) ;
2007-12-19 16:57:18 +01:00
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2008-08-04 23:04:47 +02:00
ok ( itemCount = = itemCount_justDrives + itemCount_allDirs ,
" DlgDirList() incorrectly filled the listbox! \n " ) ;
2007-12-19 16:57:18 +01:00
2007-11-11 00:09:45 +01:00
/* Now test DlgDirSelectEx() in normal operation */
/* Fill with everything - drives, directory and all plain files. */
strcpy ( pathBuffer , " * " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , ID_TEST_LABEL ,
2007-11-11 00:09:45 +01:00
DDL_DIRECTORY | DDL_DRIVES ) ;
ok ( res ! = 0 , " DlgDirList(*, DDL_DIRECTORY|DDL_DRIVES) failed - 0x%08x \n " , GetLastError ( ) ) ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_SETCURSEL , - 1 , 0 ) ; /* Unselect any current selection */
2007-11-11 00:09:45 +01:00
memset ( pathBuffer , 0 , MAX_PATH ) ;
SetLastError ( 0xdeadbeef ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirSelectExA ( hWnd , pathBuffer , MAX_PATH , ID_TEST_LISTBOX ) ;
2007-11-11 00:09:45 +01:00
ok ( GetLastError ( ) = = 0xdeadbeef ,
" DlgDirSelectEx() with no selection modified last error code from 0xdeadbeef to 0x%08x \n " ,
GetLastError ( ) ) ;
ok ( res = = 0 , " DlgDirSelectEx() with no selection returned %d, expected 0 \n " , res ) ;
/* WinXP-SP2 leaves pathBuffer untouched, but Win98 fills it with garbage. */
/*
ok ( strlen ( pathBuffer ) = = 0 , " DlgDirSelectEx() with no selection filled buffer with %s \n " , pathBuffer ) ;
*/
/* Test proper drive/dir/file recognition */
2013-10-23 07:53:49 +02:00
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:45 +01:00
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( itemBuffer , 0 , MAX_PATH ) ;
memset ( pathBuffer , 0 , MAX_PATH ) ;
memset ( tempBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , i , ( LPARAM ) itemBuffer ) ;
res = SendMessageA ( g_listBox , LB_SETCURSEL , i , 0 ) ;
ok ( res = = i , " SendMessageA(LB_SETCURSEL, %d) failed \n " , i ) ;
2007-11-11 00:09:45 +01:00
if ( sscanf ( itemBuffer , " [-%c-] " , & driveletter ) = = 1 ) {
/* Current item is a drive letter */
SetLastError ( 0xdeadbeef ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirSelectExA ( hWnd , pathBuffer , MAX_PATH , ID_TEST_LISTBOX ) ;
2007-11-11 00:09:45 +01:00
ok ( GetLastError ( ) = = 0xdeadbeef ,
" DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x \n " ,
i , GetLastError ( ) ) ;
ok ( res = = 1 , " DlgDirSelectEx() thinks %s (%s) is not a drive/directory! \n " , itemBuffer , pathBuffer ) ;
/* For drive letters, DlgDirSelectEx tacks on a colon */
ok ( pathBuffer [ 0 ] = = driveletter & & pathBuffer [ 1 ] = = ' : ' & & pathBuffer [ 2 ] = = ' \0 ' ,
" %d: got \" %s \" expected \" %c: \" \n " , i , pathBuffer , driveletter ) ;
} else if ( itemBuffer [ 0 ] = = ' [ ' ) {
/* Current item is the parent directory */
SetLastError ( 0xdeadbeef ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirSelectExA ( hWnd , pathBuffer , MAX_PATH , ID_TEST_LISTBOX ) ;
2007-11-11 00:09:45 +01:00
ok ( GetLastError ( ) = = 0xdeadbeef ,
" DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x \n " ,
i , GetLastError ( ) ) ;
ok ( res = = 1 , " DlgDirSelectEx() thinks %s (%s) is not a drive/directory! \n " , itemBuffer , pathBuffer ) ;
/* For directories, DlgDirSelectEx tacks on a backslash */
p = pathBuffer + strlen ( pathBuffer ) ;
ok ( * ( p - 1 ) = = ' \\ ' , " DlgDirSelectEx did NOT tack on a backslash to dir, got %s \n " , pathBuffer ) ;
tempBuffer [ 0 ] = ' [ ' ;
2013-10-23 07:53:49 +02:00
lstrcpynA ( tempBuffer + 1 , pathBuffer , strlen ( pathBuffer ) ) ;
2007-11-11 00:09:45 +01:00
strcat ( tempBuffer , " ] " ) ;
ok ( ! strcmp ( tempBuffer , itemBuffer ) , " Formatted directory should be %s, got %s \n " , tempBuffer , itemBuffer ) ;
} else {
/* Current item is a plain file */
SetLastError ( 0xdeadbeef ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirSelectExA ( hWnd , pathBuffer , MAX_PATH , ID_TEST_LISTBOX ) ;
2007-11-11 00:09:45 +01:00
ok ( GetLastError ( ) = = 0xdeadbeef ,
" DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x \n " ,
i , GetLastError ( ) ) ;
ok ( res = = 0 , " DlgDirSelectEx() thinks %s (%s) is a drive/directory! \n " , itemBuffer , pathBuffer ) ;
/* NOTE: WinXP tacks a period on all files that lack an extension. This affects
* for example , " Makefile " , which gets reported as " Makefile. "
*/
strcpy ( tempBuffer , itemBuffer ) ;
if ( strchr ( tempBuffer , ' . ' ) = = NULL ) strcat ( tempBuffer , " . " ) ;
ok ( ! strcmp ( pathBuffer , tempBuffer ) , " Formatted file should be %s, got %s \n " , tempBuffer , pathBuffer ) ;
}
}
2012-07-17 14:50:47 +02:00
DeleteFileA ( " wtest1.tmp.c " ) ;
2007-11-11 00:09:45 +01:00
/* Now test DlgDirSelectEx() in abnormal operation */
/* Fill list with bogus entries, that look somewhat valid */
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_RESETCONTENT , 0 , 0 ) ;
SendMessageA ( g_listBox , LB_ADDSTRING , 0 , ( LPARAM ) " [notexist.dir] " ) ;
SendMessageA ( g_listBox , LB_ADDSTRING , 0 , ( LPARAM ) " notexist.fil " ) ;
itemCount = SendMessageA ( g_listBox , LB_GETCOUNT , 0 , 0 ) ;
2007-11-11 00:09:45 +01:00
for ( i = 0 ; i < itemCount ; i + + ) {
memset ( itemBuffer , 0 , MAX_PATH ) ;
memset ( pathBuffer , 0 , MAX_PATH ) ;
memset ( tempBuffer , 0 , MAX_PATH ) ;
driveletter = ' \0 ' ;
2013-10-23 07:53:49 +02:00
SendMessageA ( g_listBox , LB_GETTEXT , i , ( LPARAM ) itemBuffer ) ;
res = SendMessageA ( g_listBox , LB_SETCURSEL , i , 0 ) ;
2007-11-11 00:09:45 +01:00
ok ( res = = i , " SendMessage(LB_SETCURSEL, %d) failed \n " , i ) ;
if ( sscanf ( itemBuffer , " [-%c-] " , & driveletter ) = = 1 ) {
/* Current item is a drive letter */
SetLastError ( 0xdeadbeef ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirSelectExA ( hWnd , pathBuffer , MAX_PATH , ID_TEST_LISTBOX ) ;
2007-11-11 00:09:45 +01:00
ok ( GetLastError ( ) = = 0xdeadbeef ,
" DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x \n " ,
i , GetLastError ( ) ) ;
ok ( res = = 1 , " DlgDirSelectEx() thinks %s (%s) is not a drive/directory! \n " , itemBuffer , pathBuffer ) ;
/* For drive letters, DlgDirSelectEx tacks on a colon */
ok ( pathBuffer [ 0 ] = = driveletter & & pathBuffer [ 1 ] = = ' : ' & & pathBuffer [ 2 ] = = ' \0 ' ,
" %d: got \" %s \" expected \" %c: \" \n " , i , pathBuffer , driveletter ) ;
} else if ( itemBuffer [ 0 ] = = ' [ ' ) {
/* Current item is the parent directory */
SetLastError ( 0xdeadbeef ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirSelectExA ( hWnd , pathBuffer , MAX_PATH , ID_TEST_LISTBOX ) ;
2007-11-11 00:09:45 +01:00
ok ( GetLastError ( ) = = 0xdeadbeef ,
" DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x \n " ,
i , GetLastError ( ) ) ;
ok ( res = = 1 , " DlgDirSelectEx() thinks %s (%s) is not a drive/directory! \n " , itemBuffer , pathBuffer ) ;
/* For directories, DlgDirSelectEx tacks on a backslash */
p = pathBuffer + strlen ( pathBuffer ) ;
ok ( * ( p - 1 ) = = ' \\ ' , " DlgDirSelectEx did NOT tack on a backslash to dir, got %s \n " , pathBuffer ) ;
tempBuffer [ 0 ] = ' [ ' ;
2013-10-23 07:53:49 +02:00
lstrcpynA ( tempBuffer + 1 , pathBuffer , strlen ( pathBuffer ) ) ;
2007-11-11 00:09:45 +01:00
strcat ( tempBuffer , " ] " ) ;
ok ( ! strcmp ( tempBuffer , itemBuffer ) , " Formatted directory should be %s, got %s \n " , tempBuffer , itemBuffer ) ;
} else {
/* Current item is a plain file */
SetLastError ( 0xdeadbeef ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirSelectExA ( hWnd , pathBuffer , MAX_PATH , ID_TEST_LISTBOX ) ;
2007-11-11 00:09:45 +01:00
ok ( GetLastError ( ) = = 0xdeadbeef ,
" DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x \n " ,
i , GetLastError ( ) ) ;
ok ( res = = 0 , " DlgDirSelectEx() thinks %s (%s) is a drive/directory! \n " , itemBuffer , pathBuffer ) ;
/* NOTE: WinXP and Win98 tack a period on all files that lack an extension.
* This affects for example , " Makefile " , which gets reported as " Makefile. "
*/
strcpy ( tempBuffer , itemBuffer ) ;
if ( strchr ( tempBuffer , ' . ' ) = = NULL ) strcat ( tempBuffer , " . " ) ;
ok ( ! strcmp ( pathBuffer , tempBuffer ) , " Formatted file should be %s, got %s \n " , tempBuffer , pathBuffer ) ;
}
}
2008-02-08 09:45:31 +01:00
2012-07-17 14:50:47 +02:00
/* Test behavior when loading folders from root with and without wildcard */
strcpy ( pathBuffer , " C: \\ " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , 0 , DDL_DIRECTORY | DDL_EXCLUSIVE ) ;
2012-07-17 14:50:47 +02:00
ok ( res | | broken ( ! res ) /* NT4/W2K */ , " DlgDirList failed to list C: \\ folders \n " ) ;
todo_wine ok ( ! strcmp ( pathBuffer , " * " ) | | broken ( ! res ) /* NT4/W2K */ ,
" DlgDirList set the invalid path spec '%s', expected '*' \n " , pathBuffer ) ;
strcpy ( pathBuffer , " C: \\ * " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , 0 , DDL_DIRECTORY | DDL_EXCLUSIVE ) ;
2012-07-17 14:50:47 +02:00
ok ( res | | broken ( ! res ) /* NT4/W2K */ , " DlgDirList failed to list C: \\ * folders \n " ) ;
ok ( ! strcmp ( pathBuffer , " * " ) | | broken ( ! res ) /* NT4/W2K */ ,
" DlgDirList set the invalid path spec '%s', expected '*' \n " , pathBuffer ) ;
/* Try loading files from an invalid folder */
SetLastError ( 0xdeadbeef ) ;
strcpy ( pathBuffer , " C: \\ INVALID$$DIR " ) ;
2013-10-23 07:53:49 +02:00
res = DlgDirListA ( hWnd , pathBuffer , ID_TEST_LISTBOX , 0 , DDL_DIRECTORY | DDL_EXCLUSIVE ) ;
2012-07-17 14:50:47 +02:00
todo_wine ok ( ! res , " DlgDirList should have failed with 0 but %d was returned \n " , res ) ;
todo_wine ok ( GetLastError ( ) = = ERROR_NO_WILDCARD_CHARACTERS ,
" GetLastError should return 0x589, got 0x%X \n " , GetLastError ( ) ) ;
DestroyWindow ( hWnd ) ;
2007-11-11 00:09:45 +01:00
}
2013-03-28 11:21:22 +01:00
static void test_set_count ( void )
{
2018-11-15 10:46:12 +01:00
static const DWORD styles [ ] =
{
LBS_OWNERDRAWFIXED ,
LBS_HASSTRINGS ,
} ;
2013-03-28 11:21:22 +01:00
HWND parent , listbox ;
2018-11-15 10:46:12 +01:00
unsigned int i ;
2013-03-28 11:21:22 +01:00
LONG ret ;
RECT r ;
parent = create_parent ( ) ;
listbox = create_listbox ( LBS_OWNERDRAWFIXED | LBS_NODATA | WS_CHILD | WS_VISIBLE , parent ) ;
UpdateWindow ( listbox ) ;
GetUpdateRect ( listbox , & r , TRUE ) ;
ok ( IsRectEmpty ( & r ) , " got non-empty rect \n " ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( listbox , LB_SETCOUNT , 100 , 0 ) ;
2013-03-28 11:21:22 +01:00
ok ( ret = = 0 , " got %d \n " , ret ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( listbox , LB_GETCOUNT , 0 , 0 ) ;
2013-03-28 11:21:22 +01:00
ok ( ret = = 100 , " got %d \n " , ret ) ;
GetUpdateRect ( listbox , & r , TRUE ) ;
ok ( ! IsRectEmpty ( & r ) , " got empty rect \n " ) ;
ValidateRect ( listbox , NULL ) ;
GetUpdateRect ( listbox , & r , TRUE ) ;
ok ( IsRectEmpty ( & r ) , " got non-empty rect \n " ) ;
2013-10-23 07:53:49 +02:00
ret = SendMessageA ( listbox , LB_SETCOUNT , 99 , 0 ) ;
2013-03-28 11:21:22 +01:00
ok ( ret = = 0 , " got %d \n " , ret ) ;
GetUpdateRect ( listbox , & r , TRUE ) ;
ok ( ! IsRectEmpty ( & r ) , " got empty rect \n " ) ;
DestroyWindow ( listbox ) ;
2018-11-15 10:46:12 +01:00
for ( i = 0 ; i < ARRAY_SIZE ( styles ) ; + + i )
{
listbox = create_listbox ( styles [ i ] | WS_CHILD | WS_VISIBLE , parent ) ;
SetLastError ( 0xdeadbeef ) ;
ret = SendMessageA ( listbox , LB_SETCOUNT , 100 , 0 ) ;
ok ( ret = = LB_ERR , " expected %d, got %d \n " , LB_ERR , ret ) ;
ok ( GetLastError ( ) = = ERROR_SETCOUNT_ON_BAD_LB , " Unexpected error %d. \n " , GetLastError ( ) ) ;
DestroyWindow ( listbox ) ;
}
2013-03-28 11:21:22 +01:00
DestroyWindow ( parent ) ;
}
2013-05-07 19:18:43 +02:00
static DWORD ( WINAPI * pGetListBoxInfo ) ( HWND ) ;
static int lb_getlistboxinfo ;
static LRESULT WINAPI listbox_subclass_proc ( HWND hwnd , UINT message , WPARAM wParam , LPARAM lParam )
{
WNDPROC oldproc = ( WNDPROC ) GetWindowLongPtrA ( hwnd , GWLP_USERDATA ) ;
if ( message = = LB_GETLISTBOXINFO )
lb_getlistboxinfo + + ;
return CallWindowProcA ( oldproc , hwnd , message , wParam , lParam ) ;
}
static void test_GetListBoxInfo ( void )
{
HWND listbox , parent ;
WNDPROC oldproc ;
DWORD ret ;
2013-10-23 07:53:49 +02:00
pGetListBoxInfo = ( void * ) GetProcAddress ( GetModuleHandleA ( " user32.dll " ) , " GetListBoxInfo " ) ;
2013-05-07 19:18:43 +02:00
if ( ! pGetListBoxInfo )
{
win_skip ( " GetListBoxInfo() not available \n " ) ;
return ;
}
parent = create_parent ( ) ;
listbox = create_listbox ( WS_CHILD | WS_VISIBLE , parent ) ;
oldproc = ( WNDPROC ) SetWindowLongPtrA ( listbox , GWLP_WNDPROC , ( LONG_PTR ) listbox_subclass_proc ) ;
SetWindowLongPtrA ( listbox , GWLP_USERDATA , ( LONG_PTR ) oldproc ) ;
lb_getlistboxinfo = 0 ;
ret = pGetListBoxInfo ( listbox ) ;
ok ( ret > 0 , " got %d \n " , ret ) ;
todo_wine
ok ( lb_getlistboxinfo = = 0 , " got %d \n " , lb_getlistboxinfo ) ;
DestroyWindow ( listbox ) ;
DestroyWindow ( parent ) ;
}
2014-02-20 12:35:18 +01:00
static void test_missing_lbuttonup ( void )
{
HWND listbox , parent , capture ;
parent = create_parent ( ) ;
listbox = create_listbox ( WS_CHILD | WS_VISIBLE , parent ) ;
/* Send button down without a corresponding button up */
SendMessageA ( listbox , WM_LBUTTONDOWN , 0 , MAKELPARAM ( 10 , 10 ) ) ;
capture = GetCapture ( ) ;
ok ( capture = = listbox , " got %p expected %p \n " , capture , listbox ) ;
/* Capture is released and LBN_SELCHANGE sent during WM_KILLFOCUS */
got_selchange = 0 ;
SetFocus ( NULL ) ;
capture = GetCapture ( ) ;
ok ( capture = = NULL , " got %p \n " , capture ) ;
ok ( got_selchange , " got %d \n " , got_selchange ) ;
DestroyWindow ( listbox ) ;
DestroyWindow ( parent ) ;
}
2014-04-23 21:58:29 +02:00
static void test_extents ( void )
{
HWND listbox , parent ;
DWORD res ;
2014-04-28 18:16:15 +02:00
SCROLLINFO sinfo ;
BOOL br ;
2014-04-23 21:58:29 +02:00
parent = create_parent ( ) ;
listbox = create_listbox ( WS_CHILD | WS_VISIBLE , parent ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 0 , " Got wrong initial horizontal extent: %u \n " , res ) ;
2014-04-28 18:16:15 +02:00
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 100 , " got wrong max: %u \n " , sinfo . nMax ) ;
2015-09-28 11:20:45 +02:00
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) = = 0 ,
" List box should not have a horizontal scroll bar \n " ) ;
2014-04-28 18:16:15 +02:00
2015-09-28 11:20:45 +02:00
/* horizontal extent < width */
2014-04-23 21:58:29 +02:00
SendMessageA ( listbox , LB_SETHORIZONTALEXTENT , 64 , 0 ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 64 , " Got wrong horizontal extent: %u \n " , res ) ;
2014-04-28 18:16:15 +02:00
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 100 , " got wrong max: %u \n " , sinfo . nMax ) ;
2015-09-28 11:20:45 +02:00
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) = = 0 ,
" List box should not have a horizontal scroll bar \n " ) ;
/* horizontal extent > width */
SendMessageA ( listbox , LB_SETHORIZONTALEXTENT , 184 , 0 ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 184 , " Got wrong horizontal extent: %u \n " , res ) ;
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 100 , " got wrong max: %u \n " , sinfo . nMax ) ;
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) = = 0 ,
" List box should not have a horizontal scroll bar \n " ) ;
2014-04-28 18:16:15 +02:00
2014-04-23 21:58:29 +02:00
DestroyWindow ( listbox ) ;
listbox = create_listbox ( WS_CHILD | WS_VISIBLE | WS_HSCROLL , parent ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 0 , " Got wrong initial horizontal extent: %u \n " , res ) ;
2014-04-28 18:16:15 +02:00
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 100 , " got wrong max: %u \n " , sinfo . nMax ) ;
2015-09-28 11:20:45 +02:00
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) = = 0 ,
" List box should not have a horizontal scroll bar \n " ) ;
/* horizontal extent < width */
SendMessageA ( listbox , LB_SETHORIZONTALEXTENT , 64 , 0 ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 64 , " Got wrong horizontal extent: %u \n " , res ) ;
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 63 , " got wrong max: %u \n " , sinfo . nMax ) ;
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) = = 0 ,
" List box should not have a horizontal scroll bar \n " ) ;
/* horizontal extent > width */
SendMessageA ( listbox , LB_SETHORIZONTALEXTENT , 184 , 0 ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 184 , " Got wrong horizontal extent: %u \n " , res ) ;
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 183 , " got wrong max: %u \n " , sinfo . nMax ) ;
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) ! = 0 ,
" List box should have a horizontal scroll bar \n " ) ;
SendMessageA ( listbox , LB_SETHORIZONTALEXTENT , 0 , 0 ) ;
2014-04-28 18:16:15 +02:00
2015-09-28 11:20:45 +02:00
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 0 , " Got wrong horizontal extent: %u \n " , res ) ;
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 0 , " got wrong max: %u \n " , sinfo . nMax ) ;
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) = = 0 ,
" List box should not have a horizontal scroll bar \n " ) ;
DestroyWindow ( listbox ) ;
listbox = create_listbox ( WS_CHILD | WS_VISIBLE | WS_HSCROLL | LBS_DISABLENOSCROLL , parent ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 0 , " Got wrong initial horizontal extent: %u \n " , res ) ;
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 0 , " got wrong max: %u \n " , sinfo . nMax ) ;
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) ! = 0 ,
" List box should have a horizontal scroll bar \n " ) ;
/* horizontal extent < width */
2014-04-23 21:58:29 +02:00
SendMessageA ( listbox , LB_SETHORIZONTALEXTENT , 64 , 0 ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 64 , " Got wrong horizontal extent: %u \n " , res ) ;
2014-04-28 18:16:15 +02:00
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 63 , " got wrong max: %u \n " , sinfo . nMax ) ;
2015-09-28 11:20:45 +02:00
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) ! = 0 ,
" List box should have a horizontal scroll bar \n " ) ;
/* horizontal extent > width */
SendMessageA ( listbox , LB_SETHORIZONTALEXTENT , 184 , 0 ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 184 , " Got wrong horizontal extent: %u \n " , res ) ;
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 183 , " got wrong max: %u \n " , sinfo . nMax ) ;
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) ! = 0 ,
" List box should have a horizontal scroll bar \n " ) ;
2014-04-28 18:16:15 +02:00
SendMessageA ( listbox , LB_SETHORIZONTALEXTENT , 0 , 0 ) ;
res = SendMessageA ( listbox , LB_GETHORIZONTALEXTENT , 0 , 0 ) ;
ok ( res = = 0 , " Got wrong horizontal extent: %u \n " , res ) ;
sinfo . cbSize = sizeof ( sinfo ) ;
sinfo . fMask = SIF_RANGE ;
br = GetScrollInfo ( listbox , SB_HORZ , & sinfo ) ;
ok ( br = = TRUE , " GetScrollInfo failed \n " ) ;
ok ( sinfo . nMin = = 0 , " got wrong min: %u \n " , sinfo . nMin ) ;
ok ( sinfo . nMax = = 0 , " got wrong max: %u \n " , sinfo . nMax ) ;
2015-09-28 11:20:45 +02:00
ok ( ( GetWindowLongA ( listbox , GWL_STYLE ) & WS_HSCROLL ) ! = 0 ,
" List box should have a horizontal scroll bar \n " ) ;
2014-04-28 18:16:15 +02:00
2014-04-23 21:58:29 +02:00
DestroyWindow ( listbox ) ;
DestroyWindow ( parent ) ;
}
2018-02-28 17:37:03 +01:00
static void test_WM_MEASUREITEM ( void )
{
HWND parent , listbox ;
LRESULT data ;
parent = create_parent ( ) ;
listbox = create_listbox ( WS_CHILD | LBS_OWNERDRAWVARIABLE , parent ) ;
data = SendMessageA ( listbox , LB_GETITEMDATA , 0 , 0 ) ;
ok ( data = = ( LRESULT ) strings [ 0 ] , " data = %08lx, expected %p \n " , data , strings [ 0 ] ) ;
DestroyWindow ( parent ) ;
parent = create_parent ( ) ;
listbox = create_listbox ( WS_CHILD | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS , parent ) ;
data = SendMessageA ( listbox , LB_GETITEMDATA , 0 , 0 ) ;
ok ( ! data , " data = %08lx \n " , data ) ;
DestroyWindow ( parent ) ;
}
2018-11-15 10:46:13 +01:00
static void test_LBS_NODATA ( void )
{
2018-11-15 10:46:14 +01:00
static const DWORD invalid_styles [ ] =
{
0 ,
LBS_OWNERDRAWVARIABLE ,
LBS_SORT ,
LBS_HASSTRINGS ,
LBS_OWNERDRAWFIXED | LBS_SORT ,
LBS_OWNERDRAWFIXED | LBS_HASSTRINGS ,
} ;
2018-11-15 10:46:13 +01:00
static const UINT invalid_idx [ ] = { - 2 , 2 } ;
static const UINT valid_idx [ ] = { 0 , 1 } ;
static const ULONG_PTR zero_data ;
2018-11-15 10:46:14 +01:00
HWND listbox , parent ;
2018-11-15 10:46:13 +01:00
unsigned int i ;
ULONG_PTR data ;
INT ret ;
listbox = CreateWindowA ( " listbox " , " TestList " , LBS_NODATA | LBS_OWNERDRAWFIXED | WS_VISIBLE ,
0 , 0 , 100 , 100 , NULL , NULL , NULL , 0 ) ;
ok ( listbox ! = NULL , " Failed to create ListBox window. \n " ) ;
ret = SendMessageA ( listbox , LB_INSERTSTRING , - 1 , 0 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( listbox , LB_INSERTSTRING , - 1 , 0 ) ;
ok ( ret = = 1 , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( listbox , LB_GETCOUNT , 0 , 0 ) ;
ok ( ret = = 2 , " Unexpected return value %d. \n " , ret ) ;
/* Invalid indices. */
for ( i = 0 ; i < ARRAY_SIZE ( invalid_idx ) ; + + i )
{
ret = SendMessageA ( listbox , LB_SETITEMDATA , invalid_idx [ i ] , 42 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( listbox , LB_GETTEXTLEN , invalid_idx [ i ] , 0 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
if ( ret = = LB_ERR )
{
ret = SendMessageA ( listbox , LB_GETTEXT , invalid_idx [ i ] , ( LPARAM ) & data ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
}
ret = SendMessageA ( listbox , LB_GETITEMDATA , invalid_idx [ i ] , 0 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
}
/* Valid indices. */
for ( i = 0 ; i < ARRAY_SIZE ( valid_idx ) ; + + i )
{
ret = SendMessageA ( listbox , LB_SETITEMDATA , valid_idx [ i ] , 42 ) ;
ok ( ret = = TRUE , " Unexpected return value %d. \n " , ret ) ;
ret = SendMessageA ( listbox , LB_GETTEXTLEN , valid_idx [ i ] , 0 ) ;
ok ( ret = = sizeof ( data ) , " Unexpected return value %d. \n " , ret ) ;
memset ( & data , 0xee , sizeof ( data ) ) ;
ret = SendMessageA ( listbox , LB_GETTEXT , valid_idx [ i ] , ( LPARAM ) & data ) ;
ok ( ret = = sizeof ( data ) , " Unexpected return value %d. \n " , ret ) ;
ok ( ! memcmp ( & data , & zero_data , sizeof ( data ) ) , " Unexpected item data. \n " ) ;
ret = SendMessageA ( listbox , LB_GETITEMDATA , valid_idx [ i ] , 0 ) ;
ok ( ret = = 0 , " Unexpected return value %d. \n " , ret ) ;
}
/* More messages that don't work with LBS_NODATA. */
2018-11-15 10:46:22 +01:00
SetLastError ( 0xdeadbeef ) ;
ret = SendMessageA ( listbox , LB_FINDSTRING , 1 , 0 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " GetLastError should return 0x57, got 0x%X \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
2018-11-15 10:46:13 +01:00
ret = SendMessageA ( listbox , LB_FINDSTRING , 1 , 42 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
2018-11-15 10:46:22 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " GetLastError should return 0x57, got 0x%X \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
ret = SendMessageA ( listbox , LB_FINDSTRINGEXACT , 1 , 0 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " GetLastError should return 0x57, got 0x%X \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
2018-11-15 10:46:13 +01:00
ret = SendMessageA ( listbox , LB_FINDSTRINGEXACT , 1 , 42 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
2018-11-15 10:46:22 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " GetLastError should return 0x57, got 0x%X \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
ret = SendMessageA ( listbox , LB_SELECTSTRING , 1 , 0 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " GetLastError should return 0x57, got 0x%X \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
2018-11-15 10:46:13 +01:00
ret = SendMessageA ( listbox , LB_SELECTSTRING , 1 , 42 ) ;
ok ( ret = = LB_ERR , " Unexpected return value %d. \n " , ret ) ;
2018-11-15 10:46:22 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " GetLastError should return 0x57, got 0x%X \n " , GetLastError ( ) ) ;
2018-11-15 10:46:13 +01:00
DestroyWindow ( listbox ) ;
2018-11-15 10:46:14 +01:00
/* Invalid window style combinations. */
parent = create_parent ( ) ;
ok ( parent ! = NULL , " Failed to create parent window. \n " ) ;
for ( i = 0 ; i < ARRAY_SIZE ( invalid_styles ) ; + + i )
{
DWORD style ;
listbox = CreateWindowA ( " listbox " , " TestList " , LBS_NODATA | WS_CHILD | invalid_styles [ i ] ,
0 , 0 , 100 , 100 , parent , ( HMENU ) 1 , NULL , 0 ) ;
ok ( listbox ! = NULL , " Failed to create a listbox. \n " ) ;
style = GetWindowLongA ( listbox , GWL_STYLE ) ;
ok ( ( style & invalid_styles [ i ] ) = = invalid_styles [ i ] , " %u: unexpected window styles %#x. \n " , i , style ) ;
ret = SendMessageA ( listbox , LB_SETCOUNT , 100 , 0 ) ;
ok ( ret = = LB_ERR , " %u: unexpected return value %d. \n " , i , ret ) ;
DestroyWindow ( listbox ) ;
}
DestroyWindow ( parent ) ;
2018-11-15 10:46:13 +01:00
}
2003-04-26 04:09:43 +02:00
START_TEST ( listbox )
{
const struct listbox_test SS =
/* {add_style} */
2018-11-15 10:46:13 +01:00
{ { 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 =
2018-11-15 10:46:13 +01:00
{ { 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 =
2018-11-15 10:46:13 +01:00
{ { 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 =
2018-11-15 10:46:13 +01:00
{ { 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 } } ;
2005-01-10 17:22:33 +01:00
const struct listbox_test ES =
2018-11-15 10:46:13 +01:00
{ { 0 , LB_ERR , 0 , 0 } , { 0 , 0 , 0 , 0 } ,
2005-01-10 17:22:33 +01:00
{ 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 =
2018-11-15 10:46:13 +01:00
{ { LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2005-01-10 17:22:33 +01: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 } } ;
2005-01-10 17:22:33 +01:00
const struct listbox_test EMS =
2018-11-15 10:46:13 +01:00
{ { 0 , LB_ERR , 0 , 0 } , { 0 , 0 , 0 , 0 } ,
2005-01-10 17:22:33 +01:00
{ 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 =
2018-11-15 10:46:13 +01:00
{ { LB_ERR , LB_ERR , 0 , LB_ERR } , { 0 , 0 , 0 , 0 } ,
2005-01-10 17:22:33 +01: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
trace ( " Testing single selection... \n " ) ;
2018-11-15 10:46:13 +01:00
check ( 0 , SS ) ;
trace ( " ... with NOSEL \n " ) ;
check ( LBS_NOSEL , SS_NS ) ;
trace ( " ... LBS_NODATA variant ... \n " ) ;
check ( LBS_NODATA | LBS_OWNERDRAWFIXED , SS ) ;
2003-04-26 04:09:43 +02:00
trace ( " ... with NOSEL \n " ) ;
2018-11-15 10:46:13 +01:00
check ( LBS_NODATA | LBS_OWNERDRAWFIXED | LBS_NOSEL , SS_NS ) ;
2003-04-26 04:09:43 +02:00
trace ( " Testing multiple selection... \n " ) ;
2018-11-15 10:46:13 +01:00
check ( LBS_MULTIPLESEL , MS ) ;
trace ( " ... with NOSEL \n " ) ;
check ( LBS_MULTIPLESEL | LBS_NOSEL , MS_NS ) ;
trace ( " ... LBS_NODATA variant ... \n " ) ;
check ( LBS_NODATA | LBS_OWNERDRAWFIXED | LBS_MULTIPLESEL , MS ) ;
2003-04-26 04:09:43 +02:00
trace ( " ... with NOSEL \n " ) ;
2018-11-15 10:46:13 +01:00
check ( LBS_NODATA | LBS_OWNERDRAWFIXED | LBS_MULTIPLESEL | LBS_NOSEL , MS_NS ) ;
2005-01-10 17:22:33 +01:00
trace ( " Testing extended selection... \n " ) ;
2018-11-15 10:46:13 +01:00
check ( LBS_EXTENDEDSEL , ES ) ;
trace ( " ... with NOSEL \n " ) ;
check ( LBS_EXTENDEDSEL | LBS_NOSEL , ES_NS ) ;
trace ( " ... LBS_NODATA variant ... \n " ) ;
check ( LBS_NODATA | LBS_OWNERDRAWFIXED | LBS_EXTENDEDSEL , ES ) ;
2005-01-10 17:22:33 +01:00
trace ( " ... with NOSEL \n " ) ;
2018-11-15 10:46:13 +01:00
check ( LBS_NODATA | LBS_OWNERDRAWFIXED | LBS_EXTENDEDSEL | LBS_NOSEL , ES_NS ) ;
2005-01-10 17:22:33 +01:00
trace ( " Testing extended and multiple selection... \n " ) ;
2018-11-15 10:46:13 +01:00
check ( LBS_EXTENDEDSEL | LBS_MULTIPLESEL , EMS ) ;
trace ( " ... with NOSEL \n " ) ;
check ( LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_NOSEL , EMS_NS ) ;
trace ( " ... LBS_NODATA variant ... \n " ) ;
check ( LBS_NODATA | LBS_OWNERDRAWFIXED | LBS_EXTENDEDSEL | LBS_MULTIPLESEL , EMS ) ;
2005-01-10 17:22:33 +01:00
trace ( " ... with NOSEL \n " ) ;
2018-11-15 10:46:13 +01:00
check ( LBS_NODATA | LBS_OWNERDRAWFIXED | LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_NOSEL , EMS_NS ) ;
2005-01-03 15:40:13 +01:00
check_item_height ( ) ;
2005-07-29 16:42:19 +02:00
test_ownerdraw ( ) ;
2015-07-16 11:30:30 +02:00
test_LB_SELITEMRANGE ( ) ;
test_LB_SETCURSEL ( ) ;
2006-03-09 06:22:30 +01:00
test_listbox_height ( ) ;
2006-10-27 17:22:02 +02:00
test_itemfrompoint ( ) ;
2007-08-14 18:35:18 +02:00
test_listbox_item_data ( ) ;
2007-11-11 00:09:41 +01:00
test_listbox_LB_DIR ( ) ;
2007-11-11 00:09:45 +01:00
test_listbox_dlgdir ( ) ;
2013-03-28 11:21:22 +01:00
test_set_count ( ) ;
2013-05-07 19:18:43 +02:00
test_GetListBoxInfo ( ) ;
2014-02-20 12:35:18 +01:00
test_missing_lbuttonup ( ) ;
2014-04-23 21:58:29 +02:00
test_extents ( ) ;
2018-02-28 17:37:03 +01:00
test_WM_MEASUREITEM ( ) ;
2018-08-15 10:22:54 +02:00
test_LB_SETSEL ( ) ;
2018-11-15 10:46:13 +01:00
test_LBS_NODATA ( ) ;
2003-04-26 04:09:43 +02:00
}