492d8edbb79ca21e43d6a9c3b3a6c30b37d89524
[reactos.git] / rostests / apitests / ntdll / RtlDetermineDosPathNameType.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlDetermineDosPathNameType_U/RtlDetermineDosPathNameType_Ustr
5 * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
6 */
7
8 #define WIN32_NO_STATUS
9 #include <wine/test.h>
10 #include <pseh/pseh2.h>
11 #include <ndk/mmfuncs.h>
12 #include <ndk/rtlfuncs.h>
13
14 /*
15 ULONG
16 NTAPI
17 RtlDetermineDosPathNameType_U(
18 IN PCWSTR Path
19 );
20
21 ULONG
22 NTAPI
23 RtlDetermineDosPathNameType_Ustr(
24 IN PCUNICODE_STRING Path
25 );
26 */
27
28 static
29 ULONG
30 (NTAPI
31 *RtlDetermineDosPathNameType_Ustr)(
32 IN PCUNICODE_STRING Path
33 )
34 //= (PVOID)0x7c830669;
35 ;
36
37 static
38 PVOID
39 AllocateGuarded(
40 SIZE_T SizeRequested)
41 {
42 NTSTATUS Status;
43 SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
44 PVOID VirtualMemory = NULL;
45 PCHAR StartOfBuffer;
46
47 Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS);
48
49 if (!NT_SUCCESS(Status))
50 return NULL;
51
52 Size -= PAGE_SIZE;
53 if (Size)
54 {
55 Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE);
56 if (!NT_SUCCESS(Status))
57 {
58 Size = 0;
59 Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE);
60 ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
61 return NULL;
62 }
63 }
64
65 StartOfBuffer = VirtualMemory;
66 StartOfBuffer += Size - SizeRequested;
67
68 return StartOfBuffer;
69 }
70
71 static
72 VOID
73 MakeReadOnly(
74 PVOID Pointer,
75 SIZE_T SizeRequested)
76 {
77 NTSTATUS Status;
78 SIZE_T Size = PAGE_ROUND_UP(SizeRequested);
79 PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
80
81 if (Size)
82 {
83 Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE);
84 if (!NT_SUCCESS(Status))
85 {
86 Size = 0;
87 Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE);
88 ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
89 }
90 }
91 }
92
93 static
94 VOID
95 FreeGuarded(
96 PVOID Pointer)
97 {
98 NTSTATUS Status;
99 PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
100 SIZE_T Size = 0;
101
102 Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE);
103 ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
104 }
105
106 #define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
107 #define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
108
109 START_TEST(RtlDetermineDosPathNameType)
110 {
111 NTSTATUS ExceptionStatus;
112 RTL_PATH_TYPE PathType;
113 struct
114 {
115 PCWSTR FileName;
116 RTL_PATH_TYPE PathType;
117 } Tests[] =
118 {
119 { L"", RtlPathTypeRelative },
120 { L"xyz", RtlPathTypeRelative },
121 { L"CON", RtlPathTypeRelative },
122 { L"NUL", RtlPathTypeRelative },
123 { L":", RtlPathTypeRelative },
124 { L"::", RtlPathTypeDriveRelative },
125 { L":::", RtlPathTypeDriveRelative },
126 { L"::::", RtlPathTypeDriveRelative },
127 { L"\\", RtlPathTypeRooted },
128 { L"\\:", RtlPathTypeRooted },
129 { L"\\C:", RtlPathTypeRooted },
130 { L"\\C:\\", RtlPathTypeRooted },
131 { L"/", RtlPathTypeRooted },
132 { L"/:", RtlPathTypeRooted },
133 { L"/C:", RtlPathTypeRooted },
134 { L"/C:/", RtlPathTypeRooted },
135 { L"C", RtlPathTypeRelative },
136 { L"C:", RtlPathTypeDriveRelative },
137 { L"C:a", RtlPathTypeDriveRelative },
138 { L"C:a\\", RtlPathTypeDriveRelative },
139 { L"C:\\", RtlPathTypeDriveAbsolute },
140 { L"C:/", RtlPathTypeDriveAbsolute },
141 { L"C:\\a", RtlPathTypeDriveAbsolute },
142 { L"C:/a", RtlPathTypeDriveAbsolute },
143 { L"C:\\\\", RtlPathTypeDriveAbsolute },
144 { L"\\\\", RtlPathTypeUncAbsolute },
145 { L"\\\\\\", RtlPathTypeUncAbsolute },
146 { L"\\\\;", RtlPathTypeUncAbsolute },
147 { L"\\??\\", RtlPathTypeRooted },
148 { L"\\??\\UNC", RtlPathTypeRooted },
149 { L"\\??\\UNC\\", RtlPathTypeRooted },
150 { L"\\?", RtlPathTypeRooted },
151 { L"\\?\\", RtlPathTypeRooted },
152 { L"\\?\\UNC", RtlPathTypeRooted },
153 { L"\\?\\UNC\\", RtlPathTypeRooted },
154 { L"\\\\?\\UNC\\", RtlPathTypeLocalDevice },
155 { L"\\\\?", RtlPathTypeRootLocalDevice },
156 { L"\\\\??", RtlPathTypeUncAbsolute },
157 { L"\\\\??\\", RtlPathTypeUncAbsolute },
158 { L"\\\\??\\C:\\", RtlPathTypeUncAbsolute },
159 { L"\\\\.", RtlPathTypeRootLocalDevice },
160 { L"\\\\.\\", RtlPathTypeLocalDevice },
161 { L"\\\\.\\C:\\", RtlPathTypeLocalDevice },
162 { L"\\/", RtlPathTypeUncAbsolute },
163 { L"/\\", RtlPathTypeUncAbsolute },
164 { L"//", RtlPathTypeUncAbsolute },
165 { L"///", RtlPathTypeUncAbsolute },
166 { L"//;", RtlPathTypeUncAbsolute },
167 { L"//?", RtlPathTypeRootLocalDevice },
168 { L"/\\?", RtlPathTypeRootLocalDevice },
169 { L"\\/?", RtlPathTypeRootLocalDevice },
170 { L"//??", RtlPathTypeUncAbsolute },
171 { L"//?" L"?/", RtlPathTypeUncAbsolute },
172 { L"//?" L"?/C:/", RtlPathTypeUncAbsolute },
173 { L"//.", RtlPathTypeRootLocalDevice },
174 { L"\\/.", RtlPathTypeRootLocalDevice },
175 { L"/\\.", RtlPathTypeRootLocalDevice },
176 { L"//./", RtlPathTypeLocalDevice },
177 { L"//./C:/", RtlPathTypeLocalDevice },
178 };
179 ULONG i;
180 PWSTR FileName;
181 USHORT Length;
182
183 if (!RtlDetermineDosPathNameType_Ustr)
184 skip("RtlDetermineDosPathNameType_Ustr unavailable\n");
185
186 StartSeh() RtlDetermineDosPathNameType_U(NULL); EndSeh(STATUS_ACCESS_VIOLATION);
187
188 if (RtlDetermineDosPathNameType_Ustr)
189 {
190 UNICODE_STRING PathString;
191 StartSeh() RtlDetermineDosPathNameType_Ustr(NULL); EndSeh(STATUS_ACCESS_VIOLATION);
192
193 RtlInitEmptyUnicodeString(&PathString, NULL, MAXUSHORT);
194 PathType = RtlDetermineDosPathNameType_Ustr(&PathString);
195 ok(PathType == RtlPathTypeRelative, "PathType = %d\n", PathType);
196 }
197
198 for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++)
199 {
200 Length = (USHORT)wcslen(Tests[i].FileName) * sizeof(WCHAR);
201 FileName = AllocateGuarded(Length + sizeof(UNICODE_NULL));
202 RtlCopyMemory(FileName, Tests[i].FileName, Length + sizeof(UNICODE_NULL));
203 MakeReadOnly(FileName, Length + sizeof(UNICODE_NULL));
204 StartSeh()
205 PathType = RtlDetermineDosPathNameType_U(FileName);
206 ok(PathType == Tests[i].PathType, "PathType is %d, expected %d for '%S'\n", PathType, Tests[i].PathType, Tests[i].FileName);
207 EndSeh(STATUS_SUCCESS);
208 FreeGuarded(FileName);
209
210 if (RtlDetermineDosPathNameType_Ustr)
211 {
212 UNICODE_STRING PathString;
213
214 FileName = AllocateGuarded(Length);
215 RtlCopyMemory(FileName, Tests[i].FileName, Length);
216 MakeReadOnly(FileName, Length);
217 PathString.Buffer = FileName;
218 PathString.Length = Length;
219 PathString.MaximumLength = MAXUSHORT;
220 StartSeh()
221 PathType = RtlDetermineDosPathNameType_Ustr(&PathString);
222 ok(PathType == Tests[i].PathType, "PathType is %d, expected %d for '%S'\n", PathType, Tests[i].PathType, Tests[i].FileName);
223 EndSeh(STATUS_SUCCESS);
224 FreeGuarded(FileName);
225 }
226 }
227 }