torture/t_asn1.c

説明を見る。
00001 /*
00002  * Copyright (C) 2004 by Volker Lendecke
00003  *
00004  * Test harness for asn1_write_*, inspired by Love Hornquist Astrand
00005  */
00006 
00007 #include "includes.h"
00008 
00009 static DATA_BLOB tests[] = {
00010         {"\x02\x01\x00", 3, NULL},
00011         {"\x02\x01\x7f", 3, NULL},
00012         {"\x02\x02\x00\x80", 4, NULL},
00013         {"\x02\x02\x01\x00", 4, NULL},
00014         {"\x02\x01\x80", 3, NULL},
00015         {"\x02\x02\xff\x7f", 4, NULL},
00016         {"\x02\x01\xff", 3, NULL},
00017         {"\x02\x02\xff\x01", 4, NULL},
00018         {"\x02\x02\x00\xff", 4, NULL},
00019         {"\x02\x04\x80\x00\x00\x00", 6, NULL},
00020         {"\x02\x04\x7f\xff\xff\xff", 6, NULL},
00021         {NULL, 0, NULL}
00022 };
00023 
00024 static int values[] = {0, 127, 128, 256, -128, -129, -1, -255, 255,
00025                        0x80000000, 0x7fffffff};
00026 
00027 int main(void)
00028 {
00029         int i = 0;
00030         int val;
00031         BOOL ok = True;
00032 
00033         for (i=0; tests[i].data != NULL; i++) {
00034                 ASN1_DATA data;
00035                 DATA_BLOB blob;
00036 
00037                 ZERO_STRUCT(data);
00038                 asn1_write_Integer(&data, values[i]);
00039 
00040                 if ((data.length != tests[i].length) ||
00041                     (memcmp(data.data, tests[i].data, data.length) != 0)) {
00042                         printf("Test for %d failed\n", values[i]);
00043                         ok = False;
00044                 }
00045 
00046                 blob.data = data.data;
00047                 blob.length = data.length;
00048                 asn1_load(&data, blob);
00049                 if (!asn1_read_Integer(&data, &val)) {
00050                         printf("Could not read our own Integer for %d\n",
00051                                values[i]);
00052                         ok = False;
00053                 }
00054                 if (val != values[i]) {
00055                         printf("%d -> ASN -> Int %d\n", values[i], val);
00056                         ok = False;
00057                 }
00058         }
00059 
00060         return ok ? 0 : 1;
00061 }

Sambaに対してSat Aug 29 21:23:27 2009に生成されました。  doxygen 1.4.7