LCOV - code coverage report
Current view: top level - libtasn1-2.x/tests - Test_tree.c (source / functions) Hit Total Coverage
Test: GNU Libtasn1 Lines: 124 187 66.3 %
Date: 2012-09-24 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 80 114 70.2 %

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

Generated by: LCOV version 1.9