wininet/tests: Add a test for reading chunked data.

This commit is contained in:
Alexandre Julliard 2009-05-14 16:49:19 +02:00
parent 3d02c42b39
commit bb5d973127
1 changed files with 109 additions and 0 deletions

View File

@ -493,6 +493,114 @@ abort:
first_connection_to_test_url = FALSE;
}
static void InternetReadFile_chunked_test(void)
{
BOOL res;
CHAR buffer[4000];
DWORD length;
const char *types[2] = { "*", NULL };
HINTERNET hi, hic = 0, hor = 0;
trace("Starting InternetReadFile chunked test\n");
trace("InternetOpenA <--\n");
hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
trace("InternetOpenA -->\n");
if (hi == 0x0) goto abort;
trace("InternetConnectA <--\n");
hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
trace("InternetConnectA -->\n");
if (hic == 0x0) goto abort;
trace("HttpOpenRequestA <--\n");
hor = HttpOpenRequestA(hic, "GET", "/testchunked", 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 %u\n", GetLastError());
}
trace("HttpOpenRequestA -->\n");
if (hor == 0x0) goto abort;
trace("HttpSendRequestA -->\n");
SetLastError(0xdeadbeef);
res = HttpSendRequestA(hor, "", -1, NULL, 0);
ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
"Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
trace("HttpSendRequestA <--\n");
length = 100;
res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
buffer[length]=0;
trace("Option CONTENT_TYPE -> %i %s\n",res,buffer);
SetLastError( 0xdeadbeef );
length = 100;
res = HttpQueryInfoA(hor,HTTP_QUERY_TRANSFER_ENCODING,buffer,&length,0x0);
buffer[length]=0;
trace("Option TRANSFER_ENCODING -> %i %s\n",res,buffer);
ok( res, "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
ok( !strcmp( buffer, "chunked" ), "Wrong transfer encoding '%s'\n", buffer );
SetLastError( 0xdeadbeef );
length = 16;
res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
ok( !res, "Found CONTENT_LENGTH option '%s'\n", buffer );
ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Wrong error %u\n", GetLastError() );
length = 100;
trace("Entering Query loop\n");
while (TRUE)
{
res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
ok(!(!res && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
ok(res, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
trace("got %u available\n",length);
if (length)
{
DWORD got;
char *buffer = HeapAlloc(GetProcessHeap(),0,length+1);
res = InternetReadFile(hor,buffer,length,&got);
buffer[got]=0;
trace("ReadFile -> %i %i\n",res,got);
ok( length == got, "only got %u of %u available\n", got, length );
ok( buffer[got-1] == '\n', "received partial line '%s'\n", buffer );
HeapFree(GetProcessHeap(),0,buffer);
if (!got) break;
}
if (length == 0)
break;
}
abort:
trace("aborting\n");
if (hor != 0x0) {
res = InternetCloseHandle(hor);
ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
}
if (hi != 0x0) {
res = InternetCloseHandle(hi);
ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
}
}
static void InternetReadFileExA_test(int flags)
{
DWORD rc;
@ -2571,5 +2679,6 @@ START_TEST(http)
test_http_connection();
test_user_agent_header();
test_bogus_accept_types_array();
InternetReadFile_chunked_test();
HttpSendRequestEx_test();
}