netapi32/tests: Use LoadLibrary where needed and skip.
[wine/testsucceed.git] / dlls / netapi32 / tests / apibuf.c
blob751081e9b52b0a169875d5cf8bca57747c67ac04
1 /*
2 * Copyright 2002 Andriy Palamarchuk
4 * Conformance test of the network buffer function.
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.
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.
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
21 #include <stdarg.h>
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>
32 static NET_API_STATUS (WINAPI *pNetApiBufferAllocate)(DWORD,LPVOID*)=NULL;
33 static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
34 static NET_API_STATUS (WINAPI *pNetApiBufferReallocate)(LPVOID,DWORD,LPVOID*)=NULL;
35 static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
38 static void run_apibuf_tests(void)
40 VOID *p;
41 DWORD dwSize;
42 NET_API_STATUS res;
44 /* test normal logic */
45 ok(pNetApiBufferAllocate(1024, (LPVOID *)&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");
50 ok(pNetApiBufferReallocate(p, 1500, (LPVOID *) &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");
55 ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
57 /* test errors handling */
58 ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
60 ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
61 ok(dwSize >= 0, "The size\n");
62 ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer\n");
64 /* border reallocate cases */
65 ok(pNetApiBufferReallocate(0, 1500, (LPVOID *) &p) == NERR_Success, "Reallocate with OldBuffer = NULL failed\n");
66 ok(p != NULL, "No memory got allocated\n");
67 ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success, "Memory not reserved\n");
68 ok(pNetApiBufferReallocate(p, 0, (LPVOID *) &p) == NERR_Success, "Not freed\n");
69 ok(p == NULL, "Pointer not cleared\n");
71 /* 0-length buffer */
72 ok(pNetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
73 "Reserved memory\n");
74 ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
75 ok((dwSize >= 0) && (dwSize < 0xFFFFFFFF),"The size of the 0-length buffer\n");
76 ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
78 /* NULL-Pointer */
79 /* NT: ERROR_INVALID_PARAMETER, lasterror is untouched) */
80 SetLastError(0xdeadbeef);
81 res = pNetApiBufferAllocate(0, (LPVOID *)NULL);
82 ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
83 "returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
84 "0xdeadbeef)\n", res, GetLastError());
86 SetLastError(0xdeadbeef);
87 res = pNetApiBufferAllocate(1024, (LPVOID *)NULL);
88 ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
89 "returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
90 "0xdeadbeef)\n", res, GetLastError());
93 START_TEST(apibuf)
95 HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
97 pNetApiBufferAllocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferAllocate");
98 pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
99 pNetApiBufferReallocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferReallocate");
100 pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
102 if (pNetApiBufferAllocate && pNetApiBufferFree && pNetApiBufferReallocate && pNetApiBufferSize)
103 run_apibuf_tests();
104 else
105 skip("Needed functions are not available\n");
107 FreeLibrary(hnetapi32);