From e480fa87adbf31a609e2056aae49348727c2df6d Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Wed, 8 Jan 2020 15:23:22 -0600 Subject: [PATCH] netapi32/tests: Remove some workarounds for no longer supported versions of Windows. Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/netapi32/tests/Makefile.in | 2 +- dlls/netapi32/tests/access.c | 153 ++++++++++---------------------- dlls/netapi32/tests/apibuf.c | 50 ++++------- dlls/netapi32/tests/ds.c | 39 +++----- dlls/netapi32/tests/wksta.c | 122 ++++++++----------------- 5 files changed, 113 insertions(+), 253 deletions(-) diff --git a/dlls/netapi32/tests/Makefile.in b/dlls/netapi32/tests/Makefile.in index 2b87bce0acc..3ca81e6e2bc 100644 --- a/dlls/netapi32/tests/Makefile.in +++ b/dlls/netapi32/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = netapi32.dll -IMPORTS = advapi32 +IMPORTS = advapi32 netapi32 C_SRCS = \ access.c \ diff --git a/dlls/netapi32/tests/access.c b/dlls/netapi32/tests/access.c index c7be9148a3a..3cf6cb35ddb 100644 --- a/dlls/netapi32/tests/access.c +++ b/dlls/netapi32/tests/access.c @@ -40,39 +40,9 @@ static WCHAR sTooLongPassword[] = L"abcdefghabcdefghabcdefghabcdefghabcdefgh" static WCHAR sTestUserOldPass[] = L"OldPassW0rdSet!~"; -static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID); -static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD); -static NET_API_STATUS (WINAPI *pNetQueryDisplayInformation)(LPWSTR,DWORD,DWORD,DWORD,DWORD,LPDWORD,PVOID*); -static NET_API_STATUS (WINAPI *pNetUserGetInfo)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*); -static NET_API_STATUS (WINAPI *pNetUserModalsGet)(LPCWSTR,DWORD,LPBYTE*); -static NET_API_STATUS (WINAPI *pNetUserAdd)(LPCWSTR,DWORD,LPBYTE,LPDWORD); -static NET_API_STATUS (WINAPI *pNetUserDel)(LPCWSTR,LPCWSTR); -static NET_API_STATUS (WINAPI *pNetLocalGroupGetInfo)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*); -static NET_API_STATUS (WINAPI *pNetLocalGroupGetMembers)(LPCWSTR,LPCWSTR,DWORD,LPBYTE*,DWORD,LPDWORD,LPDWORD,PDWORD_PTR); static DWORD (WINAPI *pDavGetHTTPFromUNCPath)(LPCWSTR,LPWSTR,LPDWORD); static DWORD (WINAPI *pDavGetUNCFromHTTPPath)(LPCWSTR,LPWSTR,LPDWORD); -static BOOL init_access_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 available.\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 NET_API_STATUS create_test_user(void) { USER_INFO_1 usri; @@ -85,12 +55,12 @@ static NET_API_STATUS create_test_user(void) usri.usri1_flags = UF_SCRIPT; usri.usri1_script_path = NULL; - return pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL); + return NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); } static NET_API_STATUS delete_test_user(void) { - return pNetUserDel(NULL, L"testuser"); + return NetUserDel(NULL, L"testuser"); } static void run_usergetinfo_tests(void) @@ -107,18 +77,18 @@ static void run_usergetinfo_tests(void) } /* Level 0 */ - rc = pNetUserGetInfo(NULL, L"testuser", 0, (LPBYTE *)&ui0); + rc = NetUserGetInfo(NULL, L"testuser", 0, (BYTE **)&ui0); ok(rc == NERR_Success, "NetUserGetInfo level 0 failed: 0x%08x.\n", rc); ok(!wcscmp(L"testuser", ui0->usri0_name), "Got level 0 name %s.\n", debugstr_w(ui0->usri0_name)); - pNetApiBufferSize(ui0, &dwSize); + NetApiBufferSize(ui0, &dwSize); ok(dwSize >= (sizeof(USER_INFO_0) + (wcslen(ui0->usri0_name) + 1) * sizeof(WCHAR)), "Is allocated with NetApiBufferAllocate\n"); /* Level 10 */ - rc = pNetUserGetInfo(NULL, L"testuser", 10, (LPBYTE *)&ui10); + rc = NetUserGetInfo(NULL, L"testuser", 10, (BYTE **)&ui10); ok(rc == NERR_Success, "NetUserGetInfo level 10 failed: 0x%08x.\n", rc); ok(!wcscmp(L"testuser", ui10->usri10_name), "Got level 10 name %s.\n", debugstr_w(ui10->usri10_name)); - pNetApiBufferSize(ui10, &dwSize); + NetApiBufferSize(ui10, &dwSize); ok(dwSize >= (sizeof(USER_INFO_10) + (wcslen(ui10->usri10_name) + 1 + wcslen(ui10->usri10_comment) + 1 + @@ -126,22 +96,22 @@ static void run_usergetinfo_tests(void) wcslen(ui10->usri10_full_name) + 1) * sizeof(WCHAR)), "Is allocated with NetApiBufferAllocate\n"); - pNetApiBufferFree(ui0); - pNetApiBufferFree(ui10); + NetApiBufferFree(ui0); + NetApiBufferFree(ui10); /* NetUserGetInfo should always work for the current user. */ - rc=pNetUserGetInfo(NULL, user_name, 0, (LPBYTE*)&ui0); + rc = NetUserGetInfo(NULL, user_name, 0, (BYTE **)&ui0); ok(rc == NERR_Success, "NetUsetGetInfo for current user failed: 0x%08x.\n", rc); - pNetApiBufferFree(ui0); + NetApiBufferFree(ui0); /* errors handling */ - rc = pNetUserGetInfo(NULL, L"testuser", 10000, (LPBYTE *)&ui0); + rc = NetUserGetInfo(NULL, L"testuser", 10000, (BYTE **)&ui0); ok(rc == ERROR_INVALID_LEVEL,"Invalid Level: rc=%d\n",rc); - rc = pNetUserGetInfo(NULL, L"Nonexistent User", 0, (LPBYTE *)&ui0); + rc = NetUserGetInfo(NULL, L"Nonexistent User", 0, (BYTE **)&ui0); ok(rc == NERR_UserNotFound,"Invalid User Name: rc=%d\n",rc); todo_wine { /* FIXME - Currently Wine can't verify whether the network path is good or bad */ - rc = pNetUserGetInfo(L"\\\\Ba path", L"testuser", 0, (LPBYTE *)&ui0); + rc = NetUserGetInfo(L"\\\\Ba path", L"testuser", 0, (BYTE **)&ui0); ok(rc == ERROR_BAD_NETPATH || rc == ERROR_NETWORK_UNREACHABLE || rc == RPC_S_SERVER_UNAVAILABLE || @@ -149,12 +119,12 @@ static void run_usergetinfo_tests(void) rc == RPC_S_INVALID_NET_ADDR, /* Some Win7 */ "Bad Network Path: rc=%d\n",rc); } - rc = pNetUserGetInfo(L"", L"testuser", 0, (LPBYTE *)&ui0); + rc = NetUserGetInfo(L"", L"testuser", 0, (BYTE **)&ui0); ok(rc == ERROR_BAD_NETPATH || rc == NERR_Success, "Bad Network Path: rc=%d\n",rc); - rc = pNetUserGetInfo(L"\\", L"testuser", 0, (LPBYTE *)&ui0); + rc = NetUserGetInfo(L"\\", L"testuser", 0, (BYTE **)&ui0); ok(rc == ERROR_INVALID_NAME || rc == ERROR_INVALID_HANDLE,"Invalid Server Name: rc=%d\n",rc); - rc = pNetUserGetInfo(L"\\\\", L"testuser", 0, (LPBYTE *)&ui0); + rc = NetUserGetInfo(L"\\\\", L"testuser", 0, (BYTE **)&ui0); ok(rc == ERROR_INVALID_NAME || rc == ERROR_INVALID_HANDLE,"Invalid Server Name: rc=%d\n",rc); if(delete_test_user() != NERR_Success) @@ -172,7 +142,7 @@ static void run_querydisplayinformation1_tests(void) do { - Result = pNetQueryDisplayInformation( + Result = NetQueryDisplayInformation( NULL, 1, i, 1000, MAX_PREFERRED_LENGTH, &EntryCount, (PVOID *)&Buffer); @@ -200,7 +170,7 @@ static void run_querydisplayinformation1_tests(void) rec++; } - pNetApiBufferFree(Buffer); + NetApiBufferFree(Buffer); } while (Result == ERROR_MORE_DATA); ok(hasAdmin, "Doesn't have 'Administrator' account\n"); @@ -211,11 +181,11 @@ static void run_usermodalsget_tests(void) NET_API_STATUS rc; USER_MODALS_INFO_2 * umi2 = NULL; - rc = pNetUserModalsGet(NULL, 2, (LPBYTE *)&umi2); + rc = NetUserModalsGet(NULL, 2, (BYTE **)&umi2); ok(rc == ERROR_SUCCESS, "NetUserModalsGet failed, rc = %d\n", rc); if (umi2) - pNetApiBufferFree(umi2); + NetApiBufferFree(umi2); } static void run_userhandling_tests(void) @@ -232,37 +202,26 @@ static void run_userhandling_tests(void) usri.usri1_name = sTooLongName; usri.usri1_password = sTestUserOldPass; - ret = pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL); - if (ret == NERR_Success || ret == NERR_UserExists) - { - /* Windows NT4 does create the user. Delete the user and also if it already existed - * due to a previous test run on NT4. - */ - trace("We are on NT4, we have to delete the user with the too long username\n"); - ret = pNetUserDel(NULL, sTooLongName); - ok(ret == NERR_Success, "Deleting the user failed : %d\n", ret); - } - else if (ret == ERROR_ACCESS_DENIED) + ret = NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); + if (ret == ERROR_ACCESS_DENIED) { skip("not enough permissions to add a user\n"); return; } else - ok(ret == NERR_BadUsername || - broken(ret == NERR_PasswordTooShort), /* NT4 */ - "Adding user with too long username returned 0x%08x\n", ret); + ok(ret == NERR_BadUsername, "Got %u.\n", ret); usri.usri1_name = (WCHAR *)L"testuser"; usri.usri1_password = sTooLongPassword; - ret = pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL); + ret = NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); ok(ret == NERR_PasswordTooShort || ret == ERROR_ACCESS_DENIED /* Win2003 */, "Adding user with too long password returned 0x%08x\n", ret); usri.usri1_name = sTooLongName; usri.usri1_password = sTooLongPassword; - ret = pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL); + ret = NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); /* NT4 doesn't have a problem with the username so it will report the too long password * as the error. NERR_PasswordTooShort is reported for all kind of password related errors. */ @@ -272,10 +231,10 @@ static void run_userhandling_tests(void) usri.usri1_name = (WCHAR *)L"testuser"; usri.usri1_password = sTestUserOldPass; - ret = pNetUserAdd(NULL, 5, (LPBYTE)&usri, NULL); + ret = NetUserAdd(NULL, 5, (BYTE *)&usri, NULL); ok(ret == ERROR_INVALID_LEVEL, "Adding user with level 5 returned 0x%08x\n", ret); - ret = pNetUserAdd(NULL, 1, (LPBYTE)&usri, NULL); + ret = NetUserAdd(NULL, 1, (BYTE *)&usri, NULL); if(ret == ERROR_ACCESS_DENIED) { skip("Insufficient permissions to add users. Skipping test.\n"); @@ -287,11 +246,7 @@ static void run_userhandling_tests(void) return; } - ok(ret == NERR_Success || - broken(ret == NERR_PasswordTooShort), /* NT4 */ - "Adding user failed with error 0x%08x\n", ret); - if(ret != NERR_Success) - return; + ok(!ret, "Got %u.\n", ret); /* On Windows XP (and newer), calling NetUserChangePassword with a NULL * domainname parameter creates a user home directory, iff the machine is @@ -301,10 +256,10 @@ static void run_userhandling_tests(void) * So let's not test NetUserChangePassword for now. */ - ret = pNetUserDel(NULL, L"testuser"); + ret = NetUserDel(NULL, L"testuser"); ok(ret == NERR_Success, "Deleting the user failed.\n"); - ret = pNetUserDel(NULL, L"testuser"); + ret = NetUserDel(NULL, L"testuser"); ok(ret == NERR_UserNotFound, "Deleting a nonexistent user returned 0x%08x\n",ret); } @@ -316,7 +271,7 @@ static void run_localgroupgetinfo_tests(void) DWORD entries_read = 0, total_entries =0; int i; - status = pNetLocalGroupGetInfo(NULL, L"Administrators", 1, (BYTE **)&lgi); + status = NetLocalGroupGetInfo(NULL, L"Administrators", 1, (BYTE **)&lgi); ok(status == NERR_Success || broken(status == NERR_GroupNotFound), "NetLocalGroupGetInfo unexpectedly returned %d\n", status); if (status != NERR_Success) return; @@ -324,9 +279,9 @@ static void run_localgroupgetinfo_tests(void) trace("Local groupname:%s\n", wine_dbgstr_w( lgi->lgrpi1_name)); trace("Comment: %s\n", wine_dbgstr_w( lgi->lgrpi1_comment)); - pNetApiBufferFree(lgi); + NetApiBufferFree(lgi); - status = pNetLocalGroupGetMembers(NULL, L"Administrators", 3, (BYTE **)&buffer, + status = NetLocalGroupGetMembers(NULL, L"Administrators", 3, (BYTE **)&buffer, MAX_PREFERRED_LENGTH, &entries_read, &total_entries, NULL); ok(status == NERR_Success, "NetLocalGroupGetMembers unexpectedly returned %d\n", status); ok(entries_read > 0 && total_entries > 0, "Amount of entries is unexpectedly 0\n"); @@ -334,7 +289,7 @@ static void run_localgroupgetinfo_tests(void) for(i=0;i #include -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(); } diff --git a/dlls/netapi32/tests/ds.c b/dlls/netapi32/tests/ds.c index 4b00499c8d5..10cbddab6cb 100644 --- a/dlls/netapi32/tests/ds.c +++ b/dlls/netapi32/tests/ds.c @@ -26,27 +26,24 @@ #include #include -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(); } diff --git a/dlls/netapi32/tests/wksta.c b/dlls/netapi32/tests/wksta.c index 709ed776950..684905c4dcb 100644 --- a/dlls/netapi32/tests/wksta.c +++ b/dlls/netapi32/tests/wksta.c @@ -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"); + DWORD size; + BOOL ret; - 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"); + pNetpGetComputerName = (void *)GetProcAddress(GetModuleHandleA("netapi32.dll"), "NetpGetComputerName"); - /* 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; - } + 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 (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); + if (pNetpGetComputerName) + run_get_comp_name_tests(); + else + win_skip("Function NetpGetComputerName not available\n"); + run_wkstausergetinfo_tests(); + run_wkstatransportenum_tests(); + run_wkstajoininfo_tests(); }