vfs_adjust_stat.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. lib/vfs - test vfs_adjust_stat() functionality
  3. Copyright (C) 2017-2024
  4. Free Software Foundation, Inc.
  5. Written by:
  6. Andrew Borodin <aborodin@vmail.ru>, 2017
  7. This file is part of the Midnight Commander.
  8. The Midnight Commander is free software: you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, either version 3 of the License,
  11. or (at your option) any later version.
  12. The Midnight Commander is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define TEST_SUITE_NAME "/lib/vfs"
  20. #include "tests/mctest.h"
  21. #include <sys/stat.h>
  22. /* --------------------------------------------------------------------------------------------- */
  23. /* @DataSource("test_test_vfs_adjust_stat_ds") */
  24. /* *INDENT-OFF* */
  25. static const struct test_vfs_adjust_stat_ds
  26. {
  27. struct stat etalon_stat;
  28. } test_vfs_adjust_stat_ds[] =
  29. {
  30. /* 0 */
  31. {
  32. .etalon_stat =
  33. {
  34. .st_size = 0,
  35. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  36. .st_blksize = 512,
  37. #endif
  38. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  39. .st_blocks = 0
  40. #endif
  41. }
  42. },
  43. /* 1 */
  44. {
  45. .etalon_stat =
  46. {
  47. .st_size = 4096,
  48. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  49. .st_blksize = 512,
  50. #endif
  51. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  52. .st_blocks = 8
  53. #endif
  54. }
  55. },
  56. /* 2 */
  57. {
  58. .etalon_stat =
  59. {
  60. .st_size = 4096,
  61. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  62. .st_blksize = 1024,
  63. #endif
  64. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  65. .st_blocks = 8
  66. #endif
  67. }
  68. },
  69. /* 3 */
  70. {
  71. .etalon_stat =
  72. {
  73. .st_size = 4096,
  74. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  75. .st_blksize = 2048,
  76. #endif
  77. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  78. .st_blocks = 8
  79. #endif
  80. }
  81. },
  82. /* 4 */
  83. {
  84. .etalon_stat =
  85. {
  86. .st_size = 4096,
  87. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  88. .st_blksize = 4096,
  89. #endif
  90. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  91. .st_blocks = 8
  92. #endif
  93. }
  94. },
  95. /* 5 */
  96. {
  97. .etalon_stat =
  98. {
  99. .st_size = 5000,
  100. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  101. .st_blksize = 512,
  102. #endif
  103. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  104. .st_blocks = 10
  105. #endif
  106. }
  107. },
  108. /* 6 */
  109. {
  110. .etalon_stat =
  111. {
  112. .st_size = 5000,
  113. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  114. .st_blksize = 1024,
  115. #endif
  116. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  117. .st_blocks = 10
  118. #endif
  119. }
  120. },
  121. /* 7 */
  122. {
  123. .etalon_stat =
  124. {
  125. .st_size = 5000,
  126. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  127. .st_blksize = 2048,
  128. #endif
  129. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  130. .st_blocks = 12
  131. #endif
  132. }
  133. },
  134. /* 8 */
  135. {
  136. .etalon_stat =
  137. {
  138. .st_size = 5000,
  139. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  140. .st_blksize = 4096,
  141. #endif
  142. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  143. .st_blocks = 16
  144. #endif
  145. }
  146. }
  147. };
  148. /* *INDENT-ON* */
  149. /* --------------------------------------------------------------------------------------------- */
  150. /* @Test(dataSource = "test_vfs_adjust_stat_ds") */
  151. /* *INDENT-OFF* */
  152. START_PARAMETRIZED_TEST (test_vfs_adjust_stat, test_vfs_adjust_stat_ds)
  153. /* *INDENT-ON* */
  154. {
  155. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  156. /* given */
  157. struct stat expected_stat;
  158. expected_stat.st_size = data->etalon_stat.st_size;
  159. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  160. expected_stat.st_blksize = data->etalon_stat.st_blksize;
  161. #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
  162. /* when */
  163. vfs_adjust_stat (&expected_stat);
  164. /* then */
  165. ck_assert_int_eq (data->etalon_stat.st_blocks, expected_stat.st_blocks);
  166. #else
  167. ck_assert_int_eq (0, 0);
  168. #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
  169. }
  170. /* *INDENT-OFF* */
  171. END_PARAMETRIZED_TEST
  172. /* *INDENT-ON* */
  173. /* --------------------------------------------------------------------------------------------- */
  174. int
  175. main (void)
  176. {
  177. TCase *tc_core;
  178. tc_core = tcase_create ("Core");
  179. /* Add new tests here: *************** */
  180. mctest_add_parameterized_test (tc_core, test_vfs_adjust_stat, test_vfs_adjust_stat_ds);
  181. /* *********************************** */
  182. return mctest_run_all (tc_core);
  183. }
  184. /* --------------------------------------------------------------------------------------------- */