FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/bprint.c
Date: 2026-04-24 19:58:39
Exec Total Coverage
Lines: 47 47 100.0%
Functions: 2 2 100.0%
Branches: 7 8 87.5%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2012 Nicolas George
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 "libavutil/avassert.h"
22 #include "libavutil/bprint.c"
23
24 7 static void bprint_pascal(AVBPrint *b, unsigned size)
25 {
26 unsigned i, j;
27 unsigned p[42];
28
29
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 av_assert0(size < FF_ARRAY_ELEMS(p));
30
31 7 p[0] = 1;
32 7 av_bprintf(b, "%8d\n", 1);
33
2/2
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 7 times.
142 for (i = 1; i <= size; i++) {
34 135 p[i] = 1;
35
2/2
✓ Branch 0 taken 1520 times.
✓ Branch 1 taken 135 times.
1655 for (j = i - 1; j > 0; j--)
36 1520 p[j] = p[j] + p[j - 1];
37
2/2
✓ Branch 0 taken 1790 times.
✓ Branch 1 taken 135 times.
1925 for (j = 0; j <= i; j++)
38 1790 av_bprintf(b, "%8d", p[j]);
39 135 av_bprintf(b, "\n");
40 }
41 7 }
42
43 1 int main(void)
44 {
45 AVBPrint b;
46 char buf[256];
47 1 struct tm testtime = { .tm_year = 100, .tm_mon = 11, .tm_mday = 20 };
48
49 1 av_bprint_init(&b, 0, AV_BPRINT_SIZE_UNLIMITED);
50 1 bprint_pascal(&b, 5);
51 1 printf("Short text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
52 1 printf("%s\n", b.str);
53 1 av_bprint_finalize(&b, NULL);
54
55 1 av_bprint_init(&b, 0, AV_BPRINT_SIZE_UNLIMITED);
56 1 bprint_pascal(&b, 25);
57 1 printf("Long text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
58 1 av_bprint_finalize(&b, NULL);
59
60 1 av_bprint_init(&b, 0, 2048);
61 1 bprint_pascal(&b, 25);
62 1 printf("Long text in limited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
63 1 av_bprint_finalize(&b, NULL);
64
65 1 av_bprint_init(&b, 0, AV_BPRINT_SIZE_AUTOMATIC);
66 1 bprint_pascal(&b, 5);
67 1 printf("Short text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
68
69 1 av_bprint_init(&b, 0, AV_BPRINT_SIZE_AUTOMATIC);
70 1 bprint_pascal(&b, 25);
71 1 printf("Long text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str)/8*8, b.len);
72 /* Note that the size of the automatic buffer is arch-dependent. */
73
74 1 av_bprint_init(&b, 0, AV_BPRINT_SIZE_COUNT_ONLY);
75 1 bprint_pascal(&b, 25);
76 1 printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
77
78 1 av_bprint_init_for_buffer(&b, buf, sizeof(buf));
79 1 bprint_pascal(&b, 25);
80 1 printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(buf), b.len);
81
82 1 av_bprint_init(&b, 0, AV_BPRINT_SIZE_UNLIMITED);
83 1 av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
84 1 printf("strftime full: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
85 1 av_bprint_finalize(&b, NULL);
86
87 1 av_bprint_init(&b, 0, 8);
88 1 av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
89 1 printf("strftime truncated: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
90
91 1 return 0;
92 }
93