On Win9x netapi32.dll does not export a single API so we do a

GetProcAddress for each of them and skip the tests when necessary.
On Win9x GetUserNameW and GetComputerNameW are stubs.
Improve error reporting in access.c.
This commit is contained in:
Francois Gouget 2002-12-19 01:04:12 +00:00 committed by Alexandre Julliard
parent 305ead6205
commit b611dac7ef
3 changed files with 127 additions and 70 deletions

View File

@ -38,40 +38,54 @@ const WCHAR sInvalidName[] = {'\\',0};
const WCHAR sInvalidName2[] = {'\\','\\',0};
const WCHAR sEmptyStr[] = { 0 };
static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
static NET_API_STATUS (WINAPI *pNetQueryDisplayInformation)(LPWSTR,DWORD,DWORD,DWORD,DWORD,LPDWORD,PVOID*)=NULL;
static NET_API_STATUS (WINAPI *pNetUserGetInfo)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*)=NULL;
void init_access_tests(void)
static int init_access_tests(void)
{
DWORD dwSize;
BOOL rc;
user_name[0] = 0;
dwSize = sizeof(user_name);
ok(GetUserNameW(user_name, &dwSize), "User Name Retrieved");
rc=GetUserNameW(user_name, &dwSize);
if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return 0;
ok(rc, "User Name Retrieved");
computer_name[0] = 0;
dwSize = sizeof(computer_name);
ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
return 1;
}
void run_usergetinfo_tests(void)
{
NET_API_STATUS rc;
PUSER_INFO_0 ui0 = NULL;
PUSER_INFO_10 ui10 = NULL;
DWORD dwSize;
/* If this one is not defined then none of the others will be defined */
if (!pNetUserGetInfo)
return;
/* Level 0 */
ok(NetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0) == NERR_Success,
"NetUserGetInfo is successful");
rc=pNetUserGetInfo(NULL, sAdminUserName, 0, (LPBYTE *)&ui0);
ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld", rc);
ok(!lstrcmpW(sAdminUserName, ui0->usri0_name), "This is really user name");
NetApiBufferSize(ui0, &dwSize);
pNetApiBufferSize(ui0, &dwSize);
ok(dwSize >= (sizeof(USER_INFO_0) +
(lstrlenW(ui0->usri0_name) + 1) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate");
/* Level 10 */
ok(NetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10) == NERR_Success,
"NetUserGetInfo is successful");
rc=pNetUserGetInfo(NULL, sAdminUserName, 10, (LPBYTE *)&ui10);
ok(rc == NERR_Success, "NetUserGetInfo: rc=%ld", rc);
ok(!lstrcmpW(sAdminUserName, ui10->usri10_name), "This is really user name");
NetApiBufferSize(ui10, &dwSize);
pNetApiBufferSize(ui10, &dwSize);
ok(dwSize >= (sizeof(USER_INFO_10) +
(lstrlenW(ui10->usri10_name) + 1 +
lstrlenW(ui10->usri10_comment) + 1 +
@ -79,25 +93,25 @@ void run_usergetinfo_tests(void)
lstrlenW(ui10->usri10_full_name) + 1) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate");
NetApiBufferFree(ui0);
NetApiBufferFree(ui10);
pNetApiBufferFree(ui0);
pNetApiBufferFree(ui10);
/* errors handling */
ok(NetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
"Invalid Level");
ok(NetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0) == NERR_UserNotFound,
"Invalid User Name");
rc=pNetUserGetInfo(NULL, sAdminUserName, 10000, (LPBYTE *)&ui0);
ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%ld",rc);
rc=pNetUserGetInfo(NULL, sNonexistentUser, 0, (LPBYTE *)&ui0);
ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%ld",rc);
todo_wine {
/* FIXME - Currently Wine can't verify whether the network path is good or bad */
ok(NetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0) == ERROR_BAD_NETPATH,
"Bad Network Path");
rc=pNetUserGetInfo(sBadNetPath, sAdminUserName, 0, (LPBYTE *)&ui0);
ok(rc == ERROR_BAD_NETPATH,"Bad Network Path: rc=%ld",rc);
}
ok(NetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0) == ERROR_BAD_NETPATH,
"Bad Network Path");
ok(NetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0) == ERROR_INVALID_NAME,
"Invalid Server Name");
ok(NetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0) == ERROR_INVALID_NAME,
"Invalid Server Name");
rc=pNetUserGetInfo(sEmptyStr, sAdminUserName, 0, (LPBYTE *)&ui0);
ok(rc == ERROR_BAD_NETPATH,"Bad Network Path: rc=%ld",rc);
rc=pNetUserGetInfo(sInvalidName, sAdminUserName, 0, (LPBYTE *)&ui0);
ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld",rc);
rc=pNetUserGetInfo(sInvalidName2, sAdminUserName, 0, (LPBYTE *)&ui0);
ok(rc == ERROR_INVALID_NAME,"Invalid Server Name: rc=%ld",rc);
}
/* checks Level 1 of NetQueryDisplayInformation */
@ -109,9 +123,12 @@ void run_querydisplayinformation1_tests(void)
BOOL hasAdmin = FALSE;
BOOL hasGuest = FALSE;
if (!pNetQueryDisplayInformation)
return;
do
{
Result = NetQueryDisplayInformation(
Result = pNetQueryDisplayInformation(
NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount,
(PVOID *)&Buffer);
@ -139,7 +156,7 @@ void run_querydisplayinformation1_tests(void)
rec++;
}
NetApiBufferFree(Buffer);
pNetApiBufferFree(Buffer);
} while (Result == ERROR_MORE_DATA);
ok(hasAdmin, "Has Administrator account");
@ -148,7 +165,16 @@ void run_querydisplayinformation1_tests(void)
START_TEST(access)
{
init_access_tests();
run_usergetinfo_tests();
run_querydisplayinformation1_tests();
HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
pNetQueryDisplayInformation=(void*)GetProcAddress(hnetapi32,"NetQueryDisplayInformation");
pNetUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetUserGetInfo");
if (!pNetApiBufferSize)
trace("It appears there is no netapi32 functionality on this platform\n");
if (init_access_tests()) {
run_usergetinfo_tests();
run_querydisplayinformation1_tests();
}
}

