1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * PROJECT:         ReactOS kernel-mode tests
3*c2c66affSColin Finck  * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
4*c2c66affSColin Finck  * PURPOSE:         Test for FsRtlDissectName/FsRtlDissectDbcs
5*c2c66affSColin Finck  * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
6*c2c66affSColin Finck  */
7*c2c66affSColin Finck 
8*c2c66affSColin Finck #include <kmt_test.h>
9*c2c66affSColin Finck 
10*c2c66affSColin Finck static struct
11*c2c66affSColin Finck {
12*c2c66affSColin Finck     PCSTR Name;
13*c2c66affSColin Finck     INT Offset1;
14*c2c66affSColin Finck     INT Offset2;
15*c2c66affSColin Finck     INT Length1;
16*c2c66affSColin Finck     INT Length2;
17*c2c66affSColin Finck } Tests[] =
18*c2c66affSColin Finck {
19*c2c66affSColin Finck     { NULL,         -1, -1       },
20*c2c66affSColin Finck     { "",           -1, -1       },
21*c2c66affSColin Finck     { "a",           0, -1, 1, 1 },
22*c2c66affSColin Finck     { "a\\b",        0,  2, 1, 1 },
23*c2c66affSColin Finck     { "a\\",         0,  2, 1, 0 },
24*c2c66affSColin Finck     { "\\b",         1, -1, 1    },
25*c2c66affSColin Finck     { "\\",          1, -1, 0    },
26*c2c66affSColin Finck     { "a\\b\\c",     0,  2, 1, 3 },
27*c2c66affSColin Finck     { "\\a\\b\\c",   1,  3, 1, 3 },
28*c2c66affSColin Finck     /* Forward slashes are not separators */
29*c2c66affSColin Finck     { "/",           0, -1, 1    },
30*c2c66affSColin Finck     { "/a",          0, -1, 2    },
31*c2c66affSColin Finck     { "/a/b",        0, -1, 4    },
32*c2c66affSColin Finck     /* Normal parsing cycle */
33*c2c66affSColin Finck     { "Good Morning!\\Good Evening!\\Good Night",   0,  14, 13, 24 },
34*c2c66affSColin Finck     { "Good Evening!\\Good Night",                  0,  14, 13, 10 },
35*c2c66affSColin Finck     { "Good Night",                                 0,  -1, 10 },
36*c2c66affSColin Finck     /* Double backslashes */
37*c2c66affSColin Finck     { "\\\\",        1,  2, 0, 0 },
38*c2c66affSColin Finck     { "a\\\\",       0,  2, 1, 1 },
39*c2c66affSColin Finck     { "\\\\b",       1,  2, 0, 1 },
40*c2c66affSColin Finck     { "a\\\\b",      0,  2, 1, 2 },
41*c2c66affSColin Finck     /* Even more backslashes */
42*c2c66affSColin Finck     { "\\\\\\",      1,  2, 0, 1 },
43*c2c66affSColin Finck     { "a\\\\\\",     0,  2, 1, 2 },
44*c2c66affSColin Finck     { "\\\\\\b",     1,  2, 0, 2 },
45*c2c66affSColin Finck     { "a\\\\\\b",    0,  2, 1, 3 },
46*c2c66affSColin Finck     { "a\\\\\\\\b",  0,  2, 1, 4 },
47*c2c66affSColin Finck };
48*c2c66affSColin Finck 
START_TEST(FsRtlDissect)49*c2c66affSColin Finck START_TEST(FsRtlDissect)
50*c2c66affSColin Finck {
51*c2c66affSColin Finck     NTSTATUS Status;
52*c2c66affSColin Finck     ANSI_STRING NameA;
53*c2c66affSColin Finck     ANSI_STRING FirstA;
54*c2c66affSColin Finck     ANSI_STRING RemainingA;
55*c2c66affSColin Finck     UNICODE_STRING NameU;
56*c2c66affSColin Finck     UNICODE_STRING FirstU;
57*c2c66affSColin Finck     UNICODE_STRING RemainingU;
58*c2c66affSColin Finck     ULONG i;
59*c2c66affSColin Finck 
60*c2c66affSColin Finck     for (i = 0; i < RTL_NUMBER_OF(Tests); i++)
61*c2c66affSColin Finck     {
62*c2c66affSColin Finck         RtlInitAnsiString(&NameA, Tests[i].Name);
63*c2c66affSColin Finck         RtlFillMemory(&FirstA, sizeof(FirstA), 0x55);
64*c2c66affSColin Finck         RtlFillMemory(&RemainingA, sizeof(RemainingA), 0x55);
65*c2c66affSColin Finck         FsRtlDissectDbcs(NameA, &FirstA, &RemainingA);
66*c2c66affSColin Finck         if (Tests[i].Offset1 == -1)
67*c2c66affSColin Finck         {
68*c2c66affSColin Finck             ok(FirstA.Buffer == NULL, "[%s] First=%p, expected NULL\n", Tests[i].Name, FirstA.Buffer);
69*c2c66affSColin Finck             ok(FirstA.Length == 0, "[%s] FirstLen=%u, expected 0\n", Tests[i].Name, FirstA.Length);
70*c2c66affSColin Finck             ok(FirstA.MaximumLength == 0, "[%s] FirstMaxLen=%u, expected 0\n", Tests[i].Name, FirstA.MaximumLength);
71*c2c66affSColin Finck         }
72*c2c66affSColin Finck         else
73*c2c66affSColin Finck         {
74*c2c66affSColin Finck             ok(FirstA.Buffer == NameA.Buffer + Tests[i].Offset1, "[%s] First=%p, expected %p\n", Tests[i].Name, FirstA.Buffer, NameA.Buffer + Tests[i].Offset1);
75*c2c66affSColin Finck             ok(FirstA.Length == Tests[i].Length1, "[%s] FirstLen=%u, expected %d\n", Tests[i].Name, FirstA.Length, Tests[i].Length1);
76*c2c66affSColin Finck             ok(FirstA.MaximumLength == Tests[i].Length1, "[%s] FirstMaxLen=%u, expected %d\n", Tests[i].Name, FirstA.MaximumLength, Tests[i].Length1);
77*c2c66affSColin Finck         }
78*c2c66affSColin Finck         if (Tests[i].Offset2 == -1)
79*c2c66affSColin Finck         {
80*c2c66affSColin Finck             ok(RemainingA.Buffer == NULL, "[%s] Remaining=%p, expected NULL\n", Tests[i].Name, RemainingA.Buffer);
81*c2c66affSColin Finck             ok(RemainingA.Length == 0, "[%s] RemainingLen=%u, expected 0\n", Tests[i].Name, RemainingA.Length);
82*c2c66affSColin Finck             ok(RemainingA.MaximumLength == 0, "[%s] RemainingMaxLen=%u, expected 0\n", Tests[i].Name, RemainingA.MaximumLength);
83*c2c66affSColin Finck         }
84*c2c66affSColin Finck         else
85*c2c66affSColin Finck         {
86*c2c66affSColin Finck             ok(RemainingA.Buffer == NameA.Buffer + Tests[i].Offset2, "[%s] Remaining=%p, expected %p\n", Tests[i].Name, RemainingA.Buffer, NameA.Buffer + Tests[i].Offset2);
87*c2c66affSColin Finck             ok(RemainingA.Length == Tests[i].Length2, "[%s] RemainingLen=%u, expected %d\n", Tests[i].Name, RemainingA.Length, Tests[i].Length2);
88*c2c66affSColin Finck             ok(RemainingA.MaximumLength == Tests[i].Length2, "[%s] RemainingMaxLen=%u, expected %d\n", Tests[i].Name, RemainingA.MaximumLength, Tests[i].Length2);
89*c2c66affSColin Finck         }
90*c2c66affSColin Finck 
91*c2c66affSColin Finck         Status = RtlAnsiStringToUnicodeString(&NameU, &NameA, TRUE);
92*c2c66affSColin Finck         if (skip(NT_SUCCESS(Status), "Conversion failed with %lx\n", Status))
93*c2c66affSColin Finck             continue;
94*c2c66affSColin Finck         RtlFillMemory(&FirstU, sizeof(FirstU), 0x55);
95*c2c66affSColin Finck         RtlFillMemory(&RemainingU, sizeof(RemainingU), 0x55);
96*c2c66affSColin Finck         FsRtlDissectName(NameU, &FirstU, &RemainingU);
97*c2c66affSColin Finck         if (Tests[i].Offset1 == -1)
98*c2c66affSColin Finck         {
99*c2c66affSColin Finck             ok(FirstU.Buffer == NULL, "[%s] First=%p, expected NULL\n", Tests[i].Name, FirstU.Buffer);
100*c2c66affSColin Finck             ok(FirstU.Length == 0, "[%s] FirstLen=%u, expected 0\n", Tests[i].Name, FirstU.Length);
101*c2c66affSColin Finck             ok(FirstU.MaximumLength == 0, "[%s] FirstMaxLen=%u, expected 0\n", Tests[i].Name, FirstU.MaximumLength);
102*c2c66affSColin Finck         }
103*c2c66affSColin Finck         else
104*c2c66affSColin Finck         {
105*c2c66affSColin Finck             ok(FirstU.Buffer == NameU.Buffer + Tests[i].Offset1, "[%s] First=%p, expected %p\n", Tests[i].Name, FirstU.Buffer, NameU.Buffer + Tests[i].Offset1);
106*c2c66affSColin Finck             ok(FirstU.Length == Tests[i].Length1 * sizeof(WCHAR), "[%s] FirstLen=%u, expected %d\n", Tests[i].Name, FirstU.Length, Tests[i].Length1 * sizeof(WCHAR));
107*c2c66affSColin Finck             ok(FirstU.MaximumLength == Tests[i].Length1 * sizeof(WCHAR), "[%s] FirstMaxLen=%u, expected %d\n", Tests[i].Name, FirstU.MaximumLength, Tests[i].Length1 * sizeof(WCHAR));
108*c2c66affSColin Finck         }
109*c2c66affSColin Finck         if (Tests[i].Offset2 == -1)
110*c2c66affSColin Finck         {
111*c2c66affSColin Finck             ok(RemainingU.Buffer == NULL, "[%s] Remaining=%p, expected NULL\n", Tests[i].Name, RemainingU.Buffer);
112*c2c66affSColin Finck             ok(RemainingU.Length == 0, "[%s] RemainingLen=%u, expected 0\n", Tests[i].Name, RemainingU.Length);
113*c2c66affSColin Finck             ok(RemainingU.MaximumLength == 0, "[%s] RemainingMaxLen=%u, expected 0\n", Tests[i].Name, RemainingU.MaximumLength);
114*c2c66affSColin Finck         }
115*c2c66affSColin Finck         else
116*c2c66affSColin Finck         {
117*c2c66affSColin Finck             ok(RemainingU.Buffer == NameU.Buffer + Tests[i].Offset2, "[%s] Remaining=%p, expected %p\n", Tests[i].Name, RemainingU.Buffer, NameU.Buffer + Tests[i].Offset2);
118*c2c66affSColin Finck             ok(RemainingU.Length == Tests[i].Length2 * sizeof(WCHAR), "[%s] RemainingLen=%u, expected %d\n", Tests[i].Name, RemainingU.Length, Tests[i].Length2 * sizeof(WCHAR));
119*c2c66affSColin Finck             ok(RemainingU.MaximumLength == Tests[i].Length2 * sizeof(WCHAR), "[%s] RemainingMaxLen=%u, expected %d\n", Tests[i].Name, RemainingU.MaximumLength, Tests[i].Length2 * sizeof(WCHAR));
120*c2c66affSColin Finck         }
121*c2c66affSColin Finck         RtlFreeUnicodeString(&NameU);
122*c2c66affSColin Finck     }
123*c2c66affSColin Finck }
124