wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / wlanapi / tests / wlanapi.c
blob55ac21eee049118dd9d79f635afbc08215e1d37f
1 /*
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
22 #include <windows.h>
23 #include <wlanapi.h>
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;
31 BOOL is_xp;
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");
60 else
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);
68 /* good tests */
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);
80 else
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);
86 /* open twice */
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)
109 void *ptr;
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");
119 WlanFreeMemory(ptr);
121 WlanFreeMemory(NULL); /* return is void, proves that won't crash */
124 static void test_WlanEnumInterfaces(void)
126 HANDLE handle;
127 DWORD neg_version, i, ret, reserved = 0xdeadbeef;
128 WLAN_INTERFACE_INFO_LIST *bad_list = (WLAN_INTERFACE_INFO_LIST *)0xdeadcafe,
129 *list = bad_list;
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");
146 /* good tests */
147 list = NULL;
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);
156 return;
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");
168 break;
169 case wlan_interface_state_connected:
170 trace(" Status: Connected\n");
171 break;
172 default:
173 trace(" Status: Other\n");
174 break;
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);
185 START_TEST(wlanapi)
187 HANDLE handle;
188 DWORD neg_version;
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");
195 return;
198 test_WlanOpenHandle();
199 test_WlanAllocateFreeMemory();
200 test_WlanEnumInterfaces();