src/JavaRuntimeConstantPoolTests.st
branchjk_new_structure
changeset 778 caa3a009f617
parent 777 e6e61412ae43
child 814 68df82c46fb0
--- a/src/JavaRuntimeConstantPoolTests.st	Fri May 13 06:55:55 2011 +0000
+++ b/src/JavaRuntimeConstantPoolTests.st	Fri May 13 08:01:14 2011 +0000
@@ -1,103 +1,89 @@
 "{ Package: 'stx:libjava' }"
 
 AbstractJavaTestCase subclass:#JavaRuntimeConstantPoolTests
-	instanceVariableNames:''
+	instanceVariableNames:'constantPoolCacheBackup'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Languages-Java-Tests-RuntimeConstantPool'
 !
 
 
+!JavaRuntimeConstantPoolTests methodsFor:'helpers'!
+
+cleanUpCPCache
+    "warning - counting with the fact that cp cache is backed up in setUp and restored in tearDown methods"
+    JavaConstantPool allConstantPools: OrderedCollection new.
+
+    "Created: / 13-05-2011 / 09:42:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!JavaRuntimeConstantPoolTests methodsFor:'running'!
+
+setUp
+    super setUp.
+    constantPoolCacheBackup := JavaConstantPool allConstantPools.
+
+    "Created: / 13-05-2011 / 09:33:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+tearDown
+super tearDown.
+    JavaConstantPool allConstantPools: constantPoolCacheBackup.
+
+    "Created: / 13-05-2011 / 09:33:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
 !JavaRuntimeConstantPoolTests methodsFor:'tests'!
 
+testConstantPoolCaching
+    | newConstantPool |
+
+    JavaConstantPool allConstantPools: OrderedCollection new.
+    newConstantPool := self getPrettyBigConstantPool.
+    self 
+        assertTrue: (JavaConstantPool allConstantPools includes: newConstantPool).
+
+    "Created: / 13-05-2011 / 09:36:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
 testInvalidateAll
-    | newConstantPool  tmpConstantPoolCache |
+    | cp |
 
-    tmpConstantPoolCache := JavaConstantPool allConstantPools.
-    JavaConstantPool allConstantPools: OrderedCollection new.
-    newConstantPool := JavaConstantPool new: 8.
-    newConstantPool at: 1 put: 6.
-    newConstantPool at: 2 put: 'hello'.
-    newConstantPool at: 3 put: (self getClassRefFor: 'Ljava/lang/Object;').
-    newConstantPool at: 4
-        put: (JavaMethodRef2  in: nil
-                namedAndTyped: (self getName: '<init>' descriptor: '()V')
-                inClassIdentifiedByRef: (newConstantPool at: 3)).
-    newConstantPool at: 5 put: (self getClassRefFor:'Ljava/lang/String;').
-    newConstantPool at: 6
-        put: (JavaFieldRef2  in: nil
-                namedAndTyped: (self getName: 'value' descriptor: '[C')
-                inClassIdentifiedByRef: (newConstantPool at: 5)).
-    newConstantPool at: 7 put: (self getClassRefFor: 'Ljava/lang/Runnable;').
-    newConstantPool at: 8
-        put: (JavaInterfaceMethodRef2 in: nil
-                namedAndTyped: (self getName: 'run' descriptor: '()V')
-                inClassIdentifiedByRef: (newConstantPool at: 7)).
-    JavaConstantPool allConstantPools do: 
-            [:each | 
-            self 
-                assertTrue: (JavaConstantPool allConstantPools includes: newConstantPool) ].
-    JavaConstantPool allConstantPools: tmpConstantPoolCache.
+    cp := self getPrettyBigConstantPool.
+    cp do: [:each | each isJavaRef ifTrue: [each resolve]].
+    cp 
+             do: [:each | each isJavaRef ifTrue: [ self assertTrue: (each isResolved) ] ].
+             cp invalidateAll.
+
+    cp 
+                 do: [:each | each isJavaRef ifTrue: [ self assertTrue: (each isResolved not) ] ].
 
     "Created: / 08-04-2011 / 17:03:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-    "Modified: / 10-05-2011 / 16:58:59 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 13-05-2011 / 09:48:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
 testInvalidateForClass
