ole32/tests: Add a test for IBindCtx::GetRunningObjectTable().
[wine.git] / dlls / ndis.sys / tests / ndis.c
blobd6a2db0fd9d727c0f4e2fd43797dd2d30eec8f9d
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 = %d)\n", status );
58 return;
61 oid = OID_GEN_MEDIA_SUPPORTED;
62 ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
63 &oid, sizeof(oid), &medium, sizeof(medium), &size, NULL );
64 ok( ret, "OID_GEN_MEDIA_SUPPORTED failed (ret = %d)\n", ret );
65 ok( medium == row->MediaType, "Wrong media type\n" );
67 oid = OID_GEN_MEDIA_IN_USE;
68 ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
69 &oid, sizeof(oid), &medium, sizeof(medium), &size, NULL );
70 ok( ret, "OID_GEN_MEDIA_IN_USE failed (ret = %d)\n", ret );
71 ok( medium == row->MediaType, "Wrong media type\n" );
73 oid = OID_802_3_PERMANENT_ADDRESS;
74 ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
75 &oid, sizeof(oid), addr, sizeof(addr), &size, NULL );
76 ok( ret, "OID_802_3_PERMANENT_ADDRESS failed (ret = %d)\n", ret );
77 ok( row->PhysicalAddressLength == size && !memcmp( row->PermanentPhysicalAddress, addr, size ),
78 "Wrong permanent address\n" );
80 oid = OID_802_3_CURRENT_ADDRESS;
81 ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
82 &oid, sizeof(oid), addr, sizeof(addr), &size, NULL );
83 ok( ret, "OID_802_3_CURRENT_ADDRESS failed (ret = %d)\n", ret );
84 ok( row->PhysicalAddressLength == size && !memcmp( row->PhysicalAddress, addr, size ),
85 "Wrong current address\n" );
88 static void test_ndis_ioctl(void)
90 HKEY nics, sub_key;
91 LSTATUS ret;
92 WCHAR card[16];
93 WCHAR description[100], service_name[100];
94 DWORD size, type, i = 0;
96 ret = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
97 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards", 0, KEY_READ, &nics );
98 ok( ret == ERROR_SUCCESS, "NetworkCards key missing\n" );
100 while (1)
102 MIB_IF_ROW2 row = {{0}};
103 GUID guid;
105 size = sizeof(card);
106 ret = RegEnumKeyExW( nics, i, card, &size, NULL, NULL, NULL, NULL );
107 if (ret != ERROR_SUCCESS)
108 break;
109 i++;
111 ret = RegOpenKeyExW( nics, card, 0, KEY_READ, &sub_key );
112 ok( ret == ERROR_SUCCESS, "Could not open network card subkey\n" );
114 size = sizeof(service_name);
115 ret = RegQueryValueExW( sub_key, L"ServiceName", NULL, &type, (BYTE *)service_name, &size );
116 ok( ret == ERROR_SUCCESS && type == REG_SZ, "Wrong ServiceName\n" );
118 CLSIDFromString( service_name, (LPCLSID)&guid );
119 ConvertInterfaceGuidToLuid( &guid, &row.InterfaceLuid );
121 ret = GetIfEntry2(&row);
122 ok( ret == NO_ERROR, "GetIfEntry2 failed\n" );
124 ok( IsEqualGUID( &guid, &row.InterfaceGuid ), "Wrong ServiceName\n" );
126 size = sizeof(description);
127 ret = RegQueryValueExW( sub_key, L"Description", NULL, &type, (BYTE *)description, &size );
128 ok( ret == ERROR_SUCCESS && type == REG_SZ, "Wrong Description\n" );
130 trace( "testing device <%s>\n", wine_dbgstr_w(description) );
131 test_device( service_name, &row );
133 RegCloseKey( sub_key );
136 if (i == 0)
137 skip( "Network card subkeys missing\n" );
139 RegCloseKey( nics );
142 START_TEST(ndis)
144 test_ndis_ioctl();