2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Device Interface functions test
5 * PROGRAMMER: Filip Navara <xnavara@volny.cz>
8 /* TODO: what's with the prototypes at the top, what's with the if-ed out part? Doesn't process most results */
18 (NTAPI
*IoGetDeviceInterfaces_Func
)(
19 IN CONST GUID
*InterfaceClassGuid
,
20 IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL
,
22 OUT PWSTR
*SymbolicLinkList
);
25 ReactOS_IoGetDeviceInterfaces(
26 IN CONST GUID
*InterfaceClassGuid
,
27 IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL
,
29 OUT PWSTR
*SymbolicLinkList
);
32 static VOID
DeviceInterfaceTest_Func()
35 PWSTR SymbolicLinkList
;
36 PWSTR SymbolicLinkListPtr
;
37 GUID Guid
= {0x378de44c, 0x56ef, 0x11d1, {0xbc, 0x8c, 0x00, 0xa0, 0xc9, 0x14, 0x05, 0xdd}};
39 Status
= IoGetDeviceInterfaces(
45 ok(NT_SUCCESS(Status
),
46 "IoGetDeviceInterfaces failed with status 0x%X\n",
47 (unsigned int)Status
);
48 if (!NT_SUCCESS(Status
))
53 DPRINT("IoGetDeviceInterfaces results:\n");
54 for (SymbolicLinkListPtr
= SymbolicLinkList
;
55 SymbolicLinkListPtr
[0] != 0 && SymbolicLinkListPtr
[1] != 0;
56 SymbolicLinkListPtr
+= wcslen(SymbolicLinkListPtr
) + 1)
58 DPRINT1("Symbolic Link: %S\n", SymbolicLinkListPtr
);
62 DPRINT("[PnP Test] Trying to get aliases\n");
64 for (SymbolicLinkListPtr
= SymbolicLinkList
;
65 SymbolicLinkListPtr
[0] != 0 && SymbolicLinkListPtr
[1] != 0;
66 SymbolicLinkListPtr
+= wcslen(SymbolicLinkListPtr
) + 1)
68 UNICODE_STRING SymbolicLink
;
69 UNICODE_STRING AliasSymbolicLink
;
71 SymbolicLink
.Buffer
= SymbolicLinkListPtr
;
72 SymbolicLink
.Length
= SymbolicLink
.MaximumLength
= wcslen(SymbolicLinkListPtr
);
73 RtlInitUnicodeString(&AliasSymbolicLink
, NULL
);
74 IoGetDeviceInterfaceAlias(
78 if (AliasSymbolicLink
.Buffer
!= NULL
)
80 DPRINT("[PnP Test] Original: %S\n", SymbolicLinkListPtr
);
81 DPRINT("[PnP Test] Alias: %S\n", AliasSymbolicLink
.Buffer
);
86 ExFreePool(SymbolicLinkList
);
91 Test_IoRegisterDeviceInterface(VOID
)
93 GUID Guid
= {0x378de44c, 0x56ef, 0x11d1, {0xbc, 0x8c, 0x00, 0xa0, 0xc9, 0x14, 0x05, 0xdd}};
94 DEVICE_OBJECT DeviceObject
;
95 EXTENDED_DEVOBJ_EXTENSION DeviceObjectExtension
;
96 DEVICE_NODE DeviceNode
;
97 UNICODE_STRING SymbolicLinkName
;
100 RtlInitUnicodeString(&SymbolicLinkName
, L
"");
102 // Prepare our surrogate of a Device Object
103 DeviceObject
.DeviceObjectExtension
= (PDEVOBJ_EXTENSION
)&DeviceObjectExtension
;
105 // 1. DeviceNode = NULL
106 DeviceObjectExtension
.DeviceNode
= NULL
;
107 Status
= IoRegisterDeviceInterface(&DeviceObject
, &Guid
, NULL
,
110 ok(Status
== STATUS_INVALID_DEVICE_REQUEST
,
111 "IoRegisterDeviceInterface returned 0x%08lX\n", Status
);
113 // 2. DeviceNode->InstancePath is of a null length
114 DeviceObjectExtension
.DeviceNode
= &DeviceNode
;
115 DeviceNode
.InstancePath
.Length
= 0;
116 Status
= IoRegisterDeviceInterface(&DeviceObject
, &Guid
, NULL
,
119 ok(Status
== STATUS_INVALID_DEVICE_REQUEST
,
120 "IoRegisterDeviceInterface returned 0x%08lX\n", Status
);
122 DeviceInterfaceTest_Func();
125 static UCHAR NotificationContext
;
127 static DRIVER_NOTIFICATION_CALLBACK_ROUTINE NotificationCallback
;
131 NotificationCallback(
132 _In_ PVOID NotificationStructure
,
133 _Inout_opt_ PVOID Context
)
135 PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification
= NotificationStructure
;
137 OBJECT_ATTRIBUTES ObjectAttributes
;
140 ok_irql(PASSIVE_LEVEL
);
141 ok_eq_pointer(Context
, &NotificationContext
);
142 ok_eq_uint(Notification
->Version
, 1);
143 ok_eq_uint(Notification
->Size
, sizeof(*Notification
));
145 /* symbolic link must exist */
146 trace("Interface change: %wZ\n", Notification
->SymbolicLinkName
);
147 InitializeObjectAttributes(&ObjectAttributes
,
148 Notification
->SymbolicLinkName
,
152 Status
= ZwOpenSymbolicLinkObject(&Handle
, GENERIC_READ
, &ObjectAttributes
);
153 ok_eq_hex(Status
, STATUS_SUCCESS
);
154 if (!skip(NT_SUCCESS(Status
), "No symbolic link\n"))
156 Status
= ObCloseHandle(Handle
, KernelMode
);
157 ok_eq_hex(Status
, STATUS_SUCCESS
);
159 return STATUS_SUCCESS
;
164 Test_IoRegisterPlugPlayNotification(VOID
)
167 PVOID NotificationEntry
;
169 Status
= IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange
,
170 PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
,
171 (PVOID
)&GUID_DEVICE_SYS_BUTTON
,
173 NotificationCallback
,
174 &NotificationContext
,
176 ok_eq_hex(Status
, STATUS_SUCCESS
);
177 if (!skip(NT_SUCCESS(Status
), "PlugPlayNotification not registered\n"))
179 Status
= IoUnregisterPlugPlayNotification(NotificationEntry
);
180 ok_eq_hex(Status
, STATUS_SUCCESS
);
184 START_TEST(IoDeviceInterface
)
186 // FIXME: This test crashes in Windows
187 (void)Test_IoRegisterDeviceInterface
;
188 Test_IoRegisterPlugPlayNotification();