]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/cdump/test/run-01-common-bundle-unbundle.c
cdump: first cut of translation of Tridge's genstruct junkcode.
[ccan-lca-2011.git] / ccan / cdump / test / run-01-common-bundle-unbundle.c
1 #include <ccan/cdump/cdump.h>
2 /* Include the C files directly. */
3 #include <ccan/cdump/cdump.c>
4 #include <ccan/tap/tap.h>
5
6 int main(void)
7 {
8         char c = 'A';
9         unsigned char uc = 66;
10         unsigned u = 0xdeadbeef;
11         int i = -54;
12         time_t t = 1000000;
13         float f = 2.0;
14         double d = 3.0;
15         struct cdump_string *s;
16
17         /* This is how many tests you plan to run */
18         plan_tests(7 * 5);
19
20         s = talloc(NULL, struct cdump_string);
21         s->length = 0;
22         s->s = NULL;
23
24         ok1(cdump_bundle_char(s, &c, 0));
25         ok1(strcmp(s->s, "65") == 0);
26         ok1(s->length == strlen(s->s));
27         ok1(cdump_unbundle_char(NULL, &c, s->s));
28         ok1(c == 'A');
29         s->length = 0;
30         s->s = NULL;
31
32         ok1(cdump_bundle_unsigned_char(s, &uc, 0));
33         ok1(strcmp(s->s, "66") == 0);
34         ok1(s->length == strlen(s->s));
35         ok1(cdump_unbundle_unsigned_char(NULL, &uc, s->s));
36         ok1(uc == 66);
37         s->length = 0;
38         s->s = NULL;
39
40         ok1(cdump_bundle_int(s, &i, 0));
41         ok1(strcmp(s->s, "-54") == 0);
42         ok1(s->length == strlen(s->s));
43         ok1(cdump_unbundle_int(NULL, &i, s->s));
44         ok1(i == -54);
45         s->length = 0;
46         s->s = NULL;
47
48         ok1(cdump_bundle_unsigned(s, &u, 0));
49         ok1(strcmp(s->s, "3735928559") == 0);
50         ok1(s->length == strlen(s->s));
51         ok1(cdump_unbundle_unsigned(NULL, &u, s->s));
52         ok1(u == 0xdeadbeef);
53         s->length = 0;
54         s->s = NULL;
55
56         ok1(cdump_bundle_time_t(s, &t, 0));
57         ok1(strcmp(s->s, "1000000") == 0);
58         ok1(s->length == strlen(s->s));
59         ok1(cdump_unbundle_time_t(NULL, &t, s->s));
60         ok1(t == 1000000);
61         s->length = 0;
62         s->s = NULL;
63
64         ok1(cdump_bundle_double(s, &d, 0));
65         ok1(strcmp(s->s, "3") == 0);
66         ok1(s->length == strlen(s->s));
67         ok1(cdump_unbundle_double(NULL, &d, s->s));
68         ok1(d == 3.0);
69         s->length = 0;
70         s->s = NULL;
71
72         ok1(cdump_bundle_float(s, &f, 0));
73         ok1(strcmp(s->s, "2") == 0);
74         ok1(s->length == strlen(s->s));
75         ok1(cdump_unbundle_float(NULL, &f, s->s));
76         ok1(f == 2.0);
77         s->length = 0;
78         s->s = NULL;
79
80         /* Everything should have been allocated off this, so no leaks. */
81         talloc_free(s);
82
83         /* This exits depending on whether all tests passed */
84         return exit_status();
85 }