PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/test/language/gc/weak_reference/test_weak_ref03.e

http://github.com/tybor/Liberty
Specman e | 111 lines | 79 code | 8 blank | 24 comment | 1 complexity | e849560d81ed8b5a621630d8951d3da1 MD5 | raw file
  1-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries.
  2-- See the Copyright notice at the end of this file.
  3--
  4class TEST_WEAK_REF03
  5   -- Test GC of NATIVE_ARRAY[WEAK_REFERENCE[X]], WEAK_REFERENCE[X] and X.
  6
  7inherit
  8   EIFFELTEST_TOOLS
  9
 10create {}
 11   make
 12
 13feature {}
 14   make
 15      local
 16         mem: MEMORY; i, wr_voided: INTEGER; na_aux: NATIVE_ARRAY[AUX_WEAK_REF03]
 17         na_wr: NATIVE_ARRAY[WEAK_REFERENCE[AUX_WEAK_REF03]]; aux_wr: AUX_WEAK_REF03
 18         wr: WEAK_REFERENCE[AUX_WEAK_REF03]
 19      do
 20         assert(mem.collecting)
 21         -- Test # 1
 22         from
 23            na_aux := na_aux.calloc(Nb_items)
 24            na_wr := na_wr.calloc(Nb_items)
 25            i := Nb_items - 1
 26         until
 27            i < 0
 28         loop
 29            create aux_wr.make(Current)
 30            create wr.set_item(aux_wr)
 31            na_wr.put(wr, i)
 32            assert(na_wr.item(i).item = aux_wr) -- Test # 2 4 6 8 10 12 14 16 18 20 22 24 26
 33            na_aux.put(aux_wr, i)
 34            assert(na_aux.item(i) = aux_wr) -- Test # 3 5 7 9 11 13 15 17 19 21 25 27
 35            i := i - 1
 36         end
 37         aux_wr := Void
 38         generate_garbage
 39         mem.collection_off
 40         mem.full_collect
 41         assert(aux_wr_nb_disposed = 0) -- Test # 28
 42         from
 43            i := Nb_items - 1
 44         until
 45            i < 0
 46         loop
 47            assert(na_wr.item(i).item = na_aux.item(i))
 48            -- Test # 29 30 31 32 33 34 35 36 37 38 39 40 41
 49            na_aux.put(Void, i)
 50            i := i - 1
 51         end
 52         generate_garbage
 53         mem.collection_on
 54         mem.full_collect
 55         assert(aux_wr_nb_disposed > Nb_items / 2) -- Test # 42
 56         from
 57            i := Nb_items - 1
 58         until
 59            i < 0
 60         loop
 61            if na_wr.item(i).item = Void then
 62               wr_voided := wr_voided + 1
 63            end
 64            i := i - 1
 65         end
 66         assert(aux_wr_nb_disposed <= wr_voided) -- Test # 43
 67      end
 68
 69   Nb_items: INTEGER 13
 70
 71   generate_garbage
 72      local
 73         i: INTEGER; s: STRING
 74      do
 75         from
 76            i := 1
 77         until
 78            i = 10000
 79         loop
 80            create s.make_from_string("quark           ends here")
 81            i := i + 1
 82         end
 83      end
 84
 85   aux_wr_nb_disposed: INTEGER
 86
 87feature {AUX_WEAK_REF03}
 88   increment_aux_wr_nb_disposed
 89      do
 90         aux_wr_nb_disposed := aux_wr_nb_disposed + 1
 91      end
 92
 93end -- class TEST_WEAK_REF03
 94--
 95-- ------------------------------------------------------------------------------------------------------------------------------
 96-- Copyright notice below. Please read.
 97--
 98-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
 99-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
100-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
101-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
102-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
103-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
104--
105-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
106-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
107--
108-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
109--
110-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
111-- ------------------------------------------------------------------------------------------------------------------------------