1 /*
2 * Library superblock type test program
3 *
4 * Copyright (C) 2010-2021, Joachim Metz <joachim.metz@gmail.com>
5 *
6 * Refer to AUTHORS for acknowledgements.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <common.h>
23 #include <byte_stream.h>
24 #include <file_stream.h>
25 #include <types.h>
26
27 #if defined( HAVE_STDLIB_H ) || defined( WINAPI )
28 #include <stdlib.h>
29 #endif
30
31 #include "fsext_test_functions.h"
32 #include "fsext_test_libbfio.h"
33 #include "fsext_test_libcerror.h"
34 #include "fsext_test_libfsext.h"
35 #include "fsext_test_macros.h"
36 #include "fsext_test_memory.h"
37 #include "fsext_test_unused.h"
38
39 #include "../libfsext/libfsext_superblock.h"
40
41 uint8_t fsext_test_superblock_data1[ 1024 ] = {
42 0x00, 0x05, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x0f, 0x00, 0x00,
43 0xf2, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0xe7, 0x12, 0xc1, 0x3f,
45 0x48, 0x13, 0xc1, 0x3f, 0x02, 0x00, 0x21, 0x00, 0x53, 0xef, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
46 0x68, 0x10, 0xc1, 0x3f, 0x00, 0x4e, 0xed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
47 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
48 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xe2, 0x30, 0x71, 0x19, 0x02, 0x4a, 0x42, 0x7f,
49 0xbd, 0x74, 0xdb, 0xe8, 0xa9, 0x56, 0x87, 0xa6, 0x4b, 0x57, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43,
50 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
106
107 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
108
109 /* Tests the libfsext_superblock_initialize function
110 * Returns 1 if successful or 0 if not
111 */
fsext_test_superblock_initialize(void)112 int fsext_test_superblock_initialize(
113 void )
114 {
115 libcerror_error_t *error = NULL;
116 libfsext_superblock_t *superblock = NULL;
117 int result = 0;
118
119 #if defined( HAVE_FSEXT_TEST_MEMORY )
120 int number_of_malloc_fail_tests = 1;
121 int number_of_memset_fail_tests = 1;
122 int test_number = 0;
123 #endif
124
125 /* Test regular cases
126 */
127 result = libfsext_superblock_initialize(
128 &superblock,
129 &error );
130
131 FSEXT_TEST_ASSERT_EQUAL_INT(
132 "result",
133 result,
134 1 );
135
136 FSEXT_TEST_ASSERT_IS_NOT_NULL(
137 "superblock",
138 superblock );
139
140 FSEXT_TEST_ASSERT_IS_NULL(
141 "error",
142 error );
143
144 result = libfsext_superblock_free(
145 &superblock,
146 &error );
147
148 FSEXT_TEST_ASSERT_EQUAL_INT(
149 "result",
150 result,
151 1 );
152
153 FSEXT_TEST_ASSERT_IS_NULL(
154 "superblock",
155 superblock );
156
157 FSEXT_TEST_ASSERT_IS_NULL(
158 "error",
159 error );
160
161 /* Test error cases
162 */
163 result = libfsext_superblock_initialize(
164 NULL,
165 &error );
166
167 FSEXT_TEST_ASSERT_EQUAL_INT(
168 "result",
169 result,
170 -1 );
171
172 FSEXT_TEST_ASSERT_IS_NOT_NULL(
173 "error",
174 error );
175
176 libcerror_error_free(
177 &error );
178
179 superblock = (libfsext_superblock_t *) 0x12345678UL;
180
181 result = libfsext_superblock_initialize(
182 &superblock,
183 &error );
184
185 superblock = NULL;
186
187 FSEXT_TEST_ASSERT_EQUAL_INT(
188 "result",
189 result,
190 -1 );
191
192 FSEXT_TEST_ASSERT_IS_NOT_NULL(
193 "error",
194 error );
195
196 libcerror_error_free(
197 &error );
198
199 #if defined( HAVE_FSEXT_TEST_MEMORY )
200
201 for( test_number = 0;
202 test_number < number_of_malloc_fail_tests;
203 test_number++ )
204 {
205 /* Test libfsext_superblock_initialize with malloc failing
206 */
207 fsext_test_malloc_attempts_before_fail = test_number;
208
209 result = libfsext_superblock_initialize(
210 &superblock,
211 &error );
212
213 if( fsext_test_malloc_attempts_before_fail != -1 )
214 {
215 fsext_test_malloc_attempts_before_fail = -1;
216
217 if( superblock != NULL )
218 {
219 libfsext_superblock_free(
220 &superblock,
221 NULL );
222 }
223 }
224 else
225 {
226 FSEXT_TEST_ASSERT_EQUAL_INT(
227 "result",
228 result,
229 -1 );
230
231 FSEXT_TEST_ASSERT_IS_NULL(
232 "superblock",
233 superblock );
234
235 FSEXT_TEST_ASSERT_IS_NOT_NULL(
236 "error",
237 error );
238
239 libcerror_error_free(
240 &error );
241 }
242 }
243 for( test_number = 0;
244 test_number < number_of_memset_fail_tests;
245 test_number++ )
246 {
247 /* Test libfsext_superblock_initialize with memset failing
248 */
249 fsext_test_memset_attempts_before_fail = test_number;
250
251 result = libfsext_superblock_initialize(
252 &superblock,
253 &error );
254
255 if( fsext_test_memset_attempts_before_fail != -1 )
256 {
257 fsext_test_memset_attempts_before_fail = -1;
258
259 if( superblock != NULL )
260 {
261 libfsext_superblock_free(
262 &superblock,
263 NULL );
264 }
265 }
266 else
267 {
268 FSEXT_TEST_ASSERT_EQUAL_INT(
269 "result",
270 result,
271 -1 );
272
273 FSEXT_TEST_ASSERT_IS_NULL(
274 "superblock",
275 superblock );
276
277 FSEXT_TEST_ASSERT_IS_NOT_NULL(
278 "error",
279 error );
280
281 libcerror_error_free(
282 &error );
283 }
284 }
285 #endif /* defined( HAVE_FSEXT_TEST_MEMORY ) */
286
287 return( 1 );
288
289 on_error:
290 if( error != NULL )
291 {
292 libcerror_error_free(
293 &error );
294 }
295 if( superblock != NULL )
296 {
297 libfsext_superblock_free(
298 &superblock,
299 NULL );
300 }
301 return( 0 );
302 }
303
304 /* Tests the libfsext_superblock_free function
305 * Returns 1 if successful or 0 if not
306 */
fsext_test_superblock_free(void)307 int fsext_test_superblock_free(
308 void )
309 {
310 libcerror_error_t *error = NULL;
311 int result = 0;
312
313 /* Test error cases
314 */
315 result = libfsext_superblock_free(
316 NULL,
317 &error );
318
319 FSEXT_TEST_ASSERT_EQUAL_INT(
320 "result",
321 result,
322 -1 );
323
324 FSEXT_TEST_ASSERT_IS_NOT_NULL(
325 "error",
326 error );
327
328 libcerror_error_free(
329 &error );
330
331 return( 1 );
332
333 on_error:
334 if( error != NULL )
335 {
336 libcerror_error_free(
337 &error );
338 }
339 return( 0 );
340 }
341
342 /* Tests the libfsext_superblock_read_data function
343 * Returns 1 if successful or 0 if not
344 */
fsext_test_superblock_read_data(void)345 int fsext_test_superblock_read_data(
346 void )
347 {
348 libcerror_error_t *error = NULL;
349 libfsext_superblock_t *superblock = NULL;
350 int result = 0;
351
352 /* Initialize test
353 */
354 result = libfsext_superblock_initialize(
355 &superblock,
356 &error );
357
358 FSEXT_TEST_ASSERT_EQUAL_INT(
359 "result",
360 result,
361 1 );
362
363 FSEXT_TEST_ASSERT_IS_NOT_NULL(
364 "superblock",
365 superblock );
366
367 FSEXT_TEST_ASSERT_IS_NULL(
368 "error",
369 error );
370
371 /* Test regular cases
372 */
373 result = libfsext_superblock_read_data(
374 superblock,
375 fsext_test_superblock_data1,
376 1024,
377 &error );
378
379 FSEXT_TEST_ASSERT_EQUAL_INT(
380 "result",
381 result,
382 1 );
383
384 FSEXT_TEST_ASSERT_IS_NULL(
385 "error",
386 error );
387
388 /* Test error cases
389 */
390 result = libfsext_superblock_read_data(
391 NULL,
392 fsext_test_superblock_data1,
393 1024,
394 &error );
395
396 FSEXT_TEST_ASSERT_EQUAL_INT(
397 "result",
398 result,
399 -1 );
400
401 FSEXT_TEST_ASSERT_IS_NOT_NULL(
402 "error",
403 error );
404
405 libcerror_error_free(
406 &error );
407
408 result = libfsext_superblock_read_data(
409 superblock,
410 NULL,
411 1024,
412 &error );
413
414 FSEXT_TEST_ASSERT_EQUAL_INT(
415 "result",
416 result,
417 -1 );
418
419 FSEXT_TEST_ASSERT_IS_NOT_NULL(
420 "error",
421 error );
422
423 libcerror_error_free(
424 &error );
425
426 result = libfsext_superblock_read_data(
427 superblock,
428 fsext_test_superblock_data1,
429 (size_t) SSIZE_MAX + 1,
430 &error );
431
432 FSEXT_TEST_ASSERT_EQUAL_INT(
433 "result",
434 result,
435 -1 );
436
437 FSEXT_TEST_ASSERT_IS_NOT_NULL(
438 "error",
439 error );
440
441 libcerror_error_free(
442 &error );
443
444 result = libfsext_superblock_read_data(
445 superblock,
446 fsext_test_superblock_data1,
447 0,
448 &error );
449
450 FSEXT_TEST_ASSERT_EQUAL_INT(
451 "result",
452 result,
453 -1 );
454
455 FSEXT_TEST_ASSERT_IS_NOT_NULL(
456 "error",
457 error );
458
459 libcerror_error_free(
460 &error );
461
462 /* Test error case where signature is invalid
463 */
464 byte_stream_copy_from_uint16_little_endian(
465 &( fsext_test_superblock_data1[ 56 ] ),
466 0xffff );
467
468 result = libfsext_superblock_read_data(
469 superblock,
470 fsext_test_superblock_data1,
471 1024,
472 &error );
473
474 byte_stream_copy_from_uint16_little_endian(
475 &( fsext_test_superblock_data1[ 56 ] ),
476 0xef53 );
477
478 FSEXT_TEST_ASSERT_EQUAL_INT(
479 "result",
480 result,
481 -1 );
482
483 FSEXT_TEST_ASSERT_IS_NOT_NULL(
484 "error",
485 error );
486
487 libcerror_error_free(
488 &error );
489
490 /* Clean up
491 */
492 result = libfsext_superblock_free(
493 &superblock,
494 &error );
495
496 FSEXT_TEST_ASSERT_EQUAL_INT(
497 "result",
498 result,
499 1 );
500
501 FSEXT_TEST_ASSERT_IS_NULL(
502 "superblock",
503 superblock );
504
505 FSEXT_TEST_ASSERT_IS_NULL(
506 "error",
507 error );
508
509 return( 1 );
510
511 on_error:
512 if( error != NULL )
513 {
514 libcerror_error_free(
515 &error );
516 }
517 if( superblock != NULL )
518 {
519 libfsext_superblock_free(
520 &superblock,
521 NULL );
522 }
523 return( 0 );
524 }
525
526 /* Tests the libfsext_superblock_read_file_io_handle function
527 * Returns 1 if successful or 0 if not
528 */
fsext_test_superblock_read_file_io_handle(void)529 int fsext_test_superblock_read_file_io_handle(
530 void )
531 {
532 libbfio_handle_t *file_io_handle = NULL;
533 libcerror_error_t *error = NULL;
534 libfsext_superblock_t *superblock = NULL;
535 int result = 0;
536
537 /* Initialize test
538 */
539 result = libfsext_superblock_initialize(
540 &superblock,
541 &error );
542
543 FSEXT_TEST_ASSERT_EQUAL_INT(
544 "result",
545 result,
546 1 );
547
548 FSEXT_TEST_ASSERT_IS_NOT_NULL(
549 "superblock",
550 superblock );
551
552 FSEXT_TEST_ASSERT_IS_NULL(
553 "error",
554 error );
555
556 /* Initialize file IO handle
557 */
558 result = fsext_test_open_file_io_handle(
559 &file_io_handle,
560 fsext_test_superblock_data1,
561 1024,
562 &error );
563
564 FSEXT_TEST_ASSERT_EQUAL_INT(
565 "result",
566 result,
567 1 );
568
569 FSEXT_TEST_ASSERT_IS_NOT_NULL(
570 "file_io_handle",
571 file_io_handle );
572
573 FSEXT_TEST_ASSERT_IS_NULL(
574 "error",
575 error );
576
577 /* Test regular cases
578 */
579 result = libfsext_superblock_read_file_io_handle(
580 superblock,
581 file_io_handle,
582 0,
583 &error );
584
585 FSEXT_TEST_ASSERT_EQUAL_INT(
586 "result",
587 result,
588 1 );
589
590 FSEXT_TEST_ASSERT_IS_NULL(
591 "error",
592 error );
593
594 /* Test error cases
595 */
596 result = libfsext_superblock_read_file_io_handle(
597 NULL,
598 file_io_handle,
599 0,
600 &error );
601
602 FSEXT_TEST_ASSERT_EQUAL_INT(
603 "result",
604 result,
605 -1 );
606
607 FSEXT_TEST_ASSERT_IS_NOT_NULL(
608 "error",
609 error );
610
611 libcerror_error_free(
612 &error );
613
614 result = libfsext_superblock_read_file_io_handle(
615 superblock,
616 NULL,
617 0,
618 &error );
619
620 FSEXT_TEST_ASSERT_EQUAL_INT(
621 "result",
622 result,
623 -1 );
624
625 FSEXT_TEST_ASSERT_IS_NOT_NULL(
626 "error",
627 error );
628
629 libcerror_error_free(
630 &error );
631
632 result = libfsext_superblock_read_file_io_handle(
633 superblock,
634 file_io_handle,
635 -1,
636 &error );
637
638 FSEXT_TEST_ASSERT_EQUAL_INT(
639 "result",
640 result,
641 -1 );
642
643 FSEXT_TEST_ASSERT_IS_NOT_NULL(
644 "error",
645 error );
646
647 libcerror_error_free(
648 &error );
649
650 /* Test data invalid
651 */
652 byte_stream_copy_from_uint16_little_endian(
653 &( fsext_test_superblock_data1[ 56 ] ),
654 0xffff );
655
656 result = libfsext_superblock_read_file_io_handle(
657 superblock,
658 file_io_handle,
659 0,
660 &error );
661
662 byte_stream_copy_from_uint16_little_endian(
663 &( fsext_test_superblock_data1[ 56 ] ),
664 0xef53 );
665
666 FSEXT_TEST_ASSERT_EQUAL_INT(
667 "result",
668 result,
669 -1 );
670
671 FSEXT_TEST_ASSERT_IS_NOT_NULL(
672 "error",
673 error );
674
675 libcerror_error_free(
676 &error );
677
678 /* Clean up file IO handle
679 */
680 result = fsext_test_close_file_io_handle(
681 &file_io_handle,
682 &error );
683
684 FSEXT_TEST_ASSERT_EQUAL_INT(
685 "result",
686 result,
687 0 );
688
689 FSEXT_TEST_ASSERT_IS_NULL(
690 "error",
691 error );
692
693 /* Test data too small
694 */
695 result = fsext_test_open_file_io_handle(
696 &file_io_handle,
697 fsext_test_superblock_data1,
698 8,
699 &error );
700
701 FSEXT_TEST_ASSERT_EQUAL_INT(
702 "result",
703 result,
704 1 );
705
706 FSEXT_TEST_ASSERT_IS_NOT_NULL(
707 "file_io_handle",
708 file_io_handle );
709
710 FSEXT_TEST_ASSERT_IS_NULL(
711 "error",
712 error );
713
714 result = libfsext_superblock_read_file_io_handle(
715 superblock,
716 file_io_handle,
717 0,
718 &error );
719
720 FSEXT_TEST_ASSERT_EQUAL_INT(
721 "result",
722 result,
723 -1 );
724
725 FSEXT_TEST_ASSERT_IS_NOT_NULL(
726 "error",
727 error );
728
729 libcerror_error_free(
730 &error );
731
732 result = fsext_test_close_file_io_handle(
733 &file_io_handle,
734 &error );
735
736 FSEXT_TEST_ASSERT_EQUAL_INT(
737 "result",
738 result,
739 0 );
740
741 FSEXT_TEST_ASSERT_IS_NULL(
742 "error",
743 error );
744
745 /* Clean up
746 */
747 result = libfsext_superblock_free(
748 &superblock,
749 &error );
750
751 FSEXT_TEST_ASSERT_EQUAL_INT(
752 "result",
753 result,
754 1 );
755
756 FSEXT_TEST_ASSERT_IS_NULL(
757 "superblock",
758 superblock );
759
760 FSEXT_TEST_ASSERT_IS_NULL(
761 "error",
762 error );
763
764 return( 1 );
765
766 on_error:
767 if( error != NULL )
768 {
769 libcerror_error_free(
770 &error );
771 }
772 if( file_io_handle != NULL )
773 {
774 libbfio_handle_free(
775 &file_io_handle,
776 NULL );
777 }
778 if( superblock != NULL )
779 {
780 libfsext_superblock_free(
781 &superblock,
782 NULL );
783 }
784 return( 0 );
785 }
786
787 #endif /* defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT ) */
788
789 /* The main program
790 */
791 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
wmain(int argc FSEXT_TEST_ATTRIBUTE_UNUSED,wchar_t * const argv[]FSEXT_TEST_ATTRIBUTE_UNUSED)792 int wmain(
793 int argc FSEXT_TEST_ATTRIBUTE_UNUSED,
794 wchar_t * const argv[] FSEXT_TEST_ATTRIBUTE_UNUSED )
795 #else
796 int main(
797 int argc FSEXT_TEST_ATTRIBUTE_UNUSED,
798 char * const argv[] FSEXT_TEST_ATTRIBUTE_UNUSED )
799 #endif
800 {
801 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
802 libcerror_error_t *error = NULL;
803 libfsext_superblock_t *superblock = NULL;
804 int result = 0;
805 #endif
806
807 FSEXT_TEST_UNREFERENCED_PARAMETER( argc )
808 FSEXT_TEST_UNREFERENCED_PARAMETER( argv )
809
810 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
811
812 FSEXT_TEST_RUN(
813 "libfsext_superblock_initialize",
814 fsext_test_superblock_initialize );
815
816 FSEXT_TEST_RUN(
817 "libfsext_superblock_free",
818 fsext_test_superblock_free );
819
820 FSEXT_TEST_RUN(
821 "libfsext_superblock_read_data",
822 fsext_test_superblock_read_data );
823
824 FSEXT_TEST_RUN(
825 "libfsext_superblock_read_file_io_handle",
826 fsext_test_superblock_read_file_io_handle );
827
828 #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )
829
830 /* Initialize superblock for tests
831 */
832 result = libfsext_superblock_initialize(
833 &superblock,
834 &error );
835
836 FSEXT_TEST_ASSERT_EQUAL_INT(
837 "result",
838 result,
839 1 );
840
841 FSEXT_TEST_ASSERT_IS_NOT_NULL(
842 "superblock",
843 superblock );
844
845 FSEXT_TEST_ASSERT_IS_NULL(
846 "error",
847 error );
848
849 result = libfsext_superblock_read_data(
850 superblock,
851 fsext_test_superblock_data1,
852 1024,
853 &error );
854
855 FSEXT_TEST_ASSERT_EQUAL_INT(
856 "result",
857 result,
858 1 );
859
860 FSEXT_TEST_ASSERT_IS_NULL(
861 "error",
862 error );
863
864 /* Run tests
865 */
866 /* TODO: add tests for libfsext_superblock_get_utf8_volume_label_size */
867
868 /* TODO: add tests for libfsext_superblock_get_utf8_volume_label */
869
870 /* TODO: add tests for libfsext_superblock_get_utf16_volume_label_size */
871
872 /* TODO: add tests for libfsext_superblock_get_utf16_volume_label */
873
874 /* TODO: add tests for libfsext_superblock_get_utf8_last_mount_path_size */
875
876 /* TODO: add tests for libfsext_superblock_get_utf8_last_mount_path */
877
878 /* TODO: add tests for libfsext_superblock_get_utf16_last_mount_path_size */
879
880 /* TODO: add tests for libfsext_superblock_get_utf16_last_mount_path */
881
882 /* Clean up
883 */
884 result = libfsext_superblock_free(
885 &superblock,
886 &error );
887
888 FSEXT_TEST_ASSERT_EQUAL_INT(
889 "result",
890 result,
891 1 );
892
893 FSEXT_TEST_ASSERT_IS_NULL(
894 "superblock",
895 superblock );
896
897 FSEXT_TEST_ASSERT_IS_NULL(
898 "error",
899 error );
900
901 #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */
902 #endif /* defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT ) */
903
904 return( EXIT_SUCCESS );
905
906 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
907
908 on_error:
909 #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )
910 if( error != NULL )
911 {
912 libcerror_error_free(
913 &error );
914 }
915 if( superblock != NULL )
916 {
917 libfsext_superblock_free(
918 &superblock,
919 NULL );
920 }
921 #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */
922
923 return( EXIT_FAILURE );
924
925 #endif /* defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT ) */
926 }
927
928