LCOV - code coverage report
Current view: top level - libavutil/tests - bprint.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 47 47 100.0 %
Date: 2017-10-18 21:45:51 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.13