Package: ConjectureDefinition

ConjectureDefinition

nameinstructionbranchcomplexitylinemethod
ConjectureDefinition(ConjectureDefinition)
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
ConjectureDefinition(String, OperationValidationExpression, IValidationExpression, int)
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
ConjectureDefinition(String, OperationValidationExpression, ValueValidationExpression, IValidationExpression, int)
M: 35 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
ConjectureDefinition(ValueValidationExpression, IValidationExpression, int)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
associateVariable(String[], Value)
M: 30 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
associatedWith(String, String)
M: 24 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getLogFormat()
M: 108 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
getMonitoredValues()
M: 26 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
isPassed()
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
printLogFormat()
M: 93 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
process(String, String, RTMessage.MessageType, long, long, int)
M: 72 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
toString()
M: 48 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
valueChanged(ValueValidationExpression)
M: 53 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /***************************************************************************
2: *
3: *        Copyright (c) 2009 IHA
4: *
5: *        Author: Kenneth Lausdahl and Augusto Ribeiro
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: **************************************************************************/
23:
24: package org.overture.interpreter.runtime.validation;
25:
26: import java.util.ArrayList;
27: import java.util.List;
28:
29: import org.overture.interpreter.messages.rtlog.RTMessage.MessageType;
30: import org.overture.interpreter.scheduler.SystemClock;
31: import org.overture.interpreter.values.Value;
32:
33: public abstract class ConjectureDefinition
34: {
35:
36:         public String name;
37:         public OperationValidationExpression opExpr;
38:         public ValueValidationExpression valueExpr;
39:         public IValidationExpression endingExpr;
40:         public int interval;
41:         private List<ConjectureValue> conjectureValues = new ArrayList<ConjectureValue>();
42:         public boolean startupValue;
43:
44:         public ConjectureDefinition(String name,
45:                         OperationValidationExpression opExpr,
46:                         IValidationExpression endingExpr, int interval)
47:         {
48:                 this.name = name;
49:                 this.opExpr = opExpr;
50:                 this.endingExpr = endingExpr;
51:                 this.valueExpr = null;
52:                 this.interval = interval;
53:         }
54:
55:         public ConjectureDefinition(String name,
56:                         OperationValidationExpression opExpr,
57:                         ValueValidationExpression valueExpr,
58:                         IValidationExpression endingExpr, int interval)
59:         {
60:                 this.name = name;
61:                 this.opExpr = opExpr;
62:                 this.endingExpr = endingExpr;
63:                 this.valueExpr = valueExpr;
64:                 this.interval = interval;
65:
66:•                if (valueExpr != null)
67:                 {
68:                         valueExpr.setConjecture(this);
69:                 }
70:
71:•                if (endingExpr instanceof ValueValidationExpression)
72:                 {
73:                         ((ValueValidationExpression) endingExpr).setConjecture(this);
74:                 }
75:         }
76:
77:         public ConjectureDefinition(ValueValidationExpression valueExpr,
78:                         IValidationExpression endingExpr, int interval)
79:         {
80:                 this.opExpr = null;
81:                 this.endingExpr = endingExpr;
82:                 this.valueExpr = valueExpr;
83:                 this.interval = interval;
84:         }
85:
86:         public ConjectureDefinition(ConjectureDefinition c)
87:         {
88:                 this.opExpr = c.opExpr;
89:                 this.endingExpr = c.endingExpr;
90:                 this.valueExpr = c.valueExpr;
91:                 this.interval = c.interval;
92:         }
93:
94:         abstract public boolean validate(long triggerTime, long endTime);
95:
96:         public List<String[]> getMonitoredValues()
97:         {
98:                 List<String[]> res = new ArrayList<String[]>();
99:
100:•                if (this.valueExpr != null)
101:                 {
102:                         res.addAll(this.valueExpr.getMonitoredValues());
103:                 }
104:
105:•                if (this.endingExpr instanceof ValueValidationExpression)
106:                 {
107:                         res.addAll(((ValueValidationExpression) this.endingExpr).getMonitoredValues());
108:                 }
109:
110:                 return res;
111:         }
112:
113:         public void process(String opname, String classname, MessageType kind,
114:                         long wallTime, long threadId, int objectReference)
115:         {
116:
117:•                if (endingExpr instanceof OperationValidationExpression)
118:                 {
119:                         OperationValidationExpression ove = (OperationValidationExpression) endingExpr;
120:
121:•                        if (ove.matches(opname, classname, kind))
122:                         {
123:•                                for (ConjectureValue conj : conjectureValues)
124:                                 {
125:•                                        if (!conj.isEnded())
126:                                         {
127:                                                 conj.setEnd(wallTime, threadId, objectReference);
128:                                         }
129:                                 }
130:                         }
131:                 }
132:
133:•                if (opExpr.matches(opname, classname, kind))
134:                 {
135:
136:•                        if (valueExpr != null)
137:                         {
138:•                                if (valueExpr.isTrue())
139:                                 {
140:                                         conjectureValues.add(new ConjectureValue(this, wallTime, threadId, objectReference));
141:                                 }
142:                         } else
143:                         {
144:                                 conjectureValues.add(new ConjectureValue(this, wallTime, threadId, objectReference));
145:                         }
146:
147:                 }
148:
149:         }
150:
151:         public boolean associatedWith(String classname, String opname)
152:         {
153:
154:•                if (this.opExpr != null)
155:                 {
156:•                        if (this.opExpr.isAssociatedWith(opname, classname))
157:                         {
158:                                 return true;
159:                         }
160:                 }
161:
162:•                if (endingExpr instanceof OperationValidationExpression)
163:                 {
164:                         return ((OperationValidationExpression) this.endingExpr).isAssociatedWith(opname, classname);
165:                 }
166:
167:                 return false;
168:         }
169:
170:         @Override
171:         public String toString()
172:         {
173:                 StringBuffer s = new StringBuffer();
174:
175:•                if (opExpr != null)
176:                 {
177:                         s.append(opExpr.toString());
178:                         s.append(",");
179:                 }
180:
181:•                if (valueExpr != null)
182:                 {
183:                         s.append(valueExpr.toString());
184:                         s.append(",");
185:                 }
186:
187:                 s.append(endingExpr.toString());
188:                 s.append(",");
189:                 s.append(interval);
190:
191:                 return s.toString();
192:         }
193:
194:         public void associateVariable(String[] strings, Value v)
195:         {
196:•                if (valueExpr != null)
197:                 {
198:•                        if (valueExpr.isValueMonitored(strings))
199:                         {
200:                                 valueExpr.associateVariable(strings, v);
201:                         }
202:
203:                 }
204:
205:•                if (endingExpr instanceof ValueValidationExpression)
206:                 {
207:                         ValueValidationExpression vve = (ValueValidationExpression) endingExpr;
208:•                        if (vve.isValueMonitored(strings))
209:                         {
210:                                 vve.associateVariable(strings, v);
211:                         }
212:                 }
213:
214:         }
215:
216:         public void valueChanged(ValueValidationExpression valueValidationExpression)
217:         {
218:•                if (opExpr == null && valueValidationExpression == valueExpr)
219:                 {
220:•                        if (valueExpr.isTrue())
221:                         {
222:                                 conjectureValues.add(new ConjectureValue(this, SystemClock.getWallTime(), -1, -1));
223:                         }
224:                 } else
225:                 {
226:•                        if (endingExpr instanceof ValueValidationExpression)
227:                         {
228:•                                if (((ValueValidationExpression) endingExpr).isTrue())
229:                                 {
230:•                                        for (ConjectureValue conj : conjectureValues)
231:                                         {
232:•                                                if (!conj.isEnded())
233:                                                 {
234:                                                         conj.setEnd(SystemClock.getWallTime(), -1, -1);
235:                                                 }
236:                                         }
237:                                 }
238:                         }
239:                 }
240:
241:         }
242:
243:         public boolean isPassed()
244:         {
245:•                for (ConjectureValue cv : conjectureValues)
246:                 {
247:•                        if (!cv.isValidated())
248:                         {
249:                                 return false;
250:                         }
251:                 }
252:
253:                 return true;
254:         }
255:
256:         public void printLogFormat()
257:         {
258:                 StringBuffer s = new StringBuffer();
259:                 s.append("\"" + this.name + "\"" + " " + "\"" + this.toString() + "\""
260:                                 + " ");
261:
262:•                if (isPassed())
263:                 {
264:                         s.append("PASS");
265:                         System.out.println(s.toString());
266:                 } else
267:                 {
268:•                        for (ConjectureValue cv : conjectureValues)
269:                         {
270:•                                if (!cv.isValidated())
271:                                 {
272:                                         StringBuffer ts = new StringBuffer(s.toString());
273:
274:                                         ts.append(cv.triggerTime);
275:                                         ts.append(" ");
276:                                         ts.append(cv.triggerThreadId);
277:                                         ts.append(" ");
278:                                         ts.append(cv.endTime);
279:                                         ts.append(" ");
280:                                         ts.append(cv.endThreadId);
281:                                         System.out.println(ts.toString());
282:                                 }
283:
284:                         }
285:                 }
286:
287:         }
288:
289:         public String getLogFormat()
290:         {
291:                 StringBuffer s = new StringBuffer();
292:
293:•                if (isPassed())
294:                 {
295:
296:                         s.append("\"" + this.name + "\"" + " " + "\"" + this.toString()
297:                                         + "\"" + " ");
298:                         s.append("PASS");
299:                         s.append("\n");
300:                 } else
301:                 {
302:•                        for (ConjectureValue cv : conjectureValues)
303:                         {
304:•                                if (!cv.isValidated())
305:                                 {
306:                                         s.append("\"" + this.name + "\"" + " " + "\""
307:                                                         + this.toString() + "\"" + " ");
308:                                         s.append(cv.triggerTime);
309:                                         s.append(" ");
310:                                         s.append(cv.triggerThreadId);
311:                                         s.append(" ");
312:                                         s.append(cv.endTime);
313:                                         s.append(" ");
314:                                         s.append(cv.endThreadId);
315:                                         s.append("\n");
316:                                 }
317:                         }
318:                 }
319:
320:                 return s.toString();
321:         }
322:
323: }