include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / jsproxy / tests / jsproxy.c
blob901ffdf910e94d9a4506f25ae519a0cd80569d5e
1 /*
2 * Copyright 2016 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <windef.h>
22 #include <winbase.h>
23 #include <wininet.h>
25 #include "wine/test.h"
27 static BOOL old_jsproxy;
29 static BOOL (WINAPI *pInternetInitializeAutoProxyDll)
30 (DWORD, LPSTR, LPSTR, AutoProxyHelperFunctions *, AUTO_PROXY_SCRIPT_BUFFER *);
31 static BOOL (WINAPI *pInternetDeInitializeAutoProxyDll)(LPSTR, DWORD);
32 static BOOL (WINAPI *pInternetGetProxyInfo)(LPCSTR, DWORD, LPSTR, DWORD, LPSTR *, LPDWORD);
34 static void test_InternetInitializeAutoProxyDll(void)
36 const char url[] = "http://localhost";
37 char script[] = "function FindProxyForURL(url, host) {return \"DIRECT\";}\0test";
38 char script2[] = "function FindProxyForURL(url, host) {return \"PROXY 10.0.0.1:8080\";}\0test";
39 char script3[] = "function FindProxyForURL(url, host) {return \"DIRECT\";}";
40 char *proxy, host[] = "localhost";
41 AUTO_PROXY_SCRIPT_BUFFER buf;
42 DWORD err, len;
43 BOOL ret;
45 buf.dwStructSize = sizeof(buf);
46 buf.lpszScriptBuffer = script;
47 buf.dwScriptBufferSize = 0;
48 SetLastError( 0xdeadbeef );
49 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
50 err = GetLastError();
51 ok( !ret, "unexpected success\n" );
52 if (!ret && err == 0xdeadbeef)
54 win_skip("InternetInitializeAutoProxyDll() is not supported on Windows 11\n");
55 return;
57 ok( err == ERROR_INVALID_PARAMETER, "got %lu\n", err );
59 buf.dwScriptBufferSize = strlen(script) + 1;
60 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
61 ok( ret, "got %lu\n", GetLastError() );
63 ret = pInternetGetProxyInfo( url, strlen(url), host, strlen(host), &proxy, &len );
64 ok( ret, "got %lu\n", GetLastError() );
65 ok( !strcmp( proxy, "DIRECT" ), "got \"%s\"\n", proxy );
66 ok( len == strlen(proxy) + 1, "got len=%ld for \"%s\"\n", len, proxy );
67 GlobalFree( proxy );
69 buf.dwScriptBufferSize = strlen(script2) + 1;
70 buf.lpszScriptBuffer = script2;
71 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
72 ok( ret, "got %lu\n", GetLastError() );
74 ret = pInternetGetProxyInfo( url, strlen(url), host, strlen(host), &proxy, &len );
75 ok( ret, "got %lu\n", GetLastError() );
76 ok( !strcmp( proxy, "PROXY 10.0.0.1:8080" ), "got \"%s\"\n", proxy );
77 ok( len == strlen(proxy) + 1, "got len=%ld for \"%s\"\n", len, proxy );
78 GlobalFree( proxy );
80 buf.dwScriptBufferSize = strlen(script2) + 2;
81 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
82 ok( ret, "got %lu\n", GetLastError() );
84 ret = pInternetGetProxyInfo( url, strlen(url), host, strlen(host), &proxy, &len );
85 ok( ret, "got %lu\n", GetLastError() );
86 ok( !strcmp( proxy, "PROXY 10.0.0.1:8080" ), "got \"%s\"\n", proxy );
87 ok( len == strlen(proxy) + 1, "got len=%ld for \"%s\"\n", len, proxy );
88 GlobalFree( proxy );
90 buf.lpszScriptBuffer = script3;
91 buf.dwScriptBufferSize = strlen(script3);
92 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
93 ok( ret || broken(old_jsproxy && !ret), "got %lu\n", GetLastError() );
95 buf.dwScriptBufferSize = 1;
96 script3[0] = 0;
97 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
98 ok( ret, "got %lu\n", GetLastError() );
100 ret = pInternetDeInitializeAutoProxyDll( NULL, 0 );
101 ok( ret, "got %lu\n", GetLastError() );
104 static void test_InternetGetProxyInfo(void)
106 const char url[] = "http://localhost";
107 char script[] = "function FindProxyForURL(url, host) { "
108 "if (url.substring(0, 4) === 'test') return url + ' ' + host; "
109 "return \"DIRECT\"; }";
110 char *proxy, host[] = "localhost";
111 AUTO_PROXY_SCRIPT_BUFFER buf;
112 DWORD len, err;
113 BOOL ret;
115 SetLastError( 0xdeadbeef );
116 ret = pInternetGetProxyInfo( url, strlen(url), host, strlen(host), &proxy, &len );
117 err = GetLastError();
118 if (!ret && err == 0xdeadbeef)
120 win_skip("InternetGetProxyInfo() is not supported on Windows 11\n");
121 return;
123 ok( !ret, "unexpected success\n" );
124 ok( err == ERROR_CAN_NOT_COMPLETE, "got %lu\n", err );
126 buf.dwStructSize = sizeof(buf);
127 buf.lpszScriptBuffer = script;
128 buf.dwScriptBufferSize = strlen(script) + 1;
129 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
130 ok( ret, "got %lu\n", GetLastError() );
132 len = 0;
133 proxy = NULL;
134 ret = pInternetGetProxyInfo( url, strlen(url), host, strlen(host), &proxy, &len );
135 ok( ret, "got %lu\n", GetLastError() );
136 ok( !strcmp( proxy, "DIRECT" ), "got \"%s\"\n", proxy );
137 ok( len == strlen("DIRECT") + 1, "got %lu\n", len );
138 GlobalFree( proxy );
140 len = 0;
141 proxy = NULL;
142 ret = pInternetGetProxyInfo( url, strlen(url) + 1, host, strlen(host), &proxy, &len );
143 ok( ret, "got %lu\n", GetLastError() );
144 ok( !strcmp( proxy, "DIRECT" ), "got \"%s\"\n", proxy );
145 ok( len == strlen("DIRECT") + 1, "got %lu\n", len );
146 GlobalFree( proxy );
148 len = 0;
149 proxy = NULL;
150 ret = pInternetGetProxyInfo( url, strlen(url) - 1, host, strlen(host), &proxy, &len );
151 ok( ret, "got %lu\n", GetLastError() );
152 ok( !strcmp( proxy, "DIRECT" ), "got \"%s\"\n", proxy );
153 ok( len == strlen("DIRECT") + 1, "got %lu\n", len );
154 GlobalFree( proxy );
156 len = 0;
157 proxy = NULL;
158 ret = pInternetGetProxyInfo( url, strlen(url), host, strlen(host) + 1, &proxy, &len );
159 ok( ret, "got %lu\n", GetLastError() );
160 ok( !strcmp( proxy, "DIRECT" ), "got \"%s\"\n", proxy );
161 ok( len == strlen("DIRECT") + 1, "got %lu\n", len );
162 GlobalFree( proxy );
164 len = 0;
165 proxy = NULL;
166 ret = pInternetGetProxyInfo( "testa", 4, host, 4, &proxy, &len);
167 ok( ret, "got %lu\n", GetLastError() );
168 ok( !strcmp( proxy, "test loca" ), "got \"%s\"\n", proxy );
169 ok( len == 10, "got %lu\n", len );
170 GlobalFree( proxy );
172 ret = pInternetDeInitializeAutoProxyDll( NULL, 0 );
173 ok( ret, "got %lu\n", GetLastError() );
176 START_TEST(jsproxy)
178 HMODULE module = LoadLibraryA( "jsproxy.dll" );
179 pInternetInitializeAutoProxyDll = (void *)GetProcAddress( module, "InternetInitializeAutoProxyDll" );
180 pInternetDeInitializeAutoProxyDll = (void *)GetProcAddress( module, "InternetDeInitializeAutoProxyDll" );
181 pInternetGetProxyInfo = (void *)GetProcAddress( module, "InternetGetProxyInfo" );
183 if (!pInternetInitializeAutoProxyDll)
185 win_skip( "InternetInitializeAutoProxyDll not available\n" );
186 return;
189 old_jsproxy = !GetProcAddress( module, "InternetGetProxyInfoEx" );
190 if (old_jsproxy)
191 trace( "InternetGetProxyInfoEx not available\n" );
193 test_InternetInitializeAutoProxyDll();
194 test_InternetGetProxyInfo();