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: import org.objectweb.asm.Type;
10:
11: /**
12: * A probe for a comparing conditional branch. For decision coverage both
13: * possible conditions for the branch have to be encountered.
14: *
15: * @author Niklas Mehner.
16: */
17: public class NullCmpBranchProbe extends BranchProbe {
18: private static final Type NULL_TYPE = Type.getType("LNULL;");
19: /** Wether the compared references should be equal. */
20: private boolean equal;
21:
22: public NullCmpBranchProbe(ProbeData pd, boolean equal) {
23: super (pd, getStackEntry(pd.getStackEntry(0), equal));
24:
25: this .equal = equal;
26: }
27:
28: private static HanselValue getStackEntry(HanselValue stackEntry,
29: boolean equal) {
30: if (equal) {
31: return new EqOp(stackEntry, HanselValue.NULL);
32: } else {
33: return new NeOp(stackEntry, HanselValue.NULL);
34: }
35: }
36:
37: /**
38: * Called, when a probe is hit.
39: * @param obj Object to be compared.
40: */
41: public void hit(Object obj) {
42: cover((obj != null) ^ equal);
43: }
44:
45: public void insertProbeCode(MethodVisitor cv) {
46: cv.visitInsn(Opcodes.DUP);
47: cv.visitLdcInsn(new Integer(getID()));
48: cv.visitMethodInsn(Opcodes.INVOKESTATIC, HIT_CLASS,
49: "hitBranch", "(Ljava/lang/Object;I)V");
50: }
51: }
|