/*****************************************************************/
/**                                                             **/
/**             (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
   Integer(2),Integer(4);

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;

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

   int2_s1 = 14;
   int2_s2 = 15;
   int2_s3 = 16;
   int2_s4 = 17;

   int4_s1 = 18;
   int4_s2 = 19;
   int4_s3 = 20;
   int4_s4 = 21;

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

   Bind_STUB(inst1,argv[1],"w",Asn_1_ber);
   Give inst1 {
      inv_two(,);
      inv_two(,);
      inv_two(int2_s1,);
      inv_two(int2_s2,);
      inv_two(int2_s1,);
      inv_two( , int4_s1);
      inv_two( , int4_s2);
      inv_two( , int4_s1);
      inv_two(int2_s3, int4_s3);
      inv_two(int2_s4, int4_s3);
      inv_two(int2_s3, int4_s4);
      inv_two(int2_s3, int4_s3);
   }
   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(int2_r1,);
   }
   Accept inst1
   {
      On inv_two(int2_r2, , ...); /* redundant ... but legal */
   }
   Accept inst1
   {
      On inv_two( , , ...)
	 two_received3 = 1;
   }
   /* second arg sent **********************************/
   Accept inst1
   {
      On inv_two(,int4_r1);
   }
   Accept inst1
   {
      On inv_two( ,int4_r2, ...); /* redundant ... but legal */
   }
   Accept inst1
   {
      On inv_two( , , ...)
	 two_received4 = 1;
   }
   /* two args sent ************************************/
   Accept inst1
   {
      On inv_two(int2_r3, int4_r3, ...);
   }
   Accept inst1
   {
      On inv_two(int2_r4 , , ...);
   }
   Accept inst1
   {
      On inv_two( ,int4_r4, ...);
   }
   Accept inst1
   {
      On inv_two( , , ...)
	 two_received5 = 1;
   }
   Unbind(inst1);

/***************** 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(int2_r1,) was not received\n");
      exit(1);
   }
   if (int2_s2 != int2_r2) {
      printf("   inv_two(int2_r2,,...) 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( , int4_r1) was not received\n");
      exit(1);
   }
   if (int4_s2 != int4_r2) {
      printf("   inv_two( , int4_r2,...) 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(int2,int4,...) was not received\n");
      exit(1);
   }
   if (int2_s4 != int2_r4) {
      printf("   inv_two(int2, , ...) was not received\n");
      exit(1);
   }
   if (int4_s4 != int4_r4) {
      printf("   inv_two( , int4, ...) 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);
}
