add vector length check
[libtasn1.git] / tests / Test_tree.c
blob4270caf17089de5e79cd2065a2fbd8ca7b44c900
1 /*
2 * Copyright (C) 2002 Fabio Fiorina
4 * This file is part of LIBASN1.
6 * LIBASN1 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 2 of the License, or
9 * (at your option) any later version.
11 * LIBASN1 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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 /*****************************************************/
23 /* File: Test_tree.c */
24 /* Description: Test sequences for these functions: */
25 /* asn1_visit_tree, */
26 /* asn1_create_structure, */
27 /* asn1_delete_structure, */
28 /* asn1_write_value, */
29 /* asn1_read_value, */
30 /*****************************************************/
32 #include <stdio.h>
33 #include <string.h>
34 #include "libtasn1.h"
36 #include "Test_tree_asn1_tab.c"
38 #define ACT_NULL 0
39 #define ACT_CREATE 1
40 #define ACT_DELETE 2
41 #define ACT_WRITE 3
42 #define ACT_READ 4
43 #define ACT_VISIT 5
44 #define ACT_ENCODING 6
45 #define ACT_DECODING 7
46 #define ACT_PRINT_DER 8
47 #define ACT_EXPAND_ANY 9
48 #define ACT_DECODING_ELEMENT 10
49 #define ACT_EXPAND_OCTET 11
50 #define ACT_NUMBER_OF_ELEMENTS 12
51 #define ACT_DECODING_START_END 13
52 #define ACT_READ_DEFINITIONS 14
53 #define ACT_READ_TAG_CLASS 15
54 #define ACT_OID_2_STRUCTURE 16
55 #define ACT_READ_LENGTH 17
56 #define ACT_ENCODING_LENGTH 18
59 typedef struct{
60 int action;
61 char *par1;
62 unsigned char *par2;
63 int par3;
64 int errorNumber;
65 } test_type;
68 test_type test_array[]={
70 {ACT_DELETE,"","",0,ASN1_ELEMENT_NOT_FOUND},
72 /* Test: OID to STRUCTURE */
73 {ACT_OID_2_STRUCTURE,"2.5.29.3","",0,ASN1_ELEMENT_NOT_FOUND},
74 {ACT_OID_2_STRUCTURE,"1.2.29.2","",0,ASN1_ELEMENT_NOT_FOUND},
75 {ACT_OID_2_STRUCTURE,"2.5.29.2","anyTest2",0,ASN1_SUCCESS},
77 /* Test: READ TAG and CLASS */
78 {ACT_CREATE,"TEST_TREE.SequenceTestTag",0,0,ASN1_SUCCESS},
79 {ACT_READ_TAG_CLASS,"int","",0,ASN1_ELEMENT_NOT_FOUND},
80 {ACT_READ_TAG_CLASS,"int1","TAG",ASN1_TAG_INTEGER,ASN1_SUCCESS},
81 {ACT_READ_TAG_CLASS,"int1","CLASS",ASN1_CLASS_UNIVERSAL,ASN1_SUCCESS},
82 {ACT_READ_TAG_CLASS,"int2","TAG",3,ASN1_SUCCESS},
83 {ACT_READ_TAG_CLASS,"int2","CLASS",ASN1_CLASS_CONTEXT_SPECIFIC,ASN1_SUCCESS},
84 {ACT_READ_TAG_CLASS,"str1","TAG",1,ASN1_SUCCESS},
85 {ACT_READ_TAG_CLASS,"str1","CLASS",ASN1_CLASS_CONTEXT_SPECIFIC,ASN1_SUCCESS},
86 {ACT_READ_TAG_CLASS,"str2","TAG",28,ASN1_SUCCESS},
87 {ACT_READ_TAG_CLASS,"str2","CLASS",ASN1_CLASS_UNIVERSAL,ASN1_SUCCESS},
88 {ACT_READ_TAG_CLASS,"str3","TAG",28,ASN1_SUCCESS},
89 {ACT_READ_TAG_CLASS,"str3","CLASS",ASN1_CLASS_UNIVERSAL,ASN1_SUCCESS},
90 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
91 {ACT_DELETE,"","",0,ASN1_SUCCESS},
93 /* Test: OBJECT IDENTIFIER elements */
94 {ACT_CREATE,"TEST_TREE.Sequence1",0,0,ASN1_SUCCESS},
95 {ACT_WRITE,"int1","v2",0,ASN1_SUCCESS},
96 {ACT_READ,"int1","\x01",1,ASN1_SUCCESS},
97 {ACT_WRITE,"int2","0",0,ASN1_SUCCESS},
98 {ACT_WRITE,"oct","\x02\x01\x0a",3,ASN1_SUCCESS},
99 {ACT_WRITE,"id","1 2 3 4 5",0,ASN1_VALUE_NOT_VALID},
100 {ACT_WRITE,"id","2.5.29.2",0,ASN1_SUCCESS},
101 {ACT_READ,"id","2.5.29.2",9,ASN1_SUCCESS},
102 {ACT_READ_LENGTH,"id",NULL,9,ASN1_MEM_ERROR},
103 {ACT_WRITE,"any1","\x02\x01\x05",3,ASN1_SUCCESS},
104 {ACT_READ_DEFINITIONS,"TEST_TREE.id-anyTest","2.5.29.1",9,ASN1_SUCCESS},
105 {ACT_ENCODING_LENGTH,"",0,20,ASN1_MEM_ERROR},
106 {ACT_ENCODING,"",0,19,ASN1_MEM_ERROR},
107 {ACT_ENCODING,"",0,200,ASN1_SUCCESS},
108 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
109 {ACT_DELETE,"","",0,ASN1_SUCCESS},
110 {ACT_CREATE,"TEST_TREE.Sequence1",0,0,ASN1_SUCCESS},
111 {ACT_DECODING,0,0,0,ASN1_SUCCESS},
112 {ACT_DECODING_START_END,"id","START",7,ASN1_SUCCESS},
113 {ACT_READ,"id","2.5.29.2",9,ASN1_SUCCESS},
114 {ACT_EXPAND_ANY,"",NULL,0,ASN1_SUCCESS},
115 {ACT_EXPAND_OCTET,"oct","id",0,ASN1_SUCCESS},
116 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
117 {ACT_DELETE,"","",0,ASN1_SUCCESS},
119 /* Test: CHOICE elements */
120 {ACT_CREATE,"TEST_TREE.X520LocalityName",0,0,ASN1_SUCCESS},
121 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
122 {ACT_WRITE,"","teletexString",0,ASN1_SUCCESS},
123 {ACT_WRITE,"teletexString","PROVA",5,ASN1_SUCCESS},
124 {ACT_ENCODING_LENGTH,"",0,7,ASN1_MEM_ERROR},
125 {ACT_ENCODING,"",0,6,ASN1_MEM_ERROR},
126 {ACT_ENCODING,"",0,7,ASN1_SUCCESS},
127 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
128 {ACT_DELETE,"","",0,ASN1_SUCCESS},
129 {ACT_CREATE,"TEST_TREE.X520LocalityName",0,0,ASN1_SUCCESS},
130 {ACT_DECODING,0,0,0,ASN1_SUCCESS},
131 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
132 {ACT_DELETE,"","",0,ASN1_SUCCESS},
134 /* Test: OPTIONAL elements */
135 {ACT_CREATE,"TEST_TREE.DHParameter",0,0,ASN1_SUCCESS},
136 {ACT_WRITE,"prime","1",0,ASN1_SUCCESS},
137 {ACT_WRITE,"base","2",0,ASN1_SUCCESS},
138 {ACT_WRITE,"privateValueLength",NULL,0,ASN1_SUCCESS},
139 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
140 {ACT_ENCODING_LENGTH,"",0,8,ASN1_MEM_ERROR},
141 {ACT_ENCODING,"",0,7,ASN1_MEM_ERROR},
142 {ACT_ENCODING,"",0,8,ASN1_SUCCESS},
143 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
144 {ACT_DELETE,"","",0,ASN1_SUCCESS},
145 {ACT_CREATE,"TEST_TREE.DHParameter",0,0,ASN1_SUCCESS},
146 {ACT_DECODING,0,0,0,ASN1_SUCCESS},
147 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
148 {ACT_DELETE,"","",0,ASN1_SUCCESS},
150 /* Test: Integer */
151 {ACT_CREATE,"TEST_TREE.AnyTest2",0,0,ASN1_SUCCESS},
152 {ACT_WRITE,"","int",0,ASN1_SUCCESS},
153 {ACT_WRITE,"int","0",0,ASN1_SUCCESS},
154 {ACT_ENCODING_LENGTH,"",0,3,ASN1_MEM_ERROR},
155 {ACT_ENCODING,"",0,2,ASN1_MEM_ERROR},
156 {ACT_ENCODING,"",0,3,ASN1_SUCCESS},
157 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
158 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
159 {ACT_WRITE,"int","-1",0,ASN1_SUCCESS},
160 {ACT_ENCODING,"",0,1024,ASN1_SUCCESS},
161 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
162 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
163 {ACT_WRITE,"int","1",0,ASN1_SUCCESS},
164 {ACT_ENCODING,"",0,1024,ASN1_SUCCESS},
165 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
166 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
167 {ACT_WRITE,"int","2000000000",0,ASN1_SUCCESS},
168 {ACT_ENCODING,"",0,1024,ASN1_SUCCESS},
169 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
170 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
171 {ACT_WRITE,"int","-2000000000",0,ASN1_SUCCESS},
172 {ACT_ENCODING,"",0,1024,ASN1_SUCCESS},
173 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
174 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
175 {ACT_WRITE,"int","-20000000000",0,ASN1_SUCCESS},
176 {ACT_ENCODING,"",0,1024,ASN1_SUCCESS},
177 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
178 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
179 {ACT_WRITE,"int","20000000000",0,ASN1_SUCCESS},
180 {ACT_ENCODING,"",0,1024,ASN1_SUCCESS},
181 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
182 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
183 {ACT_DELETE,"","",0,ASN1_SUCCESS},
185 /* Test: elements without names */
186 {ACT_CREATE,"TEST_TREE.Sequence1",0,0,ASN1_SUCCESS},
187 {ACT_WRITE,"int2","10",0,ASN1_SUCCESS},
188 {ACT_WRITE,"seq","NEW",1,ASN1_SUCCESS},
189 {ACT_WRITE,"seq.?LAST","1",0,ASN1_SUCCESS},
190 {ACT_WRITE,"seq","NEW",1,ASN1_SUCCESS},
191 {ACT_WRITE,"seq.?LAST","2",0,ASN1_SUCCESS},
192 {ACT_WRITE,"any1",NULL,0,ASN1_SUCCESS},
193 {ACT_NUMBER_OF_ELEMENTS,"seq","",2,ASN1_SUCCESS},
194 {ACT_WRITE,"id","1.2.3.4",0,ASN1_SUCCESS},
195 {ACT_WRITE,"oct","\x30\x03\x02\x01\x15",5,ASN1_SUCCESS},
196 {ACT_ENCODING,"int2",0,1024,ASN1_SUCCESS},
197 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
198 {ACT_ENCODING,"seq.?2",0,2,ASN1_MEM_ERROR},
199 {ACT_ENCODING,"seq.?2",0,3,ASN1_SUCCESS},
200 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
201 {ACT_ENCODING_LENGTH,"",0,25,ASN1_MEM_ERROR},
202 {ACT_ENCODING,"",0,24,ASN1_MEM_ERROR},
203 {ACT_ENCODING,"",0,25,ASN1_SUCCESS},
204 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
205 {ACT_CREATE,"TEST_TREE.Sequence1",0,0,ASN1_SUCCESS},
206 {ACT_DECODING_ELEMENT,"int2",0,0,ASN1_SUCCESS},
207 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
208 {ACT_READ,"int2","\x0a",1,ASN1_SUCCESS},
209 {ACT_READ_LENGTH,"int2",NULL,1,ASN1_MEM_ERROR},
210 {ACT_CREATE,"TEST_TREE.Sequence1",0,0,ASN1_SUCCESS},
211 {ACT_DECODING,0,0,0,ASN1_SUCCESS},
212 {ACT_DECODING_START_END,"seq.?2","START",10,ASN1_SUCCESS},
213 {ACT_EXPAND_OCTET,"oct","id",0,ASN1_SUCCESS},
214 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
215 {ACT_DELETE,"","",0,ASN1_SUCCESS},
217 /* Test GeneralString */
218 {ACT_CREATE,"TEST_TREE.Test3",0,0,ASN1_SUCCESS},
219 {ACT_WRITE,"a","1234",0,ASN1_SUCCESS},
220 {ACT_WRITE,"b","prova",5,ASN1_SUCCESS},
221 {ACT_ENCODING_LENGTH,"",0,17,ASN1_MEM_ERROR},
222 {ACT_ENCODING,"",0,16,ASN1_MEM_ERROR},
223 {ACT_ENCODING,"",0,17,ASN1_SUCCESS},
224 {ACT_PRINT_DER,0,0,0,ASN1_SUCCESS},
225 {ACT_DELETE,"","",0,ASN1_SUCCESS},
226 {ACT_CREATE,"TEST_TREE.Test3",0,0,ASN1_SUCCESS},
227 {ACT_DECODING,0,0,0,ASN1_SUCCESS},
228 {ACT_DECODING_ELEMENT,"b",0,0,ASN1_SUCCESS},
229 {ACT_READ,"b","prova",5,ASN1_SUCCESS},
230 {ACT_READ_LENGTH,"b",NULL,5,ASN1_MEM_ERROR},
231 {ACT_VISIT,"","",ASN1_PRINT_ALL,ASN1_SUCCESS},
232 {ACT_DELETE,"","",0,ASN1_SUCCESS},
236 /* end */
237 {ACT_NULL}
242 int
243 main(int argc,char *argv[])
245 asn1_retCode result;
246 ASN1_TYPE definitions=ASN1_TYPE_EMPTY;
247 ASN1_TYPE asn1_element=ASN1_TYPE_EMPTY;
248 char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
249 FILE *out;
250 test_type *test;
251 int errorCounter=0,testCounter=0,der_len;
252 unsigned char value[1024],der[1024];
253 int valueLen,tag=0,class=0;
254 int k;
255 int start,end;
257 printf("\n\n/****************************************/\n");
258 printf( "/* Test sequence : Test_tree */\n");
259 printf( "/****************************************/\n\n");
261 /* Check version */
262 if(asn1_check_version("0.2.2")==NULL)
263 printf("\nLibrary version check ERROR:\n actual version: %s\n\n",asn1_check_version(NULL));
265 if(1)
266 result=asn1_parser2tree("Test_tree.asn",&definitions,errorDescription);
267 else
268 result=asn1_array2tree(Test_tree_asn1_tab,&definitions,errorDescription);
270 if(result!=ASN1_SUCCESS){
271 libtasn1_perror(result);
272 printf("ErrorDescription = %s\n\n",errorDescription);
273 exit(1);
276 if(1)
277 out=stdout;
278 else
279 out=fopen("Test_tree.out","w");
281 if(out==NULL){
282 printf("Output file ERROR\n");
283 exit(1);
286 if(0){
287 asn1_print_structure(out,definitions,"TEST_TREE",ASN1_PRINT_ALL);
288 fprintf(out,"\n");
291 test=test_array;
293 while(test->action != ACT_NULL){
294 testCounter++;
296 switch(test->action){
297 case ACT_CREATE:
298 result=asn1_create_element(definitions,test->par1,&asn1_element);
299 break;
300 case ACT_DELETE:
301 result=asn1_delete_structure(&asn1_element);
302 break;
303 case ACT_WRITE:
304 if((test->par2) && (!strcmp("DER",test->par2)))
305 result=asn1_write_value(asn1_element,test->par1,der,der_len);
306 else
307 result=asn1_write_value(asn1_element,test->par1,test->par2,test->par3);
308 break;
309 case ACT_READ:
310 valueLen=test->par3;
311 result=asn1_read_value(asn1_element,test->par1,value,&valueLen);
312 break;
313 case ACT_READ_LENGTH:
314 valueLen=0;
315 result=asn1_read_value(asn1_element,test->par1,NULL,&valueLen);
316 break;
317 case ACT_READ_DEFINITIONS:
318 valueLen=1024;
319 result=asn1_read_value(definitions,test->par1,value,&valueLen);
320 break;
321 case ACT_READ_TAG_CLASS:
322 result=asn1_read_tag(asn1_element,test->par1,&tag,&class);
323 break;
324 case ACT_ENCODING:
325 der_len=test->par3;
326 result=asn1_der_coding(asn1_element,test->par1,der,&der_len,
327 errorDescription);
328 break;
329 case ACT_ENCODING_LENGTH:
330 der_len=0;
331 result=asn1_der_coding(asn1_element,test->par1,NULL,&der_len,
332 errorDescription);
333 break;
334 case ACT_DECODING:
335 result=asn1_der_decoding(&asn1_element,der,der_len,
336 errorDescription);
337 break;
338 case ACT_DECODING_ELEMENT:
339 result=asn1_der_decoding_element(&asn1_element,test->par1,der,der_len,
340 errorDescription);
341 break;
342 case ACT_DECODING_START_END:
343 result=asn1_der_decoding_startEnd(asn1_element,der,der_len,test->par1,
344 &start,&end);
345 break;
346 case ACT_EXPAND_ANY:
347 result=asn1_expand_any_defined_by(definitions,&asn1_element);
348 break;
349 case ACT_EXPAND_OCTET:
350 result=asn1_expand_octet_string(definitions,&asn1_element,test->par1,
351 test->par2);
352 break;
353 case ACT_OID_2_STRUCTURE:
354 result=asn1_find_structure_from_oid(definitions,test->par1,value);
355 break;
356 case ACT_VISIT:
357 asn1_print_structure(out,asn1_element,test->par1,test->par3);
358 fprintf(out,"\n");
359 result=ASN1_SUCCESS;
360 break;
361 case ACT_PRINT_DER:
362 printf("DER encoding len:%i\n",der_len);
363 printf("DER encoding: ");
364 for(k=0;k<der_len;k++)
365 printf("%02x ",der[k]);
366 printf("\n\n");
367 result=ASN1_SUCCESS;
368 break;
369 case ACT_NUMBER_OF_ELEMENTS:
370 result=asn1_number_of_elements(asn1_element,test->par1,&valueLen);
371 break;
372 default:
373 break;
377 switch(test->action){
378 case ACT_CREATE:
379 case ACT_DELETE:
380 case ACT_WRITE:
381 case ACT_VISIT:
382 case ACT_ENCODING:
383 case ACT_DECODING:
384 case ACT_PRINT_DER:
385 case ACT_EXPAND_ANY:
386 case ACT_EXPAND_OCTET:
387 if(result != test->errorNumber){
388 errorCounter++;
389 printf("ERROR N. %d:\n",errorCounter);
390 printf(" Action %d - %s - %s - %d\n",test->action,test->par1,
391 test->par2,test->par3);
392 printf(" Error expected: %s\n",libtasn1_strerror(test->errorNumber));
393 printf(" Error detected: %s\n\n",libtasn1_strerror(result));
395 break;
396 case ACT_DECODING_ELEMENT:
397 if(result != test->errorNumber){
398 errorCounter++;
399 printf("ERROR N. %d:\n",errorCounter);
400 printf(" Action %d - %s - %s - %d\n",test->action,test->par1,
401 test->par2,test->par3);
402 printf(" Error expected: %s\n",libtasn1_strerror(test->errorNumber));
403 printf(" Error detected: %s\n",libtasn1_strerror(result));
404 printf(" Error description : %s\n\n",errorDescription);
406 break;
407 case ACT_NUMBER_OF_ELEMENTS:
408 case ACT_READ_LENGTH:
409 if((result != test->errorNumber) ||
410 (valueLen != test->par3)){
411 errorCounter++;
412 printf("ERROR N. %d:\n",errorCounter);
413 printf(" Action %d - %s\n",test->action,test->par1);
414 printf(" Error expected: %s - %d\n",libtasn1_strerror(test->errorNumber),
415 test->par3);
416 printf(" Error detected: %s - %d\n\n",libtasn1_strerror(result),
417 valueLen);
419 break;
420 case ACT_ENCODING_LENGTH:
421 if((result != test->errorNumber) ||
422 (der_len != test->par3)){
423 errorCounter++;
424 printf("ERROR N. %d:\n",errorCounter);
425 printf(" Action %d - %s\n",test->action,test->par1);
426 printf(" Error expected: %s - %d\n",libtasn1_strerror(test->errorNumber),
427 test->par3);
428 printf(" Error detected: %s - %d\n\n",libtasn1_strerror(result),
429 der_len);
431 break;
432 case ACT_OID_2_STRUCTURE:
433 if((result != test->errorNumber) ||
434 ((result == ASN1_SUCCESS) && (strcmp(value,test->par2)))){
435 errorCounter++;
436 printf("ERROR N. %d:\n",errorCounter);
437 printf(" Action %d - %s\n",test->action,test->par1);
438 printf(" Error expected: %s - %s\n",libtasn1_strerror(test->errorNumber),
439 test->par2);
440 printf("\n Error detected: %s - %s\n\n",libtasn1_strerror(result),
441 value);
443 break;
444 case ACT_DECODING_START_END:
445 if((result != test->errorNumber) ||
446 ((!strcmp(test->par2,"START")) && (start != test->par3)) ||
447 ((!strcmp(test->par2,"END")) && (end != test->par3)) ){
448 errorCounter++;
449 printf("ERROR N. %d:\n",errorCounter);
450 printf(" Action %d - %s - %d\n",test->action,test->par1,
451 test->par3);
452 printf(" Error expected: %s - %s - %d\n",libtasn1_strerror(test->errorNumber),
453 test->par2,test->par3);
454 printf(" Error detected: %s - %d - %d\n\n",libtasn1_strerror(result),
455 start,end);
457 break;
459 case ACT_READ_TAG_CLASS:
460 if((result != test->errorNumber) ||
461 ((!strcmp(test->par2,"TAG")) && (tag != test->par3)) ||
462 ((!strcmp(test->par2,"CLASS")) && (class != test->par3))){
463 errorCounter++;
464 printf("ERROR N. %d:\n",errorCounter);
465 printf(" Action %d - %s - %d\n",test->action,test->par1,
466 test->par3);
467 printf(" Error expected: %s - %s - %d\n",libtasn1_strerror(test->errorNumber),
468 test->par2,test->par3);
469 printf(" Error detected: %s - %d - %d\n\n",libtasn1_strerror(result),
470 tag,class);
473 break;
475 case ACT_READ:
476 case ACT_READ_DEFINITIONS:
477 for(k=0;k<valueLen;k++)
478 if(test->par2[k] != value[k]){
479 k=-1;
480 break;
483 if((result != test->errorNumber) ||
484 (valueLen != test->par3) ||
485 (k == -1)){
486 errorCounter++;
487 printf("ERROR N. %d:\n",errorCounter);
488 printf(" Action %d - %s\n",test->action,test->par1);
489 printf(" Error expected: %s - %d - ",libtasn1_strerror(test->errorNumber),
490 test->par3);
491 for(k=0;k<test->par3;k++)
492 printf("%02x",test->par2[k]);
493 printf("\n Error detected: %s - %d - ",libtasn1_strerror(result),
494 valueLen);
495 for(k=0;k<valueLen;k++)
496 printf("%02x",value[k]);
497 printf("\n\n");
501 break;
502 default:
503 break;
506 test++;
510 printf("Total tests : %d\n",testCounter);
511 printf("Total errors: %d\n",errorCounter);
514 /* Clear the definition structures */
515 asn1_delete_structure(&definitions);
518 if(out != stdout) fclose(out);
520 exit(0);