LCOV - code coverage report
Current view: top level - tests/gpgsm - t-decrypt.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 24 83.3 %
Date: 2016-12-15 13:18:47 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* t-encrypt.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             : #include "t-support.h"
      35             : 
      36             : 
      37             : static const char test_text1[] = "Hallo Leute!\n";
      38             : static const char test_cip1[] =
      39             : "-----BEGIN CMS OBJECT-----\n"
      40             : "MIAGCSqGSIb3DQEHA6CAMIACAQAxggEJMIIBBQIBADBwMGsxCzAJBgNVBAYTAkRF\n"
      41             : "MRMwEQYDVQQHFApE/HNzZWxkb3JmMRYwFAYDVQQKEw1nMTAgQ29kZSBHbWJIMRkw\n"
      42             : "FwYDVQQLExBBZWd5cHRlbiBQcm9qZWN0MRQwEgYDVQQDEwt0ZXN0IGNlcnQgMQIB\n"
      43             : "ADALBgkqhkiG9w0BAQEEgYBOFcOfUtAav+XjKGM1RJtF+8JLkbnu46S3T3709Iok\n"
      44             : "u+Z9dwpOyfHwxXOmjzkSKQSBBxxi6ar+sKjU/KfPIvaMpARwT+NfIVSCZRWIJ27z\n"
      45             : "wbSrav/kcRRDDA0wXV7dHVmSLPUJNCpiFMNZbkYtI+ai15g0PVeDw+szYd9zdsjJ\n"
      46             : "2zCABgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECA8gPQY2NtJToIAECAeoY3MIcz9h\n"
      47             : "BAiiytWtOSmqnwAA\n"
      48             : "-----END CMS OBJECT-----\n";
      49             : 
      50             : 
      51             : int
      52           1 : main (void)
      53             : {
      54             :   gpgme_ctx_t ctx;
      55             :   gpgme_error_t err;
      56             :   gpgme_data_t in, out;
      57             :   size_t len;
      58             :   char *test_text2;
      59             :   gpgme_decrypt_result_t result;
      60             : 
      61           1 :   init_gpgme (GPGME_PROTOCOL_CMS);
      62             : 
      63           1 :   err = gpgme_new (&ctx);
      64           1 :   fail_if_err (err);
      65           1 :   gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
      66             : 
      67           1 :   err = gpgme_data_new_from_mem (&in, test_cip1, strlen (test_cip1), 0);
      68           1 :   fail_if_err (err);
      69             : 
      70           1 :   err = gpgme_data_new (&out);
      71           1 :   fail_if_err (err);
      72             : 
      73           1 :   err = gpgme_op_decrypt (ctx, in, out);
      74           1 :   fail_if_err (err);
      75           1 :   result = gpgme_op_decrypt_result (ctx);
      76           1 :   if (result->unsupported_algorithm)
      77             :     {
      78           0 :       fprintf (stderr, "%s:%i: unsupported algorithm: %s\n",
      79             :                __FILE__, __LINE__, result->unsupported_algorithm);
      80           0 :       exit (1);
      81             :     }
      82           1 :   test_text2 = gpgme_data_release_and_get_mem (out, &len);
      83           1 :   test_text2[len] = '\0';
      84           1 :   if (strcmp (test_text1, test_text2))
      85             :     {
      86           0 :       fprintf (stderr, "%s:%i: data mismatch: expected: \n\"%s\"\n"
      87             :                "got:\n\"%s\"",
      88             :                __FILE__, __LINE__, test_text1, test_text2);
      89           0 :       exit (1);
      90             :     }
      91             : 
      92           1 :   free (test_text2);
      93           1 :   gpgme_data_release (in);
      94           1 :   gpgme_release (ctx);
      95           1 :   return 0;
      96             : }

Generated by: LCOV version 1.12