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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
28 #include "winresrc.h" /* Ensure we use Unicode defns with native headers */
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;
42 WCHAR user_name[UNLEN + 1];
43 WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
45 static int init_wksta_tests(void)
51 dwSize = sizeof(user_name)/sizeof(user_name[0]);
52 rc=GetUserNameW(user_name, &dwSize);
53 if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) {
54 skip("GetUserNameW is not implemented\n");
57 ok(rc, "User Name Retrieved\n");
60 dwSize = sizeof(computer_name)/sizeof(computer_name[0]);
61 ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
65 static void run_get_comp_name_tests(void)
69 ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved\n");
70 ok(!lstrcmpW(computer_name, ws), "This is really computer name\n");
71 pNetApiBufferFree(ws);
74 static void run_wkstausergetinfo_tests(void)
76 LPWKSTA_USER_INFO_0 ui0 = NULL;
77 LPWKSTA_USER_INFO_1 ui1 = NULL;
78 LPWKSTA_USER_INFO_1101 ui1101 = NULL;
82 ok(pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success,
83 "NetWkstaUserGetInfo is successful\n");
84 ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name\n");
85 pNetApiBufferSize(ui0, &dwSize);
86 ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
87 lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
88 "Is allocated with NetApiBufferAllocate\n");
91 ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
92 "NetWkstaUserGetInfo is successful\n");
93 ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
94 "the same name as returned for level 0\n");
95 pNetApiBufferSize(ui1, &dwSize);
96 ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
97 (lstrlenW(ui1->wkui1_username) +
98 lstrlenW(ui1->wkui1_logon_domain) +
99 lstrlenW(ui1->wkui1_oth_domains) +
100 lstrlenW(ui1->wkui1_logon_server)) * sizeof(WCHAR)),
101 "Is allocated with NetApiBufferAllocate\n");
104 ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
105 "NetWkstaUserGetInfo is successful\n");
106 ok(lstrcmpW(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains) == 0,
107 "the same oth_domains as returned for level 1\n");
108 pNetApiBufferSize(ui1101, &dwSize);
109 ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
110 lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
111 "Is allocated with NetApiBufferAllocate\n");
113 pNetApiBufferFree(ui0);
114 pNetApiBufferFree(ui1);
115 pNetApiBufferFree(ui1101);
117 /* errors handling */
118 ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
122 static void run_wkstatransportenum_tests(void)
125 NET_API_STATUS apiReturn;
126 DWORD entriesRead, totalEntries;
128 /* 1st check: is param 2 (level) correct? (only if param 5 passed?) */
129 apiReturn = pNetWkstaTransportEnum(NULL, 1, NULL, MAX_PREFERRED_LENGTH,
130 NULL, &totalEntries, NULL);
131 ok(apiReturn == ERROR_INVALID_LEVEL || apiReturn == ERROR_INVALID_PARAMETER,
132 "NetWkstaTransportEnum returned %d\n", apiReturn);
134 /* 2nd check: is param 5 passed? (only if level passes?) */
135 apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
136 NULL, &totalEntries, NULL);
138 /* if no network adapter present, bail, the rest of the test will fail */
139 if (apiReturn == ERROR_NETWORK_UNREACHABLE)
142 ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == ERROR_INVALID_PARAMETER,
143 "NetWkstaTransportEnum returned %d\n", apiReturn);
145 /* 3rd check: is param 3 passed? */
146 apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
148 ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == RPC_X_NULL_REF_POINTER || apiReturn == ERROR_INVALID_PARAMETER,
149 "NetWkstaTransportEnum returned %d\n", apiReturn);
151 /* 4th check: is param 6 passed? */
152 apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
153 &entriesRead, NULL, NULL);
154 ok(apiReturn == RPC_X_NULL_REF_POINTER, "null pointer\n");
156 /* final check: valid return, actually get data back */
157 apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
158 &entriesRead, &totalEntries, NULL);
159 ok(apiReturn == NERR_Success || apiReturn == ERROR_NETWORK_UNREACHABLE,
160 "NetWkstaTransportEnum returned %d\n", apiReturn);
161 if (apiReturn == NERR_Success) {
162 /* WKSTA_TRANSPORT_INFO_0 *transports = (WKSTA_TRANSPORT_INFO_0 *)bufPtr; */
164 ok(bufPtr != NULL, "got data back\n");
165 ok(entriesRead > 0, "read at least one transport\n");
166 ok(totalEntries > 0, "at least one transport\n");
167 pNetApiBufferFree(bufPtr);
173 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
175 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
176 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
177 pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
178 pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
179 pNetWkstaTransportEnum=(void*)GetProcAddress(hnetapi32,"NetWkstaTransportEnum");
181 /* These functions were introduced with NT. It's safe to assume that
182 * if one is not available, none are.
184 if (!pNetApiBufferFree) {
185 skip("Needed functions are not available\n");
186 FreeLibrary(hnetapi32);
190 if (init_wksta_tests()) {
191 run_get_comp_name_tests();
192 run_wkstausergetinfo_tests();
193 run_wkstatransportenum_tests();
196 FreeLibrary(hnetapi32);