[WININET_APITEST] Add Download testcase (#1832)

CORE-16310
This commit is contained in:
Katayama Hirofumi MZ 2019-08-15 17:50:57 +09:00 committed by GitHub
parent 9990169aaa
commit 7464241ada
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 2 deletions

View file

@ -1,7 +1,7 @@
add_executable(wininet_apitest InternetOpen.c testlist.c)
add_executable(wininet_apitest Download.c InternetOpen.c testlist.c)
target_link_libraries(wininet_apitest wine)
set_module_type(wininet_apitest win32cui)
#add_delay_importlibs(wininet_apitest wininet)
add_importlibs(wininet_apitest msvcrt kernel32 ntdll)
add_importlibs(wininet_apitest wininet msvcrt kernel32 ntdll)
add_rostests_file(TARGET wininet_apitest)

View file

@ -0,0 +1,83 @@
/*
* PROJECT: ReactOS API Tests
* LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
* PURPOSE: wininet Download testcase
* COPYRIGHT: Copyright 2019 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
*/
#include <apitest.h>
#include <stdio.h>
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define COM_NO_WINDOWS_H
#include <windef.h>
#include <wininet.h>
#define FILENAME "download-testdata.txt"
#define TESTDATA "This is a test data.\r\n"
static void DoDownload1(const char *url, const char *filename)
{
HANDLE hFile;
HINTERNET hInternet, hConnect;
static const char s_header[] = "Accept: */" "*\r\n\r\n";
BYTE buffer[256];
DWORD cbRead;
BOOL ret;
hFile = CreateFileA(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
ok(hFile != INVALID_HANDLE_VALUE, "hFile was INVALID_HANDLE_VALUE.\n");
hInternet = InternetOpenA(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
ok(hInternet != NULL, "hInternet was NULL.\n");
hConnect = InternetOpenUrlA(hInternet, url, s_header, lstrlenA(s_header),
INTERNET_FLAG_DONT_CACHE, 0);
ok(hConnect != NULL, "hConnect was NULL.\n");
for (;;)
{
Sleep(100);
ret = InternetReadFile(hConnect, buffer, ARRAYSIZE(buffer), &cbRead);
if (!ret || !cbRead)
break;
if (!WriteFile(hFile, buffer, cbRead, &cbRead, NULL))
{
ok(0, "WriteFile returns FALSE.\n");
break;
}
}
ok_int(InternetCloseHandle(hConnect), TRUE);
ok_int(InternetCloseHandle(hInternet), TRUE);
CloseHandle(hFile);
}
static void DoDownload2(const char *url, const char *filename)
{
FILE *fp;
char buf[256];
DoDownload1(url, filename);
ok_int(GetFileAttributesA(FILENAME) != INVALID_FILE_ATTRIBUTES, TRUE);
fp = fopen(FILENAME, "rb");
ok(fp != NULL, "fp was NULL.\n");
ok(fgets(buf, ARRAYSIZE(buf), fp) != NULL, "fgets failed.\n");
ok_str(buf, TESTDATA);
fclose(fp);
DeleteFileA(FILENAME);
}
START_TEST(Download)
{
// https://tinyurl.com/y4cpy2fu
// -->
// https://raw.githubusercontent.com/katahiromz/downloads/master/download-testdata.txt
DoDownload2("https://tinyurl.com/y4cpy2fu", FILENAME);
DoDownload2(
"https://raw.githubusercontent.com/katahiromz/downloads/master/download-testdata.txt",
FILENAME);
}

View file

@ -3,10 +3,12 @@
#define STANDALONE
#include <apitest.h>
extern void func_Download(void);
extern void func_InternetOpen(void);
const struct test winetest_testlist[] =
{
{ "Download", func_Download },
{ "InternetOpen", func_InternetOpen },
{ 0, 0 }