4 * PURPOSE: A test set for the File System Driver
5 * PROJECT: ReactOS kernel
6 * COPYRIGHT: See COPYING in the top level directory
7 * PROGRAMMER: Rex Jolliff (rex@lvcablemodem.com)
16 #include "testsuite.h"
18 const char *rootDir = "c:\\";
19 const char *systemRootDir = "c:\\ReactOS";
20 const char *systemDllDir = "c:\\ReactOS\\System32";
21 const char *bogusRootFile = "c:\\bogus";
22 const char *bogusDirAndFile = "c:\\bogus\\bogus";
23 const char *bogusSystemRootFile = "c:\\ReactOS\\bogus";
24 const char *bogusSystemDllFile = "c:\\ReactOS\\System32\\bogus";
25 const char *shortFile = "c:\\ReactOS\\boot.bat";
26 const char *longFile = "c:\\ReactOS\\loadros.com";
28 void testOpenExistant (void)
32 fileHandle = CreateFile (rootDir, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
33 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
34 CloseHandle (fileHandle);
35 fileHandle = CreateFile (systemRootDir, GENERIC_READ, 0, 0,
37 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
38 CloseHandle (fileHandle);
39 fileHandle = CreateFile (systemDllDir, GENERIC_READ, 0, 0,
41 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
42 CloseHandle (fileHandle);
45 void testOpenNonExistant (void)
50 fileHandle = CreateFile (bogusRootFile, GENERIC_READ, 0, 0,
52 ASSERT (fileHandle == INVALID_HANDLE_VALUE);
53 status = GetLastError ();
54 ASSERT (status == ERROR_FILE_NOT_FOUND);
55 CloseHandle (fileHandle);
56 fileHandle = CreateFile (bogusDirAndFile, GENERIC_READ, 0, 0,
58 ASSERT (fileHandle == INVALID_HANDLE_VALUE);
59 status = GetLastError ();
60 ASSERT (status == ERROR_PATH_NOT_FOUND);
61 CloseHandle (fileHandle);
62 fileHandle = CreateFile (bogusSystemRootFile, GENERIC_READ, 0, 0,
64 ASSERT (fileHandle == INVALID_HANDLE_VALUE);
65 status = GetLastError ();
66 ASSERT (status == ERROR_FILE_NOT_FOUND);
67 CloseHandle (fileHandle);
68 fileHandle = CreateFile (bogusSystemDllFile, GENERIC_READ, 0, 0,
70 ASSERT (fileHandle == INVALID_HANDLE_VALUE);
71 status = GetLastError ();
72 ASSERT (status == ERROR_FILE_NOT_FOUND);
73 CloseHandle (fileHandle);
76 void testCreateExistant (void)
81 fileHandle = CreateFile (rootDir, GENERIC_READ, 0, 0,
83 ASSERT (fileHandle == INVALID_HANDLE_VALUE);
84 status = GetLastError ();
85 ASSERT (status == ERROR_ALREADY_EXISTS);
86 fileHandle = CreateFile (systemRootDir, GENERIC_READ, 0, 0,
88 ASSERT (fileHandle == INVALID_HANDLE_VALUE);
89 status = GetLastError ();
90 ASSERT (status == ERROR_ALREADY_EXISTS);
91 fileHandle = CreateFile (systemDllDir, GENERIC_READ, 0, 0,
93 ASSERT (fileHandle == INVALID_HANDLE_VALUE);
94 status = GetLastError ();
95 ASSERT (status == ERROR_ALREADY_EXISTS);
98 void testCreateNonExistant (void)
103 fileHandle = CreateFile (bogusRootFile, GENERIC_READ, 0, 0,
105 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
106 CloseHandle (fileHandle);
107 fileHandle = CreateFile (bogusSystemRootFile, GENERIC_READ, 0, 0,
109 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
110 CloseHandle (fileHandle);
111 fileHandle = CreateFile (bogusSystemDllFile, GENERIC_READ, 0, 0,
113 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
114 CloseHandle (fileHandle);
116 fileHandle = CreateFile (bogusDirAndFile, GENERIC_READ, 0, 0,
118 ASSERT (fileHandle == INVALID_HANDLE_VALUE);
119 status = GetLastError ();
120 ASSERT (status == ERROR_PATH_NOT_FOUND);
121 CloseHandle (fileHandle);
125 void testDeleteFiles (void)
130 fileHandle = CreateFile ("bogus", GENERIC_READ, 0, 0,
132 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
133 CloseHandle (fileHandle);
134 returnValue = DeleteFile ("bogus");
135 ASSERT_MSG (returnValue,
136 "Delete of bogus failed, error:%d",
140 returnValue = DeleteFile (bogusRootFile);
141 ASSERT_MSG (returnValue,
142 "Delete of %s failed, error:%d",
145 returnValue = DeleteFile (bogusRootFile);
146 ASSERT_MSG (!returnValue,
147 "2nd Delete of %s succeeded but should fail",
149 returnValue = DeleteFile (bogusSystemRootFile);
150 ASSERT_MSG (returnValue,
151 "Delete of %s failed, error:%d",
154 returnValue = DeleteFile (bogusSystemRootFile);
155 ASSERT_MSG (!returnValue,
156 "2nd Delete of %s succeeded but should fail",
157 bogusSystemRootFile);
158 returnValue = DeleteFile (bogusSystemDllFile);
159 ASSERT_MSG (returnValue,
160 "Delete of %s failed, error:%d",
163 returnValue = DeleteFile (bogusSystemDllFile);
164 ASSERT_MSG (!returnValue,
165 "2nd Delete of %s succeeded but should fail",
167 returnValue = DeleteFile (bogusDirAndFile);
168 ASSERT_MSG (!returnValue,
169 "Delete of %s succeded but should fail",
174 void testOpenWithBlankPathElements (void)
178 fileHandle = CreateFile ("c:", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
179 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
180 CloseHandle (fileHandle);
181 fileHandle = CreateFile ("c:\\\\", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
182 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
183 CloseHandle (fileHandle);
184 fileHandle = CreateFile ("c:\\\\reactos\\", GENERIC_READ, 0, 0,
185 OPEN_EXISTING, 0, 0);
186 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
187 CloseHandle (fileHandle);
188 fileHandle = CreateFile ("c:\\reactos\\\\", GENERIC_READ, 0, 0,
189 OPEN_EXISTING, 0, 0);
190 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
191 CloseHandle (fileHandle);
192 fileHandle = CreateFile ("c:\\reactos\\\\system32\\", GENERIC_READ, 0, 0,
193 OPEN_EXISTING, 0, 0);
194 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
195 CloseHandle (fileHandle);
196 fileHandle = CreateFile ("c:\\reactos\\system32\\\\", GENERIC_READ, 0, 0,
197 OPEN_EXISTING, 0, 0);
198 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
199 CloseHandle (fileHandle);
202 void testReadOnInvalidHandle (void)
208 returnValue = ReadFile (INVALID_HANDLE_VALUE,
213 ASSERT_MSG (!returnValue,
214 "Read from invalid handle succeeded but should fail",0);
215 ASSERT (GetLastError () != ENOFILE);
218 void testReadOnZeroLengthFile (void)
225 fileHandle = CreateFile (bogusRootFile, GENERIC_READ, 0, 0,
227 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
228 CloseHandle (fileHandle);
229 fileHandle = CreateFile (bogusRootFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
230 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
231 returnValue = ReadFile (fileHandle, buffer, 256, &bytesRead, NULL);
232 ASSERT_MSG (!returnValue,
233 "Read from zero length file succeeded but should fail",0);
234 ASSERT (GetLastError () != ERROR_HANDLE_EOF);
235 CloseHandle (fileHandle);
236 returnValue = DeleteFile (bogusRootFile);
237 ASSERT_MSG (returnValue,
238 "Delete of %s failed, error:%d",
243 void testReadOnShortFile (void)
250 fileHandle = CreateFile (shortFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
251 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
252 returnValue = ReadFile (fileHandle,
257 ASSERT_MSG (returnValue,
258 "Read from short length file failed, error:%d",
260 ASSERT (bytesRead > 0 && bytesRead < 256);
261 CloseHandle (fileHandle);
264 void testReadOnLongFile (void)
272 fileHandle = CreateFile (longFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
273 ASSERT (fileHandle != INVALID_HANDLE_VALUE);
274 for (count = 0; count < 20; count++)
276 returnValue = ReadFile (fileHandle,
281 ASSERT_MSG (returnValue,
282 "Read from short length file failed, error:%d",
284 ASSERT (bytesRead == 256);
286 CloseHandle (fileHandle);
291 TEST_RUNNER testRunner;
292 TEST_SUITE testsToRun [] =
294 ADD_TEST (testOpenExistant),
295 ADD_TEST (testOpenNonExistant),
296 ADD_TEST (testCreateExistant),
297 ADD_TEST (testCreateNonExistant),
298 ADD_TEST (testDeleteFiles),
299 /* ADD_TEST (testOverwriteExistant),*/
300 /* ADD_TEST (testOverwriteNonExistant),*/
301 ADD_TEST (testOpenWithBlankPathElements),
302 ADD_TEST (testReadOnInvalidHandle),
303 ADD_TEST (testReadOnZeroLengthFile),
304 ADD_TEST (testReadOnShortFile),
305 ADD_TEST (testReadOnLongFile),
306 /* ADD_TEST (test), */
310 memset (&testRunner, 0, sizeof (TEST_RUNNER));
311 tsRunTests (&testRunner, testsToRun);
312 tsReportResults (&testRunner);