s3/docs: Fix serveral typos.
[Samba.git] / source / torture / t_asn1.c
blob5862742bc12dea7c57460c582b56cae833ca2d40
1 /*
2 * Copyright (C) 2004 by Volker Lendecke
4 * Test harness for asn1_write_*, inspired by Love Hornquist Astrand
5 */
7 #include "includes.h"
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},
21 {NULL, 0, NULL}
24 static int values[] = {0, 127, 128, 256, -128, -129, -1, -255, 255,
25 0x80000000, 0x7fffffff};
27 int main(void)
29 int i = 0;
30 int val;
31 bool ok = True;
33 for (i=0; tests[i].data != NULL; i++) {
34 ASN1_DATA data;
35 DATA_BLOB blob;
37 ZERO_STRUCT(data);
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]);
43 ok = False;
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",
51 values[i]);
52 ok = False;
54 if (val != values[i]) {
55 printf("%d -> ASN -> Int %d\n", values[i], val);
56 ok = False;
60 return ok ? 0 : 1;