https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7464241adabfbdfec5a05…
commit 7464241adabfbdfec5a058697632a8d3938479fb
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Thu Aug 15 17:50:57 2019 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Thu Aug 15 17:50:57 2019 +0900
[WININET_APITEST] Add Download testcase (#1832)
CORE-16310
---
modules/rostests/apitests/wininet/CMakeLists.txt | 4 +-
modules/rostests/apitests/wininet/Download.c | 83 ++++++++++++++++++++++++
modules/rostests/apitests/wininet/testlist.c | 2 +
3 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/modules/rostests/apitests/wininet/CMakeLists.txt
b/modules/rostests/apitests/wininet/CMakeLists.txt
index fb18c91ac17..45baa402dda 100644
--- a/modules/rostests/apitests/wininet/CMakeLists.txt
+++ b/modules/rostests/apitests/wininet/CMakeLists.txt
@@ -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)
diff --git a/modules/rostests/apitests/wininet/Download.c
b/modules/rostests/apitests/wininet/Download.c
new file mode 100644
index 00000000000..307f532f065
--- /dev/null
+++ b/modules/rostests/apitests/wininet/Download.c
@@ -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(a)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-test…
+
DoDownload2("https://tinyurl.com/y4cpy2fu"y2fu", FILENAME);
+
+ DoDownload2(
+
"https://raw.githubusercontent.com/katahiromz/downloads/master/download-testdata.txt",
+ FILENAME);
+}
diff --git a/modules/rostests/apitests/wininet/testlist.c
b/modules/rostests/apitests/wininet/testlist.c
index 16c84d6f87f..801c8c4d42e 100644
--- a/modules/rostests/apitests/wininet/testlist.c
+++ b/modules/rostests/apitests/wininet/testlist.c
@@ -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 }