View File

@ -26,40 +26,57 @@
#include <lmapibuf.h>
#include <lmaccess.h>
static NET_API_STATUS (WINAPI *pNetApiBufferAllocate)(DWORD,LPVOID*)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferReallocate)(LPVOID,DWORD,LPVOID*)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
void run_apibuf_tests(void)
{
VOID *p;
DWORD dwSize;
if (!pNetApiBufferAllocate)
return;
/* test normal logic */
ok(NetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success,
ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success,
"Reserved memory");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(dwSize >= 1024, "The size is correct");
ok(NetApiBufferReallocate(p, 1500, (LPVOID *) &p) == NERR_Success,
ok(pNetApiBufferReallocate(p, 1500, (LPVOID *) &p) == NERR_Success,
"Reallocated");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(dwSize >= 1500, "The size is correct");
ok(NetApiBufferFree(p) == NERR_Success, "Freed");
ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
/* test errors handling */
ok(NetApiBufferFree(p) == NERR_Success, "Freed");
ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(dwSize >= 0, "The size");
ok(NetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer");
ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer");
/* 0-length buffer */
ok(NetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
ok(pNetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
"Reserved memory");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
ok((dwSize >= 0) && (dwSize < 0xFFFFFFFF),"The size of the 0-length buffer");
ok(NetApiBufferFree(p) == NERR_Success, "Freed");
ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
}
START_TEST(apibuf)
{
HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
pNetApiBufferAllocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferAllocate");
pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
pNetApiBufferReallocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferReallocate");
pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
if (!pNetApiBufferSize)
trace("It appears there is no netapi32 functionality on this platform\n");
run_apibuf_tests();
}

View File

@ -27,64 +27,69 @@
#include "lmwksta.h"
#include "lmapibuf.h"
typedef NET_API_STATUS (WINAPI *NetpGetComputerName_func)(LPWSTR *Buffer);
static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
static NET_API_STATUS (WINAPI *pNetpGetComputerName)(LPWSTR*)=NULL;
static NET_API_STATUS (WINAPI *pNetWkstaUserGetInfo)(LPWSTR,DWORD,PBYTE*)=NULL;
WCHAR user_name[UNLEN + 1];
WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
void init_wksta_tests(void)
static int init_wksta_tests(void)
{
DWORD dwSize;
BOOL rc;
user_name[0] = 0;
dwSize = sizeof(user_name);
ok(GetUserNameW(user_name, &dwSize), "User Name Retrieved");
rc=GetUserNameW(user_name, &dwSize);
if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return 0;
ok(rc, "User Name Retrieved");
computer_name[0] = 0;
dwSize = sizeof(computer_name);
ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved");
return 1;
}
void run_get_comp_name_tests(void)
static void run_get_comp_name_tests(void)
{
HANDLE hnetapi32 = GetModuleHandleA("netapi32.dll");
if (hnetapi32)
{
WCHAR empty[] = {0};
LPWSTR ws = empty;
NetpGetComputerName_func pNetpGetComputerName;
pNetpGetComputerName = (NetpGetComputerName_func)GetProcAddress(hnetapi32,"NetpGetComputerName");
if (pNetpGetComputerName)
{
ok((*pNetpGetComputerName)(&ws) == NERR_Success, "Computer name is retrieved");
ok(!lstrcmpW(computer_name, ws), "This is really computer name");
NetApiBufferFree(ws);
}
}
WCHAR empty[] = {0};
LPWSTR ws = empty;
if (!pNetpGetComputerName)
return;
ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved");
ok(!lstrcmpW(computer_name, ws), "This is really computer name");
pNetApiBufferFree(ws);
}
void run_wkstausergetinfo_tests(void)
static void run_wkstausergetinfo_tests(void)
{
LPWKSTA_USER_INFO_0 ui0 = NULL;
LPWKSTA_USER_INFO_1 ui1 = NULL;
LPWKSTA_USER_INFO_1101 ui1101 = NULL;
DWORD dwSize;
if (!pNetWkstaUserGetInfo)
return;
/* Level 0 */
ok(NetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success,
ok(pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0) == NERR_Success,
"NetWkstaUserGetInfo is successful");
ok(!lstrcmpW(user_name, ui0->wkui0_username), "This is really user name");
NetApiBufferSize(ui0, &dwSize);
pNetApiBufferSize(ui0, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) +
lstrlenW(ui0->wkui0_username) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate");
/* Level 1 */
ok(NetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
"NetWkstaUserGetInfo is successful");
ok(lstrcmpW(ui1->wkui1_username, ui0->wkui0_username) == 0,
"the same name as returned for level 0");
NetApiBufferSize(ui1, &dwSize);
pNetApiBufferSize(ui1, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
(lstrlenW(ui1->wkui1_username) +
lstrlenW(ui1->wkui1_logon_domain) +
@ -93,27 +98,36 @@ void run_wkstausergetinfo_tests(void)
"Is allocated with NetApiBufferAllocate");
/* Level 1101 */
ok(NetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
"NetWkstaUserGetInfo is successful");
ok(lstrcmpW(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains) == 0,
"the same oth_domains as returned for level 1");
NetApiBufferSize(ui1101, &dwSize);
pNetApiBufferSize(ui1101, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) +
lstrlenW(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate");
NetApiBufferFree(ui0);
NetApiBufferFree(ui1);
NetApiBufferFree(ui1101);
pNetApiBufferFree(ui0);
pNetApiBufferFree(ui1);
pNetApiBufferFree(ui1101);
/* errors handling */
ok(NetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
"Invalid level");
}
START_TEST(wksta)
{
init_wksta_tests();
run_get_comp_name_tests();
run_wkstausergetinfo_tests();
HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
pNetpGetComputerName=(void*)GetProcAddress(hnetapi32,"NetpGetComputerName");
pNetWkstaUserGetInfo=(void*)GetProcAddress(hnetapi32,"NetWkstaUserGetInfo");
if (!pNetApiBufferSize)
trace("It appears there is no netapi32 functionality on this platform\n");
if (init_wksta_tests()) {
run_get_comp_name_tests();
run_wkstausergetinfo_tests();
}
}