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: 2015-11-05 17:10:59 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 "stringhelp.h"
      36             : 
      37             : #include "t-support.h"
      38             : 
      39             : static void
      40           1 : test_map_static_macro_string (void)
      41             : {
      42             :   static struct {
      43             :     const char *string;
      44             :     const char *expected;
      45             :     const char *lastresult;
      46             :   } tests[] = {
      47             :     { "@GPG@ (@GNUPG@)",
      48             :       GPG_NAME " (" GNUPG_NAME ")" },
      49             :     { "@GPG@(@GNUPG@)",
      50             :       GPG_NAME "(" GNUPG_NAME ")" },
      51             :     { "@GPG@@GNUPG@",
      52             :       GPG_NAME  GNUPG_NAME },
      53             :     { " @GPG@@GNUPG@",
      54             :       " " GPG_NAME  GNUPG_NAME },
      55             :     { " @GPG@@GNUPG@ ",
      56             :       " " GPG_NAME  GNUPG_NAME " " },
      57             :     { " @GPG@GNUPG@ ",
      58             :       " " GPG_NAME "GNUPG@ " },
      59             :     { " @ GPG@GNUPG@ ",
      60             :       " @ GPG" GNUPG_NAME " " },
      61             :     { "--@GPGTAR@",
      62             :       "--" GPGTAR_NAME }
      63             :   };
      64             :   int testno;
      65             :   const char *result;
      66             : 
      67           9 :   for (testno=0; testno < DIM(tests); testno++)
      68             :     {
      69           8 :       result = map_static_macro_string (tests[testno].string);
      70           8 :       if (!result)
      71           0 :         fail (testno);
      72           8 :       if (strcmp (result, tests[testno].expected))
      73           0 :         fail (testno);
      74           8 :       if (!tests[testno].lastresult)
      75           8 :         tests[testno].lastresult = result;
      76             :     }
      77             : 
      78             :   /* A second time to check that the same string is been returned.  */
      79           9 :   for (testno=0; testno < DIM(tests); testno++)
      80             :     {
      81           8 :       result = map_static_macro_string (tests[testno].string);
      82           8 :       if (!result)
      83           0 :         fail (testno);
      84           8 :       if (strcmp (result, tests[testno].expected))
      85           0 :         fail (testno);
      86           8 :       if (result != tests[testno].lastresult)
      87           0 :         fail (testno);
      88             :     }
      89           1 : }
      90             : 
      91             : 
      92             : int
      93           1 : main (int argc, char **argv)
      94             : {
      95             :   (void)argc;
      96             :   (void)argv;
      97             : 
      98           1 :   test_map_static_macro_string ();
      99             : 
     100           1 :   return 0;
     101             : }

Generated by: LCOV version 1.11