Sync advapi32, comctl32, crypt32, cryptui, cryptnet, fusion, gdi32, gdiplus, hlink...
[reactos.git] / rostests / winetests / rasapi32 / rasapi.c
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
29 static HMODULE hmodule;
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
41 RASAPI32_GET_PROC(RasEnumDevicesA)
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);
58 if(ERROR_RASMAN_CANNOT_INITIALIZE == result ||
59 ERROR_STATE_MACHINES_NOT_STARTED == result) {
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);
68 ok(result == ERROR_BUFFER_TOO_SMALL,
69 "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
70
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;
76 }
77
78 /* test first parameter */
79 cb = bufsize;
80 result = pRasEnumDevicesA(NULL, &cb, &cDevices);
81 ok(result == ERROR_BUFFER_TOO_SMALL ||
82 result == ERROR_INVALID_USER_BUFFER, /* win98 */
83 "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
84
85 rasDevInfo[0].dwSize = 0;
86 cb = bufsize;
87 result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
88 todo_wine
89 ok(result == ERROR_INVALID_SIZE ||
90 result == ERROR_INVALID_USER_BUFFER, /* win98 */
91 "Expected ERROR_INVALID_SIZE, got %08d\n", result);
92
93 rasDevInfo[0].dwSize = sizeof(RASDEVINFOA) -1;
94 cb = bufsize;
95 result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
96 todo_wine
97 ok(result == ERROR_INVALID_SIZE ||
98 result == ERROR_INVALID_USER_BUFFER, /* win98 */
99 "Expected ERROR_INVALID_SIZE, got %08d\n", result);
100
101 rasDevInfo[0].dwSize = sizeof(RASDEVINFOA) +1;
102 cb = bufsize;
103 result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
104 todo_wine
105 ok(result == ERROR_INVALID_SIZE ||
106 result == ERROR_INVALID_USER_BUFFER, /* win98 */
107 "Expected ERROR_INVALID_SIZE, got %08d\n", result);
108
109 /* test second parameter */
110 rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
111 result = pRasEnumDevicesA(rasDevInfo, NULL, &cDevices);
112 ok(result == ERROR_INVALID_PARAMETER,
113 "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
114
115 rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
116 cb = 0;
117 result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
118 ok(result == ERROR_BUFFER_TOO_SMALL ||
119 result == ERROR_INVALID_SIZE, /* vista, 2k8 */
120 "Expected ERROR_BUFFER_TOO_SMALL/ERROR_INVALID_SIZE, got %08d\n", result);
121
122 rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
123 cb = bufsize -1;
124 result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
125 ok(result == ERROR_BUFFER_TOO_SMALL,
126 "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
127
128 rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
129 cb = bufsize +1;
130 result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
131 ok(result == ERROR_SUCCESS,
132 "Expected ERROR_SUCCESS, got %08d\n", result);
133
134 /* test third parameter */
135 rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
136 cb = bufsize;
137 result = pRasEnumDevicesA(rasDevInfo, &cb, NULL);
138 ok(result == ERROR_INVALID_PARAMETER,
139 "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
140
141 /* test combinations of invalid parameters */
142 result = pRasEnumDevicesA(NULL, NULL, &cDevices);
143 ok(result == ERROR_INVALID_PARAMETER,
144 "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
145
146 result = pRasEnumDevicesA(NULL, &cb, NULL);
147 ok(result == ERROR_INVALID_PARAMETER ||
148 result == ERROR_INVALID_USER_BUFFER, /* win98 */
149 "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
150
151 cb = 0;
152 rasDevInfo[0].dwSize = 0;
153 result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
154 todo_wine
155 ok(result == ERROR_INVALID_SIZE ||
156 broken(result == ERROR_BUFFER_TOO_SMALL), /* win98 */
157 "Expected ERROR_INVALID_SIZE, got %08d\n", result);
158
159 HeapFree(GetProcessHeap(), 0, rasDevInfo);
160 }
161
162 START_TEST(rasapi)
163 {
164 InitFunctionPtrs();
165
166 test_rasenum();
167
168 FreeLibrary(hmodule);
169 }