01: package org.hansel.probes;
02:
03: import org.hansel.Probe;
04: import org.hansel.ProbeData;
05: import org.hansel.stack.HanselValue;
06:
07: /**
08: * A probe for a conditional branch. For decision coverage both possible
09: * conditions for the branch have to be encountered.
10: *
11: * @author Niklas Mehner.
12: */
13: public abstract class BranchProbe extends Probe {
14: /** Wether the branch has been executed with the condition beeing true. */
15: private boolean coverTrue;
16:
17: /** Wether the branch has been executed with the condition beeing false. */
18: private boolean coverFalse;
19:
20: private HanselValue value;
21:
22: public BranchProbe(ProbeData pd, HanselValue value) {
23: super (pd);
24:
25: this .value = value;
26: this .coverTrue = false;
27: this .coverFalse = false;
28: }
29:
30: /**
31: * Return the filure message for this probe.
32: * @return Failure message.
33: */
34: public String getFailureMessage() {
35: String expression;
36: if (coverTrue) {
37: expression = value.invert().toString();
38: } else {
39: expression = value.toString();
40: }
41:
42: String result = "Branch not completely covered. Condition '"
43: + expression + "' is not fulfilled.";
44:
45: return result;
46: }
47:
48: protected void cover(boolean condition) {
49: if (condition) {
50: coverTrue = true;
51: } else {
52: coverFalse = true;
53: }
54: }
55:
56: /**
57: * Return wether this probe failed to be covered.
58: * A probe for a conditional branch fails, if the branch is only taken,
59: * or only omitted. If both cases are encountered, the probe is fully
60: * covered. If the probe is not executed at all, this method still returns
61: * false, because in that case, another probe has to fail (otherwise this
62: * probe had been reached). Because the other failure is more important,
63: * the result of this probe is left out in this case.
64: * @return true If covering this probe failed.
65: */
66: public boolean displayFailure() {
67: return coverTrue ^ coverFalse;
68: }
69:
70: public boolean coverageFailure() {
71: return !(coverTrue & coverFalse);
72: }
73:
74: }
|