2005-06-30 22:49:27 +02: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 14:49:52 +02:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2005-06-30 22:49:27 +02:00
*/
2003-09-06 01:08:26 +02:00
# include <stdarg.h>
2002-06-22 01:59:49 +02:00
# include <stdio.h>
2002-10-29 22:24:35 +01:00
# include <stdlib.h>
# include "windef.h"
2002-06-22 01:59:49 +02:00
# include "winbase.h"
# include "wininet.h"
2006-05-16 16:03:45 +02:00
# include "winsock.h"
2002-06-22 01:59:49 +02:00
2002-10-29 22:24:35 +01:00
# include "wine/test.h"
2008-12-10 10:47:13 +01:00
# define TEST_URL "http: //test.winehq.org/hello.html"
2005-10-31 15:06:35 +01:00
2007-07-15 23:29:48 +02:00
static BOOL first_connection_to_test_url = TRUE ;
/* Adapted from dlls/urlmon/tests/protocol.c */
# define SET_EXPECT2(status, num) \
expect [ status ] = num
# define SET_EXPECT(status) \
SET_EXPECT2 ( status , 1 )
2008-08-26 11:27:26 +02:00
# define SET_OPTIONAL2(status, num) \
optional [ status ] = num
# define SET_OPTIONAL(status) \
SET_OPTIONAL2 ( status , 1 )
2007-07-15 23:29:48 +02:00
/* SET_WINE_ALLOW's should be used with an appropriate
* todo_wine CHECK_NOTIFIED at a later point in the code */
# define SET_WINE_ALLOW2(status, num) \
wine_allow [ status ] = num
# define SET_WINE_ALLOW(status) \
SET_WINE_ALLOW2 ( status , 1 )
# define CHECK_EXPECT(status) \
do { \
2008-08-26 11:27:26 +02:00
if ( ! expect [ status ] & & ! optional [ status ] & & wine_allow [ status ] ) \
2007-07-15 23:29:48 +02:00
{ \
todo_wine ok ( expect [ status ] , " unexpected status %d (%s) \n " , status , \
status < MAX_INTERNET_STATUS & & status_string [ status ] [ 0 ] ! = 0 ? \
status_string [ status ] : " unknown " ) ; \
wine_allow [ status ] - - ; \
} \
else \
{ \
2008-08-26 11:27:26 +02:00
ok ( expect [ status ] | | optional [ status ] , " unexpected status %d (%s) \n " , status , \
2007-07-15 23:29:48 +02:00
status < MAX_INTERNET_STATUS & & status_string [ status ] [ 0 ] ! = 0 ? \
status_string [ status ] : " unknown " ) ; \
2008-08-26 11:27:26 +02:00
if ( expect [ status ] ) expect [ status ] - - ; \
else optional [ status ] - - ; \
2007-07-15 23:29:48 +02:00
} \
notified [ status ] + + ; \
} while ( 0 )
/* CLEAR_NOTIFIED used in cases when notification behavior
* differs between Windows versions */
# define CLEAR_NOTIFIED(status) \
2008-08-26 11:27:26 +02:00
expect [ status ] = optional [ status ] = wine_allow [ status ] = notified [ status ] = 0 ;
2007-07-15 23:29:48 +02:00
# define CHECK_NOTIFIED2(status, num) \
do { \
ok ( notified [ status ] = = ( num ) , " expected status %d (%s) %d times, received %d times \n " , \
status , status < MAX_INTERNET_STATUS & & status_string [ status ] [ 0 ] ! = 0 ? \
status_string [ status ] : " unknown " , ( num ) , notified [ status ] ) ; \
CLEAR_NOTIFIED ( status ) ; \
} while ( 0 )
# define CHECK_NOTIFIED(status) \
CHECK_NOTIFIED2 ( status , 1 )
# define CHECK_NOT_NOTIFIED(status) \
CHECK_NOTIFIED2 ( status , 0 )
# define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
# define MAX_STATUS_NAME 50
2008-08-26 11:27:26 +02:00
static int expect [ MAX_INTERNET_STATUS ] , optional [ MAX_INTERNET_STATUS ] ,
wine_allow [ MAX_INTERNET_STATUS ] , notified [ MAX_INTERNET_STATUS ] ;
2007-07-15 23:29:48 +02:00
static CHAR status_string [ MAX_INTERNET_STATUS ] [ MAX_STATUS_NAME ] ;
2005-11-16 12:21:41 +01:00
static HANDLE hCompleteEvent ;
2002-06-22 01:59:49 +02:00
2007-02-20 15:53:49 +01:00
static INTERNET_STATUS_CALLBACK ( WINAPI * pInternetSetStatusCallbackA ) ( HINTERNET , INTERNET_STATUS_CALLBACK ) ;
2005-06-13 21:05:42 +02:00
static VOID WINAPI callback (
2002-06-22 01:59:49 +02:00
HINTERNET hInternet ,
2006-10-28 14:14:52 +02:00
DWORD_PTR dwContext ,
2002-06-22 01:59:49 +02:00
DWORD dwInternetStatus ,
LPVOID lpvStatusInformation ,
DWORD dwStatusInformationLength
)
{
2007-07-15 23:29:48 +02:00
CHECK_EXPECT ( dwInternetStatus ) ;
2002-06-22 01:59:49 +02:00
switch ( dwInternetStatus )
{
case INTERNET_STATUS_RESOLVING_NAME :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_NAME_RESOLVED :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTING_TO_SERVER :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTED_TO_SERVER :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_SENDING_REQUEST :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_REQUEST_SENT :
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( DWORD ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(DWORD) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( DWORD * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_RECEIVING_RESPONSE :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_RESPONSE_RECEIVED :
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( DWORD ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(DWORD) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( DWORD * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CTL_RESPONSE_RECEIVED :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_PREFETCH :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CLOSING_CONNECTION :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTION_CLOSED :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_HANDLE_CREATED :
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( HINTERNET ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(HINTERNET) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( HINTERNET * ) lpvStatusInformation , dwStatusInformationLength ) ;
2008-05-06 23:58:31 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_DETECTING_PROXY ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_HANDLE_CLOSING :
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( HINTERNET ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(HINTERNET) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( HINTERNET * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_REQUEST_COMPLETE :
2005-11-16 12:21:41 +01:00
{
INTERNET_ASYNC_RESULT * iar = ( INTERNET_ASYNC_RESULT * ) lpvStatusInformation ;
2005-11-22 12:59:16 +01:00
ok ( dwStatusInformationLength = = sizeof ( INTERNET_ASYNC_RESULT ) ,
2006-10-05 13:19:00 +02:00
" info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d \n " ,
2005-11-22 12:59:16 +01:00
dwStatusInformationLength ) ;
2007-08-30 16:21:33 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
iar - > dwResult , iar - > dwError , dwStatusInformationLength ) ;
SetEvent ( hCompleteEvent ) ;
2002-06-22 01:59:49 +02:00
break ;
2005-11-16 12:21:41 +01:00
}
2002-06-22 01:59:49 +02:00
case INTERNET_STATUS_REDIRECT :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \" %s \" %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2007-03-05 13:06:47 +01:00
* ( LPSTR ) lpvStatusInformation = ' \0 ' ;
2008-05-06 23:58:31 +02:00
CLEAR_NOTIFIED ( INTERNET_STATUS_DETECTING_PROXY ) ;
SET_EXPECT ( INTERNET_STATUS_DETECTING_PROXY ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_INTERMEDIATE_RESPONSE :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
2005-11-16 12:21:41 +01:00
default :
2006-10-28 14:14:52 +02:00
trace ( " %04x:Callback %p 0x%lx %d %p %d \n " ,
2005-11-16 12:21:41 +01:00
GetCurrentThreadId ( ) , hInternet , dwContext , dwInternetStatus ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
}
}
2005-11-16 12:21:41 +01:00
static void InternetReadFile_test ( int flags )
2002-06-22 01:59:49 +02:00
{
2008-02-13 13:33:42 +01:00
BOOL res ;
2002-06-22 01:59:49 +02:00
CHAR buffer [ 4000 ] ;
DWORD length ;
DWORD out ;
2002-12-07 00:21:35 +01:00
const char * types [ 2 ] = { " * " , NULL } ;
2002-12-17 22:03:33 +01:00
HINTERNET hi , hic = 0 , hor = 0 ;
2002-06-22 01:59:49 +02:00
2005-11-16 12:21:41 +01:00
hCompleteEvent = CreateEvent ( NULL , FALSE , FALSE , NULL ) ;
trace ( " Starting InternetReadFile test with flags 0x%x \n " , flags ) ;
2002-06-22 01:59:49 +02:00
trace ( " InternetOpenA <-- \n " ) ;
2005-11-16 12:21:41 +01:00
hi = InternetOpenA ( " " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , flags ) ;
2007-01-06 19:25:07 +01:00
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
trace ( " InternetOpenA --> \n " ) ;
2002-10-09 20:12:20 +02:00
if ( hi = = 0x0 ) goto abort ;
2007-02-20 15:53:49 +01:00
pInternetSetStatusCallbackA ( hi , & callback ) ;
2002-06-22 01:59:49 +02:00
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2002-06-22 01:59:49 +02:00
trace ( " InternetConnectA <-- \n " ) ;
2008-12-10 10:47:13 +01:00
hic = InternetConnectA ( hi , " test.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
2005-11-16 12:21:41 +01:00
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
2007-01-06 19:25:07 +01:00
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
trace ( " InternetConnectA --> \n " ) ;
2002-10-09 20:12:20 +02:00
if ( hic = = 0x0 ) goto abort ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2002-06-22 01:59:49 +02:00
trace ( " HttpOpenRequestA <-- \n " ) ;
2008-12-10 10:47:13 +01:00
hor = HttpOpenRequestA ( hic , " GET " , " /testredirect " , NULL , NULL , types ,
2005-11-16 12:21:41 +01:00
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE ,
0xdeadbead ) ;
if ( hor = = 0x0 & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) {
2002-10-09 20:12:20 +02: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 19:25:07 +01:00
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %u \n " , GetLastError ( ) ) ;
2002-10-09 20:12:20 +02:00
}
2002-06-22 01:59:49 +02:00
trace ( " HttpOpenRequestA --> \n " ) ;
2002-10-09 20:12:20 +02:00
if ( hor = = 0x0 ) goto abort ;
2008-02-13 13:33:42 +01:00
length = sizeof ( buffer ) ;
res = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
ok ( res , " InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u \n " , GetLastError ( ) ) ;
2008-12-10 10:47:13 +01:00
ok ( ! strcmp ( buffer , " http://test.winehq.org/testredirect " ) , " Wrong URL %s \n " , buffer ) ;
2008-02-13 13:33:42 +01:00
2008-10-07 16:39:50 +02:00
length = sizeof ( buffer ) ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_RAW_HEADERS , buffer , & length , 0x0 ) ;
ok ( res , " HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d \n " , GetLastError ( ) ) ;
ok ( length = = 0 , " HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d \n " , length ) ;
ok ( ! strcmp ( buffer , " " ) , " HTTP_QUERY_RAW_HEADERS: expected string \" \" , but got \" %s \" \n " , buffer ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
2008-06-23 20:58:41 +02:00
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
2007-07-15 23:29:48 +02:00
if ( first_connection_to_test_url )
{
SET_EXPECT ( INTERNET_STATUS_RESOLVING_NAME ) ;
SET_EXPECT ( INTERNET_STATUS_NAME_RESOLVED ) ;
2008-08-26 11:27:26 +02:00
SET_WINE_ALLOW ( INTERNET_STATUS_RESOLVING_NAME ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_NAME_RESOLVED ) ;
2007-07-15 23:29:48 +02:00
}
else
{
2008-08-26 11:27:26 +02:00
SET_WINE_ALLOW2 ( INTERNET_STATUS_RESOLVING_NAME , 2 ) ;
SET_WINE_ALLOW2 ( INTERNET_STATUS_NAME_RESOLVED , 2 ) ;
2007-07-15 23:29:48 +02:00
}
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT2 ( INTERNET_STATUS_SENDING_REQUEST , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_REQUEST_SENT , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_RECEIVING_RESPONSE , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_RESPONSE_RECEIVED , 2 ) ;
2008-12-17 14:33:49 +01:00
SET_OPTIONAL2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
SET_OPTIONAL2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_REDIRECT ) ;
2008-08-26 11:27:26 +02:00
SET_OPTIONAL ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2007-07-15 23:29:48 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
else
SET_WINE_ALLOW ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2002-06-22 01:59:49 +02:00
trace ( " HttpSendRequestA --> \n " ) ;
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
2008-10-07 16:39:46 +02:00
res = HttpSendRequestA ( hor , " " , - 1 , NULL , 0 ) ;
2005-11-16 12:21:41 +01:00
if ( flags & INTERNET_FLAG_ASYNC )
2008-10-07 16:39:46 +02:00
ok ( ! res & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ,
2005-11-16 12:21:41 +01:00
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
2002-06-22 01:59:49 +02:00
else
2008-10-07 16:39:46 +02:00
ok ( res | | ( GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) ,
2007-01-06 19:25:07 +01:00
" Synchronous HttpSendRequest returning 0, error %u \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
trace ( " HttpSendRequestA <-- \n " ) ;
2005-11-16 12:21:41 +01:00
if ( flags & INTERNET_FLAG_ASYNC )
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2002-06-22 01:59:49 +02:00
2008-08-26 11:27:26 +02:00
todo_wine if ( first_connection_to_test_url )
2007-07-15 23:29:48 +02:00
{
CHECK_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
2008-08-26 11:27:26 +02:00
else
2007-07-15 23:29:48 +02:00
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
CHECK_NOTIFIED2 ( INTERNET_STATUS_SENDING_REQUEST , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_REQUEST_SENT , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_RECEIVING_RESPONSE , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_RESPONSE_RECEIVED , 2 ) ;
2008-12-11 15:24:12 +01:00
todo_wine CHECK_NOTIFIED2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
todo_wine CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REDIRECT ) ;
if ( flags & INTERNET_FLAG_ASYNC )
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
else
todo_wine CHECK_NOT_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
/* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2002-06-22 01:59:49 +02:00
length = 4 ;
2008-10-07 16:39:46 +02:00
res = InternetQueryOptionA ( hor , INTERNET_OPTION_REQUEST_FLAGS , & out , & length ) ;
ok ( res , " InternetQueryOptionA(INTERNET_OPTION_REQUEST) failed with error %d \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
length = 100 ;
2008-10-07 16:39:46 +02:00
res = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
ok ( res , " InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
2008-10-07 16:39:46 +02:00
length = sizeof ( buffer ) ;
res = HttpQueryInfoA ( hor , HTTP_QUERY_RAW_HEADERS , buffer , & length , 0x0 ) ;
ok ( res , " HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d \n " , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
buffer [ length ] = 0 ;
2008-02-13 13:33:42 +01:00
length = sizeof ( buffer ) ;
res = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
ok ( res , " InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u \n " , GetLastError ( ) ) ;
2008-12-10 10:47:13 +01:00
ok ( ! strcmp ( buffer , " http://test.winehq.org/hello.html " ) , " Wrong URL %s \n " , buffer ) ;
2002-06-22 01:59:49 +02:00
length = 16 ;
2008-10-07 16:39:46 +02:00
res = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_LENGTH , & buffer , & length , 0x0 ) ;
trace ( " Option 0x5 -> %i %s (%u) \n " , res , buffer , GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
length = 100 ;
2008-10-07 16:39:46 +02:00
res = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_TYPE , buffer , & length , 0x0 ) ;
2002-06-22 01:59:49 +02:00
buffer [ length ] = 0 ;
2008-10-07 16:39:46 +02:00
trace ( " Option 0x1 -> %i %s \n " , res , buffer ) ;
2002-06-22 01:59:49 +02:00
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
2008-10-07 16:39:46 +02:00
res = InternetReadFile ( NULL , buffer , 100 , & length ) ;
ok ( ! res , " InternetReadFile should have failed \n " ) ;
2005-11-16 12:21:41 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_HANDLE ,
2007-01-06 19:25:07 +01:00
" InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u \n " ,
2005-11-16 12:21:41 +01:00
GetLastError ( ) ) ;
2002-06-22 01:59:49 +02:00
length = 100 ;
2004-01-23 23:44:26 +01:00
trace ( " Entering Query loop \n " ) ;
2002-06-22 01:59:49 +02:00
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2007-07-15 23:29:46 +02:00
while ( TRUE )
2002-06-22 01:59:49 +02:00
{
2007-07-15 23:29:48 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2008-10-07 16:39:46 +02:00
res = InternetQueryDataAvailable ( hor , & length , 0x0 , 0x0 ) ;
ok ( ! ( ! res & & length ! = 0 ) , " InternetQueryDataAvailable failed with non-zero length \n " ) ;
ok ( res | | ( ( flags & INTERNET_FLAG_ASYNC ) & & GetLastError ( ) = = ERROR_IO_PENDING ) ,
2007-08-12 22:41:47 +02:00
" InternetQueryDataAvailable failed, error %d \n " , GetLastError ( ) ) ;
2007-07-15 23:29:46 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
{
2008-10-07 16:39:46 +02:00
if ( res )
2007-07-15 23:29:48 +02:00
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
}
else if ( GetLastError ( ) = = ERROR_IO_PENDING )
2007-07-15 23:29:46 +02:00
{
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2007-07-15 23:29:46 +02:00
continue ;
}
}
2002-06-22 01:59:49 +02:00
if ( length )
{
char * buffer ;
2005-03-22 19:26:06 +01:00
buffer = HeapAlloc ( GetProcessHeap ( ) , 0 , length + 1 ) ;
2002-06-22 01:59:49 +02:00
2008-10-07 16:39:46 +02:00
res = InternetReadFile ( hor , buffer , length , & length ) ;
2002-06-22 01:59:49 +02:00
buffer [ length ] = 0 ;
2008-10-07 16:39:46 +02:00
trace ( " ReadFile -> %s %i \n " , res ? " TRUE " : " FALSE " , length ) ;
2002-06-22 01:59:49 +02:00
HeapFree ( GetProcessHeap ( ) , 0 , buffer ) ;
}
2007-07-15 23:29:46 +02:00
if ( length = = 0 )
break ;
2002-06-22 01:59:49 +02:00
}
2007-07-15 23:29:48 +02:00
/* WinXP does not send, but Win98 does */
CLEAR_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2002-10-09 20:12:20 +02:00
abort :
2008-12-10 10:47:13 +01:00
trace ( " aborting \n " ) ;
2007-07-15 23:29:48 +02:00
SET_EXPECT2 ( INTERNET_STATUS_HANDLE_CLOSING , ( hor ! = 0x0 ) + ( hic ! = 0x0 ) ) ;
2002-10-09 20:12:20 +02:00
if ( hor ! = 0x0 ) {
2007-07-15 23:29:48 +02:00
SET_WINE_ALLOW ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
2008-12-10 10:47:13 +01:00
trace ( " closing \n " ) ;
2008-10-07 16:39:46 +02:00
res = InternetCloseHandle ( hor ) ;
ok ( res , " InternetCloseHandle of handle opened by HttpOpenRequestA failed \n " ) ;
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
2008-10-07 16:39:46 +02:00
res = InternetCloseHandle ( hor ) ;
ok ( ! res , " Double close of handle opened by HttpOpenRequestA succeeded \n " ) ;
2005-11-16 12:21:41 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_HANDLE ,
2007-01-06 19:25:07 +01:00
" Double close of handle should have set ERROR_INVALID_HANDLE instead of %u \n " ,
2005-11-16 12:21:41 +01:00
GetLastError ( ) ) ;
2002-10-09 20:12:20 +02:00
}
2007-09-21 04:00:38 +02:00
/* We intentionally do not close the handle opened by InternetConnectA as this
* tickles bug # 9479 : native closes child internet handles when the parent handles
* are closed . This is verified below by checking that the number of
* INTERNET_STATUS_HANDLE_CLOSING notifications matches the number expected . */
2002-10-09 20:12:20 +02:00
if ( hi ! = 0x0 ) {
2007-07-15 23:29:48 +02:00
SET_WINE_ALLOW ( INTERNET_STATUS_HANDLE_CLOSING ) ;
2008-12-10 10:47:13 +01:00
trace ( " closing 2 \n " ) ;
2008-10-07 16:39:46 +02:00
res = InternetCloseHandle ( hi ) ;
ok ( res , " InternetCloseHandle of handle opened by InternetOpenA failed \n " ) ;
2005-11-16 12:21:41 +01:00
if ( flags & INTERNET_FLAG_ASYNC )
Sleep ( 100 ) ;
}
2007-08-22 07:07:06 +02:00
CHECK_NOTIFIED2 ( INTERNET_STATUS_HANDLE_CLOSING , ( hor ! = 0x0 ) + ( hic ! = 0x0 ) ) ;
2008-12-10 10:47:13 +01:00
if ( hor ! = 0x0 ) todo_wine
2007-07-15 23:29:48 +02:00
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
}
else
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
}
2005-11-16 12:21:41 +01:00
CloseHandle ( hCompleteEvent ) ;
2007-07-15 23:29:48 +02:00
first_connection_to_test_url = FALSE ;
2005-11-16 12:21:41 +01:00
}
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 19:25:07 +01:00
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
trace ( " InternetOpenA --> \n " ) ;
if ( hi = = 0x0 ) goto abort ;
2007-02-20 15:53:49 +01:00
pInternetSetStatusCallbackA ( hi , & callback ) ;
2005-11-16 12:21:41 +01:00
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2005-11-16 12:21:41 +01:00
trace ( " InternetConnectA <-- \n " ) ;
2008-12-10 10:47:13 +01:00
hic = InternetConnectA ( hi , " test.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
2005-11-16 12:21:41 +01:00
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
2007-01-06 19:25:07 +01:00
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
trace ( " InternetConnectA --> \n " ) ;
if ( hic = = 0x0 ) goto abort ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
SET_EXPECT ( INTERNET_STATUS_HANDLE_CREATED ) ;
2005-11-16 12:21:41 +01:00
trace ( " HttpOpenRequestA <-- \n " ) ;
2008-12-10 10:47:13 +01:00
hor = HttpOpenRequestA ( hic , " GET " , " /testredirect " , NULL , NULL , types ,
2005-11-16 12:21:41 +01:00
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 19:25:07 +01:00
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
}
trace ( " HttpOpenRequestA --> \n " ) ;
if ( hor = = 0x0 ) goto abort ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_HANDLE_CREATED ) ;
2008-06-23 20:58:41 +02:00
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
2007-07-15 23:29:48 +02:00
if ( first_connection_to_test_url )
{
SET_EXPECT ( INTERNET_STATUS_RESOLVING_NAME ) ;
SET_EXPECT ( INTERNET_STATUS_NAME_RESOLVED ) ;
2008-08-26 11:27:26 +02:00
SET_WINE_ALLOW ( INTERNET_STATUS_RESOLVING_NAME ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_NAME_RESOLVED ) ;
2007-07-15 23:29:48 +02:00
}
else
{
2008-08-26 11:27:26 +02:00
SET_WINE_ALLOW2 ( INTERNET_STATUS_RESOLVING_NAME , 2 ) ;
SET_WINE_ALLOW2 ( INTERNET_STATUS_NAME_RESOLVED , 2 ) ;
2007-07-15 23:29:48 +02:00
}
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
SET_EXPECT2 ( INTERNET_STATUS_SENDING_REQUEST , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_REQUEST_SENT , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_RECEIVING_RESPONSE , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_RESPONSE_RECEIVED , 2 ) ;
2008-12-11 15:24:12 +01:00
SET_EXPECT2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
SET_EXPECT2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_REDIRECT ) ;
2008-08-26 20:40:28 +02:00
SET_OPTIONAL ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
SET_OPTIONAL ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2007-07-15 23:29:48 +02:00
if ( flags & INTERNET_FLAG_ASYNC )
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
else
SET_WINE_ALLOW ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2005-11-16 12:21:41 +01:00
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 19:25:07 +01:00
" Synchronous HttpSendRequest returning 0, error %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
trace ( " HttpSendRequestA <-- \n " ) ;
if ( ! rc & & ( GetLastError ( ) = = ERROR_IO_PENDING ) )
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2007-07-15 23:29:48 +02:00
if ( first_connection_to_test_url )
{
CHECK_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
else todo_wine
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESOLVING_NAME ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_NAME_RESOLVED ) ;
}
CHECK_NOTIFIED2 ( INTERNET_STATUS_SENDING_REQUEST , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_REQUEST_SENT , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_RECEIVING_RESPONSE , 2 ) ;
CHECK_NOTIFIED2 ( INTERNET_STATUS_RESPONSE_RECEIVED , 2 ) ;
2008-12-11 15:24:12 +01:00
todo_wine CHECK_NOTIFIED2 ( INTERNET_STATUS_CLOSING_CONNECTION , 2 ) ;
todo_wine CHECK_NOTIFIED2 ( INTERNET_STATUS_CONNECTION_CLOSED , 2 ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REDIRECT ) ;
if ( flags & INTERNET_FLAG_ASYNC )
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
else
todo_wine CHECK_NOT_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
/* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
2005-11-16 12:21:41 +01:00
/* 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 19:25:07 +01:00
" InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u \n " ,
2005-11-16 12:21:41 +01: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 ;
2008-12-11 15:24:12 +01:00
SET_EXPECT ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_EXPECT ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2005-11-16 12:21:41 +01:00
rc = InternetReadFileEx ( hor , & inetbuffers , 0 , 0xdeadcafe ) ;
2007-01-06 19:25:07 +01:00
ok ( rc , " InternetReadFileEx failed with error %u \n " , GetLastError ( ) ) ;
2008-08-26 11:27:26 +02:00
trace ( " read %i bytes \n " , inetbuffers . dwBufferLength ) ;
2007-07-15 23:29:48 +02:00
todo_wine
{
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
}
2005-11-16 12:21:41 +01:00
rc = InternetReadFileEx ( NULL , & inetbuffers , 0 , 0xdeadcafe ) ;
ok ( ! rc & & ( GetLastError ( ) = = ERROR_INVALID_HANDLE ) ,
2007-01-06 19:25:07 +01:00
" InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u \n " ,
2005-11-16 12:21:41 +01:00
rc ? " TRUE " : " FALSE " , GetLastError ( ) ) ;
length = 0 ;
trace ( " Entering Query loop \n " ) ;
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2005-11-16 12:21:41 +01:00
while ( TRUE )
{
inetbuffers . dwStructSize = sizeof ( INTERNET_BUFFERS ) ;
inetbuffers . dwBufferLength = 1024 ;
inetbuffers . lpvBuffer = HeapAlloc ( GetProcessHeap ( ) , 0 , inetbuffers . dwBufferLength + 1 ) ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
2008-12-11 15:24:12 +01:00
SET_WINE_ALLOW ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
SET_EXPECT ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_EXPECT ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2007-07-15 23:29:48 +02:00
SET_EXPECT ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
2005-11-16 12:21:41 +01:00
rc = InternetReadFileExA ( hor , & inetbuffers , IRF_ASYNC | IRF_USE_CONTEXT , 0xcafebabe ) ;
if ( ! rc )
{
if ( GetLastError ( ) = = ERROR_IO_PENDING )
{
trace ( " InternetReadFileEx -> PENDING \n " ) ;
2008-03-27 21:52:24 +01:00
ok ( flags & INTERNET_FLAG_ASYNC ,
" Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC \n " ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
2005-11-16 12:21:41 +01:00
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
2005-11-16 12:21:41 +01:00
}
else
{
2007-01-06 19:25:07 +01:00
trace ( " InternetReadFileEx -> FAILED %u \n " , GetLastError ( ) ) ;
2005-11-16 12:21:41 +01:00
break ;
}
}
else
2007-06-05 20:45:26 +02:00
{
2005-11-16 12:21:41 +01:00
trace ( " InternetReadFileEx -> SUCCEEDED \n " ) ;
2007-07-15 23:29:48 +02:00
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
if ( inetbuffers . dwBufferLength )
{
2008-12-11 15:24:12 +01:00
todo_wine {
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
}
2007-07-15 23:29:48 +02:00
}
else
{
/* Win98 still sends these when 0 bytes are read, WinXP does not */
CLEAR_NOTIFIED ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
}
2007-06-05 20:45:26 +02:00
}
2005-11-16 12:21:41 +01:00
2006-10-05 13:19:00 +02:00
trace ( " read %i bytes \n " , inetbuffers . dwBufferLength ) ;
2005-11-16 12:21:41 +01:00
( ( char * ) inetbuffers . lpvBuffer ) [ inetbuffers . dwBufferLength ] = ' \0 ' ;
ok ( inetbuffers . dwOffsetHigh = = 1234 & & inetbuffers . dwOffsetLow = = 5678 ,
2006-10-05 13:19:00 +02:00
" InternetReadFileEx sets offsets to 0x%x%08x \n " ,
2005-11-16 12:21:41 +01:00
inetbuffers . dwOffsetHigh , inetbuffers . dwOffsetLow ) ;
HeapFree ( GetProcessHeap ( ) , 0 , inetbuffers . lpvBuffer ) ;
if ( ! inetbuffers . dwBufferLength )
break ;
length + = inetbuffers . dwBufferLength ;
}
2008-12-10 10:47:13 +01:00
ok ( length > 0 , " failed to read any of the document \n " ) ;
2006-10-05 13:19:00 +02:00
trace ( " Finished. Read %d bytes \n " , length ) ;
2005-11-16 12:21:41 +01:00
2007-07-15 23:29:48 +02:00
/* WinXP does not send, but Win98 does */
CLEAR_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CLEAR_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2005-11-16 12:21:41 +01:00
abort :
2007-07-15 23:29:48 +02:00
SET_EXPECT2 ( INTERNET_STATUS_HANDLE_CLOSING , ( hor ! = 0x0 ) + ( hic ! = 0x0 ) ) ;
2005-11-16 12:21:41 +01:00
if ( hor ) {
2007-08-22 07:12:52 +02:00
SET_WINE_ALLOW ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
SET_WINE_ALLOW ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2005-11-16 12:21:41 +01:00
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 ) {
2007-07-15 23:29:48 +02:00
SET_WINE_ALLOW ( INTERNET_STATUS_HANDLE_CLOSING ) ;
2005-11-16 12:21:41 +01:00
rc = InternetCloseHandle ( hi ) ;
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetOpenA failed \n " ) ;
if ( flags & INTERNET_FLAG_ASYNC )
2002-10-09 20:12:20 +02:00
Sleep ( 100 ) ;
2007-08-22 07:07:06 +02:00
CHECK_NOTIFIED2 ( INTERNET_STATUS_HANDLE_CLOSING , ( hor ! = 0x0 ) + ( hic ! = 0x0 ) ) ;
2002-10-09 20:12:20 +02:00
}
2008-08-26 11:27:26 +02:00
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
CHECK_NOT_NOTIFIED ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
2005-11-16 12:21:41 +01:00
CloseHandle ( hCompleteEvent ) ;
2007-07-15 23:29:48 +02:00
first_connection_to_test_url = FALSE ;
2002-06-22 01:59:49 +02:00
}
2005-06-13 21:05:42 +02:00
static void InternetOpenUrlA_test ( void )
2003-02-25 04:57:59 +01:00
{
HINTERNET myhinternet , myhttp ;
char buffer [ 0x400 ] ;
DWORD size , readbytes , totalbytes = 0 ;
2004-12-27 18:26:37 +01:00
BOOL ret ;
2003-02-25 04:57:59 +01:00
myhinternet = InternetOpen ( " Winetest " , 0 , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE ) ;
2007-01-06 19:25:07 +01:00
ok ( ( myhinternet ! = 0 ) , " InternetOpen failed, error %u \n " , GetLastError ( ) ) ;
2003-02-25 04:57:59 +01:00
size = 0x400 ;
2004-12-27 18:26:37 +01:00
ret = InternetCanonicalizeUrl ( TEST_URL , buffer , & size , ICU_BROWSER_MODE ) ;
2007-01-06 19:25:07 +01:00
ok ( ret , " InternetCanonicalizeUrl failed, error %u \n " , GetLastError ( ) ) ;
2006-03-14 18:49:19 +01:00
2003-09-25 22:29:40 +02:00
SetLastError ( 0 ) ;
2004-01-16 03:03:16 +01:00
myhttp = InternetOpenUrl ( myhinternet , TEST_URL , 0 , 0 ,
2003-02-25 04:57:59 +01:00
INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_TRANSFER_BINARY , 0 ) ;
2007-11-11 13:35:06 +01:00
if ( GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
2003-09-25 22:29:40 +02:00
return ; /* WinXP returns this when not connected to the net */
2007-01-06 19:25:07 +01:00
ok ( ( myhttp ! = 0 ) , " InternetOpenUrl failed, error %u \n " , GetLastError ( ) ) ;
2004-12-27 18:26:37 +01:00
ret = InternetReadFile ( myhttp , buffer , 0x400 , & readbytes ) ;
2007-01-06 19:25:07 +01:00
ok ( ret , " InternetReadFile failed, error %u \n " , GetLastError ( ) ) ;
2003-02-25 04:57:59 +01:00
totalbytes + = readbytes ;
while ( readbytes & & InternetReadFile ( myhttp , buffer , 0x400 , & readbytes ) )
totalbytes + = readbytes ;
2006-10-05 13:19:00 +02:00
trace ( " read 0x%08x bytes \n " , totalbytes ) ;
2007-11-11 13:35:06 +01:00
InternetCloseHandle ( myhttp ) ;
InternetCloseHandle ( myhinternet ) ;
2003-02-25 04:57:59 +01:00
}
2004-08-06 20:58:04 +02:00
2005-11-21 16:17:55 +01: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 12:31:38 +01:00
BOOL ret ;
2005-11-21 16:17:55 +01:00
2006-10-05 20:44:30 +02:00
static char szPostData [ ] = " mode=Test " ;
2005-11-21 16:17:55 +01:00
static const char szContentType [ ] = " Content-Type: application/x-www-form-urlencoded " ;
2006-10-05 20:44:30 +02:00
2005-11-21 16:17:55 +01: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 12:44:56 +02:00
if ( ! hRequest & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
2008-07-10 03:04:05 +02:00
skip ( " Network unreachable, skipping test \n " ) ;
2006-09-21 12:44:56 +02:00
goto done ;
}
2007-01-06 19:25:07 +01:00
ok ( hRequest ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
2005-11-21 16:17:55 +01:00
BufferIn . dwStructSize = sizeof ( INTERNET_BUFFERS ) ;
2005-11-29 11:42:23 +01:00
BufferIn . Next = ( LPINTERNET_BUFFERS ) 0xdeadcab ;
2005-11-21 16:17:55 +01:00
BufferIn . lpcszHeader = szContentType ;
2008-02-19 00:20:50 +01:00
BufferIn . dwHeadersLength = sizeof ( szContentType ) - 1 ;
BufferIn . dwHeadersTotal = sizeof ( szContentType ) - 1 ;
2006-10-05 20:44:30 +02:00
BufferIn . lpvBuffer = szPostData ;
2005-11-30 12:31:38 +01:00
BufferIn . dwBufferLength = 3 ;
2005-11-21 16:17:55 +01:00
BufferIn . dwBufferTotal = sizeof ( szPostData ) - 1 ;
BufferIn . dwOffsetLow = 0 ;
BufferIn . dwOffsetHigh = 0 ;
2005-11-30 12:31:38 +01:00
ret = HttpSendRequestEx ( hRequest , & BufferIn , NULL , 0 , 0 ) ;
2007-01-06 19:25:07 +01:00
ok ( ret , " HttpSendRequestEx Failed with error %u \n " , GetLastError ( ) ) ;
2005-11-21 16:17:55 +01:00
2005-11-30 12:31:38 +01:00
for ( i = 3 ; szPostData [ i ] ; i + + )
2005-11-21 16:17:55 +01: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 20:14:43 +01:00
" Unable to read response \n " ) ;
2005-11-21 16:17:55 +01:00
szBuffer [ dwBytesRead ] = 0 ;
2006-10-05 13:19:00 +02:00
ok ( dwBytesRead = = 13 , " Read %u bytes instead of 13 \n " , dwBytesRead ) ;
2005-11-21 16:17:55 +01: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 12:44:56 +02:00
done :
2005-11-21 16:17:55 +01:00
ok ( InternetCloseHandle ( hConnect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( hSession ) , " Close session handle failed \n " ) ;
}
2005-11-22 15:53:30 +01:00
2007-02-12 15:19:17 +01: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 " ) ;
2008-01-31 15:47:25 +01:00
connect = InternetConnectA ( session , NULL , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect = = NULL , " InternetConnectA should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
connect = InternetConnectA ( session , " " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect = = NULL , " InternetConnectA should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER , " InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d \n " , GetLastError ( ) ) ;
2008-12-10 10:47:13 +01:00
connect = InternetConnectA ( session , " test.winehq.org " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
2007-02-12 15:19:17 +01:00
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-12-10 10:47:13 +01:00
ok ( connect ! = NULL , " Unable to connect to http://test.winehq.org with error %d \n " , GetLastError ( ) ) ;
2007-02-12 15:19:17 +01:00
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , types , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
if ( ! request & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
2008-07-10 03:04:05 +02:00
skip ( " Network unreachable, skipping test \n " ) ;
2007-02-12 15:19:17 +01:00
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 " ) ;
}
2008-02-13 13:33:42 +01:00
static void test_http_cache ( void )
{
HINTERNET session , connect , request ;
char file_name [ MAX_PATH ] , url [ INTERNET_MAX_URL_LENGTH ] ;
DWORD size , file_size ;
BYTE buf [ 100 ] ;
HANDLE file ;
BOOL ret ;
static const char * types [ ] = { " * " , " " , NULL } ;
session = InternetOpenA ( " Wine Regression Test " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , 0 ) ;
ok ( session ! = NULL , " Unable to open Internet session \n " ) ;
2008-12-10 10:47:13 +01:00
connect = InternetConnectA ( session , " test.winehq.org " , INTERNET_DEFAULT_HTTP_PORT , NULL , NULL ,
2008-02-13 13:33:42 +01:00
INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-12-10 10:47:13 +01:00
ok ( connect ! = NULL , " Unable to connect to http://test.winehq.org with error %d \n " , GetLastError ( ) ) ;
2008-02-13 13:33:42 +01:00
2008-12-10 10:47:13 +01:00
request = HttpOpenRequestA ( connect , NULL , " /hello.html " , NULL , NULL , types , INTERNET_FLAG_NEED_FILE , 0 ) ;
2008-02-13 13:33:42 +01:00
if ( ! request & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
2008-07-10 03:04:05 +02:00
skip ( " Network unreachable, skipping test \n " ) ;
2008-02-13 13:33:42 +01:00
ok ( InternetCloseHandle ( connect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( session ) , " Close session handle failed \n " ) ;
return ;
}
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
size = sizeof ( url ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_URL , url , & size ) ;
ok ( ret , " InternetQueryOptionA(INTERNET_OPTION_url) failed: %u \n " , GetLastError ( ) ) ;
2008-12-10 10:47:13 +01:00
ok ( ! strcmp ( url , " http://test.winehq.org/hello.html " ) , " Wrong URL %s \n " , url ) ;
2008-02-13 13:33:42 +01:00
size = sizeof ( file_name ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
ok ( ! ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_INTERNET_ITEM_NOT_FOUND , " GetLastError()=%u \n " , GetLastError ( ) ) ;
ok ( ! size , " size = %d \n " , size ) ;
ret = HttpSendRequest ( request , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
size = sizeof ( file_name ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
ok ( ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u \n " , GetLastError ( ) ) ;
file = CreateFile ( file_name , GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE , NULL , OPEN_EXISTING ,
FILE_ATTRIBUTE_NORMAL , NULL ) ;
ok ( file ! = INVALID_HANDLE_VALUE , " Could not create file: %u \n " , GetLastError ( ) ) ;
file_size = GetFileSize ( file , NULL ) ;
2008-12-11 15:24:12 +01:00
todo_wine ok ( file_size = = 106 , " file size = %u \n " , file_size ) ;
2008-02-13 13:33:42 +01:00
2008-12-11 15:24:12 +01:00
size = sizeof ( buf ) ;
2008-02-13 13:33:42 +01:00
ret = InternetReadFile ( request , buf , sizeof ( buf ) , & size ) ;
ok ( ret , " InternetReadFile failed: %u \n " , GetLastError ( ) ) ;
2008-12-11 15:24:12 +01:00
ok ( size = = 100 , " size = %u \n " , size ) ;
2008-02-13 13:33:42 +01:00
file_size = GetFileSize ( file , NULL ) ;
2008-12-11 15:24:12 +01:00
todo_wine ok ( file_size = = 106 , " file size = %u \n " , file_size ) ;
2008-02-13 13:33:42 +01:00
CloseHandle ( file ) ;
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
file = CreateFile ( file_name , GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE , NULL , OPEN_EXISTING ,
FILE_ATTRIBUTE_NORMAL , NULL ) ;
2008-12-11 15:24:12 +01:00
todo_wine ok ( file ! = INVALID_HANDLE_VALUE , " CreateFile succeeded \n " ) ;
CloseHandle ( file ) ;
2008-02-13 13:33:42 +01:00
request = HttpOpenRequestA ( connect , NULL , " / " , NULL , NULL , types , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( request ! = NULL , " Failed to open request handle err %u \n " , GetLastError ( ) ) ;
2008-12-11 15:24:12 +01:00
size = sizeof ( file_name ) ;
2008-02-13 13:33:42 +01:00
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
ok ( ! ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded \n " ) ;
ok ( GetLastError ( ) = = ERROR_INTERNET_ITEM_NOT_FOUND , " GetLastError()=%u \n " , GetLastError ( ) ) ;
ok ( ! size , " size = %d \n " , size ) ;
ret = HttpSendRequest ( request , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
size = sizeof ( file_name ) ;
ret = InternetQueryOptionA ( request , INTERNET_OPTION_DATAFILE_NAME , file_name , & size ) ;
2008-12-11 15:24:12 +01:00
todo_wine ok ( ret , " InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed % u \ n " , GetLastError()) ;
2008-02-13 13:33:42 +01:00
file = CreateFile ( file_name , GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_WRITE , NULL , OPEN_EXISTING ,
FILE_ATTRIBUTE_NORMAL , NULL ) ;
2008-12-11 15:24:12 +01:00
todo_wine ok ( file ! = INVALID_HANDLE_VALUE , " CreateFile succeeded \n " ) ;
CloseHandle ( file ) ;
2008-02-13 13:33:42 +01:00
ok ( InternetCloseHandle ( request ) , " Close request handle failed \n " ) ;
ok ( InternetCloseHandle ( connect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( session ) , " Close session handle failed \n " ) ;
}
2005-11-22 15:53:30 +01:00
static void HttpHeaders_test ( void )
{
HINTERNET hSession ;
HINTERNET hConnect ;
HINTERNET hRequest ;
2005-12-13 17:07:41 +01:00
CHAR buffer [ 256 ] ;
2008-07-30 15:49:04 +02:00
WCHAR wbuffer [ 256 ] ;
2005-12-13 17:07:41 +01:00
DWORD len = 256 ;
2008-07-30 15:49:04 +02:00
DWORD oldlen ;
2005-12-13 17:07:41 +01:00
DWORD index = 0 ;
2005-11-22 15:53:30 +01: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 12:44:56 +02:00
if ( ! hRequest & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED )
{
2008-07-10 03:04:05 +02:00
skip ( " Network unreachable, skipping test \n " ) ;
2006-09-21 12:44:56 +02:00
goto done ;
}
2005-11-22 15:53:30 +01:00
ok ( hRequest ! = NULL , " Failed to open request handle \n " ) ;
2005-12-13 17:07:41 +01: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 ) ;
2007-08-16 01:29:58 +02:00
ok ( len = = 5 , " Invalid length (exp. 5, got %d) \n " , len ) ;
2008-01-23 22:26:58 +01:00
ok ( ( len < sizeof ( buffer ) ) & & ( buffer [ len ] = = 0 ) , " Buffer not NULL-terminated \n " ) ; /* len show only 5 characters but the buffer is NULL-terminated*/
2005-12-13 17:07:41 +01:00
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 " ) ;
2007-08-16 01:56:43 +02:00
index = 0 ;
len = 5 ; /* could store the string but not the NULL terminator */
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) = = FALSE , " Query succeeded on a too small buffer \n " ) ;
ok ( strcmp ( buffer , " Warning " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ; /* string not touched */
ok ( len = = 6 , " Invalid length (exp. 6, got %d) \n " , len ) ; /* unlike success, the length includes the NULL-terminator */
2007-08-16 01:55:15 +02:00
/* a call with NULL will fail but will return the length */
index = 0 ;
len = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
NULL , & len , & index ) = = FALSE , " Query worked \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( len > 40 , " Invalid length (exp. more than 40, got %d) \n " , len ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
/* even for a len that is too small */
index = 0 ;
len = 15 ;
SetLastError ( 0xdeadbeef ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
NULL , & len , & index ) = = FALSE , " Query worked \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( len > 40 , " Invalid length (exp. more than 40, got %d) \n " , len ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
index = 0 ;
len = 0 ;
SetLastError ( 0xdeadbeef ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
NULL , & len , & index ) = = FALSE , " Query worked \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( len > 40 , " Invalid length (exp. more than 40, got %d) \n " , len ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
2008-07-30 15:49:04 +02:00
oldlen = len ; /* bytes; at least long enough to hold buffer & nul */
2007-08-16 01:55:15 +02:00
2007-08-16 01:29:58 +02:00
/* a working query */
index = 0 ;
len = sizeof ( buffer ) ;
2008-07-30 15:49:04 +02:00
memset ( buffer , ' x ' , sizeof ( buffer ) ) ;
2007-08-16 01:29:58 +02:00
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Unable to query header \n " ) ;
2008-07-30 15:49:04 +02:00
ok ( len + sizeof ( CHAR ) < = oldlen , " Result longer than advertised \n " ) ;
ok ( ( len < sizeof ( buffer ) - sizeof ( CHAR ) ) & & ( buffer [ len / sizeof ( CHAR ) ] = = 0 ) , " No NUL at end \n " ) ;
ok ( len = = strlen ( buffer ) * sizeof ( CHAR ) , " Length wrong \n " ) ;
2007-08-16 01:29:58 +02:00
/* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
ok ( strncmp ( buffer , " POST /posttest.php HTTP/1 " , 25 ) = = 0 , " Invalid beginning of headers string \n " ) ;
ok ( strcmp ( buffer + strlen ( buffer ) - 4 , " \r \n \r \n " ) = = 0 , " Invalid end of headers string \n " ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
2008-07-30 15:49:04 +02:00
/* Like above two tests, but for W version */
2007-08-16 01:29:58 +02:00
2008-07-30 15:49:04 +02:00
index = 0 ;
len = 0 ;
SetLastError ( 0xdeadbeef ) ;
ok ( HttpQueryInfoW ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
NULL , & len , & index ) = = FALSE , " Query worked \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " Unexpected last error: %d \n " , GetLastError ( ) ) ;
ok ( len > 80 , " Invalid length (exp. more than 80, got %d) \n " , len ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
oldlen = len ; /* bytes; at least long enough to hold buffer & nul */
/* a working query */
index = 0 ;
len = sizeof ( wbuffer ) ;
memset ( wbuffer , ' x ' , sizeof ( wbuffer ) ) ;
ok ( HttpQueryInfoW ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
wbuffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( len + sizeof ( WCHAR ) < = oldlen , " Result longer than advertised \n " ) ;
ok ( len = = lstrlenW ( wbuffer ) * sizeof ( WCHAR ) , " Length wrong \n " ) ;
ok ( ( len < sizeof ( wbuffer ) - sizeof ( WCHAR ) ) & & ( wbuffer [ len / sizeof ( WCHAR ) ] = = 0 ) , " No NUL at end \n " ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
/* end of W version tests */
2007-08-16 01:29:58 +02:00
2008-08-28 01:54:17 +02:00
/* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
index = 0 ;
len = sizeof ( buffer ) ;
memset ( buffer , ' x ' , sizeof ( buffer ) ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_RAW_HEADERS_CRLF ,
buffer , & len , & index ) = = TRUE , " Query failed \n " ) ;
ok ( len = = 2 , " Expected 2, got %d \n " , len ) ;
ok ( strcmp ( buffer , " \r \n " ) = = 0 , " Expected CRLF, got '%s' \n " , buffer ) ;
ok ( index = = 0 , " Index was incremented \n " ) ;
2005-12-13 17:07:41 +01:00
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 15:53:30 +01:00
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test3 " , - 1 , HTTP_ADDREQ_FLAG_REPLACE ) , " Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE \n " ) ;
2005-12-13 17:07:41 +01: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 15:53:30 +01: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 17:07:41 +01: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 15:53:30 +01:00
ok ( InternetCloseHandle ( hRequest ) , " Close request handle failed \n " ) ;
2006-09-21 12:44:56 +02:00
done :
2005-11-22 15:53:30 +01:00
ok ( InternetCloseHandle ( hConnect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( hSession ) , " Close session handle failed \n " ) ;
}
2008-02-17 20:41:56 +01:00
static const char contmsg [ ] =
" HTTP/1.1 100 Continue \r \n " ;
2006-05-16 16:03:45 +02:00
static const char okmsg [ ] =
2008-02-17 20:41:56 +01:00
" HTTP/1.1 200 OK \r \n "
2006-05-16 16:03:45 +02:00
" Server: winetest \r \n "
" \r \n " ;
2008-12-01 15:35:05 +01:00
static const char okmsg2 [ ] =
" HTTP/1.1 200 OK \r \n "
" Date: Mon, 01 Dec 2008 13:44:34 GMT \r \n "
" Server: winetest \r \n "
" Content-Length: 0 \r \n "
" Set-Cookie: one \r \n "
" Set-Cookie: two \r \n "
" \r \n " ;
2007-08-09 21:43:25 +02:00
static const char notokmsg [ ] =
2008-02-17 20:41:56 +01:00
" HTTP/1.1 400 Bad Request \r \n "
2007-08-09 21:43:25 +02:00
" Server: winetest \r \n "
" \r \n " ;
static const char noauthmsg [ ] =
2008-02-17 20:41:56 +01:00
" HTTP/1.1 401 Unauthorized \r \n "
2007-08-09 21:43:25 +02:00
" Server: winetest \r \n "
2008-10-17 13:46:52 +02:00
" Connection: close \r \n "
" WWW-Authenticate: Basic realm= \" placebo \" \r \n "
2007-08-09 21:43:25 +02:00
" \r \n " ;
2006-05-30 15:55:16 +02: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 16:03:45 +02: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 ;
2007-11-26 23:07:34 +01:00
int r , c , i , on ;
SOCKET s ;
2006-05-16 16:03:45 +02:00
struct sockaddr_in sa ;
char buffer [ 0x100 ] ;
WSADATA wsaData ;
2006-05-30 15:55:16 +02:00
int last_request = 0 ;
2008-07-02 09:52:18 +02:00
char host_header [ 22 ] ;
2008-07-02 09:56:12 +02:00
static int test_b = 0 ;
2006-05-16 16:03:45 +02:00
WSAStartup ( MAKEWORD ( 1 , 1 ) , & wsaData ) ;
s = socket ( AF_INET , SOCK_STREAM , 0 ) ;
2007-11-26 23:07:34 +01:00
if ( s = = INVALID_SOCKET )
2006-05-30 15:55:16 +02:00
return 1 ;
on = 1 ;
setsockopt ( s , SOL_SOCKET , SO_REUSEADDR , ( char * ) & on , sizeof on ) ;
2006-05-16 16:03:45 +02: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 15:55:16 +02:00
listen ( s , 0 ) ;
2006-05-16 16:03:45 +02:00
SetEvent ( si - > hEvent ) ;
2008-07-02 09:52:18 +02:00
sprintf ( host_header , " Host: localhost:%d " , si - > port ) ;
2006-05-30 15:55:16 +02:00
do
2006-05-16 16:03:45 +02:00
{
2006-05-30 15:55:16 +02: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 " ) )
{
2008-02-02 16:08:28 +01:00
if ( ! strstr ( buffer , " Content-Length: 0 " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
2006-05-30 15:55:16 +02:00
}
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 ) ;
}
2007-08-09 21:43:25 +02:00
if ( strstr ( buffer , " /test3 " ) )
{
if ( strstr ( buffer , " Authorization: Basic dXNlcjpwd2Q= " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , noauthmsg , sizeof noauthmsg - 1 , 0 ) ;
}
if ( strstr ( buffer , " /test4 " ) )
{
if ( strstr ( buffer , " Connection: Close " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-02-02 16:08:28 +01:00
if ( strstr ( buffer , " POST /test5 " ) )
2007-10-28 16:32:46 +01:00
{
if ( strstr ( buffer , " Content-Length: 0 " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-02-17 20:41:56 +01:00
if ( strstr ( buffer , " GET /test6 " ) )
{
send ( c , contmsg , sizeof contmsg - 1 , 0 ) ;
send ( c , contmsg , sizeof contmsg - 1 , 0 ) ;
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
2008-05-09 13:12:42 +02:00
if ( strstr ( buffer , " POST /test7 " ) )
{
if ( strstr ( buffer , " Content-Length: 100 " ) )
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
}
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-05-31 21:47:24 +02:00
if ( strstr ( buffer , " /test8 " ) )
{
if ( ! strstr ( buffer , " Connection: Close " ) & &
2008-07-02 09:52:18 +02:00
strstr ( buffer , " Connection: Keep-Alive " ) & &
! strstr ( buffer , " Cache-Control: no-cache " ) & &
! strstr ( buffer , " Pragma: no-cache " ) & &
strstr ( buffer , host_header ) )
2008-05-31 21:47:24 +02:00
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
if ( strstr ( buffer , " /test9 " ) )
{
if ( ! strstr ( buffer , " Connection: Close " ) & &
2008-07-02 09:52:18 +02:00
! strstr ( buffer , " Connection: Keep-Alive " ) & &
! strstr ( buffer , " Cache-Control: no-cache " ) & &
! strstr ( buffer , " Pragma: no-cache " ) & &
strstr ( buffer , host_header ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
if ( strstr ( buffer , " /testA " ) )
{
if ( ! strstr ( buffer , " Connection: Close " ) & &
! strstr ( buffer , " Connection: Keep-Alive " ) & &
( strstr ( buffer , " Cache-Control: no-cache " ) | |
strstr ( buffer , " Pragma: no-cache " ) ) & &
strstr ( buffer , host_header ) )
2008-05-31 21:47:24 +02:00
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-07-02 09:56:12 +02:00
if ( ! test_b & & strstr ( buffer , " /testB HTTP/1.1 " ) )
{
test_b = 1 ;
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
recvfrom ( c , buffer , sizeof buffer , 0 , NULL , NULL ) ;
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
}
2008-07-19 19:55:39 +02:00
if ( strstr ( buffer , " /testC " ) )
{
if ( strstr ( buffer , " Cookie: cookie=biscuit " ) )
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
else
send ( c , notokmsg , sizeof notokmsg - 1 , 0 ) ;
}
2008-12-01 15:35:05 +01:00
if ( strstr ( buffer , " /testD " ) )
{
send ( c , okmsg2 , sizeof okmsg2 - 1 , 0 ) ;
}
2008-02-02 16:08:28 +01:00
if ( strstr ( buffer , " GET /quit " ) )
2006-05-30 15:55:16 +02:00
{
send ( c , okmsg , sizeof okmsg - 1 , 0 ) ;
send ( c , page1 , sizeof page1 - 1 , 0 ) ;
last_request = 1 ;
}
2006-05-16 16:03:45 +02:00
2006-05-30 15:55:16 +02:00
shutdown ( c , 2 ) ;
closesocket ( c ) ;
} while ( ! last_request ) ;
2006-05-16 16:03:45 +02:00
closesocket ( s ) ;
return 0 ;
}
2008-02-02 16:08:28 +01:00
static void test_basic_request ( int port , const char * verb , const char * url )
2006-05-16 16:03:45 +02:00
{
HINTERNET hi , hc , hr ;
2006-05-30 15:55:16 +02:00
DWORD r , count ;
2006-05-16 16:03:45 +02:00
char buffer [ 0x100 ] ;
2008-03-30 20:19:46 +02:00
hi = InternetOpen ( NULL , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
2006-05-16 16:03:45 +02:00
ok ( hi ! = NULL , " open failed \n " ) ;
2006-05-30 15:55:16 +02:00
hc = InternetConnect ( hi , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2006-05-16 16:03:45 +02:00
ok ( hc ! = NULL , " connect failed \n " ) ;
2008-02-02 16:08:28 +01:00
hr = HttpOpenRequest ( hc , verb , url , NULL , NULL , NULL , 0 , 0 ) ;
2006-05-16 16:03:45 +02: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 15:55:16 +02: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 20:24:35 +02:00
static CHAR username [ ] = " mike " ,
password [ ] = " 1101 " ;
2006-05-30 15:55:16 +02: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 */
2008-12-10 10:47:13 +01:00
hc = InternetConnect ( hi , " test.winehq.org/ " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2006-05-30 15:55:16 +02:00
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 20:24:35 +02:00
r = InternetSetOption ( hr , INTERNET_OPTION_PROXY_USERNAME , username , 4 ) ;
2006-05-30 15:55:16 +02:00
ok ( r , " failed to set user \n " ) ;
2006-08-10 20:24:35 +02:00
r = InternetSetOption ( hr , INTERNET_OPTION_PROXY_PASSWORD , password , 4 ) ;
2006-05-30 15:55:16 +02: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 ) ;
}
2007-08-09 21:43:25 +02:00
static void test_header_handling_order ( int port )
{
static char authorization [ ] = " Authorization: Basic dXNlcjpwd2Q= " ;
static char connection [ ] = " Connection: Close " ;
static const char * types [ 2 ] = { " * " , NULL } ;
HINTERNET session , connect , request ;
DWORD size , status ;
BOOL ret ;
session = InternetOpen ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( session ! = NULL , " InternetOpen failed \n " ) ;
connect = InternetConnect ( session , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
request = HttpOpenRequest ( connect , NULL , " /test3 " , NULL , NULL , types , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2009-01-03 20:15:06 +01:00
ret = HttpAddRequestHeaders ( request , authorization , ~ 0u , HTTP_ADDREQ_FLAG_ADD ) ;
2008-02-01 14:40:15 +01:00
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
ret = HttpSendRequest ( request , NULL , 0 , NULL , 0 ) ;
2007-08-09 21:43:25 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( request , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( status = = 200 , " request failed with status %u \n " , status ) ;
InternetCloseHandle ( request ) ;
request = HttpOpenRequest ( connect , NULL , " /test4 " , NULL , NULL , types , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2009-01-03 20:15:06 +01:00
ret = HttpSendRequest ( request , connection , ~ 0u , NULL , 0 ) ;
2007-08-09 21:43:25 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( request , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
2008-07-19 19:53:09 +02:00
ok ( status = = 200 | | status = = 400 /* IE6 */ , " got status %u, expected 200 or 400 \n " , status ) ;
2007-08-09 21:43:25 +02:00
2008-05-09 13:12:42 +02:00
InternetCloseHandle ( request ) ;
request = HttpOpenRequest ( connect , " POST " , " /test7 " , NULL , NULL , types , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
2009-01-03 20:15:06 +01:00
ret = HttpAddRequestHeaders ( request , " Content-Length: 100 \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) ;
2008-05-09 13:12:42 +02:00
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
2009-01-03 20:15:06 +01:00
ret = HttpSendRequest ( request , connection , ~ 0u , NULL , 0 ) ;
2008-05-09 13:12:42 +02:00
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( request , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
2008-07-19 19:53:09 +02:00
ok ( status = = 200 | | status = = 400 /* IE6 */ , " got status %u, expected 200 or 400 \n " , status ) ;
2008-05-09 13:12:42 +02:00
2007-08-09 21:43:25 +02:00
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2008-05-31 21:47:24 +02:00
static void test_connection_header ( int port )
{
HINTERNET ses , con , req ;
DWORD size , status ;
BOOL ret ;
ses = InternetOpen ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
con = InternetConnect ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
req = HttpOpenRequest ( con , NULL , " /test8 " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequest ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( status = = 200 , " request failed with status %u \n " , status ) ;
InternetCloseHandle ( req ) ;
req = HttpOpenRequest ( con , NULL , " /test9 " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequest ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
2008-07-02 09:52:18 +02:00
ok ( status = = 200 , " request failed with status %u \n " , status ) ;
InternetCloseHandle ( req ) ;
req = HttpOpenRequest ( con , NULL , " /test9 " , NULL , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequest ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( status = = 200 , " request failed with status %u \n " , status ) ;
InternetCloseHandle ( req ) ;
req = HttpOpenRequest ( con , " POST " , " /testA " , NULL , NULL , NULL , INTERNET_FLAG_NO_CACHE_WRITE , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequest ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
2008-05-31 21:47:24 +02:00
ok ( status = = 200 , " request failed with status %u \n " , status ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-07-02 09:56:12 +02:00
static void test_http1_1 ( int port )
{
HINTERNET ses , con , req ;
BOOL ret ;
ses = InternetOpen ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
con = InternetConnect ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
req = HttpOpenRequest ( con , NULL , " /testB " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequest ( req , NULL , 0 , NULL , 0 ) ;
if ( ret )
{
InternetCloseHandle ( req ) ;
req = HttpOpenRequest ( con , NULL , " /testB " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequest ( req , NULL , 0 , NULL , 0 ) ;
todo_wine
ok ( ret , " HttpSendRequest failed \n " ) ;
}
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-07-19 19:55:39 +02:00
static void test_cookie_header ( int port )
{
HINTERNET ses , con , req ;
DWORD size , status , error ;
BOOL ret ;
char buffer [ 64 ] ;
ses = InternetOpen ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
con = InternetConnect ( ses , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
InternetSetCookie ( " http://localhost " , " cookie " , " biscuit " ) ;
req = HttpOpenRequest ( con , NULL , " /testC " , NULL , NULL , NULL , INTERNET_FLAG_KEEP_CONNECTION , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
SetLastError ( 0xdeadbeef ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
error = GetLastError ( ) ;
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( error = = ERROR_HTTP_HEADER_NOT_FOUND , " got %u expected ERROR_HTTP_HEADER_NOT_FOUND \n " , error ) ;
ret = HttpSendRequest ( req , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed: %u \n " , GetLastError ( ) ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( status = = 200 , " request failed with status %u \n " , status ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed: %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buffer , " cookie=biscuit " ) , " got '%s' expected \' cookie=biscuit \' \n " , buffer ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-10-17 13:46:52 +02:00
static void test_basic_authentication ( int port )
{
HINTERNET session , connect , request ;
DWORD size , status ;
BOOL ret ;
session = InternetOpen ( " winetest " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( session ! = NULL , " InternetOpen failed \n " ) ;
connect = InternetConnect ( session , " localhost " , port , " user " , " pwd " , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( connect ! = NULL , " InternetConnect failed \n " ) ;
request = HttpOpenRequest ( connect , NULL , " /test3 " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( request ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequest ( request , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed %u \n " , GetLastError ( ) ) ;
status = 0 ;
size = sizeof ( status ) ;
ret = HttpQueryInfo ( request , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , & status , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( status = = 200 , " request failed with status %u \n " , status ) ;
InternetCloseHandle ( request ) ;
InternetCloseHandle ( connect ) ;
InternetCloseHandle ( session ) ;
}
2008-12-01 15:35:05 +01:00
static void test_HttpQueryInfo ( int port )
{
HINTERNET hi , hc , hr ;
DWORD size , index ;
char buffer [ 1024 ] ;
BOOL ret ;
hi = InternetOpen ( NULL , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( hi ! = NULL , " InternetOpen failed \n " ) ;
hc = InternetConnect ( hi , " localhost " , port , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
ok ( hc ! = NULL , " InternetConnect failed \n " ) ;
hr = HttpOpenRequest ( hc , NULL , " /testD " , NULL , NULL , NULL , 0 , 0 ) ;
ok ( hr ! = NULL , " HttpOpenRequest failed \n " ) ;
ret = HttpSendRequest ( hr , NULL , 0 , NULL , 0 ) ;
ok ( ret , " HttpSendRequest failed \n " ) ;
index = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_RAW_HEADERS , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_RAW_HEADERS , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_RAW_HEADERS_CRLF , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_STATUS_TEXT , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_VERSION , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_STATUS_CODE , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 0 , " expected 0 got %u \n " , index ) ;
index = 0xdeadbeef ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_FORWARDED , buffer , & size , & index ) ;
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( index = = 0xdeadbeef , " expected 0xdeadbeef got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_SERVER , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
strcpy ( buffer , " Server " ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_CUSTOM , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
index = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_SET_COOKIE , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 1 , " expected 1 got %u \n " , index ) ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( hr , HTTP_QUERY_SET_COOKIE , buffer , & size , & index ) ;
ok ( ret , " HttpQueryInfo failed %u \n " , GetLastError ( ) ) ;
ok ( index = = 2 , " expected 2 got %u \n " , index ) ;
InternetCloseHandle ( hr ) ;
InternetCloseHandle ( hc ) ;
InternetCloseHandle ( hi ) ;
}
2006-05-30 15:55:16 +02:00
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 ;
2008-02-02 16:08:28 +01:00
test_basic_request ( si . port , " GET " , " /test1 " ) ;
2006-05-30 15:55:16 +02:00
test_proxy_indirect ( si . port ) ;
test_proxy_direct ( si . port ) ;
2007-08-09 21:43:25 +02:00
test_header_handling_order ( si . port ) ;
2008-02-02 16:08:28 +01:00
test_basic_request ( si . port , " POST " , " /test5 " ) ;
2008-02-17 20:41:56 +01:00
test_basic_request ( si . port , " GET " , " /test6 " ) ;
2008-05-31 21:47:24 +02:00
test_connection_header ( si . port ) ;
2008-07-02 09:56:12 +02:00
test_http1_1 ( si . port ) ;
2008-07-19 19:55:39 +02:00
test_cookie_header ( si . port ) ;
2008-10-17 13:46:52 +02:00
test_basic_authentication ( si . port ) ;
2008-12-01 15:35:05 +01:00
test_HttpQueryInfo ( si . port ) ;
2006-05-30 15:55:16 +02:00
/* send the basic request again to shutdown the server thread */
2008-02-02 16:08:28 +01:00
test_basic_request ( si . port , " GET " , " /quit " ) ;
2006-05-16 16:03:45 +02:00
r = WaitForSingleObject ( hThread , 3000 ) ;
ok ( r = = WAIT_OBJECT_0 , " thread wait failed \n " ) ;
CloseHandle ( hThread ) ;
}
2005-11-22 15:53:30 +01:00
2008-05-02 21:59:24 +02:00
static void test_user_agent_header ( void )
{
HINTERNET ses , con , req ;
DWORD size , err ;
char buffer [ 64 ] ;
BOOL ret ;
ses = InternetOpen ( " Gizmo5 " , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 ) ;
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2008-12-10 10:47:13 +01:00
con = InternetConnect ( ses , " test.winehq.org " , 80 , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
2008-05-02 21:59:24 +02:00
ok ( con ! = NULL , " InternetConnect failed \n " ) ;
2008-12-10 10:47:13 +01:00
req = HttpOpenRequest ( con , " GET " , " /hello.html " , " HTTP/1.0 " , NULL , NULL , 0 , 0 ) ;
2008-05-02 21:59:24 +02:00
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
err = GetLastError ( ) ;
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( err = = ERROR_HTTP_HEADER_NOT_FOUND , " expected ERROR_HTTP_HEADER_NOT_FOUND, got %u \n " , err ) ;
2009-01-03 20:15:06 +01:00
ret = HttpAddRequestHeaders ( req , " User-Agent: Gizmo Project \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) ;
2008-05-02 21:59:24 +02:00
ok ( ret , " HttpAddRequestHeaders succeeded \n " ) ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
err = GetLastError ( ) ;
ok ( ret , " HttpQueryInfo failed \n " ) ;
ok ( err = = ERROR_HTTP_HEADER_NOT_FOUND , " expected ERROR_HTTP_HEADER_NOT_FOUND, got %u \n " , err ) ;
InternetCloseHandle ( req ) ;
req = HttpOpenRequest ( con , " GET " , " / " , " HTTP/1.0 " , NULL , NULL , 0 , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed \n " ) ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
err = GetLastError ( ) ;
ok ( ! ret , " HttpQueryInfo succeeded \n " ) ;
ok ( err = = ERROR_HTTP_HEADER_NOT_FOUND , " expected ERROR_HTTP_HEADER_NOT_FOUND, got %u \n " , err ) ;
2009-01-03 20:15:06 +01:00
ret = HttpAddRequestHeaders ( req , " Accept: audio/*, image/*, text/* \r \n User-Agent: Gizmo Project \r \n " , ~ 0u , HTTP_ADDREQ_FLAG_ADD_IF_NEW ) ;
2008-05-02 21:59:24 +02:00
ok ( ret , " HttpAddRequestHeaders failed \n " ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed: %u \n " , GetLastError ( ) ) ;
ok ( ! strcmp ( buffer , " audio/*, image/*, text/* " ) , " got '%s' expected 'audio/*, image/*, text/*' \n " , buffer ) ;
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-05-07 13:19:37 +02:00
static void test_bogus_accept_types_array ( void )
{
HINTERNET ses , con , req ;
2008-10-24 11:08:12 +02:00
static const char * types [ ] = { ( const char * ) 6240 , " */* " , " %p " , " " , ( const char * ) 0xffffffff , " */* " , NULL } ;
2008-05-07 13:19:37 +02:00
DWORD size ;
char buffer [ 32 ] ;
BOOL ret ;
ses = InternetOpen ( " MERONG(0.9/;p) " , INTERNET_OPEN_TYPE_DIRECT , " " , " " , 0 ) ;
con = InternetConnect ( ses , " www.winehq.org " , 80 , NULL , NULL , INTERNET_SERVICE_HTTP , 0 , 0 ) ;
req = HttpOpenRequest ( con , " POST " , " /post/post_action.php " , " HTTP/1.0 " , " " , types , INTERNET_FLAG_FORMS_SUBMIT , 0 ) ;
ok ( req ! = NULL , " HttpOpenRequest failed: %u \n " , GetLastError ( ) ) ;
buffer [ 0 ] = 0 ;
size = sizeof ( buffer ) ;
ret = HttpQueryInfo ( req , HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS , buffer , & size , NULL ) ;
ok ( ret , " HttpQueryInfo failed: %u \n " , GetLastError ( ) ) ;
2008-10-28 00:34:22 +01:00
ok ( ! strcmp ( buffer , " , */*, %p, , , */* " ) | | /* IE6 */
2008-05-09 15:11:49 +02:00
! strcmp ( buffer , " */*, %p, */* " ) ,
2008-10-28 00:34:22 +01:00
" got '%s' expected '*/*, %%p, */*' or ', */*, %%p, , , */*' \n " , buffer ) ;
2008-05-07 13:19:37 +02:00
InternetCloseHandle ( req ) ;
InternetCloseHandle ( con ) ;
InternetCloseHandle ( ses ) ;
}
2008-05-16 13:50:36 +02:00
struct context
{
HANDLE event ;
HINTERNET req ;
} ;
static void WINAPI cb ( HINTERNET handle , DWORD_PTR context , DWORD status , LPVOID info , DWORD size )
{
2008-05-31 21:46:34 +02:00
INTERNET_ASYNC_RESULT * result = info ;
struct context * ctx = ( struct context * ) context ;
2008-05-16 13:50:36 +02:00
trace ( " %p 0x%08lx %u %p 0x%08x \n " , handle , context , status , info , size ) ;
if ( status = = INTERNET_STATUS_REQUEST_COMPLETE )
{
trace ( " request handle: 0x%08lx \n " , result - > dwResult ) ;
ctx - > req = ( HINTERNET ) result - > dwResult ;
SetEvent ( ctx - > event ) ;
}
2008-05-31 21:46:34 +02:00
if ( status = = INTERNET_STATUS_HANDLE_CLOSING )
{
DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP , size = sizeof ( type ) ;
if ( InternetQueryOption ( handle , INTERNET_OPTION_HANDLE_TYPE , & type , & size ) )
ok ( type ! = INTERNET_HANDLE_TYPE_CONNECT_HTTP , " unexpected callback \n " ) ;
SetEvent ( ctx - > event ) ;
}
2008-05-16 13:50:36 +02:00
}
static void test_open_url_async ( void )
{
BOOL ret ;
HINTERNET ses , req ;
2008-10-06 15:48:04 +02:00
DWORD size , error ;
2008-05-16 13:50:36 +02:00
struct context ctx ;
ULONG type ;
ctx . req = NULL ;
ctx . event = CreateEvent ( NULL , TRUE , FALSE , " Z:_home_hans_jaman-installer.exe_ev1 " ) ;
ses = InternetOpen ( " AdvancedInstaller " , 0 , NULL , NULL , INTERNET_FLAG_ASYNC ) ;
ok ( ses ! = NULL , " InternetOpen failed \n " ) ;
2008-10-06 15:48:04 +02:00
SetLastError ( 0xdeadbeef ) ;
ret = InternetSetOptionA ( NULL , INTERNET_OPTION_CALLBACK , & cb , sizeof ( DWORD_PTR ) ) ;
error = GetLastError ( ) ;
ok ( ! ret , " InternetSetOptionA succeeded \n " ) ;
ok ( error = = ERROR_INTERNET_INCORRECT_HANDLE_TYPE , " got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE \n " , error ) ;
ret = InternetSetOptionA ( ses , INTERNET_OPTION_CALLBACK , & cb , sizeof ( DWORD_PTR ) ) ;
error = GetLastError ( ) ;
ok ( ! ret , " InternetSetOptionA failed \n " ) ;
ok ( error = = ERROR_INTERNET_OPTION_NOT_SETTABLE , " got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE \n " , error ) ;
2008-05-22 10:38:03 +02:00
pInternetSetStatusCallbackA ( ses , cb ) ;
2008-05-16 13:50:36 +02:00
ResetEvent ( ctx . event ) ;
2008-12-10 10:47:13 +01:00
req = InternetOpenUrl ( ses , " http://test.winehq.org " , NULL , 0 , 0 , ( DWORD_PTR ) & ctx ) ;
2008-05-16 13:50:36 +02:00
ok ( ! req & & GetLastError ( ) = = ERROR_IO_PENDING , " InternetOpenUrl failed \n " ) ;
WaitForSingleObject ( ctx . event , INFINITE ) ;
type = 0 ;
size = sizeof ( type ) ;
ret = InternetQueryOption ( ctx . req , INTERNET_OPTION_HANDLE_TYPE , & type , & size ) ;
2008-05-18 21:09:50 +02:00
ok ( ret , " InternetQueryOption failed: %u \n " , GetLastError ( ) ) ;
2008-05-16 13:50:36 +02:00
ok ( type = = INTERNET_HANDLE_TYPE_HTTP_REQUEST ,
" expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u \n " , type ) ;
2008-05-18 21:09:50 +02:00
size = 0 ;
ret = HttpQueryInfo ( ctx . req , HTTP_QUERY_RAW_HEADERS_CRLF , NULL , & size , NULL ) ;
ok ( ! ret & & GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER , " HttpQueryInfo failed \n " ) ;
ok ( size > 0 , " expected size > 0 \n " ) ;
2008-05-31 21:46:34 +02:00
ResetEvent ( ctx . event ) ;
2008-05-16 13:50:36 +02:00
InternetCloseHandle ( ctx . req ) ;
2008-05-31 21:46:34 +02:00
WaitForSingleObject ( ctx . event , INFINITE ) ;
2008-05-16 13:50:36 +02:00
InternetCloseHandle ( ses ) ;
2008-05-31 21:46:34 +02:00
CloseHandle ( ctx . event ) ;
2008-05-16 13:50:36 +02:00
}
2007-07-15 23:29:48 +02:00
# define STATUS_STRING(status) \
memcpy ( status_string [ status ] , # status , sizeof ( CHAR ) * \
( strlen ( # status ) < MAX_STATUS_NAME ? \
strlen ( # status ) : \
MAX_STATUS_NAME - 1 ) )
static void init_status_tests ( void )
{
memset ( expect , 0 , sizeof ( expect ) ) ;
2008-08-26 11:27:26 +02:00
memset ( optional , 0 , sizeof ( optional ) ) ;
2007-07-15 23:29:48 +02:00
memset ( wine_allow , 0 , sizeof ( wine_allow ) ) ;
memset ( notified , 0 , sizeof ( notified ) ) ;
memset ( status_string , 0 , sizeof ( status_string ) ) ;
STATUS_STRING ( INTERNET_STATUS_RESOLVING_NAME ) ;
STATUS_STRING ( INTERNET_STATUS_NAME_RESOLVED ) ;
STATUS_STRING ( INTERNET_STATUS_CONNECTING_TO_SERVER ) ;
STATUS_STRING ( INTERNET_STATUS_CONNECTED_TO_SERVER ) ;
STATUS_STRING ( INTERNET_STATUS_SENDING_REQUEST ) ;
STATUS_STRING ( INTERNET_STATUS_REQUEST_SENT ) ;
STATUS_STRING ( INTERNET_STATUS_RECEIVING_RESPONSE ) ;
STATUS_STRING ( INTERNET_STATUS_RESPONSE_RECEIVED ) ;
STATUS_STRING ( INTERNET_STATUS_CTL_RESPONSE_RECEIVED ) ;
STATUS_STRING ( INTERNET_STATUS_PREFETCH ) ;
STATUS_STRING ( INTERNET_STATUS_CLOSING_CONNECTION ) ;
STATUS_STRING ( INTERNET_STATUS_CONNECTION_CLOSED ) ;
STATUS_STRING ( INTERNET_STATUS_HANDLE_CREATED ) ;
STATUS_STRING ( INTERNET_STATUS_HANDLE_CLOSING ) ;
2008-05-06 23:58:31 +02:00
STATUS_STRING ( INTERNET_STATUS_DETECTING_PROXY ) ;
2007-07-15 23:29:48 +02:00
STATUS_STRING ( INTERNET_STATUS_REQUEST_COMPLETE ) ;
STATUS_STRING ( INTERNET_STATUS_REDIRECT ) ;
STATUS_STRING ( INTERNET_STATUS_INTERMEDIATE_RESPONSE ) ;
STATUS_STRING ( INTERNET_STATUS_USER_INPUT_REQUIRED ) ;
STATUS_STRING ( INTERNET_STATUS_STATE_CHANGE ) ;
STATUS_STRING ( INTERNET_STATUS_COOKIE_SENT ) ;
STATUS_STRING ( INTERNET_STATUS_COOKIE_RECEIVED ) ;
STATUS_STRING ( INTERNET_STATUS_PRIVACY_IMPACTED ) ;
STATUS_STRING ( INTERNET_STATUS_P3P_HEADER ) ;
STATUS_STRING ( INTERNET_STATUS_P3P_POLICYREF ) ;
STATUS_STRING ( INTERNET_STATUS_COOKIE_HISTORY ) ;
}
# undef STATUS_STRING
2002-06-22 01:59:49 +02:00
START_TEST ( http )
{
2007-02-20 15:53:49 +01:00
HMODULE hdll ;
hdll = GetModuleHandleA ( " wininet.dll " ) ;
pInternetSetStatusCallbackA = ( void * ) GetProcAddress ( hdll , " InternetSetStatusCallbackA " ) ;
if ( ! pInternetSetStatusCallbackA )
skip ( " skipping the InternetReadFile tests \n " ) ;
else
{
2007-07-15 23:29:48 +02:00
init_status_tests ( ) ;
2007-02-20 15:53:49 +01:00
InternetReadFile_test ( INTERNET_FLAG_ASYNC ) ;
InternetReadFile_test ( 0 ) ;
InternetReadFileExA_test ( INTERNET_FLAG_ASYNC ) ;
2008-05-22 10:38:03 +02:00
test_open_url_async ( ) ;
2007-02-20 15:53:49 +01:00
}
2007-02-12 15:19:17 +01:00
InternetOpenRequest_test ( ) ;
2008-02-13 13:33:42 +01:00
test_http_cache ( ) ;
2003-02-25 04:57:59 +01:00
InternetOpenUrlA_test ( ) ;
2005-11-21 16:17:55 +01:00
HttpSendRequestEx_test ( ) ;
2005-11-22 15:53:30 +01:00
HttpHeaders_test ( ) ;
2006-05-16 16:03:45 +02:00
test_http_connection ( ) ;
2008-05-02 21:59:24 +02:00
test_user_agent_header ( ) ;
2008-05-07 13:19:37 +02:00
test_bogus_accept_types_array ( ) ;
2002-06-22 01:59:49 +02:00
}