FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/file.c
Date: 2026-04-22 13:46:37
Exec Total Coverage
Lines: 14 20 70.0%
Functions: 2 2 100.0%
Branches: 7 12 58.3%

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 <stdarg.h>
20 #include <stdio.h>
21
22 #include "libavutil/file.c"
23 #include "libavutil/log.h"
24
25 static int last_log_level = -1;
26
27 2 static void log_callback(void *ctx, int level, const char *fmt, va_list args)
28 {
29 (void)ctx; (void)fmt; (void)args;
30 2 last_log_level = level;
31 2 }
32
33 1 int main(int argc, char **argv)
34 {
35
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 const char *path = argc > 1 ? argv[1] : "file.c";
36 uint8_t *buf;
37 size_t size;
38
39 1 av_log_set_callback(log_callback);
40
41 /* map an existing file and verify it is non-empty and readable */
42
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (av_file_map(path, &buf, &size, 0, NULL) < 0)
43 return 1;
44 1 av_file_unmap(buf, size);
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (size == 0)
46 return 1;
47
48 /* for offset i, error must be logged at AV_LOG_ERROR + i */
49
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < 2; i++) {
50 2 last_log_level = -1;
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (av_file_map("no_such_file_xyz", &buf, &size, i, NULL) >= 0) {
52 av_file_unmap(buf, size);
53 return 2;
54 }
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (last_log_level != AV_LOG_ERROR + i) {
56 fprintf(stderr, "expected level %d with offset=%d, got %d\n",
57 AV_LOG_ERROR + i, i, last_log_level);
58 return 3;
59 }
60 }
61
62 1 return 0;
63 }
64