filex_unicode_directory_entry_change_test.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*This test is determined to cover lines 315 327 352 390 in fx_unicode_directory_entry_change.c. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include "fx_utility.h"
  7. #include "fx_ram_driver_test.h"
  8. #include <stdio.h>
  9. #define DEMO_STACK_SIZE 8192
  10. /* Set the cache size as the size of one sector causing frequently IO operation. */
  11. #define CACHE_SIZE 128
  12. /* Define the ThreadX and FileX object control blocks... */
  13. #ifndef FX_STANDALONE_ENABLE
  14. static TX_THREAD ftest_0;
  15. #endif
  16. static FX_MEDIA ram_disk;
  17. /* Define the counters used in the test application... */
  18. #ifndef FX_STANDALONE_ENABLE
  19. static UCHAR *ram_disk_memory;
  20. static UCHAR *cache_buffer;
  21. #else
  22. static UCHAR cache_buffer[256];
  23. #endif
  24. /* Define thread prototypes. */
  25. void filex_unicode_directory_entry_change_test_application_define(void *first_unused_memory);
  26. static void ftest_0_entry(ULONG thread_input);
  27. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  28. void test_control_return(UINT status);
  29. extern UINT _fx_unicode_directory_entry_change(FX_MEDIA *media_ptr, FX_DIR_ENTRY *entry_ptr, UCHAR *unicode_name, ULONG unicode_name_length);
  30. static UINT driver_called_counter = 0;
  31. /* Create a terrible driver. */
  32. static void _fx_terrible_driver(FX_MEDIA *media_ptr)
  33. {
  34. driver_called_counter++;
  35. // printf("\n_fx_terrible_driver has been called %d times.", driver_called_counter);
  36. if (driver_called_counter == 3)
  37. {
  38. media_ptr->fx_media_driver_status=FX_IO_ERROR;
  39. return;
  40. }
  41. (*_fx_ram_driver)(media_ptr);
  42. }
  43. /* Define what the initial system looks like. */
  44. #ifdef CTEST
  45. void test_application_define(void *first_unused_memory)
  46. #else
  47. void filex_unicode_directory_entry_change_test_application_define(void *first_unused_memory)
  48. #endif
  49. {
  50. #ifndef FX_STANDALONE_ENABLE
  51. UCHAR *pointer;
  52. /* Setup the working pointer. */
  53. pointer = (UCHAR *)first_unused_memory;
  54. /* Create the main thread. */
  55. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  56. pointer, DEMO_STACK_SIZE,
  57. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  58. pointer = pointer + DEMO_STACK_SIZE;
  59. /* Setup memory for the RAM disk and the sector cache. */
  60. cache_buffer = pointer;
  61. pointer = pointer + CACHE_SIZE;
  62. ram_disk_memory = pointer;
  63. #endif
  64. /* Initialize the FileX system. */
  65. fx_system_initialize();
  66. #ifdef FX_STANDALONE_ENABLE
  67. ftest_0_entry(0);
  68. #endif
  69. }
  70. static UCHAR long_unicode_name1[] = { 1, 0, 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, 0, 0, 0, 0, 0,};
  71. /* Define the test threads. */
  72. static void ftest_0_entry(ULONG thread_input)
  73. {
  74. FX_DIR_ENTRY entry; /* set a point to the entry */
  75. FX_DIR_ENTRY *entry_ptr=&entry;
  76. UINT status, length;
  77. FX_PARAMETER_NOT_USED(thread_input);
  78. /* Print out some test information banners. */
  79. printf("FileX Test: Unicode directory entry change test....................");
  80. /* Format the media with FAT32. This needs to be done before opening it! */
  81. status = fx_media_format(&ram_disk,
  82. _fx_ram_driver, // Driver entry
  83. ram_disk_memory_large, // RAM disk memory pointer
  84. cache_buffer, // Media buffer pointer
  85. CACHE_SIZE, // Media buffer size
  86. "MY_RAM_DISK", // Volume Name
  87. 1, // Number of FATs
  88. 32, // Directory Entries
  89. 0, // Hidden sectors
  90. 70000, // Total sectors
  91. 128, // Sector size
  92. 1, // Sectors per cluster
  93. 1, // Heads
  94. 1); // Sectors per track
  95. return_value_if_fail(status == FX_SUCCESS, 1);
  96. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
  97. return_value_if_fail(status == FX_SUCCESS, 2);
  98. /* initiallize the entry */
  99. entry_ptr->fx_dir_entry_name = "Z12345";
  100. entry_ptr->fx_dir_entry_attributes = 16;
  101. entry_ptr->fx_dir_entry_byte_offset = 0;
  102. entry_ptr->fx_dir_entry_cluster = 3;
  103. entry_ptr->fx_dir_entry_created_date = 18977;
  104. entry_ptr->fx_dir_entry_created_time = 0;
  105. entry_ptr->fx_dir_entry_created_time_ms = 0;
  106. entry_ptr->fx_dir_entry_date = 18977;
  107. entry_ptr->fx_dir_entry_file_size = 0;
  108. entry_ptr->fx_dir_entry_last_accessed_date = 18977;
  109. entry_ptr->fx_dir_entry_last_search_byte_offset = 0;
  110. entry_ptr->fx_dir_entry_last_search_cluster = 0;
  111. entry_ptr->fx_dir_entry_last_search_log_sector = 0;
  112. entry_ptr->fx_dir_entry_last_search_relative_cluster = 0;
  113. entry_ptr->fx_dir_entry_log_sector = 2189;
  114. entry_ptr->fx_dir_entry_long_name_present = 1;
  115. entry_ptr->fx_dir_entry_long_name_shorted = 0;
  116. entry_ptr->fx_dir_entry_next_log_sector = 0;
  117. entry_ptr->fx_dir_entry_reserved = 0;
  118. entry_ptr->fx_dir_entry_time = 0;
  119. /*This case is determined to cover lines 390 in fx_unicode_directory_entry_change.c. */
  120. length = fx_unicode_length_get(long_unicode_name1);
  121. status=_fx_unicode_directory_entry_change(&ram_disk, entry_ptr, long_unicode_name1, length);
  122. return_value_if_fail(status == FX_FILE_CORRUPT, 3);
  123. /*This case is determined to cover lines 327 in fx_unicode_directory_entry_change.c. */
  124. *(ram_disk.fx_media_driver_buffer) = 90;
  125. status = _fx_unicode_directory_entry_change(&ram_disk, entry_ptr, long_unicode_name1, length);
  126. return_value_if_fail(status == FX_FILE_CORRUPT, 4);
  127. /*This case is determined to cover lines 352 in fx_unicode_directory_entry_change.c. */
  128. entry_ptr->fx_dir_entry_byte_offset = CACHE_SIZE + 1;
  129. *(ram_disk.fx_media_driver_buffer+ CACHE_SIZE+1) = 90;
  130. /*set the the logical sector that is in root directory */
  131. entry_ptr->fx_dir_entry_log_sector =ram_disk.fx_media_data_sector_start-1;
  132. status = _fx_unicode_directory_entry_change(&ram_disk, entry_ptr, long_unicode_name1, length);
  133. return_value_if_fail(status == FX_FILE_CORRUPT, 5);
  134. /*This case is determined to cover lines 315 in fx_unicode_directory_entry_change.c. */
  135. entry_ptr->fx_dir_entry_byte_offset = CACHE_SIZE + 1;
  136. *(ram_disk.fx_media_driver_buffer + CACHE_SIZE + 1) = 90;
  137. entry_ptr->fx_dir_entry_log_sector = ram_disk.fx_media_data_sector_start ;
  138. ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_cluster = 20;
  139. /* Register our terrible dirver to make IO ERROR at a particular time. */
  140. ram_disk.fx_media_driver_entry = _fx_terrible_driver;
  141. status = _fx_unicode_directory_entry_change(&ram_disk, entry_ptr, long_unicode_name1, length);
  142. /* Unregister our terrible driver. */
  143. ram_disk.fx_media_driver_entry = _fx_ram_driver;
  144. return_value_if_fail(status == FX_IO_ERROR, 6);
  145. /* initiallize the entry */
  146. entry_ptr->fx_dir_entry_name = "Z12345";
  147. entry_ptr->fx_dir_entry_attributes = 16;
  148. entry_ptr->fx_dir_entry_byte_offset = 0;
  149. entry_ptr->fx_dir_entry_cluster = 3;
  150. entry_ptr->fx_dir_entry_created_date = 18977;
  151. entry_ptr->fx_dir_entry_created_time = 0;
  152. entry_ptr->fx_dir_entry_created_time_ms = 0;
  153. entry_ptr->fx_dir_entry_date = 18977;
  154. entry_ptr->fx_dir_entry_file_size = 0;
  155. entry_ptr->fx_dir_entry_last_accessed_date = 18977;
  156. entry_ptr->fx_dir_entry_last_search_byte_offset = 0;
  157. entry_ptr->fx_dir_entry_last_search_cluster = 0;
  158. entry_ptr->fx_dir_entry_last_search_log_sector = 0;
  159. entry_ptr->fx_dir_entry_last_search_relative_cluster = 0;
  160. entry_ptr->fx_dir_entry_log_sector = 2189;
  161. entry_ptr->fx_dir_entry_long_name_present = 1;
  162. entry_ptr->fx_dir_entry_long_name_shorted = 0;
  163. entry_ptr->fx_dir_entry_next_log_sector = 0;
  164. entry_ptr->fx_dir_entry_reserved = 0;
  165. entry_ptr->fx_dir_entry_time = 0;
  166. /* Covered the last branch at Line 323 in fx_unicode_directory_entry_change.c. */
  167. *(ram_disk.fx_media_driver_buffer) = 90;
  168. /* Register a wrong information in fat cache. */
  169. ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_cluster = 2;
  170. ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_value = 0;
  171. status = _fx_unicode_directory_entry_change(&ram_disk, entry_ptr, long_unicode_name1, length);
  172. printf("SUCCESS!\n");
  173. test_control_return(0);
  174. }