filex_directory_attributes_read_set_test.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /* This FileX test concentrates on the file attributes read/set operation. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include <stdio.h>
  7. #include "fx_ram_driver_test.h"
  8. void test_control_return(UINT status);
  9. #define DEMO_STACK_SIZE 4096
  10. #define CACHE_SIZE 128*128
  11. /* Define the ThreadX and FileX object control blocks... */
  12. #ifndef FX_STANDALONE_ENABLE
  13. static TX_THREAD ftest_0;
  14. #endif
  15. static FX_MEDIA ram_disk;
  16. /* Define the counters used in the test application... */
  17. #ifndef FX_STANDALONE_ENABLE
  18. static UCHAR *ram_disk_memory;
  19. static UCHAR *cache_buffer;
  20. #else
  21. static UCHAR cache_buffer[CACHE_SIZE];
  22. #endif
  23. /* Define thread prototypes. */
  24. void filex_directory_attributes_read_set_application_define(void *first_unused_memory);
  25. static void ftest_0_entry(ULONG thread_input);
  26. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  27. /* Define what the initial system looks like. */
  28. #ifdef CTEST
  29. void test_application_define(void *first_unused_memory)
  30. #else
  31. void filex_directory_attributes_read_set_application_define(void *first_unused_memory)
  32. #endif
  33. {
  34. #ifndef FX_STANDALONE_ENABLE
  35. UCHAR *pointer;
  36. /* Setup the working pointer. */
  37. pointer = (UCHAR *) first_unused_memory;
  38. /* Create the main thread. */
  39. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  40. pointer, DEMO_STACK_SIZE,
  41. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  42. pointer = pointer + DEMO_STACK_SIZE;
  43. /* Setup memory for the RAM disk and the sector cache. */
  44. cache_buffer = pointer;
  45. pointer = pointer + CACHE_SIZE;
  46. ram_disk_memory = pointer;
  47. #endif
  48. /* Initialize the FileX system. */
  49. fx_system_initialize();
  50. #ifdef FX_STANDALONE_ENABLE
  51. ftest_0_entry(0);
  52. #endif
  53. }
  54. /* Define the test threads. */
  55. static void ftest_0_entry(ULONG thread_input)
  56. {
  57. UINT status;
  58. UINT attributes;
  59. FX_PARAMETER_NOT_USED(thread_input);
  60. /* Print out some test information banners. */
  61. printf("FileX Test: Directory attributes read/set test.....................");
  62. /* Format the media. This needs to be done before opening it! */
  63. status = fx_media_format(&ram_disk,
  64. _fx_ram_driver, // Driver entry
  65. ram_disk_memory, // RAM disk memory pointer
  66. cache_buffer, // Media buffer pointer
  67. CACHE_SIZE, // Media buffer size
  68. "MY_RAM_DISK", // Volume Name
  69. 1, // Number of FATs
  70. 32, // Directory Entries
  71. 0, // Hidden sectors
  72. 512, // Total sectors
  73. 128, // Sector size
  74. 1, // Sectors per cluster
  75. 1, // Heads
  76. 1); // Sectors per track
  77. /* Determine if the format had an error. */
  78. if (status)
  79. {
  80. printf("ERROR!\n");
  81. test_control_return(2);
  82. }
  83. /* test error checking */
  84. #ifndef FX_DISABLE_ERROR_CHECKING
  85. /* check directory attributes read null pointer error */
  86. status = fx_directory_attributes_read(FX_NULL, "TEST_DIR", &attributes);
  87. if (status != FX_PTR_ERROR)
  88. {
  89. printf("ERROR!\n");
  90. test_control_return(99);
  91. }
  92. /* check directory attributes set null pointer error */
  93. status = fx_directory_attributes_set(FX_NULL, "TEST_DIR", attributes);
  94. if (status != FX_PTR_ERROR)
  95. {
  96. printf("ERROR!\n");
  97. test_control_return(99);
  98. }
  99. /* check directory attributes set null pointer error */
  100. status = fx_directory_attributes_set(&ram_disk, "TEST_DIR", 0x1111);
  101. if (status != FX_INVALID_ATTR)
  102. {
  103. printf("ERROR!\n");
  104. test_control_return(99);
  105. }
  106. #endif
  107. /* check directory attributes read to make sure it throws an error when the media hasnt been opened */
  108. status = fx_directory_attributes_read(&ram_disk, "TEST_DIR", &attributes);
  109. if (status != FX_MEDIA_NOT_OPEN)
  110. {
  111. printf("ERROR!\n");
  112. test_control_return(99);
  113. }
  114. /* check directory attributes set to make sure it throws an error when the media hasnt been opened */
  115. status = fx_directory_attributes_set(&ram_disk, "TEST_DIR", 0x0000);
  116. if (status != FX_MEDIA_NOT_OPEN)
  117. {
  118. printf("ERROR!\n");
  119. test_control_return(99);
  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. /* Check the status. */
  124. if (status != FX_SUCCESS)
  125. {
  126. /* Error, return error code. */
  127. printf("ERROR!\n");
  128. test_control_return(3);
  129. }
  130. /* Create a directory called TEST_DIR in the root directory. */
  131. status = fx_directory_create(&ram_disk, "TEST_DIR");
  132. /* Check the create status. */
  133. if (status != FX_SUCCESS)
  134. {
  135. printf("ERROR!\n");
  136. test_control_return(4);
  137. }
  138. /* Create a file called NOT_A_DIR in the root directory. */
  139. status = fx_file_create(&ram_disk, "NOT_A_DIR");
  140. /* Check the create status. */
  141. if (status != FX_SUCCESS)
  142. {
  143. printf("ERROR!\n");
  144. test_control_return(4);
  145. }
  146. /* Invalidate the media cache. */
  147. fx_media_cache_invalidate(&ram_disk);
  148. /* Pickup the attributes of the directory. */
  149. status = fx_directory_attributes_read(&ram_disk, "TEST_DIR", &attributes);
  150. /* Check the attributes read status. */
  151. if ((status != FX_SUCCESS) || (attributes != FX_DIRECTORY))
  152. {
  153. printf("ERROR!\n");
  154. test_control_return(5);
  155. }
  156. /* check directory attributes set to make sure it throws an error when the directory is write protected */
  157. ram_disk.fx_media_driver_write_protect = FX_TRUE;
  158. status = fx_directory_attributes_set(&ram_disk, "TEST_DIR", attributes);
  159. if (status == FX_SUCCESS)
  160. {
  161. printf("ERROR!\n");
  162. test_control_return(99);
  163. }
  164. ram_disk.fx_media_driver_write_protect = FX_FALSE;
  165. /* check directory attributes read to make sure it throws an error when it isnt a directory */
  166. status = fx_directory_attributes_read(&ram_disk, "NOT_A_DIR", &attributes);
  167. if (status != FX_NOT_DIRECTORY)
  168. {
  169. printf("ERROR!\n");
  170. test_control_return(99);
  171. }
  172. /* check directory attributes read to make sure it throws an error when the directory isnt found */
  173. status = fx_directory_attributes_read(&ram_disk, "DOES_NOT_EXIST", &attributes);
  174. if (status == FX_SUCCESS)
  175. {
  176. printf("ERROR!\n");
  177. test_control_return(99);
  178. }
  179. /* check directory attributes set to make sure it throws an error when it isnt a directory */
  180. status = fx_directory_attributes_set(&ram_disk, "NOT_A_DIR", attributes);
  181. if (status != FX_NOT_DIRECTORY)
  182. {
  183. printf("ERROR!\n");
  184. test_control_return(99);
  185. }
  186. /* check directory attributes set to make sure it throws an error when the directory isnt found */
  187. status = fx_directory_attributes_set(&ram_disk, "DOES_NOT_EXIST", attributes);
  188. if (status == FX_SUCCESS)
  189. {
  190. printf("ERROR!\n");
  191. test_control_return(99);
  192. }
  193. /* Invalidate the media cache. */
  194. fx_media_cache_invalidate(&ram_disk);
  195. /* Now write the attributes out for the directory. */
  196. status = fx_directory_attributes_set(&ram_disk, "TEST_DIR", attributes | FX_ARCHIVE | FX_SYSTEM | FX_READ_ONLY | FX_HIDDEN);
  197. /* Check the attributes set status. */
  198. if (status != FX_SUCCESS)
  199. {
  200. printf("ERROR!\n");
  201. test_control_return(6);
  202. }
  203. /* Invalidate the media cache. */
  204. fx_media_cache_invalidate(&ram_disk);
  205. /* Pickup the attributes of the directory again. */
  206. status = fx_directory_attributes_read(&ram_disk, "TEST_DIR", &attributes);
  207. /* Check the attributes read status. */
  208. if ((status != FX_SUCCESS) || (attributes != (FX_ARCHIVE | FX_READ_ONLY | FX_DIRECTORY | FX_SYSTEM | FX_HIDDEN)))
  209. {
  210. printf("ERROR!\n");
  211. test_control_return(7);
  212. }
  213. /* Close the media. */
  214. status = fx_media_close(&ram_disk);
  215. /* Determine if the test was successful. */
  216. if (status != FX_SUCCESS)
  217. {
  218. printf("ERROR!\n");
  219. test_control_return(8);
  220. }
  221. else
  222. {
  223. printf("SUCCESS!\n");
  224. test_control_return(0);
  225. }
  226. }