1 /* This FileX test concentrates on the unicode file rename operations. */
2
3 #ifndef FX_STANDALONE_ENABLE
4 #include "tx_api.h"
5 #endif
6 #include "fx_api.h"
7 #include "fx_ram_driver_test.h"
8 #include <stdio.h>
9
10 #define DEMO_STACK_SIZE 8192
11 #define CACHE_SIZE 16*128
12
13 /* Define the ThreadX and FileX object control blocks... */
14
15 #ifndef FX_STANDALONE_ENABLE
16 static TX_THREAD ftest_0;
17 #endif
18 static FX_MEDIA ram_disk;
19
20
21 /* Define the counters used in the test application... */
22
23 #ifndef FX_STANDALONE_ENABLE
24 static UCHAR *ram_disk_memory;
25 static UCHAR *cache_buffer;
26 #else
27 static UCHAR cache_buffer[CACHE_SIZE];
28 #endif
29 /* Notice that old_file_name is the same as new_file_name1. */
30 static UCHAR old_file_name[] = {3, 0, 4, 0, 5, 0, 6, 0, 0, 0};
31 static UCHAR new_file_name1[] = {3, 0, 4, 0, 5, 0, 6, 0, 0, 0};
32 static UCHAR new_file_name2[] = {3, 0, 4, 0, 5, 0, 0, 0};
33 static UCHAR new_file_name3[] = {3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 0, 0};
34 static UCHAR new_file_name4[] = {2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 0, 0};
35 static UCHAR new_file_name5[] = {'a', 0, 'b', 0, 'c', 0, 0, 0};
36 static UCHAR new_file_name5_bak[] = {'a', 0, 'b', 0, 'c', 0, 0, 0};
37 static UCHAR new_file_name6[] = {'a', 0, 'y', 0, 'c', 0, 0, 0};
38 static UCHAR new_file_name7[] = {'a', 1, 'z', 0, 'c', 0, 0, 0};
39 static UCHAR new_file_name8[] = {'z' + 1, 0, 'z', 0, 'c', 0, 'd', 0, 0, 0};
40 static UCHAR new_file_name9[] = {'z' + 1, 1, 'z', 0, 'c', 0, 'd', 0, 0, 0};
41 static UCHAR destination_name[100];
42
43 #define TEST_COUNT 3
44
45 /* Define thread prototypes. */
46
47 void filex_unicode_file_rename_application_define(void *first_unused_memory);
48 static void ftest_0_entry(ULONG thread_input);
49
50 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
51 void test_control_return(UINT status);
52
53
54
55 /* Define what the initial system looks like. */
56
57 #ifdef CTEST
test_application_define(void * first_unused_memory)58 void test_application_define(void *first_unused_memory)
59 #else
60 void filex_unicode_file_rename_application_define(void *first_unused_memory)
61 #endif
62 {
63
64 #ifndef FX_STANDALONE_ENABLE
65 UCHAR *pointer;
66
67
68 /* Setup the working pointer. */
69 pointer = (UCHAR *) first_unused_memory;
70
71 /* Create the main thread. */
72 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
73 pointer, DEMO_STACK_SIZE,
74 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
75
76 pointer = pointer + DEMO_STACK_SIZE;
77
78 /* Setup memory for the RAM disk and the sector cache. */
79 cache_buffer = pointer;
80 pointer = pointer + CACHE_SIZE;
81 ram_disk_memory = pointer;
82
83 #endif
84
85 /* Initialize the FileX system. */
86 fx_system_initialize();
87 #ifdef FX_STANDALONE_ENABLE
88 ftest_0_entry(0);
89 #endif
90 }
91
92
93
94 /* Define the test threads. */
95
ftest_0_entry(ULONG thread_input)96 static void ftest_0_entry(ULONG thread_input)
97 {
98
99 UINT i;
100 UINT status, count;
101 ULONG length;
102 ULONG old_length;
103 ULONG new_length;
104
105 FX_PARAMETER_NOT_USED(thread_input);
106
107 /* Print out some test information banners. */
108 printf("FileX Test: Unicode File Rename Test...............................");
109
110 /* Loop to test FAT 12, 16, 32. */
111 for (i = 0; i < TEST_COUNT; i ++)
112 {
113 if (i == 0)
114 {
115 /* Format the media with FAT12. This needs to be done before opening it! */
116 status = fx_media_format(&ram_disk,
117 _fx_ram_driver, // Driver entry
118 ram_disk_memory_large, // RAM disk memory pointer
119 cache_buffer, // Media buffer pointer
120 CACHE_SIZE, // Media buffer size
121 "MY_RAM_DISK", // Volume Name
122 1, // Number of FATs
123 32, // Directory Entries
124 0, // Hidden sectors
125 256, // Total sectors
126 256, // Sector size
127 8, // Sectors per cluster
128 1, // Heads
129 1); // Sectors per track
130 }
131 else if (i == 1)
132 {
133 /* Format the media with FAT16. This needs to be done before opening it! */
134 status = fx_media_format(&ram_disk,
135 _fx_ram_driver, // Driver entry
136 ram_disk_memory_large, // RAM disk memory pointer
137 cache_buffer, // Media buffer pointer
138 CACHE_SIZE, // Media buffer size
139 "MY_RAM_DISK", // Volume Name
140 1, // Number of FATs
141 32, // Directory Entries
142 0, // Hidden sectors
143 4200 * 8, // Total sectors
144 256, // Sector size
145 8, // Sectors per cluster
146 1, // Heads
147 1); // Sectors per track
148 }
149 else if (i == 2)
150 {
151 /* Format the media with FAT32. This needs to be done before opening it! */
152 status = fx_media_format(&ram_disk,
153 _fx_ram_driver, // Driver entry
154 ram_disk_memory_large, // RAM disk memory pointer
155 cache_buffer, // Media buffer pointer
156 CACHE_SIZE, // Media buffer size
157 "MY_RAM_DISK", // Volume Name
158 1, // Number of FATs
159 32, // Directory Entries
160 0, // Hidden sectors
161 70000 * 8, // Total sectors
162 256, // Sector size
163 8, // Sectors per cluster
164 1, // Heads
165 1); // Sectors per track
166 }
167
168 /* Determine if the format had an error. */
169 if (status)
170 {
171
172 printf("ERROR!\n");
173 test_control_return(1);
174 }
175
176 /* Attempt to rename a file before the media has been opened */
177 status = fx_unicode_file_rename(&ram_disk, (UCHAR *)"name", 1, (UCHAR *)"name", 1, (CHAR *) destination_name);
178 if (status != FX_MEDIA_NOT_OPEN)
179 {
180 printf("ERROR!\n");
181 test_control_return(2);
182 }
183
184 /* Open the ram_disk. */
185 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
186
187 /* Check the status. */
188 if (status != FX_SUCCESS)
189 {
190
191 /* Error, return error code. */
192 printf("ERROR!\n");
193 test_control_return(3);
194 }
195
196 /* Attempt to rename a file that does not exist */
197 status = fx_unicode_file_rename(&ram_disk, (UCHAR *)"does_not_exist", 1, (UCHAR *)"does_not_exist", 1, (CHAR *) destination_name);
198 if (status == FX_SUCCESS)
199 {
200 printf("ERROR!\n");
201 test_control_return(4);
202 }
203
204 /* Create the unicode file name to create the same unicode file names in the sub directory. */
205 length = fx_unicode_length_get(old_file_name);
206 status = fx_unicode_file_create(&ram_disk, old_file_name, length, (CHAR *) destination_name);
207
208 /* Check for expected error. */
209 if (status)
210 {
211
212 /* Error creating unicode file names. Return to caller. */
213 printf("ERROR!\n");
214 test_control_return(5);
215 }
216
217 /* Rename the old file name to new_file_name1. */
218 old_length = fx_unicode_length_get(old_file_name);
219 new_length = fx_unicode_length_get(new_file_name1);
220 status = fx_unicode_file_rename(&ram_disk, old_file_name, old_length, new_file_name1, new_length, (CHAR *) destination_name);
221
222 /* Check for expected error. */
223 if (status)
224 {
225
226 /* Error creating unicode file names. Return to caller. */
227 printf("ERROR!\n");
228 test_control_return(6);
229 }
230
231 /* Rename the new_file_name1 to new_file_name2. */
232 old_length = fx_unicode_length_get(new_file_name1);
233 new_length = fx_unicode_length_get(new_file_name2);
234 status = fx_unicode_file_rename(&ram_disk, new_file_name1, old_length, new_file_name2, new_length, (CHAR *) destination_name);
235
236 /* Check for expected error. */
237 if (status)
238 {
239
240 /* Error creating unicode file names. Return to caller. */
241 printf("ERROR!\n");
242 test_control_return(7);
243 }
244
245 /* Rename the new_file_name2 to new_file_name3. */
246 old_length = fx_unicode_length_get(new_file_name2);
247 new_length = fx_unicode_length_get(new_file_name3);
248 status = fx_unicode_file_rename(&ram_disk, new_file_name2, old_length, new_file_name3, new_length, (CHAR *) destination_name);
249
250 /* Check for expected error. */
251 if (status)
252 {
253
254 /* Error creating unicode file names. Return to caller. */
255 printf("ERROR!\n");
256 test_control_return(8);
257 }
258
259 /* Rename the new_file_name3 to new_file_name4. */
260 old_length = fx_unicode_length_get(new_file_name3);
261 new_length = fx_unicode_length_get(new_file_name4);
262 status = fx_unicode_file_rename(&ram_disk, new_file_name3, old_length, new_file_name4, new_length, (CHAR *) destination_name);
263
264 /* Check for expected error. */
265 if (status)
266 {
267
268 /* Error creating unicode file names. Return to caller. */
269 printf("ERROR!\n");
270 test_control_return(9);
271 }
272
273 /* Attempt to create the old_file_name again. */
274 length = fx_unicode_length_get(old_file_name);
275 status = fx_unicode_file_create(&ram_disk, old_file_name, length, (CHAR *) destination_name);
276
277 /* Check for expected error. */
278 if (status)
279 {
280
281 /* Error creating unicode file name. Return to caller. */
282 printf("ERROR!\n");
283 test_control_return(10);
284 }
285
286 /* Attempt to create the new_file_name1 same as old_file_name again. */
287 length = fx_unicode_length_get(new_file_name1);
288 status = fx_unicode_file_create(&ram_disk, new_file_name1, length, (CHAR *) destination_name);
289
290 /* Check for expected error. */
291 if (status != FX_ALREADY_CREATED)
292 {
293
294 /* Error creating unicode directory name. Return to caller. */
295 printf("ERROR!\n");
296 test_control_return(11);
297 }
298
299
300 /* Attempt to create the new_file_name2 again. */
301 length = fx_unicode_length_get(new_file_name2);
302 status = fx_unicode_file_create(&ram_disk, new_file_name2, length, (CHAR *) destination_name);
303
304 /* Check for expected error. */
305 if (status)
306 {
307
308 /* Error creating unicode directory name. Return to caller. */
309 printf("ERROR!\n");
310 test_control_return(12);
311 }
312
313 /* Attempt to create the new_file_name1 again. */
314 length = fx_unicode_length_get(new_file_name3);
315 status = fx_unicode_file_create(&ram_disk, new_file_name3, length, (CHAR *) destination_name);
316
317 /* Check for expected error. */
318 if (status)
319 {
320
321 /* Error creating unicode directory name. Return to caller. */
322 printf("ERROR!\n");
323 test_control_return(13);
324 }
325
326 /* Attempt to create the new_file_name4 again. */
327 length = fx_unicode_length_get(new_file_name4);
328 status = fx_unicode_file_create(&ram_disk, new_file_name4, length, (CHAR *) destination_name);
329
330 /* Check for expected error. */
331 if (status != FX_ALREADY_CREATED)
332 {
333
334 /* Error creating unicode directory name. Return to caller. */
335 printf("ERROR!\n");
336 test_control_return(14);
337 }
338
339 #ifndef FX_DISABLE_ERROR_CHECKING
340 /* send a null pointer to generate an error */
341 status = fx_unicode_file_rename(FX_NULL, old_file_name, old_length, new_file_name1, new_length, (CHAR *) destination_name);
342 if (status != FX_PTR_ERROR)
343 {
344 printf("ERROR!\n");
345 test_control_return(15);
346 }
347 #endif /* FX_DISABLE_ERROR_CHECKING */
348
349 /* Create a file whose name is consists of lowcase characters. */
350 length = fx_unicode_length_get(new_file_name5);
351 status = fx_unicode_file_create(&ram_disk, new_file_name5, length, (CHAR *)destination_name);
352
353 /* Check for expected error. */
354 return_value_if_fail( status == FX_SUCCESS, 16);
355
356 /* Rename as the same file name. */
357 length = fx_unicode_length_get(new_file_name5);
358 status = fx_unicode_file_rename(&ram_disk, new_file_name5, length, new_file_name5, length, (CHAR *)destination_name);
359
360 /* Check for expected error. */
361 return_value_if_fail( status == FX_SUCCESS, 17);
362
363 length = fx_unicode_length_get(new_file_name6);
364 status = fx_unicode_file_create(&ram_disk, new_file_name6, length, (CHAR *)destination_name);
365
366 /* Check for expected error. */
367 return_value_if_fail( status == FX_SUCCESS, 18);
368
369 /* Attempt to rename new_file_name6 as existed new_file_name5 */
370 old_length = fx_unicode_length_get(new_file_name6);
371 new_length = fx_unicode_length_get(new_file_name5);
372 status = fx_unicode_file_rename(&ram_disk, new_file_name6, old_length, new_file_name5, new_length, (CHAR *)destination_name);
373
374 /* Check for expected error. */
375 return_value_if_fail( status == FX_ALREADY_CREATED, 19);
376
377 /* Attempt to rename new_file_name6 as new_file_name7 */
378 old_length = fx_unicode_length_get(new_file_name6);
379 new_length = fx_unicode_length_get(new_file_name7);
380 status = fx_unicode_file_rename(&ram_disk, new_file_name6, old_length, new_file_name7, new_length, (CHAR *)destination_name);
381
382 /* Check for expected error. */
383 return_value_if_fail( status == FX_SUCCESS, 20);
384
385 /* Attempt to rename new_file_name5 as exised new_file_name7 */
386 old_length = fx_unicode_length_get(new_file_name5);
387 new_length = fx_unicode_length_get(new_file_name7);
388 status = fx_unicode_file_rename(&ram_disk, new_file_name5, old_length, new_file_name7, new_length, (CHAR *)destination_name);
389
390 /* Check for expected error. */
391 return_value_if_fail( status == FX_ALREADY_CREATED, 21);
392
393 /* Attempt to rename new_file_name7 as itself. */
394 old_length = fx_unicode_length_get(new_file_name7);
395 new_length = fx_unicode_length_get(new_file_name7);
396 status = fx_unicode_file_rename(&ram_disk, new_file_name7, old_length, new_file_name7, new_length, (CHAR *)destination_name);
397
398 /* Check for expected error. */
399 return_value_if_fail( status == FX_SUCCESS, 22);
400
401 /* Created two files whose name's first byte is 'z'+1. */
402 length = fx_unicode_length_get(new_file_name8);
403 status = fx_unicode_file_create(&ram_disk, new_file_name8, length, (CHAR *)destination_name);
404 length = fx_unicode_length_get(new_file_name9);
405 status += fx_unicode_file_create(&ram_disk, new_file_name9, length, (CHAR *)destination_name);
406 return_value_if_fail( status == FX_SUCCESS, 23);
407
408 /* Attempt to rename new_file_name9 as existed new_file_name8 */
409 old_length = fx_unicode_length_get(new_file_name9);
410 new_length = fx_unicode_length_get(new_file_name8);
411 status = fx_unicode_file_rename(&ram_disk, new_file_name9, old_length, new_file_name8, new_length, (CHAR *)destination_name);
412 return_value_if_fail( status == FX_ALREADY_CREATED, 24);
413
414 /* Attempt to rename new_file_name9 as existed new_file_name7 */
415 old_length = fx_unicode_length_get(new_file_name9);
416 new_length = fx_unicode_length_get(new_file_name7);
417 status = fx_unicode_file_rename(&ram_disk, new_file_name9, old_length, new_file_name7, new_length, (CHAR *)destination_name);
418 return_value_if_fail( status == FX_ALREADY_CREATED, 25);
419
420 /* Attempt to create a lot of directories with similar names to overflow. */
421 length = fx_unicode_length_get(new_file_name5);
422 for ( count = 0; count < 27; count++)
423 {
424 new_file_name5[0]++;
425 status = fx_unicode_directory_create(&ram_disk, new_file_name5, length, (CHAR *)destination_name);
426 return_value_if_fail( (status == FX_SUCCESS) || (status == FX_ALREADY_CREATED) || (status == FX_NO_MORE_SPACE), 24 + count);
427 }
428 old_length = fx_unicode_length_get(new_file_name5_bak);
429 new_length = fx_unicode_length_get(new_file_name5);
430 status = fx_unicode_directory_rename(&ram_disk, new_file_name5_bak, old_length, new_file_name5, new_length, (CHAR *)destination_name);
431 return_value_if_fail( (status == FX_NOT_FOUND) || ( status == FX_NOT_DIRECTORY), 53);
432
433 /* Close the media. */
434 status = fx_media_close(&ram_disk);
435
436 /* Determine if the test was successful. */
437 return_value_if_fail( status == FX_SUCCESS, 51);
438 }
439
440 printf("SUCCESS!\n");
441 test_control_return(0);
442 }
443