2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlDosSearchPath_U
5 * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
8 #define WIN32_NO_STATUS
11 #include <wine/test.h>
12 #include <pseh/pseh2.h>
13 #include <ndk/rtlfuncs.h>
28 #define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
29 #define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus)
39 SIZE_T ExpectedLength
= wcslen(Expected
) * sizeof(WCHAR
);
41 BOOLEAN Result
= TRUE
;
44 if (Length
!= ExpectedLength
)
46 ok(0, "String length is %lu, expected %lu\n", (ULONG
)Length
, (ULONG
)ExpectedLength
);
50 EqualLength
= RtlCompareMemory(Buffer
, Expected
, Length
);
51 if (EqualLength
!= Length
)
53 ok(0, "String is '%S', expected '%S'\n", Buffer
, Expected
);
57 if (Buffer
[Length
/ sizeof(WCHAR
)] != UNICODE_NULL
)
59 ok(0, "Not null terminated\n");
63 /* the function nulls the rest of the buffer! */
64 for (i
= Length
+ sizeof(UNICODE_NULL
); i
< MaximumLength
; i
++)
66 UCHAR Char
= ((PUCHAR
)Buffer
)[i
];
69 ok(0, "Found 0x%x at offset %lu, expected 0x%x\n", Char
, (ULONG
)i
, 0);
70 /* don't count this as a failure unless the string was actually wrong */
72 /* don't flood the log */
87 PUCHAR Array
= Buffer
;
90 for (i
= 0; i
< Size
; i
++)
91 if (Array
[i
] != Value
)
93 trace("Expected %x, found %x at offset %lu\n", Value
, Array
[i
], (ULONG
)i
);
99 #define InvalidPointer ((PVOID)0x0123456789ABCDEFULL)
101 START_TEST(RtlDosSearchPath_U
)
103 NTSTATUS ExceptionStatus
;
105 WCHAR Buffer
[MAX_PATH
];
109 WCHAR FileName
[MAX_PATH
];
110 WCHAR CustomPath
[MAX_PATH
] = L
"RtlDosSearchPath_U_TestPath";
113 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
114 /* Make sure this directory doesn't exist */
115 while (GetFileAttributes(FileName
) != INVALID_FILE_ATTRIBUTES
)
117 wcscat(CustomPath
, L
"X");
118 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
120 Success
= CreateDirectory(FileName
, NULL
);
121 ok(Success
, "CreateDirectory failed, results might not be accurate\n");
122 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists", CustomPath
);
123 Success
= CreateDirectory(FileName
, NULL
);
124 ok(Success
, "CreateDirectory failed, results might not be accurate\n");
125 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath
);
126 Handle
= CreateFile(FileName
, 0, 0, NULL
, CREATE_NEW
, 0, NULL
);
127 ok(Handle
!= INVALID_HANDLE_VALUE
, "CreateFile failed, results might not be accurate\n");
128 if (Handle
!= INVALID_HANDLE_VALUE
)
131 /* NULL parameters */
132 StartSeh() RtlDosSearchPath_U(NULL
, NULL
, NULL
, 0, NULL
, NULL
); EndSeh(STATUS_ACCESS_VIOLATION
);
133 StartSeh() Length
= RtlDosSearchPath_U(NULL
, L
"", NULL
, 0, NULL
, NULL
); EndSeh(STATUS_ACCESS_VIOLATION
);
134 StartSeh() Length
= RtlDosSearchPath_U(NULL
, L
"", NULL
, 0, Buffer
, NULL
); EndSeh(STATUS_ACCESS_VIOLATION
);
135 StartSeh() Length
= RtlDosSearchPath_U(NULL
, L
"", NULL
, 1, Buffer
, NULL
); EndSeh(STATUS_ACCESS_VIOLATION
);
136 StartSeh() Length
= RtlDosSearchPath_U(NULL
, L
"", NULL
, 2, Buffer
, NULL
); EndSeh(STATUS_ACCESS_VIOLATION
);
137 StartSeh() Length
= RtlDosSearchPath_U(L
"", NULL
, NULL
, 0, NULL
, NULL
); EndSeh(STATUS_ACCESS_VIOLATION
);
139 /* Empty strings - first one that doesn't crash */
141 Length
= RtlDosSearchPath_U(L
"", L
"", NULL
, 0, NULL
, NULL
);
142 ok(Length
== 0, "Length %lu\n", Length
);
143 EndSeh(STATUS_SUCCESS
);
145 /* Check what's initialized */
146 PartName
= InvalidPointer
;
148 Length
= RtlDosSearchPath_U(L
"", L
"", NULL
, 0, NULL
, &PartName
);
149 ok(Length
== 0, "Length = %lu\n", Length
);
150 EndSeh(STATUS_SUCCESS
);
151 ok(PartName
== InvalidPointer
, "PartName = %p\n", PartName
);
153 RtlFillMemory(Buffer
, sizeof(Buffer
), 0x55);
155 Length
= RtlDosSearchPath_U(L
"", L
"", NULL
, sizeof(Buffer
), Buffer
, NULL
);
156 ok(Length
== 0, "Length %lu\n", Length
);
157 EndSeh(STATUS_SUCCESS
);
158 Okay
= CheckBuffer(Buffer
, sizeof(Buffer
), 0x55);
159 ok(Okay
, "CheckBuffer failed\n");
161 PartName
= InvalidPointer
;
162 RtlFillMemory(Buffer
, sizeof(Buffer
), 0x55);
164 Length
= RtlDosSearchPath_U(L
"", L
"", NULL
, sizeof(Buffer
), Buffer
, &PartName
);
165 ok(Length
== 0, "Length %lu\n", Length
);
166 EndSeh(STATUS_SUCCESS
);
167 ok(PartName
== InvalidPointer
, "PartName = %p\n", PartName
);
168 Okay
= CheckBuffer(Buffer
, sizeof(Buffer
), 0x55);
169 ok(Okay
, "CheckBuffer failed\n");
171 /* Empty path string searches in current directory */
172 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists", CustomPath
);
173 Success
= SetCurrentDirectory(FileName
);
174 ok(Success
, "SetCurrentDirectory failed\n");
175 PartName
= InvalidPointer
;
176 RtlFillMemory(Buffer
, sizeof(Buffer
), 0x55);
178 Length
= RtlDosSearchPath_U(L
"", L
"ThisFileExists", NULL
, sizeof(Buffer
), Buffer
, &PartName
);
179 ok(Length
== wcslen(FileName
) * sizeof(WCHAR
) + sizeof(L
"\\ThisFileExists") - sizeof(UNICODE_NULL
), "Length %lu\n", Length
);
180 EndSeh(STATUS_SUCCESS
);
181 ok(PartName
== &Buffer
[wcslen(FileName
) + 1], "PartName = %p\n", PartName
);
182 wcscat(FileName
, L
"\\ThisFileExists");
183 Okay
= CheckStringBuffer(Buffer
, Length
, sizeof(Buffer
), FileName
);
184 ok(Okay
, "CheckStringBuffer failed\n");
186 /* Absolute path in FileName is also okay */
187 PartName
= InvalidPointer
;
188 RtlFillMemory(Buffer
, sizeof(Buffer
), 0x55);
190 Length
= RtlDosSearchPath_U(L
"", L
"C:\\", NULL
, sizeof(Buffer
), Buffer
, &PartName
);
191 ok(Length
== sizeof(L
"C:\\") - sizeof(UNICODE_NULL
), "Length %lu\n", Length
);
192 EndSeh(STATUS_SUCCESS
);
193 ok(PartName
== NULL
, "PartName = %p\n", PartName
);
194 Okay
= CheckStringBuffer(Buffer
, Length
, sizeof(Buffer
), L
"C:\\");
195 ok(Okay
, "CheckStringBuffer failed\n");
197 /* Empty FileName also works */
198 PartName
= InvalidPointer
;
199 RtlFillMemory(Buffer
, sizeof(Buffer
), 0x55);
201 Length
= RtlDosSearchPath_U(L
"C:\\", L
"", NULL
, sizeof(Buffer
), Buffer
, &PartName
);
202 ok(Length
== sizeof(L
"C:\\") - sizeof(UNICODE_NULL
), "Length %lu\n", Length
);
203 EndSeh(STATUS_SUCCESS
);
204 ok(PartName
== NULL
, "PartName = %p\n", PartName
);
205 Okay
= CheckStringBuffer(Buffer
, Length
, sizeof(Buffer
), L
"C:\\");
206 ok(Okay
, "CheckStringBuffer failed\n");
208 /* Clean up test folder */
209 SetCurrentDirectory(L
"C:\\");
210 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists\\ThisFileExists", CustomPath
);
211 Success
= DeleteFile(FileName
);
212 ok(Success
, "DeleteFile failed, test might leave stale file\n");
213 swprintf(FileName
, L
"C:\\%ls\\ThisFolderExists", CustomPath
);
214 Success
= RemoveDirectory(FileName
);
215 ok(Success
, "RemoveDirectory failed %(lu), test might leave stale directory\n", GetLastError());
216 swprintf(FileName
, L
"C:\\%ls", CustomPath
);
217 Success
= RemoveDirectory(FileName
);
218 ok(Success
, "RemoveDirectory failed (%lu), test might leave stale directory\n", GetLastError());