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

   Record {
      Integer(2) <Optional> int2;
      Integer(4) <Optional> int4a;
      Integer(4) <Optional> int4b;
   } rectype;

   Invoke ike 52 Integer(2);

End;


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

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

   rec_s.int2 = -12;
   rec_s.int4a = -34;
   rec_s.int4b = -56;
   rec_s.__int2_absent = 1;
   rec_s.__int4a_absent = 1;
   rec_s.__int4b_absent = 0;
   rec_r.int2 = -13;
   rec_r.int4a = -35;
   rec_r.int4b = -57;

/***************** 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 (-13 != rec_r.int2) {
      printf("   rec_r.int2 value was bad\n");
      exit(1);
   }
   if (-35 != rec_r.int4a) {
      printf("   rec_r.int4a value was bad\n");
      exit(1);
   }
   if (-56 != rec_r.int4b) {
      printf("   rec_r.int4b value was bad\n");
      exit(1);
   }
   if (rec_r.__int2_absent != 1) {
      printf("   rec_r.__int2_absent is %d (should be 1)\n",
	      rec_r.__int2_absent);
      exit(1);
   }
   if (rec_r.__int4a_absent != 1) {
      printf("   rec_r.__int4a_absent is %d (should be 1)\n",
	      rec_r.__int4a_absent);
      exit(1);
   }
   if (rec_r.__int4b_absent != 0) {
      printf("   rec_r.__int4b_absent is %d (should be 0)\n",
	      rec_r.__int4b_absent);
      exit(1);
   }

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