Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 187   Methods: 4
NCLOC: 111   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestInstructionWithDifferentConstantPool.java 100% 100% 100% 100%
coverage
 1    /*
 2    * Copyright (c) 2001-2009, Jean Tessier
 3    * All rights reserved.
 4    *
 5    * Redistribution and use in source and binary forms, with or without
 6    * modification, are permitted provided that the following conditions
 7    * are met:
 8    *
 9    * * Redistributions of source code must retain the above copyright
 10    * notice, this list of conditions and the following disclaimer.
 11    *
 12    * * Redistributions in binary form must reproduce the above copyright
 13    * notice, this list of conditions and the following disclaimer in the
 14    * documentation and/or other materials provided with the distribution.
 15    *
 16    * * Neither the name of Jean Tessier nor the names of his contributors
 17    * may be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 24    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31    */
 32   
 33    package com.jeantessier.classreader;
 34   
 35    import java.util.*;
 36   
 37    import junit.framework.*;
 38   
 39    public class TestInstructionWithDifferentConstantPool extends TestCase {
 40    private ClassfileLoader oldLoader;
 41    private ClassfileLoader newLoader;
 42   
 43  3 protected void setUp() throws Exception {
 44  3 super.setUp();
 45   
 46  3 oldLoader = new AggregatingClassfileLoader();
 47  3 oldLoader.load("tests/JarJarDiff/old/ModifiedPackage/DifferentConstantPool.class");
 48   
 49  3 newLoader = new AggregatingClassfileLoader();
 50  3 newLoader.load("tests/JarJarDiff/new/ModifiedPackage/DifferentConstantPool.class");
 51    }
 52   
 53  1 public void testSamePositionInChangedConstantPool() {
 54  1 Classfile oldClassfile = oldLoader.getClassfile("ModifiedPackage.DifferentConstantPool");
 55  1 Method_info oldMethod = oldClassfile.getMethod("DifferentConstantPool()");
 56  1 Code_attribute oldCode = oldMethod.getCode();
 57  1 byte[] oldBytecode = oldCode.getCode();
 58   
 59  1 Classfile newClassfile = newLoader.getClassfile("ModifiedPackage.DifferentConstantPool");
 60  1 Method_info newMethod = newClassfile.getMethod("DifferentConstantPool()");
 61  1 Code_attribute newCode = newMethod.getCode();
 62  1 byte[] newBytecode = newCode.getCode();
 63   
 64  1 assertEquals("Bytecode length", oldBytecode.length, newBytecode.length);
 65   
 66  1 for (int i=0; i<oldBytecode.length; i++) {
 67  5 assertEquals("byte " + i, oldBytecode[i], newBytecode[i]);
 68    }
 69   
 70  1 Iterator<Instruction> oldIterator = oldCode.iterator();
 71  1 Iterator<Instruction> newIterator = newCode.iterator();
 72   
 73  1 Instruction oldInstruction;
 74  1 Instruction newInstruction;
 75   
 76    // Instruction 0: aload_0
 77  1 oldInstruction = oldIterator.next();
 78  1 newInstruction = newIterator.next();
 79  1 assertEquals("aload_0", oldInstruction.getOpcode(), newInstruction.getOpcode());
 80  1 assertEquals("aload_0", oldInstruction, newInstruction);
 81  1 assertEquals("aload_0", oldInstruction.hashCode(), newInstruction.hashCode());
 82   
 83    // Instruction 1: invokespecial
 84  1 oldInstruction = oldIterator.next();
 85  1 newInstruction = newIterator.next();
 86  1 assertEquals("invokespecial", oldInstruction.getOpcode(), newInstruction.getOpcode());
 87  1 assertEquals("invokespecial", oldInstruction, newInstruction);
 88  1 assertEquals("invokespecial", oldInstruction.hashCode(), newInstruction.hashCode());
 89   
 90    // Instruction 2: return
 91  1 oldInstruction = oldIterator.next();
 92  1 newInstruction = newIterator.next();
 93  1 assertEquals("return", oldInstruction.getOpcode(), newInstruction.getOpcode());
 94  1 assertEquals("return", oldInstruction, newInstruction);
 95  1 assertEquals("return", oldInstruction.hashCode(), newInstruction.hashCode());
 96   
 97    // The end
 98  1 assertFalse("Extra instructions", oldIterator.hasNext());
 99  1 assertFalse("Extra instructions", newIterator.hasNext());
 100    }
 101   
 102  1 public void testIndependantOfConstantPool() {
 103  1 Classfile oldClassfile = oldLoader.getClassfile("ModifiedPackage.DifferentConstantPool");
 104  1 Method_info oldMethod = oldClassfile.getMethod("movedMethodRefInfo()");
 105  1 Code_attribute oldCode = oldMethod.getCode();
 106  1 byte[] oldBytecode = oldCode.getCode();
 107   
 108  1 Classfile newClassfile = newLoader.getClassfile("ModifiedPackage.DifferentConstantPool");
 109  1 Method_info newMethod = newClassfile.getMethod("movedMethodRefInfo()");
 110  1 Code_attribute newCode = newMethod.getCode();
 111  1 byte[] newBytecode = newCode.getCode();
 112   
 113  1 assertEquals("Bytecode length", oldBytecode.length, newBytecode.length);
 114   
 115  1 for (int i=0; i<oldBytecode.length; i++) {
 116  1 assertEquals("byte " + i, oldBytecode[i], newBytecode[i]);
 117    }
 118   
 119  1 Iterator<Instruction> oldIterator = oldCode.iterator();
 120  1 Iterator<Instruction> newIterator = newCode.iterator();
 121   
 122  1 Instruction oldInstruction;
 123  1 Instruction newInstruction;
 124   
 125    // Instruction 0: return
 126  1 oldInstruction = oldIterator.next();
 127  1 newInstruction = newIterator.next();
 128  1 assertEquals("return", oldInstruction.getOpcode(), newInstruction.getOpcode());
 129  1 assertEquals("return", oldInstruction, newInstruction);
 130  1 assertEquals("return", oldInstruction.hashCode(), newInstruction.hashCode());
 131   
 132    // The end
 133  1 assertFalse("Extra instructions", oldIterator.hasNext());
 134  1 assertFalse("Extra instructions", newIterator.hasNext());
 135    }
 136   
 137  1 public void testShiftInChangedConstantPool() {
 138  1 Classfile oldClassfile = oldLoader.getClassfile("ModifiedPackage.DifferentConstantPool");
 139  1 Method_info oldMethod = oldClassfile.getMethod("callingMovedMethodRefInfo()");
 140  1 Code_attribute oldCode = oldMethod.getCode();
 141  1 byte[] oldBytecode = oldCode.getCode();
 142   
 143  1 Classfile newClassfile = newLoader.getClassfile("ModifiedPackage.DifferentConstantPool");
 144  1 Method_info newMethod = newClassfile.getMethod("callingMovedMethodRefInfo()");
 145  1 Code_attribute newCode = newMethod.getCode();
 146  1 byte[] newBytecode = newCode.getCode();
 147   
 148  1 assertEquals("Bytecode length", oldBytecode.length, newBytecode.length);
 149   
 150  1 boolean same = oldBytecode.length == newBytecode.length;
 151  1 for (int i=0; same && i<oldBytecode.length; i++) {
 152  4 same = oldBytecode[i] == newBytecode[i];
 153    }
 154  1 assertFalse("Bytes are identical", same);
 155   
 156  1 Iterator<Instruction> oldIterator = oldCode.iterator();
 157  1 Iterator<Instruction> newIterator = newCode.iterator();
 158   
 159  1 Instruction oldInstruction;
 160  1 Instruction newInstruction;
 161   
 162    // Instruction 0: aload_0
 163  1 oldInstruction = oldIterator.next();
 164  1 newInstruction = newIterator.next();
 165  1 assertEquals("aload_0", oldInstruction.getOpcode(), newInstruction.getOpcode());
 166  1 assertEquals("aload_0", oldInstruction, newInstruction);
 167  1 assertEquals("aload_0", oldInstruction.hashCode(), newInstruction.hashCode());
 168   
 169    // Instruction 1: invokevirtual
 170  1 oldInstruction = oldIterator.next();
 171  1 newInstruction = newIterator.next();
 172  1 assertEquals("invokevirtual", oldInstruction.getOpcode(), newInstruction.getOpcode());
 173  1 assertEquals("invokevirtual", oldInstruction, newInstruction);
 174  1 assertEquals("invokevirtual", oldInstruction.hashCode(), newInstruction.hashCode());
 175   
 176    // Instruction 2: return
 177  1 oldInstruction = oldIterator.next();
 178  1 newInstruction = newIterator.next();
 179  1 assertEquals("return", oldInstruction.getOpcode(), newInstruction.getOpcode());
 180  1 assertEquals("return", oldInstruction, newInstruction);
 181  1 assertEquals("return", oldInstruction.hashCode(), newInstruction.hashCode());
 182   
 183    // The end
 184  1 assertFalse("Extra instructions", oldIterator.hasNext());
 185  1 assertFalse("Extra instructions", newIterator.hasNext());
 186    }
 187    }