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
29 #include "wine/test.h"
31 #define TEST_URL "http://urlcachetest.winehq.org/index.html"
33 static void test_urlcacheA(void)
36 char filename[MAX_PATH + 1];
40 LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
41 DWORD cbCacheEntryInfo;
42 DWORD cbCacheEntryInfoSaved;
43 static const FILETIME filetime_zero;
47 ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filename, 0);
48 ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
50 hFile = CreateFileA(filename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
51 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
52 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA failed with error %d\n", GetLastError());
54 ret = WriteFile(hFile, &zero_byte, sizeof(zero_byte), &written, NULL);
55 ok(ret, "WriteFile failed with error %d\n", GetLastError());
59 ret = CommitUrlCacheEntry(TEST_URL, filename, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, "html", NULL);
60 ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
63 ret = RetrieveUrlCacheEntryFile(TEST_URL, NULL, &cbCacheEntryInfo, 0);
64 ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
65 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "RetrieveUrlCacheEntryFile should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
67 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
68 ret = RetrieveUrlCacheEntryFile(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, 0);
69 ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
71 ok(lpCacheEntryInfo->dwStructSize == sizeof(*lpCacheEntryInfo), "lpCacheEntryInfo->dwStructSize was %d\n", lpCacheEntryInfo->dwStructSize);
72 ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL), "lpCacheEntryInfo->lpszSourceUrlName should be %s instead of %s\n", TEST_URL, lpCacheEntryInfo->lpszSourceUrlName);
73 ok(!strcmp(lpCacheEntryInfo->lpszLocalFileName, filename), "lpCacheEntryInfo->lpszLocalFileName should be %s instead of %s\n", filename, lpCacheEntryInfo->lpszLocalFileName);
74 ok(!strcmp(lpCacheEntryInfo->lpszFileExtension, "html"), "lpCacheEntryInfo->lpszFileExtension should be html instead of %s\n", lpCacheEntryInfo->lpszFileExtension);
76 HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
78 ret = UnlockUrlCacheEntryFile(TEST_URL, 0);
79 ok(ret, "UnlockUrlCacheEntryFile failed with error %d\n", GetLastError());
82 /* test Find*UrlCacheEntry functions */
84 hEnumHandle = FindFirstUrlCacheEntry(NULL, NULL, &cbCacheEntryInfo);
85 ok(!hEnumHandle, "FindFirstUrlCacheEntry should have failed\n");
86 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "FindFirstUrlCacheEntry should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
87 lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo * sizeof(char));
88 cbCacheEntryInfoSaved = cbCacheEntryInfo;
89 hEnumHandle = FindFirstUrlCacheEntry(NULL, lpCacheEntryInfo, &cbCacheEntryInfo);
90 ok(hEnumHandle != NULL, "FindFirstUrlCacheEntry failed with error %d\n", GetLastError());
93 if (!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL))
98 cbCacheEntryInfo = cbCacheEntryInfoSaved;
99 ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
102 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
104 lpCacheEntryInfo = HeapReAlloc(GetProcessHeap(), 0, lpCacheEntryInfo, cbCacheEntryInfo);
105 cbCacheEntryInfoSaved = cbCacheEntryInfo;
106 ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
109 ok(ret, "FindNextUrlCacheEntry failed with error %d\n", GetLastError());
113 ok(found, "committed url cache entry not found during enumeration\n");
115 ret = FindCloseUrlCache(hEnumHandle);
116 ok(ret, "FindCloseUrlCache failed with error %d\n", GetLastError());
119 ret = DeleteUrlCacheEntry(TEST_URL);
120 ok(ret, "DeleteUrlCacheEntry failed with error %d\n", GetLastError());
122 ret = DeleteFile(filename);
124 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "local file should no longer exist\n");