ReactOS  0.4.14-dev-342-gdc047f9
mpr.c File Reference
#include <stdio.h>
#include "windows.h"
#include "winnetwk.h"
#include "wine/test.h"
Include dependency graph for mpr.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define MPR_GET_PROC(func)   p ## func = (void*)GetProcAddress(hmpr, #func)
 

Functions

static void test_WNetGetUniversalName (void)
 
static void test_WNetGetRemoteName (void)
 
static DWORD (WINAPI *pWNetCachePassword)(LPSTR
 
static UINT (WINAPI *pWNetEnumCachedPasswords)(LPSTR
 
static void InitFunctionPtrs (void)
 
static BOOL CALLBACK enum_password_proc (PASSWORD_CACHE_ENTRY *pce, DWORD param)
 
static void test_WNetCachePassword (void)
 
static void test_WNetUseConnection (void)
 
 START_TEST (mpr)
 

Variables

static WORD
 
static LPSTR
 
static BYTE
 
static LPWORD
 
static ENUMPASSWORDPROC
 
static DWORD
 
static LPNETRESOURCEA
 
static LPCSTR
 
static LPDWORD
 
static const charm_resource = "wine-test-resource"
 
static const charm_password = "wine-test-password"
 
static const BYTE m_type = 1
 
static const DWORD m_param = 8
 
static BOOL m_callback_reached
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 19 of file mpr.c.

◆ MPR_GET_PROC

#define MPR_GET_PROC (   func)    p ## func = (void*)GetProcAddress(hmpr, #func)

Definition at line 169 of file mpr.c.

Function Documentation

◆ DWORD()

static DWORD ( WINAPI pWNetCachePassword)
static

◆ enum_password_proc()

static BOOL CALLBACK enum_password_proc ( PASSWORD_CACHE_ENTRY *  pce,
DWORD  param 
)
static

Definition at line 189 of file mpr.c.

190 {
191  WORD size = 0;
192  char* buf;
193 
194  ok(param == m_param, "param, got %d, got %d\n", param, m_param);
195 
196  size = offsetof( PASSWORD_CACHE_ENTRY, abResource[pce->cbResource + pce->cbPassword] );
197  ok(pce->cbEntry == size, "cbEntry, got %d, expected %d\n", pce->cbEntry, size);
198  ok(pce->cbResource == strlen(m_resource), "cbResource, got %d\n", pce->cbResource);
199  ok(pce->cbPassword == strlen(m_password), "cbPassword, got %d\n", pce->cbPassword);
200  ok(pce->iEntry == 0, "iEntry, got %d, got %d\n", pce->iEntry, 0);
201  ok(pce->nType == m_type, "nType, got %d, got %d\n", pce->nType, m_type);
202 
203  buf = (char*)pce->abResource;
204  ok(strncmp(buf, m_resource, pce->cbResource)==0, "enumerated resource differs, got %.*s, expected %s\n", pce->cbResource, buf, m_resource);
205 
206  buf += pce->cbResource;
207  ok(strncmp(buf, m_password, pce->cbPassword)==0, "enumerated resource differs, got %.*s, expected %s\n", pce->cbPassword, buf, m_password);
208 
209  m_callback_reached = 1;
210  return TRUE;
211 }
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static const char * m_resource
Definition: mpr.c:183
static const char * m_password
Definition: mpr.c:184
#define offsetof(TYPE, MEMBER)
GLsizeiptr size
Definition: glext.h:5919
static BOOL m_callback_reached
Definition: mpr.c:187
GLfloat param
Definition: glext.h:5796
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned short WORD
Definition: ntddk_ex.h:93
#define ok(value,...)
Definition: atltest.h:57
static const DWORD m_param
Definition: mpr.c:186
static const BYTE m_type
Definition: mpr.c:185

Referenced by test_WNetCachePassword().

◆ InitFunctionPtrs()

static void InitFunctionPtrs ( void  )
static

Definition at line 172 of file mpr.c.

173 {
174  HMODULE hmpr = GetModuleHandleA("mpr.dll");
175 
181 }
DWORD WINAPI WNetCachePassword(LPSTR pbResource, WORD cbResource, LPSTR pbPassword, WORD cbPassword, BYTE nType, WORD x)
Definition: pwcache.c:85
DWORD WINAPI WNetUseConnectionA(HWND hwndOwner, NETRESOURCEA *resource, LPCSTR password, LPCSTR userid, DWORD flags, LPSTR accessname, DWORD *buffer_size, DWORD *result)
Definition: wnet.c:2349
UINT WINAPI WNetRemoveCachedPassword(LPSTR pbResource, WORD cbResource, BYTE nType)
Definition: pwcache.c:130
DWORD WINAPI WNetGetCachedPassword(LPSTR pbResource, WORD cbResource, LPSTR pbPassword, LPWORD pcbPassword, BYTE nType)
Definition: pwcache.c:180
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define MPR_GET_PROC(func)
Definition: mpr.c:169
UINT WINAPI WNetEnumCachedPasswords(LPSTR pbPrefix, WORD cbPrefix, BYTE nType, ENUMPASSWORDPROC enumPasswordProc, DWORD param)
Definition: pwcache.c:240

Referenced by test_WNetCachePassword().

◆ START_TEST()

START_TEST ( mpr  )

Definition at line 318 of file mpr.c.

319 {
324 }
static void test_WNetGetRemoteName(void)
Definition: mpr.c:92
static void test_WNetCachePassword(void)
Definition: mpr.c:213
static void test_WNetGetUniversalName(void)
Definition: mpr.c:27
static void test_WNetUseConnection(void)
Definition: mpr.c:262

◆ test_WNetCachePassword()

static void test_WNetCachePassword ( void  )
static

Definition at line 213 of file mpr.c.

214 {
215  char resource_buf[32];
216  char password_buf[32];
217  char prefix_buf[32];
218  WORD resource_len;
219  WORD password_len;
220  WORD prefix_len;
221  DWORD ret;
222 
224 
225  if (pWNetCachePassword &&
226  pWNetGetCachedPassword &&
227  pWNetEnumCachedPasswords &&
228  pWNetRemoveCachedPassword)
229  {
230  strcpy(resource_buf, m_resource);
231  resource_len = strlen(m_resource);
232  strcpy(password_buf, m_password);
233  password_len = strlen(m_password);
234  ret = pWNetCachePassword(resource_buf, resource_len, password_buf, password_len, m_type, 0);
235  ok(ret == WN_SUCCESS, "WNetCachePassword failed: got %d, expected %d\n", ret, WN_SUCCESS);
236 
237  strcpy(resource_buf, m_resource);
238  resource_len = strlen(m_resource);
239  strcpy(password_buf, "------");
240  password_len = sizeof(password_buf);
241  ret = pWNetGetCachedPassword(resource_buf, resource_len, password_buf, &password_len, m_type);
242  ok(ret == WN_SUCCESS, "WNetGetCachedPassword failed: got %d, expected %d\n", ret, WN_SUCCESS);
243  ok(password_len == strlen(m_password), "password length different, got %d\n", password_len);
244  ok(strncmp(password_buf, m_password, password_len)==0, "passwords different, got %.*s, expected %s\n", password_len, password_buf, m_password);
245 
246  prefix_len = 9;
247  strcpy(prefix_buf, m_resource);
248  prefix_buf[prefix_len] = '0';
249  ret = pWNetEnumCachedPasswords(prefix_buf, prefix_len, m_type, enum_password_proc, m_param);
250  ok(ret == WN_SUCCESS, "WNetEnumCachedPasswords failed: got %d, expected %d\n", ret, WN_SUCCESS);
251  ok(m_callback_reached == 1, "callback was not reached\n");
252 
253  strcpy(resource_buf, m_resource);
254  resource_len = strlen(m_resource);
255  ret = pWNetRemoveCachedPassword(resource_buf, resource_len, m_type);
256  ok(ret == WN_SUCCESS, "WNetRemoveCachedPassword failed: got %d, expected %d\n", ret, WN_SUCCESS);
257  } else {
258  win_skip("WNetCachePassword() is not supported.\n");
259  }
260 }
#define WN_SUCCESS
Definition: winnetwk.h:111
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static void InitFunctionPtrs(void)
Definition: mpr.c:172
static const char * m_resource
Definition: mpr.c:183
static const char * m_password
Definition: mpr.c:184
static BOOL CALLBACK enum_password_proc(PASSWORD_CACHE_ENTRY *pce, DWORD param)
Definition: mpr.c:189
static BOOL m_callback_reached
Definition: mpr.c:187
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
#define ok(value,...)
Definition: atltest.h:57
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
static const DWORD m_param
Definition: mpr.c:186
static const BYTE m_type
Definition: mpr.c:185
#define win_skip
Definition: test.h:141

Referenced by START_TEST().

◆ test_WNetGetRemoteName()

static void test_WNetGetRemoteName ( void  )
static

Definition at line 92 of file mpr.c.

93 {
94  DWORD ret;
95  char buffer[1024];
96  DWORD drive_type, info_size, fail_size;
97  char driveA[] = "A:\\";
98  char driveandpathA[] = "A:\\file.txt";
99  WCHAR driveW[] = {'A',':','\\',0};
100 
101  for(; *driveA <= 'Z'; ++*driveA, ++*driveandpathA, ++*driveW){
102  drive_type = GetDriveTypeW(driveW);
103 
104  info_size = sizeof(buffer);
106  buffer, &info_size);
107  if(drive_type == DRIVE_REMOTE)
108  todo_wine
109  ok(ret == WN_NO_ERROR, "WNetGetUniversalNameA failed: %08x\n", ret);
110  else
112  "(%s) WNetGetUniversalNameA gave wrong error: %u\n", driveA, ret);
113  ok(info_size == sizeof(buffer), "Got wrong size: %u\n", info_size);
114 
115  fail_size = 0;
117  buffer, &fail_size);
118  if(drive_type == DRIVE_REMOTE)
119  todo_wine
120  ok(ret == WN_BAD_VALUE || ret == WN_MORE_DATA, "WNetGetUniversalNameA failed: %08x\n", ret);
121  else
123  "(%s) WNetGetUniversalNameA gave wrong error: %u\n", driveA, ret);
125  buffer, NULL);
126  todo_wine ok(ret == WN_BAD_POINTER, "WNetGetUniversalNameA failed: %08x\n", ret);
127 
129  NULL, &info_size);
130 
131  if(drive_type == DRIVE_REMOTE)
132  todo_wine
133  ok(ret == WN_BAD_POINTER || ret == WN_BAD_VALUE, "WNetGetUniversalNameA failed: %08x\n", ret);
134  else
136  "(%s) WNetGetUniversalNameA gave wrong error: %u\n", driveA, ret);
137 
138  fail_size = ARRAY_SIZE(driveA) - 1;
140  buffer, &fail_size);
141  if(drive_type == DRIVE_REMOTE)
142  todo_wine ok(ret == WN_MORE_DATA, "WNetGetUniversalNameA failed: %08x\n", ret);
143 
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);
151  buffer, &info_size);
152  todo_wine{
153  if(drive_type == DRIVE_REMOTE)
154  ok(ret == WN_NO_ERROR, "WNetGetUniversalNameW failed: %08x\n", ret);
155  else
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 }
GLuint buffer
Definition: glext.h:5915
#define WN_NO_NET_OR_BAD_PATH
Definition: winnetwk.h:140
#define WN_NOT_CONNECTED
Definition: winnetwk.h:132
#define WN_NO_ERROR
Definition: winnetwk.h:112
#define WN_BAD_VALUE
Definition: winnetwk.h:119
#define DRIVE_REMOTE
Definition: winbase.h:250
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define REMOTE_NAME_INFO_LEVEL
Definition: winnetwk.h:152
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI WNetGetUniversalNameA(LPCSTR lpLocalPath, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpBufferSize)
Definition: wnet.c:2730
DWORD WINAPI WNetGetUniversalNameW(LPCWSTR lpLocalPath, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpBufferSize)
Definition: wnet.c:2777
int ret
#define todo_wine
Definition: test.h:154
#define WN_BAD_POINTER
Definition: winnetwk.h:118
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
#define WN_MORE_DATA
Definition: winnetwk.h:117

