Release 1.6-rc2.
[wine/testsucceed.git] / dlls / wininet / tests / urlcache.c
blobc9acea232143e829dd7a10cb86ae37b69135d1f2
1 /*
2 * URL Cache Tests
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
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnls.h"
28 #include "wininet.h"
29 #include "winineti.h"
31 #include "wine/test.h"
33 static const char test_url[] = "http://urlcachetest.winehq.org/index.html";
34 static const WCHAR test_urlW[] = {'h','t','t','p',':','/','/','u','r','l','c','a','c','h','e','t','e','s','t','.',
35 'w','i','n','e','h','q','.','o','r','g','/','i','n','d','e','x','.','h','t','m','l',0};
36 static const char test_url1[] = "Visited: user@http://urlcachetest.winehq.org/index.html";
37 static const char test_hash_collisions1[] = "Visited: http://winehq.org/doc0.html";
38 static const char test_hash_collisions2[] = "Visited: http://winehq.org/doc75651909.html";
40 static BOOL (WINAPI *pDeleteUrlCacheEntryA)(LPCSTR);
41 static BOOL (WINAPI *pUnlockUrlCacheEntryFileA)(LPCSTR,DWORD);
43 static char filenameA[MAX_PATH + 1];
44 static char filenameA1[MAX_PATH + 1];
45 static BOOL old_ie = FALSE;
47 static void check_cache_entry_infoA(const char *returnedfrom, LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo)
49 ok(lpCacheEntryInfo->dwStructSize == sizeof(*lpCacheEntryInfo), "%s: dwStructSize was %d\n", returnedfrom, lpCacheEntryInfo->dwStructSize);
50 ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, test_url), "%s: lpszSourceUrlName should be %s instead of %s\n", returnedfrom, test_url, lpCacheEntryInfo->lpszSourceUrlName);
51 ok(!strcmp(lpCacheEntryInfo->lpszLocalFileName, filenameA), "%s: lpszLocalFileName should be %s instead of %s\n", returnedfrom, filenameA, lpCacheEntryInfo->lpszLocalFileName);
52 ok(!strcmp(lpCacheEntryInfo->lpszFileExtension, "html"), "%s: lpszFileExtension should be html instead of %s\n", returnedfrom, lpCacheEntryInfo->lpszFileExtension);
55 static void test_find_url_cache_entriesA(void)
57 BOOL ret;
58 HANDLE hEnumHandle;
59 BOOL found = FALSE;
60 DWORD cbCacheEntryInfo;
61 DWORD cbCacheEntryInfoSaved;
62 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
64 cbCacheEntryInfo = 0;
65 SetLastError(0xdeadbeef);
66 hEnumHandle = FindFirstUrlCacheEntry(NULL, NULL, &cbCacheEntryInfo);
67 ok(!hEnumHandle, "FindFirstUrlCacheEntry should have failed\n");
68 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "FindFirstUrlCacheEntry should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
69 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo * sizeof(char));
70 cbCacheEntryInfoSaved = cbCacheEntryInfo;
71 hEnumHandle = FindFirstUrlCacheEntry(NULL, lpCacheEntryInfo, &cbCacheEntryInfo);
72 ok(hEnumHandle != NULL, "FindFirstUrlCacheEntry failed with error %d\n", GetLastError());
73 while (TRUE)
75 if (!strcmp(lpCacheEntryInfo->lpszSourceUrlName, test_url))
77 found = TRUE;
78 ret = TRUE;
79 break;
81 SetLastError(0xdeadbeef);
82 cbCacheEntryInfo = cbCacheEntryInfoSaved;
83 ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
84 if (!ret)
86 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
88 lpCacheEntryInfo = HeapReAlloc(GetProcessHeap(), 0, lpCacheEntryInfo, cbCacheEntryInfo);
89 cbCacheEntryInfoSaved = cbCacheEntryInfo;
90 ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
93 if (!ret)
94 break;
96 ok(ret, "FindNextUrlCacheEntry failed with error %d\n", GetLastError());
97 ok(found, "Committed url cache entry not found during enumeration\n");
99 ret = FindCloseUrlCache(hEnumHandle);
100 ok(ret, "FindCloseUrlCache failed with error %d\n", GetLastError());
103 static void test_GetUrlCacheEntryInfoExA(void)
105 BOOL ret;
106 DWORD cbCacheEntryInfo, cbRedirectUrl;
107 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
109 SetLastError(0xdeadbeef);
110 ret = GetUrlCacheEntryInfoEx(NULL, NULL, NULL, NULL, NULL, NULL, 0);
111 ok(!ret, "GetUrlCacheEntryInfoEx with NULL URL and NULL args should have failed\n");
112 ok(GetLastError() == ERROR_INVALID_PARAMETER,
113 "GetUrlCacheEntryInfoEx with NULL URL and NULL args should have set last error to ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
115 cbCacheEntryInfo = sizeof(INTERNET_CACHE_ENTRY_INFO);
116 SetLastError(0xdeadbeef);
117 ret = GetUrlCacheEntryInfoEx("", NULL, &cbCacheEntryInfo, NULL, NULL, NULL, 0);
118 ok(!ret, "GetUrlCacheEntryInfoEx with zero-length buffer should fail\n");
119 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
120 "GetUrlCacheEntryInfoEx should have set last error to ERROR_FILE_NOT_FOUND instead of %d\n", GetLastError());
122 ret = GetUrlCacheEntryInfoEx(test_url, NULL, NULL, NULL, NULL, NULL, 0);
123 ok(ret, "GetUrlCacheEntryInfoEx with NULL args failed with error %d\n", GetLastError());
125 cbCacheEntryInfo = 0;
126 SetLastError(0xdeadbeef);
127 ret = GetUrlCacheEntryInfoEx(test_url, NULL, &cbCacheEntryInfo, NULL, NULL, NULL, 0);
128 ok(!ret, "GetUrlCacheEntryInfoEx with zero-length buffer should fail\n");
129 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
130 "GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
132 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
134 SetLastError(0xdeadbeef);
135 ret = GetUrlCacheEntryInfoEx(test_url, NULL, NULL, NULL, NULL, NULL, 0x200 /*GET_INSTALLED_ENTRY*/);
136 ok(!ret, "GetUrlCacheEntryInfoEx succeeded\n");
137 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
138 "GetUrlCacheEntryInfoEx should have set last error to ERROR_FILE_NOT_FOUND instead of %d\n", GetLastError());
140 /* Unicode version of function seems to ignore 0x200 flag */
141 ret = GetUrlCacheEntryInfoExW(test_urlW, NULL, NULL, NULL, NULL, NULL, 0x200 /*GET_INSTALLED_ENTRY*/);
142 ok(ret || broken(old_ie && !ret), "GetUrlCacheEntryInfoExW failed with error %d\n", GetLastError());
144 ret = GetUrlCacheEntryInfoEx(test_url, lpCacheEntryInfo, &cbCacheEntryInfo, NULL, NULL, NULL, 0);
145 ok(ret, "GetUrlCacheEntryInfoEx failed with error %d\n", GetLastError());
147 if (ret) check_cache_entry_infoA("GetUrlCacheEntryInfoEx", lpCacheEntryInfo);
149 lpCacheEntryInfo->CacheEntryType |= 0x10000000; /* INSTALLED_CACHE_ENTRY */
150 ret = SetUrlCacheEntryInfoA(test_url, lpCacheEntryInfo, CACHE_ENTRY_ATTRIBUTE_FC);
151 ok(ret, "SetUrlCacheEntryInfoA failed with error %d\n", GetLastError());
153 SetLastError(0xdeadbeef);
154 ret = GetUrlCacheEntryInfoEx(test_url, NULL, NULL, NULL, NULL, NULL, 0x200 /*GET_INSTALLED_ENTRY*/);
155 ok(ret, "GetUrlCacheEntryInfoEx failed with error %d\n", GetLastError());
157 cbCacheEntryInfo = 100000;
158 SetLastError(0xdeadbeef);
159 ret = GetUrlCacheEntryInfoEx(test_url, NULL, &cbCacheEntryInfo, NULL, NULL, NULL, 0);
160 ok(!ret, "GetUrlCacheEntryInfoEx with zero-length buffer should fail\n");
161 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
163 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
165 /* Querying the redirect URL fails with ERROR_INVALID_PARAMETER */
166 SetLastError(0xdeadbeef);
167 ret = GetUrlCacheEntryInfoEx(test_url, NULL, NULL, NULL, &cbRedirectUrl, NULL, 0);
168 ok(!ret, "GetUrlCacheEntryInfoEx should have failed\n");
169 ok(GetLastError() == ERROR_INVALID_PARAMETER,
170 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
171 SetLastError(0xdeadbeef);
172 ret = GetUrlCacheEntryInfoEx(test_url, NULL, &cbCacheEntryInfo, NULL, &cbRedirectUrl, NULL, 0);
173 ok(!ret, "GetUrlCacheEntryInfoEx should have failed\n");
174 ok(GetLastError() == ERROR_INVALID_PARAMETER,
175 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
178 static void test_RetrieveUrlCacheEntryA(void)
180 BOOL ret;
181 DWORD cbCacheEntryInfo;
183 cbCacheEntryInfo = 0;
184 SetLastError(0xdeadbeef);
185 ret = RetrieveUrlCacheEntryFile(NULL, NULL, &cbCacheEntryInfo, 0);
186 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
187 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
189 if (0)
191 /* Crashes on Win9x, NT4 and W2K */
192 SetLastError(0xdeadbeef);
193 ret = RetrieveUrlCacheEntryFile(test_url, NULL, NULL, 0);
194 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
195 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
198 SetLastError(0xdeadbeef);
199 cbCacheEntryInfo = 100000;
200 ret = RetrieveUrlCacheEntryFile(NULL, NULL, &cbCacheEntryInfo, 0);
201 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
202 ok(GetLastError() == ERROR_INVALID_PARAMETER, "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
205 static void test_IsUrlCacheEntryExpiredA(void)
207 static const char uncached_url[] =
208 "What's the airspeed velocity of an unladen swallow?";
209 BOOL ret;
210 FILETIME ft;
211 DWORD size;
212 LPINTERNET_CACHE_ENTRY_INFO info;
213 ULARGE_INTEGER exp_time;
215 /* The function returns TRUE when the output time is NULL or the tested URL
216 * is NULL.
218 ret = IsUrlCacheEntryExpiredA(NULL, 0, NULL);
219 ok(ret, "expected TRUE\n");
220 ft.dwLowDateTime = 0xdeadbeef;
221 ft.dwHighDateTime = 0xbaadf00d;
222 ret = IsUrlCacheEntryExpiredA(NULL, 0, &ft);
223 ok(ret, "expected TRUE\n");
224 ok(ft.dwLowDateTime == 0xdeadbeef && ft.dwHighDateTime == 0xbaadf00d,
225 "expected time to be unchanged, got (%u,%u)\n",
226 ft.dwLowDateTime, ft.dwHighDateTime);
227 ret = IsUrlCacheEntryExpiredA(test_url, 0, NULL);
228 ok(ret, "expected TRUE\n");
230 /* The return value should indicate whether the URL is expired,
231 * and the filetime indicates the last modified time, but a cache entry
232 * with a zero expire time is "not expired".
234 ft.dwLowDateTime = 0xdeadbeef;
235 ft.dwHighDateTime = 0xbaadf00d;
236 ret = IsUrlCacheEntryExpiredA(test_url, 0, &ft);
237 ok(!ret, "expected FALSE\n");
238 ok(!ft.dwLowDateTime && !ft.dwHighDateTime,
239 "expected time (0,0), got (%u,%u)\n",
240 ft.dwLowDateTime, ft.dwHighDateTime);
242 /* Same behavior with bogus flags. */
243 ft.dwLowDateTime = 0xdeadbeef;
244 ft.dwHighDateTime = 0xbaadf00d;
245 ret = IsUrlCacheEntryExpiredA(test_url, 0xffffffff, &ft);
246 ok(!ret, "expected FALSE\n");
247 ok(!ft.dwLowDateTime && !ft.dwHighDateTime,
248 "expected time (0,0), got (%u,%u)\n",
249 ft.dwLowDateTime, ft.dwHighDateTime);
251 /* Set the expire time to a point in the past.. */
252 ret = GetUrlCacheEntryInfo(test_url, NULL, &size);
253 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
254 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
255 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
256 info = HeapAlloc(GetProcessHeap(), 0, size);
257 ret = GetUrlCacheEntryInfo(test_url, info, &size);
258 ok(ret, "GetUrlCacheEntryInfo failed: %d\n", GetLastError());
259 GetSystemTimeAsFileTime(&info->ExpireTime);
260 exp_time.u.LowPart = info->ExpireTime.dwLowDateTime;
261 exp_time.u.HighPart = info->ExpireTime.dwHighDateTime;
262 exp_time.QuadPart -= 10 * 60 * (ULONGLONG)10000000;
263 info->ExpireTime.dwLowDateTime = exp_time.u.LowPart;
264 info->ExpireTime.dwHighDateTime = exp_time.u.HighPart;
265 ret = SetUrlCacheEntryInfo(test_url, info, CACHE_ENTRY_EXPTIME_FC);
266 ok(ret, "SetUrlCacheEntryInfo failed: %d\n", GetLastError());
267 ft.dwLowDateTime = 0xdeadbeef;
268 ft.dwHighDateTime = 0xbaadf00d;
269 /* and the entry should be expired. */
270 ret = IsUrlCacheEntryExpiredA(test_url, 0, &ft);
271 ok(ret, "expected TRUE\n");
272 /* The modified time returned is 0. */
273 ok(!ft.dwLowDateTime && !ft.dwHighDateTime,
274 "expected time (0,0), got (%u,%u)\n",
275 ft.dwLowDateTime, ft.dwHighDateTime);
276 /* Set the expire time to a point in the future.. */
277 exp_time.QuadPart += 20 * 60 * (ULONGLONG)10000000;
278 info->ExpireTime.dwLowDateTime = exp_time.u.LowPart;
279 info->ExpireTime.dwHighDateTime = exp_time.u.HighPart;
280 ret = SetUrlCacheEntryInfo(test_url, info, CACHE_ENTRY_EXPTIME_FC);
281 ok(ret, "SetUrlCacheEntryInfo failed: %d\n", GetLastError());
282 ft.dwLowDateTime = 0xdeadbeef;
283 ft.dwHighDateTime = 0xbaadf00d;
284 /* and the entry should no longer be expired. */
285 ret = IsUrlCacheEntryExpiredA(test_url, 0, &ft);
286 ok(!ret, "expected FALSE\n");
287 /* The modified time returned is still 0. */
288 ok(!ft.dwLowDateTime && !ft.dwHighDateTime,
289 "expected time (0,0), got (%u,%u)\n",
290 ft.dwLowDateTime, ft.dwHighDateTime);
291 /* Set the modified time... */
292 GetSystemTimeAsFileTime(&info->LastModifiedTime);
293 ret = SetUrlCacheEntryInfo(test_url, info, CACHE_ENTRY_MODTIME_FC);
294 ok(ret, "SetUrlCacheEntryInfo failed: %d\n", GetLastError());
295 /* and the entry should still be unexpired.. */
296 ret = IsUrlCacheEntryExpiredA(test_url, 0, &ft);
297 ok(!ret, "expected FALSE\n");
298 /* but the modified time returned is the last modified time just set. */
299 ok(ft.dwLowDateTime == info->LastModifiedTime.dwLowDateTime &&
300 ft.dwHighDateTime == info->LastModifiedTime.dwHighDateTime,
301 "expected time (%u,%u), got (%u,%u)\n",
302 info->LastModifiedTime.dwLowDateTime,
303 info->LastModifiedTime.dwHighDateTime,
304 ft.dwLowDateTime, ft.dwHighDateTime);
305 HeapFree(GetProcessHeap(), 0, info);
307 /* An uncached URL is implicitly expired, but with unknown time. */
308 ft.dwLowDateTime = 0xdeadbeef;
309 ft.dwHighDateTime = 0xbaadf00d;
310 ret = IsUrlCacheEntryExpiredA(uncached_url, 0, &ft);
311 ok(ret, "expected TRUE\n");
312 ok(!ft.dwLowDateTime && !ft.dwHighDateTime,
313 "expected time (0,0), got (%u,%u)\n",
314 ft.dwLowDateTime, ft.dwHighDateTime);
317 static void _check_file_exists(LONG l, LPCSTR filename)
319 HANDLE file;
321 file = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
322 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
323 ok_(__FILE__,l)(file != INVALID_HANDLE_VALUE,
324 "expected file to exist, CreateFile failed with error %d\n",
325 GetLastError());
326 CloseHandle(file);
329 #define check_file_exists(f) _check_file_exists(__LINE__, f)
331 static void _check_file_not_exists(LONG l, LPCSTR filename)
333 HANDLE file;
335 file = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
336 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
337 ok_(__FILE__,l)(file == INVALID_HANDLE_VALUE,
338 "expected file not to exist\n");
339 if (file != INVALID_HANDLE_VALUE)
340 CloseHandle(file);
343 #define check_file_not_exists(f) _check_file_not_exists(__LINE__, f)
345 static void create_and_write_file(LPCSTR filename, void *data, DWORD len)
347 HANDLE file;
348 DWORD written;
349 BOOL ret;
351 file = CreateFileA(filename, GENERIC_WRITE,
352 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
353 FILE_ATTRIBUTE_NORMAL, NULL);
354 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed with error %d\n", GetLastError());
356 ret = WriteFile(file, data, len, &written, NULL);
357 ok(ret, "WriteFile failed with error %d\n", GetLastError());
359 CloseHandle(file);
362 static void test_urlcacheA(void)
364 static char ok_header[] = "HTTP/1.0 200 OK\r\n\r\n";
365 BOOL ret;
366 HANDLE hFile;
367 BYTE zero_byte = 0;
368 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
369 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo2;
370 DWORD cbCacheEntryInfo;
371 static const FILETIME filetime_zero;
372 FILETIME now;
374 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA, 0);
375 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
377 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA1, 0);
378 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
379 check_file_exists(filenameA1);
380 DeleteFileA(filenameA1);
382 ok(lstrcmpiA(filenameA, filenameA1), "expected a different file name\n");
384 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
386 ret = CommitUrlCacheEntry(test_url1, NULL, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
387 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
388 cbCacheEntryInfo = 0;
389 ret = GetUrlCacheEntryInfo(test_url1, NULL, &cbCacheEntryInfo);
390 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
391 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
392 "GetUrlCacheEntryInfo should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
393 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
394 ret = GetUrlCacheEntryInfo(test_url1, lpCacheEntryInfo, &cbCacheEntryInfo);
395 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
396 ok(!memcmp(&lpCacheEntryInfo->ExpireTime, &filetime_zero, sizeof(FILETIME)),
397 "expected zero ExpireTime\n");
398 ok(!memcmp(&lpCacheEntryInfo->LastModifiedTime, &filetime_zero, sizeof(FILETIME)),
399 "expected zero LastModifiedTime\n");
400 ok(lpCacheEntryInfo->CacheEntryType == (NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY) ||
401 broken(lpCacheEntryInfo->CacheEntryType == NORMAL_CACHE_ENTRY /* NT4/W2k */),
402 "expected type NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, got %08x\n",
403 lpCacheEntryInfo->CacheEntryType);
404 ok(!U(*lpCacheEntryInfo).dwExemptDelta, "expected dwExemptDelta 0, got %d\n",
405 U(*lpCacheEntryInfo).dwExemptDelta);
407 /* Make sure there is a notable change in timestamps */
408 Sleep(1000);
410 /* A subsequent commit with a different time/type doesn't change most of the entry */
411 GetSystemTimeAsFileTime(&now);
412 ret = CommitUrlCacheEntry(test_url1, NULL, now, now, NORMAL_CACHE_ENTRY,
413 (LPBYTE)ok_header, strlen(ok_header), NULL, NULL);
414 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
415 cbCacheEntryInfo = 0;
416 ret = GetUrlCacheEntryInfo(test_url1, NULL, &cbCacheEntryInfo);
417 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
418 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
419 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
420 lpCacheEntryInfo2 = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
421 ret = GetUrlCacheEntryInfo(test_url1, lpCacheEntryInfo2, &cbCacheEntryInfo);
422 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
423 /* but it does change the time.. */
424 ok(memcmp(&lpCacheEntryInfo2->ExpireTime, &filetime_zero, sizeof(FILETIME)),
425 "expected positive ExpireTime\n");
426 ok(memcmp(&lpCacheEntryInfo2->LastModifiedTime, &filetime_zero, sizeof(FILETIME)),
427 "expected positive LastModifiedTime\n");
428 ok(lpCacheEntryInfo2->CacheEntryType == (NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY) ||
429 broken(lpCacheEntryInfo2->CacheEntryType == NORMAL_CACHE_ENTRY /* NT4/W2k */),
430 "expected type NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, got %08x\n",
431 lpCacheEntryInfo2->CacheEntryType);
432 /* and set the headers. */
433 ok(lpCacheEntryInfo2->dwHeaderInfoSize == 19,
434 "expected headers size 19, got %d\n",
435 lpCacheEntryInfo2->dwHeaderInfoSize);
436 /* Hit rate gets incremented by 1 */
437 ok((lpCacheEntryInfo->dwHitRate + 1) == lpCacheEntryInfo2->dwHitRate,
438 "HitRate not incremented by one on commit\n");
439 /* Last access time should be updated */
440 ok(!(lpCacheEntryInfo->LastAccessTime.dwHighDateTime == lpCacheEntryInfo2->LastAccessTime.dwHighDateTime &&
441 lpCacheEntryInfo->LastAccessTime.dwLowDateTime == lpCacheEntryInfo2->LastAccessTime.dwLowDateTime),
442 "Last accessed time was not updated by commit\n");
443 /* File extension should be unset */
444 ok(lpCacheEntryInfo2->lpszFileExtension == NULL,
445 "Fileextension isn't unset: %s\n",
446 lpCacheEntryInfo2->lpszFileExtension);
447 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
448 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo2);
450 ret = CommitUrlCacheEntry(test_url, filenameA, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
451 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
453 cbCacheEntryInfo = 0;
454 SetLastError(0xdeadbeef);
455 ret = RetrieveUrlCacheEntryFile(test_url, NULL, &cbCacheEntryInfo, 0);
456 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
457 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
458 "RetrieveUrlCacheEntryFile should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
460 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
461 ret = RetrieveUrlCacheEntryFile(test_url, lpCacheEntryInfo, &cbCacheEntryInfo, 0);
462 ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
464 if (ret) check_cache_entry_infoA("RetrieveUrlCacheEntryFile", lpCacheEntryInfo);
466 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
468 cbCacheEntryInfo = 0;
469 SetLastError(0xdeadbeef);
470 ret = RetrieveUrlCacheEntryFile(test_url1, NULL, &cbCacheEntryInfo, 0);
471 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
472 ok(GetLastError() == ERROR_INVALID_DATA,
473 "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_DATA instead of %d\n", GetLastError());
475 if (pUnlockUrlCacheEntryFileA)
477 ret = pUnlockUrlCacheEntryFileA(test_url, 0);
478 ok(ret, "UnlockUrlCacheEntryFileA failed with error %d\n", GetLastError());
481 /* test Find*UrlCacheEntry functions */
482 test_find_url_cache_entriesA();
484 test_GetUrlCacheEntryInfoExA();
485 test_RetrieveUrlCacheEntryA();
486 test_IsUrlCacheEntryExpiredA();
488 if (pDeleteUrlCacheEntryA)
490 ret = pDeleteUrlCacheEntryA(test_url);
491 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
492 ret = pDeleteUrlCacheEntryA(test_url1);
493 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
496 SetLastError(0xdeadbeef);
497 ret = DeleteFile(filenameA);
498 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "local file should no longer exist\n");
500 /* Creating two entries with the same URL */
501 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA, 0);
502 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
504 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA1, 0);
505 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
507 ok(lstrcmpiA(filenameA, filenameA1), "expected a different file name\n");
509 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
510 create_and_write_file(filenameA1, &zero_byte, sizeof(zero_byte));
511 check_file_exists(filenameA);
512 check_file_exists(filenameA1);
514 ret = CommitUrlCacheEntry(test_url, filenameA, filetime_zero,
515 filetime_zero, NORMAL_CACHE_ENTRY, (LPBYTE)ok_header,
516 strlen(ok_header), "html", NULL);
517 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
518 check_file_exists(filenameA);
519 check_file_exists(filenameA1);
520 ret = CommitUrlCacheEntry(test_url, filenameA1, filetime_zero,
521 filetime_zero, COOKIE_CACHE_ENTRY, NULL, 0, "html", NULL);
522 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
523 /* By committing the same URL a second time, the prior entry is
524 * overwritten...
526 cbCacheEntryInfo = 0;
527 SetLastError(0xdeadbeef);
528 ret = GetUrlCacheEntryInfo(test_url, NULL, &cbCacheEntryInfo);
529 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
530 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
531 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
532 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
533 ret = GetUrlCacheEntryInfo(test_url, lpCacheEntryInfo, &cbCacheEntryInfo);
534 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
535 /* with the previous entry type retained.. */
536 ok(lpCacheEntryInfo->CacheEntryType & NORMAL_CACHE_ENTRY,
537 "expected cache entry type NORMAL_CACHE_ENTRY, got %d (0x%08x)\n",
538 lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
539 /* and the headers overwritten.. */
540 ok(!lpCacheEntryInfo->dwHeaderInfoSize, "expected headers size 0, got %d\n",
541 lpCacheEntryInfo->dwHeaderInfoSize);
542 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
543 /* and the previous filename shouldn't exist. */
544 check_file_not_exists(filenameA);
545 check_file_exists(filenameA1);
547 if (pDeleteUrlCacheEntryA)
549 ret = pDeleteUrlCacheEntryA(test_url);
550 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
551 check_file_not_exists(filenameA);
552 check_file_not_exists(filenameA1);
553 /* Just in case, clean up files */
554 DeleteFileA(filenameA1);
555 DeleteFileA(filenameA);
558 /* Check whether a retrieved cache entry can be deleted before it's
559 * unlocked:
561 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA, 0);
562 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
563 ret = CommitUrlCacheEntry(test_url, filenameA, filetime_zero, filetime_zero,
564 NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
565 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
567 cbCacheEntryInfo = 0;
568 SetLastError(0xdeadbeef);
569 ret = RetrieveUrlCacheEntryFile(test_url, NULL, &cbCacheEntryInfo, 0);
570 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
571 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
572 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
574 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
575 ret = RetrieveUrlCacheEntryFile(test_url, lpCacheEntryInfo,
576 &cbCacheEntryInfo, 0);
577 ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
579 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
581 if (pDeleteUrlCacheEntryA)
583 ret = pDeleteUrlCacheEntryA(test_url);
584 ok(!ret, "Expected failure\n");
585 ok(GetLastError() == ERROR_SHARING_VIOLATION,
586 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
587 check_file_exists(filenameA);
590 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
591 memset(lpCacheEntryInfo, 0, cbCacheEntryInfo);
592 ret = GetUrlCacheEntryInfo(test_url, lpCacheEntryInfo, &cbCacheEntryInfo);
593 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
594 ok(lpCacheEntryInfo->CacheEntryType & 0x400000,
595 "CacheEntryType hasn't PENDING_DELETE_CACHE_ENTRY set, (flags %08x)\n",
596 lpCacheEntryInfo->CacheEntryType);
597 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
599 if (pUnlockUrlCacheEntryFileA)
601 check_file_exists(filenameA);
602 ret = pUnlockUrlCacheEntryFileA(test_url, 0);
603 ok(ret, "UnlockUrlCacheEntryFileA failed: %d\n", GetLastError());
604 /* By unlocking the already-deleted cache entry, the file associated
605 * with it is deleted..
607 check_file_not_exists(filenameA);
608 /* (just in case, delete file) */
609 DeleteFileA(filenameA);
611 if (pDeleteUrlCacheEntryA)
613 /* and a subsequent deletion should fail. */
614 ret = pDeleteUrlCacheEntryA(test_url);
615 ok(!ret, "Expected failure\n");
616 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
617 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
620 /* Test whether preventing a file from being deleted causes
621 * DeleteUrlCacheEntryA to fail.
623 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA, 0);
624 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
626 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
627 check_file_exists(filenameA);
629 ret = CommitUrlCacheEntry(test_url, filenameA, filetime_zero,
630 filetime_zero, NORMAL_CACHE_ENTRY, (LPBYTE)ok_header,
631 strlen(ok_header), "html", NULL);
632 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
633 check_file_exists(filenameA);
634 hFile = CreateFileA(filenameA, GENERIC_READ, 0, NULL, OPEN_EXISTING,
635 FILE_ATTRIBUTE_NORMAL, NULL);
636 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA failed: %d\n",
637 GetLastError());
638 if (pDeleteUrlCacheEntryA)
640 /* DeleteUrlCacheEntryA should succeed.. */
641 ret = pDeleteUrlCacheEntryA(test_url);
642 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
644 CloseHandle(hFile);
645 if (pDeleteUrlCacheEntryA)
647 /* and a subsequent deletion should fail.. */
648 ret = pDeleteUrlCacheEntryA(test_url);
649 ok(!ret, "Expected failure\n");
650 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
651 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
653 /* and the file should be untouched. */
654 check_file_exists(filenameA);
655 DeleteFileA(filenameA);
657 /* Try creating a sticky entry. Unlike non-sticky entries, the filename
658 * must have been set already.
660 SetLastError(0xdeadbeef);
661 ret = CommitUrlCacheEntry(test_url, NULL, filetime_zero, filetime_zero,
662 STICKY_CACHE_ENTRY, (LPBYTE)ok_header, strlen(ok_header), "html",
663 NULL);
664 ok(!ret, "expected failure\n");
665 ok(GetLastError() == ERROR_INVALID_PARAMETER,
666 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
667 SetLastError(0xdeadbeef);
668 ret = CommitUrlCacheEntry(test_url, NULL, filetime_zero, filetime_zero,
669 NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
670 (LPBYTE)ok_header, strlen(ok_header), "html", NULL);
671 ok(!ret, "expected failure\n");
672 ok(GetLastError() == ERROR_INVALID_PARAMETER,
673 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
675 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA, 0);
676 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
677 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
678 ret = CommitUrlCacheEntry(test_url, filenameA, filetime_zero, filetime_zero,
679 NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
680 (LPBYTE)ok_header, strlen(ok_header), "html", NULL);
681 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
682 cbCacheEntryInfo = 0;
683 SetLastError(0xdeadbeef);
684 ret = GetUrlCacheEntryInfo(test_url, NULL, &cbCacheEntryInfo);
685 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
686 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
687 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
688 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
689 ret = GetUrlCacheEntryInfo(test_url, lpCacheEntryInfo, &cbCacheEntryInfo);
690 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
691 ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
692 "expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n",
693 lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
694 ok(U(*lpCacheEntryInfo).dwExemptDelta == 86400,
695 "expected dwExemptDelta 86400, got %d\n",
696 U(*lpCacheEntryInfo).dwExemptDelta);
697 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
698 if (pDeleteUrlCacheEntryA)
700 ret = pDeleteUrlCacheEntryA(test_url);
701 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
702 /* When explicitly deleting the cache entry, the file is also deleted */
703 check_file_not_exists(filenameA);
705 /* Test once again, setting the exempt delta via SetUrlCacheEntryInfo */
706 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA, 0);
707 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
708 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
709 ret = CommitUrlCacheEntry(test_url, filenameA, filetime_zero, filetime_zero,
710 NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
711 (LPBYTE)ok_header, strlen(ok_header), "html", NULL);
712 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
713 cbCacheEntryInfo = 0;
714 SetLastError(0xdeadbeef);
715 ret = GetUrlCacheEntryInfo(test_url, NULL, &cbCacheEntryInfo);
716 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
717 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
718 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
719 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
720 ret = GetUrlCacheEntryInfo(test_url, lpCacheEntryInfo, &cbCacheEntryInfo);
721 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
722 ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
723 "expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n",
724 lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
725 ok(U(*lpCacheEntryInfo).dwExemptDelta == 86400,
726 "expected dwExemptDelta 86400, got %d\n",
727 U(*lpCacheEntryInfo).dwExemptDelta);
728 U(*lpCacheEntryInfo).dwExemptDelta = 0;
729 ret = SetUrlCacheEntryInfoA(test_url, lpCacheEntryInfo,
730 CACHE_ENTRY_EXEMPT_DELTA_FC);
731 ok(ret, "SetUrlCacheEntryInfo failed: %d\n", GetLastError());
732 ret = GetUrlCacheEntryInfo(test_url, lpCacheEntryInfo, &cbCacheEntryInfo);
733 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
734 ok(!U(*lpCacheEntryInfo).dwExemptDelta, "expected dwExemptDelta 0, got %d\n",
735 U(*lpCacheEntryInfo).dwExemptDelta);
736 /* See whether a sticky cache entry has the flag cleared once the exempt
737 * delta is meaningless.
739 ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
740 "expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n",
741 lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
743 /* Recommit of Url entry keeps dwExemptDelta */
744 U(*lpCacheEntryInfo).dwExemptDelta = 8600;
745 ret = SetUrlCacheEntryInfoA(test_url, lpCacheEntryInfo,
746 CACHE_ENTRY_EXEMPT_DELTA_FC);
747 ok(ret, "SetUrlCacheEntryInfo failed: %d\n", GetLastError());
749 ret = CreateUrlCacheEntry(test_url, 0, "html", filenameA1, 0);
750 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
751 create_and_write_file(filenameA1, &zero_byte, sizeof(zero_byte));
753 ret = CommitUrlCacheEntry(test_url, filenameA1, filetime_zero, filetime_zero,
754 NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
755 (LPBYTE)ok_header, strlen(ok_header), "html", NULL);
756 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
758 ret = GetUrlCacheEntryInfo(test_url, lpCacheEntryInfo, &cbCacheEntryInfo);
759 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
760 ok(U(*lpCacheEntryInfo).dwExemptDelta == 8600,
761 "expected dwExemptDelta 8600, got %d\n",
762 U(*lpCacheEntryInfo).dwExemptDelta);
764 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
766 if (pDeleteUrlCacheEntryA)
768 ret = pDeleteUrlCacheEntryA(test_url);
769 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
770 check_file_not_exists(filenameA);
773 /* Test if files with identical hash keys are handled correctly */
774 ret = CommitUrlCacheEntryA(test_hash_collisions1, NULL, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
775 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
776 ret = CommitUrlCacheEntryA(test_hash_collisions2, NULL, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
777 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
779 cbCacheEntryInfo = 0;
780 ret = GetUrlCacheEntryInfo(test_hash_collisions1, NULL, &cbCacheEntryInfo);
781 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
782 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
783 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
784 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
785 ret = GetUrlCacheEntryInfo(test_hash_collisions1, lpCacheEntryInfo, &cbCacheEntryInfo);
786 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
787 ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, test_hash_collisions1),
788 "got incorrect entry: %s\n", lpCacheEntryInfo->lpszSourceUrlName);
789 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
791 cbCacheEntryInfo = 0;
792 ret = GetUrlCacheEntryInfo(test_hash_collisions2, NULL, &cbCacheEntryInfo);
793 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
794 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
795 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
796 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
797 ret = GetUrlCacheEntryInfo(test_hash_collisions2, lpCacheEntryInfo, &cbCacheEntryInfo);
798 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
799 ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, test_hash_collisions2),
800 "got incorrect entry: %s\n", lpCacheEntryInfo->lpszSourceUrlName);
801 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
803 if (pDeleteUrlCacheEntryA) {
804 ret = pDeleteUrlCacheEntryA(test_hash_collisions1);
805 ok(ret, "DeleteUrlCacheEntry failed: %d\n", GetLastError());
806 ret = pDeleteUrlCacheEntryA(test_hash_collisions2);
807 ok(ret, "DeleteUrlCacheEntry failed: %d\n", GetLastError());
811 static void test_urlcacheW(void)
813 static struct test_data
815 DWORD err;
816 WCHAR url[128];
817 char encoded_url[128];
818 WCHAR extension[32];
819 WCHAR header_info[128];
820 }urls[] = {
822 0, {'h','t','t','p',':','/','/','T','.','p','l','/','t',0},
823 "http://T.pl/t", {0}, {0}
826 0, {'w','w','w','.','T','.','p','l','/','t',0},
827 "www.T.pl/t", {0}, {0}
830 0, {'h','t','t','p',':','/','/','w','w','w','.','t','e','s','t',0x15b,0x107,
831 '.','o','r','g','/','t','e','s','t','.','h','t','m','l',0},
832 "http://www.xn--test-ota71c.org/test.html", {'t','x','t',0}, {0}
835 0, {'w','w','w','.','T','e','s','t',0x15b,0x107,'.','o','r','g',
836 '/','t','e','s','t','.','h','t','m','l',0},
837 "www.Test\xc5\x9b\xc4\x87.org/test.html", {'a',0x106,'a',0}, {'b',0x106,'b',0}
840 0, {'H','t','t','p','s',':','/','/',0x15b,0x15b,0x107,'/','t',0x107,'/',
841 't','e','s','t','?','a','=','%','2','0',0x106,0},
842 "Https://xn--4da1oa/t\xc4\x87/test?a=%20\xc4\x86", {'a',0x15b,'a',0}, {'b',0x15b,'b',0}
845 12005, {'h','t','t','p','s',':','/','/','/','/',0x107,'.','o','r','g','/','t','e','s','t',0},
846 "", {0}, {0}
849 0, {'C','o','o','k','i','e',':',' ','u','s','e','r','@','h','t','t','p',
850 ':','/','/','t',0x15b,0x107,'.','o','r','g','/',0},
851 "Cookie: user@http://t\xc5\x9b\xc4\x87.org/", {0}, {0}
854 static const FILETIME filetime_zero;
856 WCHAR bufW[MAX_PATH];
857 DWORD i;
858 BOOL ret;
860 if(old_ie) {
861 win_skip("urlcache unicode functions\n");
862 return;
865 for(i=0; i<sizeof(urls)/sizeof(*urls); i++) {
866 INTERNET_CACHE_ENTRY_INFOA *entry_infoA;
867 INTERNET_CACHE_ENTRY_INFOW *entry_infoW;
868 DWORD size;
870 SetLastError(0xdeadbeef);
871 ret = CreateUrlCacheEntryW(urls[i].url, 0, NULL, bufW, 0);
872 if(urls[i].err != 0) {
873 ok(!ret, "%d) CreateUrlCacheEntryW succeeded\n", i);
874 ok(urls[i].err == GetLastError(), "%d) GetLastError() = %d\n", i, GetLastError());
875 continue;
877 ok(ret, "%d) CreateUrlCacheEntryW failed: %d\n", i, GetLastError());
879 /* dwHeaderSize is ignored, pass 0 to prove it */
880 ret = CommitUrlCacheEntryW(urls[i].url, bufW, filetime_zero, filetime_zero,
881 NORMAL_CACHE_ENTRY, urls[i].header_info, 0, urls[i].extension, NULL);
882 ok(ret, "%d) CommitUrlCacheEntryW failed: %d\n", i, GetLastError());
884 SetLastError(0xdeadbeef);
885 size = 0;
886 ret = GetUrlCacheEntryInfoW(urls[i].url, NULL, &size);
887 ok(!ret && GetLastError()==ERROR_INSUFFICIENT_BUFFER,
888 "%d) GetLastError() = %d\n", i, GetLastError());
889 entry_infoW = HeapAlloc(GetProcessHeap(), 0, size);
890 ret = GetUrlCacheEntryInfoW(urls[i].url, entry_infoW, &size);
891 ok(ret, "%d) GetUrlCacheEntryInfoW failed: %d\n", i, GetLastError());
893 ret = GetUrlCacheEntryInfoA(urls[i].encoded_url, NULL, &size);
894 ok(!ret && GetLastError()==ERROR_INSUFFICIENT_BUFFER,
895 "%d) GetLastError() = %d\n", i, GetLastError());
896 if(!ret && GetLastError()!=ERROR_INSUFFICIENT_BUFFER) {
897 win_skip("ANSI version of url is incorrect\n");
898 continue;
900 entry_infoA = HeapAlloc(GetProcessHeap(), 0, size);
901 ret = GetUrlCacheEntryInfoA(urls[i].encoded_url, entry_infoA, &size);
902 ok(ret, "%d) GetUrlCacheEntryInfoA failed: %d\n", i, GetLastError());
904 ok(entry_infoW->dwStructSize == entry_infoA->dwStructSize,
905 "%d) entry_infoW->dwStructSize = %d, expected %d\n",
906 i, entry_infoW->dwStructSize, entry_infoA->dwStructSize);
907 ok(!lstrcmpW(urls[i].url, entry_infoW->lpszSourceUrlName),
908 "%d) entry_infoW->lpszSourceUrlName = %s\n",
909 i, wine_dbgstr_w(entry_infoW->lpszSourceUrlName));
910 ok(!lstrcmpA(urls[i].encoded_url, entry_infoA->lpszSourceUrlName),
911 "%d) entry_infoA->lpszSourceUrlName = %s\n",
912 i, entry_infoA->lpszSourceUrlName);
913 ok(entry_infoW->CacheEntryType == entry_infoA->CacheEntryType,
914 "%d) entry_infoW->CacheEntryType = %x, expected %x\n",
915 i, entry_infoW->CacheEntryType, entry_infoA->CacheEntryType);
916 ok(entry_infoW->dwUseCount == entry_infoA->dwUseCount,
917 "%d) entry_infoW->dwUseCount = %d, expected %d\n",
918 i, entry_infoW->dwUseCount, entry_infoA->dwUseCount);
919 ok(entry_infoW->dwHitRate == entry_infoA->dwHitRate,
920 "%d) entry_infoW->dwHitRate = %d, expected %d\n",
921 i, entry_infoW->dwHitRate, entry_infoA->dwHitRate);
922 ok(entry_infoW->dwSizeLow == entry_infoA->dwSizeLow,
923 "%d) entry_infoW->dwSizeLow = %d, expected %d\n",
924 i, entry_infoW->dwSizeLow, entry_infoA->dwSizeLow);
925 ok(entry_infoW->dwSizeHigh == entry_infoA->dwSizeHigh,
926 "%d) entry_infoW->dwSizeHigh = %d, expected %d\n",
927 i, entry_infoW->dwSizeHigh, entry_infoA->dwSizeHigh);
928 ok(!memcmp(&entry_infoW->LastModifiedTime, &entry_infoA->LastModifiedTime, sizeof(FILETIME)),
929 "%d) entry_infoW->LastModifiedTime is incorrect\n", i);
930 ok(!memcmp(&entry_infoW->ExpireTime, &entry_infoA->ExpireTime, sizeof(FILETIME)),
931 "%d) entry_infoW->ExpireTime is incorrect\n", i);
932 ok(!memcmp(&entry_infoW->LastAccessTime, &entry_infoA->LastAccessTime, sizeof(FILETIME)),
933 "%d) entry_infoW->LastAccessTime is incorrect\n", i);
934 ok(!memcmp(&entry_infoW->LastSyncTime, &entry_infoA->LastSyncTime, sizeof(FILETIME)),
935 "%d) entry_infoW->LastSyncTime is incorrect\n", i);
937 MultiByteToWideChar(CP_ACP, 0, entry_infoA->lpszLocalFileName, -1, bufW, MAX_PATH);
938 ok(!lstrcmpW(entry_infoW->lpszLocalFileName, bufW),
939 "%d) entry_infoW->lpszLocalFileName = %s, expected %s\n",
940 i, wine_dbgstr_w(entry_infoW->lpszLocalFileName), wine_dbgstr_w(bufW));
942 if(!urls[i].header_info[0]) {
943 ok(!entry_infoW->lpHeaderInfo, "entry_infoW->lpHeaderInfo != NULL\n");
944 }else {
945 ok(!lstrcmpW((WCHAR*)entry_infoW->lpHeaderInfo, urls[i].header_info),
946 "%d) entry_infoW->lpHeaderInfo = %s\n",
947 i, wine_dbgstr_w((WCHAR*)entry_infoW->lpHeaderInfo));
950 if(!urls[i].extension[0]) {
951 ok(!entry_infoW->lpszFileExtension, "entry_infoW->lpszFileExtension != NULL\n");
952 }else {
953 MultiByteToWideChar(CP_ACP, 0, entry_infoA->lpszFileExtension, -1, bufW, MAX_PATH);
954 ok(!lstrcmpW(entry_infoW->lpszFileExtension, bufW),
955 "%d) entry_infoW->lpszFileExtension = %s, expected %s\n",
956 i, wine_dbgstr_w(entry_infoW->lpszFileExtension), wine_dbgstr_w(bufW));
959 HeapFree(GetProcessHeap(), 0, entry_infoW);
960 HeapFree(GetProcessHeap(), 0, entry_infoA);
962 if(pDeleteUrlCacheEntryA) {
963 ret = pDeleteUrlCacheEntryA(urls[i].encoded_url);
964 ok(ret, "%d) DeleteUrlCacheEntryW failed: %d\n", i, GetLastError());
969 static void test_FindCloseUrlCache(void)
971 BOOL r;
972 DWORD err;
974 SetLastError(0xdeadbeef);
975 r = FindCloseUrlCache(NULL);
976 err = GetLastError();
977 ok(0 == r, "expected 0, got %d\n", r);
978 ok(ERROR_INVALID_HANDLE == err, "expected %d, got %d\n", ERROR_INVALID_HANDLE, err);
981 static void test_GetDiskInfoA(void)
983 BOOL ret;
984 DWORD error, cluster_size;
985 DWORDLONG free, total;
986 char path[MAX_PATH], *p;
988 GetSystemDirectoryA(path, MAX_PATH);
989 if ((p = strchr(path, '\\'))) *++p = 0;
991 ret = GetDiskInfoA(path, &cluster_size, &free, &total);
992 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
994 ret = GetDiskInfoA(path, &cluster_size, &free, NULL);
995 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
997 ret = GetDiskInfoA(path, &cluster_size, NULL, NULL);
998 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
1000 ret = GetDiskInfoA(path, NULL, NULL, NULL);
1001 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
1003 SetLastError(0xdeadbeef);
1004 strcpy(p, "\\non\\existing\\path");
1005 ret = GetDiskInfoA(path, NULL, NULL, NULL);
1006 error = GetLastError();
1007 ok(!ret ||
1008 broken(old_ie && ret), /* < IE7 */
1009 "GetDiskInfoA succeeded\n");
1010 ok(error == ERROR_PATH_NOT_FOUND ||
1011 broken(old_ie && error == 0xdeadbeef), /* < IE7 */
1012 "got %u expected ERROR_PATH_NOT_FOUND\n", error);
1014 SetLastError(0xdeadbeef);
1015 ret = GetDiskInfoA(NULL, NULL, NULL, NULL);
1016 error = GetLastError();
1017 ok(!ret, "GetDiskInfoA succeeded\n");
1018 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
1021 START_TEST(urlcache)
1023 HMODULE hdll;
1024 hdll = GetModuleHandleA("wininet.dll");
1026 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
1027 win_skip("Too old IE (older than 6.0)\n");
1028 return;
1030 if(!GetProcAddress(hdll, "InternetGetSecurityInfoByURL")) /* < IE7 */
1031 old_ie = TRUE;
1033 pDeleteUrlCacheEntryA = (void*)GetProcAddress(hdll, "DeleteUrlCacheEntryA");
1034 pUnlockUrlCacheEntryFileA = (void*)GetProcAddress(hdll, "UnlockUrlCacheEntryFileA");
1035 test_urlcacheA();
1036 test_urlcacheW();
1037 test_FindCloseUrlCache();
1038 test_GetDiskInfoA();