Changeset 557 for trunk/quest-core-tasktrees-test
- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- Location:
- trunk/quest-core-tasktrees-test
- Files:
-
- 4 added
- 13 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/manager/TaskTreeManagerTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManagerTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 21:32:36 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.manager; … … 15 13 import org.junit.Test; 16 14 17 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;18 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;19 import de.ugoe.cs.quest.eventcore. userinteraction.InteractionEvent;15 import de.ugoe.cs.quest.eventcore.Event; 16 import de.ugoe.cs.quest.eventcore.IEventTarget; 17 import de.ugoe.cs.quest.eventcore.IEventType; 20 18 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 21 19 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; … … 23 21 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 24 22 25 //-------------------------------------------------------------------------------------------------26 23 /** 27 24 * TODO comment 28 * 25 * 29 26 * @version $Revision: $ $Date: $ 30 * @author 27 * @author 2011, last modified by $Author: $ 31 28 */ 32 //------------------------------------------------------------------------------------------------- 33 34 public class TaskTreeManagerTest 35 { 36 /** */ 37 TaskTreeManager mManager; 38 39 //----------------------------------------------------------------------------------------------- 40 /** 41 * 42 */ 43 //----------------------------------------------------------------------------------------------- 44 @Before 45 public void setUp() 46 { 47 Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 29 public class TaskTreeManagerTest { 48 30 49 mManager = new TaskTreeManager(); 50 } 51 52 //----------------------------------------------------------------------------------------------- 53 /** 54 * 55 */ 56 //----------------------------------------------------------------------------------------------- 57 @After 58 public void tearDown() 59 { 60 mManager = null; 61 ComponentManager.clearInstance(); 62 } 63 64 //----------------------------------------------------------------------------------------------- 65 /** 66 * 67 */ 68 //----------------------------------------------------------------------------------------------- 69 @Test 70 public void testOneInteractionOnOneElement() 71 { 72 simulateInteraction(new DummyGUIElement("elem1"), new DummyInteraction("bla", 1)); 73 new TaskTreeChecker().assertTaskTree 74 ("Sequence sequence {" + 75 " Interaction bla {}" + 76 "}", mManager.getTaskTree()); 77 } 78 79 //----------------------------------------------------------------------------------------------- 80 /** 81 * 82 */ 83 //----------------------------------------------------------------------------------------------- 84 @Test 85 public void testManyInteractionsOnOneElement() 86 { 87 GUIElement element = new DummyGUIElement("elem1"); 88 simulateInteraction(element, new DummyInteraction("bla", 1)); 89 simulateInteraction(element, new DummyInteraction("bli", 1)); 90 simulateInteraction(element, new DummyInteraction("blo", 1)); 91 simulateInteraction(element, new DummyInteraction("blu", 1)); 92 simulateInteraction(element, new DummyInteraction("bla", 1)); 93 94 new TaskTreeChecker().assertTaskTree 95 ("Sequence sequence {" + 96 " Interaction bla {}" + 97 " Interaction bli {}" + 98 " Interaction blo {}" + 99 " Interaction blu {}" + 100 " Interaction bla {}" + 101 "}", mManager.getTaskTree()); 102 } 103 104 //----------------------------------------------------------------------------------------------- 105 /** 106 * 107 */ 108 //----------------------------------------------------------------------------------------------- 109 @Test 110 public void testOneInteractionOnManyElements() 111 { 112 GUIElement element1 = new DummyGUIElement("elem1"); 113 GUIElement element2 = new DummyGUIElement("elem2"); 114 GUIElement element3 = new DummyGUIElement("elem3"); 115 GUIElement element4 = new DummyGUIElement("elem4"); 116 GUIElement element5 = new DummyGUIElement("elem5"); 117 GUIElement element6 = new DummyGUIElement("elem6"); 118 simulateInteraction(element1, new DummyInteraction("bla", 1)); 119 simulateInteraction(element2, new DummyInteraction("bli", 1)); 120 simulateInteraction(element3, new DummyInteraction("bla", 1)); 121 simulateInteraction(element4, new DummyInteraction("bli", 1)); 122 simulateInteraction(element5, new DummyInteraction("blo", 1)); 123 simulateInteraction(element6, new DummyInteraction("bla", 1)); 124 125 new TaskTreeChecker().assertTaskTree 126 ("Sequence sequence0 {" + 127 " Sequence sequence1 {" + 128 " Interaction bla {}" + 129 " }" + 130 " Sequence sequence2 {" + 131 " Interaction bli {}" + 132 " }" + 133 " Sequence sequence3 {" + 134 " Interaction bla {}" + 135 " }" + 136 " Sequence sequence4 {" + 137 " Interaction bli {}" + 138 " }" + 139 " Sequence sequence5 {" + 140 " Interaction blo {}" + 141 " }" + 142 " Sequence sequence6 {" + 143 " Interaction bla {}" + 144 " }" + 145 "}", mManager.getTaskTree()); 146 } 147 148 //----------------------------------------------------------------------------------------------- 149 /** 150 * 151 */ 152 //----------------------------------------------------------------------------------------------- 153 @Test 154 public void testManyInteractionsOnManyElements() 155 { 156 GUIElement element1 = new DummyGUIElement("elem1"); 157 GUIElement element2 = new DummyGUIElement("elem2"); 158 GUIElement element3 = new DummyGUIElement("elem3"); 159 GUIElement element4 = new DummyGUIElement("elem4"); 160 GUIElement element5 = new DummyGUIElement("elem5"); 161 GUIElement element6 = new DummyGUIElement("elem6"); 162 simulateInteraction(element1, new DummyInteraction("bla", 1)); 163 simulateInteraction(element1, new DummyInteraction("bli", 1)); 164 simulateInteraction(element1, new DummyInteraction("bla", 1)); 165 simulateInteraction(element2, new DummyInteraction("bli", 1)); 166 simulateInteraction(element2, new DummyInteraction("blo", 1)); 167 simulateInteraction(element3, new DummyInteraction("bla", 1)); 168 simulateInteraction(element4, new DummyInteraction("bli", 1)); 169 simulateInteraction(element4, new DummyInteraction("bla", 1)); 170 simulateInteraction(element4, new DummyInteraction("bli", 1)); 171 simulateInteraction(element4, new DummyInteraction("blo", 1)); 172 simulateInteraction(element5, new DummyInteraction("bla", 1)); 173 simulateInteraction(element6, new DummyInteraction("bli", 1)); 174 simulateInteraction(element6, new DummyInteraction("bla", 1)); 175 simulateInteraction(element6, new DummyInteraction("bli", 1)); 176 simulateInteraction(element6, new DummyInteraction("blo", 1)); 177 178 new TaskTreeChecker().assertTaskTree 179 ("Sequence sequence0 {" + 180 " Sequence sequence1 {" + 181 " Interaction bla {}" + 182 " Interaction bli {}" + 183 " Interaction bla {}" + 184 " }" + 185 " Sequence sequence2 {" + 186 " Interaction bli {}" + 187 " Interaction blo {}" + 188 " }" + 189 " Sequence sequence3 {" + 190 " Interaction bla {}" + 191 " }" + 192 " Sequence sequence4 {" + 193 " Interaction bli {}" + 194 " Interaction bla {}" + 195 " Interaction bli {}" + 196 " Interaction blo {}" + 197 " }" + 198 " Sequence sequence5 {" + 199 " Interaction bla {}" + 200 " }" + 201 " Sequence sequence6 {" + 202 " Interaction bli {}" + 203 " Interaction bla {}" + 204 " Interaction bli {}" + 205 " Interaction blo {}" + 206 " }" + 207 "}", mManager.getTaskTree()); 208 } 209 210 //----------------------------------------------------------------------------------------------- 211 /** 212 * 213 */ 214 //----------------------------------------------------------------------------------------------- 215 @Test 216 public void testInteractionIterationDetection() throws Exception 217 { 218 GUIElement element1 = new DummyGUIElement("elem1"); 219 Interaction interaction1 = new DummyInteraction("bla", 1); 220 simulateInteraction(element1, interaction1); 221 new TaskTreeChecker().assertTaskTree 222 ("Sequence sequence1 {" + 223 " Interaction bla {}" + 224 "}", mManager.getTaskTree()); 225 226 simulateInteraction(element1, interaction1); 227 new TaskTreeChecker().assertTaskTree 228 ("Sequence sequence1 {" + 229 " Iteration iteration1 {" + 230 " Interaction bla {}" + 231 " }" + 232 "}", mManager.getTaskTree()); 233 234 simulateInteraction(element1, interaction1); 235 new TaskTreeChecker().assertTaskTree 236 ("Sequence sequence1 {" + 237 " Iteration iteration1 {" + 238 " Interaction bla {}" + 239 " }" + 240 "}", mManager.getTaskTree()); 241 242 for (int i = 0; i < 10; i++) 243 { 244 simulateInteraction(element1, interaction1); 245 } 246 247 new TaskTreeChecker().assertTaskTree 248 ("Sequence sequence1 {" + 249 " Iteration iteration1 {" + 250 " Interaction bla {}" + 251 " }" + 252 "}", mManager.getTaskTree()); 253 254 // now test with preceding and trailing other interactions 255 Interaction interaction2 = new DummyInteraction("bli", 1); 256 Interaction interaction3 = new DummyInteraction("blup", 1); 257 258 simulateInteraction(element1, interaction2); 259 simulateInteraction(element1, interaction3); 260 for (int i = 0; i < 10; i++) 261 { 262 simulateInteraction(element1, interaction1); 263 } 264 simulateInteraction(element1, interaction3); 265 simulateInteraction(element1, interaction2); 266 267 new TaskTreeChecker().assertTaskTree 268 ("Sequence sequence1 {" + 269 " Iteration iteration1 {" + 270 " Interaction bla {}" + 271 " }" + 272 " Interaction bli {}" + 273 " Interaction blup {}" + 274 " Iteration iteration2 {" + 275 " Interaction bla {}" + 276 " }" + 277 " Interaction blup {}" + 278 " Interaction bli {}" + 279 "}", mManager.getTaskTree()); 280 281 // now test with iterations of iterations 282 283 for (int i = 0; i < 10; i++) 284 { 285 for (int j = 0; j < 5; j++) 286 { 287 simulateInteraction(element1, interaction1); 288 } 289 for (int j = 0; j < 5; j++) 290 { 291 simulateInteraction(element1, interaction2); 292 } 293 for (int j = 0; j < 5; j++) 294 { 295 simulateInteraction(element1, interaction3); 296 } 297 } 298 299 new TaskTreeChecker().assertTaskTree 300 ("Sequence sequence0 {" + 301 " Iteration iteration0 {" + 302 " Interaction bla {}" + 303 " }" + 304 " Interaction bli {}" + 305 " Interaction blup {}" + 306 " Iteration iteration1 {" + 307 " Interaction bla {}" + 308 " }" + 309 " Interaction blup {}" + 310 " Interaction bli {}" + 311 " Iteration iteration2 {" + 312 " Sequence sequence1 {" + 313 " Iteration iteration3 {" + 314 " Interaction bla {}" + 315 " }" + 316 " Iteration iteration4 {" + 317 " Interaction bli {}" + 318 " }" + 319 " Iteration iteration5 {" + 320 " Interaction blup {}" + 321 " }" + 322 " }" + 323 " }" + 324 "}", mManager.getTaskTree()); 325 326 } 327 328 //----------------------------------------------------------------------------------------------- 329 /** 330 * 331 */ 332 //----------------------------------------------------------------------------------------------- 333 @Test 334 public void testSequenceIterationDetection() throws Exception 335 { 336 GUIElement element1 = new DummyGUIElement("elem1"); 337 Interaction interaction1 = new DummyInteraction("bla", 1); 338 Interaction interaction2 = new DummyInteraction("bli", 1); 339 Interaction interaction3 = new DummyInteraction("blup", 1); 340 simulateInteraction(element1, interaction1); 341 simulateInteraction(element1, interaction2); 342 simulateInteraction(element1, interaction3); 343 new TaskTreeChecker().assertTaskTree 344 ("Sequence sequence1 {" + 345 " Interaction bla {}" + 346 " Interaction bli {}" + 347 " Interaction blup {}" + 348 "}", mManager.getTaskTree()); 349 350 simulateInteraction(element1, interaction1); 351 simulateInteraction(element1, interaction2); 352 simulateInteraction(element1, interaction3); 353 new TaskTreeChecker().assertTaskTree 354 ("Sequence sequence1 {" + 355 " Iteration iteration1 {" + 356 " Sequence sequence2 {" + 357 " Interaction bla {}" + 358 " Interaction bli {}" + 359 " Interaction blup {}" + 360 " }" + 361 " }" + 362 "}", mManager.getTaskTree()); 363 364 simulateInteraction(element1, interaction1); 365 simulateInteraction(element1, interaction2); 366 simulateInteraction(element1, interaction3); 367 new TaskTreeChecker().assertTaskTree 368 ("Sequence sequence1 {" + 369 " Iteration iteration1 {" + 370 " Sequence sequence2 {" + 371 " Interaction bla {}" + 372 " Interaction bli {}" + 373 " Interaction blup {}" + 374 " }" + 375 " }" + 376 "}", mManager.getTaskTree()); 377 378 for (int i = 0; i < 10; i++) 379 { 380 simulateInteraction(element1, interaction1); 381 simulateInteraction(element1, interaction2); 382 simulateInteraction(element1, interaction3); 383 } 384 385 new TaskTreeChecker().assertTaskTree 386 ("Sequence sequence1 {" + 387 " Iteration iteration1 {" + 388 " Sequence sequence2 {" + 389 " Interaction bla {}" + 390 " Interaction bli {}" + 391 " Interaction blup {}" + 392 " }" + 393 " }" + 394 "}", mManager.getTaskTree()); 395 396 // now test with preceding and trailing other interactions 397 Interaction interaction4 = new DummyInteraction("ble", 1); 398 Interaction interaction5 = new DummyInteraction("blo", 1); 399 Interaction interaction6 = new DummyInteraction("blu", 1); 400 simulateInteraction(element1, interaction4); 401 simulateInteraction(element1, interaction5); 402 simulateInteraction(element1, interaction6); 403 for (int i = 0; i < 10; i++) 404 { 405 simulateInteraction(element1, interaction1); 406 simulateInteraction(element1, interaction2); 407 simulateInteraction(element1, interaction3); 408 } 409 simulateInteraction(element1, interaction6); 410 simulateInteraction(element1, interaction5); 411 simulateInteraction(element1, interaction4); 412 413 new TaskTreeChecker().assertTaskTree 414 ("Sequence sequence1 {" + 415 " Iteration iteration1 {" + 416 " Sequence sequence2 {" + 417 " Interaction bla {}" + 418 " Interaction bli {}" + 419 " Interaction blup {}" + 420 " }" + 421 " }" + 422 " Interaction ble {}" + 423 " Interaction blo {}" + 424 " Interaction blu {}" + 425 " Iteration iteration2 {" + 426 " Sequence sequence3 {" + 427 " Interaction bla {}" + 428 " Interaction bli {}" + 429 " Interaction blup {}" + 430 " }" + 431 " }" + 432 " Interaction blu {}" + 433 " Interaction blo {}" + 434 " Interaction ble {}" + 435 "}", mManager.getTaskTree()); 436 437 // now test with iterations of iterations 438 for (int i = 0; i < 10; i++) 439 { 440 for (int j = 0; j < 5; j++) 441 { 442 simulateInteraction(element1, interaction1); 443 simulateInteraction(element1, interaction2); 444 simulateInteraction(element1, interaction3); 445 } 446 for (int j = 0; j < 5; j++) 447 { 448 simulateInteraction(element1, interaction2); 449 simulateInteraction(element1, interaction1); 450 simulateInteraction(element1, interaction3); 451 } 452 for (int j = 0; j < 5; j++) 453 { 454 simulateInteraction(element1, interaction1); 455 simulateInteraction(element1, interaction2); 456 simulateInteraction(element1, interaction3); 457 } 458 } 459 460 new TaskTreeChecker().assertTaskTree 461 ("Sequence sequence1 {" + 462 " Iteration iteration1 {" + 463 " Sequence sequence2 {" + 464 " Interaction bla {}" + 465 " Interaction bli {}" + 466 " Interaction blup {}" + 467 " }" + 468 " }" + 469 " Interaction ble {}" + 470 " Interaction blo {}" + 471 " Interaction blu {}" + 472 " Iteration iteration2 {" + 473 " Sequence sequence3 {" + 474 " Interaction bla {}" + 475 " Interaction bli {}" + 476 " Interaction blup {}" + 477 " }" + 478 " }" + 479 " Interaction blu {}" + 480 " Interaction blo {}" + 481 " Interaction ble {}" + 482 " Iteration iteration3 {" + 483 " Sequence sequence4 {" + 484 " Iteration iteration4 {" + 485 " Sequence sequence4 {" + 486 " Interaction bla {}" + 487 " Interaction bli {}" + 488 " Interaction blup {}" + 489 " }" + 490 " }" + 491 " Iteration iteration5 {" + 492 " Sequence sequence5 {" + 493 " Interaction bli {}" + 494 " Interaction bla {}" + 495 " Interaction blup {}" + 496 " }" + 497 " }" + 498 " Iteration iteration6 {" + 499 " Sequence sequence6 {" + 500 " Interaction bla {}" + 501 " Interaction bli {}" + 502 " Interaction blup {}" + 503 " }" + 504 " }" + 505 " }" + 506 " }" + 507 "}", mManager.getTaskTree()); 508 } 509 510 //----------------------------------------------------------------------------------------------- 511 /** 512 * 513 */ 514 //----------------------------------------------------------------------------------------------- 515 @Test 516 public void testGUIElementHierarchyChanges() throws Exception 517 { 518 GUIElement element1 = new DummyGUIElement("elem1"); 519 GUIElement element2 = new DummyGUIElement("elem2"); 520 GUIElement element3 = new DummyGUIElement("elem3"); 521 GUIElement parent1 = new DummyGUIElement("parent1"); 522 GUIElement parent2 = new DummyGUIElement("parent2"); 523 GUIElement parent3 = new DummyGUIElement("parent3"); 524 525 element1.setParent(parent1); 526 element2.setParent(parent2); 527 element3.setParent(parent3); 528 529 parent1.setParent(parent2); 530 parent2.setParent(parent3); 531 532 Interaction interaction1 = new DummyInteraction("bla", 1); 533 simulateInteraction(element1, interaction1); 534 simulateInteraction(element2, interaction1); 535 simulateInteraction(element3, interaction1); 536 simulateInteraction(element2, interaction1); 537 simulateInteraction(element3, interaction1); 538 simulateInteraction(element2, interaction1); 539 simulateInteraction(element1, interaction1); 540 541 new TaskTreeChecker().assertTaskTree 542 ("Sequence sequence0 {" + 543 " Sequence sequence1 {" + 544 " Interaction bla {}" + 545 " }" + 546 " Sequence sequence2 {" + 547 " Interaction bla {}" + 548 " }" + 549 " Iteration iteration0 {" + 550 " Sequence sequence3 {" + 551 " Sequence sequence4 {" + 552 " Interaction bla {}" + 553 " }" + 554 " Sequence sequence5 {" + 555 " Interaction bla {}" + 556 " }" + 557 " }" + 558 " }" + 559 " Sequence sequence6 {" + 560 " Interaction bla {}" + 561 " }" + 562 "}", mManager.getTaskTree()); 563 564 } 565 566 //----------------------------------------------------------------------------------------------- 567 /** 568 * @param interactionsDoNotOverwriteElement 569 */ 570 //----------------------------------------------------------------------------------------------- 571 private void simulateInteraction(GUIElement GUIElement, Interaction interaction) 572 { 573 mManager.handleNewInteractionEvent(new InteractionEvent(GUIElement, interaction)); 574 } 31 /** */ 32 TaskTreeManager manager; 33 34 /** 35 * 36 */ 37 @Before 38 public void setUp() { 39 Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 40 41 manager = new TaskTreeManager(); 42 } 43 44 /** 45 * 46 */ 47 @After 48 public void tearDown() { 49 manager = null; 50 ComponentManager.clearInstance(); 51 } 52 53 /** 54 * 55 */ 56 @Test 57 public void testOneEventOnOneElement() { 58 simulateEvent(new DummyInteraction("bla", 1), new DummyGUIElement("elem1")); 59 new TaskTreeChecker().assertTaskTree 60 ("Sequence sequence {" + 61 " Event bla {}" + 62 "}", manager.getTaskTree()); 63 } 64 65 /** 66 * 67 */ 68 @Test 69 public void testManyEventsOnOneElement() { 70 IEventTarget eventTarget = new DummyGUIElement("elem1"); 71 simulateEvent(new DummyInteraction("bla", 1), eventTarget); 72 simulateEvent(new DummyInteraction("bli", 1), eventTarget); 73 simulateEvent(new DummyInteraction("blo", 1), eventTarget); 74 simulateEvent(new DummyInteraction("blu", 1), eventTarget); 75 simulateEvent(new DummyInteraction("bla", 1), eventTarget); 76 77 new TaskTreeChecker().assertTaskTree 78 ("Sequence sequence {" + 79 " Event bla {}" + 80 " Event bli {}" + 81 " Event blo {}" + 82 " Event blu {}" + 83 " Event bla {}" + 84 "}", manager.getTaskTree()); 85 } 86 87 /** 88 * 89 */ 90 @Test 91 public void testOneEventOnManyElements() { 92 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 93 IEventTarget eventTarget2 = new DummyGUIElement("elem2"); 94 IEventTarget eventTarget3 = new DummyGUIElement("elem3"); 95 IEventTarget eventTarget4 = new DummyGUIElement("elem4"); 96 IEventTarget eventTarget5 = new DummyGUIElement("elem5"); 97 IEventTarget eventTarget6 = new DummyGUIElement("elem6"); 98 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 99 simulateEvent(new DummyInteraction("bli", 1), eventTarget2); 100 simulateEvent(new DummyInteraction("bla", 1), eventTarget3); 101 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 102 simulateEvent(new DummyInteraction("blo", 1), eventTarget5); 103 simulateEvent(new DummyInteraction("bla", 1), eventTarget6); 104 105 new TaskTreeChecker().assertTaskTree 106 ("Sequence sequence0 {" + 107 " Sequence sequence1 {" + 108 " Event bla {}" + 109 " }" + 110 " Sequence sequence2 {" + 111 " Event bli {}" + 112 " }" + 113 " Sequence sequence3 {" + 114 " Event bla {}" + 115 " }" + 116 " Sequence sequence4 {" + 117 " Event bli {}" + 118 " }" + 119 " Sequence sequence5 {" + 120 " Event blo {}" + 121 " }" + 122 " Sequence sequence6 {" + 123 " Event bla {}" + 124 " }" + 125 "}", manager.getTaskTree()); 126 } 127 128 /** 129 * 130 */ 131 @Test 132 public void testManyEventsOnManyElements() { 133 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 134 IEventTarget eventTarget2 = new DummyGUIElement("elem2"); 135 IEventTarget eventTarget3 = new DummyGUIElement("elem3"); 136 IEventTarget eventTarget4 = new DummyGUIElement("elem4"); 137 IEventTarget eventTarget5 = new DummyGUIElement("elem5"); 138 IEventTarget eventTarget6 = new DummyGUIElement("elem6"); 139 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 140 simulateEvent(new DummyInteraction("bli", 1), eventTarget1); 141 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 142 simulateEvent(new DummyInteraction("bli", 1), eventTarget2); 143 simulateEvent(new DummyInteraction("blo", 1), eventTarget2); 144 simulateEvent(new DummyInteraction("bla", 1), eventTarget3); 145 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 146 simulateEvent(new DummyInteraction("bla", 1), eventTarget4); 147 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 148 simulateEvent(new DummyInteraction("blo", 1), eventTarget4); 149 simulateEvent(new DummyInteraction("bla", 1), eventTarget5); 150 simulateEvent(new DummyInteraction("bli", 1), eventTarget6); 151 simulateEvent(new DummyInteraction("bla", 1), eventTarget6); 152 simulateEvent(new DummyInteraction("bli", 1), eventTarget6); 153 simulateEvent(new DummyInteraction("blo", 1), eventTarget6); 154 155 new TaskTreeChecker().assertTaskTree 156 ("Sequence sequence0 {" + 157 " Sequence sequence1 {" + 158 " Event bla {}" + 159 " Event bli {}" + 160 " Event bla {}" + 161 " }" + 162 " Sequence sequence2 {" + 163 " Event bli {}" + 164 " Event blo {}" + 165 " }" + 166 " Sequence sequence3 {" + 167 " Event bla {}" + 168 " }" + 169 " Sequence sequence4 {" + 170 " Event bli {}" + 171 " Event bla {}" + 172 " Event bli {}" + 173 " Event blo {}" + 174 " }" + 175 " Sequence sequence5 {" + 176 " Event bla {}" + 177 " }" + 178 " Sequence sequence6 {" + 179 " Event bli {}" + 180 " Event bla {}" + 181 " Event bli {}" + 182 " Event blo {}" + 183 " }" + 184 "}", manager.getTaskTree()); 185 } 186 187 /** 188 * 189 */ 190 @Test 191 public void testEventIterationDetection() throws Exception { 192 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 193 IEventType event1 = new DummyInteraction("bla", 1); 194 simulateEvent(event1, eventTarget1); 195 new TaskTreeChecker().assertTaskTree 196 ("Sequence sequence1 {" + 197 " Event bla {}" + 198 "}", manager.getTaskTree()); 199 200 simulateEvent(event1, eventTarget1); 201 new TaskTreeChecker().assertTaskTree 202 ("Sequence sequence1 {" + 203 " Iteration iteration1 {" + 204 " Event bla {}" + 205 " }" + 206 "}", manager.getTaskTree()); 207 208 simulateEvent(event1, eventTarget1); 209 new TaskTreeChecker().assertTaskTree 210 ("Sequence sequence1 {" + 211 " Iteration iteration1 {" + 212 " Event bla {}" + 213 " }" + 214 "}", manager.getTaskTree()); 215 216 for (int i = 0; i < 10; i++) { 217 simulateEvent(event1, eventTarget1); 218 } 219 220 new TaskTreeChecker().assertTaskTree 221 ("Sequence sequence1 {" + 222 " Iteration iteration1 {" + 223 " Event bla {}" + 224 " }" + 225 "}", manager.getTaskTree()); 226 227 // now test with preceding and trailing other interactions 228 IEventType event2 = new DummyInteraction("bli", 1); 229 IEventType event3 = new DummyInteraction("blup", 1); 230 231 simulateEvent(event2, eventTarget1); 232 simulateEvent(event3, eventTarget1); 233 for (int i = 0; i < 10; i++) { 234 simulateEvent(event1, eventTarget1); 235 } 236 simulateEvent(event3, eventTarget1); 237 simulateEvent(event2, eventTarget1); 238 239 new TaskTreeChecker().assertTaskTree 240 ("Sequence sequence1 {" + 241 " Iteration iteration1 {" + 242 " Event bla {}" + 243 " }" + 244 " Event bli {}" + 245 " Event blup {}" + 246 " Iteration iteration2 {" + 247 " Event bla {}" + 248 " }" + 249 " Event blup {}" + 250 " Event bli {}" + 251 "}", manager.getTaskTree()); 252 253 // now test with iterations of iterations 254 255 for (int i = 0; i < 10; i++) { 256 for (int j = 0; j < 5; j++) { 257 simulateEvent(event1, eventTarget1); 258 } 259 for (int j = 0; j < 5; j++) { 260 simulateEvent(event2, eventTarget1); 261 } 262 for (int j = 0; j < 5; j++) { 263 simulateEvent(event3, eventTarget1); 264 } 265 } 266 267 new TaskTreeChecker().assertTaskTree 268 ("Sequence sequence0 {" + 269 " Iteration iteration0 {" + 270 " Event bla {}" + 271 " }" + 272 " Event bli {}" + 273 " Event blup {}" + 274 " Iteration iteration1 {" + 275 " Event bla {}" + 276 " }" + 277 " Event blup {}" + 278 " Event bli {}" + 279 " Iteration iteration2 {" + 280 " Sequence sequence1 {" + 281 " Iteration iteration3 {" + 282 " Event bla {}" + 283 " }" + 284 " Iteration iteration4 {" + 285 " Event bli {}" + 286 " }" + 287 " Iteration iteration5 {" + 288 " Event blup {}" + 289 " }" + 290 " }" + 291 " }" + 292 "}", manager.getTaskTree()); 293 294 } 295 296 /** 297 * 298 */ 299 @Test 300 public void testSequenceIterationDetection() throws Exception { 301 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 302 IEventType event1 = new DummyInteraction("bla", 1); 303 IEventType event2 = new DummyInteraction("bli", 1); 304 IEventType event3 = new DummyInteraction("blup", 1); 305 simulateEvent(event1, eventTarget1); 306 simulateEvent(event2, eventTarget1); 307 simulateEvent(event3, eventTarget1); 308 new TaskTreeChecker().assertTaskTree 309 ("Sequence sequence1 {" + 310 " Event bla {}" + 311 " Event bli {}" + 312 " Event blup {}" + 313 "}", manager.getTaskTree()); 314 315 simulateEvent(event1, eventTarget1); 316 simulateEvent(event2, eventTarget1); 317 simulateEvent(event3, eventTarget1); 318 new TaskTreeChecker().assertTaskTree 319 ("Sequence sequence1 {" + 320 " Iteration iteration1 {" + 321 " Sequence sequence2 {" + 322 " Event bla {}" + 323 " Event bli {}" + 324 " Event blup {}" + 325 " }" + 326 " }" + 327 "}", manager.getTaskTree()); 328 329 simulateEvent(event1, eventTarget1); 330 simulateEvent(event2, eventTarget1); 331 simulateEvent(event3, eventTarget1); 332 new TaskTreeChecker().assertTaskTree 333 ("Sequence sequence1 {" + 334 " Iteration iteration1 {" + 335 " Sequence sequence2 {" + 336 " Event bla {}" + 337 " Event bli {}" + 338 " Event blup {}" + 339 " }" + 340 " }" + 341 "}", manager.getTaskTree()); 342 343 for (int i = 0; i < 10; i++) { 344 simulateEvent(event1, eventTarget1); 345 simulateEvent(event2, eventTarget1); 346 simulateEvent(event3, eventTarget1); 347 } 348 349 new TaskTreeChecker().assertTaskTree 350 ("Sequence sequence1 {" + 351 " Iteration iteration1 {" + 352 " Sequence sequence2 {" + 353 " Event bla {}" + 354 " Event bli {}" + 355 " Event blup {}" + 356 " }" + 357 " }" + 358 "}", manager.getTaskTree()); 359 360 // now test with preceding and trailing other interactions 361 IEventType event4 = new DummyInteraction("ble", 1); 362 IEventType event5 = new DummyInteraction("blo", 1); 363 IEventType event6 = new DummyInteraction("blu", 1); 364 simulateEvent(event4, eventTarget1); 365 simulateEvent(event5, eventTarget1); 366 simulateEvent(event6, eventTarget1); 367 for (int i = 0; i < 10; i++) { 368 simulateEvent(event1, eventTarget1); 369 simulateEvent(event2, eventTarget1); 370 simulateEvent(event3, eventTarget1); 371 } 372 simulateEvent(event6, eventTarget1); 373 simulateEvent(event5, eventTarget1); 374 simulateEvent(event4, eventTarget1); 375 376 new TaskTreeChecker().assertTaskTree 377 ("Sequence sequence1 {" + 378 " Iteration iteration1 {" + 379 " Sequence sequence2 {" + 380 " Event bla {}" + 381 " Event bli {}" + 382 " Event blup {}" + 383 " }" + 384 " }" + 385 " Event ble {}" + 386 " Event blo {}" + 387 " Event blu {}" + 388 " Iteration iteration2 {" + 389 " Sequence sequence3 {" + 390 " Event bla {}" + 391 " Event bli {}" + 392 " Event blup {}" + 393 " }" + 394 " }" + 395 " Event blu {}" + 396 " Event blo {}" + 397 " Event ble {}" + 398 "}", manager.getTaskTree()); 399 400 // now test with iterations of iterations 401 for (int i = 0; i < 10; i++) { 402 for (int j = 0; j < 5; j++) { 403 simulateEvent(event1, eventTarget1); 404 simulateEvent(event2, eventTarget1); 405 simulateEvent(event3, eventTarget1); 406 } 407 for (int j = 0; j < 5; j++) { 408 simulateEvent(event2, eventTarget1); 409 simulateEvent(event1, eventTarget1); 410 simulateEvent(event3, eventTarget1); 411 } 412 for (int j = 0; j < 5; j++) { 413 simulateEvent(event1, eventTarget1); 414 simulateEvent(event2, eventTarget1); 415 simulateEvent(event3, eventTarget1); 416 } 417 } 418 419 new TaskTreeChecker().assertTaskTree 420 ("Sequence sequence1 {" + 421 " Iteration iteration1 {" + 422 " Sequence sequence2 {" + 423 " Event bla {}" + 424 " Event bli {}" + 425 " Event blup {}" + 426 " }" + 427 " }" + 428 " Event ble {}" + 429 " Event blo {}" + 430 " Event blu {}" + 431 " Iteration iteration2 {" + 432 " Sequence sequence3 {" + 433 " Event bla {}" + 434 " Event bli {}" + 435 " Event blup {}" + 436 " }" + 437 " }" + 438 " Event blu {}" + 439 " Event blo {}" + 440 " Event ble {}" + 441 " Iteration iteration3 {" + 442 " Sequence sequence4 {" + 443 " Iteration iteration4 {" + 444 " Sequence sequence4 {" + 445 " Event bla {}" + 446 " Event bli {}" + 447 " Event blup {}" + 448 " }" + 449 " }" + 450 " Iteration iteration5 {" + 451 " Sequence sequence5 {" + 452 " Event bli {}" + 453 " Event bla {}" + 454 " Event blup {}" + 455 " }" + 456 " }" + 457 " Iteration iteration6 {" + 458 " Sequence sequence6 {" + 459 " Event bla {}" + 460 " Event bli {}" + 461 " Event blup {}" + 462 " }" + 463 " }" + 464 " }" + 465 " }" + 466 "}", manager.getTaskTree()); 467 } 468 469 /** 470 * 471 */ 472 private void simulateEvent(IEventType eventType, IEventTarget eventTarget) { 473 manager.handleNewEvent(new Event(eventType, eventTarget)); 474 } 575 475 576 476 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/AbstractTemporalRelationshipTC.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: AbstractTemporalRelationshipTC.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 14 13 import org.junit.Before; 15 14 16 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;17 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;15 import de.ugoe.cs.quest.eventcore.IEventTarget; 16 import de.ugoe.cs.quest.eventcore.IEventType; 18 17 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 19 18 import de.ugoe.cs.quest.tasktrees.testutils.SimpleLogFormatter; 20 19 import de.ugoe.cs.quest.tasktrees.testutils.Utilities; 21 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;22 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;23 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTree;24 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;25 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;26 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder Impl;27 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory Impl;20 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 21 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 22 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 23 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 24 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 25 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder; 26 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory; 28 27 29 //-------------------------------------------------------------------------------------------------30 28 /** 31 29 * TODO comment … … 34 32 * @author 2012, last modified by $Author: patrick$ 35 33 */ 36 //------------------------------------------------------------------------------------------------- 37 public class AbstractTemporalRelationshipTC 38 { 34 public class AbstractTemporalRelationshipTC { 39 35 40 /** */ 41 private List<InteractionTask> mInteractions; 42 43 /** */ 44 private TaskTreeBuilder mTaskTreeBuilder = new TaskTreeBuilderImpl(); 36 /** */ 37 private List<IEventTask> events; 45 38 46 /** */ 47 private TaskTreeNodeFactory mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); 48 49 /** */ 50 private NodeEqualityRuleManager mNodeEqualityRuleManager = 51 Utilities.getNodeEqualityRuleManagerForTests(); 39 /** */ 40 private ITaskTreeBuilder taskTreeBuilder = new TaskTreeBuilder(); 52 41 53 //----------------------------------------------------------------------------------------------- 54 /** 42 /** */ 43 private ITaskTreeNodeFactory taskTreeNodeFactory = new TaskTreeNodeFactory(); 44 45 /** */ 46 private NodeEqualityRuleManager nodeEqualityRuleManager = 47 Utilities.getNodeEqualityRuleManagerForTests(); 48 49 /** 55 50 * 56 51 */ 57 //----------------------------------------------------------------------------------------------- 58 @Before 59 public void setUp() 60 { 61 Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 62 mInteractions = new ArrayList<InteractionTask>(); 63 } 52 @Before 53 public void setUp() { 54 Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 55 events = new ArrayList<IEventTask>(); 56 } 64 57 65 //----------------------------------------------------------------------------------------------- 66 /** 67 * @param interactionsDoNotOverwriteElement 68 */ 69 //----------------------------------------------------------------------------------------------- 70 protected void simulateInteraction(GUIElement GUIElement, Interaction interaction) 71 { 72 mInteractions.add 73 (mTaskTreeNodeFactory.createNewInteractionTask(GUIElement, interaction)); 74 } 58 /** 59 * 60 */ 61 protected void simulateEvent(IEventType eventType, IEventTarget eventTarget) { 62 events.add(taskTreeNodeFactory.createNewEventTask(eventType, eventTarget)); 63 } 75 64 76 //----------------------------------------------------------------------------------------------- 77 /** 78 * @param interactionsDoNotOverwriteElement 79 * @return 80 */ 81 //----------------------------------------------------------------------------------------------- 82 protected TaskTree getTaskTree() 83 { 84 Sequence sequence = mTaskTreeNodeFactory.createNewSequence(); 85 86 for (InteractionTask task : mInteractions) 87 { 88 mTaskTreeBuilder.addChild(sequence, task); 65 /** 66 * 67 * @return 68 */ 69 protected ITaskTree getTaskTree() { 70 ISequence sequence = taskTreeNodeFactory.createNewSequence(); 71 72 for (IEventTask task : events) { 73 taskTreeBuilder.addChild(sequence, task); 74 } 75 76 TemporalRelationshipRuleManager ruleManager = 77 new TemporalRelationshipRuleManager(nodeEqualityRuleManager); 78 79 ruleManager.init(); 80 ruleManager.applyRules(sequence, taskTreeBuilder, taskTreeNodeFactory, true); 81 82 return taskTreeNodeFactory.createTaskTree(sequence); 89 83 } 90 91 TemporalRelationshipRuleManager ruleManager =92 new TemporalRelationshipRuleManager(mNodeEqualityRuleManager);93 94 ruleManager.init();95 ruleManager.applyRules(sequence, mTaskTreeBuilder, mTaskTreeNodeFactory, true);96 97 return mTaskTreeNodeFactory.createTaskTree(sequence);98 }99 84 100 85 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManagerTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 21:32:36 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; … … 11 9 import org.junit.Test; 12 10 13 import de.ugoe.cs.quest.eventcore.guimodel.GUIElement; 14 import de.ugoe.cs.quest.eventcore.userinteraction.Interaction; 11 import de.ugoe.cs.quest.eventcore.IEventTarget; 15 12 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 16 13 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 17 14 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 18 15 19 //-------------------------------------------------------------------------------------------------20 16 /** 21 17 * TODO comment 22 * 18 * 23 19 * @version $Revision: $ $Date: $ 24 * @author 20 * @author 2011, last modified by $Author: $ 25 21 */ 26 //------------------------------------------------------------------------------------------------- 27 public class DefaultGUIElementSequenceDetectionRuleTest extends AbstractTemporalRelationshipTC 28 { 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 @Test 35 public void testOneInteractionOnOneElement() 36 { 37 simulateInteraction(new DummyGUIElement("elem1"), new DummyInteraction("bla", 1)); 22 public class DefaultGuiEventSequenceDetectionRuleTest extends AbstractTemporalRelationshipTC { 38 23 39 new TaskTreeChecker().assertTaskTree 40 ("Sequence sequence {" + 41 " Interaction bla {}" + 42 "}", getTaskTree()); 43 } 44 45 //----------------------------------------------------------------------------------------------- 46 /** 47 * 48 */ 49 //----------------------------------------------------------------------------------------------- 50 @Test 51 public void testManyInteractionsOnOneElement() 52 { 53 GUIElement element = new DummyGUIElement("elem1"); 54 simulateInteraction(element, new DummyInteraction("bla", 1)); 55 simulateInteraction(element, new DummyInteraction("bli", 1)); 56 simulateInteraction(element, new DummyInteraction("blo", 1)); 57 simulateInteraction(element, new DummyInteraction("blu", 1)); 58 simulateInteraction(element, new DummyInteraction("bla", 1)); 59 60 new TaskTreeChecker().assertTaskTree 61 ("Sequence sequence {" + 62 " Interaction bla {}" + 63 " Interaction bli {}" + 64 " Interaction blo {}" + 65 " Interaction blu {}" + 66 " Interaction bla {}" + 67 "}", getTaskTree()); 68 } 69 70 //----------------------------------------------------------------------------------------------- 71 /** 72 * 73 */ 74 //----------------------------------------------------------------------------------------------- 75 @Test 76 public void testOneInteractionOnManyElements() 77 { 78 GUIElement element1 = new DummyGUIElement("elem1"); 79 GUIElement element2 = new DummyGUIElement("elem2"); 80 GUIElement element3 = new DummyGUIElement("elem3"); 81 GUIElement element4 = new DummyGUIElement("elem4"); 82 GUIElement element5 = new DummyGUIElement("elem5"); 83 GUIElement element6 = new DummyGUIElement("elem6"); 84 simulateInteraction(element1, new DummyInteraction("bla", 1)); 85 simulateInteraction(element2, new DummyInteraction("bli", 1)); 86 simulateInteraction(element3, new DummyInteraction("bla", 1)); 87 simulateInteraction(element4, new DummyInteraction("bli", 1)); 88 simulateInteraction(element5, new DummyInteraction("blo", 1)); 89 simulateInteraction(element6, new DummyInteraction("bla", 1)); 24 /** 25 * 26 */ 27 @Test 28 public void testOneInteractionOnOneElement() { 29 simulateEvent(new DummyInteraction("bla", 1), new DummyGUIElement("elem1")); 90 30 91 new TaskTreeChecker().assertTaskTree 92 ("Sequence sequence0 {" + 93 " Sequence sequence1 {" + 94 " Interaction bla {}" + 95 " }" + 96 " Sequence sequence2 {" + 97 " Interaction bli {}" + 98 " }" + 99 " Sequence sequence3 {" + 100 " Interaction bla {}" + 101 " }" + 102 " Sequence sequence4 {" + 103 " Interaction bli {}" + 104 " }" + 105 " Sequence sequence5 {" + 106 " Interaction blo {}" + 107 " }" + 108 " Sequence sequence6 {" + 109 " Interaction bla {}" + 110 " }" + 111 "}", getTaskTree()); 112 } 31 new TaskTreeChecker().assertTaskTree 32 ("Sequence sequence {" + 33 " Event bla {}" + 34 "}", getTaskTree()); 35 } 113 36 114 //----------------------------------------------------------------------------------------------- 115 /** 116 * 117 */ 118 //----------------------------------------------------------------------------------------------- 119 @Test 120 public void testManyInteractionsOnManyElements() 121 { 122 GUIElement element1 = new DummyGUIElement("elem1"); 123 GUIElement element2 = new DummyGUIElement("elem2"); 124 GUIElement element3 = new DummyGUIElement("elem3"); 125 GUIElement element4 = new DummyGUIElement("elem4"); 126 GUIElement element5 = new DummyGUIElement("elem5"); 127 GUIElement element6 = new DummyGUIElement("elem6"); 128 simulateInteraction(element1, new DummyInteraction("bla", 1)); 129 simulateInteraction(element1, new DummyInteraction("bli", 1)); 130 simulateInteraction(element1, new DummyInteraction("bla", 1)); 131 simulateInteraction(element2, new DummyInteraction("bli", 1)); 132 simulateInteraction(element2, new DummyInteraction("blo", 1)); 133 simulateInteraction(element3, new DummyInteraction("bla", 1)); 134 simulateInteraction(element4, new DummyInteraction("bli", 1)); 135 simulateInteraction(element4, new DummyInteraction("bla", 1)); 136 simulateInteraction(element4, new DummyInteraction("bli", 1)); 137 simulateInteraction(element4, new DummyInteraction("blo", 1)); 138 simulateInteraction(element5, new DummyInteraction("bla", 1)); 139 simulateInteraction(element6, new DummyInteraction("bli", 1)); 140 simulateInteraction(element6, new DummyInteraction("bla", 1)); 141 simulateInteraction(element6, new DummyInteraction("bli", 1)); 142 simulateInteraction(element6, new DummyInteraction("blo", 1)); 143 144 new TaskTreeChecker().assertTaskTree 145 ("Sequence sequence0 {" + 146 " Sequence sequence1 {" + 147 " Interaction bla {}" + 148 " Interaction bli {}" + 149 " Interaction bla {}" + 150 " }" + 151 " Sequence sequence2 {" + 152 " Interaction bli {}" + 153 " Interaction blo {}" + 154 " }" + 155 " Sequence sequence3 {" + 156 " Interaction bla {}" + 157 " }" + 158 " Sequence sequence4 {" + 159 " Interaction bli {}" + 160 " Interaction bla {}" + 161 " Interaction bli {}" + 162 " Interaction blo {}" + 163 " }" + 164 " Sequence sequence5 {" + 165 " Interaction bla {}" + 166 " }" + 167 " Sequence sequence6 {" + 168 " Interaction bli {}" + 169 " Interaction bla {}" + 170 " Interaction bli {}" + 171 " Interaction blo {}" + 172 " }" + 173 "}", getTaskTree()); 174 } 37 /** 38 * 39 */ 40 @Test 41 public void testManyInteractionsOnOneElement() { 42 IEventTarget eventTarget = new DummyGUIElement("elem1"); 43 simulateEvent(new DummyInteraction("bla", 1), eventTarget); 44 simulateEvent(new DummyInteraction("bli", 1), eventTarget); 45 simulateEvent(new DummyInteraction("blo", 1), eventTarget); 46 simulateEvent(new DummyInteraction("blu", 1), eventTarget); 47 simulateEvent(new DummyInteraction("bla", 1), eventTarget); 175 48 176 //----------------------------------------------------------------------------------------------- 177 /** 178 * 179 */ 180 //----------------------------------------------------------------------------------------------- 181 @Test 182 public void testGUIElementHierarchyChanges() throws Exception 183 { 184 GUIElement element1 = new DummyGUIElement("elem1"); 185 GUIElement element2 = new DummyGUIElement("elem2"); 186 GUIElement element3 = new DummyGUIElement("elem3"); 187 GUIElement parent1 = new DummyGUIElement("parent1"); 188 GUIElement parent2 = new DummyGUIElement("parent2"); 189 GUIElement parent3 = new DummyGUIElement("parent3"); 190 191 element1.setParent(parent1); 192 element2.setParent(parent2); 193 element3.setParent(parent3); 194 195 parent1.setParent(parent2); 196 parent2.setParent(parent3); 197 198 Interaction interaction1 = new DummyInteraction("bla", 1); 199 simulateInteraction(element1, interaction1); 200 simulateInteraction(element2, interaction1); 201 simulateInteraction(element3, interaction1); 202 simulateInteraction(element2, interaction1); 203 simulateInteraction(element3, interaction1); 204 simulateInteraction(element2, interaction1); 205 simulateInteraction(element1, interaction1); 206 207 new TaskTreeChecker().assertTaskTree 208 ("Sequence sequence0 {" + 209 " Sequence sequence1 {" + 210 " Interaction bla {}" + 211 " }" + 212 " Sequence sequence2 {" + 213 " Interaction bla {}" + 214 " }" + 215 " Iteration iteration0 {" + 216 " Sequence sequence3 {" + 217 " Sequence sequence4 {" + 218 " Interaction bla {}" + 219 " }" + 220 " Sequence sequence5 {" + 221 " Interaction bla {}" + 222 " }" + 223 " }" + 224 " }" + 225 " Sequence sequence6 {" + 226 " Interaction bla {}" + 227 " }" + 228 "}", getTaskTree()); 49 new TaskTreeChecker().assertTaskTree 50 ("Sequence sequence {" + 51 " Event bla {}" + 52 " Event bli {}" + 53 " Event blo {}" + 54 " Event blu {}" + 55 " Event bla {}" + 56 "}", getTaskTree()); 57 } 229 58 230 } 231 59 /** 60 * 61 */ 62 @Test 63 public void testOneInteractionOnManyElements() { 64 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 65 IEventTarget eventTarget2 = new DummyGUIElement("elem2"); 66 IEventTarget eventTarget3 = new DummyGUIElement("elem3"); 67 IEventTarget eventTarget4 = new DummyGUIElement("elem4"); 68 IEventTarget eventTarget5 = new DummyGUIElement("elem5"); 69 IEventTarget eventTarget6 = new DummyGUIElement("elem6"); 70 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 71 simulateEvent(new DummyInteraction("bli", 1), eventTarget2); 72 simulateEvent(new DummyInteraction("bla", 1), eventTarget3); 73 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 74 simulateEvent(new DummyInteraction("blo", 1), eventTarget5); 75 simulateEvent(new DummyInteraction("bla", 1), eventTarget6); 76 77 new TaskTreeChecker().assertTaskTree 78 ("Sequence sequence0 {" + 79 " Sequence sequence1 {" + 80 " Event bla {}" + 81 " }" + 82 " Sequence sequence2 {" + 83 " Event bli {}" + 84 " }" + 85 " Sequence sequence3 {" + 86 " Event bla {}" + 87 " }" + 88 " Sequence sequence4 {" + 89 " Event bli {}" + 90 " }" + 91 " Sequence sequence5 {" + 92 " Event blo {}" + 93 " }" + 94 " Sequence sequence6 {" + 95 " Event bla {}" + 96 " }" + 97 "}", getTaskTree()); 98 } 99 100 /** 101 * 102 */ 103 @Test 104 public void testManyInteractionsOnManyElements() { 105 IEventTarget eventTarget1 = new DummyGUIElement("elem1"); 106 IEventTarget eventTarget2 = new DummyGUIElement("elem2"); 107 IEventTarget eventTarget3 = new DummyGUIElement("elem3"); 108 IEventTarget eventTarget4 = new DummyGUIElement("elem4"); 109 IEventTarget eventTarget5 = new DummyGUIElement("elem5"); 110 IEventTarget eventTarget6 = new DummyGUIElement("elem6"); 111 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 112 simulateEvent(new DummyInteraction("bli", 1), eventTarget1); 113 simulateEvent(new DummyInteraction("bla", 1), eventTarget1); 114 simulateEvent(new DummyInteraction("bli", 1), eventTarget2); 115 simulateEvent(new DummyInteraction("blo", 1), eventTarget2); 116 simulateEvent(new DummyInteraction("bla", 1), eventTarget3); 117 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 118 simulateEvent(new DummyInteraction("bla", 1), eventTarget4); 119 simulateEvent(new DummyInteraction("bli", 1), eventTarget4); 120 simulateEvent(new DummyInteraction("blo", 1), eventTarget4); 121 simulateEvent(new DummyInteraction("bla", 1), eventTarget5); 122 simulateEvent(new DummyInteraction("bli", 1), eventTarget6); 123 simulateEvent(new DummyInteraction("bla", 1), eventTarget6); 124 simulateEvent(new DummyInteraction("bli", 1), eventTarget6); 125 simulateEvent(new DummyInteraction("blo", 1), eventTarget6); 126 127 new TaskTreeChecker().assertTaskTree 128 ("Sequence sequence0 {" + 129 " Sequence sequence1 {" + 130 " Event bla {}" + 131 " Event bli {}" + 132 " Event bla {}" + 133 " }" + 134 " Sequence sequence2 {" + 135 " Event bli {}" + 136 " Event blo {}" + 137 " }" + 138 " Sequence sequence3 {" + 139 " Event bla {}" + 140 " }" + 141 " Sequence sequence4 {" + 142 " Event bli {}" + 143 " Event bla {}" + 144 " Event bli {}" + 145 " Event blo {}" + 146 " }" + 147 " Sequence sequence5 {" + 148 " Event bla {}" + 149 " }" + 150 " Sequence sequence6 {" + 151 " Event bli {}" + 152 " Event bla {}" + 153 " Event bli {}" + 154 " Event blo {}" + 155 " }" + 156 "}", getTaskTree()); 157 } 158 232 159 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultIterationDetectionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRuleTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 9 import org.junit.Test; 11 10 12 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;13 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;11 import de.ugoe.cs.quest.eventcore.IEventTarget; 12 import de.ugoe.cs.quest.eventcore.IEventType; 14 13 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 15 14 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 16 15 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 17 16 18 //-------------------------------------------------------------------------------------------------19 17 /** 20 18 * TODO comment … … 23 21 * @author 2012, last modified by $Author: patrick$ 24 22 */ 25 //------------------------------------------------------------------------------------------------- 26 public class DefaultIterationDetectionRuleTest extends AbstractTemporalRelationshipTC 27 { 28 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 @Test 35 public void testInteractionIterationDetection() throws Exception 36 { 37 GUIElement element1 = new DummyGUIElement("elem1"); 38 Interaction interaction1 = new DummyInteraction("bla", 1); 39 simulateInteraction(element1, interaction1); 40 new TaskTreeChecker().assertTaskTree 41 ("Sequence sequence1 {" + 42 " Interaction bla {}" + 43 "}", getTaskTree()); 44 45 simulateInteraction(element1, interaction1); 46 new TaskTreeChecker().assertTaskTree 47 ("Sequence sequence1 {" + 48 " Iteration iteration1 {" + 49 " Interaction bla {}" + 50 " }" + 51 "}", getTaskTree()); 52 53 simulateInteraction(element1, interaction1); 54 new TaskTreeChecker().assertTaskTree 55 ("Sequence sequence1 {" + 56 " Iteration iteration1 {" + 57 " Interaction bla {}" + 58 " }" + 59 "}", getTaskTree()); 60 61 for (int i = 0; i < 10; i++) 62 { 63 simulateInteraction(element1, interaction1); 23 public class DefaultIterationDetectionRuleTest extends AbstractTemporalRelationshipTC { 24 25 /** 26 * 27 */ 28 @Test 29 public void testInteractionIterationDetection() throws Exception { 30 IEventTarget element1 = new DummyGUIElement("elem1"); 31 IEventType event1 = new DummyInteraction("bla", 1); 32 simulateEvent(event1, element1); 33 new TaskTreeChecker().assertTaskTree 34 ("Sequence sequence1 {" + 35 " Event bla {}" + 36 "}", getTaskTree()); 37 38 simulateEvent(event1, element1); 39 new TaskTreeChecker().assertTaskTree 40 ("Sequence sequence1 {" + 41 " Iteration iteration1 {" + 42 " Event bla {}" + 43 " }" + 44 "}", getTaskTree()); 45 46 simulateEvent(event1, element1); 47 new TaskTreeChecker().assertTaskTree 48 ("Sequence sequence1 {" + 49 " Iteration iteration1 {" + 50 " Event bla {}" + 51 " }" + 52 "}", getTaskTree()); 53 54 for (int i = 0; i < 10; i++) { 55 simulateEvent(event1, element1); 56 } 57 58 new TaskTreeChecker().assertTaskTree 59 ("Sequence sequence1 {" + 60 " Iteration iteration1 {" + 61 " Event bla {}" + 62 " }" + 63 "}", getTaskTree()); 64 65 // now test with preceding and trailing other events 66 IEventType event2 = new DummyInteraction("bli", 1); 67 IEventType event3 = new DummyInteraction("blup", 1); 68 69 simulateEvent(event2, element1); 70 simulateEvent(event3, element1); 71 for (int i = 0; i < 10; i++) { 72 simulateEvent(event1, element1); 73 } 74 simulateEvent(event3, element1); 75 simulateEvent(event2, element1); 76 77 new TaskTreeChecker().assertTaskTree 78 ("Sequence sequence1 {" + 79 " Iteration iteration1 {" + 80 " Event bla {}" + 81 " }" + 82 " Event bli {}" + 83 " Event blup {}" + 84 " Iteration iteration2 {" + 85 " Event bla {}" + 86 " }" + 87 " Event blup {}" + 88 " Event bli {}" + 89 "}", getTaskTree()); 90 91 // now test with iterations of iterations 92 93 for (int i = 0; i < 10; i++) { 94 for (int j = 0; j < 5; j++) { 95 simulateEvent(event1, element1); 96 } 97 for (int j = 0; j < 5; j++) { 98 simulateEvent(event2, element1); 99 } 100 for (int j = 0; j < 5; j++) { 101 simulateEvent(event3, element1); 102 } 103 } 104 105 new TaskTreeChecker().assertTaskTree 106 ("Sequence sequence1 {" + 107 " Iteration iteration1 {" + 108 " Event bla {}" + 109 " }" + 110 " Event bli {}" + 111 " Event blup {}" + 112 " Iteration iteration2 {" + 113 " Event bla {}" + 114 " }" + 115 " Event blup {}" + 116 " Event bli {}" + 117 " Iteration iteration3 {" + 118 " Sequence sequence2 {" + 119 " Iteration iteration4 {" + 120 " Event bla {}" + 121 " }" + 122 " Iteration iteration5 {" + 123 " Event bli {}" + 124 " }" + 125 " Iteration iteration6 {" + 126 " Event blup {}" + 127 " }" + 128 " }" + 129 " }" + 130 "}", getTaskTree()); 131 64 132 } 65 66 new TaskTreeChecker().assertTaskTree 67 ("Sequence sequence1 {" + 68 " Iteration iteration1 {" + 69 " Interaction bla {}" + 70 " }" + 71 "}", getTaskTree()); 72 73 // now test with preceding and trailing other interactions 74 Interaction interaction2 = new DummyInteraction("bli", 1); 75 Interaction interaction3 = new DummyInteraction("blup", 1); 76 77 simulateInteraction(element1, interaction2); 78 simulateInteraction(element1, interaction3); 79 for (int i = 0; i < 10; i++) 80 { 81 simulateInteraction(element1, interaction1); 133 134 /** 135 * 136 */ 137 @Test 138 public void testSequenceIterationDetection() throws Exception { 139 IEventTarget element1 = new DummyGUIElement("elem1"); 140 IEventType event1 = new DummyInteraction("bla", 1); 141 IEventType event2 = new DummyInteraction("bli", 1); 142 IEventType event3 = new DummyInteraction("blup", 1); 143 simulateEvent(event1, element1); 144 simulateEvent(event2, element1); 145 simulateEvent(event3, element1); 146 new TaskTreeChecker().assertTaskTree 147 ("Sequence sequence1 {" + 148 " Event bla {}" + 149 " Event bli {}" + 150 " Event blup {}" + 151 "}", getTaskTree()); 152 153 simulateEvent(event1, element1); 154 simulateEvent(event2, element1); 155 simulateEvent(event3, element1); 156 new TaskTreeChecker().assertTaskTree 157 ("Sequence sequence1 {" + 158 " Iteration iteration1 {" + 159 " Sequence sequence2 {" + 160 " Event bla {}" + 161 " Event bli {}" + 162 " Event blup {}" + 163 " }" + 164 " }" + 165 "}", getTaskTree()); 166 167 simulateEvent(event1, element1); 168 simulateEvent(event2, element1); 169 simulateEvent(event3, element1); 170 new TaskTreeChecker().assertTaskTree 171 ("Sequence sequence1 {" + 172 " Iteration iteration1 {" + 173 " Sequence sequence2 {" + 174 " Event bla {}" + 175 " Event bli {}" + 176 " Event blup {}" + 177 " }" + 178 " }" + 179 "}", getTaskTree()); 180 181 for (int i = 0; i < 10; i++) { 182 simulateEvent(event1, element1); 183 simulateEvent(event2, element1); 184 simulateEvent(event3, element1); 185 } 186 187 new TaskTreeChecker().assertTaskTree 188 ("Sequence sequence1 {" + 189 " Iteration iteration1 {" + 190 " Sequence sequence2 {" + 191 " Event bla {}" + 192 " Event bli {}" + 193 " Event blup {}" + 194 " }" + 195 " }" + 196 "}", getTaskTree()); 197 198 // now test with preceding and trailing other events 199 IEventType event4 = new DummyInteraction("ble", 1); 200 IEventType event5 = new DummyInteraction("blo", 1); 201 IEventType event6 = new DummyInteraction("blu", 1); 202 simulateEvent(event4, element1); 203 simulateEvent(event5, element1); 204 simulateEvent(event6, element1); 205 for (int i = 0; i < 10; i++) { 206 simulateEvent(event1, element1); 207 simulateEvent(event2, element1); 208 simulateEvent(event3, element1); 209 } 210 simulateEvent(event6, element1); 211 simulateEvent(event5, element1); 212 simulateEvent(event4, element1); 213 214 new TaskTreeChecker().assertTaskTree 215 ("Sequence sequence1 {" + 216 " Iteration iteration1 {" + 217 " Sequence sequence2 {" + 218 " Event bla {}" + 219 " Event bli {}" + 220 " Event blup {}" + 221 " }" + 222 " }" + 223 " Event ble {}" + 224 " Event blo {}" + 225 " Event blu {}" + 226 " Iteration iteration2 {" + 227 " Sequence sequence3 {" + 228 " Event bla {}" + 229 " Event bli {}" + 230 " Event blup {}" + 231 " }" + 232 " }" + 233 " Event blu {}" + 234 " Event blo {}" + 235 " Event ble {}" + 236 "}", getTaskTree()); 237 238 // now test with iterations of iterations 239 for (int i = 0; i < 10; i++) { 240 for (int j = 0; j < 5; j++) { 241 simulateEvent(event1, element1); 242 simulateEvent(event2, element1); 243 simulateEvent(event3, element1); 244 } 245 for (int j = 0; j < 5; j++) { 246 simulateEvent(event2, element1); 247 simulateEvent(event1, element1); 248 simulateEvent(event3, element1); 249 } 250 for (int j = 0; j < 5; j++) { 251 simulateEvent(event1, element1); 252 simulateEvent(event2, element1); 253 simulateEvent(event3, element1); 254 } 255 } 256 257 new TaskTreeChecker().assertTaskTree 258 ("Sequence sequence1 {" + 259 " Iteration iteration1 {" + 260 " Sequence sequence2 {" + 261 " Event bla {}" + 262 " Event bli {}" + 263 " Event blup {}" + 264 " }" + 265 " }" + 266 " Event ble {}" + 267 " Event blo {}" + 268 " Event blu {}" + 269 " Iteration iteration2 {" + 270 " Sequence sequence3 {" + 271 " Event bla {}" + 272 " Event bli {}" + 273 " Event blup {}" + 274 " }" + 275 " }" + 276 " Event blu {}" + 277 " Event blo {}" + 278 " Event ble {}" + 279 " Iteration iteration3 {" + 280 " Sequence sequence4 {" + 281 " Iteration iteration4 {" + 282 " Sequence sequence4 {" + 283 " Event bla {}" + 284 " Event bli {}" + 285 " Event blup {}" + 286 " }" + 287 " }" + 288 " Iteration iteration5 {" + 289 " Sequence sequence5 {" + 290 " Event bli {}" + 291 " Event bla {}" + 292 " Event blup {}" + 293 " }" + 294 " }" + 295 " Iteration iteration6 {" + 296 " Sequence sequence6 {" + 297 " Event bla {}" + 298 " Event bli {}" + 299 " Event blup {}" + 300 " }" + 301 " }" + 302 " }" + 303 " }" + 304 "}", getTaskTree()); 82 305 } 83 simulateInteraction(element1, interaction3); 84 simulateInteraction(element1, interaction2); 85 86 new TaskTreeChecker().assertTaskTree 87 ("Sequence sequence1 {" + 88 " Iteration iteration1 {" + 89 " Interaction bla {}" + 90 " }" + 91 " Interaction bli {}" + 92 " Interaction blup {}" + 93 " Iteration iteration2 {" + 94 " Interaction bla {}" + 95 " }" + 96 " Interaction blup {}" + 97 " Interaction bli {}" + 98 "}", getTaskTree()); 99 100 // now test with iterations of iterations 101 102 for (int i = 0; i < 10; i++) 103 { 104 for (int j = 0; j < 5; j++) 105 { 106 simulateInteraction(element1, interaction1); 107 } 108 for (int j = 0; j < 5; j++) 109 { 110 simulateInteraction(element1, interaction2); 111 } 112 for (int j = 0; j < 5; j++) 113 { 114 simulateInteraction(element1, interaction3); 115 } 116 } 117 118 new TaskTreeChecker().assertTaskTree 119 ("Sequence sequence1 {" + 120 " Iteration iteration1 {" + 121 " Interaction bla {}" + 122 " }" + 123 " Interaction bli {}" + 124 " Interaction blup {}" + 125 " Iteration iteration2 {" + 126 " Interaction bla {}" + 127 " }" + 128 " Interaction blup {}" + 129 " Interaction bli {}" + 130 " Iteration iteration3 {" + 131 " Sequence sequence2 {" + 132 " Iteration iteration4 {" + 133 " Interaction bla {}" + 134 " }" + 135 " Iteration iteration5 {" + 136 " Interaction bli {}" + 137 " }" + 138 " Iteration iteration6 {" + 139 " Interaction blup {}" + 140 " }" + 141 " }" + 142 " }" + 143 "}", getTaskTree()); 144 145 } 146 147 //----------------------------------------------------------------------------------------------- 148 /** 149 * 150 */ 151 //----------------------------------------------------------------------------------------------- 152 @Test 153 public void testSequenceIterationDetection() throws Exception 154 { 155 GUIElement element1 = new DummyGUIElement("elem1"); 156 Interaction interaction1 = new DummyInteraction("bla", 1); 157 Interaction interaction2 = new DummyInteraction("bli", 1); 158 Interaction interaction3 = new DummyInteraction("blup", 1); 159 simulateInteraction(element1, interaction1); 160 simulateInteraction(element1, interaction2); 161 simulateInteraction(element1, interaction3); 162 new TaskTreeChecker().assertTaskTree 163 ("Sequence sequence1 {" + 164 " Interaction bla {}" + 165 " Interaction bli {}" + 166 " Interaction blup {}" + 167 "}", getTaskTree()); 168 169 simulateInteraction(element1, interaction1); 170 simulateInteraction(element1, interaction2); 171 simulateInteraction(element1, interaction3); 172 new TaskTreeChecker().assertTaskTree 173 ("Sequence sequence1 {" + 174 " Iteration iteration1 {" + 175 " Sequence sequence2 {" + 176 " Interaction bla {}" + 177 " Interaction bli {}" + 178 " Interaction blup {}" + 179 " }" + 180 " }" + 181 "}", getTaskTree()); 182 183 simulateInteraction(element1, interaction1); 184 simulateInteraction(element1, interaction2); 185 simulateInteraction(element1, interaction3); 186 new TaskTreeChecker().assertTaskTree 187 ("Sequence sequence1 {" + 188 " Iteration iteration1 {" + 189 " Sequence sequence2 {" + 190 " Interaction bla {}" + 191 " Interaction bli {}" + 192 " Interaction blup {}" + 193 " }" + 194 " }" + 195 "}", getTaskTree()); 196 197 for (int i = 0; i < 10; i++) 198 { 199 simulateInteraction(element1, interaction1); 200 simulateInteraction(element1, interaction2); 201 simulateInteraction(element1, interaction3); 202 } 203 204 new TaskTreeChecker().assertTaskTree 205 ("Sequence sequence1 {" + 206 " Iteration iteration1 {" + 207 " Sequence sequence2 {" + 208 " Interaction bla {}" + 209 " Interaction bli {}" + 210 " Interaction blup {}" + 211 " }" + 212 " }" + 213 "}", getTaskTree()); 214 215 // now test with preceding and trailing other interactions 216 Interaction interaction4 = new DummyInteraction("ble", 1); 217 Interaction interaction5 = new DummyInteraction("blo", 1); 218 Interaction interaction6 = new DummyInteraction("blu", 1); 219 simulateInteraction(element1, interaction4); 220 simulateInteraction(element1, interaction5); 221 simulateInteraction(element1, interaction6); 222 for (int i = 0; i < 10; i++) 223 { 224 simulateInteraction(element1, interaction1); 225 simulateInteraction(element1, interaction2); 226 simulateInteraction(element1, interaction3); 227 } 228 simulateInteraction(element1, interaction6); 229 simulateInteraction(element1, interaction5); 230 simulateInteraction(element1, interaction4); 231 232 new TaskTreeChecker().assertTaskTree 233 ("Sequence sequence1 {" + 234 " Iteration iteration1 {" + 235 " Sequence sequence2 {" + 236 " Interaction bla {}" + 237 " Interaction bli {}" + 238 " Interaction blup {}" + 239 " }" + 240 " }" + 241 " Interaction ble {}" + 242 " Interaction blo {}" + 243 " Interaction blu {}" + 244 " Iteration iteration2 {" + 245 " Sequence sequence3 {" + 246 " Interaction bla {}" + 247 " Interaction bli {}" + 248 " Interaction blup {}" + 249 " }" + 250 " }" + 251 " Interaction blu {}" + 252 " Interaction blo {}" + 253 " Interaction ble {}" + 254 "}", getTaskTree()); 255 256 // now test with iterations of iterations 257 for (int i = 0; i < 10; i++) 258 { 259 for (int j = 0; j < 5; j++) 260 { 261 simulateInteraction(element1, interaction1); 262 simulateInteraction(element1, interaction2); 263 simulateInteraction(element1, interaction3); 264 } 265 for (int j = 0; j < 5; j++) 266 { 267 simulateInteraction(element1, interaction2); 268 simulateInteraction(element1, interaction1); 269 simulateInteraction(element1, interaction3); 270 } 271 for (int j = 0; j < 5; j++) 272 { 273 simulateInteraction(element1, interaction1); 274 simulateInteraction(element1, interaction2); 275 simulateInteraction(element1, interaction3); 276 } 277 } 278 279 new TaskTreeChecker().assertTaskTree 280 ("Sequence sequence1 {" + 281 " Iteration iteration1 {" + 282 " Sequence sequence2 {" + 283 " Interaction bla {}" + 284 " Interaction bli {}" + 285 " Interaction blup {}" + 286 " }" + 287 " }" + 288 " Interaction ble {}" + 289 " Interaction blo {}" + 290 " Interaction blu {}" + 291 " Iteration iteration2 {" + 292 " Sequence sequence3 {" + 293 " Interaction bla {}" + 294 " Interaction bli {}" + 295 " Interaction blup {}" + 296 " }" + 297 " }" + 298 " Interaction blu {}" + 299 " Interaction blo {}" + 300 " Interaction ble {}" + 301 " Iteration iteration3 {" + 302 " Sequence sequence4 {" + 303 " Iteration iteration4 {" + 304 " Sequence sequence4 {" + 305 " Interaction bla {}" + 306 " Interaction bli {}" + 307 " Interaction blup {}" + 308 " }" + 309 " }" + 310 " Iteration iteration5 {" + 311 " Sequence sequence5 {" + 312 " Interaction bli {}" + 313 " Interaction bla {}" + 314 " Interaction blup {}" + 315 " }" + 316 " }" + 317 " Iteration iteration6 {" + 318 " Sequence sequence6 {" + 319 " Interaction bla {}" + 320 " Interaction bli {}" + 321 " Interaction blup {}" + 322 " }" + 323 " }" + 324 " }" + 325 " }" + 326 "}", getTaskTree()); 327 } 328 306 329 307 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultMouseClickReductionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManagerTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 21:32:36 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; … … 11 9 import org.junit.Test; 12 10 13 import de.ugoe.cs.quest.eventcore.gui model.GUIElement;14 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonDown;15 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonInteraction;16 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonUp;17 import de.ugoe.cs.quest.eventcore. userinteraction.MouseClick;11 import de.ugoe.cs.quest.eventcore.gui.MouseButtonDown; 12 import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction; 13 import de.ugoe.cs.quest.eventcore.gui.MouseButtonUp; 14 import de.ugoe.cs.quest.eventcore.gui.MouseClick; 15 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 18 16 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 19 17 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 20 18 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 21 19 22 //-------------------------------------------------------------------------------------------------23 20 /** 24 21 * TODO comment 25 * 22 * 26 23 * @version $Revision: $ $Date: $ 27 * @author 24 * @author 2011, last modified by $Author: $ 28 25 */ 29 //------------------------------------------------------------------------------------------------- 30 public class DefaultMouseClickReductionRuleTest extends AbstractTemporalRelationshipTC 31 { 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * 35 */ 36 //----------------------------------------------------------------------------------------------- 37 @Test 38 public void testMouseClickInOneSequenceElement() 39 { 40 MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT; 41 MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE; 42 MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT; 43 44 GUIElement element1 = new DummyGUIElement("elem1"); 45 GUIElement element2 = new DummyGUIElement("elem1"); 46 47 simulateInteraction(element1, new MouseButtonDown(leftBtn)); 48 simulateInteraction(element1, new MouseButtonUp(leftBtn)); 49 simulateInteraction(element1, new MouseClick(leftBtn)); 26 public class DefaultMouseClickReductionRuleTest extends AbstractTemporalRelationshipTC { 50 27 51 new TaskTreeChecker().assertTaskTree 52 ("Sequence sequence {" + 53 " Interaction LeftMouseClick {}" + 54 "}", getTaskTree()); 55 56 simulateInteraction(element1, new DummyInteraction("bla", 1)); 57 simulateInteraction(element1, new DummyInteraction("bli", 1)); 58 simulateInteraction(element1, new MouseButtonDown(middleBtn)); 59 simulateInteraction(element1, new MouseButtonUp(middleBtn)); 60 simulateInteraction(element1, new MouseClick(middleBtn)); 61 simulateInteraction(element1, new DummyInteraction("blo", 1)); 62 simulateInteraction(element1, new DummyInteraction("blu", 1)); 28 /** 29 * 30 */ 31 @Test 32 public void testMouseClickInOneSequenceElement() { 33 MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT; 34 MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE; 35 MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT; 63 36 64 new TaskTreeChecker().assertTaskTree 65 ("Sequence sequence {" + 66 " Interaction LeftMouseClick {}" + 67 " Interaction bla {}" + 68 " Interaction bli {}" + 69 " Interaction MiddleMouseClick {}" + 70 " Interaction blo {}" + 71 " Interaction blu {}" + 72 "}", getTaskTree()); 37 IGUIElement element1 = new DummyGUIElement("elem1"); 38 IGUIElement element2 = new DummyGUIElement("elem1"); 73 39 74 simulateInteraction(element2, new DummyInteraction("bla", 1)); 75 simulateInteraction(element2, new DummyInteraction("bli", 1)); 76 simulateInteraction(element2, new MouseButtonDown(rightBtn)); 77 simulateInteraction(element2, new MouseButtonUp(rightBtn)); 78 simulateInteraction(element2, new MouseClick(rightBtn)); 79 simulateInteraction(element2, new DummyInteraction("blo", 1)); 80 simulateInteraction(element2, new DummyInteraction("blu", 1)); 40 simulateEvent(new MouseButtonDown(leftBtn), element1); 41 simulateEvent(new MouseButtonUp(leftBtn), element1); 42 simulateEvent(new MouseClick(leftBtn), element1); 81 43 82 new TaskTreeChecker().assertTaskTree 83 ("Sequence sequence0 {" + 84 " Sequence sequence1 {" + 85 " Interaction LeftMouseClick {}" + 86 " Interaction bla {}" + 87 " Interaction bli {}" + 88 " Interaction MiddleMouseClick {}" + 89 " Interaction blo {}" + 90 " Interaction blu {}" + 91 " }" + 92 " Sequence sequence2 {" + 93 " Interaction bla {}" + 94 " Interaction bli {}" + 95 " Interaction RightMouseClick {}" + 96 " Interaction blo {}" + 97 " Interaction blu {}" + 98 " }" + 99 "}", getTaskTree()); 44 new TaskTreeChecker().assertTaskTree 45 ("Sequence sequence {" + 46 " Event LeftMouseClick {}" + 47 "}", getTaskTree()); 100 48 101 simulateInteraction(element1, new MouseButtonDown(leftBtn)); 102 simulateInteraction(element1, new MouseButtonUp(leftBtn)); 103 simulateInteraction(element2, new MouseClick(leftBtn)); 49 simulateEvent(new DummyInteraction("bla", 1), element1); 50 simulateEvent(new DummyInteraction("bli", 1), element1); 51 simulateEvent(new MouseButtonDown(middleBtn), element1); 52 simulateEvent(new MouseButtonUp(middleBtn), element1); 53 simulateEvent(new MouseClick(middleBtn), element1); 54 simulateEvent(new DummyInteraction("blo", 1), element1); 55 simulateEvent(new DummyInteraction("blu", 1), element1); 104 56 105 new TaskTreeChecker().assertTaskTree 106 ("Sequence sequence0 {" + 107 " Sequence sequence1 {" + 108 " Interaction LeftMouseClick {}" + 109 " Interaction bla {}" + 110 " Interaction bli {}" + 111 " Interaction MiddleMouseClick {}" + 112 " Interaction blo {}" + 113 " Interaction blu {}" + 114 " }" + 115 " Sequence sequence2 {" + 116 " Interaction bla {}" + 117 " Interaction bli {}" + 118 " Interaction RightMouseClick {}" + 119 " Interaction blo {}" + 120 " Interaction blu {}" + 121 " }" + 122 " Sequence sequence3 {" + 123 " Interaction LeftMouseButtonDown {}" + 124 " Interaction LeftMouseButtonUp {}" + 125 " }" + 126 " Sequence sequence4 {" + 127 " Interaction LeftMouseClick {}" + 128 " }" + 129 "}", getTaskTree()); 57 new TaskTreeChecker().assertTaskTree 58 ("Sequence sequence {" + 59 " Event LeftMouseClick {}" + 60 " Event bla {}" + 61 " Event bli {}" + 62 " Event MiddleMouseClick {}" + 63 " Event blo {}" + 64 " Event blu {}" + 65 "}", getTaskTree()); 130 66 131 simulateInteraction(element1, new MouseButtonDown(middleBtn)); 132 simulateInteraction(element1, new MouseButtonUp(middleBtn)); 133 simulateInteraction(element1, new MouseClick(rightBtn)); 134 simulateInteraction(element2, new DummyInteraction("bla", 1)); 67 simulateEvent(new DummyInteraction("bla", 1), element2); 68 simulateEvent(new DummyInteraction("bli", 1), element2); 69 simulateEvent(new MouseButtonDown(rightBtn), element2); 70 simulateEvent(new MouseButtonUp(rightBtn), element2); 71 simulateEvent(new MouseClick(rightBtn), element2); 72 simulateEvent(new DummyInteraction("blo", 1), element2); 73 simulateEvent(new DummyInteraction("blu", 1), element2); 135 74 136 new TaskTreeChecker().assertTaskTree 137 ("Sequence sequence0 {" + 138 " Sequence sequence1 {" + 139 " Interaction LeftMouseClick {}" + 140 " Interaction bla {}" + 141 " Interaction bli {}" + 142 " Interaction MiddleMouseClick {}" + 143 " Interaction blo {}" + 144 " Interaction blu {}" + 145 " }" + 146 " Sequence sequence2 {" + 147 " Interaction bla {}" + 148 " Interaction bli {}" + 149 " Interaction RightMouseClick {}" + 150 " Interaction blo {}" + 151 " Interaction blu {}" + 152 " }" + 153 " Sequence sequence3 {" + 154 " Interaction LeftMouseButtonDown {}" + 155 " Interaction LeftMouseButtonUp {}" + 156 " }" + 157 " Sequence sequence4 {" + 158 " Interaction LeftMouseClick {}" + 159 " }" + 160 " Sequence sequence5 {" + 161 " Sequence sequence6 {" + 162 " Interaction MiddleMouseButtonDown {}" + 163 " Interaction MiddleMouseButtonUp {}" + 164 " }" + 165 " Interaction RightMouseClick {}" + 166 " }" + 167 " Sequence sequence7 {" + 168 " Interaction bla {}" + 169 " }" + 170 "}", getTaskTree()); 75 new TaskTreeChecker().assertTaskTree 76 ("Sequence sequence0 {" + 77 " Sequence sequence1 {" + 78 " Event LeftMouseClick {}" + 79 " Event bla {}" + 80 " Event bli {}" + 81 " Event MiddleMouseClick {}" + 82 " Event blo {}" + 83 " Event blu {}" + 84 " }" + 85 " Sequence sequence2 {" + 86 " Event bla {}" + 87 " Event bli {}" + 88 " Event RightMouseClick {}" + 89 " Event blo {}" + 90 " Event blu {}" + 91 " }" + 92 "}", getTaskTree()); 171 93 172 } 173 94 simulateEvent(new MouseButtonDown(leftBtn), element1); 95 simulateEvent(new MouseButtonUp(leftBtn), element1); 96 simulateEvent(new MouseClick(leftBtn), element2); 97 98 new TaskTreeChecker().assertTaskTree 99 ("Sequence sequence0 {" + 100 " Sequence sequence1 {" + 101 " Event LeftMouseClick {}" + 102 " Event bla {}" + 103 " Event bli {}" + 104 " Event MiddleMouseClick {}" + 105 " Event blo {}" + 106 " Event blu {}" + 107 " }" + 108 " Sequence sequence2 {" + 109 " Event bla {}" + 110 " Event bli {}" + 111 " Event RightMouseClick {}" + 112 " Event blo {}" + 113 " Event blu {}" + 114 " }" + 115 " Sequence sequence3 {" + 116 " Event LeftMouseButtonDown {}" + 117 " Event LeftMouseButtonUp {}" + 118 " }" + 119 " Sequence sequence4 {" + 120 " Event LeftMouseClick {}" + 121 " }" + 122 "}", getTaskTree()); 123 124 simulateEvent(new MouseButtonDown(middleBtn), element1); 125 simulateEvent(new MouseButtonUp(middleBtn), element1); 126 simulateEvent(new MouseClick(rightBtn), element1); 127 simulateEvent(new DummyInteraction("bla", 1), element2); 128 129 new TaskTreeChecker().assertTaskTree 130 ("Sequence sequence0 {" + 131 " Sequence sequence1 {" + 132 " Event LeftMouseClick {}" + 133 " Event bla {}" + 134 " Event bli {}" + 135 " Event MiddleMouseClick {}" + 136 " Event blo {}" + 137 " Event blu {}" + 138 " }" + 139 " Sequence sequence2 {" + 140 " Event bla {}" + 141 " Event bli {}" + 142 " Event RightMouseClick {}" + 143 " Event blo {}" + 144 " Event blu {}" + 145 " }" + 146 " Sequence sequence3 {" + 147 " Event LeftMouseButtonDown {}" + 148 " Event LeftMouseButtonUp {}" + 149 " }" + 150 " Sequence sequence4 {" + 151 " Event LeftMouseClick {}" + 152 " }" + 153 " Sequence sequence5 {" + 154 " Sequence sequence6 {" + 155 " Event MiddleMouseButtonDown {}" + 156 " Event MiddleMouseButtonUp {}" + 157 " }" + 158 " Event RightMouseClick {}" + 159 " }" + 160 " Sequence sequence7 {" + 161 " Event bla {}" + 162 " }" + 163 "}", getTaskTree()); 164 165 } 166 174 167 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultTextInputReductionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRuleTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 9 import org.junit.Test; 11 10 12 import de.ugoe.cs.quest.eventcore.gui model.GUIElement;13 import de.ugoe.cs.quest.eventcore.gui model.TextField;14 import de.ugoe.cs.quest.eventcore. userinteraction.KeyPressed;15 import de.ugoe.cs.quest.eventcore. userinteraction.KeyReleased;11 import de.ugoe.cs.quest.eventcore.gui.KeyPressed; 12 import de.ugoe.cs.quest.eventcore.gui.KeyReleased; 13 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 14 import de.ugoe.cs.quest.eventcore.guimodel.ITextField; 16 15 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 17 16 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 18 17 import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; 19 18 20 //-------------------------------------------------------------------------------------------------21 19 /** 22 20 * TODO comment … … 25 23 * @author 2012, last modified by $Author: patrick$ 26 24 */ 27 //------------------------------------------------------------------------------------------------- 28 public class DefaultTextInputReductionRuleTest extends AbstractTemporalRelationshipTC 29 { 30 31 //----------------------------------------------------------------------------------------------- 32 /** 33 * 34 */ 35 //----------------------------------------------------------------------------------------------- 36 @Test 37 public void testSimpleTextEntry() 38 { 39 GUIElement element1 = new DummyTextField("elem1"); 40 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A)); 41 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A)); 42 new TaskTreeChecker(true).assertTaskTree 43 ("Sequence sequence0 {" + 44 " TextInputInteraction TextInput a {" + 45 " Interaction KeyPressed LETTER_A {}" + 46 " Interaction KeyReleased LETTER_A {}" + 47 " }" + 48 "}", getTaskTree()); 49 50 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_B)); 51 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_B)); 52 new TaskTreeChecker().assertTaskTree 53 ("Sequence sequence0 {" + 54 " TextInputInteraction TextInput ab {" + 55 " Interaction KeyPressed LETTER_A {}" + 56 " Interaction KeyReleased LETTER_A {}" + 57 " Interaction KeyPressed LETTER_B {}" + 58 " Interaction KeyReleased LETTER_B {}" + 59 " }" + 60 "}", getTaskTree()); 61 62 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 63 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C)); 64 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C)); 65 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 66 new TaskTreeChecker().assertTaskTree 67 ("Sequence sequence0 {" + 68 " TextInputInteraction TextInput abC {" + 69 " Interaction KeyPressed LETTER_A {}" + 70 " Interaction KeyReleased LETTER_A {}" + 71 " Interaction KeyPressed LETTER_B {}" + 72 " Interaction KeyReleased LETTER_B {}" + 73 " Interaction KeyPressed SHIFT {}" + 74 " Interaction KeyPressed LETTER_C {}" + 75 " Interaction KeyReleased LETTER_C {}" + 76 " Interaction KeyReleased SHIFT {}" + 77 " }" + 78 "}", getTaskTree()); 79 80 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 81 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_D)); 82 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_D)); 83 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_E)); 84 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_E)); 85 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_F)); 86 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_F)); 87 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 88 new TaskTreeChecker().assertTaskTree 89 ("Sequence sequence0 {" + 90 " TextInputInteraction TextInput abCDEF {" + 91 " Interaction KeyPressed LETTER_A {}" + 92 " Interaction KeyReleased LETTER_A {}" + 93 " Interaction KeyPressed LETTER_B {}" + 94 " Interaction KeyReleased LETTER_B {}" + 95 " Interaction KeyPressed SHIFT {}" + 96 " Interaction KeyPressed LETTER_C {}" + 97 " Interaction KeyReleased LETTER_C {}" + 98 " Interaction KeyReleased SHIFT {}" + 99 " Interaction KeyPressed SHIFT {}" + 100 " Interaction KeyPressed LETTER_D {}" + 101 " Interaction KeyReleased LETTER_D {}" + 102 " Interaction KeyPressed LETTER_E {}" + 103 " Interaction KeyReleased LETTER_E {}" + 104 " Interaction KeyPressed LETTER_F {}" + 105 " Interaction KeyReleased LETTER_F {}" + 106 " Interaction KeyReleased SHIFT {}" + 107 " }" + 108 "}", getTaskTree()); 109 110 111 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 112 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 113 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_G)); 114 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_G)); 115 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 116 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 117 new TaskTreeChecker().assertTaskTree 118 ("Sequence sequence0 {" + 119 " TextInputInteraction TextInput abCDEFg {" + 120 " Interaction KeyPressed LETTER_A {}" + 121 " Interaction KeyReleased LETTER_A {}" + 122 " Interaction KeyPressed LETTER_B {}" + 123 " Interaction KeyReleased LETTER_B {}" + 124 " Interaction KeyPressed SHIFT {}" + 125 " Interaction KeyPressed LETTER_C {}" + 126 " Interaction KeyReleased LETTER_C {}" + 127 " Interaction KeyReleased SHIFT {}" + 128 " Interaction KeyPressed SHIFT {}" + 129 " Interaction KeyPressed LETTER_D {}" + 130 " Interaction KeyReleased LETTER_D {}" + 131 " Interaction KeyPressed LETTER_E {}" + 132 " Interaction KeyReleased LETTER_E {}" + 133 " Interaction KeyPressed LETTER_F {}" + 134 " Interaction KeyReleased LETTER_F {}" + 135 " Interaction KeyReleased SHIFT {}" + 136 " Interaction KeyPressed SHIFT {}" + 137 " Interaction KeyPressed SHIFT {}" + 138 " Interaction KeyPressed LETTER_G {}" + 139 " Interaction KeyReleased LETTER_G {}" + 140 " Interaction KeyReleased SHIFT {}" + 141 " Interaction KeyReleased SHIFT {}" + 142 " }" + 143 "}", getTaskTree()); 144 145 } 146 147 //----------------------------------------------------------------------------------------------- 148 /** 149 * 150 */ 151 //----------------------------------------------------------------------------------------------- 152 @Test 153 public void testTextEntryOnDifferentGuiElements() 154 { 155 GUIElement element1 = new DummyTextField("elem1"); 156 GUIElement element2 = new DummyTextField("elem2"); 157 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A)); 158 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A)); 159 new TaskTreeChecker().assertTaskTree 160 ("Sequence sequence0 {" + 161 " TextInputInteraction TextInput a {" + 162 " Interaction KeyPressed LETTER_A {}" + 163 " Interaction KeyReleased LETTER_A {}" + 164 " }" + 165 "}", getTaskTree()); 166 167 simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_B)); 168 simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_B)); 169 new TaskTreeChecker().assertTaskTree 170 ("Sequence sequence0 {" + 171 " Sequence sequence1 {" + 172 " TextInputInteraction TextInput a {" + 173 " Interaction KeyPressed LETTER_A {}" + 174 " Interaction KeyReleased LETTER_A {}" + 175 " }" + 176 " }" + 177 " Sequence sequence2 {" + 178 " TextInputInteraction TextInput b {" + 179 " Interaction KeyPressed LETTER_B {}" + 180 " Interaction KeyReleased LETTER_B {}" + 181 " }" + 182 " }" + 183 "}", getTaskTree()); 184 185 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 186 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C)); 187 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C)); 188 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 189 new TaskTreeChecker().assertTaskTree 190 ("Sequence sequence0 {" + 191 " Sequence sequence1 {" + 192 " TextInputInteraction TextInput a {" + 193 " Interaction KeyPressed LETTER_A {}" + 194 " Interaction KeyReleased LETTER_A {}" + 195 " }" + 196 " }" + 197 " Sequence sequence2 {" + 198 " TextInputInteraction TextInput b {" + 199 " Interaction KeyPressed LETTER_B {}" + 200 " Interaction KeyReleased LETTER_B {}" + 201 " }" + 202 " }" + 203 " Sequence sequence3 {" + 204 " TextInputInteraction TextInput C {" + 205 " Interaction KeyPressed SHIFT {}" + 206 " Interaction KeyPressed LETTER_C {}" + 207 " Interaction KeyReleased LETTER_C {}" + 208 " Interaction KeyReleased SHIFT {}" + 209 " }" + 210 " }" + 211 "}", getTaskTree()); 212 213 simulateInteraction(element2, new KeyPressed(VirtualKey.SHIFT)); 214 simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_D)); 215 simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_D)); 216 simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_E)); 217 simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_E)); 218 simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_F)); 219 simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_F)); 220 simulateInteraction(element2, new KeyReleased(VirtualKey.SHIFT)); 221 new TaskTreeChecker().assertTaskTree 222 ("Sequence sequence0 {" + 223 " Sequence sequence1 {" + 224 " TextInputInteraction TextInput a {" + 225 " Interaction KeyPressed LETTER_A {}" + 226 " Interaction KeyReleased LETTER_A {}" + 227 " }" + 228 " }" + 229 " Sequence sequence2 {" + 230 " TextInputInteraction TextInput b {" + 231 " Interaction KeyPressed LETTER_B {}" + 232 " Interaction KeyReleased LETTER_B {}" + 233 " }" + 234 " }" + 235 " Sequence sequence3 {" + 236 " TextInputInteraction TextInput C {" + 237 " Interaction KeyPressed SHIFT {}" + 238 " Interaction KeyPressed LETTER_C {}" + 239 " Interaction KeyReleased LETTER_C {}" + 240 " Interaction KeyReleased SHIFT {}" + 241 " }" + 242 " }" + 243 " Sequence sequence4 {" + 244 " TextInputInteraction TextInput DEF {" + 245 " Interaction KeyPressed SHIFT {}" + 246 " Interaction KeyPressed LETTER_D {}" + 247 " Interaction KeyReleased LETTER_D {}" + 248 " Interaction KeyPressed LETTER_E {}" + 249 " Interaction KeyReleased LETTER_E {}" + 250 " Interaction KeyPressed LETTER_F {}" + 251 " Interaction KeyReleased LETTER_F {}" + 252 " Interaction KeyReleased SHIFT {}" + 253 " }" + 254 " }" + 255 "}", getTaskTree()); 256 257 258 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 259 simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT)); 260 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_G)); 261 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_G)); 262 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 263 simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT)); 264 new TaskTreeChecker().assertTaskTree 265 ("Sequence sequence0 {" + 266 " Sequence sequence1 {" + 267 " TextInputInteraction TextInput a {" + 268 " Interaction KeyPressed LETTER_A {}" + 269 " Interaction KeyReleased LETTER_A {}" + 270 " }" + 271 " }" + 272 " Sequence sequence2 {" + 273 " TextInputInteraction TextInput b {" + 274 " Interaction KeyPressed LETTER_B {}" + 275 " Interaction KeyReleased LETTER_B {}" + 276 " }" + 277 " }" + 278 " Sequence sequence3 {" + 279 " TextInputInteraction TextInput C {" + 280 " Interaction KeyPressed SHIFT {}" + 281 " Interaction KeyPressed LETTER_C {}" + 282 " Interaction KeyReleased LETTER_C {}" + 283 " Interaction KeyReleased SHIFT {}" + 284 " }" + 285 " }" + 286 " Sequence sequence4 {" + 287 " TextInputInteraction TextInput DEF {" + 288 " Interaction KeyPressed SHIFT {}" + 289 " Interaction KeyPressed LETTER_D {}" + 290 " Interaction KeyReleased LETTER_D {}" + 291 " Interaction KeyPressed LETTER_E {}" + 292 " Interaction KeyReleased LETTER_E {}" + 293 " Interaction KeyPressed LETTER_F {}" + 294 " Interaction KeyReleased LETTER_F {}" + 295 " Interaction KeyReleased SHIFT {}" + 296 " }" + 297 " }" + 298 " Sequence sequence5 {" + 299 " TextInputInteraction TextInput g {" + 300 " Interaction KeyPressed SHIFT {}" + 301 " Interaction KeyPressed SHIFT {}" + 302 " Interaction KeyPressed LETTER_G {}" + 303 " Interaction KeyReleased LETTER_G {}" + 304 " Interaction KeyReleased SHIFT {}" + 305 " Interaction KeyReleased SHIFT {}" + 306 " }" + 307 " }" + 308 "}", getTaskTree()); 309 310 } 311 312 //----------------------------------------------------------------------------------------------- 313 /** 314 * 315 */ 316 //----------------------------------------------------------------------------------------------- 317 @Test 318 public void testUsageOfBackspace() 319 { 320 GUIElement element1 = new DummyTextField("elem1"); 321 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A)); 322 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A)); 323 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_B)); 324 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_B)); 325 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C)); 326 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C)); 327 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_D)); 328 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_D)); 329 simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE)); 330 simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE)); 331 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_E)); 332 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_E)); 333 simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_F)); 334 simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_F)); 335 new TaskTreeChecker().assertTaskTree 336 ("Sequence sequence0 {" + 337 " TextInputInteraction TextInput abcef {" + 338 " Interaction KeyPressed LETTER_A {}" + 339 " Interaction KeyReleased LETTER_A {}" + 340 " Interaction KeyPressed LETTER_B {}" + 341 " Interaction KeyReleased LETTER_B {}" + 342 " Interaction KeyPressed LETTER_C {}" + 343 " Interaction KeyReleased LETTER_C {}" + 344 " Interaction KeyPressed LETTER_D {}" + 345 " Interaction KeyReleased LETTER_D {}" + 346 " Interaction KeyPressed BACK_SPACE {}" + 347 " Interaction KeyReleased BACK_SPACE {}" + 348 " Interaction KeyPressed LETTER_E {}" + 349 " Interaction KeyReleased LETTER_E {}" + 350 " Interaction KeyPressed LETTER_F {}" + 351 " Interaction KeyReleased LETTER_F {}" + 352 " }" + 353 "}", getTaskTree()); 354 355 simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE)); 356 simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE)); 357 simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE)); 358 simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE)); 359 simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE)); 360 simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE)); 361 new TaskTreeChecker().assertTaskTree 362 ("Sequence sequence0 {" + 363 " TextInputInteraction TextInput ab {" + 364 " Interaction KeyPressed LETTER_A {}" + 365 " Interaction KeyReleased LETTER_A {}" + 366 " Interaction KeyPressed LETTER_B {}" + 367 " Interaction KeyReleased LETTER_B {}" + 368 " Interaction KeyPressed LETTER_C {}" + 369 " Interaction KeyReleased LETTER_C {}" + 370 " Interaction KeyPressed LETTER_D {}" + 371 " Interaction KeyReleased LETTER_D {}" + 372 " Interaction KeyPressed BACK_SPACE {}" + 373 " Interaction KeyReleased BACK_SPACE {}" + 374 " Interaction KeyPressed LETTER_E {}" + 375 " Interaction KeyReleased LETTER_E {}" + 376 " Interaction KeyPressed LETTER_F {}" + 377 " Interaction KeyReleased LETTER_F {}" + 378 " Interaction KeyPressed BACK_SPACE {}" + 379 " Interaction KeyReleased BACK_SPACE {}" + 380 " Interaction KeyPressed BACK_SPACE {}" + 381 " Interaction KeyReleased BACK_SPACE {}" + 382 " Interaction KeyPressed BACK_SPACE {}" + 383 " Interaction KeyReleased BACK_SPACE {}" + 384 " }" + 385 "}", getTaskTree()); 386 387 } 388 389 //----------------------------------------------------------------------------------------------- 390 /** 391 * 392 */ 393 //----------------------------------------------------------------------------------------------- 394 private static class DummyTextField extends DummyGUIElement implements TextField 395 { 396 397 //--------------------------------------------------------------------------------------------- 25 public class DefaultTextInputReductionRuleTest extends AbstractTemporalRelationshipTC { 26 398 27 /** 399 * TODO: comment400 28 * 401 * @param name402 29 */ 403 //--------------------------------------------------------------------------------------------- 404 public DummyTextField(String name) 405 { 406 super(name); 30 @Test 31 public void testSimpleTextEntry() { 32 IGUIElement element1 = new DummyTextField("elem1"); 33 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 34 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 35 new TaskTreeChecker(true).assertTaskTree 36 ("Sequence sequence0 {" + 37 " TextInputEvent TextInput a {" + 38 " Event KeyPressed LETTER_A {}" + 39 " Event KeyReleased LETTER_A {}" + 40 " }" + 41 "}", getTaskTree()); 42 43 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 44 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 45 new TaskTreeChecker().assertTaskTree 46 ("Sequence sequence0 {" + 47 " TextInputEvent TextInput ab {" + 48 " Event KeyPressed LETTER_A {}" + 49 " Event KeyReleased LETTER_A {}" + 50 " Event KeyPressed LETTER_B {}" + 51 " Event KeyReleased LETTER_B {}" + 52 " }" + 53 "}", getTaskTree()); 54 55 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 56 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 57 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 58 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 59 new TaskTreeChecker().assertTaskTree 60 ("Sequence sequence0 {" + 61 " TextInputEvent TextInput abC {" + 62 " Event KeyPressed LETTER_A {}" + 63 " Event KeyReleased LETTER_A {}" + 64 " Event KeyPressed LETTER_B {}" + 65 " Event KeyReleased LETTER_B {}" + 66 " Event KeyPressed SHIFT {}" + 67 " Event KeyPressed LETTER_C {}" + 68 " Event KeyReleased LETTER_C {}" + 69 " Event KeyReleased SHIFT {}" + 70 " }" + 71 "}", getTaskTree()); 72 73 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 74 simulateEvent(new KeyPressed(VirtualKey.LETTER_D), element1); 75 simulateEvent(new KeyReleased(VirtualKey.LETTER_D), element1); 76 simulateEvent(new KeyPressed(VirtualKey.LETTER_E), element1); 77 simulateEvent(new KeyReleased(VirtualKey.LETTER_E), element1); 78 simulateEvent(new KeyPressed(VirtualKey.LETTER_F), element1); 79 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element1); 80 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 81 new TaskTreeChecker().assertTaskTree 82 ("Sequence sequence0 {" + 83 " TextInputEvent TextInput abCDEF {" + 84 " Event KeyPressed LETTER_A {}" + 85 " Event KeyReleased LETTER_A {}" + 86 " Event KeyPressed LETTER_B {}" + 87 " Event KeyReleased LETTER_B {}" + 88 " Event KeyPressed SHIFT {}" + 89 " Event KeyPressed LETTER_C {}" + 90 " Event KeyReleased LETTER_C {}" + 91 " Event KeyReleased SHIFT {}" + 92 " Event KeyPressed SHIFT {}" + 93 " Event KeyPressed LETTER_D {}" + 94 " Event KeyReleased LETTER_D {}" + 95 " Event KeyPressed LETTER_E {}" + 96 " Event KeyReleased LETTER_E {}" + 97 " Event KeyPressed LETTER_F {}" + 98 " Event KeyReleased LETTER_F {}" + 99 " Event KeyReleased SHIFT {}" + 100 " }" + 101 "}", getTaskTree()); 102 103 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 104 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 105 simulateEvent(new KeyPressed(VirtualKey.LETTER_G), element1); 106 simulateEvent(new KeyReleased(VirtualKey.LETTER_G), element1); 107 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 108 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 109 new TaskTreeChecker().assertTaskTree 110 ("Sequence sequence0 {" + 111 " TextInputEvent TextInput abCDEFg {" + 112 " Event KeyPressed LETTER_A {}" + 113 " Event KeyReleased LETTER_A {}" + 114 " Event KeyPressed LETTER_B {}" + 115 " Event KeyReleased LETTER_B {}" + 116 " Event KeyPressed SHIFT {}" + 117 " Event KeyPressed LETTER_C {}" + 118 " Event KeyReleased LETTER_C {}" + 119 " Event KeyReleased SHIFT {}" + 120 " Event KeyPressed SHIFT {}" + 121 " Event KeyPressed LETTER_D {}" + 122 " Event KeyReleased LETTER_D {}" + 123 " Event KeyPressed LETTER_E {}" + 124 " Event KeyReleased LETTER_E {}" + 125 " Event KeyPressed LETTER_F {}" + 126 " Event KeyReleased LETTER_F {}" + 127 " Event KeyReleased SHIFT {}" + 128 " Event KeyPressed SHIFT {}" + 129 " Event KeyPressed SHIFT {}" + 130 " Event KeyPressed LETTER_G {}" + 131 " Event KeyReleased LETTER_G {}" + 132 " Event KeyReleased SHIFT {}" + 133 " Event KeyReleased SHIFT {}" + 134 " }" + 135 "}", getTaskTree()); 136 407 137 } 408 138 409 } 139 /** 140 * 141 */ 142 @Test 143 public void testTextEntryOnDifferentGuiElements() { 144 IGUIElement element1 = new DummyTextField("elem1"); 145 IGUIElement element2 = new DummyTextField("elem2"); 146 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 147 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 148 new TaskTreeChecker().assertTaskTree 149 ("Sequence sequence0 {" + 150 " TextInputEvent TextInput a {" + 151 " Event KeyPressed LETTER_A {}" + 152 " Event KeyReleased LETTER_A {}" + 153 " }" + 154 "}", getTaskTree()); 155 156 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element2); 157 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element2); 158 new TaskTreeChecker().assertTaskTree 159 ("Sequence sequence0 {" + 160 " Sequence sequence1 {" + 161 " TextInputEvent TextInput a {" + 162 " Event KeyPressed LETTER_A {}" + 163 " Event KeyReleased LETTER_A {}" + 164 " }" + 165 " }" + 166 " Sequence sequence2 {" + 167 " TextInputEvent TextInput b {" + 168 " Event KeyPressed LETTER_B {}" + 169 " Event KeyReleased LETTER_B {}" + 170 " }" + 171 " }" + 172 "}", getTaskTree()); 173 174 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 175 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 176 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 177 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 178 new TaskTreeChecker().assertTaskTree 179 ("Sequence sequence0 {" + 180 " Sequence sequence1 {" + 181 " TextInputEvent TextInput a {" + 182 " Event KeyPressed LETTER_A {}" + 183 " Event KeyReleased LETTER_A {}" + 184 " }" + 185 " }" + 186 " Sequence sequence2 {" + 187 " TextInputEvent TextInput b {" + 188 " Event KeyPressed LETTER_B {}" + 189 " Event KeyReleased LETTER_B {}" + 190 " }" + 191 " }" + 192 " Sequence sequence3 {" + 193 " TextInputEvent TextInput C {" + 194 " Event KeyPressed SHIFT {}" + 195 " Event KeyPressed LETTER_C {}" + 196 " Event KeyReleased LETTER_C {}" + 197 " Event KeyReleased SHIFT {}" + 198 " }" + 199 " }" + 200 "}", getTaskTree()); 201 202 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element2); 203 simulateEvent(new KeyPressed(VirtualKey.LETTER_D), element2); 204 simulateEvent(new KeyReleased(VirtualKey.LETTER_D), element2); 205 simulateEvent(new KeyPressed(VirtualKey.LETTER_E), element2); 206 simulateEvent(new KeyReleased(VirtualKey.LETTER_E), element2); 207 simulateEvent(new KeyPressed(VirtualKey.LETTER_F), element2); 208 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element2); 209 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element2); 210 new TaskTreeChecker().assertTaskTree 211 ("Sequence sequence0 {" + 212 " Sequence sequence1 {" + 213 " TextInputEvent TextInput a {" + 214 " Event KeyPressed LETTER_A {}" + 215 " Event KeyReleased LETTER_A {}" + 216 " }" + 217 " }" + 218 " Sequence sequence2 {" + 219 " TextInputEvent TextInput b {" + 220 " Event KeyPressed LETTER_B {}" + 221 " Event KeyReleased LETTER_B {}" + 222 " }" + 223 " }" + 224 " Sequence sequence3 {" + 225 " TextInputEvent TextInput C {" + 226 " Event KeyPressed SHIFT {}" + 227 " Event KeyPressed LETTER_C {}" + 228 " Event KeyReleased LETTER_C {}" + 229 " Event KeyReleased SHIFT {}" + 230 " }" + 231 " }" + 232 " Sequence sequence4 {" + 233 " TextInputEvent TextInput DEF {" + 234 " Event KeyPressed SHIFT {}" + 235 " Event KeyPressed LETTER_D {}" + 236 " Event KeyReleased LETTER_D {}" + 237 " Event KeyPressed LETTER_E {}" + 238 " Event KeyReleased LETTER_E {}" + 239 " Event KeyPressed LETTER_F {}" + 240 " Event KeyReleased LETTER_F {}" + 241 " Event KeyReleased SHIFT {}" + 242 " }" + 243 " }" + 244 "}", getTaskTree()); 245 246 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 247 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 248 simulateEvent(new KeyPressed(VirtualKey.LETTER_G), element1); 249 simulateEvent(new KeyReleased(VirtualKey.LETTER_G), element1); 250 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 251 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 252 new TaskTreeChecker().assertTaskTree 253 ("Sequence sequence0 {" + 254 " Sequence sequence1 {" + 255 " TextInputEvent TextInput a {" + 256 " Event KeyPressed LETTER_A {}" + 257 " Event KeyReleased LETTER_A {}" + 258 " }" + 259 " }" + 260 " Sequence sequence2 {" + 261 " TextInputEvent TextInput b {" + 262 " Event KeyPressed LETTER_B {}" + 263 " Event KeyReleased LETTER_B {}" + 264 " }" + 265 " }" + 266 " Sequence sequence3 {" + 267 " TextInputEvent TextInput C {" + 268 " Event KeyPressed SHIFT {}" + 269 " Event KeyPressed LETTER_C {}" + 270 " Event KeyReleased LETTER_C {}" + 271 " Event KeyReleased SHIFT {}" + 272 " }" + 273 " }" + 274 " Sequence sequence4 {" + 275 " TextInputEvent TextInput DEF {" + 276 " Event KeyPressed SHIFT {}" + 277 " Event KeyPressed LETTER_D {}" + 278 " Event KeyReleased LETTER_D {}" + 279 " Event KeyPressed LETTER_E {}" + 280 " Event KeyReleased LETTER_E {}" + 281 " Event KeyPressed LETTER_F {}" + 282 " Event KeyReleased LETTER_F {}" + 283 " Event KeyReleased SHIFT {}" + 284 " }" + 285 " }" + 286 " Sequence sequence5 {" + 287 " TextInputEvent TextInput g {" + 288 " Event KeyPressed SHIFT {}" + 289 " Event KeyPressed SHIFT {}" + 290 " Event KeyPressed LETTER_G {}" + 291 " Event KeyReleased LETTER_G {}" + 292 " Event KeyReleased SHIFT {}" + 293 " Event KeyReleased SHIFT {}" + 294 " }" + 295 " }" + 296 "}", getTaskTree()); 297 298 } 299 300 /** 301 * 302 */ 303 @Test 304 public void testUsageOfBackspace() { 305 IGUIElement element1 = new DummyTextField("elem1"); 306 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 307 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 308 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 309 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 310 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 311 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 312 simulateEvent(new KeyPressed(VirtualKey.LETTER_D), element1); 313 simulateEvent(new KeyReleased(VirtualKey.LETTER_D), element1); 314 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 315 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 316 simulateEvent(new KeyPressed(VirtualKey.LETTER_E), element1); 317 simulateEvent(new KeyReleased(VirtualKey.LETTER_E), element1); 318 simulateEvent(new KeyPressed(VirtualKey.LETTER_F), element1); 319 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element1); 320 new TaskTreeChecker().assertTaskTree 321 ("Sequence sequence0 {" + 322 " TextInputEvent TextInput abcef {" + 323 " Event KeyPressed LETTER_A {}" + 324 " Event KeyReleased LETTER_A {}" + 325 " Event KeyPressed LETTER_B {}" + 326 " Event KeyReleased LETTER_B {}" + 327 " Event KeyPressed LETTER_C {}" + 328 " Event KeyReleased LETTER_C {}" + 329 " Event KeyPressed LETTER_D {}" + 330 " Event KeyReleased LETTER_D {}" + 331 " Event KeyPressed BACK_SPACE {}" + 332 " Event KeyReleased BACK_SPACE {}" + 333 " Event KeyPressed LETTER_E {}" + 334 " Event KeyReleased LETTER_E {}" + 335 " Event KeyPressed LETTER_F {}" + 336 " Event KeyReleased LETTER_F {}" + 337 " }" + 338 "}", getTaskTree()); 339 340 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 341 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 342 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 343 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 344 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 345 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 346 new TaskTreeChecker().assertTaskTree 347 ("Sequence sequence0 {" + 348 " TextInputEvent TextInput ab {" + 349 " Event KeyPressed LETTER_A {}" + 350 " Event KeyReleased LETTER_A {}" + 351 " Event KeyPressed LETTER_B {}" + 352 " Event KeyReleased LETTER_B {}" + 353 " Event KeyPressed LETTER_C {}" + 354 " Event KeyReleased LETTER_C {}" + 355 " Event KeyPressed LETTER_D {}" + 356 " Event KeyReleased LETTER_D {}" + 357 " Event KeyPressed BACK_SPACE {}" + 358 " Event KeyReleased BACK_SPACE {}" + 359 " Event KeyPressed LETTER_E {}" + 360 " Event KeyReleased LETTER_E {}" + 361 " Event KeyPressed LETTER_F {}" + 362 " Event KeyReleased LETTER_F {}" + 363 " Event KeyPressed BACK_SPACE {}" + 364 " Event KeyReleased BACK_SPACE {}" + 365 " Event KeyPressed BACK_SPACE {}" + 366 " Event KeyReleased BACK_SPACE {}" + 367 " Event KeyPressed BACK_SPACE {}" + 368 " Event KeyReleased BACK_SPACE {}" + 369 " }" + 370 "}", getTaskTree()); 371 372 } 373 374 /** 375 * 376 */ 377 private static class DummyTextField extends DummyGUIElement implements ITextField { 378 379 /** */ 380 private static final long serialVersionUID = 1L; 381 382 /** 383 * TODO: comment 384 * 385 * @param name 386 */ 387 public DummyTextField(String name) { 388 super(name); 389 } 390 391 } 410 392 411 393 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TrackBarSelectionDetectionRuleTest.java
r468 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRuleTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 9 import org.junit.Test; 11 10 12 import de.ugoe.cs.quest.eventcore.gui model.GUIElement;13 import de.ugoe.cs.quest.eventcore.guimodel. TrackBar;14 import de.ugoe.cs.quest.eventcore. userinteraction.ValueSelection;11 import de.ugoe.cs.quest.eventcore.gui.ValueSelection; 12 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 13 import de.ugoe.cs.quest.eventcore.guimodel.ITrackBar; 15 14 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 16 15 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 17 16 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 18 17 19 //-------------------------------------------------------------------------------------------------20 18 /** 21 19 * TODO comment … … 24 22 * @author 2012, last modified by $Author: patrick$ 25 23 */ 26 //------------------------------------------------------------------------------------------------- 27 public class TrackBarSelectionDetectionRuleTest extends AbstractTemporalRelationshipTC 28 { 24 public class TrackBarSelectionDetectionRuleTest extends AbstractTemporalRelationshipTC { 29 25 30 //-----------------------------------------------------------------------------------------------31 /**32 *33 */34 //-----------------------------------------------------------------------------------------------35 @Test36 public void testSimpleDetection() throws Exception37 {38 GUIElement element1 = new DummyTrackBar();39 simulateInteraction(element1, new ValueSelection<Integer>(1));40 new TaskTreeChecker().assertTaskTree41 ("Sequence sequence1 {" +42 " Iteration interation1 {" +43 " Selection selection1 {" +44 " Interaction ValueSelection {}" +45 " }" +46 " }" +47 "}", getTaskTree());48 49 simulateInteraction(element1, new ValueSelection<Integer>(2));50 new TaskTreeChecker().assertTaskTree51 ("Sequence sequence1 {" +52 " Iteration interation1 {" +53 " Selection selection1 {" +54 " Interaction ValueSelection {}" +55 " Interaction ValueSelection {}" +56 " }" +57 " }" +58 "}", getTaskTree());59 60 simulateInteraction(element1, new ValueSelection<Integer>(3));61 new TaskTreeChecker().assertTaskTree62 ("Sequence sequence1 {" +63 " Iteration interation1 {" +64 " Selection selection1 {" +65 " Interaction ValueSelection {}" +66 " Interaction ValueSelection {}" +67 " Interaction ValueSelection {}" +68 " }" +69 " }" +70 "}", getTaskTree());71 72 simulateInteraction(element1, new ValueSelection<Integer>(2));73 new TaskTreeChecker().assertTaskTree74 ("Sequence sequence1 {" +75 " Iteration interation1 {" +76 " Selection selection1 {" +77 " Interaction ValueSelection {}" +78 " Interaction ValueSelection {}" +79 " Interaction ValueSelection {}" +80 " }" +81 " }" +82 "}", getTaskTree());83 84 simulateInteraction(element1, new ValueSelection<Integer>(3));85 new TaskTreeChecker().assertTaskTree86 ("Sequence sequence1 {" +87 " Iteration interation1 {" +88 " Selection selection1 {" +89 " Interaction ValueSelection {}" +90 " Interaction ValueSelection {}" +91 " Interaction ValueSelection {}" +92 " }" +93 " }" +94 "}", getTaskTree());95 96 }97 98 //-----------------------------------------------------------------------------------------------99 /**100 *101 */102 //-----------------------------------------------------------------------------------------------103 @Test104 public void testComplexDetection() throws Exception105 {106 GUIElement element1 = new DummyTrackBar();107 simulateInteraction(element1, new ValueSelection<Integer>(1));108 simulateInteraction(element1, new ValueSelection<Integer>(2));109 simulateInteraction(element1, new ValueSelection<Integer>(3));110 simulateInteraction(element1, new ValueSelection<Integer>(1));111 simulateInteraction(element1, new DummyInteraction("bla", 1));112 simulateInteraction(element1, new DummyInteraction("bla", 2));113 simulateInteraction(element1, new ValueSelection<Integer>(2));114 simulateInteraction(element1, new ValueSelection<Integer>(1));115 simulateInteraction(element1, new DummyInteraction("bla", 3));116 simulateInteraction(element1, new ValueSelection<Integer>(3));117 simulateInteraction(element1, new ValueSelection<Integer>(2));118 simulateInteraction(element1, new ValueSelection<Integer>(3));119 simulateInteraction(element1, new DummyInteraction("bla", 1));120 simulateInteraction(element1, new DummyInteraction("bla", 2));121 simulateInteraction(element1, new ValueSelection<Integer>(1));122 simulateInteraction(element1, new ValueSelection<Integer>(1));123 124 new TaskTreeChecker().assertTaskTree125 ("Sequence sequence1 {" +126 " Iteration interation1 {" +127 " Selection selection1 {" +128 " Interaction ValueSelection {}" +129 " Interaction ValueSelection {}" +130 " Interaction ValueSelection {}" +131 " }" +132 " }" +133 " Interaction bla {}" +134 " Interaction bla {}" +135 " Iteration interation2 {" +136 " Selection selection2 {" +137 " Interaction ValueSelection {}" +138 " Interaction ValueSelection {}" +139 " }" +140 " }" +141 " Interaction bla {}" +142 " Iteration interation3 {" +143 " Selection selection3 {" +144 " Interaction ValueSelection {}" +145 " Interaction ValueSelection {}" +146 " }" +147 " }" +148 " Interaction bla {}" +149 " Interaction bla {}" +150 " Iteration interation4 {" +151 " Selection selection4 {" +152 " Interaction ValueSelection {}" +153 " }" +154 " }" +155 "}", getTaskTree());156 }157 158 //-----------------------------------------------------------------------------------------------159 /**160 * TODO comment161 *162 * @version $Revision: $ $Date: 28.04.2012$163 * @author 2012, last modified by $Author: patrick$164 */165 //-----------------------------------------------------------------------------------------------166 public class DummyTrackBar extends DummyGUIElement implements TrackBar167 {168 169 //---------------------------------------------------------------------------------------------170 26 /** 171 27 * 172 28 */ 173 //--------------------------------------------------------------------------------------------- 174 public DummyTrackBar() 175 { 176 super("DummyTrackBar"); 29 @Test 30 public void testSimpleDetection() throws Exception { 31 IGUIElement element1 = new DummyTrackBar(); 32 simulateEvent(new ValueSelection<Integer>(1), element1); 33 new TaskTreeChecker().assertTaskTree 34 ("Sequence sequence1 {" + 35 " Iteration interation1 {" + 36 " Selection selection1 {" + 37 " Event ValueSelection {}" + 38 " }" + 39 " }" + 40 "}", getTaskTree()); 41 42 simulateEvent(new ValueSelection<Integer>(2), element1); 43 new TaskTreeChecker().assertTaskTree 44 ("Sequence sequence1 {" + 45 " Iteration interation1 {" + 46 " Selection selection1 {" + 47 " Event ValueSelection {}" + 48 " Event ValueSelection {}" + 49 " }" + 50 " }" + 51 "}", getTaskTree()); 52 53 simulateEvent(new ValueSelection<Integer>(3), element1); 54 new TaskTreeChecker().assertTaskTree 55 ("Sequence sequence1 {" + 56 " Iteration interation1 {" + 57 " Selection selection1 {" + 58 " Event ValueSelection {}" + 59 " Event ValueSelection {}" + 60 " Event ValueSelection {}" + 61 " }" + 62 " }" + 63 "}", getTaskTree()); 64 65 simulateEvent(new ValueSelection<Integer>(2), element1); 66 new TaskTreeChecker().assertTaskTree 67 ("Sequence sequence1 {" + 68 " Iteration interation1 {" + 69 " Selection selection1 {" + 70 " Event ValueSelection {}" + 71 " Event ValueSelection {}" + 72 " Event ValueSelection {}" + 73 " }" + 74 " }" + 75 "}", getTaskTree()); 76 77 simulateEvent(new ValueSelection<Integer>(3), element1); 78 new TaskTreeChecker().assertTaskTree 79 ("Sequence sequence1 {" + 80 " Iteration interation1 {" + 81 " Selection selection1 {" + 82 " Event ValueSelection {}" + 83 " Event ValueSelection {}" + 84 " Event ValueSelection {}" + 85 " }" + 86 " }" + 87 "}", getTaskTree()); 88 177 89 } 178 } 90 91 /** 92 * 93 */ 94 @Test 95 public void testComplexDetection() throws Exception { 96 IGUIElement element1 = new DummyTrackBar(); 97 simulateEvent(new ValueSelection<Integer>(1), element1); 98 simulateEvent(new ValueSelection<Integer>(2), element1); 99 simulateEvent(new ValueSelection<Integer>(3), element1); 100 simulateEvent(new ValueSelection<Integer>(1), element1); 101 simulateEvent(new DummyInteraction("bla", 1), element1); 102 simulateEvent(new DummyInteraction("bla", 2), element1); 103 simulateEvent(new ValueSelection<Integer>(2), element1); 104 simulateEvent(new ValueSelection<Integer>(1), element1); 105 simulateEvent(new DummyInteraction("bla", 3), element1); 106 simulateEvent(new ValueSelection<Integer>(3), element1); 107 simulateEvent(new ValueSelection<Integer>(2), element1); 108 simulateEvent(new ValueSelection<Integer>(3), element1); 109 simulateEvent(new DummyInteraction("bla", 1), element1); 110 simulateEvent(new DummyInteraction("bla", 2), element1); 111 simulateEvent(new ValueSelection<Integer>(1), element1); 112 simulateEvent(new ValueSelection<Integer>(1), element1); 113 114 new TaskTreeChecker().assertTaskTree 115 ("Sequence sequence1 {" + 116 " Iteration interation1 {" + 117 " Selection selection1 {" + 118 " Event ValueSelection {}" + 119 " Event ValueSelection {}" + 120 " Event ValueSelection {}" + 121 " }" + 122 " }" + 123 " Event bla {}" + 124 " Event bla {}" + 125 " Iteration interation2 {" + 126 " Selection selection2 {" + 127 " Event ValueSelection {}" + 128 " Event ValueSelection {}" + 129 " }" + 130 " }" + 131 " Event bla {}" + 132 " Iteration interation3 {" + 133 " Selection selection3 {" + 134 " Event ValueSelection {}" + 135 " Event ValueSelection {}" + 136 " }" + 137 " }" + 138 " Event bla {}" + 139 " Event bla {}" + 140 " Iteration interation4 {" + 141 " Selection selection4 {" + 142 " Event ValueSelection {}" + 143 " }" + 144 " }" + 145 "}", getTaskTree()); 146 } 147 148 /** 149 * TODO comment 150 * 151 * @version $Revision: $ $Date: 28.04.2012$ 152 * @author 2012, last modified by $Author: patrick$ 153 */ 154 public class DummyTrackBar extends DummyGUIElement implements ITrackBar { 155 156 /** */ 157 private static final long serialVersionUID = 1L; 158 159 /** 160 * 161 */ 162 public DummyTrackBar() { 163 super("DummyTrackBar"); 164 } 165 } 179 166 180 167 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/DummyGUIElement.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DummyGUIElement.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.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 10 9 import de.ugoe.cs.quest.eventcore.guimodel.AbstractDefaultGUIElement; 11 import de.ugoe.cs.quest.eventcore.guimodel. GUIElement;10 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 12 11 13 //-------------------------------------------------------------------------------------------------14 12 /** 15 13 * TODO comment … … 18 16 * @author 2012, last modified by $Author: patrick$ 19 17 */ 20 //------------------------------------------------------------------------------------------------- 21 public class DummyGUIElement extends AbstractDefaultGUIElement 22 implements GUIElement 23 { 24 /** */ 25 private String mName; 18 public class DummyGUIElement extends AbstractDefaultGUIElement implements IGUIElement { 19 20 /** */ 21 private static final long serialVersionUID = 1L; 26 22 27 //--------------------------------------------------------------------------------------------- 28 /** 29 * 30 */ 31 //--------------------------------------------------------------------------------------------- 32 public DummyGUIElement(String name) 33 { 34 super(); 35 mName = name; 36 } 23 /** */ 24 private String name; 37 25 38 //----------------------------------------------------------------------------------------------- 39 /* (non-Javadoc) 40 * @see java.lang.Object#toString() 41 */ 42 //----------------------------------------------------------------------------------------------- 43 @Override 44 public String toString() 45 { 46 return mName; 47 } 26 /** 27 * 28 */ 29 public DummyGUIElement(String name) { 30 super(); 31 this.name = name; 32 } 48 33 49 //----------------------------------------------------------------------------------------------- 50 /* (non-Javadoc) 51 * @see de.harms.attef.userinteraction.GUIElement#equals(GUIElement) 52 */ 53 //----------------------------------------------------------------------------------------------- 54 public boolean equals(GUIElement other) 55 { 56 return this == other; 57 } 34 /* (non-Javadoc) 35 * @see de.ugoe.cs.quest.eventcore.IEventTarget#getPlatform() 36 */ 37 @Override 38 public String getPlatform() { 39 return "Dummy"; 40 } 41 42 /* 43 * (non-Javadoc) 44 * 45 * @see java.lang.Object#toString() 46 */ 47 @Override 48 public String toString() { 49 return name; 50 } 51 52 /* 53 * (non-Javadoc) 54 * 55 * @see de.harms.attef.userinteraction.GUIElement#equals(GUIElement) 56 */ 57 public boolean equals(IGUIElement other) { 58 return this == other; 59 } 58 60 59 61 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/DummyInteraction.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DummyInteraction.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.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 10 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;9 import de.ugoe.cs.quest.eventcore.gui.IInteraction; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 12 * TODO comment … … 17 15 * @author 2012, last modified by $Author: patrick$ 18 16 */ 19 //------------------------------------------------------------------------------------------------- 20 public class DummyInteraction implements Interaction 21 { 22 /** */ 23 private int mInteractionNumber; 24 25 /** */ 26 private String mInteractionType; 27 28 //----------------------------------------------------------------------------------------------- 29 /** 30 * @param interactionNumber 31 * @param interactionType 32 */ 33 //----------------------------------------------------------------------------------------------- 34 public DummyInteraction(String interactionType, int interactionNumber) 35 { 36 super(); 37 mInteractionNumber = interactionNumber; 38 mInteractionType = interactionType; 39 } 17 public class DummyInteraction implements IInteraction { 18 19 /** */ 20 private static final long serialVersionUID = 1L; 40 21 41 //----------------------------------------------------------------------------------------------- 42 /* (non-Javadoc) 43 * @see de.harms.attef.userinteraction.Interaction#getName() 44 */ 45 //----------------------------------------------------------------------------------------------- 46 public String getName() 47 { 48 return mInteractionType; 49 } 22 /** */ 23 private int interactionNumber; 50 24 51 //----------------------------------------------------------------------------------------------- 52 /* (non-Javadoc) 53 * @see java.lang.Object#toString() 54 */ 55 //----------------------------------------------------------------------------------------------- 56 @Override 57 public String toString() 58 { 59 return mInteractionType; 60 } 25 /** */ 26 private String interactionType; 61 27 62 //-----------------------------------------------------------------------------------------------63 /* (non-Javadoc)64 * @see de.harms.attef.userinteraction.Interaction#startsLogicalSequence()65 */66 //-----------------------------------------------------------------------------------------------67 public boolean startsLogicalSequence()68 {69 return false;70 }28 /** 29 * @param interactionNumber 30 * @param interactionType 31 */ 32 public DummyInteraction(String interactionType, int interactionNumber) { 33 super(); 34 this.interactionNumber = interactionNumber; 35 this.interactionType = interactionType; 36 } 71 37 72 //----------------------------------------------------------------------------------------------- 73 /* (non-Javadoc) 74 * @see de.harms.attef.userinteraction.Interaction#finishesLogicalSequence() 75 */ 76 //----------------------------------------------------------------------------------------------- 77 public boolean finishesLogicalSequence() 78 { 79 return false; 80 } 38 /* 39 * (non-Javadoc) 40 * 41 * @see de.harms.attef.userinteraction.Interaction#getName() 42 */ 43 public String getName() { 44 return interactionType; 45 } 81 46 82 //-----------------------------------------------------------------------------------------------83 /**84 * @return the interactionType85 */86 //-----------------------------------------------------------------------------------------------87 public String getInteractionType()88 {89 return mInteractionType;90 }47 /* 48 * (non-Javadoc) 49 * 50 * @see java.lang.Object#toString() 51 */ 52 @Override 53 public String toString() { 54 return interactionType; 55 } 91 56 92 //----------------------------------------------------------------------------------------------- 93 /** 94 * @return the interactionNumber 95 */ 96 //----------------------------------------------------------------------------------------------- 97 public int getInteractionNumber() 98 { 99 return mInteractionNumber; 100 } 57 /* 58 * (non-Javadoc) 59 * 60 * @see de.harms.attef.userinteraction.Interaction#startsLogicalSequence() 61 */ 62 public boolean startsLogicalSequence() { 63 return false; 64 } 65 66 /* 67 * (non-Javadoc) 68 * 69 * @see de.harms.attef.userinteraction.Interaction#finishesLogicalSequence() 70 */ 71 public boolean finishesLogicalSequence() { 72 return false; 73 } 74 75 /** 76 * @return the interactionType 77 */ 78 public String getInteractionType() { 79 return interactionType; 80 } 81 82 /** 83 * @return the interactionNumber 84 */ 85 public int getInteractionNumber() { 86 return interactionNumber; 87 } 101 88 102 89 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/DummyTextField.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DummyGUIElement.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.testutils; 9 9 10 import de.ugoe.cs.quest.eventcore.guimodel. TextField;10 import de.ugoe.cs.quest.eventcore.guimodel.ITextField; 11 11 12 //-------------------------------------------------------------------------------------------------13 12 /** 14 13 * TODO comment … … 17 16 * @author 2012, last modified by $Author: patrick$ 18 17 */ 19 //------------------------------------------------------------------------------------------------- 20 public class DummyTextField extends DummyGUIElement 21 implements TextField 22 { 18 public class DummyTextField extends DummyGUIElement implements ITextField { 23 19 24 //---------------------------------------------------------------------------------------------25 /**26 * 27 */28 //---------------------------------------------------------------------------------------------29 public DummyTextField(String name)30 {31 super("text field \"" + name + "\"");32 }20 /** */ 21 private static final long serialVersionUID = 1L; 22 23 /** 24 * 25 */ 26 public DummyTextField(String name) { 27 super("text field \"" + name + "\""); 28 } 33 29 34 30 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/SimpleLogFormatter.java
r445 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TestLogger.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 26.11.2011 15:26:38 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.testutils; … … 16 14 import java.util.logging.LogRecord; 17 15 18 19 //-------------------------------------------------------------------------------------------------20 16 /** 21 17 * TODO comment 22 * 18 * 23 19 * @version $Revision: $ $Date: $ 24 * @author 20 * @author 2011, last modified by $Author: $ 25 21 */ 26 //------------------------------------------------------------------------------------------------- 22 public class SimpleLogFormatter extends Formatter { 27 23 28 public class SimpleLogFormatter extends Formatter 29 { 30 //----------------------------------------------------------------------------------------------- 31 /** 32 * 33 */ 34 //----------------------------------------------------------------------------------------------- 35 @Override 36 public String format(LogRecord record) 37 { 38 StringBuffer result = new StringBuffer(); 39 result.append(record.getLevel().getName().charAt(0)); 40 result.append(" | "); 41 result.append(new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss,SSS").format(record.getMillis())); 42 result.append(" | "); 43 tailValue("" + record.getThreadID(), 6, result); 44 result.append(" | "); 45 tailValue(record.getLoggerName(), 30, result); 46 result.append(" | "); 47 result.append(record.getMessage()); 48 49 if (record.getThrown() != null) 50 { 51 ByteArrayOutputStream out = new ByteArrayOutputStream(); 52 record.getThrown().printStackTrace(new PrintStream(out)); 53 result.append("\n"); 54 result.append(out.toString()); 55 try 56 { 57 out.close(); 58 } 59 catch (IOException e) 60 { 61 // ignore 62 } 24 /** 25 * 26 */ 27 @Override 28 public String format(LogRecord record) { 29 StringBuffer result = new StringBuffer(); 30 result.append(record.getLevel().getName().charAt(0)); 31 result.append(" | "); 32 result.append(new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss,SSS").format(record.getMillis())); 33 result.append(" | "); 34 tailValue("" + record.getThreadID(), 6, result); 35 result.append(" | "); 36 tailValue(record.getLoggerName(), 30, result); 37 result.append(" | "); 38 result.append(record.getMessage()); 39 40 if (record.getThrown() != null) { 41 ByteArrayOutputStream out = new ByteArrayOutputStream(); 42 record.getThrown().printStackTrace(new PrintStream(out)); 43 result.append("\n"); 44 result.append(out.toString()); 45 try { 46 out.close(); 47 } 48 catch (IOException e) { 49 // ignore 50 } 51 } 52 53 result.append("\n"); 54 55 return result.toString(); 63 56 } 64 65 result.append("\n"); 66 67 return result.toString(); 68 } 69 70 //----------------------------------------------------------------------------------------------- 71 /** 72 * 73 */ 74 //----------------------------------------------------------------------------------------------- 75 private void tailValue(String value, int length, StringBuffer output) 76 { 77 for (int i = value.length() - length - 1; i < value.length(); i++) 78 { 79 if (i < 0) 80 { 81 output.append(" "); 82 } 83 else 84 { 85 output.append(value.charAt(i)); 86 } 57 58 /** 59 * 60 */ 61 private void tailValue(String value, int length, StringBuffer output) { 62 for (int i = value.length() - length - 1; i < value.length(); i++) { 63 if (i < 0) { 64 output.append(" "); 65 } 66 else { 67 output.append(value.charAt(i)); 68 } 69 } 87 70 } 88 }89 71 } -
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 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/Utilities.java
r445 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TestUtils.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.testutils; 9 9 10 10 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 11 11 12 //-------------------------------------------------------------------------------------------------13 12 /** 14 13 * TODO comment … … 17 16 * @author 2012, last modified by $Author: patrick$ 18 17 */ 19 //------------------------------------------------------------------------------------------------- 20 public class Utilities 21 { 22 /** */ 23 private static final NodeEqualityRuleManager NODE_EQUALITY_RULE_MANAGER = 24 new NodeEqualityRuleManager(); 25 26 static 27 { 28 NODE_EQUALITY_RULE_MANAGER.init(); 29 } 18 public class Utilities { 19 20 /** */ 21 private static final NodeEqualityRuleManager NODE_EQUALITY_RULE_MANAGER = 22 new NodeEqualityRuleManager(); 30 23 31 //----------------------------------------------------------------------------------------------- 32 /** 33 * TODO: comment 34 * 35 * @return 36 */ 37 //----------------------------------------------------------------------------------------------- 38 public static NodeEqualityRuleManager getNodeEqualityRuleManagerForTests() 39 { 40 return NODE_EQUALITY_RULE_MANAGER; 41 } 24 static { 25 NODE_EQUALITY_RULE_MANAGER.init(); 26 } 27 28 /** 29 * TODO: comment 30 * 31 * @return 32 */ 33 public static NodeEqualityRuleManager getNodeEqualityRuleManagerForTests() { 34 return NODE_EQUALITY_RULE_MANAGER; 35 } 42 36 43 37 } -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeImplTest.java
r452 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeImplTest.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 02.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 9 … … 19 19 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 20 20 import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction; 21 import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; 22 import de.ugoe.cs.quest.tasktrees.treeifc.Iteration; 23 import de.ugoe.cs.quest.tasktrees.treeifc.NodeInfo; 24 import de.ugoe.cs.quest.tasktrees.treeifc.Selection; 25 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 26 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTree; 27 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 28 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 29 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 30 31 //------------------------------------------------------------------------------------------------- 21 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 22 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 23 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeInfo; 24 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 25 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 26 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 27 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 28 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 29 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 30 32 31 /** 33 32 * TODO comment … … 36 35 * @author 2012, last modified by $Author: patrick$ 37 36 */ 38 //------------------------------------------------------------------------------------------------- 39 public class TaskTreeImplTest 40 { 41 /** */ 42 private static final int MAX_TREE_DEPTH = 15; 43 44 /** */ 45 private TaskTreeBuilder mTaskTreeBuilder = new TaskTreeBuilderImpl(); 46 47 /** */ 48 private TaskTreeNodeFactory mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); 49 50 //----------------------------------------------------------------------------------------------- 51 /** 52 * @throws Exception 53 * 54 */ 55 //----------------------------------------------------------------------------------------------- 56 @Test 57 public void testRandomTrees() throws Exception 58 { 59 int noOfTrees = 10; 60 int noOfMaxChildren = 8; 61 int maxDepth = MAX_TREE_DEPTH; 37 public class TaskTreeImplTest { 62 38 63 for (int i = 0; i < noOfTrees; i++) 64 { 65 System.err.println("iteration " + (i + 1) + ":"); 66 System.err.println(" creating tree"); 67 Map<TaskTreeNode, NodeInfo> treeInfos = new HashMap<TaskTreeNode, NodeInfo>(); 68 TaskTreeNode rootNode = createTree(noOfMaxChildren, maxDepth, treeInfos); 69 System.err.println(" creating task tree"); 70 TaskTree taskTree = mTaskTreeNodeFactory.createTaskTree(rootNode); 71 72 System.err.println(" validating task tree"); 73 assertEquals(rootNode, taskTree.getRoot()); 74 assertMapsEqual(treeInfos, taskTree.getTaskMap()); 75 } 76 } 77 78 //----------------------------------------------------------------------------------------------- 79 /** 80 * TODO: comment 81 * 82 * @param treeInfos 83 * @param taskMap 84 */ 85 //----------------------------------------------------------------------------------------------- 86 private void assertMapsEqual(Map<TaskTreeNode, NodeInfo> map1, 87 Map<TaskTreeNode, NodeInfo> map2) 88 { 89 try 90 { 91 if (map1 == null) 92 { 93 assertNull(map2); 94 return; 95 } 96 97 assertEquals(map1.size(), map2.size()); 98 99 for (Map.Entry<TaskTreeNode, NodeInfo> entry : map1.entrySet()) 100 { 101 NodeInfo value2 = map2.get(entry.getKey()); 102 assertNotNull(value2); 103 assertEquals(entry.getValue().getTask(), value2.getTask()); 104 assertEquals(entry.getValue().getNoOfOccurencesInTree(), value2.getNoOfOccurencesInTree()); 105 } 106 } 107 catch (AssertionError e) 108 { 109 dumpMap(map1); 110 dumpMap(map2); 111 throw e; 112 } 113 } 114 115 //----------------------------------------------------------------------------------------------- 116 /** 117 * TODO: comment 118 * 119 * @param map2 120 */ 121 //----------------------------------------------------------------------------------------------- 122 private void dumpMap(Map<TaskTreeNode, NodeInfo> map) 123 { 124 System.err.println(); 125 126 if (map == null) 127 { 128 System.err.println("map is null"); 129 } 130 else 131 { 132 System.err.println("map:"); 133 for (Map.Entry<TaskTreeNode, NodeInfo> entry : map.entrySet()) 134 { 135 System.err.print(" "); 136 System.err.print(entry.getKey()); 137 for (int i = entry.getKey().toString().length(); i < 49; i++) 39 /** */ 40 private static final int MAX_TREE_DEPTH = 15; 41 42 /** */ 43 private ITaskTreeBuilder taskTreeBuilder = new TaskTreeBuilder(); 44 45 /** */ 46 private ITaskTreeNodeFactory taskTreeNodeFactory = new TaskTreeNodeFactory(); 47 48 /** 49 * @throws Exception 50 * 51 */ 52 @Test 53 public void testRandomTrees() throws Exception { 54 int noOfTrees = 10; 55 int noOfMaxChildren = 8; 56 int maxDepth = MAX_TREE_DEPTH; 57 58 for (int i = 0; i < noOfTrees; i++) { 59 System.err.println("iteration " + (i + 1) + ":"); 60 System.err.println(" creating tree"); 61 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos = 62 new HashMap<ITaskTreeNode, ITaskTreeNodeInfo>(); 63 ITaskTreeNode rootNode = createTree(noOfMaxChildren, maxDepth, treeInfos); 64 System.err.println(" creating task tree"); 65 ITaskTree taskTree = taskTreeNodeFactory.createTaskTree(rootNode); 66 67 System.err.println(" validating task tree"); 68 assertEquals(rootNode, taskTree.getRoot()); 69 assertMapsEqual(treeInfos, taskTree.getTaskMap()); 70 } 71 } 72 73 /** 74 * TODO: comment 75 * 76 * @param treeInfos 77 * @param taskMap 78 */ 79 private void assertMapsEqual(Map<ITaskTreeNode, ITaskTreeNodeInfo> map1, 80 Map<ITaskTreeNode, ITaskTreeNodeInfo> map2) 81 { 82 try { 83 if (map1 == null) { 84 assertNull(map2); 85 return; 86 } 87 88 assertEquals(map1.size(), map2.size()); 89 90 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : map1.entrySet()) { 91 ITaskTreeNodeInfo value2 = map2.get(entry.getKey()); 92 assertNotNull(value2); 93 assertEquals(entry.getValue().getTask(), value2.getTask()); 94 assertEquals(entry.getValue().getNoOfOccurencesInTree(), 95 value2.getNoOfOccurencesInTree()); 96 } 97 } 98 catch (AssertionError e) { 99 dumpMap(map1); 100 dumpMap(map2); 101 throw e; 102 } 103 } 104 105 /** 106 * TODO: comment 107 * 108 * @param map2 109 */ 110 private void dumpMap(Map<ITaskTreeNode, ITaskTreeNodeInfo> map) { 111 System.err.println(); 112 113 if (map == null) { 114 System.err.println("map is null"); 115 } 116 else { 117 System.err.println("map:"); 118 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : map.entrySet()) { 119 System.err.print(" "); 120 System.err.print(entry.getKey()); 121 for (int i = entry.getKey().toString().length(); i < 49; i++) { 122 System.err.print(" "); 123 } 124 System.err.print(" : "); 125 System.err.println(entry.getValue()); 126 } 127 } 128 129 System.err.println(); 130 } 131 132 /** 133 * TODO: comment 134 * 135 * @param noOfMaxChildren 136 * @param maxDepth 137 * @param treeInfos 138 * @return 139 */ 140 private ITaskTreeNode createTree(int maxNoOfChildren, 141 int maxDepth, 142 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 143 throws Exception 144 { 145 /* 146 * for (int i = 0; i < (MAX_TREE_DEPTH + 1 - maxDepth); i++) { System.err.print(" "); } 147 */ 148 149 ITaskTreeNode tree; 150 151 // integrating the maximum depth here assures, that either something between 0 and 8 will 152 // be the type, or if the max depth decreases near 0 only event tasks will be created 153 // to finish the tree creation 154 int type = (int) (Math.random() * (Math.min(8, maxDepth))); 155 156 switch (type) 138 157 { 139 System.err.print(" "); 140 } 141 System.err.print(" : "); 142 System.err.println(entry.getValue()); 143 } 144 } 145 146 System.err.println(); 147 } 148 149 //----------------------------------------------------------------------------------------------- 150 /** 151 * TODO: comment 152 * 153 * @param noOfMaxChildren 154 * @param maxDepth 155 * @param treeInfos 156 * @return 157 */ 158 //----------------------------------------------------------------------------------------------- 159 private TaskTreeNode createTree(int maxNoOfChildren, 160 int maxDepth, 161 Map<TaskTreeNode, NodeInfo> treeInfos) 162 throws Exception 163 { 164 /*for (int i = 0; i < (MAX_TREE_DEPTH + 1 - maxDepth); i++) 165 { 166 System.err.print(" "); 167 }*/ 168 169 TaskTreeNode tree; 170 171 // integrating the maximum depth here assures, that either something between 0 and 8 will 172 // be the type, or if the max depth decreases near 0 only interaction tasks will be created 173 // to finish the tree creation 174 int type = (int) (Math.random() * (Math.min(8, maxDepth))); 175 176 switch (type) 177 { 178 case 0: 179 { 180 //System.err.print("creating new interaction task "); 181 tree = createNewInteractionTask(treeInfos); 182 break; 183 } 184 case 1: 185 { 186 //System.err.print("reusing interaction task "); 187 tree = reuseInteractionTask(treeInfos); 188 break; 189 } 190 case 2: 191 { 192 //System.err.println("creating new sequence {"); 193 tree = createNewSequence(maxNoOfChildren, maxDepth, treeInfos); 194 break; 195 } 196 case 3: 197 { 198 //System.err.println("reusing sequence {"); 199 tree = reuseSequence(maxNoOfChildren, maxDepth, treeInfos); 200 break; 201 } 202 case 4: 203 { 204 //System.err.println("creating new selection {"); 205 tree = createNewSelection(maxNoOfChildren, maxDepth, treeInfos); 206 break; 207 } 208 case 5: 209 { 210 //System.err.println("reusing selection {"); 211 tree = reuseSelection(maxNoOfChildren, maxDepth, treeInfos); 212 break; 213 } 214 case 6: 215 { 216 //System.err.println("creating new iteration {"); 217 tree = createNewIteration(maxNoOfChildren, maxDepth, treeInfos); 218 break; 219 } 220 case 7: 221 { 222 //System.err.println("reusing iteration {"); 223 tree = reuseIteration(maxNoOfChildren, maxDepth, treeInfos); 224 break; 225 } 226 default: 227 { 228 //System.err.print("creating new interaction task per default "); 229 tree = createNewInteractionTask(treeInfos); 230 } 231 } 232 233 /* 234 if (!(tree instanceof InteractionTask)) 235 { 236 for (int i = 0; i < (MAX_TREE_DEPTH + 1 - maxDepth); i++) 237 { 238 System.err.print(" "); 239 } 240 241 System.err.print("} "); 242 } 243 244 System.err.println(tree);*/ 245 246 return tree; 247 } 248 249 //----------------------------------------------------------------------------------------------- 250 /** 251 * TODO: comment 252 * 253 * @param treeInfos 254 * @return 255 */ 256 //----------------------------------------------------------------------------------------------- 257 private InteractionTask createNewInteractionTask(Map<TaskTreeNode, NodeInfo> treeInfos) 258 throws Exception 259 { 260 Thread.sleep(2); 261 long id = System.currentTimeMillis(); 262 InteractionTask task = mTaskTreeNodeFactory.createNewInteractionTask 263 (new DummyGUIElement("elem" + id), new DummyInteraction("interaction" + id, 1)); 264 265 treeInfos.put(task, new NodeInfoImpl(task)); 266 267 return task; 268 } 269 270 //----------------------------------------------------------------------------------------------- 271 /** 272 * TODO: comment 273 * 274 * @param treeInfos 275 * @return 276 */ 277 //----------------------------------------------------------------------------------------------- 278 private InteractionTask reuseInteractionTask(Map<TaskTreeNode, NodeInfo> treeInfos) 279 throws Exception 280 { 281 int noOfInteractionTasks = 0; 282 283 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 284 { 285 if (entry.getKey() instanceof InteractionTask) 286 { 287 noOfInteractionTasks++; 288 } 289 } 290 291 if (noOfInteractionTasks > 0) 292 { 293 noOfInteractionTasks = (int) (Math.random() * noOfInteractionTasks); 294 295 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 296 { 297 if (entry.getKey() instanceof InteractionTask) 298 { 299 if (--noOfInteractionTasks <= 0) 300 { 301 return (InteractionTask) entry.getKey(); 302 } 303 } 304 } 305 } 306 else 307 { 308 return createNewInteractionTask(treeInfos); 309 } 310 311 throw new RuntimeException("this is an implementation error"); 312 } 313 314 //----------------------------------------------------------------------------------------------- 315 /** 316 * TODO: comment 317 * 318 * @param treeInfos 319 * @return 320 */ 321 //----------------------------------------------------------------------------------------------- 322 private Sequence createNewSequence(int maxNoOfChildren, 323 int maxDepth, 324 Map<TaskTreeNode, NodeInfo> treeInfos) 325 throws Exception 326 { 327 Sequence sequence = mTaskTreeNodeFactory.createNewSequence(); 328 329 int noOfChildren = (int) (Math.random() * maxNoOfChildren); 330 331 for (int i = 0; i < noOfChildren; i++) 332 { 333 TaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 334 335 // through first removing an existing parent it is assured, that a parent is recorded 336 // only once. This is needed, because parent may be reused in a tree as well, but we always 337 // iterate the whole tree 338 ((NodeInfoImpl) treeInfos.get(child)).removeParent(sequence); 339 ((NodeInfoImpl) treeInfos.get(child)).addParent(sequence); 340 mTaskTreeBuilder.addChild(sequence, child); 341 } 342 343 treeInfos.put(sequence, new NodeInfoImpl(sequence)); 344 return sequence; 345 } 346 347 //----------------------------------------------------------------------------------------------- 348 /** 349 * TODO: comment 350 * 351 * @param treeInfos 352 * @return 353 */ 354 //----------------------------------------------------------------------------------------------- 355 private Sequence reuseSequence(int maxNoOfChildren, 356 int maxDepth, 357 Map<TaskTreeNode, NodeInfo> treeInfos) 358 throws Exception 359 { 360 int noOfSequences = 0; 361 362 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 363 { 364 if (entry.getKey() instanceof Sequence) 365 { 366 noOfSequences++; 367 } 368 } 369 370 if (noOfSequences > 0) 371 { 372 noOfSequences = (int) (Math.random() * noOfSequences); 373 374 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 375 { 376 if (entry.getKey() instanceof Sequence) 377 { 378 if (--noOfSequences <= 0) 379 { 380 return (Sequence) entry.getKey(); 381 } 382 } 383 } 384 } 385 else 386 { 387 return createNewSequence(maxNoOfChildren, maxDepth, treeInfos); 388 } 389 390 throw new RuntimeException("this is an implementation error"); 391 } 392 393 //----------------------------------------------------------------------------------------------- 394 /** 395 * TODO: comment 396 * 397 * @param treeInfos 398 * @return 399 */ 400 //----------------------------------------------------------------------------------------------- 401 private Selection createNewSelection(int maxNoOfChildren, 402 int maxDepth, 403 Map<TaskTreeNode, NodeInfo> treeInfos) 404 throws Exception 405 { 406 Selection selection = mTaskTreeNodeFactory.createNewSelection(); 407 408 int noOfChildren = (int) (Math.random() * maxNoOfChildren); 409 410 for (int i = 0; i < noOfChildren; i++) 411 { 412 TaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 413 414 // through first removing an existing parent it is assured, that a parent is recorded 415 // only once. This is needed, because parent may be reused in a tree as well, but we always 416 // iterate the whole tree 417 ((NodeInfoImpl) treeInfos.get(child)).removeParent(selection); 418 ((NodeInfoImpl) treeInfos.get(child)).addParent(selection); 419 mTaskTreeBuilder.addChild(selection, child); 420 } 421 422 treeInfos.put(selection, new NodeInfoImpl(selection)); 423 return selection; 424 } 425 426 //----------------------------------------------------------------------------------------------- 427 /** 428 * TODO: comment 429 * 430 * @param treeInfos 431 * @return 432 */ 433 //----------------------------------------------------------------------------------------------- 434 private Selection reuseSelection(int maxNoOfChildren, 435 int maxDepth, 436 Map<TaskTreeNode, NodeInfo> treeInfos) 437 throws Exception 438 { 439 int noOfSelections = 0; 440 441 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 442 { 443 if (entry.getKey() instanceof Selection) 444 { 445 noOfSelections++; 446 } 447 } 448 449 if (noOfSelections > 0) 450 { 451 noOfSelections = (int) (Math.random() * noOfSelections); 452 453 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 454 { 455 if (entry.getKey() instanceof Selection) 456 { 457 if (--noOfSelections <= 0) 458 { 459 return (Selection) entry.getKey(); 460 } 461 } 462 } 463 } 464 else 465 { 466 return createNewSelection(maxNoOfChildren, maxDepth, treeInfos); 467 } 468 469 throw new RuntimeException("this is an implementation error"); 470 } 471 472 //----------------------------------------------------------------------------------------------- 473 /** 474 * TODO: comment 475 * 476 * @param treeInfos 477 * @return 478 */ 479 //----------------------------------------------------------------------------------------------- 480 private Iteration createNewIteration(int maxNoOfChildren, 481 int maxDepth, 482 Map<TaskTreeNode, NodeInfo> treeInfos) 483 throws Exception 484 { 485 Iteration iteration = mTaskTreeNodeFactory.createNewIteration(); 486 487 TaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 488 489 // through first removing an existing parent it is assured, that a parent is recorded 490 // only once. This is needed, because parent may be reused in a tree as well, but we always 491 // iterate the whole tree 492 ((NodeInfoImpl) treeInfos.get(child)).removeParent(iteration); 493 ((NodeInfoImpl) treeInfos.get(child)).addParent(iteration); 494 mTaskTreeBuilder.setChild(iteration, child); 495 496 treeInfos.put(iteration, new NodeInfoImpl(iteration)); 497 return iteration; 498 } 499 500 //----------------------------------------------------------------------------------------------- 501 /** 502 * TODO: comment 503 * 504 * @param treeInfos 505 * @return 506 */ 507 //----------------------------------------------------------------------------------------------- 508 private Iteration reuseIteration(int maxNoOfChildren, 509 int maxDepth, 510 Map<TaskTreeNode, NodeInfo> treeInfos) 511 throws Exception 512 { 513 int noOfIterations = 0; 514 515 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 516 { 517 if (entry.getKey() instanceof Iteration) 518 { 519 noOfIterations++; 520 } 521 } 522 523 if (noOfIterations > 0) 524 { 525 noOfIterations = (int) (Math.random() * noOfIterations); 526 527 for (Map.Entry<TaskTreeNode, NodeInfo> entry : treeInfos.entrySet()) 528 { 529 if (entry.getKey() instanceof Iteration) 530 { 531 if (--noOfIterations <= 0) 532 { 533 return (Iteration) entry.getKey(); 534 } 535 } 536 } 537 } 538 else 539 { 540 return createNewIteration(maxNoOfChildren, maxDepth, treeInfos); 541 } 542 543 throw new RuntimeException("this is an implementation error"); 544 } 158 case 0: { 159 // System.err.print("creating new event task "); 160 tree = createNewEventTask(treeInfos); 161 break; 162 } 163 case 1: { 164 // System.err.print("reusing event task "); 165 tree = reuseEventTask(treeInfos); 166 break; 167 } 168 case 2: { 169 // System.err.println("creating new sequence {"); 170 tree = createNewSequence(maxNoOfChildren, maxDepth, treeInfos); 171 break; 172 } 173 case 3: { 174 // System.err.println("reusing sequence {"); 175 tree = reuseSequence(maxNoOfChildren, maxDepth, treeInfos); 176 break; 177 } 178 case 4: { 179 // System.err.println("creating new selection {"); 180 tree = createNewSelection(maxNoOfChildren, maxDepth, treeInfos); 181 break; 182 } 183 case 5: { 184 // System.err.println("reusing selection {"); 185 tree = reuseSelection(maxNoOfChildren, maxDepth, treeInfos); 186 break; 187 } 188 case 6: { 189 // System.err.println("creating new iteration {"); 190 tree = createNewIteration(maxNoOfChildren, maxDepth, treeInfos); 191 break; 192 } 193 case 7: { 194 // System.err.println("reusing iteration {"); 195 tree = reuseIteration(maxNoOfChildren, maxDepth, treeInfos); 196 break; 197 } 198 default: { 199 // System.err.print("creating new event task per default "); 200 tree = createNewEventTask(treeInfos); 201 } 202 } 203 204 /* 205 * if (!(tree instanceof InteractionTask)) { for (int i = 0; i < (MAX_TREE_DEPTH + 1 - 206 * maxDepth); i++) { System.err.print(" "); } 207 * 208 * System.err.print("} "); } 209 * 210 * System.err.println(tree); 211 */ 212 213 return tree; 214 } 215 216 /** 217 * TODO: comment 218 * 219 * @param treeInfos 220 * @return 221 */ 222 private IEventTask createNewEventTask(Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 223 throws Exception 224 { 225 Thread.sleep(2); 226 long id = System.currentTimeMillis(); 227 IEventTask task = 228 taskTreeNodeFactory.createNewEventTask(new DummyInteraction("interaction" + id, 1), 229 new DummyGUIElement("elem" + id)); 230 231 treeInfos.put(task, new NodeInfo(task)); 232 233 return task; 234 } 235 236 /** 237 * TODO: comment 238 * 239 * @param treeInfos 240 * @return 241 */ 242 private IEventTask reuseEventTask(Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 243 throws Exception 244 { 245 int noOfEventTasks = 0; 246 247 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 248 if (entry.getKey() instanceof IEventTask) { 249 noOfEventTasks++; 250 } 251 } 252 253 if (noOfEventTasks > 0) { 254 noOfEventTasks = (int) (Math.random() * noOfEventTasks); 255 256 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 257 if (entry.getKey() instanceof IEventTask) { 258 if (--noOfEventTasks <= 0) { 259 return (IEventTask) entry.getKey(); 260 } 261 } 262 } 263 } 264 else { 265 return createNewEventTask(treeInfos); 266 } 267 268 throw new RuntimeException("this is an implementation error"); 269 } 270 271 /** 272 * TODO: comment 273 * 274 * @param treeInfos 275 * @return 276 */ 277 private ISequence createNewSequence(int maxNoOfChildren, 278 int maxDepth, 279 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 280 throws Exception 281 { 282 ISequence sequence = taskTreeNodeFactory.createNewSequence(); 283 284 int noOfChildren = (int) (Math.random() * maxNoOfChildren); 285 286 for (int i = 0; i < noOfChildren; i++) { 287 ITaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 288 289 // through first removing an existing parent it is assured, that a parent is recorded 290 // only once. This is needed, because parent may be reused in a tree as well, but we 291 // always 292 // iterate the whole tree 293 ((NodeInfo) treeInfos.get(child)).removeParent(sequence); 294 ((NodeInfo) treeInfos.get(child)).addParent(sequence); 295 taskTreeBuilder.addChild(sequence, child); 296 } 297 298 treeInfos.put(sequence, new NodeInfo(sequence)); 299 return sequence; 300 } 301 302 /** 303 * TODO: comment 304 * 305 * @param treeInfos 306 * @return 307 */ 308 private ISequence reuseSequence(int maxNoOfChildren, 309 int maxDepth, 310 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 311 throws Exception 312 { 313 int noOfSequences = 0; 314 315 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 316 if (entry.getKey() instanceof ISequence) { 317 noOfSequences++; 318 } 319 } 320 321 if (noOfSequences > 0) { 322 noOfSequences = (int) (Math.random() * noOfSequences); 323 324 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 325 if (entry.getKey() instanceof ISequence) { 326 if (--noOfSequences <= 0) { 327 return (ISequence) entry.getKey(); 328 } 329 } 330 } 331 } 332 else { 333 return createNewSequence(maxNoOfChildren, maxDepth, treeInfos); 334 } 335 336 throw new RuntimeException("this is an implementation error"); 337 } 338 339 /** 340 * TODO: comment 341 * 342 * @param treeInfos 343 * @return 344 */ 345 private ISelection createNewSelection(int maxNoOfChildren, 346 int maxDepth, 347 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 348 throws Exception 349 { 350 ISelection selection = taskTreeNodeFactory.createNewSelection(); 351 352 int noOfChildren = (int) (Math.random() * maxNoOfChildren); 353 354 for (int i = 0; i < noOfChildren; i++) { 355 ITaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 356 357 // through first removing an existing parent it is assured, that a parent is recorded 358 // only once. This is needed, because parent may be reused in a tree as well, but we 359 // always 360 // iterate the whole tree 361 ((NodeInfo) treeInfos.get(child)).removeParent(selection); 362 ((NodeInfo) treeInfos.get(child)).addParent(selection); 363 taskTreeBuilder.addChild(selection, child); 364 } 365 366 treeInfos.put(selection, new NodeInfo(selection)); 367 return selection; 368 } 369 370 /** 371 * TODO: comment 372 * 373 * @param treeInfos 374 * @return 375 */ 376 private ISelection reuseSelection(int maxNoOfChildren, 377 int maxDepth, 378 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 379 throws Exception 380 { 381 int noOfSelections = 0; 382 383 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 384 if (entry.getKey() instanceof ISelection) { 385 noOfSelections++; 386 } 387 } 388 389 if (noOfSelections > 0) { 390 noOfSelections = (int) (Math.random() * noOfSelections); 391 392 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 393 if (entry.getKey() instanceof ISelection) { 394 if (--noOfSelections <= 0) { 395 return (ISelection) entry.getKey(); 396 } 397 } 398 } 399 } 400 else { 401 return createNewSelection(maxNoOfChildren, maxDepth, treeInfos); 402 } 403 404 throw new RuntimeException("this is an implementation error"); 405 } 406 407 /** 408 * TODO: comment 409 * 410 * @param treeInfos 411 * @return 412 */ 413 private IIteration createNewIteration(int maxNoOfChildren, 414 int maxDepth, 415 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 416 throws Exception 417 { 418 IIteration iteration = taskTreeNodeFactory.createNewIteration(); 419 420 ITaskTreeNode child = createTree(maxNoOfChildren, maxDepth - 1, treeInfos); 421 422 // through first removing an existing parent it is assured, that a parent is recorded 423 // only once. This is needed, because parent may be reused in a tree as well, but we always 424 // iterate the whole tree 425 ((NodeInfo) treeInfos.get(child)).removeParent(iteration); 426 ((NodeInfo) treeInfos.get(child)).addParent(iteration); 427 taskTreeBuilder.setChild(iteration, child); 428 429 treeInfos.put(iteration, new NodeInfo(iteration)); 430 return iteration; 431 } 432 433 /** 434 * TODO: comment 435 * 436 * @param treeInfos 437 * @return 438 */ 439 private IIteration reuseIteration(int maxNoOfChildren, 440 int maxDepth, 441 Map<ITaskTreeNode, ITaskTreeNodeInfo> treeInfos) 442 throws Exception 443 { 444 int noOfIterations = 0; 445 446 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 447 if (entry.getKey() instanceof IIteration) { 448 noOfIterations++; 449 } 450 } 451 452 if (noOfIterations > 0) { 453 noOfIterations = (int) (Math.random() * noOfIterations); 454 455 for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : treeInfos.entrySet()) { 456 if (entry.getKey() instanceof IIteration) { 457 if (--noOfIterations <= 0) { 458 return (IIteration) entry.getKey(); 459 } 460 } 461 } 462 } 463 else { 464 return createNewIteration(maxNoOfChildren, maxDepth, treeInfos); 465 } 466 467 throw new RuntimeException("this is an implementation error"); 468 } 545 469 546 470 }
Note: See TracChangeset
for help on using the changeset viewer.