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
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 \
--- /dev/null
+#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;
+}