Referenced by START_TEST().

◆ test_WNetGetUniversalName()

static void test_WNetGetUniversalName ( void  )
static

Definition at line 27 of file mpr.c.

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);
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 */
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 = 1;
56  buffer, &fail_size);
57  if(drive_type == DRIVE_REMOTE)
58  {
59  todo_wine ok(ret == WN_BAD_VALUE || ret == WN_MORE_DATA, "WNetGetUniversalNameA failed: %08x\n", ret);
60  ok(fail_size > 1, "Got %d\n", fail_size);
61  }
62  else
64  "(%s) WNetGetUniversalNameW gave wrong error: %u\n", driveA, ret);
65 
66  fail_size = ARRAY_SIZE(driveA) - 1;
68  buffer, &fail_size);
69  if(drive_type == DRIVE_REMOTE)
70  ok(ret == WN_MORE_DATA, "WNetGetUniversalNameA failed: %08x\n", ret);
71 
73  buffer, &info_size);
74  if(drive_type == DRIVE_REMOTE)
75  todo_wine ok(ret == WN_NO_ERROR, "WNetGetUniversalNameA failed: %08x\n", ret);
76 
77  info_size = sizeof(buffer);
79  buffer, &info_size);
80 
81  if(drive_type == DRIVE_REMOTE)
82  ok(ret == WN_NO_ERROR, "WNetGetUniversalNameW failed: %08x\n", ret);
83  else
85  "WNetGetUniversalNameW(%s, ...) returned %u (drive_type: %u)\n",
86  wine_dbgstr_w(driveW), ret, drive_type);
87  if(drive_type != DRIVE_REMOTE)
88  ok(info_size == sizeof(buffer), "Got wrong size: %u\n", info_size);
89  }
90 }
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
GLuint buffer
Definition: glext.h:5915
#define WN_NO_NET_OR_BAD_PATH
Definition: winnetwk.h:140
#define WN_NOT_CONNECTED
Definition: winnetwk.h:132
#define WN_NO_ERROR
Definition: winnetwk.h:112
#define WN_BAD_VALUE
Definition: winnetwk.h:119
#define DRIVE_REMOTE
Definition: winbase.h:250
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI WNetGetUniversalNameA(LPCSTR lpLocalPath, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpBufferSize)
Definition: wnet.c:2730
DWORD WINAPI WNetGetUniversalNameW(LPCWSTR lpLocalPath, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpBufferSize)
Definition: wnet.c:2777
int ret
#define todo_wine
Definition: test.h:154
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
#define WN_MORE_DATA
Definition: winnetwk.h:117
#define UNIVERSAL_NAME_INFO_LEVEL
Definition: winnetwk.h:151

