diff options
author | aclement <aclement> | 2004-08-03 12:31:29 +0000 |
---|---|---|
committer | aclement <aclement> | 2004-08-03 12:31:29 +0000 |
commit | 2982b4cc622a2a95429b16f0aa3c55b7e20d798a (patch) | |
tree | a1453e59e3356d36b7bacaf272298f91f6fa1407 /ajde/testsrc | |
parent | fe049bdf23ae91b938e64fc2106aebf72be34e3b (diff) | |
download | aspectj-2982b4cc622a2a95429b16f0aa3c55b7e20d798a.tar.gz aspectj-2982b4cc622a2a95429b16f0aa3c55b7e20d798a.zip |
The BIG commit.
- Enhanced structure model support.
- *Incremental* structure model support written and tested (currently switched off, see incModelTests.xml)
- -showWeaveInfo compiler option
- existence of a 'runtimetest' surfaced through relationships
- UI can determine if errors/warnings came from DEOWs.
- Code to enable type mungers to remember source locations written (currently switched off)
Diffstat (limited to 'ajde/testsrc')
5 files changed, 425 insertions, 47 deletions
diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java index e70619504..a2155fd9b 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java @@ -38,6 +38,7 @@ public class AjdeTests extends TestCase { suite.addTestSuite(BuildCancellingTest.class); suite.addTestSuite(JarManifestTest.class); suite.addTestSuite(DuplicateManifestTest.class); + suite.addTestSuite(ShowWeaveMessagesTestCase.class); //$JUnit-END$ return suite; diff --git a/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java index d5902854b..bcf70db2e 100644 --- a/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java +++ b/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java @@ -73,16 +73,16 @@ public class AsmDeclarationsTest extends AjdeTestCase { assertNotNull(decWarnNode); assertEquals(decWarnNode.toLabelString(), decWarnMessage); - String decParentsMessage = "declare parents: Point"; + String decParentsMessage = "declare parents: implements Serializable"; IProgramElement decParentsNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_PARENTS, "declare parents"); assertNotNull(decParentsNode); assertEquals(decParentsNode.toLabelString(), decParentsMessage); // check the next two relative to this one int declareIndex = decParentsNode.getParent().getChildren().indexOf(decParentsNode); - String decParentsPtnMessage = "declare parents: Point+"; - assertEquals(((IProgramElement)aspect.getChildren().get(declareIndex+1)).toLabelString(), decParentsPtnMessage); - String decParentsTPMessage = "declare parents: <type pattern>"; - assertEquals(((IProgramElement)aspect.getChildren().get(declareIndex+2)).toLabelString(), decParentsTPMessage); + String decParentsPtnMessage = "declare parents: extends Observable"; + assertEquals(decParentsPtnMessage,((IProgramElement)aspect.getChildren().get(declareIndex+1)).toLabelString()); + String decParentsTPMessage = "declare parents: extends Observable"; + assertEquals(decParentsTPMessage,((IProgramElement)aspect.getChildren().get(declareIndex+2)).toLabelString()); String decSoftMessage = "declare soft: SizeException"; IProgramElement decSoftNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_SOFT, "declare soft"); diff --git a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java index 407ad1004..64b365276 100644 --- a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java +++ b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java @@ -35,12 +35,13 @@ public class AsmRelationshipsTest extends AjdeTestCase { IProgramElement dp = manager.getHierarchy().findElementForLabel( aspect, IProgramElement.Kind.DECLARE_PARENTS, - "declare parents: Point"); + "declare parents: implements Serializable"/*Point"*/); assertNotNull(dp); List relations = manager.getRelationshipMap().get(dp); - -// assertTrue(false); + + List rels = AsmManager.getDefault().getRelationshipMap().get(dp); + assertTrue(rels.size()>0); // assertTrue(rel.getTargets().size() > 0); // diff --git a/ajde/testsrc/org/aspectj/ajde/BuildCancellingTest.java b/ajde/testsrc/org/aspectj/ajde/BuildCancellingTest.java index 5d07718e1..007727ea1 100644 --- a/ajde/testsrc/org/aspectj/ajde/BuildCancellingTest.java +++ b/ajde/testsrc/org/aspectj/ajde/BuildCancellingTest.java @@ -217,7 +217,7 @@ public class BuildCancellingTest extends AjdeTestCase { programmableBPM, false); -// Should just be A1 on the disk - uncomment this line to verify that! +// Should just be A1 on the disk - uncomment this line to verify that! (and uncomment diskContents()) // assertTrue("Incorrect disk contents found",diskContents("A1")); assertTrue("Should have cancelled after first class weave?:"+programmableBPM.numWovenClassMessages, @@ -258,7 +258,7 @@ public class BuildCancellingTest extends AjdeTestCase { programmableBPM, false); -// Uncomment this line to verify disk contents +// Uncomment this line to verify disk contents(and uncomment diskContents()) // assertTrue("Incorrect disk contents found",diskContents("A1 Cl1 A2")); assertTrue("Should have cancelled after first class weave?:"+programmableBPM.numWovenClassMessages, @@ -350,43 +350,43 @@ public class BuildCancellingTest extends AjdeTestCase { } - private boolean diskContents(String shouldExist) { - String[] fullList = new String[] { "A1","A2","A3","A4","Cl1","Cl2","Cl3","HW"}; - boolean isOK = true; - for (int i = 0; i < fullList.length; i++) { - String file = fullList[i]; - if (shouldExist.indexOf(file)!=-1) { - // There should be a class file called this - if (!openFile("bin/"+file+".class").exists()) { - isOK=false; - System.out.println("Couldn't find this expected file: "+file+".class"); - } - } else { - // There should NOT be a class file called this - if (openFile("bin/"+file+".class").exists()) { - isOK=false; - System.out.println("Found this file when not expected: "+file+".class"); - } - } - } - return isOK; - } - - private int wovenClassesFound() { - int found = 0; - File fA1 = openFile("bin/A1.class"); - File fA2 = openFile("bin/A2.class"); - File fA3 = openFile("bin/A3.class"); - File fA4 = openFile("bin/A4.class"); - File fHW = openFile("bin/HW.class"); - - found+=(fA1.exists()?1:0); - found+=(fA2.exists()?1:0); - found+=(fA3.exists()?1:0); - found+=(fA4.exists()?1:0); - found+=(fHW.exists()?1:0); - return found; - } +// private boolean diskContents(String shouldExist) { +// String[] fullList = new String[] { "A1","A2","A3","A4","Cl1","Cl2","Cl3","HW"}; +// boolean isOK = true; +// for (int i = 0; i < fullList.length; i++) { +// String file = fullList[i]; +// if (shouldExist.indexOf(file)!=-1) { +// // There should be a class file called this +// if (!openFile("bin/"+file+".class").exists()) { +// isOK=false; +// System.out.println("Couldn't find this expected file: "+file+".class"); +// } +// } else { +// // There should NOT be a class file called this +// if (openFile("bin/"+file+".class").exists()) { +// isOK=false; +// System.out.println("Found this file when not expected: "+file+".class"); +// } +// } +// } +// return isOK; +// } +// +// private int wovenClassesFound() { +// int found = 0; +// File fA1 = openFile("bin/A1.class"); +// File fA2 = openFile("bin/A2.class"); +// File fA3 = openFile("bin/A3.class"); +// File fA4 = openFile("bin/A4.class"); +// File fHW = openFile("bin/HW.class"); +// +// found+=(fA1.exists()?1:0); +// found+=(fA2.exists()?1:0); +// found+=(fA3.exists()?1:0); +// found+=(fA4.exists()?1:0); +// found+=(fHW.exists()?1:0); +// return found; +// } private boolean checkFor(String what) { diff --git a/ajde/testsrc/org/aspectj/ajde/ShowWeaveMessagesTestCase.java b/ajde/testsrc/org/aspectj/ajde/ShowWeaveMessagesTestCase.java new file mode 100644 index 000000000..8127ad3cb --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ShowWeaveMessagesTestCase.java @@ -0,0 +1,376 @@ +/* ******************************************************************* + * Copyright (c) 2004 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Andy Clement Initial version + * ******************************************************************/ + +package org.aspectj.ajde; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.aspectj.ajde.internal.CompilerAdapter; +import org.aspectj.bridge.IMessage; +import org.aspectj.util.FileUtil; + +/** + * Weaving messages are complicated things. There are multiple places where weaving + * takes place and the places vary depending on whether we are doing a binary weave or + * going from source. All places that output weaving messages are tagged: + * // TAG: WeavingMessage + * so you can easily find them! + * + * Advice is the simplest to deal with as that is advice weaving is always done in the weaver. + * + * Next is intertype declarations. These are also always done in the weaver but in the case + * of a binary weave we don't know the originating source line for the ITD. + * + * Finally, declares. + * Declare Parents: extends Can only be done when going from source, if attempted by a + * binary weave then an error message (compiler limitation) is + * produced. + * Declare Parents: implements Is (currently!) done at both compile time and weave time. + * If going from source then the message is produced by the + * code in the compiler. if going from binary then the message + * is produced by the weaver. + * Declare Soft: Comes out with 'advice' as a special kind of advice: softener advice + * + * + * Q: Where are the messages turned on/off? + * A: It is a bit messy. See BuildArgParser.genBuildConfig(). Basically that method is the first time + * we parse the option set. Whether weaving messages are on or off is stored in the build config. + * As soon as we have parser the options and determined that weave messages are on, we grab the + * top level message handler and tell it not to ignore WeaveInfo messages. + * + * + * TODO - Other forms of declare? Do they need messages? e.g. declare precedence * + */ +public class ShowWeaveMessagesTestCase extends AjdeTestCase { + + static { + // Switch this to true for a single iteration if you want to reconstruct the + // 'expected weaving messages' files. + regenerate = false; + } + + private static boolean regenerate; + private CompilerAdapter compilerAdapter; + public static final String PROJECT_DIR = "WeaveInfoMessagesTest"; + + public static final String binDir = "bin"; + public static final String expectedResultsDir = "expected"; + + + public ShowWeaveMessagesTestCase(String arg0) { + super(arg0); + } + + /* + * Ensure the output directory in clean + */ + protected void setUp() throws Exception { + super.setUp(PROJECT_DIR); + FileUtil.deleteContents(openFile(binDir)); + } + + protected void tearDown() throws Exception { + super.tearDown(); + FileUtil.deleteContents(openFile(binDir)); + } + + + + + /** + * Weave all the possible kinds of advice and verify the messages that come out. + */ + public void testWeaveMessagesAdvice() { + System.out.println("testWeaveMessagesAdvice: Building with One.lst"); + compilerAdapter = new CompilerAdapter(); + compilerAdapter.showInfoMessages(true); + compilerAdapter.compile((String) openFile("One.lst").getAbsolutePath(),new BPM(),false); + verifyWeavingMessages("advice",true); + } + + + + + /** + * Weave field and method ITDs and check the weave messages that come out. + */ + public void testWeaveMessagesITD() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesITD: Building with Two.lst"); + compilerAdapter = new CompilerAdapter(); + compilerAdapter.showInfoMessages(true); + compilerAdapter.compile((String) openFile("Two.lst").getAbsolutePath(),new BPM(),false); + verifyWeavingMessages("itd",true); + } + + + /** + * Weave "declare parents: implements" and check the weave messages that come out. + */ + public void testWeaveMessagesDeclare() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesDeclare: Building with Three.lst"); + compilerAdapter = new CompilerAdapter(); + compilerAdapter.showInfoMessages(true); + compilerAdapter.compile((String) openFile("Three.lst").getAbsolutePath(),new BPM(),false); + verifyWeavingMessages("declare1",true); + } + + /** + * Weave "declare parents: extends" and check the weave messages that come out. + * Can't do equivalent binary test - as can't do extends in binary. + */ + public void testWeaveMessagesDeclareExtends() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesDeclareExtends: Building with Four.lst"); + compilerAdapter = new CompilerAdapter(); + compilerAdapter.showInfoMessages(true); + compilerAdapter.compile((String) openFile("Four.lst").getAbsolutePath(),new BPM(),false); + verifyWeavingMessages("declare.extends",true); + } + + /** + * Weave "declare soft: type: pointcut" and check the weave messages that come out. + */ + public void testWeaveMessagesDeclareSoft() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesDeclareSoft: Building with Five.lst"); + compilerAdapter = new CompilerAdapter(); + compilerAdapter.showInfoMessages(true); + compilerAdapter.compile((String) openFile("Five.lst").getAbsolutePath(),new BPM(),false); + verifyWeavingMessages("declare.soft",true); + } + + + // BINARY WEAVING TESTS + + /** + * Binary weave variant of the advice weaving test above - to check messages are ok for + * binary weave. Unlike the source level weave, in this test we are using an aspect on + * the aspectpath - which means it has already had its necessary parts woven - so the list + * of weaving messages we expect is less. + */ + public void testWeaveMessagesBinaryAdvice() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesBinaryAdvice: Simple.jar + AspectAdvice.jar"); + Set inpath = new HashSet(); + inpath.add(openFile("Simple.jar")); + ideManager.getProjectProperties().setInpath(inpath); + Set aspectpath = new HashSet(); + aspectpath.add(openFile("AspectAdvice.jar")); + ideManager.getProjectProperties().setAspectPath(aspectpath); + assertTrue("Build failed", doSynchronousBuild("Empty.lst")); + List l = ideManager.getCompilationSourceLineTasks(); + verifyWeavingMessages("advice.binary",true); + } + + public void testWeaveMessagesBinaryITD() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesBinaryITD: Simple.jar + AspectITD.jar"); + Set inpath = new HashSet(); + inpath.add(openFile("Simple.jar")); + ideManager.getProjectProperties().setInpath(inpath); + Set aspectpath = new HashSet(); + aspectpath.add(openFile("AspectITD.jar")); + ideManager.getProjectProperties().setAspectPath(aspectpath); + assertTrue("Build failed", doSynchronousBuild("Empty.lst")); + List l = ideManager.getCompilationSourceLineTasks(); + verifyWeavingMessages("itd",false); + } + + + public void testWeaveMessagesBinaryDeclare() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesBinaryDeclare: Simple.jar + AspectDeclare.jar"); + Set inpath = new HashSet(); + inpath.add(openFile("Simple.jar")); + ideManager.getProjectProperties().setInpath(inpath); + Set aspectpath = new HashSet(); + aspectpath.add(openFile("AspectDeclare.jar")); + ideManager.getProjectProperties().setAspectPath(aspectpath); + assertTrue("Build failed", doSynchronousBuild("Empty.lst")); + verifyWeavingMessages("declare1",false); + } + + /** + * Weave "declare soft: type: pointcut" and check the weave messages that come out. + */ + public void testWeaveMessagesBinaryDeclareSoft() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesBinaryDeclareSoft: Simple.jar + AspectDeclareSoft.jar"); + Set inpath = new HashSet(); + inpath.add(openFile("Simple.jar")); + ideManager.getProjectProperties().setInpath(inpath); + Set aspectpath = new HashSet(); + aspectpath.add(openFile("AspectDeclareSoft.jar")); + ideManager.getProjectProperties().setAspectPath(aspectpath); + assertTrue("Build failed", doSynchronousBuild("Empty.lst")); + verifyWeavingMessages("declare.soft",false); + } + + + + + // BINARY WEAVING WHEN WE'VE LOST THE SOURCE POINTERS + + public void testWeaveMessagesBinaryAdviceNoDebugInfo() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesBinaryAdvice: Simple.jar + AspectAdvice.jar"); + Set inpath = new HashSet(); + inpath.add(openFile("Simple_nodebug.jar")); + ideManager.getProjectProperties().setInpath(inpath); + Set aspectpath = new HashSet(); + aspectpath.add(openFile("AspectAdvice_nodebug.jar")); + ideManager.getProjectProperties().setAspectPath(aspectpath); + assertTrue("Build failed", doSynchronousBuild("Empty.lst")); + List l = ideManager.getCompilationSourceLineTasks(); + verifyWeavingMessages("advice.binary.nodebug",true); + } + + public void testWeaveMessagesBinaryITDNoDebugInfo() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesBinaryITD: Simple.jar + AspectITD.jar"); + Set inpath = new HashSet(); + inpath.add(openFile("Simple_nodebug.jar")); + ideManager.getProjectProperties().setInpath(inpath); + Set aspectpath = new HashSet(); + aspectpath.add(openFile("AspectITD_nodebug.jar")); + ideManager.getProjectProperties().setAspectPath(aspectpath); + assertTrue("Build failed", doSynchronousBuild("Empty.lst")); + List l = ideManager.getCompilationSourceLineTasks(); + verifyWeavingMessages("itd.nodebug",true); + } + + public void testWeaveMessagesBinaryDeclareNoDebugInfo() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesBinaryDeclareNoDebugInfo: Simple.jar + AspectDeclare.jar"); + Set inpath = new HashSet(); + inpath.add(openFile("Simple_nodebug.jar")); + ideManager.getProjectProperties().setInpath(inpath); + Set aspectpath = new HashSet(); + aspectpath.add(openFile("AspectDeclare_nodebug.jar")); + ideManager.getProjectProperties().setAspectPath(aspectpath); + assertTrue("Build failed", doSynchronousBuild("Empty.lst")); + verifyWeavingMessages("declare1.nodebug",true); + } + + /** + * Weave "declare soft: type: pointcut" and check the weave messages that come out. + */ + public void testWeaveMessagesBinaryDeclareSoftNoDebugInfo() { + System.out.println("\n\n\n\n\n\ntestWeaveMessagesBinaryDeclareSoftNoDebugInfo: Simple.jar + AspectDeclareSoft.jar"); + Set inpath = new HashSet(); + inpath.add(openFile("Simple_nodebug.jar")); + ideManager.getProjectProperties().setInpath(inpath); + Set aspectpath = new HashSet(); + aspectpath.add(openFile("AspectDeclareSoft_nodebug.jar")); + ideManager.getProjectProperties().setAspectPath(aspectpath); + assertTrue("Build failed", doSynchronousBuild("Empty.lst")); + verifyWeavingMessages("declare.soft.nodebug",true); + } + + + private class BPM implements BuildProgressMonitor { + public void start(String configFile) {} + + public void setProgressText(String text) {} + + public void setProgressBarVal(int newVal) { } + + public void incrementProgressBarVal() {} + + public void setProgressBarMax(int maxVal) { } + + public int getProgressBarMax() { + return 0; + } + + public void finish() {} + + } + + + public void verifyWeavingMessages(String testid,boolean source) { + File expectedF = openFile(expectedResultsDir+File.separator+testid+".txt"); + if (regenerate && source) { + // Create the file + saveWeaveMessages(expectedF); + } else { + // Verify the file matches what we have + compareWeaveMessages(expectedF); + } + } + + /** + * Compare weaving messages with what is in the file + */ + private void compareWeaveMessages(File f) { + List fileContents = new ArrayList(); + BufferedReader fr; + try { + // Load the file in + fr = new BufferedReader(new FileReader(f)); + String line = null; + while ((line=fr.readLine())!=null) fileContents.add(line); + + // See if the messages match + int msgCount = 0; + List l = ideManager.getCompilationSourceLineTasks(); + for (Iterator iter = l.iterator(); iter.hasNext();) { + IMessage msg = ((NullIdeTaskListManager.SourceLineTask) iter.next()).message; + if (msg.getKind().equals(IMessage.WEAVEINFO)) { + if (!fileContents.contains(msg.getMessage())) { + fail("Could not find message '"+msg.getMessage()+"' in the expected results\n"+ + stringify(fileContents)); + } else { + fileContents.remove(msg.getMessage()); + } + msgCount++; + } + } + assertTrue("Didn't get these expected messages: "+fileContents,fileContents.size()==0); + System.out.println("Successfully verified "+msgCount+" weaving messages"); + } catch (Exception e) { + fail("Unexpected exception saving weaving messages:"+e); + } + } + + private String stringify(List l) { + StringBuffer result = new StringBuffer(); + for (Iterator iter = l.iterator(); iter.hasNext();) { + String str = (String) iter.next(); + result.append(str);result.append("\n"); + } + return result.toString(); + } + + /** + * Store the weaving messages in the specified file. + */ + private void saveWeaveMessages(File f) { + System.out.println("Saving weave messages into "+f.getName()); + FileWriter fw; + try { + fw = new FileWriter(f); + List l = ideManager.getCompilationSourceLineTasks(); + for (Iterator iter = l.iterator(); iter.hasNext();) { + IMessage msg = ((NullIdeTaskListManager.SourceLineTask) iter.next()).message; + if (msg.getKind().equals(IMessage.WEAVEINFO)) { + fw.write(msg.getMessage()+"\n"); + } + } + fw.close(); + } catch (Exception e) { + fail("Unexpected exception saving weaving messages:"+e); + } + } + + + +} |