filex_unicode_name_string_test.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* This FileX test concentrates on the unicode operations. */
  2. #ifndef FX_STANDALONE_ENABLE
  3. #include "tx_api.h"
  4. #endif
  5. #include "fx_api.h"
  6. #include "fx_ram_driver_test.h"
  7. #include <stdio.h>
  8. #define DEMO_STACK_SIZE 8192
  9. #define CACHE_SIZE 16*128
  10. /* Define the ThreadX and FileX object control blocks... */
  11. #ifndef FX_STANDALONE_ENABLE
  12. static TX_THREAD ftest_0;
  13. extern TX_THREAD *_tx_thread_current_ptr;
  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_unicode_name_string_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. void test_control_return(UINT status);
  28. /* Define what the initial system looks like. */
  29. #ifdef CTEST
  30. void test_application_define(void *first_unused_memory)
  31. #else
  32. void filex_unicode_name_string_application_define(void *first_unused_memory)
  33. #endif
  34. {
  35. #ifndef FX_STANDALONE_ENABLE
  36. UCHAR *pointer;
  37. /* Setup the working pointer. */
  38. pointer = (UCHAR *) first_unused_memory;
  39. /* Create the main thread. */
  40. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  41. pointer, DEMO_STACK_SIZE,
  42. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  43. pointer = pointer + DEMO_STACK_SIZE;
  44. /* Setup memory for the RAM disk and the sector cache. */
  45. cache_buffer = pointer;
  46. pointer = pointer + CACHE_SIZE;
  47. ram_disk_memory = pointer;
  48. #endif
  49. /* Initialize the FileX system. */
  50. fx_system_initialize();
  51. #ifdef FX_STANDALONE_ENABLE
  52. ftest_0_entry(0);
  53. #endif
  54. }
  55. /* Define the test threads. */
  56. static void ftest_0_entry(ULONG thread_input)
  57. {
  58. UINT status;
  59. UCHAR buffer[512];
  60. #ifndef FX_DISABLE_ERROR_CHECKING
  61. UCHAR destination_name[300] = {0};
  62. UCHAR long_unicode_name[] = {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};
  63. #endif /* FX_DISABLE_ERROR_CHECKING */
  64. #ifndef FX_STANDALONE_ENABLE
  65. UCHAR *path_ptr;
  66. #else
  67. UCHAR path_ptr[1024];
  68. #endif
  69. FX_LOCAL_PATH local_path;
  70. FX_PARAMETER_NOT_USED(thread_input);
  71. /* Print out some test information banners. */
  72. printf("FileX Test: Unicode name string test...............................");
  73. /* Format the media. This needs to be done before opening it! */
  74. status = fx_media_format(&ram_disk,
  75. _fx_ram_driver, // Driver entry
  76. ram_disk_memory, // RAM disk memory pointer
  77. cache_buffer, // Media buffer pointer
  78. CACHE_SIZE, // Media buffer size
  79. "MY_RAM_DISK", // Volume Name
  80. 1, // Number of FATs
  81. 32, // Directory Entries
  82. 0, // Hidden sectors
  83. 512, // Total sectors
  84. 128, // Sector size
  85. 1, // Sectors per cluster
  86. 1, // Heads
  87. 1); // Sectors per track
  88. /* Open the ram_disk. */
  89. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  90. return_if_fail( status == FX_SUCCESS);
  91. #ifndef FX_DISABLE_ERROR_CHECKING
  92. /* Disable write protect */
  93. ram_disk.fx_media_driver_write_protect = FX_FALSE;
  94. /* lengthen the unicode name to include the last 0 */
  95. ULONG length = 15;
  96. /* Test creating directory. */
  97. status = fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *) destination_name);
  98. return_if_fail( status == FX_INVALID_NAME);
  99. /* Test creating file. */
  100. status = fx_unicode_file_create(&ram_disk, long_unicode_name, length, (CHAR *) destination_name);
  101. return_if_fail( status == FX_INVALID_NAME);
  102. #endif
  103. /* Create a directory named a...(254 times). */
  104. buffer[0] = '/';
  105. for (UINT i = 1; i < 300; i++)
  106. buffer[i] = 'a';
  107. buffer[255] = 0;
  108. /* Chenged to the specified directory and ensure the string related to current position is end as zero. */
  109. status = fx_directory_create( &ram_disk, (CHAR *)buffer);
  110. #ifndef FX_STANDALONE_ENABLE
  111. status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)buffer);
  112. #else
  113. status = fx_directory_default_set(&ram_disk, (CHAR *)buffer);
  114. #endif
  115. #ifndef FX_STANDALONE_ENABLE
  116. path_ptr = (UCHAR *)((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_string;
  117. #endif
  118. path_ptr[255] = 0;
  119. return_if_fail( status == FX_SUCCESS);
  120. /* Specify last found name as the directory we just created. */
  121. buffer[255] = '/';
  122. buffer[256] = 0;
  123. for (UINT i = 0; i <= 256; i++)
  124. ram_disk.fx_media_last_found_name[i] = (CHAR)buffer[i];
  125. /* Access the directory and see what will happen. */
  126. status = fx_directory_create( &ram_disk, "a");
  127. return_if_fail( status == FX_SUCCESS);
  128. status = fx_media_close(&ram_disk);
  129. return_if_fail( status == FX_SUCCESS);
  130. printf("SUCCESS!\n");
  131. test_control_return(0);
  132. }