Referenced by START_TEST().

◆ test_WNetUseConnection()

static void test_WNetUseConnection ( void  )
static

Definition at line 262 of file mpr.c.

263 {
264  DWORD ret, bufSize, outRes;
265  LPNETRESOURCEA netRes;
266  char outBuf[4], drive[] = "J:", letter;
267 
268  if (!pWNetUseConnectionA)
269  {
270  win_skip("WNetUseConnection() is not supported.\n");
271  return;
272  }
273  netRes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(NETRESOURCEA) + sizeof("\\\\127.0.0.1\\c$") + sizeof("J:"));
274  netRes->dwType = RESOURCETYPE_DISK;
277  netRes->lpLocalName = (LPSTR)((LPBYTE)netRes + sizeof(NETRESOURCEA));
278  netRes->lpRemoteName = (LPSTR)((LPBYTE)netRes + sizeof(NETRESOURCEA) + sizeof("J:"));
279 
280  for (letter = 'J'; letter <= 'Z'; letter++)
281  {
282  drive[0] = letter;
283  strcpy(netRes->lpLocalName, drive);
284  strcpy(netRes->lpRemoteName, "\\\\127.0.0.1\\c$");
285  bufSize = 0;
286  ret = pWNetUseConnectionA(NULL, netRes, NULL, NULL, 0, NULL, &bufSize, &outRes);
287  if (ret != ERROR_ALREADY_ASSIGNED) break;
288  }
289  if (ret == ERROR_ALREADY_ASSIGNED) goto end; /* no drives available */
290  todo_wine ok(ret == WN_SUCCESS, "Unexpected return: %u\n", ret);
291  ok(bufSize == 0, "Unexpected buffer size: %u\n", bufSize);
293 
294  bufSize = 0;
295  ret = pWNetUseConnectionA(NULL, netRes, NULL, NULL, 0, outBuf, &bufSize, &outRes);
296  todo_wine ok(ret == ERROR_INVALID_PARAMETER, "Unexpected return: %u\n", ret);
297  ok(bufSize == 0, "Unexpected buffer size: %u\n", bufSize);
299 
300  todo_wine {
301  bufSize = 1;
302  ret = pWNetUseConnectionA(NULL, netRes, NULL, NULL, 0, outBuf, &bufSize, &outRes);
303  ok(ret == ERROR_MORE_DATA, "Unexpected return: %u\n", ret);
304  ok(bufSize == 3, "Unexpected buffer size: %u\n", bufSize);
306 
307  bufSize = 4;
308  ret = pWNetUseConnectionA(NULL, netRes, NULL, NULL, 0, outBuf, &bufSize, &outRes);
309  ok(ret == WN_SUCCESS, "Unexpected return: %u\n", ret);
310  }
311  ok(bufSize == 4, "Unexpected buffer size: %u\n", bufSize);
313 
314 end:
315  HeapFree(GetProcessHeap(), 0, netRes);
316 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
DWORD dwType
Definition: winnetwk.h:168
#define RESOURCEUSAGE_CONNECTABLE
Definition: winnetwk.h:68
#define WN_SUCCESS
Definition: winnetwk.h:111
LPSTR lpLocalName
Definition: winnetwk.h:171
GLuint GLuint end
Definition: gl.h:1545
struct _NETRESOURCEA NETRESOURCEA
DWORD dwDisplayType
Definition: winnetwk.h:169
DWORD WINAPI WNetCancelConnectionA(LPCSTR lpName, BOOL fForce)
Definition: wnet.c:2386
GLuint GLsizei bufSize
Definition: glext.h:6040
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define RESOURCEDISPLAYTYPE_SHARE
Definition: winnetwk.h:78
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
DWORD dwUsage
Definition: winnetwk.h:170
#define todo_wine
Definition: test.h:154
#define ERROR_ALREADY_ASSIGNED
Definition: winerror.h:169
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define RESOURCETYPE_DISK
Definition: winnetwk.h:64
#define ok(value,...)
Definition: atltest.h:57
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
LPSTR lpRemoteName
Definition: winnetwk.h:172
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
static LPSTR
Definition: mpr.c:163
#define win_skip
Definition: test.h:141
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by START_TEST().

