[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 FreeGuarded(
74 PVOID Pointer)
75 {
76 NTSTATUS Status;
77 PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
78 SIZE_T Size = 0;
79
80 Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE);
81 ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
82 }
83
84 #define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
85 #define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
86
87 START_TEST(RtlDetermineDosPathNameType)
88 {
89 NTSTATUS ExceptionStatus;
90 RTL_PATH_TYPE PathType;
91 struct
92 {
93 PCWSTR FileName;
94 RTL_PATH_TYPE PathType;
95 } Tests[] =
96 {
97 { L"", RtlPathTypeRelative },
98 { L"xyz", RtlPathTypeRelative },
99 { L"CON", RtlPathTypeRelative },
100 { L"NUL", RtlPathTypeRelative },
101 { L":", RtlPathTypeRelative },
102 { L"::", RtlPathTypeDriveRelative },
103 { L":::", RtlPathTypeDriveRelative },
104 { L"::::", RtlPathTypeDriveRelative },
105 { L"\\", RtlPathTypeRooted },
106 { L"\\:", RtlPathTypeRooted },
107 { L"\\C:", RtlPathTypeRooted },
108 { L"\\C:\\", RtlPathTypeRooted },
109 { L"/", RtlPathTypeRooted },
110 { L"/:", RtlPathTypeRooted },
111 { L"/C:", RtlPathTypeRooted },
112 { L"/C:/", RtlPathTypeRooted },
113 { L"C", RtlPathTypeRelative },
114 { L"C:", RtlPathTypeDriveRelative },
115 { L"C:a", RtlPathTypeDriveRelative },
116 { L"C:a\\", RtlPathTypeDriveRelative },
117 { L"C:\\", RtlPathTypeDriveAbsolute },
118 { L"C:/", RtlPathTypeDriveAbsolute },
119 { L"C:\\a", RtlPathTypeDriveAbsolute },
120 { L"C:/a", RtlPathTypeDriveAbsolute },
121 { L"C:\\\\", RtlPathTypeDriveAbsolute },
122 { L"\\\\", RtlPathTypeUncAbsolute },
123 { L"\\\\\\", RtlPathTypeUncAbsolute },
124 { L"\\\\;", RtlPathTypeUncAbsolute },
125 { L"\\??\\", RtlPathTypeRooted },
126 { L"\\??\\UNC", RtlPathTypeRooted },
127 { L"\\??\\UNC\\", RtlPathTypeRooted },
128 { L"\\?", RtlPathTypeRooted },
129 { L"\\?\\", RtlPathTypeRooted },
130 { L"\\?\\UNC", RtlPathTypeRooted },
131 { L"\\?\\UNC\\", RtlPathTypeRooted },
132 { L"\\\\?\\UNC\\", RtlPathTypeLocalDevice },
133 { L"\\\\?", RtlPathTypeRootLocalDevice },
134 { L"\\\\??", RtlPathTypeUncAbsolute },
135 { L"\\\\??\\", RtlPathTypeUncAbsolute },
136 { L"\\\\??\\C:\\", RtlPathTypeUncAbsolute },
137 { L"\\\\.", RtlPathTypeRootLocalDevice },
138 { L"\\\\.\\", RtlPathTypeLocalDevice },
139 { L"\\\\.\\C:\\", RtlPathTypeLocalDevice },
140 { L"\\/", RtlPathTypeUncAbsolute },
141 { L"/\\", RtlPathTypeUncAbsolute },
142 { L"//", RtlPathTypeUncAbsolute },
143 { L"///", RtlPathTypeUncAbsolute },
144 { L"//;", RtlPathTypeUncAbsolute },
145 { L"//?", RtlPathTypeRootLocalDevice },
146 { L"/\\?", RtlPathTypeRootLocalDevice },
147 { L"\\/?", RtlPathTypeRootLocalDevice },
148 { L"//??", RtlPathTypeUncAbsolute },
149 { L"//?" L"?/", RtlPathTypeUncAbsolute },
150 { L"//?" L"?/C:/", RtlPathTypeUncAbsolute },
151 { L"//.", RtlPathTypeRootLocalDevice },
152 { L"\\/.", RtlPathTypeRootLocalDevice },
153 { L"/\\.", RtlPathTypeRootLocalDevice },
154 { L"//./", RtlPathTypeLocalDevice },
155 { L"//./C:/", RtlPathTypeLocalDevice },
156 };
157 ULONG i;
158 PWSTR FileName;
159 USHORT Length;
160
161 if (!RtlDetermineDosPathNameType_Ustr)
162 skip(0, "RtlDetermineDosPathNameType_Ustr unavailable\n");
163
164 StartSeh() RtlDetermineDosPathNameType_U(NULL); EndSeh(STATUS_ACCESS_VIOLATION);
165
166 if (RtlDetermineDosPathNameType_Ustr)
167 {
168 UNICODE_STRING PathString;
169 StartSeh() RtlDetermineDosPathNameType_Ustr(NULL); EndSeh(STATUS_ACCESS_VIOLATION);
170
171 RtlInitEmptyUnicodeString(&PathString, NULL, MAXUSHORT);
172 PathType = RtlDetermineDosPathNameType_Ustr(&PathString);
173 ok(PathType == RtlPathTypeRelative, "PathType = %d\n", PathType);
174 }
175
176 for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++)
177 {
178 Length = (USHORT)wcslen(Tests[i].FileName) * sizeof(WCHAR);
179 FileName = AllocateGuarded(Length + sizeof(UNICODE_NULL));
180 RtlCopyMemory(FileName, Tests[i].FileName, Length + sizeof(UNICODE_NULL));
181 StartSeh()
182 PathType = RtlDetermineDosPathNameType_U(FileName);
183 ok(PathType == Tests[i].PathType, "PathType is %d, expected %d for '%S'\n", PathType, Tests[i].PathType, Tests[i].FileName);
184 EndSeh(STATUS_SUCCESS);
185 FreeGuarded(FileName);
186
187 if (RtlDetermineDosPathNameType_Ustr)
188 {
189 UNICODE_STRING PathString;
190
191 FileName = AllocateGuarded(Length);
192 RtlCopyMemory(FileName, Tests[i].FileName, Length);
193 PathString.Buffer = FileName;
194 PathString.Length = Length;
195 PathString.MaximumLength = MAXUSHORT;
196 StartSeh()
197 PathType = RtlDetermineDosPathNameType_Ustr(&PathString);
198 ok(PathType == Tests[i].PathType, "PathType is %d, expected %d for '%S'\n", PathType, Tests[i].PathType, Tests[i].FileName);
199 EndSeh(STATUS_SUCCESS);
200 FreeGuarded(FileName);
201 }
202 }
203 }