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