[PATCH v2 3/5] comsvcs: Implement ISharedPropertyGroupManager_CreatePropertyGroup().

Jactry Zeng jzeng at codeweavers.com
Wed Aug 19 02:48:58 CDT 2020


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
v2:
- Storage struct group_manager * instead of ISharedPropertyGroupManager * in struct property_group;
- Storage property groups to a link instead of an array;
- Add more tests of ISharedPropertyGroupManager_CreatePropertyGroup().

 dlls/comsvcs/comsvcs_private.h |   2 +
 dlls/comsvcs/property.c        | 257 ++++++++++++++++++++++++++++++++-
 dlls/comsvcs/tests/property.c  | 128 ++++++++++++++++
 include/winerror.h             |  11 ++
 4 files changed, 394 insertions(+), 4 deletions(-)

diff --git a/dlls/comsvcs/comsvcs_private.h b/dlls/comsvcs/comsvcs_private.h
index 8a67bcffd8..eee6e9938c 100644
--- a/dlls/comsvcs/comsvcs_private.h
+++ b/dlls/comsvcs/comsvcs_private.h
@@ -37,6 +37,7 @@ enum tid_t
 {
     NULL_tid,
     ISharedPropertyGroupManager_tid,
+    ISharedPropertyGroup_tid,
     LAST_tid
 };
 
@@ -44,6 +45,7 @@ static REFIID tid_ids[] =
 {
     &IID_NULL,
     &IID_ISharedPropertyGroupManager,
+    &IID_ISharedPropertyGroup,
 };
 
 HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo);
diff --git a/dlls/comsvcs/property.c b/dlls/comsvcs/property.c
index e4aeab924d..81b13a2cc8 100644
--- a/dlls/comsvcs/property.c
+++ b/dlls/comsvcs/property.c
@@ -17,12 +17,26 @@
  */
 
 #include <comsvcs_private.h>
+#include <wine/list.h>
 
 WINE_DEFAULT_DEBUG_CHANNEL(comsvcs);
 
+struct group_manager;
+
+struct property_group
+{
+    ISharedPropertyGroup ISharedPropertyGroup_iface;
+    struct group_manager *parent;
+    LONG isolation, release;
+    struct list entry;
+    LONG refcount;
+    BSTR name;
+};
+
 struct group_manager
 {
     ISharedPropertyGroupManager ISharedPropertyGroupManager_iface;
+    struct list property_groups;
     LONG refcount;
     CRITICAL_SECTION cs;
 };
@@ -34,6 +48,166 @@ static inline struct group_manager *impl_from_ISharedPropertyGroupManager(IShare
     return CONTAINING_RECORD(iface, struct group_manager, ISharedPropertyGroupManager_iface);
 }
 
