LCOV - code coverage report
Current view: top level - tests/gpg - t-encrypt-sym.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 36 94.4 %
Date: 2016-12-01 18:45:36 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* t-encrypt-sym.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 <stdio.h>
      29             : #include <stdlib.h>
      30             : #include <string.h>
      31             : #include <assert.h>
      32             : #include <unistd.h>
      33             : 
      34             : #include <gpgme.h>
      35             : 
      36             : #include "t-support.h"
      37             : 
      38             : 
      39             : int
      40           1 : main (int argc, char *argv[])
      41             : {
      42             :   gpgme_ctx_t ctx;
      43             :   gpgme_error_t err;
      44             :   gpgme_data_t plain, cipher;
      45           1 :   const char *text = "Hallo Leute\n";
      46             :   char *text2;
      47             :   char *p;
      48             :   size_t len;
      49             : 
      50             :   (void)argc;
      51             :   (void)argv;
      52             : 
      53           1 :   init_gpgme (GPGME_PROTOCOL_OpenPGP);
      54             : 
      55           1 :   err = gpgme_new (&ctx);
      56           1 :   fail_if_err (err);
      57           1 :   gpgme_set_armor (ctx, 1);
      58             : 
      59           1 :   p = getenv("GPG_AGENT_INFO");
      60           1 :   if (!(p && strchr (p, ':')))
      61           1 :     gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL);
      62             : 
      63           1 :   err = gpgme_data_new_from_mem (&plain, text, strlen (text), 0);
      64           1 :   fail_if_err (err);
      65             : 
      66           1 :   err = gpgme_data_new (&cipher);
      67           1 :   fail_if_err (err);
      68             : 
      69           1 :   err = gpgme_op_encrypt (ctx, 0, 0, plain, cipher);
      70           1 :   fail_if_err (err);
      71             : 
      72           1 :   fflush (NULL);
      73           1 :   fputs ("Begin Result Encryption:\n", stdout);
      74           1 :   print_data (cipher);
      75           1 :   fputs ("End Result.\n", stdout);
      76             : 
      77           1 :   gpgme_data_seek (cipher, 0, SEEK_SET);
      78             : 
      79           1 :   gpgme_data_release (plain);
      80           1 :   err = gpgme_data_new (&plain);
      81           1 :   fail_if_err (err);
      82             : 
      83           1 :   err = gpgme_op_decrypt (ctx, cipher, plain);
      84           1 :   fail_if_err (err);
      85             : 
      86           1 :   fputs ("Begin Result Decryption:\n", stdout);
      87           1 :   print_data (plain);
      88           1 :   fputs ("End Result.\n", stdout);
      89             : 
      90           1 :   text2 = gpgme_data_release_and_get_mem (plain, &len);
      91           1 :   if (strncmp (text, text2, len))
      92             :     {
      93           0 :       fprintf (stderr, "%s:%d: Wrong plaintext\n", __FILE__, __LINE__);
      94           0 :       exit (1);
      95             :     }
      96             : 
      97           1 :   gpgme_data_release (cipher);
      98           1 :   free (text2);
      99           1 :   gpgme_release (ctx);
     100             : 
     101           1 :   return 0;
     102             : }

Generated by: LCOV version 1.11