include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / ndis.sys / tests / ndis.c
blob9a9ddcf7e7f15dee57aa24a59c080655f5709da4
1 /*
2 * Unit tests for ndis ioctls
4 * Copyright (c) 2020 Isabella Bosia
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 #include <ntstatus.h>
22 #define WIN32_NO_STATUS
23 #include <windows.h>
24 #include <winioctl.h>
25 #include <winsock2.h>
26 #include <ws2ipdef.h>
27 #include <iphlpapi.h>
28 #include <netioapi.h>
29 #include <shlwapi.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <winternl.h>
33 #include <winnt.h>
34 #include "wine/test.h"
36 static void test_device(const WCHAR *service_name, const MIB_IF_ROW2 *row)
38 DWORD size;
39 int ret;
40 NDIS_MEDIUM medium;
41 UCHAR addr[IF_MAX_PHYS_ADDRESS_LENGTH];
42 HANDLE netdev = INVALID_HANDLE_VALUE;
43 int oid;
44 UNICODE_STRING str;
45 OBJECT_ATTRIBUTES attr;
46 NTSTATUS status;
47 IO_STATUS_BLOCK iosb;
48 WCHAR meoW[47];
50 swprintf( meoW, ARRAY_SIZE(meoW), L"\\Device\\%s", service_name );
51 RtlInitUnicodeString( &str, meoW );
52 InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
53 status = NtOpenFile( &netdev, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ, 0 );
55 if (status != STATUS_SUCCESS)
57 skip( "Couldn't open the device (status = %ld)\n", status );
58 return;
61 oid = 0xdeadbeef;
62 iosb.Status = 0xdeadbeef;
63 iosb.Information = 0xdeadbeef;
64 status = NtDeviceIoControlFile( netdev, NULL, NULL, NULL, &iosb,
65 IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), &medium, sizeof(medium) );
66 ok(status == STATUS_INVALID_PARAMETER, "got status %#lx\n", status);
67 ok(iosb.Status == 0xdeadbeef, "got %#lx\n", iosb.Status);
68 ok(iosb.Information == 0xdeadbeef, "got size %#Ix\n", iosb.Information);
70 oid = OID_GEN_MEDIA_SUPPORTED;
71 ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
72 &oid, sizeof(oid), &medium, sizeof(medium), &size, NULL );
73 ok( ret, "OID_GEN_MEDIA_SUPPORTED failed (ret = %d)\n", ret );
74 ok( medium == row->MediaType, "Wrong media type\n" );
76 oid = OID_GEN_MEDIA_IN_USE;
77 ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
78 &oid, sizeof(oid), &medium, sizeof(medium), &size, NULL );
79 ok( ret, "OID_GEN_MEDIA_IN_USE failed (ret = %d)\n", ret );
80 ok( medium == row->MediaType, "Wrong media type\n" );
82 oid = OID_802_3_PERMANENT_ADDRESS;
83 ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
84 &oid, sizeof(oid), addr, sizeof(addr), &size, NULL );
85 ok( ret, "OID_802_3_PERMANENT_ADDRESS failed (ret = %d)\n", ret );
86 ok( row->PhysicalAddressLength == size && !memcmp( row->PermanentPhysicalAddress, addr, size ),
87 "Wrong permanent address\n" );
89 oid = OID_802_3_CURRENT_ADDRESS;
90 ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
91 &oid, sizeof(oid), addr, sizeof(addr), &size, NULL );
92 ok( ret, "OID_802_3_CURRENT_ADDRESS failed (ret = %d)\n", ret );
93 ok( row->PhysicalAddressLength == size && !memcmp( row->PhysicalAddress, addr, size ),
94 "Wrong current address\n" );
97 static void test_ndis_ioctl(void)
99 HKEY nics, sub_key;
100 LSTATUS ret;
101 WCHAR card[16];
102 WCHAR description[100], service_name[100];
103 DWORD size, type, i = 0;
105 ret = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
106 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards", 0, KEY_READ, &nics );
107 ok( ret == ERROR_SUCCESS, "NetworkCards key missing\n" );
109 while (1)
111 MIB_IF_ROW2 row = {{0}};
112 GUID guid;
114 size = sizeof(card);
115 ret = RegEnumKeyExW( nics, i, card, &size, NULL, NULL, NULL, NULL );
116 if (ret != ERROR_SUCCESS)
117 break;
118 i++;
120 ret = RegOpenKeyExW( nics, card, 0, KEY_READ, &sub_key );
121 ok( ret == ERROR_SUCCESS, "Could not open network card subkey\n" );
123 size = sizeof(service_name);
124 ret = RegQueryValueExW( sub_key, L"ServiceName", NULL, &type, (BYTE *)service_name, &size );
125 ok( ret == ERROR_SUCCESS && type == REG_SZ, "Wrong ServiceName\n" );
127 CLSIDFromString( service_name, (LPCLSID)&guid );
128 ConvertInterfaceGuidToLuid( &guid, &row.InterfaceLuid );
130 ret = GetIfEntry2(&row);
131 ok( ret == NO_ERROR, "GetIfEntry2 failed\n" );
133 ok( IsEqualGUID( &guid, &row.InterfaceGuid ), "Wrong ServiceName\n" );
135 size = sizeof(description);
136 ret = RegQueryValueExW( sub_key, L"Description", NULL, &type, (BYTE *)description, &size );
137 ok( ret == ERROR_SUCCESS && type == REG_SZ, "Wrong Description\n" );
139 trace( "testing device <%s>\n", wine_dbgstr_w(description) );
140 test_device( service_name, &row );
142 RegCloseKey( sub_key );
145 if (i == 0)
146 skip( "Network card subkeys missing\n" );
148 RegCloseKey( nics );
151 START_TEST(ndis)
153 test_ndis_ioctl();