01: package org.hansel.probes;
02:
03: import org.hansel.ProbeData;
04: import org.hansel.stack.EqOp;
05: import org.hansel.stack.HanselValue;
06: import org.hansel.stack.NeOp;
07: import org.objectweb.asm.MethodVisitor;
08: import org.objectweb.asm.Opcodes;
09:
10: /**
11: * A probe for a comparing conditional branch. For decision coverage both
12: * possible conditions for the branch have to be encountered.
13: *
14: * @author Niklas Mehner.
15: */
16: public class ACmpBranchProbe extends BranchProbe {
17: /** Wether the compared references should be equal. */
18: private boolean equal;
19:
20: public ACmpBranchProbe(ProbeData pd, boolean equal) {
21: super (pd, getStackEntry(pd.getStackEntry(0), pd
22: .getStackEntry(1), equal));
23:
24: this .equal = equal;
25: }
26:
27: private static HanselValue getStackEntry(HanselValue stackEntry0,
28: HanselValue stackEntry1, boolean equal) {
29:
30: if (equal) {
31: return new EqOp(stackEntry1, stackEntry0);
32: } else {
33: return new NeOp(stackEntry1, stackEntry0);
34: }
35: }
36:
37: /**
38: * Called, when a probe is hit.
39: * @param obj1 First object to be compared.
40: * @param obj2 Second object to be compared.
41: */
42: public void hit(Object obj1, Object obj2) {
43: cover((obj1 == obj2) == equal);
44: }
45:
46: /**
47: * Returns the code of the probe.
48: * @param cp ConstantPool all names of methods etc. have to be
49: * inserted.
50: * @return List of instructions to call this probe.
51: */
52: public void insertProbeCode(MethodVisitor cv) {
53: cv.visitInsn(Opcodes.DUP2);
54: cv.visitLdcInsn(new Integer(getID()));
55: cv
56: .visitMethodInsn(Opcodes.INVOKESTATIC, HIT_CLASS,
57: "hitBranch",
58: "(Ljava/lang/Object;Ljava/lang/Object;I)V");
59: }
60: }
|