ntdll: Fix race in NtRead/WriteFile.
[wine/testsucceed.git] / dlls / fusion / tests / fusion.c
blob6ebd4550eb0c68e29f902add9707e060eea0526e
1 /*
2 * Copyright 2008 James Hawkins
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 #include <windows.h>
20 #include <fusion.h>
22 #include "wine/test.h"
24 static HMODULE hmscoree;
26 static HRESULT (WINAPI *pGetCachePath)(ASM_CACHE_FLAGS dwCacheFlags,
27 LPWSTR pwzCachePath, PDWORD pcchPath);
28 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR szDllName, LPCWSTR szVersion,
29 LPVOID pvReserved, HMODULE *phModDll);
30 static HRESULT (WINAPI *pGetCORVersion)(LPWSTR pbuffer, DWORD cchBuffer,
31 DWORD *dwLength);
33 static CHAR string1[MAX_PATH], string2[MAX_PATH];
35 #define ok_w2(format, szString1, szString2) \
37 WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
38 WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
39 ok(!lstrcmpA(string1, string2), format, string1, string2)
41 static BOOL init_functionpointers(void)
43 HRESULT hr;
44 HMODULE hfusion;
46 static const WCHAR szFusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
48 hmscoree = LoadLibraryA("mscoree.dll");
49 if (!hmscoree)
51 win_skip("mscoree.dll not available\n");
52 return FALSE;
55 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
56 if (!pLoadLibraryShim)
58 win_skip("LoadLibraryShim not available\n");
59 FreeLibrary(hmscoree);
60 return FALSE;
63 pGetCORVersion = (void *)GetProcAddress(hmscoree, "GetCORVersion");
65 hr = pLoadLibraryShim(szFusion, NULL, NULL, &hfusion);
66 if (FAILED(hr))
68 win_skip("fusion.dll not available\n");
69 FreeLibrary(hmscoree);
70 return FALSE;
73 pGetCachePath = (void *)GetProcAddress(hfusion, "GetCachePath");
74 return TRUE;
77 static void test_GetCachePath(void)
79 CHAR windirA[MAX_PATH];
80 WCHAR windir[MAX_PATH];
81 WCHAR cachepath[MAX_PATH];
82 WCHAR version[MAX_PATH];
83 WCHAR path[MAX_PATH];
84 DWORD size;
85 HRESULT hr;
87 static const WCHAR backslash[] = {'\\',0};
88 static const WCHAR nochange[] = {'n','o','c','h','a','n','g','e',0};
89 static const WCHAR assembly[] = {'a','s','s','e','m','b','l','y',0};
90 static const WCHAR gac[] = {'G','A','C',0};
92 if (!pGetCachePath)
94 win_skip("GetCachePath not implemented\n");
95 return;
98 GetWindowsDirectoryA(windirA, MAX_PATH);
99 MultiByteToWideChar(CP_ACP, 0, windirA, -1, windir, MAX_PATH);
100 lstrcpyW(cachepath, windir);
101 lstrcatW(cachepath, backslash);
102 lstrcatW(cachepath, assembly);
103 lstrcatW(cachepath, backslash);
104 lstrcatW(cachepath, gac);
106 /* NULL pwzCachePath, pcchPath is 0 */
107 size = 0;
108 hr = pGetCachePath(ASM_CACHE_GAC, NULL, &size);
109 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
110 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr);
111 ok(size == lstrlenW(cachepath) + 1,
112 "Expected %d, got %d\n", lstrlenW(cachepath) + 1, size);
114 /* NULL pwszCachePath, pcchPath is MAX_PATH */
115 size = MAX_PATH;
116 hr = pGetCachePath(ASM_CACHE_GAC, NULL, &size);
117 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
118 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr);
119 ok(size == lstrlenW(cachepath) + 1,
120 "Expected %d, got %d\n", lstrlenW(cachepath) + 1, size);
122 /* both pwszCachePath and pcchPath NULL */
123 hr = pGetCachePath(ASM_CACHE_GAC, NULL, NULL);
124 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
126 /* NULL pcchPath */
127 lstrcpyW(path, nochange);
128 hr = pGetCachePath(ASM_CACHE_GAC, path, NULL);
129 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
130 ok_w2("Expected \"%s\", got \"%s\"\n", nochange, path);
132 /* get the cache path */
133 lstrcpyW(path, nochange);
134 size = MAX_PATH;
135 hr = pGetCachePath(ASM_CACHE_GAC, path, &size);
136 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
137 ok_w2("Expected \"%s\", got \"%s\"\n", cachepath, path);
139 /* pcchPath has no room for NULL terminator */
140 lstrcpyW(path, nochange);
141 size = lstrlenW(cachepath);
142 hr = pGetCachePath(ASM_CACHE_GAC, path, &size);
143 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
144 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr);
145 ok_w2("Expected \"%s\", got \"%s\"\n", nochange, path);
147 lstrcpyW(cachepath, windir);
148 lstrcatW(cachepath, backslash);
149 lstrcatW(cachepath, assembly);
151 /* ASM_CACHE_ROOT */
152 lstrcpyW(path, nochange);
153 size = MAX_PATH;
154 hr = pGetCachePath(ASM_CACHE_ROOT, path, &size);
155 ok(hr == S_OK ||
156 broken(hr == E_INVALIDARG), /* .NET 1.1 */
157 "Expected S_OK, got %08x\n", hr);
158 if (hr == S_OK)
159 ok_w2("Expected \"%s\", got \"%s\"\n", cachepath, path);
161 if (pGetCORVersion)
163 CHAR versionA[MAX_PATH];
164 CHAR cachepathA[MAX_PATH];
165 CHAR nativeimgA[MAX_PATH];
166 CHAR zapfmtA[MAX_PATH];
168 if (hr == S_OK)
170 lstrcpyA(nativeimgA, "NativeImages_");
171 #ifdef _WIN64
172 lstrcpyA(zapfmtA, "%s\\%s\\%s%s_64");
173 #else
174 lstrcpyA(zapfmtA, "%s\\%s\\%s%s_32");
175 #endif
177 else
179 lstrcpyA(nativeimgA, "NativeImages1_");
180 lstrcpyA(zapfmtA, "%s\\%s\\%s%s");
183 pGetCORVersion(version, MAX_PATH, &size);
184 WideCharToMultiByte(CP_ACP, 0, version, -1, versionA, MAX_PATH, 0, 0);
186 wsprintfA(cachepathA, zapfmtA, windirA, "assembly", nativeimgA, versionA);
187 MultiByteToWideChar(CP_ACP, 0, cachepathA, -1, cachepath, MAX_PATH);
189 /* ASM_CACHE_ZAP */
190 lstrcpyW(path, nochange);
191 size = MAX_PATH;
192 hr = pGetCachePath(ASM_CACHE_ZAP, path, &size);
193 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
194 ok_w2("Expected \"%s\", got \"%s\"\n", cachepath, path);
197 /* two flags at once */
198 lstrcpyW(path, nochange);
199 size = MAX_PATH;
200 hr = pGetCachePath(ASM_CACHE_GAC | ASM_CACHE_ROOT, path, &size);
201 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
202 ok_w2("Expected \"%s\", got \"%s\"\n", nochange, path);
205 START_TEST(fusion)
207 if (!init_functionpointers())
208 return;
210 test_GetCachePath();
212 FreeLibrary(hmscoree);