1 package junit.quilt.cover.state;
2
3 import junit.quilt.framework.QuiltCollectorImpl;
4 import junit.quilt.framework.CoverageSegmentImpl;
5
6 import junit.quilt.cover.generic.*;
7
8 import java.util.List;
9
10 public class SimpleStateMachine
11 extends QuiltCollectorImpl
12 implements StateMachineCollector
13 {
14 private static String capabilities[] = {
15 STATEMENT_COVERAGE,
16 BRANCH_COVERAGE };
17
18 private class StateCollector
19 extends StatementSegment
20 {
21 private int state = -1;
22 private int data[][];
23
24 public StateCollector(String sourceFile,
25 BlockVertex bv,
26 int state,
27 int data[][]) {
28 super( sourceFile, bv );
29 this.state = state;
30 this.data = data;
31 }
32
33 public int getNumVisits() {
34 int RC = 0;
35 for (int i = 0; i < data[state].length; i++) {
36 RC += data[state][i];
37 }
38 return RC;
39 }
40 }
41
42 private class TransitionCollector
43 extends CoverageSegmentImpl
44 {
45 private int start = -1;
46 private int end = -1;
47 private int data[][];
48
49 public TransitionCollector(int start,
50 int end,
51 int data[][]) {
52 this.start = start;
53 this.end = end;
54 this.data = data;
55 }
56
57 public int getNumVisits() {
58 return data[start][end];
59 }
60 }
61
62 private String sourceFile = null;
63
64 private boolean valid[][];
65 private int visits[][];
66
67 private StateCollector[] allstates;
68 private TransitionCollector[][] alltrans;
69
70 private int last = -1;
71 private int numStates = -1;
72
73 public SimpleStateMachine( String sourcefile,
74 int numStates ) {
75 super( capabilities );
76 this.sourceFile = sourceFile;
77 valid = new boolean[numStates][numStates];
78 visits = new int[numStates][numStates];
79 this.numStates = numStates;
80
81 allstates = new StateCollector[numStates];
82 alltrans = new TransitionCollector[numStates][numStates];
83
84 }
85
86 public void visit( int state ) {
87 if (last > 0)
88 visits[last][state]++;
89 last = state;
90 }
91
92 public void addState( int state, BlockVertex bv ) {
93 if (allstates[state] == null) {
94 allstates[state] =
95 new StateCollector( sourceFile,
96 bv,
97 state,
98 visits );
99 addSegment( STATEMENT_COVERAGE, allstates[state] );
100 }
101 }
102
103 public void addTransition( int start, int end ) {
104 if (alltrans[start][end] == null) {
105 valid[start][end] = true;
106 alltrans[start][end] =
107 new TransitionCollector( start, end, visits );
108 addSegment( BRANCH_COVERAGE, alltrans[start][end] );
109 }
110 }
111
112 public void start() {}
113
114 public void reset() {
115 for (int i = 0; i < numStates; i++) {
116 for (int j = 0; j < numStates; j++) {
117 visits[i][j] = 0;
118 }
119 }
120 }
121 }
122
123
124
125
126
127
This page was automatically generated by Maven