mfreadwrite/reader: Add missing allocation check (Coverity).
[wine/zf.git] / dlls / combase / tests / roapi.c
blobb9cb476aafed070fbb4d59ee1e422c233f0e9947
1 /*
2 * Copyright (c) 2018 Alistair Leslie-Hughes
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
18 #define COBJMACROS
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winerror.h"
24 #include "winstring.h"
26 #include "initguid.h"
27 #include "roapi.h"
30 #include "wine/test.h"
32 static HRESULT (WINAPI *pRoActivateInstance)(HSTRING, IInspectable **);
33 static HRESULT (WINAPI *pRoInitialize)(RO_INIT_TYPE);
34 static void (WINAPI *pRoUninitialize)(void);
35 static HRESULT (WINAPI *pRoGetActivationFactory)(HSTRING, REFIID, void **);
37 static HRESULT (WINAPI *pWindowsCreateString)(LPCWSTR, UINT32, HSTRING *);
38 static HRESULT (WINAPI *pWindowsDeleteString)(HSTRING);
40 #define SET(x) p##x = (void*)GetProcAddress(hmod, #x)
42 static BOOL init_functions(void)
44 HMODULE hmod = LoadLibraryA("combase.dll");
45 if (!hmod)
47 win_skip("Failed to load combase.dll, skipping tests\n");
48 return FALSE;
50 SET(RoActivateInstance);
51 SET(RoInitialize);
52 SET(RoUninitialize);
53 SET(RoGetActivationFactory);
55 SET(WindowsCreateString);
56 SET(WindowsDeleteString);
58 return TRUE;
61 static void test_ActivationFactories(void)
63 HRESULT hr;
64 HSTRING str, str2;
65 IActivationFactory *factory = NULL;
66 IInspectable *inspect = NULL;
68 if(!pRoGetActivationFactory || !pRoActivateInstance)
70 win_skip("RoGetActivationFactory not available\n");
71 return;
74 hr = pWindowsCreateString(L"Windows.Data.Xml.Dom.XmlDocument",
75 ARRAY_SIZE(L"Windows.Data.Xml.Dom.XmlDocument") - 1, &str);
76 ok(hr == S_OK, "got %08x\n", hr);
78 hr = pWindowsCreateString(L"Does.Not.Exist", ARRAY_SIZE(L"Does.Not.Exist") - 1, &str2);
79 ok(hr == S_OK, "got %08x\n", hr);
81 hr = pRoInitialize(RO_INIT_MULTITHREADED);
82 ok(hr == S_OK, "got %08x\n", hr);
84 hr = pRoGetActivationFactory(str2, &IID_IActivationFactory, (void **)&factory);
85 ok(hr == REGDB_E_CLASSNOTREG, "got %08x\n", hr);
87 hr = pRoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory);
88 todo_wine ok(hr == S_OK, "got %08x\n", hr);
89 if(factory)
90 IActivationFactory_Release(factory);
92 hr = pRoActivateInstance(str2, &inspect);
93 ok(hr == REGDB_E_CLASSNOTREG, "got %08x\n", hr);
95 hr = pRoActivateInstance(str, &inspect);
96 todo_wine ok(hr == S_OK, "got %08x\n", hr);
97 if(inspect)
98 IInspectable_Release(inspect);
100 pWindowsDeleteString(str2);
101 pWindowsDeleteString(str);
102 pRoUninitialize();
105 START_TEST(roapi)
107 if (!init_functions())
108 return;
110 test_ActivationFactories();