wine/dlls/user listbox.c tests/listbox.c

Alexandre Julliard julliard at wine.codeweavers.com
Thu Dec 1 05:59:24 CST 2005


ChangeSet ID:	21588
CVSROOT:	/opt/cvs-commit
Module name:	wine
Changes by:	julliard at winehq.org	2005/12/01 05:59:24

Modified files:
	dlls/user      : listbox.c 
	dlls/user/tests: listbox.c 

Log message:
	Dmitry Timoshkov <dmitry at codeweavers.com>
	Add a test for LB_SELITEMRANGE, make it pass under Wine.

Patch: http://cvs.winehq.org/patch.py?id=21588

Old revision  New revision  Changes     Path
 1.25          1.26          +7 -5       wine/dlls/user/listbox.c
 1.11          1.12          +87 -0      wine/dlls/user/tests/listbox.c

Index: wine/dlls/user/listbox.c
diff -u -p wine/dlls/user/listbox.c:1.25 wine/dlls/user/listbox.c:1.26
--- wine/dlls/user/listbox.c:1.25	1 Dec 2005 11:59:24 -0000
+++ wine/dlls/user/listbox.c	1 Dec 2005 11:59:24 -0000
@@ -1380,11 +1380,13 @@ static LRESULT LISTBOX_SelectItemRange( 
     /* A few sanity checks */
 
     if (descr->style & LBS_NOSEL) return LB_ERR;
-    if ((last == -1) && (descr->nb_items == 0)) return LB_OKAY;
     if (!(descr->style & LBS_MULTIPLESEL)) return LB_ERR;
-    if (last == -1) last = descr->nb_items - 1;
-    if ((first < 0) || (first >= descr->nb_items)) return LB_ERR;
-    if ((last < 0) || (last >= descr->nb_items)) return LB_ERR;
+
+    if (!descr->nb_items) return LB_OKAY;
+
+    if (last >= descr->nb_items) last = descr->nb_items - 1;
+    if (first < 0) first = 0;
+    if (last < first) return LB_OKAY;
 
     if (on)  /* Turn selection on */
     {
@@ -1424,7 +1426,7 @@ static LRESULT LISTBOX_SetSelection( LB_
     if (descr->style & LBS_MULTIPLESEL)
     {
         if (index == -1)  /* Select all items */
-            return LISTBOX_SelectItemRange( descr, 0, -1, on );
+            return LISTBOX_SelectItemRange( descr, 0, descr->nb_items, on );
         else  /* Only one item */
             return LISTBOX_SelectItemRange( descr, index, index, on );
     }
Index: wine/dlls/user/tests/listbox.c
diff -u -p wine/dlls/user/tests/listbox.c:1.11 wine/dlls/user/tests/listbox.c:1.12
--- wine/dlls/user/tests/listbox.c:1.11	1 Dec 2005 11:59:24 -0000
+++ wine/dlls/user/tests/listbox.c	1 Dec 2005 11:59:24 -0000
@@ -304,6 +304,92 @@ static void test_ownerdraw(void)
     DestroyWindow(parent);
 }
 
+#define listbox_test_query(exp, got) \
+  ok(exp.selected == got.selected, "expected selected %d, got %d\n", exp.selected, got.selected); \
+  ok(exp.anchor == got.anchor, "expected anchor %d, got %d\n", exp.anchor, got.anchor); \
+  ok(exp.caret == got.caret, "expected caret %d, got %d\n", exp.caret, got.caret); \
+  ok(exp.selcount == got.selcount, "expected selcount %d, got %d\n", exp.selcount, got.selcount);
+
+static void test_selection(void)
+{
+    static const struct listbox_stat test_nosel = { 0, LB_ERR, 0, 0 };
+    static const struct listbox_stat test_1 = { 0, LB_ERR, 0, 2 };
+    static const struct listbox_stat test_2 = { 0, LB_ERR, 0, 3 };
+    static const struct listbox_stat test_3 = { 0, LB_ERR, 0, 4 };
+    HWND hLB;
+    struct listbox_stat answer;
+    INT ret;
+
+    trace("testing LB_SELITEMRANGE\n");
+
+    hLB = create_listbox(LBS_EXTENDEDSEL, 0);
+    assert(hLB);
+
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
+    ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_1, answer);
+
+    SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(0, 4));
+    ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_3, answer);
+
+    SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(-5, 5));
+    ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(2, 10));
+    ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_1, answer);
+
+    SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(4, 10));
+    ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(10, 1));
+    ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_2, answer);
+
+    SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_nosel, answer);
+
+    ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, -1));
+    ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
+    listbox_query(hLB, &answer);
+    listbox_test_query(test_2, answer);
+
+    DestroyWindow(hLB);
+}
+
 START_TEST(listbox)
 {
   const struct listbox_test SS =
@@ -376,4 +462,5 @@ START_TEST(listbox)
 
   check_item_height();
   test_ownerdraw();
+  test_selection();
 }



More information about the wine-cvs mailing list