Changeset 957
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-events-test/src/test/java/de/ugoe/cs/autoquest/eventcore/gui/MouseClickCondenserTest.java
r946 r957 18 18 import static org.junit.Assert.assertFalse; 19 19 import static org.junit.Assert.assertTrue; 20 import static org.junit.Assert.fail; 20 21 21 22 import java.util.ArrayList; … … 47 48 */ 48 49 @Test 49 public void test MouseClickInOneSequenceElement() {50 public void testNormalSequence() { 50 51 MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT; 51 52 MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE; … … 53 54 54 55 IGUIElement element1 = new DummyGUIElement("elem1"); 55 IGUIElement element2 = new DummyGUIElement("elem2");56 56 57 57 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 58 58 simulateEvent(new MouseButtonUp(leftBtn, 0, 0), element1); 59 59 simulateEvent(new MouseClick(leftBtn, 0, 0), element1); 60 assertCondensedMouseClicks("elem1"); 60 assertCondensedMouseClicks("click left elem1"); 61 62 simulateEvent(new MouseButtonDown(middleBtn, 0, 0), element1); 63 simulateEvent(new MouseButtonUp(middleBtn, 0, 0), element1); 64 simulateEvent(new MouseClick(middleBtn, 0, 0), element1); 65 assertCondensedMouseClicks("click left elem1", "click middle elem1"); 66 67 simulateEvent(new MouseButtonDown(rightBtn, 0, 0), element1); 68 simulateEvent(new MouseButtonUp(rightBtn, 0, 0), element1); 69 simulateEvent(new MouseClick(rightBtn, 0, 0), element1); 70 assertCondensedMouseClicks("click left elem1", "click middle elem1", "click right elem1"); 71 72 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 73 simulateEvent(new MouseButtonUp(leftBtn, 0, 0), element1); 74 assertCondensedMouseClicks("click left elem1", "click middle elem1", "click right elem1", 75 "click left elem1"); 76 77 simulateEvent(new MouseButtonDown(middleBtn, 0, 0), element1); 78 simulateEvent(new MouseButtonUp(middleBtn, 0, 0), element1); 79 assertCondensedMouseClicks("click left elem1", "click middle elem1", "click right elem1", 80 "click left elem1", "click middle elem1"); 81 82 simulateEvent(new MouseButtonDown(rightBtn, 0, 0), element1); 83 simulateEvent(new MouseButtonUp(rightBtn, 0, 0), element1); 84 assertCondensedMouseClicks("click left elem1", "click middle elem1", "click right elem1", 85 "click left elem1", "click middle elem1", "click right elem1"); 86 87 } 88 89 /** 90 * 91 */ 92 @Test 93 public void testMouseClickInSequence() { 94 MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE; 95 MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT; 96 97 IGUIElement element1 = new DummyGUIElement("elem1"); 98 IGUIElement element2 = new DummyGUIElement("elem2"); 61 99 62 100 simulateEvent(new DummyInteraction("bla", 1), element1); … … 67 105 simulateEvent(new DummyInteraction("blo", 1), element1); 68 106 simulateEvent(new DummyInteraction("blu", 1), element1); 69 assertCondensedMouseClicks(" elem1", "", "", "elem1", "", "");107 assertCondensedMouseClicks("", "", "click middle elem1", "", ""); 70 108 71 109 simulateEvent(new DummyInteraction("bla", 1), element2); … … 76 114 simulateEvent(new DummyInteraction("blo", 1), element2); 77 115 simulateEvent(new DummyInteraction("blu", 1), element2); 78 assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", ""); 116 assertCondensedMouseClicks("", "", "click middle elem1", "", "", 117 "", "", "click right elem2", "", ""); 118 119 } 120 121 122 /** 123 * 124 */ 125 @Test 126 public void testNoMouseClick() { 127 MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT; 128 MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE; 129 MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT; 130 131 IGUIElement element1 = new DummyGUIElement("elem1"); 132 IGUIElement element2 = new DummyGUIElement("elem2"); 79 133 80 134 simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1); 81 simulateEvent(new MouseButtonUp(leftBtn, 0, 0), element1); 82 simulateEvent(new MouseClick(leftBtn, 0, 0), element2); 83 assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", "", 84 "", "", "elem2"); 85 86 simulateEvent(new MouseButtonDown(middleBtn, 0, 0), element1); 87 simulateEvent(new MouseButtonUp(middleBtn, 0, 0), element1); 88 simulateEvent(new MouseClick(rightBtn, 0, 0), element1); 89 simulateEvent(new DummyInteraction("bla", 1), element2); 90 assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", "", 91 "", "", "elem2", "", "", "elem1", ""); 135 simulateEvent(new MouseButtonUp(leftBtn, 0, 0), element2); 136 simulateEvent(new MouseClick(leftBtn, 0, 0), element1); 137 assertCondensedMouseClicks("", "", "click left elem1"); 138 139 simulateEvent(new MouseButtonDown(middleBtn, 0, 0), element1); 140 simulateEvent(new MouseButtonUp(rightBtn, 0, 0), element1); 141 simulateEvent(new MouseClick(middleBtn, 0, 0), element1); 142 assertCondensedMouseClicks("", "", "click left elem1", "", "", "click middle elem1"); 143 144 simulateEvent(new MouseButtonDown(leftBtn, 1, 0), element1); 145 simulateEvent(new MouseButtonUp(leftBtn, 0, 1), element1); 146 simulateEvent(new MouseClick(leftBtn, 1, 1), element1); 147 assertCondensedMouseClicks("", "", "click left elem1", "", "", "click middle elem1", 148 "", "", "click left elem1"); 92 149 } 93 150 … … 100 157 101 158 /** 102 *103 */104 private void assertCondensedMouseClicks(String... clickedTargets) {105 MouseClickCondenser condenser = new MouseClickCondenser();106 List<Event> result = condenser.condenseMouseClicks(events);159 * 160 */ 161 private void assertCondensedMouseClicks(String... clickedTargets) { 162 MouseClickCondenser condenser = new MouseClickCondenser(); 163 List<Event> result = condenser.condenseMouseClicks(events); 107 164 108 assertEquals(clickedTargets.length, result.size());165 assertEquals(clickedTargets.length, result.size()); 109 166 110 for (int i = 0; i < clickedTargets.length; i++) {111 String clickedTarget = clickedTargets[i];167 for (int i = 0; i < clickedTargets.length; i++) { 168 String clickedTarget = clickedTargets[i]; 112 169 113 if ((clickedTarget != null) && (!"".equals(clickedTarget))) { 114 assertTrue(result.get(i).getType() instanceof MouseClick); 115 assertTrue(result.get(i).getTarget() instanceof DummyGUIElement); 116 assertEquals 117 (clickedTarget, ((DummyGUIElement) result.get(i).getTarget()).getStringIdentifier()); 118 } 119 else { 120 assertFalse(result.get(i).getType() instanceof MouseClick); 121 } 122 } 123 } 170 if ((clickedTarget != null) && (!"".equals(clickedTarget))) { 171 String[] parts = clickedTarget.split(" "); 172 assertEquals("invalid test case", 3, parts.length); 173 174 if ("click".equals(parts[0])) { 175 assertTrue(result.get(i).getType() instanceof MouseClick); 176 } 177 else { 178 fail("invalid assertion in test case"); 179 } 180 181 if ("left".equals(parts[1])) { 182 assertEquals(MouseButtonInteraction.Button.LEFT, 183 ((MouseButtonInteraction) result.get(i).getType()).getButton()); 184 } 185 else if ("middle".equals(parts[1])) { 186 assertEquals(MouseButtonInteraction.Button.MIDDLE, 187 ((MouseButtonInteraction) result.get(i).getType()).getButton()); 188 } 189 else if ("right".equals(parts[1])) { 190 assertEquals(MouseButtonInteraction.Button.RIGHT, 191 ((MouseButtonInteraction) result.get(i).getType()).getButton()); 192 } 193 else { 194 fail("invalid assertion in test case"); 195 } 196 197 assertTrue(result.get(i).getTarget() instanceof DummyGUIElement); 198 199 assertEquals 200 (parts[2], ((DummyGUIElement) result.get(i).getTarget()).getStringIdentifier()); 201 } 202 else { 203 assertFalse(result.get(i).getType() instanceof MouseClick); 204 } 205 } 206 } 124 207 } -
trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/gui/MouseClickCondenser.java
r947 r957 24 24 * <p> 25 25 * This class condenses mouse clicks, i.e. it reduces a sequence of mouse button down, mouse button 26 * up and mouse click with the same button on the same event target to a single mouse click with 27 * that button on that target. The mouse button down and mouse button up events are discarded. For 28 * this, it iterates the provided sequence and identifies any match of the named event sequence 29 * pattern. This match is condensed to the mouse click event. 26 * up and possibly a subsequent mouse click with the same button on the same event target and the 27 * same coordinates to a single mouse click with that button on that target at the coordinates. 28 * The mouse button down and mouse button up events are discarded. For this, it iterates the 29 * provided sequence and identifies any match of the named event sequence pattern. This match is 30 * condensed to the mouse click event. 31 * </p> 32 * <p> 33 * This class does not create events of proper type if the events are not of type {@link Event} 34 * but derived from it. 30 35 * </p> 31 36 * TODO correctly identify drag and drop … … 54 59 55 60 int index = 0; 56 while (index < sequence.size()) // -2 because we don't need to go to the end 61 boolean mouseClickHandled; 62 while (index < sequence.size()) 57 63 { 58 if ((index + 2) < sequence.size()) { 59 Event mouseButtonDown = sequence.get(index); 60 Event mouseButtonUp = sequence.get(index + 1); 61 Event mouseClick = sequence.get(index + 2); 62 if (mouseClickSequenceFound(mouseButtonDown, mouseButtonUp, mouseClick)) { 63 // skip the mouse button down and mouse button up event 64 mouseClickHandled = false; 65 if ((index + 1) < sequence.size()) { 66 Event mbDown = sequence.get(index); 67 Event mbUp = sequence.get(index + 1); 68 69 if (((index + 2) < sequence.size()) && 70 mouseClickSequenceFound(mbDown, mbUp, sequence.get(index + 2))) 71 { 72 // skip the mouse button down and mouse button up event and add the mouse click 64 73 index += 2; 74 resultingSequence.add(sequence.get(index)); 75 index++; 76 mouseClickHandled = true; 77 } 78 else if (mouseClickSequenceFound(mbDown, mbUp)) { 79 // skip the mouse button down and mouse button up event and add a mouse click 80 index += 2; 81 resultingSequence.add(createClick(mbDown, mbUp)); 82 mouseClickHandled = true; 65 83 } 66 84 } 67 85 68 resultingSequence.add(sequence.get(index)); 69 index++; 86 if (!mouseClickHandled) { 87 resultingSequence.add(sequence.get(index)); 88 index++; 89 } 70 90 } 71 91 … … 79 99 Event mouseButtonUp, 80 100 Event mouseClick) 101 { 102 if (!mouseClickSequenceFound(mouseButtonDown, mouseButtonUp)) { 103 return false; 104 } 105 106 // check the third node for validity 107 if (!(mouseClick.getType() instanceof MouseClick)) { 108 return false; 109 } 110 111 IEventTarget eventTarget = mouseButtonDown.getTarget(); 112 113 if (!eventTarget.equals(mouseClick.getTarget())) { 114 return false; 115 } 116 117 MouseButtonInteraction.Button button = 118 ((MouseButtonDown) mouseButtonDown.getType()).getButton(); 119 120 if (!button.equals(((MouseClick) mouseClick.getType()).getButton())) { 121 return false; 122 } 123 124 int x = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 125 126 if (x != ((MouseClick) mouseClick.getType()).getX()) { 127 return false; 128 } 129 130 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 131 132 if (y != ((MouseClick) mouseClick.getType()).getY()) { 133 return false; 134 } 135 136 return true; 137 } 138 139 /** 140 * 141 */ 142 private boolean mouseClickSequenceFound(Event mouseButtonDown, 143 Event mouseButtonUp) 81 144 { 82 145 // check the first in a row of three for validity … … 103 166 } 104 167 105 // check the third node for validity 106 if (!(mouseClick.getType() instanceof MouseClick)) { 168 int x = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 169 170 if (x != ((MouseButtonUp) mouseButtonUp.getType()).getX()) { 107 171 return false; 108 172 } 173 174 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 109 175 110 if ( !eventTarget.equals(mouseClick.getTarget())) {176 if (y != ((MouseButtonUp) mouseButtonUp.getType()).getY()) { 111 177 return false; 112 178 } 113 114 if (!button.equals(((MouseClick) mouseClick.getType()).getButton())) { 115 return false; 116 } 117 179 118 180 return true; 119 181 } 120 182 183 /** 184 * 185 */ 186 private Event createClick(Event mouseButtonDown, Event mouseButtonUp) { 187 MouseButtonInteraction.Button button = 188 ((MouseButtonDown) mouseButtonDown.getType()).getButton(); 189 190 int x = ((MouseButtonDown) mouseButtonDown.getType()).getX(); 191 int y = ((MouseButtonDown) mouseButtonDown.getType()).getY(); 192 193 return new Event(new MouseClick(button, x, y), mouseButtonDown.getTarget()); 194 } 195 121 196 }
Note: See TracChangeset
for help on using the changeset viewer.