aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2006-06-17 03:30:43 +0000
committerLev Walkin <vlm@lionet.info>2006-06-17 03:30:43 +0000
commit650da77a4e5f1a2dbfb986a06ceeae93038e0352 (patch)
treee74a308c9763e860ace2111f4358337f4b2aa691
parentc2c3492c86e9dfc59ac3f8671b32d9bbd9231868 (diff)
testing optional component of a sequence
-rw-r--r--asn1c/tests/check-32.c61
-rw-r--r--tests/32-sequence-of-OK.asn110
2 files changed, 70 insertions, 1 deletions
diff --git a/asn1c/tests/check-32.c b/asn1c/tests/check-32.c
index 49ad2d60..0fdbee9f 100644
--- a/asn1c/tests/check-32.c
+++ b/asn1c/tests/check-32.c
@@ -6,19 +6,78 @@
#include <assert.h>
#include <Programming.h>
+#include <SeqWithMandatory.h>
+#include <SeqWithOptional.h>
int
main(int ac, char **av) {
Programming_t p;
+ SeqWithMandatory_t swm;
+ SeqWithOptional_t *swo = 0;
+ Error_t *err;
+ asn_enc_rval_t erv;
+ asn_dec_rval_t drv;
+ char buf[128];
+ size_t bufsize = sizeof(buf);
(void)ac; /* Unused argument */
(void)av; /* Unused argument */
+ /*
+ * No plans to fill Programming_t up:
+ * just checking whether it compiles or not.
+ */
memset(&p, 0, sizeof(p));
/*
- * No plans to fill it up: just checking whether it compiles or not.
+ * Construct a dummy sequence:
+ * SeqWithMandatory ::= {
+ * seqOfMan [0] EXPLICIT SEQUENCE OF Error
+ * }
*/
+ err = calloc(1, sizeof *err);
+ memset(&swm, 0, sizeof swm);
+ OCTET_STRING_fromBuf(&swm.someString, "Oley", 4);
+ ASN_SEQUENCE_ADD(&swm.seqOfMan, err);
+
+ /*
+ * Encode the sequence.
+ */
+ erv = der_encode_to_buffer(&asn_DEF_SeqWithMandatory,
+ &swm, buf, &bufsize);
+ assert(erv.encoded == bufsize);
+
+ /*
+ * Try to decode it using a compatible type.
+ */
+ drv = ber_decode(0, &asn_DEF_SeqWithOptional, (void **)&swo,
+ buf, bufsize);
+ assert(drv.code == RC_OK);
+ assert(drv.consumed == bufsize);
+ assert(swo->seqOfOpt != 0);
+
+ xer_fprint(stderr, &asn_DEF_SeqWithOptional, swo);
+ swo->seqOfOpt = 0;
+
+ bufsize = sizeof(buf);
+ erv = der_encode_to_buffer(&asn_DEF_SeqWithOptional,
+ swo, buf, &bufsize);
+ assert(erv.encoded == bufsize);
+
+ swo = 0;
+ drv = ber_decode(0, &asn_DEF_SeqWithMandatory, (void **)&swo,
+ buf, bufsize);
+ assert(drv.code != RC_OK);
+ swo = 0;
+ drv = ber_decode(0, &asn_DEF_SeqWithOptional, (void **)&swo,
+ buf, bufsize);
+ assert(drv.code == RC_OK);
+ assert(drv.consumed == bufsize);
+ assert(swo->seqOfOpt == 0);
+
+ xer_fprint(stderr, &asn_DEF_SeqWithOptional, swo);
+
+ printf("Finished\n");
return 0;
}
diff --git a/tests/32-sequence-of-OK.asn1 b/tests/32-sequence-of-OK.asn1
index 2b82127f..467e5bd1 100644
--- a/tests/32-sequence-of-OK.asn1
+++ b/tests/32-sequence-of-OK.asn1
@@ -21,4 +21,14 @@ BEGIN
maxSize INTEGER ::= 10
+ SeqWithMandatory ::= SEQUENCE {
+ someString UTF8String,
+ seqOfMan [0] EXPLICIT SEQUENCE OF Error
+ }
+
+ SeqWithOptional ::= SEQUENCE {
+ someString UTF8String,
+ seqOfOpt [0] EXPLICIT SEQUENCE OF Error OPTIONAL
+ }
+
END