/*****************************************************************/
/**                                                             **/
/**             (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_two 5
   Any, Any;

End;


main(argc,argv)
   int argc;
   char *argv[];
{
   Control (sample) inst1;
   Integer(2) int2_s1, int2_s2, int2_s3, int2_s4;
   Integer(2) int2_r1, int2_r2, int2_r3, int2_r4;
   Integer(4) int4_s1, int4_s2, int4_s3, int4_s4;
   Integer(4) int4_r1, int4_r2, int4_r3, int4_r4;
   int two_received1 = 0;
   int two_received2 = 0;
   int two_received3 = 0;
   int two_received4 = 0;
   int two_received5 = 0;
   Any encoded_any1,encoded_any2,encoded_any3,encoded_any4;
   Any encoded_any5,encoded_any6,encoded_any7,encoded_any8;
   Any decoded_any1,decoded_any2,decoded_any3,decoded_any4;
   Any decoded_any5,decoded_any6,decoded_any7,decoded_any8;

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

   int2_s1 = 14;
   EncodeAny(sample, Integer(2), encoded_any1, int2_s1);
   int2_s2 = 15;
   EncodeAny(sample, Integer(2), encoded_any2, int2_s2);
   int2_s3 = 16;
   EncodeAny(sample, Integer(2), encoded_any3, int2_s3);
   int2_s4 = 17;
   EncodeAny(sample, Integer(2), encoded_any4, int2_s4);

   int4_s1 = 18;
   EncodeAny(sample, Integer(4), encoded_any5, int4_s1);
   int4_s2 = 19;
   EncodeAny(sample, Integer(4), encoded_any6, int4_s2);
   int4_s3 = 20;
   EncodeAny(sample, Integer(4), encoded_any7, int4_s3);
   int4_s4 = 21;
   EncodeAny(sample, Integer(4), encoded_any8, int4_s4);

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

   Bind_STUB(inst1,argv[1],"w",Asn_1_ber);
   Give inst1 {
      inv_two(,);
      inv_two(,);
      inv_two(encoded_any1,);
      inv_two(encoded_any2,);
      inv_two(encoded_any1,);
      inv_two( , encoded_any5);
      inv_two( , encoded_any6);
      inv_two( , encoded_any5);
      inv_two(encoded_any3, encoded_any7);
      inv_two(encoded_any4, encoded_any7);
      inv_two(encoded_any3, encoded_any8);
      inv_two(encoded_any3, encoded_any7);
   }
   Unbind(inst1);

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

   Bind_STUB(inst1,argv[1],"r",Asn_1_ber);
   /* no args sent ************************************/
   Accept inst1
   {
      On inv_two(,)
	 two_received1 = 1;
   }
   Accept inst1
   {
      On inv_two(,,...)
	 two_received2 = 1;
   }
   /* first arg sent ***********************************/
   Accept inst1
   {
      On inv_two(decoded_any1,);
   }
   Accept inst1
   {
      On inv_two(decoded_any2, , ...); /* redundant ... but legal */
   }
   Accept inst1
   {
      On inv_two( , , ...)
	 two_received3 = 1;
   }
   /* second arg sent **********************************/
   Accept inst1
   {
      On inv_two(,decoded_any5);
   }
   Accept inst1
   {
      On inv_two( ,decoded_any6, ...); /* redundant ... but legal */
   }
   Accept inst1
   {
      On inv_two( , , ...)
	 two_received4 = 1;
   }
   /* two args sent ************************************/
   Accept inst1
   {
      On inv_two(decoded_any3, decoded_any7, ...);
   }
   Accept inst1
   {
      On inv_two(decoded_any4 , , ...);
   }
   Accept inst1
   {
      On inv_two( ,decoded_any8, ...);
   }
   Accept inst1
   {
      On inv_two( , , ...)
	 two_received5 = 1;
   }
   Unbind(inst1);
   DecodeAny(sample, Integer(2), int2_r1, decoded_any1);
   DecodeAny(sample, Integer(2), int2_r2, decoded_any2);
   DecodeAny(sample, Integer(2), int2_r3, decoded_any3);
   DecodeAny(sample, Integer(2), int2_r4, decoded_any4);
   DecodeAny(sample, Integer(4), int4_r1, decoded_any5);
   DecodeAny(sample, Integer(4), int4_r2, decoded_any6);
   DecodeAny(sample, Integer(4), int4_r3, decoded_any7);
   DecodeAny(sample, Integer(4), int4_r4, decoded_any8);

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

   if (two_received1 != 1) {
      printf("   inv_two(,) was not received\n");
      exit(1);
   }
   if (two_received2 != 1) {
      printf("   inv_two(,,...) was not received (no args sent)\n");
      exit(1);
   }
   if (int2_s1 != int2_r1) {
      printf("   inv_two(decoded_any1,) was not received\n");
      exit(1);
   }
   if (int2_s2 != int2_r2) {
      printf("   inv_two(decoded_any2,,...) was not received\n");
      exit(1);
   }
   if (two_received3 != 1) {
      printf("   inv_two(,,...) was not received (1st sent)\n");
      exit(1);
   }
   if (int4_s1 != int4_r1) {
      printf("   inv_two( , decoded_any5) was not received\n");
      exit(1);
   }
   if (int4_s2 != int4_r2) {
      printf("   inv_two( , decoded_any6,...) was not received\n");
      exit(1);
   }
   if (two_received4 != 1) {
      printf("   inv_two(,,...) was not received (2nd sent)\n");
      exit(1);
   }
   if ((int2_s3 != int2_r3) || (int4_s3 != int4_r3)) {
      printf("   inv_two(decoded_any3,decoded_any7,...) was not received\n");
      exit(1);
   }
   if (int2_s4 != int2_r4) {
      printf("   inv_two(decoded_any4, , ...) was not received\n");
      exit(1);
   }
   if (int4_s4 != int4_r4) {
      printf("   inv_two( , decoded_any8, ...) was not received\n");
      exit(1);
   }
   if (two_received5 != 1) {
      printf("   inv_two( , , ...) was not received (2sent)\n");
      exit(1);
   }

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