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

   Array 
      Union { 
	 Integer(2) u1; 
	 Enumerated(4) u2;
      } 
   arr_un_type[3];

   Array 
      Array Integer(2) [2] 
   arr_arr_type[3];

End;


main(argc,argv)
   int argc;
   char *argv[];
{
   arr_un_type au_s,au_r;
   arr_arr_type aa_s,aa_r;
   Data (interf) inst1;

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

   au_s[0].tag = 0;
   au_s[0].un.u1 = 1;
   au_s[1].tag = 1;
   au_s[1].un.u2 = 2;
   au_s[2].tag = 0;
   au_s[2].un.u1 = -3;

   aa_s[0][0] = 1;
   aa_s[0][1] = 2;
   aa_s[1][0] = 3;
   aa_s[1][1] = 4;
   aa_s[2][0] = -5;
   aa_s[2][1] = 0;

   Roprinti("arr_un_type", au_s,interf);
   Roprinti("arr_arr_type", aa_s,interf);

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

   Bind_STUB(inst1,argv[1],"w",Asn_1_ber);
   Encode inst1
   {
      au_s => arr_un_type;
   }
   Unbind(inst1);

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

   Bind_STUB(inst1,argv[1],"r",Asn_1_ber);
   Decode inst1
      {
         On arr_un_type => (au_r);
      }
   Unbind(inst1);

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

   Bind_STUB(inst1,argv[1],"w",Asn_1_ber);
   Encode inst1
   {
      aa_s => arr_arr_type;
   }
   Unbind(inst1);

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

   Bind_STUB(inst1,argv[1],"r",Asn_1_ber);
   Decode inst1
      {
         On arr_arr_type => (aa_r);
      }
   Unbind(inst1);

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

   if (au_s[0].tag != au_r[0].tag) {
      printf("   au_s[0].tag value is %d (should be %d)\n",
	      au_s[0].tag, au_r[0].tag);
      exit(1);
   }
   if (au_s[0].un.u1 != au_r[0].un.u1) {
      printf("   au_s[0].un.u1 value is %d (should be %d)\n",
	      au_s[0].un.u1, au_r[0].un.u1);
      exit(1);
   }
   if (au_s[1].tag != au_r[1].tag) {
      printf("   au_s[1].tag value is %d (should be %d)\n",
	      au_s[1].tag, au_r[1].tag);
      exit(1);
   }
   if (au_s[1].un.u2 != au_r[1].un.u2) {
      printf("   au_s[1].un.u2 value is %d (should be %d)\n",
	      au_s[1].un.u2, au_r[1].un.u2);
      exit(1);
   }
   if (au_s[2].tag != au_r[2].tag) {
      printf("   au_s[2].tag value is %d (should be %d)\n",
	      au_s[2].tag, au_r[2].tag);
      exit(1);
   }
   if (au_s[2].un.u1 != au_r[2].un.u1) {
      printf("   au_s[2].un.u1 value is %d (should be %d)\n",
	      au_s[2].un.u1, au_r[2].un.u1);
      exit(1);
   }
   if (aa_s[0][0] != aa_r[0][0]) {
      printf("   aa_s[0][0] value is %d (should be %d)\n",
	      aa_s[0][0], aa_r[0][0]);
      exit(1);
   }
   if (aa_s[0][1] != aa_r[0][1]) {
      printf("   aa_s[0][1] value is %d (should be %d)\n",
	      aa_s[0][1], aa_r[0][1]);
      exit(1);
   }
   if (aa_s[1][0] != aa_r[1][0]) {
      printf("   aa_s[1][0] value is %d (should be %d)\n",
	      aa_s[1][0], aa_r[1][0]);
      exit(1);
   }
   if (aa_s[1][1] != aa_r[1][1]) {
      printf("   aa_s[1][1] value is %d (should be %d)\n",
	      aa_s[1][1], aa_r[1][1]);
      exit(1);
   }
   if (aa_s[2][0] != aa_r[2][0]) {
      printf("   aa_s[2][0] value is %d (should be %d)\n",
	      aa_s[2][0], aa_r[2][0]);
      exit(1);
   }
   if (aa_s[2][1] != aa_r[2][1]) {
      printf("   aa_s[1][2] value is %d (should be %d)\n",
	      aa_s[2][1], aa_r[2][1]);
      exit(1);
   }

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