LCOV - code coverage report
Current view: top level - tests - Test_tree.c (source / functions) Hit Total Coverage
Test: GNU Libtasn1 Lines: 117 202 57.9 %
Date: 2013-03-24 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 83 124 66.9 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2002-2013 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                 :            : #include "Test_tree_asn1_tab.c"
      38                 :            : 
      39                 :            : #define ACT_NULL       0
      40                 :            : #define ACT_CREATE     1
      41                 :            : #define ACT_DELETE     2
      42                 :            : #define ACT_WRITE      3
      43                 :            : #define ACT_READ       4
      44                 :            : #define ACT_VISIT      5
      45                 :            : #define ACT_ENCODING   6
      46                 :            : #define ACT_DECODING   7
      47                 :            : #define ACT_PRINT_DER  8
      48                 :            : #define ACT_EXPAND_ANY 9
      49                 :            : #define ACT_DECODING_ELEMENT   10
      50                 :            : #define ACT_EXPAND_OCTET       11
      51                 :            : #define ACT_NUMBER_OF_ELEMENTS 12
      52                 :            : #define ACT_DECODING_START_END 13
      53                 :            : #define ACT_READ_DEFINITIONS   14
      54                 :            : #define ACT_READ_TAG_CLASS     15
      55                 :            : #define ACT_OID_2_STRUCTURE    16
      56                 :            : #define ACT_READ_LENGTH        17
      57                 :            : #define ACT_ENCODING_LENGTH    18
      58                 :            : #define ACT_READ_BIT           19
      59                 :            : #define ACT_SET_DER            20
      60                 :            : #define ACT_DELETE_ELEMENT     21
      61                 :            : 
      62                 :            : 
      63                 :            : typedef struct
      64                 :            : {
      65                 :            :   int action;
      66                 :            :   const char *par1;
      67                 :            :   const char *par2;
      68                 :            :   int par3;
      69                 :            :   int errorNumber;
      70                 :            :   int line;
      71                 :            : } test_type;
      72                 :            : 
      73                 :            : 
      74                 :            : test_type test_array[] = {
      75                 :            : 
      76                 :            :   {ACT_DELETE, "", "", 0, ASN1_ELEMENT_NOT_FOUND, __LINE__},
      77                 :            : 
      78                 :            :   /* Test: APPLICATION 30 */
      79                 :            :   {ACT_CREATE, "TEST_TREE.KrbError", 0, 0, ASN1_SUCCESS, __LINE__},
      80                 :            :   {ACT_WRITE, "pvno", "5", 0, ASN1_SUCCESS, __LINE__},
      81                 :            :   {ACT_ENCODING_LENGTH, "", 0, 5, ASN1_MEM_ERROR, __LINE__},
      82                 :            :   {ACT_ENCODING, "", 0, 4, ASN1_MEM_ERROR, __LINE__},
      83                 :            :   {ACT_ENCODING, "", 0, 5, ASN1_SUCCESS, __LINE__},
      84                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
      85                 :            :   {ACT_CREATE, "TEST_TREE.KrbError", 0, 0, ASN1_SUCCESS, __LINE__},
      86                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
      87                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
      88                 :            :   {ACT_DELETE_ELEMENT, "pvno", "", 0, ASN1_SUCCESS, __LINE__},
      89                 :            :   {ACT_DELETE_ELEMENT, "pvno", "", 0, ASN1_ELEMENT_NOT_FOUND, __LINE__},
      90                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
      91                 :            : 
      92                 :            :   /* Test: CHOICE */
      93                 :            :   {ACT_CREATE, "TEST_TREE.CertTemplate", 0, 0, ASN1_SUCCESS, __LINE__},
      94                 :            :   {ACT_WRITE, "version", 0, 0, ASN1_SUCCESS, __LINE__},
      95                 :            :   {ACT_WRITE, "validity", 0, 0, ASN1_SUCCESS, __LINE__},
      96                 :            :   {ACT_WRITE, "issuer", "rdnSequence", 0, ASN1_SUCCESS, __LINE__},
      97                 :            :   {ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
      98                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.3", 0, ASN1_SUCCESS,
      99                 :            :    __LINE__},
     100                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.value",
     101                 :            :    "\x0c\x18\x71\x75\x61\x73\x61\x72\x2e\x6c\x61\x73\x2e\x69\x63\x2e\x75\x6e\x69\x63\x61\x6d\x70\x2e\x62\x72",
     102                 :            :    26, ASN1_SUCCESS, __LINE__},
     103                 :            :   {ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
     104                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.7", 0, ASN1_SUCCESS,
     105                 :            :    __LINE__},
     106                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.value",
     107                 :            :    "\x0c\x08\x43\x61\x6d\x70\x69\x6e\x61\x73", 10, ASN1_SUCCESS, __LINE__},
     108                 :            :   {ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
     109                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.6", 0, ASN1_SUCCESS,
     110                 :            :    __LINE__},
     111                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.value",
     112                 :            :    "\x13\x06\x42\x72\x61\x73\x69\x6c", 8, ASN1_SUCCESS, __LINE__},
     113                 :            :   {ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
     114                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.10", 0, ASN1_SUCCESS,
     115                 :            :    __LINE__},
     116                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.value", "\x0c\x02\x49\x43", 4,
     117                 :            :    ASN1_SUCCESS, __LINE__},
     118                 :            :   {ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
     119                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.11", 0, ASN1_SUCCESS,
     120                 :            :    __LINE__},
     121                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.value", "\x0c\x03\x4c\x41\x53", 5,
     122                 :            :    ASN1_SUCCESS, __LINE__},
     123                 :            :   {ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
     124                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "2.5.4.8", 0, ASN1_SUCCESS,
     125                 :            :    __LINE__},
     126                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.value",
     127                 :            :    "\x0c\x09\x53\x61\x6f\x20\x50\x61\x75\x6c\x6f", 11, ASN1_SUCCESS,
     128                 :            :    __LINE__},
     129                 :            :   {ACT_WRITE, "issuer.rdnSequence", "NEW", 0, ASN1_SUCCESS, __LINE__},
     130                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.type", "1.2.840.113549.1.9.1", 0,
     131                 :            :    ASN1_SUCCESS, __LINE__},
     132                 :            :   {ACT_WRITE, "issuer.rdnSequence.?LAST.value",
     133                 :            :    "\x16\x19\x65\x64\x75\x61\x72\x64\x6f\x40\x6c\x61\x73\x2e\x69\x63\x2e\x75\x6e\x69\x63\x61\x6d\x70\x2e\x62\x72",
     134                 :            :    27, ASN1_SUCCESS, __LINE__},
     135                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     136                 :            :   {ACT_ENCODING_LENGTH, "", 0, 152, ASN1_MEM_ERROR, __LINE__},
     137                 :            :   {ACT_ENCODING, "", 0, 151, ASN1_MEM_ERROR, __LINE__},
     138                 :            :   {ACT_ENCODING, "", 0, 152, ASN1_SUCCESS, __LINE__},
     139                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     140                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     141                 :            :   {ACT_CREATE, "TEST_TREE.CertTemplate", 0, 0, ASN1_SUCCESS, __LINE__},
     142                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     143                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     144                 :            :   {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?1", "", 0, ASN1_SUCCESS,
     145                 :            :    __LINE__},
     146                 :            :   {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?1", "", 0,
     147                 :            :    ASN1_ELEMENT_NOT_FOUND, __LINE__},
     148                 :            :   {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?3", "", 0, ASN1_SUCCESS,
     149                 :            :    __LINE__},
     150                 :            :   {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?5", "", 0, ASN1_SUCCESS,
     151                 :            :    __LINE__},
     152                 :            :   {ACT_DELETE_ELEMENT, "issuer.rdnSequence.?7", "", 0, ASN1_SUCCESS,
     153                 :            :    __LINE__},
     154                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     155                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     156                 :            : 
     157                 :            :   /* Test: Empty sequnces */
     158                 :            :   {ACT_CREATE, "TEST_TREE.sequenceEmpty", 0, 0, ASN1_SUCCESS, __LINE__},
     159                 :            :   {ACT_WRITE, "int1", "1", 0, ASN1_SUCCESS, __LINE__},
     160                 :            :   {ACT_WRITE, "seq1.int", NULL, 0, ASN1_SUCCESS, __LINE__},
     161                 :            :   {ACT_ENCODING_LENGTH, "", 0, 11, ASN1_MEM_ERROR, __LINE__},
     162                 :            :   {ACT_ENCODING, "", 0, 10, ASN1_MEM_ERROR, __LINE__},
     163                 :            :   {ACT_ENCODING, "", 0, 11, ASN1_SUCCESS, __LINE__},
     164                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     165                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     166                 :            :   {ACT_CREATE, "TEST_TREE.sequenceEmpty", 0, 0, ASN1_SUCCESS, __LINE__},
     167                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     168                 :            :   {ACT_DECODING_START_END, "seq1", "START", 5, ASN1_SUCCESS, __LINE__},
     169                 :            :   {ACT_DECODING_START_END, "seq1", "END", 6, ASN1_SUCCESS, __LINE__},
     170                 :            :   {ACT_DECODING_START_END, "set1", "START", 7, ASN1_SUCCESS, __LINE__},
     171                 :            :   {ACT_DECODING_START_END, "set1", "END", 10, ASN1_SUCCESS, __LINE__},
     172                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     173                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     174                 :            : 
     175                 :            :   /* Test: Indefinite Length */
     176                 :            :   {ACT_CREATE, "TEST_TREE.IndefiniteLengthTest", 0, 0, ASN1_SUCCESS,
     177                 :            :    __LINE__},
     178                 :            :   {ACT_WRITE, "int1", "1", 0, ASN1_SUCCESS, __LINE__},
     179                 :            :   {ACT_WRITE, "seq1.int", "2", 0, ASN1_SUCCESS, __LINE__},
     180                 :            :   {ACT_WRITE, "set1", "NEW", 0, ASN1_SUCCESS, __LINE__},
     181                 :            :   {ACT_WRITE, "set1.?LAST", "1.2.3.4", 0, ASN1_SUCCESS, __LINE__},
     182                 :            :   {ACT_WRITE, "set1", "NEW", 0, ASN1_SUCCESS, __LINE__},
     183                 :            :   {ACT_WRITE, "set1.?LAST", "1.2.5.6", 0, ASN1_SUCCESS, __LINE__},
     184                 :            :   {ACT_ENCODING, "", 0, 255, ASN1_SUCCESS, __LINE__},
     185                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     186                 :            :   {ACT_SET_DER,
     187                 :            :    "\x30\x18\xa1\x80\x02\x01\x02\x00\x00\x31\x80\x06\x03\x2a\x03\x04\x06\x03\x2a\x05\x06\x00\x00\x02\x01\x01",
     188                 :            :    0, 26, ASN1_SUCCESS, __LINE__},
     189                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     190                 :            :   {ACT_CREATE, "TEST_TREE.IndefiniteLengthTest", 0, 0, ASN1_SUCCESS,
     191                 :            :    __LINE__},
     192                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     193                 :            :   {ACT_DECODING_START_END, "seq1", "START", 2, ASN1_SUCCESS, __LINE__},
     194                 :            :   {ACT_DECODING_START_END, "seq1", "END", 8, ASN1_SUCCESS, __LINE__},
     195                 :            :   {ACT_DECODING_START_END, "set1", "START", 9, ASN1_SUCCESS, __LINE__},
     196                 :            :   {ACT_DECODING_START_END, "set1", "END", 22, ASN1_SUCCESS, __LINE__},
     197                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     198                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     199                 :            : 
     200                 :            :   /* Test: OID */
     201                 :            :   {ACT_CREATE, "TEST_TREE.OidTest", 0, 0, ASN1_SUCCESS, __LINE__},
     202                 :            :   {ACT_READ_LENGTH, "oid", NULL, 9, ASN1_MEM_ERROR, __LINE__},
     203                 :            :   {ACT_READ, "oid", "2.5.29.2", 9, ASN1_SUCCESS, __LINE__},
     204                 :            :   {ACT_WRITE, "oid", "1.2.3.4", 0, ASN1_SUCCESS, __LINE__},
     205                 :            :   {ACT_WRITE, "oid2", "2.5.29.1", 0, ASN1_SUCCESS, __LINE__},
     206                 :            :   {ACT_WRITE, "oid3", "1.2.29.2", 0, ASN1_SUCCESS, __LINE__},
     207                 :            :   {ACT_ENCODING_LENGTH, "", 0, 7, ASN1_MEM_ERROR, __LINE__},
     208                 :            :   {ACT_ENCODING, "", 0, 6, ASN1_MEM_ERROR, __LINE__},
     209                 :            :   {ACT_ENCODING, "", 0, 7, ASN1_SUCCESS, __LINE__},
     210                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     211                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     212                 :            :   {ACT_CREATE, "TEST_TREE.OidTest", 0, 0, ASN1_SUCCESS, __LINE__},
     213                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     214                 :            :   {ACT_DECODING_START_END, "oid", "START", 2, ASN1_SUCCESS, __LINE__},
     215                 :            :   {ACT_DECODING_START_END, "oid", "END", 6, ASN1_SUCCESS, __LINE__},
     216                 :            :   {ACT_DECODING_START_END, "", "START", 0, ASN1_SUCCESS, __LINE__},
     217                 :            :   {ACT_DECODING_START_END, "", "END", 6, ASN1_SUCCESS, __LINE__},
     218                 :            :   {ACT_READ, "oid2", "2.5.29.1", 9, ASN1_SUCCESS, __LINE__},
     219                 :            :   {ACT_READ, "oid3", "1.2.29.2", 9, ASN1_SUCCESS, __LINE__},
     220                 :            :   {ACT_WRITE, "oid", "1.2.3.4", 0, ASN1_SUCCESS, __LINE__},
     221                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     222                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     223                 :            : 
     224                 :            :   /* Test: ENCODING_LENGTH and READ_LEN */
     225                 :            :   {ACT_CREATE, "TEST_TREE.OidAndTimeTest", 0, 0, ASN1_SUCCESS, __LINE__},
     226                 :            :   {ACT_WRITE, "oid", "1.2.3.4", 0, ASN1_SUCCESS, __LINE__},
     227                 :            :   {ACT_WRITE, "time1", "9801011200Z", 1, ASN1_SUCCESS, __LINE__},
     228                 :            :   {ACT_WRITE, "time2", "2001010112001.12-0700", 1, ASN1_SUCCESS, __LINE__},
     229                 :            :   {ACT_WRITE, "oct", "ABCD", 4, ASN1_SUCCESS, __LINE__},
     230                 :            :   {ACT_WRITE, "bol", "TRUE", 1, ASN1_SUCCESS, __LINE__},
     231                 :            :   {ACT_WRITE, "enum", "2", 0, ASN1_SUCCESS, __LINE__},
     232                 :            :   {ACT_WRITE, "bit", "1\xC0", 10, ASN1_SUCCESS, __LINE__},
     233                 :            :   {ACT_WRITE, "any", "\x30\x01\x01", 3, ASN1_SUCCESS, __LINE__},
     234                 :            :   {ACT_WRITE, "set", "NEW", 0, ASN1_SUCCESS, __LINE__},
     235                 :            :   {ACT_WRITE, "set.?LAST", "10", 0, ASN1_SUCCESS, __LINE__},
     236                 :            :   {ACT_WRITE, "set", "NEW", 0, ASN1_SUCCESS, __LINE__},
     237                 :            :   {ACT_WRITE, "set.?LAST", "1", 0, ASN1_SUCCESS, __LINE__},
     238                 :            :   {ACT_WRITE, "gen", "Prova", 5, ASN1_SUCCESS, __LINE__},
     239                 :            :   {ACT_READ_LENGTH, "oid", NULL, 8, ASN1_MEM_ERROR, __LINE__},
     240                 :            :   {ACT_READ_LENGTH, "time1", NULL, 12, ASN1_MEM_ERROR, __LINE__},
     241                 :            :   {ACT_READ_LENGTH, "time2", NULL, 22, ASN1_MEM_ERROR, __LINE__},
     242                 :            :   {ACT_READ_LENGTH, "oct", NULL, 4, ASN1_MEM_ERROR, __LINE__},
     243                 :            :   {ACT_READ_LENGTH, "bol", NULL, 5, ASN1_MEM_ERROR, __LINE__},
     244                 :            :   {ACT_READ_LENGTH, "enum", NULL, 1, ASN1_MEM_ERROR, __LINE__},
     245                 :            :   {ACT_READ_LENGTH, "any", NULL, 3, ASN1_MEM_ERROR, __LINE__},
     246                 :            :   {ACT_READ_LENGTH, "gen", NULL, 5, ASN1_MEM_ERROR, __LINE__},
     247                 :            :   {ACT_READ_LENGTH, "bit", NULL, 10, ASN1_MEM_ERROR, __LINE__},
     248                 :            :   {ACT_READ_BIT, "bit", "1\xC0", 10, ASN1_SUCCESS, __LINE__},
     249                 :            :   {ACT_ENCODING_LENGTH, "", 0, 79, ASN1_MEM_ERROR, __LINE__},
     250                 :            :   {ACT_ENCODING, "", 0, 78, ASN1_MEM_ERROR, __LINE__},
     251                 :            :   {ACT_ENCODING, "", 0, 79, ASN1_SUCCESS, __LINE__},
     252                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     253                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     254                 :            :   {ACT_CREATE, "TEST_TREE.OidAndTimeTest", 0, 0, ASN1_SUCCESS, __LINE__},
     255                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     256                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     257                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     258                 :            : 
     259                 :            :   /* Test: OID to STRUCTURE */
     260                 :            :   {ACT_OID_2_STRUCTURE, "2.5.29.3", "", 0, ASN1_ELEMENT_NOT_FOUND, __LINE__},
     261                 :            :   {ACT_OID_2_STRUCTURE, "1.2.29.2", "", 0, ASN1_ELEMENT_NOT_FOUND, __LINE__},
     262                 :            :   {ACT_OID_2_STRUCTURE, "2.5.29.2", "anyTest2", 0, ASN1_SUCCESS, __LINE__},
     263                 :            : 
     264                 :            :   /* Test: READ TAG and CLASS */
     265                 :            :   {ACT_CREATE, "TEST_TREE.SequenceTestTag", 0, 0, ASN1_SUCCESS, __LINE__},
     266                 :            :   {ACT_READ_TAG_CLASS, "int", "", 0, ASN1_ELEMENT_NOT_FOUND, __LINE__},
     267                 :            :   {ACT_READ_TAG_CLASS, "int1", "TAG", ASN1_TAG_INTEGER, ASN1_SUCCESS,
     268                 :            :    __LINE__},
     269                 :            :   {ACT_READ_TAG_CLASS, "int1", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS,
     270                 :            :    __LINE__},
     271                 :            :   {ACT_READ_TAG_CLASS, "int2", "TAG", 3, ASN1_SUCCESS, __LINE__},
     272                 :            :   {ACT_READ_TAG_CLASS, "int2", "CLASS", ASN1_CLASS_CONTEXT_SPECIFIC,
     273                 :            :    ASN1_SUCCESS, __LINE__},
     274                 :            :   {ACT_READ_TAG_CLASS, "str1", "TAG", 1, ASN1_SUCCESS, __LINE__},
     275                 :            :   {ACT_READ_TAG_CLASS, "str1", "CLASS", ASN1_CLASS_CONTEXT_SPECIFIC,
     276                 :            :    ASN1_SUCCESS, __LINE__},
     277                 :            :   {ACT_READ_TAG_CLASS, "str2", "TAG", 28, ASN1_SUCCESS, __LINE__},
     278                 :            :   {ACT_READ_TAG_CLASS, "str2", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS,
     279                 :            :    __LINE__},
     280                 :            :   {ACT_READ_TAG_CLASS, "str3", "TAG", 28, ASN1_SUCCESS, __LINE__},
     281                 :            :   {ACT_READ_TAG_CLASS, "str3", "CLASS", ASN1_CLASS_UNIVERSAL, ASN1_SUCCESS,
     282                 :            :    __LINE__},
     283                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     284                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     285                 :            : 
     286                 :            :   /* Test: OBJECT IDENTIFIER  elements */
     287                 :            :   {ACT_CREATE, "TEST_TREE.Sequence1", 0, 0, ASN1_SUCCESS, __LINE__},
     288                 :            :   {ACT_WRITE, "int1", "v2", 0, ASN1_SUCCESS, __LINE__},
     289                 :            :   {ACT_READ, "int1", "\x01", 1, ASN1_SUCCESS, __LINE__},
     290                 :            :   {ACT_WRITE, "int2", "0", 0, ASN1_SUCCESS, __LINE__},
     291                 :            :   {ACT_WRITE, "oct", "\x02\x01\x0a", 3, ASN1_SUCCESS, __LINE__},
     292                 :            :   {ACT_WRITE, "id", "1 2 3 4 5", 0, ASN1_VALUE_NOT_VALID, __LINE__},
     293                 :            :   {ACT_WRITE, "id", "2.5.29.2", 0, ASN1_SUCCESS, __LINE__},
     294                 :            :   {ACT_READ, "id", "2.5.29.2", 9, ASN1_SUCCESS, __LINE__},
     295                 :            :   {ACT_READ_LENGTH, "id", NULL, 9, ASN1_MEM_ERROR, __LINE__},
     296                 :            :   {ACT_WRITE, "any1", "\x02\x01\x05", 3, ASN1_SUCCESS, __LINE__},
     297                 :            :   {ACT_READ_DEFINITIONS, "TEST_TREE.id-anyTest", "2.5.29.1", 9, ASN1_SUCCESS,
     298                 :            :    __LINE__},
     299                 :            :   {ACT_ENCODING_LENGTH, "", 0, 20, ASN1_MEM_ERROR, __LINE__},
     300                 :            :   {ACT_ENCODING, "", 0, 19, ASN1_MEM_ERROR, __LINE__},
     301                 :            :   {ACT_ENCODING, "", 0, 200, ASN1_SUCCESS, __LINE__},
     302                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     303                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     304                 :            :   {ACT_CREATE, "TEST_TREE.Sequence1", 0, 0, ASN1_SUCCESS, __LINE__},
     305                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     306                 :            :   {ACT_DECODING_START_END, "id", "START", 7, ASN1_SUCCESS, __LINE__},
     307                 :            :   {ACT_READ, "id", "2.5.29.2", 9, ASN1_SUCCESS, __LINE__},
     308                 :            :   {ACT_EXPAND_ANY, "", NULL, 0, ASN1_SUCCESS, __LINE__},
     309                 :            :   {ACT_EXPAND_OCTET, "oct", "id", 0, ASN1_SUCCESS, __LINE__},
     310                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     311                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     312                 :            : 
     313                 :            :   /* Test: CHOICE elements */
     314                 :            :   {ACT_CREATE, "TEST_TREE.X520LocalityName", 0, 0, ASN1_SUCCESS, __LINE__},
     315                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     316                 :            :   {ACT_WRITE, "", "teletexString", 0, ASN1_SUCCESS, __LINE__},
     317                 :            :   {ACT_WRITE, "teletexString", "PROVA", 5, ASN1_SUCCESS, __LINE__},
     318                 :            :   {ACT_ENCODING_LENGTH, "", 0, 7, ASN1_MEM_ERROR, __LINE__},
     319                 :            :   {ACT_ENCODING, "", 0, 6, ASN1_MEM_ERROR, __LINE__},
     320                 :            :   {ACT_ENCODING, "", 0, 7, ASN1_SUCCESS, __LINE__},
     321                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     322                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     323                 :            :   {ACT_CREATE, "TEST_TREE.X520LocalityName", 0, 0, ASN1_SUCCESS, __LINE__},
     324                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     325                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     326                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     327                 :            : 
     328                 :            :   /* Test: OPTIONAL elements */
     329                 :            :   {ACT_CREATE, "TEST_TREE.DHParameter", 0, 0, ASN1_SUCCESS, __LINE__},
     330                 :            :   {ACT_WRITE, "prime", "1", 0, ASN1_SUCCESS, __LINE__},
     331                 :            :   {ACT_WRITE, "base", "2", 0, ASN1_SUCCESS, __LINE__},
     332                 :            :   {ACT_WRITE, "privateValueLength", NULL, 0, ASN1_SUCCESS, __LINE__},
     333                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     334                 :            :   {ACT_ENCODING_LENGTH, "", 0, 8, ASN1_MEM_ERROR, __LINE__},
     335                 :            :   {ACT_ENCODING, "", 0, 7, ASN1_MEM_ERROR, __LINE__},
     336                 :            :   {ACT_ENCODING, "", 0, 8, ASN1_SUCCESS, __LINE__},
     337                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     338                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     339                 :            :   {ACT_CREATE, "TEST_TREE.DHParameter", 0, 0, ASN1_SUCCESS, __LINE__},
     340                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     341                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     342                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     343                 :            : 
     344                 :            :   /* Test: Integer */
     345                 :            :   {ACT_CREATE, "TEST_TREE.AnyTest2", 0, 0, ASN1_SUCCESS, __LINE__},
     346                 :            :   {ACT_WRITE, "", "int", 0, ASN1_SUCCESS, __LINE__},
     347                 :            :   {ACT_WRITE, "int", "0", 0, ASN1_SUCCESS, __LINE__},
     348                 :            :   {ACT_ENCODING_LENGTH, "", 0, 3, ASN1_MEM_ERROR, __LINE__},
     349                 :            :   {ACT_ENCODING, "", 0, 2, ASN1_MEM_ERROR, __LINE__},
     350                 :            :   {ACT_ENCODING, "", 0, 3, ASN1_SUCCESS, __LINE__},
     351                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     352                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     353                 :            :   {ACT_WRITE, "int", "-1", 0, ASN1_SUCCESS, __LINE__},
     354                 :            :   {ACT_ENCODING, "", 0, 1024, ASN1_SUCCESS, __LINE__},
     355                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     356                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     357                 :            :   {ACT_WRITE, "int", "1", 0, ASN1_SUCCESS, __LINE__},
     358                 :            :   {ACT_ENCODING, "", 0, 1024, ASN1_SUCCESS, __LINE__},
     359                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     360                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     361                 :            :   {ACT_WRITE, "int", "2000000000", 0, ASN1_SUCCESS, __LINE__},
     362                 :            :   {ACT_ENCODING, "", 0, 1024, ASN1_SUCCESS, __LINE__},
     363                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     364                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     365                 :            :   {ACT_WRITE, "int", "-2000000000", 0, ASN1_SUCCESS, __LINE__},
     366                 :            :   {ACT_ENCODING, "", 0, 1024, ASN1_SUCCESS, __LINE__},
     367                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     368                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     369                 :            :   {ACT_WRITE, "int", "-20000000000", 0, ASN1_SUCCESS, __LINE__},
     370                 :            :   {ACT_ENCODING, "", 0, 1024, ASN1_SUCCESS, __LINE__},
     371                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     372                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     373                 :            :   {ACT_WRITE, "int", "20000000000", 0, ASN1_SUCCESS, __LINE__},
     374                 :            :   {ACT_ENCODING, "", 0, 1024, ASN1_SUCCESS, __LINE__},
     375                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     376                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     377                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     378                 :            : 
     379                 :            :   /* Test: elements without names */
     380                 :            :   {ACT_CREATE, "TEST_TREE.Sequence1", 0, 0, ASN1_SUCCESS, __LINE__},
     381                 :            :   {ACT_WRITE, "int2", "10", 0, ASN1_SUCCESS, __LINE__},
     382                 :            :   {ACT_WRITE, "seq", "NEW", 1, ASN1_SUCCESS, __LINE__},
     383                 :            :   {ACT_WRITE, "seq.?LAST", "1", 0, ASN1_SUCCESS, __LINE__},
     384                 :            :   {ACT_WRITE, "seq", "NEW", 1, ASN1_SUCCESS, __LINE__},
     385                 :            :   {ACT_WRITE, "seq.?LAST", "2", 0, ASN1_SUCCESS, __LINE__},
     386                 :            :   {ACT_WRITE, "any1", NULL, 0, ASN1_SUCCESS, __LINE__},
     387                 :            :   {ACT_NUMBER_OF_ELEMENTS, "seq", "", 2, ASN1_SUCCESS, __LINE__},
     388                 :            :   {ACT_WRITE, "id", "1.2.3.4", 0, ASN1_SUCCESS, __LINE__},
     389                 :            :   {ACT_WRITE, "oct", "\x30\x03\x02\x01\x15", 5, ASN1_SUCCESS, __LINE__},
     390                 :            :   {ACT_ENCODING, "int2", 0, 1024, ASN1_SUCCESS, __LINE__},
     391                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     392                 :            :   {ACT_ENCODING, "seq.?2", 0, 2, ASN1_MEM_ERROR, __LINE__},
     393                 :            :   {ACT_ENCODING, "seq.?2", 0, 3, ASN1_SUCCESS, __LINE__},
     394                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     395                 :            :   {ACT_ENCODING_LENGTH, "", 0, 25, ASN1_MEM_ERROR, __LINE__},
     396                 :            :   {ACT_ENCODING, "", 0, 24, ASN1_MEM_ERROR, __LINE__},
     397                 :            :   {ACT_ENCODING, "", 0, 25, ASN1_SUCCESS, __LINE__},
     398                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     399                 :            :   {ACT_CREATE, "TEST_TREE.Sequence1", 0, 0, ASN1_SUCCESS, __LINE__},
     400                 :            :   {ACT_DECODING_ELEMENT, "int2", 0, 0, ASN1_SUCCESS, __LINE__},
     401                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     402                 :            :   {ACT_READ, "int2", "\x0a", 1, ASN1_SUCCESS, __LINE__},
     403                 :            :   {ACT_READ_LENGTH, "int2", NULL, 1, ASN1_MEM_ERROR, __LINE__},
     404                 :            :   {ACT_CREATE, "TEST_TREE.Sequence1", 0, 0, ASN1_SUCCESS, __LINE__},
     405                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     406                 :            :   {ACT_DECODING_START_END, "seq.?2", "START", 10, ASN1_SUCCESS, __LINE__},
     407                 :            :   {ACT_EXPAND_OCTET, "oct", "id", 0, ASN1_SUCCESS, __LINE__},
     408                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     409                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     410                 :            : 
     411                 :            :   /* Test GeneralString */
     412                 :            :   {ACT_CREATE, "TEST_TREE.Test3", 0, 0, ASN1_SUCCESS, __LINE__},
     413                 :            :   {ACT_WRITE, "a", "1234", 0, ASN1_SUCCESS, __LINE__},
     414                 :            :   {ACT_WRITE, "b", "prova", 5, ASN1_SUCCESS, __LINE__},
     415                 :            :   {ACT_ENCODING_LENGTH, "", 0, 17, ASN1_MEM_ERROR, __LINE__},
     416                 :            :   {ACT_ENCODING, "", 0, 16, ASN1_MEM_ERROR, __LINE__},
     417                 :            :   {ACT_ENCODING, "", 0, 17, ASN1_SUCCESS, __LINE__},
     418                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     419                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     420                 :            :   {ACT_CREATE, "TEST_TREE.Test3", 0, 0, ASN1_SUCCESS, __LINE__},
     421                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     422                 :            :   {ACT_DECODING_ELEMENT, "b", 0, 0, ASN1_SUCCESS, __LINE__},
     423                 :            :   {ACT_READ, "b", "prova", 5, ASN1_SUCCESS, __LINE__},
     424                 :            :   {ACT_READ_LENGTH, "b", NULL, 5, ASN1_MEM_ERROR, __LINE__},
     425                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     426                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     427                 :            : 
     428                 :            :   /* Bug regression test: Empty write on 64-bit platforms */
     429                 :            :   {ACT_CREATE, "TEST_TREE.Checksum", 0, 0, ASN1_SUCCESS, __LINE__},
     430                 :            :   {ACT_WRITE, "checksum", "foo", 0, ASN1_SUCCESS, __LINE__},
     431                 :            :   {ACT_WRITE, "checksum", "", 0, ASN1_SUCCESS, __LINE__},
     432                 :            :   {ACT_ENCODING_LENGTH, "", 0, 4, ASN1_MEM_ERROR, __LINE__},
     433                 :            :   {ACT_ENCODING, "", 0, 3, ASN1_MEM_ERROR, __LINE__},
     434                 :            :   {ACT_ENCODING, "", 0, 4, ASN1_SUCCESS, __LINE__},
     435                 :            :   {ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     436                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     437                 :            :   {ACT_CREATE, "TEST_TREE.Checksum", 0, 0, ASN1_SUCCESS, __LINE__},
     438                 :            :   {ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
     439                 :            :   {ACT_DECODING_ELEMENT, "checksum", 0, 0, ASN1_SUCCESS, __LINE__},
     440                 :            :   {ACT_READ, "checksum", "", 0, ASN1_SUCCESS, __LINE__},
     441                 :            :   {ACT_READ_LENGTH, "checksum", NULL, 0, ASN1_SUCCESS, __LINE__},     /* MEM_FAILURE? */
     442                 :            :   {ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
     443                 :            :   {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
     444                 :            : 
     445                 :            :   /* end */
     446                 :            :   {ACT_NULL}
     447                 :            : 
     448                 :            : };
     449                 :            : 
     450                 :            : 
     451                 :            : #define  error() fprintf(stderr, "Error at line %d\n", __LINE__); exit(1)
     452                 :            : 
     453                 :            : int
     454                 :          1 : main (int argc, char *argv[])
     455                 :            : {
     456                 :            :   int result;
     457                 :          1 :   asn1_node definitions = NULL;
     458                 :          1 :   asn1_node asn1_element = NULL;
     459                 :            :   char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
     460                 :            :   FILE *out;
     461                 :            :   test_type *test;
     462                 :          1 :   int errorCounter = 0, testCounter = 0, der_len;
     463                 :            :   unsigned char value[1024], der[1024];
     464                 :          1 :   int valueLen, tag = 0, class = 0;
     465                 :            :   int k;
     466                 :          1 :   int start, end, verbose = 0;
     467                 :          1 :   const char *str_p = NULL;
     468                 :          1 :   const char *treefile = getenv ("ASN1TREE");
     469                 :            : 
     470         [ -  + ]:          1 :   if (argc > 1)
     471                 :          0 :     verbose = 1;
     472                 :            : 
     473         [ -  + ]:          1 :   if (!treefile)
     474                 :          0 :     treefile = "Test_tree.asn";
     475                 :            : 
     476         [ -  + ]:          1 :   if (verbose != 0)
     477                 :            :     {
     478                 :          0 :       printf ("\n\n/****************************************/\n");
     479                 :          0 :       printf ("/*     Test sequence : Test_tree        */\n");
     480                 :          0 :       printf ("/****************************************/\n\n");
     481                 :          0 :       printf ("ASN1TREE: %s\n", treefile);
     482                 :            :     }
     483                 :            : 
     484                 :            :   /* Check version */
     485         [ -  + ]:          1 :   if (asn1_check_version ("0.2.11") == NULL)
     486                 :          0 :     printf ("\nLibrary version check ERROR:\n actual version: %s\n\n",
     487                 :            :             asn1_check_version (NULL));
     488                 :            : 
     489                 :            :   if (1)
     490                 :          1 :     result = asn1_parser2tree (treefile, &definitions, errorDescription);
     491                 :            :   else
     492                 :            :     result =
     493                 :            :       asn1_array2tree (Test_tree_asn1_tab, &definitions, errorDescription);
     494                 :            : 
     495         [ -  + ]:          1 :   if (result != ASN1_SUCCESS)
     496                 :            :     {
     497                 :          0 :       asn1_perror (result);
     498                 :          0 :       printf ("ErrorDescription = %s\n\n", errorDescription);
     499                 :          0 :       exit (1);
     500                 :            :     }
     501                 :            : 
     502                 :            :   if (1)
     503                 :          1 :     out = stdout;
     504                 :            :   else
     505                 :            :     out = fopen ("Test_tree.out", "w");
     506                 :            : 
     507         [ -  + ]:          1 :   if (out == NULL)
     508                 :            :     {
     509                 :          0 :       printf ("Output file ERROR\n");
     510                 :          0 :       exit (1);
     511                 :            :     }
     512                 :            : 
     513                 :            :   if (0)
     514                 :            :     {
     515                 :            :       asn1_print_structure (out, definitions, "TEST_TREE", ASN1_PRINT_ALL);
     516                 :            :       fprintf (out, "\n");
     517                 :            :     }
     518                 :            : 
     519                 :          1 :   test = test_array;
     520                 :            : 
     521         [ +  + ]:        306 :   while (test->action != ACT_NULL)
     522                 :            :     {
     523                 :        305 :       testCounter++;
     524                 :            : 
     525   [ +  +  +  +  :        305 :       switch (test->action)
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
                   +  - ]
     526                 :            :         {
     527                 :            :         case ACT_CREATE:
     528                 :         27 :           result =
     529                 :         27 :             asn1_create_element (definitions, test->par1, &asn1_element);
     530                 :         27 :           break;
     531                 :            :         case ACT_DELETE:
     532                 :         25 :           result = asn1_delete_structure (&asn1_element);
     533                 :         25 :           break;
     534                 :            :         case ACT_DELETE_ELEMENT:
     535                 :          7 :           result = asn1_delete_element (asn1_element, test->par1);
     536                 :          7 :           break;
     537                 :            :         case ACT_WRITE:
     538 [ +  + ][ -  + ]:         81 :           if ((test->par2) && (!strcmp ("DER", test->par2)))
     539                 :          0 :             result =
     540                 :          0 :               asn1_write_value (asn1_element, test->par1, der, der_len);
     541                 :            :           else
     542                 :         81 :             result =
     543                 :         81 :               asn1_write_value (asn1_element, test->par1, test->par2,
     544                 :            :                                 test->par3);
     545                 :         81 :           break;
     546                 :            :         case ACT_READ:
     547                 :            :         case ACT_READ_BIT:
     548                 :         10 :           valueLen = test->par3;
     549                 :         10 :           result =
     550                 :         10 :             asn1_read_value (asn1_element, test->par1, value, &valueLen);
     551                 :         10 :           break;
     552                 :            :         case ACT_READ_LENGTH:
     553                 :         14 :           valueLen = 0;
     554                 :         14 :           result =
     555                 :         14 :             asn1_read_value (asn1_element, test->par1, NULL, &valueLen);
     556                 :         14 :           break;
     557                 :            :         case ACT_READ_DEFINITIONS:
     558                 :          1 :           valueLen = 1024;
     559                 :          1 :           result =
     560                 :          1 :             asn1_read_value (definitions, test->par1, value, &valueLen);
     561                 :          1 :           break;
     562                 :            :         case ACT_READ_TAG_CLASS:
     563                 :         11 :           result = asn1_read_tag (asn1_element, test->par1, &tag, &class);
     564                 :         11 :           break;
     565                 :            :         case ACT_ENCODING:
     566                 :         34 :           der_len = test->par3;
     567                 :         34 :           result = asn1_der_coding (asn1_element, test->par1, der, &der_len,
     568                 :            :                                     errorDescription);
     569                 :         34 :           break;
     570                 :            :         case ACT_ENCODING_LENGTH:
     571                 :         12 :           der_len = 0;
     572                 :         12 :           result = asn1_der_coding (asn1_element, test->par1, NULL, &der_len,
     573                 :            :                                     errorDescription);
     574                 :         12 :           break;
     575                 :            :         case ACT_DECODING:
     576                 :         12 :           result = asn1_der_decoding (&asn1_element, der, der_len,
     577                 :            :                                       errorDescription);
     578                 :         12 :           break;
     579                 :            :         case ACT_DECODING_ELEMENT:
     580                 :          3 :           result =
     581                 :          3 :             asn1_der_decoding_element (&asn1_element, test->par1, der,
     582                 :            :                                        der_len, errorDescription);
     583                 :          3 :           break;
     584                 :            :         case ACT_DECODING_START_END:
     585                 :         14 :           result =
     586                 :         14 :             asn1_der_decoding_startEnd (asn1_element, der, der_len,
     587                 :            :                                         test->par1, &start, &end);
     588                 :         14 :           break;
     589                 :            :         case ACT_EXPAND_ANY:
     590                 :          1 :           result = asn1_expand_any_defined_by (definitions, &asn1_element);
     591                 :          1 :           break;
     592                 :            :         case ACT_EXPAND_OCTET:
     593                 :          2 :           result =
     594                 :          2 :             asn1_expand_octet_string (definitions, &asn1_element, test->par1,
     595                 :            :                                       test->par2);
     596                 :          2 :           break;
     597                 :            :         case ACT_OID_2_STRUCTURE:
     598                 :          3 :           str_p = asn1_find_structure_from_oid (definitions, test->par1);
     599                 :          3 :           break;
     600                 :            :         case ACT_VISIT:
     601         [ -  + ]:         25 :           if (verbose)
     602                 :            :             {
     603                 :          0 :               asn1_print_structure (out, asn1_element, test->par1,
     604                 :            :                                     test->par3);
     605                 :          0 :               fprintf (out, "\n");
     606                 :            :             }
     607                 :         25 :           result = ASN1_SUCCESS;
     608                 :         25 :           break;
     609                 :            :         case ACT_PRINT_DER:
     610         [ -  + ]:         21 :           if (verbose)
     611                 :            :             {
     612                 :          0 :               printf ("DER encoding len:%i\n", der_len);
     613                 :          0 :               printf ("DER encoding: ");
     614         [ #  # ]:          0 :               for (k = 0; k < der_len; k++)
     615                 :          0 :                 printf ("%02x ", der[k]);
     616                 :          0 :               printf ("\n\n");
     617                 :            :             }
     618                 :         21 :           result = ASN1_SUCCESS;
     619                 :         21 :           break;
     620                 :            :         case ACT_SET_DER:
     621                 :          1 :           der_len = test->par3;
     622                 :          1 :           memcpy (der, test->par1, der_len);
     623                 :          1 :           result = ASN1_SUCCESS;
     624                 :          1 :           break;
     625                 :            :         case ACT_NUMBER_OF_ELEMENTS:
     626                 :          1 :           result =
     627                 :          1 :             asn1_number_of_elements (asn1_element, test->par1, &valueLen);
     628                 :          1 :           break;
     629                 :            :         default:
     630                 :          0 :           break;
     631                 :            :         }
     632                 :            : 
     633                 :            : 
     634   [ +  +  +  +  :        305 :       switch (test->action)
             +  +  +  +  
                      - ]
     635                 :            :         {
     636                 :            :         case ACT_CREATE:
     637                 :            :         case ACT_DELETE:
     638                 :            :         case ACT_DELETE_ELEMENT:
     639                 :            :         case ACT_WRITE:
     640                 :            :         case ACT_VISIT:
     641                 :            :         case ACT_ENCODING:
     642                 :            :         case ACT_DECODING:
     643                 :            :         case ACT_PRINT_DER:
     644                 :            :         case ACT_EXPAND_ANY:
     645                 :            :         case ACT_EXPAND_OCTET:
     646                 :            :         case ACT_SET_DER:
     647         [ -  + ]:        236 :           if (result != test->errorNumber)
     648                 :            :             {
     649                 :          0 :               errorCounter++;
     650                 :          0 :               printf ("ERROR in %d:\n", test->line);
     651                 :          0 :               printf ("  Action %d - %s - %s - %d\n", test->action,
     652                 :            :                       test->par1, test->par2, test->par3);
     653                 :          0 :               printf ("  Error expected: %s\n",
     654                 :            :                       asn1_strerror (test->errorNumber));
     655                 :          0 :               printf ("  Error detected: %s\n\n", asn1_strerror (result));
     656                 :          0 :               error ();
     657                 :            :             }
     658                 :        236 :           break;
     659                 :            :         case ACT_DECODING_ELEMENT:
     660         [ -  + ]:          3 :           if (result != test->errorNumber)
     661                 :            :             {
     662                 :          0 :               errorCounter++;
     663                 :          0 :               printf ("ERROR in %d:\n", test->line);
     664                 :          0 :               printf ("  Action %d - %s - %s - %d\n", test->action,
     665                 :            :                       test->par1, test->par2, test->par3);
     666                 :          0 :               printf ("  Error expected: %s\n",
     667                 :            :                       asn1_strerror (test->errorNumber));
     668                 :          0 :               printf ("  Error detected: %s\n", asn1_strerror (result));
     669                 :          0 :               printf ("  Error description : %s\n\n", errorDescription);
     670                 :          0 :               error ();
     671                 :            :             }
     672                 :          3 :           break;
     673                 :            :         case ACT_NUMBER_OF_ELEMENTS:
     674                 :            :         case ACT_READ_LENGTH:
     675 [ +  - ][ -  + ]:         15 :           if ((result != test->errorNumber) || (valueLen != test->par3))
     676                 :            :             {
     677                 :          0 :               errorCounter++;
     678                 :          0 :               printf ("ERROR in %d:\n", test->line);
     679                 :          0 :               printf ("  Action %d - %s\n", test->action, test->par1);
     680                 :          0 :               printf ("  Error expected: %s - %d\n",
     681                 :            :                       asn1_strerror (test->errorNumber), test->par3);
     682                 :          0 :               printf ("  Error detected: %s - %d\n\n", asn1_strerror (result),
     683                 :            :                       valueLen);
     684                 :          0 :               error ();
     685                 :            :             }
     686                 :         15 :           break;
     687                 :            :         case ACT_ENCODING_LENGTH:
     688 [ +  - ][ -  + ]:         12 :           if ((result != test->errorNumber) || (der_len != test->par3))
     689                 :            :             {
     690                 :          0 :               errorCounter++;
     691                 :          0 :               printf ("ERROR in %d:\n", test->line);
     692                 :          0 :               printf ("  Action %d - %s\n", test->action, test->par1);
     693                 :          0 :               printf ("  Error expected: %s - %d\n",
     694                 :            :                       asn1_strerror (test->errorNumber), test->par3);
     695                 :          0 :               printf ("  Error detected: %s - %d\n\n", asn1_strerror (result),
     696                 :            :                       der_len);
     697                 :          0 :               error ();
     698                 :            :             }
     699                 :         12 :           break;
     700                 :            :         case ACT_OID_2_STRUCTURE:
     701 [ +  + ][ +  - ]:          3 :           if (((test->errorNumber != ASN1_SUCCESS) && (str_p != NULL)) ||
                 [ +  + ]
     702 [ +  - ][ +  + ]:          3 :               ((test->errorNumber == ASN1_SUCCESS) && (str_p == NULL)) ||
     703                 :          3 :               ((test->errorNumber == ASN1_SUCCESS)
     704         [ -  + ]:          1 :                && (strcmp (str_p, test->par2))))
     705                 :            :             {
     706                 :          0 :               errorCounter++;
     707                 :          0 :               printf ("ERROR in %d:\n", test->line);
     708                 :          0 :               printf ("  Action %d - %s\n", test->action, test->par1);
     709                 :          0 :               printf ("  Error expected: %s - %s\n",
     710                 :            :                       asn1_strerror (test->errorNumber), test->par2);
     711                 :          0 :               printf ("  Value detected: %s\n\n", str_p);
     712                 :          0 :               error ();
     713                 :            :             }
     714                 :          3 :           break;
     715                 :            :         case ACT_DECODING_START_END:
     716 [ +  - ][ +  + ]:         14 :           if ((result != test->errorNumber) ||
     717 [ +  - ][ +  + ]:         14 :               ((!strcmp (test->par2, "START")) && (start != test->par3)) ||
     718         [ -  + ]:          6 :               ((!strcmp (test->par2, "END")) && (end != test->par3)))
     719                 :            :             {
     720                 :          0 :               errorCounter++;
     721                 :          0 :               printf ("ERROR in %d:\n", test->line);
     722                 :          0 :               printf ("  Action %d - %s - %d\n", test->action, test->par1,
     723                 :            :                       test->par3);
     724                 :          0 :               printf ("  Error expected: %s - %s - %d\n",
     725                 :            :                       asn1_strerror (test->errorNumber), test->par2,
     726                 :            :                       test->par3);
     727                 :          0 :               printf ("  Error detected: %s - %d - %d\n\n",
     728                 :            :                       asn1_strerror (result), start, end);
     729                 :          0 :               error ();
     730                 :            :             }
     731                 :         14 :           break;
     732                 :            : 
     733                 :            :         case ACT_READ_TAG_CLASS:
     734 [ +  - ][ +  + ]:         11 :           if ((result != test->errorNumber) ||
     735 [ +  - ][ +  + ]:         11 :               ((!strcmp (test->par2, "TAG")) && (tag != test->par3)) ||
     736         [ -  + ]:          5 :               ((!strcmp (test->par2, "CLASS")) && (class != test->par3)))
     737                 :            :             {
     738                 :          0 :               errorCounter++;
     739                 :          0 :               printf ("ERROR in %d:\n", test->line);
     740                 :          0 :               printf ("  Action %d - %s - %d\n", test->action, test->par1,
     741                 :            :                       test->par3);
     742                 :          0 :               printf ("  Error expected: %s - %s - %d\n",
     743                 :            :                       asn1_strerror (test->errorNumber), test->par2,
     744                 :            :                       test->par3);
     745                 :          0 :               printf ("  Error detected: %s - %d - %d\n\n",
     746                 :            :                       asn1_strerror (result), tag, class);
     747                 :          0 :               error ();
     748                 :            :             }
     749                 :            : 
     750                 :         11 :           break;
     751                 :            : 
     752                 :            :         case ACT_READ:
     753                 :            :         case ACT_READ_DEFINITIONS:
     754                 :            :         case ACT_READ_BIT:
     755         [ +  + ]:         11 :           if (test->action == ACT_READ_BIT)
     756                 :            :             {
     757         [ -  + ]:          1 :               if (valueLen % 8 == 0)
     758                 :          0 :                 tag = valueLen / 8;
     759                 :            :               else
     760                 :          1 :                 tag = (valueLen / 8) + 1;
     761         [ -  + ]:          1 :               if (test->par3 % 8 == 0)
     762                 :          0 :                 class = test->par3 / 8;
     763                 :            :               else
     764                 :          1 :                 class = (test->par3 / 8) + 1;
     765                 :            :             }
     766                 :            : 
     767         [ +  + ]:         13 :           for (k = 0; k < class; k++)
     768         [ -  + ]:          2 :             if ((unsigned char) test->par2[k] != value[k])
     769                 :            :               {
     770                 :          0 :                 k = -1;
     771                 :          0 :                 break;
     772                 :            :               }
     773                 :            : 
     774 [ +  - ][ +  - ]:         11 :           if ((result != test->errorNumber) ||
     775         [ -  + ]:         11 :               (valueLen != test->par3) || (k == -1))
     776                 :            :             {
     777                 :          0 :               errorCounter++;
     778                 :          0 :               printf ("ERROR in %d:\n", test->line);
     779                 :          0 :               printf ("  Action %d - %s\n", test->action, test->par1);
     780                 :          0 :               printf ("  Error expected: %s - %d - ",
     781                 :            :                       asn1_strerror (test->errorNumber), test->par3);
     782         [ #  # ]:          0 :               for (k = 0; k < test->par3; k++)
     783                 :          0 :                 printf ("%02x", test->par2[k]);
     784                 :          0 :               printf ("\n  Error detected: %s - %d - ",
     785                 :            :                       asn1_strerror (result), valueLen);
     786         [ #  # ]:          0 :               for (k = 0; k < valueLen; k++)
     787                 :          0 :                 printf ("%02x", value[k]);
     788                 :          0 :               printf ("\n\n");
     789                 :            : 
     790                 :          0 :               error ();
     791                 :            :             }
     792                 :            : 
     793                 :         11 :           break;
     794                 :            :         default:
     795                 :          0 :           break;
     796                 :            :         }
     797                 :            : 
     798                 :        305 :       test++;
     799                 :            :     }
     800                 :            : 
     801                 :            : 
     802         [ -  + ]:          1 :   if (verbose != 0)
     803                 :            :     {
     804                 :          0 :       printf ("Total tests : %d\n", testCounter);
     805                 :          0 :       printf ("Total errors: %d\n", errorCounter);
     806                 :            :     }
     807                 :            : 
     808                 :            :   /* Clear the definition structures */
     809                 :          1 :   asn1_delete_structure (&definitions);
     810                 :            : 
     811                 :            : 
     812         [ -  + ]:          1 :   if (out != stdout)
     813                 :          0 :     fclose (out);
     814                 :            : 
     815         [ -  + ]:          1 :   if (errorCounter > 0)
     816                 :          0 :     return 1;
     817                 :            : 
     818                 :          1 :   exit (0);
     819                 :            : }

Generated by: LCOV version 1.9