1 /* Unit test suite for list boxes.
3 * Copyright 2003 Ferenc Wagner
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
33 #define WAIT Sleep (1000)
34 #define REDRAW RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)
40 static const char * const strings[4] = {
44 "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."
48 create_listbox (DWORD add_style, HWND parent)
54 handle=CreateWindow ("LISTBOX", "TestList",
55 (LBS_STANDARD & ~LBS_SORT) | add_style,
57 parent, (HMENU)ctl_id, NULL, 0);
60 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[0]);
61 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[1]);
62 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[2]);
63 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[3]);
66 ShowWindow (handle, SW_SHOW);
78 int selected, anchor, caret, selcount;
82 struct listbox_prop prop;
83 struct listbox_stat init, init_todo;
84 struct listbox_stat click, click_todo;
85 struct listbox_stat step, step_todo;
86 struct listbox_stat sel, sel_todo;
90 listbox_query (HWND handle, struct listbox_stat *results)
92 results->selected = SendMessage (handle, LB_GETCURSEL, 0, 0);
93 results->anchor = SendMessage (handle, LB_GETANCHORINDEX, 0, 0);
94 results->caret = SendMessage (handle, LB_GETCARETINDEX, 0, 0);
95 results->selcount = SendMessage (handle, LB_GETSELCOUNT, 0, 0);
99 buttonpress (HWND handle, WORD x, WORD y)
104 SendMessage (handle, WM_LBUTTONDOWN, (WPARAM) MK_LBUTTON, lp);
105 SendMessage (handle, WM_LBUTTONUP , (WPARAM) 0 , lp);
110 keypress (HWND handle, WPARAM keycode, BYTE scancode, BOOL extended)
112 LPARAM lp=1+(scancode<<16)+(extended?KEYEVENTF_EXTENDEDKEY:0);
115 SendMessage (handle, WM_KEYDOWN, keycode, lp);
116 SendMessage (handle, WM_KEYUP , keycode, lp | 0xc000000);
120 #define listbox_field_ok(t, s, f, got) \
121 ok (t.s.f==got.f, "style %#x, step " #s ", field " #f \
122 ": expected %d, got %d\n", (unsigned int)t.prop.add_style, \
125 #define listbox_todo_field_ok(t, s, f, got) \
126 if (t.s##_todo.f) todo_wine { listbox_field_ok(t, s, f, got); } \
127 else listbox_field_ok(t, s, f, got)
129 #define listbox_ok(t, s, got) \
130 listbox_todo_field_ok(t, s, selected, got); \
131 listbox_todo_field_ok(t, s, anchor, got); \
132 listbox_todo_field_ok(t, s, caret, got); \
133 listbox_todo_field_ok(t, s, selcount, got)
136 check (const struct listbox_test test)
138 struct listbox_stat answer;
139 HWND hLB=create_listbox (test.prop.add_style, 0);
144 listbox_query (hLB, &answer);
145 listbox_ok (test, init, answer);
147 SendMessage (hLB, LB_GETITEMRECT, (WPARAM) 1, (LPARAM) &second_item);
148 buttonpress(hLB, (WORD)second_item.left, (WORD)second_item.top);
150 listbox_query (hLB, &answer);
151 listbox_ok (test, click, answer);
153 keypress (hLB, VK_DOWN, 0x50, TRUE);
155 listbox_query (hLB, &answer);
156 listbox_ok (test, step, answer);
159 hLB=create_listbox (test.prop.add_style, 0);
161 SendMessage (hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
162 listbox_query (hLB, &answer);
163 listbox_ok (test, sel, answer);
166 DWORD size = SendMessage (hLB, LB_GETTEXTLEN, i, 0);
171 txt = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, size+1);
172 resA=SendMessageA(hLB, LB_GETTEXT, i, (LPARAM)txt);
173 ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
175 txtw = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, 2*size+2);
176 resW=SendMessageW(hLB, LB_GETTEXT, i, (LPARAM)txtw);
178 trace("SendMessageW(LB_GETTEXT) not supported on this platform (resA=%d resW=%d), skipping...\n",
181 WideCharToMultiByte( CP_ACP, 0, txtw, -1, txt, size, NULL, NULL );
182 ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
185 HeapFree (GetProcessHeap(), 0, txtw);
186 HeapFree (GetProcessHeap(), 0, txt);
189 /* Confirm the count of items, and that an invalid delete does not remove anything */
190 res = SendMessage (hLB, LB_GETCOUNT, 0, 0);
191 ok((res==4), "Expected 4 items, got %d\n", res);
192 res = SendMessage (hLB, LB_DELETESTRING, -1, 0);
193 ok((res==LB_ERR), "Expected LB_ERR items, got %d\n", res);
194 res = SendMessage (hLB, LB_DELETESTRING, 4, 0);
195 ok((res==LB_ERR), "Expected LB_ERR items, got %d\n", res);
196 res = SendMessage (hLB, LB_GETCOUNT, 0, 0);
197 ok((res==4), "Expected 4 items, got %d\n", res);
203 static void check_item_height(void)
211 hLB = create_listbox (0, 0);
212 ok ((hdc = GetDCEx( hLB, 0, DCX_CACHE )) != 0, "Can't get hdc\n");
213 ok ((font = GetCurrentObject(hdc, OBJ_FONT)) != 0, "Can't get the current font\n");
214 ok (GetTextMetrics( hdc, &tm ), "Can't read font metrics\n");
215 ReleaseDC( hLB, hdc);
217 ok (SendMessage(hLB, WM_SETFONT, (WPARAM)font, 0) == 0, "Can't set font\n");
219 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 0, 0);
220 ok (itemHeight == tm.tmHeight, "Item height wrong, got %d, expecting %d\n", itemHeight, tm.tmHeight);
224 hLB = CreateWindow ("LISTBOX", "TestList", LBS_OWNERDRAWVARIABLE,
225 0, 0, 100, 100, NULL, NULL, NULL, 0);
226 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 0, 0);
227 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
228 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 5, 0);
229 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
230 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, -5, 0);
231 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
235 static LRESULT WINAPI main_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
241 RECT rc_item, rc_client, rc_clip;
242 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
244 trace("%p WM_DRAWITEM %08lx %08lx\n", hwnd, wparam, lparam);
246 ok(wparam == dis->CtlID, "got wParam=%08lx instead of %08x\n",
248 ok(dis->CtlType == ODT_LISTBOX, "wrong CtlType %04x\n", dis->CtlType);
250 GetClientRect(dis->hwndItem, &rc_client);
251 trace("hwndItem %p client rect (%d,%d-%d,%d)\n", dis->hwndItem,
252 rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
253 GetClipBox(dis->hDC, &rc_clip);
254 trace("clip rect (%d,%d-%d,%d)\n", rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
255 ok(EqualRect(&rc_client, &rc_clip), "client rect of the listbox should be equal to the clip box\n");
257 trace("rcItem (%d,%d-%d,%d)\n", dis->rcItem.left, dis->rcItem.top,
258 dis->rcItem.right, dis->rcItem.bottom);
259 SendMessage(dis->hwndItem, LB_GETITEMRECT, dis->itemID, (LPARAM)&rc_item);
260 trace("item rect (%d,%d-%d,%d)\n", rc_item.left, rc_item.top, rc_item.right, rc_item.bottom);
261 ok(EqualRect(&dis->rcItem, &rc_item), "item rects are not equal\n");
270 return DefWindowProc(hwnd, msg, wparam, lparam);
273 static void test_ownerdraw(void)
281 cls.lpfnWndProc = main_window_proc;
284 cls.hInstance = GetModuleHandle(0);
286 cls.hCursor = LoadCursor(0, (LPSTR)IDC_ARROW);
287 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
288 cls.lpszMenuName = NULL;
289 cls.lpszClassName = "main_window_class";
290 assert(RegisterClass(&cls));
292 parent = CreateWindowEx(0, "main_window_class", NULL,
293 WS_POPUP | WS_VISIBLE,
295 GetDesktopWindow(), 0,
296 GetModuleHandle(0), NULL);
299 hLB = create_listbox(LBS_OWNERDRAWFIXED | WS_CHILD | WS_VISIBLE, parent);
304 /* make height short enough */
305 SendMessage(hLB, LB_GETITEMRECT, 0, (LPARAM)&rc);
306 SetWindowPos(hLB, 0, 0, 0, 100, rc.bottom - rc.top + 1,
307 SWP_NOZORDER | SWP_NOMOVE);
309 /* make 0 item invisible */
310 SendMessage(hLB, LB_SETTOPINDEX, 1, 0);
311 ret = SendMessage(hLB, LB_GETTOPINDEX, 0, 0);
312 ok(ret == 1, "wrong top index %d\n", ret);
314 SendMessage(hLB, LB_GETITEMRECT, 0, (LPARAM)&rc);
315 trace("item 0 rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
316 ok(!IsRectEmpty(&rc), "empty item rect\n");
317 ok(rc.top < 0, "rc.top is not negative (%d)\n", rc.top);
320 DestroyWindow(parent);
323 #define listbox_test_query(exp, got) \
324 ok(exp.selected == got.selected, "expected selected %d, got %d\n", exp.selected, got.selected); \
325 ok(exp.anchor == got.anchor, "expected anchor %d, got %d\n", exp.anchor, got.anchor); \
326 ok(exp.caret == got.caret, "expected caret %d, got %d\n", exp.caret, got.caret); \
327 ok(exp.selcount == got.selcount, "expected selcount %d, got %d\n", exp.selcount, got.selcount);
329 static void test_selection(void)
331 static const struct listbox_stat test_nosel = { 0, LB_ERR, 0, 0 };
332 static const struct listbox_stat test_1 = { 0, LB_ERR, 0, 2 };
333 static const struct listbox_stat test_2 = { 0, LB_ERR, 0, 3 };
334 static const struct listbox_stat test_3 = { 0, LB_ERR, 0, 4 };
336 struct listbox_stat answer;
339 trace("testing LB_SELITEMRANGE\n");
341 hLB = create_listbox(LBS_EXTENDEDSEL, 0);
344 listbox_query(hLB, &answer);
345 listbox_test_query(test_nosel, answer);
347 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
348 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
349 listbox_query(hLB, &answer);
350 listbox_test_query(test_1, answer);
352 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
353 listbox_query(hLB, &answer);
354 listbox_test_query(test_nosel, answer);
356 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(0, 4));
357 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
358 listbox_query(hLB, &answer);
359 listbox_test_query(test_3, answer);
361 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
362 listbox_query(hLB, &answer);
363 listbox_test_query(test_nosel, answer);
365 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(-5, 5));
366 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
367 listbox_query(hLB, &answer);
368 listbox_test_query(test_nosel, answer);
370 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
371 listbox_query(hLB, &answer);
372 listbox_test_query(test_nosel, answer);
374 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(2, 10));
375 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
376 listbox_query(hLB, &answer);
377 listbox_test_query(test_1, answer);
379 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
380 listbox_query(hLB, &answer);
381 listbox_test_query(test_nosel, answer);
383 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(4, 10));
384 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
385 listbox_query(hLB, &answer);
386 listbox_test_query(test_nosel, answer);
388 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
389 listbox_query(hLB, &answer);
390 listbox_test_query(test_nosel, answer);
392 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(10, 1));
393 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
394 listbox_query(hLB, &answer);
395 listbox_test_query(test_2, answer);
397 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
398 listbox_query(hLB, &answer);
399 listbox_test_query(test_nosel, answer);
401 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, -1));
402 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
403 listbox_query(hLB, &answer);
404 listbox_test_query(test_2, answer);
409 static void test_listbox_height(void)
414 hList = CreateWindow( "ListBox", "list test", 0,
415 1, 1, 600, 100, NULL, NULL, NULL, NULL );
416 ok( hList != NULL, "failed to create listbox\n");
418 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
419 ok( id == 0, "item id wrong\n");
421 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 20, 0 ));
422 ok( r == 0, "send message failed\n");
424 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
425 ok( r == 20, "height wrong\n");
427 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0, 30 ));
428 ok( r == -1, "send message failed\n");
430 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
431 ok( r == 20, "height wrong\n");
433 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0x100, 0 ));
434 ok( r == -1, "send message failed\n");
436 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
437 ok( r == 20, "height wrong\n");
439 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0xff, 0 ));
440 ok( r == 0, "send message failed\n");
442 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
443 ok( r == 0xff, "height wrong\n");
445 DestroyWindow( hList );
448 static void test_itemfrompoint(void)
450 /* WS_POPUP is required in order to have a more accurate size calculation (
451 without caption). LBS_NOINTEGRALHEIGHT is required in order to test
452 behavior of partially-displayed item.
454 HWND hList = CreateWindow( "ListBox", "list test",
455 WS_VISIBLE|WS_POPUP|LBS_NOINTEGRALHEIGHT,
456 1, 1, 600, 100, NULL, NULL, NULL, NULL );
460 /* For an empty listbox win2k returns 0x1ffff, win98 returns 0x10000 */
461 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 30 ));
462 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
464 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( 700, 30 ));
465 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
467 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( 30, 300 ));
468 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
470 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
471 ok( id == 0, "item id wrong\n");
472 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi1");
473 ok( id == 1, "item id wrong\n");
475 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 30 ));
476 ok( r == 0x1, "ret %x\n", r );
478 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 601 ));
479 ok( r == 0x10001, "ret %x\n", r );
481 /* Resize control so that below assertions about sizes are valid */
482 r = SendMessage( hList, LB_GETITEMRECT, 0, (LPARAM)&rc);
483 ok( r == 1, "ret %x\n", r);
484 r = MoveWindow(hList, 1, 1, 600, (rc.bottom - rc.top + 1) * 9 / 2, TRUE);
485 ok( r != 0, "ret %x\n", r);
487 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi2");
488 ok( id == 2, "item id wrong\n");
489 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi3");
490 ok( id == 3, "item id wrong\n");
491 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi4");
492 ok( id == 4, "item id wrong\n");
493 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi5");
494 ok( id == 5, "item id wrong\n");
495 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi6");
496 ok( id == 6, "item id wrong\n");
497 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi7");
498 ok( id == 7, "item id wrong\n");
500 /* Set the listbox up so that id 1 is at the top, this leaves 5
501 partially visible at the bottom and 6, 7 are invisible */
503 SendMessage( hList, LB_SETTOPINDEX, 1, 0);
504 r = SendMessage( hList, LB_GETTOPINDEX, 0, 0);
505 ok( r == 1, "top %d\n", r);
507 r = SendMessage( hList, LB_GETITEMRECT, 5, (LPARAM)&rc);
508 ok( r == 1, "ret %x\n", r);
509 r = SendMessage( hList, LB_GETITEMRECT, 6, (LPARAM)&rc);
510 ok( r == 0, "ret %x\n", r);
512 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(/* x */ 10, /* y */ 10) );
513 ok( r == 1, "ret %x\n", r);
515 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(1000, 10) );
516 ok( r == 0x10001, "ret %x\n", r );
518 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, -10) );
519 ok( r == 0x10001, "ret %x\n", r );
521 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, 100) );
522 ok( r == 0x10005, "item %x\n", r );
524 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, 200) );
525 ok( r == 0x10005, "item %x\n", r );
527 DestroyWindow( hList );
530 static void test_listbox_item_data(void)
535 hList = CreateWindow( "ListBox", "list test", 0,
536 1, 1, 600, 100, NULL, NULL, NULL, NULL );
537 ok( hList != NULL, "failed to create listbox\n");
539 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
540 ok( id == 0, "item id wrong\n");
542 r = SendMessage( hList, LB_SETITEMDATA, 0, MAKELPARAM( 20, 0 ));
543 ok(r == TRUE, "LB_SETITEMDATA returned %d instead of TRUE\n", r);
545 r = SendMessage( hList, LB_GETITEMDATA, 0, 0);
546 ok( r == 20, "get item data failed\n");
548 DestroyWindow( hList );
551 static void test_listbox_LB_DIR()
555 int itemCount_justFiles;
556 int itemCount_justDrives;
557 int itemCount_allFiles;
559 char pathBuffer[MAX_PATH];
563 /* NOTE: for this test to succeed, there must be no subdirectories
564 under the current directory. In addition, there must be at least
565 one file that fits the wildcard w*.c . Normally, the test
566 directory itself satisfies both conditions.
568 hList = CreateWindow( "ListBox", "list test", WS_VISIBLE|WS_POPUP,
569 1, 1, 600, 100, NULL, NULL, NULL, NULL );
572 /* Test for standard usage */
574 /* This should list all the files in the test directory. */
575 strcpy(pathBuffer, "*");
576 SendMessage(hList, LB_RESETCONTENT, 0, 0);
577 res = SendMessage(hList, LB_DIR, 0, (LPARAM)pathBuffer);
578 ok (res >= 0, "SendMessage(LB_DIR, 0, *) failed - 0x%08x\n", GetLastError());
580 /* There should be some content in the listbox */
581 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
582 ok (itemCount > 0, "SendMessage(LB_DIR) did NOT fill the listbox!\n");
583 itemCount_allFiles = itemCount;
584 ok(res + 1 == itemCount,
585 "SendMessage(LB_DIR, 0, *) returned incorrect index (expected %d got %d)!\n",
589 /* This should list all the w*.c files in the test directory
590 * As of this writing, this includes win.c, winstation.c, wsprintf.c
592 strcpy(pathBuffer, "w*.c");
593 SendMessage(hList, LB_RESETCONTENT, 0, 0);
594 res = SendMessage(hList, LB_DIR, 0, (LPARAM)pathBuffer);
595 ok (res >= 0, "SendMessage(LB_DIR, 0, w*.c) failed - 0x%08x\n", GetLastError());
597 /* Path specification does NOT converted to uppercase */
598 ok (!strcmp(pathBuffer, "w*.c"),
599 "expected no change to pathBuffer, got %s\n", pathBuffer);
601 /* There should be some content in the listbox */
602 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
603 ok (itemCount > 0, "SendMessage(LB_DIR) did NOT fill the listbox!\n");
604 itemCount_justFiles = itemCount;
605 ok(res + 1 == itemCount,
606 "SendMessage(LB_DIR, 0, w*.c) returned incorrect index (expected %d got %d)!\n",
609 /* Every single item in the control should start with a w and end in .c */
610 for (i = 0; i < itemCount; i++) {
611 memset(pathBuffer, 0, MAX_PATH);
612 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
613 p = pathBuffer + strlen(pathBuffer);
614 ok(((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
615 (*(p-1) == 'c' || *(p-1) == 'C') &&
616 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
619 /* Test DDL_DIRECTORY */
620 strcpy(pathBuffer, "*");
621 SendMessage(hList, LB_RESETCONTENT, 0, 0);
622 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY, (LPARAM)pathBuffer);
623 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY, *) failed - 0x%08x\n", GetLastError());
625 /* There should be some content in the listbox.
626 * All files plus "[..]"
628 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
629 ok (itemCount == itemCount_allFiles + 1,
630 "SendMessage(LB_DIR, DDL_DIRECTORY, *) filled with %d entries, expected %d\n",
631 itemCount, itemCount_allFiles + 1);
632 ok(res + 1 == itemCount,
633 "SendMessage(LB_DIR, DDL_DIRECTORY, *) returned incorrect index (expected %d got %d)!\n",
637 /* Test DDL_DIRECTORY */
638 strcpy(pathBuffer, "w*.c");
639 SendMessage(hList, LB_RESETCONTENT, 0, 0);
640 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY, (LPARAM)pathBuffer);
641 ok (res >= 0, "SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) failed - 0x%08x\n", GetLastError());
643 /* There should be some content in the listbox. Since the parent directory does not
644 * fit w*.c, there should be exactly the same number of items as without DDL_DIRECTORY
646 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
647 ok (itemCount == itemCount_justFiles,
648 "SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) filled with %d entries, expected %d\n",
649 itemCount, itemCount_justFiles);
650 ok(res + 1 == itemCount,
651 "SendMessage(LB_DIR, DDL_DIRECTORY, w*.c) returned incorrect index (expected %d got %d)!\n",
654 /* Every single item in the control should start with a w and end in .c. */
655 for (i = 0; i < itemCount; i++) {
656 memset(pathBuffer, 0, MAX_PATH);
657 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
658 p = pathBuffer + strlen(pathBuffer);
660 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
661 (*(p-1) == 'c' || *(p-1) == 'C') &&
662 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
666 /* Test DDL_DRIVES|DDL_EXCLUSIVE */
667 strcpy(pathBuffer, "*");
668 SendMessage(hList, LB_RESETCONTENT, 0, 0);
669 res = SendMessage(hList, LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
670 ok (res > 0, "SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) failed - 0x%08x\n", GetLastError());
672 /* There should be some content in the listbox. In particular, there should
673 * be at least one element before, since the string "[-c-]" should
674 * have been added. Depending on the user setting, more drives might have
677 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
679 "SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) filled with %d entries, expected at least %d\n",
681 itemCount_justDrives = itemCount;
682 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DRIVES|DDL_EXCLUSIVE, *) returned incorrect index!\n");
684 /* Every single item in the control should fit the format [-c-] */
685 for (i = 0; i < itemCount; i++) {
686 memset(pathBuffer, 0, MAX_PATH);
688 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
689 ok( strlen(pathBuffer) == 5, "Length of drive string is not 5\n" );
690 ok( sscanf(pathBuffer, "[-%c-]", &driveletter) == 1, "Element %d (%s) does not fit [-X-]\n", i, pathBuffer);
691 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
692 if (!(driveletter >= 'a' && driveletter <= 'z')) {
693 /* Correct after invalid entry is found */
694 trace("removing count of invalid entry %s\n", pathBuffer);
695 itemCount_justDrives--;
700 trace("Files with w*.c: %d Mapped drives: %d Directories: 1\n",
701 itemCount_justFiles, itemCount_justDrives);
703 /* Test DDL_DRIVES. */
704 strcpy(pathBuffer, "*");
705 SendMessage(hList, LB_RESETCONTENT, 0, 0);
706 res = SendMessage(hList, LB_DIR, DDL_DRIVES, (LPARAM)pathBuffer);
707 ok (res > 0, "SendMessage(LB_DIR, DDL_DRIVES, *) failed - 0x%08x\n", GetLastError());
709 /* There should be some content in the listbox. In particular, there should
710 * be at least one element before, since the string "[-c-]" should
711 * have been added. Depending on the user setting, more drives might have
714 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
715 ok (itemCount == itemCount_justDrives + itemCount_allFiles,
716 "SendMessage(LB_DIR, DDL_DRIVES, w*.c) filled with %d entries, expected %d\n",
717 itemCount, itemCount_justDrives + itemCount_allFiles);
718 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DRIVES, w*.c) returned incorrect index!\n");
721 /* Test DDL_DRIVES. */
722 strcpy(pathBuffer, "w*.c");
723 SendMessage(hList, LB_RESETCONTENT, 0, 0);
724 res = SendMessage(hList, LB_DIR, DDL_DRIVES, (LPARAM)pathBuffer);
725 ok (res > 0, "SendMessage(LB_DIR, DDL_DRIVES, w*.c) failed - 0x%08x\n", GetLastError());
727 /* There should be some content in the listbox. In particular, there should
728 * be at least one element before, since the string "[-c-]" should
729 * have been added. Depending on the user setting, more drives might have
732 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
733 ok (itemCount == itemCount_justDrives + itemCount_justFiles,
734 "SendMessage(LB_DIR, DDL_DRIVES, w*.c) filled with %d entries, expected %d\n",
735 itemCount, itemCount_justDrives + itemCount_justFiles);
736 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DRIVES, w*.c) returned incorrect index!\n");
738 /* Every single item in the control should fit the format [-c-], or w*.c */
739 for (i = 0; i < itemCount; i++) {
740 memset(pathBuffer, 0, MAX_PATH);
742 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
743 p = pathBuffer + strlen(pathBuffer);
744 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
745 ok( strlen(pathBuffer) == 5, "Length of drive string is not 5\n" );
746 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
749 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
750 (*(p-1) == 'c' || *(p-1) == 'C') &&
751 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
756 /* Test DDL_DIRECTORY|DDL_DRIVES. This does *not* imply DDL_EXCLUSIVE */
757 strcpy(pathBuffer, "*");
758 SendMessage(hList, LB_RESETCONTENT, 0, 0);
759 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES, (LPARAM)pathBuffer);
760 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, *) failed - 0x%08x\n", GetLastError());
762 /* There should be some content in the listbox. In particular, there should
763 * be exactly the number of plain files, plus the number of mapped drives.
765 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
766 ok (itemCount == itemCount_allFiles + itemCount_justDrives + 1,
767 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d\n",
768 itemCount, itemCount_allFiles + itemCount_justDrives + 1);
769 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) returned incorrect index!\n");
771 /* Every single item in the control should start with a w and end in .c,
772 * except for the "[..]" string, which should appear exactly as it is,
773 * and the mapped drives in the format "[-X-]".
775 for (i = 0; i < itemCount; i++) {
776 memset(pathBuffer, 0, MAX_PATH);
778 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
779 p = pathBuffer + strlen(pathBuffer);
780 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
781 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
786 /* Test DDL_DIRECTORY|DDL_DRIVES. */
787 strcpy(pathBuffer, "w*.c");
788 SendMessage(hList, LB_RESETCONTENT, 0, 0);
789 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES, (LPARAM)pathBuffer);
790 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) failed - 0x%08x\n", GetLastError());
792 /* There should be some content in the listbox. In particular, there should
793 * be exactly the number of plain files, plus the number of mapped drives.
795 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
796 ok (itemCount == itemCount_justFiles + itemCount_justDrives,
797 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d\n",
798 itemCount, itemCount_justFiles + itemCount_justDrives);
799 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES, w*.c) returned incorrect index!\n");
801 /* Every single item in the control should start with a w and end in .c,
802 * except the mapped drives in the format "[-X-]". The "[..]" directory
805 for (i = 0; i < itemCount; i++) {
806 memset(pathBuffer, 0, MAX_PATH);
808 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
809 p = pathBuffer + strlen(pathBuffer);
810 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
811 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
814 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
815 (*(p-1) == 'c' || *(p-1) == 'C') &&
816 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
820 /* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
821 strcpy(pathBuffer, "*");
822 SendMessage(hList, LB_RESETCONTENT, 0, 0);
823 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
824 ok (res == 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) failed - 0x%08x\n", GetLastError());
826 /* There should be exactly one element: "[..]" */
827 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
829 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
831 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, *) returned incorrect index!\n");
833 memset(pathBuffer, 0, MAX_PATH);
834 SendMessage(hList, LB_GETTEXT, 0, (LPARAM)pathBuffer);
835 ok( !strcmp(pathBuffer, "[..]"), "First (and only) element is not [..]\n");
837 /* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
838 strcpy(pathBuffer, "w*.c");
839 SendMessage(hList, LB_RESETCONTENT, 0, 0);
840 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
841 ok (res == LB_ERR, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE, w*.c) returned %d expected %d\n", res, LB_ERR);
843 /* There should be no elements, since "[..]" does not fit w*.c */
844 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
846 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
849 /* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
850 strcpy(pathBuffer, "*");
851 SendMessage(hList, LB_RESETCONTENT, 0, 0);
852 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
853 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c,) failed - 0x%08x\n", GetLastError());
855 /* There should be no plain files on the listbox */
856 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
857 ok (itemCount == itemCount_justDrives + 1,
858 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
859 itemCount, itemCount_justDrives + 1);
860 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c) returned incorrect index!\n");
862 for (i = 0; i < itemCount; i++) {
863 memset(pathBuffer, 0, MAX_PATH);
865 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
866 p = pathBuffer + strlen(pathBuffer);
867 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
868 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
870 ok( !strcmp(pathBuffer, "[..]"), "Element %d (%s) does not fit expected [..]\n", i, pathBuffer);
875 /* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
876 strcpy(pathBuffer, "w*.c");
877 SendMessage(hList, LB_RESETCONTENT, 0, 0);
878 res = SendMessage(hList, LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, (LPARAM)pathBuffer);
879 ok (res > 0, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c,) failed - 0x%08x\n", GetLastError());
881 /* There should be no plain files on the listbox, and no [..], since it does not fit w*.c */
882 itemCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
883 ok (itemCount == itemCount_justDrives,
884 "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
885 itemCount, itemCount_justDrives);
886 ok(res + 1 == itemCount, "SendMessage(LB_DIR, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE, w*.c) returned incorrect index!\n");
888 for (i = 0; i < itemCount; i++) {
889 memset(pathBuffer, 0, MAX_PATH);
891 SendMessage(hList, LB_GETTEXT, i, (LPARAM)pathBuffer);
892 p = pathBuffer + strlen(pathBuffer);
893 ok (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1, "Element %d (%s) does not fit [-X-]\n", i, pathBuffer);
894 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
896 DestroyWindow(hList);
902 #define ID_TEST_LABEL 1001
903 #define ID_TEST_LISTBOX 1002
905 static BOOL on_listbox_container_create (HWND hwnd, LPCREATESTRUCT lpcs)
907 g_label = CreateWindow(
909 "Contents of static control before DlgDirList.",
910 WS_CHILD | WS_VISIBLE,
912 hwnd, (HMENU)ID_TEST_LABEL, NULL, 0);
913 if (!g_label) return FALSE;
914 g_listBox = CreateWindow(
917 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_VSCROLL,
919 hwnd, (HMENU)ID_TEST_LISTBOX, NULL, 0);
920 if (!g_listBox) return FALSE;
925 static LRESULT CALLBACK listbox_container_window_procA (
926 HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
935 result = on_listbox_container_create(hwnd, (LPCREATESTRUCTA) lParam)
939 result = DefWindowProcA (hwnd, uiMsg, wParam, lParam);
945 static BOOL RegisterListboxWindowClass(HINSTANCE hInst)
952 cls.hInstance = hInst;
954 cls.hCursor = LoadCursorA (NULL, IDC_ARROW);
955 cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
956 cls.lpszMenuName = NULL;
957 cls.lpfnWndProc = listbox_container_window_procA;
958 cls.lpszClassName = "ListboxContainerClass";
959 if (!RegisterClassA (&cls)) return FALSE;
964 static void test_listbox_dlgdir(void)
969 int itemCount_justFiles;
970 int itemCount_justDrives;
972 char pathBuffer[MAX_PATH];
973 char itemBuffer[MAX_PATH];
974 char tempBuffer[MAX_PATH];
978 /* NOTE: for this test to succeed, there must be no subdirectories
979 under the current directory. In addition, there must be at least
980 one file that fits the wildcard w*.c . Normally, the test
981 directory itself satisfies both conditions.
984 hInst = GetModuleHandleA(0);
985 if (!RegisterListboxWindowClass(hInst)) assert(0);
986 hWnd = CreateWindow("ListboxContainerClass", "ListboxContainerClass",
987 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
988 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
989 NULL, NULL, hInst, 0);
992 /* Test for standard usage */
994 /* The following should be overwritten by the directory path */
995 SendMessage(g_label, WM_SETTEXT, 0, (LPARAM)"default contents");
997 /* This should list all the w*.c files in the test directory
998 * As of this writing, this includes win.c, winstation.c, wsprintf.c
1000 strcpy(pathBuffer, "w*.c");
1001 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL, 0);
1002 ok (res != 0, "DlgDirList(*.c, 0) failed - 0x%08x\n", GetLastError());
1004 /* Path specification gets converted to uppercase */
1005 ok (!strcmp(pathBuffer, "W*.C"),
1006 "expected conversion to uppercase, got %s\n", pathBuffer);
1008 /* Loaded path should have overwritten the label text */
1009 SendMessage(g_label, WM_GETTEXT, (WPARAM)MAX_PATH, (LPARAM)pathBuffer);
1010 trace("Static control after DlgDirList: %s\n", pathBuffer);
1011 ok (strcmp("default contents", pathBuffer), "DlgDirList() did not modify static control!\n");
1013 /* There should be some content in the listbox */
1014 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1015 ok (itemCount > 0, "DlgDirList() did NOT fill the listbox!\n");
1016 itemCount_justFiles = itemCount;
1018 /* Every single item in the control should start with a w and end in .c */
1019 for (i = 0; i < itemCount; i++) {
1020 memset(pathBuffer, 0, MAX_PATH);
1021 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1022 p = pathBuffer + strlen(pathBuffer);
1023 ok(((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
1024 (*(p-1) == 'c' || *(p-1) == 'C') &&
1025 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
1028 /* Test DDL_DIRECTORY */
1029 strcpy(pathBuffer, "w*.c");
1030 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1032 ok (res != 0, "DlgDirList(*.c, DDL_DIRECTORY) failed - 0x%08x\n", GetLastError());
1034 /* There should be some content in the listbox. In particular, there should
1035 * be exactly one more element than before, since the string "[..]" should
1038 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1039 ok (itemCount == itemCount_justFiles + 1,
1040 "DlgDirList(DDL_DIRECTORY) filled with %d entries, expected %d\n",
1041 itemCount, itemCount_justFiles + 1);
1043 /* Every single item in the control should start with a w and end in .c,
1044 * except for the "[..]" string, which should appear exactly as it is.
1046 for (i = 0; i < itemCount; i++) {
1047 memset(pathBuffer, 0, MAX_PATH);
1048 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1049 p = pathBuffer + strlen(pathBuffer);
1050 ok( !strcmp(pathBuffer, "[..]") ||
1051 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
1052 (*(p-1) == 'c' || *(p-1) == 'C') &&
1053 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
1056 /* Test DDL_DRIVES. At least on WinXP-SP2, this implies DDL_EXCLUSIVE */
1057 strcpy(pathBuffer, "w*.c");
1058 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1060 ok (res != 0, "DlgDirList(*.c, DDL_DRIVES) failed - 0x%08x\n", GetLastError());
1062 /* There should be some content in the listbox. In particular, there should
1063 * be at least one element before, since the string "[-c-]" should
1064 * have been added. Depending on the user setting, more drives might have
1067 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1069 "DlgDirList(DDL_DRIVES) filled with %d entries, expected at least %d\n",
1071 itemCount_justDrives = itemCount;
1073 /* Every single item in the control should fit the format [-c-] */
1074 for (i = 0; i < itemCount; i++) {
1075 memset(pathBuffer, 0, MAX_PATH);
1077 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1078 ok( strlen(pathBuffer) == 5, "Length of drive string is not 5\n" );
1079 ok( sscanf(pathBuffer, "[-%c-]", &driveletter) == 1, "Element %d (%s) does not fit [-X-]\n", i, pathBuffer);
1080 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
1081 if (!(driveletter >= 'a' && driveletter <= 'z')) {
1082 /* Correct after invalid entry is found */
1083 trace("removing count of invalid entry %s\n", pathBuffer);
1084 itemCount_justDrives--;
1088 /* Test DDL_DIRECTORY|DDL_DRIVES. This does *not* imply DDL_EXCLUSIVE */
1089 strcpy(pathBuffer, "w*.c");
1090 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1091 DDL_DIRECTORY|DDL_DRIVES);
1092 ok (res != 0, "DlgDirList(*.c, DDL_DIRECTORY|DDL_DRIVES) failed - 0x%08x\n", GetLastError());
1094 /* There should be some content in the listbox. In particular, there should
1095 * be exactly the number of plain files, plus the number of mapped drives,
1098 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1099 ok (itemCount == itemCount_justFiles + itemCount_justDrives + 1,
1100 "DlgDirList(DDL_DIRECTORY|DDL_DRIVES) filled with %d entries, expected %d\n",
1101 itemCount, itemCount_justFiles + itemCount_justDrives + 1);
1103 /* Every single item in the control should start with a w and end in .c,
1104 * except for the "[..]" string, which should appear exactly as it is,
1105 * and the mapped drives in the format "[-X-]".
1107 for (i = 0; i < itemCount; i++) {
1108 memset(pathBuffer, 0, MAX_PATH);
1110 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1111 p = pathBuffer + strlen(pathBuffer);
1112 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
1113 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
1115 ok( !strcmp(pathBuffer, "[..]") ||
1116 ((pathBuffer[0] == 'w' || pathBuffer[0] == 'W') &&
1117 (*(p-1) == 'c' || *(p-1) == 'C') &&
1118 (*(p-2) == '.')), "Element %d (%s) does not fit requested w*.c\n", i, pathBuffer);
1122 /* Test DDL_DIRECTORY|DDL_EXCLUSIVE. */
1123 strcpy(pathBuffer, "w*.c");
1124 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1125 DDL_DIRECTORY|DDL_EXCLUSIVE);
1126 ok (res != 0, "DlgDirList(*.c, DDL_DIRECTORY|DDL_EXCLUSIVE) failed - 0x%08x\n", GetLastError());
1128 /* There should be exactly one element: "[..]" */
1129 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1131 "DlgDirList(DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
1134 memset(pathBuffer, 0, MAX_PATH);
1135 SendMessage(g_listBox, LB_GETTEXT, 0, (LPARAM)pathBuffer);
1136 ok( !strcmp(pathBuffer, "[..]"), "First (and only) element is not [..]\n");
1138 /* Test DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE. */
1139 strcpy(pathBuffer, "w*.c");
1140 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1141 DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE);
1142 ok (res != 0, "DlgDirList(*.c, DDL_DIRECTORY|DDL_DRIVES|DDL_EXCLUSIVE) failed - 0x%08x\n", GetLastError());
1144 /* There should be no plain files on the listbox */
1145 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1146 ok (itemCount == itemCount_justDrives + 1,
1147 "DlgDirList(DDL_DIRECTORY|DDL_EXCLUSIVE) filled with %d entries, expected %d\n",
1148 itemCount, itemCount_justDrives + 1);
1150 for (i = 0; i < itemCount; i++) {
1151 memset(pathBuffer, 0, MAX_PATH);
1153 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)pathBuffer);
1154 p = pathBuffer + strlen(pathBuffer);
1155 if (sscanf(pathBuffer, "[-%c-]", &driveletter) == 1) {
1156 ok( driveletter >= 'a' && driveletter <= 'z', "Drive letter not in range a..z, got ascii %d\n", driveletter);
1158 ok( !strcmp(pathBuffer, "[..]"), "Element %d (%s) does not fit expected [..]\n", i, pathBuffer);
1162 /* Now test DlgDirSelectEx() in normal operation */
1163 /* Fill with everything - drives, directory and all plain files. */
1164 strcpy(pathBuffer, "*");
1165 res = DlgDirList(hWnd, pathBuffer, ID_TEST_LISTBOX, ID_TEST_LABEL,
1166 DDL_DIRECTORY|DDL_DRIVES);
1167 ok (res != 0, "DlgDirList(*, DDL_DIRECTORY|DDL_DRIVES) failed - 0x%08x\n", GetLastError());
1169 SendMessage(g_listBox, LB_SETCURSEL, -1, 0); /* Unselect any current selection */
1170 memset(pathBuffer, 0, MAX_PATH);
1171 SetLastError(0xdeadbeef);
1172 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1173 ok (GetLastError() == 0xdeadbeef,
1174 "DlgDirSelectEx() with no selection modified last error code from 0xdeadbeef to 0x%08x\n",
1176 ok (res == 0, "DlgDirSelectEx() with no selection returned %d, expected 0\n", res);
1177 /* WinXP-SP2 leaves pathBuffer untouched, but Win98 fills it with garbage. */
1179 ok (strlen(pathBuffer) == 0, "DlgDirSelectEx() with no selection filled buffer with %s\n", pathBuffer);
1181 /* Test proper drive/dir/file recognition */
1182 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1183 for (i = 0; i < itemCount; i++) {
1184 memset(itemBuffer, 0, MAX_PATH);
1185 memset(pathBuffer, 0, MAX_PATH);
1186 memset(tempBuffer, 0, MAX_PATH);
1188 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)itemBuffer);
1189 res = SendMessage(g_listBox, LB_SETCURSEL, i, 0);
1190 ok (res == i, "SendMessage(LB_SETCURSEL, %d) failed\n", i);
1191 if (sscanf(itemBuffer, "[-%c-]", &driveletter) == 1) {
1192 /* Current item is a drive letter */
1193 SetLastError(0xdeadbeef);
1194 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1195 ok (GetLastError() == 0xdeadbeef,
1196 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1198 ok(res == 1, "DlgDirSelectEx() thinks %s (%s) is not a drive/directory!\n", itemBuffer, pathBuffer);
1200 /* For drive letters, DlgDirSelectEx tacks on a colon */
1201 ok (pathBuffer[0] == driveletter && pathBuffer[1] == ':' && pathBuffer[2] == '\0',
1202 "%d: got \"%s\" expected \"%c:\"\n", i, pathBuffer, driveletter);
1203 } else if (itemBuffer[0] == '[') {
1204 /* Current item is the parent directory */
1205 SetLastError(0xdeadbeef);
1206 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1207 ok (GetLastError() == 0xdeadbeef,
1208 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1210 ok(res == 1, "DlgDirSelectEx() thinks %s (%s) is not a drive/directory!\n", itemBuffer, pathBuffer);
1212 /* For directories, DlgDirSelectEx tacks on a backslash */
1213 p = pathBuffer + strlen(pathBuffer);
1214 ok (*(p-1) == '\\', "DlgDirSelectEx did NOT tack on a backslash to dir, got %s\n", pathBuffer);
1216 tempBuffer[0] = '[';
1217 strncpy(tempBuffer + 1, pathBuffer, strlen(pathBuffer) - 1);
1218 strcat(tempBuffer, "]");
1219 ok (!strcmp(tempBuffer, itemBuffer), "Formatted directory should be %s, got %s\n", tempBuffer, itemBuffer);
1221 /* Current item is a plain file */
1222 SetLastError(0xdeadbeef);
1223 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1224 ok (GetLastError() == 0xdeadbeef,
1225 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1227 ok(res == 0, "DlgDirSelectEx() thinks %s (%s) is a drive/directory!\n", itemBuffer, pathBuffer);
1229 /* NOTE: WinXP tacks a period on all files that lack an extension. This affects
1230 * for example, "Makefile", which gets reported as "Makefile."
1232 strcpy(tempBuffer, itemBuffer);
1233 if (strchr(tempBuffer, '.') == NULL) strcat(tempBuffer, ".");
1234 ok (!strcmp(pathBuffer, tempBuffer), "Formatted file should be %s, got %s\n", tempBuffer, pathBuffer);
1238 /* Now test DlgDirSelectEx() in abnormal operation */
1239 /* Fill list with bogus entries, that look somewhat valid */
1240 SendMessage(g_listBox, LB_RESETCONTENT, 0, 0);
1241 SendMessage(g_listBox, LB_ADDSTRING, 0, (LPARAM)"[notexist.dir]");
1242 SendMessage(g_listBox, LB_ADDSTRING, 0, (LPARAM)"notexist.fil");
1243 itemCount = SendMessage(g_listBox, LB_GETCOUNT, 0, 0);
1244 for (i = 0; i < itemCount; i++) {
1245 memset(itemBuffer, 0, MAX_PATH);
1246 memset(pathBuffer, 0, MAX_PATH);
1247 memset(tempBuffer, 0, MAX_PATH);
1249 SendMessage(g_listBox, LB_GETTEXT, i, (LPARAM)itemBuffer);
1250 res = SendMessage(g_listBox, LB_SETCURSEL, i, 0);
1251 ok (res == i, "SendMessage(LB_SETCURSEL, %d) failed\n", i);
1252 if (sscanf(itemBuffer, "[-%c-]", &driveletter) == 1) {
1253 /* Current item is a drive letter */
1254 SetLastError(0xdeadbeef);
1255 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1256 ok (GetLastError() == 0xdeadbeef,
1257 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1259 ok(res == 1, "DlgDirSelectEx() thinks %s (%s) is not a drive/directory!\n", itemBuffer, pathBuffer);
1261 /* For drive letters, DlgDirSelectEx tacks on a colon */
1262 ok (pathBuffer[0] == driveletter && pathBuffer[1] == ':' && pathBuffer[2] == '\0',
1263 "%d: got \"%s\" expected \"%c:\"\n", i, pathBuffer, driveletter);
1264 } else if (itemBuffer[0] == '[') {
1265 /* Current item is the parent directory */
1266 SetLastError(0xdeadbeef);
1267 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1268 ok (GetLastError() == 0xdeadbeef,
1269 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1271 ok(res == 1, "DlgDirSelectEx() thinks %s (%s) is not a drive/directory!\n", itemBuffer, pathBuffer);
1273 /* For directories, DlgDirSelectEx tacks on a backslash */
1274 p = pathBuffer + strlen(pathBuffer);
1275 ok (*(p-1) == '\\', "DlgDirSelectEx did NOT tack on a backslash to dir, got %s\n", pathBuffer);
1277 tempBuffer[0] = '[';
1278 strncpy(tempBuffer + 1, pathBuffer, strlen(pathBuffer) - 1);
1279 strcat(tempBuffer, "]");
1280 ok (!strcmp(tempBuffer, itemBuffer), "Formatted directory should be %s, got %s\n", tempBuffer, itemBuffer);
1282 /* Current item is a plain file */
1283 SetLastError(0xdeadbeef);
1284 res = DlgDirSelectEx(hWnd, pathBuffer, MAX_PATH, ID_TEST_LISTBOX);
1285 ok (GetLastError() == 0xdeadbeef,
1286 "DlgDirSelectEx() with selection at %d modified last error code from 0xdeadbeef to 0x%08x\n",
1288 ok(res == 0, "DlgDirSelectEx() thinks %s (%s) is a drive/directory!\n", itemBuffer, pathBuffer);
1290 /* NOTE: WinXP and Win98 tack a period on all files that lack an extension.
1291 * This affects for example, "Makefile", which gets reported as "Makefile."
1293 strcpy(tempBuffer, itemBuffer);
1294 if (strchr(tempBuffer, '.') == NULL) strcat(tempBuffer, ".");
1295 ok (!strcmp(pathBuffer, tempBuffer), "Formatted file should be %s, got %s\n", tempBuffer, pathBuffer);
1298 DestroyWindow(hWnd);
1303 const struct listbox_test SS =
1306 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1307 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1308 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1309 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1310 /* {selected, anchor, caret, selcount}{TODO fields} */
1311 const struct listbox_test SS_NS =
1313 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1314 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1315 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1316 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1317 const struct listbox_test MS =
1319 { 0, LB_ERR, 0, 0}, {0,0,0,0},
1320 { 1, 1, 1, 1}, {0,0,0,0},
1321 { 2, 1, 2, 1}, {0,0,0,0},
1322 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
1323 const struct listbox_test MS_NS =
1324 {{LBS_MULTIPLESEL | LBS_NOSEL},
1325 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1326 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1327 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1328 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1329 const struct listbox_test ES =
1331 { 0, LB_ERR, 0, 0}, {0,0,0,0},
1332 { 1, 1, 1, 1}, {0,0,0,0},
1333 { 2, 2, 2, 1}, {0,0,0,0},
1334 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
1335 const struct listbox_test ES_NS =
1336 {{LBS_EXTENDEDSEL | LBS_NOSEL},
1337 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1338 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1339 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1340 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1341 const struct listbox_test EMS =
1342 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL},
1343 { 0, LB_ERR, 0, 0}, {0,0,0,0},
1344 { 1, 1, 1, 1}, {0,0,0,0},
1345 { 2, 2, 2, 1}, {0,0,0,0},
1346 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
1347 const struct listbox_test EMS_NS =
1348 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_NOSEL},
1349 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
1350 { 1, 1, 1, LB_ERR}, {0,0,0,0},
1351 { 2, 2, 2, LB_ERR}, {0,0,0,0},
1352 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
1354 trace (" Testing single selection...\n");
1356 trace (" ... with NOSEL\n");
1358 trace (" Testing multiple selection...\n");
1360 trace (" ... with NOSEL\n");
1362 trace (" Testing extended selection...\n");
1364 trace (" ... with NOSEL\n");
1366 trace (" Testing extended and multiple selection...\n");
1368 trace (" ... with NOSEL\n");
1371 check_item_height();
1374 test_listbox_height();
1375 test_itemfrompoint();
1376 test_listbox_item_data();
1377 test_listbox_LB_DIR();
1378 test_listbox_dlgdir();