[ROSTESTS]
[reactos.git] / rostests / winetests / fusion / fusion.c
1 /*
2 * Copyright 2008 James Hawkins
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdarg.h>
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 //#include <windows.h>
26 #include <windef.h>
27 #include <winbase.h>
28 #include <winnls.h>
29 #include <objbase.h>
30 #include <fusion.h>
31
32 #include <wine/test.h>
33
34 static HMODULE hmscoree;
35
36 static HRESULT (WINAPI *pGetCachePath)(ASM_CACHE_FLAGS dwCacheFlags,
37 LPWSTR pwzCachePath, PDWORD pcchPath);
38 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR szDllName, LPCWSTR szVersion,
39 LPVOID pvReserved, HMODULE *phModDll);
40 static HRESULT (WINAPI *pGetCORVersion)(LPWSTR pbuffer, DWORD cchBuffer,
41 DWORD *dwLength);
42
43 static BOOL init_functionpointers(void)
44 {
45 HRESULT hr;
46 HMODULE hfusion;
47
48 static const WCHAR szFusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
49
50 hmscoree = LoadLibraryA("mscoree.dll");
51 if (!hmscoree)
52 {
53 win_skip("mscoree.dll not available\n");
54 return FALSE;
55 }
56
57 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
58 if (!pLoadLibraryShim)
59 {
60 win_skip("LoadLibraryShim not available\n");
61 FreeLibrary(hmscoree);
62 return FALSE;
63 }
64
65 pGetCORVersion = (void *)GetProcAddress(hmscoree, "GetCORVersion");
66
67 hr = pLoadLibraryShim(szFusion, NULL, NULL, &hfusion);
68 if (FAILED(hr))
69 {
70 win_skip("fusion.dll not available\n");
71 FreeLibrary(hmscoree);
72 return FALSE;
73 }
74
75 pGetCachePath = (void *)GetProcAddress(hfusion, "GetCachePath");
76 return TRUE;
77 }
78
79 static void test_GetCachePath(void)
80 {
81 CHAR windirA[MAX_PATH];
82 WCHAR windir[MAX_PATH];
83 WCHAR cachepath[MAX_PATH];
84 WCHAR version[MAX_PATH];
85 WCHAR path[MAX_PATH];
86 DWORD size;
87 HRESULT hr;
88
89 static const WCHAR backslash[] = {'\\',0};
90 static const WCHAR nochange[] = {'n','o','c','h','a','n','g','e',0};
91 static const WCHAR assembly[] = {'a','s','s','e','m','b','l','y',0};
92 static const WCHAR gac[] = {'G','A','C',0};
93
94 if (!pGetCachePath)
95 {
96 win_skip("GetCachePath not implemented\n");
97 return;
98 }
99
100 GetWindowsDirectoryA(windirA, MAX_PATH);
101 MultiByteToWideChar(CP_ACP, 0, windirA, -1, windir, MAX_PATH);
102 lstrcpyW(cachepath, windir);
103 lstrcatW(cachepath, backslash);
104 lstrcatW(cachepath, assembly);
105 lstrcatW(cachepath, backslash);
106 lstrcatW(cachepath, gac);
107
108 /* NULL pwzCachePath, pcchPath is 0 */
109 size = 0;
110 hr = pGetCachePath(ASM_CACHE_GAC, NULL, &size);
111 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
112 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr);
113 ok(size == lstrlenW(cachepath) + 1,
114 "Expected %d, got %d\n", lstrlenW(cachepath) + 1, size);
115
116 /* NULL pwszCachePath, pcchPath is MAX_PATH */
117 size = MAX_PATH;
118 hr = pGetCachePath(ASM_CACHE_GAC, NULL, &size);
119 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
120 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr);
121 ok(size == lstrlenW(cachepath) + 1,
122 "Expected %d, got %d\n", lstrlenW(cachepath) + 1, size);
123
124 /* both pwszCachePath and pcchPath NULL */
125 hr = pGetCachePath(ASM_CACHE_GAC, NULL, NULL);
126 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
127
128 /* NULL pcchPath */
129 lstrcpyW(path, nochange);
130 hr = pGetCachePath(ASM_CACHE_GAC, path, NULL);
131 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
132 ok( !lstrcmpW( nochange, path ), "Expected %s, got %s\n", wine_dbgstr_w(nochange), wine_dbgstr_w(path));
133
134 /* get the cache path */
135 lstrcpyW(path, nochange);
136 size = MAX_PATH;
137 hr = pGetCachePath(ASM_CACHE_GAC, path, &size);
138 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
139 ok( !lstrcmpW( cachepath, path ), "Expected %s, got %s\n", wine_dbgstr_w(cachepath), wine_dbgstr_w(path));
140
141 /* pcchPath has no room for NULL terminator */
142 lstrcpyW(path, nochange);
143 size = lstrlenW(cachepath);
144 hr = pGetCachePath(ASM_CACHE_GAC, path, &size);
145 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
146 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr);
147 ok( !lstrcmpW( nochange, path ), "Expected %s, got %s\n", wine_dbgstr_w(nochange), wine_dbgstr_w(path));
148
149 lstrcpyW(cachepath, windir);
150 lstrcatW(cachepath, backslash);
151 lstrcatW(cachepath, assembly);
152
153 /* ASM_CACHE_ROOT */
154 lstrcpyW(path, nochange);
155 size = MAX_PATH;
156 hr = pGetCachePath(ASM_CACHE_ROOT, path, &size);
157 ok(hr == S_OK ||
158 broken(hr == E_INVALIDARG), /* .NET 1.1 */
159 "Expected S_OK, got %08x\n", hr);
160 if (hr == S_OK)
161 ok( !lstrcmpW( cachepath, path ), "Expected %s, got %s\n", wine_dbgstr_w(cachepath), wine_dbgstr_w(path));
162
163 if (pGetCORVersion)
164 {
165 CHAR versionA[MAX_PATH];
166 CHAR cachepathA[MAX_PATH];
167 CHAR nativeimgA[MAX_PATH];
168 CHAR zapfmtA[MAX_PATH];
169
170 if (hr == S_OK)
171 {
172 lstrcpyA(nativeimgA, "NativeImages_");
173 #ifdef _WIN64
174 lstrcpyA(zapfmtA, "%s\\%s\\%s%s_64");
175 #else
176 lstrcpyA(zapfmtA, "%s\\%s\\%s%s_32");
177 #endif
178 }
179 else
180 {
181 lstrcpyA(nativeimgA, "NativeImages1_");
182 lstrcpyA(zapfmtA, "%s\\%s\\%s%s");
183 }
184
185 pGetCORVersion(version, MAX_PATH, &size);
186 WideCharToMultiByte(CP_ACP, 0, version, -1, versionA, MAX_PATH, 0, 0);
187
188 wsprintfA(cachepathA, zapfmtA, windirA, "assembly", nativeimgA, versionA);
189 MultiByteToWideChar(CP_ACP, 0, cachepathA, -1, cachepath, MAX_PATH);
190
191 /* ASM_CACHE_ZAP */
192 lstrcpyW(path, nochange);
193 size = MAX_PATH;
194 hr = pGetCachePath(ASM_CACHE_ZAP, path, &size);
195 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
196 ok( !lstrcmpW( cachepath, path ), "Expected %s, got %s\n", wine_dbgstr_w(cachepath), wine_dbgstr_w(path));
197 }
198
199 /* two flags at once */
200 lstrcpyW(path, nochange);
201 size = MAX_PATH;
202 hr = pGetCachePath(ASM_CACHE_GAC | ASM_CACHE_ROOT, path, &size);
203 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
204 ok( !lstrcmpW( nochange, path ), "Expected %s, got %s\n", wine_dbgstr_w(nochange), wine_dbgstr_w(path));
205 }
206
207 START_TEST(fusion)
208 {
209 if (!init_functionpointers())
210 return;
211
212 test_GetCachePath();
213
214 FreeLibrary(hmscoree);
215 }