Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/bluetoothapis/tests/radio.c
5968 views
1
/*
2
* Tests for Bluetooth radio methods
3
*
4
* Copyright 2024 Vibhav Pant
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
23
#include <windef.h>
24
#include <winbase.h>
25
26
#include <bthsdpdef.h>
27
#include <bluetoothapis.h>
28
29
#include <wine/test.h>
30
31
void test_BluetoothFindFirstRadio( void )
32
{
33
HANDLE radio, dummy = (HANDLE)0xdeadbeef;
34
BLUETOOTH_FIND_RADIO_PARAMS find_params;
35
HBLUETOOTH_RADIO_FIND find;
36
DWORD err, exp;
37
38
radio = dummy;
39
SetLastError( 0xdeadbeef );
40
find = BluetoothFindFirstRadio( NULL, &radio );
41
ok( !find, "Expected %p to be NULL\n", find );
42
err = GetLastError();
43
ok( err == ERROR_INVALID_PARAMETER, "%lu != %d\n", err, ERROR_INVALID_PARAMETER );
44
ok( radio == dummy, "%p != %p\n", radio, dummy );
45
46
radio = dummy;
47
find_params.dwSize = 0;
48
SetLastError( 0xdeadbeef );
49
find = BluetoothFindFirstRadio( &find_params, &radio );
50
ok( !find, "Expected %p to be NULL\n", find );
51
err = GetLastError();
52
ok( err == ERROR_REVISION_MISMATCH, "%lu != %d\n", err, ERROR_REVISION_MISMATCH );
53
ok( radio == dummy, "%p != %p\n", radio, dummy );
54
55
find_params.dwSize = sizeof( find_params );
56
SetLastError( 0xdeadbeef );
57
find = BluetoothFindFirstRadio( &find_params, &radio );
58
err = GetLastError();
59
exp = find ? ERROR_SUCCESS : ERROR_NO_MORE_ITEMS;
60
ok( err == exp, "%lu != %lu\n", err, exp );
61
if (find)
62
{
63
BOOL ret;
64
65
CloseHandle( radio );
66
ret = BluetoothFindRadioClose( find );
67
ok( ret, "BluetoothFindRadioClose failed: %lu\n", GetLastError() );
68
}
69
}
70
71
void test_BluetoothFindNextRadio( void )
72
{
73
HANDLE radio, dummy = (HANDLE)0xdeadbeef;
74
BLUETOOTH_FIND_RADIO_PARAMS find_params;
75
HBLUETOOTH_RADIO_FIND find;
76
DWORD err;
77
BOOL ret;
78
79
find_params.dwSize = sizeof( find_params );
80
find = BluetoothFindFirstRadio( &find_params, &radio );
81
if (!find)
82
{
83
skip( "No Bluetooth radios found.\n" );
84
return;
85
}
86
CloseHandle( radio );
87
88
radio = dummy;
89
SetLastError( 0xdeadbeef );
90
ret = BluetoothFindNextRadio( NULL, &radio );
91
ok( !ret, "Expected BluetoothFindNextRadio to return FALSE\n" );
92
err = GetLastError();
93
ok( err == ERROR_INVALID_HANDLE, "%lu != %d\n", err, ERROR_INVALID_HANDLE );
94
ok( radio == dummy, "%p != %p\n", radio, dummy );
95
96
for(;;)
97
{
98
SetLastError( 0xdeadbeef );
99
ret = BluetoothFindNextRadio( find, &radio );
100
if (!ret)
101
{
102
err = GetLastError();
103
ok( err == ERROR_NO_MORE_ITEMS, "%lu != %d\n", err, ERROR_NO_MORE_ITEMS );
104
break;
105
}
106
CloseHandle( radio );
107
}
108
ret = BluetoothFindRadioClose( find );
109
ok( ret, "BluetoothFindRadioClose failed: %lu\n", GetLastError() );
110
}
111
112
void test_BluetoothFindRadioClose( void )
113
{
114
DWORD err;
115
116
SetLastError( 0xdeadbeef );
117
ok( !BluetoothFindRadioClose( NULL ), "Expected BluetoothFindRadioClose to return FALSE\n" );
118
err = GetLastError();
119
ok( err == ERROR_INVALID_HANDLE, "%lu != %d\n", err, ERROR_INVALID_HANDLE );
120
}
121
122
void test_for_all_radios( const char *file, int line, void (*test)( HANDLE radio, void *data ), void *data )
123
{
124
DWORD err, idx = 0;
125
HANDLE radio;
126
HBLUETOOTH_RADIO_FIND find;
127
BLUETOOTH_FIND_RADIO_PARAMS find_params;
128
129
find_params.dwSize = sizeof( find_params );
130
find = BluetoothFindFirstRadio( &find_params, &radio );
131
if (!find)
132
{
133
err = GetLastError();
134
ok( err == ERROR_NO_MORE_ITEMS, "%lu != %d\n", err, ERROR_NO_MORE_ITEMS );
135
skip_(file, line)( "No Bluetooth radios found.\n" );
136
return;
137
}
138
139
for(;;)
140
{
141
BOOL ret;
142
143
winetest_push_context( "radio %lu", idx++ );
144
test( radio, data );
145
winetest_pop_context();
146
147
CloseHandle( radio );
148
ret = BluetoothFindNextRadio( find, &radio );
149
if (!ret)
150
{
151
err = GetLastError();
152
ok( err == ERROR_NO_MORE_ITEMS, "%lu != %d\n", err, ERROR_NO_MORE_ITEMS );
153
break;
154
}
155
}
156
BluetoothFindRadioClose( find );
157
}
158
159
void test_BluetoothGetRadioInfo( HANDLE radio, void *data )
160
{
161
DWORD err;
162
BLUETOOTH_RADIO_INFO info = {0};
163
164
err = BluetoothGetRadioInfo( NULL, NULL );
165
ok( err == ERROR_INVALID_PARAMETER, "%lu != %d\n", err, ERROR_INVALID_PARAMETER );
166
err = BluetoothGetRadioInfo( radio, NULL );
167
ok( err == ERROR_INVALID_PARAMETER, "%lu != %d\n", err, ERROR_INVALID_PARAMETER );
168
err = BluetoothGetRadioInfo( radio, &info );
169
ok( err == ERROR_REVISION_MISMATCH, "%lu != %d\n", err, ERROR_REVISION_MISMATCH );
170
171
info.dwSize = sizeof( info );
172
err = BluetoothGetRadioInfo( radio, &info );
173
ok( !err, "BluetoothGetRadioInfo failed: %lu\n", err );
174
if (err)
175
return;
176
177
trace( "address: %x:%x:%x:%x:%x:%x\n", info.address.rgBytes[0], info.address.rgBytes[1], info.address.rgBytes[2],
178
info.address.rgBytes[3], info.address.rgBytes[4], info.address.rgBytes[5] );
179
trace( "name: %s\n", debugstr_w( info.szName ) );
180
trace( "class: %lx\n", info.ulClassofDevice );
181
trace( "LMP subversion: %x\n", info.lmpSubversion );
182
trace( "manufacturer: %x\n", info.manufacturer );
183
}
184
185
void test_radio_BluetoothIsConnectable( HANDLE radio, void *data )
186
{
187
BOOL *result = data;
188
189
*result |= BluetoothIsConnectable( radio );
190
}
191
192
void test_BluetoothIsConnectable( void )
193
{
194
BOOL ret;
195
BOOL result = FALSE;
196
197
ret = BluetoothIsConnectable( NULL );
198
/* If ret is true, then at least one radio must be connectable. If ret returns false, then no radios are connectable. */
199
test_for_all_radios( __FILE__, __LINE__, test_radio_BluetoothIsConnectable, &result );
200
201
ok( ret == result, "%d != %d\n", ret, result );
202
}
203
204
void test_radio_BluetoothIsDiscoverable( HANDLE radio, void *data )
205
{
206
BOOL *result = data;
207
208
*result |= BluetoothIsDiscoverable( radio );
209
}
210
211
void test_BluetoothIsDiscoverable( void )
212
{
213
BOOL ret;
214
BOOL result = FALSE;
215
216
ret = BluetoothIsDiscoverable( NULL );
217
test_for_all_radios( __FILE__, __LINE__, test_radio_BluetoothIsDiscoverable, &result );
218
219
ok( ret == result, "%d != %d\n", ret, result );
220
}
221
222
void test_radio_BluetoothEnableIncomingConnections( HANDLE radio, void *data )
223
{
224
BOOL connectable;
225
BOOL *result = data;
226
227
*result |= BluetoothEnableIncomingConnections( radio, TRUE );
228
ok( *result, "%d != 1\n", *result );
229
if (*result)
230
{
231
connectable = BluetoothIsConnectable( radio );
232
ok( connectable, "%d != 1\n", connectable );
233
}
234
else
235
skip("BluetoothEnableIncomingConnections failed, skipping.\n");
236
}
237
238
void test_BluetoothEnableIncomingConnections( void )
239
{
240
BOOL result = FALSE;
241
242
test_for_all_radios( __FILE__, __LINE__, test_radio_BluetoothEnableIncomingConnections, &result );
243
if (result)
244
{
245
BOOL connectable;
246
connectable = BluetoothIsConnectable( NULL );
247
ok( connectable, "%d != 1\n", connectable );
248
}
249
}
250
251
void test_radio_BluetoothEnableDiscovery( HANDLE radio, void *data )
252
{
253
BOOL ret;
254
255
if (BluetoothIsDiscoverable( radio ))
256
{
257
ret = BluetoothEnableDiscovery( radio, FALSE );
258
ok( ret, "%d != 1\n", ret );
259
}
260
261
/* Enabling discovery requires incoming connections to be enabled as well, so this should result in an error. */
262
BluetoothEnableIncomingConnections( radio, FALSE );
263
ret = BluetoothEnableDiscovery( radio, TRUE );
264
ok( !ret, "%d != 0\n", ret );
265
266
BluetoothEnableIncomingConnections( radio, TRUE );
267
ret = BluetoothEnableDiscovery( radio, TRUE );
268
ok( ret, "%d != 1\n", ret );
269
ret = BluetoothIsDiscoverable( radio );
270
ok ( ret, "%d != 1\n", ret );
271
}
272
273
void test_BluetoothEnableDiscovery( void )
274
{
275
test_for_all_radios( __FILE__, __LINE__, test_radio_BluetoothEnableDiscovery, NULL );
276
}
277
278
START_TEST( radio )
279
{
280
test_BluetoothFindFirstRadio();
281
test_BluetoothFindNextRadio();
282
test_BluetoothFindRadioClose();
283
284
test_for_all_radios( __FILE__, __LINE__, test_BluetoothGetRadioInfo, NULL );
285
test_BluetoothIsDiscoverable();
286
test_BluetoothIsConnectable();
287
test_BluetoothEnableIncomingConnections();
288
test_BluetoothEnableDiscovery();
289
}
290
291