1 /*
2  * Library directory_entry 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 <types.h>
25 
26 #if defined( HAVE_STDLIB_H ) || defined( WINAPI )
27 #include <stdlib.h>
28 #endif
29 
30 #include "fsext_test_libcerror.h"
31 #include "fsext_test_libfsext.h"
32 #include "fsext_test_macros.h"
33 #include "fsext_test_memory.h"
34 #include "fsext_test_unused.h"
35 
36 #include "../libfsext/libfsext_directory_entry.h"
37 
38 uint8_t fsext_test_directory_entry_data1[ 16 ] = {
39 	0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x05, 0x01, 0x66, 0x69, 0x6c, 0x65, 0x31, 0x00, 0x00, 0x00 };
40 
41 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
42 
43 /* Tests the libfsext_directory_entry_initialize function
44  * Returns 1 if successful or 0 if not
45  */
fsext_test_directory_entry_initialize(void)46 int fsext_test_directory_entry_initialize(
47      void )
48 {
49 	libcerror_error_t *error                    = NULL;
50 	libfsext_directory_entry_t *directory_entry = NULL;
51 	int result                                  = 0;
52 
53 #if defined( HAVE_FSEXT_TEST_MEMORY )
54 	int number_of_malloc_fail_tests             = 1;
55 	int number_of_memset_fail_tests             = 1;
56 	int test_number                             = 0;
57 #endif
58 
59 	/* Test regular cases
60 	 */
61 	result = libfsext_directory_entry_initialize(
62 	          &directory_entry,
63 	          &error );
64 
65 	FSEXT_TEST_ASSERT_EQUAL_INT(
66 	 "result",
67 	 result,
68 	 1 );
69 
70 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
71 	 "directory_entry",
72 	 directory_entry );
73 
74 	FSEXT_TEST_ASSERT_IS_NULL(
75 	 "error",
76 	 error );
77 
78 	result = libfsext_directory_entry_free(
79 	          &directory_entry,
80 	          &error );
81 
82 	FSEXT_TEST_ASSERT_EQUAL_INT(
83 	 "result",
84 	 result,
85 	 1 );
86 
87 	FSEXT_TEST_ASSERT_IS_NULL(
88 	 "directory_entry",
89 	 directory_entry );
90 
91 	FSEXT_TEST_ASSERT_IS_NULL(
92 	 "error",
93 	 error );
94 
95 	/* Test error cases
96 	 */
97 	result = libfsext_directory_entry_initialize(
98 	          NULL,
99 	          &error );
100 
101 	FSEXT_TEST_ASSERT_EQUAL_INT(
102 	 "result",
103 	 result,
104 	 -1 );
105 
106 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
107 	 "error",
108 	 error );
109 
110 	libcerror_error_free(
111 	 &error );
112 
113 	directory_entry = (libfsext_directory_entry_t *) 0x12345678UL;
114 
115 	result = libfsext_directory_entry_initialize(
116 	          &directory_entry,
117 	          &error );
118 
119 	directory_entry = NULL;
120 
121 	FSEXT_TEST_ASSERT_EQUAL_INT(
122 	 "result",
123 	 result,
124 	 -1 );
125 
126 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
127 	 "error",
128 	 error );
129 
130 	libcerror_error_free(
131 	 &error );
132 
133 #if defined( HAVE_FSEXT_TEST_MEMORY )
134 
135 	for( test_number = 0;
136 	     test_number < number_of_malloc_fail_tests;
137 	     test_number++ )
138 	{
139 		/* Test libfsext_directory_entry_initialize with malloc failing
140 		 */
141 		fsext_test_malloc_attempts_before_fail = test_number;
142 
143 		result = libfsext_directory_entry_initialize(
144 		          &directory_entry,
145 		          &error );
146 
147 		if( fsext_test_malloc_attempts_before_fail != -1 )
148 		{
149 			fsext_test_malloc_attempts_before_fail = -1;
150 
151 			if( directory_entry != NULL )
152 			{
153 				libfsext_directory_entry_free(
154 				 &directory_entry,
155 				 NULL );
156 			}
157 		}
158 		else
159 		{
160 			FSEXT_TEST_ASSERT_EQUAL_INT(
161 			 "result",
162 			 result,
163 			 -1 );
164 
165 			FSEXT_TEST_ASSERT_IS_NULL(
166 			 "directory_entry",
167 			 directory_entry );
168 
169 			FSEXT_TEST_ASSERT_IS_NOT_NULL(
170 			 "error",
171 			 error );
172 
173 			libcerror_error_free(
174 			 &error );
175 		}
176 	}
177 	for( test_number = 0;
178 	     test_number < number_of_memset_fail_tests;
179 	     test_number++ )
180 	{
181 		/* Test libfsext_directory_entry_initialize with memset failing
182 		 */
183 		fsext_test_memset_attempts_before_fail = test_number;
184 
185 		result = libfsext_directory_entry_initialize(
186 		          &directory_entry,
187 		          &error );
188 
189 		if( fsext_test_memset_attempts_before_fail != -1 )
190 		{
191 			fsext_test_memset_attempts_before_fail = -1;
192 
193 			if( directory_entry != NULL )
194 			{
195 				libfsext_directory_entry_free(
196 				 &directory_entry,
197 				 NULL );
198 			}
199 		}
200 		else
201 		{
202 			FSEXT_TEST_ASSERT_EQUAL_INT(
203 			 "result",
204 			 result,
205 			 -1 );
206 
207 			FSEXT_TEST_ASSERT_IS_NULL(
208 			 "directory_entry",
209 			 directory_entry );
210 
211 			FSEXT_TEST_ASSERT_IS_NOT_NULL(
212 			 "error",
213 			 error );
214 
215 			libcerror_error_free(
216 			 &error );
217 		}
218 	}
219 #endif /* defined( HAVE_FSEXT_TEST_MEMORY ) */
220 
221 	return( 1 );
222 
223 on_error:
224 	if( error != NULL )
225 	{
226 		libcerror_error_free(
227 		 &error );
228 	}
229 	if( directory_entry != NULL )
230 	{
231 		libfsext_directory_entry_free(
232 		 &directory_entry,
233 		 NULL );
234 	}
235 	return( 0 );
236 }
237 
238 /* Tests the libfsext_directory_entry_free function
239  * Returns 1 if successful or 0 if not
240  */
fsext_test_directory_entry_free(void)241 int fsext_test_directory_entry_free(
242      void )
243 {
244 	libcerror_error_t *error = NULL;
245 	int result               = 0;
246 
247 	/* Test error cases
248 	 */
249 	result = libfsext_directory_entry_free(
250 	          NULL,
251 	          &error );
252 
253 	FSEXT_TEST_ASSERT_EQUAL_INT(
254 	 "result",
255 	 result,
256 	 -1 );
257 
258 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
259 	 "error",
260 	 error );
261 
262 	libcerror_error_free(
263 	 &error );
264 
265 	return( 1 );
266 
267 on_error:
268 	if( error != NULL )
269 	{
270 		libcerror_error_free(
271 		 &error );
272 	}
273 	return( 0 );
274 }
275 
276 /* Tests the libfsext_directory_entry_clone function
277  * Returns 1 if successful or 0 if not
278  */
fsext_test_directory_entry_clone(void)279 int fsext_test_directory_entry_clone(
280      void )
281 {
282 	libcerror_error_t *error                                = NULL;
283 	libfsext_directory_entry_t *destination_directory_entry = NULL;
284 	libfsext_directory_entry_t *source_directory_entry      = NULL;
285 	int result                                              = 0;
286 
287 #if defined( HAVE_FSEXT_TEST_MEMORY )
288 	int number_of_malloc_fail_tests                         = 2;
289 	int test_number                                         = 0;
290 
291 #if defined( OPTIMIZATION_DISABLED )
292 	int number_of_memcpy_fail_tests                         = 2;
293 #endif
294 #endif /* defined( HAVE_FSEXT_TEST_MEMORY ) */
295 
296 	/* Initialize test
297 	 */
298 	result = libfsext_directory_entry_initialize(
299 	          &source_directory_entry,
300 	          &error );
301 
302 	FSEXT_TEST_ASSERT_EQUAL_INT(
303 	 "result",
304 	 result,
305 	 1 );
306 
307 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
308 	 "source_directory_entry",
309 	 source_directory_entry );
310 
311 	FSEXT_TEST_ASSERT_IS_NULL(
312 	 "error",
313 	 error );
314 
315 	/* Test regular cases
316 	 */
317 	result = libfsext_directory_entry_clone(
318 	          &destination_directory_entry,
319 	          source_directory_entry,
320 	          &error );
321 
322 	FSEXT_TEST_ASSERT_EQUAL_INT(
323 	 "result",
324 	 result,
325 	 1 );
326 
327 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
328 	 "destination_directory_entry",
329 	 destination_directory_entry );
330 
331 	FSEXT_TEST_ASSERT_IS_NULL(
332 	 "error",
333 	 error );
334 
335 	result = libfsext_directory_entry_free(
336 	          &destination_directory_entry,
337 	          &error );
338 
339 	FSEXT_TEST_ASSERT_EQUAL_INT(
340 	 "result",
341 	 result,
342 	 1 );
343 
344 	FSEXT_TEST_ASSERT_IS_NULL(
345 	 "destination_directory_entry",
346 	 destination_directory_entry );
347 
348 	FSEXT_TEST_ASSERT_IS_NULL(
349 	 "error",
350 	 error );
351 
352 	result = libfsext_directory_entry_clone(
353 	          &destination_directory_entry,
354 	          NULL,
355 	          &error );
356 
357 	FSEXT_TEST_ASSERT_EQUAL_INT(
358 	 "result",
359 	 result,
360 	 1 );
361 
362 	FSEXT_TEST_ASSERT_IS_NULL(
363 	 "destination_directory_entry",
364 	 destination_directory_entry );
365 
366 	FSEXT_TEST_ASSERT_IS_NULL(
367 	 "error",
368 	 error );
369 
370 	/* Test error cases
371 	 */
372 	result = libfsext_directory_entry_clone(
373 	          NULL,
374 	          source_directory_entry,
375 	          &error );
376 
377 	FSEXT_TEST_ASSERT_EQUAL_INT(
378 	 "result",
379 	 result,
380 	 -1 );
381 
382 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
383 	 "error",
384 	 error );
385 
386 	libcerror_error_free(
387 	 &error );
388 
389 	destination_directory_entry = (libfsext_directory_entry_t *) 0x12345678UL;
390 
391 	result = libfsext_directory_entry_clone(
392 	          &destination_directory_entry,
393 	          source_directory_entry,
394 	          &error );
395 
396 	destination_directory_entry = NULL;
397 
398 	FSEXT_TEST_ASSERT_EQUAL_INT(
399 	 "result",
400 	 result,
401 	 -1 );
402 
403 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
404 	 "error",
405 	 error );
406 
407 	libcerror_error_free(
408 	 &error );
409 
410 #if defined( HAVE_FSEXT_TEST_MEMORY )
411 
412 	for( test_number = 0;
413 	     test_number < number_of_malloc_fail_tests;
414 	     test_number++ )
415 	{
416 		/* Test libfsext_directory_entry_clone with malloc failing
417 		 */
418 		fsext_test_malloc_attempts_before_fail = test_number;
419 
420 		result = libfsext_directory_entry_clone(
421 		          &destination_directory_entry,
422 		          source_directory_entry,
423 		          &error );
424 
425 		if( fsext_test_malloc_attempts_before_fail != -1 )
426 		{
427 			fsext_test_malloc_attempts_before_fail = -1;
428 
429 			if( destination_directory_entry != NULL )
430 			{
431 				libfsext_directory_entry_free(
432 				 &destination_directory_entry,
433 				 NULL );
434 			}
435 		}
436 		else
437 		{
438 			FSEXT_TEST_ASSERT_EQUAL_INT(
439 			 "result",
440 			 result,
441 			 -1 );
442 
443 			FSEXT_TEST_ASSERT_IS_NULL(
444 			 "destination_directory_entry",
445 			 destination_directory_entry );
446 
447 			FSEXT_TEST_ASSERT_IS_NOT_NULL(
448 			 "error",
449 			 error );
450 
451 			libcerror_error_free(
452 			 &error );
453 		}
454 	}
455 #if defined( OPTIMIZATION_DISABLED )
456 
457 	for( test_number = 0;
458 	     test_number < number_of_memcpy_fail_tests;
459 	     test_number++ )
460 	{
461 		/* Test libfsext_directory_entry_clone with memcpy failing
462 		 */
463 		fsext_test_memcpy_attempts_before_fail = test_number;
464 
465 		result = libfsext_directory_entry_clone(
466 		          &destination_directory_entry,
467 		          source_directory_entry,
468 		          &error );
469 
470 		if( fsext_test_memcpy_attempts_before_fail != -1 )
471 		{
472 			fsext_test_memcpy_attempts_before_fail = -1;
473 
474 			if( destination_directory_entry != NULL )
475 			{
476 				libfsext_directory_entry_free(
477 				 &destination_directory_entry,
478 				 NULL );
479 			}
480 		}
481 		else
482 		{
483 			FSEXT_TEST_ASSERT_EQUAL_INT(
484 			 "result",
485 			 result,
486 			 -1 );
487 
488 			FSEXT_TEST_ASSERT_IS_NULL(
489 			 "destination_directory_entry",
490 			 destination_directory_entry );
491 
492 			FSEXT_TEST_ASSERT_IS_NOT_NULL(
493 			 "error",
494 			 error );
495 
496 			libcerror_error_free(
497 			 &error );
498 		}
499 	}
500 #endif /* defined( OPTIMIZATION_DISABLED ) */
501 #endif /* defined( HAVE_FSEXT_TEST_MEMORY ) */
502 
503 	/* Clean up
504 	 */
505 	result = libfsext_directory_entry_free(
506 	          &source_directory_entry,
507 	          &error );
508 
509 	FSEXT_TEST_ASSERT_EQUAL_INT(
510 	 "result",
511 	 result,
512 	 1 );
513 
514 	FSEXT_TEST_ASSERT_IS_NULL(
515 	 "source_directory_entry",
516 	 source_directory_entry );
517 
518 	FSEXT_TEST_ASSERT_IS_NULL(
519 	 "error",
520 	 error );
521 
522 	return( 1 );
523 
524 on_error:
525 	if( error != NULL )
526 	{
527 		libcerror_error_free(
528 		 &error );
529 	}
530 	if( destination_directory_entry != NULL )
531 	{
532 		libfsext_directory_entry_free(
533 		 &destination_directory_entry,
534 		 NULL );
535 	}
536 	if( source_directory_entry != NULL )
537 	{
538 		libfsext_directory_entry_free(
539 		 &source_directory_entry,
540 		 NULL );
541 	}
542 	return( 0 );
543 }
544 
545 /* Tests the libfsext_directory_entry_read_data function
546  * Returns 1 if successful or 0 if not
547  */
fsext_test_directory_entry_read_data(void)548 int fsext_test_directory_entry_read_data(
549      void )
550 {
551 	libcerror_error_t *error                    = NULL;
552 	libfsext_directory_entry_t *directory_entry = NULL;
553 	int result                                  = 0;
554 
555 	/* Initialize test
556 	 */
557 	result = libfsext_directory_entry_initialize(
558 	          &directory_entry,
559 	          &error );
560 
561 	FSEXT_TEST_ASSERT_EQUAL_INT(
562 	 "result",
563 	 result,
564 	 1 );
565 
566 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
567 	 "directory_entry",
568 	 directory_entry );
569 
570 	FSEXT_TEST_ASSERT_IS_NULL(
571 	 "error",
572 	 error );
573 
574 	/* Test regular cases
575 	 */
576 	result = libfsext_directory_entry_read_data(
577 	          directory_entry,
578 	          fsext_test_directory_entry_data1,
579 	          16,
580 	          &error );
581 
582 	FSEXT_TEST_ASSERT_EQUAL_INT(
583 	 "result",
584 	 result,
585 	 1 );
586 
587 	FSEXT_TEST_ASSERT_IS_NULL(
588 	 "error",
589 	 error );
590 
591 	/* Test error cases
592 	 */
593 	result = libfsext_directory_entry_read_data(
594 	          NULL,
595 	          fsext_test_directory_entry_data1,
596 	          16,
597 	          &error );
598 
599 	FSEXT_TEST_ASSERT_EQUAL_INT(
600 	 "result",
601 	 result,
602 	 -1 );
603 
604 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
605 	 "error",
606 	 error );
607 
608 	libcerror_error_free(
609 	 &error );
610 
611 	result = libfsext_directory_entry_read_data(
612 	          directory_entry,
613 	          NULL,
614 	          16,
615 	          &error );
616 
617 	FSEXT_TEST_ASSERT_EQUAL_INT(
618 	 "result",
619 	 result,
620 	 -1 );
621 
622 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
623 	 "error",
624 	 error );
625 
626 	libcerror_error_free(
627 	 &error );
628 
629 	result = libfsext_directory_entry_read_data(
630 	          directory_entry,
631 	          fsext_test_directory_entry_data1,
632 	          (size_t) SSIZE_MAX + 1,
633 	          &error );
634 
635 	FSEXT_TEST_ASSERT_EQUAL_INT(
636 	 "result",
637 	 result,
638 	 -1 );
639 
640 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
641 	 "error",
642 	 error );
643 
644 	libcerror_error_free(
645 	 &error );
646 
647 	result = libfsext_directory_entry_read_data(
648 	          directory_entry,
649 	          fsext_test_directory_entry_data1,
650 	          0,
651 	          &error );
652 
653 	FSEXT_TEST_ASSERT_EQUAL_INT(
654 	 "result",
655 	 result,
656 	 -1 );
657 
658 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
659 	 "error",
660 	 error );
661 
662 	libcerror_error_free(
663 	 &error );
664 
665 	/* Clean up
666 	 */
667 	result = libfsext_directory_entry_free(
668 	          &directory_entry,
669 	          &error );
670 
671 	FSEXT_TEST_ASSERT_EQUAL_INT(
672 	 "result",
673 	 result,
674 	 1 );
675 
676 	FSEXT_TEST_ASSERT_IS_NULL(
677 	 "directory_entry",
678 	 directory_entry );
679 
680 	FSEXT_TEST_ASSERT_IS_NULL(
681 	 "error",
682 	 error );
683 
684 	return( 1 );
685 
686 on_error:
687 	if( error != NULL )
688 	{
689 		libcerror_error_free(
690 		 &error );
691 	}
692 	if( directory_entry != NULL )
693 	{
694 		libfsext_directory_entry_free(
695 		 &directory_entry,
696 		 NULL );
697 	}
698 	return( 0 );
699 }
700 
701 /* Tests the libfsext_directory_entry_get_inode_number function
702  * Returns 1 if successful or 0 if not
703  */
fsext_test_directory_entry_get_inode_number(libfsext_directory_entry_t * directory_entry)704 int fsext_test_directory_entry_get_inode_number(
705      libfsext_directory_entry_t *directory_entry )
706 {
707 	libcerror_error_t *error = NULL;
708 	uint32_t inode_number    = 0;
709 	int inode_number_is_set  = 0;
710 	int result               = 0;
711 
712 	/* Test regular cases
713 	 */
714 	result = libfsext_directory_entry_get_inode_number(
715 	          directory_entry,
716 	          &inode_number,
717 	          &error );
718 
719 	FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
720 	 "result",
721 	 result,
722 	 -1 );
723 
724 	FSEXT_TEST_ASSERT_IS_NULL(
725 	 "error",
726 	 error );
727 
728 	inode_number_is_set = result;
729 
730 	/* Test error cases
731 	 */
732 	result = libfsext_directory_entry_get_inode_number(
733 	          NULL,
734 	          &inode_number,
735 	          &error );
736 
737 	FSEXT_TEST_ASSERT_EQUAL_INT(
738 	 "result",
739 	 result,
740 	 -1 );
741 
742 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
743 	 "error",
744 	 error );
745 
746 	libcerror_error_free(
747 	 &error );
748 
749 	if( inode_number_is_set != 0 )
750 	{
751 		result = libfsext_directory_entry_get_inode_number(
752 		          directory_entry,
753 		          NULL,
754 		          &error );
755 
756 		FSEXT_TEST_ASSERT_EQUAL_INT(
757 		 "result",
758 		 result,
759 		 -1 );
760 
761 		FSEXT_TEST_ASSERT_IS_NOT_NULL(
762 		 "error",
763 		 error );
764 
765 		libcerror_error_free(
766 		 &error );
767 	}
768 	return( 1 );
769 
770 on_error:
771 	if( error != NULL )
772 	{
773 		libcerror_error_free(
774 		 &error );
775 	}
776 	return( 0 );
777 }
778 
779 /* Tests the libfsext_directory_entry_get_utf8_name_size function
780  * Returns 1 if successful or 0 if not
781  */
fsext_test_directory_entry_get_utf8_name_size(libfsext_directory_entry_t * directory_entry)782 int fsext_test_directory_entry_get_utf8_name_size(
783      libfsext_directory_entry_t *directory_entry )
784 {
785 	libcerror_error_t *error = NULL;
786 	size_t utf8_name_size    = 0;
787 	int result               = 0;
788 
789 	/* Test regular cases
790 	 */
791 	result = libfsext_directory_entry_get_utf8_name_size(
792 	          directory_entry,
793 	          &utf8_name_size,
794 	          &error );
795 
796 	FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
797 	 "result",
798 	 result,
799 	 -1 );
800 
801 	FSEXT_TEST_ASSERT_IS_NULL(
802 	 "error",
803 	 error );
804 
805 	/* Test error cases
806 	 */
807 	result = libfsext_directory_entry_get_utf8_name_size(
808 	          NULL,
809 	          &utf8_name_size,
810 	          &error );
811 
812 	FSEXT_TEST_ASSERT_EQUAL_INT(
813 	 "result",
814 	 result,
815 	 -1 );
816 
817 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
818 	 "error",
819 	 error );
820 
821 	libcerror_error_free(
822 	 &error );
823 
824 	result = libfsext_directory_entry_get_utf8_name_size(
825 		  directory_entry,
826 		  NULL,
827 		  &error );
828 
829 	FSEXT_TEST_ASSERT_EQUAL_INT(
830 	 "result",
831 	 result,
832 	 -1 );
833 
834 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
835 	 "error",
836 	 error );
837 
838 	libcerror_error_free(
839 	 &error );
840 
841 	return( 1 );
842 
843 on_error:
844 	if( error != NULL )
845 	{
846 		libcerror_error_free(
847 		 &error );
848 	}
849 	return( 0 );
850 }
851 
852 /* Tests the libfsext_directory_entry_get_utf8_name function
853  * Returns 1 if successful or 0 if not
854  */
fsext_test_directory_entry_get_utf8_name(libfsext_directory_entry_t * directory_entry)855 int fsext_test_directory_entry_get_utf8_name(
856      libfsext_directory_entry_t *directory_entry )
857 {
858 	uint8_t utf8_name[ 256 ];
859 
860 	libcerror_error_t *error = NULL;
861 	int result               = 0;
862 
863 	/* Test regular cases
864 	 */
865 	result = libfsext_directory_entry_get_utf8_name(
866 	          directory_entry,
867 	          utf8_name,
868 	          256,
869 	          &error );
870 
871 	FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
872 	 "result",
873 	 result,
874 	 -1 );
875 
876 	FSEXT_TEST_ASSERT_IS_NULL(
877 	 "error",
878 	 error );
879 
880 	/* Test error cases
881 	 */
882 	result = libfsext_directory_entry_get_utf8_name(
883 	          NULL,
884 	          utf8_name,
885 	          256,
886 	          &error );
887 
888 	FSEXT_TEST_ASSERT_EQUAL_INT(
889 	 "result",
890 	 result,
891 	 -1 );
892 
893 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
894 	 "error",
895 	 error );
896 
897 	libcerror_error_free(
898 	 &error );
899 
900 	result = libfsext_directory_entry_get_utf8_name(
901 	          directory_entry,
902 	          NULL,
903 	          256,
904 	          &error );
905 
906 	FSEXT_TEST_ASSERT_EQUAL_INT(
907 	 "result",
908 	 result,
909 	 -1 );
910 
911 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
912 	 "error",
913 	 error );
914 
915 	libcerror_error_free(
916 	 &error );
917 
918 	result = libfsext_directory_entry_get_utf8_name(
919 	          directory_entry,
920 	          utf8_name,
921 	          0,
922 	          &error );
923 
924 	FSEXT_TEST_ASSERT_EQUAL_INT(
925 	 "result",
926 	 result,
927 	 -1 );
928 
929 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
930 	 "error",
931 	 error );
932 
933 	libcerror_error_free(
934 	 &error );
935 
936 	result = libfsext_directory_entry_get_utf8_name(
937 	          directory_entry,
938 	          utf8_name,
939 	          (size_t) SSIZE_MAX + 1,
940 	          &error );
941 
942 	FSEXT_TEST_ASSERT_EQUAL_INT(
943 	 "result",
944 	 result,
945 	 -1 );
946 
947 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
948 	 "error",
949 	 error );
950 
951 	libcerror_error_free(
952 	 &error );
953 
954 	return( 1 );
955 
956 on_error:
957 	if( error != NULL )
958 	{
959 		libcerror_error_free(
960 		 &error );
961 	}
962 	return( 0 );
963 }
964 
965 /* Tests the libfsext_directory_entry_get_utf16_name_size function
966  * Returns 1 if successful or 0 if not
967  */
fsext_test_directory_entry_get_utf16_name_size(libfsext_directory_entry_t * directory_entry)968 int fsext_test_directory_entry_get_utf16_name_size(
969      libfsext_directory_entry_t *directory_entry )
970 {
971 	libcerror_error_t *error = NULL;
972 	size_t utf16_name_size   = 0;
973 	int result               = 0;
974 
975 	/* Test regular cases
976 	 */
977 	result = libfsext_directory_entry_get_utf16_name_size(
978 	          directory_entry,
979 	          &utf16_name_size,
980 	          &error );
981 
982 	FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
983 	 "result",
984 	 result,
985 	 -1 );
986 
987 	FSEXT_TEST_ASSERT_IS_NULL(
988 	 "error",
989 	 error );
990 
991 	/* Test error cases
992 	 */
993 	result = libfsext_directory_entry_get_utf16_name_size(
994 	          NULL,
995 	          &utf16_name_size,
996 	          &error );
997 
998 	FSEXT_TEST_ASSERT_EQUAL_INT(
999 	 "result",
1000 	 result,
1001 	 -1 );
1002 
1003 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
1004 	 "error",
1005 	 error );
1006 
1007 	libcerror_error_free(
1008 	 &error );
1009 
1010 	result = libfsext_directory_entry_get_utf16_name_size(
1011 		  directory_entry,
1012 		  NULL,
1013 		  &error );
1014 
1015 	FSEXT_TEST_ASSERT_EQUAL_INT(
1016 	 "result",
1017 	 result,
1018 	 -1 );
1019 
1020 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
1021 	 "error",
1022 	 error );
1023 
1024 	libcerror_error_free(
1025 	 &error );
1026 
1027 	return( 1 );
1028 
1029 on_error:
1030 	if( error != NULL )
1031 	{
1032 		libcerror_error_free(
1033 		 &error );
1034 	}
1035 	return( 0 );
1036 }
1037 
1038 /* Tests the libfsext_directory_entry_get_utf16_name function
1039  * Returns 1 if successful or 0 if not
1040  */
fsext_test_directory_entry_get_utf16_name(libfsext_directory_entry_t * directory_entry)1041 int fsext_test_directory_entry_get_utf16_name(
1042      libfsext_directory_entry_t *directory_entry )
1043 {
1044 	uint16_t utf16_name[ 256 ];
1045 
1046 	libcerror_error_t *error = NULL;
1047 	int result               = 0;
1048 
1049 	/* Test regular cases
1050 	 */
1051 	result = libfsext_directory_entry_get_utf16_name(
1052 	          directory_entry,
1053 	          utf16_name,
1054 	          256,
1055 	          &error );
1056 
1057 	FSEXT_TEST_ASSERT_NOT_EQUAL_INT(
1058 	 "result",
1059 	 result,
1060 	 -1 );
1061 
1062 	FSEXT_TEST_ASSERT_IS_NULL(
1063 	 "error",
1064 	 error );
1065 
1066 	/* Test error cases
1067 	 */
1068 	result = libfsext_directory_entry_get_utf16_name(
1069 	          NULL,
1070 	          utf16_name,
1071 	          256,
1072 	          &error );
1073 
1074 	FSEXT_TEST_ASSERT_EQUAL_INT(
1075 	 "result",
1076 	 result,
1077 	 -1 );
1078 
1079 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
1080 	 "error",
1081 	 error );
1082 
1083 	libcerror_error_free(
1084 	 &error );
1085 
1086 	result = libfsext_directory_entry_get_utf16_name(
1087 	          directory_entry,
1088 	          NULL,
1089 	          256,
1090 	          &error );
1091 
1092 	FSEXT_TEST_ASSERT_EQUAL_INT(
1093 	 "result",
1094 	 result,
1095 	 -1 );
1096 
1097 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
1098 	 "error",
1099 	 error );
1100 
1101 	libcerror_error_free(
1102 	 &error );
1103 
1104 	result = libfsext_directory_entry_get_utf16_name(
1105 	          directory_entry,
1106 	          utf16_name,
1107 	          0,
1108 	          &error );
1109 
1110 	FSEXT_TEST_ASSERT_EQUAL_INT(
1111 	 "result",
1112 	 result,
1113 	 -1 );
1114 
1115 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
1116 	 "error",
1117 	 error );
1118 
1119 	libcerror_error_free(
1120 	 &error );
1121 
1122 	result = libfsext_directory_entry_get_utf16_name(
1123 	          directory_entry,
1124 	          utf16_name,
1125 	          (size_t) SSIZE_MAX + 1,
1126 	          &error );
1127 
1128 	FSEXT_TEST_ASSERT_EQUAL_INT(
1129 	 "result",
1130 	 result,
1131 	 -1 );
1132 
1133 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
1134 	 "error",
1135 	 error );
1136 
1137 	libcerror_error_free(
1138 	 &error );
1139 
1140 	return( 1 );
1141 
1142 on_error:
1143 	if( error != NULL )
1144 	{
1145 		libcerror_error_free(
1146 		 &error );
1147 	}
1148 	return( 0 );
1149 }
1150 
1151 #endif /* defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT ) */
1152 
1153 /* The main program
1154  */
1155 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
wmain(int argc FSEXT_TEST_ATTRIBUTE_UNUSED,wchar_t * const argv[]FSEXT_TEST_ATTRIBUTE_UNUSED)1156 int wmain(
1157      int argc FSEXT_TEST_ATTRIBUTE_UNUSED,
1158      wchar_t * const argv[] FSEXT_TEST_ATTRIBUTE_UNUSED )
1159 #else
1160 int main(
1161      int argc FSEXT_TEST_ATTRIBUTE_UNUSED,
1162      char * const argv[] FSEXT_TEST_ATTRIBUTE_UNUSED )
1163 #endif
1164 {
1165 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
1166 	libcerror_error_t *error                    = NULL;
1167 	libfsext_directory_entry_t *directory_entry = NULL;
1168 	int result                                  = 0;
1169 #endif
1170 
1171 	FSEXT_TEST_UNREFERENCED_PARAMETER( argc )
1172 	FSEXT_TEST_UNREFERENCED_PARAMETER( argv )
1173 
1174 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
1175 
1176 	FSEXT_TEST_RUN(
1177 	 "libfsext_directory_entry_initialize",
1178 	 fsext_test_directory_entry_initialize );
1179 
1180 	FSEXT_TEST_RUN(
1181 	 "libfsext_directory_entry_free",
1182 	 fsext_test_directory_entry_free );
1183 
1184 	FSEXT_TEST_RUN(
1185 	 "libfsext_directory_entry_clone",
1186 	 fsext_test_directory_entry_clone );
1187 
1188 	FSEXT_TEST_RUN(
1189 	 "libfsext_directory_entry_read_data",
1190 	 fsext_test_directory_entry_read_data );
1191 
1192 	/* TODO: add tests for libfsext_directory_entry_compare_with_utf8_string */
1193 
1194 	/* TODO: add tests for libfsext_directory_entry_compare_with_utf16_string */
1195 
1196 #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )
1197 
1198 	/* Initialize directory_entry for tests
1199 	 */
1200 	result = libfsext_directory_entry_initialize(
1201 	          &directory_entry,
1202 	          &error );
1203 
1204 	FSEXT_TEST_ASSERT_EQUAL_INT(
1205 	 "result",
1206 	 result,
1207 	 1 );
1208 
1209 	FSEXT_TEST_ASSERT_IS_NOT_NULL(
1210 	 "directory_entry",
1211 	 directory_entry );
1212 
1213 	FSEXT_TEST_ASSERT_IS_NULL(
1214 	 "error",
1215 	 error );
1216 
1217 	result = libfsext_directory_entry_read_data(
1218 	          directory_entry,
1219 	          fsext_test_directory_entry_data1,
1220 	          16,
1221 	          &error );
1222 
1223 	FSEXT_TEST_ASSERT_EQUAL_INT(
1224 	 "result",
1225 	 result,
1226 	 1 );
1227 
1228 	FSEXT_TEST_ASSERT_IS_NULL(
1229 	 "error",
1230 	 error );
1231 
1232 	/* Run tests
1233 	 */
1234 	FSEXT_TEST_RUN_WITH_ARGS(
1235 	 "libfsext_directory_entry_get_inode_number",
1236 	 fsext_test_directory_entry_get_inode_number,
1237 	 directory_entry );
1238 
1239 	FSEXT_TEST_RUN_WITH_ARGS(
1240 	 "libfsext_directory_entry_get_utf8_name_size",
1241 	 fsext_test_directory_entry_get_utf8_name_size,
1242 	 directory_entry );
1243 
1244 	FSEXT_TEST_RUN_WITH_ARGS(
1245 	 "libfsext_directory_entry_get_utf8_name",
1246 	 fsext_test_directory_entry_get_utf8_name,
1247 	 directory_entry );
1248 
1249 	FSEXT_TEST_RUN_WITH_ARGS(
1250 	 "libfsext_directory_entry_get_utf16_name_size",
1251 	 fsext_test_directory_entry_get_utf16_name_size,
1252 	 directory_entry );
1253 
1254 	FSEXT_TEST_RUN_WITH_ARGS(
1255 	 "libfsext_directory_entry_get_utf16_name",
1256 	 fsext_test_directory_entry_get_utf16_name,
1257 	 directory_entry );
1258 
1259 	/* Clean up
1260 	 */
1261 	result = libfsext_directory_entry_free(
1262 	          &directory_entry,
1263 	          &error );
1264 
1265 	FSEXT_TEST_ASSERT_EQUAL_INT(
1266 	 "result",
1267 	 result,
1268 	 1 );
1269 
1270 	FSEXT_TEST_ASSERT_IS_NULL(
1271 	 "directory_entry",
1272 	 directory_entry );
1273 
1274 	FSEXT_TEST_ASSERT_IS_NULL(
1275 	 "error",
1276 	 error );
1277 
1278 #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */
1279 
1280 #endif /* defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT ) */
1281 
1282 	return( EXIT_SUCCESS );
1283 
1284 #if defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT )
1285 
1286 on_error:
1287 #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )
1288 
1289 	if( error != NULL )
1290 	{
1291 		libcerror_error_free(
1292 		 &error );
1293 	}
1294 	if( directory_entry != NULL )
1295 	{
1296 		libfsext_directory_entry_free(
1297 		 &directory_entry,
1298 		 NULL );
1299 	}
1300 #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */
1301 
1302 	return( EXIT_FAILURE );
1303 
1304 #endif /* defined( __GNUC__ ) && !defined( LIBFSEXT_DLL_IMPORT ) */
1305 }
1306 
1307