1 /* This FileX test concentrates on the directory long/short name get operations. */
2
3 #ifndef FX_STANDALONE_ENABLE
4 #include "tx_api.h"
5 #endif
6 #include "fx_api.h"
7 #include <stdio.h>
8 #include "fx_ram_driver_test.h"
9
10 #define DEMO_STACK_SIZE 8192
11 #define CACHE_SIZE 16*128
12
13
14 /* Define the ThreadX and FileX object control blocks... */
15
16 #ifndef FX_STANDALONE_ENABLE
17 static TX_THREAD ftest_0;
18 #endif
19 static FX_MEDIA ram_disk;
20
21
22 /* Define the counters used in the test application... */
23
24 #ifndef FX_STANDALONE_ENABLE
25 static UCHAR *ram_disk_memory;
26 static UCHAR *cache_buffer;
27 #else
28 static UCHAR cache_buffer[CACHE_SIZE];
29 #endif
30 static CHAR name[50];
31 static CHAR max_name[FX_MAX_LONG_NAME_LEN+1];
32 static CHAR return_name[FX_MAX_LONG_NAME_LEN+1];
33
34
35 /* Define thread prototypes. */
36
37 void filex_directory_long_short_get_application_define(void *first_unused_memory);
38 static void ftest_0_entry(ULONG thread_input);
39
40 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
41 void test_control_return(UINT status);
42
43
44
45 /* Define what the initial system looks like. */
46
47 #ifdef CTEST
test_application_define(void * first_unused_memory)48 void test_application_define(void *first_unused_memory)
49 #else
50 void filex_directory_long_short_get_application_define(void *first_unused_memory)
51 #endif
52 {
53
54 #ifndef FX_STANDALONE_ENABLE
55 UCHAR *pointer;
56
57
58 /* Setup the working pointer. */
59 pointer = (UCHAR *) first_unused_memory;
60
61 /* Create the main thread. */
62 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
63 pointer, DEMO_STACK_SIZE,
64 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
65
66 pointer = pointer + DEMO_STACK_SIZE;
67
68 /* Setup memory for the RAM disk and the sector cache. */
69 cache_buffer = pointer;
70 pointer = pointer + CACHE_SIZE;
71 ram_disk_memory = pointer;
72
73 #endif
74
75 /* Initialize the FileX system. */
76 fx_system_initialize();
77 #ifdef FX_STANDALONE_ENABLE
78 ftest_0_entry(0);
79 #endif
80 }
81
82
83
84 /* Define the test threads. */
85
ftest_0_entry(ULONG thread_input)86 static void ftest_0_entry(ULONG thread_input)
87 {
88
89 UINT status;
90 UINT i;
91
92 FX_PARAMETER_NOT_USED(thread_input);
93
94 /* Print out some test information banners. */
95 printf("FileX Test: Directory long/short name get test.....................");
96
97 /* Format the media. This needs to be done before opening it! */
98 status = fx_media_format(&ram_disk,
99 _fx_ram_driver, // Driver entry
100 ram_disk_memory, // RAM disk memory pointer
101 cache_buffer, // Media buffer pointer
102 CACHE_SIZE, // Media buffer size
103 "MY_RAM_DISK", // Volume Name
104 1, // Number of FATs
105 128, // Directory Entries
106 0, // Hidden sectors
107 2048, // Total sectors
108 128, // Sector size
109 1, // Sectors per cluster
110 1, // Heads
111 1); // Sectors per track
112
113 /* Determine if the format had an error. */
114 if (status)
115 {
116
117 printf("ERROR!\n");
118 test_control_return(1);
119 }
120
121 /* Open the ram_disk. */
122 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
123
124 /* Check the status. */
125 if (status != FX_SUCCESS)
126 {
127
128 /* Error, return error code. */
129 printf("ERROR!\n");
130 test_control_return(2);
131 }
132
133 /* Attempt to get a directory that does not exist */
134 status = fx_directory_short_name_get(&ram_disk, "does_not_exist", "does_not_exist");
135 if (status == FX_SUCCESS)
136 {
137 printf("ERROR!\n");
138 test_control_return(3);
139 }
140
141 /* Simple 8.3 rename in the root directory. */
142 status = fx_directory_create(&ram_disk, "subdir");
143 status += fx_file_create(&ram_disk, "name");
144 status += fx_file_create(&ram_disk, "longnametest");
145 status += fx_file_create(&ram_disk, "subdir/SNAME.TXT");
146 status += fx_file_create(&ram_disk, "subdir/longnametest");
147
148 /* Check the directory/file create status. */
149 if (status != FX_SUCCESS)
150 {
151
152 /* Error creating files/directories. Return to caller. */
153 printf("ERROR!\n");
154 test_control_return(4);
155 }
156
157 /* Only run this if error checking is enabled */
158 #ifndef FX_DISABLE_ERROR_CHECKING
159 /* send null pointer to generate an error */
160 status = fx_directory_short_name_get(FX_NULL, "subdir", name);
161 if (status != FX_PTR_ERROR)
162 {
163 printf("ERROR!\n");
164 test_control_return(5);
165 }
166 /* send null pointer to generate an error */
167 status = fx_directory_short_name_get_extended(FX_NULL, "subdir", name, 1);
168 if (status != FX_PTR_ERROR)
169 {
170 printf("ERROR!\n");
171 test_control_return(5);
172 }
173 #endif /* FX_DISABLE_ERROR_CHECKING */
174
175 /* attempt to get the long name of something that doesnt exist */
176 status = fx_directory_long_name_get(&ram_disk, "does_not_exist", "does_not_exist");
177 if (status == FX_SUCCESS)
178 {
179 printf("ERROR!\n");
180 test_control_return(6);
181 }
182
183 /* Get the short name of a long name. */
184 status = fx_directory_short_name_get(&ram_disk, "subdir", name);
185 status += fx_directory_long_name_get(&ram_disk, name, name);
186
187 /* Check for errors. */
188 if ((status != FX_SUCCESS) || (strcmp(name, "subdir")))
189 {
190
191 /* Error getting long/short name. Return to caller. */
192 printf("ERROR!\n");
193 test_control_return(7);
194 }
195
196 /* Set name to known state. */
197 memcpy(name, "ORIGINALSTRING", 15);
198
199 /* Test extended short name get with short buffer length. */
200 status = fx_directory_short_name_get_extended(&ram_disk, "subdir", name, 2);
201
202 /* Check for errors. */
203 if ((status != FX_BUFFER_ERROR) || (memcmp(name, "S\0IGINALSTRING\0", 15)))
204 {
205
206 /* Error getting short name extended. Return to caller. */
207 printf("ERROR!\n");
208 test_control_return(7);
209 }
210
211 /* Get the long name from short name. */
212 status = fx_directory_long_name_get(&ram_disk, "NAME", name);
213 status += fx_directory_short_name_get(&ram_disk, name, name);
214
215 /* Check for errors. */
216 if ((status != FX_SUCCESS) || (strcmp(name, "NAME")))
217 {
218
219 /* Error getting long/short name. Return to caller. */
220 printf("ERROR!\n");
221 test_control_return(8);
222 }
223
224 /* Get the short name of a long name. */
225 status = fx_directory_short_name_get(&ram_disk, "longnametest", name);
226 status += fx_directory_long_name_get(&ram_disk, name, name);
227
228 /* Check for errors. */
229 if ((status != FX_SUCCESS) || (strcmp(name, "longnametest")))
230 {
231
232 /* Error getting long/short name. Return to caller. */
233 printf("ERROR!\n");
234 test_control_return(9);
235 }
236
237 /* Move to sub-directory. */
238 status += fx_directory_default_set(&ram_disk, "subdir");
239
240 /* Get the long name from short name. */
241 status += fx_directory_long_name_get(&ram_disk, "SNAME.TXT", name);
242 status += fx_directory_short_name_get(&ram_disk, name, name);
243
244 /* Check for errors. */
245 if ((status != FX_SUCCESS) || (strcmp(name, "SNAME.TXT")))
246 {
247
248 /* Error getting long/short name. Return to caller. */
249 printf("ERROR!\n");
250 test_control_return(10);
251 }
252
253 /* Set name to known state. */
254 memcpy(name, "ORIGINALSTRING", 15);
255
256 /* Get the long name from short name using extended version. */
257 status = fx_directory_long_name_get_extended(&ram_disk, "SNAME.TXT", name, 2);
258
259 /* Check for error. */
260 if ((status != FX_BUFFER_ERROR) || (memcmp(name, "S\0IGINALSTRING\0", 15)))
261 {
262
263 /* Error getting long/short name. Return to caller. */
264 printf("ERROR!\n");
265 test_control_return(10);
266 }
267
268 /* Set name to known state. */
269 memcpy(name, "ORIGINALSTRING", 15);
270 status = fx_directory_short_name_get_extended(&ram_disk, "SNAME.TXT", name, 2);
271
272 /* Check for error. */
273 if ((status != FX_BUFFER_ERROR) || (memcmp(name, "S\0IGINALSTRING\0", 15)))
274 {
275
276 /* Error getting long/short name. Return to caller. */
277 printf("ERROR!\n");
278 test_control_return(10);
279 }
280
281 /* Get the short name from long name. */
282 status = fx_directory_short_name_get(&ram_disk, "longnametest", name);
283 status += fx_directory_long_name_get(&ram_disk, name, name);
284
285 /* Check for errors. */
286 if ((status != FX_SUCCESS) || (strcmp(name, "longnametest")))
287 {
288
289 /* Error getting long/short name. Return to caller. */
290 printf("ERROR!\n");
291 test_control_return(11);
292 }
293
294 /* Only run this if error checking is enabled */
295 #ifndef FX_DISABLE_ERROR_CHECKING
296 /* send null pointer to generate an error */
297 status = fx_directory_long_name_get(FX_NULL, "NAME", name);
298 if (status != FX_PTR_ERROR)
299 {
300 printf("ERROR!\n");
301 test_control_return(12);
302 }
303 /* send null pointer to generate an error */
304 status = fx_directory_long_name_get_extended(FX_NULL, "NAME", name, 1);
305 if (status != FX_PTR_ERROR)
306 {
307 printf("ERROR!\n");
308 test_control_return(12);
309 }
310 #endif /* FX_DISABLE_ERROR_CHECKING */
311
312
313 /* Create a maximum size short file name. */
314 status = fx_file_create(&ram_disk, "MAX_SIZE.TXT");
315
316 /* Get the short name. */
317 status += fx_directory_short_name_get(&ram_disk, "MAX_SIZE.TXT", name);
318
319 /* Check for errors. */
320 if ((status != FX_SUCCESS) || (strcmp(name, "MAX_SIZE.TXT")))
321 {
322
323 /* Error getting long/short name. Return to caller. */
324 printf("ERROR!\n");
325 test_control_return(13);
326 }
327
328 /* Build a maximum sized long file name. */
329 for (i = 0; i < (FX_MAX_LONG_NAME_LEN-1); i++)
330 {
331
332 /* Set a character in the file name. */
333 max_name[i] = 'a';
334 }
335 max_name[i] = 0;
336 max_name[i-4] = '.';
337
338 /* Create a maximum size long file name. */
339 status = fx_file_create(&ram_disk, max_name);
340
341 /* Get the short name. */
342 status += fx_directory_short_name_get(&ram_disk, max_name, return_name);
343
344 /* Check for errors. */
345 if ((status != FX_SUCCESS) || (strcmp(return_name, "AAA~001A.AAA")))
346 {
347
348 /* Error getting long/short name. Return to caller. */
349 printf("ERROR!\n");
350 test_control_return(14);
351 }
352
353 /* Get the long name. */
354 status += fx_directory_long_name_get(&ram_disk, return_name, return_name);
355
356 /* Check for errors. */
357 if ((status != FX_SUCCESS) || (strcmp(return_name, max_name)))
358 {
359
360 /* Error getting long/short name. Return to caller. */
361 printf("ERROR!\n");
362 test_control_return(15);
363 }
364
365
366 /* Close the media. */
367 status = fx_media_close(&ram_disk);
368
369 /* Determine if the test was successful. */
370 if (status != FX_SUCCESS)
371 {
372
373 printf("ERROR!\n");
374 test_control_return(16);
375 }
376 else
377 {
378
379 printf("SUCCESS!\n");
380 test_control_return(0);
381 }
382 }
383