[WININET_WINETEST] Sync with Wine Staging 4.18. CORE-16441
[reactos.git] / modules / rostests / winetests / wininet / internet.c
index a83583a..13b2930 100644 (file)
 
 #include <stdarg.h>
 #include <stdio.h>
-//#include <string.h>
+#include <string.h>
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "wininet.h"
+#include "winerror.h"
+#include "winreg.h"
 
-#include <windef.h>
-#include <winbase.h>
-#include <winuser.h>
-#include <wininet.h>
-//#include "winerror.h"
-#include <winreg.h>
-
-#include <wine/test.h>
+#include "wine/test.h"
 
 static BOOL (WINAPI *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
                                                 DWORD, DWORD, DWORD, DWORD);
@@ -630,7 +629,7 @@ static void test_cookie_url(void)
     ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
        "InternetGetCookeA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
 
-    len = sizeof(bufw)/sizeof(*bufw);
+    len = ARRAY_SIZE(bufw);
     res = InternetGetCookieW(about_blankW, NULL, bufw, &len);
     ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
        "InternetGetCookeW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
@@ -640,7 +639,7 @@ static void test_cookie_url(void)
     ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
        "InternetGetCookeExA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
 
-    len = sizeof(bufw)/sizeof(*bufw);
+    len = ARRAY_SIZE(bufw);
     res = pInternetGetCookieExW(about_blankW, NULL, bufw, &len, 0, NULL);
     ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
        "InternetGetCookeExW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
@@ -888,7 +887,7 @@ static void InternetTimeFromSystemTimeW_test(void)
 
     /* test too small buffer size */
     SetLastError(0xdeadbeef);
-    ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
+    ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, ARRAY_SIZE(string));
     error = GetLastError();
     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
     ok( error == ERROR_INSUFFICIENT_BUFFER,
@@ -1085,7 +1084,7 @@ static void test_PrivacyGetSetZonePreferenceW(void)
     trace("template %u\n", old_template);
 
     if(old_template == PRIVACY_TEMPLATE_ADVANCED) {
-        pref_size = sizeof(pref)/sizeof(WCHAR);
+        pref_size = ARRAY_SIZE(pref);
         ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, pref, &pref_size);
         ok(ret == 0, "expected ret == 0, got %u\n", ret);
     }
@@ -1166,6 +1165,28 @@ static void test_InternetSetOption(void)
     ok(ret == FALSE, "InternetSetOption should've failed\n");
     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
 
+    ret = InternetSetOptionA(req, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
+    ok(ret == TRUE, "InternetSetOption should've succeeded\n");
+
+    ret = InternetSetOptionA(con, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
+    ok(ret == TRUE, "InternetSetOption should've succeeded\n");
+
+    ret = InternetSetOptionA(ses, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
+    ok(ret == TRUE, "InternetSetOption should've succeeded\n");
+
+    ret = InternetSetOptionA(ses, INTERNET_OPTION_REFRESH, NULL, 0);
+    ok(ret == TRUE, "InternetSetOption should've succeeded\n");
+
+    SetLastError(0xdeadbeef);
+    ret = InternetSetOptionA(req, INTERNET_OPTION_REFRESH, NULL, 0);
+    ok(ret == FALSE, "InternetSetOption should've failed\n");
+    ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %u\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    ret = InternetSetOptionA(con, INTERNET_OPTION_REFRESH, NULL, 0);
+    ok(ret == FALSE, "InternetSetOption should've failed\n");
+    ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %u\n", GetLastError());
+
     ret = InternetCloseHandle(req);
     ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
     ret = InternetCloseHandle(con);
@@ -1534,14 +1555,11 @@ static void test_InternetErrorDlg(void)
         /* Handle some special cases */
         switch(i)
         {
-        case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
-        case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
+        case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR: /* later 9.x versions */
+        case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR: /* later 9.x versions */
+        case ERROR_INTERNET_SEC_CERT_WEAK_SIGNATURE: /* later 11.x versions */
             if(res == ERROR_CANCELLED)
-            {
-                /* Some windows XP, w2k3 x64, W2K8 */
-                win_skip("Skipping some tests for %d\n", i);
-                continue;
-            }
+                expected = ERROR_CANCELLED;
             break;
         case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
             if(res != expected)
@@ -1700,7 +1718,7 @@ static void test_InternetGetConnectedStateExW(void)
 
     flags = 0;
     buffer[0] = 0;
-    res = pInternetGetConnectedStateExW(&flags, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
+    res = pInternetGetConnectedStateExW(&flags, buffer, ARRAY_SIZE(buffer), 0);
     trace("Internet Connection: Flags 0x%02x - Name '%s'\n", flags, wine_dbgstr_w(buffer));
 todo_wine
     ok (flags & INTERNET_RAS_INSTALLED, "Missing RAS flag\n");
@@ -1734,21 +1752,21 @@ todo_wine
     ok(!buffer[0], "Buffer must not change, got %02X\n", buffer[0]);
 
     buffer[0] = 0;
-    res = pInternetGetConnectedStateExW(NULL, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
+    res = pInternetGetConnectedStateExW(NULL, buffer, ARRAY_SIZE(buffer), 0);
     ok(res == TRUE, "Expected TRUE, got %d\n", res);
     sz = lstrlenW(buffer);
     ok(sz > 0, "Expected a connection name\n");
 
     buffer[0] = 0;
     flags = 0;
-    res = pInternetGetConnectedStateExW(&flags, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
+    res = pInternetGetConnectedStateExW(&flags, buffer, ARRAY_SIZE(buffer), 0);
     ok(res == TRUE, "Expected TRUE, got %d\n", res);
     ok(flags, "Expected at least one flag set\n");
     sz = lstrlenW(buffer);
     ok(sz > 0, "Expected a connection name\n");
 
     flags = 0;
-    res = pInternetGetConnectedStateExW(&flags, NULL, sizeof(buffer) / sizeof(buffer[0]), 0);
+    res = pInternetGetConnectedStateExW(&flags, NULL, ARRAY_SIZE(buffer), 0);
     ok(res == TRUE, "Expected TRUE, got %d\n", res);
     ok(flags, "Expected at least one flag set\n");
 
@@ -1798,6 +1816,65 @@ todo_wine
     ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
 }
 
+static void test_format_message(HMODULE hdll)
+{
+    DWORD ret;
+    CHAR out[0x100];
+
+    /* These messages come from wininet and not the system. */
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM , NULL, ERROR_INTERNET_TIMEOUT,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret == 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_TIMEOUT,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_INTERNAL_ERROR,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_INVALID_URL,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_UNRECOGNIZED_SCHEME,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_NAME_NOT_RESOLVED,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_INVALID_OPERATION,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0 || broken(!ret) /* XP, w2k3 */, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_OPERATION_CANCELLED,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_ITEM_NOT_FOUND,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_CANNOT_CONNECT,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_CONNECTION_ABORTED,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_SEC_CERT_DATE_INVALID,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+
+    ret = FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE, hdll, ERROR_INTERNET_SEC_CERT_CN_INVALID,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out), NULL);
+    ok(ret != 0, "FormatMessageA returned %d\n", ret);
+}
+
 /* ############################### */
 
 START_TEST(internet)
@@ -1864,4 +1941,5 @@ START_TEST(internet)
 
     test_InternetSetOption();
     test_end_browser_session();
+    test_format_message(hdll);
 }