ReactOS  0.4.14-dev-583-g2a1ba2c
wksta.c File Reference
#include <stdarg.h>
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winnls.h"
#include "winresrc.h"
#include "nb30.h"
#include "lmcons.h"
#include "lmerr.h"
#include "lmwksta.h"
#include "lmapibuf.h"
#include "lmjoin.h"
Include dependency graph for wksta.c:

Go to the source code of this file.

Functions

static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)
 
static BOOL init_wksta_tests (void)
 
static void run_get_comp_name_tests (void)
 
static void run_wkstausergetinfo_tests (void)
 
static void run_wkstatransportenum_tests (void)
 
static void run_wkstajoininfo_tests (void)
 
 START_TEST (wksta)
 

Variables

static LPDWORD =NULL
 
static DWORD
 
static LPWSTR PNETSETUP_JOIN_STATUS
 
static WCHAR user_name [UNLEN+1]
 
static WCHAR computer_name [MAX_COMPUTERNAME_LENGTH+1]
 

Function Documentation

◆ init_wksta_tests()

static BOOL init_wksta_tests ( void  )
static

Definition at line 47 of file wksta.c.

48 {
49  DWORD dwSize;
50  BOOL rc;
51 
52  user_name[0] = 0;
56  win_skip("GetUserNameW is not implemented\n");
57  return FALSE;
58  }
59  ok(rc, "User Name Retrieved\n");
60 
61  computer_name[0] = 0;
63  ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
64  return TRUE;
65 }
#define TRUE
Definition: types.h:120
static WCHAR computer_name[MAX_COMPUTERNAME_LENGTH+1]
Definition: wksta.c:45
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:440
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define win_skip
Definition: test.h:150
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
static WCHAR user_name[UNLEN+1]
Definition: wksta.c:44

Referenced by START_TEST().

◆ NET_API_STATUS()

static NET_API_STATUS ( WINAPI pNetApiBufferFree)
static

◆ run_get_comp_name_tests()

static void run_get_comp_name_tests ( void  )
static

Definition at line 67 of file wksta.c.

68 {
69  LPWSTR ws = NULL;
70 
71  ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved\n");
72  ok(!lstrcmpW(computer_name, ws), "This is really computer name\n");
73  pNetApiBufferFree(ws);
74 }
const char * ws
Definition: skip_ws.cpp:7
static WCHAR computer_name[MAX_COMPUTERNAME_LENGTH+1]
Definition: wksta.c:45
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
#define NERR_Success
Definition: lmerr.h:5
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: atltest.h:57
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by START_TEST().

◆ run_wkstajoininfo_tests()

static void run_wkstajoininfo_tests ( void  )
static

Definition at line 190 of file wksta.c.

