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-2025
   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 <https://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 #if defined(HAVE_STRUCT_STAT_ST_BLKSIZE) && defined(HAVE_STRUCT_STAT_ST_BLOCKS)
  35 #    define STRUCT_STAT(size, blksize, blocks)                                                     \
  36         {                                                                                          \
  37             .st_size = size,                                                                       \
  38             .st_blksize = blksize,                                                                 \
  39             .st_blocks = blocks,                                                                   \
  40         }
  41 #elif defined(HAVE_STRUCT_STAT_ST_BLKSIZE)
  42 #    define STRUCT_STAT(st_blksize, st_blocks)                                                     \
  43         {                                                                                          \
  44             .st_size = size,                                                                       \
  45             .st_blksize = st_blksize,                                                              \
  46         }
  47 #elif defined(HAVE_STRUCT_STAT_ST_BLOCKS)
  48 #    define STRUCT_STAT(st_blksize, st_blocks)                                                     \
  49         {                                                                                          \
  50             .st_size = size,                                                                       \
  51             .st_blocks = st_blocks,                                                                \
  52         }
  53 #else
  54 #    define STRUCT_STAT(st_blksize, st_blocks)                                                     \
  55         {                                                                                          \
  56             .st_size = size,                                                                       \
  57         }
  58 #endif
  59 
  60 /* @DataSource("test_test_vfs_adjust_stat_ds") */
  61 static const struct test_vfs_adjust_stat_ds
  62 {
  63     struct stat etalon_stat;
  64 } test_vfs_adjust_stat_ds[] = {
  65     { .etalon_stat = STRUCT_STAT (0, 512, 0) },       // 0
  66     { .etalon_stat = STRUCT_STAT (4096, 512, 8) },    // 1
  67     { .etalon_stat = STRUCT_STAT (4096, 1024, 8) },   // 2
  68     { .etalon_stat = STRUCT_STAT (4096, 2048, 8) },   // 3
  69     { .etalon_stat = STRUCT_STAT (4096, 4096, 8) },   // 4
  70     { .etalon_stat = STRUCT_STAT (5000, 512, 10) },   // 5
  71     { .etalon_stat = STRUCT_STAT (5000, 1024, 10) },  // 6
  72     { .etalon_stat = STRUCT_STAT (5000, 2048, 12) },  // 7
  73     { .etalon_stat = STRUCT_STAT (5000, 4096, 16) },  // 8
  74 };
  75 
  76 #undef STRUCT_STAT
  77 
  78 /* --------------------------------------------------------------------------------------------- */
  79 
  80 /* @Test(dataSource = "test_vfs_adjust_stat_ds") */
  81 START_PARAMETRIZED_TEST (test_vfs_adjust_stat, test_vfs_adjust_stat_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
  82 {
  83 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  84     // given
  85     struct stat expected_stat;
  86 
  87     expected_stat.st_size = data->etalon_stat.st_size;
  88 #    ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  89     expected_stat.st_blksize = data->etalon_stat.st_blksize;
  90 #    endif
  91     // when
  92     vfs_adjust_stat (&expected_stat);
  93 
  94     // then
  95     ck_assert_int_eq (data->etalon_stat.st_blocks, expected_stat.st_blocks);
  96 #else
  97     ck_assert_int_eq (0, 0);
  98 #endif
  99 }
 100 END_PARAMETRIZED_TEST
 101 
 102 /* --------------------------------------------------------------------------------------------- */
 103 
 104 int
 105 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 106 {
 107     TCase *tc_core;
 108 
 109     tc_core = tcase_create ("Core");
 110 
 111     // Add new tests here: ***************
 112     mctest_add_parameterized_test (tc_core, test_vfs_adjust_stat, test_vfs_adjust_stat_ds);
 113     // ***********************************
 114 
 115     return mctest_run_all (tc_core);
 116 }
 117 
 118 /* --------------------------------------------------------------------------------------------- */

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