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
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
,
33 static CHAR string1
[MAX_PATH
], string2
[MAX_PATH
];
35 #define ok_w2(format, szString1, szString2) \
37 if (lstrcmpW(szString1, szString2) != 0) \
39 WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
40 WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
41 ok(0, format, string1, string2); \
44 static BOOL
init_functionpointers(void)
49 static const WCHAR szFusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
51 hmscoree
= LoadLibraryA("mscoree.dll");
54 skip("mscoree.dll not available\n");
58 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
59 if (!pLoadLibraryShim
)
61 skip("LoadLibraryShim not available\n");
62 FreeLibrary(hmscoree
);
66 pGetCORVersion
= (void *)GetProcAddress(hmscoree
, "GetCORVersion");
68 hr
= pLoadLibraryShim(szFusion
, NULL
, NULL
, &hfusion
);
71 skip("fusion.dll not available\n");
72 FreeLibrary(hmscoree
);
76 pGetCachePath
= (void *)GetProcAddress(hfusion
, "GetCachePath");
80 static void test_GetCachePath(void)
82 WCHAR cachepath
[MAX_PATH
];
83 WCHAR version
[MAX_PATH
];
88 static const WCHAR backslash
[] = {'\\',0};
89 static const WCHAR nochange
[] = {'n','o','c','h','a','n','g','e',0};
90 static const WCHAR assembly
[] = {'a','s','s','e','m','b','l','y',0};
91 static const WCHAR gac
[] = {'G','A','C',0};
92 static const WCHAR nativeimg
[] = {
93 'N','a','t','i','v','e','I','m','a','g','e','s','_',0};
94 static const WCHAR zapfmt
[] = {
95 '%','s','\\','%','s','\\','%','s','%','s','_','3','2',0};
99 skip("GetCachePath not implemented\n");
103 GetWindowsDirectoryW(cachepath
, MAX_PATH
);
104 lstrcatW(cachepath
, backslash
);
105 lstrcatW(cachepath
, assembly
);
106 lstrcatW(cachepath
, backslash
);
107 lstrcatW(cachepath
, gac
);
109 /* NULL pwzCachePath, pcchPath is 0 */
111 hr
= pGetCachePath(ASM_CACHE_GAC
, NULL
, &size
);
112 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
),
113 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr
);
114 ok(size
== lstrlenW(cachepath
) + 1,
115 "Expected %d, got %d\n", lstrlenW(cachepath
) + 1, size
);
117 /* NULL pwszCachePath, pcchPath is MAX_PATH */
119 hr
= pGetCachePath(ASM_CACHE_GAC
, NULL
, &size
);
120 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
),
121 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr
);
122 ok(size
== lstrlenW(cachepath
) + 1,
123 "Expected %d, got %d\n", lstrlenW(cachepath
) + 1, size
);
125 /* both pwszCachePath and pcchPath NULL */
126 hr
= pGetCachePath(ASM_CACHE_GAC
, NULL
, NULL
);
127 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
130 lstrcpyW(path
, nochange
);
131 hr
= pGetCachePath(ASM_CACHE_GAC
, path
, NULL
);
132 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
133 ok_w2("Expected \"%s\", got \"%s\"\n", nochange
, path
);
135 /* get the cache path */
136 lstrcpyW(path
, nochange
);
138 hr
= pGetCachePath(ASM_CACHE_GAC
, path
, &size
);
139 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
140 ok_w2("Expected \"%s\", got \"%s\"\n", cachepath
, path
);
142 /* pcchPath has no room for NULL terminator */
143 lstrcpyW(path
, nochange
);
144 size
= lstrlenW(cachepath
);
145 hr
= pGetCachePath(ASM_CACHE_GAC
, path
, &size
);
146 ok(hr
== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
),
147 "Expected HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), got %08x\n", hr
);
148 ok_w2("Expected \"%s\", got \"%s\"\n", nochange
, path
);
152 pGetCORVersion(version
, MAX_PATH
, &size
);
153 GetWindowsDirectoryW(path
, MAX_PATH
);
154 wsprintfW(cachepath
, zapfmt
, path
, assembly
, nativeimg
, version
);
157 lstrcpyW(path
, nochange
);
159 hr
= pGetCachePath(ASM_CACHE_ZAP
, path
, &size
);
160 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
161 ok_w2("Expected \"%s\", got \"%s\"\n", cachepath
, path
);
164 GetWindowsDirectoryW(cachepath
, MAX_PATH
);
165 lstrcatW(cachepath
, backslash
);
166 lstrcatW(cachepath
, assembly
);
169 lstrcpyW(path
, nochange
);
171 hr
= pGetCachePath(ASM_CACHE_ROOT
, path
, &size
);
172 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
173 ok_w2("Expected \"%s\", got \"%s\"\n", cachepath
, path
);
175 /* two flags at once */
176 lstrcpyW(path
, nochange
);
178 hr
= pGetCachePath(ASM_CACHE_GAC
| ASM_CACHE_ROOT
, path
, &size
);
179 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
180 ok_w2("Expected \"%s\", got \"%s\"\n", nochange
, path
);
185 if (!init_functionpointers())
190 FreeLibrary(hmscoree
);