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 "wine/test.h"
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;
37 WCHAR user_name[UNLEN + 1];
38 WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
40 static int init_wksta_tests(void)
46 dwSize = sizeof(user_name);
47 rc=GetUserNameW(user_name, &dwSize);
48 if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
50 ok(rc, "User Name Retrieved");
53 dwSize = sizeof(computer_name);
54 ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
58 static void run_get_comp_name_tests(void)
62 if (!pNetpGetComputerName)
65 ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved");
66 ok(!lstrcmpW(computer_name, ws), "This is really computer name");
67 pNetApiBufferFree(ws);
70 static void run_wkstausergetinfo_tests(void)
72 LPWKSTA_USER_INFO_0 ui0 = NULL;
73 LPWKSTA_USER_INFO_1 ui1 = NULL;
74 LPWKSTA_USER_INFO_1101 ui1101 = NULL;
77 if (!pNetWkstaUserGetInfo)
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");
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");
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");
112 pNetApiBufferFree(ui0);
113 pNetApiBufferFree(ui1);
114 pNetApiBufferFree(ui1101);
116 /* errors handling */
117 ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
121 static void run_wkstatransportenum_tests(void)
124 NET_API_STATUS apiReturn;
125 DWORD entriesRead, totalEntries;
127 if (!pNetWkstaTransportEnum)
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");
135 /* 2nd check: is param 5 passed? (only if level passes?) */
136 apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
137 NULL, &totalEntries, NULL);
139 /* if no network adapter present, bail, the rest of the test will fail */
140 if (apiReturn == ERROR_NETWORK_UNREACHABLE)
143 ok(apiReturn == STATUS_ACCESS_VIOLATION, "access violation");
145 /* 3rd check: is param 3 passed? */
146 apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
148 ok(apiReturn == STATUS_ACCESS_VIOLATION, "STATUS_ACCESS_VIOLATION");
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");
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; */
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);
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");
180 if (init_wksta_tests()) {
181 run_get_comp_name_tests();
182 run_wkstausergetinfo_tests();
183 run_wkstatransportenum_tests();