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
25 #include "wine/test.h"
27 static BOOL (WINAPI
*pInternetInitializeAutoProxyDll
)
28 (DWORD
, LPSTR
, LPSTR
, AutoProxyHelperFunctions
*, AUTO_PROXY_SCRIPT_BUFFER
*);
29 static BOOL (WINAPI
*pInternetDeInitializeAutoProxyDll
)(LPSTR
, DWORD
);
30 static BOOL (WINAPI
*pInternetGetProxyInfo
)(LPCSTR
, DWORD
, LPSTR
, DWORD
, LPSTR
*, LPDWORD
);
32 static void test_InternetInitializeAutoProxyDll(void)
34 const char url
[] = "http://localhost";
35 char script
[] = "function FindProxyForURL(url, host) {return \"DIRECT\";}\0test";
36 char script2
[] = "function FindProxyForURL(url, host) {return \"PROXY 10.0.0.1:8080\";}\0test";
37 char *proxy
, host
[] = "localhost";
38 AUTO_PROXY_SCRIPT_BUFFER buf
;
42 buf
.dwStructSize
= sizeof(buf
);
43 buf
.lpszScriptBuffer
= script
;
44 buf
.dwScriptBufferSize
= 0;
45 SetLastError( 0xdeadbeef );
46 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
48 ok( !ret
, "unexpected success\n" );
49 ok( err
== ERROR_INVALID_PARAMETER
, "got %u\n", err
);
51 buf
.dwScriptBufferSize
= strlen(script
) + 1;
52 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
53 ok( ret
, "got %u\n", GetLastError() );
55 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
56 ok( ret
, "got %u\n", GetLastError() );
57 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
60 buf
.dwScriptBufferSize
= strlen(script2
) + 1;
61 buf
.lpszScriptBuffer
= script2
;
62 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
63 ok( ret
, "got %u\n", GetLastError() );
65 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
66 ok( ret
, "got %u\n", GetLastError() );
67 ok( !strcmp( proxy
, "PROXY 10.0.0.1:8080" ), "got \"%s\"\n", proxy
);
70 buf
.dwScriptBufferSize
= strlen(script2
) + 2;
71 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
72 ok( ret
, "got %u\n", GetLastError() );
74 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
75 ok( ret
, "got %u\n", GetLastError() );
76 ok( !strcmp( proxy
, "PROXY 10.0.0.1:8080" ), "got \"%s\"\n", proxy
);
79 ret
= pInternetDeInitializeAutoProxyDll( NULL
, 0 );
80 ok( ret
, "got %u\n", GetLastError() );
83 static void test_InternetGetProxyInfo(void)
85 const char url
[] = "http://localhost";
86 char script
[] = "function FindProxyForURL(url, host) { return \"DIRECT\"; }";
87 char *proxy
, host
[] = "localhost";
88 AUTO_PROXY_SCRIPT_BUFFER buf
;
92 SetLastError( 0xdeadbeef );
93 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
95 ok( !ret
, "unexpected success\n" );
96 ok( err
== ERROR_CAN_NOT_COMPLETE
, "got %u\n", err
);
98 buf
.dwStructSize
= sizeof(buf
);
99 buf
.lpszScriptBuffer
= script
;
100 buf
.dwScriptBufferSize
= strlen(script
) + 1;
101 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
102 ok( ret
, "got %u\n", GetLastError() );
106 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
107 ok( ret
, "got %u\n", GetLastError() );
108 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
109 ok( len
== strlen("DIRECT") + 1, "got %u\n", len
);
114 ret
= pInternetGetProxyInfo( url
, strlen(url
) + 1, host
, strlen(host
), &proxy
, &len
);
115 ok( ret
, "got %u\n", GetLastError() );
116 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
117 ok( len
== strlen("DIRECT") + 1, "got %u\n", len
);
122 ret
= pInternetGetProxyInfo( url
, strlen(url
) - 1, host
, strlen(host
), &proxy
, &len
);
123 ok( ret
, "got %u\n", GetLastError() );
124 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
125 ok( len
== strlen("DIRECT") + 1, "got %u\n", len
);
130 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
) + 1, &proxy
, &len
);
131 ok( ret
, "got %u\n", GetLastError() );
132 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
133 ok( len
== strlen("DIRECT") + 1, "got %u\n", len
);
136 ret
= pInternetDeInitializeAutoProxyDll( NULL
, 0 );
137 ok( ret
, "got %u\n", GetLastError() );
142 HMODULE module
= LoadLibraryA( "jsproxy.dll" );
143 pInternetInitializeAutoProxyDll
= (void *)GetProcAddress( module
, "InternetInitializeAutoProxyDll" );
144 pInternetDeInitializeAutoProxyDll
= (void *)GetProcAddress( module
, "InternetDeInitializeAutoProxyDll" );
145 pInternetGetProxyInfo
= (void *)GetProcAddress( module
, "InternetGetProxyInfo" );
147 if (!pInternetInitializeAutoProxyDll
)
149 win_skip( "InternetInitializeAutoProxyDll not available\n" );
153 test_InternetInitializeAutoProxyDll();
154 test_InternetGetProxyInfo();