root/tests/lib/vfs/vfs_adjust_stat.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. START_PARAMETRIZED_TEST
  2. main

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

/* [previous][next][first][last][top][bottom][index][help]  */