blob: 8af08fbab796c2bbbd011cdcb6365b18b2b42593 [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) {
Lev Walkinffe79f42010-10-25 00:10:34 -070016 (void)app_key;
17 assert(buf_offset + size < sizeof(buf));
18 memcpy(buf + buf_offset, buffer, size);
Lev Walkinffe79f42010-10-25 00:10:34 -070019 buf_offset += size;
20 return 0;
21}
22
23static void
24check_xer(e_Enum2 eval, char *xer_string) {
25 asn_dec_rval_t rv;
26 char buf2[128];
27 Enum2_t *e = 0;
28 long val;
29
30 rv = xer_decode(0, &asn_DEF_Enum2, (void **)&e,
31 xer_string, strlen(xer_string));
32 assert(rv.code == RC_OK);
33 assert(rv.consumed == strlen(xer_string));
34
35 asn_INTEGER2long(e, &val);
36 printf("%s -> %ld == %d\n", xer_string, val, eval);
37 assert(val == eval);
38
39 buf_offset = 0;
40 xer_encode(&asn_DEF_Enum2, e, XER_F_CANONICAL, buf_writer, 0);
41 buf[buf_offset] = 0;
42 sprintf(buf2, "<Enum2>%s</Enum2>", xer_string);
Lev Walkin1715b322013-03-28 04:02:13 -070043 printf("%d -> %s == %s\n", eval, buf, buf2);
Lev Walkinffe79f42010-10-25 00:10:34 -070044 assert(0 == strcmp(buf, buf2));
Vasil Velichkovcef21e02017-10-09 23:40:17 +030045
46 ASN_STRUCT_FREE(asn_DEF_Enum2, e);
Lev Walkinffe79f42010-10-25 00:10:34 -070047}
48
49int
50main() {
51
52 check_xer(Enum2_red, "<red/>");
53 check_xer(Enum2_green, "<green/>");
54 check_xer(Enum2_blue, "<blue/>");
55 check_xer(Enum2_orange, "<orange/>");
56 check_xer(Enum2_alpha, "<alpha/>");
57 check_xer(Enum2_beta, "<beta/>");
58 check_xer(Enum2_gamma, "<gamma/>");
59
60 return 0;
61}