Add a test for LB_SELITEMRANGE, make it pass under Wine

Dmitry Timoshkov dmitry at baikal.ru
Thu Dec 1 01:00:34 CST 2005


Hello,

here is another fix for the problem reported by Andreas Rosenberg.

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

diff -up cvs/hq/wine/dlls/user/listbox.c wine/dlls/user/listbox.c
--- cvs/hq/wine/dlls/user/listbox.c	2005-11-10 11:28:36.000000000 +0800
+++ wine/dlls/user/listbox.c	2005-12-01 14:53:41.000000000 +0800
@@ -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 );
     }
diff -up cvs/hq/wine/dlls/user/tests/listbox.c wine/dlls/user/tests/listbox.c
--- cvs/hq/wine/dlls/user/tests/listbox.c	2005-08-30 12:30:21.000000000 +0900
+++ wine/dlls/user/tests/listbox.c	2005-12-01 14:21:24.000000000 +0800
@@ -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-patches mailing list