6 poolDictionaries:'' |
6 poolDictionaries:'' |
7 category:'Languages-Java-Tests-RuntimeConstantPool' |
7 category:'Languages-Java-Tests-RuntimeConstantPool' |
8 ! |
8 ! |
9 |
9 |
10 |
10 |
|
11 !JavaConstantPoolsTests class methodsFor:'resources'! |
|
12 |
|
13 resources |
|
14 ^ Array with: JavaInitializedResource with: JavaTestsResource. |
|
15 |
|
16 "Created: / 26-04-2011 / 13:03:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
17 ! ! |
|
18 |
11 !JavaConstantPoolsTests methodsFor:'tests'! |
19 !JavaConstantPoolsTests methodsFor:'tests'! |
12 |
20 |
13 testInvalidateAll |
21 testInvalidateAll |
14 | newConstantPool tmpConstantPoolCache | |
22 | newConstantPool tmpConstantPoolCache | |
15 |
23 |
16 tmpConstantPoolCache := JavaConstantPool allConstantPools. |
24 tmpConstantPoolCache := JavaConstantPool allConstantPools. |
17 JavaConstantPool allConstantPools: LinkedList new. |
25 JavaConstantPool allConstantPools: OrderedCollection new. |
18 newConstantPool := JavaConstantPool new: 8. |
26 newConstantPool := JavaConstantPool new: 8. |
19 newConstantPool at: 1 put: 6. |
27 newConstantPool at: 1 put: 6. |
20 newConstantPool at: 2 put: 'hello'. |
28 newConstantPool at: 2 put: 'hello'. |
21 newConstantPool at: 3 put: (JavaClassRef2 for: 'Ljava/lang/Object;'). |
29 newConstantPool at: 3 put: (JavaClassRef2 for: 'Ljava/lang/Object;'). |
22 newConstantPool at: 4 |
30 newConstantPool at: 4 |
31 newConstantPool at: 7 put: (JavaClassRef2 for: 'Ljava/lang/Runnable;'). |
39 newConstantPool at: 7 put: (JavaClassRef2 for: 'Ljava/lang/Runnable;'). |
32 newConstantPool at: 8 |
40 newConstantPool at: 8 |
33 put: (JavaInterfaceMethodRef2 |
41 put: (JavaInterfaceMethodRef2 |
34 namedAndTyped: (JavaNameAndType2 name: 'run' descriptor: '()V') |
42 namedAndTyped: (JavaNameAndType2 name: 'run' descriptor: '()V') |
35 inClassIdentifiedByRef: (newConstantPool at: 7)). |
43 inClassIdentifiedByRef: (newConstantPool at: 7)). |
36 JavaConstantPool allConstantPools do: self |
44 JavaConstantPool allConstantPools do: |
37 assertTrue: (JavaConstantPool allConstantPools includes: newConstantPool). |
45 [ :each | self |
38 JavaConstantPool allConstantPools:tmpConstantPoolCache. |
46 assertTrue: (JavaConstantPool allConstantPools includes: newConstantPool) ]. |
|
47 JavaConstantPool allConstantPools: tmpConstantPoolCache. |
39 |
48 |
40 "Created: / 08-04-2011 / 17:03:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
49 "Created: / 08-04-2011 / 17:03:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
50 "Modified: / 11-04-2011 / 18:50:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
41 ! |
51 ! |
42 |
52 |
43 testInvalidateForClass |
53 testInvalidateForClass |
44 | newConstantPool tmpConstantPoolCache | |
54 | newConstantPool tmpConstantPoolCache | |
45 |
55 |
|
56 "/backup cps |
46 tmpConstantPoolCache := JavaConstantPool allConstantPools. |
57 tmpConstantPoolCache := JavaConstantPool allConstantPools. |
47 JavaConstantPool allConstantPools: LinkedList new. |
58 JavaConstantPool allConstantPools: OrderedCollection new. |
48 newConstantPool := JavaConstantPool new: 8. |
59 newConstantPool := JavaConstantPool new: 8. |
49 newConstantPool at: 1 put: 6. |
60 newConstantPool at: 1 put: 6. |
50 newConstantPool at: 2 put: 'hello'. |
61 newConstantPool at: 2 put: 'hello'. |
51 newConstantPool at: 3 put: (JavaClassRef2 for: 'Ljava/lang/Object;'). |
62 newConstantPool at: 3 |
|
63 put: (JavaClassRef2 |
|
64 for: 'Lstx/libjava/tests/mocks/ImplementorOfPublicInterface;'). |
52 newConstantPool at: 4 |
65 newConstantPool at: 4 |
53 put: (JavaMethodRef2 |
66 put: (JavaMethodRef2 namedAndTyped: (JavaNameAndType2 name: 'publicMethod' |
54 namedAndTyped: (JavaNameAndType2 name: '<init>' descriptor: '()V') |
67 descriptor: '()Ljava/lang/String;') |
55 inClassIdentifiedByRef: (newConstantPool at: 3)). |
68 inClassIdentifiedByRef: (newConstantPool at: 3)). |
56 newConstantPool at: 5 put: (JavaClassRef2 for: 'Ljava/lang/String;'). |
69 newConstantPool at: 5 |
|
70 put: (JavaClassRef2 for: 'Lstx/libjava/tests/mocks/PublicClass;'). |
57 newConstantPool at: 6 |
71 newConstantPool at: 6 |
58 put: (JavaFieldRef2 |
72 put: (JavaFieldRef2 namedAndTyped: (JavaNameAndType2 name: 'publicField' |
59 namedAndTyped: (JavaNameAndType2 name: 'value' descriptor: '[C') |
73 descriptor: 'Ljava/lang/String;') |
60 inClassIdentifiedByRef: (newConstantPool at: 5)). |
74 inClassIdentifiedByRef: (newConstantPool at: 5)). |
61 newConstantPool at: 7 put: (JavaClassRef2 for: 'Ljava/lang/Runnable;'). |
75 newConstantPool at: 7 put: (JavaClassRef2 for: 'Ljava/lang/Runnable;'). |
62 newConstantPool at: 8 |
76 newConstantPool at: 8 |
63 put: (JavaInterfaceMethodRef2 |
77 put: (JavaInterfaceMethodRef2 |
64 namedAndTyped: (JavaNameAndType2 name: 'run' descriptor: '()V') |
78 namedAndTyped: (JavaNameAndType2 name: 'run' descriptor: '()V') |
65 inClassIdentifiedByRef: (newConstantPool at: 7)). |
79 inClassIdentifiedByRef: (newConstantPool at: 7)). |
66 JavaConstantPool invalidateReferencesToClass: 'Ljava/lang/String;'. |
80 |
|
81 "/end of initialization part |
|
82 |
|
83 newConstantPool do: [:each | each isJavaRef ifTrue: [ each resolve ] ]. |
|
84 |
|
85 "/end of resolving part |
|
86 |
|
87 JavaConstantPool invalidateReferencesToClass: 'Lstx/libjava/tests/mocks/PublicClass;'. |
67 self assertTrue: (newConstantPool at: 3) isResolved. |
88 self assertTrue: (newConstantPool at: 3) isResolved. |
68 self assertTrue: (newConstantPool at: 7) isResolved. |
89 self assertTrue: (newConstantPool at: 7) isResolved. |
69 self assertTrue: (newConstantPool at: 5) isResolved not. |
90 self assertTrue: (newConstantPool at: 5) isResolved not. |
|
91 |
|
92 "/and put pack what was there before |
|
93 |
70 JavaConstantPool allConstantPools: tmpConstantPoolCache. |
94 JavaConstantPool allConstantPools: tmpConstantPoolCache. |
71 |
95 |
72 "Created: / 08-04-2011 / 17:10:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
96 "Created: / 08-04-2011 / 17:10:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
97 "Modified: / 14-04-2011 / 15:41:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
73 ! |
98 ! |
74 |
99 |
75 testNewCreatedCPIsInCache |
100 testNewCreatedCPIsInCache |
76 |newConstantPool| |
101 |newConstantPool| |
77 newConstantPool := JavaConstantPool new: 500. |
102 newConstantPool := JavaConstantPool new: 500. |