LCOV - code coverage report
Current view: top level - src/libavutil/tests - avstring.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 27 100.0 %
Date: 2017-01-22 02:20:28 Functions: 1 1 100.0 %

          Line data    Source code
       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 <stdio.h>
      20             : 
      21             : #include "libavutil/common.h"
      22             : #include "libavutil/mem.h"
      23             : #include "libavutil/avstring.h"
      24             : 
      25           1 : int main(void)
      26             : {
      27             :     int i;
      28             :     char *fullpath, *ptr;
      29             :     static const char * const strings[] = {
      30             :         "''",
      31             :         "",
      32             :         ":",
      33             :         "\\",
      34             :         "'",
      35             :         "    ''    :",
      36             :         "    ''  ''  :",
      37             :         "foo   '' :",
      38             :         "'foo'",
      39             :         "foo     ",
      40             :         "  '  foo  '  ",
      41             :         "foo\\",
      42             :         "foo':  blah:blah",
      43             :         "foo\\:  blah:blah",
      44             :         "foo\'",
      45             :         "'foo :  '  :blahblah",
      46             :         "\\ :blah",
      47             :         "     foo",
      48             :         "      foo       ",
      49             :         "      foo     \\ ",
      50             :         "foo ':blah",
      51             :         " foo   bar    :   blahblah",
      52             :         "\\f\\o\\o",
      53             :         "'foo : \\ \\  '   : blahblah",
      54             :         "'\\fo\\o:': blahblah",
      55             :         "\\'fo\\o\\:':  foo  '  :blahblah"
      56             :     };
      57           1 :     const char *haystack = "Education consists mainly in what we have unlearned.";
      58             :     const char * const needle[] = {"learned.", "unlearned.", "Unlearned"};
      59             : 
      60           1 :     printf("Testing av_get_token()\n");
      61          27 :     for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
      62          26 :         const char *p = strings[i];
      63             :         char *q;
      64          26 :         printf("|%s|", p);
      65          26 :         q = av_get_token(&p, ":");
      66          26 :         printf(" -> |%s|", q);
      67          26 :         printf(" + |%s|\n", p);
      68          26 :         av_free(q);
      69             :     }
      70             : 
      71           1 :     printf("Testing av_append_path_component()\n");
      72             :     #define TEST_APPEND_PATH_COMPONENT(path, component, expected) \
      73             :         fullpath = av_append_path_component((path), (component)); \
      74             :         printf("%s = %s\n", fullpath ? fullpath : "(null)", expected); \
      75             :         av_free(fullpath);
      76           1 :     TEST_APPEND_PATH_COMPONENT(NULL, NULL, "(null)")
      77           1 :     TEST_APPEND_PATH_COMPONENT("path", NULL, "path");
      78           1 :     TEST_APPEND_PATH_COMPONENT(NULL, "comp", "comp");
      79           1 :     TEST_APPEND_PATH_COMPONENT("path", "comp", "path/comp");
      80           1 :     TEST_APPEND_PATH_COMPONENT("path/", "comp", "path/comp");
      81           1 :     TEST_APPEND_PATH_COMPONENT("path", "/comp", "path/comp");
      82           1 :     TEST_APPEND_PATH_COMPONENT("path/", "/comp", "path/comp");
      83           1 :     TEST_APPEND_PATH_COMPONENT("path/path2/", "/comp/comp2", "path/path2/comp/comp2");
      84             : 
      85             :     /*Testing av_strnstr()*/
      86             :     #define TEST_STRNSTR(haystack, needle, hay_length, expected) \
      87             :         ptr = av_strnstr(haystack, needle, hay_length); \
      88             :         if (ptr != expected){ \
      89             :             printf("expected: %p, received %p\n", expected, ptr); \
      90             :         }
      91           1 :     TEST_STRNSTR(haystack, needle [0], strlen(haystack), haystack+44);
      92           1 :     TEST_STRNSTR(haystack, needle [1], strlen(haystack), haystack+42);
      93           1 :     TEST_STRNSTR(haystack, needle [2], strlen(haystack), NULL       );
      94           1 :     TEST_STRNSTR(haystack, strings[1], strlen(haystack), haystack   );
      95             : 
      96             :     /*Testing av_d2str()*/
      97             :     #define TEST_D2STR(value, expected) \
      98             :         if((ptr = av_d2str(value)) == NULL){ \
      99             :             printf("error, received null pointer!\n"); \
     100             :         } else { \
     101             :             if(strcmp(ptr, expected) != 0) \
     102             :                 printf( "expected: %s, received: %s\n", expected, ptr); \
     103             :             av_free(ptr); \
     104             :         }
     105           1 :     TEST_D2STR(0         ,  "0.000000");
     106           1 :     TEST_D2STR(-1.2333234, "-1.233323");
     107           1 :     TEST_D2STR(-1.2333237, "-1.233324");
     108           1 :     return 0;
     109             : }

Generated by: LCOV version 1.12