191 {
193  LPWSTR buffer = NULL;
194  NETSETUP_JOIN_STATUS buffertype = 0xdada;
195  /* NT4 doesn't have this function */
196  if (!pNetGetJoinInformation) {
197  win_skip("NetGetJoinInformation not available\n");
198  return;
199  }
200 
201  ret = pNetGetJoinInformation(NULL, NULL, NULL);
202  ok(ret == ERROR_INVALID_PARAMETER, "NetJoinGetInformation returned unexpected 0x%08x\n", ret);
203  ok(buffertype == 0xdada, "buffertype set to unexpected value %d\n", buffertype);
204 
205  ret = pNetGetJoinInformation(NULL, &buffer, &buffertype);
206  ok(ret == NERR_Success, "NetJoinGetInformation returned unexpected 0x%08x\n", ret);
207  ok(buffertype != 0xdada && buffertype != NetSetupUnknownStatus, "buffertype set to unexpected value %d\n", buffertype);
208  trace("workstation joined to %s with status %d\n", wine_dbgstr_w(buffer), buffertype);
209  pNetApiBufferFree(buffer);
210 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
GLuint buffer
Definition: glext.h:5915
#define NERR_Success
Definition: lmerr.h:5
smooth NULL
Definition: ftsmooth.c:416
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define trace
Definition: atltest.h:70
int ret
#define ok(value,...)
Definition: atltest.h:57
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define win_skip
Definition: test.h:150
enum _NETSETUP_JOIN_STATUS NETSETUP_JOIN_STATUS

Referenced by START_TEST().

◆ run_wkstatransportenum_tests()

static void run_wkstatransportenum_tests ( void  )
static

Definition at line 139 of file wksta.c.

140 {
141  LPBYTE bufPtr;
142  NET_API_STATUS apiReturn;
143  DWORD entriesRead, totalEntries;
144 
145  /* 1st check: is param 2 (level) correct? (only if param 5 passed?) */
146  apiReturn = pNetWkstaTransportEnum(NULL, 1, NULL, MAX_PREFERRED_LENGTH,
147  NULL, &totalEntries, NULL);
148  ok(apiReturn == ERROR_INVALID_LEVEL || apiReturn == ERROR_INVALID_PARAMETER,
149  "NetWkstaTransportEnum returned %d\n", apiReturn);
150 
151  /* 2nd check: is param 5 passed? (only if level passes?) */
152  apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
153  NULL, &totalEntries, NULL);
154 
155  /* if no network adapter present, bail, the rest of the test will fail */
156  if (apiReturn == ERROR_NETWORK_UNREACHABLE)
157  return;
158 
159  ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == ERROR_INVALID_PARAMETER,
160  "NetWkstaTransportEnum returned %d\n", apiReturn);
161 
162  /* 3rd check: is param 3 passed? */
163  apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
164  NULL, NULL, NULL);
165  ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == RPC_X_NULL_REF_POINTER || apiReturn == ERROR_INVALID_PARAMETER,
166  "NetWkstaTransportEnum returned %d\n", apiReturn);
167 
168  /* 4th check: is param 6 passed? */
169  apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
170  &entriesRead, NULL, NULL);
171  ok(apiReturn == RPC_X_NULL_REF_POINTER,
172  "NetWkstaTransportEnum returned %d\n", apiReturn);
173 
174  /* final check: valid return, actually get data back */
175  apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
176  &entriesRead, &totalEntries, NULL);
177  ok(apiReturn == NERR_Success || apiReturn == ERROR_NETWORK_UNREACHABLE || apiReturn == NERR_WkstaNotStarted,
178  "NetWkstaTransportEnum returned %d\n", apiReturn);
179  if (apiReturn == NERR_Success) {
180  /* WKSTA_TRANSPORT_INFO_0 *transports = (WKSTA_TRANSPORT_INFO_0 *)bufPtr; */
181 
182  ok(bufPtr != NULL, "got data back\n");
183  ok(entriesRead > 0, "read at least one transport\n");
184  ok(totalEntries > 0 || broken(totalEntries == 0) /* Win7 */,
185  "at least one transport\n");
186  pNetApiBufferFree(bufPtr);
187  }
188 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
#define RPC_X_NULL_REF_POINTER
Definition: winerror.h:1087
#define NERR_Success
Definition: lmerr.h:5
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
#define NERR_WkstaNotStarted
Definition: lmerr.h:26
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
unsigned long DWORD
Definition: ntddk_ex.h:95
#define broken(x)
Definition: _sntprintf.h:21
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define ERROR_NETWORK_UNREACHABLE
Definition: winerror.h:734
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196

Referenced by START_TEST().

◆ run_wkstausergetinfo_tests()

static void run_wkstausergetinfo_tests ( void  )
static

Definition at line 76 of file wksta.c.

