INT21_GetFreeDiskSpace(): The drive parameter is found in the DL
[wine] / dlls / netapi32 / tests / wksta.c
1 /*
2  * Copyright 2002 Andriy Palamarchuk
3  *
4  * Conformance test of the workstation functions.
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winnls.h"
28 #include "winresrc.h" /* Ensure we use Unicode defns with native headers */
29 #include "nb30.h"
30 #include "lmcons.h"
31 #include "lmerr.h"
32 #include "lmwksta.h"
33 #include "lmapibuf.h"
34
35 static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
36 static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
37 static NET_API_STATUS (WINAPI *pNetpGetComputerName)(LPWSTR*)=NULL;
38 static NET_API_STATUS (WINAPI *pNetWkstaUserGetInfo)(LPWSTR,DWORD,PBYTE*)=NULL;
39 static NET_API_STATUS (WINAPI *pNetWkstaTransportEnum)(LPWSTR,DWORD,LPBYTE*,
40  DWORD,LPDWORD,LPDWORD,LPDWORD)=NULL;
41
42 WCHAR user_name[UNLEN + 1];
43 WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
44
45 static int init_wksta_tests(void)
46 {
47     DWORD dwSize;
48     BOOL rc;
49
50     user_name[0] = 0;
51     dwSize = sizeof(user_name);
52     rc=GetUserNameW(user_name, &dwSize);
53     if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
54         return 0;
55     ok(rc, "User Name Retrieved");
56
57     computer_name[0] = 0;
58     dwSize = sizeof(computer_name);
59     ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
60     return 1;
61 }
62
63 static void run_get_comp_name_tests(void)
64 {
65     WCHAR empty[] = {0};
66     LPWSTR ws = empty;
67     if (!pNetpGetComputerName)
68         return;
69
70     ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved");
71     ok(!lstrcmpW(computer_name, ws), "This is really computer name");
72     pNetApiBufferFree(ws);
73 }
74
75 static void run_wkstausergetinfo_tests(void)
76 {
77     LPWKSTA_USER_INFO_0 ui0 = NULL;
78     LPWKSTA_USER_INFO_1 ui1 = NULL;
79     LPWKSTA_USER_INFO_1101 ui1101 = NULL;
80     DWORD dwSize;
81
82     if (!pNetWkstaUserGetInfo)
83         return;
84
85     /* Level 0 */
86     ok(pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success,
87        "NetWkstaUserGetInfo is successful");
88     ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name");
89     pNetApiBufferSize(ui0, &dwSize);
90     ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
91                  lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
92        "Is allocated with NetApiBufferAllocate");
93
94     /* Level 1 */
95     ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
96        "NetWkstaUserGetInfo is successful");
97     ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
98        "the same name as returned for level 0");
99     pNetApiBufferSize(ui1, &dwSize);
100     ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
101                   (lstrlenW(ui1->wkui1_username) +
102                    lstrlenW(ui1->wkui1_logon_domain) +
103                    lstrlenW(ui1->wkui1_oth_domains) +
104                    lstrlenW(ui1->wkui1_logon_server)) * sizeof(WCHAR)),
105        "Is allocated with NetApiBufferAllocate");
106
107     /* Level 1101 */
108     ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
109        "NetWkstaUserGetInfo is successful");
110     ok(lstrcmpW(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains) == 0,
111        "the same oth_domains as returned for level 1");
112     pNetApiBufferSize(ui1101, &dwSize);
113     ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
114                  lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
115        "Is allocated with NetApiBufferAllocate");
116
117     pNetApiBufferFree(ui0);
118     pNetApiBufferFree(ui1);
119     pNetApiBufferFree(ui1101);
120
121     /* errors handling */
122     ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
123        "Invalid level");
124 }
125
126 static void run_wkstatransportenum_tests(void)
127 {
128     LPBYTE bufPtr;
129     NET_API_STATUS apiReturn;
130     DWORD entriesRead, totalEntries;
131
132     if (!pNetWkstaTransportEnum)
133         return;
134
135     /* 1st check: is param 2 (level) correct? (only if param 5 passed?) */
136     apiReturn = pNetWkstaTransportEnum(NULL, 1, NULL, MAX_PREFERRED_LENGTH,
137         NULL, &totalEntries, NULL);
138     ok(apiReturn == ERROR_INVALID_LEVEL || apiReturn == ERROR_INVALID_PARAMETER,
139        "NetWkstaTransportEnum returned %ld", apiReturn);
140
141     /* 2nd check: is param 5 passed? (only if level passes?) */
142     apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
143         NULL, &totalEntries, NULL);
144
145     /* if no network adapter present, bail, the rest of the test will fail */
146     if (apiReturn == ERROR_NETWORK_UNREACHABLE)
147         return;
148
149     ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == ERROR_INVALID_PARAMETER,
150        "NetWkstaTransportEnum returned %ld", apiReturn);
151
152     /* 3rd check: is param 3 passed? */
153     apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
154         NULL, NULL, NULL);
155     ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == ERROR_INVALID_PARAMETER,
156        "NetWkstaTransportEnum returned %ld", apiReturn);
157
158     /* 4th check: is param 6 passed? */
159     apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
160         &entriesRead, NULL, NULL);
161     ok(apiReturn == RPC_X_NULL_REF_POINTER, "null pointer");
162
163     /* final check: valid return, actually get data back */
164     apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
165         &entriesRead, &totalEntries, NULL);
166     ok(apiReturn == NERR_Success || apiReturn == ERROR_NETWORK_UNREACHABLE,
167        "NetWkstaTransportEnum returned %ld", apiReturn);
168     if (apiReturn == NERR_Success) {
169         /* WKSTA_TRANSPORT_INFO_0 *transports = (WKSTA_TRANSPORT_INFO_0 *)bufPtr; */
170
171         ok(bufPtr != NULL, "got data back");
172         ok(entriesRead > 0, "read at least one transport");
173         ok(totalEntries > 0, "at least one transport");
174         pNetApiBufferFree(bufPtr);
175     }
176 }
177
178 START_TEST(wksta)
179 {
180     HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
181     pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
182     pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
183     pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
184     pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
185     pNetWkstaTransportEnum=(void*)GetProcAddress(hnetapi32,"NetWkstaTransportEnum");
186     if (!pNetApiBufferSize)
187         trace("It appears there is no netapi32 functionality on this platform\n");
188
189     if (init_wksta_tests()) {
190         run_get_comp_name_tests();
191         run_wkstausergetinfo_tests();
192         run_wkstatransportenum_tests();
193     }
194 }