LCOV - code coverage report
Current view: top level - libtasn1-2.x/tests - Test_indefinite.c (source / functions) Hit Total Coverage
Test: GNU Libtasn1 Lines: 29 46 63.0 %
Date: 2012-09-24 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 18 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2002-2012 Free Software Foundation, Inc.
       3                 :            :  *
       4                 :            :  * This file is part of LIBTASN1.
       5                 :            :  *
       6                 :            :  * This program is free software: you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation, either version 3 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  */
      20                 :            : 
      21                 :            : 
      22                 :            : /*****************************************************/
      23                 :            : /* File: Test_tree.c                                 */
      24                 :            : /* Description: Test sequences for these functions:  */
      25                 :            : /*     asn1_visit_tree,                              */
      26                 :            : /*     asn1_create_element,                          */
      27                 :            : /*     asn1_delete_structure,                        */
      28                 :            : /*     asn1_write_value,                             */
      29                 :            : /*     asn1_read_value,                              */
      30                 :            : /*****************************************************/
      31                 :            : 
      32                 :            : #include <stdio.h>
      33                 :            : #include <string.h>
      34                 :            : #include <stdlib.h>
      35                 :            : #include "libtasn1.h"
      36                 :            : 
      37                 :            : 
      38                 :            : 
      39                 :            : int
      40                 :          1 : main (int argc, char *argv[])
      41                 :            : {
      42                 :            :   asn1_retCode result;
      43                 :            :   char buffer[10 * 1024];
      44                 :          1 :   ASN1_TYPE definitions = ASN1_TYPE_EMPTY;
      45                 :          1 :   ASN1_TYPE asn1_element = ASN1_TYPE_EMPTY;
      46                 :            :   char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
      47                 :            :   FILE *out, *fd;
      48                 :            :   ssize_t size;
      49                 :          1 :   const char *treefile = getenv ("ASN1PKIX");
      50                 :          1 :   const char *indeffile = getenv ("ASN1INDEF");
      51                 :            : 
      52         [ -  + ]:          1 :   if (!treefile)
      53                 :          0 :     treefile = "pkix.asn";
      54                 :            : 
      55         [ -  + ]:          1 :   if (!indeffile)
      56                 :          0 :     indeffile = "TestIndef.p12";
      57                 :            : 
      58                 :          1 :   printf ("\n\n/****************************************/\n");
      59                 :          1 :   printf ("/*     Test sequence : Test_indefinite  */\n");
      60                 :          1 :   printf ("/****************************************/\n\n");
      61                 :          1 :   printf ("ASN1TREE: %s\n", treefile);
      62                 :            : 
      63                 :            :   /* Check version */
      64         [ -  + ]:          1 :   if (asn1_check_version ("0.2.11") == NULL)
      65                 :          0 :     printf ("\nLibrary version check ERROR:\n actual version: %s\n\n",
      66                 :            :             asn1_check_version (NULL));
      67                 :            : 
      68                 :          1 :   result = asn1_parser2tree (treefile, &definitions, errorDescription);
      69         [ -  + ]:          1 :   if (result != ASN1_SUCCESS)
      70                 :            :     {
      71                 :          0 :       asn1_perror (result);
      72                 :          0 :       printf ("ErrorDescription = %s\n\n", errorDescription);
      73                 :          0 :       exit (1);
      74                 :            :     }
      75                 :            : 
      76                 :          1 :   out = stdout;
      77                 :            : 
      78                 :          1 :   fd = fopen (indeffile, "rb");
      79         [ -  + ]:          1 :   if (fd == NULL)
      80                 :            :     {
      81                 :          0 :       printf ("Cannot read file %s\n", indeffile);
      82                 :          0 :       exit (1);
      83                 :            :     }
      84                 :          1 :   size = fread (buffer, 1, sizeof (buffer), fd);
      85         [ -  + ]:          1 :   if (size <= 0)
      86                 :            :     {
      87                 :          0 :       printf ("Cannot read from file %s\n", indeffile);
      88                 :          0 :       exit (1);
      89                 :            :     }
      90                 :            : 
      91                 :          1 :   fclose (fd);
      92                 :            : 
      93                 :          1 :   result =
      94                 :          1 :     asn1_create_element (definitions, "PKIX1.pkcs-12-PFX", &asn1_element);
      95         [ -  + ]:          1 :   if (result != ASN1_SUCCESS)
      96                 :            :     {
      97                 :          0 :       asn1_perror (result);
      98                 :          0 :       printf ("Cannot create PKCS12 element\n");
      99                 :          0 :       exit (1);
     100                 :            :     }
     101                 :            : 
     102                 :          1 :   result = asn1_der_decoding (&asn1_element, buffer, size, errorDescription);
     103         [ -  + ]:          1 :   if (result != ASN1_SUCCESS)
     104                 :            :     {
     105                 :          0 :       asn1_perror (result);
     106                 :          0 :       printf ("Cannot decode BER data (size %ld)\n", (long) size);
     107                 :          0 :       exit (1);
     108                 :            :     }
     109                 :            : 
     110                 :            :   /* Clear the definition structures */
     111                 :          1 :   asn1_delete_structure (&definitions);
     112                 :          1 :   asn1_delete_structure (&asn1_element);
     113                 :            : 
     114         [ -  + ]:          1 :   if (out != stdout)
     115                 :          0 :     fclose (out);
     116                 :            : 
     117                 :          1 :   exit (0);
     118                 :            : }

Generated by: LCOV version 1.9