2002-09-11 04:35:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
|
|
|
*
|
|
|
|
* Conformance test of the network buffer function.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-09-11 04:35:17 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-09-11 04:35:17 +02:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <windef.h>
|
2002-09-11 04:35:17 +02:00
|
|
|
#include <winbase.h>
|
|
|
|
#include <winerror.h>
|
|
|
|
#include <lmcons.h>
|
|
|
|
#include <lmerr.h>
|
|
|
|
#include <lmapibuf.h>
|
|
|
|
#include <lmaccess.h>
|
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2005-06-20 17:35:54 +02:00
|
|
|
static void run_apibuf_tests(void)
|
2002-09-11 04:35:17 +02:00
|
|
|
{
|
|
|
|
VOID *p;
|
|
|
|
DWORD dwSize;
|
2006-09-08 11:29:54 +02:00
|
|
|
NET_API_STATUS res;
|
2002-09-11 04:35:17 +02:00
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
if (!pNetApiBufferAllocate)
|
|
|
|
return;
|
|
|
|
|
2002-09-11 04:35:17 +02:00
|
|
|
/* test normal logic */
|
2002-12-19 02:04:12 +01:00
|
|
|
ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success,
|
2004-01-27 21:13:03 +01:00
|
|
|
"Reserved memory\n");
|
|
|
|
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
|
|
|
|
ok(dwSize >= 1024, "The size is correct\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
|
2002-12-19 02:04:12 +01:00
|
|
|
ok(pNetApiBufferReallocate(p, 1500, (LPVOID *) &p) == NERR_Success,
|
2004-01-27 21:13:03 +01:00
|
|
|
"Reallocated\n");
|
|
|
|
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
|
|
|
|
ok(dwSize >= 1500, "The size is correct\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
|
|
|
|
/* test errors handling */
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
|
|
|
|
ok(dwSize >= 0, "The size\n");
|
|
|
|
ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer\n");
|
2002-09-11 04:35:17 +02:00
|
|
|
|
2003-12-04 02:42:34 +01:00
|
|
|
/* border reallocate cases */
|
2004-04-22 00:24:38 +02:00
|
|
|
ok(pNetApiBufferReallocate(0, 1500, (LPVOID *) &p) == NERR_Success, "Reallocate with OldBuffer = NULL failed\n");
|
|
|
|
ok(p != NULL, "No memory got allocated\n");
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success, "Memory not reserved\n");
|
|
|
|
ok(pNetApiBufferReallocate(p, 0, (LPVOID *) &p) == NERR_Success, "Not freed\n");
|
|
|
|
ok(p == NULL, "Pointer not cleared\n");
|
2003-12-04 02:42:34 +01:00
|
|
|
|
|
|
|
/* 0-length buffer */
|
2002-12-19 02:04:12 +01:00
|
|
|
ok(pNetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
|
2004-01-27 21:13:03 +01:00
|
|
|
"Reserved memory\n");
|
|
|
|
ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
|
|
|
|
ok((dwSize >= 0) && (dwSize < 0xFFFFFFFF),"The size of the 0-length buffer\n");
|
|
|
|
ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
|
2006-09-08 11:29:54 +02:00
|
|
|
|
|
|
|
/* NULL-Pointer */
|
|
|
|
/* NT: ERROR_INVALID_PARAMETER, lasterror is untouched) */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pNetApiBufferAllocate(0, (LPVOID *)NULL);
|
|
|
|
ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
|
2006-12-27 00:19:50 +01:00
|
|
|
"returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
|
2006-09-08 11:29:54 +02:00
|
|
|
"0xdeadbeef)\n", res, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
res = pNetApiBufferAllocate(1024, (LPVOID *)NULL);
|
|
|
|
ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
|
2006-12-27 00:19:50 +01:00
|
|
|
"returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
|
2006-09-08 11:29:54 +02:00
|
|
|
"0xdeadbeef)\n", res, GetLastError());
|
2002-09-11 04:35:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(apibuf)
|
|
|
|
{
|
2002-12-19 02:04:12 +01:00
|
|
|
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");
|
|
|
|
|
2002-09-11 04:35:17 +02:00
|
|
|
run_apibuf_tests();
|
|
|
|
}
|