ReactOS 0.4.16-dev-2357-g35d0dfe
metahost.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "ole2.h"
#include "corerror.h"
#include "ocidl.h"
#include "initguid.h"
#include "metahost.h"
#include "wine/test.h"
Include dependency graph for metahost.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

static HRESULT (WINAPI *pCLRCreateInstance)(REFCLSID clsid
 
static BOOL init_pointers (void)
 
static void cleanup (void)
 
static void test_getruntime (WCHAR *version)
 
static void test_enumruntimes (void)
 
static void WINAPI notification_dummy_callback (ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet, CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
 
static void WINAPI notification_callback (ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet, CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
 
static void test_notification (void)
 
static void test_notification_cb (void)
 
 START_TEST (metahost)
 

Variables

static int has_mono = 0
 
static HMODULE hmscoree
 
static REFIID riid
 
static REFIID LPVOIDppInterface
 
static ICLRMetaHostmetahost
 
static const WCHAR v4_0 [] = {'v','4','.','0','.','3','0','3','1','9',0}
 
static DWORD expect_runtime_tid
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 19 of file metahost.c.

Function Documentation

◆ cleanup()

static void cleanup ( void  )
static

Definition at line 70 of file metahost.c.

71{
72 ICLRMetaHost_Release(metahost);
73
75}
#define FreeLibrary(x)
Definition: compat.h:748
static ICLRMetaHost * metahost
Definition: metahost.c:42
static HMODULE hmscoree
Definition: metahost.c:38

Referenced by START_TEST().

◆ HRESULT()

static HRESULT ( WINAPI pCLRCreateInstance)
static

◆ init_pointers()

static BOOL init_pointers ( void  )
static

Definition at line 48 of file metahost.c.

49{
51
52 hmscoree = LoadLibraryA("mscoree.dll");
53
54 if (hmscoree)
55 pCLRCreateInstance = (void *)GetProcAddress(hmscoree, "CLRCreateInstance");
56
57 if (pCLRCreateInstance)
58 hr = pCLRCreateInstance(&CLSID_CLRMetaHost, &IID_ICLRMetaHost, (void**)&metahost);
59
60 if (FAILED(hr))
61 {
62 win_skip(".NET 4 is not installed\n");
64 return FALSE;
65 }
66
67 return TRUE;
68}
#define E_FAIL
Definition: ddrawi.h:102
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define FAILED(hr)
Definition: intsafe.h:51
#define win_skip
Definition: minitest.h:67
HRESULT hr
Definition: shlfolder.c:183

Referenced by START_TEST().

◆ notification_callback()

static void WINAPI notification_callback ( ICLRRuntimeInfo *  pRuntimeInfo,
CallbackThreadSetFnPtr  pfnCallbackThreadSet,
CallbackThreadUnsetFnPtr  pfnCallbackThreadUnset 
)
static

Definition at line 160 of file metahost.c.

162{
163 HRESULT hr;
164 WCHAR buf[20];
165 DWORD buf_size = 20;
166
167 ok(expect_runtime_tid != 0, "unexpected call\n");
168
169 if (expect_runtime_tid != 0)
170 {
172 "expected call on thread %04lx, got thread %04lx\n", expect_runtime_tid, GetCurrentThreadId());
174 }
175
176 hr = ICLRRuntimeInfo_GetVersionString(pRuntimeInfo, buf, &buf_size);
177 ok(hr == S_OK, "GetVersion returned %lx\n", hr);
178 ok(lstrcmpW(buf, v4_0) == 0, "GetVersion returned %s\n", wine_dbgstr_w(buf));
179
180 hr = pfnCallbackThreadSet();
181 ok(hr == S_OK, "pfnCallbackThreadSet returned %lx\n", hr);
182
183 hr = pfnCallbackThreadUnset();
184 ok(hr == S_OK, "pfnCallbackThreadUnset returned %lx\n", hr);
185}
#define ok(value,...)
Definition: atltest.h:57
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define S_OK
Definition: intsafe.h:52
#define wine_dbgstr_w
Definition: kernel32.h:34
static DWORD expect_runtime_tid
Definition: metahost.c:46
static const WCHAR v4_0[]
Definition: metahost.c:44
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by test_notification().

◆ notification_dummy_callback()

static void WINAPI notification_dummy_callback ( ICLRRuntimeInfo *  pRuntimeInfo,
CallbackThreadSetFnPtr  pfnCallbackThreadSet,
CallbackThreadUnsetFnPtr  pfnCallbackThreadUnset 
)
static

Definition at line 154 of file metahost.c.

156{
157 ok(0, "unexpected call\n");
158}

Referenced by test_notification().

◆ START_TEST()

START_TEST ( metahost  )

Definition at line 230 of file metahost.c.

231{
232 if (!init_pointers())
233 return;
234
238
239 cleanup();
240}
static void cleanup(void)
Definition: metahost.c:70
static void test_enumruntimes(void)
Definition: metahost.c:108
static void test_notification(void)
Definition: metahost.c:187
static BOOL init_pointers(void)
Definition: metahost.c:48
static void test_notification_cb(void)
Definition: metahost.c:201

◆ test_enumruntimes()

static void test_enumruntimes ( void  )
static

Definition at line 108 of file metahost.c.

109{
110 IEnumUnknown *runtime_enum;
111 IUnknown *unk;
112 DWORD count;
113 ICLRRuntimeInfo *runtime_info;
114 HRESULT hr;
116
117 hr = ICLRMetaHost_EnumerateInstalledRuntimes(metahost, &runtime_enum);
118 ok(hr == S_OK, "EnumerateInstalledRuntimes returned %lx\n", hr);
119 if (FAILED(hr)) return;
120
121 while ((hr = IEnumUnknown_Next(runtime_enum, 1, &unk, &count)) == S_OK)
122 {
123 hr = IUnknown_QueryInterface(unk, &IID_ICLRRuntimeInfo, (void**)&runtime_info);
124 ok(hr == S_OK, "QueryInterface returned %lx\n", hr);
125
126 count = 1;
127 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
128 ok(hr == E_NOT_SUFFICIENT_BUFFER, "GetVersionString returned %lx\n", hr);
129 ok(count > 1, "GetVersionString returned count %lu\n", count);
130
131 count = 0xdeadbeef;
132 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, NULL, &count);
133 ok(hr == S_OK, "GetVersionString returned %lx\n", hr);
134 ok(count > 1 && count != 0xdeadbeef, "GetVersionString returned count %lu\n", count);
135
136 count = MAX_PATH;
137 hr = ICLRRuntimeInfo_GetVersionString(runtime_info, buf, &count);
138 ok(hr == S_OK, "GetVersionString returned %lx\n", hr);
139 ok(count > 1, "GetVersionString returned count %lu\n", count);
140
141 trace("runtime found: %s\n", wine_dbgstr_w(buf));
142
143 ICLRRuntimeInfo_Release(runtime_info);
144 IUnknown_Release(unk);
145
147 }
148
149 ok(hr == S_FALSE, "IEnumUnknown_Next returned %lx\n", hr);
150
151 IEnumUnknown_Release(runtime_enum);
152}
#define trace
Definition: atltest.h:70
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
GLuint GLuint GLsizei count
Definition: gl.h:1545
static void test_getruntime(WCHAR *version)
Definition: metahost.c:77
#define S_FALSE
Definition: winerror.h:3451
#define E_NOT_SUFFICIENT_BUFFER
Definition: winerror.h:3437

Referenced by START_TEST().

◆ test_getruntime()

static void test_getruntime ( WCHAR version)
static

Definition at line 77 of file metahost.c.

78{
79 static const WCHAR dotzero[] = {'.','0',0};
80 WCHAR *dot;
81 HRESULT hr;
82 ICLRRuntimeInfo *info;
85
86 hr = ICLRMetaHost_GetRuntime(metahost, NULL, &IID_ICLRRuntimeInfo, (void**)&info);
87 ok(hr == E_POINTER, "GetVersion failed, hr=%lx\n", hr);
88
89 hr = ICLRMetaHost_GetRuntime(metahost, version, &IID_ICLRRuntimeInfo, (void**)&info);
90 ok(hr == S_OK, "GetVersion failed, hr=%lx\n", hr);
91 if (hr != S_OK) return;
92
94 hr = ICLRRuntimeInfo_GetVersionString(info, buf, &count);
95 ok(hr == S_OK, "GetVersionString returned %lx\n", hr);
96 ok(count == lstrlenW(buf)+1, "GetVersionString returned count %lu but string of length %u\n", count, lstrlenW(buf)+1);
97 ok(lstrcmpW(buf, version) == 0, "got unexpected version %s\n", wine_dbgstr_w(buf));
98
99 ICLRRuntimeInfo_Release(info);
100
101 /* Versions must match exactly. */
102 dot = wcsrchr(version, '.');
103 lstrcpyW(dot, dotzero);
104 hr = ICLRMetaHost_GetRuntime(metahost, version, &IID_ICLRRuntimeInfo, (void**)&info);
105 ok(hr == CLR_E_SHIM_RUNTIME, "GetVersion failed, hr=%lx\n", hr);
106}
#define CLR_E_SHIM_RUNTIME
Definition: corerror.h:226
#define wcsrchr
Definition: compat.h:16
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
static const WCHAR version[]
Definition: asmname.c:66
#define E_POINTER
Definition: winerror.h:3480

Referenced by test_enumruntimes().

◆ test_notification()

static void test_notification ( void  )
static

Definition at line 187 of file metahost.c.

188{
189 HRESULT hr;
190
191 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost, NULL);
192 ok(hr == E_POINTER, "RequestRuntimeLoadedNotification returned %lx\n", hr);
193
194 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost,notification_callback);
195 ok(hr == S_OK, "RequestRuntimeLoadedNotification failed, hr=%lx\n", hr);
196
197 hr = ICLRMetaHost_RequestRuntimeLoadedNotification(metahost,notification_dummy_callback);
198 ok(hr == HOST_E_INVALIDOPERATION, "RequestRuntimeLoadedNotification returned %lx\n", hr);
199}
#define HOST_E_INVALIDOPERATION
Definition: corerror.h:914
static void WINAPI notification_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet, CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
Definition: metahost.c:160
static void WINAPI notification_dummy_callback(ICLRRuntimeInfo *pRuntimeInfo, CallbackThreadSetFnPtr pfnCallbackThreadSet, CallbackThreadUnsetFnPtr pfnCallbackThreadUnset)
Definition: metahost.c:154

