/*****************************************************************/
/**                                                             **/
/**             (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;

    Real(20,5) 			Real20_5type;
    BitString(17) 		BitString17type;
    ObjectIdentifier(5,2) 	ObjectIdentifier5_2type;
    Boolean(1) 			Boolean1type;
    Integer(4) 			Integer4type;
    OctetString(10)		OctetString10type;
    Enumerated(4) 		Enumerated4type;
    Null	 		Nulltype;
    IA5String(30) 		IA5String30type;

    Record 
    {
       Real(20,5) 		<Optional 1.23 Default 4.56>	real20_5r1;
       BitString(17) 		<Optional 01011000010110000 
				 Default 10101000101010001>	bs17r2;
       ObjectIdentifier(5,2) 	<Optional 2.67.12345 
				 Default 4.5.6>			oid5_2r3;
       Boolean(1) 		<Optional False Default True>	bool1r4;
       Integer(4) 		<Optional 123 Default 456>	int4r5;
       OctetString(10)		<Optional 0x5A5A5A5A5A5A5A5A5A5A  
				 Default 0x9ab>			os10r6;
       Enumerated(4) 		<Optional 345 Default 678>	en4r7;
       Null			<Optional >			nulr8;
       IA5String(30) 		<Optional "hi" Default "hello">	ia5_30r9;
    } rectype;

   Invoke ike 52 Integer(2);

End;


main(argc,argv)
   int argc;
   char *argv[];
{
   rectype rec_s, rec_r;
   Data (sample) inst;

   int i;
   int l1,l2;

   Real20_5type real20_5default = 4.56;
   static BitString17type bs17default = {17, {0xa8,0xa8,0x80} };
   static ObjectIdentifier5_2type oid5_2default = {3,{4,5,6}};
   Boolean1type bool1default = 1;
   Integer4type int4default = 456;
   static OctetString10type os10default = { 2, {0x9a,0xb0} };
   Enumerated4type en4default = 678;
   static IA5String30type ia5_30default = { 5, "hello"};

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

   rec_s.real20_5r1 = 1.23;
   rec_s.bs17r2.len = 17;
   rec_s.bs17r2.val[0] = 0x58;
   rec_s.bs17r2.val[1] = 0x58;
   rec_s.bs17r2.val[2] = 0x58;
   rec_s.oid5_2r3.size = 3;
   rec_s.oid5_2r3.comp[0] = 2;
   rec_s.oid5_2r3.comp[1] = 67;
   rec_s.oid5_2r3.comp[2] = 12345;
   rec_s.bool1r4 = 0;
   rec_s.int4r5 = 123;
   memset(rec_s.os10r6.val,0x5A,10);
   rec_s.os10r6.len = 10;
   rec_s.en4r7= 345;
   /* don't set rec_s.nulr8 */
   rec_s.__nulr8_absent= 1;
   rec_s.ia5_30r9.len = 2;
   memcpy(rec_s.ia5_30r9.val,"hi",2);


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

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

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

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

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

   if (real20_5default != rec_r.real20_5r1) {
      printf("   rec_r.real20_5r1 value was bad\n");
      exit(1);
   }
   if (!__ROr_cmpP_BitString(&bs17default,&rec_r.bs17r2,(l1=17,&l1) ,0)) {
      printf("   rec_r.bs17r2 value was bad\n");
      exit(1);
   }
   if (!__ROr_cmpP_ObjectIdentifier(&oid5_2default,&(rec_r.oid5_2r3),(l1=5,&l1) ,(l2=2,&l2))) {
      printf("   rec_r.oid5_2r3 value was bad\n");
      exit(1);
   }
   if (!__ROr_cmpP_Boolean(&bool1default, 
			   &(rec_r.bool1r4),
			   (l1=1,&l1) ,0)) {
      printf("   rec_r.bool1r4 value was bad\n");
      exit(1);
   }
   if (int4default != rec_r.int4r5) {
      printf("   rec_r.int4r5 value was bad\n");
      exit(1);
   }
   if (!__ROr_CMPP_OctetString(os10default,rec_r.os10r6,(l1=10,&l1) ,0)) {
      printf("   rec_r.os10r6 value was bad\n");
      exit(1);
   }
   if (en4default != rec_r.en4r7) {
      printf("   rec_r.en4r7 value was bad\n");
      exit(1);
   }
   if (!__ROr_CMPP_IA5String(ia5_30default,rec_r.ia5_30r9,(l2=5,&l2),0)) {
      printf("   rec_r.ia5_30r9 value was bad\n");
      exit(1);
   }
   if (rec_r.__nulr8_absent != 1) {
      printf("   rec_r.__nulr8_absent == %d (should be 1)\n",
	      rec_r.__nulr8_absent);
      exit(1);
   }

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