winex11.drv: Fix a memory leak.
[wine/multimedia.git] / dlls / mscoree / tests / metahost.c
blob50821be6de883060d75c51f4a4abca4f0b67cdc0
1 /*
2 * Copyright 2010 Vincent Povirk
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 #define COBJMACROS
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "ole2.h"
26 #include "corerror.h"
27 #include "initguid.h"
28 #include "metahost.h"
29 #include "wine/test.h"
31 static HMODULE hmscoree;
33 static HRESULT (WINAPI *pCLRCreateInstance)(REFCLSID clsid, REFIID riid, LPVOID *ppInterface);
35 static ICLRMetaHost *metahost;
37 static BOOL init_pointers(void)
39 HRESULT hr = E_FAIL;
41 hmscoree = LoadLibraryA("mscoree.dll");
43 if (hmscoree)
44 pCLRCreateInstance = (void *)GetProcAddress(hmscoree, "CLRCreateInstance");
46 if (pCLRCreateInstance)
47 hr = pCLRCreateInstance(&CLSID_CLRMetaHost, &IID_ICLRMetaHost, (void**)&metahost);
49 if (FAILED(hr))
51 win_skip(".NET 4 is not installed\n");
52 FreeLibrary(hmscoree);
53 return FALSE;
56 return TRUE;
59 static void cleanup(void)
61 ICLRMetaHost_Release(metahost);
63 FreeLibrary(hmscoree);
66 static void test_enumruntimes(void)
68 IEnumUnknown *runtime_enum;
69 IUnknown *unk;
70 DWORD count;
71 ICLRRuntimeInfo *runtime_info;
72 HRESULT hr;
73 WCHAR buf[MAX_PATH];
75 hr = ICLRMetaHost_EnumerateInstalledRuntimes(metahost, &runtime_enum);
76 ok(hr == S_OK, "EnumerateInstalledRuntimes returned %x\n", hr);
77 if (FAILED(hr)) return;
79 while ((hr = IEnumUnknown_Next(runtime_enum, 1, &unk, &count)) == S_OK)
81 hr = IUnknown_QueryInterface(unk, &IID_ICLRRuntimeInfo, (void**)&runtime_info);
82 ok(hr == S_OK, "QueryInterface returned %x\n", hr);
84 count = 1;
85 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
86 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "GetVersionString returned %x\n", hr);
87 ok(count > 1, "GetVersionString returned count %u\n", count);
89 count = 0xdeadbeef;
90 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, NULL, &count);
91 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
92 ok(count > 1 && count != 0xdeadbeef, "GetVersionString returned count %u\n", count);
94 count = MAX_PATH;
95 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
96 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
97 ok(count > 1, "GetVersionString returned count %u\n", count);
99 trace("runtime found: %s\n", wine_dbgstr_w(buf));
101 ICLRRuntimeInfo_Release(runtime_info);
103 IUnknown_Release(unk);
106 ok(hr == S_FALSE, "IEnumUnknown_Next returned %x\n", hr);
108 IEnumUnknown_Release(runtime_enum);
111 static void test_getruntime(void)
113 static const WCHAR twodotzero[] = {'v','2','.','0','.','5','0','7','2','7',0};
114 static const WCHAR twodotzerodotzero[] = {'v','2','.','0','.','0',0};
115 HRESULT hr;
116 ICLRRuntimeInfo *info;
117 DWORD count;
118 WCHAR buf[MAX_PATH];
120 hr = ICLRMetaHost_GetRuntime(metahost, NULL, &IID_ICLRRuntimeInfo, (void**)&info);
121 ok(hr == E_POINTER, "GetVersion failed, hr=%x\n", hr);
123 hr = ICLRMetaHost_GetRuntime(metahost, twodotzero, &IID_ICLRRuntimeInfo, (void**)&info);
124 if (hr == CLR_E_SHIM_RUNTIME)
125 /* FIXME: Get Mono properly packaged so we can fail here. */
126 todo_wine ok(hr == S_OK, "GetVersion failed, hr=%x\n", hr);
127 else
128 ok(hr == S_OK, "GetVersion failed, hr=%x\n", hr);
129 if (hr != S_OK) return;
131 count = MAX_PATH;
132 hr = ICLRRuntimeInfo_GetVersionString(info, buf, &count);
133 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
134 ok(count == lstrlenW(buf)+1, "GetVersionString returned count %u but string of length %u\n", count, lstrlenW(buf)+1);
135 ok(lstrcmpW(buf, twodotzero) == 0, "got unexpected version %s\n", wine_dbgstr_w(buf));
137 ICLRRuntimeInfo_Release(info);
139 /* Versions must match exactly. */
140 hr = ICLRMetaHost_GetRuntime(metahost, twodotzerodotzero, &IID_ICLRRuntimeInfo, (void**)&info);
141 ok(hr == CLR_E_SHIM_RUNTIME, "GetVersion failed, hr=%x\n", hr);
144 START_TEST(metahost)
146 if (!init_pointers())
147 return;
149 test_enumruntimes();
151 test_getruntime();
153 cleanup();