FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/side_data_array.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 2 2 100.0%
Branches: 15 22 68.2%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2023 Jan Ekström <jeebjp@gmail.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdio.h>
22 #include "libavutil/frame.c"
23 #include "libavutil/internal.h"
24
25 2 static void print_entries(const AVFrameSideData **sd, const int nb_sd)
26 {
27
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2 times.
13 for (int i = 0; i < nb_sd; i++) {
28 11 const AVFrameSideData *entry = sd[i];
29
30 22 printf("sd %d (size %"SIZE_SPECIFIER"), %s",
31 11 i, entry->size, av_frame_side_data_name(entry->type));
32
33
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
11 if (entry->type != AV_FRAME_DATA_SEI_UNREGISTERED) {
34 4 putchar('\n');
35 4 continue;
36 }
37
38 7 printf(": %d\n", *(int32_t *)entry->data);
39 }
40 2 }
41
42 typedef struct FrameSideDataSet {
43 AVFrameSideData **sd;
44 int nb_sd;
45 } FrameSideDataSet;
46
47 1 int main(void)
48 {
49 1 FrameSideDataSet set = { 0 };
50
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 av_assert0(
52 av_frame_side_data_new(&set.sd, &set.nb_sd,
53 AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
54 sizeof(int64_t), 0));
55
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 av_assert0(
56 av_frame_side_data_new(&set.sd, &set.nb_sd,
57 AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
58 sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_REPLACE));
59
60 // test entries in the middle
61
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int value = 1; value < 4; value++) {
62 3 AVFrameSideData *sd = av_frame_side_data_new(
63 &set.sd, &set.nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED,
64 sizeof(int32_t), 0);
65
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 av_assert0(sd);
67
68 3 *(int32_t *)sd->data = value;
69 }
70
71
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 av_assert0(
72 av_frame_side_data_new(
73 &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL,
74 sizeof(int64_t), 0));
75
76
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 av_assert0(
77 av_frame_side_data_new(
78 &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL,
79 sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_REPLACE));
80
81 // test entries at the end
82
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int value = 1; value < 4; value++) {
83 3 AVFrameSideData *sd = av_frame_side_data_new(
84 &set.sd, &set.nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED,
85 sizeof(int32_t), 0);
86
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 av_assert0(sd);
88
89 3 *(int32_t *)sd->data = value + 3;
90 }
91
92 1 puts("Initial addition results with duplicates:");
93 1 print_entries((const AVFrameSideData **)set.sd, set.nb_sd);
94
95 {
96 1 AVFrameSideData *sd = av_frame_side_data_new(
97 &set.sd, &set.nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED,
98 sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_UNIQUE);
99
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 av_assert0(sd);
101
102 1 *(int32_t *)sd->data = 1337;
103 }
104
105 1 puts("\nFinal state after a single 'no-duplicates' addition:");
106 1 print_entries((const AVFrameSideData **)set.sd, set.nb_sd);
107
108 1 av_frame_side_data_free(&set.sd, &set.nb_sd);
109
110 1 return 0;
111 }
112