include/windows.foundation: Add double reference.
[wine.git] / dlls / combase / tests / wine.combase.test.c
blobe6171c6c6e7f3ae8f406a8cf5b9895d99f54a752
1 /*
2 * Copyright 2022 RĂ©mi Bernon for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stddef.h>
22 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
26 #include "initguid.h"
27 #include "inspectable.h"
28 #include "roapi.h"
29 #include "winstring.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(combase);
35 struct factory
37 IActivationFactory IActivationFactory_iface;
38 LONG ref;
39 BOOL trusted;
42 static inline struct factory *impl_from_IActivationFactory(IActivationFactory *iface)
44 return CONTAINING_RECORD(iface, struct factory, IActivationFactory_iface);
47 static HRESULT WINAPI factory_QueryInterface(IActivationFactory *iface, REFIID iid, void **out)
49 struct factory *impl = impl_from_IActivationFactory(iface);
51 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
53 if (IsEqualGUID(iid, &IID_IUnknown)
54 || IsEqualGUID(iid, &IID_IInspectable)
55 || IsEqualGUID(iid, &IID_IAgileObject)
56 || IsEqualGUID(iid, &IID_IActivationFactory))
58 IInspectable_AddRef((*out = &impl->IActivationFactory_iface));
59 return S_OK;
62 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
63 *out = NULL;
64 return E_NOINTERFACE;
67 static ULONG WINAPI factory_AddRef(IActivationFactory *iface)
69 struct factory *impl = impl_from_IActivationFactory(iface);
70 ULONG ref = InterlockedIncrement(&impl->ref);
71 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
72 return ref;
75 static ULONG WINAPI factory_Release(IActivationFactory *iface)
77 struct factory *impl = impl_from_IActivationFactory(iface);
78 ULONG ref = InterlockedDecrement(&impl->ref);
79 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
80 return ref;
83 static HRESULT WINAPI factory_GetIids(IActivationFactory *iface, ULONG *iid_count, IID **iids)
85 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
86 return E_NOTIMPL;
89 static HRESULT WINAPI factory_GetRuntimeClassName(IActivationFactory *iface, HSTRING *class_name)
91 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
92 return E_NOTIMPL;
95 static HRESULT WINAPI factory_GetTrustLevel(IActivationFactory *iface, TrustLevel *trust_level)
97 struct factory *impl = impl_from_IActivationFactory(iface);
99 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
101 if (!impl->trusted) return E_NOTIMPL;
103 *trust_level = BaseTrust;
104 return S_OK;
107 static HRESULT WINAPI factory_ActivateInstance(IActivationFactory *iface, IInspectable **instance)
109 FIXME("iface %p, instance %p stub!\n", iface, instance);
110 return E_NOTIMPL;
113 static const struct IActivationFactoryVtbl factory_vtbl =
115 factory_QueryInterface,
116 factory_AddRef,
117 factory_Release,
118 /* IInspectable methods */
119 factory_GetIids,
120 factory_GetRuntimeClassName,
121 factory_GetTrustLevel,
122 /* IActivationFactory methods */
123 factory_ActivateInstance,
126 static struct factory class_factory = {{&factory_vtbl}, 0};
127 static struct factory trusted_factory = {{&factory_vtbl}, 0, TRUE};
129 HRESULT WINAPI DllCanUnloadNow(void)
131 FIXME("stub!\n");
132 return S_OK;
135 HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory)
137 const WCHAR *buffer = WindowsGetStringRawBuffer(classid, NULL);
139 FIXME("class %s, factory %p stub!\n", debugstr_w(buffer), factory);
141 if (!wcscmp(buffer, L"Wine.Test.Class"))
143 IActivationFactory_AddRef((*factory = &class_factory.IActivationFactory_iface));
144 return S_OK;
146 if (!wcscmp(buffer, L"Wine.Test.Trusted"))
148 IActivationFactory_AddRef((*factory = &trusted_factory.IActivationFactory_iface));
149 return S_OK;
152 return REGDB_E_CLASSNOTREG;
155 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void **out)
157 FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid), debugstr_guid(riid), out);
158 return CLASS_E_CLASSNOTAVAILABLE;