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
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
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"
2002-10-29 22:24:35 +01:00
# include "wine/test.h"
2004-01-16 03:03:16 +01:00
# define TEST_URL "http: //www.winehq.org/site/about"
# define TEST_URL_PATH " / site / about"
2005-04-11 18:10:50 +02:00
# define TEST_URL2 "http: //www.myserver.com/myscript.php?arg=1"
# define TEST_URL2_SERVER "www.myserver.com"
# define TEST_URL2_PATH " / myscript.php"
# define TEST_URL2_PATHEXTRA " / myscript.php?arg=1"
# define TEST_URL2_EXTRA "?arg=1"
2005-05-24 13:43:35 +02:00
# define TEST_URL3 "file: ///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml"
2004-01-16 03:03:16 +01:00
2005-10-31 15:06:35 +01:00
# define CREATE_URL1 "http: //username:password@www.winehq.org/site/about"
# define CREATE_URL2 "http: //username@www.winehq.org/site/about"
# define CREATE_URL3 "http: //username:"
# define CREATE_URL4 "http: //www.winehq.org/site/about"
# define CREATE_URL5 "http: //"
# define CREATE_URL6 "nhtt: //username:password@www.winehq.org:80/site/about"
# define CREATE_URL7 "http: //username:password@www.winehq.org:42/site/about"
2005-11-16 12:21:41 +01:00
static HANDLE hCompleteEvent ;
2002-06-22 01:59:49 +02:00
2005-06-13 21:05:42 +02:00
static VOID WINAPI callback (
2002-06-22 01:59:49 +02:00
HINTERNET hInternet ,
DWORD dwContext ,
DWORD dwInternetStatus ,
LPVOID lpvStatusInformation ,
DWORD dwStatusInformationLength
)
{
switch ( dwInternetStatus )
{
case INTERNET_STATUS_RESOLVING_NAME :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \" %s \" %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_NAME_RESOLVED :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \" %s \" %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTING_TO_SERVER :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \" %s \" %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTED_TO_SERVER :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \" %s \" %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_SENDING_REQUEST :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %ld \n " ,
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 ) ,
" info length should be sizeof(DWORD) instead of %ld \n " ,
dwStatusInformationLength ) ;
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%lx %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( DWORD * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_RECEIVING_RESPONSE :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %ld \n " ,
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 ) ,
" info length should be sizeof(DWORD) instead of %ld \n " ,
dwStatusInformationLength ) ;
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%lx %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( DWORD * ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CTL_RESPONSE_RECEIVED :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_PREFETCH :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CLOSING_CONNECTION :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_CONNECTION_CLOSED :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %ld \n " ,
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 ) ,
" info length should be sizeof(HINTERNET) instead of %ld \n " ,
dwStatusInformationLength ) ;
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
* ( HINTERNET * ) lpvStatusInformation , dwStatusInformationLength ) ;
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 ) ,
" info length should be sizeof(HINTERNET) instead of %ld \n " ,
dwStatusInformationLength ) ;
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %ld \n " ,
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 ) ,
" info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %ld \n " ,
dwStatusInformationLength ) ;
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%ld} %ld \n " ,
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 :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \" %s \" %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
( LPCSTR ) lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
case INTERNET_STATUS_INTERMEDIATE_RESPONSE :
2005-11-16 12:21:41 +01:00
trace ( " %04lx:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %ld \n " ,
GetCurrentThreadId ( ) , hInternet , dwContext ,
lpvStatusInformation , dwStatusInformationLength ) ;
2002-06-22 01:59:49 +02:00
break ;
2005-11-16 12:21:41 +01:00
default :
trace ( " %04lx:Callback %p 0x%lx %ld %p %ld \n " ,
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
{
DWORD rc ;
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 ) ;
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %ld \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 ;
2002-06-22 01:59:49 +02:00
InternetSetStatusCallback ( hi , & callback ) ;
trace ( " InternetConnectA <-- \n " ) ;
2005-11-16 12:21:41 +01:00
hic = InternetConnectA ( hi , " www.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %ld \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 ;
2002-06-22 01:59:49 +02:00
trace ( " HttpOpenRequestA <-- \n " ) ;
2005-11-16 12:21:41 +01:00
hor = HttpOpenRequestA ( hic , " GET " , " /about/ " , NULL , NULL , types ,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE ,
0xdeadbead ) ;
if ( hor = = 0x0 & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) {
2002-10-09 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 {
2005-11-16 12:21:41 +01:00
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %ld \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 ;
2002-06-22 01:59:49 +02:00
trace ( " HttpSendRequestA --> \n " ) ;
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
rc = HttpSendRequestA ( hor , " " , - 1 , NULL , 0 ) ;
if ( flags & INTERNET_FLAG_ASYNC )
ok ( ( ( rc = = 0 ) & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
2002-06-22 01:59:49 +02:00
else
2005-11-16 12:21:41 +01:00
ok ( ( rc ! = 0 ) | | GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ,
2004-01-23 23:44:26 +01:00
" Synchronous HttpSendRequest returning 0, error %ld \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
length = 4 ;
2005-11-16 12:21:41 +01:00
rc = InternetQueryOptionA ( hor , INTERNET_OPTION_REQUEST_FLAGS , & out , & length ) ;
2002-06-22 01:59:49 +02:00
trace ( " Option 0x17 -> %li %li \n " , rc , out ) ;
length = 100 ;
2005-11-16 12:21:41 +01:00
rc = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
2002-06-22 01:59:49 +02:00
trace ( " Option 0x22 -> %li %s \n " , rc , buffer ) ;
length = 4000 ;
2005-11-16 12:21:41 +01:00
rc = HttpQueryInfoA ( hor , HTTP_QUERY_RAW_HEADERS , buffer , & length , 0x0 ) ;
2002-06-22 01:59:49 +02:00
buffer [ length ] = 0 ;
trace ( " Option 0x16 -> %li %s \n " , rc , buffer ) ;
length = 4000 ;
2005-11-16 12:21:41 +01:00
rc = InternetQueryOptionA ( hor , INTERNET_OPTION_URL , buffer , & length ) ;
2002-06-22 01:59:49 +02:00
buffer [ length ] = 0 ;
trace ( " Option 0x22 -> %li %s \n " , rc , buffer ) ;
length = 16 ;
2005-11-16 12:21:41 +01:00
rc = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_LENGTH , & buffer , & length , 0x0 ) ;
2002-06-22 01:59:49 +02:00
trace ( " Option 0x5 -> %li %s (%li) \n " , rc , buffer , GetLastError ( ) ) ;
length = 100 ;
2005-11-16 12:21:41 +01:00
rc = HttpQueryInfoA ( hor , HTTP_QUERY_CONTENT_TYPE , buffer , & length , 0x0 ) ;
2002-06-22 01:59:49 +02:00
buffer [ length ] = 0 ;
trace ( " Option 0x1 -> %li %s \n " , rc , buffer ) ;
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
rc = InternetReadFile ( NULL , buffer , 100 , & length ) ;
ok ( ! rc , " InternetReadFile should have failed \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_HANDLE ,
" InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %ld \n " ,
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
while ( length )
{
rc = InternetQueryDataAvailable ( hor , & length , 0x0 , 0x0 ) ;
2004-10-28 23:01:04 +02:00
ok ( ! ( rc = = 0 & & length ! = 0 ) , " InternetQueryDataAvailable failed \n " ) ;
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
rc = InternetReadFile ( hor , buffer , length , & length ) ;
buffer [ length ] = 0 ;
trace ( " ReadFile -> %li %li \n " , rc , length ) ;
HeapFree ( GetProcessHeap ( ) , 0 , buffer ) ;
}
}
2002-10-09 20:12:20 +02:00
abort :
if ( hor ! = 0x0 ) {
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
2002-10-09 20:12:20 +02:00
rc = InternetCloseHandle ( hor ) ;
2004-01-23 23:44:26 +01:00
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by HttpOpenRequestA failed \n " ) ;
2005-11-16 12:21:41 +01:00
SetLastError ( 0xdeadbeef ) ;
2004-09-24 00:53:04 +02:00
rc = InternetCloseHandle ( hor ) ;
ok ( ( rc = = 0 ) , " Double close of handle opened by HttpOpenRequestA succeeded \n " ) ;
2005-11-16 12:21:41 +01:00
ok ( GetLastError ( ) = = ERROR_INVALID_HANDLE ,
" Double close of handle should have set ERROR_INVALID_HANDLE instead of %ld \n " ,
GetLastError ( ) ) ;
2002-10-09 20:12:20 +02:00
}
2002-12-17 22:03:33 +01:00
if ( hic ! = 0x0 ) {
2002-10-09 20:12:20 +02:00
rc = InternetCloseHandle ( hic ) ;
2004-01-23 23:44:26 +01:00
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetConnectA failed \n " ) ;
2002-10-09 20:12:20 +02:00
}
if ( hi ! = 0x0 ) {
rc = InternetCloseHandle ( hi ) ;
2004-01-23 23:44:26 +01:00
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetOpenA failed \n " ) ;
2005-11-16 12:21:41 +01:00
if ( flags & INTERNET_FLAG_ASYNC )
Sleep ( 100 ) ;
}
CloseHandle ( hCompleteEvent ) ;
}
static void InternetReadFileExA_test ( int flags )
{
DWORD rc ;
DWORD length ;
const char * types [ 2 ] = { " * " , NULL } ;
HINTERNET hi , hic = 0 , hor = 0 ;
INTERNET_BUFFERS inetbuffers ;
hCompleteEvent = CreateEvent ( NULL , FALSE , FALSE , NULL ) ;
trace ( " Starting InternetReadFileExA test with flags 0x%x \n " , flags ) ;
trace ( " InternetOpenA <-- \n " ) ;
hi = InternetOpenA ( " " , INTERNET_OPEN_TYPE_PRECONFIG , NULL , NULL , flags ) ;
ok ( ( hi ! = 0x0 ) , " InternetOpen failed with error %ld \n " , GetLastError ( ) ) ;
trace ( " InternetOpenA --> \n " ) ;
if ( hi = = 0x0 ) goto abort ;
InternetSetStatusCallback ( hi , & callback ) ;
trace ( " InternetConnectA <-- \n " ) ;
hic = InternetConnectA ( hi , " www.winehq.org " , INTERNET_INVALID_PORT_NUMBER ,
NULL , NULL , INTERNET_SERVICE_HTTP , 0x0 , 0xdeadbeef ) ;
ok ( ( hic ! = 0x0 ) , " InternetConnect failed with error %ld \n " , GetLastError ( ) ) ;
trace ( " InternetConnectA --> \n " ) ;
if ( hic = = 0x0 ) goto abort ;
trace ( " HttpOpenRequestA <-- \n " ) ;
hor = HttpOpenRequestA ( hic , " GET " , " /about/ " , NULL , NULL , types ,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE ,
0xdeadbead ) ;
if ( hor = = 0x0 & & GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ) {
/*
* If the internet name can ' t be resolved we are probably behind
* a firewall or in some other way not directly connected to the
* Internet . Not enough reason to fail the test . Just ignore and
* abort .
*/
} else {
ok ( ( hor ! = 0x0 ) , " HttpOpenRequest failed with error %ld \n " , GetLastError ( ) ) ;
}
trace ( " HttpOpenRequestA --> \n " ) ;
if ( hor = = 0x0 ) goto abort ;
trace ( " HttpSendRequestA --> \n " ) ;
SetLastError ( 0xdeadbeef ) ;
rc = HttpSendRequestA ( hor , " " , - 1 , NULL , 0 ) ;
if ( flags & INTERNET_FLAG_ASYNC )
ok ( ( ( rc = = 0 ) & & ( GetLastError ( ) = = ERROR_IO_PENDING ) ) ,
" Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING \n " ) ;
else
ok ( ( rc ! = 0 ) | | GetLastError ( ) = = ERROR_INTERNET_NAME_NOT_RESOLVED ,
" Synchronous HttpSendRequest returning 0, error %ld \n " , GetLastError ( ) ) ;
trace ( " HttpSendRequestA <-- \n " ) ;
if ( ! rc & & ( GetLastError ( ) = = ERROR_IO_PENDING ) )
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
/* tests invalid dwStructSize */
inetbuffers . dwStructSize = sizeof ( INTERNET_BUFFERS ) + 1 ;
inetbuffers . lpcszHeader = NULL ;
inetbuffers . dwHeadersLength = 0 ;
inetbuffers . dwBufferLength = 10 ;
inetbuffers . lpvBuffer = HeapAlloc ( GetProcessHeap ( ) , 0 , 10 ) ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
rc = InternetReadFileEx ( hor , & inetbuffers , 0 , 0xdeadcafe ) ;
ok ( ! rc & & ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ) ,
" InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %ld \n " ,
rc ? " TRUE " : " FALSE " , GetLastError ( ) ) ;
HeapFree ( GetProcessHeap ( ) , 0 , inetbuffers . lpvBuffer ) ;
/* tests to see whether lpcszHeader is used - it isn't */
inetbuffers . dwStructSize = sizeof ( INTERNET_BUFFERS ) ;
inetbuffers . lpcszHeader = ( LPCTSTR ) 0xdeadbeef ;
inetbuffers . dwHeadersLength = 255 ;
inetbuffers . dwBufferLength = 0 ;
inetbuffers . lpvBuffer = NULL ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
rc = InternetReadFileEx ( hor , & inetbuffers , 0 , 0xdeadcafe ) ;
ok ( rc , " InternetReadFileEx failed with error %ld \n " , GetLastError ( ) ) ;
rc = InternetReadFileEx ( NULL , & inetbuffers , 0 , 0xdeadcafe ) ;
ok ( ! rc & & ( GetLastError ( ) = = ERROR_INVALID_HANDLE ) ,
" InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %ld \n " ,
rc ? " TRUE " : " FALSE " , GetLastError ( ) ) ;
length = 0 ;
trace ( " Entering Query loop \n " ) ;
while ( TRUE )
{
inetbuffers . dwStructSize = sizeof ( INTERNET_BUFFERS ) ;
inetbuffers . dwBufferLength = 1024 ;
inetbuffers . lpvBuffer = HeapAlloc ( GetProcessHeap ( ) , 0 , inetbuffers . dwBufferLength + 1 ) ;
inetbuffers . dwOffsetHigh = 1234 ;
inetbuffers . dwOffsetLow = 5678 ;
rc = InternetReadFileExA ( hor , & inetbuffers , IRF_ASYNC | IRF_USE_CONTEXT , 0xcafebabe ) ;
if ( ! rc )
{
if ( GetLastError ( ) = = ERROR_IO_PENDING )
{
trace ( " InternetReadFileEx -> PENDING \n " ) ;
WaitForSingleObject ( hCompleteEvent , INFINITE ) ;
}
else
{
trace ( " InternetReadFileEx -> FAILED %ld \n " , GetLastError ( ) ) ;
break ;
}
}
else
trace ( " InternetReadFileEx -> SUCCEEDED \n " ) ;
trace ( " read %li bytes \n " , inetbuffers . dwBufferLength ) ;
( ( char * ) inetbuffers . lpvBuffer ) [ inetbuffers . dwBufferLength ] = ' \0 ' ;
ok ( inetbuffers . dwOffsetHigh = = 1234 & & inetbuffers . dwOffsetLow = = 5678 ,
" InternetReadFileEx sets offsets to 0x%lx%08lx \n " ,
inetbuffers . dwOffsetHigh , inetbuffers . dwOffsetLow ) ;
HeapFree ( GetProcessHeap ( ) , 0 , inetbuffers . lpvBuffer ) ;
if ( ! inetbuffers . dwBufferLength )
break ;
length + = inetbuffers . dwBufferLength ;
}
trace ( " Finished. Read %ld bytes \n " , length ) ;
abort :
if ( hor ) {
rc = InternetCloseHandle ( hor ) ;
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by HttpOpenRequestA failed \n " ) ;
rc = InternetCloseHandle ( hor ) ;
ok ( ( rc = = 0 ) , " Double close of handle opened by HttpOpenRequestA succeeded \n " ) ;
}
if ( hic ) {
rc = InternetCloseHandle ( hic ) ;
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetConnectA failed \n " ) ;
}
if ( hi ) {
rc = InternetCloseHandle ( hi ) ;
ok ( ( rc ! = 0 ) , " InternetCloseHandle of handle opened by InternetOpenA failed \n " ) ;
if ( flags & INTERNET_FLAG_ASYNC )
2002-10-09 20:12:20 +02:00
Sleep ( 100 ) ;
}
2005-11-16 12:21:41 +01:00
CloseHandle ( hCompleteEvent ) ;
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 ] ;
URL_COMPONENTSA urlComponents ;
char protocol [ 32 ] , hostName [ 1024 ] , userName [ 1024 ] ;
char password [ 1024 ] , extra [ 1024 ] , path [ 1024 ] ;
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 ) ;
ok ( ( myhinternet ! = 0 ) , " InternetOpen failed, error %lx \n " , GetLastError ( ) ) ;
size = 0x400 ;
2004-12-27 18:26:37 +01:00
ret = InternetCanonicalizeUrl ( TEST_URL , buffer , & size , ICU_BROWSER_MODE ) ;
ok ( ret , " InternetCanonicalizeUrl failed, error %lx \n " , GetLastError ( ) ) ;
2003-02-25 04:57:59 +01:00
urlComponents . dwStructSize = sizeof ( URL_COMPONENTSA ) ;
urlComponents . lpszScheme = protocol ;
urlComponents . dwSchemeLength = 32 ;
urlComponents . lpszHostName = hostName ;
urlComponents . dwHostNameLength = 1024 ;
urlComponents . lpszUserName = userName ;
urlComponents . dwUserNameLength = 1024 ;
urlComponents . lpszPassword = password ;
urlComponents . dwPasswordLength = 1024 ;
urlComponents . lpszUrlPath = path ;
urlComponents . dwUrlPathLength = 2048 ;
urlComponents . lpszExtraInfo = extra ;
urlComponents . dwExtraInfoLength = 1024 ;
2004-12-27 18:26:37 +01:00
ret = InternetCrackUrl ( TEST_URL , 0 , 0 , & urlComponents ) ;
ok ( ret , " InternetCrackUrl failed, error %lx \n " , GetLastError ( ) ) ;
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 ) ;
2003-09-25 22:29:40 +02:00
if ( GetLastError ( ) = = 12007 )
return ; /* WinXP returns this when not connected to the net */
2003-02-25 04:57:59 +01:00
ok ( ( myhttp ! = 0 ) , " InternetOpenUrl failed, error %lx \n " , GetLastError ( ) ) ;
2004-12-27 18:26:37 +01:00
ret = InternetReadFile ( myhttp , buffer , 0x400 , & readbytes ) ;
ok ( ret , " InternetReadFile failed, error %lx \n " , GetLastError ( ) ) ;
2003-02-25 04:57:59 +01:00
totalbytes + = readbytes ;
while ( readbytes & & InternetReadFile ( myhttp , buffer , 0x400 , & readbytes ) )
totalbytes + = readbytes ;
2003-07-22 05:16:47 +02:00
trace ( " read 0x%08lx bytes \n " , totalbytes ) ;
2003-02-25 04:57:59 +01:00
}
2005-08-16 17:56:42 +02:00
static inline void copy_compsA (
URL_COMPONENTSA * src ,
URL_COMPONENTSA * dst ,
DWORD scheLen ,
DWORD hostLen ,
DWORD userLen ,
DWORD passLen ,
DWORD pathLen ,
DWORD extrLen )
{
* dst = * src ;
dst - > dwSchemeLength = scheLen ;
dst - > dwHostNameLength = hostLen ;
dst - > dwUserNameLength = userLen ;
dst - > dwPasswordLength = passLen ;
dst - > dwUrlPathLength = pathLen ;
dst - > dwExtraInfoLength = extrLen ;
SetLastError ( 0xfaceabad ) ;
}
static inline void zero_compsA (
URL_COMPONENTSA * dst ,
DWORD scheLen ,
DWORD hostLen ,
DWORD userLen ,
DWORD passLen ,
DWORD pathLen ,
DWORD extrLen )
{
ZeroMemory ( dst , sizeof ( URL_COMPONENTSA ) ) ;
dst - > dwStructSize = sizeof ( URL_COMPONENTSA ) ;
dst - > dwSchemeLength = scheLen ;
dst - > dwHostNameLength = hostLen ;
dst - > dwUserNameLength = userLen ;
dst - > dwPasswordLength = passLen ;
dst - > dwUrlPathLength = pathLen ;
dst - > dwExtraInfoLength = extrLen ;
SetLastError ( 0xfaceabad ) ;
}
2005-06-13 21:05:42 +02:00
static void InternetCrackUrl_test ( void )
2003-02-25 04:57:59 +01:00
{
2005-08-16 17:56:42 +02:00
URL_COMPONENTSA urlSrc , urlComponents ;
2003-02-25 04:57:59 +01:00
char protocol [ 32 ] , hostName [ 1024 ] , userName [ 1024 ] ;
char password [ 1024 ] , extra [ 1024 ] , path [ 1024 ] ;
2004-12-27 18:26:37 +01:00
BOOL ret ;
2005-08-17 11:53:57 +02:00
DWORD GLE ;
2003-02-25 04:57:59 +01:00
2005-08-16 17:56:42 +02:00
ZeroMemory ( & urlSrc , sizeof ( urlSrc ) ) ;
urlSrc . dwStructSize = sizeof ( urlSrc ) ;
urlSrc . lpszScheme = protocol ;
urlSrc . lpszHostName = hostName ;
urlSrc . lpszUserName = userName ;
urlSrc . lpszPassword = password ;
urlSrc . lpszUrlPath = path ;
urlSrc . lpszExtraInfo = extra ;
copy_compsA ( & urlSrc , & urlComponents , 32 , 1024 , 1024 , 1024 , 2048 , 1024 ) ;
2004-12-27 18:26:37 +01:00
ret = InternetCrackUrl ( TEST_URL , 0 , 0 , & urlComponents ) ;
ok ( ret , " InternetCrackUrl failed, error %lx \n " , GetLastError ( ) ) ;
2004-01-23 23:44:26 +01:00
ok ( ( strcmp ( TEST_URL_PATH , path ) = = 0 ) , " path cracked wrong \n " ) ;
2005-04-11 18:10:50 +02:00
/* Bug 1805: Confirm the returned lengths are correct: */
/* 1. When extra info split out explicitly */
2005-08-16 17:56:42 +02:00
zero_compsA ( & urlComponents , 0 , 1 , 0 , 0 , 1 , 1 ) ;
2005-04-11 18:10:50 +02:00
ok ( InternetCrackUrlA ( TEST_URL2 , 0 , 0 , & urlComponents ) , " InternetCrackUrl failed, error 0x%lx \n " , GetLastError ( ) ) ;
2005-09-29 12:33:20 +02:00
ok ( urlComponents . dwUrlPathLength = = strlen ( TEST_URL2_PATH ) , " .dwUrlPathLength should be %ld, but is %ld \n " , ( DWORD ) strlen ( TEST_URL2_PATH ) , urlComponents . dwUrlPathLength ) ;
2005-04-11 18:10:50 +02:00
ok ( ! strncmp ( urlComponents . lpszUrlPath , TEST_URL2_PATH , strlen ( TEST_URL2_PATH ) ) , " lpszUrlPath should be %s but is %s \n " , TEST_URL2_PATH , urlComponents . lpszUrlPath ) ;
2005-09-29 12:33:20 +02:00
ok ( urlComponents . dwHostNameLength = = strlen ( TEST_URL2_SERVER ) , " .dwHostNameLength should be %ld, but is %ld \n " , ( DWORD ) strlen ( TEST_URL2_SERVER ) , urlComponents . dwHostNameLength ) ;
2005-04-11 18:10:50 +02:00
ok ( ! strncmp ( urlComponents . lpszHostName , TEST_URL2_SERVER , strlen ( TEST_URL2_SERVER ) ) , " lpszHostName should be %s but is %s \n " , TEST_URL2_SERVER , urlComponents . lpszHostName ) ;
2005-09-29 12:33:20 +02:00
ok ( urlComponents . dwExtraInfoLength = = strlen ( TEST_URL2_EXTRA ) , " .dwExtraInfoLength should be %ld, but is %ld \n " , ( DWORD ) strlen ( TEST_URL2_EXTRA ) , urlComponents . dwExtraInfoLength ) ;
2005-04-11 18:10:50 +02:00
ok ( ! strncmp ( urlComponents . lpszExtraInfo , TEST_URL2_EXTRA , strlen ( TEST_URL2_EXTRA ) ) , " lpszExtraInfo should be %s but is %s \n " , TEST_URL2_EXTRA , urlComponents . lpszHostName ) ;
/* 2. When extra info is not split out explicitly and is in url path */
2005-08-16 17:56:42 +02:00
zero_compsA ( & urlComponents , 0 , 1 , 0 , 0 , 1 , 0 ) ;
2005-04-11 18:10:50 +02:00
ok ( InternetCrackUrlA ( TEST_URL2 , 0 , 0 , & urlComponents ) , " InternetCrackUrl failed with GLE 0x%lx \n " , GetLastError ( ) ) ;
2005-09-29 12:33:20 +02:00
ok ( urlComponents . dwUrlPathLength = = strlen ( TEST_URL2_PATHEXTRA ) , " .dwUrlPathLength should be %ld, but is %ld \n " , ( DWORD ) strlen ( TEST_URL2_PATHEXTRA ) , urlComponents . dwUrlPathLength ) ;
2005-04-11 18:10:50 +02:00
ok ( ! strncmp ( urlComponents . lpszUrlPath , TEST_URL2_PATHEXTRA , strlen ( TEST_URL2_PATHEXTRA ) ) , " lpszUrlPath should be %s but is %s \n " , TEST_URL2_PATHEXTRA , urlComponents . lpszUrlPath ) ;
2005-09-29 12:33:20 +02:00
ok ( urlComponents . dwHostNameLength = = strlen ( TEST_URL2_SERVER ) , " .dwHostNameLength should be %ld, but is %ld \n " , ( DWORD ) strlen ( TEST_URL2_SERVER ) , urlComponents . dwHostNameLength ) ;
2005-04-11 18:10:50 +02:00
ok ( ! strncmp ( urlComponents . lpszHostName , TEST_URL2_SERVER , strlen ( TEST_URL2_SERVER ) ) , " lpszHostName should be %s but is %s \n " , TEST_URL2_SERVER , urlComponents . lpszHostName ) ;
2005-05-24 13:43:35 +02:00
/*3. Check for %20 */
2005-08-17 11:53:57 +02:00
copy_compsA ( & urlSrc , & urlComponents , 32 , 1024 , 1024 , 1024 , 2048 , 1024 ) ;
2005-05-24 13:43:35 +02:00
ok ( InternetCrackUrlA ( TEST_URL3 , 0 , ICU_DECODE , & urlComponents ) , " InternetCrackUrl failed with GLE 0x%lx \n " , GetLastError ( ) ) ;
2005-08-17 11:53:57 +02:00
/* Tests for lpsz* members pointing to real strings while
* some corresponding length members are set to zero */
copy_compsA ( & urlSrc , & urlComponents , 0 , 1024 , 1024 , 1024 , 2048 , 1024 ) ;
ret = InternetCrackUrlA ( TEST_URL3 , 0 , ICU_DECODE , & urlComponents ) ;
ok ( ret = = 1 , " InternetCrackUrl returned %d with GLE=%ld (expected to return 1) \n " ,
ret , GetLastError ( ) ) ;
copy_compsA ( & urlSrc , & urlComponents , 32 , 0 , 1024 , 1024 , 2048 , 1024 ) ;
ret = InternetCrackUrlA ( TEST_URL3 , 0 , ICU_DECODE , & urlComponents ) ;
ok ( ret = = 1 , " InternetCrackUrl returned %d with GLE=%ld (expected to return 1) \n " ,
ret , GetLastError ( ) ) ;
copy_compsA ( & urlSrc , & urlComponents , 32 , 1024 , 0 , 1024 , 2048 , 1024 ) ;
ret = InternetCrackUrlA ( TEST_URL3 , 0 , ICU_DECODE , & urlComponents ) ;
ok ( ret = = 1 , " InternetCrackUrl returned %d with GLE=%ld (expected to return 1) \n " ,
ret , GetLastError ( ) ) ;
copy_compsA ( & urlSrc , & urlComponents , 32 , 1024 , 1024 , 0 , 2048 , 1024 ) ;
ret = InternetCrackUrlA ( TEST_URL3 , 0 , ICU_DECODE , & urlComponents ) ;
ok ( ret = = 1 , " InternetCrackUrl returned %d with GLE=%ld (expected to return 1) \n " ,
ret , GetLastError ( ) ) ;
copy_compsA ( & urlSrc , & urlComponents , 32 , 1024 , 1024 , 1024 , 0 , 1024 ) ;
ret = InternetCrackUrlA ( TEST_URL3 , 0 , ICU_DECODE , & urlComponents ) ;
GLE = GetLastError ( ) ;
todo_wine
ok ( ret = = 0 & & ( GLE = = ERROR_INVALID_HANDLE | | GLE = = ERROR_INSUFFICIENT_BUFFER ) ,
" InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER) \n " ,
ret , GLE ) ;
copy_compsA ( & urlSrc , & urlComponents , 32 , 1024 , 1024 , 1024 , 2048 , 0 ) ;
ret = InternetCrackUrlA ( TEST_URL3 , 0 , ICU_DECODE , & urlComponents ) ;
GLE = GetLastError ( ) ;
todo_wine
ok ( ret = = 0 & & ( GLE = = ERROR_INVALID_HANDLE | | GLE = = ERROR_INSUFFICIENT_BUFFER ) ,
" InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER) \n " ,
ret , GLE ) ;
copy_compsA ( & urlSrc , & urlComponents , 0 , 0 , 0 , 0 , 0 , 0 ) ;
ret = InternetCrackUrlA ( TEST_URL3 , 0 , ICU_DECODE , & urlComponents ) ;
GLE = GetLastError ( ) ;
todo_wine
ok ( ret = = 0 & & GLE = = ERROR_INVALID_PARAMETER ,
" InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_PARAMETER) \n " ,
ret , GLE ) ;
2003-02-25 04:57:59 +01:00
}
2002-06-22 01:59:49 +02:00
2005-06-13 21:05:42 +02:00
static void InternetCrackUrlW_test ( void )
2004-08-06 20:58:04 +02:00
{
WCHAR url [ ] = {
' h ' , ' t ' , ' t ' , ' p ' , ' : ' , ' / ' , ' / ' , ' 1 ' , ' 9 ' , ' 2 ' , ' . ' , ' 1 ' , ' 6 ' , ' 8 ' , ' . ' , ' 0 ' , ' . ' , ' 2 ' , ' 2 ' , ' / ' ,
' C ' , ' F ' , ' I ' , ' D ' , ' E ' , ' / ' , ' m ' , ' a ' , ' i ' , ' n ' , ' . ' , ' c ' , ' f ' , ' m ' , ' ? ' , ' C ' , ' F ' , ' S ' , ' V ' , ' R ' ,
' = ' , ' I ' , ' D ' , ' E ' , ' & ' , ' A ' , ' C ' , ' T ' , ' I ' , ' O ' , ' N ' , ' = ' , ' I ' , ' D ' , ' E ' , ' _ ' , ' D ' , ' E ' , ' F ' , ' A ' ,
' U ' , ' L ' , ' T ' , 0 } ;
URL_COMPONENTSW comp ;
WCHAR scheme [ 20 ] , host [ 20 ] , user [ 20 ] , pwd [ 20 ] , urlpart [ 50 ] , extra [ 50 ] ;
BOOL r ;
urlpart [ 0 ] = 0 ;
scheme [ 0 ] = 0 ;
extra [ 0 ] = 0 ;
host [ 0 ] = 0 ;
user [ 0 ] = 0 ;
pwd [ 0 ] = 0 ;
memset ( & comp , 0 , sizeof comp ) ;
comp . dwStructSize = sizeof comp ;
comp . lpszScheme = scheme ;
comp . dwSchemeLength = sizeof scheme ;
comp . lpszHostName = host ;
comp . dwHostNameLength = sizeof host ;
comp . lpszUserName = user ;
comp . dwUserNameLength = sizeof user ;
comp . lpszPassword = pwd ;
comp . dwPasswordLength = sizeof pwd ;
comp . lpszUrlPath = urlpart ;
comp . dwUrlPathLength = sizeof urlpart ;
comp . lpszExtraInfo = extra ;
comp . dwExtraInfoLength = sizeof extra ;
r = InternetCrackUrlW ( url , 0 , 0 , & comp ) ;
ok ( r , " failed to crack url \n " ) ;
ok ( comp . dwSchemeLength = = 4 , " scheme length wrong \n " ) ;
ok ( comp . dwHostNameLength = = 12 , " host length wrong \n " ) ;
ok ( comp . dwUserNameLength = = 0 , " user length wrong \n " ) ;
ok ( comp . dwPasswordLength = = 0 , " password length wrong \n " ) ;
ok ( comp . dwUrlPathLength = = 15 , " url length wrong \n " ) ;
ok ( comp . dwExtraInfoLength = = 29 , " extra length wrong \n " ) ;
urlpart [ 0 ] = 0 ;
scheme [ 0 ] = 0 ;
extra [ 0 ] = 0 ;
host [ 0 ] = 0 ;
user [ 0 ] = 0 ;
pwd [ 0 ] = 0 ;
memset ( & comp , 0 , sizeof comp ) ;
comp . dwStructSize = sizeof comp ;
comp . lpszHostName = host ;
comp . dwHostNameLength = sizeof host ;
comp . lpszUrlPath = urlpart ;
comp . dwUrlPathLength = sizeof urlpart ;
r = InternetCrackUrlW ( url , 0 , 0 , & comp ) ;
ok ( r , " failed to crack url \n " ) ;
ok ( comp . dwSchemeLength = = 0 , " scheme length wrong \n " ) ;
ok ( comp . dwHostNameLength = = 12 , " host length wrong \n " ) ;
ok ( comp . dwUserNameLength = = 0 , " user length wrong \n " ) ;
ok ( comp . dwPasswordLength = = 0 , " password length wrong \n " ) ;
ok ( comp . dwUrlPathLength = = 44 , " url length wrong \n " ) ;
ok ( comp . dwExtraInfoLength = = 0 , " extra length wrong \n " ) ;
urlpart [ 0 ] = 0 ;
scheme [ 0 ] = 0 ;
extra [ 0 ] = 0 ;
host [ 0 ] = 0 ;
user [ 0 ] = 0 ;
pwd [ 0 ] = 0 ;
memset ( & comp , 0 , sizeof comp ) ;
comp . dwStructSize = sizeof comp ;
comp . lpszHostName = host ;
comp . dwHostNameLength = sizeof host ;
comp . lpszUrlPath = urlpart ;
comp . dwUrlPathLength = sizeof urlpart ;
comp . lpszExtraInfo = NULL ;
comp . dwExtraInfoLength = sizeof extra ;
r = InternetCrackUrlW ( url , 0 , 0 , & comp ) ;
ok ( r , " failed to crack url \n " ) ;
ok ( comp . dwSchemeLength = = 0 , " scheme length wrong \n " ) ;
ok ( comp . dwHostNameLength = = 12 , " host length wrong \n " ) ;
ok ( comp . dwUserNameLength = = 0 , " user length wrong \n " ) ;
ok ( comp . dwPasswordLength = = 0 , " password length wrong \n " ) ;
ok ( comp . dwUrlPathLength = = 15 , " url length wrong \n " ) ;
ok ( comp . dwExtraInfoLength = = 29 , " extra length wrong \n " ) ;
}
2005-06-13 21:05:42 +02:00
static void InternetTimeFromSystemTimeA_test ( void )
2005-01-18 12:43:40 +01:00
{
BOOL ret ;
static const SYSTEMTIME time = { 2005 , 1 , 5 , 7 , 12 , 6 , 35 , 0 } ;
char string [ INTERNET_RFC1123_BUFSIZE ] ;
static const char expect [ ] = " Fri, 07 Jan 2005 12:06:35 GMT " ;
ret = InternetTimeFromSystemTimeA ( & time , INTERNET_RFC1123_FORMAT , string , sizeof ( string ) ) ;
ok ( ret , " InternetTimeFromSystemTimeA failed (%ld) \n " , GetLastError ( ) ) ;
ok ( ! memcmp ( string , expect , sizeof ( expect ) ) ,
" InternetTimeFromSystemTimeA failed (%ld) \n " , GetLastError ( ) ) ;
}
2005-06-13 21:05:42 +02:00
static void InternetTimeFromSystemTimeW_test ( void )
2005-01-18 12:43:40 +01:00
{
BOOL ret ;
static const SYSTEMTIME time = { 2005 , 1 , 5 , 7 , 12 , 6 , 35 , 0 } ;
WCHAR string [ INTERNET_RFC1123_BUFSIZE + 1 ] ;
static const WCHAR expect [ ] = { ' F ' , ' r ' , ' i ' , ' , ' , ' ' , ' 0 ' , ' 7 ' , ' ' , ' J ' , ' a ' , ' n ' , ' ' , ' 2 ' , ' 0 ' , ' 0 ' , ' 5 ' , ' ' ,
' 1 ' , ' 2 ' , ' : ' , ' 0 ' , ' 6 ' , ' : ' , ' 3 ' , ' 5 ' , ' ' , ' G ' , ' M ' , ' T ' , 0 } ;
ret = InternetTimeFromSystemTimeW ( & time , INTERNET_RFC1123_FORMAT , string , sizeof ( string ) ) ;
ok ( ret , " InternetTimeFromSystemTimeW failed (%ld) \n " , GetLastError ( ) ) ;
ok ( ! memcmp ( string , expect , sizeof ( expect ) ) ,
" InternetTimeFromSystemTimeW failed (%ld) \n " , GetLastError ( ) ) ;
}
2005-06-13 21:05:42 +02:00
static void InternetTimeToSystemTimeA_test ( void )
2005-01-18 12:43:40 +01:00
{
BOOL ret ;
SYSTEMTIME time ;
static const SYSTEMTIME expect = { 2005 , 1 , 5 , 7 , 12 , 6 , 35 , 0 } ;
static const char string [ ] = " Fri, 07 Jan 2005 12:06:35 GMT " ;
static const char string2 [ ] = " fri 7 jan 2005 12 06 35 " ;
ret = InternetTimeToSystemTimeA ( string , & time , 0 ) ;
ok ( ret , " InternetTimeToSystemTimeA failed (%ld) \n " , GetLastError ( ) ) ;
ok ( ! memcmp ( & time , & expect , sizeof ( expect ) ) ,
" InternetTimeToSystemTimeA failed (%ld) \n " , GetLastError ( ) ) ;
ret = InternetTimeToSystemTimeA ( string2 , & time , 0 ) ;
ok ( ret , " InternetTimeToSystemTimeA failed (%ld) \n " , GetLastError ( ) ) ;
ok ( ! memcmp ( & time , & expect , sizeof ( expect ) ) ,
" InternetTimeToSystemTimeA failed (%ld) \n " , GetLastError ( ) ) ;
}
2005-06-13 21:05:42 +02:00
static void InternetTimeToSystemTimeW_test ( void )
2005-01-18 12:43:40 +01:00
{
BOOL ret ;
SYSTEMTIME time ;
static const SYSTEMTIME expect = { 2005 , 1 , 5 , 7 , 12 , 6 , 35 , 0 } ;
static const WCHAR string [ ] = { ' F ' , ' r ' , ' i ' , ' , ' , ' ' , ' 0 ' , ' 7 ' , ' ' , ' J ' , ' a ' , ' n ' , ' ' , ' 2 ' , ' 0 ' , ' 0 ' , ' 5 ' , ' ' ,
' 1 ' , ' 2 ' , ' : ' , ' 0 ' , ' 6 ' , ' : ' , ' 3 ' , ' 5 ' , ' ' , ' G ' , ' M ' , ' T ' , 0 } ;
static const WCHAR string2 [ ] = { ' ' , ' f ' , ' r ' , ' i ' , ' ' , ' 7 ' , ' ' , ' j ' , ' a ' , ' n ' , ' ' , ' 2 ' , ' 0 ' , ' 0 ' , ' 5 ' , ' ' ,
' 1 ' , ' 2 ' , ' ' , ' 0 ' , ' 6 ' , ' ' , ' 3 ' , ' 5 ' , 0 } ;
static const WCHAR string3 [ ] = { ' F ' , ' r ' , 0 } ;
2005-03-17 19:55:41 +01:00
ret = InternetTimeToSystemTimeW ( NULL , NULL , 0 ) ;
ok ( ! ret , " InternetTimeToSystemTimeW succeeded (%ld) \n " , GetLastError ( ) ) ;
ret = InternetTimeToSystemTimeW ( NULL , & time , 0 ) ;
ok ( ! ret , " InternetTimeToSystemTimeW succeeded (%ld) \n " , GetLastError ( ) ) ;
ret = InternetTimeToSystemTimeW ( string , NULL , 0 ) ;
ok ( ! ret , " InternetTimeToSystemTimeW succeeded (%ld) \n " , GetLastError ( ) ) ;
ret = InternetTimeToSystemTimeW ( string , & time , 1 ) ;
ok ( ret , " InternetTimeToSystemTimeW failed (%ld) \n " , GetLastError ( ) ) ;
2005-01-18 12:43:40 +01:00
ret = InternetTimeToSystemTimeW ( string , & time , 0 ) ;
ok ( ret , " InternetTimeToSystemTimeW failed (%ld) \n " , GetLastError ( ) ) ;
ok ( ! memcmp ( & time , & expect , sizeof ( expect ) ) ,
" InternetTimeToSystemTimeW failed (%ld) \n " , GetLastError ( ) ) ;
ret = InternetTimeToSystemTimeW ( string2 , & time , 0 ) ;
ok ( ret , " InternetTimeToSystemTimeW failed (%ld) \n " , GetLastError ( ) ) ;
ok ( ! memcmp ( & time , & expect , sizeof ( expect ) ) ,
" InternetTimeToSystemTimeW failed (%ld) \n " , GetLastError ( ) ) ;
ret = InternetTimeToSystemTimeW ( string3 , & time , 0 ) ;
2005-03-17 19:55:41 +01:00
ok ( ret , " InternetTimeToSystemTimeW failed (%ld) \n " , GetLastError ( ) ) ;
2005-01-18 12:43:40 +01:00
}
2005-10-31 15:06:35 +01:00
static void fill_url_components ( LPURL_COMPONENTS lpUrlComponents )
{
lpUrlComponents - > dwStructSize = sizeof ( URL_COMPONENTS ) ;
lpUrlComponents - > lpszScheme = " http " ;
lpUrlComponents - > dwSchemeLength = strlen ( lpUrlComponents - > lpszScheme ) ;
lpUrlComponents - > nScheme = INTERNET_SCHEME_HTTP ;
lpUrlComponents - > lpszHostName = " www.winehq.org " ;
lpUrlComponents - > dwHostNameLength = strlen ( lpUrlComponents - > lpszHostName ) ;
lpUrlComponents - > nPort = 80 ;
lpUrlComponents - > lpszUserName = " username " ;
lpUrlComponents - > dwUserNameLength = strlen ( lpUrlComponents - > lpszUserName ) ;
lpUrlComponents - > lpszPassword = " password " ;
lpUrlComponents - > dwPasswordLength = strlen ( lpUrlComponents - > lpszPassword ) ;
lpUrlComponents - > lpszUrlPath = " /site/about " ;
lpUrlComponents - > dwUrlPathLength = strlen ( lpUrlComponents - > lpszUrlPath ) ;
lpUrlComponents - > lpszExtraInfo = " " ;
lpUrlComponents - > dwExtraInfoLength = strlen ( lpUrlComponents - > lpszExtraInfo ) ;
}
static void InternetCreateUrlA_test ( )
{
URL_COMPONENTS urlComp ;
LPSTR szUrl ;
DWORD len = - 1 ;
BOOL ret ;
/* test NULL lpUrlComponents */
ret = InternetCreateUrlA ( NULL , 0 , NULL , & len ) ;
SetLastError ( 0xdeadbeef ) ;
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = - 1 , " Expected len -1, got %ld \n " , len ) ;
/* test garbage lpUrlComponets */
ret = InternetCreateUrlA ( & urlComp , 0 , NULL , & len ) ;
SetLastError ( 0xdeadbeef ) ;
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = - 1 , " Expected len -1, got %ld \n " , len ) ;
/* test zero'ed lpUrlComponents */
ZeroMemory ( & urlComp , sizeof ( URL_COMPONENTS ) ) ;
SetLastError ( 0xdeadbeef ) ;
ret = InternetCreateUrlA ( & urlComp , 0 , NULL , & len ) ;
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" Expected ERROR_INVALID_PARAMETER, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = - 1 , " Expected len -1, got %ld \n " , len ) ;
/* test valid lpUrlComponets, NULL lpdwUrlLength */
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
ret = InternetCreateUrlA ( & urlComp , 0 , NULL , NULL ) ;
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" Expected ERROR_INVALID_PARAMETER, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = - 1 , " Expected len -1, got %ld \n " , len ) ;
/* test valid lpUrlComponets, emptry szUrl
* lpdwUrlLength is size of buffer required on exit , including
* the terminating null when GLE = = ERROR_INSUFFICIENT_BUFFER
*/
SetLastError ( 0xdeadbeef ) ;
ret = InternetCreateUrlA ( & urlComp , 0 , NULL , & len ) ;
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" Expected ERROR_INSUFFICIENT_BUFFER, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 51 , " Expected len 51, got %ld \n " , len ) ;
/* test correct size, NULL szUrl */
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
ret = InternetCreateUrlA ( & urlComp , 0 , NULL , & len ) ;
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" Expected ERROR_INSUFFICIENT_BUFFER, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 51 , " Expected len 51, got %ld \n " , len ) ;
/* test valid lpUrlComponets, alloced szUrl, small size */
SetLastError ( 0xdeadbeef ) ;
szUrl = HeapAlloc ( GetProcessHeap ( ) , 0 , len ) ;
len - = 2 ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_INSUFFICIENT_BUFFER ,
" Expected ERROR_INSUFFICIENT_BUFFER, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 51 , " Expected len 51, got %ld \n " , len ) ;
/* alloced szUrl, NULL lpszScheme
* shows that it uses dwXLength instead of strlen ( lpszX )
*/
SetLastError ( 0xdeadbeef ) ;
urlComp . lpszScheme = NULL ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 50 , " Expected len 50, got %ld \n " , len ) ;
/* alloced szUrl, invalid nScheme
* any nScheme out of range seems ignored
*/
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
urlComp . nScheme = - 3 ;
len + + ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 50 , " Expected len 50, got %ld \n " , len ) ;
/* test valid lpUrlComponets, alloced szUrl */
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
len = 51 ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 50 , " Expected len 50, got %ld \n " , len ) ;
ok ( strstr ( szUrl , " 80 " ) = = NULL , " Didn't expect to find 80 in szUrl \n " ) ;
ok ( ! strcmp ( szUrl , CREATE_URL1 ) , " Expected %s, got %s \n " , CREATE_URL1 , szUrl ) ;
/* valid username, NULL password */
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
urlComp . lpszPassword = NULL ;
len = 42 ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 41 , " Expected len 41, got %ld \n " , len ) ;
ok ( ! strcmp ( szUrl , CREATE_URL2 ) , " Expected %s, got %s \n " , CREATE_URL2 , szUrl ) ;
/* valid username, empty password */
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
urlComp . lpszPassword = " " ;
len = 51 ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 50 , " Expected len 50, got %ld \n " , len ) ;
ok ( ! strcmp ( szUrl , CREATE_URL3 ) , " Expected %s, got %s \n " , CREATE_URL2 , szUrl ) ;
/* valid password, NULL username
* if password is provided , username has to exist
*/
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
urlComp . lpszUserName = NULL ;
len = 42 ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ! ret , " Expected failure \n " ) ;
ok ( GetLastError ( ) = = ERROR_INVALID_PARAMETER ,
" Expected ERROR_INVALID_PARAMETER, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 42 , " Expected len 42, got %ld \n " , len ) ;
ok ( ! strcmp ( szUrl , CREATE_URL3 ) , " Expected %s, got %s \n " , CREATE_URL2 , szUrl ) ;
/* valid password, empty username
* if password is provided , username has to exist
*/
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
urlComp . lpszUserName = " " ;
len = 51 ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 50 , " Expected len 50, got %ld \n " , len ) ;
ok ( ! strcmp ( szUrl , CREATE_URL5 ) , " Expected %s, got %s \n " , CREATE_URL4 , szUrl ) ;
/* NULL username, NULL password */
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
urlComp . lpszUserName = NULL ;
urlComp . lpszPassword = NULL ;
len = 42 ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
2005-11-14 12:23:02 +01:00
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
2005-10-31 15:06:35 +01:00
ok ( len = = 32 , " Expected len 32, got %ld \n " , len ) ;
ok ( ! strcmp ( szUrl , CREATE_URL4 ) , " Expected %s, got %s \n " , CREATE_URL3 , szUrl ) ;
/* empty username, empty password */
fill_url_components ( & urlComp ) ;
SetLastError ( 0xdeadbeef ) ;
urlComp . lpszUserName = " " ;
urlComp . lpszPassword = " " ;
len = 51 ;
ret = InternetCreateUrlA ( & urlComp , 0 , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( GetLastError ( ) = = 0xdeadbeef ,
" Expected 0xdeadbeef, got %ld \n " , GetLastError ( ) ) ;
ok ( len = = 50 , " Expected len 50, got %ld \n " , len ) ;
ok ( ! strcmp ( szUrl , CREATE_URL5 ) , " Expected %s, got %s \n " , CREATE_URL4 , szUrl ) ;
/* if lpszScheme != "http" or nPort != 80, display nPort.
* depending on nScheme , displays only first x characters
* of lpszScheme :
* HTTP : x = 4
* FTP : x = 3 etc
*/
fill_url_components ( & urlComp ) ;
HeapFree ( GetProcessHeap ( ) , 0 , szUrl ) ;
urlComp . lpszScheme = " nhttp " ;
len = 54 ;
szUrl = HeapAlloc ( GetProcessHeap ( ) , 0 , len ) ;
ret = InternetCreateUrlA ( & urlComp , ICU_ESCAPE , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( len = = 53 , " Expected len 51, got %ld \n " , len ) ;
ok ( strstr ( szUrl , " 80 " ) ! = NULL , " Expected to find 80 in szUrl \n " ) ;
ok ( ! strncmp ( szUrl , " nhtt:// " , 7 ) , " Expected 'nhtt://' \n " ) ;
ok ( ! strcmp ( szUrl , CREATE_URL6 ) , " Expected %s, got %s \n " , CREATE_URL5 , szUrl ) ;
/* if lpszScheme != "http" or nPort != 80, display nPort */
HeapFree ( GetProcessHeap ( ) , 0 , szUrl ) ;
urlComp . lpszScheme = " http " ;
urlComp . nPort = 42 ;
szUrl = HeapAlloc ( GetProcessHeap ( ) , 0 , + + len ) ;
ret = InternetCreateUrlA ( & urlComp , ICU_ESCAPE , szUrl , & len ) ;
ok ( ret , " Expected success \n " ) ;
ok ( len = = 53 , " Expected len 53, got %ld \n " , len ) ;
ok ( strstr ( szUrl , " 42 " ) ! = NULL , " Expected to find 42 in szUrl \n " ) ;
ok ( ! strcmp ( szUrl , CREATE_URL7 ) , " Expected %s, got %s \n " , CREATE_URL6 , szUrl ) ;
HeapFree ( GetProcessHeap ( ) , 0 , szUrl ) ;
}
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
static const char szPostData [ ] = " mode=Test " ;
static const char szContentType [ ] = " Content-Type: application/x-www-form-urlencoded " ;
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 ) ;
ok ( hRequest ! = NULL , " Failed to open request handle \n " ) ;
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 ;
BufferIn . dwHeadersLength = sizeof ( szContentType ) ;
BufferIn . dwHeadersTotal = sizeof ( szContentType ) ;
2005-11-30 12:31:38 +01:00
BufferIn . lpvBuffer = ( LPVOID ) szPostData ;
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 ) ;
ok ( ret , " HttpSendRequestEx Failed with error %ld \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 ;
ok ( dwBytesRead = = 13 , " Read %lu bytes instead of 13 \n " , dwBytesRead ) ;
ok ( strncmp ( szBuffer , " mode => Test \n " , dwBytesRead ) = = 0 , " Got string %s \n " , szBuffer ) ;
ok ( InternetCloseHandle ( hRequest ) , " Close request handle failed \n " ) ;
ok ( InternetCloseHandle ( hConnect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( hSession ) , " 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 ] ;
DWORD len = 256 ;
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 ) ;
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 ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) = = 0 , " Second Index Should Not Exist \n " ) ;
ok ( HttpAddRequestHeaders ( hRequest , " Warning:test2 " , - 1 , HTTP_ADDREQ_FLAG_ADD ) ,
" Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD \n " ) ;
index = 0 ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Unable to query header \n " ) ;
ok ( index = = 1 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test1 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) , " Failed to get second header \n " ) ;
ok ( index = = 2 , " Index was not incremented \n " ) ;
ok ( strcmp ( buffer , " test2 " ) = = 0 , " incorrect string was returned(%s) \n " , buffer ) ;
len = sizeof ( buffer ) ;
strcpy ( buffer , " Warning " ) ;
ok ( HttpQueryInfo ( hRequest , HTTP_QUERY_CUSTOM | HTTP_QUERY_FLAG_REQUEST_HEADERS ,
buffer , & len , & index ) = = 0 , " Third Header Should Not Exist \n " ) ;
2005-11-22 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 " ) ;
ok ( InternetCloseHandle ( hConnect ) , " Close connect handle failed \n " ) ;
ok ( InternetCloseHandle ( hSession ) , " Close session handle failed \n " ) ;
}
2002-06-22 01:59:49 +02:00
START_TEST ( http )
{
2005-11-16 12:21:41 +01:00
InternetReadFile_test ( INTERNET_FLAG_ASYNC ) ;
InternetReadFile_test ( 0 ) ;
InternetReadFileExA_test ( INTERNET_FLAG_ASYNC ) ;
2003-02-25 04:57:59 +01:00
InternetCrackUrl_test ( ) ;
InternetOpenUrlA_test ( ) ;
2004-08-06 20:58:04 +02:00
InternetCrackUrlW_test ( ) ;
2005-01-18 12:43:40 +01:00
InternetTimeFromSystemTimeA_test ( ) ;
InternetTimeFromSystemTimeW_test ( ) ;
InternetTimeToSystemTimeA_test ( ) ;
InternetTimeToSystemTimeW_test ( ) ;
2005-10-31 15:06:35 +01:00
InternetCreateUrlA_test ( ) ;
2005-11-21 16:17:55 +01:00
HttpSendRequestEx_test ( ) ;
2005-11-22 15:53:30 +01:00
HttpHeaders_test ( ) ;
2002-06-22 01:59:49 +02:00
}