Module: wine
Branch: master
Commit: 716ecc42f90f732ef968fa9e49499368ad176cf7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=716ecc42f90f732ef968fa9e4…
Author: Rob Shearman <rob(a)codeweavers.com>
Date: Wed Mar 12 16:41:35 2008 +0000
wininet: Support the lpszFileExtension "reserved" parameter being passed into CommitUrlCacheEntryA.
Store it in the URL cache entry and allow it to be retrieved by
RetrieveUrlCacheEntryFile and other functions.
---
dlls/wininet/tests/urlcache.c | 3 +-
dlls/wininet/urlcache.c | 132 ++++++++++++++++++++++++++---------------
2 files changed, 87 insertions(+), 48 deletions(-)
Diff: http://source.winehq.org/git/wine.git/?a=commitdiff;h=716ecc42f90f732ef968f…
Module: wine
Branch: master
Commit: cdd135c2f3024835192d7fef55e3a0e9e2bbfd73
URL: http://source.winehq.org/git/wine.git/?a=commit;h=cdd135c2f3024835192d7fef5…
Author: Rob Shearman <rob(a)codeweavers.com>
Date: Wed Mar 12 15:36:00 2008 +0000
wininet: Fix URLCache_LocalFileNameToPathA to return a full path, rather than just the container path.
This was caused by path_len including the nul-terminator and so the rest
of the string was being added after the nul-terminator, which is
incorrect. This is fixed by making path_len not include the nul-terminator.
Also fix a few other issues with the function, like not passing a
correct length into the second call to WideCharToMultiByte, nRequired
being calculated incorrectly and the string not always being nul-terminated.
Add a test for this function by testing the lpszLocalFileName field
obtained from RetrieveUrlCacheEntryFileA.
---
dlls/wininet/tests/urlcache.c | 1 +
dlls/wininet/urlcache.c | 8 ++++----
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/wininet/tests/urlcache.c b/dlls/wininet/tests/urlcache.c
index 572420a..3d82caf 100644
--- a/dlls/wininet/tests/urlcache.c
+++ b/dlls/wininet/tests/urlcache.c
@@ -70,6 +70,7 @@ static void test_urlcacheA(void)
ok(lpCacheEntryInfo->dwStructSize == sizeof(*lpCacheEntryInfo), "lpCacheEntryInfo->dwStructSize was %d\n", lpCacheEntryInfo->dwStructSize);
ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL), "lpCacheEntryInfo->lpszSourceUrlName should be %s instead of %s\n", TEST_URL, lpCacheEntryInfo->lpszSourceUrlName);
+ ok(!strcmp(lpCacheEntryInfo->lpszLocalFileName, filename), "lpCacheEntryInfo->lpszLocalFileName should be %s instead of %s\n", filename, lpCacheEntryInfo->lpszLocalFileName);
HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
diff --git a/dlls/wininet/urlcache.c b/dlls/wininet/urlcache.c
index 90c0d58..2f24b15 100644
--- a/dlls/wininet/urlcache.c
+++ b/dlls/wininet/urlcache.c
@@ -909,14 +909,14 @@ static BOOL URLCache_LocalFileNameToPathA(
return FALSE;
}
- path_len = WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, NULL, 0, NULL, NULL);
- file_name_len = strlen(szLocalFileName);
+ path_len = WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, NULL, 0, NULL, NULL) - 1;
+ file_name_len = strlen(szLocalFileName) + 1 /* for nul-terminator */;
dir_len = DIR_LENGTH;
- nRequired = (path_len + dir_len + 1 + file_name_len) * sizeof(WCHAR);
+ nRequired = (path_len + dir_len + 1 + file_name_len) * sizeof(char);
if (nRequired < *lpBufferSize)
{
- WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, szPath, -1, NULL, NULL);
+ WideCharToMultiByte(CP_ACP, 0, pContainer->path, -1, szPath, path_len, NULL, NULL);
memcpy(szPath+path_len, pHeader->directory_data[Directory].filename, dir_len);
szPath[path_len + dir_len] = '\\';
memcpy(szPath + path_len + dir_len + 1, szLocalFileName, file_name_len);
Module: wine
Branch: master
Commit: 99e7f7ab6e0a371f530c479b1b5b1e9158c2e652
URL: http://source.winehq.org/git/wine.git/?a=commit;h=99e7f7ab6e0a371f530c479b1…
Author: Rob Shearman <rob(a)codeweavers.com>
Date: Wed Mar 12 13:28:04 2008 +0000
wininet: Add tests for some URL cache functions.
---
dlls/wininet/tests/Makefile.in | 3 +-
dlls/wininet/tests/urlcache.c | 87 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 1 deletions(-)
diff --git a/dlls/wininet/tests/Makefile.in b/dlls/wininet/tests/Makefile.in
index 078f37c..ba8f662 100644
--- a/dlls/wininet/tests/Makefile.in
+++ b/dlls/wininet/tests/Makefile.in
@@ -10,7 +10,8 @@ CTESTS = \
generated.c \
http.c \
internet.c \
- url.c
+ url.c \
+ urlcache.c
@MAKE_TEST_RULES@
diff --git a/dlls/wininet/tests/urlcache.c b/dlls/wininet/tests/urlcache.c
new file mode 100644
index 0000000..cf1cb22
--- /dev/null
+++ b/dlls/wininet/tests/urlcache.c
@@ -0,0 +1,87 @@
+/*
+ * URL Cache Tests
+ *
+ * Copyright 2008 Robert Shearman for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wininet.h"
+
+#include "wine/test.h"
+
+#define TEST_URL "http://urlcachetest.winehq.org/index.html"
+
+static void test_urlcacheA(void)
+{
+ BOOL ret;
+ char filename[MAX_PATH + 1];
+ HANDLE hFile;
+ DWORD written;
+ BYTE zero_byte = 0;
+ LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo;
+ DWORD cbCacheEntryInfo;
+ static const FILETIME filetime_zero;
+
+ ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filename, 0);
+ ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError());
+
+ hFile = CreateFileA(filename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA failed with error %d\n", GetLastError());
+
+ ret = WriteFile(hFile, &zero_byte, sizeof(zero_byte), &written, NULL);
+ ok(ret, "WriteFile failed with error %d\n", GetLastError());
+
+ CloseHandle(hFile);
+
+ ret = CommitUrlCacheEntry(TEST_URL, filename, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, NULL, NULL);
+ ok(ret, "CommitUrlCacheEntry failed with error %d\n", GetLastError());
+
+ cbCacheEntryInfo = 0;
+ ret = RetrieveUrlCacheEntryFile(TEST_URL, NULL, &cbCacheEntryInfo, 0);
+ ok(!ret, "RetrieveUrlCacheEntryFile should have failed\n");
+ ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "RetrieveUrlCacheEntryFile should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d\n", GetLastError());
+
+ lpCacheEntryInfo = HeapAlloc(GetProcessHeap(), 0, cbCacheEntryInfo);
+ ret = RetrieveUrlCacheEntryFile(TEST_URL, lpCacheEntryInfo, &cbCacheEntryInfo, 0);
+ ok(ret, "RetrieveUrlCacheEntryFile failed with error %d\n", GetLastError());
+
+ ok(lpCacheEntryInfo->dwStructSize == sizeof(*lpCacheEntryInfo), "lpCacheEntryInfo->dwStructSize was %d\n", lpCacheEntryInfo->dwStructSize);
+ ok(!strcmp(lpCacheEntryInfo->lpszSourceUrlName, TEST_URL), "lpCacheEntryInfo->lpszSourceUrlName should be %s instead of %s\n", TEST_URL, lpCacheEntryInfo->lpszSourceUrlName);
+
+ HeapFree(GetProcessHeap(), 0, lpCacheEntryInfo);
+
+ ret = UnlockUrlCacheEntryFile(TEST_URL, 0);
+ ok(ret, "UnlockUrlCacheEntryFile failed with error %d\n", GetLastError());
+
+ ret = DeleteUrlCacheEntry(TEST_URL);
+ ok(ret, "DeleteUrlCacheEntry failed with error %d\n", GetLastError());
+
+ ret = DeleteFile(filename);
+ todo_wine
+ ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "local file should no longer exist\n");
+}
+
+START_TEST(urlcache)
+{
+ test_urlcacheA();
+}