2008-03-12 14:28:04 +01:00
/*
* 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"
2009-05-13 14:01:18 +02:00
# include "winineti.h"
2008-03-12 14:28:04 +01:00
# include "wine/test.h"
# define TEST_URL "http: //urlcachetest.winehq.org/index.html"
2009-09-25 12:01:35 +02:00
# define TEST_URL1 "Visited: user@http: //urlcachetest.winehq.org/index.html"
2008-03-12 14:28:04 +01:00
2008-05-22 10:38:29 +02:00
static BOOL ( WINAPI * pDeleteUrlCacheEntryA ) ( LPCSTR ) ;
static BOOL ( WINAPI * pUnlockUrlCacheEntryFileA ) ( LPCSTR , DWORD ) ;
2008-04-30 16:24:40 +02:00
static char filenameA [ MAX_PATH + 1 ] ;
2009-09-25 12:01:35 +02:00
static char filenameA1 [ MAX_PATH + 1 ] ;
2008-04-30 16:24:40 +02:00
static void check_cache_entry_infoA ( const char * returnedfrom , LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo )
{
ok ( lpCacheEntryInfo - > dwStructSize = = sizeof ( * lpCacheEntryInfo ) , " %s: dwStructSize was %d \n " , returnedfrom , lpCacheEntryInfo - > dwStructSize ) ;
ok ( ! strcmp ( lpCacheEntryInfo - > lpszSourceUrlName , TEST_URL ) , " %s: lpszSourceUrlName should be %s instead of %s \n " , returnedfrom , TEST_URL , lpCacheEntryInfo - > lpszSourceUrlName ) ;
ok ( ! strcmp ( lpCacheEntryInfo - > lpszLocalFileName , filenameA ) , " %s: lpszLocalFileName should be %s instead of %s \n " , returnedfrom , filenameA , lpCacheEntryInfo - > lpszLocalFileName ) ;
ok ( ! strcmp ( lpCacheEntryInfo - > lpszFileExtension , " html " ) , " %s: lpszFileExtension should be html instead of %s \n " , returnedfrom , lpCacheEntryInfo - > lpszFileExtension ) ;
}
static void test_find_url_cache_entriesA ( void )
2008-03-12 14:28:04 +01:00
{
BOOL ret ;
2008-03-12 14:29:47 +01:00
HANDLE hEnumHandle ;
BOOL found = FALSE ;
2008-04-30 16:24:40 +02:00
DWORD cbCacheEntryInfo ;
DWORD cbCacheEntryInfoSaved ;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo ;
2008-03-12 14:28:04 +01:00
2008-03-12 14:29:47 +01:00
cbCacheEntryInfo = 0 ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-03-12 14:29:47 +01:00
hEnumHandle = FindFirstUrlCacheEntry ( NULL , NULL , & cbCacheEntryInfo ) ;
ok ( ! hEnumHandle , " FindFirstUrlCacheEntry should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " FindFirstUrlCacheEntry should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo * sizeof ( char ) ) ;
cbCacheEntryInfoSaved = cbCacheEntryInfo ;
hEnumHandle = FindFirstUrlCacheEntry ( NULL , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
ok ( hEnumHandle ! = NULL , " FindFirstUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
while ( TRUE )
{
if ( ! strcmp ( lpCacheEntryInfo - > lpszSourceUrlName , TEST_URL ) )
{
found = TRUE ;
break ;
}
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-03-12 14:29:47 +01:00
cbCacheEntryInfo = cbCacheEntryInfoSaved ;
ret = FindNextUrlCacheEntry ( hEnumHandle , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
if ( ! ret )
{
if ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER )
{
lpCacheEntryInfo = HeapReAlloc ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo , cbCacheEntryInfo ) ;
cbCacheEntryInfoSaved = cbCacheEntryInfo ;
ret = FindNextUrlCacheEntry ( hEnumHandle , lpCacheEntryInfo , & cbCacheEntryInfo ) ;
}
}
ok ( ret , " FindNextUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
if ( ! ret )
break ;
}
ok ( found , " committed url cache entry not found during enumeration \n " ) ;
ret = FindCloseUrlCache ( hEnumHandle ) ;
ok ( ret , " FindCloseUrlCache failed with error %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
}
static void test_GetUrlCacheEntryInfoExA ( void )
{
BOOL ret ;
DWORD cbCacheEntryInfo ;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-04-30 16:24:40 +02:00
ret = GetUrlCacheEntryInfoEx ( NULL , NULL , NULL , NULL , NULL , NULL , 0 ) ;
ok ( ! ret , " GetUrlCacheEntryInfoEx with NULL URL and NULL args should have failed \n " ) ;
2009-09-25 12:01:35 +02:00
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" GetUrlCacheEntryInfoEx with NULL URL and NULL args should have set last error to ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = sizeof ( INTERNET_CACHE_ENTRY_INFO ) ;
SetLastError ( 0xdeadbeef ) ;
ret = GetUrlCacheEntryInfoEx ( " " , NULL , & cbCacheEntryInfo , NULL , NULL , NULL , 0 ) ;
ok ( ! ret , " GetUrlCacheEntryInfoEx with zero-length buffer should fail \n " ) ;
ok ( GetLastError ( ) = = ERROR_FILE_NOT_FOUND ,
" GetUrlCacheEntryInfoEx should have set last error to ERROR_FILE_NOT_FOUND instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
ret = GetUrlCacheEntryInfoEx ( TEST_URL , NULL , NULL , NULL , NULL , NULL , 0 ) ;
ok ( ret , " GetUrlCacheEntryInfoEx with NULL args failed with error %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = 0 ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-04-30 16:24:40 +02:00
ret = GetUrlCacheEntryInfoEx ( TEST_URL , NULL , & cbCacheEntryInfo , NULL , NULL , NULL , 0 ) ;
ok ( ! ret , " GetUrlCacheEntryInfoEx with zero-length buffer should fail \n " ) ;
2009-09-25 12:01:35 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
2009-09-25 12:01:35 +02:00
SetLastError ( 0xdeadbeef ) ;
ret = GetUrlCacheEntryInfoEx ( TEST_URL , lpCacheEntryInfo , & cbCacheEntryInfo , NULL , NULL , NULL , 0x200 ) ;
ok ( ! ret , " GetUrlCacheEntryInfoEx succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_FILE_NOT_FOUND ,
" GetUrlCacheEntryInfoEx should have set last error to ERROR_FILE_NOT_FOUND instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
ret = GetUrlCacheEntryInfoEx ( TEST_URL , lpCacheEntryInfo , & cbCacheEntryInfo , NULL , NULL , NULL , 0 ) ;
ok ( ret , " GetUrlCacheEntryInfoEx failed with error %d \n " , GetLastError ( ) ) ;
check_cache_entry_infoA ( " GetUrlCacheEntryInfoEx " , lpCacheEntryInfo ) ;
2008-10-03 13:57:57 +02:00
cbCacheEntryInfo = 100000 ;
2008-10-07 16:39:33 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-10-03 13:57:57 +02:00
ret = GetUrlCacheEntryInfoEx ( TEST_URL , NULL , & cbCacheEntryInfo , NULL , NULL , NULL , 0 ) ;
ok ( ! ret , " GetUrlCacheEntryInfoEx with zero-length buffer should fail \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " GetUrlCacheEntryInfoEx should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
}
2008-10-07 16:39:33 +02:00
static void test_RetrieveUrlCacheEntryA ( void )
{
BOOL ret ;
DWORD cbCacheEntryInfo ;
cbCacheEntryInfo = 0 ;
SetLastError ( 0xdeadbeef ) ;
ret = RetrieveUrlCacheEntryFile ( NULL , NULL , & cbCacheEntryInfo , 0 ) ;
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
2008-10-08 17:39:37 +02:00
if ( 0 )
{
/* Crashes on Win9x, NT4 and W2K */
SetLastError ( 0xdeadbeef ) ;
ret = RetrieveUrlCacheEntryFile ( TEST_URL , NULL , NULL , 0 ) ;
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
}
2008-10-07 16:39:33 +02:00
SetLastError ( 0xdeadbeef ) ;
cbCacheEntryInfo = 100000 ;
ret = RetrieveUrlCacheEntryFile ( NULL , NULL , & cbCacheEntryInfo , 0 ) ;
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
}
2008-04-30 16:24:40 +02:00
static void test_urlcacheA ( void )
{
BOOL ret ;
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 " , filenameA , 0 ) ;
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2009-09-25 12:01:35 +02:00
ret = CreateUrlCacheEntry ( TEST_URL , 0 , " html " , filenameA1 , 0 ) ;
ok ( ret , " CreateUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
ok ( lstrcmpiA ( filenameA , filenameA1 ) , " expected a different file name \n " ) ;
2008-04-30 16:24:40 +02:00
hFile = CreateFileA ( filenameA , 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 ) ;
2009-09-25 12:01:35 +02:00
ret = CommitUrlCacheEntry ( TEST_URL1 , NULL , filetime_zero , filetime_zero , NORMAL_CACHE_ENTRY | URLHISTORY_CACHE_ENTRY , NULL , 0 , NULL , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
ret = CommitUrlCacheEntry ( TEST_URL1 , NULL , filetime_zero , filetime_zero , NORMAL_CACHE_ENTRY | URLHISTORY_CACHE_ENTRY , NULL , 0 , NULL , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
ret = CommitUrlCacheEntry ( TEST_URL , filenameA , filetime_zero , filetime_zero , NORMAL_CACHE_ENTRY , NULL , 0 , " html " , NULL ) ;
ok ( ret , " CommitUrlCacheEntry failed with error %d \n " , GetLastError ( ) ) ;
cbCacheEntryInfo = 0 ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-04-30 16:24:40 +02:00
ret = RetrieveUrlCacheEntryFile ( TEST_URL , NULL , & cbCacheEntryInfo , 0 ) ;
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
2009-09-25 12:01:35 +02:00
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" RetrieveUrlCacheEntryFile should have set last error to ERROR_INSUFFICIENT_BUFFER instead of %d \n " , GetLastError ( ) ) ;
2008-04-30 16:24:40 +02:00
lpCacheEntryInfo = HeapAlloc ( GetProcessHeap ( ) , 0 , cbCacheEntryInfo ) ;
ret = RetrieveUrlCacheEntryFile ( TEST_URL , lpCacheEntryInfo , & cbCacheEntryInfo , 0 ) ;
ok ( ret , " RetrieveUrlCacheEntryFile failed with error %d \n " , GetLastError ( ) ) ;
check_cache_entry_infoA ( " RetrieveUrlCacheEntryFile " , lpCacheEntryInfo ) ;
HeapFree ( GetProcessHeap ( ) , 0 , lpCacheEntryInfo ) ;
2009-09-25 12:01:35 +02:00
cbCacheEntryInfo = 0 ;
SetLastError ( 0xdeadbeef ) ;
ret = RetrieveUrlCacheEntryFile ( TEST_URL1 , NULL , & cbCacheEntryInfo , 0 ) ;
ok ( ! ret , " RetrieveUrlCacheEntryFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_DATA ,
" RetrieveUrlCacheEntryFile should have set last error to ERROR_INVALID_DATA instead of %d \n " , GetLastError ( ) ) ;
2008-05-22 10:38:29 +02:00
if ( pUnlockUrlCacheEntryFileA )
{
ret = pUnlockUrlCacheEntryFileA ( TEST_URL , 0 ) ;
ok ( ret , " UnlockUrlCacheEntryFileA failed with error %d \n " , GetLastError ( ) ) ;
}
2008-04-30 16:24:40 +02:00
/* test Find*UrlCacheEntry functions */
test_find_url_cache_entriesA ( ) ;
2008-03-12 14:29:47 +01:00
2008-04-30 16:24:40 +02:00
test_GetUrlCacheEntryInfoExA ( ) ;
2008-10-07 16:39:33 +02:00
test_RetrieveUrlCacheEntryA ( ) ;
2008-03-12 14:29:47 +01:00
2008-05-22 10:38:29 +02:00
if ( pDeleteUrlCacheEntryA )
{
ret = pDeleteUrlCacheEntryA ( TEST_URL ) ;
ok ( ret , " DeleteUrlCacheEntryA failed with error %d \n " , GetLastError ( ) ) ;
2009-09-25 12:01:35 +02:00
ret = pDeleteUrlCacheEntryA ( TEST_URL1 ) ;
ok ( ret , " DeleteUrlCacheEntryA failed with error %d \n " , GetLastError ( ) ) ;
2008-05-22 10:38:29 +02:00
}
2008-03-12 14:28:04 +01:00
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-04-30 16:24:40 +02:00
ret = DeleteFile ( filenameA ) ;
2008-03-12 14:28:04 +01:00
todo_wine
ok ( ! ret & & GetLastError ( ) = = ERROR_FILE_NOT_FOUND , " local file should no longer exist \n " ) ;
}
2008-05-08 20:14:41 +02:00
static void test_FindCloseUrlCache ( void )
{
BOOL r ;
DWORD err ;
2009-09-25 12:01:10 +02:00
SetLastError ( 0xdeadbeef ) ;
2008-05-08 20:14:41 +02:00
r = FindCloseUrlCache ( NULL ) ;
err = GetLastError ( ) ;
ok ( 0 = = r , " expected 0, got %d \n " , r ) ;
ok ( ERROR_INVALID_HANDLE = = err , " expected %d, got %d \n " , ERROR_INVALID_HANDLE , err ) ;
}
2009-05-13 14:01:18 +02:00
static void test_GetDiskInfoA ( void )
{
BOOL ret ;
DWORD error , cluster_size ;
DWORDLONG free , total ;
char path [ MAX_PATH ] , * p ;
GetSystemDirectoryA ( path , MAX_PATH ) ;
if ( ( p = strchr ( path , ' \\ ' ) ) ) * + + p = 0 ;
ret = GetDiskInfoA ( path , & cluster_size , & free , & total ) ;
ok ( ret , " GetDiskInfoA failed %u \n " , GetLastError ( ) ) ;
ret = GetDiskInfoA ( path , & cluster_size , & free , NULL ) ;
ok ( ret , " GetDiskInfoA failed %u \n " , GetLastError ( ) ) ;
ret = GetDiskInfoA ( path , & cluster_size , NULL , NULL ) ;
ok ( ret , " GetDiskInfoA failed %u \n " , GetLastError ( ) ) ;
ret = GetDiskInfoA ( path , NULL , NULL , NULL ) ;
ok ( ret , " GetDiskInfoA failed %u \n " , GetLastError ( ) ) ;
SetLastError ( 0xdeadbeef ) ;
strcpy ( p , " \\ non \\ existing \\ path " ) ;
ret = GetDiskInfoA ( path , NULL , NULL , NULL ) ;
error = GetLastError ( ) ;
2009-05-13 20:50:36 +02:00
ok ( ! ret | |
broken ( ret ) , /* < IE7 */
" GetDiskInfoA succeeded \n " ) ;
ok ( error = = ERROR_PATH_NOT_FOUND | |
broken ( error = = 0xdeadbeef ) , /* < IE7 */
" got %u expected ERROR_PATH_NOT_FOUND \n " , error ) ;
2009-05-13 14:01:18 +02:00
SetLastError ( 0xdeadbeef ) ;
ret = GetDiskInfoA ( NULL , NULL , NULL , NULL ) ;
error = GetLastError ( ) ;
ok ( ! ret , " GetDiskInfoA succeeded \n " ) ;
ok ( error = = ERROR_INVALID_PARAMETER , " got %u expected ERROR_INVALID_PARAMETER \n " , error ) ;
}
2008-03-12 14:28:04 +01:00
START_TEST ( urlcache )
{
2008-05-22 10:38:29 +02:00
HMODULE hdll ;
hdll = GetModuleHandleA ( " wininet.dll " ) ;
pDeleteUrlCacheEntryA = ( void * ) GetProcAddress ( hdll , " DeleteUrlCacheEntryA " ) ;
pUnlockUrlCacheEntryFileA = ( void * ) GetProcAddress ( hdll , " UnlockUrlCacheEntryFileA " ) ;
2008-03-12 14:28:04 +01:00
test_urlcacheA ( ) ;
2008-05-08 20:14:41 +02:00
test_FindCloseUrlCache ( ) ;
2009-05-13 14:01:18 +02:00
test_GetDiskInfoA ( ) ;
2008-03-12 14:28:04 +01:00
}