2 * Copyright 2002 Andriy Palamarchuk
4 * Conformance test of the access 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>
28 WCHAR user_name[UNLEN + 1];
29 WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
31 const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
33 const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
34 const WCHAR sNonexistentUser[] = {'N','o','n','e','x','i','s','t','e','n','t',' ',
36 const WCHAR sBadNetPath[] = {'\\','\\','B','a',' ',' ','p','a','t','h',0};
37 const WCHAR sInvalidName[] = {'\\',0};
38 const WCHAR sInvalidName2[] = {'\\','\\',0};
39 const WCHAR sEmptyStr[] = { 0 };
41 static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
42 static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
43 static NET_API_STATUS (WINAPI *pNetQueryDisplayInformation)(LPWSTR,DWORD,DWORD,DWORD,DWORD,LPDWORD,PVOID*)=NULL;
44 static NET_API_STATUS (WINAPI *pNetUserGetInfo)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*)=NULL;
46 static int init_access_tests(void)
52 dwSize = sizeof(user_name);
53 rc=GetUserNameW(user_name, &dwSize);
54 if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
56 ok(rc, "User Name Retrieved");
59 dwSize = sizeof(computer_name);
60 ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
64 void run_usergetinfo_tests(void)
67 PUSER_INFO_0 ui0 = NULL;
68 PUSER_INFO_10 ui10 = NULL;
71 /* If this one is not defined then none of the others will be defined */
76 rc=pNetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0);
77 ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld", rc);
78 ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name");
79 pNetApiBufferSize(ui0, &dwSize);
80 ok(dwSize >= (sizeof(USER_INFO_0) +
81 (lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)),
82 "Is allocated with NetApiBufferAllocate");
85 rc=pNetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10);
86 ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld", rc);
87 ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name");
88 pNetApiBufferSize(ui10, &dwSize);
89 ok(dwSize >= (sizeof(USER_INFO_10) +
90 (lstrlenW(ui10->usri10_name) + 1 +
91 lstrlenW(ui10->usri10_comment) + 1 +
92 lstrlenW(ui10->usri10_usr_comment) + 1 +
93 lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)),
94 "Is allocated with NetApiBufferAllocate");
96 pNetApiBufferFree(ui0);
97 pNetApiBufferFree(ui10);
100 rc=pNetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0);
101 ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%ld",rc);
102 rc=pNetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0);
103 ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%ld",rc);
105 /* FIXME - Currently Wine can't verify whether the network path is good or bad */
106 rc=pNetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0);
107 ok(rc == ERROR_BAD_NETPATH,"Bad Network Path: rc=%ld",rc);
109 rc=pNetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0);
110 ok(rc == ERROR_BAD_NETPATH,"Bad Network Path: rc=%ld",rc);
111 rc=pNetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0);
112 ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld",rc);
113 rc=pNetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0);
114 ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld",rc);
117 /* checks Level 1 of NetQueryDisplayInformation */
118 void run_querydisplayinformation1_tests(void)
120 PNET_DISPLAY_USER Buffer, rec;
121 DWORD Result, EntryCount;
123 BOOL hasAdmin = FALSE;
124 BOOL hasGuest = FALSE;
126 if (!pNetQueryDisplayInformation)
131 Result = pNetQueryDisplayInformation(
132 NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount,
135 ok((Result == ERROR_SUCCESS) || (Result == ERROR_MORE_DATA),
136 "Information Retrieved");
138 for(; EntryCount > 0; EntryCount--)
140 if (!lstrcmpW(rec->usri1_name, sAdminUserName))
142 ok(!hasAdmin, "One admin user");
143 ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set");
144 ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set");
147 else if (!lstrcmpW(rec->usri1_name, sGuestUserName))
149 ok(!hasGuest, "One guest record");
150 ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set");
151 ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set");
155 i = rec->usri1_next_index;
159 pNetApiBufferFree(Buffer);
160 } while (Result == ERROR_MORE_DATA);
162 ok(hasAdmin, "Has Administrator account");
163 ok(hasGuest, "Has Guest account");
168 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
169 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
170 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
171 pNetQueryDisplayInformation=(void*)GetProcAddress(hnetapi32,"NetQueryDisplayInformation");
172 pNetUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetUserGetInfo");
173 if (!pNetApiBufferSize)
174 trace("It appears there is no netapi32 functionality on this platform\n");
176 if (init_access_tests()) {
177 run_usergetinfo_tests();
178 run_querydisplayinformation1_tests();