+static inline struct property_group *impl_from_ISharedPropertyGroup(ISharedPropertyGroup *iface)
+{
+    return CONTAINING_RECORD(iface, struct property_group, ISharedPropertyGroup_iface);
+}
+
+static HRESULT WINAPI property_group_QueryInterface(ISharedPropertyGroup *iface, REFIID riid, void **out)
+{
+    struct property_group *group = impl_from_ISharedPropertyGroup(iface);
+
+    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
+
+    *out = NULL;
+    if (IsEqualGUID(riid, &IID_IUnknown)
+            || IsEqualGUID(riid, &IID_IDispatch)
+            || IsEqualGUID(riid, &IID_ISharedPropertyGroup))
+    {
+        *out = &group->ISharedPropertyGroup_iface;
+        IUnknown_AddRef((IUnknown*)*out);
+
+        return S_OK;
+    }
+
+    WARN("%s not implemented.\n", debugstr_guid(riid));
+    return E_NOINTERFACE;
+}
+
+static ULONG WINAPI property_group_AddRef(ISharedPropertyGroup *iface)
+{
+    struct property_group *group = impl_from_ISharedPropertyGroup(iface);
+    ULONG refcount = InterlockedIncrement(&group->refcount);
+
+    TRACE("%p increasing refcount to %u.\n", iface, refcount);
+
+    return refcount;
+}
+
+static ULONG WINAPI property_group_Release(ISharedPropertyGroup *iface)
+{
+    struct property_group *group = impl_from_ISharedPropertyGroup(iface);
+    ULONG refcount = InterlockedDecrement(&group->refcount);
+
+    TRACE("%p decreasing refcount to %u.\n", iface, refcount);
+
+    if (!refcount)
+    {
+        struct group_manager *manager = group->parent;
+
+        SysFreeString(group->name);
+
+        EnterCriticalSection(&manager->cs);
+        list_remove(&group->entry);
+        LeaveCriticalSection(&manager->cs);
+
+        ISharedPropertyGroupManager_Release(&manager->ISharedPropertyGroupManager_iface);
+    }
+
+    return refcount;
+}
+
+static HRESULT WINAPI property_group_GetTypeInfoCount(ISharedPropertyGroup *iface, UINT *info)
+{
+    TRACE("iface %p, info %p.\n", iface, info);
+
+    if (!info)
+        return E_INVALIDARG;
+    *info = 1;
+    return S_OK;
+}
+
+static HRESULT WINAPI property_group_GetTypeInfo(ISharedPropertyGroup *iface, UINT index, LCID lcid, ITypeInfo **info)
+{
+    HRESULT hr;
+
+    TRACE("iface %p, index %u, lcid %u, info %p.\n", iface, index, lcid, info);
+
+    if (index)
+        return DISP_E_BADINDEX;
+
+    hr = get_typeinfo(ISharedPropertyGroup_tid, info);
+    if (SUCCEEDED(hr))
+        ITypeInfo_AddRef(*info);
+    return hr;
+}
+
+static HRESULT WINAPI property_group_GetIDsOfNames(ISharedPropertyGroup *iface, REFIID riid, LPOLESTR *names, UINT count,
+        LCID lcid, DISPID *dispid)
+{
+    ITypeInfo *typeinfo;
+    HRESULT hr;
+
+    TRACE("iface %p, riid %s, names %p, count %u, lcid %u, dispid %p.\n",
+            iface, debugstr_guid(riid), names, count, lcid, dispid);
+
+    hr = get_typeinfo(ISharedPropertyGroup_tid, &typeinfo);
+    if (SUCCEEDED(hr))
+    {
+        hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, dispid);
+        ITypeInfo_Release(typeinfo);
+    }
+
+    return hr;
+}
+
+static HRESULT WINAPI property_group_Invoke(ISharedPropertyGroup *iface, DISPID member, REFIID riid, LCID lcid,
+        WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *except, UINT *argerr)
+{
+    ITypeInfo *typeinfo;
+    HRESULT hr;
+
+    TRACE("iface %p, member %u, riid %s, lcid %u, flags %x, params %p, result %p, except %p, argerr %p.\n",
+            iface, member, debugstr_guid(riid), lcid, flags, params, result, except, argerr);
+
+    hr = get_typeinfo(ISharedPropertyGroup_tid, &typeinfo);
+    if (SUCCEEDED(hr))
+        hr = ITypeInfo_Invoke(typeinfo, iface, member, flags, params, result, except, argerr);
+    return hr;
+}
+
+static HRESULT WINAPI property_group_CreatePropertyByPosition(ISharedPropertyGroup *iface, int index,
+        VARIANT_BOOL *exists, ISharedProperty **property)
+{
+    FIXME("iface %p, index %d, exisits %p, property %p: stub.\n",
+            iface, index, exists, property);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI property_group_get_PropertyByPosition(ISharedPropertyGroup *iface, int index, ISharedProperty **property)
+{
+    FIXME("iface %p, index %d, property %p: stub.\n", iface, index, property);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI property_group_CreateProperty(ISharedPropertyGroup *iface, BSTR name, VARIANT_BOOL *exists,
+        ISharedProperty **property)
+{
+    FIXME("iface %p, name %s, exists %p, property %p: stub.\n", iface, debugstr_w(name), exists, property);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI property_group_get_Property(ISharedPropertyGroup *iface, BSTR name, ISharedProperty **property)
+{
+    FIXME("iface %p, name %s, property %p: stub.\n", iface, debugstr_w(name), property);
+    return E_NOTIMPL;
+}
+
+static const ISharedPropertyGroupVtbl property_group_vtbl =
+{
+    property_group_QueryInterface,
+    property_group_AddRef,
+    property_group_Release,
+    property_group_GetTypeInfoCount,
+    property_group_GetTypeInfo,
+    property_group_GetIDsOfNames,
+    property_group_Invoke,
+    property_group_CreatePropertyByPosition,
+    property_group_get_PropertyByPosition,
+    property_group_CreateProperty,
+    property_group_get_Property,
+};
+
 static HRESULT WINAPI group_manager_QueryInterface(ISharedPropertyGroupManager *iface, REFIID riid, void **out)
 {
     struct group_manager *manager = impl_from_ISharedPropertyGroupManager(iface);
@@ -74,10 +248,21 @@ static ULONG WINAPI group_manager_Release(ISharedPropertyGroupManager *iface)
 
     if (!refcount)
     {
+        if (!list_empty(&manager->property_groups))
+        {
+            struct property_group *group, *group2;
+
+            LIST_FOR_EACH_ENTRY_SAFE(group, group2, &manager->property_groups, struct property_group, entry)
+            {
+                list_remove(&group->entry);
+                SysFreeString(group->name);
+                heap_free(group);
+            }
+        }
+        manager->cs.DebugInfo->Spare[0] = 0;
+        DeleteCriticalSection(&manager->cs);
         heap_free(manager);
         group_manager = NULL;
-        group_manager->cs.DebugInfo->Spare[0] = 0;
-        DeleteCriticalSection(&group_manager->cs);
     }
 
     return refcount;
@@ -142,12 +327,74 @@ static HRESULT WINAPI group_manager_Invoke(ISharedPropertyGroupManager *iface, D
     return hr;
 }
 
+static struct property_group *find_propery_group(struct group_manager *manager, BSTR name)
+{
+    struct property_group *group, *group2;
+
+    LIST_FOR_EACH_ENTRY_SAFE(group, group2, &group_manager->property_groups, struct property_group, entry)
+    {
+        if (!lstrcmpW(group->name, name))
+            return group;
+    }
+    return NULL;
+}
+
 static HRESULT WINAPI group_manager_CreatePropertyGroup(ISharedPropertyGroupManager *iface, BSTR name, LONG *isolation,
         LONG *release, VARIANT_BOOL *exists, ISharedPropertyGroup **group)
 {
-    FIXME("iface %p, name %s, isolation %p, release %p, exists %p, group %p: stub.\n",
+    struct group_manager *manager = impl_from_ISharedPropertyGroupManager(iface);
+    struct property_group *property_group;
+    HRESULT hr;
+
+    TRACE("iface %p, name %s, isolation %p, release %p, exists %p, group %p.\n",
             iface, debugstr_w(name), isolation, release, exists, group);
-    return E_NOTIMPL;
+
+    if (!name)
+        return E_POINTER;
+
+    if (*isolation > 1 || *release > 1)
+        return E_INVALIDARG;
+
+    if (*isolation || *release)
+        FIXME("Unsopported mode: isolation %d, release %d.\n", *isolation, *release);
+
+    EnterCriticalSection(&manager->cs);
+
+    property_group = find_propery_group(manager, name);
+    if (!property_group)
+    {
+        property_group = heap_alloc(sizeof(*property_group));
+        if (!property_group)
+        {
+            LeaveCriticalSection(&manager->cs);
+            return E_OUTOFMEMORY;
+        }
+        property_group->ISharedPropertyGroup_iface.lpVtbl = &property_group_vtbl;
+        property_group->parent = manager;
+        property_group->isolation = *isolation;
+        property_group->release = *release;
+        property_group->refcount = 1;
+        property_group->name = SysAllocString(name);
+
+        list_add_tail(&manager->property_groups, &property_group->entry);
+
+        *exists = FALSE;
+        *group = &property_group->ISharedPropertyGroup_iface;
+        ISharedPropertyGroupManager_AddRef(&property_group->parent->ISharedPropertyGroupManager_iface);
+        hr = S_OK;
+    }
+    else
+    {
+        *exists = TRUE;
+        *isolation = property_group->isolation;
+        *release = property_group->release;
+        hr = ISharedPropertyGroup_QueryInterface(&property_group->ISharedPropertyGroup_iface,
+                &IID_ISharedPropertyGroup, (void **)group);
+    }
+
+    LeaveCriticalSection(&manager->cs);
+
+    return hr;
 }
 
 static HRESULT WINAPI group_manager_get_Group(ISharedPropertyGroupManager *iface, BSTR name, ISharedPropertyGroup **group)
@@ -194,6 +441,8 @@ HRESULT WINAPI group_manager_create(IClassFactory *iface, IUnknown *outer, REFII
 
         group_manager->ISharedPropertyGroupManager_iface.lpVtbl = &group_manager_vtbl;
         group_manager->refcount = 1;
+        list_init(&group_manager->property_groups);
+
         InitializeCriticalSection(&group_manager->cs);
         group_manager->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ISharedPropertyGroupManager.cs");
     }
diff --git a/dlls/comsvcs/tests/property.c b/dlls/comsvcs/tests/property.c
index 140f62dfc0..1008b04c53 100644
--- a/dlls/comsvcs/tests/property.c
+++ b/dlls/comsvcs/tests/property.c
@@ -161,11 +161,139 @@ static void test_interfaces(void)
     ISharedPropertyGroupManager_Release(manager);
 }
 
+static void test_property_group(void)
+{
+    ISharedPropertyGroup *group, *group1;
+    ISharedPropertyGroupManager *manager;
+    ULONG refcount, expected_refcount;
+    LONG isolation, release;
+    VARIANT_BOOL exists;
+    IDispatch *dispatch;
+    HRESULT hr;
+    BSTR name;
+    struct test_name_id test_name_ids[] =
+    {
+        {L"CreatePropertyByPosition", 0x1},
+        {L"PropertyByPosition", 0x2},
+        {L"CreateProperty", 0x3},
+        {L"Property", 0x4},
+    };
+
+    hr = CoCreateInstance(&CLSID_SharedPropertyGroupManager, NULL, CLSCTX_INPROC_SERVER,
+            &IID_ISharedPropertyGroupManager, (void **)&manager);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+
+    hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, NULL, &isolation, &release, &exists, &group);
+    ok(hr == E_POINTER, "Got hr %#x.\n", hr);
+
+    name = SysAllocString(L"testgroupname");
+    isolation = 2;
+    release = 0;
+    hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group);
+    ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
+
+    /* Crash on Windows */
+    if (0)
+    {
+        ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, NULL, &release, &exists, &group);
+        ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, NULL, &exists, &group);
+        ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, NULL, &group);
+    }
+
+    isolation = 0;
+    release = 2;
+    hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group);
+    ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
+
+    isolation = 1;
+    release = 0;
+    hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group);
+    todo_wine ok(hr == CONTEXT_E_NOCONTEXT, "Got hr %#x.\n", hr);
+    if (group)
+        ISharedPropertyGroup_Release(group);
+
+    isolation = 0;
+    release = 0;
+    exists = TRUE;
+    expected_refcount = get_refcount(manager) + 1;
+    hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+    ok(!exists, "Got unexpected value %d.\n", exists);
+    refcount = get_refcount(group);
+    ok(refcount == 1, "Got unexpected refcount: %d.\n", refcount);
+    refcount = get_refcount(manager);
+    ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+
+    refcount = get_refcount(manager);
+    ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+    ISharedPropertyGroup_AddRef(group);
+    refcount = get_refcount(manager);
+    ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+    ISharedPropertyGroup_Release(group);
+    refcount = get_refcount(manager);
+    ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+
+    /* Create an existing group */
+    isolation = 1;
+    release = 1;
+    expected_refcount = get_refcount(manager);
+    hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group1);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+    ok(!!exists, "Got unexpected value %d.\n", exists);
+    ok(!isolation, "Got unexpected value %d.\n", isolation);
+    ok(!release, "Got unexpected value %d.\n", release);
+    ok(group == group1, "Got unexpected pointer: %p.\n", group1);
+    refcount = get_refcount(group);
+    ok(refcount == 2, "Got unexpected refcount: %d.\n", refcount);
+    refcount = get_refcount(manager);
+    ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+    ISharedPropertyGroup_Release(group1);
+    refcount = get_refcount(group);
+    ok(refcount == 1, "Got unexpected refcount: %d.\n", refcount);
+    SysFreeString(name);
+
+    name = SysAllocString(L"testgroupname2");
+    isolation = 0;
+    release = 1;
+    exists = TRUE;
+    expected_refcount = get_refcount(manager) + 1;
+    hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group1);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+    ok(!exists, "Got unexpected value %d.\n", exists);
+    refcount = get_refcount(group1);
+    todo_wine ok(refcount == 2, "Got unexpected refcount: %d.\n", refcount);
+    refcount = get_refcount(manager);
+    ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+    SysFreeString(name);
+
+    hr = ISharedPropertyGroup_QueryInterface(group, &IID_IDispatch, (void **)&dispatch);
+    ok(hr == S_OK, "Got hr %#x.\n", hr);
+    TEST_TYPEINFO(dispatch, test_name_ids, ARRAY_SIZE(test_name_ids), &IID_ISharedPropertyGroup);
+    IDispatch_Release(dispatch);
+
+    expected_refcount = get_refcount(manager);
+    ISharedPropertyGroup_Release(group1);
+    refcount = get_refcount(manager);
+    todo_wine ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+    expected_refcount = get_refcount(manager) - 1;
+    ISharedPropertyGroup_Release(group1);
+    refcount = get_refcount(manager);
+    todo_wine ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+
+    expected_refcount = get_refcount(manager) - 1;
+    ISharedPropertyGroup_Release(group);
+    refcount = get_refcount(manager);
+    ok(refcount == expected_refcount, "Got refcount: %d, expected %d.\n", refcount, expected_refcount);
+
+    ISharedPropertyGroupManager_Release(manager);
+}
+
 START_TEST(property)
 {
     CoInitialize(NULL);
 
     test_interfaces();
+    test_property_group();
 
     CoUninitialize();
 }
