00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include <string.h>
00030 #include <stdlib.h>
00031 #include "libtasn1.h"
00032
00033 typedef struct{
00034 int lineNumber;
00035 char *line;
00036 int errorNumber;
00037 char *errorDescription;
00038 } test_type;
00039
00040 char fileCorrectName[]="Test_parser.asn";
00041 char fileErroredName[]="Test_parser_ERROR.asn";
00042
00043 #define _FILE_ "Test_parser_ERROR.asn"
00044
00045 test_type test_array[]={
00046
00047 {5,"TEST_PARSER2 { } DEFINITIONS IMPLICIT TAGS ::= BEGIN int1 ::= INTEGER END",
00048 ASN1_SYNTAX_ERROR,_FILE_":6: parse error near 'TEST_PARSER'"},
00049 {6,"TEST_PARSER { }",ASN1_SUCCESS,""},
00050
00051
00052 {12,"a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 ::= INTEGER",
00053 ASN1_SUCCESS,""},
00054 {12,"a12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 ::= INTEGER",
00055 ASN1_NAME_TOO_LONG,_FILE_":12: name too long (more than 128 characters)"},
00056
00057
00058 {12,"ident1 ::= ident2 ident2 ::= INTEGER",
00059 ASN1_SUCCESS,""},
00060 {12,"ident1 ::= ident2",
00061 ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'ident2' not found"},
00062 {12,"obj1 OBJECT IDENTIFIER ::= {pkix 0 5 4} "
00063 "pkix OBJECT IDENTIFIER ::= {1 2}",
00064 ASN1_SUCCESS,""},
00065 {12,"obj1 OBJECT IDENTIFIER ::= {pkix 0 5 4}",
00066 ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'pkix' not found"},
00067
00068
00069 {14,"int1 INTEGER OPTIONAL,",ASN1_SUCCESS,""},
00070 {14,"int1 INTEGER DEFAULT 1,",ASN1_SUCCESS,""},
00071 {14,"int1 INTEGER DEFAULT -1,",ASN1_SUCCESS,""},
00072 {14,"int1 INTEGER DEFAULT v1,",ASN1_SUCCESS,""},
00073 {14,"int1 [1] INTEGER,",ASN1_SUCCESS,""},
00074 {14,"int1 [1] EXPLICIT INTEGER,",ASN1_SUCCESS,""},
00075 {14,"int1 [1] IMPLICIT INTEGER,",ASN1_SUCCESS,""},
00076 {12,"Integer ::= [1] EXPLICIT INTEGER {v1(-1), v2(1)}",ASN1_SUCCESS,""},
00077 {12,"Integer ::= INTEGER {v1(0), v2}",
00078 ASN1_SYNTAX_ERROR,_FILE_":12: parse error near '}'"},
00079 {12,"Integer ::= INTEGER {v1(0), 1}",
00080 ASN1_SYNTAX_ERROR,_FILE_":12: parse error near '1'"},
00081 {12,"const1 INTEGER ::= -1",ASN1_SUCCESS,""},
00082 {12,"const1 INTEGER ::= 1",ASN1_SUCCESS,""},
00083 {12,"const1 INTEGER ::= v1",
00084 ASN1_SYNTAX_ERROR,_FILE_":12: parse error near 'v1'"},
00085 {16," generic generalstring",
00086 ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'generalstring' not found"},
00087
00088
00089 {20," oid1 OBJECT IDENTIFIER DEFAULT Oid-type",
00090 ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'Oid-type' not found"},
00091 {20," oid1 OBJECT IDENTIFIER DEFAULT 1",
00092 ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier '1' not found"},
00093 {20," oid1 OBJECT IDENTIFIER DEFAULT",
00094 ASN1_SYNTAX_ERROR,_FILE_":21: parse error near '}'"},
00095 {20," oid1 OBJECT IDENTIFIER DEFAULT Oid-type1",
00096 ASN1_SUCCESS,""},
00097
00098
00099
00100 {0}
00101 };
00102
00103 int
00104 readLine(FILE *file,char *line)
00105 {
00106 int c;
00107
00108 while(((c=fgetc(file))!=EOF) && (c!='\n')){
00109 *line=c;
00110 line++;
00111 }
00112
00113 *line=0;
00114
00115 return c;
00116 }
00117
00118
00119 void
00120 createFile(int lineNumber,char *line)
00121 {
00122 FILE *fileIn,*fileOut;
00123 char lineRead[1024];
00124 int fileInLineNumber=0;
00125
00126 fileIn=fopen(fileCorrectName,"r");
00127 fileOut=fopen(fileErroredName,"w");
00128
00129 while(readLine(fileIn,lineRead) != EOF){
00130 fileInLineNumber++;
00131 if(fileInLineNumber==lineNumber)
00132 fprintf(fileOut,"%s\n",line);
00133 else
00134 fprintf(fileOut,"%s\n",lineRead);
00135 }
00136
00137 fclose(fileOut);
00138 fclose(fileIn);
00139 }
00140
00141
00142 int
00143 main(int argc,char *argv[])
00144 {
00145 asn1_retCode result;
00146 ASN1_TYPE definitions=ASN1_TYPE_EMPTY;
00147 char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
00148 test_type *test;
00149 int errorCounter=0,testCounter=0;
00150
00151 printf("\n\n/****************************************/\n");
00152 printf( "/* Test sequence : Test_parser */\n");
00153 printf( "/****************************************/\n\n");
00154
00155
00156 result=asn1_parser2tree(fileCorrectName,&definitions,errorDescription);
00157
00158 if(result!=ASN1_SUCCESS){
00159 printf("File '%s' not correct\n",fileCorrectName);
00160 libtasn1_perror(result);
00161 printf("ErrorDescription = %s\n\n",errorDescription);
00162 exit(1);
00163 }
00164
00165
00166
00167
00168
00169 asn1_delete_structure(&definitions);
00170
00171
00172 test=test_array;
00173
00174 while(test->lineNumber != 0){
00175 testCounter++;
00176
00177 createFile(test->lineNumber,test->line);
00178
00179 result=asn1_parser2tree(fileErroredName,&definitions,errorDescription);
00180 asn1_delete_structure(&definitions);
00181
00182 if((result != test->errorNumber) ||
00183 (strcmp(errorDescription,test->errorDescription))){
00184 errorCounter++;
00185 printf("ERROR N. %d:\n",errorCounter);
00186 printf(" Line %d - %s\n",test->lineNumber,test->line);
00187 printf(" Error expected: %s - %s\n",libtasn1_strerror(test->errorNumber),
00188 test->errorDescription);
00189 printf(" Error detected: %s - %s\n\n",libtasn1_strerror(result),
00190 errorDescription);
00191 }
00192
00193 test++;
00194 }
00195
00196
00197 printf("Total tests : %d\n",testCounter);
00198 printf("Total errors: %d\n",errorCounter);
00199
00200 exit(0);
00201 }
00202
00203
00204
00205
00206
00207
00208