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) { |
Lev Walkin | ffe79f4 | 2010-10-25 00:10:34 -0700 | [diff] [blame] | 16 | (void)app_key; |
| 17 | assert(buf_offset + size < sizeof(buf)); |
| 18 | memcpy(buf + buf_offset, buffer, size); |
Lev Walkin | ffe79f4 | 2010-10-25 00:10:34 -0700 | [diff] [blame] | 19 | buf_offset += size; |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | static void |
| 24 | check_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 Walkin | 1715b32 | 2013-03-28 04:02:13 -0700 | [diff] [blame] | 43 | printf("%d -> %s == %s\n", eval, buf, buf2); |
Lev Walkin | ffe79f4 | 2010-10-25 00:10:34 -0700 | [diff] [blame] | 44 | assert(0 == strcmp(buf, buf2)); |
Vasil Velichkov | cef21e0 | 2017-10-09 23:40:17 +0300 | [diff] [blame] | 45 | |
| 46 | ASN_STRUCT_FREE(asn_DEF_Enum2, e); |
Lev Walkin | ffe79f4 | 2010-10-25 00:10:34 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | int |
| 50 | main() { |
| 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 | } |