4 * Copyright 2008 Robert Shearman for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
32 #define TEST_URL "http://urlcachetest.winehq.org/index.html"
33 #define TEST_URL1 "Visited: user@http://urlcachetest.winehq.org/index.html"
35 static BOOL (WINAPI *pDeleteUrlCacheEntryA)(LPCSTR);
36 static BOOL (WINAPI *pUnlockUrlCacheEntryFileA)(LPCSTR,DWORD);
38 static char filenameA[MAX_PATH + 1];
39 static char filenameA1[MAX_PATH + 1];
41 static void check_cache_entry_infoA(const char *returnedfrom, LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo)
43 ok(lpCacheEntryInfo->dwStructSize == sizeof(*lpCacheEntryInfo), "%s: dwStructSize was %d\n", returnedfrom, lpCacheEntryInfo->dwStructSize);
44 ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL), "%s: lpszSourceUrlName should be %s instead of %s\n", returnedfrom, TEST_URL, lpCacheEntryInfo->lpszSourceUrlName);
45 ok(!strcmp(lpCacheEntryInfo->lpszLocalFileName, filenameA), "%s: lpszLocalFileName should be %s instead of %s\n", returnedfrom, filenameA, lpCacheEntryInfo->lpszLocalFileName);
46 ok(!strcmp(lpCacheEntryInfo->lpszFileExtension, "html"), "%s: lpszFileExtension should be html instead of %s\n", returnedfrom, lpCacheEntryInfo->lpszFileExtension);
49 static void test_find_url_cache_entriesA(void)
54 DWORD cbCacheEntryInfo;
55 DWORD cbCacheEntryInfoSaved;
56 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
59 SetLastError(0xdeadbeef);
60 hEnumHandle = FindFirstUrlCacheEntry(NULL, NULL, &cbCacheEntryInfo);
61 ok(!hEnumHandle, "FindFirstUrlCacheEntry should have failed\n");
62 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "FindFirstUrlCacheEntry should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
63 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo * sizeof(char));
64 cbCacheEntryInfoSaved = cbCacheEntryInfo;
65 hEnumHandle = FindFirstUrlCacheEntry(NULL, lpCacheEntryInfo, &cbCacheEntryInfo);
66 ok(hEnumHandle != NULL, "FindFirstUrlCacheEntry failed with error %d\n", GetLastError());
69 if (!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL))
74 SetLastError(0xdeadbeef);
75 cbCacheEntryInfo = cbCacheEntryInfoSaved;
76 ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
79 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
81 lpCacheEntryInfo = HeapReAlloc(GetProcessHeap(), 0, lpCacheEntryInfo, cbCacheEntryInfo);
82 cbCacheEntryInfoSaved = cbCacheEntryInfo;
83 ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
86 ok(ret, "FindNextUrlCacheEntry failed with error %d\n", GetLastError());
90 ok(found, "committed url cache entry not found during enumeration\n");
92 ret = FindCloseUrlCache(hEnumHandle);
93 ok(ret, "FindCloseUrlCache failed with error %d\n", GetLastError());
96 static void test_GetUrlCacheEntryInfoExA(void)
99 DWORD cbCacheEntryInfo, cbRedirectUrl;
100 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
102 SetLastError(0xdeadbeef);
103 ret = GetUrlCacheEntryInfoEx(NULL, NULL, NULL, NULL, NULL, NULL, 0);
104 ok(!ret, "GetUrlCacheEntryInfoEx with NULL URL and NULL args should have failed\n");
105 ok(GetLastError() == ERROR_INVALID_PARAMETER,
106 "GetUrlCacheEntryInfoEx with NULL URL and NULL args should have set last error to ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
108 cbCacheEntryInfo = sizeof(INTERNET_CACHE_ENTRY_INFO);
109 SetLastError(0xdeadbeef);
110 ret = GetUrlCacheEntryInfoEx("", NULL, &cbCacheEntryInfo, NULL, NULL, NULL, 0);
111 ok(!ret, "GetUrlCacheEntryInfoEx with zero-length buffer should fail\n");
112 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
113 "GetUrlCacheEntryInfoEx should have set last error to ERROR_FILE_NOT_FOUND instead of %d\n", GetLastError());
115 ret = GetUrlCacheEntryInfoEx(TEST_URL, NULL, NULL, NULL, NULL, NULL, 0);
116 ok(ret, "GetUrlCacheEntryInfoEx with NULL args failed with error %d\n", GetLastError());
118 cbCacheEntryInfo = 0;
119 SetLastError(0xdeadbeef);
120 ret = GetUrlCacheEntryInfoEx(TEST_URL, NULL, &cbCacheEntryInfo, NULL, NULL, NULL, 0);
121 ok(!ret, "GetUrlCacheEntryInfoEx with zero-length buffer should fail\n");
122 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
123 "GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
125 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
127 SetLastError(0xdeadbeef);
128 ret = GetUrlCacheEntryInfoEx(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, NULL, NULL, NULL, 0x200);
129 ok(!ret, "GetUrlCacheEntryInfoEx succeeded\n");
130 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
131 "GetUrlCacheEntryInfoEx should have set last error to ERROR_FILE_NOT_FOUND instead of %d\n", GetLastError());
133 ret = GetUrlCacheEntryInfoEx(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, NULL, NULL, NULL, 0);
134 ok(ret, "GetUrlCacheEntryInfoEx failed with error %d\n", GetLastError());
136 check_cache_entry_infoA("GetUrlCacheEntryInfoEx", lpCacheEntryInfo);
138 cbCacheEntryInfo = 100000;
139 SetLastError(0xdeadbeef);
140 ret = GetUrlCacheEntryInfoEx(TEST_URL, NULL, &cbCacheEntryInfo, NULL, NULL, NULL, 0);
141 ok(!ret, "GetUrlCacheEntryInfoEx with zero-length buffer should fail\n");
142 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
144 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
146 /* Querying the redirect URL fails with ERROR_INVALID_PARAMETER */
147 SetLastError(0xdeadbeef);
148 ret = GetUrlCacheEntryInfoEx(TEST_URL, NULL, NULL, NULL, &cbRedirectUrl, NULL, 0);
149 ok(GetLastError() == ERROR_INVALID_PARAMETER,
150 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
151 SetLastError(0xdeadbeef);
152 ret = GetUrlCacheEntryInfoEx(TEST_URL, NULL, &cbCacheEntryInfo, NULL, &cbRedirectUrl, NULL, 0);
153 ok(GetLastError() == ERROR_INVALID_PARAMETER,
154 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
157 static void test_RetrieveUrlCacheEntryA(void)
160 DWORD cbCacheEntryInfo;
162 cbCacheEntryInfo = 0;
163 SetLastError(0xdeadbeef);
164 ret = RetrieveUrlCacheEntryFile(NULL, NULL, &cbCacheEntryInfo, 0);
165 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
166 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
170 /* Crashes on Win9x, NT4 and W2K */
171 SetLastError(0xdeadbeef);
172 ret = RetrieveUrlCacheEntryFile(TEST_URL, NULL, NULL, 0);
173 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
174 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
177 SetLastError(0xdeadbeef);
178 cbCacheEntryInfo = 100000;
179 ret = RetrieveUrlCacheEntryFile(NULL, NULL, &cbCacheEntryInfo, 0);
180 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
181 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
184 static void test_urlcacheA(void)
190 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
191 DWORD cbCacheEntryInfo;
192 static const FILETIME filetime_zero;
194 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
195 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
197 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA1, 0);
198 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
200 ok(lstrcmpiA(filenameA, filenameA1), "expected a different file name\n");
202 hFile = CreateFileA(filenameA, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
203 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
204 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA failed with error %d\n", GetLastError());
206 ret = WriteFile(hFile, &zero_byte, sizeof(zero_byte), &written, NULL);
207 ok(ret, "WriteFile failed with error %d\n", GetLastError());
211 ret = CommitUrlCacheEntry(TEST_URL1, NULL, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, NULL, 0, NULL, NULL);
212 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
214 ret = CommitUrlCacheEntry(TEST_URL1, NULL, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, NULL, 0, NULL, NULL);
215 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
217 ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
218 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
220 cbCacheEntryInfo = 0;
221 SetLastError(0xdeadbeef);
222 ret = RetrieveUrlCacheEntryFile(TEST_URL, NULL, &cbCacheEntryInfo, 0);
223 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
224 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
225 "RetrieveUrlCacheEntryFile should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
227 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
228 ret = RetrieveUrlCacheEntryFile(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, 0);
229 ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
231 check_cache_entry_infoA("RetrieveUrlCacheEntryFile", lpCacheEntryInfo);
233 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
235 cbCacheEntryInfo = 0;
236 SetLastError(0xdeadbeef);
237 ret = RetrieveUrlCacheEntryFile(TEST_URL1, NULL, &cbCacheEntryInfo, 0);
238 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
239 ok(GetLastError() == ERROR_INVALID_DATA,
240 "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_DATA instead of %d\n", GetLastError());
242 if (pUnlockUrlCacheEntryFileA)
244 ret = pUnlockUrlCacheEntryFileA(TEST_URL, 0);
245 ok(ret, "UnlockUrlCacheEntryFileA failed with error %d\n", GetLastError());
248 /* test Find*UrlCacheEntry functions */
249 test_find_url_cache_entriesA();
251 test_GetUrlCacheEntryInfoExA();
252 test_RetrieveUrlCacheEntryA();
254 if (pDeleteUrlCacheEntryA)
256 ret = pDeleteUrlCacheEntryA(TEST_URL);
257 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
258 ret = pDeleteUrlCacheEntryA(TEST_URL1);
259 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
262 SetLastError(0xdeadbeef);
263 ret = DeleteFile(filenameA);
265 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "local file should no longer exist\n");
268 static void test_FindCloseUrlCache(void)
273 SetLastError(0xdeadbeef);
274 r = FindCloseUrlCache(NULL);
275 err = GetLastError();
276 ok(0 == r, "expected 0, got %d\n", r);
277 ok(ERROR_INVALID_HANDLE == err, "expected %d, got %d\n", ERROR_INVALID_HANDLE, err);
280 static void test_GetDiskInfoA(void)
283 DWORD error, cluster_size;
284 DWORDLONG free, total;
285 char path[MAX_PATH], *p;
287 GetSystemDirectoryA(path, MAX_PATH);
288 if ((p = strchr(path, '\\'))) *++p = 0;
290 ret = GetDiskInfoA(path, &cluster_size, &free, &total);
291 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
293 ret = GetDiskInfoA(path, &cluster_size, &free, NULL);
294 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
296 ret = GetDiskInfoA(path, &cluster_size, NULL, NULL);
297 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
299 ret = GetDiskInfoA(path, NULL, NULL, NULL);
300 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
302 SetLastError(0xdeadbeef);
303 strcpy(p, "\\non\\existing\\path");
304 ret = GetDiskInfoA(path, NULL, NULL, NULL);
305 error = GetLastError();
307 broken(ret), /* < IE7 */
308 "GetDiskInfoA succeeded\n");
309 ok(error == ERROR_PATH_NOT_FOUND ||
310 broken(error == 0xdeadbeef), /* < IE7 */
311 "got %u expected ERROR_PATH_NOT_FOUND\n", error);
313 SetLastError(0xdeadbeef);
314 ret = GetDiskInfoA(NULL, NULL, NULL, NULL);
315 error = GetLastError();
316 ok(!ret, "GetDiskInfoA succeeded\n");
317 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
323 hdll = GetModuleHandleA("wininet.dll");
325 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
326 win_skip("Too old IE (older than 6.0)\n");
330 pDeleteUrlCacheEntryA = (void*)GetProcAddress(hdll, "DeleteUrlCacheEntryA");
331 pUnlockUrlCacheEntryFileA = (void*)GetProcAddress(hdll, "UnlockUrlCacheEntryFileA");
333 test_FindCloseUrlCache();