apibuf.c 3.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20
 */

21 22
#include <stdarg.h>

23
#include "wine/test.h"
24
#include <windef.h>
25 26 27 28 29 30 31
#include <winbase.h>
#include <winerror.h>
#include <lmcons.h>
#include <lmerr.h>
#include <lmapibuf.h>
#include <lmaccess.h>

32 33 34 35 36 37
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;


38
static void run_apibuf_tests(void)
39 40 41
{
    VOID *p;
    DWORD dwSize;
42
    NET_API_STATUS res;
43 44

    /* test normal logic */
45
    ok(pNetApiBufferAllocate(1024, &p) == NERR_Success,
46 47 48
       "Reserved memory\n");
    ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
    ok(dwSize >= 1024, "The size is correct\n");
49

50
    ok(pNetApiBufferReallocate(p, 1500, &p) == NERR_Success,
51 52 53
       "Reallocated\n");
    ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
    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 63
    ok(pNetApiBufferAllocate(1024, &p) == NERR_Success, "Memory not reserved\n");
    ok(pNetApiBufferReallocate(p, 0, &p) == NERR_Success, "Not freed\n");
64
    ok(p == NULL, "Pointer not cleared\n");
65

66
    /* 0-length buffer */
67
    ok(pNetApiBufferAllocate(0, &p) == NERR_Success,
68 69
       "Reserved memory\n");
    ok(pNetApiBufferSize(p, &dwSize) == NERR_Success, "Got size\n");
70
    ok(dwSize < 0xFFFFFFFF, "The size of the 0-length buffer\n");
71
    ok(pNetApiBufferFree(p) == NERR_Success, "Freed\n");
72 73 74 75

    /* NULL-Pointer */
    /* NT: ERROR_INVALID_PARAMETER, lasterror is untouched) */
    SetLastError(0xdeadbeef);
76
    res = pNetApiBufferAllocate(0, NULL);
77
    ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
78
        "returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
79 80 81
        "0xdeadbeef)\n", res, GetLastError());

    SetLastError(0xdeadbeef);
82
    res = pNetApiBufferAllocate(1024, NULL);
83
    ok( (res == ERROR_INVALID_PARAMETER) && (GetLastError() == 0xdeadbeef),
84
        "returned %d with 0x%x (expected ERROR_INVALID_PARAMETER with "
85
        "0xdeadbeef)\n", res, GetLastError());
86 87 88 89
}

START_TEST(apibuf)
{
90
    HMODULE hnetapi32=LoadLibraryA("netapi32.dll");
91

92 93 94 95 96
    pNetApiBufferAllocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferAllocate");
    pNetApiBufferFree=(void*)GetProcAddress(hnetapi32,"NetApiBufferFree");
    pNetApiBufferReallocate=(void*)GetProcAddress(hnetapi32,"NetApiBufferReallocate");
    pNetApiBufferSize=(void*)GetProcAddress(hnetapi32,"NetApiBufferSize");

97 98 99
    if (pNetApiBufferAllocate && pNetApiBufferFree && pNetApiBufferReallocate && pNetApiBufferSize)
        run_apibuf_tests();
    else
100
        win_skip("Needed functions are not available\n");
101 102

    FreeLibrary(hnetapi32);
103
}