class definition
authorClaus Gittinger <cg@exept.de>
Mon, 10 Oct 2011 13:49:42 +0200
changeset 643 c64d1153611e
parent 642 7139738e93ad
child 644 c8240e7bfb37
class definition added: #testArrayKeysAndValuesDo #testWeakArrayKeysAndValuesDo #version
RegressionTests__EnumerationTests.st
--- a/RegressionTests__EnumerationTests.st	Sun Oct 09 11:42:06 2011 +0200
+++ b/RegressionTests__EnumerationTests.st	Mon Oct 10 13:49:42 2011 +0200
@@ -52,8 +52,46 @@
     ]
 
     "
-     self testArrayKeysAndValuesDo
+     self new testArrayKeysAndValuesDo
     "
+
+    "Modified (comment): / 10-10-2011 / 13:48:48 / cg"
+!
+
+testWeakArrayKeysAndValuesDo
+    "test GC while enumerating an array"
+
+    |a w|
+
+    a := WeakArray new:100.
+    w := WeakArray new:100.
+    1 to:a size do:[:i |
+        |o|
+
+        o := Object new.
+        a at:i put:o.
+        w at:i put:o.
+    ].
+
+    w keysAndValuesDo:[:index :val |
+        self assert:(val class == Object).
+    ].
+
+    w keysAndValuesDo:[:index :val |
+        index == 5 ifTrue:[
+            a at:7 put:nil.
+            ObjectMemory scavenge
+        ].
+        index == 7 ifTrue:[
+            self assert:(val == 0).
+        ]
+    ]
+
+    "
+     self new testWeakArrayKeysAndValuesDo
+    "
+
+    "Created: / 10-10-2011 / 12:51:43 / cg"
 ! !
 
 !EnumerationTests class methodsFor:'documentation'!