[NTDLL_APITEST]
[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"::\\", RtlPathTypeDriveAbsolute },
128 { L"\\", RtlPathTypeRooted },
129 { L"\\:", RtlPathTypeRooted },
130 { L"\\C:", RtlPathTypeRooted },
131 { L"\\C:\\", RtlPathTypeRooted },
132 { L"/", RtlPathTypeRooted },
133 { L"/:", RtlPathTypeRooted },
134 { L"/C:", RtlPathTypeRooted },
135 { L"/C:/", RtlPathTypeRooted },
136 { L"C", RtlPathTypeRelative },
137 { L"C:", RtlPathTypeDriveRelative },
138 { L"C:a", RtlPathTypeDriveRelative },
139 { L"C:a\\", RtlPathTypeDriveRelative },
140 { L"C:\\", RtlPathTypeDriveAbsolute },
141 { L"C:/", RtlPathTypeDriveAbsolute },
142 { L"C:\\a", RtlPathTypeDriveAbsolute },
143 { L"C:/a", RtlPathTypeDriveAbsolute },
144 { L"C:\\\\", RtlPathTypeDriveAbsolute },
145 { L"\\\\", RtlPathTypeUncAbsolute },
146 { L"\\\\\\", RtlPathTypeUncAbsolute },
147 { L"\\\\;", RtlPathTypeUncAbsolute },
148 { L"\\??\\", RtlPathTypeRooted },
149 { L"\\??\\UNC", RtlPathTypeRooted },
150 { L"\\??\\UNC\\", RtlPathTypeRooted },
151 { L"\\?", RtlPathTypeRooted },
152 { L"\\?\\", RtlPathTypeRooted },
153 { L"\\?\\UNC", RtlPathTypeRooted },
154 { L"\\?\\UNC\\", RtlPathTypeRooted },
155 { L"\\\\?\\UNC\\", RtlPathTypeLocalDevice },
156 { L"\\\\?", RtlPathTypeRootLocalDevice },
157 { L"\\\\??", RtlPathTypeUncAbsolute },
158 { L"\\\\??\\", RtlPathTypeUncAbsolute },
159 { L"\\\\??\\C:\\", RtlPathTypeUncAbsolute },
160 { L"\\\\.", RtlPathTypeRootLocalDevice },
161 { L"\\\\.\\", RtlPathTypeLocalDevice },
162 { L"\\\\.\\C:\\", RtlPathTypeLocalDevice },
163 { L"\\/", RtlPathTypeUncAbsolute },
164 { L"/\\", RtlPathTypeUncAbsolute },
165 { L"//", RtlPathTypeUncAbsolute },
166 { L"///", RtlPathTypeUncAbsolute },
167 { L"//;", RtlPathTypeUncAbsolute },
168 { L"//?", RtlPathTypeRootLocalDevice },
169 { L"/\\?", RtlPathTypeRootLocalDevice },
170 { L"\\/?", RtlPathTypeRootLocalDevice },
171 { L"//??", RtlPathTypeUncAbsolute },
172 { L"//?" L"?/", RtlPathTypeUncAbsolute },
173 { L"//?" L"?/C:/", RtlPathTypeUncAbsolute },
174 { L"//.", RtlPathTypeRootLocalDevice },
175 { L"\\/.", RtlPathTypeRootLocalDevice },
176 { L"/\\.", RtlPathTypeRootLocalDevice },
177 { L"//./", RtlPathTypeLocalDevice },
178 { L"//./C:/", RtlPathTypeLocalDevice },
179 { L"%SystemRoot%", RtlPathTypeRelative },
180 };
181 ULONG i;
182 PWSTR FileName;
183 USHORT Length;
184
185 if (!RtlDetermineDosPathNameType_Ustr)
186 skip("RtlDetermineDosPathNameType_Ustr unavailable\n");
187
188 StartSeh() RtlDetermineDosPathNameType_U(NULL); EndSeh(STATUS_ACCESS_VIOLATION);
189
190 if (RtlDetermineDosPathNameType_Ustr)
191 {
192 UNICODE_STRING PathString;
193 StartSeh() RtlDetermineDosPathNameType_Ustr(NULL); EndSeh(STATUS_ACCESS_VIOLATION);
194
195 RtlInitEmptyUnicodeString(&PathString, NULL, MAXUSHORT);
196 PathType = RtlDetermineDosPathNameType_Ustr(&PathString);
197 ok(PathType == RtlPathTypeRelative, "PathType = %d\n", PathType);
198 }
199
200 for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++)
201 {
202 Length = (USHORT)wcslen(Tests[i].FileName) * sizeof(WCHAR);
203 FileName = AllocateGuarded(Length + sizeof(UNICODE_NULL));
204 RtlCopyMemory(FileName, Tests[i].FileName, Length + sizeof(UNICODE_NULL));
205 MakeReadOnly(FileName, Length + sizeof(UNICODE_NULL));
206 StartSeh()
207 PathType = RtlDetermineDosPathNameType_U(FileName);
208 ok(PathType == Tests[i].PathType, "PathType is %d, expected %d for '%S'\n", PathType, Tests[i].PathType, Tests[i].FileName);
209 EndSeh(STATUS_SUCCESS);
210 FreeGuarded(FileName);
211
212 if (RtlDetermineDosPathNameType_Ustr)
213 {
214 UNICODE_STRING PathString;
215
216 FileName = AllocateGuarded(Length);
217 RtlCopyMemory(FileName, Tests[i].FileName, Length);
218 MakeReadOnly(FileName, Length);
219 PathString.Buffer = FileName;
220 PathString.Length = Length;
221 PathString.MaximumLength = MAXUSHORT;
222 StartSeh()
223 PathType = RtlDetermineDosPathNameType_Ustr(&PathString);
224 ok(PathType == Tests[i].PathType, "PathType is %d, expected %d for '%S'\n", PathType, Tests[i].PathType, Tests[i].FileName);
225 EndSeh(STATUS_SUCCESS);
226 FreeGuarded(FileName);
227 }
228 }
229 }