/*****************************************************************/
/**                                                             **/
/**             (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;
      recur_rec (*) f2;
      recur_rec (*) f3;
   } recur_rec;

End;


main(argc,argv)
   int argc;
   char *argv[];
{
   recur_rec var1s, var2s, var3s, var4s;
   recur_rec var1r, var2r, var3r, var4r;
   Data (interf) inst1;

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

   var1s.f1 = 3;
   var1s.f2 = &var2s;
   var1s.f3 = &var3s;

   var2s.f1 = 4;
   var2s.f2 = 0;
   var2s.f3 = 0;

   var3s.f1 = 5;
   var3s.f2 = 0;
   var3s.f3 = &var4s;

   var4s.f1 = 6;
   var4s.f2 = 0;
   var4s.f3 = 0;

   Roprinti("recur_rec", &var1s,interf);

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

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

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

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

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

   if (var1s.f1 != var1r.f1) {
      printf("   var1r.f1 value is %d (should be %d)\n",
	      var1r.f1, var1s.f1);
      exit(1);
   }
   if (var2s.f1 != ((recur_rec*)(var1r.f2))->f1) {
      printf("   ((recur_rec*)(var1r.f2))->f1 is %d (should be %d)\n",
	      ((recur_rec*)(var1r.f2))->f1, var2s.f1);
      exit(1);
   }
   if (var3s.f1 != ((recur_rec*)(var1r.f3))->f1) {
      printf("   ((recur_rec*)(var1r.f3))->f1 is %d (should be %d)\n",
	      ((recur_rec*)(var1r.f3))->f1, var3s.f1);
      exit(1);
   }
   if (var4s.f1 != ((recur_rec*)((recur_rec*)(var1r.f3))->f3)->f1) {
      printf("   ((recur_rec*)((recur_rec*)(var1r.f3))->f3)->f1 is %d (should be %d)\n",
	      ((recur_rec*)((recur_rec*)(var1r.f3))->f3)->f1, var4s.f1);
      exit(1);
   }

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