Nikolay Sivov : oleaut32: Basic parameter validation tests for some GetTypeInfo* methods.

Alexandre Julliard julliard at winehq.org
Wed Dec 22 10:57:39 CST 2010


Module: wine
Branch: master
Commit: c395ae563ef667388b8416926e0dd12381d9e796
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c395ae563ef667388b8416926e0dd12381d9e796

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Dec 22 04:02:03 2010 +0300

oleaut32: Basic parameter validation tests for some GetTypeInfo* methods.

---

 dlls/oleaut32/tests/typelib.c |   34 ++++++++++++++++++++++++++++++++++
 dlls/oleaut32/typelib.c       |    8 ++++----
 dlls/oleaut32/typelib2.c      |   10 +++++++---
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/dlls/oleaut32/tests/typelib.c b/dlls/oleaut32/tests/typelib.c
index 9928311..7aa032e 100644
--- a/dlls/oleaut32/tests/typelib.c
+++ b/dlls/oleaut32/tests/typelib.c
@@ -502,10 +502,31 @@ static void test_TypeInfo(void)
     DISPPARAMS dispparams;
     GUID bogusguid = {0x806afb4f,0x13f7,0x42d2,{0x89,0x2c,0x6c,0x97,0xc3,0x6a,0x36,0xc1}};
     VARIANT var;
+    UINT count;
+    TYPEKIND kind;
 
     hr = LoadTypeLib(wszStdOle2, &pTypeLib);
     ok_ole_success(hr, LoadTypeLib);
 
+    count = ITypeLib_GetTypeInfoCount(pTypeLib);
+    ok(count > 0, "got %d\n", count);
+
+    /* invalid index */
+    hr = ITypeLib_GetTypeInfo(pTypeLib, count, &pTypeInfo);
+    ok(hr == TYPE_E_ELEMENTNOTFOUND, "got 0x%08x\n", hr);
+
+    hr = ITypeLib_GetTypeInfo(pTypeLib, 0, NULL);
+    ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+    hr = ITypeLib_GetTypeInfoType(pTypeLib, count, &kind);
+    ok(hr == TYPE_E_ELEMENTNOTFOUND, "got 0x%08x\n", hr);
+
+    hr = ITypeLib_GetTypeInfoType(pTypeLib, count, NULL);
+    ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+    hr = ITypeLib_GetTypeInfoType(pTypeLib, 0, NULL);
+    ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
     hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pTypeInfo);
     ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid); 
 
@@ -1307,6 +1328,7 @@ static void test_CreateTypeLib(void) {
     int impltypeflags;
     VARIANT cust_data;
     HRESULT hres;
+    TYPEKIND kind;
 
     trace("CreateTypeLib tests\n");
 
@@ -1328,6 +1350,18 @@ static void test_CreateTypeLib(void) {
     hres = ICreateTypeLib_QueryInterface(createtl, &IID_ITypeLib, (void**)&tl);
     ok(hres == S_OK, "got %08x\n", hres);
 
+    hres = ITypeLib_GetTypeInfo(tl, 0, NULL);
+    ok(hres == E_INVALIDARG, "got 0x%08x\n", hres);
+
+    hres = ITypeLib_GetTypeInfoType(tl, 0, &kind);
+    ok(hres == TYPE_E_ELEMENTNOTFOUND, "got 0x%08x\n", hres);
+
+    hres = ITypeLib_GetTypeInfoType(tl, 0, NULL);
+    ok(hres == E_INVALIDARG, "got 0x%08x\n", hres);
+
+    hres = ITypeLib_GetTypeInfoType(tl, 0, NULL);
+    ok(hres == E_INVALIDARG, "got 0x%08x\n", hres);
+
     hres = ITypeLib_GetLibAttr(tl, &libattr);
     ok(hres == S_OK, "got %08x\n", hres);
 
diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c
index 06c464d..8eda482 100644
--- a/dlls/oleaut32/typelib.c
+++ b/dlls/oleaut32/typelib.c
@@ -4278,13 +4278,13 @@ static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
     UINT i;
     ITypeInfoImpl *pTInfo = This->pTypeInfo;
 
-    if (ITypeLib2_fnGetTypeInfoCount(iface) < index + 1)
-    	 return TYPE_E_ELEMENTNOTFOUND;
-
-    TRACE("(%p) index %d\n", This, index);
+    TRACE("(%p, %d, %p)\n", This, index, pTKind);
 
     if(!pTKind) return E_INVALIDARG;
 
+    if(ITypeLib2_GetTypeInfoCount(iface) <= index)
+        return TYPE_E_ELEMENTNOTFOUND;
+
     /* search element n in list */
     for(i=0; i < index; i++)
     {
diff --git a/dlls/oleaut32/typelib2.c b/dlls/oleaut32/typelib2.c
index eccc72b..825dca5 100644
--- a/dlls/oleaut32/typelib2.c
+++ b/dlls/oleaut32/typelib2.c
@@ -4862,6 +4862,8 @@ static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
 
     TRACE("(%p,%d,%p)\n", iface, index, ppTInfo);
 
+    if (!ppTInfo) return E_INVALIDARG;
+
     if (index >= This->typelib_header.nrtypeinfos) {
 	return TYPE_E_ELEMENTNOTFOUND;
     }
@@ -4877,17 +4879,19 @@ static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
 static HRESULT WINAPI ITypeLib2_fnGetTypeInfoType(
         ITypeLib2 * iface,
         UINT index,
-        TYPEKIND* pTKind)
+        TYPEKIND* kind)
 {
     ICreateTypeLib2Impl *This = impl_from_ITypeLib2(iface);
 
-    TRACE("(%p,%d,%p)\n", iface, index, pTKind);
+    TRACE("(%p,%d,%p)\n", iface, index, kind);
+
+    if (!kind) return E_INVALIDARG;
 
     if (index >= This->typelib_header.nrtypeinfos) {
 	return TYPE_E_ELEMENTNOTFOUND;
     }
 
-    *pTKind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 15;
+    *kind = (This->typelib_segment_data[MSFT_SEG_TYPEINFO][This->typelib_typeinfo_offsets[index]]) & 0xF;
 
     return S_OK;
 }




More information about the wine-cvs mailing list