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: 2018-11-15 08:49:49 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, const char *fpr, int total,
      40             :               int total_stat)
      41             : {
      42             :   (void)fpr;
      43             : 
      44           2 :   if (result->considered != total)
      45             :     {
      46           0 :       fprintf (stderr, "Unexpected number of considered keys %i\n",
      47             :                result->considered);
      48           0 :       exit (1);
      49             :     }
      50           2 :   if (result->no_user_id != 0)
      51             :     {
      52           0 :       fprintf (stderr, "Unexpected number of user ids %i\n",
      53             :                result->no_user_id);
      54           0 :       exit (1);
      55             :     }
      56           2 :   if (result->imported != 0 && result->imported != 1)
      57             :     {
      58           0 :       fprintf (stderr, "Unexpected number of imported keys %i\n",
      59             :                result->imported);
      60           0 :       exit (1);
      61             :     }
      62           2 :   if (result->imported_rsa != 0)
      63             :     {
      64           0 :       fprintf (stderr, "Unexpected number of imported RSA keys %i\n",
      65             :                result->imported_rsa);
      66           0 :       exit (1);
      67             :     }
      68           2 :   if ((result->imported == 0 && result->unchanged != total)
      69           2 :       || (result->imported == 1 && result->unchanged != total - 1))
      70             :     {
      71           0 :       fprintf (stderr, "Unexpected number of unchanged keys %i\n",
      72             :                result->unchanged);
      73           0 :       exit (1);
      74             :     }
      75           2 :   if (result->new_user_ids != 0)
      76             :     {
      77           0 :       fprintf (stderr, "Unexpected number of new user IDs %i\n",
      78             :                result->new_user_ids);
      79           0 :       exit (1);
      80             :     }
      81           2 :   if (result->new_sub_keys != 0)
      82             :     {
      83           0 :       fprintf (stderr, "Unexpected number of new sub keys %i\n",
      84             :                result->new_sub_keys);
      85           0 :       exit (1);
      86             :     }
      87           2 :   if (result->new_signatures != 0)
      88             :     {
      89           0 :       fprintf (stderr, "Unexpected number of new signatures %i\n",
      90             :                result->new_signatures);
      91           0 :       exit (1);
      92             :     }
      93           2 :   if (result->new_revocations != 0)
      94             :     {
      95           0 :       fprintf (stderr, "Unexpected number of new revocations %i\n",
      96             :                result->new_revocations);
      97           0 :       exit (1);
      98             :     }
      99           2 :   if (result->secret_read != 0)
     100             :     {
     101           0 :       fprintf (stderr, "Unexpected number of secret keys read %i\n",
     102             :                result->secret_read);
     103           0 :       exit (1);
     104             :     }
     105           2 :   if (result->secret_imported != 0)
     106             :     {
     107           0 :       fprintf (stderr, "Unexpected number of secret keys imported %i\n",
     108             :                result->secret_imported);
     109           0 :       exit (1);
     110             :     }
     111           2 :   if (result->secret_unchanged != 0)
     112             :     {
     113           0 :       fprintf (stderr, "Unexpected number of secret keys unchanged %i\n",
     114             :                result->secret_unchanged);
     115           0 :       exit (1);
     116             :     }
     117           2 :   if (result->not_imported != 0)
     118             :     {
     119           0 :       fprintf (stderr, "Unexpected number of secret keys not imported %i\n",
     120             :                result->not_imported);
     121           0 :       exit (1);
     122             :     }
     123             : 
     124             :   {
     125             :     int n;
     126             :     gpgme_import_status_t r;
     127             : 
     128           5 :     for (n=0, r=result->imports; r; r=r->next)
     129           3 :       n++;
     130             : 
     131           2 :     if (n != total_stat)
     132             :     {
     133           0 :       fprintf (stderr, "Unexpected number of status reports\n");
     134           0 :       exit (1);
     135             :     }
     136             :   }
     137           2 : }
     138             : 
     139             : 
     140             : int
     141           1 : main (void)
     142             : {
     143             :   gpgme_ctx_t ctx;
     144             :   gpgme_error_t err;
     145             :   gpgme_data_t in;
     146             :   gpgme_import_result_t result;
     147           1 :   char *cert_1 = make_filename ("cert_dfn_pca01.der");
     148           1 :   char *cert_2 = make_filename ("cert_dfn_pca15.der");
     149             : 
     150           1 :   init_gpgme (GPGME_PROTOCOL_CMS);
     151             : 
     152           1 :   err = gpgme_new (&ctx);
     153           1 :   fail_if_err (err);
     154             : 
     155           1 :   gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
     156             : 
     157           1 :   err = gpgme_data_new_from_file (&in, cert_1, 1);
     158           1 :   free (cert_1);
     159           1 :   fail_if_err (err);
     160             : 
     161           1 :   err = gpgme_op_import (ctx, in);
     162           1 :   fail_if_err (err);
     163           1 :   result = gpgme_op_import_result (ctx);
     164           1 :   check_result (result, "DFA56FB5FC41E3A8921F77AD1622EEFD9152A5AD", 1, 1);
     165           1 :   gpgme_data_release (in);
     166             : 
     167           1 :   err = gpgme_data_new_from_file (&in, cert_2, 1);
     168           1 :   free (cert_2);
     169           1 :   fail_if_err (err);
     170             : 
     171           1 :   err = gpgme_op_import (ctx, in);
     172           1 :   fail_if_err (err);
     173           1 :   result = gpgme_op_import_result (ctx);
     174           1 :   check_result (result, "2C8F3C356AB761CB3674835B792CDA52937F9285", 1, 2);
     175           1 :   gpgme_data_release (in);
     176             : 
     177           1 :   gpgme_release (ctx);
     178           1 :   return 0;
     179             : }

Generated by: LCOV version 1.13