Changeset 1294 for trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeChecker.java
- Timestamp:
- 08/14/13 17:04:42 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeChecker.java
r1146 r1294 20 20 import java.util.HashMap; 21 21 import java.util.Iterator; 22 import java.util.LinkedList; 22 23 import java.util.List; 23 24 import java.util.Map; … … 27 28 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 28 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 29 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 30 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 31 35 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 32 36 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; … … 70 74 * 71 75 */ 72 public void assert TaskInstanceList(String userSessionSpec, ITaskInstanceList taskInstances) {76 public void assertUserSession(String userSessionSpec, IUserSession session) { 73 77 if (doTrace) { 74 new TaskTreeEncoder().encode( taskInstances, System.err);78 new TaskTreeEncoder().encode(session, System.err); 75 79 } 76 80 … … 86 90 87 91 if (taskInstanceSpec != null) { 88 assertTaskInstanceList(taskInstanceSpec, taskInstances, tasks); 92 assertUserSession(taskInstanceSpec, session, tasks); 93 } 94 } 95 } 96 97 /** 98 * 99 */ 100 public void assertTaskInstance(String userSessionSpec, ITaskInstance taskInstance) { 101 if (doTrace) { 102 new TaskTreeEncoder().encode(taskInstance, System.err); 103 } 104 105 TaskSpec taskInstanceSpec = null; 106 107 Matcher taskMatcher = taskPattern.matcher(userSessionSpec); 108 109 Map<String, ITask> tasks = new HashMap<String, ITask>(); 110 111 while (taskMatcher.find()) { 112 113 taskInstanceSpec = parseTaskInstance(taskMatcher); 114 115 if (taskInstanceSpec != null) { 116 assertTaskInstance(taskInstanceSpec, taskInstance, tasks); 89 117 } 90 118 } … … 154 182 } 155 183 156 List<ITaskInstance> expectedChildren = expected.getChildren();157 List<ITaskInstance> checkedChildren = checked.getChildren();184 List<ITaskInstance> expectedChildren = getChildren(expected); 185 List<ITaskInstance> checkedChildren = getChildren(checked); 158 186 159 187 if ((expectedChildren != null) && (expectedChildren.size() > 0)) { … … 241 269 * @param taskMapCopy 242 270 */ 243 private void assert TaskInstanceList(TaskSpec taskSpec,244 ITaskInstanceList taskInstances,245 271 private void assertUserSession(TaskSpec taskSpec, 272 IUserSession session, 273 Map<String, ITask> tasks) 246 274 { 247 275 if (doTrace) { 248 System.err.println("\ncomparing " + taskSpec.type + " with " + taskInstances+ "\n");249 } 250 251 if ( (taskInstances instanceof IUserSession) && (!"UserSession".equals(taskSpec.type))) {276 System.err.println("\ncomparing " + taskSpec.type + " with " + session + "\n"); 277 } 278 279 if (!"UserSession".equals(taskSpec.type)) { 252 280 fail("can not compare a task instance with a user session"); 253 281 } 254 else if ((!(taskInstances instanceof IUserSession)) && 255 (!"TaskInstances".equals(taskSpec.type))) 256 { 282 283 List<ITaskInstance> children = session.getExecutedTasks(); 284 285 if (taskSpec.children.length != children.size()) { 286 fail("number of task instances in task instance list does not match"); 287 } 288 289 for (int i = 0; i < children.size(); i++) { 290 TaskSpec childSpec = taskSpec.children[i]; 291 assertTrue(taskSpecEqualsTaskInstance(childSpec, children.get(i), tasks)); 292 } 293 } 294 295 /** 296 * @param task 297 * @param taskMapCopy 298 */ 299 private void assertTaskInstance(TaskSpec taskSpec, 300 ITaskInstance taskInstance, 301 Map<String, ITask> tasks) 302 { 303 if (doTrace) { 304 System.err.println("\ncomparing " + taskSpec.type + " with " + taskInstance + "\n"); 305 } 306 307 if (!"TaskInstances".equals(taskSpec.type)) { 257 308 fail("can not compare a task instance with a task instance list"); 258 309 } 259 310 260 if (taskSpec.children.length != taskInstances.size()) { 311 List<ITaskInstance> children = getChildren(taskInstance); 312 313 if (taskSpec.children.length != children.size()) { 261 314 fail("number of task instances in task instance list does not match"); 262 315 } 263 316 264 for (int i = 0; i < taskInstances.size(); i++) {317 for (int i = 0; i < children.size(); i++) { 265 318 TaskSpec childSpec = taskSpec.children[i]; 266 assertTrue(taskSpecEqualsTaskInstance(childSpec, taskInstances.get(i), tasks));319 assertTrue(taskSpecEqualsTaskInstance(childSpec, children.get(i), tasks)); 267 320 } 268 321 } … … 284 337 if (("Event".equals(taskSpec.type) && (!(task instanceof IEventTask))) || 285 338 ("TextInputEvent".equals(taskSpec.type) && 286 ((!(task instanceof IEventTask)) ||287 (!(((IEventTask ) task).getEventType() instanceof TextInput)))) ||339 ((!(taskInstance instanceof IEventTaskInstance)) || 340 (!(((IEventTaskInstance) taskInstance).getEvent().getType() instanceof TextInput)))) || 288 341 ("Sequence".equals(taskSpec.type) && (!(task instanceof ISequence))) || 289 342 ("Selection".equals(taskSpec.type) && (!(task instanceof ISelection))) || … … 306 359 307 360 if ("TextInputEvent".equals(taskSpec.type)) { 308 TextInput eventType = (TextInput) ((IEventTask) task).getEventType(); 361 TextInput eventType = (TextInput) 362 ((IEventTaskInstance) taskInstance).getEvent().getType(); 363 309 364 if ((taskSpec.additionalInfo != null) && 310 365 !"".equals(taskSpec.additionalInfo) && … … 319 374 } 320 375 } 321 else if ((task instanceof IEventTask) && (((IEventTask) task).getEventType() != null) && 322 (!taskSpec.name.equals(((IEventTask) task).getEventType().getName()))) 376 else if ((task instanceof IEventTask) && 377 (((IEventTaskInstance) taskInstance).getEvent().getType() != null) && 378 (!taskSpec.name.equals(((IEventTaskInstance) taskInstance).getEvent().getType().getName()))) 323 379 { 324 380 // simple event names do not match. But what about the event name in … … 328 384 (!"".equals(taskSpec.additionalInfo) ? " " + taskSpec.additionalInfo : ""); 329 385 330 if (!complexName.equals(((IEventTask ) task).getEventType().getName())) {386 if (!complexName.equals(((IEventTaskInstance) taskInstance).getEvent().getType().getName())) { 331 387 if (doTrace) { 332 System.err.println("event names do not match: " + taskSpec.name + " != " + 333 ((IEventTask) task).getEventType().getName() + "\n"); 388 System.err.println 389 ("event names do not match: " + taskSpec.name + " != " + 390 ((IEventTaskInstance) taskInstance).getEvent().getType().getName() + "\n"); 334 391 } 335 392 return false; … … 358 415 } 359 416 360 if (((taskSpec.children == null) && (taskInstance.getChildren().size() > 0)) || 417 List<ITaskInstance> children = getChildren(taskInstance); 418 419 if (((taskSpec.children == null) && (children.size() > 0)) || 361 420 ((taskSpec.children != null) && 362 (taskSpec.children.length != taskInstance.getChildren().size())))421 (taskSpec.children.length != children.size()))) 363 422 { 364 423 if (doTrace) { … … 366 425 ("numbers of children do not match: " + 367 426 (taskSpec.children == null ? "0" : taskSpec.children.length) + " != " + 368 (taskInstance.getChildren() == null ? "0" : 369 taskInstance.getChildren().size()) + "\n"); 427 (children == null ? "0" : children.size()) + "\n"); 370 428 } 371 429 return false; 372 430 } 373 431 374 Iterator<ITaskInstance> children = taskInstance.getChildren().iterator();432 Iterator<ITaskInstance> childrenIterator = children.iterator(); 375 433 if (taskSpec.children != null) { 376 434 for (TaskSpec child : taskSpec.children) { 377 if (!taskSpecEqualsTaskInstance(child, children .next(), tasks)) {435 if (!taskSpecEqualsTaskInstance(child, childrenIterator.next(), tasks)) { 378 436 if (doTrace) { 379 437 System.err.println("one of the children does not match\n"); … … 384 442 } 385 443 386 if (!children .hasNext()) {444 if (!childrenIterator.hasNext()) { 387 445 if (doTrace) { 388 446 System.err.println("nodes match\n"); … … 398 456 } 399 457 458 /** 459 * <p> 460 * TODO: comment 461 * </p> 462 * 463 * @param taskInstance 464 * @return 465 */ 466 private List<ITaskInstance> getChildren(ITaskInstance taskInstance) { 467 List<ITaskInstance> result = new LinkedList<ITaskInstance>(); 468 469 if (taskInstance instanceof ITaskInstanceList) { 470 for (ITaskInstance child : (ITaskInstanceList) taskInstance) { 471 result.add(child); 472 } 473 } 474 else if (taskInstance instanceof ISelectionInstance) { 475 result.add(((ISelectionInstance) taskInstance).getChild()); 476 } 477 else if (taskInstance instanceof IOptionalInstance) { 478 result.add(((IOptionalInstance) taskInstance).getChild()); 479 } 480 481 return result; 482 } 483 400 484 /** 401 485 *
Note: See TracChangeset
for help on using the changeset viewer.