LCOV - code coverage report
Current view: top level - tests - common.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 25 34 73.5 %
Date: 2015-10-19 Functions: 5 5 100.0 %

          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          58 : tests_set_cwd(void)
      31             : {
      32             :     int ret;
      33             : 
      34          58 :     ret = chdir(TEST_DIR);
      35          58 :     if (ret == -1) {
      36           0 :         fprintf(stderr, "Could not chdir to [%s].\n"
      37             :                 "Attempting to continue with current dir\n", TEST_DIR);
      38             :     }
      39          58 : }
      40             : 
      41          76 : void test_dom_suite_setup(const char *tests_path)
      42             : {
      43             :     errno_t ret;
      44             : 
      45             :     /* Create tests directory if it doesn't exist */
      46             :     /* (relative to current dir) */
      47          76 :     ret = mkdir(tests_path, 0775);
      48          76 :     if (ret != 0 && errno != EEXIST) {
      49           0 :         fprintf(stderr, "Could not create test directory\n");
      50             :     }
      51          76 : }
      52             : 
      53             : /* Check that the option names of the two maps are the same
      54             :  * and appear in the same order.
      55             :  */
      56             : errno_t
      57           5 : compare_dp_options(struct dp_option *map1, size_t size1,
      58             :                    struct dp_option *map2)
      59             : {
      60             :     size_t i;
      61             : 
      62         229 :     for (i = 0; i < size1; i++) {
      63             :         /* Check for a valid option */
      64         224 :         if (map1[i].opt_name == NULL) return EINVAL;
      65             : 
      66             :         /* Check whether we've gone past the end of map2 */
      67         224 :         if (map2[i].opt_name == NULL) return ERANGE;
      68             : 
      69             :         /* Ensure that the option names are the same */
      70         224 :         if(strcmp(map1[i].opt_name, map2[i].opt_name) != 0) {
      71           0 :             fprintf(stderr, "Expected [%s], got [%s]\n",
      72           0 :                     map1[i].opt_name, map2[i].opt_name);
      73           0 :             return EINVAL;
      74             :         }
      75             :     }
      76             : 
      77             :     /* Leftover options in map2 */
      78           5 :     if (map2[i].opt_name != NULL) return ERANGE;
      79             : 
      80           5 :     return EOK;
      81             : }
      82             : 
      83             : /* Check that the option names of the two maps are the same
      84             :  * and appear in the same order.
      85             :  */
      86             : errno_t
      87          15 : compare_sdap_attr_maps(struct sdap_attr_map *map1, size_t size1,
      88             :                        struct sdap_attr_map *map2)
      89             : {
      90             :     size_t i;
      91             : 
      92         188 :     for (i = 0; i < size1; i++) {
      93             :         /* Check for a valid option */
      94         173 :         if (map1[i].opt_name == NULL) return EINVAL;
      95             : 
      96             :         /* Check whether we've gone past the end of map2 */
      97         173 :         if (map2[i].opt_name == NULL) return ERANGE;
      98             : 
      99             :         /* Ensure that the option names are the same */
     100         173 :         if(strcmp(map1[i].opt_name, map2[i].opt_name) != 0) {
     101           0 :             fprintf(stderr, "Expected [%s], got [%s]\n",
     102           0 :                     map1[i].opt_name, map2[i].opt_name);
     103           0 :             return EINVAL;
     104             :         }
     105             :     }
     106             : 
     107             :     /* Leftover options in map2 */
     108          15 :     if (map2[i].opt_name != NULL) return ERANGE;
     109             : 
     110          15 :     return EOK;
     111             : }
     112             : 
     113           2 : bool ldb_modules_path_is_set(void)
     114             : {
     115           2 :     if (getenv("LDB_MODULES_PATH")) {
     116           2 :         return true;
     117             :     }
     118             : 
     119           0 :     return false;
     120             : }

Generated by: LCOV version 1.10