mountmgr: Name DosDevices constants consistently.
[wine.git] / dlls / rasapi32 / tests / rasapi.c
blob5171bb2762cad0d4910e2ee635450ac72c26b3f0
1 /*
2 * Unit test suite for rasapi32 functions
4 * Copyright 2008 Austin English
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>
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"
29 static HMODULE hmodule;
30 static DWORD (WINAPI *pRasEnumDevicesA)(LPRASDEVINFOA, LPDWORD, LPDWORD);
32 #define RASAPI32_GET_PROC(func) \
33 p ## func = (void*)GetProcAddress(hmodule, #func); \
34 if(!p ## func) \
35 trace("GetProcAddress(%s) failed\n", #func);
37 static void InitFunctionPtrs(void)
39 hmodule = LoadLibraryA("rasapi32.dll");
41 RASAPI32_GET_PROC(RasEnumDevicesA)
44 static void test_rasenum(void)
46 DWORD result;
47 DWORD cDevices = 0;
48 DWORD bufsize = 0, cb = 0;
49 LPRASDEVINFOA rasDevInfo;
51 if(!pRasEnumDevicesA) {
52 win_skip("Skipping RasEnumDevicesA tests, function not present\n");
53 return;
56 /* create the return buffer */
57 result = pRasEnumDevicesA(NULL, &bufsize, &cDevices);
58 if(ERROR_RASMAN_CANNOT_INITIALIZE == result ||
59 ERROR_STATE_MACHINES_NOT_STARTED == result) {
60 win_skip("RAS configuration problem\n");
61 return;
63 if(ERROR_SUCCESS == result) {
64 win_skip("RasEnumDevicesA found nothing to enumerate\n");
65 return;
67 trace("RasEnumDevicesA: returned %d buffersize %d\n", result, bufsize);
68 ok(result == ERROR_BUFFER_TOO_SMALL,
69 "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
71 rasDevInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
72 max(bufsize,sizeof(RASDEVINFOA)));
73 if(!rasDevInfo) {
74 win_skip("failed to allocate buffer for RasEnumDevicesA tests\n");
75 return;
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);
83 ok(result == ERROR_BUFFER_TOO_SMALL ||
84 result == ERROR_INVALID_USER_BUFFER, /* win98 */
85 "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
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);
92 ok(result == ERROR_INVALID_SIZE ||
93 result == ERROR_INVALID_USER_BUFFER, /* win98 */
94 "Expected ERROR_INVALID_SIZE, got %08d\n", result);
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);
101 ok(result == ERROR_INVALID_SIZE ||
102 result == ERROR_INVALID_USER_BUFFER, /* win98 */
103 "Expected ERROR_INVALID_SIZE, got %08d\n", result);
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);
110 ok(result == ERROR_INVALID_SIZE ||
111 result == ERROR_INVALID_USER_BUFFER, /* win98 */
112 "Expected ERROR_INVALID_SIZE, got %08d\n", result);
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);
119 ok(result == ERROR_INVALID_PARAMETER,
120 "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
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);
128 ok(result == ERROR_BUFFER_TOO_SMALL ||
129 result == ERROR_INVALID_SIZE, /* vista, 2k8 */
130 "Expected ERROR_BUFFER_TOO_SMALL/ERROR_INVALID_SIZE, got %08d\n", result);
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);
137 ok(result == ERROR_BUFFER_TOO_SMALL,
138 "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
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);
145 ok(result == ERROR_SUCCESS,
146 "Expected ERROR_SUCCESS, got %08d\n", result);
148 /* test third parameter */
149 rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
150 cb = bufsize;
151 result = pRasEnumDevicesA(rasDevInfo, &cb, NULL);
152 ok(result == ERROR_INVALID_PARAMETER,
153 "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
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);
159 ok(result == ERROR_INVALID_PARAMETER,
160 "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
162 result = pRasEnumDevicesA(NULL, &cb, NULL);
163 ok(result == ERROR_INVALID_PARAMETER ||
164 result == ERROR_INVALID_USER_BUFFER, /* win98 */
165 "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
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);
172 ok(result == ERROR_INVALID_SIZE ||
173 broken(result == ERROR_BUFFER_TOO_SMALL), /* win98 */
174 "Expected ERROR_INVALID_SIZE, got %08d\n", result);
176 HeapFree(GetProcessHeap(), 0, rasDevInfo);
179 START_TEST(rasapi)
181 InitFunctionPtrs();
183 test_rasenum();
185 FreeLibrary(hmodule);