localspl: Build language resource files separately.
[wine] / dlls / rasapi32 / tests / 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         win_skip("RAS configuration problem\n");
60         return;
61     }
62     if(ERROR_SUCCESS == result) {
63         win_skip("RasEnumDevicesA found nothing to enumerate\n");
64         return;
65     }
66     trace("RasEnumDevicesA: returned %d buffersize %d\n", result, bufsize);
67     ok(result == ERROR_BUFFER_TOO_SMALL,
68     "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
69
70     rasDevInfo = (LPRASDEVINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
71                                           max(bufsize,sizeof(RASDEVINFOA)));
72     if(!rasDevInfo) {
73         win_skip("failed to allocate buffer for RasEnumDevicesA tests\n");
74         return;
75     }
76
77     /* test first parameter */
78     cb = bufsize;
79     result = pRasEnumDevicesA(NULL, &cb, &cDevices);
80     ok(result == ERROR_BUFFER_TOO_SMALL ||
81     result == ERROR_INVALID_USER_BUFFER, /* win98 */
82     "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
83
84     rasDevInfo[0].dwSize = 0;
85     cb = bufsize;
86     result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
87     todo_wine
88     ok(result == ERROR_INVALID_SIZE ||
89     result == ERROR_INVALID_USER_BUFFER, /* win98 */
90     "Expected ERROR_INVALID_SIZE, got %08d\n", result);
91
92     rasDevInfo[0].dwSize = sizeof(RASDEVINFOA) -1;
93     cb = bufsize;
94     result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
95     todo_wine
96     ok(result == ERROR_INVALID_SIZE ||
97     result == ERROR_INVALID_USER_BUFFER, /* win98 */
98     "Expected ERROR_INVALID_SIZE, got %08d\n", result);
99
100     rasDevInfo[0].dwSize = sizeof(RASDEVINFOA) +1;
101     cb = bufsize;
102     result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
103     todo_wine
104     ok(result == ERROR_INVALID_SIZE ||
105     result == ERROR_INVALID_USER_BUFFER, /* win98 */
106     "Expected ERROR_INVALID_SIZE, got %08d\n", result);
107
108     /* test second parameter */
109     rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
110     result = pRasEnumDevicesA(rasDevInfo, NULL, &cDevices);
111     ok(result == ERROR_INVALID_PARAMETER,
112     "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
113
114     rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
115     cb = 0;
116     result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
117     ok(result == ERROR_BUFFER_TOO_SMALL ||
118     result == ERROR_INVALID_SIZE, /* vista, 2k8 */
119     "Expected ERROR_BUFFER_TOO_SMALL/ERROR_INVALID_SIZE, got %08d\n", result);
120
121     rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
122     cb = bufsize -1;
123     result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
124     ok(result == ERROR_BUFFER_TOO_SMALL,
125     "Expected ERROR_BUFFER_TOO_SMALL, got %08d\n", result);
126
127     rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
128     cb = bufsize +1;
129     result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
130     ok(result == ERROR_SUCCESS,
131     "Expected ERROR_SUCCESS, got %08d\n", result);
132
133     /* test third parameter */
134     rasDevInfo[0].dwSize = sizeof(RASDEVINFOA);
135     cb = bufsize;
136     result = pRasEnumDevicesA(rasDevInfo, &cb, NULL);
137     ok(result == ERROR_INVALID_PARAMETER,
138     "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
139
140     /* test combinations of invalid parameters */
141     result = pRasEnumDevicesA(NULL, NULL, &cDevices);
142     ok(result == ERROR_INVALID_PARAMETER,
143     "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
144
145     result = pRasEnumDevicesA(NULL, &cb, NULL);
146     ok(result == ERROR_INVALID_PARAMETER ||
147     result == ERROR_INVALID_USER_BUFFER, /* win98 */
148     "Expected ERROR_INVALID_PARAMETER, got %08d\n", result);
149
150     cb = 0;
151     rasDevInfo[0].dwSize = 0;
152     result = pRasEnumDevicesA(rasDevInfo, &cb, &cDevices);
153     todo_wine
154     ok(result == ERROR_INVALID_SIZE ||
155     broken(result == ERROR_BUFFER_TOO_SMALL), /* win98 */
156     "Expected ERROR_INVALID_SIZE, got %08d\n", result);
157
158     HeapFree(GetProcessHeap(), 0, rasDevInfo);
159 }
160
161 START_TEST(rasapi)
162 {
163     InitFunctionPtrs();
164
165     test_rasenum();
166
167     FreeLibrary(hmodule);
168 }