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