Merge the MDI and common window creation code. Change the way MDI
[wine.git] / dlls / netapi32 / tests / access.c
blob64e37dc774c324399f84e05e3742470d25f2c1ab
1 /*
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 <stdarg.h>
23 #include <wine/test.h>
24 #include <windef.h>
25 #include <winbase.h>
26 #include <winerror.h>
27 #include <lmaccess.h>
28 #include <lmerr.h>
29 #include <lmapibuf.h>
31 WCHAR user_name[UNLEN + 1];
32 WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
34 const WCHAR sAdminUserName[] = {'A','d','m','i','n','i','s','t','r','a','t',
35 'o','r',0};
36 const WCHAR sGuestUserName[] = {'G','u','e','s','t',0};
37 const WCHAR sNonexistentUser[] = {'N','o','n','e','x','i','s','t','e','n','t',' ',
38 'U','s','e','r',0};
39 const WCHAR sBadNetPath[] = {'\\','\\','B','a',' ',' ','p','a','t','h',0};
40 const WCHAR sInvalidName[] = {'\\',0};
41 const WCHAR sInvalidName2[] = {'\\','\\',0};
42 const WCHAR sEmptyStr[] = { 0 };
44 static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
45 static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
46 static NET_API_STATUS (WINAPI *pNetQueryDisplayInformation)(LPWSTR,DWORD,DWORD,DWORD,DWORD,LPDWORD,PVOID*)=NULL;
47 static NET_API_STATUS (WINAPI *pNetUserGetInfo)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*)=NULL;
49 static int init_access_tests(void)
51 DWORD dwSize;
52 BOOL rc;
54 user_name[0] = 0;
55 dwSize = sizeof(user_name);
56 rc=GetUserNameW(user_name, &dwSize);
57 if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
58 return 0;
59 ok(rc, "User Name Retrieved");
61 computer_name[0] = 0;
62 dwSize = sizeof(computer_name);
63 ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
64 return 1;
67 void run_usergetinfo_tests(void)
69 NET_API_STATUS rc;
70 PUSER_INFO_0 ui0 = NULL;
71 PUSER_INFO_10 ui10 = NULL;
72 DWORD dwSize;
74 /* If this one is not defined then none of the others will be defined */
75 if (!pNetUserGetInfo)
76 return;
78 /* Level 0 */
79 rc=pNetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0);
80 ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld", rc);
81 ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name");
82 pNetApiBufferSize(ui0, &dwSize);
83 ok(dwSize >= (sizeof(USER_INFO_0) +
84 (lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)),
85 "Is allocated with NetApiBufferAllocate");
87 /* Level 10 */
88 rc=pNetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10);
89 ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld", rc);
90 ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name");
91 pNetApiBufferSize(ui10, &dwSize);
92 ok(dwSize >= (sizeof(USER_INFO_10) +
93 (lstrlenW(ui10->usri10_name) + 1 +
94 lstrlenW(ui10->usri10_comment) + 1 +
95 lstrlenW(ui10->usri10_usr_comment) + 1 +
96 lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)),
97 "Is allocated with NetApiBufferAllocate");
99 pNetApiBufferFree(ui0);
100 pNetApiBufferFree(ui10);
102 /* errors handling */
103 rc=pNetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0);
104 ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%ld",rc);
105 rc=pNetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0);
106 ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%ld",rc);
107 todo_wine {
108 /* FIXME - Currently Wine can't verify whether the network path is good or bad */
109 rc=pNetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0);
110 ok(rc == ERROR_BAD_NETPATH || rc == ERROR_NETWORK_UNREACHABLE,
111 "Bad Network Path: rc=%ld",rc);
113 rc=pNetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0);
114 ok(rc == ERROR_BAD_NETPATH,"Bad Network Path: rc=%ld",rc);
115 rc=pNetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0);
116 ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld",rc);
117 rc=pNetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0);
118 ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld",rc);
121 /* checks Level 1 of NetQueryDisplayInformation */
122 void run_querydisplayinformation1_tests(void)
124 PNET_DISPLAY_USER Buffer, rec;
125 DWORD Result, EntryCount;
126 DWORD i = 0;
127 BOOL hasAdmin = FALSE;
128 BOOL hasGuest = FALSE;
130 if (!pNetQueryDisplayInformation)
131 return;
135 Result = pNetQueryDisplayInformation(
136 NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount,
137 (PVOID *)&Buffer);
139 ok((Result == ERROR_SUCCESS) || (Result == ERROR_MORE_DATA),
140 "Information Retrieved");
141 rec = Buffer;
142 for(; EntryCount > 0; EntryCount--)
144 if (!lstrcmpW(rec->usri1_name, sAdminUserName))
146 ok(!hasAdmin, "One admin user");
147 ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set");
148 ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set");
149 hasAdmin = TRUE;
151 else if (!lstrcmpW(rec->usri1_name, sGuestUserName))
153 ok(!hasGuest, "One guest record");
154 ok(rec->usri1_flags & UF_SCRIPT, "UF_SCRIPT flag is set");
155 ok(rec->usri1_flags & UF_NORMAL_ACCOUNT, "UF_NORMAL_ACCOUNT flag is set");
156 hasGuest = TRUE;
159 i = rec->usri1_next_index;
160 rec++;
163 pNetApiBufferFree(Buffer);
164 } while (Result == ERROR_MORE_DATA);
166 ok(hasAdmin, "Has Administrator account");
167 ok(hasGuest, "Has Guest account");
170 START_TEST(access)
172 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
173 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
174 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
175 pNetQueryDisplayInformation=(void*)GetProcAddress(hnetapi32,"NetQueryDisplayInformation");
176 pNetUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetUserGetInfo");
177 if (!pNetApiBufferSize)
178 trace("It appears there is no netapi32 functionality on this platform\n");
180 if (init_access_tests()) {
181 run_usergetinfo_tests();
182 run_querydisplayinformation1_tests();