8 #include <Programming.h>
9 #include <SeqWithMandatory.h>
10 #include <SeqWithOptional.h>
13 main(int ac, char **av) {
15 SeqWithMandatory_t swm;
16 SeqWithOptional_t *swo = 0;
22 (void)ac; /* Unused argument */
23 (void)av; /* Unused argument */
26 * No plans to fill Programming_t up:
27 * just checking whether it compiles or not.
29 memset(&p, 0, sizeof(p));
32 * Construct a dummy sequence:
33 * SeqWithMandatory ::= {
34 * seqOfMan [0] EXPLICIT SEQUENCE OF Error
37 err = calloc(1, sizeof *err);
38 memset(&swm, 0, sizeof swm);
39 OCTET_STRING_fromBuf(&swm.someString, "Oley", 4);
40 ASN_SEQUENCE_ADD(&swm.seqOfMan, err);
43 * Encode the sequence.
45 erv = der_encode_to_buffer(&asn_DEF_SeqWithMandatory,
46 &swm, buf, sizeof buf);
47 assert(erv.encoded > 0);
48 buf[erv.encoded] = '\0';
51 * Try to decode it using a compatible type.
53 drv = ber_decode(0, &asn_DEF_SeqWithOptional, (void **)&swo,
55 assert(drv.code == RC_OK);
56 assert((ssize_t)drv.consumed == erv.encoded);
57 assert(swo->seqOfOpt != 0);
59 xer_fprint(stderr, &asn_DEF_SeqWithOptional, swo);
60 void *tmp = swo->seqOfOpt;
63 erv = der_encode_to_buffer(&asn_DEF_SeqWithOptional,
64 swo, buf, sizeof buf);
65 assert(erv.encoded > 0);
66 buf[erv.encoded] = '\0';
69 ASN_STRUCT_RESET(asn_DEF_SeqWithMandatory, &swm);
70 ASN_STRUCT_FREE(asn_DEF_SeqWithOptional, swo);
73 drv = ber_decode(0, &asn_DEF_SeqWithMandatory, (void **)&swo,
75 assert(drv.code != RC_OK);
76 ASN_STRUCT_FREE(asn_DEF_SeqWithOptional, swo);
78 drv = ber_decode(0, &asn_DEF_SeqWithOptional, (void **)&swo,
80 assert(drv.code == RC_OK);
81 assert((ssize_t)drv.consumed == erv.encoded);
82 assert(swo->seqOfOpt == 0);
84 xer_fprint(stderr, &asn_DEF_SeqWithOptional, swo);
85 ASN_STRUCT_FREE(asn_DEF_SeqWithOptional, swo);