LCOV - code coverage report
Current view: top level - tests - format-test.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 86 86 100.0 %
Date: 2012-07-17 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 39 74 52.7 %

           Branch data     Line data    Source code
       1                 :            : /***
       2                 :            :   This file is part of PulseAudio.
       3                 :            : 
       4                 :            :   PulseAudio is free software; you can redistribute it and/or modify
       5                 :            :   it under the terms of the GNU Lesser General Public License as published
       6                 :            :   by the Free Software Foundation; either version 2.1 of the License,
       7                 :            :   or (at your option) any later version.
       8                 :            : 
       9                 :            :   PulseAudio is distributed in the hope that it will be useful, but
      10                 :            :   WITHOUT ANY WARRANTY; without even the implied warranty of
      11                 :            :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      12                 :            :   General Public License for more details.
      13                 :            : 
      14                 :            :   You should have received a copy of the GNU Lesser General Public License
      15                 :            :   along with PulseAudio; if not, write to the Free Software
      16                 :            :   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
      17                 :            :   USA.
      18                 :            : ***/
      19                 :            : 
      20                 :            : #ifdef HAVE_CONFIG_H
      21                 :            : #include <config.h>
      22                 :            : #endif
      23                 :            : 
      24                 :            : #include <stdlib.h>
      25                 :            : 
      26                 :            : #include <pulsecore/macro.h>
      27                 :            : #include <pulsecore/core-util.h>
      28                 :            : #include <pulse/format.h>
      29                 :            : #include <pulse/xmalloc.h>
      30                 :            : 
      31                 :            : #define INIT(f) f = pa_format_info_new()
      32                 :            : #define DEINIT(f) pa_format_info_free(f);
      33                 :            : #define REINIT(f) { DEINIT(f); INIT(f); }
      34                 :            : 
      35                 :          1 : int main(int argc, char *argv[]) {
      36                 :          1 :     pa_format_info *f1 = NULL, *f2 = NULL;
      37                 :          1 :     int rates1[] = { 32000, 44100, 48000 }, i, temp_int1 = -1, temp_int2 = -1, *temp_int_array;
      38                 :          1 :     const char *strings[] = { "thing1", "thing2", "thing3" };
      39                 :            :     char *temp_str, **temp_str_array;
      40                 :            : 
      41                 :            :     /* 1. Simple fixed format int check */
      42                 :          1 :     INIT(f1); INIT(f2);
      43                 :          1 :     f1->encoding = PA_ENCODING_AC3_IEC61937;
      44                 :          1 :     pa_format_info_set_prop_int(f1, PA_PROP_FORMAT_RATE, 32000);
      45                 :          1 :     f2->encoding = PA_ENCODING_AC3_IEC61937;
      46                 :          1 :     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
      47         [ -  + ]:          1 :     pa_assert(!pa_format_info_is_compatible(f1, f2));
      48                 :            : 
      49                 :            :     /* 2. Check int array membership - positive */
      50                 :          1 :     REINIT(f1); REINIT(f2);
      51                 :          1 :     f1->encoding = PA_ENCODING_AC3_IEC61937;
      52                 :          1 :     pa_format_info_set_prop_int_array(f1, PA_PROP_FORMAT_RATE, rates1, PA_ELEMENTSOF(rates1));
      53                 :          1 :     f2->encoding = PA_ENCODING_AC3_IEC61937;
      54                 :          1 :     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
      55         [ -  + ]:          1 :     pa_assert(pa_format_info_is_compatible(f1, f2));
      56         [ -  + ]:          1 :     pa_assert(pa_format_info_is_compatible(f2, f1));
      57                 :            : 
      58                 :            :     /* 3. Check int array membership - negative */
      59                 :          1 :     REINIT(f2);
      60                 :          1 :     f2->encoding = PA_ENCODING_AC3_IEC61937;
      61                 :          1 :     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 96000);
      62         [ -  + ]:          1 :     pa_assert(!pa_format_info_is_compatible(f1, f2));
      63         [ -  + ]:          1 :     pa_assert(!pa_format_info_is_compatible(f2, f1));
      64                 :            : 
      65                 :            :     /* 4. Check int range - positive */
      66                 :          1 :     REINIT(f1); REINIT(f2);
      67                 :          1 :     f1->encoding = PA_ENCODING_AC3_IEC61937;
      68                 :          1 :     pa_format_info_set_prop_int_range(f1, PA_PROP_FORMAT_RATE, 32000, 48000);
      69                 :          1 :     f2->encoding = PA_ENCODING_AC3_IEC61937;
      70                 :          1 :     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 44100);
      71         [ -  + ]:          1 :     pa_assert(pa_format_info_is_compatible(f1, f2));
      72         [ -  + ]:          1 :     pa_assert(pa_format_info_is_compatible(f2, f1));
      73                 :            : 
      74                 :            :     /* 5. Check int range - negative */
      75                 :          1 :     REINIT(f2);
      76                 :          1 :     f2->encoding = PA_ENCODING_AC3_IEC61937;
      77                 :          1 :     pa_format_info_set_prop_int(f2, PA_PROP_FORMAT_RATE, 96000);
      78         [ -  + ]:          1 :     pa_assert(!pa_format_info_is_compatible(f1, f2));
      79         [ -  + ]:          1 :     pa_assert(!pa_format_info_is_compatible(f2, f1));
      80                 :            : 
      81                 :            :     /* 6. Simple fixed format string check */
      82                 :          1 :     REINIT(f1); REINIT(f2);
      83                 :          1 :     f1->encoding = PA_ENCODING_AC3_IEC61937;
      84                 :          1 :     pa_format_info_set_prop_string(f1, "format.test_string", "thing1");
      85                 :          1 :     f2->encoding = PA_ENCODING_AC3_IEC61937;
      86                 :          1 :     pa_format_info_set_prop_string(f2, "format.test_string", "notthing1");
      87         [ -  + ]:          1 :     pa_assert(!pa_format_info_is_compatible(f1, f2));
      88                 :            : 
      89                 :            :     /* 7. Check string array membership - positive */
      90                 :          1 :     REINIT(f1); REINIT(f2);
      91                 :          1 :     f1->encoding = PA_ENCODING_AC3_IEC61937;
      92                 :          1 :     pa_format_info_set_prop_string_array(f1, "format.test_string", strings, PA_ELEMENTSOF(strings));
      93                 :          1 :     f2->encoding = PA_ENCODING_AC3_IEC61937;
      94                 :          1 :     pa_format_info_set_prop_string(f2, "format.test_string", "thing3");
      95         [ -  + ]:          1 :     pa_assert(pa_format_info_is_compatible(f1, f2));
      96         [ -  + ]:          1 :     pa_assert(pa_format_info_is_compatible(f2, f1));
      97                 :            : 
      98                 :            :     /* 8. Check string array membership - negative */
      99                 :          1 :     REINIT(f2);
     100                 :          1 :     f2->encoding = PA_ENCODING_AC3_IEC61937;
     101                 :          1 :     pa_format_info_set_prop_string(f2, "format.test_string", "thing5");
     102         [ -  + ]:          1 :     pa_assert(!pa_format_info_is_compatible(f1, f2));
     103         [ -  + ]:          1 :     pa_assert(!pa_format_info_is_compatible(f2, f1));
     104                 :            : 
     105                 :            :     /* 9. Verify setting/getting an int */
     106                 :          1 :     REINIT(f1);
     107                 :          1 :     pa_format_info_set_prop_int(f1, "format.test_string", 42);
     108         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT);
     109         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_int(f1, "format.test_string", &temp_int1) == 0);
     110         [ -  + ]:          1 :     pa_assert(temp_int1 == 42);
     111                 :            : 
     112                 :            :     /* 10. Verify setting/getting an int range */
     113                 :          1 :     REINIT(f1);
     114                 :          1 :     pa_format_info_set_prop_int_range(f1, "format.test_string", 0, 100);
     115         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT_RANGE);
     116         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_int_range(f1, "format.test_string", &temp_int1, &temp_int2) == 0);
     117 [ +  - ][ -  + ]:          1 :     pa_assert(temp_int1 == 0 && temp_int2 == 100);
     118                 :            : 
     119                 :            :     /* 11. Verify setting/getting an int array */
     120                 :          1 :     REINIT(f1);
     121                 :          1 :     pa_format_info_set_prop_int_array(f1, "format.test_string", rates1, PA_ELEMENTSOF(rates1));
     122         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_INT_ARRAY);
     123         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_int_array(f1, "format.test_string", &temp_int_array, &temp_int1) == 0);
     124         [ +  - ]:          1 :     pa_assert(temp_int1 == PA_ELEMENTSOF(rates1));
     125         [ +  + ]:          4 :     for (i = 0; i < temp_int1; i++)
     126         [ -  + ]:          3 :         pa_assert(temp_int_array[i] == rates1[i]);
     127                 :          1 :     pa_xfree(temp_int_array);
     128                 :            : 
     129                 :            :     /* 12. Verify setting/getting a string */
     130                 :          1 :     REINIT(f1);
     131                 :          1 :     pa_format_info_set_prop_string(f1, "format.test_string", "foo");
     132         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING);
     133         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_string(f1, "format.test_string", &temp_str) == 0);
     134 [ +  - ][ +  - ]:          1 :     pa_assert(pa_streq(temp_str, "foo"));
         [ +  - ][ -  + ]
     135                 :          1 :     pa_xfree(temp_str);
     136                 :            : 
     137                 :            :     /* 13. Verify setting/getting an int array */
     138                 :          1 :     REINIT(f1);
     139                 :          1 :     pa_format_info_set_prop_string_array(f1, "format.test_string", strings, PA_ELEMENTSOF(strings));
     140         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_type(f1, "format.test_string") == PA_PROP_TYPE_STRING_ARRAY);
     141         [ -  + ]:          1 :     pa_assert(pa_format_info_get_prop_string_array(f1, "format.test_string", &temp_str_array, &temp_int1) == 0);
     142         [ +  - ]:          1 :     pa_assert(temp_int1 == PA_ELEMENTSOF(strings));
     143         [ +  + ]:          4 :     for (i = 0; i < temp_int1; i++)
     144         [ -  + ]:          3 :         pa_assert(pa_streq(temp_str_array[i], strings[i]));
     145                 :          1 :     pa_format_info_free_string_array(temp_str_array, temp_int1);
     146                 :            : 
     147                 :          1 :     DEINIT(f1);
     148                 :          1 :     DEINIT(f2);
     149                 :            : 
     150                 :            :     return 0;
     151                 :            : }

Generated by: LCOV version 1.9