dbghelp: Prevent debug overflow of internal buffer while tracing.
[wine] / dlls / netapi32 / tests / apibuf.c
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
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;
36
37
38 static void run_apibuf_tests(void)
39 {
40     VOID *p;
41     DWORD dwSize;
42     NET_API_STATUS res;
43
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");
49
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");
54
55     ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
56
57     /* test errors handling */
58     ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
59
60     ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
61     ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer\n");
62
63     /* border reallocate cases */
64     ok(pNetApiBufferReallocate(0, 1500, (LPVOID *) &p) == NERR_Success, "Reallocate with OldBuffer = NULL failed\n");
65     ok(p != NULL, "No memory got allocated\n");
66     ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success, "Memory not reserved\n");
67     ok(pNetApiBufferReallocate(p, 0, (LPVOID *) &p) == NERR_Success, "Not freed\n");
68     ok(p == NULL, "Pointer not cleared\n");
69     
70     /* 0-length buffer */
71     ok(pNetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
72        "Reserved memory\n");
73     ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
74     ok(dwSize < 0xFFFFFFFF, "The size of the 0-length buffer\n");
75     ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
76
77     /* NULL-Pointer */
78     /* NT: ERROR_INVALID_PARAMETER, lasterror is untouched) */
79     SetLastError(0xdeadbeef);
80     res = pNetApiBufferAllocate(0, (LPVOID *)NULL);
81     ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
82         "returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
83         "0xdeadbeef)\n", res, GetLastError());
84
85     SetLastError(0xdeadbeef);
86     res = pNetApiBufferAllocate(1024, (LPVOID *)NULL);    
87     ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
88         "returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
89         "0xdeadbeef)\n", res, GetLastError());
90 }
91
92 START_TEST(apibuf)
93 {
94     HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
95
96     pNetApiBufferAllocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferAllocate");
97     pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
98     pNetApiBufferReallocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferReallocate");
99     pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
100
101     if (pNetApiBufferAllocate && pNetApiBufferFree && pNetApiBufferReallocate && pNetApiBufferSize)
102         run_apibuf_tests();
103     else
104         skip("Needed functions are not available\n");
105
106     FreeLibrary(hnetapi32);
107 }