------------------------->  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>  <--------------

class STORE_TEST is
   -- Test of the storing/restoring classes
   include TEST;
	 
   main is
      class_name("STORE_TEST");
      -- Create the objects
      s: STORE_FOO := #;
      s.int_attr := 5;
      s.bool_attr := true;
      s.char_attr := 'c';
      s.flt_attr := 2.0;
      s.fltd_attr := 1.0d;
      s.ref_to_self1 := s;
      s2: STORE_FOO := #;
      s.ref_to_another_foo := s2;
      s.second_ref_to_other_foo := s2;
      -- Create an array object, sarr
      sarr ::= #STORE_FOO_ARR{INT}(5);
      sarr.foarr := 3;      
      sarr[1] := 7;

      -- Store them on a stream
      strob ::= #STR_STREAM;
      storer ::= #STORE(strob);
      storer+s;			-- Store a simple object with refs to itself
      storer+sarr;
      #OUT+"\nSTAGE 1: PRINTING OUT WHAT WAS STORED\n";
      #OUT+strob.str; -- Print out what was stored
      
      -- Restore the objects
      restorer ::= #RESTORE(strob.str);
      ob,arrob: $OB;
      has_ob::=restorer.next_object(out ob);
      has_arr::= restorer.next_object(out arrob);
      
      typecase ob
      when STORE_FOO then 
	 test("First object", true, true);
	 test("a value",ob.int_attr.str,5.str);
	 test("d value",ob.flt_attr.str,(2.0).str);
      else
	 raise "Error! Bad restored type";
      end;
      -- Store them again and compare the result
      new_strob ::= #STR_STREAM;
      new_storer ::= #STORE(new_strob);
      new_storer+ob;
      new_storer+arrob;
      #OUT+"\nSTAGE 2: PRINTING OUT WHAT WAS RESTORED\n";
      #OUT+new_strob.str+"\n";
      test("Old version vs. restored",new_strob.str,strob.str);
      finish;
   end;
   
end;
---------------------------------------------------------------
class STORE_FOO is
   
   attr int_attr: INT;
   attr bool_attr: BOOL;
   attr char_attr: CHAR;
   attr flt_attr: FLT;
   attr fltd_attr: FLTD;
   attr ref_to_self1: STORE_FOO;
   attr ref_to_another_foo: STORE_FOO;
   attr second_ref_to_other_foo: STORE_FOO;

   create: SAME is
      return new;
   end;
end;
---------------------------------------------------------------
class STORE_FOO_ARR{T} is
   include ARRAY{T};
   
   attr foarr: INT;
   
   create(i: INT): SAME is
      res ::= new(i);
      return res;
   end;
end;
---------------------------------------------------------------
