• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  *
21  * Copyright (c) Sandflow Consulting LLC
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions are met:
25  *
26  * * Redistributions of source code must retain the above copyright notice, this
27  *   list of conditions and the following disclaimer.
28  * * Redistributions in binary form must reproduce the above copyright notice,
29  *   this list of conditions and the following disclaimer in the documentation
30  *   and/or other materials provided with the distribution.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
36  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGE.
43  */
44 
45 /**
46  * Tests for IMF CPL and ASSETMAP processing
47  *
48  * @author Valentin Noel
49  * @author Pierre-Anthony Lemieux
50  * @file
51  * @ingroup lavu_imf
52  */
53 
54 #include "libavformat/imf_cpl.c"
55 #include "libavformat/imfdec.c"
56 #include "libavformat/mxf.h"
57 
58 #include <stdio.h>
59 
60 const char *cpl_doc =
61     "<CompositionPlaylist xmlns=\"http://www.smpte-ra.org/schemas/2067-3/2016\""
62     " xmlns:cc=\"http://www.smpte-ra.org/schemas/2067-2/2016\""
63     " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
64     "<Id>urn:uuid:8713c020-2489-45f5-a9f7-87be539e20b5</Id>"
65     "<IssueDate>2021-07-13T17:06:22Z</IssueDate>"
66     "<Creator language=\"en\">FFMPEG</Creator>"
67     "<ContentTitle>FFMPEG sample content</ContentTitle>"
68     "<EssenceDescriptorList>"
69     "  <EssenceDescriptor>"
70     "    <Id>urn:uuid:8e097bb0-cff7-4969-a692-bad47bfb528f</Id>"
71     "  </EssenceDescriptor>"
72     "</EssenceDescriptorList>"
73     "<EditRate>24000 1001</EditRate>"
74     "<SegmentList>"
75     "<Segment>"
76     "<Id>urn:uuid:81fed4e5-9722-400a-b9d1-7f2bd21df4b6</Id>"
77     "<SequenceList>"
78     "<MarkerSequence>"
79     "<Id>urn:uuid:16327185-9205-47ef-a17b-ee28df251db7</Id>"
80     "<TrackId>urn:uuid:461f5424-8f6e-48a9-a385-5eda46fda381</TrackId>"
81     "<ResourceList>"
82     "<Resource xsi:type=\"MarkerResourceType\">"
83     "<Id>urn:uuid:ea3d0f23-55d6-4e03-86ec-cfe0666f0e6a</Id>"
84     "<IntrinsicDuration>24</IntrinsicDuration>"
85     "<Marker>"
86     "<Label>LFOA</Label>"
87     "<Offset>5</Offset>"
88     "</Marker>"
89     "</Resource>"
90     "</ResourceList>"
91     "</MarkerSequence>"
92     "<cc:MainImageSequence>"
93     "<Id>urn:uuid:6ae100b0-92d1-41be-9321-85e0933dfc42</Id>"
94     "<TrackId>urn:uuid:e8ef9653-565c-479c-8039-82d4547973c5</TrackId>"
95     "<ResourceList>"
96     "<Resource xsi:type=\"TrackFileResourceType\">"
97     "<Id>urn:uuid:7d418acb-07a3-4e57-984c-b8ea2f7de4ec</Id>"
98     "<IntrinsicDuration>24</IntrinsicDuration>"
99     "<SourceEncoding>urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751</SourceEncoding>"
100     "<TrackFileId>urn:uuid:6f768ca4-c89e-4dac-9056-a29425d40ba1</TrackFileId>"
101     "</Resource>"
102     "</ResourceList>"
103     "</cc:MainImageSequence>"
104     "<cc:MainAudioSequence>"
105     "<Id>urn:uuid:754dae53-c25f-4f3c-97e4-2bfe5463f83b</Id>"
106     "<TrackId>urn:uuid:68e3fae5-d94b-44d2-92a6-b94877fbcdb5</TrackId>"
107     "<ResourceList>"
108     "<Resource xsi:type=\"TrackFileResourceType\">"
109     "<Id>urn:uuid:61ce2a70-10a2-4521-850b-4218755ff3c9</Id>"
110     "<IntrinsicDuration>24</IntrinsicDuration>"
111     "<SourceEncoding>urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751</SourceEncoding>"
112     "<TrackFileId>urn:uuid:381dadd2-061e-46cc-a63a-e3d58ce7f488</TrackFileId>"
113     "</Resource>"
114     "</ResourceList>"
115     "</cc:MainAudioSequence>"
116     "<cc:MainAudioSequence>"
117     "<Id>urn:uuid:d29b3884-6633-4dad-9c67-7154af342bc6</Id>"
118     "<TrackId>urn:uuid:6978c106-95bc-424b-a17c-628206a5892d</TrackId>"
119     "<ResourceList>"
120     "<Resource xsi:type=\"TrackFileResourceType\">"
121     "<Id>urn:uuid:001ea472-f5da-436c-86de-acaa68c1a7e4</Id>"
122     "<IntrinsicDuration>24</IntrinsicDuration>"
123     "<SourceEncoding>urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751</SourceEncoding>"
124     "<TrackFileId>urn:uuid:381dadd2-061e-46cc-a63a-e3d58ce7f488</TrackFileId>"
125     "</Resource>"
126     "</ResourceList>"
127     "</cc:MainAudioSequence>"
128     "<cc:SubtitlesSequence>"
129     "<Id>urn:uuid:02af22bf-f776-488a-b001-eb6e16953119</Id>"
130     "<TrackId>urn:uuid:19ff6da1-be79-4235-8d04-42201ad06e65</TrackId>"
131     "<ResourceList>"
132     "<Resource xsi:type=\"TrackFileResourceType\">"
133     "<Id>urn:uuid:dfa84292-0609-4097-824c-8e2e15e2ce4d</Id>"
134     "<IntrinsicDuration>24</IntrinsicDuration>"
135     "<SourceEncoding>urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751</SourceEncoding>"
136     "<TrackFileId>urn:uuid:bd6272b6-511e-47c1-93bc-d56ebd314a70</TrackFileId>"
137     "</Resource>"
138     "</ResourceList>"
139     "</cc:SubtitlesSequence>"
140     "</SequenceList>"
141     "</Segment>"
142     "<Segment>"
143     "<Id>urn:uuid:a94be493-cd55-4bf7-b496-ea87bfe38632</Id>"
144     "<SequenceList>"
145     "<MarkerSequence>"
146     "<Id>urn:uuid:20c6020b-1fc0-4080-bcf7-89f09f95bea8</Id>"
147     "<TrackId>urn:uuid:461f5424-8f6e-48a9-a385-5eda46fda381</TrackId>"
148     "<ResourceList>"
149     "<Resource xsi:type=\"MarkerResourceType\">"
150     "<Id>urn:uuid:d1f93845-d3e5-4c3b-aa67-8d96c45cfe9c</Id>"
151     "<IntrinsicDuration>36</IntrinsicDuration>"
152     "<Marker>"
153     "<Label>FFOA</Label>"
154     "<Offset>20</Offset>"
155     "</Marker>"
156     "<Marker>"
157     "<Label>LFOC</Label>"
158     "<Offset>24</Offset>"
159     "</Marker>"
160     "</Resource>"
161     "</ResourceList>"
162     "</MarkerSequence>"
163     "<cc:MainImageSequence>"
164     "<Id>urn:uuid:9b509f42-e4e8-4f78-8c2a-12ddd79ef3c5</Id>"
165     "<TrackId>urn:uuid:e8ef9653-565c-479c-8039-82d4547973c5</TrackId>"
166     "<ResourceList>"
167     "<Resource xsi:type=\"TrackFileResourceType\">"
168     "<Id>urn:uuid:a733d812-a3d7-45e9-ba50-13b856d5d35a</Id>"
169     "<IntrinsicDuration>36</IntrinsicDuration>"
170     "<SourceEncoding>urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751</SourceEncoding>"
171     "<TrackFileId>urn:uuid:f3b263b3-096b-4360-a952-b1a9623cd0ca</TrackFileId>"
172     "</Resource>"
173     "</ResourceList>"
174     "</cc:MainImageSequence>"
175     "<cc:MainAudioSequence>"
176     "<Id>urn:uuid:19a282e6-beac-4d99-a008-afa61378eb6c</Id>"
177     "<TrackId>urn:uuid:68e3fae5-d94b-44d2-92a6-b94877fbcdb5</TrackId>"
178     "<ResourceList>"
179     "<Resource xsi:type=\"TrackFileResourceType\">"
180     "<Id>urn:uuid:53de5ff9-f5f7-47c5-a2d8-117c36cce517</Id>"
181     "<IntrinsicDuration>36</IntrinsicDuration>"
182     "<SourceEncoding>urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751</SourceEncoding>"
183     "<TrackFileId>urn:uuid:2484d613-bb7d-4bcc-8b0f-2e65938f0535</TrackFileId>"
184     "</Resource>"
185     "</ResourceList>"
186     "</cc:MainAudioSequence>"
187     "<cc:MainAudioSequence>"
188     "<Id>urn:uuid:94b0ef77-0621-4086-95a2-85432fa97d40</Id>"
189     "<TrackId>urn:uuid:6978c106-95bc-424b-a17c-628206a5892d</TrackId>"
190     "<ResourceList>"
191     "<Resource xsi:type=\"TrackFileResourceType\">"
192     "<Id>urn:uuid:2ce499f2-59bc-4053-87bc-80f4b7e7b73e</Id>"
193     "<IntrinsicDuration>36</IntrinsicDuration>"
194     "<SourceEncoding>urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751</SourceEncoding>"
195     "<TrackFileId>urn:uuid:2484d613-bb7d-4bcc-8b0f-2e65938f0535</TrackFileId>"
196     "</Resource>"
197     "</ResourceList>"
198     "</cc:MainAudioSequence>"
199     "<cc:SubtitlesSequence>"
200     "<Id>urn:uuid:9ac3b905-c599-4da8-8f0f-fc07e619899d</Id>"
201     "<TrackId>urn:uuid:19ff6da1-be79-4235-8d04-42201ad06e65</TrackId>"
202     "<ResourceList>"
203     "<Resource xsi:type=\"TrackFileResourceType\">"
204     "<Id>urn:uuid:0239017b-2ad9-4235-b46d-c4c1126e29fc</Id>"
205     "<IntrinsicDuration>36</IntrinsicDuration>"
206     "<SourceEncoding>urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751</SourceEncoding>"
207     "<TrackFileId>urn:uuid:bd6272b6-511e-47c1-93bc-d56ebd314a70</TrackFileId>"
208     "</Resource>"
209     "</ResourceList>"
210     "</cc:SubtitlesSequence>"
211     "</SequenceList>"
212     "</Segment>"
213     "</SegmentList>"
214     "</CompositionPlaylist>";
215 
216 const char *cpl_bad_doc = "<Composition></Composition>";
217 
218 const char *asset_map_doc =
219     "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
220     "<am:AssetMap xmlns:am=\"http://www.smpte-ra.org/schemas/429-9/2007/AM\">"
221     "<am:Id>urn:uuid:68d9f591-8191-46b5-38b4-affb87a14132</am:Id>"
222     "<am:AnnotationText>IMF_TEST_ASSET_MAP</am:AnnotationText>"
223     "<am:Creator>Some tool</am:Creator>"
224     "<am:VolumeCount>1</am:VolumeCount>"
225     "<am:IssueDate>2021-06-07T12:00:00+00:00</am:IssueDate>"
226     "<am:Issuer>FFmpeg</am:Issuer>"
227     "<am:AssetList>"
228     "<am:Asset>"
229     "<am:Id>urn:uuid:b5d674b8-c6ce-4bce-3bdf-be045dfdb2d0</am:Id>"
230     "<am:ChunkList>"
231     "<am:Chunk>"
232     "<am:Path>IMF_TEST_ASSET_MAP_video.mxf</am:Path>"
233     "<am:VolumeIndex>1</am:VolumeIndex>"
234     "<am:Offset>0</am:Offset>"
235     "<am:Length>1234567</am:Length>"
236     "</am:Chunk>"
237     "</am:ChunkList>"
238     "</am:Asset>"
239     "<am:Asset>"
240     "<am:Id>urn:uuid:ec3467ec-ab2a-4f49-c8cb-89caa3761f4a</am:Id>"
241     "<am:ChunkList>"
242     "<am:Chunk>"
243     "<am:Path>IMF_TEST_ASSET_MAP_video_1.mxf</am:Path>"
244     "<am:VolumeIndex>1</am:VolumeIndex>"
245     "<am:Offset>0</am:Offset>"
246     "<am:Length>234567</am:Length>"
247     "</am:Chunk>"
248     "</am:ChunkList>"
249     "</am:Asset>"
250     "<am:Asset>"
251     "<am:Id>urn:uuid:5cf5b5a7-8bb3-4f08-eaa6-3533d4b77fa6</am:Id>"
252     "<am:ChunkList>"
253     "<am:Chunk>"
254     "<am:Path>IMF_TEST_ASSET_MAP_audio.mxf</am:Path>"
255     "<am:VolumeIndex>1</am:VolumeIndex>"
256     "<am:Offset>0</am:Offset>"
257     "<am:Length>34567</am:Length>"
258     "</am:Chunk>"
259     "</am:ChunkList>"
260     "</am:Asset>"
261     "<am:Asset>"
262     "<am:Id>urn:uuid:559777d6-ec29-4375-f90d-300b0bf73686</am:Id>"
263     "<am:ChunkList>"
264     "<am:Chunk>"
265     "<am:Path>CPL_IMF_TEST_ASSET_MAP.xml</am:Path>"
266     "<am:VolumeIndex>1</am:VolumeIndex>"
267     "<am:Offset>0</am:Offset>"
268     "<am:Length>12345</am:Length>"
269     "</am:Chunk>"
270     "</am:ChunkList>"
271     "</am:Asset>"
272     "<am:Asset>"
273     "<am:Id>urn:uuid:dd04528d-9b80-452a-7a13-805b08278b3d</am:Id>"
274     "<am:PackingList>true</am:PackingList>"
275     "<am:ChunkList>"
276     "<am:Chunk>"
277     "<am:Path>PKL_IMF_TEST_ASSET_MAP.xml</am:Path>"
278     "<am:VolumeIndex>1</am:VolumeIndex>"
279     "<am:Offset>0</am:Offset>"
280     "<am:Length>2345</am:Length>"
281     "</am:Chunk>"
282     "</am:ChunkList>"
283     "</am:Asset>"
284     "</am:AssetList>"
285     "</am:AssetMap>";
286 
test_cpl_parsing(void)287 static int test_cpl_parsing(void)
288 {
289     xmlDocPtr doc;
290     FFIMFCPL *cpl;
291     int ret;
292 
293     doc = xmlReadMemory(cpl_doc, strlen(cpl_doc), NULL, NULL, 0);
294     if (doc == NULL) {
295         printf("XML parsing failed.\n");
296         return 1;
297     }
298 
299     ret = ff_imf_parse_cpl_from_xml_dom(doc, &cpl);
300     xmlFreeDoc(doc);
301     if (ret) {
302         printf("CPL parsing failed.\n");
303         return 1;
304     }
305 
306     printf("%s\n", cpl->content_title_utf8);
307     printf(AV_PRI_URN_UUID "\n", AV_UUID_ARG(cpl->id_uuid));
308     printf("%i %i\n", cpl->edit_rate.num, cpl->edit_rate.den);
309 
310     printf("Marker resource count: %" PRIu32 "\n", cpl->main_markers_track->resource_count);
311     for (uint32_t i = 0; i < cpl->main_markers_track->resource_count; i++) {
312         printf("Marker resource %" PRIu32 "\n", i);
313         for (uint32_t j = 0; j < cpl->main_markers_track->resources[i].marker_count; j++) {
314             printf("  Marker %" PRIu32 "\n", j);
315             printf("    Label %s\n", cpl->main_markers_track->resources[i].markers[j].label_utf8);
316             printf("    Offset %" PRIu32 "\n", cpl->main_markers_track->resources[i].markers[j].offset);
317         }
318     }
319 
320     printf("Main image resource count: %" PRIu32 "\n", cpl->main_image_2d_track->resource_count);
321     for (uint32_t i = 0; i < cpl->main_image_2d_track->resource_count; i++) {
322         printf("Track file resource %" PRIu32 "\n", i);
323         printf("  " AV_PRI_URN_UUID "\n", AV_UUID_ARG(cpl->main_image_2d_track->resources[i].track_file_uuid));
324     }
325 
326     printf("Main audio track count: %" PRIu32 "\n", cpl->main_audio_track_count);
327     for (uint32_t i = 0; i < cpl->main_audio_track_count; i++) {
328         printf("  Main audio virtual track %" PRIu32 "\n", i);
329         printf("  Main audio resource count: %" PRIu32 "\n", cpl->main_audio_tracks[i].resource_count);
330         for (uint32_t j = 0; j < cpl->main_audio_tracks[i].resource_count; j++) {
331             printf("  Track file resource %" PRIu32 "\n", j);
332             printf("    " AV_PRI_URN_UUID "\n", AV_UUID_ARG(cpl->main_audio_tracks[i].resources[j].track_file_uuid));
333         }
334     }
335 
336     ff_imf_cpl_free(cpl);
337 
338     return 0;
339 }
340 
test_bad_cpl_parsing(void)341 static int test_bad_cpl_parsing(void)
342 {
343     xmlDocPtr doc;
344     FFIMFCPL *cpl;
345     int ret;
346 
347     doc = xmlReadMemory(cpl_bad_doc, strlen(cpl_bad_doc), NULL, NULL, 0);
348     if (doc == NULL) {
349         printf("XML parsing failed.\n");
350         return 1;
351     }
352 
353     ret = ff_imf_parse_cpl_from_xml_dom(doc, &cpl);
354     xmlFreeDoc(doc);
355     if (ret) {
356         printf("CPL parsing failed.\n");
357         return ret;
358     }
359 
360     return 0;
361 }
362 
check_asset_locator_attributes(IMFAssetLocator * asset,IMFAssetLocator * expected_asset)363 static int check_asset_locator_attributes(IMFAssetLocator *asset, IMFAssetLocator *expected_asset)
364 {
365 
366     printf("\tCompare " AV_PRI_URN_UUID " to " AV_PRI_URN_UUID ".\n",
367            AV_UUID_ARG(asset->uuid),
368            AV_UUID_ARG(expected_asset->uuid));
369 
370     for (uint32_t i = 0; i < 16; ++i) {
371         if (asset->uuid[i] != expected_asset->uuid[i]) {
372             printf("Invalid asset locator UUID: found " AV_PRI_URN_UUID " instead of " AV_PRI_URN_UUID " expected.\n",
373                    AV_UUID_ARG(asset->uuid),
374                    AV_UUID_ARG(expected_asset->uuid));
375             return 1;
376         }
377     }
378 
379     printf("\tCompare %s to %s.\n", asset->absolute_uri, expected_asset->absolute_uri);
380     if (strcmp(asset->absolute_uri, expected_asset->absolute_uri) != 0) {
381         printf("Invalid asset locator URI: found %s instead of %s expected.\n",
382                asset->absolute_uri,
383                expected_asset->absolute_uri);
384         return 1;
385     }
386 
387     return 0;
388 }
389 
390 static IMFAssetLocator ASSET_MAP_EXPECTED_LOCATORS[5] = {
391     {.uuid = {0xb5, 0xd6, 0x74, 0xb8, 0xc6, 0xce, 0x4b, 0xce, 0x3b, 0xdf, 0xbe, 0x04, 0x5d, 0xfd, 0xb2, 0xd0},
392      .absolute_uri = (char *)"IMF_TEST_ASSET_MAP_video.mxf"},
393     {.uuid = {0xec, 0x34, 0x67, 0xec, 0xab, 0x2a, 0x4f, 0x49, 0xc8, 0xcb, 0x89, 0xca, 0xa3, 0x76, 0x1f, 0x4a},
394      .absolute_uri = (char *)"IMF_TEST_ASSET_MAP_video_1.mxf"},
395     {.uuid = {0x5c, 0xf5, 0xb5, 0xa7, 0x8b, 0xb3, 0x4f, 0x08, 0xea, 0xa6, 0x35, 0x33, 0xd4, 0xb7, 0x7f, 0xa6},
396      .absolute_uri = (char *)"IMF_TEST_ASSET_MAP_audio.mxf"},
397     {.uuid = {0x55, 0x97, 0x77, 0xd6, 0xec, 0x29, 0x43, 0x75, 0xf9, 0x0d, 0x30, 0x0b, 0x0b, 0xf7, 0x36, 0x86},
398      .absolute_uri = (char *)"CPL_IMF_TEST_ASSET_MAP.xml"},
399     {.uuid = {0xdd, 0x04, 0x52, 0x8d, 0x9b, 0x80, 0x45, 0x2a, 0x7a, 0x13, 0x80, 0x5b, 0x08, 0x27, 0x8b, 0x3d},
400      .absolute_uri = (char *)"PKL_IMF_TEST_ASSET_MAP.xml"},
401 };
402 
test_asset_map_parsing(void)403 static int test_asset_map_parsing(void)
404 {
405     IMFAssetLocatorMap asset_locator_map;
406     xmlDoc *doc;
407     int ret;
408 
409     doc = xmlReadMemory(asset_map_doc, strlen(asset_map_doc), NULL, NULL, 0);
410     if (doc == NULL) {
411         printf("Asset map XML parsing failed.\n");
412         return 1;
413     }
414 
415     printf("Allocate asset map\n");
416     imf_asset_locator_map_init(&asset_locator_map);
417 
418     printf("Parse asset map XML document\n");
419     ret = parse_imf_asset_map_from_xml_dom(NULL, doc, &asset_locator_map, doc->name);
420     if (ret) {
421         printf("Asset map parsing failed.\n");
422         goto cleanup;
423     }
424 
425     printf("Compare assets count: %d to 5\n", asset_locator_map.asset_count);
426     if (asset_locator_map.asset_count != 5) {
427         printf("Asset map parsing failed: found %d assets instead of 5 expected.\n",
428                asset_locator_map.asset_count);
429         ret = 1;
430         goto cleanup;
431     }
432 
433     for (uint32_t i = 0; i < asset_locator_map.asset_count; ++i) {
434         printf("For asset: %d:\n", i);
435         ret = check_asset_locator_attributes(&(asset_locator_map.assets[i]),
436                                              &(ASSET_MAP_EXPECTED_LOCATORS[i]));
437         if (ret > 0)
438             goto cleanup;
439     }
440 
441 cleanup:
442     imf_asset_locator_map_deinit(&asset_locator_map);
443     xmlFreeDoc(doc);
444     return ret;
445 }
446 
447 typedef struct PathTypeTestStruct {
448     const char *path;
449     int is_url;
450     int is_unix_absolute_path;
451     int is_dos_absolute_path;
452 } PathTypeTestStruct;
453 
454 static const PathTypeTestStruct PATH_TYPE_TEST_STRUCTS[11] = {
455     {.path = "file://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0},
456     {.path = "http://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0},
457     {.path = "https://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0},
458     {.path = "s3://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0},
459     {.path = "ftp://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0},
460     {.path = "/path/to/somewhere", .is_url = 0, .is_unix_absolute_path = 1, .is_dos_absolute_path = 0},
461     {.path = "path/to/somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0},
462     {.path = "C:\\path\\to\\somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 1},
463     {.path = "C:/path/to/somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 1},
464     {.path = "\\\\path\\to\\somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 1},
465     {.path = "path\\to\\somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0},
466 };
467 
test_path_type_functions(void)468 static int test_path_type_functions(void)
469 {
470     PathTypeTestStruct path_type;
471     for (uint32_t i = 0; i < 11; ++i) {
472         path_type = PATH_TYPE_TEST_STRUCTS[i];
473         if (imf_uri_is_url(path_type.path) != path_type.is_url) {
474             fprintf(stderr,
475                     "URL comparison test failed for '%s', got %d instead of expected %d\n",
476                     path_type.path,
477                     path_type.is_url,
478                     !path_type.is_url);
479             goto fail;
480         }
481 
482         if (imf_uri_is_unix_abs_path(path_type.path) != path_type.is_unix_absolute_path) {
483             fprintf(stderr,
484                     "Unix absolute path comparison test failed for '%s', got %d instead of expected %d\n",
485                     path_type.path,
486                     path_type.is_unix_absolute_path,
487                     !path_type.is_unix_absolute_path);
488             goto fail;
489         }
490 
491         if (imf_uri_is_dos_abs_path(path_type.path) != path_type.is_dos_absolute_path) {
492             fprintf(stderr,
493                     "DOS absolute path comparison test failed for '%s', got %d instead of expected %d\n",
494                     path_type.path,
495                     path_type.is_dos_absolute_path,
496                     !path_type.is_dos_absolute_path);
497             goto fail;
498         }
499     }
500 
501     return 0;
502 
503 fail:
504     return 1;
505 }
506 
main(int argc,char * argv[])507 int main(int argc, char *argv[])
508 {
509     int ret = 0;
510 
511     if (test_cpl_parsing() != 0)
512         ret = 1;
513 
514     if (test_asset_map_parsing() != 0)
515         ret = 1;
516 
517     if (test_path_type_functions() != 0)
518         ret = 1;
519 
520     printf("#### The following should fail ####\n");
521     if (test_bad_cpl_parsing() == 0)
522         ret = 1;
523     printf("#### End failing test ####\n");
524 
525     return ret;
526 }
527