-    | newConstantPool  tmpConstantPoolCache |
+    | cp |
 
-    "/backup cps
-    tmpConstantPoolCache := JavaConstantPool allConstantPools.
-    JavaConstantPool allConstantPools: OrderedCollection new.
-    newConstantPool := JavaConstantPool new: 8.
-    newConstantPool at: 1 put: 6.
-    newConstantPool at: 2 put: 'hello'.
-    newConstantPool at: 3
-        put: (self getClassRefFor: 
-                'Lstx/libjava/tests/mocks/ImplementorOfPublicInterface;').
-    newConstantPool at: 4
-        put: (JavaMethodRef2 in: nil namedAndTyped: (self getName: 'publicMethod'
-                        descriptor: '()Ljava/lang/String;')
-                inClassIdentifiedByRef: (newConstantPool at: 3)).
-    newConstantPool at: 5
-        put: (self getClassRefFor: 'Lstx/libjava/tests/mocks/PublicClass;').
-    newConstantPool at: 6
-        put: (JavaFieldRef2 in: nil namedAndTyped: (self getName:'publicField'
-                        descriptor: 'Ljava/lang/String;')
-                inClassIdentifiedByRef: (newConstantPool at: 5)).
-    newConstantPool at: 7 put: (self getClassRefFor: 'Ljava/lang/Runnable;').
-    newConstantPool at: 8
-        put: (JavaInterfaceMethodRef2 in: nil
-                namedAndTyped: (self getName: 'run' descriptor: '()V')
-                inClassIdentifiedByRef: (newConstantPool at: 7)).
-    
-    "/end of initialization part
-    
-    newConstantPool do: [:each | each isJavaRef ifTrue: [ each resolve ] ].
-    
-    "/end of resolving part
-    
-    JavaConstantPool 
-        invalidateReferencesToClass: 'Lstx/libjava/tests/mocks/PublicClass;'.
-    self assertTrue: (newConstantPool at: 3) isResolved.
-    self assertTrue: (newConstantPool at: 7) isResolved.
-    self assertTrue: (newConstantPool at: 5) isResolved not.
-    
-    "/and put pack what was there before
-    
-    JavaConstantPool allConstantPools: tmpConstantPoolCache.
+    self cleanUpCPCache.
+    cp := self getPrettyBigConstantPool.
+    cp do: [:each | each isJavaRef ifTrue: [ each resolve ] ].
+    cp 
+        do: [:each | each isJavaRef ifTrue: [ self assertTrue: (each isResolved) ] ].
+    JavaConstantPool invalidateReferencesToClass: 'Ljava/lang/Runnable;'.
+    1 to: 13
+        do: 
+            [:index | 
+            (cp at: index) isJavaRef 
+                ifTrue: [ self assertTrue: (cp at: index) isResolved ] ].
+    14 to: 20
+        do: 
+            [:index | 
+            (cp at: index) isJavaRef 
+                ifTrue: [ self assertTrue: (cp at: index) isResolved not ] ].
 
     "Created: / 08-04-2011 / 17:10:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-    "Modified: / 10-05-2011 / 16:57:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
-!
-
-testNewCreatedCPIsInCache
-|newConstantPool|
-newConstantPool := JavaConstantPool new: 500.
-self assertTrue: (JavaConstantPool allConstantPools includes: newConstantPool).
-JavaConstantPool allConstantPools remove: newConstantPool.
-
-    "Created: / 08-04-2011 / 16:57:59 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 13-05-2011 / 09:55:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
 !JavaRuntimeConstantPoolTests class methodsFor:'documentation'!