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