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

  Record {
    Integer(2) f1;
    rect2 (*) f2;
  } rect1;

  Record {
    rect1 (*) f3;
    Integer(2) f4;
  } rect2;

End;


main(argc,argv)
   int argc;
   char *argv[];
{
   rect2 rec_s, rec_r;
   Data (interf) inst1;

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

   rec_s.f3 = (rect1 *)malloc(sizeof(rect1));
   rec_s.f3->f1 = 11;
   rec_s.f3->f2 = (rect2 *)malloc(sizeof(rect2));
   rec_s.f3->f2->f3 = 0; 
   rec_s.f3->f2->f4 = 12; 
   rec_s.f4 = 10;

   Roprinti("rect2", &rec_s, interf);

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

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

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

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

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

   if (cmprect2(rec_s, rec_r)) {
      printf("   Records rec_s and rec_r are not equal\n");
      exit(1);
   }

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


int cmprect1(rec_s,rec_r)
rect1 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)
      return (cmprect2(*rec_s.f2, *rec_r.f2));
   if (rec_s.f2 != 0 || rec_r.f2 != 0)
      return (1);
   return (0);
}


int cmprect2(rec_s,rec_r)
rect2 rec_s, rec_r;
{
   if (rec_s.f4 != rec_r.f4){
      printf("   rec_r.f4 value is %d (should be %d)\n",
                 rec_r.f4, rec_s.f4);
      return (1);
   }
   if (rec_s.f3 != 0 && rec_r.f3 !=0)
      return (cmprect1(*rec_s.f3, *rec_r.f3));
   if (rec_s.f3 != 0 || rec_r.f3 != 0)
      return (1);
   return (0);
}
