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

  Record <Sequence> {
    Integer(2) f1;
    rect (*) f2;
  } rect;

  Array rect arrt[3];

End;


main(argc,argv)
   int argc;
   char *argv[];
{
   arrt arr_s,arr_r;
   Data (interf) inst1;

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

   arr_s[0].f1 = 10;
   arr_s[0].f2 = (rect *)malloc(sizeof(rect));
   arr_s[0].f2->f1 = 13;
   arr_s[0].f2->f2 = (rect *)malloc(sizeof(rect));
   arr_s[0].f2->f2->f1 = 14;
   arr_s[0].f2->f2->f2 = 0;

   arr_s[1].f1 = 11;
   arr_s[1].f2 = (rect *)malloc(sizeof(rect));
   arr_s[1].f2->f1 = 15;
   arr_s[1].f2->f2 = 0;

   arr_s[2].f1 = 12;
   arr_s[2].f2 = 0;

   Roprinti("arrt", arr_s, interf);

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

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

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

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

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

   if (cmparr(arr_s, arr_r)) {
      printf("   arrays arr_s and arr_r are not equal\n");
      exit(1);
   }

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


int cmprec(rec_s,rec_r)
rect rec_s, rec_r;
{
   if (rec_s.f1 != rec_r.f1){
      printf("   rec_r.f1 value is %d (should be %d)\n",
                 rec_r.f1, rec_s.f1);
      return (1);
   }
   if ((rec_s.f2 == 0 && rec_r.f2 != 0) || (rec_s.f2 != 0 && rec_r.f2 == 0))
      return (1);
   if (rec_s.f2 != 0 && rec_r.f2 != 0)
      return (cmprec(*rec_s.f2, *rec_r.f2));
   return (0);
}


int cmparr(arr_s,arr_r)
arrt arr_s, arr_r;
{
   int i;
   for (i=0; i<3 ; i++) {
      if (cmprec(arr_s[i],arr_r[i]))
         return (1);
   }
   return (0);
}
