Fixed header dependencies to be fully compatible with the Windows
[wine/multimedia.git] / dlls / netapi32 / tests / wksta.c
blob7833c395579f1655bd35e8c952c3e6fed6b53990
1 /*
2 * Copyright 2002 Andriy Palamarchuk
4 * Conformance test of the workstation functions.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winnls.h"
28 #include "ntstatus.h"
29 #include "winresrc.h" /* Ensure we use Unicode defns with native headers */
30 #include "nb30.h"
31 #include "lmcons.h"
32 #include "lmerr.h"
33 #include "lmwksta.h"
34 #include "lmapibuf.h"
36 static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
37 static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
38 static NET_API_STATUS (WINAPI *pNetpGetComputerName)(LPWSTR*)=NULL;
39 static NET_API_STATUS (WINAPI *pNetWkstaUserGetInfo)(LPWSTR,DWORD,PBYTE*)=NULL;
40 static NET_API_STATUS (WINAPI *pNetWkstaTransportEnum)(LPWSTR,DWORD,LPBYTE*,
41 DWORD,LPDWORD,LPDWORD,LPDWORD)=NULL;
43 WCHAR user_name[UNLEN + 1];
44 WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
46 static int init_wksta_tests(void)
48 DWORD dwSize;
49 BOOL rc;
51 user_name[0] = 0;
52 dwSize = sizeof(user_name);
53 rc=GetUserNameW(user_name, &dwSize);
54 if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
55 return 0;
56 ok(rc, "User Name Retrieved");
58 computer_name[0] = 0;
59 dwSize = sizeof(computer_name);
60 ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
61 return 1;
64 static void run_get_comp_name_tests(void)
66 WCHAR empty[] = {0};
67 LPWSTR ws = empty;
68 if (!pNetpGetComputerName)
69 return;
71 ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved");
72 ok(!lstrcmpW(computer_name, ws), "This is really computer name");
73 pNetApiBufferFree(ws);
76 static void run_wkstausergetinfo_tests(void)
78 LPWKSTA_USER_INFO_0 ui0 = NULL;
79 LPWKSTA_USER_INFO_1 ui1 = NULL;
80 LPWKSTA_USER_INFO_1101 ui1101 = NULL;
81 DWORD dwSize;
83 if (!pNetWkstaUserGetInfo)
84 return;
86 /* Level 0 */
87 ok(pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success,
88 "NetWkstaUserGetInfo is successful");
89 ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name");
90 pNetApiBufferSize(ui0, &dwSize);
91 ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
92 lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
93 "Is allocated with NetApiBufferAllocate");
95 /* Level 1 */
96 ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
97 "NetWkstaUserGetInfo is successful");
98 ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
99 "the same name as returned for level 0");
100 pNetApiBufferSize(ui1, &dwSize);
101 ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
102 (lstrlenW(ui1->wkui1_username) +
103 lstrlenW(ui1->wkui1_logon_domain) +
104 lstrlenW(ui1->wkui1_oth_domains) +
105 lstrlenW(ui1->wkui1_logon_server)) * sizeof(WCHAR)),
106 "Is allocated with NetApiBufferAllocate");
108 /* Level 1101 */
109 ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
110 "NetWkstaUserGetInfo is successful");
111 ok(lstrcmpW(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains) == 0,
112 "the same oth_domains as returned for level 1");
113 pNetApiBufferSize(ui1101, &dwSize);
114 ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
115 lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
116 "Is allocated with NetApiBufferAllocate");
118 pNetApiBufferFree(ui0);
119 pNetApiBufferFree(ui1);
120 pNetApiBufferFree(ui1101);
122 /* errors handling */
123 ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
124 "Invalid level");
127 static void run_wkstatransportenum_tests(void)
129 LPBYTE bufPtr;
130 NET_API_STATUS apiReturn;
131 DWORD entriesRead, totalEntries;
133 if (!pNetWkstaTransportEnum)
134 return;
136 /* 1st check: is param 2 (level) correct? (only if param 5 passed?) */
137 apiReturn = pNetWkstaTransportEnum(NULL, 1, NULL, MAX_PREFERRED_LENGTH,
138 NULL, &totalEntries, NULL);
139 ok(apiReturn == ERROR_INVALID_LEVEL, "Invalid level");
141 /* 2nd check: is param 5 passed? (only if level passes?) */
142 apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
143 NULL, &totalEntries, NULL);
145 /* if no network adapter present, bail, the rest of the test will fail */
146 if (apiReturn == ERROR_NETWORK_UNREACHABLE)
147 return;
149 ok(apiReturn == STATUS_ACCESS_VIOLATION, "access violation");
151 /* 3rd check: is param 3 passed? */
152 apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
153 NULL, NULL, NULL);
154 ok(apiReturn == STATUS_ACCESS_VIOLATION, "STATUS_ACCESS_VIOLATION");
156 /* 4th check: is param 6 passed? */
157 apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
158 &entriesRead, NULL, NULL);
159 ok(apiReturn == RPC_X_NULL_REF_POINTER, "null pointer");
161 /* final check: valid return, actually get data back */
162 apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
163 &entriesRead, &totalEntries, NULL);
164 ok(apiReturn == NERR_Success, "NetWkstaTransportEnum is successful");
165 if (apiReturn == NERR_Success) {
166 /* WKSTA_TRANSPORT_INFO_0 *transports = (WKSTA_TRANSPORT_INFO_0 *)bufPtr; */
168 ok(bufPtr != NULL, "got data back");
169 ok(entriesRead > 0, "read at least one transport");
170 ok(totalEntries > 0, "at least one transport");
171 pNetApiBufferFree(bufPtr);
175 START_TEST(wksta)
177 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
178 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
179 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
180 pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
181 pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
182 pNetWkstaTransportEnum=(void*)GetProcAddress(hnetapi32,"NetWkstaTransportEnum");
183 if (!pNetApiBufferSize)
184 trace("It appears there is no netapi32 functionality on this platform\n");
186 if (init_wksta_tests()) {
187 run_get_comp_name_tests();
188 run_wkstausergetinfo_tests();
189 run_wkstatransportenum_tests();