Changeset 557 for trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/TaskTreeChecker.java
- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/TaskTreeChecker.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeChecker.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 01.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.testutils; 9 8 … … 21 20 import java.util.regex.Pattern; 22 21 23 import de.ugoe.cs.quest. tasktrees.treeifc.InteractionTask;24 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;25 import de.ugoe.cs.quest.tasktrees.treeifc. NodeInfo;26 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;27 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;28 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTree;29 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;30 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;31 32 //------------------------------------------------------------------------------------------------- 22 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 23 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 24 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 25 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeInfo; 26 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 27 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 28 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 29 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 30 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 31 33 32 /** 34 33 * TODO comment … … 37 36 * @author 2012, last modified by $Author: patrick$ 38 37 */ 39 //------------------------------------------------------------------------------------------------- 40 public class TaskTreeChecker 41 { 42 /** */ 43 private boolean mDoTrace; 44 45 //----------------------------------------------------------------------------------------------- 46 /** 47 * TODO: comment 38 public class TaskTreeChecker { 39 40 /** */ 41 private boolean doTrace; 42 43 /** 44 * TODO: comment 45 * 46 */ 47 public TaskTreeChecker() { 48 this(false); 49 } 50 51 /** 52 * TODO: comment 53 * 54 */ 55 public TaskTreeChecker(boolean doTrace) { 56 this.doTrace = doTrace; 57 } 58 59 /** 60 * 61 */ 62 public void assertTaskTree(String taskTreeSpec, ITaskTree taskTree) { 63 Map<ITaskTreeNode, Integer> taskMapCopy = new HashMap<ITaskTreeNode, Integer>(); 64 65 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : taskTree.getTaskMap().entrySet()) { 66 if (entry.getValue().getNoOfOccurencesInTree() > 0) { 67 taskMapCopy.put(entry.getKey(), entry.getValue().getNoOfOccurencesInTree()); 68 } 69 else { 70 taskMapCopy.put(entry.getKey(), 1); 71 } 72 } 73 74 if (doTrace) { 75 dumpTaskMap(taskMapCopy); 76 } 77 78 TaskSpec task = null; 79 80 Matcher matcher = Pattern.compile 81 ("(\\s*(\\w+)\\s+(\\w+)\\s+((\\w*\\s)*)(\\{))|((\\}))").matcher(taskTreeSpec); 82 83 do { 84 if (!matcher.find()) { 85 if (!matcher.hitEnd()) { 86 throw new IllegalArgumentException("could not parse task specification"); 87 } 88 else { 89 break; 90 } 91 } 92 93 task = parseTask(matcher); 94 if (task != null) { 95 assertTaskAndChildrenInMapAndRemove(task, taskMapCopy); 96 } 97 } 98 while (task != null); 99 100 assertTrue("more tasks in map, than expected", taskMapCopy.isEmpty()); 101 } 102 103 /** 104 * TODO: comment 105 * 106 * @param taskTree 107 */ 108 public void dumpAsCheckString(ITaskTree taskTree) { 109 dumpNodeAsCheckString(taskTree.getRoot(), new int[4], ""); 110 } 111 112 /** 113 * TODO: comment 114 * 115 * @param root 116 * @param string 117 */ 118 private void dumpNodeAsCheckString(ITaskTreeNode node, int[] typeCounters, String indent) { 119 System.err.print(" \""); 120 System.err.print(indent); 121 122 if (node instanceof ISequence) { 123 System.err.print("Sequence sequence"); 124 System.err.print(typeCounters[0]++); 125 System.err.println(" {\" +"); 126 } 127 else if (node instanceof IIteration) { 128 System.err.print("Iteration iteration"); 129 System.err.print(typeCounters[1]++); 130 System.err.println(" {\" +"); 131 } 132 else if (node instanceof ISelection) { 133 System.err.print("Selection selection"); 134 System.err.print(typeCounters[2]++); 135 System.err.println(" {\" +"); 136 } 137 else if (node instanceof ITextInputEventTask) { 138 System.err.print("TextInputEvent textInput"); 139 System.err.print(typeCounters[3]++); 140 System.err.print(" "); 141 System.err.print(((ITextInputEventTask) node).getEnteredText()); 142 System.err.println(" {\" +"); 143 } 144 else if (node instanceof IEventTask) { 145 System.err.print("Event "); 146 System.err.print(((IEventTask) node).getEventType().getName()); 147 System.err.print(" {}\" +"); 148 } 149 else { 150 fail("unknown type of node in task tree " + node); 151 } 152 153 for (ITaskTreeNode child : node.getChildren()) { 154 dumpNodeAsCheckString(child, typeCounters, indent + " "); 155 } 156 157 if (!(node instanceof IEventTask) || (node instanceof ITextInputEventTask)) { 158 System.err.print(" \""); 159 System.err.print(indent); 160 System.err.print("}\" +"); 161 } 162 163 System.err.println(); 164 } 165 166 /** 167 * TODO: comment 168 * 169 * @param taskTree 170 */ 171 public void dumpFullTaskTree(ITaskTree taskTree) throws FileNotFoundException { 172 PrintWriter out = null; 173 try { 174 out = new PrintWriter(new FileOutputStream("taskTree.txt")); 175 dumpFullNode(taskTree.getRoot(), out, ""); 176 } 177 finally { 178 if (out != null) { 179 out.close(); 180 } 181 } 182 183 } 184 185 /** 186 * 187 */ 188 private void dumpFullNode(ITaskTreeNode node, PrintWriter out, String indent) { 189 out.print(indent); 190 if (node instanceof ISequence) { 191 out.println("Sequence"); 192 out.print(indent); 193 out.println("{"); 194 } 195 else if (node instanceof IIteration) { 196 out.println("Iteration"); 197 out.print(indent); 198 out.println("{"); 199 } 200 else if (node instanceof ISelection) { 201 out.println("Selection"); 202 out.print(indent); 203 out.println("{"); 204 } 205 else if (node instanceof ITextInputEventTask) { 206 out.print("TextInputEvent"); 207 out.print(" "); 208 out.println(((ITextInputEventTask) node).getEnteredText()); 209 out.print(indent); 210 out.println("{"); 211 } 212 else if (node instanceof IEventTask) { 213 out.print(((IEventTask) node).getEventType().getName()); 214 out.print(" "); 215 out.print(((IEventTask) node).getEventTarget()); 216 if (((IEventTask) node).getEventTarget() instanceof IGUIElement) 217 { 218 out.print(" "); 219 out.print(((IGUIElement) ((IEventTask) node).getEventTarget()).getOriginalTypeInfo()); 220 } 221 } 222 else { 223 fail("unknown type of node in task tree " + node); 224 } 225 226 for (ITaskTreeNode child : node.getChildren()) { 227 dumpFullNode(child, out, indent + " "); 228 } 229 230 if (!(node instanceof IEventTask) || (node instanceof ITextInputEventTask)) { 231 out.print(indent); 232 out.print("}"); 233 } 234 235 out.println(); 236 } 237 238 /** 239 * 240 */ 241 private TaskSpec parseTask(Matcher tokenMatcher) { 242 String firstToken = tokenMatcher.group(); 243 244 if ("}".equals(firstToken)) { 245 throw new IllegalArgumentException("found a closing bracket at an unexpected place"); 246 } 247 248 TaskSpec task = new TaskSpec(); 249 task.type = tokenMatcher.group(2); 250 task.name = tokenMatcher.group(3); 251 task.additionalInfo = tokenMatcher.group(4).trim(); 252 253 if ("".equals(task.name)) { 254 task.name = null; 255 } 256 257 if (!tokenMatcher.find()) { 258 throw new IllegalArgumentException("could not parse task specification"); 259 } 260 261 firstToken = tokenMatcher.group(); 262 263 if (!"}".equals(firstToken)) { 264 ArrayList<TaskSpec> children = new ArrayList<TaskSpec>(); 265 266 TaskSpec child = null; 267 268 do { 269 child = parseTask(tokenMatcher); 270 271 if (child != null) { 272 children.add(child); 273 274 if (!tokenMatcher.find()) { 275 throw new IllegalArgumentException("could not parse task specification"); 276 } 277 278 firstToken = tokenMatcher.group(); 279 280 if ("}".equals(firstToken)) { 281 break; 282 } 283 } 284 285 } 286 while (child != null); 287 288 task.children = children.toArray(new TaskSpec[children.size()]); 289 } 290 291 return task; 292 } 293 294 /** 295 * @param task 296 * @param taskMapCopy 297 */ 298 private void assertTaskAndChildrenInMapAndRemove(TaskSpec task, 299 Map<ITaskTreeNode, Integer> taskMap) 300 { 301 for (Map.Entry<ITaskTreeNode, Integer> entry : taskMap.entrySet()) { 302 if (taskSpecEqualsTask(task, entry.getKey())) { 303 if (task.children != null) { 304 for (TaskSpec child : task.children) { 305 assertTaskAndChildrenInMapAndRemove(child, taskMap); 306 } 307 } 308 309 int count = taskMap.get(entry.getKey()); 310 if (count == 1) { 311 taskMap.remove(entry.getKey()); 312 } 313 else { 314 taskMap.put(entry.getKey(), count - 1); 315 } 316 return; 317 } 318 } 319 320 fail("expected task " + task.type + " " + task.name + 321 " not included in task map"); 322 } 323 324 /** 325 * 326 */ 327 private boolean taskSpecEqualsTask(TaskSpec taskSpec, ITaskTreeNode task) { 328 if (doTrace) { 329 System.err.println("comparing " + taskSpec.name + " with"); 330 dumpTask(task, 0, ""); 331 } 332 333 if (("Event".equals(taskSpec.type) && (!(task instanceof IEventTask))) || 334 ("TextInputEvent".equals(taskSpec.type) && (!(task instanceof ITextInputEventTask))) || 335 ("Sequence".equals(taskSpec.type) && (!(task instanceof ISequence))) || 336 ("Selection".equals(taskSpec.type) && (!(task instanceof ISelection))) || 337 ("Iteration".equals(taskSpec.type) && (!(task instanceof IIteration)))) 338 { 339 if (doTrace) { 340 System.err.println("task types do not match: " + taskSpec.type + " != " + 341 task.getClass().getSimpleName() + "\n"); 342 } 343 return false; 344 } 345 else if (!"Event".equals(taskSpec.type) && 346 !"TextInputEvent".equals(taskSpec.type) && 347 !"Sequence".equals(taskSpec.type) && 348 !"Selection".equals(taskSpec.type) && 349 !"Iteration".equals(taskSpec.type)) 350 { 351 fail("unknown task type " + taskSpec.type + " --> please extend test case"); 352 } 353 354 if ("TextInputEvent".equals(taskSpec.type)) { 355 if (!"".equals(taskSpec.additionalInfo) && 356 !(taskSpec.additionalInfo.equals(((ITextInputEventTask) task).getEnteredText()))) 357 { 358 if (doTrace) { 359 System.err.println("expected text \"" + taskSpec.additionalInfo + 360 "\" is not equal to the text " + "provided by the task \"" + 361 ((ITextInputEventTask) task).getEnteredText() + "\"\n"); 362 } 363 return false; 364 } 365 } 366 else if ((task instanceof IEventTask) && (((IEventTask) task).getEventType() != null) && 367 (!taskSpec.name.equals(((IEventTask) task).getEventType().getName()))) 368 { 369 // simple event names do not match. But what about the event name in 370 // combination with the additional info 371 String complexName = 372 taskSpec.name + 373 (!"".equals(taskSpec.additionalInfo) ? " " + taskSpec.additionalInfo : ""); 374 375 if (!complexName.equals(((IEventTask) task).getEventType().getName())) { 376 if (doTrace) { 377 System.err.println("event names do not match: " + taskSpec.name + " != " + 378 ((IEventTask) task).getEventType().getName() + "\n"); 379 } 380 return false; 381 } 382 } 383 384 if (((taskSpec.children == null) && (task.getChildren().size() > 0)) || 385 ((taskSpec.children != null) && (taskSpec.children.length != task.getChildren().size()))) 386 { 387 if (doTrace) { 388 System.err.println 389 ("numbers of children do not match: " + 390 (taskSpec.children == null ? "0" : taskSpec.children.length) + " != " + 391 (task.getChildren() == null ? "0" : task.getChildren().size()) + "\n"); 392 } 393 return false; 394 } 395 396 Iterator<ITaskTreeNode> children = task.getChildren().iterator(); 397 if (taskSpec.children != null) { 398 for (TaskSpec child : taskSpec.children) { 399 if (!taskSpecEqualsTask(child, children.next())) { 400 if (doTrace) { 401 System.err.println("one of the children does not match\n"); 402 } 403 return false; 404 } 405 } 406 } 407 408 if (!children.hasNext()) { 409 if (doTrace) { 410 System.err.println("nodes match\n"); 411 } 412 return true; 413 } 414 else { 415 if (doTrace) { 416 System.err.println("number of children does not match\n"); 417 } 418 return false; 419 } 420 } 421 422 /** 48 423 * 49 424 */ 50 //-----------------------------------------------------------------------------------------------51 public TaskTreeChecker()52 {53 this(false);54 }55 56 //-----------------------------------------------------------------------------------------------57 /** 58 * TODO: comment425 private void dumpTaskMap(Map<ITaskTreeNode, Integer> taskMap) { 426 System.err.println(); 427 for (Map.Entry<ITaskTreeNode, Integer> entry : taskMap.entrySet()) { 428 dumpTask(entry.getKey(), entry.getValue(), ""); 429 System.err.println(); 430 } 431 } 432 433 /** 59 434 * 60 435 */ 61 //----------------------------------------------------------------------------------------------- 62 public TaskTreeChecker(boolean doTrace) 63 { 64 mDoTrace = doTrace; 65 } 66 67 //----------------------------------------------------------------------------------------------- 68 /** 69 * 70 */ 71 //----------------------------------------------------------------------------------------------- 72 public void assertTaskTree(String taskTreeSpec, TaskTree taskTree) 73 { 74 Map<TaskTreeNode, Integer> taskMapCopy = new HashMap<TaskTreeNode, Integer>(); 75 76 for (Map.Entry<TaskTreeNode, NodeInfo> entry : taskTree.getTaskMap().entrySet()) 77 { 78 if (entry.getValue().getNoOfOccurencesInTree() > 0) 79 { 80 taskMapCopy.put(entry.getKey(), entry.getValue().getNoOfOccurencesInTree()); 81 } 82 else 83 { 84 taskMapCopy.put(entry.getKey(), 1); 85 } 86 } 87 88 if (mDoTrace) 89 { 90 dumpTaskMap(taskMapCopy); 91 } 92 93 TaskSpec task = null; 94 95 Matcher matcher = 96 Pattern.compile("(\\s*(\\w+)\\s+(\\w+)\\s+((\\w*\\s)*)(\\{))|((\\}))").matcher(taskTreeSpec); 97 98 do 99 { 100 if (!matcher.find()) 101 { 102 if (!matcher.hitEnd()) 103 { 104 throw new IllegalArgumentException("could not parse task specification"); 105 } 106 else 107 { 108 break; 109 } 110 } 111 112 task = parseTask(matcher); 113 if (task != null) 114 { 115 assertTaskAndChildrenInMapAndRemove(task, taskMapCopy); 116 } 117 } 118 while (task != null); 119 120 assertTrue("more tasks in map, than expected", taskMapCopy.isEmpty()); 121 } 122 123 //----------------------------------------------------------------------------------------------- 124 /** 125 * TODO: comment 126 * 127 * @param taskTree 128 */ 129 //----------------------------------------------------------------------------------------------- 130 public void dumpAsCheckString(TaskTree taskTree) 131 { 132 dumpNodeAsCheckString(taskTree.getRoot(), new int[4], ""); 133 } 134 135 //----------------------------------------------------------------------------------------------- 136 /** 137 * TODO: comment 138 * 139 * @param root 140 * @param string 141 */ 142 //----------------------------------------------------------------------------------------------- 143 private void dumpNodeAsCheckString(TaskTreeNode node, 144 int[] typeCounters, 145 String indent) 146 { 147 System.err.print(" \""); 148 System.err.print(indent); 149 150 if (node instanceof Sequence) 151 { 152 System.err.print("Sequence sequence"); 153 System.err.print(typeCounters[0]++); 154 System.err.println(" {\" +"); 155 } 156 else if (node instanceof Iteration) 157 { 158 System.err.print("Iteration iteration"); 159 System.err.print(typeCounters[1]++); 160 System.err.println(" {\" +"); 161 } 162 else if (node instanceof Selection) 163 { 164 System.err.print("Selection selection"); 165 System.err.print(typeCounters[2]++); 166 System.err.println(" {\" +"); 167 } 168 else if (node instanceof TextInputInteractionTask) 169 { 170 System.err.print("TextInputInteraction textInput"); 171 System.err.print(typeCounters[3]++); 172 System.err.print(" "); 173 System.err.print(((TextInputInteractionTask) node).getEnteredText()); 174 System.err.println(" {\" +"); 175 } 176 else if (node instanceof InteractionTask) 177 { 178 System.err.print("Interaction "); 179 System.err.print(((InteractionTask) node).getInteraction().getName()); 180 System.err.print(" {}\" +"); 181 } 182 else 183 { 184 fail("unknown type of node in task tree " + node); 185 } 186 187 for (TaskTreeNode child : node.getChildren()) 188 { 189 dumpNodeAsCheckString(child, typeCounters, indent + " "); 190 } 191 192 if (!(node instanceof InteractionTask) || 193 (node instanceof TextInputInteractionTask)) 194 { 195 System.err.print(" \""); 196 System.err.print(indent); 197 System.err.print("}\" +"); 198 } 199 200 System.err.println(); 201 } 202 203 //----------------------------------------------------------------------------------------------- 204 /** 205 * TODO: comment 206 * 207 * @param taskTree 208 */ 209 //----------------------------------------------------------------------------------------------- 210 public void dumpFullTaskTree(TaskTree taskTree) throws FileNotFoundException 211 { 212 PrintWriter out = null; 213 try 214 { 215 out = new PrintWriter(new FileOutputStream("taskTree.txt")); 216 dumpFullNode(taskTree.getRoot(), out, ""); 217 } 218 finally 219 { 220 if (out != null) 221 { 222 out.close(); 223 } 224 } 225 226 } 227 228 //----------------------------------------------------------------------------------------------- 229 /** 230 * 231 */ 232 //----------------------------------------------------------------------------------------------- 233 private void dumpFullNode(TaskTreeNode node, PrintWriter out, String indent) 234 { 235 out.print(indent); 236 if (node instanceof Sequence) 237 { 238 out.println("Sequence"); 239 out.print(indent); 240 out.println("{"); 241 } 242 else if (node instanceof Iteration) 243 { 244 out.println("Iteration"); 245 out.print(indent); 246 out.println("{"); 247 } 248 else if (node instanceof Selection) 249 { 250 out.println("Selection"); 251 out.print(indent); 252 out.println("{"); 253 } 254 else if (node instanceof TextInputInteractionTask) 255 { 256 out.print("TextInputInteraction"); 257 out.print(" "); 258 out.println(((TextInputInteractionTask) node).getEnteredText()); 259 out.print(indent); 260 out.println("{"); 261 } 262 else if (node instanceof InteractionTask) 263 { 264 out.print(((InteractionTask) node).getInteraction().getName()); 265 out.print(" "); 266 out.print(((InteractionTask) node).getGUIElement()); 267 out.print(" "); 268 out.print(((InteractionTask) node).getGUIElement().getOriginalTypeInfo()); 269 } 270 else 271 { 272 fail("unknown type of node in task tree " + node); 273 } 274 275 for (TaskTreeNode child : node.getChildren()) 276 { 277 dumpFullNode(child, out, indent + " "); 278 } 279 280 if (!(node instanceof InteractionTask) || 281 (node instanceof TextInputInteractionTask)) 282 { 283 out.print(indent); 284 out.print("}"); 285 } 286 287 out.println(); 288 } 289 290 //----------------------------------------------------------------------------------------------- 291 /** 292 * 293 */ 294 //----------------------------------------------------------------------------------------------- 295 private TaskSpec parseTask(Matcher tokenMatcher) 296 { 297 String firstToken = tokenMatcher.group(); 298 299 if ("}".equals(firstToken)) 300 { 301 throw new IllegalArgumentException("found a closing bracket at an unexpected place"); 302 } 303 304 TaskSpec task = new TaskSpec(); 305 task.type = tokenMatcher.group(2); 306 task.interactionName = tokenMatcher.group(3); 307 task.additionalInfo = tokenMatcher.group(4).trim(); 308 309 if ("".equals(task.interactionName)) 310 { 311 task.interactionName = null; 312 } 313 314 if (!tokenMatcher.find()) 315 { 316 throw new IllegalArgumentException("could not parse task specification"); 317 } 318 319 firstToken = tokenMatcher.group(); 320 321 if (!"}".equals(firstToken)) 322 { 323 ArrayList<TaskSpec> children = new ArrayList<TaskSpec>(); 324 325 TaskSpec child = null; 326 327 do 328 { 329 child = parseTask(tokenMatcher); 330 331 if (child != null) 332 { 333 children.add(child); 334 335 if (!tokenMatcher.find()) 336 { 337 throw new IllegalArgumentException("could not parse task specification"); 338 } 339 340 firstToken = tokenMatcher.group(); 341 342 if ("}".equals(firstToken)) 343 { 344 break; 345 } 346 } 347 348 } 349 while (child != null); 350 351 task.children = children.toArray(new TaskSpec[children.size()]); 352 } 353 354 return task; 355 } 356 357 //----------------------------------------------------------------------------------------------- 358 /** 359 * @param task 360 * @param taskMapCopy 361 */ 362 //----------------------------------------------------------------------------------------------- 363 private void assertTaskAndChildrenInMapAndRemove(TaskSpec task, 364 Map<TaskTreeNode, Integer> taskMap) 365 { 366 for (Map.Entry<TaskTreeNode, Integer> entry : taskMap.entrySet()) 367 { 368 if (taskSpecEqualsTask(task, entry.getKey())) 369 { 370 if (task.children != null) 371 { 372 for (TaskSpec child : task.children) 373 { 374 assertTaskAndChildrenInMapAndRemove(child, taskMap); 375 } 376 } 377 378 int count = taskMap.get(entry.getKey()); 379 if (count == 1) 380 { 381 taskMap.remove(entry.getKey()); 382 } 383 else 384 { 385 taskMap.put(entry.getKey(), count - 1); 386 } 387 return; 388 } 389 } 390 391 fail("expected task " + task.type + " " + task.interactionName + " not included in task map"); 392 } 393 394 //----------------------------------------------------------------------------------------------- 395 /** 396 * 397 */ 398 //----------------------------------------------------------------------------------------------- 399 private boolean taskSpecEqualsTask(TaskSpec taskSpec, TaskTreeNode task) 400 { 401 if (mDoTrace) 402 { 403 System.err.println("comparing " + taskSpec.interactionName + " with"); 404 dumpTask(task, 0, ""); 405 } 406 407 if (("Interaction".equals(taskSpec.type) && (!(task instanceof InteractionTask))) || 408 ("TextInputInteraction".equals(taskSpec.type) && 409 (!(task instanceof TextInputInteractionTask))) || 410 ("Sequence".equals(taskSpec.type) && (!(task instanceof Sequence))) || 411 ("Selection".equals(taskSpec.type) && (!(task instanceof Selection))) || 412 ("Iteration".equals(taskSpec.type) && (!(task instanceof Iteration)))) 413 { 414 if (mDoTrace) 415 { 416 System.err.println("task types do not match: " + taskSpec.type + " != " + 417 task.getClass().getSimpleName() + "\n"); 418 } 419 return false; 420 } 421 else if (!"Interaction".equals(taskSpec.type) && 422 !"TextInputInteraction".equals(taskSpec.type) && 423 !"Sequence".equals(taskSpec.type) && 424 !"Selection".equals(taskSpec.type) && 425 !"Iteration".equals(taskSpec.type)) 426 { 427 fail("unknown task type " + taskSpec.type + " --> please extend test case"); 428 } 429 430 if ("TextInputInteraction".equals(taskSpec.type)) 431 { 432 if (!"".equals(taskSpec.additionalInfo) && 433 !(taskSpec.additionalInfo.equals(((TextInputInteractionTask) task).getEnteredText()))) 434 { 435 if (mDoTrace) 436 { 437 System.err.println 438 ("expected text \"" + taskSpec.additionalInfo + "\" is not equal to the text " + 439 "provided by the task \"" + ((TextInputInteractionTask) task).getEnteredText() + 440 "\"\n"); 441 } 442 return false; 443 } 444 } 445 else if ((task instanceof InteractionTask) && 446 (((InteractionTask) task).getInteraction() != null) && 447 (!taskSpec.interactionName.equals(((InteractionTask) task).getInteraction().getName()))) 448 { 449 // simple interaction names do not match. But what about the interaction name in combination 450 // with the additional info 451 String complexInteractionName = taskSpec.interactionName + 452 (!"".equals(taskSpec.additionalInfo) ? " " + taskSpec.additionalInfo : ""); 453 454 if (!complexInteractionName.equals(((InteractionTask) task).getInteraction().getName())) 455 { 456 if (mDoTrace) 457 { 458 System.err.println("interaction names do not match: " + taskSpec.interactionName + 459 " != " + ((InteractionTask) task).getInteraction().getName() + "\n"); 460 } 461 return false; 462 } 463 } 464 465 if (((taskSpec.children == null) && (task.getChildren().size() > 0)) || 466 ((taskSpec.children != null) && (taskSpec.children.length != task.getChildren().size()))) 467 { 468 if (mDoTrace) 469 { 470 System.err.println("numbers of children do not match: " + 471 (taskSpec.children == null ? "0" : taskSpec.children.length) + " != " + 472 (task.getChildren() == null ? "0" : task.getChildren().size()) + "\n"); 473 } 474 return false; 475 } 476 477 Iterator<TaskTreeNode> children = task.getChildren().iterator(); 478 if (taskSpec.children != null) 479 { 480 for (TaskSpec child : taskSpec.children) 481 { 482 if (!taskSpecEqualsTask(child, children.next())) 483 { 484 if (mDoTrace) 485 { 486 System.err.println("one of the children does not match\n"); 487 } 488 return false; 489 } 490 } 491 } 492 493 if (!children.hasNext()) 494 { 495 if (mDoTrace) 496 { 497 System.err.println("nodes match\n"); 498 } 499 return true; 500 } 501 else 502 { 503 if (mDoTrace) 504 { 505 System.err.println("number of children does not match\n"); 506 } 507 return false; 508 } 509 } 510 511 //----------------------------------------------------------------------------------------------- 512 /** 513 * 514 */ 515 //----------------------------------------------------------------------------------------------- 516 private void dumpTaskMap(Map<TaskTreeNode, Integer> taskMap) 517 { 518 System.err.println(); 519 for (Map.Entry<TaskTreeNode, Integer> entry : taskMap.entrySet()) 520 { 521 dumpTask(entry.getKey(), entry.getValue(), ""); 522 System.err.println(); 523 } 524 } 525 526 //----------------------------------------------------------------------------------------------- 527 /** 528 * 529 */ 530 //----------------------------------------------------------------------------------------------- 531 private void dumpTask(TaskTreeNode task, int count, String indent) 532 { 533 System.err.print(indent); 534 System.err.print(task); 535 System.err.print(" "); 536 System.err.print(task.getDescription()); 537 System.err.print(" "); 538 539 if (count > 0) 540 { 541 System.err.print("("); 542 System.err.print(count); 543 System.err.print(" occurrences)"); 544 } 545 546 System.err.println(); 547 548 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) 549 { 550 for (TaskTreeNode child : task.getChildren()) 551 { 552 dumpTask(child, 0, indent + " "); 553 } 554 } 555 } 556 557 //----------------------------------------------------------------------------------------------- 558 /** 559 * TODO comment 560 * 561 * @version $Revision: $ $Date: $ 562 * @author 2011, last modified by $Author: $ 563 */ 564 //----------------------------------------------------------------------------------------------- 565 private class TaskSpec 566 { 567 public String type; 568 public String interactionName; 569 public String additionalInfo; 570 public TaskSpec[] children; 571 } 436 private void dumpTask(ITaskTreeNode task, int count, String indent) { 437 System.err.print(indent); 438 System.err.print(task); 439 System.err.print(" "); 440 System.err.print(task.getDescription()); 441 System.err.print(" "); 442 443 if (count > 0) { 444 System.err.print("("); 445 System.err.print(count); 446 System.err.print(" occurrences)"); 447 } 448 449 System.err.println(); 450 451 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { 452 for (ITaskTreeNode child : task.getChildren()) { 453 dumpTask(child, 0, indent + " "); 454 } 455 } 456 } 457 458 /** 459 * TODO comment 460 * 461 * @version $Revision: $ $Date: $ 462 * @author 2011, last modified by $Author: $ 463 */ 464 private class TaskSpec { 465 public String type; 466 public String name; 467 public String additionalInfo; 468 public TaskSpec[] children; 469 } 572 470 573 471 }
Note: See TracChangeset
for help on using the changeset viewer.