include: Fix the metahost.idl import directives.
[wine/multimedia.git] / dlls / mscoree / tests / metahost.c
bloba9872f0f3885c02a66d3c882e311a0efcccfa66e
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 "ocidl.h"
28 #include "initguid.h"
29 #include "metahost.h"
30 #include "wine/test.h"
32 static HMODULE hmscoree;
34 static HRESULT (WINAPI *pCLRCreateInstance)(REFCLSID clsid, REFIID riid, LPVOID *ppInterface);
36 static ICLRMetaHost *metahost;
38 static BOOL init_pointers(void)
40 HRESULT hr = E_FAIL;
42 hmscoree = LoadLibraryA("mscoree.dll");
44 if (hmscoree)
45 pCLRCreateInstance = (void *)GetProcAddress(hmscoree, "CLRCreateInstance");
47 if (pCLRCreateInstance)
48 hr = pCLRCreateInstance(&CLSID_CLRMetaHost, &IID_ICLRMetaHost, (void**)&metahost);
50 if (FAILED(hr))
52 win_skip(".NET 4 is not installed\n");
53 FreeLibrary(hmscoree);
54 return FALSE;
57 return TRUE;
60 static void cleanup(void)
62 ICLRMetaHost_Release(metahost);
64 FreeLibrary(hmscoree);
67 static void test_enumruntimes(void)
69 IEnumUnknown *runtime_enum;
70 IUnknown *unk;
71 DWORD count;
72 ICLRRuntimeInfo *runtime_info;
73 HRESULT hr;
74 WCHAR buf[MAX_PATH];
76 hr = ICLRMetaHost_EnumerateInstalledRuntimes(metahost, &runtime_enum);
77 ok(hr == S_OK, "EnumerateInstalledRuntimes returned %x\n", hr);
78 if (FAILED(hr)) return;
80 while ((hr = IEnumUnknown_Next(runtime_enum, 1, &unk, &count)) == S_OK)
82 hr = IUnknown_QueryInterface(unk, &IID_ICLRRuntimeInfo, (void**)&runtime_info);
83 ok(hr == S_OK, "QueryInterface returned %x\n", hr);
85 count = 1;
86 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
87 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "GetVersionString returned %x\n", hr);
88 ok(count > 1, "GetVersionString returned count %u\n", count);
90 count = 0xdeadbeef;
91 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, NULL, &count);
92 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
93 ok(count > 1 && count != 0xdeadbeef, "GetVersionString returned count %u\n", count);
95 count = MAX_PATH;
96 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
97 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
98 ok(count > 1, "GetVersionString returned count %u\n", count);
100 trace("runtime found: %s\n", wine_dbgstr_w(buf));
102 ICLRRuntimeInfo_Release(runtime_info);
104 IUnknown_Release(unk);
107 ok(hr == S_FALSE, "IEnumUnknown_Next returned %x\n", hr);
109 IEnumUnknown_Release(runtime_enum);
112 static void test_getruntime(void)
114 static const WCHAR twodotzero[] = {'v','2','.','0','.','5','0','7','2','7',0};
115 static const WCHAR twodotzerodotzero[] = {'v','2','.','0','.','0',0};
116 HRESULT hr;
117 ICLRRuntimeInfo *info;
118 DWORD count;
119 WCHAR buf[MAX_PATH];
121 hr = ICLRMetaHost_GetRuntime(metahost, NULL, &IID_ICLRRuntimeInfo, (void**)&info);
122 ok(hr == E_POINTER, "GetVersion failed, hr=%x\n", hr);
124 hr = ICLRMetaHost_GetRuntime(metahost, twodotzero, &IID_ICLRRuntimeInfo, (void**)&info);
125 if (hr == CLR_E_SHIM_RUNTIME)
126 /* FIXME: Get Mono properly packaged so we can fail here. */
127 todo_wine ok(hr == S_OK, "GetVersion failed, hr=%x\n", hr);
128 else
129 ok(hr == S_OK, "GetVersion failed, hr=%x\n", hr);
130 if (hr != S_OK) return;
132 count = MAX_PATH;
133 hr = ICLRRuntimeInfo_GetVersionString(info, buf, &count);
134 ok(hr == S_OK, "GetVersionString returned %x\n", hr);
135 ok(count == lstrlenW(buf)+1, "GetVersionString returned count %u but string of length %u\n", count, lstrlenW(buf)+1);
136 ok(lstrcmpW(buf, twodotzero) == 0, "got unexpected version %s\n", wine_dbgstr_w(buf));
138 ICLRRuntimeInfo_Release(info);
140 /* Versions must match exactly. */
141 hr = ICLRMetaHost_GetRuntime(metahost, twodotzerodotzero, &IID_ICLRRuntimeInfo, (void**)&info);
142 ok(hr == CLR_E_SHIM_RUNTIME, "GetVersion failed, hr=%x\n", hr);
145 START_TEST(metahost)
147 if (!init_pointers())
148 return;
150 test_enumruntimes();
152 test_getruntime();
154 cleanup();