ReactOS  0.4.13-dev-982-g9853eab
rasapi.c
Go to the documentation of this file.
1 /*
2 * Unit test suite for rasapi32 functions
3 *
4 * Copyright 2008 Austin English
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 #include <stdio.h>
23 #include <wine/test.h>
24 #include <windef.h>
25 #include <winbase.h>
26 #include "ras.h"
27 #include "raserror.h"
28 
30 static DWORD (WINAPI *pRasEnumDevicesA)(LPRASDEVINFOA, LPDWORD, LPDWORD);
31 
32 #define RASAPI32_GET_PROC(func) \
33  p ## func = (void*)GetProcAddress(hmodule, #func); \
34  if(!p ## func) \
35  trace("GetProcAddress(%s) failed\n", #func);
36 
37 static void InitFunctionPtrs(void)
38 {
39  hmodule = LoadLibraryA("rasapi32.dll");
40 
42 }
43 
44 static void test_rasenum(void)
45 {
46  DWORD result;
47  DWORD cDevices = 0;
48  DWORD bufsize = 0, cb = 0;
49  LPRASDEVINFOA rasDevInfo;
50 
51  if(!pRasEnumDevicesA) {
52  win_skip("Skipping RasEnumDevicesA tests, function not present\n");
53  return;
54  }
55 
56  /* create the return buffer */
57  result = pRasEnumDevicesA(NULL, &bufsize, &cDevices);
60  win_skip("RAS configuration problem\n");
61  return;
62  }
63  if(ERROR_SUCCESS == result) {
64  win_skip("RasEnumDevicesA found nothing to enumerate\n");
65  return;
66  }
67  trace("RasEnumDevicesA: returned %d buffersize %d\n", result, bufsize);
69  "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
70 
72  max(bufsize,sizeof(RASDEVINFOA)));
73  if(!rasDevInfo) {
74  win_skip("failed to allocate buffer for RasEnumDevicesA tests\n");
75  return;
76  }
77 
78  /* test first parameter */
79  cb = bufsize;
80  cDevices = 0xdeadbeef;
81  result = pRasEnumDevicesA(NULL, &cb, &cDevices);
82  ok(0 < cDevices && cDevices < 32, "expected 0 < cDevices < 32, got %u\n", cDevices);
84  result == ERROR_INVALID_USER_BUFFER, /* win98 */
85  "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
86 
87  rasDevInfo[0].dwSize = 0;
88  cb = bufsize;
89  cDevices = 0xdeadbeef;
90  result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
91  ok(cDevices == 0xdeadbeef, "expected cDevices = 0xdeadbeef, got %u\n", cDevices);
93  result == ERROR_INVALID_USER_BUFFER, /* win98 */
94  "Expected ERROR_INVALID_SIZE, got %08d\n", result);
95 
96  rasDevInfo[0].dwSize = sizeof(RASDEVINFOA) -1;
97  cb = bufsize;
98  cDevices = 0xdeadbeef;
99  result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
100  ok(cDevices == 0xdeadbeef, "expected cDevices = 0xdeadbeef, got %u\n", cDevices);
102  result == ERROR_INVALID_USER_BUFFER, /* win98 */
103  "Expected ERROR_INVALID_SIZE, got %08d\n", result);
104 
105  rasDevInfo[0].dwSize = sizeof(RASDEVINFOA) +1;
106  cb = bufsize;
107  cDevices = 0xdeadbeef;
108  result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
109  ok(cDevices == 0xdeadbeef, "expected cDevices = 0xdeadbeef, got %u\n", cDevices);
111  result == ERROR_INVALID_USER_BUFFER, /* win98 */
112  "Expected ERROR_INVALID_SIZE, got %08d\n", result);
113 
114  /* test second parameter */
115  rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
116  cDevices = 0xdeadbeef;
117  result = pRasEnumDevicesA(rasDevInfo, NULL, &cDevices);
118  ok(cDevices == 0xdeadbeef, "expected cDevices = 0xdeadbeef, got %u\n", cDevices);
120  "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
121 
122  rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
123  cb = 0;
124  cDevices = 0xdeadbeef;
125  result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
126  todo_wine
127  ok(cDevices == 0xdeadbeef, "expected cDevices = 0xdeadbeef, got %u\n", cDevices);
129  result == ERROR_INVALID_SIZE, /* vista, 2k8 */
130  "Expected ERROR_BUFFER_TOO_SMALL/ERROR_INVALID_SIZE, got %08d\n", result);
131 
132  rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
133  cb = bufsize -1;
134  cDevices = 0xdeadbeef;
135  result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
136  ok(0 < cDevices && cDevices < 32, "expected 0 < cDevices < 32, got %u\n", cDevices);
138  "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
139 
140  rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
141  cb = bufsize +1;
142  cDevices = 0xdeadbeef;
143  result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
144  ok(0 < cDevices && cDevices < 32, "expected 0 < cDevices < 32, got %u\n", cDevices);
146  "Expected ERROR_SUCCESS, got %08d\n", result);
147 
148  /* test third parameter */
149  rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
150  cb = bufsize;
151  result = pRasEnumDevicesA(rasDevInfo, &cb, NULL);
153  "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
154 
155  /* test combinations of invalid parameters */
156  cDevices = 0xdeadbeef;
157  result = pRasEnumDevicesA(NULL, NULL, &cDevices);
158  ok(cDevices == 0xdeadbeef, "expected cDevices = 0xdeadbeef, got %u\n", cDevices);
160  "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
161 
162  result = pRasEnumDevicesA(NULL, &cb, NULL);
164  result == ERROR_INVALID_USER_BUFFER, /* win98 */
165  "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
166 
167  cb = 0;
168  rasDevInfo[0].dwSize = 0;
169  cDevices = 0xdeadbeef;
170  result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
171  ok(cDevices == 0xdeadbeef, "expected cDevices = 0xdeadbeef, got %u\n", cDevices);
173  broken(result == ERROR_BUFFER_TOO_SMALL), /* win98 */
174  "Expected ERROR_INVALID_SIZE, got %08d\n", result);
175 
176  HeapFree(GetProcessHeap(), 0, rasDevInfo);
177 }
178 
179 START_TEST(rasapi)
180 {
182 
183  test_rasenum();
184 
186 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define max(a, b)
Definition: svc.c:63
#define ERROR_SUCCESS
Definition: deptool.c:10
static void test_rasenum(void)
Definition: rasapi.c:44
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
DWORD dwSize
Definition: ras.h:509
struct tagRASDEVINFOA * LPRASDEVINFOA
#define ERROR_INVALID_USER_BUFFER
Definition: winerror.h:1091
#define ERROR_BUFFER_TOO_SMALL
Definition: raserror.h:9
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static HMODULE hmodule
Definition: rasapi.c:29
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_STATE_MACHINES_NOT_STARTED
Definition: raserror.h:101
#define FreeLibrary(x)
Definition: compat.h:405
#define GetProcessHeap()
Definition: compat.h:395
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define WINAPI
Definition: msvc.h:8
DWORD WINAPI RasEnumDevicesA(LPRASDEVINFOA lpRasDevinfo, LPDWORD lpcb, LPDWORD lpcDevices)
Definition: rasapi.c:247
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD cb
Definition: integrity.c:41
#define todo_wine
Definition: test.h:154
struct tagRASDEVINFOA RASDEVINFOA
#define broken(x)
Definition: _sntprintf.h:21
static DWORD(WINAPI *pRasEnumDevicesA)(LPRASDEVINFOA
#define RASAPI32_GET_PROC(func)
Definition: rasapi.c:32
START_TEST(rasapi)
Definition: rasapi.c:179
#define ok(value,...)
Definition: atltest.h:57
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define ERROR_RASMAN_CANNOT_INITIALIZE
Definition: raserror.h:117
static LPDWORD
Definition: rasapi.c:30
GLuint64EXT * result
Definition: glext.h:11304
#define win_skip
Definition: test.h:141
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_INVALID_SIZE
Definition: raserror.h:38
static void InitFunctionPtrs(void)
Definition: rasapi.c:37