[KMTESTS:KE]
[reactos.git] / rostests / kmtests / ntos_fsrtl / FsRtlTunnel.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite FsRtl Test
5 * PROGRAMMER: Ashuha Arseny, Moscow State Technical University
6 * Marina Volosnikova, Moscow State Technical University
7 * Denis Petkevich, Moscow State Technical University
8 */
9
10 #include <kmt_test.h>
11
12 #define NDEBUG
13 #include <debug.h>
14
15 /*
16 Tested with the system kmtest
17 the following functions:
18 FsRtlInitializeTunnelCache
19 FsRtlDeleteTunnelCache
20 FsRtlAddToTunnelCache
21 FsRtlDeleteKeyFromTunnelCache
22 FsRtlFindInTunnelCache
23 */
24
25 static PTUNNEL T;
26 static PTUNNEL Tb;
27
28 #define BufSize 10000
29
30 PUNICODE_STRING CopyUS(PUNICODE_STRING a)
31 {
32 PUNICODE_STRING b = (PUNICODE_STRING)ExAllocatePool(PagedPool,sizeof(UNICODE_STRING));
33 ok(b != NULL, "US is NULL after allocated memory\n");
34 b->Length = 0;
35 b->MaximumLength =a->MaximumLength;
36 b->Buffer = (PWSTR)ExAllocatePoolWithTag(PagedPool, b->MaximumLength, 1633);
37 ok(b->Buffer != NULL, "US->Buffer is NULL after allocated memory\n");
38 RtlCopyUnicodeString(b, a);
39 return b;
40 }
41
42 void TestFsRtlInitializeTunnelCache()
43 {
44 SIZE_T eq;
45 T = ExAllocatePool(PagedPool, sizeof(TUNNEL));
46 ok(T != NULL, "PTUNEL is NULL after allocated memory\n");
47 Tb = ExAllocatePool(PagedPool, sizeof(TUNNEL));
48 ok(Tb != NULL, "PTUNEL is NULL after allocated memory\n");
49
50 memset((void*)T, 0, sizeof(TUNNEL));
51 memset((void*)Tb, 0, sizeof(TUNNEL));
52
53 FsRtlInitializeTunnelCache(T);
54
55 eq = RtlCompareMemory((const VOID*)T, (const VOID*)Tb, sizeof(TUNNEL));
56
57 ok ( eq != sizeof(TUNNEL), "FsRtlInitializeTunnelCache function did not change anything in the memory at the address PTUNEL.\n");
58 }
59
60 void TestFsRtlAddToTunnelCache(ULONGLONG DirectoryKey, PUNICODE_STRING s_name, PUNICODE_STRING l_name, BOOLEAN KeyByShortName)
61 {
62 SIZE_T eq;
63 LONG b;
64 PUNICODE_STRING bs_name;
65 PUNICODE_STRING bl_name;
66 PVOID Bufb;
67 PVOID Buf;
68
69 Buf = ExAllocatePool(PagedPool, BufSize);
70 ok(Buf != NULL, "Buff in TestFsRtlAddToTunnelCache is NULL after allocated memory\n");
71 Bufb = ExAllocatePool(PagedPool, BufSize);
72 ok(Bufb != NULL, "Buff in TestFsRtlAddToTunnelCache is NULL after allocated memory\n");
73
74 // Allocate memory for the bufs_name
75 bs_name = CopyUS(s_name);
76
77 // Allocate memory for the l_name and bl_name
78 bl_name = CopyUS(l_name);
79
80 memset((void*)Buf, 0, BufSize);
81 memset((void*)Bufb, 0, BufSize);
82
83 FsRtlAddToTunnelCache(T, DirectoryKey, s_name, l_name, KeyByShortName, BufSize, Buf);
84
85 eq = RtlCompareMemory((const VOID*)Buf, (const VOID*)Bufb, BufSize);
86
87 ok( eq != sizeof(TUNNEL),"FsRtlAddToTunnelCache function did not change anything in the memory at the address Buf.\n");
88
89 b = RtlCompareUnicodeString(l_name, bl_name, TRUE);
90 ok (b == 0, "long name after call FsRtlAddToTunnelCache != long name befo call FsRtlAddToTunnelCache\n\n");
91 b = RtlCompareUnicodeString(s_name, bs_name, TRUE);
92 ok (b == 0, "short name after call FsRtlAddToTunnelCache != short name befo call FsRtlAddToTunnelCache\n\n");
93 }
94
95 BOOLEAN TestFsRtlFindInTunnelCache(ULONG DirectoryKey, PUNICODE_STRING name, PUNICODE_STRING s_name, PUNICODE_STRING l_name)
96 {
97 // Allocate memory for the Buf
98 ULONG BufsizeTemp = BufSize;
99 PVOID Buf = ExAllocatePool(PagedPool, BufSize*2);
100 ok(Buf != NULL, "Buff in FsRtlFindInTunnelCache is NULL after allocated memory\n");
101
102 return FsRtlFindInTunnelCache(T, DirectoryKey, name, s_name, l_name, &BufsizeTemp, Buf);
103 }
104
105 void TestFsRtlDeleteKeyFromTunnelCache(ULONGLONG a)
106 {
107 FsRtlDeleteKeyFromTunnelCache(T, a);
108 }
109
110 START_TEST(FsRtlTunnel)
111 {
112 PUNICODE_STRING s_name;
113 PUNICODE_STRING l_name;
114 PUNICODE_STRING name;
115 PUNICODE_STRING a;
116 BOOLEAN is;
117
118 //Initialize Cash
119 TestFsRtlInitializeTunnelCache();
120
121 s_name = (PUNICODE_STRING)ExAllocatePool(PagedPool,sizeof(UNICODE_STRING));
122 ok(s_name != NULL, "s_name in TestFsRtlAddToTunnelCache is NULL after allocated memory\n");
123 RtlInitUnicodeString(s_name, L"smal");
124
125 l_name = (PUNICODE_STRING)ExAllocatePool(PagedPool,sizeof(UNICODE_STRING));
126 ok(l_name != NULL, "l_name in TestFsRtlAddToTunnelCache is NULL after allocated memory\n");
127 RtlInitUnicodeString(l_name, L"bigbigbigbigbig");
128
129 // Add elem
130 TestFsRtlAddToTunnelCache(12345, s_name, l_name, TRUE);
131
132 name = (PUNICODE_STRING)ExAllocatePool(PagedPool,sizeof(UNICODE_STRING));
133 ok(name != NULL, "name in FsRtlFindInTunnelCache is NULL after allocated memory\n");
134 RtlInitUnicodeString(name, L"smal");
135
136 // Find
137 is = TestFsRtlFindInTunnelCache(12345, name, s_name, l_name);
138 ok(is == TRUE, "FsRtlFindInTunnelCache dosn't find elem id = 12345\n");
139
140 TestFsRtlDeleteKeyFromTunnelCache(12345); //Delete
141 is = TestFsRtlFindInTunnelCache(12345, name, s_name, l_name);
142 ok(is == FALSE, "TestFsRtlDeleteKeyFromTunnelCache dosn't delete elem id = 12345\n");
143
144 is = TestFsRtlFindInTunnelCache(12347, name, s_name, l_name);
145 ok(is == FALSE, "FsRtlDeleteTunnelCache dosn't clear cash\n");
146
147 TestFsRtlAddToTunnelCache(12345, s_name, l_name, TRUE);
148 TestFsRtlAddToTunnelCache(12347, s_name, l_name, TRUE);
149 a = (PUNICODE_STRING)ExAllocatePool(PagedPool,sizeof(UNICODE_STRING));
150 TestFsRtlAddToTunnelCache(12346, a, l_name, FALSE);
151
152 //Clear all
153 FsRtlDeleteTunnelCache(T);
154
155 is = TestFsRtlFindInTunnelCache(12345, name, s_name, l_name);
156 ok(is == FALSE, "FsRtlDeleteTunnelCache dosn't clear cash\n");
157
158 is = TestFsRtlFindInTunnelCache(12346, name, a, l_name);
159 ok(is == FALSE, "FsRtlDeleteTunnelCache dosn't clear cash\n");
160
161 is = TestFsRtlFindInTunnelCache(12347, name, s_name, l_name);
162 ok(is == FALSE, "FsRtlDeleteTunnelCache dosn't clear cash\n");
163 }