2005-06-30 20:49:27 +00:00
/*
* Wininet - Http tests
*
* Copyright 2002 Aric Stewart
* Copyright 2004 Mike McCormack
* Copyright 2005 Hans Leidekker
*
* 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
2006-05-18 12:49:52 +00:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2005-06-30 20:49:27 +00:00
*/
2003-09-05 23:08:26 +00:00
# include <stdarg.h>
2002-06-21 23:59:49 +00:00
# include <stdio.h>
2002-10-29 21:24:35 +00:00
# include <stdlib.h>
# include "windef.h"
2002-06-21 23:59:49 +00:00
# include "winbase.h"
# include "wininet.h"
2006-05-16 14:03:45 +00:00
# include "winsock.h"
2002-06-21 23:59:49 +00:00
2002-10-29 21:24:35 +00:00
# include "wine/test.h"
2004-01-16 02:03:16 +00:00
# define TEST_URL "http: //www.winehq.org/site/about"
2005-10-31 14:06:35 +00:00
2005-11-16 11:21:41 +00:00
static HANDLE hCompleteEvent ;
2002-06-21 23:59:49 +00:00
2007-02-20 14:53:49 +00:00
static INTERNET_STATUS_CALLBACK ( WINAPI * pInternetSetStatusCallbackA ) ( HINTERNET , INTERNET_STATUS_CALLBACK ) ;
static BOOL ( WINAPI * pInternetTimeFromSystemTimeA ) ( CONST SYSTEMTIME * , DWORD , LPSTR , DWORD ) ;
static BOOL ( WINAPI * pInternetTimeFromSystemTimeW ) ( CONST SYSTEMTIME * , DWORD , LPWSTR , DWORD ) ;
static BOOL ( WINAPI * pInternetTimeToSystemTimeA ) ( LPCSTR , SYSTEMTIME * , DWORD ) ;
static BOOL ( WINAPI * pInternetTimeToSystemTimeW ) ( LPCWSTR , SYSTEMTIME * , DWORD ) ;
2005-06-13 19:05:42 +00:00
static VOID WINAPI callback (
2002-06-21 23:59:49 +00:00
HINTERNET hInternet ,
2006-10-28 12:14:52 +00:00
DWORD_PTR dwContext ,
2002-06-21 23:59:49 +00:00
DWORD dwInternetStatus ,
LPVOID lpvStatusInformation ,
DWORD dwStatusInformationLength
)
{
switch ( dwInternetStatus )
{
case INTERNET_STATUS_RESOLVING_NAME :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \" %s \" %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 12:06:47 +00:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_NAME_RESOLVED :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \" %s \" %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 12:06:47 +00:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_CONNECTING_TO_SERVER :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \" %s \" %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 12:06:47 +00:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_CONNECTED_TO_SERVER :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \" %s \" %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 12:06:47 +00:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_SENDING_REQUEST :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_REQUEST_SENT :
2005-11-22 11:59:16 +00:00
ok ( dwStatusInformationLength = = sizeof ( DWORD ) ,
2006-10-05 11:19:00 +00:00
" info length should be sizeof(DWORD) instead of %d \n " ,
2005-11-22 11:59:16 +00:00
dwStatusInformationLength ) ;
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( DWORD * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_RECEIVING_RESPONSE :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_RESPONSE_RECEIVED :
2005-11-22 11:59:16 +00:00
ok ( dwStatusInformationLength = = sizeof ( DWORD ) ,
2006-10-05 11:19:00 +00:00
" info length should be sizeof(DWORD) instead of %d \n " ,
2005-11-22 11:59:16 +00:00
dwStatusInformationLength ) ;
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( DWORD * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_CTL_RESPONSE_RECEIVED :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_PREFETCH :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_CLOSING_CONNECTION :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_CONNECTION_CLOSED :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_HANDLE_CREATED :
2005-11-22 11:59:16 +00:00
ok ( dwStatusInformationLength = = sizeof ( HINTERNET ) ,
2006-10-05 11:19:00 +00:00
" info length should be sizeof(HINTERNET) instead of %d \n " ,
2005-11-22 11:59:16 +00:00
dwStatusInformationLength ) ;
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( HINTERNET * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_HANDLE_CLOSING :
2005-11-22 11:59:16 +00:00
ok ( dwStatusInformationLength = = sizeof ( HINTERNET ) ,
2006-10-05 11:19:00 +00:00
" info length should be sizeof(HINTERNET) instead of %d \n " ,
2005-11-22 11:59:16 +00:00
dwStatusInformationLength ) ;
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( HINTERNET * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_REQUEST_COMPLETE :
2005-11-16 11:21:41 +00:00
{
INTERNET_ASYNC_RESULT * iar = ( INTERNET_ASYNC_RESULT * ) lpvStatusInformation ;
2005-11-22 11:59:16 +00:00
ok ( dwStatusInformationLength = = sizeof ( INTERNET_ASYNC_RESULT ) ,
2006-10-05 11:19:00 +00:00
" info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d \n " ,
2005-11-22 11:59:16 +00:00
dwStatusInformationLength ) ;
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%d,%d} %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
iar - > dwResult , iar - > dwError , dwStatusInformationLength ) ;
SetEvent ( hCompleteEvent ) ;
2002-06-21 23:59:49 +00:00
break ;
2005-11-16 11:21:41 +00:00
}
2002-06-21 23:59:49 +00:00
case INTERNET_STATUS_REDIRECT :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \" %s \" %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 12:06:47 +00:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-21 23:59:49 +00:00
break ;
case INTERNET_STATUS_INTERMEDIATE_RESPONSE :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
break ;
2005-11-16 11:21:41 +00:00
default :
2006-10-28 12:14:52 +00:00
trace ( " %04x:Callback %p 0x%lx %d %p %d \n " ,
2005-11-16 11:21:41 +00:00
GetCurrentThreadId ( ) , hInternet , dwContext , dwInternetStatus ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-21 23:59:49 +00:00
}
}
2005-11-16 11:21:41 +00:00
static void InternetReadFile_test ( int flags )
2002-06-21 23:59:49 +00:00
{
DWORD rc ;
CHAR buffer [ 4000 ] ;
DWORD length ;
DWORD out ;
2002-12-06 23:21:35 +00:00
const char * types [ 2 ] = { " * " , NULL } ;
2002-12-17 21:03:33 +00:00
HINTERNET hi , hic = 0 , hor = 0 ;
2002-06-21 23:59:49 +00:00
2005-11-16 11:21:41 +00:00
hCompleteEvent = CreateEvent ( NULL , FALSE , FALSE , NULL ) ;
trace ( " Starting InternetReadFile test with flags 0x%x \n " , flags ) ;
2002-06-21 23:59:49 +00:00
trace ( " InternetOpenA <-- \n " ) ;
2005-11-16 11:21:41 +00:00
hi = InternetOpenA ( " " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , flags ) ;
2007-01-06 18:25:07 +00:00
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
2002-06-21 23:59:49 +00:00
trace ( " InternetOpenA --> \n " ) ;
2002-10-09 18:12:20 +00:00
if ( hi = = 0x0 ) goto abort ;
2007-02-20 14:53:49 +00:00
pInternetSetStatusCallbackA ( hi , & callback ) ;
2002-06-21 23:59:49 +00:00
trace ( " InternetConnectA <-- \n " ) ;
2005-11-16 11:21:41 +00:00
hic = InternetConnectA ( hi , " www.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
2007-01-06 18:25:07 +00:00
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
2002-06-21 23:59:49 +00:00
trace ( " InternetConnectA --> \n " ) ;
2002-10-09 18:12:20 +00:00
if ( hic = = 0x0 ) goto abort ;
2002-06-21 23:59:49 +00:00
trace ( " HttpOpenRequestA <-- \n " ) ;
2005-11-16 11:21:41 +00:00
hor = HttpOpenRequestA ( hic , " GET " , " /about/ " , NULL , NULL , types ,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE ,
0xdeadbead ) ;
if ( hor = = 0x0 & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) {
2002-10-09 18:12:20 +00:00
/*
* If the internet name can ' t be resolved we are probably behind
* a firewall or in some other way not directly connected to the
* Internet . Not enough reason to fail the test . Just ignore and
* abort .
*/
} else {
2007-01-06 18:25:07 +00:00
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %u \n " , GetLastError ( ) ) ;
2002-10-09 18:12:20 +00:00
}
2002-06-21 23:59:49 +00:00
trace ( " HttpOpenRequestA --> \n " ) ;
2002-10-09 18:12:20 +00:00
if ( hor = = 0x0 ) goto abort ;
2002-06-21 23:59:49 +00:00
trace ( " HttpSendRequestA --> \n " ) ;
2005-11-16 11:21:41 +00:00
SetLastError ( 0xdeadbeef ) ;
rc = HttpSendRequestA ( hor , " " , - 1 , NULL , 0 ) ;
if ( flags & INTERNET_FLAG_ASYNC )
ok ( ( ( rc = = 0 ) & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
2002-06-21 23:59:49 +00:00
else
2005-11-16 11:21:41 +00:00
ok ( ( rc ! = 0 ) | | GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ,
2007-01-06 18:25:07 +00:00
" Synchronous HttpSendRequest returning 0, error %u \n " , GetLastError ( ) ) ;
2002-06-21 23:59:49 +00:00
trace ( " HttpSendRequestA <-- \n " ) ;
2005-11-16 11:21:41 +00:00
if ( flags & INTERNET_FLAG_ASYNC )
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2002-06-21 23:59:49 +00:00
length = 4 ;
2005-11-16 11:21:41 +00:00
rc = InternetQueryOptionA ( hor , INTERNET_OPTION_REQUEST_FLAGS , & out , & length ) ;
2006-10-05 11:19:00 +00:00
trace ( " Option 0x17 -> %i %i \n " , rc , out ) ;
2002-06-21 23:59:49 +00:00
length = 100 ;
2005-11-16 11:21:41 +00:00
rc = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
2006-10-05 11:19:00 +00:00
trace ( " Option 0x22 -> %i %s \n " , rc , buffer ) ;
2002-06-21 23:59:49 +00:00
length = 4000 ;
2005-11-16 11:21:41 +00:00
rc = HttpQueryInfoA ( hor , HTTP_QUERY_RAW_HEADERS , buffer , & length , 0x0 ) ;
2002-06-21 23:59:49 +00:00
buffer [ length ] = 0 ;
2006-10-05 11:19:00 +00:00
trace ( " Option 0x16 -> %i %s \n " , rc , buffer ) ;
2002-06-21 23:59:49 +00:00
length = 4000 ;
2005-11-16 11:21:41 +00:00
rc = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
2002-06-21 23:59:49 +00:00
buffer [ length ] = 0 ;
2006-10-05 11:19:00 +00:00
trace ( " Option 0x22 -> %i %s \n " , rc , buffer ) ;
2002-06-21 23:59:49 +00:00
length = 16 ;
2005-11-16 11:21:41 +00:00
rc = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_LENGTH , & buffer , & length , 0x0 ) ;
2007-01-06 18:25:07 +00:00
trace ( " Option 0x5 -> %i %s (%u) \n " , rc , buffer , GetLastError ( ) ) ;
2002-06-21 23:59:49 +00:00
length = 100 ;
2005-11-16 11:21:41 +00:00
rc = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_TYPE , buffer , & length , 0x0 ) ;
2002-06-21 23:59:49 +00:00
buffer [ length ] = 0 ;
2006-10-05 11:19:00 +00:00
trace ( " Option 0x1 -> %i %s \n " , rc , buffer ) ;
2002-06-21 23:59:49 +00:00
2005-11-16 11:21:41 +00:00
SetLastError ( 0xdeadbeef ) ;
rc = InternetReadFile ( NULL , buffer , 100 , & length ) ;
ok ( ! rc , " InternetReadFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_HANDLE ,
2007-01-06 18:25:07 +00:00
" InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u \n " ,
2005-11-16 11:21:41 +00:00
GetLastError ( ) ) ;
2002-06-21 23:59:49 +00:00
length = 100 ;
2004-01-23 22:44:26 +00:00
trace ( " Entering Query loop \n " ) ;
2002-06-21 23:59:49 +00:00
while ( length )
{
rc = InternetQueryDataAvailable ( hor , & length , 0x0 , 0x0 ) ;
2004-10-28 21:01:04 +00:00
ok ( ! ( rc = = 0 & & length ! = 0 ) , " InternetQueryDataAvailable failed \n " ) ;
2002-06-21 23:59:49 +00:00
if ( length )
{
char * buffer ;
2005-03-22 18:26:06 +00:00
buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , length + 1 ) ;
2002-06-21 23:59:49 +00:00
rc = InternetReadFile ( hor , buffer , length , & length ) ;
buffer [ length ] = 0 ;
2006-10-05 11:19:00 +00:00
trace ( " ReadFile -> %i %i \n " , rc , length ) ;
2002-06-21 23:59:49 +00:00
HeapFree ( GetProcessHeap ( ) , 0 , buffer ) ;
}
}
2002-10-09 18:12:20 +00:00
abort :
if ( hor ! = 0x0 ) {
2005-11-16 11:21:41 +00:00
SetLastError ( 0xdeadbeef ) ;
2002-10-09 18:12:20 +00:00
rc = InternetCloseHandle ( hor ) ;
2004-01-23 22:44:26 +00:00
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by HttpOpenRequestA failed \n " ) ;
2005-11-16 11:21:41 +00:00
SetLastError ( 0xdeadbeef ) ;
2004-09-23 22:53:04 +00:00
rc = InternetCloseHandle ( hor ) ;
ok ( ( rc = = 0 ) , " Double close of handle opened by HttpOpenRequestA succeeded \n " ) ;
2005-11-16 11:21:41 +00:00
ok ( GetLastError ( ) = = ERROR_INVALID_HANDLE ,
2007-01-06 18:25:07 +00:00
" Double close of handle should have set ERROR_INVALID_HANDLE instead of %u \n " ,
2005-11-16 11:21:41 +00:00
GetLastError ( ) ) ;
2002-10-09 18:12:20 +00:00
}
2002-12-17 21:03:33 +00:00
if ( hic ! = 0x0 ) {
2002-10-09 18:12:20 +00:00
rc = InternetCloseHandle ( hic ) ;
2004-01-23 22:44:26 +00:00
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetConnectA failed \n " ) ;
2002-10-09 18:12:20 +00:00
}
if ( hi ! = 0x0 ) {
rc = InternetCloseHandle ( hi ) ;
2004-01-23 22:44:26 +00:00
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetOpenA failed \n " ) ;
2005-11-16 11:21:41 +00:00
if ( flags & INTERNET_FLAG_ASYNC )
Sleep ( 100 ) ;
}
CloseHandle ( hCompleteEvent ) ;
}
static void InternetReadFileExA_test ( int flags )
{
DWORD rc ;
DWORD length ;
const char * types [ 2 ] = { " * " , NULL } ;
HINTERNET hi , hic = 0 , hor = 0 ;
INTERNET_BUFFERS inetbuffers ;
hCompleteEvent = CreateEvent ( NULL , FALSE , FALSE , NULL ) ;
trace ( " Starting InternetReadFileExA test with flags 0x%x \n " , flags ) ;
trace ( " InternetOpenA <-- \n " ) ;
hi = InternetOpenA ( " " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , flags ) ;
2007-01-06 18:25:07 +00:00
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 11:21:41 +00:00
trace ( " InternetOpenA --> \n " ) ;
if ( hi = = 0x0 ) goto abort ;
2007-02-20 14:53:49 +00:00
pInternetSetStatusCallbackA ( hi , & callback ) ;
2005-11-16 11:21:41 +00:00
trace ( " InternetConnectA <-- \n " ) ;
hic = InternetConnectA ( hi , " www.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
2007-01-06 18:25:07 +00:00
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 11:21:41 +00:00
trace ( " InternetConnectA --> \n " ) ;
if ( hic = = 0x0 ) goto abort ;
trace ( " HttpOpenRequestA <-- \n " ) ;
hor = HttpOpenRequestA ( hic , " GET " , " /about/ " , NULL , NULL , types ,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE ,
0xdeadbead ) ;
if ( hor = = 0x0 & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) {
/*
* If the internet name can ' t be resolved we are probably behind
* a firewall or in some other way not directly connected to the
* Internet . Not enough reason to fail the test . Just ignore and
* abort .
*/
} else {
2007-01-06 18:25:07 +00:00
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 11:21:41 +00:00
}
trace ( " HttpOpenRequestA --> \n " ) ;
if ( hor = = 0x0 ) goto abort ;
trace ( " HttpSendRequestA --> \n " ) ;
SetLastError ( 0xdeadbeef ) ;
rc = HttpSendRequestA ( hor , " " , - 1 , NULL , 0 ) ;
if ( flags & INTERNET_FLAG_ASYNC )
ok ( ( ( rc = = 0 ) & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
else
ok ( ( rc ! = 0 ) | | GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ,
2007-01-06 18:25:07 +00:00
" Synchronous HttpSendRequest returning 0, error %u \n " , GetLastError ( ) ) ;
2005-11-16 11:21:41 +00:00
trace ( " HttpSendRequestA <-- \n " ) ;
if ( ! rc & & ( GetLastError ( ) = = ERROR_IO_PENDING ) )
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
/* tests invalid dwStructSize */
inetbuffers . dwStructSize = sizeof ( INTERNET_BUFFERS ) + 1 ;
inetbuffers . lpcszHeader = NULL ;
inetbuffers . dwHeadersLength = 0 ;
inetbuffers . dwBufferLength = 10 ;
inetbuffers . lpvBuffer = HeapAlloc ( GetProcessHeap ( ) , 0 , 10 ) ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
rc = InternetReadFileEx ( hor , & inetbuffers , 0 , 0xdeadcafe ) ;
ok ( ! rc & & ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ) ,
2007-01-06 18:25:07 +00:00
" InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u \n " ,
2005-11-16 11:21:41 +00:00
rc ? " TRUE " : " FALSE " , GetLastError ( ) ) ;
HeapFree ( GetProcessHeap ( ) , 0 , inetbuffers . lpvBuffer ) ;
/* tests to see whether lpcszHeader is used - it isn't */
inetbuffers . dwStructSize = sizeof ( INTERNET_BUFFERS ) ;
inetbuffers . lpcszHeader = ( LPCTSTR ) 0xdeadbeef ;
inetbuffers . dwHeadersLength = 255 ;
inetbuffers . dwBufferLength = 0 ;
inetbuffers . lpvBuffer = NULL ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
rc = InternetReadFileEx ( hor , & inetbuffers , 0 , 0xdeadcafe ) ;
2007-01-06 18:25:07 +00:00
ok ( rc , " InternetReadFileEx failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 11:21:41 +00:00
rc = InternetReadFileEx ( NULL , & inetbuffers , 0 , 0xdeadcafe ) ;
ok ( ! rc & & ( GetLastError ( ) = = ERROR_INVALID_HANDLE ) ,
2007-01-06 18:25:07 +00:00
" InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u \n " ,
2005-11-16 11:21:41 +00:00
rc ? " TRUE " : " FALSE " , GetLastError ( ) ) ;
length = 0 ;
trace ( " Entering Query loop \n " ) ;
while ( TRUE )
{
inetbuffers . dwStructSize = sizeof ( INTERNET_BUFFERS ) ;
inetbuffers . dwBufferLength = 1024 ;
inetbuffers . lpvBuffer = HeapAlloc ( GetProcessHeap ( ) , 0 , inetbuffers . dwBufferLength + 1 ) ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
rc = InternetReadFileExA ( hor , & inetbuffers , IRF_ASYNC | IRF_USE_CONTEXT , 0xcafebabe ) ;
if ( ! rc )
{
if ( GetLastError ( ) = = ERROR_IO_PENDING )
{
trace ( " InternetReadFileEx -> PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
}
else
{
2007-01-06 18:25:07 +00:00
trace ( " InternetReadFileEx -> FAILED %u \n " , GetLastError ( ) ) ;
2005-11-16 11:21:41 +00:00
break ;
}
}
else
trace ( " InternetReadFileEx -> SUCCEEDED \n " ) ;
2006-10-05 11:19:00 +00:00
trace ( " read %i bytes \n " , inetbuffers . dwBufferLength ) ;
2005-11-16 11:21:41 +00:00
( ( char * ) inetbuffers . lpvBuffer ) [ inetbuffers . dwBufferLength ] = ' \0 ' ;
ok ( inetbuffers . dwOffsetHigh = = 1234 & & inetbuffers . dwOffsetLow = = 5678 ,
2006-10-05 11:19:00 +00:00
" InternetReadFileEx sets offsets to 0x%x%08x \n " ,
2005-11-16 11:21:41 +00:00
inetbuffers . dwOffsetHigh , inetbuffers . dwOffsetLow ) ;
HeapFree ( GetProcessHeap ( ) , 0 , inetbuffers . lpvBuffer ) ;
if ( ! inetbuffers . dwBufferLength )
break ;
length + = inetbuffers . dwBufferLength ;
}
2007-05-28 10:13:36 +00:00
ok ( length > 0 , " failed to read any of the document \n " ) ;
2006-10-05 11:19:00 +00:00
trace ( " Finished. Read %d bytes \n " , length ) ;
2005-11-16 11:21:41 +00:00
abort :
if ( hor ) {
rc = InternetCloseHandle ( hor ) ;
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by HttpOpenRequestA failed \n " ) ;
rc = InternetCloseHandle ( hor ) ;
ok ( ( rc = = 0 ) , " Double close of handle opened by HttpOpenRequestA succeeded \n " ) ;
}
if ( hic ) {
rc = InternetCloseHandle ( hic ) ;
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetConnectA failed \n " ) ;
}
if ( hi ) {
rc = InternetCloseHandle ( hi ) ;
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetOpenA failed \n " ) ;
if ( flags & INTERNET_FLAG_ASYNC )
2002-10-09 18:12:20 +00:00
Sleep ( 100 ) ;
}
2005-11-16 11:21:41 +00:00
CloseHandle ( hCompleteEvent ) ;
2002-06-21 23:59:49 +00:00
}
2005-06-13 19:05:42 +00:00
static void InternetOpenUrlA_test ( void )
2003-02-25 03:57:59 +00:00
{
HINTERNET myhinternet , myhttp ;
char buffer [ 0x400 ] ;
DWORD size , readbytes , totalbytes = 0 ;
2004-12-27 17:26:37 +00:00
BOOL ret ;
2003-02-25 03:57:59 +00:00
myhinternet = InternetOpen ( " Winetest " , 0 , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE ) ;
2007-01-06 18:25:07 +00:00
ok ( ( myhinternet ! = 0 ) , " InternetOpen failed, error %u \n " , GetLastError ( ) ) ;
2003-02-25 03:57:59 +00:00
size = 0x400 ;
2004-12-27 17:26:37 +00:00
ret = InternetCanonicalizeUrl ( TEST_URL , buffer , & size , ICU_BROWSER_MODE ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetCanonicalizeUrl failed, error %u \n " , GetLastError ( ) ) ;
2006-03-14 17:49:19 +00:00
2003-09-25 20:29:40 +00:00
SetLastError ( 0 ) ;
2004-01-16 02:03:16 +00:00
myhttp = InternetOpenUrl ( myhinternet , TEST_URL , 0 , 0 ,
2003-02-25 03:57:59 +00:00
INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_TRANSFER_BINARY , 0 ) ;
2003-09-25 20:29:40 +00:00
if ( GetLastError ( ) = = 12007 )
return ; /* WinXP returns this when not connected to the net */
2007-01-06 18:25:07 +00:00
ok ( ( myhttp ! = 0 ) , " InternetOpenUrl failed, error %u \n " , GetLastError ( ) ) ;
2004-12-27 17:26:37 +00:00
ret = InternetReadFile ( myhttp , buffer , 0x400 , & readbytes ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetReadFile failed, error %u \n " , GetLastError ( ) ) ;
2003-02-25 03:57:59 +00:00
totalbytes + = readbytes ;
while ( readbytes & & InternetReadFile ( myhttp , buffer , 0x400 , & readbytes ) )
totalbytes + = readbytes ;
2006-10-05 11:19:00 +00:00
trace ( " read 0x%08x bytes \n " , totalbytes ) ;
2003-02-25 03:57:59 +00:00
}
2004-08-06 18:58:04 +00:00
2005-06-13 19:05:42 +00:00
static void InternetTimeFromSystemTimeA_test ( void )
2005-01-18 11:43:40 +00:00
{
BOOL ret ;
static const SYSTEMTIME time = { 2005 , 1 , 5 , 7 , 12 , 6 , 35 , 0 } ;
char string [ INTERNET_RFC1123_BUFSIZE ] ;
static const char expect [ ] = " Fri, 07 Jan 2005 12:06:35 GMT " ;
2007-02-20 14:53:49 +00:00
ret = pInternetTimeFromSystemTimeA ( & time , INTERNET_RFC1123_FORMAT , string , sizeof ( string ) ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetTimeFromSystemTimeA failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
ok ( ! memcmp ( string , expect , sizeof ( expect ) ) ,
2007-01-06 18:25:07 +00:00
" InternetTimeFromSystemTimeA failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
}
2005-06-13 19:05:42 +00:00
static void InternetTimeFromSystemTimeW_test ( void )
2005-01-18 11:43:40 +00:00
{
BOOL ret ;
static const SYSTEMTIME time = { 2005 , 1 , 5 , 7 , 12 , 6 , 35 , 0 } ;
WCHAR string [ INTERNET_RFC1123_BUFSIZE + 1 ] ;
static const WCHAR expect [ ] = { ' F ' , ' r ' , ' i ' , ' , ' , ' ' , ' 0 ' , ' 7 ' , ' ' , ' J ' , ' a ' , ' n ' , ' ' , ' 2 ' , ' 0 ' , ' 0 ' , ' 5 ' , ' ' ,
' 1 ' , ' 2 ' , ' : ' , ' 0 ' , ' 6 ' , ' : ' , ' 3 ' , ' 5 ' , ' ' , ' G ' , ' M ' , ' T ' , 0 } ;
2007-02-20 14:53:49 +00:00
ret = pInternetTimeFromSystemTimeW ( & time , INTERNET_RFC1123_FORMAT , string , sizeof ( string ) ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetTimeFromSystemTimeW failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
ok ( ! memcmp ( string , expect , sizeof ( expect ) ) ,
2007-01-06 18:25:07 +00:00
" InternetTimeFromSystemTimeW failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
}
2005-06-13 19:05:42 +00:00
static void InternetTimeToSystemTimeA_test ( void )
2005-01-18 11:43:40 +00:00
{
BOOL ret ;
SYSTEMTIME time ;
static const SYSTEMTIME expect = { 2005 , 1 , 5 , 7 , 12 , 6 , 35 , 0 } ;
static const char string [ ] = " Fri, 07 Jan 2005 12:06:35 GMT " ;
static const char string2 [ ] = " fri 7 jan 2005 12 06 35 " ;
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeA ( string , & time , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetTimeToSystemTimeA failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
ok ( ! memcmp ( & time , & expect , sizeof ( expect ) ) ,
2007-01-06 18:25:07 +00:00
" InternetTimeToSystemTimeA failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeA ( string2 , & time , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetTimeToSystemTimeA failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
ok ( ! memcmp ( & time , & expect , sizeof ( expect ) ) ,
2007-01-06 18:25:07 +00:00
" InternetTimeToSystemTimeA failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
}
2005-06-13 19:05:42 +00:00
static void InternetTimeToSystemTimeW_test ( void )
2005-01-18 11:43:40 +00:00
{
BOOL ret ;
SYSTEMTIME time ;
static const SYSTEMTIME expect = { 2005 , 1 , 5 , 7 , 12 , 6 , 35 , 0 } ;
static const WCHAR string [ ] = { ' F ' , ' r ' , ' i ' , ' , ' , ' ' , ' 0 ' , ' 7 ' , ' ' , ' J ' , ' a ' , ' n ' , ' ' , ' 2 ' , ' 0 ' , ' 0 ' , ' 5 ' , ' ' ,
' 1 ' , ' 2 ' , ' : ' , ' 0 ' , ' 6 ' , ' : ' , ' 3 ' , ' 5 ' , ' ' , ' G ' , ' M ' , ' T ' , 0 } ;
static const WCHAR string2 [ ] = { ' ' , ' f ' , ' r ' , ' i ' , ' ' , ' 7 ' , ' ' , ' j ' , ' a ' , ' n ' , ' ' , ' 2 ' , ' 0 ' , ' 0 ' , ' 5 ' , ' ' ,
' 1 ' , ' 2 ' , ' ' , ' 0 ' , ' 6 ' , ' ' , ' 3 ' , ' 5 ' , 0 } ;
static const WCHAR string3 [ ] = { ' F ' , ' r ' , 0 } ;
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeW ( NULL , NULL , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ! ret , " InternetTimeToSystemTimeW succeeded (%u) \n " , GetLastError ( ) ) ;
2005-03-17 18:55:41 +00:00
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeW ( NULL , & time , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ! ret , " InternetTimeToSystemTimeW succeeded (%u) \n " , GetLastError ( ) ) ;
2005-03-17 18:55:41 +00:00
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeW ( string , NULL , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ! ret , " InternetTimeToSystemTimeW succeeded (%u) \n " , GetLastError ( ) ) ;
2005-03-17 18:55:41 +00:00
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeW ( string , & time , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetTimeToSystemTimeW failed (%u) \n " , GetLastError ( ) ) ;
2005-03-17 18:55:41 +00:00
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeW ( string , & time , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetTimeToSystemTimeW failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
ok ( ! memcmp ( & time , & expect , sizeof ( expect ) ) ,
2007-01-06 18:25:07 +00:00
" InternetTimeToSystemTimeW failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeW ( string2 , & time , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetTimeToSystemTimeW failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
ok ( ! memcmp ( & time , & expect , sizeof ( expect ) ) ,
2007-01-06 18:25:07 +00:00
" InternetTimeToSystemTimeW failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
2007-02-20 14:53:49 +00:00
ret = pInternetTimeToSystemTimeW ( string3 , & time , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " InternetTimeToSystemTimeW failed (%u) \n " , GetLastError ( ) ) ;
2005-01-18 11:43:40 +00:00
}
2005-11-21 15:17:55 +00:00
static void HttpSendRequestEx_test ( void )
{
HINTERNET hSession ;
HINTERNET hConnect ;
HINTERNET hRequest ;
INTERNET_BUFFERS BufferIn ;
DWORD dwBytesWritten ;
DWORD dwBytesRead ;
CHAR szBuffer [ 256 ] ;
int i ;
2005-11-30 11:31:38 +00:00
BOOL ret ;
2005-11-21 15:17:55 +00:00
2006-10-05 18:44:30 +00:00
static char szPostData [ ] = " mode=Test " ;
2005-11-21 15:17:55 +00:00
static const char szContentType [ ] = " Content-Type: application/x-www-form-urlencoded " ;
2006-10-05 18:44:30 +00:00
2005-11-21 15:17:55 +00:00
hSession = InternetOpen ( " Wine Regression Test " ,
INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( hSession ! = NULL , " Unable to open Internet session \n " ) ;
hConnect = InternetConnect ( hSession , " crossover.codeweavers.com " ,
INTERNET_DEFAULT_HTTP_PORT , NULL , NULL , INTERNET_SERVICE_HTTP , 0 ,
0 ) ;
ok ( hConnect ! = NULL , " Unable to connect to http://crossover.codeweavers.com \n " ) ;
hRequest = HttpOpenRequest ( hConnect , " POST " , " /posttest.php " ,
NULL , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
2006-09-21 10:44:56 +00:00
if ( ! hRequest & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
trace ( " Network unreachable, skipping test \n " ) ;
goto done ;
}
2007-01-06 18:25:07 +00:00
ok ( hRequest ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
2005-11-21 15:17:55 +00:00
BufferIn . dwStructSize = sizeof ( INTERNET_BUFFERS ) ;
2005-11-29 10:42:23 +00:00
BufferIn . Next = ( LPINTERNET_BUFFERS ) 0xdeadcab ;
2005-11-21 15:17:55 +00:00
BufferIn . lpcszHeader = szContentType ;
BufferIn . dwHeadersLength = sizeof ( szContentType ) ;
BufferIn . dwHeadersTotal = sizeof ( szContentType ) ;
2006-10-05 18:44:30 +00:00
BufferIn . lpvBuffer = szPostData ;
2005-11-30 11:31:38 +00:00
BufferIn . dwBufferLength = 3 ;
2005-11-21 15:17:55 +00:00
BufferIn . dwBufferTotal = sizeof ( szPostData ) - 1 ;
BufferIn . dwOffsetLow = 0 ;
BufferIn . dwOffsetHigh = 0 ;
2005-11-30 11:31:38 +00:00
ret = HttpSendRequestEx ( hRequest , & BufferIn , NULL , 0 , 0 ) ;
2007-01-06 18:25:07 +00:00
ok ( ret , " HttpSendRequestEx Failed with error %u \n " , GetLastError ( ) ) ;
2005-11-21 15:17:55 +00:00
2005-11-30 11:31:38 +00:00
for ( i = 3 ; szPostData [ i ] ; i + + )
2005-11-21 15:17:55 +00:00
ok ( InternetWriteFile ( hRequest , & szPostData [ i ] , 1 , & dwBytesWritten ) ,
" InternetWriteFile failed \n " ) ;
ok ( HttpEndRequest ( hRequest , NULL , 0 , 0 ) , " HttpEndRequest Failed \n " ) ;
ok ( InternetReadFile ( hRequest , szBuffer , 255 , & dwBytesRead ) ,
2005-11-23 19:14:43 +00:00
" Unable to read response \n " ) ;
2005-11-21 15:17:55 +00:00
szBuffer [ dwBytesRead ] = 0 ;
2006-10-05 11:19:00 +00:00
ok ( dwBytesRead = = 13 , " Read %u bytes instead of 13 \n " , dwBytesRead ) ;
2005-11-21 15:17:55 +00:00
ok ( strncmp ( szBuffer , " mode => Test \n " , dwBytesRead ) = = 0 , " Got string %s \n " , szBuffer ) ;
ok ( InternetCloseHandle ( hRequest ) , " Close request handle failed \n " ) ;
2006-09-21 10:44:56 +00:00
done :
2005-11-21 15:17:55 +00:00
ok ( InternetCloseHandle ( hConnect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( hSession ) , " Close session handle failed \n " ) ;
}
2005-11-22 14:53:30 +00:00
2007-02-12 14:19:17 +00:00
static void InternetOpenRequest_test ( void )
{
HINTERNET session , connect , request ;
static const char * types [ ] = { " * " , " " , NULL } ;
static const WCHAR slash [ ] = { ' / ' , 0 } , any [ ] = { ' * ' , 0 } , empty [ ] = { 0 } ;
static const WCHAR * typesW [ ] = { any , empty , NULL } ;
BOOL ret ;
session = InternetOpenA ( " Wine Regression Test " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( session ! = NULL , " Unable to open Internet session \n " ) ;
connect = InternetConnectA ( session , " winehq.org " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect ! = NULL , " Unable to connect to http://winehq.org \n " ) ;
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , types , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
if ( ! request & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
trace ( " Network unreachable, skipping test \n " ) ;
goto done ;
}
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
ret = HttpSendRequest ( request , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
request = HttpOpenRequestW ( connect , NULL , slash , NULL , NULL , typesW , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
ret = HttpSendRequest ( request , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
done :
ok ( InternetCloseHandle ( connect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( session ) , " Close session handle failed \n " ) ;
}
2005-11-22 14:53:30 +00:00
static void HttpHeaders_test ( void )
{
HINTERNET hSession ;
HINTERNET hConnect ;
HINTERNET hRequest ;
2005-12-13 16:07:41 +00:00
CHAR buffer [ 256 ] ;
DWORD len = 256 ;
DWORD index = 0 ;
2005-11-22 14:53:30 +00:00
hSession = InternetOpen ( " Wine Regression Test " ,
INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( hSession ! = NULL , " Unable to open Internet session \n " ) ;
hConnect = InternetConnect ( hSession , " crossover.codeweavers.com " ,
INTERNET_DEFAULT_HTTP_PORT , NULL , NULL , INTERNET_SERVICE_HTTP , 0 ,
0 ) ;
ok ( hConnect ! = NULL , " Unable to connect to http://crossover.codeweavers.com \n " ) ;
hRequest = HttpOpenRequest ( hConnect , " POST " , " /posttest.php " ,
NULL , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
2006-09-21 10:44:56 +00:00
if ( ! hRequest & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
trace ( " Network unreachable, skipping test \n " ) ;
goto done ;
}
2005-11-22 14:53:30 +00:00
ok ( hRequest ! = NULL , " Failed to open request handle \n " ) ;
2005-12-13 16:07:41 +00:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) = = 0 , " Warning hearder reported as Existing \n " ) ;
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test1 " , - 1 , HTTP_ADDREQ_FLAG_ADD ) ,
" Failed to add new header \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test1 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) = = 0 , " Second Index Should Not Exist \n " ) ;
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test2 " , - 1 , HTTP_ADDREQ_FLAG_ADD ) ,
" Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test1 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2005-11-22 14:53:30 +00:00
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test3 " , - 1 , HTTP_ADDREQ_FLAG_REPLACE ) , " Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE \n " ) ;
2005-12-13 16:07:41 +00:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2005-11-22 14:53:30 +00:00
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test4 " , - 1 , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) = = 0 , " HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header \n " ) ;
2005-12-13 16:07:41 +00:00
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test4 " , - 1 , HTTP_ADDREQ_FLAG_COALESCE ) , " HTTP_ADDREQ_FLAG_COALESCE Did not work \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2, test4 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test5 " , - 1 , HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA ) , " HTTP_ADDREQ_FLAG_COALESCE Did not work \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2, test4, test5 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test6 " , - 1 , HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON ) , " HTTP_ADDREQ_FLAG_COALESCE Did not work \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2, test4, test5; test6 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test7 " , - 1 , HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE ) , " HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test3 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test7 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2005-11-22 14:53:30 +00:00
ok ( InternetCloseHandle ( hRequest ) , " Close request handle failed \n " ) ;
2006-09-21 10:44:56 +00:00
done :
2005-11-22 14:53:30 +00:00
ok ( InternetCloseHandle ( hConnect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( hSession ) , " Close session handle failed \n " ) ;
}
2006-05-16 14:03:45 +00:00
static const char okmsg [ ] =
" HTTP/1.0 200 OK \r \n "
" Server: winetest \r \n "
" \r \n " ;
2006-05-30 13:55:16 +00:00
static const char proxymsg [ ] =
" HTTP/1.1 407 Proxy Authentication Required \r \n "
" Server: winetest \r \n "
" Proxy-Connection: close \r \n "
" Proxy-Authenticate: Basic realm= \" placebo \" \r \n "
" \r \n " ;
2006-05-16 14:03:45 +00:00
static const char page1 [ ] =
" <HTML> \r \n "
" <HEAD><TITLE>wininet test page</TITLE></HEAD> \r \n "
" <BODY>The quick brown fox jumped over the lazy dog<P></BODY> \r \n "
" </HTML> \r \n \r \n " ;
struct server_info {
HANDLE hEvent ;
int port ;
} ;
static DWORD CALLBACK server_thread ( LPVOID param )
{
struct server_info * si = param ;
2006-05-30 13:55:16 +00:00
int r , s , c , i , on ;
2006-05-16 14:03:45 +00:00
struct sockaddr_in sa ;
char buffer [ 0x100 ] ;
WSADATA wsaData ;
2006-05-30 13:55:16 +00:00
int last_request = 0 ;
2006-05-16 14:03:45 +00:00
WSAStartup ( MAKEWORD ( 1 , 1 ) , & wsaData ) ;
s = socket ( AF_INET , SOCK_STREAM , 0 ) ;
if ( s < 0 )
2006-05-30 13:55:16 +00:00
return 1 ;
on = 1 ;
setsockopt ( s , SOL_SOCKET , SO_REUSEADDR , ( char * ) & on , sizeof on ) ;
2006-05-16 14:03:45 +00:00
memset ( & sa , 0 , sizeof sa ) ;
sa . sin_family = AF_INET ;
sa . sin_port = htons ( si - > port ) ;
sa . sin_addr . S_un . S_addr = inet_addr ( " 127.0.0.1 " ) ;
r = bind ( s , ( struct sockaddr * ) & sa , sizeof sa ) ;
if ( r < 0 )
return 1 ;
2006-05-30 13:55:16 +00:00
listen ( s , 0 ) ;
2006-05-16 14:03:45 +00:00
SetEvent ( si - > hEvent ) ;
2006-05-30 13:55:16 +00:00
do
2006-05-16 14:03:45 +00:00
{
2006-05-30 13:55:16 +00:00
c = accept ( s , NULL , NULL ) ;
memset ( buffer , 0 , sizeof buffer ) ;
for ( i = 0 ; i < ( sizeof buffer - 1 ) ; i + + )
{
r = recv ( c , & buffer [ i ] , 1 , 0 ) ;
if ( r ! = 1 )
break ;
if ( i < 4 ) continue ;
if ( buffer [ i - 2 ] = = ' \n ' & & buffer [ i ] = = ' \n ' & &
buffer [ i - 3 ] = = ' \r ' & & buffer [ i - 1 ] = = ' \r ' )
break ;
}
if ( strstr ( buffer , " GET /test1 " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
if ( strstr ( buffer , " /test2 " ) )
{
if ( strstr ( buffer , " Proxy-Authorization: Basic bWlrZToxMTAx " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
else
send ( c , proxymsg , sizeof proxymsg - 1 , 0 ) ;
}
if ( strstr ( buffer , " /quit " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
last_request = 1 ;
}
2006-05-16 14:03:45 +00:00
2006-05-30 13:55:16 +00:00
shutdown ( c , 2 ) ;
closesocket ( c ) ;
} while ( ! last_request ) ;
2006-05-16 14:03:45 +00:00
closesocket ( s ) ;
return 0 ;
}
2006-08-10 18:24:35 +00:00
static void test_basic_request ( int port , const char * url )
2006-05-16 14:03:45 +00:00
{
HINTERNET hi , hc , hr ;
2006-05-30 13:55:16 +00:00
DWORD r , count ;
2006-05-16 14:03:45 +00:00
char buffer [ 0x100 ] ;
hi = InternetOpen ( NULL , 0 , NULL , NULL , 0 ) ;
ok ( hi ! = NULL , " open failed \n " ) ;
2006-05-30 13:55:16 +00:00
hc = InternetConnect ( hi , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2006-05-16 14:03:45 +00:00
ok ( hc ! = NULL , " connect failed \n " ) ;
2006-05-30 13:55:16 +00:00
hr = HttpOpenRequest ( hc , NULL , url , NULL , NULL , NULL , 0 , 0 ) ;
2006-05-16 14:03:45 +00:00
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
r = HttpSendRequest ( hr , NULL , 0 , NULL , 0 ) ;
ok ( r , " HttpSendRequest failed \n " ) ;
count = 0 ;
memset ( buffer , 0 , sizeof buffer ) ;
r = InternetReadFile ( hr , buffer , sizeof buffer , & count ) ;
ok ( r , " InternetReadFile failed \n " ) ;
ok ( count = = sizeof page1 - 1 , " count was wrong \n " ) ;
ok ( ! memcmp ( buffer , page1 , sizeof page1 ) , " http data wrong \n " ) ;
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
2006-05-30 13:55:16 +00:00
}
static void test_proxy_indirect ( int port )
{
HINTERNET hi , hc , hr ;
DWORD r , sz , val ;
char buffer [ 0x40 ] ;
hi = InternetOpen ( NULL , 0 , NULL , NULL , 0 ) ;
ok ( hi ! = NULL , " open failed \n " ) ;
hc = InternetConnect ( hi , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( hc ! = NULL , " connect failed \n " ) ;
hr = HttpOpenRequest ( hc , NULL , " /test2 " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
r = HttpSendRequest ( hr , NULL , 0 , NULL , 0 ) ;
ok ( r , " HttpSendRequest failed \n " ) ;
sz = sizeof buffer ;
r = HttpQueryInfo ( hr , HTTP_QUERY_PROXY_AUTHENTICATE , buffer , & sz , NULL ) ;
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " Basic realm= \" placebo \" " ) , " proxy auth info wrong \n " ) ;
sz = sizeof buffer ;
r = HttpQueryInfo ( hr , HTTP_QUERY_STATUS_CODE , buffer , & sz , NULL ) ;
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " 407 " ) , " proxy code wrong \n " ) ;
sz = sizeof val ;
r = HttpQueryInfo ( hr , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & val , & sz , NULL ) ;
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( val = = 407 , " proxy code wrong \n " ) ;
sz = sizeof buffer ;
r = HttpQueryInfo ( hr , HTTP_QUERY_STATUS_TEXT , buffer , & sz , NULL ) ;
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " Proxy Authentication Required " ) , " proxy text wrong \n " ) ;
sz = sizeof buffer ;
r = HttpQueryInfo ( hr , HTTP_QUERY_VERSION , buffer , & sz , NULL ) ;
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " HTTP/1.1 " ) , " http version wrong \n " ) ;
sz = sizeof buffer ;
r = HttpQueryInfo ( hr , HTTP_QUERY_SERVER , buffer , & sz , NULL ) ;
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " winetest " ) , " http server wrong \n " ) ;
sz = sizeof buffer ;
r = HttpQueryInfo ( hr , HTTP_QUERY_CONTENT_ENCODING , buffer , & sz , NULL ) ;
ok ( GetLastError ( ) = = ERROR_HTTP_HEADER_NOT_FOUND , " HttpQueryInfo should fail \n " ) ;
ok ( r = = FALSE , " HttpQueryInfo failed \n " ) ;
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
}
static void test_proxy_direct ( int port )
{
HINTERNET hi , hc , hr ;
DWORD r , sz ;
char buffer [ 0x40 ] ;
2006-08-10 18:24:35 +00:00
static CHAR username [ ] = " mike " ,
password [ ] = " 1101 " ;
2006-05-30 13:55:16 +00:00
sprintf ( buffer , " localhost:%d \n " , port ) ;
hi = InternetOpen ( NULL , INTERNET_OPEN_TYPE_PROXY , buffer , NULL , 0 ) ;
ok ( hi ! = NULL , " open failed \n " ) ;
/* try connect without authorization */
hc = InternetConnect ( hi , " www.winehq.org/ " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( hc ! = NULL , " connect failed \n " ) ;
hr = HttpOpenRequest ( hc , NULL , " /test2 " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
r = HttpSendRequest ( hr , NULL , 0 , NULL , 0 ) ;
ok ( r , " HttpSendRequest failed \n " ) ;
sz = sizeof buffer ;
r = HttpQueryInfo ( hr , HTTP_QUERY_STATUS_CODE , buffer , & sz , NULL ) ;
ok ( r , " HttpQueryInfo failed \n " ) ;
ok ( ! strcmp ( buffer , " 407 " ) , " proxy code wrong \n " ) ;
/* set the user + password then try again */
todo_wine {
2006-08-10 18:24:35 +00:00
r = InternetSetOption ( hr , INTERNET_OPTION_PROXY_USERNAME , username , 4 ) ;
2006-05-30 13:55:16 +00:00
ok ( r , " failed to set user \n " ) ;
2006-08-10 18:24:35 +00:00
r = InternetSetOption ( hr , INTERNET_OPTION_PROXY_PASSWORD , password , 4 ) ;
2006-05-30 13:55:16 +00:00
ok ( r , " failed to set password \n " ) ;
}
r = HttpSendRequest ( hr , NULL , 0 , NULL , 0 ) ;
ok ( r , " HttpSendRequest failed \n " ) ;
sz = sizeof buffer ;
r = HttpQueryInfo ( hr , HTTP_QUERY_STATUS_CODE , buffer , & sz , NULL ) ;
ok ( r , " HttpQueryInfo failed \n " ) ;
todo_wine {
ok ( ! strcmp ( buffer , " 200 " ) , " proxy code wrong \n " ) ;
}
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
}
static void test_http_connection ( void )
{
struct server_info si ;
HANDLE hThread ;
DWORD id = 0 , r ;
si . hEvent = CreateEvent ( NULL , 0 , 0 , NULL ) ;
si . port = 7531 ;
hThread = CreateThread ( NULL , 0 , server_thread , ( LPVOID ) & si , 0 , & id ) ;
ok ( hThread ! = NULL , " create thread failed \n " ) ;
r = WaitForSingleObject ( si . hEvent , 10000 ) ;
ok ( r = = WAIT_OBJECT_0 , " failed to start wininet test server \n " ) ;
if ( r ! = WAIT_OBJECT_0 )
return ;
test_basic_request ( si . port , " /test1 " ) ;
test_proxy_indirect ( si . port ) ;
test_proxy_direct ( si . port ) ;
/* send the basic request again to shutdown the server thread */
test_basic_request ( si . port , " /quit " ) ;
2006-05-16 14:03:45 +00:00
r = WaitForSingleObject ( hThread , 3000 ) ;
ok ( r = = WAIT_OBJECT_0 , " thread wait failed \n " ) ;
CloseHandle ( hThread ) ;
}
2005-11-22 14:53:30 +00:00
2002-06-21 23:59:49 +00:00
START_TEST ( http )
{
2007-02-20 14:53:49 +00:00
HMODULE hdll ;
hdll = GetModuleHandleA ( " wininet.dll " ) ;
pInternetSetStatusCallbackA = ( void * ) GetProcAddress ( hdll , " InternetSetStatusCallbackA " ) ;
pInternetTimeFromSystemTimeA = ( void * ) GetProcAddress ( hdll , " InternetTimeFromSystemTimeA " ) ;
pInternetTimeFromSystemTimeW = ( void * ) GetProcAddress ( hdll , " InternetTimeFromSystemTimeW " ) ;
pInternetTimeToSystemTimeA = ( void * ) GetProcAddress ( hdll , " InternetTimeToSystemTimeA " ) ;
pInternetTimeToSystemTimeW = ( void * ) GetProcAddress ( hdll , " InternetTimeToSystemTimeW " ) ;
if ( ! pInternetSetStatusCallbackA )
skip ( " skipping the InternetReadFile tests \n " ) ;
else
{
InternetReadFile_test ( INTERNET_FLAG_ASYNC ) ;
InternetReadFile_test ( 0 ) ;
InternetReadFileExA_test ( INTERNET_FLAG_ASYNC ) ;
}
2007-02-12 14:19:17 +00:00
InternetOpenRequest_test ( ) ;
2003-02-25 03:57:59 +00:00
InternetOpenUrlA_test ( ) ;
2007-02-20 14:53:49 +00:00
if ( ! pInternetTimeFromSystemTimeA )
skip ( " skipping the InternetTime tests \n " ) ;
else
{
InternetTimeFromSystemTimeA_test ( ) ;
InternetTimeFromSystemTimeW_test ( ) ;
InternetTimeToSystemTimeA_test ( ) ;
InternetTimeToSystemTimeW_test ( ) ;
}
2005-11-21 15:17:55 +00:00
HttpSendRequestEx_test ( ) ;
2005-11-22 14:53:30 +00:00
HttpHeaders_test ( ) ;
2006-05-16 14:03:45 +00:00
test_http_connection ( ) ;
2002-06-21 23:59:49 +00:00
}