2 * Copyright (C) 2004 by Volker Lendecke
4 * Test harness for asn1_write_*, inspired by Love Hornquist Astrand
9 static 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},
24 static int values[] = {0, 127, 128, 256, -128, -129, -1, -255, 255,
25 0x80000000, 0x7fffffff};
33 for (i=0; tests[i].data != NULL; i++) {
38 asn1_write_Integer(&data, values[i]);
40 if ((data.length != tests[i].length) ||
41 (memcmp(data.data, tests[i].data, data.length) != 0)) {
42 printf("Test for %d failed\n", values[i]);
46 blob.data = data.data;
47 blob.length = data.length;
48 asn1_load(&data, blob);
49 if (!asn1_read_Integer(&data, &val)) {
50 printf("Could not read our own Integer for %d\n",
54 if (val != values[i]) {
55 printf("%d -> ASN -> Int %d\n", values[i], val);