FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/ambient_viewing_environment.c
Date: 2026-07-16 17:05:34
Exec Total Coverage
Lines: 53 56 94.6%
Functions: 2 2 100.0%
Branches: 10 20 50.0%

Line Branch Exec Source
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 #include <limits.h>
20 #include <stdio.h>
21
22 #include "libavutil/ambient_viewing_environment.h"
23 #include "libavutil/frame.h"
24 #include "libavutil/mem.h"
25
26 4 static void print_env(const AVAmbientViewingEnvironment *env)
27 {
28 4 printf("illuminance=%d/%d, light_x=%d/%d, light_y=%d/%d\n",
29 4 env->ambient_illuminance.num, env->ambient_illuminance.den,
30 4 env->ambient_light_x.num, env->ambient_light_x.den,
31 4 env->ambient_light_y.num, env->ambient_light_y.den);
32 4 }
33
34 1 int main(void)
35 {
36 AVAmbientViewingEnvironment *env;
37 AVFrame *frame;
38 1 size_t size = 0;
39
40 /* av_ambient_viewing_environment_alloc with size out-param */
41 1 printf("Testing av_ambient_viewing_environment_alloc(&size)\n");
42 1 env = av_ambient_viewing_environment_alloc(&size);
43
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (env) {
44
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("alloc: OK, size_set=%s\n", size == sizeof(*env) ? "yes" : "no");
45 1 print_env(env);
46 1 av_free(env);
47 } else {
48 printf("alloc: FAIL\n");
49 }
50
51 /* av_ambient_viewing_environment_alloc with NULL size */
52 1 printf("\nTesting av_ambient_viewing_environment_alloc(NULL)\n");
53 1 env = av_ambient_viewing_environment_alloc(NULL);
54
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (env) {
55 1 printf("alloc(NULL): OK\n");
56 1 print_env(env);
57 1 av_free(env);
58 } else {
59 printf("alloc(NULL): FAIL\n");
60 }
61
62 /* write and read back */
63 1 printf("\nTesting write/read back\n");
64 1 env = av_ambient_viewing_environment_alloc(NULL);
65
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (env) {
66 1 env->ambient_illuminance = (AVRational){ 314, 10 };
67 1 env->ambient_light_x = (AVRational){ 15635, 50000 };
68 1 env->ambient_light_y = (AVRational){ 16450, 50000 };
69 1 print_env(env);
70 1 av_free(env);
71 }
72
73 /* av_ambient_viewing_environment_create_side_data */
74 1 printf("\nTesting av_ambient_viewing_environment_create_side_data()\n");
75 1 frame = av_frame_alloc();
76
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
77 1 env = av_ambient_viewing_environment_create_side_data(frame);
78
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (env) {
79 1 printf("side_data: OK\n");
80 1 print_env(env);
81 } else {
82 printf("side_data: FAIL\n");
83 }
84 1 av_frame_free(&frame);
85 }
86
87 /* OOM paths via av_max_alloc */
88 1 printf("\nTesting OOM paths\n");
89 1 av_max_alloc(1);
90 1 env = av_ambient_viewing_environment_alloc(&size);
91
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("alloc OOM: %s\n", env ? "FAIL" : "OK");
92 1 av_free(env);
93 1 env = av_ambient_viewing_environment_alloc(NULL);
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("alloc(NULL) OOM: %s\n", env ? "FAIL" : "OK");
95 1 av_free(env);
96 1 av_max_alloc(INT_MAX);
97
98 1 frame = av_frame_alloc();
99
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
100 1 av_max_alloc(1);
101 1 env = av_ambient_viewing_environment_create_side_data(frame);
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("side_data OOM: %s\n", env ? "FAIL" : "OK");
103 1 av_max_alloc(INT_MAX);
104 1 av_frame_free(&frame);
105 }
106
107 1 return 0;
108 }
109