LCOV - code coverage report
Current view: top level - libcli/dns - resolvconftest.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 24 35 68.6 %
Date: 2024-04-21 15:09:00 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Unix SMB/CIFS implementation.
       3             :  *  Internal DNS query structures
       4             :  *  Copyright (C) Volker Lendecke 2018
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program 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
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include <stdio.h>
      21             : #include <string.h>
      22             : #include <talloc.h>
      23             : #include <errno.h>
      24             : #include "libcli/dns/resolvconf.h"
      25             : #include "lib/util/memory.h"
      26             : 
      27           1 : static int resolvconftest1(void)
      28             : {
      29           1 :         const char *content =
      30             :                 "#foo\nbar\nnameserver 1.2.3.4\nnameserver 2.3.4.5";
      31           1 :         char *file;
      32           1 :         FILE *fp;
      33           1 :         int ret;
      34           1 :         char **nameservers;
      35           1 :         size_t num_nameservers;
      36             : 
      37           1 :         file = strdup(content);
      38           1 :         if (file == NULL) {
      39           0 :                 perror("strdup failed");
      40           0 :                 return ENOMEM;
      41             :         }
      42           1 :         fp = fmemopen(file, strlen(file), "r");
      43           1 :         if (fp == NULL) {
      44           0 :                 perror("fmemopen failed");
      45           0 :                 return errno;
      46             :         }
      47             : 
      48           1 :         ret = parse_resolvconf_fp(fp, NULL, &nameservers, &num_nameservers);
      49           1 :         if (ret != 0) {
      50           0 :                 fprintf(stderr, "parse_resolvconf_fp failed: %s\n",
      51             :                         strerror(ret));
      52           0 :                 return ret;
      53             :         }
      54             : 
      55           1 :         if (num_nameservers != 2) {
      56           0 :                 fprintf(stderr, "expected 2 nameservers, got %zu\n",
      57             :                         num_nameservers);
      58           0 :                 return EIO;
      59             :         }
      60           1 :         if ((strcmp(nameservers[0], "1.2.3.4") != 0) ||
      61           1 :             (strcmp(nameservers[1], "2.3.4.5") != 0)) {
      62           0 :                 fprintf(stderr, "got wrong nameservers\n");
      63           0 :                 return EIO;
      64             :         }
      65             : 
      66           1 :         TALLOC_FREE(nameservers);
      67           1 :         fclose(fp);
      68           1 :         SAFE_FREE(file);
      69             : 
      70           1 :         return 0;
      71             : }
      72             : 
      73           1 : int main(void) {
      74           1 :         int ret;
      75             : 
      76           1 :         ret = resolvconftest1();
      77           1 :         if (ret != 0) {
      78           0 :                 return 1;
      79             :         }
      80             : 
      81             :         return 0;
      82             : }

Generated by: LCOV version 1.14