Referenced by START_TEST().

◆ test_notification_cb()

static void test_notification_cb ( void  )
static

Definition at line 201 of file metahost.c.

202{
203 HRESULT hr;
204 ICLRRuntimeInfo *info;
206
207 hr = ICLRMetaHost_GetRuntime(metahost, v4_0, &IID_ICLRRuntimeInfo, (void**)&info);
208 ok(hr == S_OK, "GetRuntime returned %lx\n", hr);
209
211 hr = ICLRRuntimeInfo_GetInterface(info, &CLSID_CLRRuntimeHost, &IID_ICLRRuntimeHost, (void**)&host);
212#ifdef __REACTOS__
213 if (hr != S_OK)
214 {
215 // skip test if mono is not installed
216 win_skip("mono runtime is not installed\n");
217 return;
218 }
219#endif
220
221 todo_wine_if(!has_mono) ok(hr == S_OK, "GetInterface returned %lx\n", hr);
222 todo_wine if(!has_mono) ok(expect_runtime_tid == 0, "notification_callback was not called\n");
223
224 if(has_mono)
225 ICLRRuntimeHost_Release(host);
226
227 ICLRRuntimeInfo_Release(info);
228}
#define todo_wine_if(is_todo)
Definition: minitest.h:81
#define todo_wine
Definition: minitest.h:80
static int has_mono
Definition: metahost.c:33
Definition: txthost.c:37

Referenced by START_TEST().

Variable Documentation

◆ expect_runtime_tid

DWORD expect_runtime_tid
static

Definition at line 46 of file metahost.c.

Referenced by notification_callback(), and test_notification_cb().

◆ has_mono

int has_mono = 0
static

Definition at line 33 of file metahost.c.

Referenced by test_notification_cb().

◆ hmscoree

HMODULE hmscoree
static

Definition at line 38 of file metahost.c.

Referenced by cleanup(), and init_pointers().

◆ metahost

◆ ppInterface

REFIID LPVOID* ppInterface

Definition at line 40 of file metahost.c.

Referenced by CLRCreateInstance(), and CreateInterface().

◆ riid

Definition at line 40 of file metahost.c.

◆ v4_0

const WCHAR v4_0[] = {'v','4','.','0','.','3','0','3','1','9',0}
static

Definition at line 44 of file metahost.c.

Referenced by notification_callback(), and test_notification_cb().