Commit b724a79e authored by Alexandre Julliard's avatar Alexandre Julliard

comctl32: Fix string comparison for listbox inexact matches.

parent b0db6cfd
......@@ -880,9 +880,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)
......@@ -910,7 +910,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;
......@@ -965,13 +965,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;
......@@ -1002,7 +1002,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;
}
}
......@@ -1017,11 +1017,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;
}
}
}
......
......@@ -2675,6 +2675,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)
{
ULONG_PTR ctx_cookie;
......@@ -2704,6 +2781,7 @@ START_TEST(listbox)
test_WM_MEASUREITEM();
test_LB_SETSEL();
test_LBS_NODATA();
test_LB_FINDSTRING();
unload_v6_module(ctx_cookie, hCtx);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment