--- a/tests/libjava/.classpath Thu Jul 05 17:18:02 2012 +0000
+++ b/tests/libjava/.classpath Thu Jul 05 18:48:34 2012 +0000
@@ -4,7 +4,23 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="/usr/share/java/log4j-1.2.jar"/>
<classpathentry kind="lib" path="/usr/share/java/junit4.jar"/>
- <classpathentry kind="lib" path="/usr/share/java/asm3-all.jar">
- </classpathentry>
+ <classpathentry kind="lib" path="/usr/share/java/asm3-all.jar"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/annotations-api.jar"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/catalina.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/catalina-ant.jar"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/catalina-ha.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/catalina-tribes.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/el-api.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/jasper.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/jasper-el.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/jasper-jdt.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/jsp-api.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/servlet-api.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/tomcat-coyote.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/tomcat-dbcp.jar" sourcepath="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/java"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/tomcat-i18n-es.jar"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/tomcat-i18n-fr.jar"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/tomcat-i18n-ja.jar"/>
+ <classpathentry kind="lib" path="/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src/lib/tomcat-juli.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
--- a/tests/libjava/.project Thu Jul 05 17:18:02 2012 +0000
+++ b/tests/libjava/.project Thu Jul 05 18:48:34 2012 +0000
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>libjava-tests</name>
+ <name>stx:libjava - tests - libjava</name>
<comment></comment>
<projects>
</projects>
--- a/tests/libjava/build.xml Thu Jul 05 17:18:02 2012 +0000
+++ b/tests/libjava/build.xml Thu Jul 05 18:48:34 2012 +0000
@@ -18,6 +18,7 @@
</path>
<target name="init">
<mkdir dir="bin"/>
+ <mkdir dir="classloader-tests-classes/bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
@@ -27,6 +28,7 @@
</target>
<target name="clean">
<delete dir="bin"/>
+ <delete dir="classloader-tests-classes/bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
@@ -37,6 +39,10 @@
<src path="src"/>
<classpath refid="libjava-tests.classpath"/>
</javac>
+ <javac debug="true" debuglevel="${debuglevel}" destdir="classloader-tests-classes/bin" source="${source}" target="${target}">
+ <src path="classloader-tests-classes/src"/>
+ <classpath refid="libjava-tests.classpath"/>
+ </javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/classloader-tests-classes/README.txt Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,2 @@
+Do not delete this directory, classes here are required
+to test classloaders. See ClassLoaderTests.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/classloader-tests-classes/src/Bar.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,4 @@
+
+public class Bar {
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/classloader-tests-classes/src/Baz.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,4 @@
+
+public class Baz {
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/classloader-tests-classes/src/Foo.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,5 @@
+
+public class Foo extends Bar {
+
+ public Baz baz;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/classloader-tests-classes/src/SqlSubclass.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,6 @@
+import javax.sql.rowset.BaseRowSet;
+
+
+public class SqlSubclass extends BaseRowSet {
+
+}
Binary file tests/libjava/foos/Bar.class has changed
--- a/tests/libjava/foos/Bar.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-
-public class Bar {
-
-}
Binary file tests/libjava/foos/Baz.class has changed
--- a/tests/libjava/foos/Baz.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-
-public class Baz {
-
-}
Binary file tests/libjava/foos/Foo.class has changed
--- a/tests/libjava/foos/Foo.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-
-public class Foo extends Bar {
-
- public Baz baz;
-}
Binary file tests/libjava/foos/SqlSubclass.class has changed
--- a/tests/libjava/foos/SqlSubclass.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-import javax.sql.rowset.BaseRowSet;
-
-
-public class SqlSubclass extends BaseRowSet {
-
-}
--- a/tests/libjava/src/stx/libjava/tests/AnnotationTests.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-package stx.libjava.tests;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import junit.framework.TestCase;
-
-import org.junit.runner.JUnitCore;
-import org.junit.runner.Result;
-import org.junit.runner.notification.Failure;
-
-import stx.libjava.tests.mocks.EnumValueAnnotation;
-import stx.libjava.tests.mocks.HeavilyAnnotatedClass;
-import stx.libjava.tests.mocks.Weather;
-
-public class AnnotationTests extends TestCase {
-
- public void testClassAnnotations() {
- Annotation[] annotations = HeavilyAnnotatedClass.class.getAnnotations();
- for (Annotation a : annotations) {
- System.out.println(a.annotationType());
- }
- assertTrue(annotations.length == 4);
- }
-
- public void testFieldAnnotations() throws Exception {
- Field field = new HeavilyAnnotatedClass().getClass().getDeclaredField("heavilyAnnotatedField");
- Annotation[] annotations = field.getAnnotations();
- for (Annotation a : annotations) {
- System.out.println(a.annotationType());
- }
- assertTrue(annotations.length == 4);
- }
-
- public void testMethodAnnotations() throws Exception {
- Method method = new HeavilyAnnotatedClass().getClass().getDeclaredMethod("heavilyAnnotatedMethod", String.class);
- Annotation[] annotations = method.getAnnotations();
- for (Annotation a : annotations) {
- System.out.println(a.annotationType());
- }
- assertTrue(annotations.length == 4);
- }
-
- public void testMethodParamAnnotations() throws Exception {
- Method method = new HeavilyAnnotatedClass().getClass().getDeclaredMethod("heavilyAnnotatedMethod", String.class);
- Annotation[][] parameterAnnotations = method.getParameterAnnotations();
- Class[] parameterTypes = method.getParameterTypes();
-
- int i=0;
- for(Annotation[] annotations : parameterAnnotations){
- Class parameterType = parameterTypes[i++];
-
- for(Annotation annotation : annotations){
-
- assertTrue(annotation instanceof EnumValueAnnotation);
-
- EnumValueAnnotation myAnnotation = (EnumValueAnnotation) annotation;
-
- assertTrue(myAnnotation.value().equals(Weather.SUNNY));
- }
- }
-
- }
-
- public static void main(String[] args) {
- System.out.println("Expected output: 4 run, 0 failed");
- Result result = runAllTests();
- System.out.println("getRunCount() = " + result.getRunCount());
- System.out.println("getFailureCount() = " + result.getFailureCount());
- for (Failure f : result.getFailures()) {
- System.out.println("Failure: " + f.toString());
- }
- }
-
- public static Result runAllTests() {
- return JUnitCore.runClasses(AnnotationTests.class);
- }
-
-}
--- a/tests/libjava/src/stx/libjava/tests/ClassLoaderHierarchyTests.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-package stx.libjava.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotSame;
-
-import java.io.File;
-import java.net.URL;
-import java.net.URLClassLoader;
-
-import org.junit.Test;
-@SuppressWarnings("rawtypes")
-public class ClassLoaderHierarchyTests {
-
- @Test
- public void testParentOfSystemClassLoader() {
- ClassLoader parent = ClassLoader.getSystemClassLoader().getParent();
-// system->sun.misc.Launcher$AppClassLoader@16f0472
-// parent->sun.misc.Launcher$ExtClassLoader@18d107f
- assertNull(parent.getParent());
- }
-
- @Test
- public void testNiceClassLoaderSelfLoading() throws Exception {
- URL[] urls = new URL[1];
- File file = new File("foos");
- urls[0] = file.toURL();
- URLClassLoader cl = new URLClassLoader(urls);
- Class result = Class.forName("Foo", true, cl);
- assertEquals(cl, result.getClassLoader());
- assertEquals(cl, result.getSuperclass().getClassLoader());
- assertNull(result.getDeclaredField("baz").getClass().getClassLoader());
- }
-
- @Test
- public void testNiceClassLoaderSelfLoadingWithPreCaching() throws Exception {
- URL[] urls = new URL[1];
- File file = new File("foos");
- urls[0] = file.toURL();
- URLClassLoader cl = new URLClassLoader(urls);
- Class result = Class.forName("Foo", true, cl);
- assertNull(result.getDeclaredField("baz").getClass().getClassLoader());
- }
-
- @Test
- public void testTwoSameClassesInDifferentCLsAreDifferent() throws Exception {
- URL[] urls = new URL[1];
- File file = new File("foos");
- urls[0] = file.toURL();
- URLClassLoader cl1 = new URLClassLoader(urls);
- URLClassLoader cl2 = new URLClassLoader(urls);
- Class result1 = Class.forName("Foo", true, cl1);
- Class result2 = Class.forName("Foo", true, cl2);
- assertNotSame(result1,result2);
- }
-
-}
-
--- a/tests/libjava/src/stx/libjava/tests/ClassLoadersTest.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,143 +0,0 @@
-package stx.libjava.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.net.URL;
-import java.net.URLClassLoader;
-
-import org.junit.Test;
-
-import stx.libjava.tests.mocks.EyeOpeningClassLoader;
-import stx.libjava.tests.mocks.MeanClassLoader;
-
-@SuppressWarnings("rawtypes")
-public class ClassLoadersTest {
-
- @Test
- public void testSystemClassLoader() throws Exception {
- ClassLoader cl = ClassLoader.getSystemClassLoader();
- Class clazz = cl.loadClass("org.junit.Test");
- assertNotNull(clazz);
- assertEquals(cl, clazz.getClassLoader());
- }
-
- @Test
- public void testSystemClassLoaderLoadingRTClass() throws Exception {
- ClassLoader cl = ClassLoader.getSystemClassLoader();
- Class clazz = cl.loadClass("java.util.ArrayList");
- assertNotNull(clazz);
- assertNull(clazz.getClassLoader());
- }
-
- @Test
- public void testNiceClassLoaderDelegation() throws Exception {
- URL[] urls = new URL[1];
- File file = new File("foos");
- urls[0] = file.toURL();
- URLClassLoader cl = new URLClassLoader(urls);
- Class result = Class.forName("org.junit.Test", true, cl);
- assertEquals(result.getClassLoader(),
- ClassLoader.getSystemClassLoader());
- }
-
- @Test
- public void testNiceClassLoaderSelfLoading() throws Exception {
- URL[] urls = new URL[1];
- File file = new File("foos");
- urls[0] = file.toURL();
- URLClassLoader cl = new URLClassLoader(urls);
- Class result = Class.forName("Foo", true, cl);
- assertEquals(cl, result.getClassLoader());
- }
-
- @Test
- public void testMeanClassLoaderSelfLoading() throws Exception {
- MeanClassLoader cl = new MeanClassLoader();
- Class result = Class.forName("org.junit.Test", true, cl);
- assertEquals(result.getClassLoader(), cl);
- }
-
- @Test
- public void testEyeOpeningClassLoaderLoadObject() throws Exception {
- try {
- EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
- cl.tryToLoadObject();
- assertTrue(false);
- } catch (SecurityException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testEyeOpeningClassLoaderLoadRuntimeException()
- throws Exception {
- try {
- EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
- cl.tryToLoadRuntimeException();
- assertTrue(false);
- } catch (SecurityException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testEyeOpeningClassLoaderLoadMethod() throws Exception {
- try {
- EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
- cl.tryToLoadMethod();
- assertTrue(false);
- } catch (SecurityException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testEyeOpeningClassLoaderLoadString() throws Exception {
- try {
- EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
- cl.tryToLoadString();
- assertTrue(false);
- } catch (SecurityException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testEyeOpeningClassLoaderLoadDatasource() throws Exception {
- try {
- EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
- cl.tryToLoadDatasource();
- // no exception should be raised
- } catch (NullPointerException e) {
- // it will fail on internals, but we only care about security
- // exception
- }
- assertTrue(true);
- }
-
- @Test
- public void testEyeOpeningClassLoaderLoadBits() throws Exception {
- try {
- EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
- cl.tryToLoadBits();
- assertTrue(false);
- } catch (SecurityException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testEyeOpeningClassLoaderLoadArray() throws Exception {
- try {
- EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
- cl.tryToLoadArray();
- assertTrue(false);
- } catch (SecurityException e) {
- assertTrue(true);
- }
- }
-}
--- a/tests/libjava/src/stx/libjava/tests/ClassLoadingTest.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-package stx.libjava.tests;
-
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-@SuppressWarnings("rawtypes")
-public class ClassLoadingTest {
-
- @Test
- public void testBootstrapClassLoader() throws Exception {
- Class clazz = Class.forName("java.lang.Object");
- assertTrue(clazz.getClassLoader() == null);
- System.out.println(System.getProperty("sun.boot.class.path"));
- System.out.println(System.getProperty("java.ext.dirs"));
- }
-
- @Test
- public void testSystemClassLoader() throws Exception {
- Class clazz = Class.forName("org.junit.Test");
- assertTrue(clazz.getClassLoader().equals(ClassLoader.getSystemClassLoader()));
- }
-
- @Test
- public void testSystemClassLoader2() throws Exception {
- Class clazz = Class.forName("org.hamcrest.Factory");
- assertTrue(clazz.getClassLoader().equals(ClassLoader.getSystemClassLoader()));
- }
-
- @Test
- public void testBootstrapCLLoadsEverythingFromRT() throws Exception {
- Class clazz = Class.forName("javax.sql.DataSource");
- assertTrue(clazz.getClassLoader() == null);
- }
-
- @Test
- public void testBootstrapCLLoadsEverythingFromRT2() throws Exception {
- Class clazz = Class.forName("org.xml.sax.Parser");
- assertTrue(clazz.getClassLoader() == null);
- }
-
- @Test
- public void testBootstrapCLLoadsEverythingFromJavaRelease() throws Exception {
- Class clazz = Class.forName("sun.io.CharToByteDoubleByte");
- assertTrue(clazz.getClassLoader() == null);
- }
-
- @Test
- public void testBootstrapCLLoadsNOTEverythingFromJavaRelease2() throws Exception {
- Class clazz = Class.forName("sun.net.spi.nameservice.dns.DNSNameService");
- ClassLoader expected = ClassLoader.getSystemClassLoader();
- ClassLoader real = clazz.getClassLoader();
- assertEquals(expected.getParent(), real);
- //WEIRD..
- assertNotSame(expected,real);
- }
-
- @Test
- public void testBootstrapCLLoadsEverythingFromJavaRelease3() throws Exception {
- Class clazz = Class.forName("javax.net.SocketFactory");
- ClassLoader real = clazz.getClassLoader();
- assertNull(real);
- }
-
- @Test
- public void testBootstrapCLLoadsEverythingFromJavaRelease4() throws Exception {
- Class clazz = Class.forName("com.sun.net.ssl.TrustManager");
- ClassLoader real = clazz.getClassLoader();
- assertNull(real);
- }
-
- @Test
- public void testBootstrapCLLoadsEverythingFromJavaRelease5() throws Exception {
- Class clazz = Class.forName("javax.crypto.Cipher");
- ClassLoader real = clazz.getClassLoader();
- assertNull(real);
- }
-
- @Test
- public void testBootstrapCLLoadsEverythingFromJavaRelease6() throws Exception {
- Class clazz = Class.forName("sun.security.internal.spec.TlsKeyMaterialParameterSpec");
- ClassLoader real = clazz.getClassLoader();
- assertNull(real);
- }
-
- @Test
- public void testBootstrapCLLoadsEverythingFromJavaRelease7() throws Exception {
- Class clazz = Class.forName("java.lang.Thread");
- assertTrue(clazz.getClassLoader() == null);
- }
-
- @Test
- public void testSystemClassLoaderClassLoader() throws Exception {
- Class clazz = ClassLoader.getSystemClassLoader().getClass();
- ClassLoader real = clazz.getClassLoader();
- assertNull(real);
- }
-
- @Test
- public void testSystemClassLoaderParentClassLoader() throws Exception {
- Class clazz = ClassLoader.getSystemClassLoader().getParent().getClass();
- ClassLoader real = clazz.getClassLoader();
- assertNull(real);
- }
-
-
-
- @Test
- public void testWeirdDNSClassLoader() throws Exception {
- Class clazz = Class.forName("sun.net.spi.nameservice.dns.DNSNameService");
- ClassLoader real = clazz.getClassLoader().getParent();
- assertNull(real);
- }
-
-
-
-}
--- a/tests/libjava/src/stx/libjava/tests/JUnit3Tests.java Thu Jul 05 17:18:02 2012 +0000
+++ b/tests/libjava/src/stx/libjava/tests/JUnit3Tests.java Thu Jul 05 18:48:34 2012 +0000
@@ -21,12 +21,18 @@
}
public void testFailure() {
- assertEquals(10,0);
+ /* Make it failing only when running on Smalltalk/X VM */
+ if (System.getProperty("java.vm.name").equals("Smalltalk/X")) {
+ assertEquals(10,0);
+ }
}
public void testError() {
- float a = 10 / 0;
- assertEquals(a, 0.0);
+ /* Make it error only when running on Smalltalk/X VM */
+ if (System.getProperty("java.vm.name").equals("Smalltalk/X")) {
+ float a = 10 / 0;
+ assertEquals(a, 0.0);
+ }
}
public static void main(String [] args) {
--- a/tests/libjava/src/stx/libjava/tests/JUnit4Tests.java Thu Jul 05 17:18:02 2012 +0000
+++ b/tests/libjava/src/stx/libjava/tests/JUnit4Tests.java Thu Jul 05 18:48:34 2012 +0000
@@ -21,7 +21,10 @@
@Test
public void helloWorldWillNotPass() {
- assertEquals("Is zero equal 5 test", 0, 5);
+ /* Make it failing only when running on Smalltalk/X VM */
+ if (System.getProperty("java.vm.name").equals("Smalltalk/X")) {
+ assertEquals("Is zero equal 5 test", 0, 5);
+ }
}
public static void main(String [] args) {
--- a/tests/libjava/src/stx/libjava/tests/MonitorTests.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-package stx.libjava.tests;
-
-import org.junit.Test;
-
-public class MonitorTests {
- /** An arbitrary token. Methods may assign
- * a value which may be asserted then
- */
- int token = 0;
-
- public void syncAndAbort(Object obj) {
- synchronized (obj) {
- abort();
- }
- }
-
- @Test
- public void test01() {
- Object obj = new Object();
- syncAndAbort(obj);
- syncAndAbort(obj);
- }
-
- public native void abort();
-
-
- /** Not a test standalone, called by
- * JavaMonitorTests>>test_releasing_01
- */
- public void test_releasing_01 () {
- try {
- token = 1;
- test_releasing_01_finally();
- token += 10;
- } catch (Exception e) {
- token += 100;
- }
-
- try {
- test_releasing_01_no_exception();
- token += 1000000;
- } catch (Exception e) {
- token += 10000000;
- }
- }
-
- public synchronized void test_releasing_01_finally_with_no_exception() {
- try {
- test_releasing_01_no_exception();
- } finally {
- token += 10000;
- }
- }
-
- public void test_releasing_01_finally() {
- try {
- test_releasing_01_throw_indirect();
- } finally {
- token += 1000;
- }
- }
-
- public synchronized void test_releasing_01_throw_indirect() {
- test_releasing_01_throw();
- }
-
- public synchronized void test_releasing_01_no_exception() {
- token += 100000;
- }
-
- public void test_releasing_01_throw() {
- throw new RuntimeException("thrown in JavaMinitorTests#test_releasing_01_throw()");
- }
-}
--- a/tests/libjava/src/stx/libjava/tests/SimpleExceptionThrower.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-package stx.libjava.tests;
-
-import java.lang.IllegalArgumentException;
-
-public class SimpleExceptionThrower {
-
- public int token = 0;
-
- public void throw_me(boolean flag) {
- if (flag)
- throw new IllegalArgumentException();
- }
-
- public void call(boolean flag) {
- this.call(new ThrowCaller(), flag);
- }
-
- public void test_03(boolean do_throw) {
- try {
- token = 1;
- if (do_throw)
- throw new IllegalArgumentException();
- token = 2;
- } finally {
- token = 3;
- }
- }
-
- public void test_04(ThrowCaller thrower, boolean do_throw) {
- try {
- token = 1;
- thrower.call(this, do_throw);
- token = 2;
- } finally {
- token = 3;
- }
- }
-
- public void call(ThrowCaller caller, boolean flag) {
- caller.call(this, flag);
- }
-
- class ThrowCaller {
- public void call(SimpleExceptionThrower inst, boolean flag) {
- inst.throw_me(flag);
- }
- };
-}
--- a/tests/libjava/src/stx/libjava/tests/StartAndStopTomcatTests.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-package stx.libjava.tests;
-
-import static org.junit.Assert.fail;
-import static org.junit.Assert.*;
-
-import org.apache.catalina.startup.Bootstrap;
-import org.junit.Test;
-
-import org.apache.catalina.startup.Catalina;
-
-public class StartAndStopTomcatTests {
-
- private static String TOMCAT = null;
-
- static {
- String tomcat = System.getProperty("stx.libjava.tomcat.dir");
- if (tomcat == null) {
- //CHANGE HERE
- TOMCAT = "/home/jv/Projects/libjava/libs/tomcat/tomcat-6.0.28-src";
- } else {
- TOMCAT = tomcat;
- }
- }
-
- public StartAndStopTomcatTests() {
-
- System.setProperty("java.util.logging.config.file", TOMCAT + "/conf/logging.properties");
- System.setProperty("java.util.logging.manager", "org.apache.juli.ClassLoaderLogManager");
- System.setProperty("java.endorsed.dirs", TOMCAT + "/endorsed");
- System.setProperty("catalina.base", TOMCAT);
- System.setProperty("catalina.home", TOMCAT);
- System.setProperty("java.io.tmpdir", TOMCAT + "/temp");
-
-
- // Bootstrap.main(new String[0]);
- }
-
- public void runTomcat() throws Exception {
- Bootstrap.main(new String[] { "start" });
- }
-
- public void stopTomcat() throws Exception {
- Bootstrap.main(new String[] { "stop" });
- }
-
- //@Test
- public void testRunningANdStoppingTomcat() throws Exception {
- runTomcat();
- stopTomcat();
-
- }
-
- //@Test
- public void testRunningTomcat() throws Exception {
- runTomcat();
- }
-
- @Test
- public void testStoppingTomcat() throws Exception {
- stopTomcat();
- }
-
- public static void main(String[] args) throws Exception {
- new StartAndStopTomcatTests().runTomcat();
- }
-}
--- a/tests/libjava/src/stx/libjava/tests/StaticVsInstanceResolvingAndLookupTests.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-package stx.libjava.tests;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Test;
-
-import stx.libjava.tests.staticVsInstance.InheritInstanceStuff;
-import stx.libjava.tests.staticVsInstance.InheritInstanceStuffWithStatic;
-import stx.libjava.tests.staticVsInstance.MissingInstanceStuff;
-import stx.libjava.tests.staticVsInstance.MissingInstanceStuffWithInterface;
-import stx.libjava.tests.staticVsInstance.StaticInSuperVsInstInSuperSuper;
-
-public class StaticVsInstanceResolvingAndLookupTests {
- //when no instance method or field is available
- //but static is, it takes static
- @Test
- public void testMissingInstanceThingy() {
- MissingInstanceStuff s = new MissingInstanceStuff();
- assertTrue(s.staticField == 0);
- assertTrue(s.staticMethod() == 0);
-
- }
-
- //when no instance method or field is available
- //but static in super super and interface in super is, it takes super
- @Test
- public void testSuperVsIfaceFight() {
- MissingInstanceStuffWithInterface s = new MissingInstanceStuffWithInterface();
- assertTrue(s.staticField == 0);
- }
-
- //when no instance method or field is available
- //but there is one in super, it will take it #nosurprise :)
- @Test
- public void testBasicInstanceSuper() {
- InheritInstanceStuff f = new InheritInstanceStuff();
- assertTrue(f.instField == 0);
- assertTrue(f.instMethod() == 0);
- }
-
- //when no instance method or field is available
- //but there is static one in super, and inst in super super
- //it takes inst in super super
- @Test
- public void testStaticInSuperVsInstInSuperSuperFight() {
- StaticInSuperVsInstInSuperSuper f = new StaticInSuperVsInstInSuperSuper();
- assertTrue(f.instField == 1);
- }
-
-
-
-
-
- //when no instance method or field is available
- //but static and interface is, it takes static
- //will not compile :)
-// @Test()
-// public void testStaticVsInterfaceFight() {
-// try {
-// MissingInstanceStuffWithInterface s = new MissingInstanceStuffWithInterface();
-// assertTrue(s.staticField == 0);
-// fail();
-// }
-// catch (Throwable e) {
-// assertTrue(true);
-// }
-// }
-}
--- a/tests/libjava/src/stx/libjava/tests/ThreadJoinTests.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-package stx.libjava.tests;
-
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-public class ThreadJoinTests {
-
- @Test
- public void testJoiningThreads() {
- NewThread ob1 = new NewThread("One");
- NewThread ob2 = new NewThread("Two");
- NewThread ob3 = new NewThread("Three");
- assertTrue(ob1.t.isAlive());
- assertTrue(ob2.t.isAlive());
- assertTrue(ob3.t.isAlive());
- try {
- ob1.t.join();
- ob2.t.join();
- ob3.t.join();
- } catch (InterruptedException e) {
- System.out.println("Main thread Interrupted");
- }
- assertFalse(ob1.t.isAlive());
- assertFalse(ob2.t.isAlive());
- assertFalse(ob3.t.isAlive());
- }
-
-}
-
-class NewThread implements Runnable {
- String name; // name of thread
- Thread t;
-
- NewThread(String threadname) {
- name = threadname;
- t = new Thread(this, name);
- t.start(); // Start the thread
- }
-
- public void run() {
- try {
- for (int i = 5; i > 0; i--) {
- Thread.sleep(1000);
- }
- } catch (InterruptedException e) {
- System.out.println(name + " interrupted.");
- }
- }
-}
--- a/tests/libjava/src/stx/libjava/tests/ThreadOrderingTests.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-package stx.libjava.tests;
-
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-public class ThreadOrderingTests extends Thread {
-
- private String flag;
- private final static String manager = "Manager was last to set the flag";
- private final static String thread = "Thread was last to set the flag";
-
- public void run() {
- synchronized (this) {
- setTheFlag(thread);
- }
- }
-
- private synchronized void setTheFlag(String code) {
- flag = code;
- }
-
- @Test
- public void testOrdering() {
- try {
- ThreadOrderingTests t = new ThreadOrderingTests();
- t.start();
- setTheFlag(manager);
- t.join();
- assertTrue(manager.equals(flag));
- } catch (InterruptedException ignored) {}
- }
-}
--- a/tests/libjava/src/stx/libjava/tests/TooManyArgsTests.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-package stx.libjava.tests;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class TooManyArgsTests {
-
- private int sumArgs(int a1, int a2, int a3, int a4, int a5, int a6, int a7,
- int a8, int a9, int a10, int a11, int a12, int a13, int a14,
- int a15, int a16, int a17, int a18, int a19, int a20) {
- int result = a1 + a2 + a3+ a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15+a16+a17+a18+a19+a20;
- return result;
- }
-
- private int[] arrayOfArgs (int a1, int a2, int a3, int a4, int a5, int a6, int a7,
- int a8, int a9, int a10, int a11, int a12, int a13, int a14,
- int a15, int a16, int a17, int a18, int a19, int a20) {
- int [] result = new int[20];
- result[0]=a1;
- result[1]=a2;
- result[2]=a3;
- result[3]=a4;
- result[4]=a5;
- result[5]=a6;
- result[6]=a7;
- result[7]=a8;
- result[8]=a9;
- result[9]=a10;
- result[10]=a11;
- result[11]=a12;
- result[12]=a13;
- result[13]=a14;
- result[14]=a15;
- result[15]=a16;
- result[16]=a17;
- result[17]=a18;
- result[18]=a19;
- result[19]=a20;
-
- return result;
- }
-
- private int[] varargs(int ... args) {
- int[] result = new int[args.length];
- for (int i = 0; i < args.length; i++) {
- result[i] = args[i];
- }
- return result;
- }
-
- @Test
- public void testSumArgs() {
- int actual = sumArgs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
- int expected = (1+20)*10;
- assertEquals(expected, actual);
- }
-
- @Test
- public void testPositions() {
- int [] result = arrayOfArgs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
- assertEquals(result[0], 1);
- assertEquals(result[1], 2);
- assertEquals(result[2], 3);
- assertEquals(result[3], 4);
- assertEquals(result[4], 5);
- assertEquals(result[5], 6);
- assertEquals(result[6], 7);
- assertEquals(result[7], 8);
- assertEquals(result[8], 9);
- assertEquals(result[9], 10);
- assertEquals(result[10], 11);
- assertEquals(result[11], 12);
- assertEquals(result[12], 13);
- assertEquals(result[13], 14);
- assertEquals(result[14], 15);
- assertEquals(result[15], 16);
- assertEquals(result[16], 17);
- assertEquals(result[17], 18);
- assertEquals(result[18], 19);
- assertEquals(result[19], 20);
- }
-
- @Test
- public void testVarargs() {
- int[] actual = varargs(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
- for (int i = 0; i < 20; i++ ) {
- assertEquals(actual[i], i+1);
- }
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lang/AnnotationTests.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,80 @@
+package stx.libjava.tests.lang;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+
+import stx.libjava.tests.mocks.EnumValueAnnotation;
+import stx.libjava.tests.mocks.HeavilyAnnotatedClass;
+import stx.libjava.tests.mocks.Weather;
+
+public class AnnotationTests extends TestCase {
+
+ public void testClassAnnotations() {
+ Annotation[] annotations = HeavilyAnnotatedClass.class.getAnnotations();
+ for (Annotation a : annotations) {
+ System.out.println(a.annotationType());
+ }
+ assertTrue(annotations.length == 4);
+ }
+
+ public void testFieldAnnotations() throws Exception {
+ Field field = new HeavilyAnnotatedClass().getClass().getDeclaredField("heavilyAnnotatedField");
+ Annotation[] annotations = field.getAnnotations();
+ for (Annotation a : annotations) {
+ System.out.println(a.annotationType());
+ }
+ assertTrue(annotations.length == 4);
+ }
+
+ public void testMethodAnnotations() throws Exception {
+ Method method = new HeavilyAnnotatedClass().getClass().getDeclaredMethod("heavilyAnnotatedMethod", String.class);
+ Annotation[] annotations = method.getAnnotations();
+ for (Annotation a : annotations) {
+ System.out.println(a.annotationType());
+ }
+ assertTrue(annotations.length == 4);
+ }
+
+ public void testMethodParamAnnotations() throws Exception {
+ Method method = new HeavilyAnnotatedClass().getClass().getDeclaredMethod("heavilyAnnotatedMethod", String.class);
+ Annotation[][] parameterAnnotations = method.getParameterAnnotations();
+ Class[] parameterTypes = method.getParameterTypes();
+
+ int i=0;
+ for(Annotation[] annotations : parameterAnnotations){
+ Class parameterType = parameterTypes[i++];
+
+ for(Annotation annotation : annotations){
+
+ assertTrue(annotation instanceof EnumValueAnnotation);
+
+ EnumValueAnnotation myAnnotation = (EnumValueAnnotation) annotation;
+
+ assertTrue(myAnnotation.value().equals(Weather.SUNNY));
+ }
+ }
+
+ }
+
+ public static void main(String[] args) {
+ System.out.println("Expected output: 4 run, 0 failed");
+ Result result = runAllTests();
+ System.out.println("getRunCount() = " + result.getRunCount());
+ System.out.println("getFailureCount() = " + result.getFailureCount());
+ for (Failure f : result.getFailures()) {
+ System.out.println("Failure: " + f.toString());
+ }
+ }
+
+ public static Result runAllTests() {
+ return JUnitCore.runClasses(AnnotationTests.class);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lang/ClassLoaderTests.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,287 @@
+package stx.libjava.tests.lang;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.junit.Test;
+
+import stx.libjava.tests.mocks.EyeOpeningClassLoader;
+import stx.libjava.tests.mocks.MeanClassLoader;
+
+@SuppressWarnings("rawtypes")
+public class ClassLoaderTests {
+
+ @Test
+ public void testBootstrapClassLoader() throws Exception {
+ Class clazz = Class.forName("java.lang.Object");
+ assertTrue(clazz.getClassLoader() == null);
+ System.out.println(System.getProperty("sun.boot.class.path"));
+ System.out.println(System.getProperty("java.ext.dirs"));
+ }
+
+ @Test
+ public void testSystemClassLoader() throws Exception {
+ ClassLoader cl = ClassLoader.getSystemClassLoader();
+ Class clazz = cl.loadClass("org.junit.Test");
+ assertNotNull(clazz);
+ assertEquals(cl, clazz.getClassLoader());
+ }
+
+ @Test
+ public void testSystemClassLoader2() throws Exception {
+ Class clazz = Class.forName("org.hamcrest.Factory");
+ assertTrue(clazz.getClassLoader().equals(ClassLoader.getSystemClassLoader()));
+ }
+
+ @Test
+ public void testBootstrapCLLoadsEverythingFromRT() throws Exception {
+ Class clazz = Class.forName("javax.sql.DataSource");
+ assertTrue(clazz.getClassLoader() == null);
+ }
+
+ @Test
+ public void testBootstrapCLLoadsEverythingFromRT2() throws Exception {
+ Class clazz = Class.forName("org.xml.sax.Parser");
+ assertTrue(clazz.getClassLoader() == null);
+ }
+
+ @Test
+ public void testBootstrapCLLoadsEverythingFromJavaRelease() throws Exception {
+ Class clazz = Class.forName("sun.io.CharToByteDoubleByte");
+ assertTrue(clazz.getClassLoader() == null);
+ }
+
+ @Test
+ public void testBootstrapCLLoadsNOTEverythingFromJavaRelease2() throws Exception {
+ Class clazz = Class.forName("sun.net.spi.nameservice.dns.DNSNameService");
+ ClassLoader expected = ClassLoader.getSystemClassLoader();
+ ClassLoader real = clazz.getClassLoader();
+ assertEquals(expected.getParent(), real);
+ //WEIRD..
+ assertNotSame(expected,real);
+ }
+
+ @Test
+ public void testBootstrapCLLoadsEverythingFromJavaRelease3() throws Exception {
+ Class clazz = Class.forName("javax.net.SocketFactory");
+ ClassLoader real = clazz.getClassLoader();
+ assertNull(real);
+ }
+
+ @Test
+ public void testBootstrapCLLoadsEverythingFromJavaRelease4() throws Exception {
+ Class clazz = Class.forName("com.sun.net.ssl.TrustManager");
+ ClassLoader real = clazz.getClassLoader();
+ assertNull(real);
+ }
+
+ @Test
+ public void testBootstrapCLLoadsEverythingFromJavaRelease5() throws Exception {
+ Class clazz = Class.forName("javax.crypto.Cipher");
+ ClassLoader real = clazz.getClassLoader();
+ assertNull(real);
+ }
+
+ @Test
+ public void testBootstrapCLLoadsEverythingFromJavaRelease6() throws Exception {
+ Class clazz = Class.forName("sun.security.internal.spec.TlsKeyMaterialParameterSpec");
+ ClassLoader real = clazz.getClassLoader();
+ assertNull(real);
+ }
+
+ @Test
+ public void testBootstrapCLLoadsEverythingFromJavaRelease7() throws Exception {
+ Class clazz = Class.forName("java.lang.Thread");
+ assertTrue(clazz.getClassLoader() == null);
+ }
+
+ @Test
+ public void testSystemClassLoaderClassLoader() throws Exception {
+ Class clazz = ClassLoader.getSystemClassLoader().getClass();
+ ClassLoader real = clazz.getClassLoader();
+ assertNull(real);
+ }
+
+ @Test
+ public void testSystemClassLoaderParentClassLoader() throws Exception {
+ Class clazz = ClassLoader.getSystemClassLoader().getParent().getClass();
+ ClassLoader real = clazz.getClassLoader();
+ assertNull(real);
+ }
+
+
+
+ @Test
+ public void testWeirdDNSClassLoader() throws Exception {
+ Class clazz = Class.forName("sun.net.spi.nameservice.dns.DNSNameService");
+ ClassLoader real = clazz.getClassLoader().getParent();
+ assertNull(real);
+ }
+
+
+
+ @Test
+ public void testSystemClassLoaderLoadingRTClass() throws Exception {
+ ClassLoader cl = ClassLoader.getSystemClassLoader();
+ Class clazz = cl.loadClass("java.util.ArrayList");
+ assertNotNull(clazz);
+ assertNull(clazz.getClassLoader());
+ }
+
+ @Test
+ public void testNiceClassLoaderDelegation() throws Exception {
+ URL[] urls = new URL[1];
+ File file = new File("foos");
+ urls[0] = file.toURL();
+ URLClassLoader cl = new URLClassLoader(urls);
+ Class result = Class.forName("org.junit.Test", true, cl);
+ assertEquals(result.getClassLoader(),
+ ClassLoader.getSystemClassLoader());
+ }
+
+ @Test
+ public void testNiceClassLoaderSelfLoading() throws Exception {
+ URL[] urls = new URL[1];
+ File file = new File("classloader-tests-classes/bin");
+ urls[0] = file.toURL();
+ URLClassLoader cl = new URLClassLoader(urls);
+ Class result = Class.forName("Foo", true, cl);
+ assertEquals(cl, result.getClassLoader());
+ }
+
+ @Test
+ public void testMeanClassLoaderSelfLoading() throws Exception {
+ MeanClassLoader cl = new MeanClassLoader();
+ Class result = Class.forName("org.junit.Test", true, cl);
+ assertEquals(result.getClassLoader(), cl);
+ }
+
+ @Test
+ public void testEyeOpeningClassLoaderLoadObject() throws Exception {
+ try {
+ EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
+ cl.tryToLoadObject();
+ assertTrue(false);
+ } catch (SecurityException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testEyeOpeningClassLoaderLoadRuntimeException()
+ throws Exception {
+ try {
+ EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
+ cl.tryToLoadRuntimeException();
+ assertTrue(false);
+ } catch (SecurityException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testEyeOpeningClassLoaderLoadMethod() throws Exception {
+ try {
+ EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
+ cl.tryToLoadMethod();
+ assertTrue(false);
+ } catch (SecurityException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testEyeOpeningClassLoaderLoadString() throws Exception {
+ try {
+ EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
+ cl.tryToLoadString();
+ assertTrue(false);
+ } catch (SecurityException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testEyeOpeningClassLoaderLoadDatasource() throws Exception {
+ try {
+ EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
+ cl.tryToLoadDatasource();
+ // no exception should be raised
+ } catch (NullPointerException e) {
+ // it will fail on internals, but we only care about security
+ // exception
+ }
+ assertTrue(true);
+ }
+
+ @Test
+ public void testEyeOpeningClassLoaderLoadBits() throws Exception {
+ try {
+ EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
+ cl.tryToLoadBits();
+ assertTrue(false);
+ } catch (SecurityException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testEyeOpeningClassLoaderLoadArray() throws Exception {
+ try {
+ EyeOpeningClassLoader cl = new EyeOpeningClassLoader();
+ cl.tryToLoadArray();
+ assertTrue(false);
+ } catch (SecurityException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testParentOfSystemClassLoader() {
+ ClassLoader parent = ClassLoader.getSystemClassLoader().getParent();
+// system->sun.misc.Launcher$AppClassLoader@16f0472
+// parent->sun.misc.Launcher$ExtClassLoader@18d107f
+ assertNull(parent.getParent());
+ }
+
+ @Test
+ public void testNiceClassLoaderSelfLoading2() throws Exception {
+ URL[] urls = new URL[1];
+ File file = new File("classloader-tests-classes/bin");
+ urls[0] = file.toURL();
+ URLClassLoader cl = new URLClassLoader(urls);
+ Class result = Class.forName("Foo", true, cl);
+ assertEquals(cl, result.getClassLoader());
+ assertEquals(cl, result.getSuperclass().getClassLoader());
+ assertNull(result.getDeclaredField("baz").getClass().getClassLoader());
+ }
+
+ @Test
+ public void testNiceClassLoaderSelfLoadingWithPreCaching() throws Exception {
+ URL[] urls = new URL[1];
+ File file = new File("classloader-tests-classes/bin");
+ urls[0] = file.toURL();
+ URLClassLoader cl = new URLClassLoader(urls);
+ Class result = Class.forName("Foo", true, cl);
+ assertNull(result.getDeclaredField("baz").getClass().getClassLoader());
+ }
+
+ @Test
+ public void testTwoSameClassesInDifferentCLsAreDifferent() throws Exception {
+ URL[] urls = new URL[1];
+ File file = new File("classloader-tests-classes/bin");
+ urls[0] = file.toURL();
+ URLClassLoader cl1 = new URLClassLoader(urls);
+ URLClassLoader cl2 = new URLClassLoader(urls);
+ Class result1 = Class.forName("Foo", true, cl1);
+ Class result2 = Class.forName("Foo", true, cl2);
+ assertNotSame(result1,result2);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lang/ExceptionTests.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,48 @@
+package stx.libjava.tests.lang;
+
+import java.lang.IllegalArgumentException;
+
+public class ExceptionTests {
+
+ public int token = 0;
+
+ public void throw_me(boolean flag) {
+ if (flag)
+ throw new IllegalArgumentException();
+ }
+
+ public void call(boolean flag) {
+ this.call(new ThrowCaller(), flag);
+ }
+
+ public void test_03(boolean do_throw) {
+ try {
+ token = 1;
+ if (do_throw)
+ throw new IllegalArgumentException();
+ token = 2;
+ } finally {
+ token = 3;
+ }
+ }
+
+ public void test_04(ThrowCaller thrower, boolean do_throw) {
+ try {
+ token = 1;
+ thrower.call(this, do_throw);
+ token = 2;
+ } finally {
+ token = 3;
+ }
+ }
+
+ public void call(ThrowCaller caller, boolean flag) {
+ caller.call(this, flag);
+ }
+
+ class ThrowCaller {
+ public void call(ExceptionTests inst, boolean flag) {
+ inst.throw_me(flag);
+ }
+ };
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lang/MonitorTests.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,79 @@
+package stx.libjava.tests.lang;
+
+import org.junit.Test;
+
+public class MonitorTests {
+ /** An arbitrary token. Methods may assign
+ * a value which may be asserted then
+ */
+ int token = 0;
+
+ public void syncAndAbort(Object obj) {
+ synchronized (obj) {
+ abort();
+ }
+ }
+
+ @Test
+ public void test01() {
+ /* Do not run this test on real JVM as there is no native
+ * abort()
+ */
+ if (System.getProperty("java.vm.name").equals("Smalltalk/X")) {
+ Object obj = new Object();
+ syncAndAbort(obj);
+ syncAndAbort(obj);
+ }
+ }
+
+ public native void abort();
+
+
+ /** Not a test standalone, called by
+ * JavaMonitorTests>>test_releasing_01
+ */
+ public void test_releasing_01 () {
+ try {
+ token = 1;
+ test_releasing_01_finally();
+ token += 10;
+ } catch (Exception e) {
+ token += 100;
+ }
+
+ try {
+ test_releasing_01_no_exception();
+ token += 1000000;
+ } catch (Exception e) {
+ token += 10000000;
+ }
+ }
+
+ public synchronized void test_releasing_01_finally_with_no_exception() {
+ try {
+ test_releasing_01_no_exception();
+ } finally {
+ token += 10000;
+ }
+ }
+
+ public void test_releasing_01_finally() {
+ try {
+ test_releasing_01_throw_indirect();
+ } finally {
+ token += 1000;
+ }
+ }
+
+ public synchronized void test_releasing_01_throw_indirect() {
+ test_releasing_01_throw();
+ }
+
+ public synchronized void test_releasing_01_no_exception() {
+ token += 100000;
+ }
+
+ public void test_releasing_01_throw() {
+ throw new RuntimeException("thrown in JavaMinitorTests#test_releasing_01_throw()");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lang/MoreThan16ArgumentsTests.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,91 @@
+package stx.libjava.tests.lang;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class MoreThan16ArgumentsTests {
+
+ private int sumArgs(int a1, int a2, int a3, int a4, int a5, int a6, int a7,
+ int a8, int a9, int a10, int a11, int a12, int a13, int a14,
+ int a15, int a16, int a17, int a18, int a19, int a20) {
+ int result = a1 + a2 + a3+ a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15+a16+a17+a18+a19+a20;
+ return result;
+ }
+
+ private int[] arrayOfArgs (int a1, int a2, int a3, int a4, int a5, int a6, int a7,
+ int a8, int a9, int a10, int a11, int a12, int a13, int a14,
+ int a15, int a16, int a17, int a18, int a19, int a20) {
+ int [] result = new int[20];
+ result[0]=a1;
+ result[1]=a2;
+ result[2]=a3;
+ result[3]=a4;
+ result[4]=a5;
+ result[5]=a6;
+ result[6]=a7;
+ result[7]=a8;
+ result[8]=a9;
+ result[9]=a10;
+ result[10]=a11;
+ result[11]=a12;
+ result[12]=a13;
+ result[13]=a14;
+ result[14]=a15;
+ result[15]=a16;
+ result[16]=a17;
+ result[17]=a18;
+ result[18]=a19;
+ result[19]=a20;
+
+ return result;
+ }
+
+ private int[] varargs(int ... args) {
+ int[] result = new int[args.length];
+ for (int i = 0; i < args.length; i++) {
+ result[i] = args[i];
+ }
+ return result;
+ }
+
+ @Test
+ public void testSumArgs() {
+ int actual = sumArgs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
+ int expected = (1+20)*10;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testPositions() {
+ int [] result = arrayOfArgs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
+ assertEquals(result[0], 1);
+ assertEquals(result[1], 2);
+ assertEquals(result[2], 3);
+ assertEquals(result[3], 4);
+ assertEquals(result[4], 5);
+ assertEquals(result[5], 6);
+ assertEquals(result[6], 7);
+ assertEquals(result[7], 8);
+ assertEquals(result[8], 9);
+ assertEquals(result[9], 10);
+ assertEquals(result[10], 11);
+ assertEquals(result[11], 12);
+ assertEquals(result[12], 13);
+ assertEquals(result[13], 14);
+ assertEquals(result[14], 15);
+ assertEquals(result[15], 16);
+ assertEquals(result[16], 17);
+ assertEquals(result[17], 18);
+ assertEquals(result[18], 19);
+ assertEquals(result[19], 20);
+ }
+
+ @Test
+ public void testVarargs() {
+ int[] actual = varargs(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
+ for (int i = 0; i < 20; i++ ) {
+ assertEquals(actual[i], i+1);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lang/StaticVsInstanceResolvingAndLookupTests.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,69 @@
+package stx.libjava.tests.lang;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+import stx.libjava.tests.mocks.instance_static.InheritInstanceStuff;
+import stx.libjava.tests.mocks.instance_static.InheritInstanceStuffWithStatic;
+import stx.libjava.tests.mocks.instance_static.MissingInstanceStuff;
+import stx.libjava.tests.mocks.instance_static.MissingInstanceStuffWithInterface;
+import stx.libjava.tests.mocks.instance_static.StaticInSuperVsInstInSuperSuper;
+
+public class StaticVsInstanceResolvingAndLookupTests {
+ //when no instance method or field is available
+ //but static is, it takes static
+ @Test
+ public void testMissingInstanceThingy() {
+ MissingInstanceStuff s = new MissingInstanceStuff();
+ assertTrue(s.staticField == 0);
+ assertTrue(s.staticMethod() == 0);
+
+ }
+
+ //when no instance method or field is available
+ //but static in super super and interface in super is, it takes super
+ @Test
+ public void testSuperVsIfaceFight() {
+ MissingInstanceStuffWithInterface s = new MissingInstanceStuffWithInterface();
+ assertTrue(s.staticField == 0);
+ }
+
+ //when no instance method or field is available
+ //but there is one in super, it will take it #nosurprise :)
+ @Test
+ public void testBasicInstanceSuper() {
+ InheritInstanceStuff f = new InheritInstanceStuff();
+ assertTrue(f.instField == 0);
+ assertTrue(f.instMethod() == 0);
+ }
+
+ //when no instance method or field is available
+ //but there is static one in super, and inst in super super
+ //it takes inst in super super
+ @Test
+ public void testStaticInSuperVsInstInSuperSuperFight() {
+ StaticInSuperVsInstInSuperSuper f = new StaticInSuperVsInstInSuperSuper();
+ assertTrue(f.instField == 1);
+ }
+
+
+
+
+
+ //when no instance method or field is available
+ //but static and interface is, it takes static
+ //will not compile :)
+// @Test()
+// public void testStaticVsInterfaceFight() {
+// try {
+// MissingInstanceStuffWithInterface s = new MissingInstanceStuffWithInterface();
+// assertTrue(s.staticField == 0);
+// fail();
+// }
+// catch (Throwable e) {
+// assertTrue(true);
+// }
+// }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lang/ThreadJoinTests.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,49 @@
+package stx.libjava.tests.lang;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class ThreadJoinTests {
+
+ @Test
+ public void testJoiningThreads() {
+ NewThread ob1 = new NewThread("One");
+ NewThread ob2 = new NewThread("Two");
+ NewThread ob3 = new NewThread("Three");
+ assertTrue(ob1.t.isAlive());
+ assertTrue(ob2.t.isAlive());
+ assertTrue(ob3.t.isAlive());
+ try {
+ ob1.t.join();
+ ob2.t.join();
+ ob3.t.join();
+ } catch (InterruptedException e) {
+ System.out.println("Main thread Interrupted");
+ }
+ assertFalse(ob1.t.isAlive());
+ assertFalse(ob2.t.isAlive());
+ assertFalse(ob3.t.isAlive());
+ }
+
+}
+
+class NewThread implements Runnable {
+ String name; // name of thread
+ Thread t;
+
+ NewThread(String threadname) {
+ name = threadname;
+ t = new Thread(this, name);
+ t.start(); // Start the thread
+ }
+
+ public void run() {
+ try {
+ for (int i = 5; i > 0; i--) {
+ Thread.sleep(1000);
+ }
+ } catch (InterruptedException e) {
+ System.out.println(name + " interrupted.");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/lang/ThreadOrderingTests.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,32 @@
+package stx.libjava.tests.lang;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class ThreadOrderingTests extends Thread {
+
+ private String flag;
+ private final static String manager = "Manager was last to set the flag";
+ private final static String thread = "Thread was last to set the flag";
+
+ public void run() {
+ synchronized (this) {
+ setTheFlag(thread);
+ }
+ }
+
+ private synchronized void setTheFlag(String code) {
+ flag = code;
+ }
+
+ @Test
+ public void testOrdering() {
+ try {
+ ThreadOrderingTests t = new ThreadOrderingTests();
+ t.start();
+ setTheFlag(manager);
+ t.join();
+ assertTrue(manager.equals(flag));
+ } catch (InterruptedException ignored) {}
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/ImplementingIfaceWithStatic.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,5 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public class ImplementingIfaceWithStatic extends SuperWithStatic {
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/InheritInstanceStuff.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,5 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public class InheritInstanceStuff extends SuperWithInstance {
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/InheritInstanceStuffWithStatic.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,11 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public class InheritInstanceStuffWithStatic extends SuperWithInstance{
+
+ public static int instField = 1;
+ //cannot override method with the same name+selector
+ //nobody cares about static :)
+// public static int instMethod() {
+// return 1;
+// }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/InterfaceWithStatic.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,7 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public interface InterfaceWithStatic {
+
+ public static int staticField = 1;
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/MissingInstanceStuff.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,8 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public class MissingInstanceStuff extends SuperWithStatic {
+
+
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/MissingInstanceStuffWithInterface.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,6 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public class MissingInstanceStuffWithInterface extends ImplementingIfaceWithStatic
+ {
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/StaticInSuperVsInstInSuperSuper.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,6 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public class StaticInSuperVsInstInSuperSuper extends
+ InheritInstanceStuffWithStatic {
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/SuperWithInstance.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,10 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public class SuperWithInstance {
+
+ public int instField = 0;
+ public int instMethod() {
+ return 0;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libjava/src/stx/libjava/tests/mocks/instance_static/SuperWithStatic.java Thu Jul 05 18:48:34 2012 +0000
@@ -0,0 +1,11 @@
+package stx.libjava.tests.mocks.instance_static;
+
+public class SuperWithStatic {
+
+ public static int staticMethod() {
+ return 0;
+ }
+
+ public static int staticField = 0;
+
+}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/ImplementingIfaceWithStatic.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public class ImplementingIfaceWithStatic extends SuperWithStatic {
-
-}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/InheritInstanceStuff.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public class InheritInstanceStuff extends SuperWithInstance {
-
-}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/InheritInstanceStuffWithStatic.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public class InheritInstanceStuffWithStatic extends SuperWithInstance{
-
- public static int instField = 1;
- //cannot override method with the same name+selector
- //nobody cares about static :)
-// public static int instMethod() {
-// return 1;
-// }
-}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/InterfaceWithStatic.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public interface InterfaceWithStatic {
-
- public static int staticField = 1;
-
-}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/MissingInstanceStuff.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public class MissingInstanceStuff extends SuperWithStatic {
-
-
-
-
-}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/MissingInstanceStuffWithInterface.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public class MissingInstanceStuffWithInterface extends ImplementingIfaceWithStatic
- {
-
-}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/StaticInSuperVsInstInSuperSuper.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public class StaticInSuperVsInstInSuperSuper extends
- InheritInstanceStuffWithStatic {
-
-}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/SuperWithInstance.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public class SuperWithInstance {
-
- public int instField = 0;
- public int instMethod() {
- return 0;
- }
-
-}
--- a/tests/libjava/src/stx/libjava/tests/staticVsInstance/SuperWithStatic.java Thu Jul 05 17:18:02 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-package stx.libjava.tests.staticVsInstance;
-
-public class SuperWithStatic {
-
- public static int staticMethod() {
- return 0;
- }
-
- public static int staticField = 0;
-
-}