Fixed a race condition on RPC worker thread creation, and a typo.
[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
35 WCHAR user_name[UNLEN + 1];
36 WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
37
38 static int init_wksta_tests(void)
39 {
40     DWORD dwSize;
41     BOOL rc;
42
43     user_name[0] = 0;
44     dwSize = sizeof(user_name);
45     rc=GetUserNameW(user_name, &dwSize);
46     if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
47         return 0;
48     ok(rc, "User Name Retrieved");
49
50     computer_name[0] = 0;
51     dwSize = sizeof(computer_name);
52     ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
53     return 1;
54 }
55
56 static void run_get_comp_name_tests(void)
57 {
58     WCHAR empty[] = {0};
59     LPWSTR ws = empty;
60     if (!pNetpGetComputerName)
61         return;
62
63     ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved");
64     ok(!lstrcmpW(computer_name, ws), "This is really computer name");
65     pNetApiBufferFree(ws);
66 }
67
68 static void run_wkstausergetinfo_tests(void)
69 {
70     LPWKSTA_USER_INFO_0 ui0 = NULL;
71     LPWKSTA_USER_INFO_1 ui1 = NULL;
72     LPWKSTA_USER_INFO_1101 ui1101 = NULL;
73     DWORD dwSize;
74
75     if (!pNetWkstaUserGetInfo)
76         return;
77
78     /* Level 0 */
79     ok(pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success,
80        "NetWkstaUserGetInfo is successful");
81     ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name");
82     pNetApiBufferSize(ui0, &dwSize);
83     ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
84                  lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
85        "Is allocated with NetApiBufferAllocate");
86
87     /* Level 1 */
88     ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
89        "NetWkstaUserGetInfo is successful");
90     ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
91        "the same name as returned for level 0");
92     pNetApiBufferSize(ui1, &dwSize);
93     ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
94                   (lstrlenW(ui1->wkui1_username) +
95                    lstrlenW(ui1->wkui1_logon_domain) +
96                    lstrlenW(ui1->wkui1_oth_domains) +
97                    lstrlenW(ui1->wkui1_logon_server)) * sizeof(WCHAR)),
98        "Is allocated with NetApiBufferAllocate");
99
100     /* Level 1101 */
101     ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
102        "NetWkstaUserGetInfo is successful");
103     ok(lstrcmpW(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains) == 0,
104        "the same oth_domains as returned for level 1");
105     pNetApiBufferSize(ui1101, &dwSize);
106     ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
107                  lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
108        "Is allocated with NetApiBufferAllocate");
109
110     pNetApiBufferFree(ui0);
111     pNetApiBufferFree(ui1);
112     pNetApiBufferFree(ui1101);
113
114     /* errors handling */
115     ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
116        "Invalid level");
117 }
118
119 START_TEST(wksta)
120 {
121     HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
122     pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
123     pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
124     pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
125     pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
126     if (!pNetApiBufferSize)
127         trace("It appears there is no netapi32 functionality on this platform\n");
128
129     if (init_wksta_tests()) {
130         run_get_comp_name_tests();
131         run_wkstausergetinfo_tests();
132     }
133 }