1 /*
2 * Library volume 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 <file_stream.h>
24 #include <narrow_string.h>
25 #include <system_string.h>
26 #include <types.h>
27 #include <wide_string.h>
28
29 #if defined( HAVE_STDLIB_H ) || defined( WINAPI )
30 #include <stdlib.h>
31 #endif
32
33 #include "fsext_test_functions.h"
34 #include "fsext_test_getopt.h"
35 #include "fsext_test_libbfio.h"
36 #include "fsext_test_libcerror.h"
37 #include "fsext_test_libfsext.h"
38 #include "fsext_test_macros.h"
39 #include "fsext_test_memory.h"
40 #include "fsext_test_unused.h"
41
42 #include "../libfsext/libfsext_volume.h"
43
44 #if !defined( LIBFSEXT_HAVE_BFIO )
45
46 LIBFSEXT_EXTERN \
47 int libfsext_check_volume_signature_file_io_handle(
48 libbfio_handle_t *file_io_handle,
49 libcerror_error_t **error );
50
51 LIBFSEXT_EXTERN \
52 int libfsext_volume_open_file_io_handle(
53 libfsext_volume_t *volume,
54 libbfio_handle_t *file_io_handle,
55 int access_flags,
56 libfsext_error_t **error );
57
58 #endif /* !defined( LIBFSEXT_HAVE_BFIO ) */
59
60 #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) && SIZEOF_WCHAR_T != 2 && SIZEOF_WCHAR_T != 4
61 #error Unsupported size of wchar_t
62 #endif
63
64 /* Define to make fsext_test_volume generate verbose output
65 #define FSEXT_TEST_VOLUME_VERBOSE
66 */
67
68 /* Creates and opens a source volume
69 * Returns 1 if successful or -1 on error
70 */
fsext_test_volume_open_source(libfsext_volume_t ** volume,libbfio_handle_t * file_io_handle,libcerror_error_t ** error)71 int fsext_test_volume_open_source(
72 libfsext_volume_t **volume,
73 libbfio_handle_t *file_io_handle,
74 libcerror_error_t **error )
75 {
76 static char *function = "fsext_test_volume_open_source";
77 int result = 0;
78
79 if( volume == NULL )
80 {
81 libcerror_error_set(
82 error,
83 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
84 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
85 "%s: invalid volume.",
86 function );
87
88 return( -1 );
89 }
90 if( file_io_handle == NULL )
91 {
92 libcerror_error_set(
93 error,
94 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
95 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
96 "%s: invalid file IO handle.",
97 function );
98
99 return( -1 );
100 }
101 if( libfsext_volume_initialize(
102 volume,
103 error ) != 1 )
104 {
105 libcerror_error_set(
106 error,
107 LIBCERROR_ERROR_DOMAIN_RUNTIME,
108 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
109 "%s: unable to initialize volume.",
110 function );
111
112 goto on_error;
113 }
114 result = libfsext_volume_open_file_io_handle(
115 *volume,
116 file_io_handle,
117 LIBFSEXT_OPEN_READ,
118 error );
119
120 if( result != 1 )
121 {
122 libcerror_error_set(
123 error,
124 LIBCERROR_ERROR_DOMAIN_IO,
125 LIBCERROR_IO_ERROR_OPEN_FAILED,
126 "%s: unable to open volume.",
127 function );
128
129 goto on_error;
130 }
131 return( 1 );
132
133 on_error:
134 if( *volume != NULL )
135 {
136 libfsext_volume_free(
137 volume,
138 NULL );
139 }
140 return( -1 );
141 }
142
143 /* Closes and frees a source volume
144 * Returns 1 if successful or -1 on error
145 */
fsext_test_volume_close_source(libfsext_volume_t ** volume,libcerror_error_t ** error)146 int fsext_test_volume_close_source(
147 libfsext_volume_t **volume,
148 libcerror_error_t **error )
149 {
150 static char *function = "fsext_test_volume_close_source";
151 int result = 0;
152
153 if( volume == NULL )
154 {
155 libcerror_error_set(
156 error,
157 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
158 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
159 "%s: invalid volume.",
160 function );
161
162 return( -1 );
163 }
164 if( libfsext_volume_close(
165 *volume,
166 error ) != 0 )
167 {
168 libcerror_error_set(
169 error,
170 LIBCERROR_ERROR_DOMAIN_IO,
171 LIBCERROR_IO_ERROR_CLOSE_FAILED,
172 "%s: unable to close volume.",
173 function );
174
175 result = -1;
176 }
177 if( libfsext_volume_free(
178 volume,
179 error ) != 1 )
180 {
181 libcerror_error_set(
182 error,
183 LIBCERROR_ERROR_DOMAIN_RUNTIME,
184 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
185 "%s: unable to free volume.",
186 function );
187
188 result = -1;
189 }
190 return( result );
191 }
192
193 /* Tests the libfsext_volume_initialize function
194 * Returns 1 if successful or 0 if not
195 */
fsext_test_volume_initialize(void)196 int fsext_test_volume_initialize(
197 void )
198 {
199 libcerror_error_t *error = NULL;
200 libfsext_volume_t *volume = NULL;
201 int result = 0;
202
203 #if defined( HAVE_FSEXT_TEST_MEMORY )
204 int number_of_malloc_fail_tests = 1;
205 int number_of_memset_fail_tests = 1;
206 int test_number = 0;
207 #endif
208
209 /* Test regular cases
210 */
211 result = libfsext_volume_initialize(
212 &volume,
213 &error );
214
215 FSEXT_TEST_ASSERT_EQUAL_INT(
216 "result",
217 result,
218 1 );
219
220 FSEXT_TEST_ASSERT_IS_NOT_NULL(
221 "volume",
222 volume );
223
224 FSEXT_TEST_ASSERT_IS_NULL(
225 "error",
226 error );
227
228 result = libfsext_volume_free(
229 &volume,
230 &error );
231
232 FSEXT_TEST_ASSERT_EQUAL_INT(
233 "result",
234 result,
235 1 );
236
237 FSEXT_TEST_ASSERT_IS_NULL(
238 "volume",
239 volume );
240
241 FSEXT_TEST_ASSERT_IS_NULL(
242 "error",
243 error );
244
245 /* Test error cases
246 */
247 result = libfsext_volume_initialize(
248 NULL,
249 &error );
250
251 FSEXT_TEST_ASSERT_EQUAL_INT(
252 "result",
253 result,
254 -1 );
255
256 FSEXT_TEST_ASSERT_IS_NOT_NULL(
257 "error",
258 error );
259
260 libcerror_error_free(
261 &error );
262
263 volume = (libfsext_volume_t *) 0x12345678UL;
264
265 result = libfsext_volume_initialize(
266 &volume,
267 &error );
268
269 FSEXT_TEST_ASSERT_EQUAL_INT(
270 "result",
271 result,
272 -1 );
273
274 FSEXT_TEST_ASSERT_IS_NOT_NULL(
275 "error",
276 error );
277
278 libcerror_error_free(
279 &error );
280
281 volume = NULL;
282
283 #if defined( HAVE_FSEXT_TEST_MEMORY )
284
285 for( test_number = 0;
286 test_number < number_of_malloc_fail_tests;
287 test_number++ )
288 {
289 /* Test libfsext_volume_initialize with malloc failing
290 */
291 fsext_test_malloc_attempts_before_fail = test_number;
292
293 result = libfsext_volume_initialize(
294 &volume,
295 &error );
296
297 if( fsext_test_malloc_attempts_before_fail != -1 )
298 {
299 fsext_test_malloc_attempts_before_fail = -1;
300
301 if( volume != NULL )
302 {
303 libfsext_volume_free(
304 &volume,
305 NULL );
306 }
307 }
308 else
309 {
310 FSEXT_TEST_ASSERT_EQUAL_INT(
311 "result",
312 result,
313 -1 );
314
315 FSEXT_TEST_ASSERT_IS_NULL(
316 "volume",
317 volume );
318
319 FSEXT_TEST_ASSERT_IS_NOT_NULL(
320 "error",
321 error );
322
323 libcerror_error_free(
324 &error );
325 }
326 }
327 for( test_number = 0;
328 test_number < number_of_memset_fail_tests;
329 test_number++ )
330 {
331 /* Test libfsext_volume_initialize with memset failing
332 */
333 fsext_test_memset_attempts_before_fail = test_number;
334
335 result = libfsext_volume_initialize(
336 &volume,
337 &error );
338
339 if( fsext_test_memset_attempts_before_fail != -1 )
340 {
341 fsext_test_memset_attempts_before_fail = -1;
342
343 if( volume != NULL )
344 {
345 libfsext_volume_free(
346 &volume,
347 NULL );
348 }
349 }
350 else
351 {
352 FSEXT_TEST_ASSERT_EQUAL_INT(
353 "result",
354 result,
355 -1 );
356
357 FSEXT_TEST_ASSERT_IS_NULL(
358 "volume",
359 volume );
360
361 FSEXT_TEST_ASSERT_IS_NOT_NULL(
362 "error",
363 error );
364
365 libcerror_error_free(
366 &error );
367 }
368 }
369 #endif /* defined( HAVE_FSEXT_TEST_MEMORY ) */
370
371 return( 1 );
372
373 on_error:
374 if( error != NULL )
375 {
376 libcerror_error_free(
377 &error );
378 }
379 if( volume != NULL )
380 {
381 libfsext_volume_free(
382 &volume,
383 NULL );
384 }
385 return( 0 );
386 }
387
388 /* Tests the libfsext_volume_free function
389 * Returns 1 if successful or 0 if not
390 */
fsext_test_volume_free(void)391 int fsext_test_volume_free(
392 void )
393 {
394 libcerror_error_t *error = NULL;
395 int result = 0;
396
397 /* Test error cases
398 */
399 result = libfsext_volume_free(
400 NULL,
401 &error );
402
403 FSEXT_TEST_ASSERT_EQUAL_INT(
404 "result",
405 result,
406 -1 );
407
408 FSEXT_TEST_ASSERT_IS_NOT_NULL(
409 "error",
410 error );
411
412 libcerror_error_free(
413 &error );
414
415 return( 1 );
416
417 on_error:
418 if( error != NULL )
419 {
420 libcerror_error_free(
421 &error );
422 }
423 return( 0 );
424 }
425
426 /* Tests the libfsext_volume_open function
427 * Returns 1 if successful or 0 if not
428 */
fsext_test_volume_open(const system_character_t * source)429 int fsext_test_volume_open(
430 const system_character_t *source )
431 {
432 char narrow_source[ 256 ];
433
434 libcerror_error_t *error = NULL;
435 libfsext_volume_t *volume = NULL;
436 int result = 0;
437
438 /* Initialize test
439 */
440 result = fsext_test_get_narrow_source(
441 source,
442 narrow_source,
443 256,
444 &error );
445
446 FSEXT_TEST_ASSERT_EQUAL_INT(
447 "result",
448 result,
449 1 );
450
451 FSEXT_TEST_ASSERT_IS_NULL(
452 "error",
453 error );
454
455 result = libfsext_volume_initialize(
456 &volume,
457 &error );
458
459 FSEXT_TEST_ASSERT_EQUAL_INT(
460 "result",
461 result,
462 1 );
463
464 FSEXT_TEST_ASSERT_IS_NOT_NULL(
465 "volume",
466 volume );
467
468 FSEXT_TEST_ASSERT_IS_NULL(
469 "error",
470 error );
471
472 /* Test open
473 */
474 result = libfsext_volume_open(
475 volume,
476 narrow_source,
477 LIBFSEXT_OPEN_READ,
478 &error );
479
480 FSEXT_TEST_ASSERT_EQUAL_INT(
481 "result",
482 result,
483 1 );
484
485 FSEXT_TEST_ASSERT_IS_NULL(
486 "error",
487 error );
488
489 /* Test error cases
490 */
491 result = libfsext_volume_open(
492 NULL,
493 narrow_source,
494 LIBFSEXT_OPEN_READ,
495 &error );
496
497 FSEXT_TEST_ASSERT_EQUAL_INT(
498 "result",
499 result,
500 -1 );
501
502 FSEXT_TEST_ASSERT_IS_NOT_NULL(
503 "error",
504 error );
505
506 libcerror_error_free(
507 &error );
508
509 result = libfsext_volume_open(
510 volume,
511 NULL,
512 LIBFSEXT_OPEN_READ,
513 &error );
514
515 FSEXT_TEST_ASSERT_EQUAL_INT(
516 "result",
517 result,
518 -1 );
519
520 FSEXT_TEST_ASSERT_IS_NOT_NULL(
521 "error",
522 error );
523
524 libcerror_error_free(
525 &error );
526
527 result = libfsext_volume_open(
528 volume,
529 narrow_source,
530 -1,
531 &error );
532
533 FSEXT_TEST_ASSERT_EQUAL_INT(
534 "result",
535 result,
536 -1 );
537
538 FSEXT_TEST_ASSERT_IS_NOT_NULL(
539 "error",
540 error );
541
542 libcerror_error_free(
543 &error );
544
545 /* Test open when already opened
546 */
547 result = libfsext_volume_open(
548 volume,
549 narrow_source,
550 LIBFSEXT_OPEN_READ,
551 &error );
552
553 FSEXT_TEST_ASSERT_EQUAL_INT(
554 "result",
555 result,
556 -1 );
557
558 FSEXT_TEST_ASSERT_IS_NOT_NULL(
559 "error",
560 error );
561
562 libcerror_error_free(
563 &error );
564
565 /* Clean up
566 */
567 result = libfsext_volume_free(
568 &volume,
569 &error );
570
571 FSEXT_TEST_ASSERT_EQUAL_INT(
572 "result",
573 result,
574 1 );
575
576 FSEXT_TEST_ASSERT_IS_NULL(
577 "volume",
578 volume );
579
580 FSEXT_TEST_ASSERT_IS_NULL(
581 "error",
582 error );
583
584 return( 1 );
585
586 on_error:
587 if( error != NULL )
588 {
589 libcerror_error_free(
590 &error );
591 }
592 if( volume != NULL )
593 {
594 libfsext_volume_free(
595 &volume,
596 NULL );
597 }
598 return( 0 );
599 }
600
601 #if defined( HAVE_WIDE_CHARACTER_TYPE )
602
603 /* Tests the libfsext_volume_open_wide function
604 * Returns 1 if successful or 0 if not
605 */
fsext_test_volume_open_wide(const system_character_t * source)606 int fsext_test_volume_open_wide(
607 const system_character_t *source )
608 {
609 wchar_t wide_source[ 256 ];
610
611 libcerror_error_t *error = NULL;
612 libfsext_volume_t *volume = NULL;
613 int result = 0;
614
615 /* Initialize test
616 */
617 result = fsext_test_get_wide_source(
618 source,
619 wide_source,
620 256,
621 &error );
622
623 FSEXT_TEST_ASSERT_EQUAL_INT(
624 "result",
625 result,
626 1 );
627
628 FSEXT_TEST_ASSERT_IS_NULL(
629 "error",
630 error );
631
632 result = libfsext_volume_initialize(
633 &volume,
634 &error );
635
636 FSEXT_TEST_ASSERT_EQUAL_INT(
637 "result",
638 result,
639 1 );
640
641 FSEXT_TEST_ASSERT_IS_NOT_NULL(
642 "volume",
643 volume );
644
645 FSEXT_TEST_ASSERT_IS_NULL(
646 "error",
647 error );
648
649 /* Test open
650 */
651 result = libfsext_volume_open_wide(
652 volume,
653 wide_source,
654 LIBFSEXT_OPEN_READ,
655 &error );
656
657 FSEXT_TEST_ASSERT_EQUAL_INT(
658 "result",
659 result,
660 1 );
661
662 FSEXT_TEST_ASSERT_IS_NULL(
663 "error",
664 error );
665
666 /* Test error cases
667 */
668 result = libfsext_volume_open_wide(
669 NULL,
670 wide_source,
671 LIBFSEXT_OPEN_READ,
672 &error );
673
674 FSEXT_TEST_ASSERT_EQUAL_INT(
675 "result",
676 result,
677 -1 );
678
679 FSEXT_TEST_ASSERT_IS_NOT_NULL(
680 "error",
681 error );
682
683 libcerror_error_free(
684 &error );
685
686 result = libfsext_volume_open_wide(
687 volume,
688 NULL,
689 LIBFSEXT_OPEN_READ,
690 &error );
691
692 FSEXT_TEST_ASSERT_EQUAL_INT(
693 "result",
694 result,
695 -1 );
696
697 FSEXT_TEST_ASSERT_IS_NOT_NULL(
698 "error",
699 error );
700
701 libcerror_error_free(
702 &error );
703
704 result = libfsext_volume_open_wide(
705 volume,
706 wide_source,
707 -1,
708 &error );
709
710 FSEXT_TEST_ASSERT_EQUAL_INT(
711 "result",
712 result,
713 -1 );
714
715 FSEXT_TEST_ASSERT_IS_NOT_NULL(
716 "error",
717 error );
718
719 libcerror_error_free(
720 &error );
721
722 /* Test open when already opened
723 */
724 result = libfsext_volume_open_wide(
725 volume,
726 wide_source,
727 LIBFSEXT_OPEN_READ,
728 &error );
729
730 FSEXT_TEST_ASSERT_EQUAL_INT(
731 "result",
732 result,
733 -1 );
734
735 FSEXT_TEST_ASSERT_IS_NOT_NULL(
736 "error",
737 error );
738
739 libcerror_error_free(
740 &error );
741
742 /* Clean up
743 */
744 result = libfsext_volume_free(
745 &volume,
746 &error );
747
748 FSEXT_TEST_ASSERT_EQUAL_INT(
749 "result",
750 result,
751 1 );
752
753 FSEXT_TEST_ASSERT_IS_NULL(
754 "volume",
755 volume );
756
757 FSEXT_TEST_ASSERT_IS_NULL(
758 "error",
759 error );
760
761 return( 1 );
762
763 on_error:
764 if( error != NULL )
765 {
766 libcerror_error_free(
767 &error );
768 }
769 if( volume != NULL )
770 {
771 libfsext_volume_free(
772 &volume,
773 NULL );
774 }
775 return( 0 );
776 }
777
778 #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */
779
780 /* Tests the libfsext_volume_open_file_io_handle function
781 * Returns 1 if successful or 0 if not
782 */
fsext_test_volume_open_file_io_handle(const system_character_t * source)783 int fsext_test_volume_open_file_io_handle(
784 const system_character_t *source )
785 {
786 libbfio_handle_t *file_io_handle = NULL;
787 libcerror_error_t *error = NULL;
788 libfsext_volume_t *volume = NULL;
789 size_t string_length = 0;
790 int result = 0;
791
792 /* Initialize test
793 */
794 result = libbfio_file_initialize(
795 &file_io_handle,
796 &error );
797
798 FSEXT_TEST_ASSERT_EQUAL_INT(
799 "result",
800 result,
801 1 );
802
803 FSEXT_TEST_ASSERT_IS_NOT_NULL(
804 "file_io_handle",
805 file_io_handle );
806
807 FSEXT_TEST_ASSERT_IS_NULL(
808 "error",
809 error );
810
811 string_length = system_string_length(
812 source );
813
814 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
815 result = libbfio_file_set_name_wide(
816 file_io_handle,
817 source,
818 string_length,
819 &error );
820 #else
821 result = libbfio_file_set_name(
822 file_io_handle,
823 source,
824 string_length,
825 &error );
826 #endif
827 FSEXT_TEST_ASSERT_EQUAL_INT(
828 "result",
829 result,
830 1 );
831
832 FSEXT_TEST_ASSERT_IS_NULL(
833 "error",
834 error );
835
836 result = libfsext_volume_initialize(
837 &volume,
838 &error );
839
840 FSEXT_TEST_ASSERT_EQUAL_INT(
841 "result",
842 result,
843 1 );
844
845 FSEXT_TEST_ASSERT_IS_NOT_NULL(
846 "volume",
847 volume );
848
849 FSEXT_TEST_ASSERT_IS_NULL(
850 "error",
851 error );
852
853 /* Test open
854 */
855 result = libfsext_volume_open_file_io_handle(
856 volume,
857 file_io_handle,
858 LIBFSEXT_OPEN_READ,
859 &error );
860
861 FSEXT_TEST_ASSERT_EQUAL_INT(
862 "result",
863 result,
864 1 );
865
866 FSEXT_TEST_ASSERT_IS_NULL(
867 "error",
868 error );
869
870 /* Test error cases
871 */
872 result = libfsext_volume_open_file_io_handle(
873 NULL,
874 file_io_handle,
875 LIBFSEXT_OPEN_READ,
876 &error );
877
878 FSEXT_TEST_ASSERT_EQUAL_INT(
879 "result",
880 result,
881 -1 );
882
883 FSEXT_TEST_ASSERT_IS_NOT_NULL(
884 "error",
885 error );
886
887 libcerror_error_free(
888 &error );
889
890 result = libfsext_volume_open_file_io_handle(
891 volume,
892 NULL,
893 LIBFSEXT_OPEN_READ,
894 &error );
895
896 FSEXT_TEST_ASSERT_EQUAL_INT(
897 "result",
898 result,
899 -1 );
900
901 FSEXT_TEST_ASSERT_IS_NOT_NULL(
902 "error",
903 error );
904
905 libcerror_error_free(
906 &error );
907
908 result = libfsext_volume_open_file_io_handle(
909 volume,
910 file_io_handle,
911 -1,
912 &error );
913
914 FSEXT_TEST_ASSERT_EQUAL_INT(
915 "result",
916 result,
917 -1 );
918
919 FSEXT_TEST_ASSERT_IS_NOT_NULL(
920 "error",
921 error );
922
923 libcerror_error_free(
924 &error );
925
926 /* Test open when already opened
927 */
928 result = libfsext_volume_open_file_io_handle(
929 volume,
930 file_io_handle,
931 LIBFSEXT_OPEN_READ,
932 &error );
933
934 FSEXT_TEST_ASSERT_EQUAL_INT(
935 "result",
936 result,
937 -1 );
938
939 FSEXT_TEST_ASSERT_IS_NOT_NULL(
940 "error",
941 error );
942
943 libcerror_error_free(
944 &error );
945
946 /* Clean up
947 */
948 result = libfsext_volume_free(
949 &volume,
950 &error );
951
952 FSEXT_TEST_ASSERT_EQUAL_INT(
953 "result",
954 result,
955 1 );
956
957 FSEXT_TEST_ASSERT_IS_NULL(
958 "volume",
959 volume );
960
961 FSEXT_TEST_ASSERT_IS_NULL(
962 "error",
963 error );
964
965 result = libbfio_handle_free(
966 &file_io_handle,
967 &error );
968
969 FSEXT_TEST_ASSERT_EQUAL_INT(
970 "result",
971 result,
972 1 );
973
974 FSEXT_TEST_ASSERT_IS_NULL(
975 "file_io_handle",
976 file_io_handle );
977
978 FSEXT_TEST_ASSERT_IS_NULL(
979 "error",
980 error );
981
982 return( 1 );
983
984 on_error:
985 if( error != NULL )
986 {
987 libcerror_error_free(
988 &error );
989 }
990 if( volume != NULL )
991 {
992 libfsext_volume_free(
993 &volume,
994 NULL );
995 }
996 if( file_io_handle != NULL )
997 {
998 libbfio_handle_free(
999 &file_io_handle,
1000 NULL );
1001 }
1002 return( 0 );
1003 }
1004
1005 /* Tests the libfsext_volume_close function
1006 * Returns 1 if successful or 0 if not
1007 */
fsext_test_volume_close(void)1008 int fsext_test_volume_close(
1009 void )
1010 {
1011 libcerror_error_t *error = NULL;
1012 int result = 0;
1013
1014 /* Test error cases
1015 */
1016 result = libfsext_volume_close(
1017 NULL,
1018 &error );
1019
1020 FSEXT_TEST_ASSERT_EQUAL_INT(
1021 "result",
1022 result,
1023 -1 );
1024
1025 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1026 "error",
1027 error );
1028
1029 libcerror_error_free(
1030 &error );
1031
1032 return( 1 );
1033
1034 on_error:
1035 if( error != NULL )
1036 {
1037 libcerror_error_free(
1038 &error );
1039 }
1040 return( 0 );
1041 }
1042
1043 /* Tests the libfsext_volume_open and libfsext_volume_close functions
1044 * Returns 1 if successful or 0 if not
1045 */
fsext_test_volume_open_close(const system_character_t * source)1046 int fsext_test_volume_open_close(
1047 const system_character_t *source )
1048 {
1049 libcerror_error_t *error = NULL;
1050 libfsext_volume_t *volume = NULL;
1051 int result = 0;
1052
1053 /* Initialize test
1054 */
1055 result = libfsext_volume_initialize(
1056 &volume,
1057 &error );
1058
1059 FSEXT_TEST_ASSERT_EQUAL_INT(
1060 "result",
1061 result,
1062 1 );
1063
1064 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1065 "volume",
1066 volume );
1067
1068 FSEXT_TEST_ASSERT_IS_NULL(
1069 "error",
1070 error );
1071
1072 /* Test open and close
1073 */
1074 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1075 result = libfsext_volume_open_wide(
1076 volume,
1077 source,
1078 LIBFSEXT_OPEN_READ,
1079 &error );
1080 #else
1081 result = libfsext_volume_open(
1082 volume,
1083 source,
1084 LIBFSEXT_OPEN_READ,
1085 &error );
1086 #endif
1087
1088 FSEXT_TEST_ASSERT_EQUAL_INT(
1089 "result",
1090 result,
1091 1 );
1092
1093 FSEXT_TEST_ASSERT_IS_NULL(
1094 "error",
1095 error );
1096
1097 result = libfsext_volume_close(
1098 volume,
1099 &error );
1100
1101 FSEXT_TEST_ASSERT_EQUAL_INT(
1102 "result",
1103 result,
1104 0 );
1105
1106 FSEXT_TEST_ASSERT_IS_NULL(
1107 "error",
1108 error );
1109
1110 /* Test open and close a second time to validate clean up on close
1111 */
1112 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1113 result = libfsext_volume_open_wide(
1114 volume,
1115 source,
1116 LIBFSEXT_OPEN_READ,
1117 &error );
1118 #else
1119 result = libfsext_volume_open(
1120 volume,
1121 source,
1122 LIBFSEXT_OPEN_READ,
1123 &error );
1124 #endif
1125
1126 FSEXT_TEST_ASSERT_EQUAL_INT(
1127 "result",
1128 result,
1129 1 );
1130
1131 FSEXT_TEST_ASSERT_IS_NULL(
1132 "error",
1133 error );
1134
1135 result = libfsext_volume_close(
1136 volume,
1137 &error );
1138
1139 FSEXT_TEST_ASSERT_EQUAL_INT(
1140 "result",
1141 result,
1142 0 );
1143
1144 FSEXT_TEST_ASSERT_IS_NULL(
1145 "error",
1146 error );
1147
1148 /* Clean up
1149 */
1150 result = libfsext_volume_free(
1151 &volume,
1152 &error );
1153
1154 FSEXT_TEST_ASSERT_EQUAL_INT(
1155 "result",
1156 result,
1157 1 );
1158
1159 FSEXT_TEST_ASSERT_IS_NULL(
1160 "volume",
1161 volume );
1162
1163 FSEXT_TEST_ASSERT_IS_NULL(
1164 "error",
1165 error );
1166
1167 return( 1 );
1168
1169 on_error:
1170 if( error != NULL )
1171 {
1172 libcerror_error_free(
1173 &error );
1174 }
1175 if( volume != NULL )
1176 {
1177 libfsext_volume_free(
1178 &volume,
1179 NULL );
1180 }
1181 return( 0 );
1182 }
1183
1184 /* Tests the libfsext_volume_signal_abort function
1185 * Returns 1 if successful or 0 if not
1186 */
fsext_test_volume_signal_abort(libfsext_volume_t * volume)1187 int fsext_test_volume_signal_abort(
1188 libfsext_volume_t *volume )
1189 {
1190 libcerror_error_t *error = NULL;
1191 int result = 0;
1192
1193 /* Test regular cases
1194 */
1195 result = libfsext_volume_signal_abort(
1196 volume,
1197 &error );
1198
1199 FSEXT_TEST_ASSERT_EQUAL_INT(
1200 "result",
1201 result,
1202 1 );
1203
1204 FSEXT_TEST_ASSERT_IS_NULL(
1205 "error",
1206 error );
1207
1208 /* Test error cases
1209 */
1210 result = libfsext_volume_signal_abort(
1211 NULL,
1212 &error );
1213
1214 FSEXT_TEST_ASSERT_EQUAL_INT(
1215 "result",
1216 result,
1217 -1 );
1218
1219 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1220 "error",
1221 error );
1222
1223 libcerror_error_free(
1224 &error );
1225
1226 return( 1 );
1227
1228 on_error:
1229 if( error != NULL )
1230 {
1231 libcerror_error_free(
1232 &error );
1233 }
1234 return( 0 );
1235 }
1236
1237 /* Tests the libfsext_volume_get_utf8_label_size function
1238 * Returns 1 if successful or 0 if not
1239 */
fsext_test_volume_get_utf8_label_size(libfsext_volume_t * volume)1240 int fsext_test_volume_get_utf8_label_size(
1241 libfsext_volume_t *volume )
1242 {
1243 libcerror_error_t *error = NULL;
1244 size_t utf8_label_size = 0;
1245 int result = 0;
1246 int utf8_label_size_is_set = 0;
1247
1248 /* Test regular cases
1249 */
1250 result = libfsext_volume_get_utf8_label_size(
1251 volume,
1252 &utf8_label_size,
1253 &error );
1254
1255 FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
1256 "result",
1257 result,
1258 -1 );
1259
1260 FSEXT_TEST_ASSERT_IS_NULL(
1261 "error",
1262 error );
1263
1264 utf8_label_size_is_set = result;
1265
1266 /* Test error cases
1267 */
1268 result = libfsext_volume_get_utf8_label_size(
1269 NULL,
1270 &utf8_label_size,
1271 &error );
1272
1273 FSEXT_TEST_ASSERT_EQUAL_INT(
1274 "result",
1275 result,
1276 -1 );
1277
1278 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1279 "error",
1280 error );
1281
1282 libcerror_error_free(
1283 &error );
1284
1285 if( utf8_label_size_is_set != 0 )
1286 {
1287 result = libfsext_volume_get_utf8_label_size(
1288 volume,
1289 NULL,
1290 &error );
1291
1292 FSEXT_TEST_ASSERT_EQUAL_INT(
1293 "result",
1294 result,
1295 -1 );
1296
1297 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1298 "error",
1299 error );
1300
1301 libcerror_error_free(
1302 &error );
1303 }
1304 return( 1 );
1305
1306 on_error:
1307 if( error != NULL )
1308 {
1309 libcerror_error_free(
1310 &error );
1311 }
1312 return( 0 );
1313 }
1314
1315 /* Tests the libfsext_volume_get_utf8_label function
1316 * Returns 1 if successful or 0 if not
1317 */
fsext_test_volume_get_utf8_label(libfsext_volume_t * volume)1318 int fsext_test_volume_get_utf8_label(
1319 libfsext_volume_t *volume )
1320 {
1321 uint8_t utf8_label[ 512 ];
1322
1323 libcerror_error_t *error = NULL;
1324 int result = 0;
1325 int utf8_label_is_set = 0;
1326
1327 /* Test regular cases
1328 */
1329 result = libfsext_volume_get_utf8_label(
1330 volume,
1331 utf8_label,
1332 512,
1333 &error );
1334
1335 FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
1336 "result",
1337 result,
1338 -1 );
1339
1340 FSEXT_TEST_ASSERT_IS_NULL(
1341 "error",
1342 error );
1343
1344 utf8_label_is_set = result;
1345
1346 /* Test error cases
1347 */
1348 result = libfsext_volume_get_utf8_label(
1349 NULL,
1350 utf8_label,
1351 512,
1352 &error );
1353
1354 FSEXT_TEST_ASSERT_EQUAL_INT(
1355 "result",
1356 result,
1357 -1 );
1358
1359 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1360 "error",
1361 error );
1362
1363 libcerror_error_free(
1364 &error );
1365
1366 if( utf8_label_is_set != 0 )
1367 {
1368 result = libfsext_volume_get_utf8_label(
1369 volume,
1370 NULL,
1371 512,
1372 &error );
1373
1374 FSEXT_TEST_ASSERT_EQUAL_INT(
1375 "result",
1376 result,
1377 -1 );
1378
1379 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1380 "error",
1381 error );
1382
1383 libcerror_error_free(
1384 &error );
1385
1386 result = libfsext_volume_get_utf8_label(
1387 volume,
1388 utf8_label,
1389 0,
1390 &error );
1391
1392 FSEXT_TEST_ASSERT_EQUAL_INT(
1393 "result",
1394 result,
1395 -1 );
1396
1397 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1398 "error",
1399 error );
1400
1401 libcerror_error_free(
1402 &error );
1403
1404 result = libfsext_volume_get_utf8_label(
1405 volume,
1406 utf8_label,
1407 (size_t) SSIZE_MAX + 1,
1408 &error );
1409
1410 FSEXT_TEST_ASSERT_EQUAL_INT(
1411 "result",
1412 result,
1413 -1 );
1414
1415 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1416 "error",
1417 error );
1418
1419 libcerror_error_free(
1420 &error );
1421 }
1422 return( 1 );
1423
1424 on_error:
1425 if( error != NULL )
1426 {
1427 libcerror_error_free(
1428 &error );
1429 }
1430 return( 0 );
1431 }
1432
1433 /* Tests the libfsext_volume_get_utf16_label_size function
1434 * Returns 1 if successful or 0 if not
1435 */
fsext_test_volume_get_utf16_label_size(libfsext_volume_t * volume)1436 int fsext_test_volume_get_utf16_label_size(
1437 libfsext_volume_t *volume )
1438 {
1439 libcerror_error_t *error = NULL;
1440 size_t utf16_label_size = 0;
1441 int result = 0;
1442 int utf16_label_size_is_set = 0;
1443
1444 /* Test regular cases
1445 */
1446 result = libfsext_volume_get_utf16_label_size(
1447 volume,
1448 &utf16_label_size,
1449 &error );
1450
1451 FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
1452 "result",
1453 result,
1454 -1 );
1455
1456 FSEXT_TEST_ASSERT_IS_NULL(
1457 "error",
1458 error );
1459
1460 utf16_label_size_is_set = result;
1461
1462 /* Test error cases
1463 */
1464 result = libfsext_volume_get_utf16_label_size(
1465 NULL,
1466 &utf16_label_size,
1467 &error );
1468
1469 FSEXT_TEST_ASSERT_EQUAL_INT(
1470 "result",
1471 result,
1472 -1 );
1473
1474 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1475 "error",
1476 error );
1477
1478 libcerror_error_free(
1479 &error );
1480
1481 if( utf16_label_size_is_set != 0 )
1482 {
1483 result = libfsext_volume_get_utf16_label_size(
1484 volume,
1485 NULL,
1486 &error );
1487
1488 FSEXT_TEST_ASSERT_EQUAL_INT(
1489 "result",
1490 result,
1491 -1 );
1492
1493 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1494 "error",
1495 error );
1496
1497 libcerror_error_free(
1498 &error );
1499 }
1500 return( 1 );
1501
1502 on_error:
1503 if( error != NULL )
1504 {
1505 libcerror_error_free(
1506 &error );
1507 }
1508 return( 0 );
1509 }
1510
1511 /* Tests the libfsext_volume_get_utf16_label function
1512 * Returns 1 if successful or 0 if not
1513 */
fsext_test_volume_get_utf16_label(libfsext_volume_t * volume)1514 int fsext_test_volume_get_utf16_label(
1515 libfsext_volume_t *volume )
1516 {
1517 uint16_t utf16_label[ 512 ];
1518
1519 libcerror_error_t *error = NULL;
1520 int result = 0;
1521 int utf16_label_is_set = 0;
1522
1523 /* Test regular cases
1524 */
1525 result = libfsext_volume_get_utf16_label(
1526 volume,
1527 utf16_label,
1528 512,
1529 &error );
1530
1531 FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
1532 "result",
1533 result,
1534 -1 );
1535
1536 FSEXT_TEST_ASSERT_IS_NULL(
1537 "error",
1538 error );
1539
1540 utf16_label_is_set = result;
1541
1542 /* Test error cases
1543 */
1544 result = libfsext_volume_get_utf16_label(
1545 NULL,
1546 utf16_label,
1547 512,
1548 &error );
1549
1550 FSEXT_TEST_ASSERT_EQUAL_INT(
1551 "result",
1552 result,
1553 -1 );
1554
1555 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1556 "error",
1557 error );
1558
1559 libcerror_error_free(
1560 &error );
1561
1562 if( utf16_label_is_set != 0 )
1563 {
1564 result = libfsext_volume_get_utf16_label(
1565 volume,
1566 NULL,
1567 512,
1568 &error );
1569
1570 FSEXT_TEST_ASSERT_EQUAL_INT(
1571 "result",
1572 result,
1573 -1 );
1574
1575 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1576 "error",
1577 error );
1578
1579 libcerror_error_free(
1580 &error );
1581
1582 result = libfsext_volume_get_utf16_label(
1583 volume,
1584 utf16_label,
1585 0,
1586 &error );
1587
1588 FSEXT_TEST_ASSERT_EQUAL_INT(
1589 "result",
1590 result,
1591 -1 );
1592
1593 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1594 "error",
1595 error );
1596
1597 libcerror_error_free(
1598 &error );
1599
1600 result = libfsext_volume_get_utf16_label(
1601 volume,
1602 utf16_label,
1603 (size_t) SSIZE_MAX + 1,
1604 &error );
1605
1606 FSEXT_TEST_ASSERT_EQUAL_INT(
1607 "result",
1608 result,
1609 -1 );
1610
1611 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1612 "error",
1613 error );
1614
1615 libcerror_error_free(
1616 &error );
1617 }
1618 return( 1 );
1619
1620 on_error:
1621 if( error != NULL )
1622 {
1623 libcerror_error_free(
1624 &error );
1625 }
1626 return( 0 );
1627 }
1628
1629 /* Tests the libfsext_volume_get_last_mount_time function
1630 * Returns 1 if successful or 0 if not
1631 */
fsext_test_volume_get_last_mount_time(libfsext_volume_t * volume)1632 int fsext_test_volume_get_last_mount_time(
1633 libfsext_volume_t *volume )
1634 {
1635 libcerror_error_t *error = NULL;
1636 int32_t posix_time = 0;
1637 int result = 0;
1638
1639 /* Test regular cases
1640 */
1641 result = libfsext_volume_get_last_mount_time(
1642 volume,
1643 &posix_time,
1644 &error );
1645
1646 FSEXT_TEST_ASSERT_EQUAL_INT(
1647 "result",
1648 result,
1649 1 );
1650
1651 FSEXT_TEST_ASSERT_IS_NULL(
1652 "error",
1653 error );
1654
1655 /* Test error cases
1656 */
1657 result = libfsext_volume_get_last_mount_time(
1658 NULL,
1659 &posix_time,
1660 &error );
1661
1662 FSEXT_TEST_ASSERT_EQUAL_INT(
1663 "result",
1664 result,
1665 -1 );
1666
1667 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1668 "error",
1669 error );
1670
1671 libcerror_error_free(
1672 &error );
1673
1674 result = libfsext_volume_get_last_mount_time(
1675 volume,
1676 NULL,
1677 &error );
1678
1679 FSEXT_TEST_ASSERT_EQUAL_INT(
1680 "result",
1681 result,
1682 -1 );
1683
1684 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1685 "error",
1686 error );
1687
1688 libcerror_error_free(
1689 &error );
1690
1691 return( 1 );
1692
1693 on_error:
1694 if( error != NULL )
1695 {
1696 libcerror_error_free(
1697 &error );
1698 }
1699 return( 0 );
1700 }
1701
1702 /* Tests the libfsext_volume_get_last_written_time function
1703 * Returns 1 if successful or 0 if not
1704 */
fsext_test_volume_get_last_written_time(libfsext_volume_t * volume)1705 int fsext_test_volume_get_last_written_time(
1706 libfsext_volume_t *volume )
1707 {
1708 libcerror_error_t *error = NULL;
1709 int32_t posix_time = 0;
1710 int result = 0;
1711
1712 /* Test regular cases
1713 */
1714 result = libfsext_volume_get_last_written_time(
1715 volume,
1716 &posix_time,
1717 &error );
1718
1719 FSEXT_TEST_ASSERT_EQUAL_INT(
1720 "result",
1721 result,
1722 1 );
1723
1724 FSEXT_TEST_ASSERT_IS_NULL(
1725 "error",
1726 error );
1727
1728 /* Test error cases
1729 */
1730 result = libfsext_volume_get_last_written_time(
1731 NULL,
1732 &posix_time,
1733 &error );
1734
1735 FSEXT_TEST_ASSERT_EQUAL_INT(
1736 "result",
1737 result,
1738 -1 );
1739
1740 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1741 "error",
1742 error );
1743
1744 libcerror_error_free(
1745 &error );
1746
1747 result = libfsext_volume_get_last_written_time(
1748 volume,
1749 NULL,
1750 &error );
1751
1752 FSEXT_TEST_ASSERT_EQUAL_INT(
1753 "result",
1754 result,
1755 -1 );
1756
1757 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1758 "error",
1759 error );
1760
1761 libcerror_error_free(
1762 &error );
1763
1764 return( 1 );
1765
1766 on_error:
1767 if( error != NULL )
1768 {
1769 libcerror_error_free(
1770 &error );
1771 }
1772 return( 0 );
1773 }
1774
1775 /* Tests the libfsext_volume_get_root_directory function
1776 * Returns 1 if successful or 0 if not
1777 */
fsext_test_volume_get_root_directory(libfsext_volume_t * volume)1778 int fsext_test_volume_get_root_directory(
1779 libfsext_volume_t *volume )
1780 {
1781 libcerror_error_t *error = NULL;
1782 libfsext_file_entry_t *root_directory = 0;
1783 int result = 0;
1784 int root_directory_is_set = 0;
1785
1786 /* Test regular cases
1787 */
1788 result = libfsext_volume_get_root_directory(
1789 volume,
1790 &root_directory,
1791 &error );
1792
1793 FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
1794 "result",
1795 result,
1796 -1 );
1797
1798 FSEXT_TEST_ASSERT_IS_NULL(
1799 "error",
1800 error );
1801
1802 root_directory_is_set = result;
1803
1804 if( root_directory_is_set != 0 )
1805 {
1806 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1807 "root_directory",
1808 root_directory );
1809
1810 result = libfsext_file_entry_free(
1811 &root_directory,
1812 &error );
1813
1814 FSEXT_TEST_ASSERT_EQUAL_INT(
1815 "result",
1816 result,
1817 1 );
1818
1819 FSEXT_TEST_ASSERT_IS_NULL(
1820 "error",
1821 error );
1822 }
1823 /* Test error cases
1824 */
1825 result = libfsext_volume_get_root_directory(
1826 NULL,
1827 &root_directory,
1828 &error );
1829
1830 FSEXT_TEST_ASSERT_EQUAL_INT(
1831 "result",
1832 result,
1833 -1 );
1834
1835 FSEXT_TEST_ASSERT_IS_NULL(
1836 "root_directory",
1837 root_directory );
1838
1839 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1840 "error",
1841 error );
1842
1843 libcerror_error_free(
1844 &error );
1845
1846 if( root_directory_is_set != 0 )
1847 {
1848 result = libfsext_volume_get_root_directory(
1849 volume,
1850 NULL,
1851 &error );
1852
1853 FSEXT_TEST_ASSERT_EQUAL_INT(
1854 "result",
1855 result,
1856 -1 );
1857
1858 FSEXT_TEST_ASSERT_IS_NULL(
1859 "root_directory",
1860 root_directory );
1861
1862 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1863 "error",
1864 error );
1865
1866 libcerror_error_free(
1867 &error );
1868 }
1869 return( 1 );
1870
1871 on_error:
1872 if( error != NULL )
1873 {
1874 libcerror_error_free(
1875 &error );
1876 }
1877 return( 0 );
1878 }
1879
1880 /* The main program
1881 */
1882 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
wmain(int argc,wchar_t * const argv[])1883 int wmain(
1884 int argc,
1885 wchar_t * const argv[] )
1886 #else
1887 int main(
1888 int argc,
1889 char * const argv[] )
1890 #endif
1891 {
1892 libbfio_handle_t *file_io_handle = NULL;
1893 libcerror_error_t *error = NULL;
1894 libfsext_volume_t *volume = NULL;
1895 system_character_t *option_offset = NULL;
1896 system_character_t *source = NULL;
1897 system_integer_t option = 0;
1898 size_t string_length = 0;
1899 off64_t volume_offset = 0;
1900 int result = 0;
1901
1902 while( ( option = fsext_test_getopt(
1903 argc,
1904 argv,
1905 _SYSTEM_STRING( "o:" ) ) ) != (system_integer_t) -1 )
1906 {
1907 switch( option )
1908 {
1909 case (system_integer_t) '?':
1910 default:
1911 fprintf(
1912 stderr,
1913 "Invalid argument: %" PRIs_SYSTEM ".\n",
1914 argv[ optind - 1 ] );
1915
1916 return( EXIT_FAILURE );
1917
1918 case (system_integer_t) 'o':
1919 option_offset = optarg;
1920
1921 break;
1922 }
1923 }
1924 if( optind < argc )
1925 {
1926 source = argv[ optind ];
1927 }
1928 if( option_offset != NULL )
1929 {
1930 string_length = system_string_length(
1931 option_offset );
1932
1933 result = fsext_test_system_string_copy_from_64_bit_in_decimal(
1934 option_offset,
1935 string_length + 1,
1936 (uint64_t *) &volume_offset,
1937 &error );
1938
1939 FSEXT_TEST_ASSERT_EQUAL_INT(
1940 "result",
1941 result,
1942 1 );
1943
1944 FSEXT_TEST_ASSERT_IS_NULL(
1945 "error",
1946 error );
1947 }
1948 #if defined( HAVE_DEBUG_OUTPUT ) && defined( FSEXT_TEST_VOLUME_VERBOSE )
1949 libfsext_notify_set_verbose(
1950 1 );
1951 libfsext_notify_set_stream(
1952 stderr,
1953 NULL );
1954 #endif
1955
1956 FSEXT_TEST_RUN(
1957 "libfsext_volume_initialize",
1958 fsext_test_volume_initialize );
1959
1960 FSEXT_TEST_RUN(
1961 "libfsext_volume_free",
1962 fsext_test_volume_free );
1963
1964 #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )
1965 if( source != NULL )
1966 {
1967 result = libbfio_file_range_initialize(
1968 &file_io_handle,
1969 &error );
1970
1971 FSEXT_TEST_ASSERT_EQUAL_INT(
1972 "result",
1973 result,
1974 1 );
1975
1976 FSEXT_TEST_ASSERT_IS_NOT_NULL(
1977 "file_io_handle",
1978 file_io_handle );
1979
1980 FSEXT_TEST_ASSERT_IS_NULL(
1981 "error",
1982 error );
1983
1984 string_length = system_string_length(
1985 source );
1986
1987 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1988 result = libbfio_file_range_set_name_wide(
1989 file_io_handle,
1990 source,
1991 string_length,
1992 &error );
1993 #else
1994 result = libbfio_file_range_set_name(
1995 file_io_handle,
1996 source,
1997 string_length,
1998 &error );
1999 #endif
2000 FSEXT_TEST_ASSERT_EQUAL_INT(
2001 "result",
2002 result,
2003 1 );
2004
2005 FSEXT_TEST_ASSERT_IS_NULL(
2006 "error",
2007 error );
2008
2009 result = libbfio_file_range_set(
2010 file_io_handle,
2011 volume_offset,
2012 0,
2013 &error );
2014
2015 FSEXT_TEST_ASSERT_EQUAL_INT(
2016 "result",
2017 result,
2018 1 );
2019
2020 FSEXT_TEST_ASSERT_IS_NULL(
2021 "error",
2022 error );
2023
2024 result = libfsext_check_volume_signature_file_io_handle(
2025 file_io_handle,
2026 &error );
2027
2028 FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
2029 "result",
2030 result,
2031 -1 );
2032
2033 FSEXT_TEST_ASSERT_IS_NULL(
2034 "error",
2035 error );
2036 }
2037 if( ( result != 0 )
2038 && ( volume_offset == 0 ) )
2039 {
2040 FSEXT_TEST_RUN_WITH_ARGS(
2041 "libfsext_volume_open",
2042 fsext_test_volume_open,
2043 source );
2044
2045 #if defined( HAVE_WIDE_CHARACTER_TYPE )
2046
2047 FSEXT_TEST_RUN_WITH_ARGS(
2048 "libfsext_volume_open_wide",
2049 fsext_test_volume_open_wide,
2050 source );
2051
2052 #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */
2053
2054 FSEXT_TEST_RUN_WITH_ARGS(
2055 "libfsext_volume_open_file_io_handle",
2056 fsext_test_volume_open_file_io_handle,
2057 source );
2058
2059 FSEXT_TEST_RUN(
2060 "libfsext_volume_close",
2061 fsext_test_volume_close );
2062
2063 FSEXT_TEST_RUN_WITH_ARGS(
2064 "libfsext_volume_open_close",
2065 fsext_test_volume_open_close,
2066 source );
2067 }
2068 if( result != 0 )
2069 {
2070 /* Initialize volume for tests
2071 */
2072 result = fsext_test_volume_open_source(
2073 &volume,
2074 file_io_handle,
2075 &error );
2076
2077 FSEXT_TEST_ASSERT_EQUAL_INT(
2078 "result",
2079 result,
2080 1 );
2081
2082 FSEXT_TEST_ASSERT_IS_NOT_NULL(
2083 "volume",
2084 volume );
2085
2086 FSEXT_TEST_ASSERT_IS_NULL(
2087 "error",
2088 error );
2089
2090 FSEXT_TEST_RUN_WITH_ARGS(
2091 "libfsext_volume_signal_abort",
2092 fsext_test_volume_signal_abort,
2093 volume );
2094
2095 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
2096
2097 /* TODO: add tests for libfsext_volume_open_read */
2098
2099 /* TODO: add tests for libfsext_volume_read_block_groups */
2100
2101 #endif /* defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT ) */
2102
2103 FSEXT_TEST_RUN_WITH_ARGS(
2104 "libfsext_volume_get_utf8_label_size",
2105 fsext_test_volume_get_utf8_label_size,
2106 volume );
2107
2108 FSEXT_TEST_RUN_WITH_ARGS(
2109 "libfsext_volume_get_utf8_label",
2110 fsext_test_volume_get_utf8_label,
2111 volume );
2112
2113 FSEXT_TEST_RUN_WITH_ARGS(
2114 "libfsext_volume_get_utf16_label_size",
2115 fsext_test_volume_get_utf16_label_size,
2116 volume );
2117
2118 FSEXT_TEST_RUN_WITH_ARGS(
2119 "libfsext_volume_get_utf16_label",
2120 fsext_test_volume_get_utf16_label,
2121 volume );
2122
2123 FSEXT_TEST_RUN_WITH_ARGS(
2124 "libfsext_volume_get_last_mount_time",
2125 fsext_test_volume_get_last_mount_time,
2126 volume );
2127
2128 FSEXT_TEST_RUN_WITH_ARGS(
2129 "libfsext_volume_get_last_written_time",
2130 fsext_test_volume_get_last_written_time,
2131 volume );
2132
2133 /* TODO: add tests for libfsntfs_volume_get_number_of_file_entries */
2134
2135 /* TODO: add tests for libfsntfs_volume_get_file_entry_by_index */
2136
2137 FSEXT_TEST_RUN_WITH_ARGS(
2138 "libfsext_volume_get_root_directory",
2139 fsext_test_volume_get_root_directory,
2140 volume );
2141
2142 /* Clean up
2143 */
2144 result = fsext_test_volume_close_source(
2145 &volume,
2146 &error );
2147
2148 FSEXT_TEST_ASSERT_EQUAL_INT(
2149 "result",
2150 result,
2151 0 );
2152
2153 FSEXT_TEST_ASSERT_IS_NULL(
2154 "volume",
2155 volume );
2156
2157 FSEXT_TEST_ASSERT_IS_NULL(
2158 "error",
2159 error );
2160 }
2161 if( file_io_handle != NULL )
2162 {
2163 result = libbfio_handle_free(
2164 &file_io_handle,
2165 &error );
2166
2167 FSEXT_TEST_ASSERT_EQUAL_INT(
2168 "result",
2169 result,
2170 1 );
2171
2172 FSEXT_TEST_ASSERT_IS_NULL(
2173 "file_io_handle",
2174 file_io_handle );
2175
2176 FSEXT_TEST_ASSERT_IS_NULL(
2177 "error",
2178 error );
2179 }
2180 #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */
2181
2182 return( EXIT_SUCCESS );
2183
2184 on_error:
2185 if( error != NULL )
2186 {
2187 libcerror_error_free(
2188 &error );
2189 }
2190 if( volume != NULL )
2191 {
2192 libfsext_volume_free(
2193 &volume,
2194 NULL );
2195 }
2196 if( file_io_handle != NULL )
2197 {
2198 libbfio_handle_free(
2199 &file_io_handle,
2200 NULL );
2201 }
2202 return( EXIT_FAILURE );
2203 }
2204
2205