summaryrefslogtreecommitdiff
path: root/tests/Test_parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Test_parser.c')
-rw-r--r--tests/Test_parser.c233
1 files changed, 119 insertions, 114 deletions
diff --git a/tests/Test_parser.c b/tests/Test_parser.c
index 398eb31..18d3c39 100644
--- a/tests/Test_parser.c
+++ b/tests/Test_parser.c
@@ -31,70 +31,76 @@
#include <stdlib.h>
#include "libtasn1.h"
-typedef struct{
+typedef struct
+{
int lineNumber;
char *line;
- int errorNumber;
+ int errorNumber;
char *errorDescription;
} test_type;
char *fileCorrectName;
-char fileErroredName[]="Test_parser_ERROR.asn";
+char fileErroredName[] = "Test_parser_ERROR.asn";
#define _FILE_ "Test_parser_ERROR.asn"
-test_type test_array[]={
+test_type test_array[] = {
/* Test DEFINITIONS syntax */
- {5,"TEST_PARSER2 { } DEFINITIONS IMPLICIT TAGS ::= BEGIN int1 ::= INTEGER END",
- ASN1_SYNTAX_ERROR,_FILE_":6: parse error near 'TEST_PARSER'"},
- {6,"TEST_PARSER { }",ASN1_SUCCESS,""},
+ {5,
+ "TEST_PARSER2 { } DEFINITIONS IMPLICIT TAGS ::= BEGIN int1 ::= INTEGER END",
+ ASN1_SYNTAX_ERROR, _FILE_ ":6: parse error near 'TEST_PARSER'"},
+ {6, "TEST_PARSER { }", ASN1_SUCCESS, ""},
/* Test ASN1_MAX_NAME_SIZE (128) */
- {12,"a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 ::= INTEGER",
- ASN1_SUCCESS,""},
- {12,"a12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 ::= INTEGER",
- ASN1_NAME_TOO_LONG,_FILE_":12: name too long (more than 128 characters)"},
+ {12,
+ "a1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 ::= INTEGER",
+ ASN1_SUCCESS, ""},
+ {12,
+ "a12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 ::= INTEGER",
+ ASN1_NAME_TOO_LONG,
+ _FILE_ ":12: name too long (more than 128 characters)"},
/* Test 'check identifier' function */
- {12,"ident1 ::= ident2 ident2 ::= INTEGER",
- ASN1_SUCCESS,""},
- {12,"ident1 ::= ident2",
- ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'ident2' not found"},
- {12,"obj1 OBJECT IDENTIFIER ::= {pkix 0 5 4} "
- "pkix OBJECT IDENTIFIER ::= {1 2}",
- ASN1_SUCCESS,""},
- {12,"obj1 OBJECT IDENTIFIER ::= {pkix 0 5 4}",
- ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'pkix' not found"},
+ {12, "ident1 ::= ident2 ident2 ::= INTEGER",
+ ASN1_SUCCESS, ""},
+ {12, "ident1 ::= ident2",
+ ASN1_IDENTIFIER_NOT_FOUND, _FILE_ ":: identifier 'ident2' not found"},
+ {12, "obj1 OBJECT IDENTIFIER ::= {pkix 0 5 4} "
+ "pkix OBJECT IDENTIFIER ::= {1 2}",
+ ASN1_SUCCESS, ""},
+ {12, "obj1 OBJECT IDENTIFIER ::= {pkix 0 5 4}",
+ ASN1_IDENTIFIER_NOT_FOUND, _FILE_ ":: identifier 'pkix' not found"},
/* Test INTEGER */
- {14,"int1 INTEGER OPTIONAL,",ASN1_SUCCESS,""},
- {14,"int1 INTEGER DEFAULT 1,",ASN1_SUCCESS,""},
- {14,"int1 INTEGER DEFAULT -1,",ASN1_SUCCESS,""},
- {14,"int1 INTEGER DEFAULT v1,",ASN1_SUCCESS,""},
- {14,"int1 [1] INTEGER,",ASN1_SUCCESS,""},
- {14,"int1 [1] EXPLICIT INTEGER,",ASN1_SUCCESS,""},
- {14,"int1 [1] IMPLICIT INTEGER,",ASN1_SUCCESS,""},
- {12,"Integer ::= [1] EXPLICIT INTEGER {v1(-1), v2(1)}",ASN1_SUCCESS,""},
- {12,"Integer ::= INTEGER {v1(0), v2}",
- ASN1_SYNTAX_ERROR,_FILE_":12: parse error near '}'"},
- {12,"Integer ::= INTEGER {v1(0), 1}",
- ASN1_SYNTAX_ERROR,_FILE_":12: parse error near '1'"},
- {12,"const1 INTEGER ::= -1",ASN1_SUCCESS,""},
- {12,"const1 INTEGER ::= 1",ASN1_SUCCESS,""},
- {12,"const1 INTEGER ::= v1",
- ASN1_SYNTAX_ERROR,_FILE_":12: parse error near 'v1'"},
- {16," generic generalstring",
- ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'generalstring' not found"},
+ {14, "int1 INTEGER OPTIONAL,", ASN1_SUCCESS, ""},
+ {14, "int1 INTEGER DEFAULT 1,", ASN1_SUCCESS, ""},
+ {14, "int1 INTEGER DEFAULT -1,", ASN1_SUCCESS, ""},
+ {14, "int1 INTEGER DEFAULT v1,", ASN1_SUCCESS, ""},
+ {14, "int1 [1] INTEGER,", ASN1_SUCCESS, ""},
+ {14, "int1 [1] EXPLICIT INTEGER,", ASN1_SUCCESS, ""},
+ {14, "int1 [1] IMPLICIT INTEGER,", ASN1_SUCCESS, ""},
+ {12, "Integer ::= [1] EXPLICIT INTEGER {v1(-1), v2(1)}", ASN1_SUCCESS, ""},
+ {12, "Integer ::= INTEGER {v1(0), v2}",
+ ASN1_SYNTAX_ERROR, _FILE_ ":12: parse error near '}'"},
+ {12, "Integer ::= INTEGER {v1(0), 1}",
+ ASN1_SYNTAX_ERROR, _FILE_ ":12: parse error near '1'"},
+ {12, "const1 INTEGER ::= -1", ASN1_SUCCESS, ""},
+ {12, "const1 INTEGER ::= 1", ASN1_SUCCESS, ""},
+ {12, "const1 INTEGER ::= v1",
+ ASN1_SYNTAX_ERROR, _FILE_ ":12: parse error near 'v1'"},
+ {16, " generic generalstring",
+ ASN1_IDENTIFIER_NOT_FOUND,
+ _FILE_ ":: identifier 'generalstring' not found"},
/* Test: OID */
- {20," oid1 OBJECT IDENTIFIER DEFAULT Oid-type",
- ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier 'Oid-type' not found"},
- {20," oid1 OBJECT IDENTIFIER DEFAULT 1",
- ASN1_IDENTIFIER_NOT_FOUND,_FILE_":: identifier '1' not found"},
- {20," oid1 OBJECT IDENTIFIER DEFAULT",
- ASN1_SYNTAX_ERROR,_FILE_":21: parse error near '}'"},
- {20," oid1 OBJECT IDENTIFIER DEFAULT Oid-type1",
- ASN1_SUCCESS,""},
+ {20, " oid1 OBJECT IDENTIFIER DEFAULT Oid-type",
+ ASN1_IDENTIFIER_NOT_FOUND, _FILE_ ":: identifier 'Oid-type' not found"},
+ {20, " oid1 OBJECT IDENTIFIER DEFAULT 1",
+ ASN1_IDENTIFIER_NOT_FOUND, _FILE_ ":: identifier '1' not found"},
+ {20, " oid1 OBJECT IDENTIFIER DEFAULT",
+ ASN1_SYNTAX_ERROR, _FILE_ ":21: parse error near '}'"},
+ {20, " oid1 OBJECT IDENTIFIER DEFAULT Oid-type1",
+ ASN1_SUCCESS, ""},
/* end */
@@ -102,115 +108,114 @@ test_type test_array[]={
};
int
-readLine(FILE *file,char *line)
+readLine (FILE * file, char *line)
{
int c;
- while(((c=fgetc(file))!=EOF) && (c!='\n')){
- *line=c;
- line++;
- }
+ while (((c = fgetc (file)) != EOF) && (c != '\n'))
+ {
+ *line = c;
+ line++;
+ }
- *line=0;
+ *line = 0;
return c;
}
void
-createFile(int lineNumber,char *line)
+createFile (int lineNumber, char *line)
{
- FILE *fileIn,*fileOut;
+ FILE *fileIn, *fileOut;
char lineRead[1024];
- int fileInLineNumber=0;
-
- fileIn=fopen(fileCorrectName,"r");
- fileOut=fopen(fileErroredName,"w");
-
- while(readLine(fileIn,lineRead) != EOF){
- fileInLineNumber++;
- if(fileInLineNumber==lineNumber)
- fprintf(fileOut,"%s\n",line);
- else
- fprintf(fileOut,"%s\n",lineRead);
- }
+ int fileInLineNumber = 0;
+
+ fileIn = fopen (fileCorrectName, "r");
+ fileOut = fopen (fileErroredName, "w");
+
+ while (readLine (fileIn, lineRead) != EOF)
+ {
+ fileInLineNumber++;
+ if (fileInLineNumber == lineNumber)
+ fprintf (fileOut, "%s\n", line);
+ else
+ fprintf (fileOut, "%s\n", lineRead);
+ }
- fclose(fileOut);
- fclose(fileIn);
+ fclose (fileOut);
+ fclose (fileIn);
}
-int
-main(int argc,char *argv[])
+int
+main (int argc, char *argv[])
{
asn1_retCode result;
- ASN1_TYPE definitions=ASN1_TYPE_EMPTY;
+ ASN1_TYPE definitions = ASN1_TYPE_EMPTY;
char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
test_type *test;
- int errorCounter=0,testCounter=0;
+ int errorCounter = 0, testCounter = 0;
fileCorrectName = getenv ("ASN1PARSER");
if (!fileCorrectName)
- fileCorrectName="Test_parser.asn";
+ fileCorrectName = "Test_parser.asn";
- printf("\n\n/****************************************/\n");
- printf( "/* Test sequence : Test_parser */\n");
- printf( "/****************************************/\n\n");
- printf("ASN1PARSER: %s\n", fileCorrectName);
+ printf ("\n\n/****************************************/\n");
+ printf ("/* Test sequence : Test_parser */\n");
+ printf ("/****************************************/\n\n");
+ printf ("ASN1PARSER: %s\n", fileCorrectName);
- result=asn1_parser2tree(fileCorrectName,&definitions,errorDescription);
+ result = asn1_parser2tree (fileCorrectName, &definitions, errorDescription);
- if(result!=ASN1_SUCCESS){
- printf("File '%s' not correct\n",fileCorrectName);
- asn1_perror(result);
- printf("ErrorDescription = %s\n\n",errorDescription);
- exit(1);
- }
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("File '%s' not correct\n", fileCorrectName);
+ asn1_perror (result);
+ printf ("ErrorDescription = %s\n\n", errorDescription);
+ exit (1);
+ }
/* Only for Test */
/* asn1_visit_tree(stdout,definitions,"TEST_PARSER",ASN1_PRINT_ALL); */
/* Clear the definitions structures */
- asn1_delete_structure(&definitions);
+ asn1_delete_structure (&definitions);
+
+ test = test_array;
- test=test_array;
+ while (test->lineNumber != 0)
+ {
+ testCounter++;
- while(test->lineNumber != 0){
- testCounter++;
+ createFile (test->lineNumber, test->line);
- createFile(test->lineNumber,test->line);
+ result =
+ asn1_parser2tree (fileErroredName, &definitions, errorDescription);
+ asn1_delete_structure (&definitions);
- result=asn1_parser2tree(fileErroredName,&definitions,errorDescription);
- asn1_delete_structure(&definitions);
+ if ((result != test->errorNumber) ||
+ (strcmp (errorDescription, test->errorDescription)))
+ {
+ errorCounter++;
+ printf ("ERROR N. %d:\n", errorCounter);
+ printf (" Line %d - %s\n", test->lineNumber, test->line);
+ printf (" Error expected: %s - %s\n",
+ asn1_strerror (test->errorNumber), test->errorDescription);
+ printf (" Error detected: %s - %s\n\n", asn1_strerror (result),
+ errorDescription);
+ }
- if((result != test->errorNumber) ||
- (strcmp(errorDescription,test->errorDescription))){
- errorCounter++;
- printf("ERROR N. %d:\n",errorCounter);
- printf(" Line %d - %s\n",test->lineNumber,test->line);
- printf(" Error expected: %s - %s\n",asn1_strerror(test->errorNumber),
- test->errorDescription);
- printf(" Error detected: %s - %s\n\n",asn1_strerror(result),
- errorDescription);
+ test++;
}
-
- test++;
- }
- printf("Total tests : %d\n",testCounter);
- printf("Total errors: %d\n",errorCounter);
+ printf ("Total tests : %d\n", testCounter);
+ printf ("Total errors: %d\n", errorCounter);
- if(errorCounter > 0)
+ if (errorCounter > 0)
return 1;
- exit(0);
+ exit (0);
}
-
-
-
-
-
-
-