Ignore:
Timestamp:
09/04/12 16:12:06 (12 years ago)
Author:
sherbold
Message:
  • complete rewrite of keyboard interaction sorting. As a result, the command cleanupKeyInteractions is deprecated.
File:
1 moved

Legend:

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

    r732 r765  
    44import static org.junit.Assert.assertEquals; 
    55 
    6 import java.util.ArrayList; 
     6import java.util.LinkedList; 
    77import java.util.List; 
    8  
     8import java.util.logging.Level; 
     9 
     10import org.junit.BeforeClass; 
    911import org.junit.Test; 
     12import static org.mockito.Mockito.*; 
    1013 
    1114import de.ugoe.cs.quest.eventcore.Event; 
    12 import de.ugoe.cs.quest.eventcore.guimodel.AbstractDefaultGUIElement; 
     15import de.ugoe.cs.quest.eventcore.gui.KeyInteractionSorter.CleanupMode; 
     16import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction.Button; 
    1317import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 
    14 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec; 
    1518import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; 
     19import de.ugoe.cs.util.console.Console; 
     20import de.ugoe.cs.util.console.TextConsole; 
    1621 
    1722/** 
    18  * @author Patrick Harms 
     23 * @author Patrick Harms, Steffen Herbold 
    1924 */ 
    20 public class SortedInteractionEventListTest { 
    21  
    22     /** 
    23    *  
    24    */ 
    25     @Test 
    26     public void testDifferentCombinationKeyCombinations() { 
    27         List<Event> checkList = new ArrayList<Event>(); 
    28         SortedInteractionEventList eventList = new SortedInteractionEventList(); 
    29  
    30         IGUIElement guiElement = new AbstractDefaultGUIElement(null, null) { 
    31  
    32             /**  */ 
    33             private static final long serialVersionUID = 1L; 
    34  
    35             @Override 
    36             public void updateSpecification(IGUIElementSpec furtherSpec) { 
    37                 // ignore 
    38             } 
    39  
    40             @Override 
    41             public String getPlatform() { 
    42                 return "TEST"; 
    43             } 
    44  
    45             @Override 
    46             public String getStringIdentifier() { 
    47                 return "DUMMY"; 
    48             } 
    49  
    50         }; 
    51  
    52         // check first of all a normal pressing and releasing of A and B 
    53         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    54         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    55         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
    56         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
    57  
    58         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    59         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    60         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
    61         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
    62  
    63         assertEquals(checkList.size(), eventList.size()); 
    64  
    65         for (int i = 0; i < checkList.size(); i++) { 
    66             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    67         } 
    68  
    69         // check what happens if A is pressed and not released before B is pressed 
    70         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_C), guiElement)); 
    71         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_D), guiElement)); 
    72         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_C), guiElement)); 
    73         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_D), guiElement)); 
    74  
    75         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_C), guiElement)); 
    76         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_C), guiElement)); 
    77         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_D), guiElement)); 
    78         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_D), guiElement)); 
    79  
    80         assertEquals(checkList.size(), eventList.size()); 
    81  
    82         for (int i = 0; i < checkList.size(); i++) { 
    83             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    84         } 
    85  
    86         // now SHIFT is pressed and released after all keys are pressed 
    87         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    88         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_E), guiElement)); 
    89         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_E), guiElement)); 
    90         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_F), guiElement)); 
    91         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_F), guiElement)); 
    92         eventList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    93  
    94         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    95         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_E), guiElement)); 
    96         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_E), guiElement)); 
    97         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_F), guiElement)); 
    98         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_F), guiElement)); 
    99         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    100  
    101         assertEquals(checkList.size(), eventList.size()); 
    102  
    103         for (int i = 0; i < checkList.size(); i++) { 
    104             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    105         } 
    106  
    107         // now SHIFT is released before the last key is released 
    108         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    109         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_G), guiElement)); 
    110         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_G), guiElement)); 
    111         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_H), guiElement)); 
    112         eventList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    113         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_H), guiElement)); 
    114  
    115         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    116         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_G), guiElement)); 
    117         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_G), guiElement)); 
    118         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_H), guiElement)); 
    119         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_H), guiElement)); 
    120         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    121  
    122         assertEquals(checkList.size(), eventList.size()); 
    123  
    124         for (int i = 0; i < checkList.size(); i++) { 
    125             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    126         } 
    127  
    128         // now SHIFT is released before all other keys are released 
    129         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    130         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_I), guiElement)); 
    131         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_J), guiElement)); 
    132         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_K), guiElement)); 
    133         eventList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    134         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_J), guiElement)); 
    135         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_K), guiElement)); 
    136         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_I), guiElement)); 
    137  
    138         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    139         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_I), guiElement)); 
    140         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_I), guiElement)); 
    141         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_J), guiElement)); 
    142         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_J), guiElement)); 
    143         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_K), guiElement)); 
    144         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_K), guiElement)); 
    145         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    146  
    147         assertEquals(checkList.size(), eventList.size()); 
    148  
    149         for (int i = 0; i < checkList.size(); i++) { 
    150             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    151         } 
    152  
    153         // now SHIFT, CTRL and ALT are pressed and released after all keys are pressed 
    154         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    155         eventList.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
    156         eventList.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
    157         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_L), guiElement)); 
    158         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_L), guiElement)); 
    159         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_M), guiElement)); 
    160         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_M), guiElement)); 
    161         eventList.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
    162         eventList.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
    163         eventList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    164  
    165         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    166         checkList.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
    167         checkList.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
    168         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_L), guiElement)); 
    169         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_L), guiElement)); 
    170         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_M), guiElement)); 
    171         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_M), guiElement)); 
    172         checkList.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
    173         checkList.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
    174         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    175  
    176         assertEquals(checkList.size(), eventList.size()); 
    177  
    178         for (int i = 0; i < checkList.size(); i++) { 
    179             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    180         } 
     25public class KeyInteractionSorterTest { 
     26 
     27    @Test 
     28    public void testSortKeyInteractions_1() { 
     29        List<Event> input = new LinkedList<Event>(); 
     30        List<Event> expected = new LinkedList<Event>(); 
     31 
     32        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     33 
     34        IGUIElement guiElement = mock(IGUIElement.class); 
     35 
     36        // Normal pressing and releasing of A and B 
     37        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     38        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     39        input.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
     40        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     41 
     42        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     43        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     44 
     45        List<Event> output = sorter.sortKeyInteractions(input); 
     46 
     47        assertEquals(expected, output); 
     48    } 
     49 
     50    @Test 
     51    public void testSortKeyInteractions_2() { 
     52        List<Event> input = new LinkedList<Event>(); 
     53        List<Event> expected = new LinkedList<Event>(); 
     54 
     55        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     56 
     57        IGUIElement guiElement = mock(IGUIElement.class); 
     58 
     59        // A is pressed and not released before B is pressed 
     60        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     61        input.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
     62        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     63        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     64 
     65        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     66        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     67 
     68        List<Event> output = sorter.sortKeyInteractions(input); 
     69 
     70        assertEquals(expected, output); 
     71    } 
     72 
     73    @Test 
     74    public void testSortKeyInteractions_3() { 
     75        List<Event> input = new LinkedList<Event>(); 
     76        List<Event> expected = new LinkedList<Event>(); 
     77 
     78        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     79 
     80        IGUIElement guiElement = mock(IGUIElement.class); 
     81 
     82        // SHIFT is pressed and released after all keys are pressed 
     83        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     84        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     85        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     86        input.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
     87        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     88        input.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     89 
     90        expected.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     91        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     92        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     93        expected.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     94 
     95        List<Event> output = sorter.sortKeyInteractions(input); 
     96 
     97        assertEquals(expected, output); 
     98    } 
     99 
     100    @Test 
     101    public void testSortKeyInteractions_4() { 
     102        List<Event> input = new LinkedList<Event>(); 
     103        List<Event> expected = new LinkedList<Event>(); 
     104 
     105        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     106 
     107        IGUIElement guiElement = mock(IGUIElement.class); 
     108 
     109        // SHIFT is released before the last key is released 
     110        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     111        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     112        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     113        input.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
     114        input.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     115        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     116 
     117        expected.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     118        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     119        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     120        expected.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     121 
     122        List<Event> output = sorter.sortKeyInteractions(input); 
     123 
     124        assertEquals(expected, output); 
     125    } 
     126 
     127    @Test 
     128    public void testSortKeyInteractions_5() { 
     129        List<Event> input = new LinkedList<Event>(); 
     130        List<Event> expected = new LinkedList<Event>(); 
     131 
     132        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     133 
     134        IGUIElement guiElement = mock(IGUIElement.class); 
     135 
     136        // SHIFT is released before all other keys are released 
     137        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     138        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     139        input.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
     140        input.add(new Event(new KeyPressed(VirtualKey.LETTER_C), guiElement)); 
     141        input.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     142        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     143        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     144        input.add(new Event(new KeyReleased(VirtualKey.LETTER_C), guiElement)); 
     145 
     146        expected.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     147        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     148        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     149        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_C), guiElement)); 
     150        expected.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     151 
     152        List<Event> output = sorter.sortKeyInteractions(input); 
     153 
     154        assertEquals(expected, output); 
     155    } 
     156 
     157    @Test 
     158    public void testSortKeyInteractions_6() { 
     159        List<Event> input = new LinkedList<Event>(); 
     160        List<Event> expected = new LinkedList<Event>(); 
     161 
     162        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     163 
     164        IGUIElement guiElement = mock(IGUIElement.class); 
     165 
     166        // SHIFT, CTRL and ALT are pressed and released after all keys are pressed 
     167        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     168        input.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
     169        input.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
     170        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     171        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     172        input.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
     173        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     174        input.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
     175        input.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
     176        input.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     177 
     178        expected.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     179        expected.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
     180        expected.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
     181        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     182        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     183        expected.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
     184        expected.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
     185        expected.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     186 
     187        List<Event> output = sorter.sortKeyInteractions(input); 
     188 
     189        assertEquals(expected, output); 
     190    } 
     191 
     192    @Test 
     193    public void testSortKeyInteractions_7() { 
     194        List<Event> input = new LinkedList<Event>(); 
     195        List<Event> expected = new LinkedList<Event>(); 
     196 
     197        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     198 
     199        IGUIElement guiElement = mock(IGUIElement.class); 
    181200 
    182201        // now SHIFT, CTRL and ALT are released before the last key is released 
    183         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    184         eventList.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
    185         eventList.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
    186         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_N), guiElement)); 
    187         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_N), guiElement)); 
    188         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_O), guiElement)); 
    189         eventList.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
    190         eventList.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
    191         eventList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    192         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_O), guiElement)); 
    193  
    194         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    195         checkList.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
    196         checkList.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
    197         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_N), guiElement)); 
    198         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_N), guiElement)); 
    199         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_O), guiElement)); 
    200         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_O), guiElement)); 
    201         checkList.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
    202         checkList.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
    203         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    204  
    205         assertEquals(checkList.size(), eventList.size()); 
    206  
    207         for (int i = 0; i < checkList.size(); i++) { 
    208             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    209         } 
    210  
    211         // now SHIFT, CTRL and ALT are released in another order and before some other keys are 
     202        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     203        input.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
     204        input.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
     205        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     206        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     207        input.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
     208        input.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
     209        input.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
     210        input.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     211        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     212 
     213        expected.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     214        expected.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
     215        expected.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
     216        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     217        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     218        expected.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
     219        expected.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
     220        expected.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     221 
     222        List<Event> output = sorter.sortKeyInteractions(input); 
     223 
     224        assertEquals(expected, output); 
     225    } 
     226 
     227    @Test 
     228    public void testSortKeyInteractions_8() { 
     229        List<Event> input = new LinkedList<Event>(); 
     230        List<Event> expected = new LinkedList<Event>(); 
     231 
     232        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     233 
     234        IGUIElement guiElement = mock(IGUIElement.class); 
     235 
     236        // SHIFT, CTRL and ALT are released in another order and before some other keys are 
    212237        // released 
    213         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    214         eventList.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
    215         eventList.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
    216         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_P), guiElement)); 
    217         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_Q), guiElement)); 
    218         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_R), guiElement)); 
    219         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_Q), guiElement)); 
    220         eventList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    221         eventList.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
    222         eventList.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
    223         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_R), guiElement)); 
    224         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_P), guiElement)); 
    225  
    226         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    227         checkList.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
    228         checkList.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
    229         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_P), guiElement)); 
    230         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_P), guiElement)); 
    231         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_Q), guiElement)); 
    232         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_Q), guiElement)); 
    233         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_R), guiElement)); 
    234         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_R), guiElement)); 
    235         checkList.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
    236         checkList.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
    237         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    238  
    239         assertEquals(checkList.size(), eventList.size()); 
    240  
    241         for (int i = 0; i < checkList.size(); i++) { 
    242             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    243         } 
    244     } 
    245  
    246     /** 
    247    *  
    248    */ 
    249     @Test 
    250     public void testSeveralSubsequentKeyPressedEvents() { 
    251         List<Event> checkList = new ArrayList<Event>(); 
    252         SortedInteractionEventList eventList = new SortedInteractionEventList(); 
    253  
    254         IGUIElement guiElement = new AbstractDefaultGUIElement(null, null) { 
    255  
    256             /**  */ 
    257             private static final long serialVersionUID = 1L; 
    258  
    259             @Override 
    260             public void updateSpecification(IGUIElementSpec furtherSpec) { 
    261                 // ignore 
    262             } 
    263  
    264             @Override 
    265             public String getPlatform() { 
    266                 return "TEST"; 
    267             } 
    268  
    269             @Override 
    270             public String getStringIdentifier() { 
    271                 return "DUMMY"; 
    272             } 
    273  
    274         }; 
    275  
    276         // check first of all a normal pressing and releasing of A and B 
    277         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    278         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    279         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    280         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    281         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    282         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    283         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    284         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    285         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    286         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    287  
    288         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    289         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    290         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    291         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    292         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    293         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    294         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    295         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    296         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    297         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    298         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    299         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    300         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    301         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    302         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    303         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    304         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    305         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    306  
    307         assertEquals(checkList.size(), eventList.size()); 
    308  
    309         for (int i = 0; i < checkList.size(); i++) { 
    310             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    311         } 
    312  
    313         // check first of all a normal pressing and releasing of A and B 
    314         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    315         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    316         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    317         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    318         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    319         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    320         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    321         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    322         eventList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    323         eventList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    324         eventList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    325         eventList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    326  
    327         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    328         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    329         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    330         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    331         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    332         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    333         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    334         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    335         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    336         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    337         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    338         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    339         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    340         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    341         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    342         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    343         checkList.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
    344         checkList.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
    345         checkList.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
    346         checkList.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
    347  
    348         assertEquals(checkList.size(), eventList.size()); 
    349  
    350         for (int i = 0; i < checkList.size(); i++) { 
    351             assertEquals(checkList.get(i).getType(), eventList.get(i).getType()); 
    352         } 
    353     } 
    354  
     238        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     239        input.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
     240        input.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
     241        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     242        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     243        input.add(new Event(new KeyPressed(VirtualKey.LETTER_B), guiElement)); 
     244        input.add(new Event(new KeyPressed(VirtualKey.LETTER_C), guiElement)); 
     245        input.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     246        input.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
     247        input.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
     248        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     249        input.add(new Event(new KeyReleased(VirtualKey.LETTER_C), guiElement)); 
     250 
     251        expected.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     252        expected.add(new Event(new KeyPressed(VirtualKey.CONTROL), guiElement)); 
     253        expected.add(new Event(new KeyPressed(VirtualKey.ALT), guiElement)); 
     254        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     255        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     256        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_C), guiElement)); 
     257        expected.add(new Event(new KeyReleased(VirtualKey.ALT), guiElement)); 
     258        expected.add(new Event(new KeyReleased(VirtualKey.CONTROL), guiElement)); 
     259        expected.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     260 
     261        List<Event> output = sorter.sortKeyInteractions(input); 
     262 
     263        assertEquals(expected, output); 
     264    } 
     265 
     266    @Test 
     267    public void testSortKeyInteractions_9() { 
     268        List<Event> input = new LinkedList<Event>(); 
     269        List<Event> expected = new LinkedList<Event>(); 
     270 
     271        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     272 
     273        IGUIElement guiElement = mock(IGUIElement.class); 
     274 
     275        // holding of A 
     276        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     277        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     278        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     279        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     280        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     281        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     282        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     283        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     284        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     285        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     286 
     287        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     288        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     289        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     290        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     291        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     292        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     293        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     294        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     295        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     296 
     297        List<Event> output = sorter.sortKeyInteractions(input); 
     298 
     299        assertEquals(expected, output); 
     300    } 
     301 
     302    @Test 
     303    public void testSortKeyInteractions_10() { 
     304        List<Event> input = new LinkedList<Event>(); 
     305        List<Event> expected = new LinkedList<Event>(); 
     306 
     307        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     308 
     309        IGUIElement guiElement = mock(IGUIElement.class); 
     310 
     311        // holding of shift and meanwhile pressing of A 
     312        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     313        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     314        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     315        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     316        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     317        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     318        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     319        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     320        input.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     321        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     322        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     323        input.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     324 
     325        expected.add(new Event(new KeyPressed(VirtualKey.SHIFT), guiElement)); 
     326        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     327        expected.add(new Event(new KeyReleased(VirtualKey.SHIFT), guiElement)); 
     328 
     329        List<Event> output = sorter.sortKeyInteractions(input); 
     330 
     331        assertEquals(expected, output); 
     332    } 
     333 
     334    @Test 
     335    public void testSortKeyInteractions_11() { 
     336        List<Event> input = new LinkedList<Event>(); 
     337        List<Event> expected = new LinkedList<Event>(); 
     338 
     339        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     340 
     341        IGUIElement guiElement = mock(IGUIElement.class); 
     342 
     343        // Check if keyboard focus change is moved in front of a sequence in case it is in between a 
     344        // pressed 
     345        // released pair 
     346        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     347        input.add(new Event(new KeyboardFocusChange(), guiElement)); 
     348        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     349 
     350        expected.add(new Event(new KeyboardFocusChange(), guiElement)); 
     351        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     352 
     353        List<Event> output = sorter.sortKeyInteractions(input); 
     354 
     355        assertEquals(expected, output); 
     356    } 
     357 
     358    @Test 
     359    public void testSortKeyInteractions_12() { 
     360        List<Event> input = new LinkedList<Event>(); 
     361        List<Event> expected = new LinkedList<Event>(); 
     362 
     363        KeyInteractionSorter sorter = new KeyInteractionSorter(); 
     364 
     365        IGUIElement guiElement = mock(IGUIElement.class); 
     366 
     367        // Check if mouse events stay where they are 
     368        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     369        input.add(new Event(new MouseButtonDown(Button.LEFT), guiElement)); 
     370        input.add(new Event(new MouseButtonUp(Button.LEFT), guiElement)); 
     371        input.add(new Event(new MouseClick(Button.LEFT), guiElement)); 
     372        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     373 
     374        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     375        expected.add(new Event(new MouseButtonDown(Button.LEFT), guiElement)); 
     376        expected.add(new Event(new MouseButtonUp(Button.LEFT), guiElement)); 
     377        expected.add(new Event(new MouseClick(Button.LEFT), guiElement)); 
     378 
     379        List<Event> output = sorter.sortKeyInteractions(input); 
     380 
     381        assertEquals(expected, output); 
     382    } 
     383 
     384    @Test 
     385    public void testSortKeyInteractions_13() { 
     386        List<Event> input = new LinkedList<Event>(); 
     387        List<Event> expected = new LinkedList<Event>(); 
     388 
     389        KeyInteractionSorter sorter = new KeyInteractionSorter(CleanupMode.REMOVAL); 
     390 
     391        IGUIElement guiElement = mock(IGUIElement.class); 
     392 
     393        // Check if mouse events stay where they are 
     394        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     395        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     396        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     397 
     398        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     399 
     400        List<Event> output = sorter.sortKeyInteractions(input); 
     401 
     402        assertEquals(expected, output); 
     403    } 
     404 
     405    @Test 
     406    public void testSortKeyInteractions_14() { 
     407        List<Event> input = new LinkedList<Event>(); 
     408        List<Event> expected = new LinkedList<Event>(); 
     409 
     410        KeyInteractionSorter sorter = new KeyInteractionSorter(CleanupMode.ADDITION); 
     411 
     412        IGUIElement guiElement = mock(IGUIElement.class); 
     413 
     414        // Check if mouse events stay where they are 
     415        input.add(new Event(new KeyPressed(VirtualKey.LETTER_A), guiElement)); 
     416        input.add(new Event(new KeyReleased(VirtualKey.LETTER_A), guiElement)); 
     417        input.add(new Event(new KeyReleased(VirtualKey.LETTER_B), guiElement)); 
     418 
     419        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_A), guiElement)); 
     420        expected.add(new Event(new KeyTyped(VirtualKey.LETTER_B), guiElement)); 
     421 
     422        List<Event> output = sorter.sortKeyInteractions(input); 
     423 
     424        assertEquals(expected, output); 
     425    } 
     426 
     427    @BeforeClass 
     428    public static void setUpBeforeClass() { 
     429        Console.reset(); 
     430        Console.getInstance().registerTraceListener(new TextConsole(Level.INFO)); 
     431    } 
    355432} 
Note: See TracChangeset for help on using the changeset viewer.