/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/

Interface sample;

/* constructed out of constructions */

Record 
{
   /* component is an Array */
   Array <Sequence Optional> Integer(2) r1[2];

   /* component is a Record */
   Record<Set Optional>  
    {
     BitString(17)	   r1;
     ObjectIdentifier(5,2) r2;
    } r2;
    
   /* component is a Union */
   Union <Optional>
   {
    Boolean(1) u1;
    Integer(4) u2;
   } r3;

   Union <Autotag Optional>
   {
    Boolean(1) u1;
    Integer(4) u2;
   } r4;

   Union <Noautotag Optional>
   {
    Boolean(1) u1;
    Integer(4) u2;
   } r5;

} constructed_type;

   Invoke inv_const 52 
      constructed_type;

End;


main(argc,argv)
   int argc;
   char *argv[];
{
   constructed_type constr_s, constr_r;
   Control (sample) inst;

   if (argc != 2)
      exit(1);   

   /* these should not end up being sent 
      because of the Optionals */
   constr_s.r1[0] = 5;
   constr_s.r1[1] = 7;
   constr_s.r2.r1.len = 17;
   constr_s.r2.r1.val[0] = 0x58;
   constr_s.r2.r1.val[1] = 0x58;
   constr_s.r2.r1.val[2] = 0x58;
   constr_s.r2.r2.size = 3;
   constr_s.r2.r2.comp[0] = 2;
   constr_s.r2.r2.comp[1] = 67;
   constr_s.r2.r2.comp[2] = 12345;
   constr_s.r3.tag = 1;
   constr_s.r3.un.u2 = 123;
   constr_s.r4.tag = 1;
   constr_s.r4.un.u2 = 133;
   constr_s.r5.tag = 1;
   constr_s.r5.un.u2 = 143;

   /* these values should not end up being changed 
      because the values above don't get sent */
   constr_r.r1[0] = 4;
   constr_r.r1[1] = 6;
   constr_r.r2.r1.len = 17;
   constr_r.r2.r1.val[0] = 0x57;
   constr_r.r2.r1.val[1] = 0x57;
   constr_r.r2.r1.val[2] = 0x57;
   constr_r.r2.r2.size = 3;
   constr_r.r2.r2.comp[0] = 1;
   constr_r.r2.r2.comp[1] = 66;
   constr_r.r2.r2.comp[2] = 12344;
   constr_r.r3.tag = 1;
   constr_r.r3.un.u2 = 122;
   constr_r.r4.tag = 1;
   constr_r.r4.un.u2 = 132;
   constr_r.r5.tag = 1;
   constr_r.r5.un.u2 = 142;

   constr_s.__r1_absent = 1;
   constr_s.__r2_absent = 1;
   constr_s.__r3_absent = 1;
   constr_s.__r4_absent = 1;
   constr_s.__r5_absent = 1;

/***************** send it out ************************/

   Bind_STUB(inst,argv[1],"w",Asn_1_ber);
   Encode inst
   {
	 constr_s => constructed_type;
   }
   Unbind(inst);

/***************** receive it back ********************/

   Bind_STUB(inst,argv[1],"r",Asn_1_ber);
   Decode inst
      {
	 On constructed_type => (constr_r);
      }
   Unbind(inst);

/***************** report results *********************/

   if (constr_r.__r1_absent != 1) {
      printf("   constr_r.__r1_absent was %d (should be 1)\n",
	      constr_r.__r1_absent);
      exit(1);
   }
   if (constr_r.r1[0] != 4) {
      printf("   constr_r.r1[0] was changed\n");
      exit(1);
   }
   if (constr_r.r1[1] != 6) {
      printf("   constr_r.r1[1] was changed\n");
      exit(1);
   }
   if (constr_r.__r2_absent != 1) {
      printf("   constr_r.__r2_absent was %d (should be 1)\n",
	      constr_r.__r2_absent);
      exit(1);
   }
   if (constr_r.r2.r1.val[0] != 0x57) {
      printf("   constr_r.r2.r1[0] was changed\n");
      exit(1);
   }
   if (constr_r.r2.r1.val[1] != 0x57) {
      printf("   constr_r.r2.r1[1] was changed\n");
      exit(1);
   }
   if (constr_r.r2.r1.val[2] != 0x57) {
      printf("   constr_r.r2.r1[2] was changed\n");
      exit(1);
   }
   if (constr_r.r2.r2.comp[0] != 1) {
      printf("   constr_r.r2.r2.comp[0] was changed\n");
      exit(1);
   }
   if (constr_r.r2.r2.comp[1] != 66) {
      printf("   constr_r.r2.r2.comp[1] was changed\n");
      exit(1);
   }
   if (constr_r.r2.r2.comp[2] != 12344) {
      printf("   constr_r.r2.r2.comp[2] was changed\n");
      exit(1);
   }
   if (constr_r.__r3_absent != 1) {
      printf("   constr_r.__r3_absent was %d (should be 1)\n",
	      constr_r.__r3_absent);
      exit(1);
   }
   if (constr_r.r3.un.u2 != 122) {
      printf("   constr_r.r3.un.u2 was changed\n");
      exit(1);
   }
   if (constr_r.__r4_absent != 1) {
      printf("   constr_r.__r4_absent was %d (should be 1)\n",
	      constr_r.__r4_absent);
      exit(1);
   }
   if (constr_r.r4.un.u2 != 132) {
      printf("   constr_r.r4.un.u2 was changed\n");
      exit(1);
   }
   if (constr_r.__r5_absent != 1) {
      printf("   constr_r.__r5_absent was %d (should be 1)\n",
	      constr_r.__r5_absent);
      exit(1);
   }
   if (constr_r.r5.un.u2 != 142) {
      printf("   constr_r.r5.un.u2 was changed\n");
      exit(1);
   }

   printf("test completed\n");
   return(0);
}
