Lev Walkin | ffe79f4 | 2010-10-25 00:10:34 -0700 | [diff] [blame] | 1 | #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 | |
| 11 | static char buf[4096]; |
| 12 | static int buf_offset; |
| 13 | |
| 14 | static int |
| 15 | buf_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 | |
| 26 | static void |
| 27 | check_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 Walkin | 1715b32 | 2013-03-28 04:02:13 -0700 | [diff] [blame] | 46 | printf("%d -> %s == %s\n", eval, buf, buf2); |
Lev Walkin | ffe79f4 | 2010-10-25 00:10:34 -0700 | [diff] [blame] | 47 | assert(0 == strcmp(buf, buf2)); |
| 48 | } |
| 49 | |
| 50 | int |
| 51 | main() { |
| 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 | } |