Commit e480fa87 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

netapi32/tests: Remove some workarounds for no longer supported versions of Windows.

parent cc5e52ea
TESTDLL = netapi32.dll
IMPORTS = advapi32
IMPORTS = advapi32 netapi32
C_SRCS = \
access.c \
......
......@@ -29,12 +29,6 @@
#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;
static void run_apibuf_tests(void)
{
VOID *p;
......@@ -42,46 +36,46 @@ static void run_apibuf_tests(void)
NET_API_STATUS res;
/* test normal logic */
ok(pNetApiBufferAllocate(1024, &p) == NERR_Success,
ok(NetApiBufferAllocate(1024, &p) == NERR_Success,
"Reserved memory\n");
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
ok(dwSize >= 1024, "The size is correct\n");
ok(pNetApiBufferReallocate(p, 1500, &p) == NERR_Success,
ok(NetApiBufferReallocate(p, 1500, &p) == NERR_Success,
"Reallocated\n");
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
ok(dwSize >= 1500, "The size is correct\n");
ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
ok(NetApiBufferFree(p) == NERR_Success, "Freed\n");
ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer\n");
ok(NetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer\n");
/* border reallocate cases */
ok(pNetApiBufferReallocate(0, 1500, &p) == NERR_Success, "Reallocate with OldBuffer = NULL failed\n");
ok(NetApiBufferReallocate(0, 1500, &p) == NERR_Success, "Reallocate with OldBuffer = NULL failed\n");
ok(p != NULL, "No memory got allocated\n");
ok(pNetApiBufferFree(p) == NERR_Success, "NetApiBufferFree failed\n");
ok(NetApiBufferFree(p) == NERR_Success, "NetApiBufferFree failed\n");
ok(pNetApiBufferAllocate(1024, &p) == NERR_Success, "Memory not reserved\n");
ok(pNetApiBufferReallocate(p, 0, &p) == NERR_Success, "Not freed\n");
ok(NetApiBufferAllocate(1024, &p) == NERR_Success, "Memory not reserved\n");
ok(NetApiBufferReallocate(p, 0, &p) == NERR_Success, "Not freed\n");
ok(p == NULL, "Pointer not cleared\n");
/* 0-length buffer */
ok(pNetApiBufferAllocate(0, &p) == NERR_Success,
ok(NetApiBufferAllocate(0, &p) == NERR_Success,
"Reserved memory\n");
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
ok(NetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
ok(dwSize < 0xFFFFFFFF, "The size of the 0-length buffer\n");
ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
ok(NetApiBufferFree(p) == NERR_Success, "Freed\n");
/* NULL-Pointer */
/* NT: ERROR_INVALID_PARAMETER, lasterror is untouched) */
SetLastError(0xdeadbeef);
res = pNetApiBufferAllocate(0, NULL);
res = NetApiBufferAllocate(0, NULL);
ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
"returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
"0xdeadbeef)\n", res, GetLastError());
SetLastError(0xdeadbeef);
res = pNetApiBufferAllocate(1024, NULL);
res = NetApiBufferAllocate(1024, NULL);
ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
"returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
"0xdeadbeef)\n", res, GetLastError());
......@@ -89,17 +83,5 @@ static void run_apibuf_tests(void)
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 (pNetApiBufferAllocate && pNetApiBufferFree && pNetApiBufferReallocate && pNetApiBufferSize)
run_apibuf_tests();
else
win_skip("Needed functions are not available\n");
FreeLibrary(hnetapi32);
run_apibuf_tests();
}
......@@ -26,27 +26,24 @@
#include <winerror.h>
#include <dsrole.h>
static DWORD (WINAPI *pDsRoleGetPrimaryDomainInformation)(LPCWSTR, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL, PBYTE*);
static void (WINAPI *pDsRoleFreeMemory)(PVOID);
static void test_params(void)
{
DWORD ret;
PDSROLE_PRIMARY_DOMAIN_INFO_BASIC dpdi;
SetLastError(0xdeadbeef);
ret = pDsRoleGetPrimaryDomainInformation(NULL, DsRolePrimaryDomainInfoBasic, NULL);
ret = DsRoleGetPrimaryDomainInformation(NULL, DsRolePrimaryDomainInfoBasic, NULL);
ok( ret == ERROR_INVALID_PARAMETER, "Expected error ERROR_INVALID_PARAMETER, got (%d)\n", ret);
SetLastError(0xdeadbeef);
ret = pDsRoleGetPrimaryDomainInformation(NULL, 0, NULL);
ret = DsRoleGetPrimaryDomainInformation(NULL, 0, NULL);
ok( ret == ERROR_INVALID_PARAMETER, "Expected error ERROR_INVALID_PARAMETER, got (%d)\n", ret);
SetLastError(0xdeadbeef);
ret = pDsRoleGetPrimaryDomainInformation(NULL, 4, NULL);
ret = DsRoleGetPrimaryDomainInformation(NULL, 4, NULL);
ok( ret == ERROR_INVALID_PARAMETER, "Expected error ERROR_INVALID_PARAMETER, got (%d)\n", ret);
SetLastError(0xdeadbeef);
ret = pDsRoleGetPrimaryDomainInformation(NULL, 4, (PBYTE *)&dpdi);
ret = DsRoleGetPrimaryDomainInformation(NULL, 4, (BYTE **)&dpdi);
ok( ret == ERROR_INVALID_PARAMETER, "Expected error ERROR_INVALID_PARAMETER, got (%d)\n", ret);
}
......@@ -58,36 +55,24 @@ static void test_get(void)
PDSROLE_OPERATION_STATE_INFO dosi;
SetLastError(0xdeadbeef);
ret = pDsRoleGetPrimaryDomainInformation(NULL, DsRolePrimaryDomainInfoBasic, (PBYTE *)&dpdi);
ret = DsRoleGetPrimaryDomainInformation(NULL, DsRolePrimaryDomainInfoBasic, (BYTE **)&dpdi);
ok( ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got (%d)\n", ret);
pDsRoleFreeMemory(dpdi);
DsRoleFreeMemory(dpdi);
SetLastError(0xdeadbeef);
ret = pDsRoleGetPrimaryDomainInformation(NULL, DsRoleUpgradeStatus, (PBYTE *)&dusi);
ret = DsRoleGetPrimaryDomainInformation(NULL, DsRoleUpgradeStatus, (BYTE **)&dusi);
todo_wine { ok( ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got (%d)\n", ret); }
pDsRoleFreeMemory(dusi);
DsRoleFreeMemory(dusi);
SetLastError(0xdeadbeef);
ret = pDsRoleGetPrimaryDomainInformation(NULL, DsRoleOperationState, (PBYTE *)&dosi);
ret = DsRoleGetPrimaryDomainInformation(NULL, DsRoleOperationState, (BYTE **)&dosi);
todo_wine { ok( ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got (%d)\n", ret); }
pDsRoleFreeMemory(dosi);
DsRoleFreeMemory(dosi);
}
START_TEST(ds)
{
HMODULE hnetapi32 = LoadLibraryA("netapi32.dll");
pDsRoleGetPrimaryDomainInformation=(void*)GetProcAddress(hnetapi32,"DsRoleGetPrimaryDomainInformation");
if (pDsRoleGetPrimaryDomainInformation)
{
pDsRoleFreeMemory=(void*)GetProcAddress(hnetapi32,"DsRoleFreeMemory");
test_params();
test_get();
}
else
win_skip("DsRoleGetPrimaryDomainInformation is not available\n");
FreeLibrary(hnetapi32);
test_params();
test_get();
}
......@@ -33,44 +33,18 @@
#include "lmapibuf.h"
#include "lmjoin.h"
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;
static NET_API_STATUS (WINAPI *pNetWkstaTransportEnum)(LPWSTR,DWORD,LPBYTE*,
DWORD,LPDWORD,LPDWORD,LPDWORD)=NULL;
static NET_API_STATUS (WINAPI *pNetGetJoinInformation)(LPCWSTR,LPWSTR*,PNETSETUP_JOIN_STATUS);
static WCHAR user_name[UNLEN + 1];
static WCHAR computer_name[MAX_COMPUTERNAME_LENGTH + 1];
static BOOL init_wksta_tests(void)
{
DWORD dwSize;
BOOL rc;
user_name[0] = 0;
dwSize = ARRAY_SIZE(user_name);
rc=GetUserNameW(user_name, &dwSize);
if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) {
win_skip("GetUserNameW is not implemented\n");
return FALSE;
}
ok(rc, "User Name Retrieved\n");
computer_name[0] = 0;
dwSize = ARRAY_SIZE(computer_name);
ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
return TRUE;
}
static void run_get_comp_name_tests(void)
{
LPWSTR ws = NULL;
ok(pNetpGetComputerName(&ws) == NERR_Success, "Computer name is retrieved\n");
ok(!wcscmp(computer_name, ws), "Expected %s, got %s.\n", debugstr_w(computer_name), debugstr_w(ws));
pNetApiBufferFree(ws);
NetApiBufferFree(ws);
}
static void run_wkstausergetinfo_tests(void)
......@@ -82,34 +56,25 @@ static void run_wkstausergetinfo_tests(void)
NET_API_STATUS rc;
/* Level 0 */
rc = pNetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0);
rc = NetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&ui0);
if (rc == NERR_WkstaNotStarted)
{
skip("Workstation service not running\n");
return;
}
ok(!rc && ui0, "got %d and %p (expected NERR_Success and != NULL\n", rc, ui0);
/* This failure occurred when I ran sshd as service and didn't authenticate
* Since the test dereferences ui0, the rest of this test is worthless
*/
if (!ui0)
{
return;
}
ok(!wcscmp(user_name, ui0->wkui0_username), "Expected username %s, got %s.\n",
debugstr_w(user_name), debugstr_w(ui0->wkui0_username));
pNetApiBufferSize(ui0, &dwSize);
NetApiBufferSize(ui0, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_0) + wcslen(ui0->wkui0_username) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate\n");
/* Level 1 */
ok(pNetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
ok(NetWkstaUserGetInfo(NULL, 1, (LPBYTE *)&ui1) == NERR_Success,
"NetWkstaUserGetInfo is successful\n");
ok(!wcscmp(user_name, ui1->wkui1_username), "Expected username %s, got %s.\n",
debugstr_w(user_name), debugstr_w(ui1->wkui1_username));
pNetApiBufferSize(ui1, &dwSize);
NetApiBufferSize(ui1, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_1) +
(wcslen(ui1->wkui1_username) +
wcslen(ui1->wkui1_logon_domain) +
......@@ -118,20 +83,20 @@ static void run_wkstausergetinfo_tests(void)
"Is allocated with NetApiBufferAllocate\n");
/* Level 1101 */
ok(pNetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
ok(NetWkstaUserGetInfo(NULL, 1101, (LPBYTE *)&ui1101) == NERR_Success,
"NetWkstaUserGetInfo is successful\n");
ok(!wcscmp(ui1101->wkui1101_oth_domains, ui1->wkui1_oth_domains), "Expected %s, got %s.\n",
debugstr_w(ui1->wkui1_oth_domains), debugstr_w(ui1101->wkui1101_oth_domains));
pNetApiBufferSize(ui1101, &dwSize);
NetApiBufferSize(ui1101, &dwSize);
ok(dwSize >= (sizeof(WKSTA_USER_INFO_1101) + wcslen(ui1101->wkui1101_oth_domains) * sizeof(WCHAR)),
"Is allocated with NetApiBufferAllocate\n");
pNetApiBufferFree(ui0);
pNetApiBufferFree(ui1);
pNetApiBufferFree(ui1101);
NetApiBufferFree(ui0);
NetApiBufferFree(ui1);
NetApiBufferFree(ui1101);
/* errors handling */
ok(pNetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
ok(NetWkstaUserGetInfo(NULL, 10000, (LPBYTE *)&ui0) == ERROR_INVALID_LEVEL,
"Invalid level\n");
}
......@@ -142,13 +107,13 @@ static void run_wkstatransportenum_tests(void)
DWORD entriesRead, totalEntries;
/* 1st check: is param 2 (level) correct? (only if param 5 passed?) */
apiReturn = pNetWkstaTransportEnum(NULL, 1, NULL, MAX_PREFERRED_LENGTH,
apiReturn = NetWkstaTransportEnum(NULL, 1, NULL, MAX_PREFERRED_LENGTH,
NULL, &totalEntries, NULL);
ok(apiReturn == ERROR_INVALID_LEVEL || apiReturn == ERROR_INVALID_PARAMETER,
"NetWkstaTransportEnum returned %d\n", apiReturn);
/* 2nd check: is param 5 passed? (only if level passes?) */
apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
apiReturn = NetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
NULL, &totalEntries, NULL);
/* if no network adapter present, bail, the rest of the test will fail */
......@@ -159,19 +124,19 @@ static void run_wkstatransportenum_tests(void)
"NetWkstaTransportEnum returned %d\n", apiReturn);
/* 3rd check: is param 3 passed? */
apiReturn = pNetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
apiReturn = NetWkstaTransportEnum(NULL, 0, NULL, MAX_PREFERRED_LENGTH,
NULL, NULL, NULL);
ok(apiReturn == STATUS_ACCESS_VIOLATION || apiReturn == RPC_X_NULL_REF_POINTER || apiReturn == ERROR_INVALID_PARAMETER,
"NetWkstaTransportEnum returned %d\n", apiReturn);
/* 4th check: is param 6 passed? */
apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
apiReturn = NetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
&entriesRead, NULL, NULL);
ok(apiReturn == RPC_X_NULL_REF_POINTER,
"NetWkstaTransportEnum returned %d\n", apiReturn);
/* final check: valid return, actually get data back */
apiReturn = pNetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
apiReturn = NetWkstaTransportEnum(NULL, 0, &bufPtr, MAX_PREFERRED_LENGTH,
&entriesRead, &totalEntries, NULL);
ok(apiReturn == NERR_Success || apiReturn == ERROR_NETWORK_UNREACHABLE || apiReturn == NERR_WkstaNotStarted,
"NetWkstaTransportEnum returned %d\n", apiReturn);
......@@ -182,7 +147,7 @@ static void run_wkstatransportenum_tests(void)
ok(entriesRead > 0, "read at least one transport\n");
ok(totalEntries > 0 || broken(totalEntries == 0) /* Win7 */,
"at least one transport\n");
pNetApiBufferFree(bufPtr);
NetApiBufferFree(bufPtr);
}
}
......@@ -191,52 +156,37 @@ static void run_wkstajoininfo_tests(void)
NET_API_STATUS ret;
LPWSTR buffer = NULL;
NETSETUP_JOIN_STATUS buffertype = 0xdada;
/* NT4 doesn't have this function */
if (!pNetGetJoinInformation) {
win_skip("NetGetJoinInformation not available\n");
return;
}
ret = pNetGetJoinInformation(NULL, NULL, NULL);
ret = NetGetJoinInformation(NULL, NULL, NULL);
ok(ret == ERROR_INVALID_PARAMETER, "NetJoinGetInformation returned unexpected 0x%08x\n", ret);
ok(buffertype == 0xdada, "buffertype set to unexpected value %d\n", buffertype);
ret = pNetGetJoinInformation(NULL, &buffer, &buffertype);
ret = NetGetJoinInformation(NULL, &buffer, &buffertype);
ok(ret == NERR_Success, "NetJoinGetInformation returned unexpected 0x%08x\n", ret);
ok(buffertype != 0xdada && buffertype != NetSetupUnknownStatus, "buffertype set to unexpected value %d\n", buffertype);
trace("workstation joined to %s with status %d\n", wine_dbgstr_w(buffer), buffertype);
pNetApiBufferFree(buffer);
NetApiBufferFree(buffer);
}
START_TEST(wksta)
{
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");
pNetWkstaTransportEnum=(void*)GetProcAddress(hnetapi32,"NetWkstaTransportEnum");
pNetGetJoinInformation=(void*)GetProcAddress(hnetapi32,"NetGetJoinInformation");
/* These functions were introduced with NT. It's safe to assume that
* if one is not available, none are.
*/
if (!pNetApiBufferFree) {
win_skip("Needed functions are not available\n");
FreeLibrary(hnetapi32);
return;
}
if (init_wksta_tests()) {
if (pNetpGetComputerName)
run_get_comp_name_tests();
else
win_skip("Function NetpGetComputerName not available\n");
run_wkstausergetinfo_tests();
run_wkstatransportenum_tests();
run_wkstajoininfo_tests();
}
FreeLibrary(hnetapi32);
DWORD size;
BOOL ret;
pNetpGetComputerName = (void *)GetProcAddress(GetModuleHandleA("netapi32.dll"), "NetpGetComputerName");
size = sizeof(user_name);
ret = GetUserNameW(user_name, &size);
ok(ret, "Failed to get user name, error %u.\n", GetLastError());
size = sizeof(computer_name);
ret = GetComputerNameW(computer_name, &size);
ok(ret, "Failed to get computer name, error %u.\n", GetLastError());
if (pNetpGetComputerName)
run_get_comp_name_tests();
else
win_skip("Function NetpGetComputerName not available\n");
run_wkstausergetinfo_tests();
run_wkstatransportenum_tests();
run_wkstajoininfo_tests();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment