diff options
author | Andy Clement <aclement@pivotal.io> | 2019-01-24 12:02:42 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-01-24 12:02:42 -0800 |
commit | e01e4369b4c60775d679d8de678f54097fdc3120 (patch) | |
tree | 9fec1dc58d902e4850f45def0f6beb44254df3da /runtime/testsrc/org | |
parent | 38a5e6c8f6ac969a71b91de3a572fdcd4fb22b1b (diff) | |
download | aspectj-e01e4369b4c60775d679d8de678f54097fdc3120.tar.gz aspectj-e01e4369b4c60775d679d8de678f54097fdc3120.zip |
mavenizing runtime module - complete
Diffstat (limited to 'runtime/testsrc/org')
4 files changed, 0 insertions, 296 deletions
diff --git a/runtime/testsrc/org/aspectj/runtime/RuntimeModuleTests.java b/runtime/testsrc/org/aspectj/runtime/RuntimeModuleTests.java deleted file mode 100644 index c9bfe88b9..000000000 --- a/runtime/testsrc/org/aspectj/runtime/RuntimeModuleTests.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.aspectj.runtime; -/* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation - * ******************************************************************/ - -import java.io.*; - -import org.aspectj.lang.*; -import org.aspectj.runtime.reflect.JoinPointImplTest; -import org.aspectj.runtime.reflect.RuntimePerformanceTest; -import org.aspectj.runtime.reflect.SignatureTest; - -import junit.framework.*; - -public class RuntimeModuleTests extends TestCase { - - public static TestSuite suite() { - TestSuite suite = new TestSuite(RuntimeModuleTests.class.getName()); - suite.addTestSuite(RuntimeModuleTests.class); // minimum 1 test (testNothing) - suite.addTestSuite(SignatureTest.class); - suite.addTestSuite(JoinPointImplTest.class); - suite.addTestSuite(RuntimePerformanceTest.class); - return suite; - } - - public RuntimeModuleTests(String name) { super(name); } - - public void testNoAspectBoundException() { - RuntimeException fun = new RuntimeException("fun"); - NoAspectBoundException nab = new NoAspectBoundException("Foo", fun); - assertEquals(fun,nab.getCause()); - } - - public void testSoftExceptionPrintStackTrace() { - // let's see -// Throwable t = new Error("xyz"); -// new SoftException(t).printStackTrace(); - - // save to specified PrintStream - ByteArrayOutputStream sink = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(sink); - new SoftException(new Error("xyz")).printStackTrace(out); - String s = new String(sink.toByteArray()); - out.flush(); - checkSoftExceptionString(s); - - // save to specified PrintWriter - sink = new ByteArrayOutputStream(); - PrintWriter pout = new PrintWriter(sink); - new SoftException(new Error("xyz")).printStackTrace(pout); - pout.flush(); - s = new String(sink.toByteArray()); - checkSoftExceptionString(s); - - // check System.err redirect - PrintStream systemErr = System.err; - try { - sink = new ByteArrayOutputStream(); - out = new PrintStream(sink); - System.setErr(out); - new SoftException(new Error("xyz")).printStackTrace(); - out.flush(); - s = new String(sink.toByteArray()); - checkSoftExceptionString(s); - } finally { - System.setErr(systemErr); - } - } - - - static void checkSoftExceptionString(String s) { - assertTrue(-1 != s.indexOf("SoftException")); - assertTrue(-1 != s.indexOf("Caused by: java.lang.Error")); - assertTrue(-1 != s.indexOf("xyz")); - assertTrue(-1 != s.indexOf("testSoftExceptionPrintStackTrace")); - } -} diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java deleted file mode 100644 index 2a17ad998..000000000 --- a/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.aspectj.runtime.reflect; - -import junit.framework.TestCase; - -/** - * @author colyer - * - */ -public class JoinPointImplTest extends TestCase { - - public void testGetArgs() { - String arg1 = "abc"; - StringBuffer arg2 = new StringBuffer("def"); - Object arg3 = new Object(); - Object[] args = new Object[] { arg1, arg2, arg3 }; - JoinPointImpl jpi = new JoinPointImpl(null,null,null,args); - - Object[] retrievedArgs = jpi.getArgs(); - assertEquals("First arg unchanged",arg1,retrievedArgs[0]); - assertEquals("Second arg unchanged",arg2,retrievedArgs[1]); - assertEquals("Third arg unchanged",arg3,retrievedArgs[2]); - retrievedArgs[0] = "xyz"; - ((StringBuffer)retrievedArgs[1]).append("ghi"); - retrievedArgs[2] = "jkl"; - Object[] afterUpdateArgs = jpi.getArgs(); - assertEquals("Object reference not changed",arg1,afterUpdateArgs[0]); - assertEquals("Object reference unchanged",arg2,afterUpdateArgs[1]); - assertEquals("state of referenced object updated","defghi",afterUpdateArgs[1].toString()); - assertEquals("Object reference not changed",arg3,afterUpdateArgs[2]); - } - -} diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/RuntimePerformanceTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/RuntimePerformanceTest.java deleted file mode 100644 index 25959aebc..000000000 --- a/runtime/testsrc/org/aspectj/runtime/reflect/RuntimePerformanceTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Matthew Webster - initial implementation - *******************************************************************************/ -package org.aspectj.runtime.reflect; - -import java.lang.reflect.Method; -import java.util.Timer; -import java.util.TimerTask; - -import org.aspectj.lang.Signature; - -import junit.framework.TestCase; - -public class RuntimePerformanceTest extends TestCase { - - private static final Timer timer = new Timer(true); - private static final long TIMEOUT = 10000; - private static final long ITERATIONS = 1000000; - private static final long WARMUP_ITERATIONS = 10000; - private static final long EXPECTED_RATIO = 8; - private static final Factory factory = new Factory("RutimePerformanceTest.java",RuntimePerformanceTest.class); - - private boolean savedUseCaches; - private Method method; - private Signature signature; - - private TimerTask task; - private boolean abort; - - public RuntimePerformanceTest(String name) { - super(name); - } - - protected void setUp() throws Exception { - super.setUp(); - - /* Save default state */ - savedUseCaches = SignatureImpl.getUseCache(); - - /* If a test takes too long we can kill it and fail */ - abort = false; - task = new TimerTask() { - public void run () { - abort = true; - } - }; - timer.schedule(task,TIMEOUT); - } - - protected void tearDown() throws Exception { - super.tearDown(); - - /* Restore default state */ - SignatureImpl.setUseCache(savedUseCaches); - - task.cancel(); - } - - public void testToString () { - Signature signature = makeMethodSig("test"); - - SignatureImpl.setUseCache(false); - warmUp(signature); - long noCache = invokeSignatureToString(signature,ITERATIONS/EXPECTED_RATIO); - System.out.println("noCache=" + noCache); - - SignatureImpl.setUseCache(true); - warmUp(signature); - long cache = invokeSignatureToString(signature,ITERATIONS); - System.out.println("cache=" + cache); - - long ratio = (EXPECTED_RATIO*noCache/cache); - System.out.println("ratio=" + ratio); - assertTrue("Using cache should be " + EXPECTED_RATIO + " times faster: " + ratio,(ratio >= EXPECTED_RATIO)); - } - - private long invokeSignatureToString (Signature sig, long iterations) { - long start = System.currentTimeMillis(); - String s; - - for (long l = 0; !abort && (l < iterations); l++) { - s = sig.toShortString(); - s = sig.toString(); - s = sig.toLongString(); - } - if (abort) throw new RuntimeException("invokeSignatureToString aborted after " + (TIMEOUT/1000) + " seconds"); - - long finish = System.currentTimeMillis(); - return (finish-start); - } - - private void warmUp (Signature sig) { - invokeSignatureToString(sig,WARMUP_ITERATIONS); - } - - private Signature makeMethodSig (String methodName) { - Class clazz = getClass(); - Class[] parameterTypes = new Class[] { String.class }; - String[] parameterNames = new String[] { "s" }; - Class[] exceptionTypes = new Class[] {}; - Class returnType = Void.TYPE; - return factory.makeMethodSig(1,methodName,clazz,parameterTypes,parameterNames,exceptionTypes,returnType); - } -}
\ No newline at end of file diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java deleted file mode 100644 index 7a66a5b39..000000000 --- a/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.aspectj.runtime.reflect; - -import java.lang.ref.Reference; -import java.lang.reflect.Field; - -import junit.framework.TestCase; - -/** - */ -public class SignatureTest extends TestCase { - public void testGetDeclaringTypeName() { - FieldSignatureImpl fsi = new FieldSignatureImpl(0,"x",SignatureTest.class,String.class); - assertEquals(SignatureTest.class.getName(),fsi.getDeclaringTypeName()); - assertSame(fsi.getDeclaringTypeName(),fsi.getDeclaringTypeName()); // should be cached. - } - - public void testToShortMiddleLongString () { - MethodSignatureImpl msi = new MethodSignatureImpl(0,"test",SignatureTest.class,new Class[] { String.class, Integer.TYPE }, new String[] { "s", "i" }, new Class[] {}, Runnable.class); - String shortString = msi.toShortString(); - assertSame(shortString,msi.toShortString()); // should be cached. - String middleString = msi.toString(); - assertSame(middleString,msi.toString()); // should be cached. - String longString = msi.toLongString(); - assertSame(longString,msi.toLongString()); // should be cached. - assertTrue("String representations should be different",!(shortString.equals(middleString) || middleString.equals(longString) || longString.equals(shortString))); - } - - public void testClearCache() throws Exception { - MethodSignatureImpl msi = new MethodSignatureImpl(0,"test",SignatureTest.class,new Class[] { String.class, Integer.TYPE }, new String[] { "s", "i" }, new Class[] {}, Runnable.class); - String shortString = msi.toShortString(); - assertSame(shortString,msi.toShortString()); - - Field field = SignatureImpl.class.getDeclaredField("stringCache"); - field.setAccessible(true); - Object res = field.get(msi); - - field = res.getClass().getDeclaredField("toStringCacheRef"); - field.setAccessible(true); - Reference ref = (Reference)field.get(res); - - ref.clear(); - assertEquals(shortString,msi.toShortString()); - - String longString = msi.toLongString(); - assertSame(longString,msi.toLongString()); // should be cached. - } -} |