[WININET_APITEST] Add Download testcase (#1832)
authorKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Thu, 15 Aug 2019 08:50:57 +0000 (17:50 +0900)
committerGitHub <noreply@github.com>
Thu, 15 Aug 2019 08:50:57 +0000 (17:50 +0900)
CORE-16310

modules/rostests/apitests/wininet/CMakeLists.txt
modules/rostests/apitests/wininet/Download.c [new file with mode: 0644]
modules/rostests/apitests/wininet/testlist.c

index fb18c91..45baa40 100644 (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)
 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)
 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 (file)
index 0000000..307f532
--- /dev/null
@@ -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);
+}
index 16c84d6..801c8c4 100644 (file)
@@ -3,10 +3,12 @@
 #define STANDALONE
 #include <apitest.h>
 
 #define STANDALONE
 #include <apitest.h>
 
+extern void func_Download(void);
 extern void func_InternetOpen(void);
 
 const struct test winetest_testlist[] =
 {
 extern void func_InternetOpen(void);
 
 const struct test winetest_testlist[] =
 {
+    { "Download", func_Download },
     { "InternetOpen", func_InternetOpen },
 
     { 0, 0 }
     { "InternetOpen", func_InternetOpen },
 
     { 0, 0 }