1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/*
* Unit test suite for wlanapi functions
*
* Copyright 2017 Bruno Jesus
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wlanapi.h>
#include "wine/test.h"
static void test_WlanOpenHandle(void)
{
HANDLE bad_handle = (HANDLE) 0xdeadcafe, handle = bad_handle, handle2;
DWORD ret, neg_version = 0xdeadbeef, reserved = 0xdead;
BOOL is_xp;
/* invalid version requested */
ret = WlanOpenHandle(0, NULL, &neg_version, &handle);
is_xp = ret == ERROR_SUCCESS;
if (!is_xp) /* the results in XP differ completely from all other versions */
{
ok(ret == ERROR_NOT_SUPPORTED, "Expected 50, got %d\n", ret);
ok(neg_version == 0xdeadbeef, "neg_vesion changed\n");
ok(handle == bad_handle, "handle changed\n");
ret = WlanOpenHandle(10, NULL, &neg_version, &handle);
ok(ret == ERROR_NOT_SUPPORTED, "Expected 50, got %d\n", ret);
ok(neg_version == 0xdeadbeef, "neg_vesion changed\n");
ok(handle == bad_handle, "handle changed\n");
/* reserved parameter must not be used */
ret = WlanOpenHandle(1, &reserved, &neg_version, &handle);
ok(ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
ok(neg_version == 0xdeadbeef, "neg_vesion changed\n");
ok(handle == bad_handle, "handle changed\n");
/* invalid parameters */
ret = WlanOpenHandle(1, NULL, NULL, &handle);
ok(ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
ok(handle == bad_handle, "bad handle\n");
ret = WlanOpenHandle(1, NULL, &neg_version, NULL);
ok(ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
ok(neg_version == 0xdeadbeef, "neg_vesion changed\n");
}
else
{
ok(neg_version == 1, "Expected 1, got %d\n", neg_version);
ok(handle != bad_handle && handle, "handle changed\n");
ret = WlanCloseHandle(handle, NULL);
ok(ret == 0, "Expected 0, got %d\n", ret);
}
/* good tests */
ret = WlanOpenHandle(1, NULL, &neg_version, &handle);
ok(ret == ERROR_SUCCESS, "Expected 0, got %d\n", ret);
ok(neg_version == 1, "Expected 1, got %d\n", neg_version);
ok(handle != bad_handle && handle, "handle changed\n");
ret = WlanCloseHandle(handle, NULL);
ok(ret == 0, "Expected 0, got %d\n", ret);
ret = WlanOpenHandle(2, NULL, &neg_version, &handle);
ok(ret == ERROR_SUCCESS, "Expected 0, got %d\n", ret);
if (!is_xp) /* XP does not support client version 2 */
ok(neg_version == 2, "Expected 2, got %d\n", neg_version);
else
ok(neg_version == 1, "Expected 1, got %d\n", neg_version);
ok(handle != bad_handle && handle, "bad handle\n");
ret = WlanCloseHandle(handle, NULL);
ok(ret == 0, "Expected 0, got %d\n", ret);
/* open twice */
ret = WlanOpenHandle(1, NULL, &neg_version, &handle);
ok(ret == ERROR_SUCCESS, "Expected 0, got %d\n", ret);
ret = WlanOpenHandle(1, NULL, &neg_version, &handle2);
ok(ret == ERROR_SUCCESS, "Expected 0, got %d\n", ret);
ret = WlanCloseHandle(handle, &reserved);
ok(ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
ret = WlanCloseHandle(handle, NULL);
ok(ret == ERROR_SUCCESS, "Expected 0, got %d\n", ret);
ret = WlanCloseHandle(handle2, NULL);
ok(ret == ERROR_SUCCESS, "Expected 0, got %d\n", ret);
ret = WlanCloseHandle(bad_handle, NULL);
ok(ret == ERROR_INVALID_HANDLE, "Expected 6, got %d\n", ret);
ret = WlanCloseHandle(NULL, NULL);
ok(ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
}
static void test_WlanAllocateFreeMemory(void)
{
void *ptr;
SetLastError(0xdeadbeef);
ptr = WlanAllocateMemory(0);
ok(ptr == NULL, "Expected NULL, got %p\n", ptr);
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", GetLastError());
ptr = WlanAllocateMemory(1024);
ok(ptr != NULL, "Expected non-NULL\n");
WlanFreeMemory(ptr);
WlanFreeMemory(NULL); /* return is void, proves that won't crash */
}
static void test_WlanEnumInterfaces(void)
{
HANDLE handle;
DWORD neg_version, i, ret, reserved = 0xdeadbeef;
WLAN_INTERFACE_INFO_LIST *bad_list = (WLAN_INTERFACE_INFO_LIST *)0xdeadcafe,
*list = bad_list;
WLAN_INTERFACE_INFO *info;
ret = WlanOpenHandle(1, NULL, &neg_version, &handle);
ok(ret == 0, "Expected 0, got %d\n", ret);
/* invalid parameters */
ret = WlanEnumInterfaces(NULL, NULL, &list);
ok(ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
ok(list == bad_list, "list changed\n");
ret = WlanEnumInterfaces(handle, &reserved, &list);
ok(ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
ok(list == bad_list, "list changed\n");
ret = WlanEnumInterfaces(handle, NULL, NULL);
ok(ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
ok(list == bad_list, "list changed\n");
/* good tests */
list = NULL;
ret = WlanEnumInterfaces(handle, NULL, &list);
ok(ret == ERROR_SUCCESS, "Expected 0, got %d\n", ret);
ok(list != NULL, "bad interface list\n");
if (!list || !list->dwNumberOfItems)
{
skip("No wireless interfaces\n");
WlanCloseHandle(handle, NULL);
WlanFreeMemory(list);
return;
}
trace("Wireless interfaces: %d\n", list->dwNumberOfItems);
for (i = 0; i < list->dwNumberOfItems;i ++)
{
info = &list->InterfaceInfo[i];
trace(" Index[%d] GUID: %s\n", i, wine_dbgstr_guid(&info->InterfaceGuid));
switch (info->isState)
{
case wlan_interface_state_disconnected:
trace(" Status: Disconnected\n");
break;
case wlan_interface_state_connected:
trace(" Status: Connected\n");
break;
default:
trace(" Status: Other\n");
break;
}
trace(" Description: %s\n", wine_dbgstr_w(info->strInterfaceDescription));
}
WlanFreeMemory(list);
ret = WlanCloseHandle(handle, NULL);
ok(ret == 0, "Expected 0, got %d\n", ret);
}
START_TEST(wlanapi)
{
HANDLE handle;
DWORD neg_version;
/* Windows checks the service before validating the client version so this
* call will always result in error, no need to free the handle. */
if (WlanOpenHandle(0, NULL, &neg_version, &handle) == ERROR_SERVICE_NOT_ACTIVE)
{
win_skip("No wireless service running\n");
return;
}
test_WlanOpenHandle();
test_WlanAllocateFreeMemory();
test_WlanEnumInterfaces();
}
|