◆ UINT()

static UINT ( WINAPI pWNetEnumCachedPasswords)
static

Variable Documentation

◆ BYTE

Definition at line 163 of file mpr.c.

◆ DWORD

Definition at line 165 of file mpr.c.

◆ ENUMPASSWORDPROC

ENUMPASSWORDPROC

Definition at line 165 of file mpr.c.

◆ LPCSTR

Definition at line 167 of file mpr.c.

◆ LPDWORD

Definition at line 167 of file mpr.c.

◆ LPNETRESOURCEA

Definition at line 167 of file mpr.c.

◆ LPSTR

Definition at line 163 of file mpr.c.

Referenced by test_WNetUseConnection().

◆ LPWORD

Definition at line 164 of file mpr.c.

◆ m_callback_reached

BOOL m_callback_reached
static

Definition at line 187 of file mpr.c.

Referenced by enum_password_proc(), and test_WNetCachePassword().

◆ m_param

const DWORD m_param = 8
static

Definition at line 186 of file mpr.c.

Referenced by enum_password_proc(), and test_WNetCachePassword().

◆ m_password

const char* m_password = "wine-test-password"
static

Definition at line 184 of file mpr.c.

Referenced by enum_password_proc(), and test_WNetCachePassword().

◆ m_resource

const char* m_resource = "wine-test-resource"
static

Definition at line 183 of file mpr.c.

Referenced by enum_password_proc(), and test_WNetCachePassword().

◆ m_type

const BYTE m_type = 1
static

Definition at line 185 of file mpr.c.

Referenced by enum_password_proc(), and test_WNetCachePassword().

◆ WORD

Definition at line 163 of file mpr.c.