[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.eventcore.gui;
|
---|
[445] | 16 |
|
---|
[721] | 17 | import static org.junit.Assert.assertEquals;
|
---|
| 18 | import static org.junit.Assert.assertFalse;
|
---|
| 19 | import static org.junit.Assert.assertTrue;
|
---|
| 20 |
|
---|
| 21 | import java.util.ArrayList;
|
---|
| 22 | import java.util.List;
|
---|
| 23 |
|
---|
[445] | 24 | import org.junit.Test;
|
---|
| 25 |
|
---|
[922] | 26 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 27 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
| 28 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonDown;
|
---|
| 29 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
|
---|
| 30 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonUp;
|
---|
| 31 | import de.ugoe.cs.autoquest.eventcore.gui.MouseClick;
|
---|
| 32 | import de.ugoe.cs.autoquest.eventcore.gui.MouseClickCondenser;
|
---|
| 33 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
|
---|
| 34 | import de.ugoe.cs.autoquest.test.DummyGUIElement;
|
---|
| 35 | import de.ugoe.cs.autoquest.test.DummyInteraction;
|
---|
[445] | 36 |
|
---|
| 37 | /**
|
---|
[721] | 38 | * @author Patrick Harms
|
---|
[445] | 39 | */
|
---|
[721] | 40 | public class MouseClickCondenserTest {
|
---|
[445] | 41 |
|
---|
[721] | 42 | /** */
|
---|
| 43 | private List<Event> events = new ArrayList<Event>();
|
---|
| 44 |
|
---|
[557] | 45 | /**
|
---|
| 46 | *
|
---|
| 47 | */
|
---|
| 48 | @Test
|
---|
| 49 | public void testMouseClickInOneSequenceElement() {
|
---|
| 50 | MouseButtonInteraction.Button leftBtn = MouseButtonInteraction.Button.LEFT;
|
---|
| 51 | MouseButtonInteraction.Button middleBtn = MouseButtonInteraction.Button.MIDDLE;
|
---|
| 52 | MouseButtonInteraction.Button rightBtn = MouseButtonInteraction.Button.RIGHT;
|
---|
[445] | 53 |
|
---|
[557] | 54 | IGUIElement element1 = new DummyGUIElement("elem1");
|
---|
[721] | 55 | IGUIElement element2 = new DummyGUIElement("elem2");
|
---|
[445] | 56 |
|
---|
[946] | 57 | simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1);
|
---|
| 58 | simulateEvent(new MouseButtonUp(leftBtn, 0, 0), element1);
|
---|
| 59 | simulateEvent(new MouseClick(leftBtn, 0, 0), element1);
|
---|
[721] | 60 | assertCondensedMouseClicks("elem1");
|
---|
[445] | 61 |
|
---|
[557] | 62 | simulateEvent(new DummyInteraction("bla", 1), element1);
|
---|
| 63 | simulateEvent(new DummyInteraction("bli", 1), element1);
|
---|
[946] | 64 | simulateEvent(new MouseButtonDown(middleBtn, 0, 0), element1);
|
---|
| 65 | simulateEvent(new MouseButtonUp(middleBtn, 0, 0), element1);
|
---|
| 66 | simulateEvent(new MouseClick(middleBtn, 0, 0), element1);
|
---|
[557] | 67 | simulateEvent(new DummyInteraction("blo", 1), element1);
|
---|
| 68 | simulateEvent(new DummyInteraction("blu", 1), element1);
|
---|
[721] | 69 | assertCondensedMouseClicks("elem1", "", "", "elem1", "", "");
|
---|
[445] | 70 |
|
---|
[557] | 71 | simulateEvent(new DummyInteraction("bla", 1), element2);
|
---|
| 72 | simulateEvent(new DummyInteraction("bli", 1), element2);
|
---|
[946] | 73 | simulateEvent(new MouseButtonDown(rightBtn, 0, 0), element2);
|
---|
| 74 | simulateEvent(new MouseButtonUp(rightBtn, 0, 0), element2);
|
---|
| 75 | simulateEvent(new MouseClick(rightBtn, 0, 0), element2);
|
---|
[557] | 76 | simulateEvent(new DummyInteraction("blo", 1), element2);
|
---|
| 77 | simulateEvent(new DummyInteraction("blu", 1), element2);
|
---|
[721] | 78 | assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", "");
|
---|
[445] | 79 |
|
---|
[946] | 80 | simulateEvent(new MouseButtonDown(leftBtn, 0, 0), element1);
|
---|
| 81 | simulateEvent(new MouseButtonUp(leftBtn, 0, 0), element1);
|
---|
| 82 | simulateEvent(new MouseClick(leftBtn, 0, 0), element2);
|
---|
[721] | 83 | assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", "",
|
---|
| 84 | "", "", "elem2");
|
---|
[557] | 85 |
|
---|
[946] | 86 | simulateEvent(new MouseButtonDown(middleBtn, 0, 0), element1);
|
---|
| 87 | simulateEvent(new MouseButtonUp(middleBtn, 0, 0), element1);
|
---|
| 88 | simulateEvent(new MouseClick(rightBtn, 0, 0), element1);
|
---|
[557] | 89 | simulateEvent(new DummyInteraction("bla", 1), element2);
|
---|
[721] | 90 | assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", "",
|
---|
| 91 | "", "", "elem2", "", "", "elem1", "");
|
---|
| 92 | }
|
---|
[557] | 93 |
|
---|
[721] | 94 | /**
|
---|
| 95 | *
|
---|
| 96 | */
|
---|
| 97 | private void simulateEvent(IEventType eventType, IGUIElement guiElement) {
|
---|
| 98 | events.add(new Event(eventType, guiElement));
|
---|
[557] | 99 | }
|
---|
| 100 |
|
---|
[721] | 101 | /**
|
---|
| 102 | *
|
---|
| 103 | */
|
---|
| 104 | private void assertCondensedMouseClicks(String... clickedTargets) {
|
---|
| 105 | MouseClickCondenser condenser = new MouseClickCondenser();
|
---|
| 106 | List<Event> result = condenser.condenseMouseClicks(events);
|
---|
| 107 |
|
---|
| 108 | assertEquals(clickedTargets.length, result.size());
|
---|
| 109 |
|
---|
| 110 | for (int i = 0; i < clickedTargets.length; i++) {
|
---|
| 111 | String clickedTarget = clickedTargets[i];
|
---|
| 112 |
|
---|
| 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 | }
|
---|
[445] | 124 | }
|
---|