------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 199x by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

immutable class VAL_CLASS is
   attr f:$STR;
end;

class REF_CLASS < $STR is
   attr i:INT; attr d:FLTD; attr b:BOOL; attr s:STR; attr f:FSTR; attr c:CPX;
   attr v:VAL_CLASS;
   create:SAME is return new; end;
   str:STR is
   	x::="[";
	x:=x+"i="+i+", ";
	x:=x+"d="+d+", ";
	x:=x+"b="+b+", ";
	x:=x+"s="+s+", ";
	x:=x+"f="+f.str+", ";
	x:=x+"c="+c.str+", ";
	x:=x+"v="+v.f.str+"]";
        return x;
   end;
end;

class TEST_COPY is
   include R_TEST;
    
   set_r(r:REF_CLASS) is
      r.i:=10;r.d:=11.1d;r.b:=true;r.s:="hallo";r.f:="-".fstr+1+"-";
      r.c:=r.c.im(-1.0).re(1.0);
      r.v:=r.v.f("+"+2+"+");
   end;

   get_array_int:ARRAY{INT} is
      a::=#ARRAY{INT}(100);
      loop a.set!(0.up!); end;
      return a;
   end;

   get_array_str:ARRAY{STR} is
      a::=#ARRAY{STR}(100);
      loop a.set!(0.up!.str); end;
      return a;
   end;

   get_array_cpx:ARRAY{CPX} is
      a::=#ARRAY{CPX}(100);
      c:CPX;
      loop a.set!(c.re(0.up!.flt)); end;
      return a;
   end;

   main is
      class_name("CLUSTER COPY");
      r0::=#REF_CLASS;
      r1::=#REF_CLASS;
      r2::=#REF_CLASS;
      r3::=#REF_CLASS;
      set_r(r0);
      if clusters<2 then
         #ERR+"\nYou need at least two clusters for this test to be meaningful, you have just 1 one.\n";
      end;
      par
	 fork@0 set_r(r1); end;
	 if clusters>1 then fork@1 set_r(r2); end; end;
	 if clusters>2 then fork@2 set_r(r3); end; end;
      end;
      test("local",r1,r0);
      if clusters>1 then test("remote 1",r2,r0); end;
      if clusters>2 then test("remote 2",r3,r0); end;

      if clusters>1 then
	 aint:ARRAY{INT};
	 astr:ARRAY{STR};
	 acpx:ARRAY{CPX};

	 par
	    fork aint:=get_array_int; end;
	    fork astr:=get_array_str; end;
	    fork acpx:=get_array_cpx; end;
	 end;
	 lint::=get_array_int;
	 lstr::=get_array_str;
	 lcpx::=get_array_cpx;
	 test("int array",aint.str,lint.str);
	 test("str array",astr.str,lstr.str);
	 test("cpx array",acpx.str,lcpx.str);

	 cint::=#ARRAY{INT}(30);
	 cstr::=#ARRAY{STR}(30);
	 ccpx::=#ARRAY{CPX}(30);

	 cint.copy(aint);
	 cstr.copy(astr);
	 ccpx.copy(acpx);

	 lint:=lint.resize(30);
	 lstr:=lstr.resize(30);
	 lcpx:=lcpx.resize(30);

	 test("int array copy",cint.str,lint.str);
	 test("str array copy",cstr.str,lstr.str);
	 test("cpx array copy",ccpx.str,lcpx.str);
      end;
      finish;
   end;
end; -- class GATE_TEST

-------------------------------------------------------------------
-- vim:sw=3:nosmartindent
