4d92e06df246ffcc0c6000a4e8a31e84d26227fd
[reactos.git] / rostests / drivers / kmtest / deviface_test.c
1 /*
2 * PnP Test
3 * Device Interface functions test
4 *
5 * Copyright 2004 Filip Navara <xnavara@volny.cz>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; see the file COPYING.LIB.
19 * If not, write to the Free Software Foundation,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 /* INCLUDES *******************************************************************/
24
25 #include <ddk/ntddk.h>
26 #include <ndk/iotypes.h>
27 #include "kmtest.h"
28
29 //#define NDEBUG
30 #include "debug.h"
31
32 /* PRIVATE FUNCTIONS **********************************************************/
33
34 NTSTATUS
35 (NTAPI *IoGetDeviceInterfaces_Func)(
36 IN CONST GUID *InterfaceClassGuid,
37 IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
38 IN ULONG Flags,
39 OUT PWSTR *SymbolicLinkList);
40
41 NTSTATUS NTAPI
42 ReactOS_IoGetDeviceInterfaces(
43 IN CONST GUID *InterfaceClassGuid,
44 IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
45 IN ULONG Flags,
46 OUT PWSTR *SymbolicLinkList);
47
48 VOID DeviceInterfaceTest_Func()
49 {
50 NTSTATUS Status;
51 PWSTR SymbolicLinkList;
52 PWSTR SymbolicLinkListPtr;
53 GUID Guid = {0x378de44c, 0x56ef, 0x11d1, {0xbc, 0x8c, 0x00, 0xa0, 0xc9, 0x14, 0x05, 0xdd}};
54
55 Status = IoGetDeviceInterfaces_Func(
56 &Guid,
57 NULL,
58 0,
59 &SymbolicLinkList);
60
61 if (!NT_SUCCESS(Status))
62 {
63 DPRINT(
64 "[PnP Test] IoGetDeviceInterfaces failed with status 0x%X\n",
65 Status);
66 return;
67 }
68
69 DPRINT("[PnP Test] IoGetDeviceInterfaces results:\n");
70 for (SymbolicLinkListPtr = SymbolicLinkList;
71 SymbolicLinkListPtr[0] != 0 && SymbolicLinkListPtr[1] != 0;
72 SymbolicLinkListPtr += wcslen(SymbolicLinkListPtr) + 1)
73 {
74 DPRINT("[PnP Test] %S\n", SymbolicLinkListPtr);
75 }
76
77 #if 0
78 DPRINT("[PnP Test] Trying to get aliases\n");
79
80 for (SymbolicLinkListPtr = SymbolicLinkList;
81 SymbolicLinkListPtr[0] != 0 && SymbolicLinkListPtr[1] != 0;
82 SymbolicLinkListPtr += wcslen(SymbolicLinkListPtr) + 1)
83 {
84 UNICODE_STRING SymbolicLink;
85 UNICODE_STRING AliasSymbolicLink;
86
87 SymbolicLink.Buffer = SymbolicLinkListPtr;
88 SymbolicLink.Length = SymbolicLink.MaximumLength = wcslen(SymbolicLinkListPtr);
89 RtlInitUnicodeString(&AliasSymbolicLink, NULL);
90 IoGetDeviceInterfaceAlias(
91 &SymbolicLink,
92 &AliasGuid,
93 &AliasSymbolicLink);
94 if (AliasSymbolicLink.Buffer != NULL)
95 {
96 DPRINT("[PnP Test] Original: %S\n", SymbolicLinkListPtr);
97 DPRINT("[PnP Test] Alias: %S\n", AliasSymbolicLink.Buffer);
98 }
99 }
100 #endif
101
102 ExFreePool(SymbolicLinkList);
103 }
104
105 VOID RegisterDI_Test()
106 {
107 GUID Guid = {0x378de44c, 0x56ef, 0x11d1, {0xbc, 0x8c, 0x00, 0xa0, 0xc9, 0x14, 0x05, 0xdd}};
108 DEVICE_OBJECT DeviceObject;
109 EXTENDED_DEVOBJ_EXTENSION DeviceObjectExtension;
110 DEVICE_NODE DeviceNode;
111 UNICODE_STRING SymbolicLinkName;
112 NTSTATUS Status;
113
114 RtlInitUnicodeString(&SymbolicLinkName, L"");
115
116 // Prepare our surrogate of a Device Object
117 DeviceObject.DeviceObjectExtension = (PDEVOBJ_EXTENSION)&DeviceObjectExtension;
118
119 // 1. DeviceNode = NULL
120 DeviceObjectExtension.DeviceNode = NULL;
121 Status = IoRegisterDeviceInterface(&DeviceObject, &Guid, NULL,
122 &SymbolicLinkName);
123
124 ok(Status == STATUS_INVALID_DEVICE_REQUEST,
125 "IoRegisterDeviceInterface returned 0x%08lX\n", Status);
126
127 // 2. DeviceNode->InstancePath is of a null length
128 DeviceObjectExtension.DeviceNode = &DeviceNode;
129 DeviceNode.InstancePath.Length = 0;
130 Status = IoRegisterDeviceInterface(&DeviceObject, &Guid, NULL,
131 &SymbolicLinkName);
132
133 ok(Status == STATUS_INVALID_DEVICE_REQUEST,
134 "IoRegisterDeviceInterface returned 0x%08lX\n", Status);
135 }
136
137 VOID NtoskrnlIoDeviceInterface()
138 {
139 StartTest();
140
141 // Test IoRegisterDeviceInterface() failures now
142 RegisterDI_Test();
143
144 /*
145 DPRINT("Calling DeviceInterfaceTest_Func with native functions\n");
146 IoGetDeviceInterfaces_Func = IoGetDeviceInterfaces;
147 DeviceInterfaceTest_Func();
148 DPRINT("Calling DeviceInterfaceTest_Func with ReactOS functions\n");
149 IoGetDeviceInterfaces_Func = ReactOS_IoGetDeviceInterfaces;
150 DeviceInterfaceTest_Func();
151 */
152
153 FinishTest("NTOSKRNL Io Device Interface Test");
154 }