summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2014-03-14 15:09:11 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2014-03-14 15:09:11 +0100
commitd84d6567ecdeeb00b2536f3c16bc4f599df23e49 (patch)
tree7b304ed6ad8898161380ae695c74a87968bac734
parent05b093a2ef966fd02a2e93248194778b1caa2d55 (diff)
downloadlibtasn1-d84d6567ecdeeb00b2536f3c16bc4f599df23e49.tar.gz
libtasn1-d84d6567ecdeeb00b2536f3c16bc4f599df23e49.tar.bz2
libtasn1-d84d6567ecdeeb00b2536f3c16bc4f599df23e49.zip
Added self-check for recursive choices.
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/Test_choice.c93
-rw-r--r--tests/choice.asn23
3 files changed, 119 insertions, 3 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 10bdba1..8f8beb8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,7 +23,7 @@ AM_LDFLAGS = -no-install
LDADD = ../lib/libtasn1.la ../gl/libgnu.la
EXTRA_DIST = Test_parser.asn Test_tree.asn Test_tree_asn1_tab.c \
- Test_encoding.asn pkix.asn TestIndef.p12
+ Test_encoding.asn pkix.asn TestIndef.p12 choice.asn
# For crlf.
EXTRA_DIST += crlf.cer
@@ -34,11 +34,11 @@ dist_check_SCRIPTS += threadsafety
MOSTLYCLEANFILES = Test_parser_ERROR.asn
check_PROGRAMS = Test_parser Test_tree Test_encoding Test_indefinite \
- Test_errors Test_simple Test_overflow Test_strings
+ Test_errors Test_simple Test_overflow Test_strings Test_choice
TESTS = Test_parser Test_tree Test_encoding Test_indefinite \
Test_errors Test_simple Test_overflow crlf threadsafety \
- Test_strings
+ Test_strings Test_choice
TESTS_ENVIRONMENT = \
ASN1PARSER=$(srcdir)/Test_parser.asn \
diff --git a/tests/Test_choice.c b/tests/Test_choice.c
new file mode 100644
index 0000000..0c6742e
--- /dev/null
+++ b/tests/Test_choice.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libtasn1.h>
+
+int
+main ()
+{
+ int result = 0;
+ asn1_node definitions = NULL, node1 = NULL, node2 = NULL;
+ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
+ unsigned i;
+
+ char data[1024];
+ int data_size = sizeof (data);
+
+ /* Encode */
+ result = asn1_parser2tree ("choice.asn", &definitions, errorDescription);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+ result = asn1_create_element (definitions, "TEST.Choice0", &node1);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+ result = asn1_write_value (node1, "", "choice1", 1);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+ result = asn1_write_value (node1, "choice1", "choice2", 1);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+ result = asn1_write_value (node1, "choice1.choice2", "int1", 1);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+ result = asn1_write_value (node1, "choice1.choice2.int1", "1234", 0);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+ result = asn1_der_coding (node1, "", data, &data_size, errorDescription);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+ asn1_delete_structure (&node1);
+
+ /* Decode */
+ result = asn1_create_element (definitions, "TEST.Choice0", &node2);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+#if 0
+ printf ("der:");
+ for (i = 0; i < data_size; i++)
+ printf ("%.2x ", (unsigned char) (data[i]));
+ printf ("\n");
+#endif
+
+ result = asn1_der_decoding (&node2, data, data_size, errorDescription);
+ if (result != ASN1_SUCCESS)
+ {
+ printf ("error in %d\n", __LINE__);
+ exit (1);
+ }
+
+ asn1_delete_structure (&node2);
+
+ return 0;
+}
diff --git a/tests/choice.asn b/tests/choice.asn
new file mode 100644
index 0000000..b309204
--- /dev/null
+++ b/tests/choice.asn
@@ -0,0 +1,23 @@
+TEST {}
+DEFINITIONS IMPLICIT TAGS ::=
+BEGIN
+
+Choice2 ::= CHOICE {
+ oct1 OCTET STRING,
+ int1 [3] INTEGER,
+ oct2 OCTET STRING
+}
+
+Choice1 ::= CHOICE {
+ int4 [0] INTEGER,
+ choice2 Choice2,
+ int5 [1] INTEGER
+}
+
+Choice0 ::= CHOICE {
+ int6 [0] INTEGER,
+ choice1 Choice1,
+ int7 [1] INTEGER
+}
+
+END