Ticket #4217: remove OS/distro-specific stuff.
[midnight-commander.git] / tests / lib / vfs / vfs_adjust_stat.c
blobbf04a85fd36ac32db5867fbc95679db79e450f93
1 /*
2 lib/vfs - test vfs_adjust_stat() functionality
4 Copyright (C) 2017-2021
5 Free Software Foundation, Inc.
7 Written by:
8 Andrew Borodin <aborodin@vmail.ru>, 2017
10 This file is part of the Midnight Commander.
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.
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.
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/>.
26 #define TEST_SUITE_NAME "/lib/vfs"
28 #include "tests/mctest.h"
30 #include <sys/stat.h>
32 /* --------------------------------------------------------------------------------------------- */
34 /* @DataSource("test_test_vfs_adjust_stat_ds") */
35 /* *INDENT-OFF* */
36 static const struct test_vfs_adjust_stat_ds
38 struct stat etalon_stat;
39 } test_vfs_adjust_stat_ds[] =
41 /* 0 */
43 .etalon_stat =
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
54 /* 1 */
56 .etalon_stat =
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
67 /* 2 */
69 .etalon_stat =
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
80 /* 3 */
82 .etalon_stat =
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
93 /* 4 */
95 .etalon_stat =
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
106 /* 5 */
108 .etalon_stat =
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
119 /* 6 */
121 .etalon_stat =
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
132 /* 7 */
134 .etalon_stat =
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
145 /* 8 */
147 .etalon_stat =
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
159 /* *INDENT-ON* */
161 /* --------------------------------------------------------------------------------------------- */
163 /* @Test(dataSource = "test_vfs_adjust_stat_ds") */
164 /* *INDENT-OFF* */
165 START_PARAMETRIZED_TEST (test_vfs_adjust_stat, test_vfs_adjust_stat_ds)
166 /* *INDENT-ON* */
168 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
169 /* given */
170 struct stat expected_stat;
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);
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 */
185 /* *INDENT-OFF* */
186 END_PARAMETRIZED_TEST
187 /* *INDENT-ON* */
189 /* --------------------------------------------------------------------------------------------- */
192 main (void)
194 TCase *tc_core;
196 tc_core = tcase_create ("Core");
198 /* Add new tests here: *************** */
199 mctest_add_parameterized_test (tc_core, test_vfs_adjust_stat, test_vfs_adjust_stat_ds);
200 /* *********************************** */
202 return mctest_run_all (tc_core);
205 /* --------------------------------------------------------------------------------------------- */