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

          Line data    Source code
       1             : /*
       2             :  * copyright (c) 2009 Michael Niedermayer
       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/dict.c"
      22             : 
      23          14 : static void print_dict(const AVDictionary *m)
      24             : {
      25          14 :     AVDictionaryEntry *t = NULL;
      26          90 :     while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX)))
      27          62 :         printf("%s %s   ", t->key, t->value);
      28          14 :     printf("\n");
      29          14 : }
      30             : 
      31           7 : static void test_separators(const AVDictionary *m, const char pair, const char val)
      32             : {
      33           7 :     AVDictionary *dict = NULL;
      34           7 :     char pairs[] = {pair , '\0'};
      35           7 :     char vals[]  = {val, '\0'};
      36             : 
      37           7 :     char *buffer = NULL;
      38             :     int ret;
      39             : 
      40           7 :     av_dict_copy(&dict, m, 0);
      41           7 :     print_dict(dict);
      42           7 :     av_dict_get_string(dict, &buffer, val, pair);
      43           7 :     printf("%s\n", buffer);
      44           7 :     av_dict_free(&dict);
      45           7 :     ret = av_dict_parse_string(&dict, buffer, vals, pairs, 0);
      46           7 :     printf("ret %d\n", ret);
      47           7 :     av_freep(&buffer);
      48           7 :     print_dict(dict);
      49           7 :     av_dict_free(&dict);
      50           7 : }
      51             : 
      52           1 : int main(void)
      53             : {
      54           1 :     AVDictionary *dict = NULL;
      55             :     AVDictionaryEntry *e;
      56           1 :     char *buffer = NULL;
      57             : 
      58           1 :     printf("Testing av_dict_get_string() and av_dict_parse_string()\n");
      59           1 :     av_dict_get_string(dict, &buffer, '=', ',');
      60           1 :     printf("%s\n", buffer);
      61           1 :     av_freep(&buffer);
      62           1 :     av_dict_set(&dict, "aaa", "aaa", 0);
      63           1 :     av_dict_set(&dict, "b,b", "bbb", 0);
      64           1 :     av_dict_set(&dict, "c=c", "ccc", 0);
      65           1 :     av_dict_set(&dict, "ddd", "d,d", 0);
      66           1 :     av_dict_set(&dict, "eee", "e=e", 0);
      67           1 :     av_dict_set(&dict, "f,f", "f=f", 0);
      68           1 :     av_dict_set(&dict, "g=g", "g,g", 0);
      69           1 :     test_separators(dict, ',', '=');
      70           1 :     av_dict_free(&dict);
      71           1 :     av_dict_set(&dict, "aaa", "aaa", 0);
      72           1 :     av_dict_set(&dict, "bbb", "bbb", 0);
      73           1 :     av_dict_set(&dict, "ccc", "ccc", 0);
      74           1 :     av_dict_set(&dict, "\\,=\'\"", "\\,=\'\"", 0);
      75           1 :     test_separators(dict, '"',  '=');
      76           1 :     test_separators(dict, '\'', '=');
      77           1 :     test_separators(dict, ',', '"');
      78           1 :     test_separators(dict, ',', '\'');
      79           1 :     test_separators(dict, '\'', '"');
      80           1 :     test_separators(dict, '"', '\'');
      81           1 :     av_dict_free(&dict);
      82             : 
      83           1 :     printf("\nTesting av_dict_set()\n");
      84           1 :     av_dict_set(&dict, "a", "a", 0);
      85           1 :     av_dict_set(&dict, "b", av_strdup("b"), AV_DICT_DONT_STRDUP_VAL);
      86           1 :     av_dict_set(&dict, av_strdup("c"), "c", AV_DICT_DONT_STRDUP_KEY);
      87           1 :     av_dict_set(&dict, av_strdup("d"), av_strdup("d"), AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
      88           1 :     av_dict_set(&dict, "e", "e", AV_DICT_DONT_OVERWRITE);
      89           1 :     av_dict_set(&dict, "e", "f", AV_DICT_DONT_OVERWRITE);
      90           1 :     av_dict_set(&dict, "f", "f", 0);
      91           1 :     av_dict_set(&dict, "f", NULL, 0);
      92           1 :     av_dict_set(&dict, "ff", "f", 0);
      93           1 :     av_dict_set(&dict, "ff", "f", AV_DICT_APPEND);
      94           1 :     e = NULL;
      95           8 :     while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
      96           6 :         printf("%s %s\n", e->key, e->value);
      97           1 :     av_dict_free(&dict);
      98             : 
      99           1 :     av_dict_set(&dict, NULL, "a", 0);
     100           1 :     av_dict_set(&dict, NULL, "b", 0);
     101           1 :     av_dict_get(dict, NULL, NULL, 0);
     102           1 :     e = NULL;
     103           2 :     while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
     104           0 :         printf("'%s' '%s'\n", e->key, e->value);
     105           1 :     av_dict_free(&dict);
     106             : 
     107             : 
     108             :     //valgrind sensible test
     109           1 :     printf("\nTesting av_dict_set_int()\n");
     110           1 :     av_dict_set_int(&dict, "1", 1, AV_DICT_DONT_STRDUP_VAL);
     111           1 :     av_dict_set_int(&dict, av_strdup("2"), 2, AV_DICT_DONT_STRDUP_KEY);
     112           1 :     av_dict_set_int(&dict, av_strdup("3"), 3, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
     113           1 :     av_dict_set_int(&dict, "4", 4, 0);
     114           1 :     av_dict_set_int(&dict, "5", 5, AV_DICT_DONT_OVERWRITE);
     115           1 :     av_dict_set_int(&dict, "5", 6, AV_DICT_DONT_OVERWRITE);
     116           1 :     av_dict_set_int(&dict, "12", 1, 0);
     117           1 :     av_dict_set_int(&dict, "12", 2, AV_DICT_APPEND);
     118           1 :     e = NULL;
     119           8 :     while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
     120           6 :         printf("%s %s\n", e->key, e->value);
     121           1 :     av_dict_free(&dict);
     122             : 
     123             :     //valgrind sensible test
     124           1 :     printf("\nTesting av_dict_set() with existing AVDictionaryEntry.key as key\n");
     125           1 :     av_dict_set(&dict, "key", "old", 0);
     126           1 :     e = av_dict_get(dict, "key", NULL, 0);
     127           1 :     av_dict_set(&dict, e->key, "new val OK", 0);
     128           1 :     e = av_dict_get(dict, "key", NULL, 0);
     129           1 :     printf("%s\n", e->value);
     130           1 :     av_dict_set(&dict, e->key, e->value, 0);
     131           1 :     e = av_dict_get(dict, "key", NULL, 0);
     132           1 :     printf("%s\n", e->value);
     133           1 :     av_dict_free(&dict);
     134             : 
     135           1 :     return 0;
     136             : }

Generated by: LCOV version 1.13