quartz: Fix discontinuities in wave parser.
[wine] / dlls / wininet / tests / urlcache.c
1 /*
2  * URL Cache Tests
3  *
4  * Copyright 2008 Robert Shearman for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wininet.h"
28
29 #include "wine/test.h"
30
31 #define TEST_URL    "http://urlcachetest.winehq.org/index.html"
32
33 static void test_urlcacheA(void)
34 {
35     BOOL ret;
36     char filename[MAX_PATH + 1];
37     HANDLE hFile;
38     DWORD written;
39     BYTE zero_byte = 0;
40     LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
41     DWORD cbCacheEntryInfo;
42     DWORD cbCacheEntryInfoSaved;
43     static const FILETIME filetime_zero;
44     HANDLE hEnumHandle;
45     BOOL found = FALSE;
46
47     ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filename, 0);
48     ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
49
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());
53
54     ret = WriteFile(hFile, &zero_byte, sizeof(zero_byte), &written, NULL);
55     ok(ret, "WriteFile failed with error %d\n", GetLastError());
56
57     CloseHandle(hFile);
58
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());
61
62     cbCacheEntryInfo = 0;
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());
66
67     lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
68     ret = RetrieveUrlCacheEntryFile(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, 0);
69     ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
70
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);
75
76     HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
77
78     ret = UnlockUrlCacheEntryFile(TEST_URL, 0);
79     ok(ret, "UnlockUrlCacheEntryFile failed with error %d\n", GetLastError());
80
81
82     /* test Find*UrlCacheEntry functions */
83     cbCacheEntryInfo = 0;
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());
91     while (TRUE)
92     {
93         if (!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL))
94         {
95             found = TRUE;
96             break;
97         }
98         cbCacheEntryInfo = cbCacheEntryInfoSaved;
99         ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
100         if (!ret)
101         {
102             if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
103             {
104                 lpCacheEntryInfo = HeapReAlloc(GetProcessHeap(), 0, lpCacheEntryInfo, cbCacheEntryInfo);
105                 cbCacheEntryInfoSaved = cbCacheEntryInfo;
106                 ret = FindNextUrlCacheEntry(hEnumHandle, lpCacheEntryInfo, &cbCacheEntryInfo);
107             }
108         }
109         ok(ret, "FindNextUrlCacheEntry failed with error %d\n", GetLastError());
110         if (!ret)
111             break;
112     }
113     ok(found, "committed url cache entry not found during enumeration\n");
114
115     ret = FindCloseUrlCache(hEnumHandle);
116     ok(ret, "FindCloseUrlCache failed with error %d\n", GetLastError());
117
118
119     ret = DeleteUrlCacheEntry(TEST_URL);
120     ok(ret, "DeleteUrlCacheEntry failed with error %d\n", GetLastError());
121
122     ret = DeleteFile(filename);
123     todo_wine
124     ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "local file should no longer exist\n");
125 }
126
127 START_TEST(urlcache)
128 {
129     test_urlcacheA();
130 }