Fixed a race condition on RPC worker thread creation, and a typo.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "wine/test.h"
22 #include <winbase.h>
23 #include <winerror.h>
24 #include <lmcons.h>
25 #include <lmerr.h>
26 #include <lmapibuf.h>
27 #include <lmaccess.h>
28
29 static NET_API_STATUS (WINAPI *pNetApiBufferAllocate)(DWORD,LPVOID*)=NULL;
30 static NET_API_STATUS (WINAPI *pNetApiBufferFree)(LPVOID)=NULL;
31 static NET_API_STATUS (WINAPI *pNetApiBufferReallocate)(LPVOID,DWORD,LPVOID*)=NULL;
32 static NET_API_STATUS (WINAPI *pNetApiBufferSize)(LPVOID,LPDWORD)=NULL;
33
34
35 void run_apibuf_tests(void)
36 {
37     VOID *p;
38     DWORD dwSize;
39
40     if (!pNetApiBufferAllocate)
41         return;
42
43     /* test normal logic */
44     ok(pNetApiBufferAllocate(1024, (LPVOID *)&p) == NERR_Success,
45        "Reserved memory");
46     ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
47     ok(dwSize >= 1024, "The size is correct");
48
49     ok(pNetApiBufferReallocate(p, 1500, (LPVOID *) &p) == NERR_Success,
50        "Reallocated");
51     ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
52     ok(dwSize >= 1500, "The size is correct");
53
54     ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
55
56     /* test errors handling */
57     ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
58
59     ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
60     ok(dwSize >= 0, "The size");
61     ok(pNetApiBufferSize(NULL, &dwSize) == ERROR_INVALID_PARAMETER, "Error for NULL pointer");
62
63    /* 0-length buffer */
64     ok(pNetApiBufferAllocate(0, (LPVOID *)&p) == NERR_Success,
65        "Reserved memory");
66     ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size");
67     ok((dwSize >= 0) && (dwSize < 0xFFFFFFFF),"The size of the 0-length buffer");
68     ok(pNetApiBufferFree(p) == NERR_Success, "Freed");
69 }
70
71 START_TEST(apibuf)
72 {
73     HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
74     pNetApiBufferAllocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferAllocate");
75     pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
76     pNetApiBufferReallocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferReallocate");
77     pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");
78     if (!pNetApiBufferSize)
79         trace("It appears there is no netapi32 functionality on this platform\n");
80
81     run_apibuf_tests();
82 }