LCOV - code coverage report
Current view: top level - tests/gpgsm - t-import.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 44 72 61.1 %
Date: 2016-09-12 13:07:23 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* t-import.c - Regression test.
       2             :    Copyright (C) 2000 Werner Koch (dd9jn)
       3             :    Copyright (C) 2001, 2003, 2004 g10 Code GmbH
       4             : 
       5             :    This file is part of GPGME.
       6             :  
       7             :    GPGME is free software; you can redistribute it and/or modify it
       8             :    under the terms of the GNU Lesser General Public License as
       9             :    published by the Free Software Foundation; either version 2.1 of
      10             :    the License, or (at your option) any later version.
      11             :    
      12             :    GPGME is distributed in the hope that it will be useful, but
      13             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :    Lesser General Public License for more details.
      16             :    
      17             :    You should have received a copy of the GNU Lesser General Public
      18             :    License along with this program; if not, write to the Free Software
      19             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      20             :    02111-1307, USA.  */
      21             : 
      22             : /* We need to include config.h so that we know whether we are building
      23             :    with large file system (LFS) support. */
      24             : #ifdef HAVE_CONFIG_H
      25             : #include <config.h>
      26             : #endif
      27             : 
      28             : #include <stdlib.h>
      29             : #include <stdio.h>
      30             : #include <string.h>
      31             : #include <errno.h>
      32             : 
      33             : #include <gpgme.h>
      34             : 
      35             : #include "t-support.h"
      36             : 
      37             : 
      38             : void
      39           2 : check_result (gpgme_import_result_t result, char *fpr, int total,
      40             :               int total_stat)
      41             : {
      42           2 :   if (result->considered != total)
      43             :     {
      44           0 :       fprintf (stderr, "Unexpected number of considered keys %i\n",
      45             :                result->considered);
      46           0 :       exit (1);
      47             :     }
      48           2 :   if (result->no_user_id != 0)
      49             :     {
      50           0 :       fprintf (stderr, "Unexpected number of user ids %i\n",
      51             :                result->no_user_id);
      52           0 :       exit (1);
      53             :     }
      54           2 :   if (result->imported != 0 && result->imported != 1)
      55             :     {
      56           0 :       fprintf (stderr, "Unexpected number of imported keys %i\n",
      57             :                result->imported);
      58           0 :       exit (1);
      59             :     }
      60           2 :   if (result->imported_rsa != 0)
      61             :     {
      62           0 :       fprintf (stderr, "Unexpected number of imported RSA keys %i\n",
      63             :                result->imported_rsa);
      64           0 :       exit (1);
      65             :     }
      66           2 :   if ((result->imported == 0 && result->unchanged != total)
      67           2 :       || (result->imported == 1 && result->unchanged != total - 1))
      68             :     {
      69           0 :       fprintf (stderr, "Unexpected number of unchanged keys %i\n",
      70             :                result->unchanged);
      71           0 :       exit (1);
      72             :     }
      73           2 :   if (result->new_user_ids != 0)
      74             :     {
      75           0 :       fprintf (stderr, "Unexpected number of new user IDs %i\n",
      76             :                result->new_user_ids);
      77           0 :       exit (1);
      78             :     }
      79           2 :   if (result->new_sub_keys != 0)
      80             :     {
      81           0 :       fprintf (stderr, "Unexpected number of new sub keys %i\n",
      82             :                result->new_sub_keys);
      83           0 :       exit (1);
      84             :     }
      85           2 :   if (result->new_signatures != 0)
      86             :     {
      87           0 :       fprintf (stderr, "Unexpected number of new signatures %i\n",
      88             :                result->new_signatures);
      89           0 :       exit (1);
      90             :     }
      91           2 :   if (result->new_revocations != 0)
      92             :     {
      93           0 :       fprintf (stderr, "Unexpected number of new revocations %i\n",
      94             :                result->new_revocations);
      95           0 :       exit (1);
      96             :     }
      97           2 :   if (result->secret_read != 0)
      98             :     {
      99           0 :       fprintf (stderr, "Unexpected number of secret keys read %i\n",
     100             :                result->secret_read);
     101           0 :       exit (1);
     102             :     }
     103           2 :   if (result->secret_imported != 0)
     104             :     {
     105           0 :       fprintf (stderr, "Unexpected number of secret keys imported %i\n",
     106             :                result->secret_imported);
     107           0 :       exit (1);
     108             :     }
     109           2 :   if (result->secret_unchanged != 0)
     110             :     {
     111           0 :       fprintf (stderr, "Unexpected number of secret keys unchanged %i\n",
     112             :                result->secret_unchanged);
     113           0 :       exit (1);
     114             :     }
     115           2 :   if (result->not_imported != 0)
     116             :     {
     117           0 :       fprintf (stderr, "Unexpected number of secret keys not imported %i\n",
     118             :                result->not_imported);
     119           0 :       exit (1);
     120             :     }
     121             :   
     122             :   {
     123             :     int n;
     124             :     gpgme_import_status_t r;
     125             : 
     126           5 :     for (n=0, r=result->imports; r; r=r->next)
     127           3 :       n++;
     128             :       
     129           2 :     if (n != total_stat)
     130             :     {
     131           0 :       fprintf (stderr, "Unexpected number of status reports\n");
     132           0 :       exit (1);
     133             :     }
     134             :   }
     135           2 : }
     136             : 
     137             : 
     138             : int 
     139           1 : main (int argc, char **argv)
     140             : {
     141             :   gpgme_ctx_t ctx;
     142             :   gpgme_error_t err;
     143             :   gpgme_data_t in;
     144             :   gpgme_import_result_t result;
     145           1 :   char *cert_1 = make_filename ("cert_dfn_pca01.der");
     146           1 :   char *cert_2 = make_filename ("cert_dfn_pca15.der");
     147             : 
     148           1 :   init_gpgme (GPGME_PROTOCOL_CMS);
     149             : 
     150           1 :   err = gpgme_new (&ctx);
     151           1 :   fail_if_err (err);
     152             :   
     153           1 :   gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
     154             : 
     155           1 :   err = gpgme_data_new_from_file (&in, cert_1, 1);
     156           1 :   free (cert_1);
     157           1 :   fail_if_err (err);
     158             : 
     159           1 :   err = gpgme_op_import (ctx, in);
     160           1 :   fail_if_err (err);
     161           1 :   result = gpgme_op_import_result (ctx);
     162           1 :   check_result (result, "DFA56FB5FC41E3A8921F77AD1622EEFD9152A5AD", 1, 1);
     163           1 :   gpgme_data_release (in);
     164             : 
     165           1 :   err = gpgme_data_new_from_file (&in, cert_2, 1);
     166           1 :   free (cert_2);
     167           1 :   fail_if_err (err);
     168             : 
     169           1 :   err = gpgme_op_import (ctx, in);
     170           1 :   fail_if_err (err);
     171           1 :   result = gpgme_op_import_result (ctx);
     172           1 :   check_result (result, "2C8F3C356AB761CB3674835B792CDA52937F9285", 1, 2);
     173           1 :   gpgme_data_release (in);
     174             : 
     175           1 :   gpgme_release (ctx);
     176           1 :   return 0;
     177             : }

Generated by: LCOV version 1.11