blob: 2c44d628dfa97009ae3da982be1ce1087d309335 [file] [log] [blame]
Lev Walkinffe79f42010-10-25 00:10:34 -07001#undef NDEBUG
2#include <stdio.h>
3#include <stdlib.h>
4#include <sys/types.h>
5#include <string.h>
6#include <assert.h>
7
8#include "Enum2.h"
9#include "xer_decoder.h"
10
11static char buf[4096];
12static int buf_offset;
13
14static int
15buf_writer(const void *buffer, size_t size, void *app_key) {
16 char *b, *bend;
17 (void)app_key;
18 assert(buf_offset + size < sizeof(buf));
19 memcpy(buf + buf_offset, buffer, size);
20 b = buf + buf_offset;
21 bend = b + size;
22 buf_offset += size;
23 return 0;
24}
25
26static void
27check_xer(e_Enum2 eval, char *xer_string) {
28 asn_dec_rval_t rv;
29 char buf2[128];
30 Enum2_t *e = 0;
31 long val;
32
33 rv = xer_decode(0, &asn_DEF_Enum2, (void **)&e,
34 xer_string, strlen(xer_string));
35 assert(rv.code == RC_OK);
36 assert(rv.consumed == strlen(xer_string));
37
38 asn_INTEGER2long(e, &val);
39 printf("%s -> %ld == %d\n", xer_string, val, eval);
40 assert(val == eval);
41
42 buf_offset = 0;
43 xer_encode(&asn_DEF_Enum2, e, XER_F_CANONICAL, buf_writer, 0);
44 buf[buf_offset] = 0;
45 sprintf(buf2, "<Enum2>%s</Enum2>", xer_string);
Lev Walkin1715b322013-03-28 04:02:13 -070046 printf("%d -> %s == %s\n", eval, buf, buf2);
Lev Walkinffe79f42010-10-25 00:10:34 -070047 assert(0 == strcmp(buf, buf2));
48}
49
50int
51main() {
52
53 check_xer(Enum2_red, "<red/>");
54 check_xer(Enum2_green, "<green/>");
55 check_xer(Enum2_blue, "<blue/>");
56 check_xer(Enum2_orange, "<orange/>");
57 check_xer(Enum2_alpha, "<alpha/>");
58 check_xer(Enum2_beta, "<beta/>");
59 check_xer(Enum2_gamma, "<gamma/>");
60
61 return 0;
62}