1 /*
2  * PROJECT:         ReactOS kernel-mode tests
3  * LICENSE:         LGPLv2+ - See COPYING.LIB in the top level directory
4  * PURPOSE:         Tests for FsRtlRemoveDotsFromPath
5  * PROGRAMMER:      Pierre Schweitzer <pierre@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 
10 #define NDEBUG
11 #include <debug.h>
12 
13 #define InitConstString(s, c)                    \
14     wcscpy(s.Buffer, c);                         \
15     s.Buffer[sizeof(c) / sizeof(WCHAR) - 1] = 0; \
16     s.Length = sizeof(c) - sizeof(UNICODE_NULL)
17 
18 NTSTATUS NTAPI FsRtlRemoveDotsFromPath(PWSTR OriginalString,
19                                        USHORT PathLength, USHORT *NewLength);
20 
21 static
22 NTSTATUS
23 (NTAPI *pFsRtlRemoveDotsFromPath)(PWSTR OriginalString,
24                                   USHORT PathLength, USHORT *NewLength);
25 
26 START_TEST(FsRtlRemoveDotsFromPath)
27 {
28     WCHAR Buf[255];
29     UNICODE_STRING TestString;
30     NTSTATUS Status;
31 
32     TestString.Buffer = Buf;
33     TestString.MaximumLength = sizeof(Buf);
34     KmtGetSystemOrEmbeddedRoutineAddress(FsRtlRemoveDotsFromPath);
35     ASSERT(pFsRtlRemoveDotsFromPath);
36 
37     InitConstString(TestString, L"\\..");
38     Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length);
39     ok_eq_hex(Status, STATUS_IO_REPARSE_DATA_INVALID);
40 
41     InitConstString(TestString, L"..");
42     Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length);
43     ok_eq_hex(Status, STATUS_IO_REPARSE_DATA_INVALID);
44 
45     InitConstString(TestString, L"..\\anyOtherContent");
46     Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length);
47     ok_eq_hex(Status, STATUS_IO_REPARSE_DATA_INVALID);
48 
49     InitConstString(TestString, L"\\\\..");
50     Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length);
51     ok_eq_hex(Status, STATUS_SUCCESS);
52     ok_eq_wstr(TestString.Buffer, L"\\");
53 
54     InitConstString(TestString, L"\\dir1\\dir2\\..\\dir3\\.\\file.txt");
55     Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length);
56     ok_eq_hex(Status, STATUS_SUCCESS);
57     ok_eq_wstr(TestString.Buffer, L"\\dir1\\dir3\\file.txt");
58 }
59 
60