Debian Codegraph @

tests/vhdi_test_dynamic_disk_header.c

raw symbols SCIP
1 /*
2 * Library dynamic_disk_header type test program
3 *
4 * Copyright (C) 2012-2025, Joachim Metz <[email protected]>
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 "vhdi_test_functions.h"
32 #include "vhdi_test_libbfio.h"
33 #include "vhdi_test_libcerror.h"
34 #include "vhdi_test_libvhdi.h"
35 #include "vhdi_test_macros.h"
36 #include "vhdi_test_memory.h"
37 #include "vhdi_test_unused.h"
38
39 #include "../libvhdi/libvhdi_dynamic_disk_header.h"
40
41 uint8_t vhdi_test_dynamic_disk_header_data1[ 1024 ] = {
42 0x63, 0x78, 0x73, 0x70, 0x61, 0x72, 0x73, 0x65, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
44 0x00, 0x20, 0x00, 0x00, 0xff, 0xff, 0xe1, 0xc1, 0xd4, 0x9c, 0x5c, 0x80, 0x35, 0x0a, 0x4a, 0x89,
45 0x89, 0x8a, 0x5a, 0xd6, 0xd1, 0x0f, 0x65, 0x78, 0x19, 0x22, 0x07, 0x7c, 0x00, 0x00, 0x00, 0x00,
46 0x00, 0x64, 0x00, 0x79, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x63, 0x00, 0x2e,
47 0x00, 0x76, 0x00, 0x68, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x57, 0x32, 0x6b, 0x75, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x57, 0x32, 0x72, 0x75, 0x00, 0x00, 0x02, 0x00,
86 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
87 0x57, 0x69, 0x32, 0x6b, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x57, 0x69, 0x32, 0x72, 0x00, 0x00, 0x02, 0x00,
89 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
106
107 #if defined( __GNUC__ ) && !defined( LIBVHDI_DLL_IMPORT )
108
109 /* Tests the libvhdi_dynamic_disk_header_initialize function
110 * Returns 1 if successful or 0 if not
111 */
112 int vhdi_test_dynamic_disk_header_initialize(
113 void )
114 {
115 libcerror_error_t *error = NULL;
116 libvhdi_dynamic_disk_header_t *dynamic_disk_header = NULL;
117 int result = 0;
118
119 #if defined( HAVE_VHDI_TEST_MEMORY )
120 int number_of_malloc_fail_tests = 1;
121 int number_of_memset_fail_tests = 1;
122 int test_number = 0;
123 #endif
124
125 /* Test regular cases
126 */
127 result = libvhdi_dynamic_disk_header_initialize(
128 &dynamic_disk_header,
129 &error );
130
131 VHDI_TEST_ASSERT_EQUAL_INT(
132 "result",
133 result,
134 1 );
135
136 VHDI_TEST_ASSERT_IS_NOT_NULL(
137 "dynamic_disk_header",
138 dynamic_disk_header );
139
140 VHDI_TEST_ASSERT_IS_NULL(
141 "error",
142 error );
143
144 result = libvhdi_dynamic_disk_header_free(
145 &dynamic_disk_header,
146 &error );
147
148 VHDI_TEST_ASSERT_EQUAL_INT(
149 "result",
150 result,
151 1 );
152
153 VHDI_TEST_ASSERT_IS_NULL(
154 "dynamic_disk_header",
155 dynamic_disk_header );
156
157 VHDI_TEST_ASSERT_IS_NULL(
158 "error",
159 error );
160
161 /* Test error cases
162 */
163 result = libvhdi_dynamic_disk_header_initialize(
164 NULL,
165 &error );
166
167 VHDI_TEST_ASSERT_EQUAL_INT(
168 "result",
169 result,
170 -1 );
171
172 VHDI_TEST_ASSERT_IS_NOT_NULL(
173 "error",
174 error );
175
176 libcerror_error_free(
177 &error );
178
179 dynamic_disk_header = (libvhdi_dynamic_disk_header_t *) 0x12345678UL;
180
181 result = libvhdi_dynamic_disk_header_initialize(
182 &dynamic_disk_header,
183 &error );
184
185 dynamic_disk_header = NULL;
186
187 VHDI_TEST_ASSERT_EQUAL_INT(
188 "result",
189 result,
190 -1 );
191
192 VHDI_TEST_ASSERT_IS_NOT_NULL(
193 "error",
194 error );
195
196 libcerror_error_free(
197 &error );
198
199 #if defined( HAVE_VHDI_TEST_MEMORY )
200
201 for( test_number = 0;
202 test_number < number_of_malloc_fail_tests;
203 test_number++ )
204 {
205 /* Test libvhdi_dynamic_disk_header_initialize with malloc failing
206 */
207 vhdi_test_malloc_attempts_before_fail = test_number;
208
209 result = libvhdi_dynamic_disk_header_initialize(
210 &dynamic_disk_header,
211 &error );
212
213 if( vhdi_test_malloc_attempts_before_fail != -1 )
214 {
215 vhdi_test_malloc_attempts_before_fail = -1;
216
217 if( dynamic_disk_header != NULL )
218 {
219 libvhdi_dynamic_disk_header_free(
220 &dynamic_disk_header,
221 NULL );
222 }
223 }
224 else
225 {
226 VHDI_TEST_ASSERT_EQUAL_INT(
227 "result",
228 result,
229 -1 );
230
231 VHDI_TEST_ASSERT_IS_NULL(
232 "dynamic_disk_header",
233 dynamic_disk_header );
234
235 VHDI_TEST_ASSERT_IS_NOT_NULL(
236 "error",
237 error );
238
239 libcerror_error_free(
240 &error );
241 }
242 }
243 for( test_number = 0;
244 test_number < number_of_memset_fail_tests;
245 test_number++ )
246 {
247 /* Test libvhdi_dynamic_disk_header_initialize with memset failing
248 */
249 vhdi_test_memset_attempts_before_fail = test_number;
250
251 result = libvhdi_dynamic_disk_header_initialize(
252 &dynamic_disk_header,
253 &error );
254
255 if( vhdi_test_memset_attempts_before_fail != -1 )
256 {
257 vhdi_test_memset_attempts_before_fail = -1;
258
259 if( dynamic_disk_header != NULL )
260 {
261 libvhdi_dynamic_disk_header_free(
262 &dynamic_disk_header,
263 NULL );
264 }
265 }
266 else
267 {
268 VHDI_TEST_ASSERT_EQUAL_INT(
269 "result",
270 result,
271 -1 );
272
273 VHDI_TEST_ASSERT_IS_NULL(
274 "dynamic_disk_header",
275 dynamic_disk_header );
276
277 VHDI_TEST_ASSERT_IS_NOT_NULL(
278 "error",
279 error );
280
281 libcerror_error_free(
282 &error );
283 }
284 }
285 #endif /* defined( HAVE_VHDI_TEST_MEMORY ) */
286
287 return( 1 );
288
289 on_error:
290 if( error != NULL )
291 {
292 libcerror_error_free(
293 &error );
294 }
295 if( dynamic_disk_header != NULL )
296 {
297 libvhdi_dynamic_disk_header_free(
298 &dynamic_disk_header,
299 NULL );
300 }
301 return( 0 );
302 }
303
304 /* Tests the libvhdi_dynamic_disk_header_free function
305 * Returns 1 if successful or 0 if not
306 */
307 int vhdi_test_dynamic_disk_header_free(
308 void )
309 {
310 libcerror_error_t *error = NULL;
311 int result = 0;
312
313 /* Test error cases
314 */
315 result = libvhdi_dynamic_disk_header_free(
316 NULL,
317 &error );
318
319 VHDI_TEST_ASSERT_EQUAL_INT(
320 "result",
321 result,
322 -1 );
323
324 VHDI_TEST_ASSERT_IS_NOT_NULL(
325 "error",
326 error );
327
328 libcerror_error_free(
329 &error );
330
331 return( 1 );
332
333 on_error:
334 if( error != NULL )
335 {
336 libcerror_error_free(
337 &error );
338 }
339 return( 0 );
340 }
341
342 /* Tests the libvhdi_dynamic_disk_header_read_data function
343 * Returns 1 if successful or 0 if not
344 */
345 int vhdi_test_dynamic_disk_header_read_data(
346 void )
347 {
348 libcerror_error_t *error = NULL;
349 libvhdi_dynamic_disk_header_t *dynamic_disk_header = NULL;
350 int result = 0;
351
352 #if defined( HAVE_VHDI_TEST_MEMORY )
353 int number_of_malloc_fail_tests = 1;
354 int number_of_memcpy_fail_tests = 2;
355 int test_number = 0;
356 #endif
357
358 /* Initialize test
359 */
360 result = libvhdi_dynamic_disk_header_initialize(
361 &dynamic_disk_header,
362 &error );
363
364 VHDI_TEST_ASSERT_EQUAL_INT(
365 "result",
366 result,
367 1 );
368
369 VHDI_TEST_ASSERT_IS_NOT_NULL(
370 "dynamic_disk_header",
371 dynamic_disk_header );
372
373 VHDI_TEST_ASSERT_IS_NULL(
374 "error",
375 error );
376
377 /* Test regular cases
378 */
379 result = libvhdi_dynamic_disk_header_read_data(
380 dynamic_disk_header,
381 vhdi_test_dynamic_disk_header_data1,
382 1024,
383 &error );
384
385 VHDI_TEST_ASSERT_EQUAL_INT(
386 "result",
387 result,
388 1 );
389
390 VHDI_TEST_ASSERT_IS_NULL(
391 "error",
392 error );
393
394 /* Clean up
395 */
396 result = libvhdi_dynamic_disk_header_free(
397 &dynamic_disk_header,
398 &error );
399
400 VHDI_TEST_ASSERT_EQUAL_INT(
401 "result",
402 result,
403 1 );
404
405 VHDI_TEST_ASSERT_IS_NULL(
406 "dynamic_disk_header",
407 dynamic_disk_header );
408
409 VHDI_TEST_ASSERT_IS_NULL(
410 "error",
411 error );
412
413 /* Initialize test
414 */
415 result = libvhdi_dynamic_disk_header_initialize(
416 &dynamic_disk_header,
417 &error );
418
419 VHDI_TEST_ASSERT_EQUAL_INT(
420 "result",
421 result,
422 1 );
423
424 VHDI_TEST_ASSERT_IS_NOT_NULL(
425 "dynamic_disk_header",
426 dynamic_disk_header );
427
428 VHDI_TEST_ASSERT_IS_NULL(
429 "error",
430 error );
431
432 /* Test error cases
433 */
434 result = libvhdi_dynamic_disk_header_read_data(
435 NULL,
436 vhdi_test_dynamic_disk_header_data1,
437 1024,
438 &error );
439
440 VHDI_TEST_ASSERT_EQUAL_INT(
441 "result",
442 result,
443 -1 );
444
445 VHDI_TEST_ASSERT_IS_NOT_NULL(
446 "error",
447 error );
448
449 libcerror_error_free(
450 &error );
451
452 result = libvhdi_dynamic_disk_header_read_data(
453 dynamic_disk_header,
454 NULL,
455 1024,
456 &error );
457
458 VHDI_TEST_ASSERT_EQUAL_INT(
459 "result",
460 result,
461 -1 );
462
463 VHDI_TEST_ASSERT_IS_NOT_NULL(
464 "error",
465 error );
466
467 libcerror_error_free(
468 &error );
469
470 result = libvhdi_dynamic_disk_header_read_data(
471 dynamic_disk_header,
472 vhdi_test_dynamic_disk_header_data1,
473 (size_t) SSIZE_MAX + 1,
474 &error );
475
476 VHDI_TEST_ASSERT_EQUAL_INT(
477 "result",
478 result,
479 -1 );
480
481 VHDI_TEST_ASSERT_IS_NOT_NULL(
482 "error",
483 error );
484
485 libcerror_error_free(
486 &error );
487
488 result = libvhdi_dynamic_disk_header_read_data(
489 dynamic_disk_header,
490 vhdi_test_dynamic_disk_header_data1,
491 0,
492 &error );
493
494 VHDI_TEST_ASSERT_EQUAL_INT(
495 "result",
496 result,
497 -1 );
498
499 VHDI_TEST_ASSERT_IS_NOT_NULL(
500 "error",
501 error );
502
503 libcerror_error_free(
504 &error );
505
506 #if defined( HAVE_VHDI_TEST_MEMORY )
507
508 for( test_number = 0;
509 test_number < number_of_malloc_fail_tests;
510 test_number++ )
511 {
512 /* Test libvhdi_dynamic_disk_header_read_data with malloc failing
513 */
514 vhdi_test_malloc_attempts_before_fail = test_number;
515
516 result = libvhdi_dynamic_disk_header_read_data(
517 dynamic_disk_header,
518 vhdi_test_dynamic_disk_header_data1,
519 1024,
520 &error );
521
522 if( vhdi_test_malloc_attempts_before_fail != -1 )
523 {
524 vhdi_test_malloc_attempts_before_fail = -1;
525 }
526 else
527 {
528 VHDI_TEST_ASSERT_EQUAL_INT(
529 "result",
530 result,
531 -1 );
532
533 VHDI_TEST_ASSERT_IS_NOT_NULL(
534 "error",
535 error );
536
537 libcerror_error_free(
538 &error );
539 }
540 }
541 for( test_number = 0;
542 test_number < number_of_memcpy_fail_tests;
543 test_number++ )
544 {
545 /* Test libvhdi_dynamic_disk_header_read_data with memcpy failing
546 */
547 vhdi_test_memcpy_attempts_before_fail = test_number;
548
549 result = libvhdi_dynamic_disk_header_read_data(
550 dynamic_disk_header,
551 vhdi_test_dynamic_disk_header_data1,
552 1024,
553 &error );
554
555 if( vhdi_test_memcpy_attempts_before_fail != -1 )
556 {
557 vhdi_test_memcpy_attempts_before_fail = -1;
558 }
559 else
560 {
561 VHDI_TEST_ASSERT_EQUAL_INT(
562 "result",
563 result,
564 -1 );
565
566 VHDI_TEST_ASSERT_IS_NOT_NULL(
567 "error",
568 error );
569
570 libcerror_error_free(
571 &error );
572 }
573 }
574 #endif /* defined( HAVE_VHDI_TEST_MEMORY ) */
575
576 /* Test error case where signature is invalid
577 */
578 byte_stream_copy_from_uint64_big_endian(
579 vhdi_test_dynamic_disk_header_data1,
580 0xffffffffffffffffUL );
581
582 result = libvhdi_dynamic_disk_header_read_data(
583 dynamic_disk_header,
584 vhdi_test_dynamic_disk_header_data1,
585 1024,
586 &error );
587
588 byte_stream_copy_from_uint64_big_endian(
589 vhdi_test_dynamic_disk_header_data1,
590 0x6378737061727365UL );
591
592 VHDI_TEST_ASSERT_EQUAL_INT(
593 "result",
594 result,
595 -1 );
596
597 VHDI_TEST_ASSERT_IS_NOT_NULL(
598 "error",
599 error );
600
601 libcerror_error_free(
602 &error );
603
604 /* Test error case where format version is invalid
605 */
606 byte_stream_copy_from_uint32_big_endian(
607 &( vhdi_test_dynamic_disk_header_data1[ 24 ] ),
608 0xffffffffUL );
609
610 result = libvhdi_dynamic_disk_header_read_data(
611 dynamic_disk_header,
612 vhdi_test_dynamic_disk_header_data1,
613 1024,
614 &error );
615
616 byte_stream_copy_from_uint32_big_endian(
617 &( vhdi_test_dynamic_disk_header_data1[ 24 ] ),
618 0x00010000UL );
619
620 VHDI_TEST_ASSERT_EQUAL_INT(
621 "result",
622 result,
623 -1 );
624
625 VHDI_TEST_ASSERT_IS_NOT_NULL(
626 "error",
627 error );
628
629 libcerror_error_free(
630 &error );
631
632 /* Test error case where block size is invalid
633 */
634 /* TODO implement */
635
636 /* Clean up
637 */
638 result = libvhdi_dynamic_disk_header_free(
639 &dynamic_disk_header,
640 &error );
641
642 VHDI_TEST_ASSERT_EQUAL_INT(
643 "result",
644 result,
645 1 );
646
647 VHDI_TEST_ASSERT_IS_NULL(
648 "dynamic_disk_header",
649 dynamic_disk_header );
650
651 VHDI_TEST_ASSERT_IS_NULL(
652 "error",
653 error );
654
655 return( 1 );
656
657 on_error:
658 if( error != NULL )
659 {
660 libcerror_error_free(
661 &error );
662 }
663 if( dynamic_disk_header != NULL )
664 {
665 libvhdi_dynamic_disk_header_free(
666 &dynamic_disk_header,
667 NULL );
668 }
669 return( 0 );
670 }
671
672 /* Tests the libvhdi_dynamic_disk_header_read_file_io_handle function
673 * Returns 1 if successful or 0 if not
674 */
675 int vhdi_test_dynamic_disk_header_read_file_io_handle(
676 void )
677 {
678 libbfio_handle_t *file_io_handle = NULL;
679 libcerror_error_t *error = NULL;
680 libvhdi_dynamic_disk_header_t *dynamic_disk_header = NULL;
681 int result = 0;
682
683 /* Initialize test
684 */
685 result = libvhdi_dynamic_disk_header_initialize(
686 &dynamic_disk_header,
687 &error );
688
689 VHDI_TEST_ASSERT_EQUAL_INT(
690 "result",
691 result,
692 1 );
693
694 VHDI_TEST_ASSERT_IS_NOT_NULL(
695 "dynamic_disk_header",
696 dynamic_disk_header );
697
698 VHDI_TEST_ASSERT_IS_NULL(
699 "error",
700 error );
701
702 /* Initialize file IO handle
703 */
704 result = vhdi_test_open_file_io_handle(
705 &file_io_handle,
706 vhdi_test_dynamic_disk_header_data1,
707 1024,
708 &error );
709
710 VHDI_TEST_ASSERT_EQUAL_INT(
711 "result",
712 result,
713 1 );
714
715 VHDI_TEST_ASSERT_IS_NOT_NULL(
716 "file_io_handle",
717 file_io_handle );
718
719 VHDI_TEST_ASSERT_IS_NULL(
720 "error",
721 error );
722
723 /* Test regular cases
724 */
725 result = libvhdi_dynamic_disk_header_read_file_io_handle(
726 dynamic_disk_header,
727 file_io_handle,
728 0,
729 &error );
730
731 VHDI_TEST_ASSERT_EQUAL_INT(
732 "result",
733 result,
734 1 );
735
736 VHDI_TEST_ASSERT_IS_NULL(
737 "error",
738 error );
739
740 /* Test error cases
741 */
742 result = libvhdi_dynamic_disk_header_read_file_io_handle(
743 NULL,
744 file_io_handle,
745 0,
746 &error );
747
748 VHDI_TEST_ASSERT_EQUAL_INT(
749 "result",
750 result,
751 -1 );
752
753 VHDI_TEST_ASSERT_IS_NOT_NULL(
754 "error",
755 error );
756
757 libcerror_error_free(
758 &error );
759
760 result = libvhdi_dynamic_disk_header_read_file_io_handle(
761 dynamic_disk_header,
762 NULL,
763 0,
764 &error );
765
766 VHDI_TEST_ASSERT_EQUAL_INT(
767 "result",
768 result,
769 -1 );
770
771 VHDI_TEST_ASSERT_IS_NOT_NULL(
772 "error",
773 error );
774
775 libcerror_error_free(
776 &error );
777
778 result = libvhdi_dynamic_disk_header_read_file_io_handle(
779 dynamic_disk_header,
780 file_io_handle,
781 -1,
782 &error );
783
784 VHDI_TEST_ASSERT_EQUAL_INT(
785 "result",
786 result,
787 -1 );
788
789 VHDI_TEST_ASSERT_IS_NOT_NULL(
790 "error",
791 error );
792
793 libcerror_error_free(
794 &error );
795
796 /* Test error case where signature is invalid
797 */
798 byte_stream_copy_from_uint64_big_endian(
799 vhdi_test_dynamic_disk_header_data1,
800 0xffffffffffffffffUL );
801
802 result = libvhdi_dynamic_disk_header_read_file_io_handle(
803 dynamic_disk_header,
804 file_io_handle,
805 0,
806 &error );
807
808 byte_stream_copy_from_uint64_big_endian(
809 vhdi_test_dynamic_disk_header_data1,
810 0x6378737061727365UL );
811
812 VHDI_TEST_ASSERT_EQUAL_INT(
813 "result",
814 result,
815 -1 );
816
817 VHDI_TEST_ASSERT_IS_NOT_NULL(
818 "error",
819 error );
820
821 libcerror_error_free(
822 &error );
823
824 /* Clean up file IO handle
825 */
826 result = vhdi_test_close_file_io_handle(
827 &file_io_handle,
828 &error );
829
830 VHDI_TEST_ASSERT_EQUAL_INT(
831 "result",
832 result,
833 0 );
834
835 VHDI_TEST_ASSERT_IS_NULL(
836 "error",
837 error );
838
839 /* Test data too small
840 */
841 result = vhdi_test_open_file_io_handle(
842 &file_io_handle,
843 vhdi_test_dynamic_disk_header_data1,
844 8,
845 &error );
846
847 VHDI_TEST_ASSERT_EQUAL_INT(
848 "result",
849 result,
850 1 );
851
852 VHDI_TEST_ASSERT_IS_NOT_NULL(
853 "file_io_handle",
854 file_io_handle );
855
856 VHDI_TEST_ASSERT_IS_NULL(
857 "error",
858 error );
859
860 result = libvhdi_dynamic_disk_header_read_file_io_handle(
861 dynamic_disk_header,
862 file_io_handle,
863 0,
864 &error );
865
866 VHDI_TEST_ASSERT_EQUAL_INT(
867 "result",
868 result,
869 -1 );
870
871 VHDI_TEST_ASSERT_IS_NOT_NULL(
872 "error",
873 error );
874
875 libcerror_error_free(
876 &error );
877
878 result = vhdi_test_close_file_io_handle(
879 &file_io_handle,
880 &error );
881
882 VHDI_TEST_ASSERT_EQUAL_INT(
883 "result",
884 result,
885 0 );
886
887 VHDI_TEST_ASSERT_IS_NULL(
888 "error",
889 error );
890
891 /* Clean up
892 */
893 result = libvhdi_dynamic_disk_header_free(
894 &dynamic_disk_header,
895 &error );
896
897 VHDI_TEST_ASSERT_EQUAL_INT(
898 "result",
899 result,
900 1 );
901
902 VHDI_TEST_ASSERT_IS_NULL(
903 "dynamic_disk_header",
904 dynamic_disk_header );
905
906 VHDI_TEST_ASSERT_IS_NULL(
907 "error",
908 error );
909
910 return( 1 );
911
912 on_error:
913 if( error != NULL )
914 {
915 libcerror_error_free(
916 &error );
917 }
918 if( file_io_handle != NULL )
919 {
920 libbfio_handle_free(
921 &file_io_handle,
922 NULL );
923 }
924 if( dynamic_disk_header != NULL )
925 {
926 libvhdi_dynamic_disk_header_free(
927 &dynamic_disk_header,
928 NULL );
929 }
930 return( 0 );
931 }
932
933 /* Tests the libvhdi_dynamic_disk_header_get_parent_identifier function
934 * Returns 1 if successful or 0 if not
935 */
936 int vhdi_test_dynamic_disk_header_get_parent_identifier(
937 libvhdi_dynamic_disk_header_t *dynamic_disk_header )
938 {
939 uint8_t guid_data[ 16 ];
940
941 libcerror_error_t *error = NULL;
942 int result = 0;
943
944 /* Test regular cases
945 */
946 result = libvhdi_dynamic_disk_header_get_parent_identifier(
947 dynamic_disk_header,
948 guid_data,
949 16,
950 &error );
951
952 VHDI_TEST_ASSERT_EQUAL_INT(
953 "result",
954 result,
955 1 );
956
957 VHDI_TEST_ASSERT_IS_NULL(
958 "error",
959 error );
960
961 /* Test error cases
962 */
963 result = libvhdi_dynamic_disk_header_get_parent_identifier(
964 NULL,
965 guid_data,
966 16,
967 &error );
968
969 VHDI_TEST_ASSERT_EQUAL_INT(
970 "result",
971 result,
972 -1 );
973
974 VHDI_TEST_ASSERT_IS_NOT_NULL(
975 "error",
976 error );
977
978 libcerror_error_free(
979 &error );
980
981 result = libvhdi_dynamic_disk_header_get_parent_identifier(
982 dynamic_disk_header,
983 NULL,
984 16,
985 &error );
986
987 VHDI_TEST_ASSERT_EQUAL_INT(
988 "result",
989 result,
990 -1 );
991
992 VHDI_TEST_ASSERT_IS_NOT_NULL(
993 "error",
994 error );
995
996 libcerror_error_free(
997 &error );
998
999 result = libvhdi_dynamic_disk_header_get_parent_identifier(
1000 dynamic_disk_header,
1001 guid_data,
1002 0,
1003 &error );
1004
1005 VHDI_TEST_ASSERT_EQUAL_INT(
1006 "result",
1007 result,
1008 -1 );
1009
1010 VHDI_TEST_ASSERT_IS_NOT_NULL(
1011 "error",
1012 error );
1013
1014 libcerror_error_free(
1015 &error );
1016
1017 result = libvhdi_dynamic_disk_header_get_parent_identifier(
1018 dynamic_disk_header,
1019 guid_data,
1020 (size_t) SSIZE_MAX + 1,
1021 &error );
1022
1023 VHDI_TEST_ASSERT_EQUAL_INT(
1024 "result",
1025 result,
1026 -1 );
1027
1028 VHDI_TEST_ASSERT_IS_NOT_NULL(
1029 "error",
1030 error );
1031
1032 libcerror_error_free(
1033 &error );
1034
1035 #if defined( HAVE_VHDI_TEST_MEMORY )
1036
1037 /* Test libvhdi_dynamic_disk_header_get_parent_identifier with memcpy failing
1038 */
1039 vhdi_test_memcpy_attempts_before_fail = 0;
1040
1041 result = libvhdi_dynamic_disk_header_get_parent_identifier(
1042 dynamic_disk_header,
1043 guid_data,
1044 16,
1045 &error );
1046
1047 if( vhdi_test_memcpy_attempts_before_fail != -1 )
1048 {
1049 vhdi_test_memcpy_attempts_before_fail = -1;
1050 }
1051 else
1052 {
1053 VHDI_TEST_ASSERT_EQUAL_INT(
1054 "result",
1055 result,
1056 -1 );
1057
1058 VHDI_TEST_ASSERT_IS_NOT_NULL(
1059 "error",
1060 error );
1061
1062 libcerror_error_free(
1063 &error );
1064 }
1065 #endif /* defined( HAVE_VHDI_TEST_MEMORY ) */
1066
1067 return( 1 );
1068
1069 on_error:
1070 if( error != NULL )
1071 {
1072 libcerror_error_free(
1073 &error );
1074 }
1075 return( 0 );
1076 }
1077
1078 /* Tests the libvhdi_dynamic_disk_header_get_utf8_parent_filename_size function
1079 * Returns 1 if successful or 0 if not
1080 */
1081 int vhdi_test_dynamic_disk_header_get_utf8_parent_filename_size(
1082 libvhdi_dynamic_disk_header_t *dynamic_disk_header )
1083 {
1084 libcerror_error_t *error = NULL;
1085 size_t utf8_parent_filename_size = 0;
1086 int result = 0;
1087 int utf8_parent_filename_size_is_set = 0;
1088
1089 /* Test regular cases
1090 */
1091 result = libvhdi_dynamic_disk_header_get_utf8_parent_filename_size(
1092 dynamic_disk_header,
1093 &utf8_parent_filename_size,
1094 &error );
1095
1096 VHDI_TEST_ASSERT_NOT_EQUAL_INT(
1097 "result",
1098 result,
1099 -1 );
1100
1101 VHDI_TEST_ASSERT_IS_NULL(
1102 "error",
1103 error );
1104
1105 utf8_parent_filename_size_is_set = result;
1106
1107 /* Test error cases
1108 */
1109 result = libvhdi_dynamic_disk_header_get_utf8_parent_filename_size(
1110 NULL,
1111 &utf8_parent_filename_size,
1112 &error );
1113
1114 VHDI_TEST_ASSERT_EQUAL_INT(
1115 "result",
1116 result,
1117 -1 );
1118
1119 VHDI_TEST_ASSERT_IS_NOT_NULL(
1120 "error",
1121 error );
1122
1123 libcerror_error_free(
1124 &error );
1125
1126 if( utf8_parent_filename_size_is_set != 0 )
1127 {
1128 result = libvhdi_dynamic_disk_header_get_utf8_parent_filename_size(
1129 dynamic_disk_header,
1130 NULL,
1131 &error );
1132
1133 VHDI_TEST_ASSERT_EQUAL_INT(
1134 "result",
1135 result,
1136 -1 );
1137
1138 VHDI_TEST_ASSERT_IS_NOT_NULL(
1139 "error",
1140 error );
1141
1142 libcerror_error_free(
1143 &error );
1144 }
1145 return( 1 );
1146
1147 on_error:
1148 if( error != NULL )
1149 {
1150 libcerror_error_free(
1151 &error );
1152 }
1153 return( 0 );
1154 }
1155
1156 /* Tests the libvhdi_dynamic_disk_header_get_utf8_parent_filename function
1157 * Returns 1 if successful or 0 if not
1158 */
1159 int vhdi_test_dynamic_disk_header_get_utf8_parent_filename(
1160 libvhdi_dynamic_disk_header_t *dynamic_disk_header )
1161 {
1162 uint8_t utf8_parent_filename[ 512 ];
1163
1164 libcerror_error_t *error = NULL;
1165 int result = 0;
1166 int utf8_parent_filename_is_set = 0;
1167
1168 /* Test regular cases
1169 */
1170 result = libvhdi_dynamic_disk_header_get_utf8_parent_filename(
1171 dynamic_disk_header,
1172 utf8_parent_filename,
1173 512,
1174 &error );
1175
1176 VHDI_TEST_ASSERT_NOT_EQUAL_INT(
1177 "result",
1178 result,
1179 -1 );
1180
1181 VHDI_TEST_ASSERT_IS_NULL(
1182 "error",
1183 error );
1184
1185 utf8_parent_filename_is_set = result;
1186
1187 /* Test error cases
1188 */
1189 result = libvhdi_dynamic_disk_header_get_utf8_parent_filename(
1190 NULL,
1191 utf8_parent_filename,
1192 512,
1193 &error );
1194
1195 VHDI_TEST_ASSERT_EQUAL_INT(
1196 "result",
1197 result,
1198 -1 );
1199
1200 VHDI_TEST_ASSERT_IS_NOT_NULL(
1201 "error",
1202 error );
1203
1204 libcerror_error_free(
1205 &error );
1206
1207 if( utf8_parent_filename_is_set != 0 )
1208 {
1209 result = libvhdi_dynamic_disk_header_get_utf8_parent_filename(
1210 dynamic_disk_header,
1211 NULL,
1212 512,
1213 &error );
1214
1215 VHDI_TEST_ASSERT_EQUAL_INT(
1216 "result",
1217 result,
1218 -1 );
1219
1220 VHDI_TEST_ASSERT_IS_NOT_NULL(
1221 "error",
1222 error );
1223
1224 libcerror_error_free(
1225 &error );
1226
1227 result = libvhdi_dynamic_disk_header_get_utf8_parent_filename(
1228 dynamic_disk_header,
1229 utf8_parent_filename,
1230 0,
1231 &error );
1232
1233 VHDI_TEST_ASSERT_EQUAL_INT(
1234 "result",
1235 result,
1236 -1 );
1237
1238 VHDI_TEST_ASSERT_IS_NOT_NULL(
1239 "error",
1240 error );
1241
1242 libcerror_error_free(
1243 &error );
1244
1245 result = libvhdi_dynamic_disk_header_get_utf8_parent_filename(
1246 dynamic_disk_header,
1247 utf8_parent_filename,
1248 (size_t) SSIZE_MAX + 1,
1249 &error );
1250
1251 VHDI_TEST_ASSERT_EQUAL_INT(
1252 "result",
1253 result,
1254 -1 );
1255
1256 VHDI_TEST_ASSERT_IS_NOT_NULL(
1257 "error",
1258 error );
1259
1260 libcerror_error_free(
1261 &error );
1262 }
1263 return( 1 );
1264
1265 on_error:
1266 if( error != NULL )
1267 {
1268 libcerror_error_free(
1269 &error );
1270 }
1271 return( 0 );
1272 }
1273
1274 /* Tests the libvhdi_dynamic_disk_header_get_utf16_parent_filename_size function
1275 * Returns 1 if successful or 0 if not
1276 */
1277 int vhdi_test_dynamic_disk_header_get_utf16_parent_filename_size(
1278 libvhdi_dynamic_disk_header_t *dynamic_disk_header )
1279 {
1280 libcerror_error_t *error = NULL;
1281 size_t utf16_parent_filename_size = 0;
1282 int result = 0;
1283 int utf16_parent_filename_size_is_set = 0;
1284
1285 /* Test regular cases
1286 */
1287 result = libvhdi_dynamic_disk_header_get_utf16_parent_filename_size(
1288 dynamic_disk_header,
1289 &utf16_parent_filename_size,
1290 &error );
1291
1292 VHDI_TEST_ASSERT_NOT_EQUAL_INT(
1293 "result",
1294 result,
1295 -1 );
1296
1297 VHDI_TEST_ASSERT_IS_NULL(
1298 "error",
1299 error );
1300
1301 utf16_parent_filename_size_is_set = result;
1302
1303 /* Test error cases
1304 */
1305 result = libvhdi_dynamic_disk_header_get_utf16_parent_filename_size(
1306 NULL,
1307 &utf16_parent_filename_size,
1308 &error );
1309
1310 VHDI_TEST_ASSERT_EQUAL_INT(
1311 "result",
1312 result,
1313 -1 );
1314
1315 VHDI_TEST_ASSERT_IS_NOT_NULL(
1316 "error",
1317 error );
1318
1319 libcerror_error_free(
1320 &error );
1321
1322 if( utf16_parent_filename_size_is_set != 0 )
1323 {
1324 result = libvhdi_dynamic_disk_header_get_utf16_parent_filename_size(
1325 dynamic_disk_header,
1326 NULL,
1327 &error );
1328
1329 VHDI_TEST_ASSERT_EQUAL_INT(
1330 "result",
1331 result,
1332 -1 );
1333
1334 VHDI_TEST_ASSERT_IS_NOT_NULL(
1335 "error",
1336 error );
1337
1338 libcerror_error_free(
1339 &error );
1340 }
1341 return( 1 );
1342
1343 on_error:
1344 if( error != NULL )
1345 {
1346 libcerror_error_free(
1347 &error );
1348 }
1349 return( 0 );
1350 }
1351
1352 /* Tests the libvhdi_dynamic_disk_header_get_utf16_parent_filename function
1353 * Returns 1 if successful or 0 if not
1354 */
1355 int vhdi_test_dynamic_disk_header_get_utf16_parent_filename(
1356 libvhdi_dynamic_disk_header_t *dynamic_disk_header )
1357 {
1358 uint16_t utf16_parent_filename[ 512 ];
1359
1360 libcerror_error_t *error = NULL;
1361 int result = 0;
1362 int utf16_parent_filename_is_set = 0;
1363
1364 /* Test regular cases
1365 */
1366 result = libvhdi_dynamic_disk_header_get_utf16_parent_filename(
1367 dynamic_disk_header,
1368 utf16_parent_filename,
1369 512,
1370 &error );
1371
1372 VHDI_TEST_ASSERT_NOT_EQUAL_INT(
1373 "result",
1374 result,
1375 -1 );
1376
1377 VHDI_TEST_ASSERT_IS_NULL(
1378 "error",
1379 error );
1380
1381 utf16_parent_filename_is_set = result;
1382
1383 /* Test error cases
1384 */
1385 result = libvhdi_dynamic_disk_header_get_utf16_parent_filename(
1386 NULL,
1387 utf16_parent_filename,
1388 512,
1389 &error );
1390
1391 VHDI_TEST_ASSERT_EQUAL_INT(
1392 "result",
1393 result,
1394 -1 );
1395
1396 VHDI_TEST_ASSERT_IS_NOT_NULL(
1397 "error",
1398 error );
1399
1400 libcerror_error_free(
1401 &error );
1402
1403 if( utf16_parent_filename_is_set != 0 )
1404 {
1405 result = libvhdi_dynamic_disk_header_get_utf16_parent_filename(
1406 dynamic_disk_header,
1407 NULL,
1408 512,
1409 &error );
1410
1411 VHDI_TEST_ASSERT_EQUAL_INT(
1412 "result",
1413 result,
1414 -1 );
1415
1416 VHDI_TEST_ASSERT_IS_NOT_NULL(
1417 "error",
1418 error );
1419
1420 libcerror_error_free(
1421 &error );
1422
1423 result = libvhdi_dynamic_disk_header_get_utf16_parent_filename(
1424 dynamic_disk_header,
1425 utf16_parent_filename,
1426 0,
1427 &error );
1428
1429 VHDI_TEST_ASSERT_EQUAL_INT(
1430 "result",
1431 result,
1432 -1 );
1433
1434 VHDI_TEST_ASSERT_IS_NOT_NULL(
1435 "error",
1436 error );
1437
1438 libcerror_error_free(
1439 &error );
1440
1441 result = libvhdi_dynamic_disk_header_get_utf16_parent_filename(
1442 dynamic_disk_header,
1443 utf16_parent_filename,
1444 (size_t) SSIZE_MAX + 1,
1445 &error );
1446
1447 VHDI_TEST_ASSERT_EQUAL_INT(
1448 "result",
1449 result,
1450 -1 );
1451
1452 VHDI_TEST_ASSERT_IS_NOT_NULL(
1453 "error",
1454 error );
1455
1456 libcerror_error_free(
1457 &error );
1458 }
1459 return( 1 );
1460
1461 on_error:
1462 if( error != NULL )
1463 {
1464 libcerror_error_free(
1465 &error );
1466 }
1467 return( 0 );
1468 }
1469
1470 #endif /* defined( __GNUC__ ) && !defined( LIBVHDI_DLL_IMPORT ) */
1471
1472 /* The main program
1473 */
1474 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1475 int wmain(
1476 int argc VHDI_TEST_ATTRIBUTE_UNUSED,
1477 wchar_t * const argv[] VHDI_TEST_ATTRIBUTE_UNUSED )
1478 #else
1479 int main(
1480 int argc VHDI_TEST_ATTRIBUTE_UNUSED,
1481 char * const argv[] VHDI_TEST_ATTRIBUTE_UNUSED )
1482 #endif
1483 {
1484 #if defined( __GNUC__ ) && !defined( LIBVHDI_DLL_IMPORT )
1485 #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )
1486
1487 libcerror_error_t *error = NULL;
1488 libvhdi_dynamic_disk_header_t *dynamic_disk_header = NULL;
1489 int result = 0;
1490
1491 #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */
1492 #endif /* defined( __GNUC__ ) && !defined( LIBVHDI_DLL_IMPORT ) */
1493
1494 VHDI_TEST_UNREFERENCED_PARAMETER( argc )
1495 VHDI_TEST_UNREFERENCED_PARAMETER( argv )
1496
1497 #if defined( __GNUC__ ) && !defined( LIBVHDI_DLL_IMPORT )
1498
1499 VHDI_TEST_RUN(
1500 "libvhdi_dynamic_disk_header_initialize",
1501 vhdi_test_dynamic_disk_header_initialize );
1502
1503 VHDI_TEST_RUN(
1504 "libvhdi_dynamic_disk_header_free",
1505 vhdi_test_dynamic_disk_header_free );
1506
1507 VHDI_TEST_RUN(
1508 "libvhdi_dynamic_disk_header_read_data",
1509 vhdi_test_dynamic_disk_header_read_data );
1510
1511 VHDI_TEST_RUN(
1512 "libvhdi_dynamic_disk_header_read_file_io_handle",
1513 vhdi_test_dynamic_disk_header_read_file_io_handle );
1514
1515 #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )
1516
1517 /* Initialize dynamic_disk_header for tests
1518 */
1519 result = libvhdi_dynamic_disk_header_initialize(
1520 &dynamic_disk_header,
1521 &error );
1522
1523 VHDI_TEST_ASSERT_EQUAL_INT(
1524 "result",
1525 result,
1526 1 );
1527
1528 VHDI_TEST_ASSERT_IS_NOT_NULL(
1529 "dynamic_disk_header",
1530 dynamic_disk_header );
1531
1532 VHDI_TEST_ASSERT_IS_NULL(
1533 "error",
1534 error );
1535
1536 result = libvhdi_dynamic_disk_header_read_data(
1537 dynamic_disk_header,
1538 vhdi_test_dynamic_disk_header_data1,
1539 1024,
1540 &error );
1541
1542 VHDI_TEST_ASSERT_EQUAL_INT(
1543 "result",
1544 result,
1545 1 );
1546
1547 VHDI_TEST_ASSERT_IS_NULL(
1548 "error",
1549 error );
1550
1551 /* Run tests
1552 */
1553 VHDI_TEST_RUN_WITH_ARGS(
1554 "libvhdi_dynamic_disk_header_get_parent_identifier",
1555 vhdi_test_dynamic_disk_header_get_parent_identifier,
1556 dynamic_disk_header );
1557
1558 VHDI_TEST_RUN_WITH_ARGS(
1559 "libvhdi_dynamic_disk_header_get_utf8_parent_filename_size",
1560 vhdi_test_dynamic_disk_header_get_utf8_parent_filename_size,
1561 dynamic_disk_header );
1562
1563 VHDI_TEST_RUN_WITH_ARGS(
1564 "libvhdi_dynamic_disk_header_get_utf8_parent_filename",
1565 vhdi_test_dynamic_disk_header_get_utf8_parent_filename,
1566 dynamic_disk_header );
1567
1568 VHDI_TEST_RUN_WITH_ARGS(
1569 "libvhdi_dynamic_disk_header_get_utf16_parent_filename_size",
1570 vhdi_test_dynamic_disk_header_get_utf16_parent_filename_size,
1571 dynamic_disk_header );
1572
1573 VHDI_TEST_RUN_WITH_ARGS(
1574 "libvhdi_dynamic_disk_header_get_utf16_parent_filename",
1575 vhdi_test_dynamic_disk_header_get_utf16_parent_filename,
1576 dynamic_disk_header );
1577
1578 /* Clean up
1579 */
1580 result = libvhdi_dynamic_disk_header_free(
1581 &dynamic_disk_header,
1582 &error );
1583
1584 VHDI_TEST_ASSERT_EQUAL_INT(
1585 "result",
1586 result,
1587 1 );
1588
1589 VHDI_TEST_ASSERT_IS_NULL(
1590 "dynamic_disk_header",
1591 dynamic_disk_header );
1592
1593 VHDI_TEST_ASSERT_IS_NULL(
1594 "error",
1595 error );
1596
1597 #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */
1598 #endif /* defined( __GNUC__ ) && !defined( LIBVHDI_DLL_IMPORT ) */
1599
1600 return( EXIT_SUCCESS );
1601
1602 #if defined( __GNUC__ ) && !defined( LIBVHDI_DLL_IMPORT )
1603
1604 on_error:
1605 #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )
1606 if( error != NULL )
1607 {
1608 libcerror_error_free(
1609 &error );
1610 }
1611 if( dynamic_disk_header != NULL )
1612 {
1613 libvhdi_dynamic_disk_header_free(
1614 &dynamic_disk_header,
1615 NULL );
1616 }
1617 #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */
1618
1619 return( EXIT_FAILURE );
1620
1621 #endif /* defined( __GNUC__ ) && !defined( LIBVHDI_DLL_IMPORT ) */
1622 }
1623