LCOV - code coverage report
Current view: top level - common - t-mapstrings.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 21 76.2 %
Date: 2016-09-12 12:29:17 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* t-mapstrings.c - Regression tests for mapstrings.c
       2             :  * Copyright (C) 2014 Werner Koch
       3             :  *
       4             :  * This file is part of GnuPG.
       5             :  *
       6             :  * This file is free software; you can redistribute it and/or modify
       7             :  * it under the terms of either
       8             :  *
       9             :  *   - the GNU Lesser General Public License as published by the Free
      10             :  *     Software Foundation; either version 3 of the License, or (at
      11             :  *     your option) any later version.
      12             :  *
      13             :  * or
      14             :  *
      15             :  *   - the GNU General Public License as published by the Free
      16             :  *     Software Foundation; either version 2 of the License, or (at
      17             :  *     your option) any later version.
      18             :  *
      19             :  * or both in parallel, as here.
      20             :  *
      21             :  * This file is distributed in the hope that it will be useful,
      22             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      24             :  * GNU General Public License for more details.
      25             :  *
      26             :  * You should have received a copy of the GNU General Public License
      27             :  * along with this program; if not, see <http://www.gnu.org/licenses/>.
      28             :  */
      29             : 
      30             : #include <config.h>
      31             : #include <stdio.h>
      32             : #include <stdlib.h>
      33             : #include <string.h>
      34             : 
      35             : #include "t-support.h"
      36             : #include "stringhelp.h"
      37             : 
      38             : static void
      39           1 : test_map_static_macro_string (void)
      40             : {
      41             :   static struct {
      42             :     const char *string;
      43             :     const char *expected;
      44             :     const char *lastresult;
      45             :   } tests[] = {
      46             :     { "@GPG@ (@GNUPG@)",
      47             :       GPG_NAME " (" GNUPG_NAME ")" },
      48             :     { "@GPG@(@GNUPG@)",
      49             :       GPG_NAME "(" GNUPG_NAME ")" },
      50             :     { "@GPG@@GNUPG@",
      51             :       GPG_NAME  GNUPG_NAME },
      52             :     { " @GPG@@GNUPG@",
      53             :       " " GPG_NAME  GNUPG_NAME },
      54             :     { " @GPG@@GNUPG@ ",
      55             :       " " GPG_NAME  GNUPG_NAME " " },
      56             :     { " @GPG@GNUPG@ ",
      57             :       " " GPG_NAME "GNUPG@ " },
      58             :     { " @ GPG@GNUPG@ ",
      59             :       " @ GPG" GNUPG_NAME " " },
      60             :     { "--@GPGTAR@",
      61             :       "--" GPGTAR_NAME }
      62             :   };
      63             :   int testno;
      64             :   const char *result;
      65             : 
      66           9 :   for (testno=0; testno < DIM(tests); testno++)
      67             :     {
      68           8 :       result = map_static_macro_string (tests[testno].string);
      69           8 :       if (!result)
      70           0 :         fail (testno);
      71           8 :       else if (strcmp (result, tests[testno].expected))
      72           0 :         fail (testno);
      73           8 :       if (!tests[testno].lastresult)
      74           8 :         tests[testno].lastresult = result;
      75             :     }
      76             : 
      77             :   /* A second time to check that the same string is been returned.  */
      78           9 :   for (testno=0; testno < DIM(tests); testno++)
      79             :     {
      80           8 :       result = map_static_macro_string (tests[testno].string);
      81           8 :       if (!result)
      82           0 :         fail (testno);
      83           8 :       else if (strcmp (result, tests[testno].expected))
      84           0 :         fail (testno);
      85           8 :       if (result != tests[testno].lastresult)
      86           0 :         fail (testno);
      87             :     }
      88           1 : }
      89             : 
      90             : 
      91             : int
      92           1 : main (int argc, char **argv)
      93             : {
      94             :   (void)argc;
      95             :   (void)argv;
      96             : 
      97           1 :   test_map_static_macro_string ();
      98             : 
      99           1 :   return 0;
     100             : }

Generated by: LCOV version 1.11