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 _check_file_exists(LONG l, LPCSTR filename)
188 file = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
189 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
190 ok_(__FILE__,l)(file != INVALID_HANDLE_VALUE,
191 "expected file to exist, CreateFile failed with error %d\n",
196 #define check_file_exists(f) _check_file_exists(__LINE__, f)
198 static void _check_file_not_exists(LONG l, LPCSTR filename)
202 file = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
203 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
204 ok_(__FILE__,l)(file == INVALID_HANDLE_VALUE,
205 "expected file not to exist\n");
206 if (file != INVALID_HANDLE_VALUE)
210 #define check_file_not_exists(f) _check_file_not_exists(__LINE__, f)
212 static void create_and_write_file(LPCSTR filename, void *data, DWORD len)
218 file = CreateFileA(filename, GENERIC_WRITE,
219 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
220 FILE_ATTRIBUTE_NORMAL, NULL);
221 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed with error %d\n", GetLastError());
223 ret = WriteFile(file, data, len, &written, NULL);
224 ok(ret, "WriteFile failed with error %d\n", GetLastError());
229 static void test_urlcacheA(void)
231 static char ok_header[] = "HTTP/1.0 200 OK\r\n\r\n";
235 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
236 DWORD cbCacheEntryInfo;
237 static const FILETIME filetime_zero;
240 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
241 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
243 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA1, 0);
244 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
246 ok(lstrcmpiA(filenameA, filenameA1), "expected a different file name\n");
248 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
250 ret = CommitUrlCacheEntry(TEST_URL1, NULL, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, NULL, 0, NULL, NULL);
251 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
252 cbCacheEntryInfo = 0;
253 ret = GetUrlCacheEntryInfo(TEST_URL1, NULL, &cbCacheEntryInfo);
254 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
255 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
256 "GetUrlCacheEntryInfo should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
257 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
258 ret = GetUrlCacheEntryInfo(TEST_URL1, lpCacheEntryInfo, &cbCacheEntryInfo);
259 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
260 ok(!memcmp(&lpCacheEntryInfo->ExpireTime, &filetime_zero, sizeof(FILETIME)),
261 "expected zero ExpireTime\n");
262 ok(!memcmp(&lpCacheEntryInfo->LastModifiedTime, &filetime_zero, sizeof(FILETIME)),
263 "expected zero LastModifiedTime\n");
264 ok(lpCacheEntryInfo->CacheEntryType == (NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY) ||
265 broken(lpCacheEntryInfo->CacheEntryType == NORMAL_CACHE_ENTRY /* NT4/W2k */),
266 "expected type NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, got %08x\n",
267 lpCacheEntryInfo->CacheEntryType);
268 ok(!lpCacheEntryInfo->dwExemptDelta, "expected dwExemptDelta 0, got %d\n",
269 lpCacheEntryInfo->dwExemptDelta);
270 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
272 /* A subsequent commit with a different time/type doesn't change the type */
273 GetSystemTimeAsFileTime(&now);
274 ret = CommitUrlCacheEntry(TEST_URL1, NULL, now, now, NORMAL_CACHE_ENTRY,
275 (LPBYTE)ok_header, strlen(ok_header), NULL, NULL);
276 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
277 cbCacheEntryInfo = 0;
278 ret = GetUrlCacheEntryInfo(TEST_URL1, NULL, &cbCacheEntryInfo);
279 ok(!ret, "GetUrlCacheEntryInfo should have failed\n");
280 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
281 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
282 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
283 ret = GetUrlCacheEntryInfo(TEST_URL1, lpCacheEntryInfo, &cbCacheEntryInfo);
284 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
285 /* but it does change the time.. */
287 ok(memcmp(&lpCacheEntryInfo->ExpireTime, &filetime_zero, sizeof(FILETIME)),
288 "expected positive ExpireTime\n");
290 ok(memcmp(&lpCacheEntryInfo->LastModifiedTime, &filetime_zero, sizeof(FILETIME)),
291 "expected positive LastModifiedTime\n");
292 ok(lpCacheEntryInfo->CacheEntryType == (NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY) ||
293 broken(lpCacheEntryInfo->CacheEntryType == NORMAL_CACHE_ENTRY /* NT4/W2k */),
294 "expected type NORMAL_CACHE_ENTRY|URLHISTORY_CACHE_ENTRY, got %08x\n",
295 lpCacheEntryInfo->CacheEntryType);
296 /* and set the headers. */
298 ok(lpCacheEntryInfo->dwHeaderInfoSize == 19,
299 "expected headers size 19, got %d\n",
300 lpCacheEntryInfo->dwHeaderInfoSize);
301 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
303 ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
304 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
306 cbCacheEntryInfo = 0;
307 SetLastError(0xdeadbeef);
308 ret = RetrieveUrlCacheEntryFile(TEST_URL, NULL, &cbCacheEntryInfo, 0);
309 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
310 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
311 "RetrieveUrlCacheEntryFile should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
313 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
314 ret = RetrieveUrlCacheEntryFile(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, 0);
315 ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
317 check_cache_entry_infoA("RetrieveUrlCacheEntryFile", lpCacheEntryInfo);
319 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
321 cbCacheEntryInfo = 0;
322 SetLastError(0xdeadbeef);
323 ret = RetrieveUrlCacheEntryFile(TEST_URL1, NULL, &cbCacheEntryInfo, 0);
324 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
325 ok(GetLastError() == ERROR_INVALID_DATA,
326 "RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_DATA instead of %d\n", GetLastError());
328 if (pUnlockUrlCacheEntryFileA)
330 ret = pUnlockUrlCacheEntryFileA(TEST_URL, 0);
331 ok(ret, "UnlockUrlCacheEntryFileA failed with error %d\n", GetLastError());
334 /* test Find*UrlCacheEntry functions */
335 test_find_url_cache_entriesA();
337 test_GetUrlCacheEntryInfoExA();
338 test_RetrieveUrlCacheEntryA();
340 if (pDeleteUrlCacheEntryA)
342 ret = pDeleteUrlCacheEntryA(TEST_URL);
343 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
344 ret = pDeleteUrlCacheEntryA(TEST_URL1);
345 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
348 SetLastError(0xdeadbeef);
349 ret = DeleteFile(filenameA);
351 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "local file should no longer exist\n");
353 /* Creating two entries with the same URL */
354 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
355 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
357 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA1, 0);
358 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
360 ok(lstrcmpiA(filenameA, filenameA1), "expected a different file name\n");
362 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
363 create_and_write_file(filenameA1, &zero_byte, sizeof(zero_byte));
364 check_file_exists(filenameA);
365 check_file_exists(filenameA1);
367 ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero,
368 filetime_zero, NORMAL_CACHE_ENTRY, (LPBYTE)ok_header,
369 strlen(ok_header), "html", NULL);
370 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
371 check_file_exists(filenameA);
372 check_file_exists(filenameA1);
373 ret = CommitUrlCacheEntry(TEST_URL, filenameA1, filetime_zero,
374 filetime_zero, COOKIE_CACHE_ENTRY, NULL, 0, "html", NULL);
375 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
376 /* By committing the same URL a second time, the prior entry is
379 cbCacheEntryInfo = 0;
380 SetLastError(0xdeadbeef);
381 ret = GetUrlCacheEntryInfo(TEST_URL, NULL, &cbCacheEntryInfo);
382 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
383 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
384 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
385 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
386 ret = GetUrlCacheEntryInfo(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo);
387 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
388 /* with the previous entry type retained.. */
389 ok(lpCacheEntryInfo->CacheEntryType & NORMAL_CACHE_ENTRY,
390 "expected cache entry type NORMAL_CACHE_ENTRY, got %d (0x%08x)\n",
391 lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
392 /* and the headers overwritten.. */
394 ok(!lpCacheEntryInfo->dwHeaderInfoSize, "expected headers size 0, got %d\n",
395 lpCacheEntryInfo->dwHeaderInfoSize);
396 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
397 /* and the previous filename shouldn't exist. */
399 check_file_not_exists(filenameA);
400 check_file_exists(filenameA1);
402 if (pDeleteUrlCacheEntryA)
404 ret = pDeleteUrlCacheEntryA(TEST_URL);
405 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
407 check_file_not_exists(filenameA);
409 check_file_not_exists(filenameA1);
410 /* Just in case, clean up files */
411 DeleteFileA(filenameA1);
412 DeleteFileA(filenameA);
415 /* Check whether a retrieved cache entry can be deleted before it's
418 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
419 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
420 ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero, filetime_zero,
421 NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
422 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
424 cbCacheEntryInfo = 0;
425 SetLastError(0xdeadbeef);
426 ret = RetrieveUrlCacheEntryFile(TEST_URL, NULL, &cbCacheEntryInfo, 0);
427 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
428 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
429 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
431 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
432 ret = RetrieveUrlCacheEntryFile(TEST_URL, lpCacheEntryInfo,
433 &cbCacheEntryInfo, 0);
434 ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
436 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
438 if (pDeleteUrlCacheEntryA)
440 ret = pDeleteUrlCacheEntryA(TEST_URL);
442 ok(!ret, "Expected failure\n");
444 ok(GetLastError() == ERROR_SHARING_VIOLATION,
445 "Expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
446 check_file_exists(filenameA);
448 if (pUnlockUrlCacheEntryFileA)
450 check_file_exists(filenameA);
451 ret = pUnlockUrlCacheEntryFileA(TEST_URL, 0);
453 ok(ret, "UnlockUrlCacheEntryFileA failed: %d\n", GetLastError());
454 /* By unlocking the already-deleted cache entry, the file associated
455 * with it is deleted..
458 check_file_not_exists(filenameA);
459 /* (just in case, delete file) */
460 DeleteFileA(filenameA);
462 if (pDeleteUrlCacheEntryA)
464 /* and a subsequent deletion should fail. */
465 ret = pDeleteUrlCacheEntryA(TEST_URL);
466 ok(!ret, "Expected failure\n");
467 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
468 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
471 /* Test whether preventing a file from being deleted causes
472 * DeleteUrlCacheEntryA to fail.
474 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
475 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
477 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
478 check_file_exists(filenameA);
480 ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero,
481 filetime_zero, NORMAL_CACHE_ENTRY, (LPBYTE)ok_header,
482 strlen(ok_header), "html", NULL);
483 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
484 check_file_exists(filenameA);
485 hFile = CreateFileA(filenameA, GENERIC_READ, 0, NULL, OPEN_EXISTING,
486 FILE_ATTRIBUTE_NORMAL, NULL);
487 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA failed: %d\n",
489 if (pDeleteUrlCacheEntryA)
491 /* DeleteUrlCacheEntryA should succeed.. */
492 ret = pDeleteUrlCacheEntryA(TEST_URL);
493 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
496 if (pDeleteUrlCacheEntryA)
498 /* and a subsequent deletion should fail.. */
499 ret = pDeleteUrlCacheEntryA(TEST_URL);
500 ok(!ret, "Expected failure\n");
501 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
502 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
504 /* and the file should be untouched. */
505 check_file_exists(filenameA);
506 DeleteFileA(filenameA);
508 /* Try creating a sticky entry. Unlike non-sticky entries, the filename
509 * must have been set already.
511 SetLastError(0xdeadbeef);
512 ret = CommitUrlCacheEntry(TEST_URL, NULL, filetime_zero, filetime_zero,
513 STICKY_CACHE_ENTRY, (LPBYTE)ok_header, strlen(ok_header), "html",
516 ok(!ret, "expected failure\n");
517 ok(GetLastError() == ERROR_INVALID_PARAMETER,
518 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
520 SetLastError(0xdeadbeef);
521 ret = CommitUrlCacheEntry(TEST_URL, NULL, filetime_zero, filetime_zero,
522 NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
523 (LPBYTE)ok_header, strlen(ok_header), "html", NULL);
525 ok(!ret, "expected failure\n");
526 ok(GetLastError() == ERROR_INVALID_PARAMETER,
527 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
529 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
530 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
531 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
532 ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero, filetime_zero,
533 NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
534 (LPBYTE)ok_header, strlen(ok_header), "html", NULL);
535 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
536 cbCacheEntryInfo = 0;
537 SetLastError(0xdeadbeef);
538 ret = GetUrlCacheEntryInfo(TEST_URL, NULL, &cbCacheEntryInfo);
539 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
540 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
541 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
542 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
543 ret = GetUrlCacheEntryInfo(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo);
544 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
545 ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
546 "expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n",
547 lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
549 ok(lpCacheEntryInfo->dwExemptDelta == 86400,
550 "expected dwExemptDelta 864000, got %d\n",
551 lpCacheEntryInfo->dwExemptDelta);
552 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
553 if (pDeleteUrlCacheEntryA)
555 ret = pDeleteUrlCacheEntryA(TEST_URL);
556 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
557 /* When explicitly deleting the cache entry, the file is also deleted */
559 check_file_not_exists(filenameA);
561 /* Test once again, setting the exempt delta via SetUrlCacheEntryInfo */
562 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0);
563 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
564 create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte));
565 ret = CommitUrlCacheEntry(TEST_URL, filenameA, filetime_zero, filetime_zero,
566 NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY,
567 (LPBYTE)ok_header, strlen(ok_header), "html", NULL);
568 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
569 cbCacheEntryInfo = 0;
570 SetLastError(0xdeadbeef);
571 ret = GetUrlCacheEntryInfo(TEST_URL, NULL, &cbCacheEntryInfo);
572 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
573 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
574 "expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
575 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
576 ret = GetUrlCacheEntryInfo(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo);
577 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
578 ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
579 "expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n",
580 lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
582 ok(lpCacheEntryInfo->dwExemptDelta == 86400,
583 "expected dwExemptDelta 864000, got %d\n",
584 lpCacheEntryInfo->dwExemptDelta);
585 lpCacheEntryInfo->dwExemptDelta = 0;
586 ret = SetUrlCacheEntryInfoA(TEST_URL, lpCacheEntryInfo,
587 CACHE_ENTRY_EXEMPT_DELTA_FC);
588 ok(ret, "SetUrlCacheEntryInfo failed: %d\n", GetLastError());
589 ret = GetUrlCacheEntryInfo(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo);
590 ok(ret, "GetUrlCacheEntryInfo failed with error %d\n", GetLastError());
591 ok(!lpCacheEntryInfo->dwExemptDelta, "expected dwExemptDelta 0, got %d\n",
592 lpCacheEntryInfo->dwExemptDelta);
593 /* See whether a sticky cache entry has the flag cleared once the exempt
594 * delta is meaningless.
596 ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY),
597 "expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n",
598 lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType);
599 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
600 if (pDeleteUrlCacheEntryA)
602 ret = pDeleteUrlCacheEntryA(TEST_URL);
603 ok(ret, "DeleteUrlCacheEntryA failed with error %d\n", GetLastError());
605 check_file_not_exists(filenameA);
609 static void test_FindCloseUrlCache(void)
614 SetLastError(0xdeadbeef);
615 r = FindCloseUrlCache(NULL);
616 err = GetLastError();
617 ok(0 == r, "expected 0, got %d\n", r);
618 ok(ERROR_INVALID_HANDLE == err, "expected %d, got %d\n", ERROR_INVALID_HANDLE, err);
621 static void test_GetDiskInfoA(void)
624 DWORD error, cluster_size;
625 DWORDLONG free, total;
626 char path[MAX_PATH], *p;
628 GetSystemDirectoryA(path, MAX_PATH);
629 if ((p = strchr(path, '\\'))) *++p = 0;
631 ret = GetDiskInfoA(path, &cluster_size, &free, &total);
632 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
634 ret = GetDiskInfoA(path, &cluster_size, &free, NULL);
635 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
637 ret = GetDiskInfoA(path, &cluster_size, NULL, NULL);
638 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
640 ret = GetDiskInfoA(path, NULL, NULL, NULL);
641 ok(ret, "GetDiskInfoA failed %u\n", GetLastError());
643 SetLastError(0xdeadbeef);
644 strcpy(p, "\\non\\existing\\path");
645 ret = GetDiskInfoA(path, NULL, NULL, NULL);
646 error = GetLastError();
648 broken(ret), /* < IE7 */
649 "GetDiskInfoA succeeded\n");
650 ok(error == ERROR_PATH_NOT_FOUND ||
651 broken(error == 0xdeadbeef), /* < IE7 */
652 "got %u expected ERROR_PATH_NOT_FOUND\n", error);
654 SetLastError(0xdeadbeef);
655 ret = GetDiskInfoA(NULL, NULL, NULL, NULL);
656 error = GetLastError();
657 ok(!ret, "GetDiskInfoA succeeded\n");
658 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
664 hdll = GetModuleHandleA("wininet.dll");
666 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
667 win_skip("Too old IE (older than 6.0)\n");
671 pDeleteUrlCacheEntryA = (void*)GetProcAddress(hdll, "DeleteUrlCacheEntryA");
672 pUnlockUrlCacheEntryFileA = (void*)GetProcAddress(hdll, "UnlockUrlCacheEntryFileA");
674 test_FindCloseUrlCache();