[MLANG_WINETEST] Sync with Wine Staging 1.9.4. CORE-10912
[reactos.git] / rostests / winetests / mpr / mpr.c
1 /*
2 * Copyright 2012 Andrew Eikum for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define COBJMACROS
20
21 #include <stdio.h>
22
23 #include "windows.h"
24 #include "winnetwk.h"
25 #include "wine/test.h"
26
27 static void test_WNetGetUniversalName(void)
28 {
29 DWORD ret;
30 char buffer[1024];
31 DWORD drive_type, info_size, fail_size;
32 char driveA[] = "A:\\";
33 char driveandpathA[] = "A:\\file.txt";
34 WCHAR driveW[] = {'A',':','\\',0};
35
36 for(; *driveA <= 'Z'; ++*driveA, ++*driveandpathA, ++*driveW){
37 drive_type = GetDriveTypeW(driveW);
38
39 info_size = sizeof(buffer);
40 ret = WNetGetUniversalNameA(driveA, UNIVERSAL_NAME_INFO_LEVEL,
41 buffer, &info_size);
42
43 if(drive_type == DRIVE_REMOTE)
44 ok(ret == WN_NO_ERROR, "WNetGetUniversalNameA failed: %08x\n", ret);
45 else
46 /* WN_NO_NET_OR_BAD_PATH (DRIVE_FIXED) returned from the virtual drive (usual Q:)
47 created by the microsoft application virtualization client */
48 ok((ret == WN_NOT_CONNECTED) || (ret == WN_NO_NET_OR_BAD_PATH),
49 "WNetGetUniversalNameA(%s, ...) returned %u (drive_type: %u)\n",
50 driveA, ret, drive_type);
51
52 ok(info_size == sizeof(buffer), "Got wrong size: %u\n", info_size);
53
54 fail_size = 0;
55 ret = WNetGetUniversalNameA(driveA, UNIVERSAL_NAME_INFO_LEVEL,
56 buffer, &fail_size);
57 if(drive_type == DRIVE_REMOTE)
58 todo_wine ok(ret == WN_BAD_VALUE, "WNetGetUniversalNameA failed: %08x\n", ret);
59 else
60 ok(ret == WN_NOT_CONNECTED || ret == WN_NO_NET_OR_BAD_PATH,
61 "(%s) WNetGetUniversalNameW gave wrong error: %u\n", driveA, ret);
62
63 fail_size = sizeof(driveA) / sizeof(char) - 1;
64 ret = WNetGetUniversalNameA(driveA, UNIVERSAL_NAME_INFO_LEVEL,
65 buffer, &fail_size);
66 if(drive_type == DRIVE_REMOTE)
67 ok(ret == WN_MORE_DATA, "WNetGetUniversalNameA failed: %08x\n", ret);
68
69 ret = WNetGetUniversalNameA(driveandpathA, UNIVERSAL_NAME_INFO_LEVEL,
70 buffer, &info_size);
71 if(drive_type == DRIVE_REMOTE)
72 todo_wine ok(ret == WN_NO_ERROR, "WNetGetUniversalNameA failed: %08x\n", ret);
73
74 info_size = sizeof(buffer);
75 ret = WNetGetUniversalNameW(driveW, UNIVERSAL_NAME_INFO_LEVEL,
76 buffer, &info_size);
77
78 if(drive_type == DRIVE_REMOTE)
79 ok(ret == WN_NO_ERROR, "WNetGetUniversalNameW failed: %08x\n", ret);
80 else
81 ok((ret == WN_NOT_CONNECTED) || (ret == WN_NO_NET_OR_BAD_PATH),
82 "WNetGetUniversalNameW(%s, ...) returned %u (drive_type: %u)\n",
83 wine_dbgstr_w(driveW), ret, drive_type);
84 if(drive_type != DRIVE_REMOTE)
85 ok(info_size == sizeof(buffer), "Got wrong size: %u\n", info_size);
86 }
87 }
88
89 static void test_WNetGetRemoteName(void)
90 {
91 DWORD ret;
92 char buffer[1024];
93 DWORD drive_type, info_size, fail_size;
94 char driveA[] = "A:\\";
95 char driveandpathA[] = "A:\\file.txt";
96 WCHAR driveW[] = {'A',':','\\',0};
97
98 for(; *driveA <= 'Z'; ++*driveA, ++*driveandpathA, ++*driveW){
99 drive_type = GetDriveTypeW(driveW);
100
101 info_size = sizeof(buffer);
102 ret = WNetGetUniversalNameA(driveA, REMOTE_NAME_INFO_LEVEL,
103 buffer, &info_size);
104 todo_wine{
105 if(drive_type == DRIVE_REMOTE)
106 ok(ret == WN_NO_ERROR, "WNetGetUniversalNameA failed: %08x\n", ret);
107 else
108 ok(ret == WN_NOT_CONNECTED || ret == WN_NO_NET_OR_BAD_PATH,
109 "(%s) WNetGetUniversalNameA gave wrong error: %u\n", driveA, ret);
110 }
111 ok(info_size == sizeof(buffer), "Got wrong size: %u\n", info_size);
112
113 fail_size = 0;
114 ret = WNetGetUniversalNameA(driveA, REMOTE_NAME_INFO_LEVEL,
115 buffer, &fail_size);
116 todo_wine{
117 if(drive_type == DRIVE_REMOTE)
118 ok(ret == WN_BAD_VALUE, "WNetGetUniversalNameA failed: %08x\n", ret);
119 else
120 ok(ret == WN_NOT_CONNECTED || ret == WN_NO_NET_OR_BAD_PATH,
121 "(%s) WNetGetUniversalNameA gave wrong error: %u\n", driveA, ret);
122 }
123 ret = WNetGetUniversalNameA(driveA, REMOTE_NAME_INFO_LEVEL,
124 buffer, NULL);
125 todo_wine ok(ret == WN_BAD_POINTER, "WNetGetUniversalNameA failed: %08x\n", ret);
126
127 ret = WNetGetUniversalNameA(driveA, REMOTE_NAME_INFO_LEVEL,
128 NULL, &info_size);
129
130 todo_wine{
131 if(((GetVersion() & 0x8000ffff) == 0x00000004) || /* NT40 */
132 (drive_type == DRIVE_REMOTE))
133 ok(ret == WN_BAD_POINTER, "WNetGetUniversalNameA failed: %08x\n", ret);
134 else
135 ok(ret == WN_NOT_CONNECTED || ret == WN_BAD_VALUE,
136 "(%s) WNetGetUniversalNameA gave wrong error: %u\n", driveA, ret); }
137
138 fail_size = sizeof(driveA) / sizeof(char) - 1;
139 ret = WNetGetUniversalNameA(driveA, REMOTE_NAME_INFO_LEVEL,
140 buffer, &fail_size);
141 if(drive_type == DRIVE_REMOTE)
142 todo_wine ok(ret == WN_MORE_DATA, "WNetGetUniversalNameA failed: %08x\n", ret);
143
144 ret = WNetGetUniversalNameA(driveandpathA, REMOTE_NAME_INFO_LEVEL,
145 buffer, &info_size);
146 if(drive_type == DRIVE_REMOTE)
147 todo_wine ok(ret == WN_NO_ERROR, "WNetGetUniversalNameA failed: %08x\n", ret);
148
149 info_size = sizeof(buffer);
150 ret = WNetGetUniversalNameW(driveW, REMOTE_NAME_INFO_LEVEL,
151 buffer, &info_size);
152
153 if(drive_type == DRIVE_REMOTE)
154 todo_wine ok(ret == WN_NO_ERROR, "WNetGetUniversalNameW failed: %08x\n", ret);
155 else
156 ok(ret == WN_NOT_CONNECTED || ret == WN_NO_NET_OR_BAD_PATH,
157 "(%s) WNetGetUniversalNameW gave wrong error: %u\n", driveA, ret);
158
159 ok(info_size == sizeof(buffer), "Got wrong size: %u\n", info_size);
160 }
161 }
162
163 static DWORD (WINAPI *pWNetCachePassword)( LPSTR, WORD, LPSTR, WORD, BYTE, WORD );
164 static DWORD (WINAPI *pWNetGetCachedPassword)( LPSTR, WORD, LPSTR, LPWORD, BYTE );
165 static UINT (WINAPI *pWNetEnumCachedPasswords)( LPSTR, WORD, BYTE, ENUMPASSWORDPROC, DWORD);
166 static UINT (WINAPI *pWNetRemoveCachedPassword)( LPSTR, WORD, BYTE );
167
168 #define MPR_GET_PROC(func) \
169 p ## func = (void*)GetProcAddress(hmpr, #func)
170
171 static void InitFunctionPtrs(void)
172 {
173 HMODULE hmpr = GetModuleHandleA("mpr.dll");
174
175 MPR_GET_PROC(WNetCachePassword);
176 MPR_GET_PROC(WNetGetCachedPassword);
177 MPR_GET_PROC(WNetEnumCachedPasswords);
178 MPR_GET_PROC(WNetRemoveCachedPassword);
179 }
180
181 static const char* m_resource = "wine-test-resource";
182 static const char* m_password = "wine-test-password";
183 static const BYTE m_type = 1;
184 static const DWORD m_param = 8;
185 static BOOL m_callback_reached;
186
187 static BOOL CALLBACK enum_password_proc(PASSWORD_CACHE_ENTRY* pce, DWORD param)
188 {
189 WORD size = 0;
190 char* buf;
191
192 ok(param == m_param, "param, got %d, got %d\n", param, m_param);
193
194 size = offsetof( PASSWORD_CACHE_ENTRY, abResource[pce->cbResource + pce->cbPassword] );
195 ok(pce->cbEntry == size, "cbEntry, got %d, expected %d\n", pce->cbEntry, size);
196 ok(pce->cbResource == strlen(m_resource), "cbResource, got %d\n", pce->cbResource);
197 ok(pce->cbPassword == strlen(m_password), "cbPassword, got %d\n", pce->cbPassword);
198 ok(pce->iEntry == 0, "iEntry, got %d, got %d\n", pce->iEntry, 0);
199 ok(pce->nType == m_type, "nType, got %d, got %d\n", pce->nType, m_type);
200
201 buf = (char*)pce->abResource;
202 ok(strncmp(buf, m_resource, pce->cbResource)==0, "enumerated resource differs, got %.*s, expected %s\n", pce->cbResource, buf, m_resource);
203
204 buf += pce->cbResource;
205 ok(strncmp(buf, m_password, pce->cbPassword)==0, "enumerated resource differs, got %.*s, expected %s\n", pce->cbPassword, buf, m_password);
206
207 m_callback_reached = 1;
208 return TRUE;
209 }
210
211 static void test_WNetCachePassword(void)
212 {
213 char resource_buf[32];
214 char password_buf[32];
215 char prefix_buf[32];
216 WORD resource_len;
217 WORD password_len;
218 WORD prefix_len;
219 DWORD ret;
220
221 InitFunctionPtrs();
222
223 if (pWNetCachePassword &&
224 pWNetGetCachedPassword &&
225 pWNetEnumCachedPasswords &&
226 pWNetRemoveCachedPassword)
227 {
228 strcpy(resource_buf, m_resource);
229 resource_len = strlen(m_resource);
230 strcpy(password_buf, m_password);
231 password_len = strlen(m_password);
232 ret = pWNetCachePassword(resource_buf, resource_len, password_buf, password_len, m_type, 0);
233 ok(ret == WN_SUCCESS, "WNetCachePassword failed: got %d, expected %d\n", ret, WN_SUCCESS);
234
235 strcpy(resource_buf, m_resource);
236 resource_len = strlen(m_resource);
237 strcpy(password_buf, "------");
238 password_len = sizeof(password_buf);
239 ret = pWNetGetCachedPassword(resource_buf, resource_len, password_buf, &password_len, m_type);
240 ok(ret == WN_SUCCESS, "WNetGetCachedPassword failed: got %d, expected %d\n", ret, WN_SUCCESS);
241 ok(password_len == strlen(m_password), "password length different, got %d\n", password_len);
242 ok(strncmp(password_buf, m_password, password_len)==0, "passwords different, got %.*s, expected %s\n", password_len, password_buf, m_password);
243
244 prefix_len = 9;
245 strcpy(prefix_buf, m_resource);
246 prefix_buf[prefix_len] = '0';
247 ret = pWNetEnumCachedPasswords(prefix_buf, prefix_len, m_type, enum_password_proc, m_param);
248 ok(ret == WN_SUCCESS, "WNetEnumCachedPasswords failed: got %d, expected %d\n", ret, WN_SUCCESS);
249 ok(m_callback_reached == 1, "callback was not reached\n");
250
251 strcpy(resource_buf, m_resource);
252 resource_len = strlen(m_resource);
253 ret = pWNetRemoveCachedPassword(resource_buf, resource_len, m_type);
254 ok(ret == WN_SUCCESS, "WNetRemoveCachedPassword failed: got %d, expected %d\n", ret, WN_SUCCESS);
255 } else {
256 win_skip("WNetCachePassword() is not supported.\n");
257 }
258 }
259
260 START_TEST(mpr)
261 {
262 test_WNetGetUniversalName();
263 test_WNetGetRemoteName();
264 test_WNetCachePassword();
265 }