77 {
81  DWORD dwSize;
82  NET_API_STATUS rc;
83 
84  /* Level 0 */
85  rc = pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0);
86  if (rc == NERR_WkstaNotStarted)
87  {
88  skip("Workstation service not running\n");
89  return;
90  }
91  ok(!rc && ui0, "got %d and %p (expected NERR_Success and != NULL\n", rc, ui0);
92 
93  /* This failure occurred when I ran sshd as service and didn't authenticate
94  * Since the test dereferences ui0, the rest of this test is worthless
95  */
96  if (!ui0)
97  {
98  return;
99  }
100 
101  ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name\n");
102  pNetApiBufferSize(ui0, &dwSize);
103  ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
104  lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
105  "Is allocated with NetApiBufferAllocate\n");
106 
107  /* Level 1 */
108  ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
109  "NetWkstaUserGetInfo is successful\n");
110  ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
111  "the same name as returned for level 0\n");
112  pNetApiBufferSize(ui1, &dwSize);
113  ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
114  (lstrlenW(ui1->wkui1_username) +
117  lstrlenW(ui1->wkui1_logon_server)) * sizeof(WCHAR)),
118  "Is allocated with NetApiBufferAllocate\n");
119 
120  /* Level 1101 */
121  ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
122  "NetWkstaUserGetInfo is successful\n");
124  "the same oth_domains as returned for level 1\n");
125  pNetApiBufferSize(ui1101, &dwSize);
126  ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
127  lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
128  "Is allocated with NetApiBufferAllocate\n");
129 
130  pNetApiBufferFree(ui0);
131  pNetApiBufferFree(ui1);
132  pNetApiBufferFree(ui1101);
133 
134  /* errors handling */
135  ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
136  "Invalid level\n");
137 }
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
LPWSTR wkui1_username
Definition: lmwksta.h:204
#define lstrlenW
Definition: compat.h:415
#define NERR_Success
Definition: lmerr.h:5
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
#define NERR_WkstaNotStarted
Definition: lmerr.h:26
LPWSTR wkui1_oth_domains
Definition: lmwksta.h:206
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPWSTR wkui1101_oth_domains
Definition: lmwksta.h:209
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ok(value,...)
Definition: atltest.h:57
LPWSTR wkui1_logon_server
Definition: lmwksta.h:207
#define skip(...)
Definition: atltest.h:64
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
LPWSTR wkui0_username
Definition: lmwksta.h:202
LPWSTR wkui1_logon_domain
Definition: lmwksta.h:205
static WCHAR user_name[UNLEN+1]
Definition: wksta.c:44

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( wksta  )

Definition at line 212 of file wksta.c.

213 {
214  HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
215 
216  pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
217  pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
218  pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
219  pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
220  pNetWkstaTransportEnum=(void*)GetProcAddress(hnetapi32,"NetWkstaTransportEnum");
221  pNetGetJoinInformation=(void*)GetProcAddress(hnetapi32,"NetGetJoinInformation");
222 
223  /* These functions were introduced with NT. It's safe to assume that
224  * if one is not available, none are.
225  */
226  if (!pNetApiBufferFree) {
227  win_skip("Needed functions are not available\n");
228  FreeLibrary(hnetapi32);
229  return;
230  }
231 
232  if (init_wksta_tests()) {
233  if (pNetpGetComputerName)
235  else
236  win_skip("Function NetpGetComputerName not available\n");
240  }
241 
242  FreeLibrary(hnetapi32);
243 }
static BOOL init_wksta_tests(void)
Definition: wksta.c:47
static void run_wkstatransportenum_tests(void)
Definition: wksta.c:139
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define FreeLibrary(x)
Definition: compat.h:413
static void run_get_comp_name_tests(void)
Definition: wksta.c:67
static void run_wkstajoininfo_tests(void)
Definition: wksta.c:190
#define GetProcAddress(x, y)
Definition: compat.h:418
static void run_wkstausergetinfo_tests(void)
Definition: wksta.c:76
#define win_skip
Definition: test.h:150

Variable Documentation

◆ computer_name

WCHAR computer_name[MAX_COMPUTERNAME_LENGTH+1]
static

Definition at line 45 of file wksta.c.

Referenced by init_wksta_tests(), and run_get_comp_name_tests().

◆ DWORD

PBYTE* static LPBYTE DWORD

Definition at line 39 of file wksta.c.

◆ LPDWORD

Definition at line 37 of file wksta.c.

◆ PNETSETUP_JOIN_STATUS

Definition at line 42 of file wksta.c.

◆ user_name

WCHAR user_name[UNLEN+1]
static

Definition at line 44 of file wksta.c.

Referenced by init_wksta_tests(), and run_wkstausergetinfo_tests().