reg/tests: Test backslashes with whitespace variations and comma placement.
[wine.git] / dlls / jsproxy / tests / jsproxy.c
blob67a29881734f806a7c8b1d0de8aafc980ef60826
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 (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;
39 DWORD err, len;
40 BOOL ret;
42 buf.dwStructSize = sizeof(buf);
43 buf.lpszScriptBuffer = script;
44 buf.dwScriptBufferSize = 0;
45 SetLastError( 0xdeadbeef );
46 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
47 err = GetLastError();
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 );
58 GlobalFree( 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 );
68 GlobalFree( 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 );
77 GlobalFree( 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;
89 DWORD len, err;
90 BOOL ret;
92 SetLastError( 0xdeadbeef );
93 ret = pInternetGetProxyInfo( url, strlen(url), host, strlen(host), &proxy, &len );
94 err = GetLastError();
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() );
104 len = 0;
105 proxy = NULL;
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 );
110 GlobalFree( proxy );
112 len = 0;
113 proxy = NULL;
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 );
118 GlobalFree( proxy );
120 len = 0;
121 proxy = NULL;
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 );
126 GlobalFree( proxy );
128 len = 0;
129 proxy = NULL;
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 );
134 GlobalFree( proxy );
136 ret = pInternetDeInitializeAutoProxyDll( NULL, 0 );
137 ok( ret, "got %u\n", GetLastError() );
140 START_TEST(jsproxy)
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" );
150 return;
153 test_InternetInitializeAutoProxyDll();
154 test_InternetGetProxyInfo();