experiments/JavaCompilerTests.st
branchdevelopment
changeset 1869 0ae14ac1c9af
child 1880 27b932afa4a7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/experiments/JavaCompilerTests.st	Wed Dec 12 23:26:59 2012 +0000
@@ -0,0 +1,206 @@
+"
+ Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
+                         SWING Research Group, Czech Technical University 
+                         in Prague
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+"
+"{ Package: 'stx:libjava/experiments' }"
+
+TestCase subclass:#JavaCompilerTests
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Languages-Java-Tests-Compiling'
+!
+
+!JavaCompilerTests class methodsFor:'documentation'!
+
+copyright
+"
+ Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
+                         SWING Research Group, Czech Technical University 
+                         in Prague
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+"
+!
+
+history
+
+    "Created: #testCompilingFromStringWithInCodeDependencies / 09-12-2012 / 09:29:55 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+    "Modified: #registerFooBarSuperclass / 09-12-2012 / 20:35:03 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+    "Modified: #testCompilingFromStringWithInCodeDependencies / 09-12-2012 / 20:36:29 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+! !
+
+!JavaCompilerTests methodsFor:'helpers'!
+
+registerFooBarSuperclass
+    | sourceCode  compiledClass |
+    sourceCode := '
+package stx.libjava;
+class FooBar {    
+
+}
+'.
+    compiledClass := JavaCompiler compile: sourceCode.
+    compiledClass isNil ifTrue: [
+        self 
+            error: 'these tests need PackageVisibleClass and aparently it could not be compiled'
+    ].
+    JavaVM registry registerClass: compiledClass.
+
+    "Created: / 09-12-2012 / 09:28:10 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+    "Modified: / 09-12-2012 / 20:35:03 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+!
+
+registerPackageVisibleClass
+    | sourceCode  compiledClass |
+    sourceCode := '
+package stx.libjava.tests;
+class PackageVisibleClass {
+
+    public int foo() {
+        return 42;
+    }
+
+}
+'.
+    compiledClass := JavaCompiler compile: sourceCode.
+    compiledClass isNil ifTrue: [
+        self 
+            error: 'these tests need PackageVisibleClass and aparently it could not be compiled'
+    ].
+    JavaVM registry registerClass: compiledClass.
+
+    "Created: / 08-12-2012 / 20:31:13 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+! !
+
+!JavaCompilerTests methodsFor:'tests'!
+
+testCompilingFromString
+    | sourceCode  compiledClass |
+    sourceCode := '
+public class Foo {
+
+    public int foo() {
+        return 42;
+    }
+
+}
+'.
+    compiledClass := JavaCompiler compile: sourceCode.
+    self assert: compiledClass notNil
+        message: 'compiler should return compiled class'.
+    self assert: compiledClass isJavaClass
+        message: 'compiler should return java class'.
+
+    "Created: / 06-12-2012 / 22:59:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+testCompilingFromStringWithImports
+    | sourceCode  compiledClass |
+    sourceCode := '
+package stx.libjava.tests;
+import org.junit.Test;
+public class Wohoo {
+
+    public int foo() {
+        return 42;
+    }
+}
+'.
+    compiledClass := JavaCompiler compile: sourceCode.
+    self assert: compiledClass notNil
+        message: 'compiler should return compiled class'.
+    self assert: compiledClass isJavaClass
+        message: 'compiler should return java class'.
+
+    "Created: / 08-12-2012 / 20:29:05 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+!
+
+testCompilingFromStringWithPackage
+    | sourceCode  compiledClass |
+    sourceCode := '
+package stx.libjava.tests;
+public class Wohoo {
+
+    public int foo() {
+        return 42;
+    }
+}
+'.
+    compiledClass := JavaCompiler compile: sourceCode.
+    self assert: compiledClass notNil
+        message: 'compiler should return compiled class'.
+    self assert: compiledClass isJavaClass
+        message: 'compiler should return java class'.
+
+    "Created: / 06-12-2012 / 23:30:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+testCompilingFromStringWithPackageDependencies
+    | sourceCode  compiledClass |
+    self registerPackageVisibleClass.
+    sourceCode := '
+package stx.libjava.tests;
+public class Wohoo {
+
+    public int foo() {
+        return new PackageVisibleClass().foo();
+    }
+}
+'.
+    compiledClass := JavaCompiler compile: sourceCode.
+    self assert: compiledClass notNil
+        message: 'compiler should return compiled class'.
+    self assert: compiledClass isJavaClass
+        message: 'compiler should return java class'.
+
+    "Created: / 08-12-2012 / 20:30:05 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+! !
+
+!JavaCompilerTests class methodsFor:'documentation'!
+
+version_SVN
+    ^ '$Id::                                                                                                                        $'
+! !