6e92529eb14a44f4c61faed5c600c8faaa541c36
[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_LongTests(void)
17 {
18 UCHAR i = 0;
19 HANDLE hFile;
20 CHAR TestDir[] = "XTestDirTunnelCache";
21 CHAR OldDir[MAX_PATH];
22 FILETIME FileTime, File1Time;
23
24 /* Create a blank test directory */
25 if (GetCurrentDirectory(MAX_PATH, OldDir) == 0)
26 {
27 win_skip("No test directory available\n");
28 return;
29 }
30
31 /* Create a blank test directory */
32 for (; i < 10; ++i)
33 {
34 TestDir[0] = '0' + i;
35 if (CreateDirectory(TestDir, NULL))
36 {
37 if (SetCurrentDirectory(TestDir) == 0)
38 {
39 RemoveDirectory(TestDir);
40 win_skip("No test directory available\n");
41 return;
42 }
43
44 break;
45 }
46 }
47
48 if (i == 10)
49 {
50 win_skip("No test directory available\n");
51 return;
52 }
53
54 hFile = CreateFile("file1",
55 GENERIC_READ | GENERIC_WRITE,
56 0, NULL,
57 CREATE_NEW,
58 FILE_ATTRIBUTE_NORMAL,
59 NULL);
60 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
61 ok(GetFileTime(hFile, &FileTime, NULL, NULL) != FALSE, "GetFileTime() failed\n");
62 CloseHandle(hFile);
63
64 /* Wait a least 10ms (resolution of FAT) */
65 /* XXX: Increased to 1s for ReactOS... */
66 Sleep(1000);
67
68 hFile = CreateFile("file2",
69 GENERIC_READ | GENERIC_WRITE,
70 0, NULL,
71 CREATE_NEW,
72 FILE_ATTRIBUTE_NORMAL,
73 NULL);
74 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
75 CloseHandle(hFile);
76
77 ok(MoveFile("file1", "file") != FALSE, "MoveFile() failed\n");
78 ok(MoveFile("file2", "file1") != FALSE, "MoveFile() failed\n");
79
80 hFile = CreateFile("file1",
81 GENERIC_READ,
82 0, NULL,
83 OPEN_EXISTING,
84 FILE_ATTRIBUTE_NORMAL,
85 NULL);
86 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
87 ok(GetFileTime(hFile, &File1Time, NULL, NULL) != FALSE, "GetFileTime() failed\n");
88 CloseHandle(hFile);
89
90 ok(RtlCompareMemory(&FileTime, &File1Time, sizeof(FILETIME)) == sizeof(FILETIME), "Tunnel cache failed\n");
91
92 DeleteFile("file2");
93 DeleteFile("file1");
94 DeleteFile("file");
95
96 SetCurrentDirectory(OldDir);
97 RemoveDirectory(TestDir);
98 }
99
100 static
101 void
102 Test_ShortTests(void)
103 {
104 UCHAR i = 0;
105 CHAR ShortName[14];
106 HANDLE hFile, hFind;
107 WIN32_FIND_DATA FileInfo;
108 CHAR TestDir[] = "XTestDirTunnelCache";
109 CHAR OldDir[MAX_PATH];
110
111 /* Create a blank test directory */
112 if (GetCurrentDirectory(MAX_PATH, OldDir) == 0)
113 {
114 win_skip("No test directory available\n");
115 return;
116 }
117
118 /* Create a blank test directory */
119 for (; i < 10; ++i)
120 {
121 TestDir[0] = '0' + i;
122 if (CreateDirectory(TestDir, NULL))
123 {
124 if (SetCurrentDirectory(TestDir) == 0)
125 {
126 RemoveDirectory(TestDir);
127 win_skip("No test directory available\n");
128 return;
129 }
130
131 break;
132 }
133 }
134
135 if (i == 10)
136 {
137 win_skip("No test directory available\n");
138 return;
139 }
140
141 hFile = CreateFile("verylongfilename",
142 GENERIC_READ | GENERIC_WRITE,
143 0, NULL,
144 CREATE_NEW,
145 FILE_ATTRIBUTE_NORMAL,
146 NULL);
147 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile() failed\n");
148 CloseHandle(hFile);
149
150 hFind = FindFirstFile("verylongfilename", &FileInfo);
151 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
152 FindClose(hFind);
153 RtlCopyMemory(ShortName, FileInfo.cAlternateFileName, sizeof(ShortName));
154
155 ok(MoveFile("verylongfilename", "verylongfilename2") != FALSE, "MoveFile() failed\n");
156 hFind = FindFirstFile("verylongfilename2", &FileInfo);
157 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
158 FindClose(hFind);
159 ok(strcmp(FileInfo.cAlternateFileName, ShortName) == 0, "strcmp() failed\n");
160
161 hFile = CreateFile("randomfilename",
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(MoveFileEx("randomfilename", "verylongfilename2", MOVEFILE_REPLACE_EXISTING) != FALSE, "MoveFile() failed\n");
171 hFind = FindFirstFile("verylongfilename2", &FileInfo);
172 ok(hFind != INVALID_HANDLE_VALUE, "FindFirstFile() failed\n");
173 FindClose(hFind);
174 ok(strcmp(FileInfo.cAlternateFileName, ShortName) == 0, "strcmp() failed\n");
175
176 DeleteFile("randomfilename");
177 DeleteFile("verylongfilename");
178 DeleteFile("verylongfilename2");
179
180 SetCurrentDirectory(OldDir);
181 RemoveDirectory(TestDir);
182 }
183
184 START_TEST(TunnelCache)
185 {
186 Test_ShortTests();
187 Test_LongTests();
188 }