2 * Unit test suite for wlanapi functions
4 * Copyright 2017 Bruno Jesus
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 #define WIN32_LEAN_AND_MEAN
25 #include "wine/test.h"
27 static void test_WlanOpenHandle(void)
29 HANDLE bad_handle
= (HANDLE
) 0xdeadcafe, handle
= bad_handle
, handle2
;
30 DWORD ret
, neg_version
= 0xdeadbeef, reserved
= 0xdead;
33 /* invalid version requested */
34 ret
= WlanOpenHandle(0, NULL
, &neg_version
, &handle
);
35 is_xp
= ret
== ERROR_SUCCESS
;
36 if (!is_xp
) /* the results in XP differ completely from all other versions */
38 ok(ret
== ERROR_NOT_SUPPORTED
, "Expected 50, got %d\n", ret
);
39 ok(neg_version
== 0xdeadbeef, "neg_version changed\n");
40 ok(handle
== bad_handle
, "handle changed\n");
41 ret
= WlanOpenHandle(10, NULL
, &neg_version
, &handle
);
42 ok(ret
== ERROR_NOT_SUPPORTED
, "Expected 50, got %d\n", ret
);
43 ok(neg_version
== 0xdeadbeef, "neg_version changed\n");
44 ok(handle
== bad_handle
, "handle changed\n");
46 /* reserved parameter must not be used */
47 ret
= WlanOpenHandle(1, &reserved
, &neg_version
, &handle
);
48 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
49 ok(neg_version
== 0xdeadbeef, "neg_version changed\n");
50 ok(handle
== bad_handle
, "handle changed\n");
52 /* invalid parameters */
53 ret
= WlanOpenHandle(1, NULL
, NULL
, &handle
);
54 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
55 ok(handle
== bad_handle
, "bad handle\n");
56 ret
= WlanOpenHandle(1, NULL
, &neg_version
, NULL
);
57 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
58 ok(neg_version
== 0xdeadbeef, "neg_version changed\n");
62 ok(neg_version
== 1, "Expected 1, got %d\n", neg_version
);
63 ok(handle
!= bad_handle
&& handle
, "handle changed\n");
64 ret
= WlanCloseHandle(handle
, NULL
);
65 ok(ret
== 0, "Expected 0, got %d\n", ret
);
69 ret
= WlanOpenHandle(1, NULL
, &neg_version
, &handle
);
70 ok(ret
== ERROR_SUCCESS
, "Expected 0, got %d\n", ret
);
71 ok(neg_version
== 1, "Expected 1, got %d\n", neg_version
);
72 ok(handle
!= bad_handle
&& handle
, "handle changed\n");
73 ret
= WlanCloseHandle(handle
, NULL
);
74 ok(ret
== 0, "Expected 0, got %d\n", ret
);
76 ret
= WlanOpenHandle(2, NULL
, &neg_version
, &handle
);
77 ok(ret
== ERROR_SUCCESS
, "Expected 0, got %d\n", ret
);
78 if (!is_xp
) /* XP does not support client version 2 */
79 ok(neg_version
== 2, "Expected 2, got %d\n", neg_version
);
81 ok(neg_version
== 1, "Expected 1, got %d\n", neg_version
);
82 ok(handle
!= bad_handle
&& handle
, "bad handle\n");
83 ret
= WlanCloseHandle(handle
, NULL
);
84 ok(ret
== 0, "Expected 0, got %d\n", ret
);
87 ret
= WlanOpenHandle(1, NULL
, &neg_version
, &handle
);
88 ok(ret
== ERROR_SUCCESS
, "Expected 0, got %d\n", ret
);
89 ret
= WlanOpenHandle(1, NULL
, &neg_version
, &handle2
);
90 ok(ret
== ERROR_SUCCESS
, "Expected 0, got %d\n", ret
);
92 ret
= WlanCloseHandle(handle
, &reserved
);
93 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
95 ret
= WlanCloseHandle(handle
, NULL
);
96 ok(ret
== ERROR_SUCCESS
, "Expected 0, got %d\n", ret
);
97 ret
= WlanCloseHandle(handle2
, NULL
);
98 ok(ret
== ERROR_SUCCESS
, "Expected 0, got %d\n", ret
);
100 ret
= WlanCloseHandle(bad_handle
, NULL
);
101 ok(ret
== ERROR_INVALID_HANDLE
, "Expected 6, got %d\n", ret
);
103 ret
= WlanCloseHandle(NULL
, NULL
);
104 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
107 static void test_WlanAllocateFreeMemory(void)
111 SetLastError(0xdeadbeef);
112 ptr
= WlanAllocateMemory(0);
113 ok(ptr
== NULL
, "Expected NULL, got %p\n", ptr
);
114 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", GetLastError());
116 ptr
= WlanAllocateMemory(1024);
117 ok(ptr
!= NULL
, "Expected non-NULL\n");
121 WlanFreeMemory(NULL
); /* return is void, proves that won't crash */
124 static void test_WlanEnumInterfaces(void)
127 DWORD neg_version
, i
, ret
, reserved
= 0xdeadbeef;
128 WLAN_INTERFACE_INFO_LIST
*bad_list
= (WLAN_INTERFACE_INFO_LIST
*)0xdeadcafe,
130 WLAN_INTERFACE_INFO
*info
;
132 ret
= WlanOpenHandle(1, NULL
, &neg_version
, &handle
);
133 ok(ret
== 0, "Expected 0, got %d\n", ret
);
135 /* invalid parameters */
136 ret
= WlanEnumInterfaces(NULL
, NULL
, &list
);
137 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
138 ok(list
== bad_list
, "list changed\n");
139 ret
= WlanEnumInterfaces(handle
, &reserved
, &list
);
140 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
141 ok(list
== bad_list
, "list changed\n");
142 ret
= WlanEnumInterfaces(handle
, NULL
, NULL
);
143 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected 87, got %d\n", ret
);
144 ok(list
== bad_list
, "list changed\n");
148 ret
= WlanEnumInterfaces(handle
, NULL
, &list
);
149 ok(ret
== ERROR_SUCCESS
, "Expected 0, got %d\n", ret
);
150 ok(list
!= NULL
, "bad interface list\n");
151 if (!list
|| !list
->dwNumberOfItems
)
153 skip("No wireless interfaces\n");
154 WlanCloseHandle(handle
, NULL
);
155 WlanFreeMemory(list
);
159 trace("Wireless interfaces: %d\n", list
->dwNumberOfItems
);
160 for (i
= 0; i
< list
->dwNumberOfItems
;i
++)
162 info
= &list
->InterfaceInfo
[i
];
163 trace(" Index[%d] GUID: %s\n", i
, wine_dbgstr_guid(&info
->InterfaceGuid
));
164 switch (info
->isState
)
166 case wlan_interface_state_disconnected
:
167 trace(" Status: Disconnected\n");
169 case wlan_interface_state_connected
:
170 trace(" Status: Connected\n");
173 trace(" Status: Other\n");
176 trace(" Description: %s\n", wine_dbgstr_w(info
->strInterfaceDescription
));
179 WlanFreeMemory(list
);
181 ret
= WlanCloseHandle(handle
, NULL
);
182 ok(ret
== 0, "Expected 0, got %d\n", ret
);
190 /* Windows checks the service before validating the client version so this
191 * call will always result in error, no need to free the handle. */
192 if (WlanOpenHandle(0, NULL
, &neg_version
, &handle
) == ERROR_SERVICE_NOT_ACTIVE
)
194 win_skip("No wireless service running\n");
198 test_WlanOpenHandle();
199 test_WlanAllocateFreeMemory();
200 test_WlanEnumInterfaces();