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

Invoke inv_one 6
   Any;

End;


main(argc,argv)
   int argc;
   char *argv[];
{
   Control (sample) inst1;
   Integer(2) i_s1, i_s2;
   Integer(2) i_r2;
   int one_received1 = 0;
   int one_received2 = 0;
   int one_received3 = 0;
   Any encoded_any1, encoded_any2;
   Any decoded_any;

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

/**************** initialization **********************/

   i_s1 = 34;
   EncodeAny(sample, Integer(2), encoded_any1, i_s1);
   i_s2 = 54;
   EncodeAny(sample, Integer(2), encoded_any2, i_s2);

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

   Bind_STUB(inst1,argv[1],"w",Asn_1_ber);
   Give inst1 {
      inv_one(encoded_any1);
      inv_one(encoded_any2);
      inv_one();
      inv_one();
   }
   Unbind(inst1);

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

   Bind_STUB(inst1,argv[1],"r",Asn_1_ber);
   Accept inst1
   {
      On inv_one(...)
	 one_received1 = 1;
   }
   Accept inst1
   {
      On inv_one(decoded_any,...)
	 one_received2 = 1;
   }
   Accept inst1
   {
      On inv_one()
	 one_received2 = 1;
   }
   Accept inst1
   {
      On inv_one(...)
	 one_received3 = 1;
   }
   Unbind(inst1);
   DecodeAny(sample, Integer(2), i_r2, decoded_any);

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

   if (one_received1 != 1) {
      printf("   inv_one(...) was not received\n");
      exit(1);
   }
   if (i_r2 != i_s2) {
      printf("   int_r2 had a bad value\n");
      exit(1);
   }
   if (one_received2 != 1) {
      printf("   inv_one() was not received\n");
      exit(1);
   }
   if (one_received3 != 1) {
      printf("   2nd inv_one(...) was not received\n");
      exit(1);
   }

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