source: trunk/server/source3/torture/t_asn1.c

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 1.4 KB
Line 
1/*
2 * Copyright (C) 2004 by Volker Lendecke
3 *
4 * Test harness for asn1_write_*, inspired by Love Hornquist Astrand
5 */
6
7#include "includes.h"
8
9static DATA_BLOB tests[] = {
10 {"\x02\x01\x00", 3, NULL},
11 {"\x02\x01\x7f", 3, NULL},
12 {"\x02\x02\x00\x80", 4, NULL},
13 {"\x02\x02\x01\x00", 4, NULL},
14 {"\x02\x01\x80", 3, NULL},
15 {"\x02\x02\xff\x7f", 4, NULL},
16 {"\x02\x01\xff", 3, NULL},
17 {"\x02\x02\xff\x01", 4, NULL},
18 {"\x02\x02\x00\xff", 4, NULL},
19 {"\x02\x04\x80\x00\x00\x00", 6, NULL},
20 {"\x02\x04\x7f\xff\xff\xff", 6, NULL},
21 {NULL, 0, NULL}
22};
23
24static int values[] = {0, 127, 128, 256, -128, -129, -1, -255, 255,
25 0x80000000, 0x7fffffff};
26
27int main(void)
28{
29 int i = 0;
30 int val;
31 bool ok = True;
32
33 for (i=0; tests[i].data != NULL; i++) {
34 ASN1_DATA *data;
35 DATA_BLOB blob;
36
37 data = asn1_init(talloc_tos());
38 if (!data) {
39 return -1;
40 }
41
42 asn1_write_Integer(data, values[i]);
43
44 if ((data->length != tests[i].length) ||
45 (memcmp(data>data, tests[i].data, data->length) != 0)) {
46 printf("Test for %d failed\n", values[i]);
47 ok = False;
48 }
49
50 blob.data = data->data;
51 blob.length = data->length;
52 asn1_load(data, blob);
53 if (!asn1_read_Integer(data, &val)) {
54 printf("Could not read our own Integer for %d\n",
55 values[i]);
56 ok = False;
57 }
58 if (val != values[i]) {
59 printf("%d -> ASN -> Int %d\n", values[i], val);
60 ok = False;
61 }
62 }
63
64 return ok ? 0 : 1;
65}
Note: See TracBrowser for help on using the repository browser.