[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / kernel32 / TunnelCache.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Tests for Tunnel Cache
5 * PROGRAMMER: Pierre Schweitzer <pierre.schweitzer@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <stdio.h>
12 #include <ndk/rtlfuncs.h>
13
14 static
15 void
16 Test_VeryLongTests(void)
17 {
18 UCHAR i = 0;
19 HANDLE hFile;
20 CHAR TestDir[] = "XTestDirTunnelCache";
21 CHAR OldDir[MAX_PATH];
22 FILETIME FileTime, File1Time;
23
24 win_skip("Too long, see: ROSTESTS-177");
25 return;
26
27 /* Create a blank test directory */
28 if (GetCurrentDirectory(MAX_PATH, OldDir) == 0)
29 {
30 win_skip("No test directory available\n");
31 return;
32 }
33
34 /* Create a blank test directory */
35 for (; i < 10; ++i)
36 {
37 TestDir[0] = '0' + i;
38 if (CreateDirectory(TestDir, NULL))
39 {
40 if (SetCurrentDirectory(TestDir) == 0)
41 {
42 RemoveDirectory(TestDir);
43 win_skip("No test directory available\n");
44 return;
45 }
46
47 break;
48 }
49 }
50
51 if (i == 10)
52 {
53 win_skip("No test directory available\n");
54 return;
55 }
56
57 hFile = CreateFile("file1",
58 GENERIC_READ | GENERIC_WRITE,
59 0, NULL,
60 CREATE_NEW,
61 FILE_ATTRIBUTE_NORMAL,
62 NULL);
63 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
64 ok(GetFileTime(hFile, &FileTime, NULL, NULL) != FALSE, "GetFileTime() failed\n");
65 CloseHandle(hFile);
66
67 /* Wait a least 10ms (resolution of FAT) */
68 /* XXX: Increased to 1s for ReactOS... */
69 Sleep(1000);
70
71 hFile = CreateFile("file2",
72 GENERIC_READ | GENERIC_WRITE,
73 0, NULL,
74 CREATE_NEW,
75 FILE_ATTRIBUTE_NORMAL,
76 NULL);
77 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
78 CloseHandle(hFile);
79
80 ok(MoveFile("file1", "file") != FALSE, "MoveFile() failed\n");
81 /* Sleep over cache expiry */
82 /* FIXME: Query correct value from registry if it exists:
83 * \HKLM\System\CurrentControlSet\Control\FileSystem\MaximumTunnelEntryAgeInSeconds */
84 Sleep(16000);
85 ok(MoveFile("file2", "file1") != FALSE, "MoveFile() failed\n");
86
87 hFile = CreateFile("file1",
88 GENERIC_READ,
89 0, NULL,
90 OPEN_EXISTING,
91 FILE_ATTRIBUTE_NORMAL,
92 NULL);
93 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
94 ok(GetFileTime(hFile, &File1Time, NULL, NULL) != FALSE, "GetFileTime() failed\n");
95 CloseHandle(hFile);
96
97 ok(RtlCompareMemory(&FileTime, &File1Time, sizeof(FILETIME)) != sizeof(FILETIME), "Tunnel cache still in action?\n");
98
99 DeleteFile("file2");
100 DeleteFile("file1");
101 DeleteFile("file");
102
103 SetCurrentDirectory(OldDir);
104 RemoveDirectory(TestDir);
105 }
106
107 static
108 void
109 Test_LongTests(void)
110 {
111 UCHAR i = 0;
112 HANDLE hFile;
113 CHAR TestDir[] = "XTestDirTunnelCache";
114 CHAR OldDir[MAX_PATH];
115 FILETIME FileTime, File1Time;
116
117 /* Create a blank test directory */
118 if (GetCurrentDirectory(MAX_PATH, OldDir) == 0)
119 {
120 win_skip("No test directory available\n");
121 return;
122 }
123
124 /* Create a blank test directory */
125 for (; i < 10; ++i)
126 {
127 TestDir[0] = '0' + i;
128 if (CreateDirectory(TestDir, NULL))
129 {
130 if (SetCurrentDirectory(TestDir) == 0)
131 {
132 RemoveDirectory(TestDir);
133 win_skip("No test directory available\n");
134 return;
135 }
136
137 break;
138 }
139 }
140
141 if (i == 10)
142 {
143 win_skip("No test directory available\n");
144 return;
145 }
146
147 hFile = CreateFile("file1",
148 GENERIC_READ | GENERIC_WRITE,
149 0, NULL,
150 CREATE_NEW,
151 FILE_ATTRIBUTE_NORMAL,
152 NULL);
153 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
154 ok(GetFileTime(hFile, &FileTime, NULL, NULL) != FALSE, "GetFileTime() failed\n");
155 CloseHandle(hFile);
156
157 /* Wait a least 10ms (resolution of FAT) */
158 /* XXX: Increased to 1s for ReactOS... */
159 Sleep(1000);
160
161 hFile = CreateFile("file2",
162 GENERIC_READ | GENERIC_WRITE,
163 0, NULL,
164 CREATE_NEW,
165 FILE_ATTRIBUTE_NORMAL,
166 NULL);
167 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
168 CloseHandle(hFile);
169
170 ok(MoveFile("file1", "file") != FALSE, "MoveFile() failed\n");
171 ok(MoveFile("file2", "file1") != FALSE, "MoveFile() failed\n");
172
173 hFile = CreateFile("file1",
174 GENERIC_READ,
175 0, NULL,
176 OPEN_EXISTING,
177 FILE_ATTRIBUTE_NORMAL,
178 NULL);
179 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
180 ok(GetFileTime(hFile, &File1Time, NULL, NULL) != FALSE, "GetFileTime() failed\n");
181 CloseHandle(hFile);
182
183 ok(RtlCompareMemory(&FileTime, &File1Time, sizeof(FILETIME)) == sizeof(FILETIME), "Tunnel cache failed\n");
184
185 DeleteFile("file2");
186 DeleteFile("file1");
187 DeleteFile("file");
188
189 SetCurrentDirectory(OldDir);
190 RemoveDirectory(TestDir);
191 }
192
193 static
194 void
195 Test_ShortTests(void)
196 {
197 UCHAR i = 0;
198 CHAR ShortName[14];
199 HANDLE hFile, hFind;
200 WIN32_FIND_DATA FileInfo;
201 CHAR TestDir[] = "XTestDirTunnelCache";
202 CHAR OldDir[MAX_PATH];
203
204 /* Create a blank test directory */
205 if (GetCurrentDirectory(MAX_PATH, OldDir) == 0)
206 {
207 win_skip("No test directory available\n");
208 return;
209 }
210
211 /* Create a blank test directory */
212 for (; i < 10; ++i)
213 {
214 TestDir[0] = '0' + i;
215 if (CreateDirectory(TestDir, NULL))
216 {
217 if (SetCurrentDirectory(TestDir) == 0)
218 {
219 RemoveDirectory(TestDir);
220 win_skip("No test directory available\n");
221 return;
222 }
223
224 break;
225 }
226 }
227
228 if (i == 10)
229 {
230 win_skip("No test directory available\n");
231 return;
232 }
233
234 hFile = CreateFile("verylongfilename",
235 GENERIC_READ | GENERIC_WRITE,
236 0, NULL,
237 CREATE_NEW,
238 FILE_ATTRIBUTE_NORMAL,
239 NULL);
240 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
241 CloseHandle(hFile);
242
243 hFind = FindFirstFile("verylongfilename", &FileInfo);
244 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
245 FindClose(hFind);
246 RtlCopyMemory(ShortName, FileInfo.cAlternateFileName, sizeof(ShortName));
247
248 ok(MoveFile("verylongfilename", "verylongfilename2") != FALSE, "MoveFile() failed\n");
249 hFind = FindFirstFile("verylongfilename2", &FileInfo);
250 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
251 FindClose(hFind);
252 ok(strcmp(FileInfo.cAlternateFileName, ShortName) == 0, "strcmp() failed\n");
253
254 hFile = CreateFile("randomfilename",
255 GENERIC_READ | GENERIC_WRITE,
256 0, NULL,
257 CREATE_NEW,
258 FILE_ATTRIBUTE_NORMAL,
259 NULL);
260 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
261 CloseHandle(hFile);
262
263 ok(MoveFileEx("randomfilename", "verylongfilename2", MOVEFILE_REPLACE_EXISTING) != FALSE, "MoveFile() failed\n");
264 hFind = FindFirstFile("verylongfilename2", &FileInfo);
265 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
266 FindClose(hFind);
267 ok(strcmp(FileInfo.cAlternateFileName, ShortName) == 0, "strcmp() failed\n");
268
269 DeleteFile("randomfilename");
270 DeleteFile("verylongfilename");
271 DeleteFile("verylongfilename2");
272
273 SetCurrentDirectory(OldDir);
274 RemoveDirectory(TestDir);
275 }
276
277 START_TEST(TunnelCache)
278 {
279 Test_ShortTests();
280 Test_LongTests();
281 Test_VeryLongTests();
282 }