Added some more tests for class reloading. development
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 17 Dec 2012 00:08:30 +0100
branchdevelopment
changeset 1903 eb0149fe91b7
parent 1902 7edd54d4c29a
child 1904 bffe474406f7
Added some more tests for class reloading.
experiments/ClassReloadingTests.st
experiments/SingleClassReloadingTests.st
--- a/experiments/ClassReloadingTests.st	Sun Dec 16 23:29:06 2012 +0100
+++ b/experiments/ClassReloadingTests.st	Mon Dec 17 00:08:30 2012 +0100
@@ -100,9 +100,10 @@
 register: compiledClass
 
     JavaVM registry registerClass: compiledClass.
-    ^ compiledClass.
+    ^JavaVM registry classNamed: compiledClass name
 
     "Created: / 16-12-2012 / 17:02:04 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+    "Modified: / 16-12-2012 / 23:56:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 testInfrastructure
--- a/experiments/SingleClassReloadingTests.st	Sun Dec 16 23:29:06 2012 +0100
+++ b/experiments/SingleClassReloadingTests.st	Mon Dec 17 00:08:30 2012 +0100
@@ -170,6 +170,202 @@
 
     "Created: / 16-12-2012 / 16:01:58 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
     "Modified (format): / 16-12-2012 / 17:24:37 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+!
+
+test_00
+    "
+    1) compile simple class with no method
+    3) recompile same source again.
+    4) check that class does not change
+    "
+
+    | jclass1 jclass2 |
+    jclass1 := self compileAndRegister:'
+public class test_01 { 
+    public int foo() { 
+        return 10; 
+    }
+}'.
+    self assert: jclass1 new foo == 10.
+
+    jclass2 := self compileAndRegister:'
+public class test_01 { 
+    public int foo() { 
+        return 10; 
+    }
+}'.
+
+    self assert: jclass1 == jclass2. "/only method update, so reloaded class should be the same
+    self assert: (JavaVM registry getClassesDefinedBy: testClassLoader) size = 1 message: 'only classes from these tests should use testClassLoader'.
+    self assert: (JavaVM registry getClassesDefinedBy: testClassLoader) anElement == jclass1 message: 'compiled classes should be registered in testClassLoader'.
+
+    "Created: / 16-12-2012 / 23:51:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_00b
+    "
+    1) compile simple class with no method byt in package
+    3) recompile same source again.
+    4) check that class does not change
+    "
+
+    | jclass1 jclass2 |
+    jclass1 := self compileAndRegister:'
+package zork;
+public class test_01 { 
+    public int foo() { 
+        return 10; 
+    }
+}'.
+    self assert: jclass1 new foo == 10.
+
+    jclass2 := self compileAndRegister:'
+package zork;
+public class test_01 { 
+    public int foo() { 
+        return 10; 
+    }
+}'.
+
+    self assert: jclass1 == jclass2. "/only method update, so reloaded class should be the same
+    self assert: (JavaVM registry getClassesDefinedBy: testClassLoader) size = 1 message: 'only classes from these tests should use testClassLoader'.
+    self assert: (JavaVM registry getClassesDefinedBy: testClassLoader) anElement == jclass1 message: 'compiled classes should be registered in testClassLoader'.
+
+    "Created: / 16-12-2012 / 23:56:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_01
+    "
+    1) compile simple class with one method return 10
+    2) call that method, check that it returns 10
+    3) recompile to return 20
+    4) call that method, check that it returns 20
+    "
+
+    | jclass1 jclass2 |
+    jclass1 := self compileAndRegister:'
+public class test_01 { 
+    public int foo() { 
+        return 10; 
+    }
+}'.
+    self assert: jclass1 new foo == 10.
+
+    jclass2 := self compileAndRegister:'
+public class test_01 { 
+    public int foo() { 
+        return 20; 
+    }
+}'.
+
+    self assert: jclass2 new foo == 20.
+    self assert: jclass1 == jclass2. "/only method update, so reloaded class should be the same
+
+    "Created: / 16-12-2012 / 23:48:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_02a
+    "
+    1) compile simple class with one method return 10
+    2) call that method indirectly, check that it returns 10
+    3) recompile to return 20
+    4) call that method indirectly, check that it returns 20
+    "
+
+    | jclass1 jclass2 caller |
+    jclass1 := self compileAndRegister:'
+public class test_02 { 
+    public int foo() { 
+        return 10; 
+    }
+}'.
+    caller := self compileAndRegister:'
+public class test_02_caller {
+    public int qux(test_02 t) {
+        return t.foo();
+    }
+}
+'.
+    self assert: (caller new qux: (jclass1 new)) == 10.
+
+    jclass2 := self compileAndRegister:'
+public class test_02 { 
+    public int foo() { 
+        return 20; 
+    }
+}'.
+    self assert: (caller new qux: (jclass2 new)) == 20.
+
+    "Created: / 17-12-2012 / 00:02:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_02b
+    "
+    1) compile simple class with one method return 10
+    2) call that method indirectly using fresh instance (NEW), 
+       check that it returns 10
+    3) recompile to return 20
+    4) call that method indirectly, check that it returns 20
+    "
+
+    | jclass1 jclass2 caller |
+    jclass1 := self compileAndRegister:'
+public class test_02 { 
+    public int foo() { 
+        return 10; 
+    }
+}'.
+    caller := self compileAndRegister:'
+public class test_02_caller {
+    public int qux() {
+        test_02 t = new test_02();
+        return t.foo();
+    }
+}
+'.
+    self assert: (caller new qux) == 10.
+
+    jclass2 := self compileAndRegister:'
+public class test_02 { 
+    public int foo() { 
+        return 20; 
+    }
+}'.
+    self assert: (caller new qux) == 20.
+
+    "Created: / 17-12-2012 / 00:04:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_02c
+    "
+    Same as 02a, but with static methods
+    "
+
+    | jclass1 jclass2 caller |
+    jclass1 := self compileAndRegister:'
+public class test_02 { 
+    public static int foo() { 
+        return 10; 
+    }
+}'.
+    caller := self compileAndRegister:'
+public class test_02_caller {
+    public int qux() {
+        return test_02.foo();
+    }
+}
+'.
+    self assert: (caller new qux) == 10.
+
+    jclass2 := self compileAndRegister:'
+public class test_02 { 
+    public static int foo() { 
+        return 20; 
+    }
+}'.
+    self assert: (caller new qux) == 20.
+
+    "Created: / 17-12-2012 / 00:03:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SingleClassReloadingTests class methodsFor:'documentation'!