Module: wine Branch: master Commit: 343398d23e8d10cc3931ff3fc98ec438c54fac74 URL: https://gitlab.winehq.org/wine/wine/-/commit/343398d23e8d10cc3931ff3fc98ec43...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Dec 19 12:42:49 2023 +0100
user32: Fix string comparison for listbox inexact matches.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55446
---
dlls/user32/listbox.c | 18 +++++------ dlls/user32/tests/listbox.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 9 deletions(-)
diff --git a/dlls/user32/listbox.c b/dlls/user32/listbox.c index 0e925973e84..d3ca2ccb951 100644 --- a/dlls/user32/listbox.c +++ b/dlls/user32/listbox.c @@ -891,9 +891,9 @@ static LRESULT LISTBOX_GetText( LB_DESCR *descr, INT index, LPWSTR buffer, BOOL return len; }
-static inline INT LISTBOX_lstrcmpiW( LCID lcid, LPCWSTR str1, LPCWSTR str2 ) +static inline INT LISTBOX_lstrcmpiW( LCID lcid, LPCWSTR str1, LPCWSTR str2, int len ) { - INT ret = CompareStringW( lcid, NORM_IGNORECASE, str1, -1, str2, -1 ); + INT ret = CompareStringW( lcid, NORM_IGNORECASE, str1, len, str2, len ); if (ret == CSTR_LESS_THAN) return -1; if (ret == CSTR_EQUAL) @@ -921,7 +921,7 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact ) { index = (min + max) / 2; if (HAS_STRINGS(descr)) - res = LISTBOX_lstrcmpiW( descr->locale, get_item_string(descr, index), str ); + res = LISTBOX_lstrcmpiW( descr->locale, get_item_string(descr, index), str, -1 ); else { COMPAREITEMSTRUCT cis; @@ -976,13 +976,13 @@ static INT LISTBOX_FindFileStrPos( LB_DESCR *descr, LPCWSTR str ) else /* directory */ { if (str[1] == '-') res = 1; - else res = LISTBOX_lstrcmpiW( descr->locale, str, p ); + else res = LISTBOX_lstrcmpiW( descr->locale, str, p, -1 ); } } else /* filename */ { if (*str == '[') res = 1; - else res = LISTBOX_lstrcmpiW( descr->locale, str, p ); + else res = LISTBOX_lstrcmpiW( descr->locale, str, p, -1 ); } if (!res) return index; if (res < 0) max = index; @@ -1017,7 +1017,7 @@ static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exa for (i = 0, index = start; i < descr->nb_items; i++, index++) { if (index == descr->nb_items) index = 0; - if (!LISTBOX_lstrcmpiW(descr->locale, str, get_item_string(descr, index))) + if (!LISTBOX_lstrcmpiW(descr->locale, str, get_item_string(descr, index), -1)) return index; } } @@ -1032,11 +1032,11 @@ static INT LISTBOX_FindString( LB_DESCR *descr, INT start, LPCWSTR str, BOOL exa if (index == descr->nb_items) index = 0; item_str = get_item_string(descr, index);
- if (!wcsnicmp(str, item_str, len)) return index; + if (!LISTBOX_lstrcmpiW(descr->locale, str, item_str, len)) return index; if (item_str[0] == '[') { - if (!wcsnicmp(str, item_str + 1, len)) return index; - if (item_str[1] == '-' && !wcsnicmp(str, item_str + 2, len)) return index; + if (!LISTBOX_lstrcmpiW(descr->locale, str, item_str + 1, len)) return index; + if (item_str[1] == '-' && !LISTBOX_lstrcmpiW(descr->locale, str, item_str + 2, len)) return index; } } } diff --git a/dlls/user32/tests/listbox.c b/dlls/user32/tests/listbox.c index 88bf2cc0801..c78171ff4d8 100644 --- a/dlls/user32/tests/listbox.c +++ b/dlls/user32/tests/listbox.c @@ -2421,6 +2421,83 @@ static void test_LBS_NODATA(void) DestroyWindow(parent); }
+static void test_LB_FINDSTRING(void) +{ + static const WCHAR *strings[] = + { + L"abci", + L"AbCI", + L"abcI", + L"abc\xcdzz", + L"abc\xedzz", + L"abc\xcd", + L"abc\xed", + L"abcO", + L"abc\xd8", + L"abcP", + }; + static const struct { const WCHAR *str; LRESULT from, res, exact, alt_res, alt_exact; } tests[] = + { + { L"ab", -1, 0, -1, 0, -1 }, + { L"abc", -1, 0, -1, 0, -1 }, + { L"abci", -1, 0, 0, 0, 0 }, + { L"ABCI", -1, 0, 0, 0, 0 }, + { L"ABC\xed", -1, 3, 3, 3, 3 }, + { L"ABC\xcd", 4, 5, 3, 5, 3 }, + { L"abcp", -1, 9, 9, 8, 8 }, + }; + HWND listbox; + unsigned int i; + LRESULT ret; + + listbox = CreateWindowW( L"listbox", L"TestList", LBS_HASSTRINGS | LBS_SORT, + 0, 0, 100, 100, NULL, NULL, NULL, 0 ); + ok( listbox != NULL, "Failed to create listbox\n" ); + SendMessageW( listbox, LB_SETLOCALE, MAKELANGID( LANG_FRENCH, SUBLANG_DEFAULT ), 0 ); + for (i = 0; i < ARRAY_SIZE(strings); i++) SendMessageW( listbox, LB_ADDSTRING, 0, (LPARAM)strings[i] ); + + for (i = 0; i < ARRAY_SIZE(tests); i++) + { + ret = SendMessageW( listbox, LB_FINDSTRING, tests[i].from, (LPARAM)tests[i].str ); + ok( ret == tests[i].res, "%u: wrong result %Id / %Id\n", i, ret, tests[i].res ); + ret = SendMessageW( listbox, LB_FINDSTRINGEXACT, tests[i].from, (LPARAM)tests[i].str ); + ok( ret == tests[i].exact, "%u: wrong result %Id / %Id\n", i, ret, tests[i].exact ); + } + + SendMessageW( listbox, LB_RESETCONTENT, 0, 0 ); + SendMessageW( listbox, LB_SETLOCALE, MAKELANGID( LANG_SWEDISH, SUBLANG_DEFAULT ), 0 ); + for (i = 0; i < ARRAY_SIZE(strings); i++) SendMessageW( listbox, LB_ADDSTRING, 0, (LPARAM)strings[i] ); + ret = SendMessageW( listbox, LB_FINDSTRING, -1, (LPARAM)L"abcp" ); + for (i = 0; i < ARRAY_SIZE(tests); i++) + { + ret = SendMessageW( listbox, LB_FINDSTRING, tests[i].from, (LPARAM)tests[i].str ); + ok( ret == tests[i].alt_res, "%u: wrong result %Id / %Id\n", i, ret, tests[i].alt_res ); + ret = SendMessageW( listbox, LB_FINDSTRINGEXACT, tests[i].from, (LPARAM)tests[i].str ); + ok( ret == tests[i].alt_exact, "%u: wrong result %Id / %Id\n", i, ret, tests[i].alt_exact ); + } + + SendMessageW( listbox, LB_RESETCONTENT, 0, 0 ); + SendMessageW( listbox, LB_ADDSTRING, 0, (LPARAM)L"abc" ); + SendMessageW( listbox, LB_ADDSTRING, 0, (LPARAM)L"[abc]" ); + SendMessageW( listbox, LB_ADDSTRING, 0, (LPARAM)L"[-abc-]" ); + ret = SendMessageW( listbox, LB_FINDSTRING, -1, (LPARAM)L"abc" ); + ok( ret == 0, "wrong result %Id\n", ret ); + ret = SendMessageW( listbox, LB_FINDSTRINGEXACT, -1, (LPARAM)L"abc" ); + todo_wine + ok( ret == 0, "wrong result %Id\n", ret ); + ret = SendMessageW( listbox, LB_FINDSTRING, 0, (LPARAM)L"abc" ); + ok( ret == 1, "wrong result %Id\n", ret ); + ret = SendMessageW( listbox, LB_FINDSTRINGEXACT, 0, (LPARAM)L"abc" ); + todo_wine + ok( ret == 0, "wrong result %Id\n", ret ); + ret = SendMessageW( listbox, LB_FINDSTRING, 1, (LPARAM)L"abc" ); + ok( ret == 2, "wrong result %Id\n", ret ); + ret = SendMessageW( listbox, LB_FINDSTRINGEXACT, 1, (LPARAM)L"abc" ); + todo_wine + ok( ret == 0, "wrong result %Id\n", ret ); + DestroyWindow( listbox ); +} + START_TEST(listbox) { const struct listbox_test SS = @@ -2520,4 +2597,5 @@ START_TEST(listbox) test_WM_MEASUREITEM(); test_LB_SETSEL(); test_LBS_NODATA(); + test_LB_FINDSTRING(); }