Ignore:
Timestamp:
08/31/12 09:58:43 (12 years ago)
Author:
pharms
Message:
  • moved condensing mouse clicks to a dedicated command
File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/quest-core-events-test/src/test/java/de/ugoe/cs/quest/eventcore/gui/MouseClickCondenserTest.java

    r692 r721  
    1 package de.ugoe.cs.quest.tasktrees.temporalrelation; 
     1package de.ugoe.cs.quest.eventcore.gui; 
     2 
     3import static org.junit.Assert.assertEquals; 
     4import static org.junit.Assert.assertFalse; 
     5import static org.junit.Assert.assertTrue; 
     6 
     7import java.util.ArrayList; 
     8import java.util.List; 
    29 
    310import org.junit.Test; 
    411 
     12import de.ugoe.cs.quest.eventcore.Event; 
     13import de.ugoe.cs.quest.eventcore.IEventType; 
    514import de.ugoe.cs.quest.eventcore.gui.MouseButtonDown; 
    615import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction; 
     
    817import de.ugoe.cs.quest.eventcore.gui.MouseClick; 
    918import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 
    10 import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker; 
    1119import de.ugoe.cs.quest.test.DummyGUIElement; 
    1220import de.ugoe.cs.quest.test.DummyInteraction; 
    1321 
    1422/** 
    15  * TODO comment 
    16  *  
    17  * @version $Revision: $ $Date: $ 
    18  * @author 2011, last modified by $Author: $ 
     23 * @author Patrick Harms 
    1924 */ 
    20 public class DefaultMouseClickReductionRuleTest extends AbstractTemporalRelationshipTC { 
     25public class MouseClickCondenserTest { 
     26 
     27    /** */ 
     28    private List<Event> events = new ArrayList<Event>(); 
    2129 
    2230    /** 
     
    3038 
    3139        IGUIElement element1 = new DummyGUIElement("elem1"); 
    32         IGUIElement element2 = new DummyGUIElement("elem1"); 
     40        IGUIElement element2 = new DummyGUIElement("elem2"); 
    3341 
    3442        simulateEvent(new MouseButtonDown(leftBtn), element1); 
    3543        simulateEvent(new MouseButtonUp(leftBtn), element1); 
    3644        simulateEvent(new MouseClick(leftBtn), element1); 
    37  
    38         new TaskTreeChecker().assertTaskTree 
    39             ("Sequence sequence {" + 
    40              "  Event LeftMouseClick {}" + 
    41              "}", getTaskTree()); 
     45        assertCondensedMouseClicks("elem1"); 
    4246 
    4347        simulateEvent(new DummyInteraction("bla", 1), element1); 
     
    4852        simulateEvent(new DummyInteraction("blo", 1), element1); 
    4953        simulateEvent(new DummyInteraction("blu", 1), element1); 
    50  
    51         new TaskTreeChecker().assertTaskTree 
    52             ("Sequence sequence {" + 
    53              "  Event LeftMouseClick {}" + 
    54              "  Event bla {}" + 
    55              "  Event bli {}" + 
    56              "  Event MiddleMouseClick {}" + 
    57              "  Event blo {}" + 
    58              "  Event blu {}" + 
    59              "}", getTaskTree()); 
     54        assertCondensedMouseClicks("elem1", "", "", "elem1", "", ""); 
    6055 
    6156        simulateEvent(new DummyInteraction("bla", 1), element2); 
     
    6661        simulateEvent(new DummyInteraction("blo", 1), element2); 
    6762        simulateEvent(new DummyInteraction("blu", 1), element2); 
    68  
    69         new TaskTreeChecker().assertTaskTree 
    70             ("Sequence sequence0 {" + 
    71              "  Sequence sequence1 {" + 
    72              "    Event LeftMouseClick {}" + 
    73              "    Event bla {}" + 
    74              "    Event bli {}" + 
    75              "    Event MiddleMouseClick {}" + 
    76              "    Event blo {}" + 
    77              "    Event blu {}" + 
    78              "  }" + 
    79              "  Sequence sequence2 {" + 
    80              "    Event bla {}" + 
    81              "    Event bli {}" + 
    82              "    Event RightMouseClick {}" + 
    83              "    Event blo {}" + 
    84              "    Event blu {}" + 
    85              "  }" + 
    86              "}", getTaskTree()); 
     63        assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", ""); 
    8764 
    8865        simulateEvent(new MouseButtonDown(leftBtn), element1); 
    8966        simulateEvent(new MouseButtonUp(leftBtn), element1); 
    9067        simulateEvent(new MouseClick(leftBtn), element2); 
    91  
    92         new TaskTreeChecker().assertTaskTree 
    93             ("Sequence sequence0 {" + 
    94              "  Sequence sequence1 {" + 
    95              "    Event LeftMouseClick {}" + 
    96              "    Event bla {}" + 
    97              "    Event bli {}" + 
    98              "    Event MiddleMouseClick {}" + 
    99              "    Event blo {}" + 
    100              "    Event blu {}" + 
    101              "  }" + 
    102              "  Sequence sequence2 {" + 
    103              "    Event bla {}" + 
    104              "    Event bli {}" + 
    105              "    Event RightMouseClick {}" + 
    106              "    Event blo {}" + 
    107              "    Event blu {}" + 
    108              "  }" + 
    109              "  Sequence sequence3 {" + 
    110              "    Event LeftMouseButtonDown {}" + 
    111              "    Event LeftMouseButtonUp {}" + 
    112              "  }" + 
    113              "  Sequence sequence4 {" + 
    114              "    Event LeftMouseClick {}" + 
    115              "  }" + 
    116              "}", getTaskTree()); 
     68        assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", "", 
     69                                   "", "", "elem2"); 
    11770 
    11871        simulateEvent(new MouseButtonDown(middleBtn), element1); 
     
    12073        simulateEvent(new MouseClick(rightBtn), element1); 
    12174        simulateEvent(new DummyInteraction("bla", 1), element2); 
    122  
    123         new TaskTreeChecker().assertTaskTree 
    124             ("Sequence sequence0 {" + 
    125              "  Sequence sequence1 {" + 
    126              "    Event LeftMouseClick {}" + 
    127              "    Event bla {}" + 
    128              "    Event bli {}" + 
    129              "    Event MiddleMouseClick {}" + 
    130              "    Event blo {}" + 
    131              "    Event blu {}" + 
    132              "  }" + 
    133              "  Sequence sequence2 {" + 
    134              "    Event bla {}" + 
    135              "    Event bli {}" + 
    136              "    Event RightMouseClick {}" + 
    137              "    Event blo {}" + 
    138              "    Event blu {}" + 
    139              "  }" + 
    140              "  Sequence sequence3 {" + 
    141              "    Event LeftMouseButtonDown {}" + 
    142              "    Event LeftMouseButtonUp {}" + 
    143              "  }" + 
    144              "  Sequence sequence4 {" + 
    145              "    Event LeftMouseClick {}" + 
    146              "  }" + 
    147              "  Sequence sequence5 {" + 
    148              "    Sequence sequence6 {" + 
    149              "      Event MiddleMouseButtonDown {}" + 
    150              "      Event MiddleMouseButtonUp {}" + 
    151              "    }" + 
    152              "    Event RightMouseClick {}" + 
    153              "  }" + 
    154              "  Sequence sequence7 {" + 
    155              "    Event bla {}" + 
    156              "  }" + 
    157              "}", getTaskTree()); 
    158  
     75        assertCondensedMouseClicks("elem1", "", "", "elem1", "", "", "", "", "elem2", "", "", 
     76                                   "", "", "elem2", "", "", "elem1", ""); 
    15977    } 
    16078 
     79    /** 
     80     * 
     81     */ 
     82    private void simulateEvent(IEventType eventType, IGUIElement guiElement) { 
     83        events.add(new Event(eventType, guiElement)); 
     84    } 
     85 
     86    /** 
     87    * 
     88    */ 
     89   private void assertCondensedMouseClicks(String... clickedTargets) { 
     90       MouseClickCondenser condenser = new MouseClickCondenser(); 
     91       List<Event> result = condenser.condenseMouseClicks(events); 
     92        
     93       assertEquals(clickedTargets.length, result.size()); 
     94        
     95       for (int i = 0; i < clickedTargets.length; i++) { 
     96           String clickedTarget = clickedTargets[i]; 
     97            
     98           if ((clickedTarget != null) && (!"".equals(clickedTarget))) { 
     99               assertTrue(result.get(i).getType() instanceof MouseClick); 
     100               assertTrue(result.get(i).getTarget() instanceof DummyGUIElement); 
     101               assertEquals 
     102                 (clickedTarget, ((DummyGUIElement) result.get(i).getTarget()).getStringIdentifier()); 
     103           } 
     104           else { 
     105               assertFalse(result.get(i).getType() instanceof MouseClick); 
     106           } 
     107       } 
     108   } 
    161109} 
Note: See TracChangeset for help on using the changeset viewer.