mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-31 11:43:31 +00:00
wbemprox: Reimplement LIKE.
Current implementation handles correctly % only at the end of the string. Nothing else matches. The new implementation while naïve and recursive handles both _ and * correctly.
This commit is contained in:
parent
332d48364f
commit
f67279c57f
2 changed files with 39 additions and 34 deletions
|
@ -93,23 +93,30 @@ void destroy_view( struct view *view )
|
||||||
free( view );
|
free( view );
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL eval_like( const WCHAR *lstr, const WCHAR *rstr )
|
static BOOL eval_like( const WCHAR *text, const WCHAR *pattern )
|
||||||
{
|
{
|
||||||
const WCHAR *p = lstr, *q = rstr;
|
if (wcsstr( pattern, L"[" )) FIXME( "character ranges (i.e. [abc], [^a-z]) are not supported\n" );
|
||||||
|
|
||||||
while (*p && *q)
|
while (*text)
|
||||||
{
|
{
|
||||||
if (q[0] == '\\' && q[1] == '\\') q++;
|
if (pattern[0] == '\\' && pattern[1] == '\\') pattern++;
|
||||||
if (*q == '%')
|
|
||||||
|
if (*pattern == '%')
|
||||||
{
|
{
|
||||||
while (*q == '%') q++;
|
while (*pattern == '%') pattern++;
|
||||||
if (!*q) return TRUE;
|
if (!*pattern) return TRUE;
|
||||||
while (*p && *q && towupper( *p ) == towupper( *q )) { p++; q++; };
|
while (!eval_like( text, pattern ) && *text) text++;
|
||||||
if (!*p && !*q) return TRUE;
|
|
||||||
|
return !!*text;
|
||||||
}
|
}
|
||||||
if (*q != '%' && towupper( *p++ ) != towupper( *q++ )) return FALSE;
|
|
||||||
|
if (*pattern != '_' && towupper( *text ) != towupper( *pattern )) return FALSE;
|
||||||
|
text++; pattern++;
|
||||||
}
|
}
|
||||||
return TRUE;
|
|
||||||
|
while (*pattern == '%') pattern++;
|
||||||
|
|
||||||
|
return *pattern == '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT eval_strcmp( UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val )
|
static HRESULT eval_strcmp( UINT op, const WCHAR *lstr, const WCHAR *rstr, LONGLONG *val )
|
||||||
|
|
|
@ -140,7 +140,7 @@ static void test_select( IWbemServices *services )
|
||||||
SysFreeString( query );
|
SysFreeString( query );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_explorer_like_query( IWbemServices *services, const WCHAR *str, BOOL expect_success, BOOL todo)
|
static void check_explorer_like_query( IWbemServices *services, const WCHAR *str, BOOL expect_success)
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
IWbemClassObject *obj[2];
|
IWbemClassObject *obj[2];
|
||||||
|
@ -155,7 +155,6 @@ static void check_explorer_like_query( IWbemServices *services, const WCHAR *str
|
||||||
VARIANT var;
|
VARIANT var;
|
||||||
IEnumWbemClassObject_Next( result, 10000, 2, obj, &count );
|
IEnumWbemClassObject_Next( result, 10000, 2, obj, &count );
|
||||||
|
|
||||||
todo_wine_if(todo)
|
|
||||||
ok( count == (expect_success ? 1 : 0), "expected to get %d results but got %lu\n",
|
ok( count == (expect_success ? 1 : 0), "expected to get %d results but got %lu\n",
|
||||||
(expect_success ? 1 : 0), count);
|
(expect_success ? 1 : 0), count);
|
||||||
|
|
||||||
|
@ -184,36 +183,35 @@ static void test_like_query( IWbemServices *services )
|
||||||
WCHAR query[250];
|
WCHAR query[250];
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
BOOL todo;
|
|
||||||
BOOL expect_success;
|
BOOL expect_success;
|
||||||
const WCHAR *str;
|
const WCHAR *str;
|
||||||
} queries[] = {
|
} queries[] = {
|
||||||
{ FALSE, TRUE, L"explorer%" },
|
{ TRUE, L"explorer%" },
|
||||||
{ FALSE, FALSE, L"xplorer.exe" },
|
{ FALSE, L"xplorer.exe" },
|
||||||
{ TRUE, FALSE, L"explorer.ex" },
|
{ FALSE, L"explorer.ex" },
|
||||||
{ FALSE, TRUE, L"%explorer%" },
|
{ TRUE, L"%explorer%" },
|
||||||
{ FALSE, TRUE, L"explorer.exe%" },
|
{ TRUE, L"explorer.exe%" },
|
||||||
{ FALSE, TRUE, L"%explorer.exe%" },
|
{ TRUE, L"%explorer.exe%" },
|
||||||
{ TRUE, TRUE, L"%plorer.exe" },
|
{ TRUE, L"%plorer.exe" },
|
||||||
{ TRUE, TRUE, L"%plorer.exe%" },
|
{ TRUE, L"%plorer.exe%" },
|
||||||
{ TRUE, TRUE, L"__plorer.exe" },
|
{ TRUE, L"__plorer.exe" },
|
||||||
{ TRUE, TRUE, L"e_plorer.exe" },
|
{ TRUE, L"e_plorer.exe" },
|
||||||
{ FALSE, FALSE, L"_plorer.exe" },
|
{ FALSE, L"_plorer.exe" },
|
||||||
{ TRUE, TRUE, L"%%%plorer.e%" },
|
{ TRUE, L"%%%plorer.e%" },
|
||||||
{ TRUE, TRUE, L"%plorer.e%" },
|
{ TRUE, L"%plorer.e%" },
|
||||||
{ TRUE, TRUE, L"%plorer.e_e" },
|
{ TRUE, L"%plorer.e_e" },
|
||||||
{ TRUE, TRUE, L"%plorer.e_e" },
|
{ TRUE, L"%plorer.e_e" },
|
||||||
{ TRUE, TRUE, L"explore%exe" },
|
{ TRUE, L"explore%exe" },
|
||||||
{ FALSE, FALSE, L"fancy_explore.exe" },
|
{ FALSE, L"fancy_explore.exe" },
|
||||||
{ FALSE, FALSE, L"fancy%xplore%exe" },
|
{ FALSE, L"fancy%xplore%exe" },
|
||||||
{ FALSE, FALSE, L"%%%f%xplore%exe" },
|
{ FALSE, L"%%%f%xplore%exe" },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; i < ARRAYSIZE(queries); i++)
|
for (i = 0; i < ARRAYSIZE(queries); i++)
|
||||||
{
|
{
|
||||||
wsprintfW( query, L"SELECT * FROM Win32_Process WHERE Caption LIKE '%ls'", queries[i].str );
|
wsprintfW( query, L"SELECT * FROM Win32_Process WHERE Caption LIKE '%ls'", queries[i].str );
|
||||||
trace("%s\n", wine_dbgstr_w(query));
|
trace("%s\n", wine_dbgstr_w(query));
|
||||||
check_explorer_like_query( services, query, queries[i].expect_success, queries[i].todo );
|
check_explorer_like_query( services, query, queries[i].expect_success );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue