41fbd59c34ff37c2180670345df64e30b77f621c
[reactos.git] / modules / rostests / kmtests / ntos_fsrtl / FsRtlLegal.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for FsRtlIsFatDbcsLegal/FsRtlIsHpfsDbcsLegal
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <kmt_test.h>
9
10 static struct
11 {
12 PCSTR Dbcs;
13 BOOLEAN LegalFat;
14 BOOLEAN LegalHpfs;
15 BOOLEAN HasWildCards;
16 BOOLEAN IsPath;
17 BOOLEAN LeadingBackslash;
18 } Tests[] =
19 {
20 { "", FALSE, FALSE },
21 { "a", TRUE, TRUE, FALSE, FALSE, FALSE },
22 { "A", TRUE, TRUE, FALSE, FALSE, FALSE },
23 { ".", TRUE, TRUE, TRUE, FALSE, FALSE },
24 { "..", TRUE, TRUE, TRUE, FALSE, FALSE },
25 { "...", FALSE, FALSE },
26 { "A ", FALSE, FALSE },
27 { " ", FALSE, FALSE },
28 { " A", TRUE, TRUE, FALSE, FALSE, FALSE },
29 { " A ", FALSE, FALSE },
30 { "A.", FALSE, FALSE },
31 { ".A", FALSE, TRUE, FALSE, FALSE, FALSE },
32 { ".A.", FALSE, FALSE },
33 { "*", TRUE, TRUE, TRUE, FALSE, FALSE },
34 { "?", TRUE, TRUE, TRUE, FALSE, FALSE },
35 { "????????.???", TRUE, TRUE, TRUE, FALSE, FALSE },
36 { "????????????", TRUE, TRUE, TRUE, FALSE, FALSE },
37 { "????????.????", TRUE, TRUE, TRUE, FALSE, FALSE },
38 { "??????????????????", TRUE, TRUE, TRUE, FALSE, FALSE },
39 { "?*?*?*?*?*?*?*?*?*", TRUE, TRUE, TRUE, FALSE, FALSE },
40 { "ABCDEFGHIJKLMNOPQ*", TRUE, TRUE, TRUE, FALSE, FALSE },
41 { "ABCDEFGHI\\*", FALSE, TRUE, TRUE, TRUE, FALSE },
42 { "*\\ABCDEFGHI", FALSE, TRUE, TRUE, TRUE, FALSE },
43 { "?.?.?", TRUE, TRUE, TRUE, FALSE, FALSE },
44 { "?..?", TRUE, TRUE, TRUE, FALSE, FALSE },
45 { "? ", TRUE, FALSE, TRUE, FALSE, FALSE },
46 { " ?", TRUE, TRUE, TRUE, FALSE, FALSE },
47 { "?.", TRUE, FALSE, TRUE, FALSE, FALSE },
48 { ".?", TRUE, TRUE, TRUE, FALSE, FALSE },
49 { "? .?", TRUE, TRUE, TRUE, FALSE, FALSE },
50 { "A?A", TRUE, TRUE, TRUE, FALSE, FALSE },
51 { "A*A", TRUE, TRUE, TRUE, FALSE, FALSE },
52 { "A<A", TRUE, TRUE, TRUE, FALSE, FALSE },
53 { "A>A", TRUE, TRUE, TRUE, FALSE, FALSE },
54 { "A\"A", TRUE, TRUE, TRUE, FALSE, FALSE },
55 { "A'A", TRUE, TRUE, FALSE, FALSE, FALSE },
56 { "A:A", FALSE, FALSE },
57 { "A\x1fG", FALSE, FALSE },
58 { "A\x01G", FALSE, FALSE },
59 { "A\x0aG", FALSE, FALSE },
60 { "A\x0dG", FALSE, FALSE },
61 { "\x7f", TRUE, TRUE, FALSE, FALSE, FALSE },
62 /* FIXME: these two are probably locale-specific */
63 { "\x80", TRUE, TRUE, FALSE, FALSE, FALSE },
64 { "\xff", TRUE, TRUE, FALSE, FALSE, FALSE },
65 { "ABCDEFGH.IJK", TRUE, TRUE, FALSE, FALSE, FALSE },
66 { "ABCDEFGHX.IJK", FALSE, TRUE, FALSE, FALSE, FALSE },
67 { "ABCDEFGHX.IJ", FALSE, TRUE, FALSE, FALSE, FALSE },
68 { "ABCDEFGH.IJKX", FALSE, TRUE, FALSE, FALSE, FALSE },
69 { "ABCDEFG.IJKX", FALSE, TRUE, FALSE, FALSE, FALSE },
70 { "ABCDEFGH", TRUE, TRUE, FALSE, FALSE, FALSE },
71 { "ABCDEFGHX", FALSE, TRUE, FALSE, FALSE, FALSE },
72 { "A.B", TRUE, TRUE, FALSE, FALSE, FALSE },
73 { "A..B", FALSE, TRUE, FALSE, FALSE, FALSE },
74 { "A.B.", FALSE, FALSE },
75 { "A.B.C", FALSE, TRUE, FALSE, FALSE, FALSE },
76 { "A .B", FALSE, TRUE, FALSE, FALSE, FALSE },
77 { " A .B", FALSE, TRUE, FALSE, FALSE, FALSE },
78 { "A. B", TRUE, TRUE, FALSE, FALSE, FALSE },
79 { "A. B ", FALSE, FALSE },
80 { "A. B ", FALSE, FALSE },
81 { " A . B", FALSE, TRUE, FALSE, FALSE, FALSE },
82 { " A . B ", FALSE, FALSE },
83 { "\\ABCDEFGH.IJK", TRUE, TRUE, FALSE, FALSE, TRUE },
84 { "ABCDEFGH.IJK\\", TRUE, TRUE, FALSE, TRUE, FALSE },
85 { "\\ABCDEFGH.IJK\\", TRUE, TRUE, FALSE, TRUE, TRUE },
86 { "\\", TRUE, TRUE, FALSE, FALSE, TRUE },
87 { "\\\\", FALSE, FALSE },
88 { "\\\\B", FALSE, FALSE },
89 { "A\\", TRUE, TRUE, FALSE, TRUE, FALSE },
90 { "A\\B", TRUE, TRUE, FALSE, TRUE, FALSE },
91 { "A\\\\", FALSE, FALSE },
92 { "A\\\\B", FALSE, FALSE },
93 /* We can exceed MAX_PATH (260) characters */
94 { "0BCDEF.HI\\1BCDEF.HI\\2BCDEF.HI\\3BCDEF.HI\\4BCDEF.HI\\5BCDEF.HI\\6BCDEF.HI\\7BCDEF.HI\\8BCDEF.HI\\9BCDEF.HI\\0BCDEF.HI\\1BCDEF.HI\\2BCDEF.HI\\3BCDEF.HI\\4BCDEF.HI\\5BCDEF.HI\\6BCDEF.HI\\7BCDEF.HI\\8BCDEF.HI\\9BCDEF.HI\\0BCDEF.HI\\1BCDEF.HI\\2BCDEF.HI\\3BCDEF.HI\\4BCDEF.HI\\5BCDEF.HI\\6BCDEF.HI", TRUE, TRUE, FALSE, TRUE, FALSE },
95 { "0BCDEF.HI\\1BCDEF.HI\\2BCDEF.HI\\3BCDEF.HI\\4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FGHI1ABCDEFGHI2ABCDEFGHI3ABCDEFGHI4ABCDEFGHI5ABCDEFGHI6ABCDEFGHI7ABCDEFGHI8ABCDEFGHI9ABCDEFGHI0ABCDEFGHI1ABCDEFGHI2ABCDEFGHI3ABCDEFGHI4ABCDEFGHI5ABCDEF", FALSE, FALSE },
100 { "ABCDEFGHI1ABCDEFGHI2ABCDEFGHI3ABCDEFGHI4ABCDEFGHI5ABCDEFGHI6ABCDEFGHI7ABCDEFGHI8ABCDEFGHI9ABCDEFGHI0ABCDEFGHI1ABCDEFGHI2ABCDEFGHI3ABCDEFGHI4ABCDEFGHI5ABCDEFGHI6ABCDEFGHI7ABCDEFGHI8ABCDEFGHI9ABCDEFGHI0ABCDEFGHI1ABCDEFGHI2ABCDEFGHI3ABCDEFGHI4ABCDEFGHI5ABCDE\\ABC", FALSE, TRUE, FALSE, TRUE, FALSE },
101 };
102
103 START_TEST(FsRtlLegal)
104 {
105 ULONG i;
106 BOOLEAN Result;
107 ANSI_STRING DbcsName;
108 ULONG Flags;
109
110 for (i = 0; i < RTL_NUMBER_OF(Tests); i++)
111 {
112 RtlInitAnsiString(&DbcsName, Tests[i].Dbcs);
113 for (Flags = 0; Flags < 8; Flags++)
114 {
115 Result = FsRtlIsFatDbcsLegal(DbcsName,
116 BooleanFlagOn(Flags, 1),
117 BooleanFlagOn(Flags, 2),
118 BooleanFlagOn(Flags, 4));
119 if (Tests[i].HasWildCards && !FlagOn(Flags, 1))
120 ok(Result == FALSE, "[%s] Result = %u but has wildcards\n", Tests[i].Dbcs, Result);
121 else if (Tests[i].IsPath && !FlagOn(Flags, 2))
122 ok(Result == FALSE, "[%s] Result = %u but is path\n", Tests[i].Dbcs, Result);
123 else if (Tests[i].LeadingBackslash && !FlagOn(Flags, 4))
124 ok(Result == FALSE, "[%s] Result = %u but has leading backslash\n", Tests[i].Dbcs, Result);
125 else if (!Tests[i].LegalFat)
126 ok(Result == FALSE, "[%s] Result = %u but is NOT legal FAT\n", Tests[i].Dbcs, Result);
127 else
128 ok(Result == TRUE, "[%s] Result = %u but IS legal FAT\n", Tests[i].Dbcs, Result);
129
130 Result = FsRtlIsHpfsDbcsLegal(DbcsName,
131 BooleanFlagOn(Flags, 1),
132 BooleanFlagOn(Flags, 2),
133 BooleanFlagOn(Flags, 4));
134 if (Tests[i].HasWildCards && !FlagOn(Flags, 1))
135 ok(Result == FALSE, "[%s] Result = %u but has wildcards\n", Tests[i].Dbcs, Result);
136 else if (Tests[i].IsPath && !FlagOn(Flags, 2))
137 ok(Result == FALSE, "[%s] Result = %u but is path\n", Tests[i].Dbcs, Result);
138 else if (Tests[i].LeadingBackslash && !FlagOn(Flags, 4))
139 ok(Result == FALSE, "[%s] Result = %u but has leading backslash\n", Tests[i].Dbcs, Result);
140 else if (!Tests[i].LegalHpfs)
141 ok(Result == FALSE, "[%s] Result = %u but is NOT legal HPFS\n", Tests[i].Dbcs, Result);
142 else
143 ok(Result == TRUE, "[%s] Result = %u but IS legal HPFS\n", Tests[i].Dbcs, Result);
144 }
145 }
146 }