1 package com.j2biz.pencil.test.compiler; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import junit.framework.TestCase; 7 8 import com.j2biz.pencil.asm.LdcWrapper; 9 import com.j2biz.pencil.asm.method.LogMsgBytecodePatternHandler; 10 import com.j2biz.pencil.asm.tree.LabelWrapper; 11 import com.j2biz.pencil.asm.tree.Node; 12 import com.j2biz.pencil.ex.ClassParseException; 13 14 public class RemoveLastStringStrategyTest extends TestCase { 15 16 private LogMsgBytecodePatternHandler strategy; 17 private List <Node> instructions; 18 19 @Override 20 protected void setUp( ) throws Exception { 21 this.instructions = new ArrayList <Node>(); 22 strategy = new LogMsgBytecodePatternHandler("enclosingMethod", instructions); 23 } 24 25 public void testMultiLiner( ) { 26 final LdcWrapper codeBlockBefore = new LdcWrapper("code block before"); 27 instructions.add(codeBlockBefore); 28 29 final LabelWrapper beforeTemplate = LabelWrapper.create(); 30 instructions.add(beforeTemplate); 31 32 final LdcWrapper template = new LdcWrapper("template"); 33 instructions.add(template); 34 strategy.markPossibleTemplateString(); 35 36 final LabelWrapper afterTemplate = LabelWrapper.create(); 37 instructions.add(afterTemplate); 38 39 Object label = strategy.removeLastByteCodesToLastLabel(); 40 41 assertEquals(instructions.size(), 2); 42 assertEquals(beforeTemplate, label); 43 } 44 45 public void testOneLiner( ) { 46 final LdcWrapper codeBlockBefore = new LdcWrapper("code block before"); 47 instructions.add(codeBlockBefore); 48 49 final LabelWrapper beforeTemplate = LabelWrapper.create(); 50 instructions.add(beforeTemplate); 51 52 final LdcWrapper template = new LdcWrapper("template"); 53 instructions.add(template); 54 strategy.markPossibleTemplateString(); 55 56 Object label = strategy.removeLastByteCodesToLastLabel(); 57 58 assertEquals(instructions.size(), 2); 59 assertEquals(beforeTemplate, label); 60 } 61 62 public void testWrongNodesOnTheStack( ) { 63 try { 64 final LdcWrapper codeBlockBefore = new LdcWrapper( 65 "code block before"); 66 instructions.add(codeBlockBefore); 67 68 final LabelWrapper beforeTemplate = LabelWrapper.create(); 69 instructions.add(beforeTemplate); 70 71 final LdcWrapper template = new LdcWrapper("template"); 72 instructions.add(template); 73 strategy.markPossibleTemplateString(); 74 75 final LdcWrapper template2 = new LdcWrapper("template2"); 76 instructions.add(template2); 77 78 Object label = strategy.removeLastByteCodesToLastLabel(); 79 80 fail("should not allow java-syntax in the call. only template-syntax." ); 81 } catch ( final ClassParseException x ) { 82 assertTrue(true); 83 } 84 } 85 86 } 87 | Popular Tags |