ReactOS 0.4.15-dev-7942-gd23573b
apibuf.c
Go to the documentation of this file.
1/*
2 * Copyright 2002 Andriy Palamarchuk
3 *
4 * Conformance test of the network buffer function.
5 *
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.
10 *
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.
15 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdarg.h>
22
23#include "wine/test.h"
24#include <windef.h>
25#include <winbase.h>
26#include <winerror.h>
27#include <lmcons.h>
28#include <lmerr.h>
29#include <lmapibuf.h>
30#include <lmaccess.h>
31
32static NET_API_STATUS (WINAPI *pNetApiBufferAllocate)(DWORD,LPVOID*)=NULL;
33static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
34static NET_API_STATUS (WINAPI *pNetApiBufferReallocate)(LPVOID,DWORD,LPVOID*)=NULL;
35static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
36
37
38static void run_apibuf_tests(void)
39{
40 VOID *p;
43
44 /* test normal logic */
45 ok(pNetApiBufferAllocate(1024, &p) == NERR_Success,
46 "Reserved memory\n");
47 ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
48 ok(dwSize >= 1024, "The size is correct\n");
49
50 ok(pNetApiBufferReallocate(p, 1500, &p) == NERR_Success,
51 "Reallocated\n");
52 ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
53 ok(dwSize >= 1500, "The size is correct\n");
54
55 ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
56
57 ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer\n");
58
59 /* border reallocate cases */
60 ok(pNetApiBufferReallocate(0, 1500, &p) == NERR_Success, "Reallocate with OldBuffer = NULL failed\n");
61 ok(p != NULL, "No memory got allocated\n");
62 ok(pNetApiBufferFree(p) == NERR_Success, "NetApiBufferFree failed\n");
63
64 ok(pNetApiBufferAllocate(1024, &p) == NERR_Success, "Memory not reserved\n");
65 ok(pNetApiBufferReallocate(p, 0, &p) == NERR_Success, "Not freed\n");
66 ok(p == NULL, "Pointer not cleared\n");
67
68 /* 0-length buffer */
69 ok(pNetApiBufferAllocate(0, &p) == NERR_Success,
70 "Reserved memory\n");
71 ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
72 ok(dwSize < 0xFFFFFFFF, "The size of the 0-length buffer\n");
73 ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
74
75 /* NULL-Pointer */
76 /* NT: ERROR_INVALID_PARAMETER, lasterror is untouched) */
77 SetLastError(0xdeadbeef);
78 res = pNetApiBufferAllocate(0, NULL);
79 ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
80 "returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
81 "0xdeadbeef)\n", res, GetLastError());
82
83 SetLastError(0xdeadbeef);
84 res = pNetApiBufferAllocate(1024, NULL);
85 ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
86 "returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
87 "0xdeadbeef)\n", res, GetLastError());
88}
89
91{
92 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
93
94 pNetApiBufferAllocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferAllocate");
95 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
96 pNetApiBufferReallocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferReallocate");
97 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
98
99 if (pNetApiBufferAllocate && pNetApiBufferFree && pNetApiBufferReallocate && pNetApiBufferSize)
101 else
102 win_skip("Needed functions are not available\n");
103
104 FreeLibrary(hnetapi32);
105}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
GLfloat GLfloat p
Definition: glext.h:8902
#define NET_API_STATUS
Definition: lmcons.h:8
#define NERR_Success
Definition: lmerr.h:5
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static LPVOID *static LPDWORD
Definition: apibuf.c:35
static DWORD
Definition: apibuf.c:34
static void run_apibuf_tests(void)
Definition: apibuf.c:38
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define LPVOID
Definition: nt_native.h:45
#define win_skip
Definition: test.h:160
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6