1 /*
2 * Library sparse_bundle_xml_plist type test program
3 *
4 * Copyright (C) 2012-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 "modi_test_functions.h"
32 #include "modi_test_libbfio.h"
33 #include "modi_test_libcerror.h"
34 #include "modi_test_libmodi.h"
35 #include "modi_test_macros.h"
36 #include "modi_test_memory.h"
37 #include "modi_test_unused.h"
38
39 #include "../libmodi/libmodi_sparse_bundle_xml_plist.h"
40
41 uint8_t modi_test_sparse_bundle_xml_plist_data1[ 494 ] = {
42 0x3c, 0x3f, 0x78, 0x6d, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x31,
43 0x2e, 0x30, 0x22, 0x20, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3d, 0x22, 0x55, 0x54,
44 0x46, 0x2d, 0x38, 0x22, 0x3f, 0x3e, 0x0a, 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45,
45 0x20, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x22, 0x2d,
46 0x2f, 0x2f, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x2f, 0x2f, 0x44, 0x54, 0x44, 0x20, 0x50, 0x4c, 0x49,
47 0x53, 0x54, 0x20, 0x31, 0x2e, 0x30, 0x2f, 0x2f, 0x45, 0x4e, 0x22, 0x20, 0x22, 0x68, 0x74, 0x74,
48 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
49 0x6d, 0x2f, 0x44, 0x54, 0x44, 0x73, 0x2f, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x4c,
50 0x69, 0x73, 0x74, 0x2d, 0x31, 0x2e, 0x30, 0x2e, 0x64, 0x74, 0x64, 0x22, 0x3e, 0x0a, 0x3c, 0x70,
51 0x6c, 0x69, 0x73, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x31, 0x2e,
52 0x30, 0x22, 0x3e, 0x0a, 0x3c, 0x64, 0x69, 0x63, 0x74, 0x3e, 0x0a, 0x09, 0x3c, 0x6b, 0x65, 0x79,
53 0x3e, 0x43, 0x46, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x44, 0x69, 0x63,
54 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x72, 0x79, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3c, 0x2f,
55 0x6b, 0x65, 0x79, 0x3e, 0x0a, 0x09, 0x3c, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3e, 0x36, 0x2e,
56 0x30, 0x3c, 0x2f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3e, 0x0a, 0x09, 0x3c, 0x6b, 0x65, 0x79,
57 0x3e, 0x62, 0x61, 0x6e, 0x64, 0x2d, 0x73, 0x69, 0x7a, 0x65, 0x3c, 0x2f, 0x6b, 0x65, 0x79, 0x3e,
58 0x0a, 0x09, 0x3c, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x3e, 0x38, 0x33, 0x38, 0x38, 0x36,
59 0x30, 0x38, 0x3c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x3e, 0x0a, 0x09, 0x3c, 0x6b,
60 0x65, 0x79, 0x3e, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x2d, 0x62, 0x61, 0x63, 0x6b, 0x69, 0x6e,
61 0x67, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2d, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3c, 0x2f,
62 0x6b, 0x65, 0x79, 0x3e, 0x0a, 0x09, 0x3c, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x3e, 0x31,
63 0x3c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x3e, 0x0a, 0x09, 0x3c, 0x6b, 0x65, 0x79,
64 0x3e, 0x64, 0x69, 0x73, 0x6b, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2d, 0x62, 0x75, 0x6e, 0x64, 0x6c,
65 0x65, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3c, 0x2f, 0x6b, 0x65, 0x79, 0x3e, 0x0a, 0x09, 0x3c, 0x73,
66 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3e, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e,
67 0x64, 0x69, 0x73, 0x6b, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x73, 0x70, 0x61, 0x72, 0x73, 0x65,
68 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x3c, 0x2f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x3e, 0x0a,
69 0x09, 0x3c, 0x6b, 0x65, 0x79, 0x3e, 0x73, 0x69, 0x7a, 0x65, 0x3c, 0x2f, 0x6b, 0x65, 0x79, 0x3e,
70 0x0a, 0x09, 0x3c, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x3e, 0x34, 0x31, 0x39, 0x34, 0x33,
71 0x30, 0x34, 0x3c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x3e, 0x0a, 0x3c, 0x2f, 0x64,
72 0x69, 0x63, 0x74, 0x3e, 0x0a, 0x3c, 0x2f, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x3e, 0x0a };
73
74 #if defined( __GNUC__ ) && !defined( LIBMODI_DLL_IMPORT )
75
76 /* Tests the libmodi_sparse_bundle_xml_plist_initialize function
77 * Returns 1 if successful or 0 if not
78 */
modi_test_sparse_bundle_xml_plist_initialize(void)79 int modi_test_sparse_bundle_xml_plist_initialize(
80 void )
81 {
82 libcerror_error_t *error = NULL;
83 libmodi_sparse_bundle_xml_plist_t *sparse_bundle_xml_plist = NULL;
84 int result = 0;
85
86 #if defined( HAVE_MODI_TEST_MEMORY )
87 int number_of_malloc_fail_tests = 1;
88 int number_of_memset_fail_tests = 1;
89 int test_number = 0;
90 #endif
91
92 /* Test regular cases
93 */
94 result = libmodi_sparse_bundle_xml_plist_initialize(
95 &sparse_bundle_xml_plist,
96 &error );
97
98 MODI_TEST_ASSERT_EQUAL_INT(
99 "result",
100 result,
101 1 );
102
103 MODI_TEST_ASSERT_IS_NOT_NULL(
104 "sparse_bundle_xml_plist",
105 sparse_bundle_xml_plist );
106
107 MODI_TEST_ASSERT_IS_NULL(
108 "error",
109 error );
110
111 result = libmodi_sparse_bundle_xml_plist_free(
112 &sparse_bundle_xml_plist,
113 &error );
114
115 MODI_TEST_ASSERT_EQUAL_INT(
116 "result",
117 result,
118 1 );
119
120 MODI_TEST_ASSERT_IS_NULL(
121 "sparse_bundle_xml_plist",
122 sparse_bundle_xml_plist );
123
124 MODI_TEST_ASSERT_IS_NULL(
125 "error",
126 error );
127
128 /* Test error cases
129 */
130 result = libmodi_sparse_bundle_xml_plist_initialize(
131 NULL,
132 &error );
133
134 MODI_TEST_ASSERT_EQUAL_INT(
135 "result",
136 result,
137 -1 );
138
139 MODI_TEST_ASSERT_IS_NOT_NULL(
140 "error",
141 error );
142
143 libcerror_error_free(
144 &error );
145
146 sparse_bundle_xml_plist = (libmodi_sparse_bundle_xml_plist_t *) 0x12345678UL;
147
148 result = libmodi_sparse_bundle_xml_plist_initialize(
149 &sparse_bundle_xml_plist,
150 &error );
151
152 sparse_bundle_xml_plist = NULL;
153
154 MODI_TEST_ASSERT_EQUAL_INT(
155 "result",
156 result,
157 -1 );
158
159 MODI_TEST_ASSERT_IS_NOT_NULL(
160 "error",
161 error );
162
163 libcerror_error_free(
164 &error );
165
166 #if defined( HAVE_MODI_TEST_MEMORY )
167
168 for( test_number = 0;
169 test_number < number_of_malloc_fail_tests;
170 test_number++ )
171 {
172 /* Test libmodi_sparse_bundle_xml_plist_initialize with malloc failing
173 */
174 modi_test_malloc_attempts_before_fail = test_number;
175
176 result = libmodi_sparse_bundle_xml_plist_initialize(
177 &sparse_bundle_xml_plist,
178 &error );
179
180 if( modi_test_malloc_attempts_before_fail != -1 )
181 {
182 modi_test_malloc_attempts_before_fail = -1;
183
184 if( sparse_bundle_xml_plist != NULL )
185 {
186 libmodi_sparse_bundle_xml_plist_free(
187 &sparse_bundle_xml_plist,
188 NULL );
189 }
190 }
191 else
192 {
193 MODI_TEST_ASSERT_EQUAL_INT(
194 "result",
195 result,
196 -1 );
197
198 MODI_TEST_ASSERT_IS_NULL(
199 "sparse_bundle_xml_plist",
200 sparse_bundle_xml_plist );
201
202 MODI_TEST_ASSERT_IS_NOT_NULL(
203 "error",
204 error );
205
206 libcerror_error_free(
207 &error );
208 }
209 }
210 for( test_number = 0;
211 test_number < number_of_memset_fail_tests;
212 test_number++ )
213 {
214 /* Test libmodi_sparse_bundle_xml_plist_initialize with memset failing
215 */
216 modi_test_memset_attempts_before_fail = test_number;
217
218 result = libmodi_sparse_bundle_xml_plist_initialize(
219 &sparse_bundle_xml_plist,
220 &error );
221
222 if( modi_test_memset_attempts_before_fail != -1 )
223 {
224 modi_test_memset_attempts_before_fail = -1;
225
226 if( sparse_bundle_xml_plist != NULL )
227 {
228 libmodi_sparse_bundle_xml_plist_free(
229 &sparse_bundle_xml_plist,
230 NULL );
231 }
232 }
233 else
234 {
235 MODI_TEST_ASSERT_EQUAL_INT(
236 "result",
237 result,
238 -1 );
239
240 MODI_TEST_ASSERT_IS_NULL(
241 "sparse_bundle_xml_plist",
242 sparse_bundle_xml_plist );
243
244 MODI_TEST_ASSERT_IS_NOT_NULL(
245 "error",
246 error );
247
248 libcerror_error_free(
249 &error );
250 }
251 }
252 #endif /* defined( HAVE_MODI_TEST_MEMORY ) */
253
254 return( 1 );
255
256 on_error:
257 if( error != NULL )
258 {
259 libcerror_error_free(
260 &error );
261 }
262 if( sparse_bundle_xml_plist != NULL )
263 {
264 libmodi_sparse_bundle_xml_plist_free(
265 &sparse_bundle_xml_plist,
266 NULL );
267 }
268 return( 0 );
269 }
270
271 /* Tests the libmodi_sparse_bundle_xml_plist_free function
272 * Returns 1 if successful or 0 if not
273 */
modi_test_sparse_bundle_xml_plist_free(void)274 int modi_test_sparse_bundle_xml_plist_free(
275 void )
276 {
277 libcerror_error_t *error = NULL;
278 int result = 0;
279
280 /* Test error cases
281 */
282 result = libmodi_sparse_bundle_xml_plist_free(
283 NULL,
284 &error );
285
286 MODI_TEST_ASSERT_EQUAL_INT(
287 "result",
288 result,
289 -1 );
290
291 MODI_TEST_ASSERT_IS_NOT_NULL(
292 "error",
293 error );
294
295 libcerror_error_free(
296 &error );
297
298 return( 1 );
299
300 on_error:
301 if( error != NULL )
302 {
303 libcerror_error_free(
304 &error );
305 }
306 return( 0 );
307 }
308
309 /* Tests the libmodi_sparse_bundle_xml_plist_read_data function
310 * Returns 1 if successful or 0 if not
311 */
modi_test_sparse_bundle_xml_plist_read_data(void)312 int modi_test_sparse_bundle_xml_plist_read_data(
313 void )
314 {
315 libcerror_error_t *error = NULL;
316 libmodi_sparse_bundle_xml_plist_t *sparse_bundle_xml_plist = NULL;
317 int result = 0;
318
319 /* Initialize test
320 */
321 result = libmodi_sparse_bundle_xml_plist_initialize(
322 &sparse_bundle_xml_plist,
323 &error );
324
325 MODI_TEST_ASSERT_EQUAL_INT(
326 "result",
327 result,
328 1 );
329
330 MODI_TEST_ASSERT_IS_NOT_NULL(
331 "sparse_bundle_xml_plist",
332 sparse_bundle_xml_plist );
333
334 MODI_TEST_ASSERT_IS_NULL(
335 "error",
336 error );
337
338 /* Test regular cases
339 */
340 result = libmodi_sparse_bundle_xml_plist_read_data(
341 sparse_bundle_xml_plist,
342 modi_test_sparse_bundle_xml_plist_data1,
343 494,
344 &error );
345
346 MODI_TEST_ASSERT_EQUAL_INT(
347 "result",
348 result,
349 1 );
350
351 MODI_TEST_ASSERT_IS_NULL(
352 "error",
353 error );
354
355 /* Test error cases
356 */
357 result = libmodi_sparse_bundle_xml_plist_read_data(
358 NULL,
359 modi_test_sparse_bundle_xml_plist_data1,
360 494,
361 &error );
362
363 MODI_TEST_ASSERT_EQUAL_INT(
364 "result",
365 result,
366 -1 );
367
368 MODI_TEST_ASSERT_IS_NOT_NULL(
369 "error",
370 error );
371
372 libcerror_error_free(
373 &error );
374
375 result = libmodi_sparse_bundle_xml_plist_read_data(
376 sparse_bundle_xml_plist,
377 NULL,
378 494,
379 &error );
380
381 MODI_TEST_ASSERT_EQUAL_INT(
382 "result",
383 result,
384 -1 );
385
386 MODI_TEST_ASSERT_IS_NOT_NULL(
387 "error",
388 error );
389
390 libcerror_error_free(
391 &error );
392
393 result = libmodi_sparse_bundle_xml_plist_read_data(
394 sparse_bundle_xml_plist,
395 modi_test_sparse_bundle_xml_plist_data1,
396 (size_t) SSIZE_MAX + 1,
397 &error );
398
399 MODI_TEST_ASSERT_EQUAL_INT(
400 "result",
401 result,
402 -1 );
403
404 MODI_TEST_ASSERT_IS_NOT_NULL(
405 "error",
406 error );
407
408 libcerror_error_free(
409 &error );
410
411 result = libmodi_sparse_bundle_xml_plist_read_data(
412 sparse_bundle_xml_plist,
413 modi_test_sparse_bundle_xml_plist_data1,
414 0,
415 &error );
416
417 MODI_TEST_ASSERT_EQUAL_INT(
418 "result",
419 result,
420 -1 );
421
422 MODI_TEST_ASSERT_IS_NOT_NULL(
423 "error",
424 error );
425
426 libcerror_error_free(
427 &error );
428
429 #if defined( HAVE_MODI_TEST_MEMORY ) && defined( BOGUS )
430 /* TODO handle "out of dynamic memory in yy_scan_buffer()" */
431
432 /* Test libmodi_sparse_bundle_xml_plist_read_data with malloc failing in libfplist_property_list_initialize
433 */
434 modi_test_malloc_attempts_before_fail = 0;
435
436 result = libmodi_sparse_bundle_xml_plist_read_data(
437 sparse_bundle_xml_plist,
438 modi_test_sparse_bundle_xml_plist_data1,
439 494,
440 &error );
441
442 if( modi_test_malloc_attempts_before_fail != -1 )
443 {
444 modi_test_malloc_attempts_before_fail = -1;
445 }
446 else
447 {
448 MODI_TEST_ASSERT_EQUAL_INT(
449 "result",
450 result,
451 -1 );
452
453 MODI_TEST_ASSERT_IS_NOT_NULL(
454 "error",
455 error );
456
457 libcerror_error_free(
458 &error );
459 }
460 /* Test libmodi_sparse_bundle_xml_plist_read_data with malloc failing in libfplist_property_list_get_root_property
461 */
462 modi_test_malloc_attempts_before_fail = 1;
463
464 result = libmodi_sparse_bundle_xml_plist_read_data(
465 sparse_bundle_xml_plist,
466 modi_test_sparse_bundle_xml_plist_data1,
467 494,
468 &error );
469
470 if( modi_test_malloc_attempts_before_fail != -1 )
471 {
472 modi_test_malloc_attempts_before_fail = -1;
473 }
474 else
475 {
476 MODI_TEST_ASSERT_EQUAL_INT(
477 "result",
478 result,
479 -1 );
480
481 MODI_TEST_ASSERT_IS_NOT_NULL(
482 "error",
483 error );
484
485 libcerror_error_free(
486 &error );
487 }
488 #endif /* defined( HAVE_MODI_TEST_MEMORY ) */
489
490 /* Clean up
491 */
492 result = libmodi_sparse_bundle_xml_plist_free(
493 &sparse_bundle_xml_plist,
494 &error );
495
496 MODI_TEST_ASSERT_EQUAL_INT(
497 "result",
498 result,
499 1 );
500
501 MODI_TEST_ASSERT_IS_NULL(
502 "sparse_bundle_xml_plist",
503 sparse_bundle_xml_plist );
504
505 MODI_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( sparse_bundle_xml_plist != NULL )
518 {
519 libmodi_sparse_bundle_xml_plist_free(
520 &sparse_bundle_xml_plist,
521 NULL );
522 }
523 return( 0 );
524 }
525
526 /* Tests the libmodi_sparse_bundle_xml_plist_read_file_io_handle function
527 * Returns 1 if successful or 0 if not
528 */
modi_test_sparse_bundle_xml_plist_read_file_io_handle(void)529 int modi_test_sparse_bundle_xml_plist_read_file_io_handle(
530 void )
531 {
532 libbfio_handle_t *file_io_handle = NULL;
533 libcerror_error_t *error = NULL;
534 libmodi_sparse_bundle_xml_plist_t *sparse_bundle_xml_plist = NULL;
535 int result = 0;
536
537 /* Initialize test
538 */
539 result = libmodi_sparse_bundle_xml_plist_initialize(
540 &sparse_bundle_xml_plist,
541 &error );
542
543 MODI_TEST_ASSERT_EQUAL_INT(
544 "result",
545 result,
546 1 );
547
548 MODI_TEST_ASSERT_IS_NOT_NULL(
549 "sparse_bundle_xml_plist",
550 sparse_bundle_xml_plist );
551
552 MODI_TEST_ASSERT_IS_NULL(
553 "error",
554 error );
555
556 /* Initialize file IO handle
557 */
558 result = modi_test_open_file_io_handle(
559 &file_io_handle,
560 modi_test_sparse_bundle_xml_plist_data1,
561 494,
562 &error );
563
564 MODI_TEST_ASSERT_EQUAL_INT(
565 "result",
566 result,
567 1 );
568
569 MODI_TEST_ASSERT_IS_NOT_NULL(
570 "file_io_handle",
571 file_io_handle );
572
573 MODI_TEST_ASSERT_IS_NULL(
574 "error",
575 error );
576
577 /* Test regular cases
578 */
579 result = libmodi_sparse_bundle_xml_plist_read_file_io_handle(
580 sparse_bundle_xml_plist,
581 file_io_handle,
582 0,
583 494,
584 &error );
585
586 MODI_TEST_ASSERT_EQUAL_INT(
587 "result",
588 result,
589 1 );
590
591 MODI_TEST_ASSERT_IS_NULL(
592 "error",
593 error );
594
595 /* Test error cases
596 */
597 result = libmodi_sparse_bundle_xml_plist_read_file_io_handle(
598 NULL,
599 file_io_handle,
600 0,
601 494,
602 &error );
603
604 MODI_TEST_ASSERT_EQUAL_INT(
605 "result",
606 result,
607 -1 );
608
609 MODI_TEST_ASSERT_IS_NOT_NULL(
610 "error",
611 error );
612
613 libcerror_error_free(
614 &error );
615
616 result = libmodi_sparse_bundle_xml_plist_read_file_io_handle(
617 sparse_bundle_xml_plist,
618 NULL,
619 0,
620 494,
621 &error );
622
623 MODI_TEST_ASSERT_EQUAL_INT(
624 "result",
625 result,
626 -1 );
627
628 MODI_TEST_ASSERT_IS_NOT_NULL(
629 "error",
630 error );
631
632 libcerror_error_free(
633 &error );
634
635 result = libmodi_sparse_bundle_xml_plist_read_file_io_handle(
636 sparse_bundle_xml_plist,
637 file_io_handle,
638 -1,
639 494,
640 &error );
641
642 MODI_TEST_ASSERT_EQUAL_INT(
643 "result",
644 result,
645 -1 );
646
647 MODI_TEST_ASSERT_IS_NOT_NULL(
648 "error",
649 error );
650
651 libcerror_error_free(
652 &error );
653
654 result = libmodi_sparse_bundle_xml_plist_read_file_io_handle(
655 sparse_bundle_xml_plist,
656 file_io_handle,
657 0,
658 (size64_t) SSIZE_MAX + 1,
659 &error );
660
661 MODI_TEST_ASSERT_EQUAL_INT(
662 "result",
663 result,
664 -1 );
665
666 MODI_TEST_ASSERT_IS_NOT_NULL(
667 "error",
668 error );
669
670 libcerror_error_free(
671 &error );
672
673 /* Clean up file IO handle
674 */
675 result = modi_test_close_file_io_handle(
676 &file_io_handle,
677 &error );
678
679 MODI_TEST_ASSERT_EQUAL_INT(
680 "result",
681 result,
682 0 );
683
684 MODI_TEST_ASSERT_IS_NULL(
685 "error",
686 error );
687
688 /* Test data too small
689 */
690 result = modi_test_open_file_io_handle(
691 &file_io_handle,
692 modi_test_sparse_bundle_xml_plist_data1,
693 8,
694 &error );
695
696 MODI_TEST_ASSERT_EQUAL_INT(
697 "result",
698 result,
699 1 );
700
701 MODI_TEST_ASSERT_IS_NOT_NULL(
702 "file_io_handle",
703 file_io_handle );
704
705 MODI_TEST_ASSERT_IS_NULL(
706 "error",
707 error );
708
709 result = libmodi_sparse_bundle_xml_plist_read_file_io_handle(
710 sparse_bundle_xml_plist,
711 file_io_handle,
712 0,
713 494,
714 &error );
715
716 MODI_TEST_ASSERT_EQUAL_INT(
717 "result",
718 result,
719 -1 );
720
721 MODI_TEST_ASSERT_IS_NOT_NULL(
722 "error",
723 error );
724
725 libcerror_error_free(
726 &error );
727
728 result = modi_test_close_file_io_handle(
729 &file_io_handle,
730 &error );
731
732 MODI_TEST_ASSERT_EQUAL_INT(
733 "result",
734 result,
735 0 );
736
737 MODI_TEST_ASSERT_IS_NULL(
738 "error",
739 error );
740
741 /* Clean up
742 */
743 result = libmodi_sparse_bundle_xml_plist_free(
744 &sparse_bundle_xml_plist,
745 &error );
746
747 MODI_TEST_ASSERT_EQUAL_INT(
748 "result",
749 result,
750 1 );
751
752 MODI_TEST_ASSERT_IS_NULL(
753 "sparse_bundle_xml_plist",
754 sparse_bundle_xml_plist );
755
756 MODI_TEST_ASSERT_IS_NULL(
757 "error",
758 error );
759
760 return( 1 );
761
762 on_error:
763 if( error != NULL )
764 {
765 libcerror_error_free(
766 &error );
767 }
768 if( file_io_handle != NULL )
769 {
770 libbfio_handle_free(
771 &file_io_handle,
772 NULL );
773 }
774 if( sparse_bundle_xml_plist != NULL )
775 {
776 libmodi_sparse_bundle_xml_plist_free(
777 &sparse_bundle_xml_plist,
778 NULL );
779 }
780 return( 0 );
781 }
782
783 #endif /* defined( __GNUC__ ) && !defined( LIBMODI_DLL_IMPORT ) */
784
785 /* The main program
786 */
787 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
wmain(int argc MODI_TEST_ATTRIBUTE_UNUSED,wchar_t * const argv[]MODI_TEST_ATTRIBUTE_UNUSED)788 int wmain(
789 int argc MODI_TEST_ATTRIBUTE_UNUSED,
790 wchar_t * const argv[] MODI_TEST_ATTRIBUTE_UNUSED )
791 #else
792 int main(
793 int argc MODI_TEST_ATTRIBUTE_UNUSED,
794 char * const argv[] MODI_TEST_ATTRIBUTE_UNUSED )
795 #endif
796 {
797 MODI_TEST_UNREFERENCED_PARAMETER( argc )
798 MODI_TEST_UNREFERENCED_PARAMETER( argv )
799
800 #if defined( __GNUC__ ) && !defined( LIBMODI_DLL_IMPORT )
801
802 MODI_TEST_RUN(
803 "libmodi_sparse_bundle_xml_plist_initialize",
804 modi_test_sparse_bundle_xml_plist_initialize );
805
806 MODI_TEST_RUN(
807 "libmodi_sparse_bundle_xml_plist_free",
808 modi_test_sparse_bundle_xml_plist_free );
809
810 MODI_TEST_RUN(
811 "libmodi_sparse_bundle_xml_plist_read_data",
812 modi_test_sparse_bundle_xml_plist_read_data );
813
814 MODI_TEST_RUN(
815 "libmodi_sparse_bundle_xml_plist_read_file_io_handle",
816 modi_test_sparse_bundle_xml_plist_read_file_io_handle );
817
818 #endif /* defined( __GNUC__ ) && !defined( LIBMODI_DLL_IMPORT ) */
819
820 return( EXIT_SUCCESS );
821
822 #if defined( __GNUC__ ) && !defined( LIBMODI_DLL_IMPORT )
823
824 on_error:
825 return( EXIT_FAILURE );
826
827 #endif /* defined( __GNUC__ ) && !defined( LIBMODI_DLL_IMPORT ) */
828 }
829
830