diff --git a/include/winerror.h b/include/winerror.h
index 4ebb48c124..ef5279201d 100644
--- a/include/winerror.h
+++ b/include/winerror.h
@@ -3036,6 +3036,17 @@ static inline HRESULT HRESULT_FROM_WIN32(unsigned int x)
 #define CO_E_DECODEFAILED                                  _HRESULT_TYPEDEF_(0x8004021A)
 #define CO_E_ACNOTINITIALIZED                              _HRESULT_TYPEDEF_(0x8004021B)
 
+#define CONTEXT_E_ABORTED                                  _HRESULT_TYPEDEF_(0x8004e002)
+#define CONTEXT_E_ABORTING                                 _HRESULT_TYPEDEF_(0x8004e003)
+#define CONTEXT_E_NOCONTEXT                                _HRESULT_TYPEDEF_(0x8004e004)
+#define CONTEXT_E_WOULD_DEADLOCK                           _HRESULT_TYPEDEF_(0x8004e005)
+#define CONTEXT_E_SYNCH_TIMEOUT                            _HRESULT_TYPEDEF_(0x8004e006)
+#define CONTEXT_E_OLDREF                                   _HRESULT_TYPEDEF_(0x8004e007)
+#define CONTEXT_E_ROLENOTFOUND                             _HRESULT_TYPEDEF_(0x8004e00c)
+#define CONTEXT_E_TMNOTAVAILABLE                           _HRESULT_TYPEDEF_(0x8004e00f)
+#define CONTEXT_E_NOJIT                                    _HRESULT_TYPEDEF_(0x8004e026)
+#define CONTEXT_E_NOTRANSACTION                            _HRESULT_TYPEDEF_(0x8004e027)
+
 /* Task Scheduler Service Error Codes */
 #define SCHED_S_TASK_READY                                 _HRESULT_TYPEDEF_(0x00041300)
 #define SCHED_S_TASK_RUNNING                               _HRESULT_TYPEDEF_(0x00041301)
-- 
2.28.0




More information about the wine-devel mailing list