Nikolay Sivov : oleaut32: Some tests for ITypeLib::FindName(), corrected parameter validation.
Alexandre Julliard
julliard at winehq.org
Thu Jan 26 14:49:25 CST 2012
Module: wine
Branch: master
Commit: a23dbc5dc559764bb3ab49d4e0745022cf322eff
URL: http://source.winehq.org/git/wine.git/?a=commit;h=a23dbc5dc559764bb3ab49d4e0745022cf322eff
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Thu Jan 26 13:42:35 2012 +0300
oleaut32: Some tests for ITypeLib::FindName(), corrected parameter validation.
---
dlls/oleaut32/tests/typelib.c | 78 +++++++++++++++++++++++++++++++++++++++-
dlls/oleaut32/typelib.c | 45 ++++++++++++++---------
2 files changed, 103 insertions(+), 20 deletions(-)
diff --git a/dlls/oleaut32/tests/typelib.c b/dlls/oleaut32/tests/typelib.c
index c7c0f93..631f6d8 100644
--- a/dlls/oleaut32/tests/typelib.c
+++ b/dlls/oleaut32/tests/typelib.c
@@ -59,6 +59,8 @@ static HRESULT WINAPI (*pRegisterTypeLibForUser)(ITypeLib*,OLECHAR*,OLECHAR*);
static HRESULT WINAPI (*pUnRegisterTypeLibForUser)(REFGUID,WORD,WORD,LCID,SYSKIND);
static const WCHAR wszStdOle2[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
+static WCHAR wszGUID[] = {'G','U','I','D',0};
+static WCHAR wszguid[] = {'g','u','i','d',0};
static const int is_win64 = sizeof(void *) > sizeof(int);
@@ -116,8 +118,6 @@ static void test_TypeComp(void)
static WCHAR wszUnchecked[] = {'U','n','c','h','e','c','k','e','d',0};
static WCHAR wszIUnknown[] = {'I','U','n','k','n','o','w','n',0};
static WCHAR wszFont[] = {'F','o','n','t',0};
- static WCHAR wszGUID[] = {'G','U','I','D',0};
- static WCHAR wszguid[] = {'g','u','i','d',0};
static WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0};
static WCHAR wszOLE_COLOR[] = {'O','L','E','_','C','O','L','O','R',0};
static WCHAR wszClone[] = {'C','l','o','n','e',0};
@@ -3112,6 +3112,79 @@ static void test_SetVarDocString(void)
DeleteFileA(filenameA);
}
+static void test_FindName(void)
+{
+ static const WCHAR invalidW[] = {'i','n','v','a','l','i','d',0};
+ WCHAR buffW[100];
+ MEMBERID memid;
+ ITypeInfo *ti;
+ ITypeLib *tl;
+ HRESULT hr;
+ UINT16 c;
+
+ hr = LoadTypeLib(wszStdOle2, &tl);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = ITypeLib_FindName(tl, NULL, 0, NULL, NULL, NULL);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+ lstrcpyW(buffW, wszGUID);
+ hr = ITypeLib_FindName(tl, buffW, 0, NULL, NULL, NULL);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+ c = 0;
+ ti = (void*)0xdeadbeef;
+ hr = ITypeLib_FindName(tl, buffW, 0, &ti, NULL, &c);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+ ok(c == 0, "got %d\n", c);
+ ok(ti == (void*)0xdeadbeef, "got %p\n", ti);
+
+ c = 1;
+ ti = (void*)0xdeadbeef;
+ hr = ITypeLib_FindName(tl, buffW, 0, &ti, NULL, &c);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+ ok(c == 1, "got %d\n", c);
+ ok(ti == (void*)0xdeadbeef, "got %p\n", ti);
+
+ c = 1;
+ memid = 0;
+ ti = (void*)0xdeadbeef;
+ hr = ITypeLib_FindName(tl, buffW, 0, &ti, &memid, &c);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+todo_wine
+ ok(memid == -1, "got %d\n", memid);
+ ok(!lstrcmpW(buffW, wszGUID), "got %s\n", wine_dbgstr_w(buffW));
+ ok(c == 1, "got %d\n", c);
+ ITypeInfo_Release(ti);
+
+ c = 1;
+ memid = 0;
+ lstrcpyW(buffW, wszguid);
+ ti = (void*)0xdeadbeef;
+ hr = ITypeLib_FindName(tl, buffW, 0, &ti, &memid, &c);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+todo_wine {
+ ok(memid == -1, "got %d\n", memid);
+ ok(!lstrcmpW(buffW, wszGUID), "got %s\n", wine_dbgstr_w(buffW));
+ ok(c == 1, "got %d\n", c);
+}
+ if (c == 1)
+ ITypeInfo_Release(ti);
+
+ c = 1;
+ memid = -1;
+ lstrcpyW(buffW, invalidW);
+ ti = (void*)0xdeadbeef;
+ hr = ITypeLib_FindName(tl, buffW, 0, &ti, &memid, &c);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(memid == -1, "got %d\n", memid);
+ ok(!lstrcmpW(buffW, invalidW), "got %s\n", wine_dbgstr_w(buffW));
+ ok(c == 0, "got %d\n", c);
+ ok(ti == (void*)0xdeadbeef, "got %p\n", ti);
+
+ ITypeLib_Release(tl);
+}
+
START_TEST(typelib)
{
const char *filename;
@@ -3131,6 +3204,7 @@ START_TEST(typelib)
test_SetVarHelpContext();
test_SetFuncAndParamNames();
test_SetVarDocString();
+ test_FindName();
if ((filename = create_test_typelib(2)))
{
diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c
index 1cab886..07e294b 100644
--- a/dlls/oleaut32/typelib.c
+++ b/dlls/oleaut32/typelib.c
@@ -4587,31 +4587,41 @@ ITypeLib2_fnIsName_exit:
*/
static HRESULT WINAPI ITypeLib2_fnFindName(
ITypeLib2 *iface,
- LPOLESTR szNameBuf,
- ULONG lHashVal,
+ LPOLESTR name,
+ ULONG hash,
ITypeInfo **ppTInfo,
- MEMBERID *rgMemId,
- UINT16 *pcFound)
+ MEMBERID *memid,
+ UINT16 *found)
{
ITypeLibImpl *This = (ITypeLibImpl *)iface;
- TLBVarDesc *pVInfo;
- UINT tic, fdc, pc, count = 0;
- UINT nNameBufLen = (lstrlenW(szNameBuf)+1)*sizeof(WCHAR);
+ UINT tic, count = 0;
+ UINT len;
- for(tic = 0; tic < This->TypeInfoCount; ++tic){
+ TRACE("(%p)->(%s %u %p %p %p)\n", This, debugstr_w(name), hash, ppTInfo, memid, found);
+
+ if ((!name && hash == 0) || !ppTInfo || !memid || !found)
+ return E_INVALIDARG;
+
+ len = (lstrlenW(name) + 1)*sizeof(WCHAR);
+ for(tic = 0; tic < This->TypeInfoCount; ++tic) {
ITypeInfoImpl *pTInfo = This->typeinfos[tic];
- if(!memcmp(szNameBuf,pTInfo->Name, nNameBufLen)) goto ITypeLib2_fnFindName_exit;
+ TLBVarDesc *var;
+ UINT fdc;
+
+ if(!memcmp(name, pTInfo->Name, len)) goto ITypeLib2_fnFindName_exit;
for(fdc = 0; fdc < pTInfo->TypeAttr.cFuncs; ++fdc) {
- TLBFuncDesc *pFInfo = &pTInfo->funcdescs[fdc];
- if(!memcmp(szNameBuf,pFInfo->Name,nNameBufLen)) goto ITypeLib2_fnFindName_exit;
- for(pc = 0;pc < pFInfo->funcdesc.cParams; pc++) {
- if(!memcmp(szNameBuf,pFInfo->pParamDesc[pc].Name,nNameBufLen))
+ TLBFuncDesc *func = &pTInfo->funcdescs[fdc];
+ UINT pc;
+
+ if(!memcmp(name, func->Name, len)) goto ITypeLib2_fnFindName_exit;
+ for(pc = 0; pc < func->funcdesc.cParams; pc++) {
+ if(!memcmp(name, func->pParamDesc[pc].Name, len))
goto ITypeLib2_fnFindName_exit;
}
}
- pVInfo = TLB_get_vardesc_by_name(pTInfo->vardescs, pTInfo->TypeAttr.cVars, szNameBuf);
- if(pVInfo)
+ var = TLB_get_vardesc_by_name(pTInfo->vardescs, pTInfo->TypeAttr.cVars, name);
+ if (var)
goto ITypeLib2_fnFindName_exit;
continue;
@@ -4620,10 +4630,9 @@ ITypeLib2_fnFindName_exit:
ppTInfo[count]=(LPTYPEINFO)pTInfo;
count++;
}
- TRACE("(%p)slow! search for %d with %s: found %d TypeInfos!\n",
- This, *pcFound, debugstr_w(szNameBuf), count);
+ TRACE("found %d typeinfos\n", count);
- *pcFound = count;
+ *found = count;
return S_OK;
}
More information about the wine-cvs
mailing list