Changeset 688 for trunk/quest-core-events-test/src/test/java
- Timestamp:
- 08/29/12 16:08:57 (12 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-events-test/src/test/java/de/ugoe/cs/quest/eventcore/gui/TextInputDetectorTest.java
r655 r688 1 package de.ugoe.cs.quest.tasktrees.temporalrelation; 1 package de.ugoe.cs.quest.eventcore.gui; 2 3 import static org.junit.Assert.*; 4 5 import java.util.ArrayList; 6 import java.util.List; 2 7 3 8 import org.junit.Test; 4 9 5 import de.ugoe.cs.quest.eventcore. gui.KeyPressed;6 import de.ugoe.cs.quest.eventcore. gui.KeyReleased;10 import de.ugoe.cs.quest.eventcore.Event; 11 import de.ugoe.cs.quest.eventcore.IEventType; 7 12 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 8 import de.ugoe.cs.quest.eventcore.guimodel.ITextField; 9 import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement; 10 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 13 import de.ugoe.cs.quest.test.DummyGUIElement; 14 import de.ugoe.cs.quest.test.DummyTextField; 11 15 import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; 12 16 13 17 /** 14 * TODO comment 15 * 16 * @version $Revision: $ $Date: 28.04.2012$ 17 * @author 2012, last modified by $Author: patrick$ 18 * @author Patrick Harms 18 19 */ 19 public class DefaultTextInputReductionRuleTest extends AbstractTemporalRelationshipTC { 20 public class TextInputDetectorTest { 21 22 private List<Event> events = new ArrayList<Event>(); 20 23 21 24 /** … … 27 30 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 28 31 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 29 new TaskTreeChecker(true).assertTaskTree 30 ("Sequence sequence0 {" + 31 " TextInputEvent TextInput a {" + 32 " Event KeyPressed LETTER_A {}" + 33 " Event KeyReleased LETTER_A {}" + 34 " }" + 35 "}", getTaskTree()); 36 37 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 38 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 39 new TaskTreeChecker().assertTaskTree 40 ("Sequence sequence0 {" + 41 " TextInputEvent TextInput ab {" + 42 " Event KeyPressed LETTER_A {}" + 43 " Event KeyReleased LETTER_A {}" + 44 " Event KeyPressed LETTER_B {}" + 45 " Event KeyReleased LETTER_B {}" + 46 " }" + 47 "}", getTaskTree()); 48 49 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 50 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 51 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 52 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 53 new TaskTreeChecker().assertTaskTree 54 ("Sequence sequence0 {" + 55 " TextInputEvent TextInput abC {" + 56 " Event KeyPressed LETTER_A {}" + 57 " Event KeyReleased LETTER_A {}" + 58 " Event KeyPressed LETTER_B {}" + 59 " Event KeyReleased LETTER_B {}" + 60 " Event KeyPressed SHIFT {}" + 61 " Event KeyPressed LETTER_C {}" + 62 " Event KeyReleased LETTER_C {}" + 63 " Event KeyReleased SHIFT {}" + 64 " }" + 65 "}", getTaskTree()); 32 assertTextInput("a"); 33 34 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 35 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 36 assertTextInput("ab"); 37 38 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 39 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 40 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 41 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 42 assertTextInput("abC"); 66 43 67 44 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); … … 73 50 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element1); 74 51 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 75 new TaskTreeChecker().assertTaskTree 76 ("Sequence sequence0 {" + 77 " TextInputEvent TextInput abCDEF {" + 78 " Event KeyPressed LETTER_A {}" + 79 " Event KeyReleased LETTER_A {}" + 80 " Event KeyPressed LETTER_B {}" + 81 " Event KeyReleased LETTER_B {}" + 82 " Event KeyPressed SHIFT {}" + 83 " Event KeyPressed LETTER_C {}" + 84 " Event KeyReleased LETTER_C {}" + 85 " Event KeyReleased SHIFT {}" + 86 " Event KeyPressed SHIFT {}" + 87 " Event KeyPressed LETTER_D {}" + 88 " Event KeyReleased LETTER_D {}" + 89 " Event KeyPressed LETTER_E {}" + 90 " Event KeyReleased LETTER_E {}" + 91 " Event KeyPressed LETTER_F {}" + 92 " Event KeyReleased LETTER_F {}" + 93 " Event KeyReleased SHIFT {}" + 94 " }" + 95 "}", getTaskTree()); 52 assertTextInput("abCDEF"); 96 53 97 54 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); … … 101 58 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 102 59 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 103 new TaskTreeChecker().assertTaskTree 104 ("Sequence sequence0 {" + 105 " TextInputEvent TextInput abCDEFg {" + 106 " Event KeyPressed LETTER_A {}" + 107 " Event KeyReleased LETTER_A {}" + 108 " Event KeyPressed LETTER_B {}" + 109 " Event KeyReleased LETTER_B {}" + 110 " Event KeyPressed SHIFT {}" + 111 " Event KeyPressed LETTER_C {}" + 112 " Event KeyReleased LETTER_C {}" + 113 " Event KeyReleased SHIFT {}" + 114 " Event KeyPressed SHIFT {}" + 115 " Event KeyPressed LETTER_D {}" + 116 " Event KeyReleased LETTER_D {}" + 117 " Event KeyPressed LETTER_E {}" + 118 " Event KeyReleased LETTER_E {}" + 119 " Event KeyPressed LETTER_F {}" + 120 " Event KeyReleased LETTER_F {}" + 121 " Event KeyReleased SHIFT {}" + 122 " Event KeyPressed SHIFT {}" + 123 " Event KeyPressed SHIFT {}" + 124 " Event KeyPressed LETTER_G {}" + 125 " Event KeyReleased LETTER_G {}" + 126 " Event KeyReleased SHIFT {}" + 127 " Event KeyReleased SHIFT {}" + 128 " }" + 129 "}", getTaskTree()); 60 assertTextInput("abCDEFg"); 130 61 131 62 } … … 140 71 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 141 72 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 142 new TaskTreeChecker().assertTaskTree 143 ("Sequence sequence0 {" + 144 " TextInputEvent TextInput a {" + 145 " Event KeyPressed LETTER_A {}" + 146 " Event KeyReleased LETTER_A {}" + 147 " }" + 148 "}", getTaskTree()); 73 assertTextInput("a"); 149 74 150 75 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element2); 151 76 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element2); 152 new TaskTreeChecker().assertTaskTree 153 ("Sequence sequence0 {" + 154 " Sequence sequence1 {" + 155 " TextInputEvent TextInput a {" + 156 " Event KeyPressed LETTER_A {}" + 157 " Event KeyReleased LETTER_A {}" + 158 " }" + 159 " }" + 160 " Sequence sequence2 {" + 161 " TextInputEvent TextInput b {" + 162 " Event KeyPressed LETTER_B {}" + 163 " Event KeyReleased LETTER_B {}" + 164 " }" + 165 " }" + 166 "}", getTaskTree()); 167 168 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 169 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 170 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 171 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 172 new TaskTreeChecker().assertTaskTree 173 ("Sequence sequence0 {" + 174 " Sequence sequence1 {" + 175 " TextInputEvent TextInput a {" + 176 " Event KeyPressed LETTER_A {}" + 177 " Event KeyReleased LETTER_A {}" + 178 " }" + 179 " }" + 180 " Sequence sequence2 {" + 181 " TextInputEvent TextInput b {" + 182 " Event KeyPressed LETTER_B {}" + 183 " Event KeyReleased LETTER_B {}" + 184 " }" + 185 " }" + 186 " Sequence sequence3 {" + 187 " TextInputEvent TextInput C {" + 188 " Event KeyPressed SHIFT {}" + 189 " Event KeyPressed LETTER_C {}" + 190 " Event KeyReleased LETTER_C {}" + 191 " Event KeyReleased SHIFT {}" + 192 " }" + 193 " }" + 194 "}", getTaskTree()); 77 assertTextInput("a", "b"); 78 79 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); 80 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 81 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 82 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 83 assertTextInput("a", "b", "C"); 195 84 196 85 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element2); … … 202 91 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element2); 203 92 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element2); 204 new TaskTreeChecker().assertTaskTree 205 ("Sequence sequence0 {" + 206 " Sequence sequence1 {" + 207 " TextInputEvent TextInput a {" + 208 " Event KeyPressed LETTER_A {}" + 209 " Event KeyReleased LETTER_A {}" + 210 " }" + 211 " }" + 212 " Sequence sequence2 {" + 213 " TextInputEvent TextInput b {" + 214 " Event KeyPressed LETTER_B {}" + 215 " Event KeyReleased LETTER_B {}" + 216 " }" + 217 " }" + 218 " Sequence sequence3 {" + 219 " TextInputEvent TextInput C {" + 220 " Event KeyPressed SHIFT {}" + 221 " Event KeyPressed LETTER_C {}" + 222 " Event KeyReleased LETTER_C {}" + 223 " Event KeyReleased SHIFT {}" + 224 " }" + 225 " }" + 226 " Sequence sequence4 {" + 227 " TextInputEvent TextInput DEF {" + 228 " Event KeyPressed SHIFT {}" + 229 " Event KeyPressed LETTER_D {}" + 230 " Event KeyReleased LETTER_D {}" + 231 " Event KeyPressed LETTER_E {}" + 232 " Event KeyReleased LETTER_E {}" + 233 " Event KeyPressed LETTER_F {}" + 234 " Event KeyReleased LETTER_F {}" + 235 " Event KeyReleased SHIFT {}" + 236 " }" + 237 " }" + 238 "}", getTaskTree()); 93 assertTextInput("a", "b", "C", "DEF"); 239 94 240 95 simulateEvent(new KeyPressed(VirtualKey.SHIFT), element1); … … 244 99 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 245 100 simulateEvent(new KeyReleased(VirtualKey.SHIFT), element1); 246 new TaskTreeChecker().assertTaskTree 247 ("Sequence sequence0 {" + 248 " Sequence sequence1 {" + 249 " TextInputEvent TextInput a {" + 250 " Event KeyPressed LETTER_A {}" + 251 " Event KeyReleased LETTER_A {}" + 252 " }" + 253 " }" + 254 " Sequence sequence2 {" + 255 " TextInputEvent TextInput b {" + 256 " Event KeyPressed LETTER_B {}" + 257 " Event KeyReleased LETTER_B {}" + 258 " }" + 259 " }" + 260 " Sequence sequence3 {" + 261 " TextInputEvent TextInput C {" + 262 " Event KeyPressed SHIFT {}" + 263 " Event KeyPressed LETTER_C {}" + 264 " Event KeyReleased LETTER_C {}" + 265 " Event KeyReleased SHIFT {}" + 266 " }" + 267 " }" + 268 " Sequence sequence4 {" + 269 " TextInputEvent TextInput DEF {" + 270 " Event KeyPressed SHIFT {}" + 271 " Event KeyPressed LETTER_D {}" + 272 " Event KeyReleased LETTER_D {}" + 273 " Event KeyPressed LETTER_E {}" + 274 " Event KeyReleased LETTER_E {}" + 275 " Event KeyPressed LETTER_F {}" + 276 " Event KeyReleased LETTER_F {}" + 277 " Event KeyReleased SHIFT {}" + 278 " }" + 279 " }" + 280 " Sequence sequence5 {" + 281 " TextInputEvent TextInput g {" + 282 " Event KeyPressed SHIFT {}" + 283 " Event KeyPressed SHIFT {}" + 284 " Event KeyPressed LETTER_G {}" + 285 " Event KeyReleased LETTER_G {}" + 286 " Event KeyReleased SHIFT {}" + 287 " Event KeyReleased SHIFT {}" + 288 " }" + 289 " }" + 290 "}", getTaskTree()); 101 assertTextInput("a", "b", "C", "DEF", "g"); 291 102 292 103 } … … 312 123 simulateEvent(new KeyPressed(VirtualKey.LETTER_F), element1); 313 124 simulateEvent(new KeyReleased(VirtualKey.LETTER_F), element1); 314 new TaskTreeChecker().assertTaskTree 315 ("Sequence sequence0 {" + 316 " TextInputEvent TextInput abcef {" + 317 " Event KeyPressed LETTER_A {}" + 318 " Event KeyReleased LETTER_A {}" + 319 " Event KeyPressed LETTER_B {}" + 320 " Event KeyReleased LETTER_B {}" + 321 " Event KeyPressed LETTER_C {}" + 322 " Event KeyReleased LETTER_C {}" + 323 " Event KeyPressed LETTER_D {}" + 324 " Event KeyReleased LETTER_D {}" + 325 " Event KeyPressed BACK_SPACE {}" + 326 " Event KeyReleased BACK_SPACE {}" + 327 " Event KeyPressed LETTER_E {}" + 328 " Event KeyReleased LETTER_E {}" + 329 " Event KeyPressed LETTER_F {}" + 330 " Event KeyReleased LETTER_F {}" + 331 " }" + 332 "}", getTaskTree()); 333 334 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 335 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 336 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 337 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 338 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 339 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 340 new TaskTreeChecker().assertTaskTree 341 ("Sequence sequence0 {" + 342 " TextInputEvent TextInput ab {" + 343 " Event KeyPressed LETTER_A {}" + 344 " Event KeyReleased LETTER_A {}" + 345 " Event KeyPressed LETTER_B {}" + 346 " Event KeyReleased LETTER_B {}" + 347 " Event KeyPressed LETTER_C {}" + 348 " Event KeyReleased LETTER_C {}" + 349 " Event KeyPressed LETTER_D {}" + 350 " Event KeyReleased LETTER_D {}" + 351 " Event KeyPressed BACK_SPACE {}" + 352 " Event KeyReleased BACK_SPACE {}" + 353 " Event KeyPressed LETTER_E {}" + 354 " Event KeyReleased LETTER_E {}" + 355 " Event KeyPressed LETTER_F {}" + 356 " Event KeyReleased LETTER_F {}" + 357 " Event KeyPressed BACK_SPACE {}" + 358 " Event KeyReleased BACK_SPACE {}" + 359 " Event KeyPressed BACK_SPACE {}" + 360 " Event KeyReleased BACK_SPACE {}" + 361 " Event KeyPressed BACK_SPACE {}" + 362 " Event KeyReleased BACK_SPACE {}" + 363 " }" + 364 "}", getTaskTree()); 365 366 } 367 368 /** 369 * 370 */ 371 private static class DummyTextField extends DummyGUIElement implements ITextField { 372 373 /** */ 374 private static final long serialVersionUID = 1L; 375 376 /** 377 * TODO: comment 378 * 379 * @param name 380 */ 381 public DummyTextField(String name) { 382 super(name); 125 assertTextInput("abcef"); 126 127 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 128 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 129 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 130 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 131 simulateEvent(new KeyPressed(VirtualKey.BACK_SPACE), element1); 132 simulateEvent(new KeyReleased(VirtualKey.BACK_SPACE), element1); 133 assertTextInput("ab"); 134 135 } 136 137 /** 138 * 139 */ 140 @Test 141 public void testOtherInteractionsInBetween() { 142 IGUIElement element1 = new DummyTextField("elem1"); 143 IGUIElement element2 = new DummyGUIElement("elem2"); 144 IGUIElement element3 = new DummyGUIElement("elem3"); 145 146 simulateEvent(new MouseClick(MouseClick.Button.LEFT), element2); 147 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 148 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 149 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 150 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 151 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 152 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 153 assertTextInput("", "abc"); 154 155 simulateEvent(new MouseClick(MouseClick.Button.LEFT), element2); 156 simulateEvent(new MouseClick(MouseClick.Button.LEFT), element3); 157 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 158 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 159 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 160 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 161 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 162 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 163 simulateEvent(new MouseClick(MouseClick.Button.LEFT), element3); 164 assertTextInput("", "abc", "", "", "abc", ""); 165 166 simulateEvent(new MouseClick(MouseClick.Button.LEFT), element2); 167 simulateEvent(new MouseClick(MouseClick.Button.LEFT), element3); 168 simulateEvent(new KeyPressed(VirtualKey.LETTER_A), element1); 169 simulateEvent(new KeyReleased(VirtualKey.LETTER_A), element1); 170 simulateEvent(new KeyPressed(VirtualKey.LETTER_B), element1); 171 simulateEvent(new KeyReleased(VirtualKey.LETTER_B), element1); 172 simulateEvent(new KeyPressed(VirtualKey.LETTER_C), element1); 173 simulateEvent(new MouseClick(MouseClick.Button.LEFT), element3); 174 simulateEvent(new KeyReleased(VirtualKey.LETTER_C), element1); 175 176 // the pressing of the c is not completed. So it must be included in the resulting 177 // text input event but it may only be followed by the mouse click. The subsequent release 178 // of the c key is ignored and results in a removal of the event. 179 assertTextInput("", "abc", "", "", "abc", "", "", "", "abc", ""); 180 } 181 182 /** 183 * 184 */ 185 private void simulateEvent(IEventType eventType, IGUIElement guiElement) { 186 events.add(new Event(eventType, guiElement)); 187 } 188 189 /** 190 * 191 */ 192 private void assertTextInput(String... enteredTexts) { 193 TextInputDetector detector = new TextInputDetector(); 194 List<Event> result = detector.detectTextInputs(events); 195 196 assertEquals(enteredTexts.length, result.size()); 197 198 for (int i = 0; i < enteredTexts.length; i++) { 199 String enteredText = enteredTexts[i]; 200 201 if ((enteredText != null) && (!"".equals(enteredText))) { 202 assertTrue(result.get(i).getType() instanceof TextInput); 203 assertNotNull(((TextInput) result.get(i).getType()).getEnteredText()); 204 assertEquals(enteredText, ((TextInput) result.get(i).getType()).getEnteredText()); 205 206 assertNotNull(((TextInput) result.get(i).getType()).getTextInputEvents()); 207 assertTrue(((TextInput) result.get(i).getType()).getTextInputEvents().size() > 0); 208 //assertTrue 209 // ((((TextInput) result.get(i).getType()).getTextInputEvents().size() % 2) == 0); 210 } 211 else { 212 assertFalse(result.get(i).getType() instanceof TextInput); 213 } 383 214 } 384 385 } 386 215 } 387 216 }
Note: See TracChangeset
for help on using the changeset viewer.