LCOV - code coverage report
Current view: top level - tests - common.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 23 78.3 %
Date: 2012-11-29 Functions: 3 3 100.0 %
Branches: 13 22 59.1 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :    SSSD
       3                 :            : 
       4                 :            :    Common utilities for check-based tests using talloc.
       5                 :            : 
       6                 :            :    Authors:
       7                 :            :         Martin Nagy <mnagy@redhat.com>
       8                 :            : 
       9                 :            :    Copyright (C) Red Hat, Inc 2009
      10                 :            : 
      11                 :            :    This program is free software; you can redistribute it and/or modify
      12                 :            :    it under the terms of the GNU General Public License as published by
      13                 :            :    the Free Software Foundation; either version 3 of the License, or
      14                 :            :    (at your option) any later version.
      15                 :            : 
      16                 :            :    This program is distributed in the hope that it will be useful,
      17                 :            :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :    GNU General Public License for more details.
      20                 :            : 
      21                 :            :    You should have received a copy of the GNU General Public License
      22                 :            :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23                 :            : */
      24                 :            : 
      25                 :            : #include <stdio.h>
      26                 :            : #include "tests/common.h"
      27                 :            : #include "util/util.h"
      28                 :            : 
      29                 :            : void
      30                 :        789 : tests_set_cwd(void)
      31                 :            : {
      32                 :            :     int ret;
      33                 :            : 
      34                 :        789 :     ret = chdir(TEST_DIR);
      35         [ -  + ]:        789 :     if (ret == -1) {
      36                 :            :         if (strlen(TEST_DIR)) {
      37                 :          0 :             fprintf(stderr,
      38                 :            :                     "Could not chdir to [%s].\n"
      39                 :            :                     "Attempting to continue with current dir\n",
      40                 :            :                     TEST_DIR);
      41                 :            :         }
      42                 :            :     }
      43                 :        789 : }
      44                 :            : 
      45                 :            : /* Check that the option names of the two maps are the same
      46                 :            :  * and appear in the same order.
      47                 :            :  */
      48                 :            : errno_t
      49                 :          4 : compare_dp_options(struct dp_option *map1, size_t size1,
      50                 :            :                    struct dp_option *map2)
      51                 :            : {
      52                 :            :     size_t i;
      53                 :            : 
      54         [ +  + ]:        194 :     for (i = 0; i < size1; i++) {
      55                 :            :         /* Check for a valid option */
      56         [ +  - ]:        190 :         if (map1[i].opt_name == NULL) return EINVAL;
      57                 :            : 
      58                 :            :         /* Check whether we've gone past the end of map2 */
      59         [ +  - ]:        190 :         if (map2[i].opt_name == NULL) return ERANGE;
      60                 :            : 
      61                 :            :         /* Ensure that the option names are the same */
      62         [ -  + ]:        190 :         if(strcmp(map1[i].opt_name, map2[i].opt_name) != 0) {
      63                 :          0 :             fprintf(stderr, "Expected [%s], got [%s]\n",
      64                 :            :                     map1[i].opt_name, map2[i].opt_name);
      65                 :          0 :             return EINVAL;
      66                 :            :         }
      67                 :            :     }
      68                 :            : 
      69                 :            :     /* Leftover options in map2 */
      70         [ +  - ]:          4 :     if (map2[i].opt_name != NULL) return ERANGE;
      71                 :            : 
      72                 :          4 :     return EOK;
      73                 :            : }
      74                 :            : 
      75                 :            : /* Check that the option names of the two maps are the same
      76                 :            :  * and appear in the same order.
      77                 :            :  */
      78                 :            : errno_t
      79                 :         15 : compare_sdap_attr_maps(struct sdap_attr_map *map1, size_t size1,
      80                 :            :                        struct sdap_attr_map *map2)
      81                 :            : {
      82                 :            :     size_t i;
      83                 :            : 
      84         [ +  + ]:        177 :     for (i = 0; i < size1; i++) {
      85                 :            :         /* Check for a valid option */
      86         [ +  - ]:        162 :         if (map1[i].opt_name == NULL) return EINVAL;
      87                 :            : 
      88                 :            :         /* Check whether we've gone past the end of map2 */
      89         [ +  - ]:        162 :         if (map2[i].opt_name == NULL) return ERANGE;
      90                 :            : 
      91                 :            :         /* Ensure that the option names are the same */
      92         [ -  + ]:        162 :         if(strcmp(map1[i].opt_name, map2[i].opt_name) != 0) {
      93                 :          0 :             fprintf(stderr, "Expected [%s], got [%s]\n",
      94                 :            :                     map1[i].opt_name, map2[i].opt_name);
      95                 :          0 :             return EINVAL;
      96                 :            :         }
      97                 :            :     }
      98                 :            : 
      99                 :            :     /* Leftover options in map2 */
     100         [ +  - ]:         15 :     if (map2[i].opt_name != NULL) return ERANGE;
     101                 :            : 
     102                 :         15 :     return EOK;
     103                 :            : }

Generated by: LCOV version 1.9