Ignore:
Timestamp:
08/17/12 08:52:45 (12 years ago)
Author:
pharms
Message:
  • adapted to new coding style in quest
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-misc-test/src/test/java/de/ugoe/cs/tasktree/keyboardmaps/KeyboardMapTest.java

    r456 r558  
    1 //------------------------------------------------------------------------------------------------- 
    21// Module    : $RCSfile: KeyboardMapTest.java,v $ 
    32// Version   : $Revision: 0.0 $  $Author: patrick $  $Date: 11.07.2012 $ 
     
    54// Creation  : 2012 by patrick 
    65// Copyright : Patrick Harms, 2012 
    7 //------------------------------------------------------------------------------------------------- 
     6 
     7 
    88package de.ugoe.cs.tasktree.keyboardmaps; 
    99 
     
    1515import org.junit.Test; 
    1616 
    17 //------------------------------------------------------------------------------------------------- 
    1817/** 
    1918 * TODO comment 
     
    2221 * @author 2012, last modified by $Author: patrick$ 
    2322 */ 
    24 //------------------------------------------------------------------------------------------------- 
    25 public class KeyboardMapTest 
    26 { 
    27  
    28   //----------------------------------------------------------------------------------------------- 
    29   /** 
     23public class KeyboardMapTest { 
     24 
     25    /** 
     26     * 
     27     */ 
     28    @Before 
     29    public void setUp() { 
     30        // Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 
     31    } 
     32 
     33    /** 
     34     * TODO: comment 
     35     *  
     36     */ 
     37    @Test 
     38    public void testInitialization() { 
     39        KeyboardMap map = KeyboardMapFactory.createKeyboardMap(Locale.ENGLISH); 
     40        assertNotNull(map); 
     41 
     42        map = KeyboardMapFactory.createKeyboardMap(Locale.FRENCH); 
     43        assertNotNull(map); 
     44 
     45        map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 
     46        assertNotNull(map); 
     47 
     48        map = KeyboardMapFactory.createKeyboardMap(Locale.ITALIAN); 
     49        assertNotNull(map); 
     50 
     51        map = KeyboardMapFactory.createKeyboardMap(Locale.JAPANESE); 
     52        assertNotNull(map); 
     53 
     54        map = KeyboardMapFactory.createKeyboardMap(Locale.KOREAN); 
     55        assertNotNull(map); 
     56 
     57        try { 
     58            map = KeyboardMapFactory.createKeyboardMap(Locale.CHINESE); 
     59            fail("expected exception did not occur"); 
     60        } 
     61        catch (IllegalArgumentException e) { 
     62            // was expected and is ignored 
     63        } 
     64 
     65        try { 
     66            map = KeyboardMapFactory.createKeyboardMap(Locale.SIMPLIFIED_CHINESE); 
     67            fail("expected exception did not occur"); 
     68        } 
     69        catch (IllegalArgumentException e) { 
     70            // was expected and is ignored 
     71        } 
     72 
     73        try { 
     74            map = KeyboardMapFactory.createKeyboardMap(Locale.TRADITIONAL_CHINESE); 
     75            fail("expected exception did not occur"); 
     76        } 
     77        catch (IllegalArgumentException e) { 
     78            // was expected and is ignored 
     79        } 
     80 
     81        map = KeyboardMapFactory.createKeyboardMap(Locale.FRANCE); 
     82        assertNotNull(map); 
     83 
     84        map = KeyboardMapFactory.createKeyboardMap(Locale.GERMANY); 
     85        assertNotNull(map); 
     86 
     87        map = KeyboardMapFactory.createKeyboardMap(Locale.ITALY); 
     88        assertNotNull(map); 
     89 
     90        map = KeyboardMapFactory.createKeyboardMap(Locale.JAPAN); 
     91        assertNotNull(map); 
     92 
     93        map = KeyboardMapFactory.createKeyboardMap(Locale.KOREA); 
     94        assertNotNull(map); 
     95 
     96        try { 
     97            map = KeyboardMapFactory.createKeyboardMap(Locale.CHINA); 
     98            fail("expected exception did not occur"); 
     99        } 
     100        catch (IllegalArgumentException e) { 
     101            // was expected and is ignored 
     102        } 
     103 
     104        try { 
     105            map = KeyboardMapFactory.createKeyboardMap(Locale.PRC); 
     106            fail("expected exception did not occur"); 
     107        } 
     108        catch (IllegalArgumentException e) { 
     109            // was expected and is ignored 
     110        } 
     111 
     112        try { 
     113            map = KeyboardMapFactory.createKeyboardMap(Locale.TAIWAN); 
     114            fail("expected exception did not occur"); 
     115        } 
     116        catch (IllegalArgumentException e) { 
     117            // was expected and is ignored 
     118        } 
     119 
     120        map = KeyboardMapFactory.createKeyboardMap(Locale.UK); 
     121        assertNotNull(map); 
     122 
     123        map = KeyboardMapFactory.createKeyboardMap(Locale.US); 
     124        assertNotNull(map); 
     125 
     126        map = KeyboardMapFactory.createKeyboardMap(Locale.CANADA); 
     127        assertNotNull(map); 
     128 
     129        map = KeyboardMapFactory.createKeyboardMap(Locale.CANADA_FRENCH); 
     130        assertNotNull(map); 
     131 
     132        map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 
     133        assertNotNull(map); 
     134 
     135    } 
     136 
     137    /** 
     138     * TODO: comment 
     139     *  
     140     */ 
     141    @Test 
     142    public void testGermanKeyboardMap() { 
     143        KeyboardMap map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 
     144        assertNotNull(map); 
     145 
     146        assertCombinations(map, VirtualKey.DIGIT_1, '1', '!', '¹', '¡', true); 
     147        assertCombinations(map, VirtualKey.EXCLAMATION_MARK, '1', '!', '¹', '¡', true); 
     148        assertCombinations(map, VirtualKey.INVERTED_EXCLAMATION_MARK, '1', '!', '¹', '¡', true); 
     149 
     150        assertCombinations(map, VirtualKey.DIGIT_2, '2', '"', '²', '⅛', true); 
     151        assertCombinations(map, VirtualKey.QUOTEDBL, '2', '"', '²', '⅛', true); 
     152 
     153        assertCombinations(map, VirtualKey.DIGIT_3, '3', '§', '³', '£', true); 
     154 
     155        assertCombinations(map, VirtualKey.DIGIT_4, '4', '$', '¼', '¤', true); 
     156        assertCombinations(map, VirtualKey.DOLLAR, '4', '$', '¼', '¤', true); 
     157 
     158        assertCombinations(map, VirtualKey.DIGIT_5, '5', '%', '½', '⅜', true); 
     159 
     160        assertCombinations(map, VirtualKey.DIGIT_6, '6', '&', '¾', '⅝', true); 
     161        assertCombinations(map, VirtualKey.AMPERSAND, '6', '&', '¾', '⅝', true); 
     162 
     163        assertCombinations(map, VirtualKey.DIGIT_7, '7', '/', '{', '⅞', true); 
     164        assertCombinations(map, VirtualKey.SLASH, '7', '/', '{', '⅞', true); 
     165        assertCombinations(map, VirtualKey.BRACELEFT, '7', '/', '{', '⅞', true); 
     166 
     167        assertCombinations(map, VirtualKey.DIGIT_8, '8', '(', '[', '™', true); 
     168        assertCombinations(map, VirtualKey.LEFT_PARENTHESIS, '8', '(', '[', '™', true); 
     169        assertCombinations(map, VirtualKey.OPEN_BRACKET, '8', '(', '[', '™', true); 
     170 
     171        assertCombinations(map, VirtualKey.DIGIT_9, '9', ')', ']', '±', true); 
     172        assertCombinations(map, VirtualKey.RIGHT_PARENTHESIS, '9', ')', ']', '±', true); 
     173        assertCombinations(map, VirtualKey.CLOSE_BRACKET, '9', ')', ']', '±', true); 
     174 
     175        assertCombinations(map, VirtualKey.DIGIT_0, '0', '=', '}', 0, true); 
     176        assertCombinations(map, VirtualKey.EQUALS, '0', '=', '}', 0, true); 
     177        assertCombinations(map, VirtualKey.BRACERIGHT, '0', '=', '}', 0, true); 
     178 
     179        assertCombinations(map, VirtualKey.BACK_SLASH, 'ß', '?', '\\', '¿', true); 
     180 
     181        assertCombinations(map, VirtualKey.LETTER_Q, 'q', 'Q', '@', 'Ω', true); 
     182        assertCombinations(map, VirtualKey.AT, 'q', 'Q', '@', 'Ω', true); 
     183 
     184        assertCombinations(map, VirtualKey.LETTER_W, 'w', 'W', 0, 0, true); 
     185 
     186        assertCombinations(map, VirtualKey.LETTER_E, 'e', 'E', '€', 0, true); 
     187        assertCombinations(map, VirtualKey.EURO_SIGN, 'e', 'E', '€', 0, true); 
     188 
     189        assertCombinations(map, VirtualKey.LETTER_R, 'r', 'R', 0, '®', true); 
     190 
     191        assertCombinations(map, VirtualKey.LETTER_T, 't', 'T', 'ŧ', 'Ŧ', true); 
     192 
     193        assertCombinations(map, VirtualKey.LETTER_Z, 'z', 'Z', '←', '¥', true); 
     194 
     195        assertCombinations(map, VirtualKey.LETTER_U, 'u', 'U', '↓', '↑', true); 
     196 
     197        assertCombinations(map, VirtualKey.LETTER_I, 'i', 'I', '→', 'ı', true); 
     198 
     199        assertCombinations(map, VirtualKey.LETTER_O, 'o', 'O', 'ø', 'Ø', true); 
     200 
     201        assertCombinations(map, VirtualKey.LETTER_P, 'p', 'P', 'þ', 'Þ', true); 
     202 
     203        assertCombinations(map, VirtualKey.LETTER_A, 'a', 'A', 'æ', 'Æ', true); 
     204 
     205        assertCombinations(map, VirtualKey.LETTER_S, 's', 'S', 0, 0, true); 
     206 
     207        assertCombinations(map, VirtualKey.LETTER_D, 'd', 'D', 'ð', 'Ð', true); 
     208 
     209        assertCombinations(map, VirtualKey.LETTER_F, 'f', 'F', 'đ', 'ª', true); 
     210 
     211        assertCombinations(map, VirtualKey.LETTER_G, 'g', 'G', 'ŋ', 'Ŋ', true); 
     212 
     213        assertCombinations(map, VirtualKey.LETTER_H, 'h', 'H', 'ħ', 'Ħ', true); 
     214 
     215        assertCombinations(map, VirtualKey.LETTER_J, 'j', 'J', 0, 0, true); 
     216 
     217        assertCombinations(map, VirtualKey.LETTER_K, 'k', 'K', 'ĸ', 0, true); 
     218 
     219        assertCombinations(map, VirtualKey.LETTER_L, 'l', 'L', 0, 0, true); 
     220 
     221        assertCombinations(map, VirtualKey.LETTER_Y, 'y', 'Y', '»', 0, true); 
     222 
     223        assertCombinations(map, VirtualKey.LETTER_X, 'x', 'X', '«', 0, true); 
     224 
     225        assertCombinations(map, VirtualKey.LETTER_C, 'c', 'C', '¢', '©', true); 
     226 
     227        assertCombinations(map, VirtualKey.LETTER_V, 'v', 'V', '„', 0, true); 
     228 
     229        assertCombinations(map, VirtualKey.LETTER_B, 'b', 'B', '“', 0, true); 
     230 
     231        assertCombinations(map, VirtualKey.LETTER_N, 'n', 'N', 0, 0, true); 
     232 
     233        assertCombinations(map, VirtualKey.LETTER_M, 'm', 'M', 'µ', 'º', true); 
     234 
     235        assertCombinations(map, VirtualKey.NUMPAD_0, '0', 0, 0, 0, false); 
     236 
     237        assertCombinations(map, VirtualKey.NUMPAD_1, '1', 0, 0, 0, false); 
     238 
     239        assertCombinations(map, VirtualKey.NUMPAD_2, '2', 0, 0, 0, false); 
     240 
     241        assertCombinations(map, VirtualKey.NUMPAD_3, '3', 0, 0, 0, false); 
     242 
     243        assertCombinations(map, VirtualKey.NUMPAD_4, '4', 0, 0, 0, false); 
     244 
     245        assertCombinations(map, VirtualKey.NUMPAD_5, '5', 0, 0, 0, false); 
     246 
     247        assertCombinations(map, VirtualKey.NUMPAD_6, '6', 0, 0, 0, false); 
     248 
     249        assertCombinations(map, VirtualKey.NUMPAD_7, '7', 0, 0, 0, false); 
     250 
     251        assertCombinations(map, VirtualKey.NUMPAD_8, '8', 0, 0, 0, false); 
     252 
     253        assertCombinations(map, VirtualKey.NUMPAD_9, '9', 0, 0, 0, false); 
     254 
     255        assertCombinations(map, VirtualKey.SEPARATOR, ',', 0, 0, 0, false); 
     256        assertCombinations(map, VirtualKey.DECIMAL, ',', 0, 0, 0, false); 
     257 
     258        assertCombinations(map, VirtualKey.CIRCUMFLEX, '^', '°', '¬', 0, true); 
     259 
     260        assertCombinations(map, VirtualKey.TAB, '\t', 0, '\t', 0, true); 
     261 
     262        assertCombinations(map, VirtualKey.SPACE, ' ', ' ', ' ', ' ', true); 
     263 
     264        assertCombinations(map, VirtualKey.COMMA, ',', ';', '·', '×', true); 
     265        assertCombinations(map, VirtualKey.SEMICOLON, ',', ';', '·', '×', true); 
     266        assertCombinations(map, VirtualKey.MULTIPLY, ',', ';', '·', '×', true); 
     267 
     268        assertCombinations(map, VirtualKey.MINUS, '-', '_', 0, 0, true); 
     269        assertCombinations(map, VirtualKey.UNDERSCORE, '-', '_', 0, 0, true); 
     270 
     271        assertCombinations(map, VirtualKey.PERIOD, '.', ':', '…', '÷', true); 
     272        assertCombinations(map, VirtualKey.COLON, '.', ':', '…', '÷', true); 
     273        assertCombinations(map, VirtualKey.DIVIDE, '.', ':', '…', '÷', true); 
     274 
     275        assertCombinations(map, VirtualKey.PLUS, '+', '*', '~', 0, true); 
     276        assertCombinations(map, VirtualKey.ASTERISK, '+', '*', '~', 0, true); 
     277        assertCombinations(map, VirtualKey.DEAD_TILDE, '+', '*', '~', 0, true); 
     278 
     279        assertCombinations(map, VirtualKey.LESS, '<', '>', '|', '¦', true); 
     280        assertCombinations(map, VirtualKey.GREATER, '<', '>', '|', '¦', true); 
     281 
     282        assertCombinations(map, VirtualKey.NUMBER_SIGN, '#', '\'', 0, 0, true); 
     283 
     284        /* 
     285         * DEAD_GRAVE(KeyEvent.VK_DEAD_GRAVE), DEAD_ACUTE(KeyEvent.VK_DEAD_ACUTE), 
     286         * DEAD_CIRCUMFLEX(KeyEvent.VK_DEAD_CIRCUMFLEX), DEAD_TILDE(KeyEvent.VK_DEAD_TILDE), 
     287         * DEAD_MACRON(KeyEvent.VK_DEAD_MACRON), DEAD_BREVE(KeyEvent.VK_DEAD_BREVE), 
     288         * DEAD_ABOVEDOT(KeyEvent.VK_DEAD_ABOVEDOT), DEAD_DIAERESIS(KeyEvent.VK_DEAD_DIAERESIS), 
     289         * DEAD_ABOVERING(KeyEvent.VK_DEAD_ABOVERING), 
     290         * DEAD_DOUBLEACUTE(KeyEvent.VK_DEAD_DOUBLEACUTE), DEAD_CARON(KeyEvent.VK_DEAD_CARON), 
     291         * DEAD_CEDILLA(KeyEvent.VK_DEAD_CEDILLA), DEAD_OGONEK(KeyEvent.VK_DEAD_OGONEK), 
     292         * DEAD_IOTA(KeyEvent.VK_DEAD_IOTA), DEAD_VOICED_SOUND(KeyEvent.VK_DEAD_VOICED_SOUND), 
     293         * DEAD_SEMIVOICED_SOUND(KeyEvent.VK_DEAD_SEMIVOICED_SOUND), 
     294         */ 
     295    } 
     296 
     297    /** 
    30298   * 
    31299   */ 
    32   //----------------------------------------------------------------------------------------------- 
    33   @Before 
    34   public void setUp() 
    35   { 
    36     //Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 
    37   } 
    38  
    39   //----------------------------------------------------------------------------------------------- 
    40   /** 
    41    * TODO: comment 
    42    * 
    43    */ 
    44   //----------------------------------------------------------------------------------------------- 
    45   @Test 
    46   public void testInitialization() 
    47   { 
    48     KeyboardMap map = KeyboardMapFactory.createKeyboardMap(Locale.ENGLISH); 
    49     assertNotNull(map); 
    50      
    51     map = KeyboardMapFactory.createKeyboardMap(Locale.FRENCH); 
    52     assertNotNull(map); 
    53      
    54     map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 
    55     assertNotNull(map); 
    56      
    57     map = KeyboardMapFactory.createKeyboardMap(Locale.ITALIAN); 
    58     assertNotNull(map); 
    59      
    60     map = KeyboardMapFactory.createKeyboardMap(Locale.JAPANESE); 
    61     assertNotNull(map); 
    62      
    63     map = KeyboardMapFactory.createKeyboardMap(Locale.KOREAN); 
    64     assertNotNull(map); 
    65      
    66     try 
     300    private void assertCombinations(KeyboardMap map, 
     301                                    VirtualKey  key, 
     302                                    int         normal, 
     303                                    int         withShift, 
     304                                    int         withAltGr, 
     305                                    int         withShiftAndAltGr, 
     306                                    boolean     numLockIndependent) 
    67307    { 
    68       map = KeyboardMapFactory.createKeyboardMap(Locale.CHINESE); 
    69       fail("expected exception did not occur"); 
    70     } 
    71     catch (IllegalArgumentException e) 
     308        if (numLockIndependent) { 
     309            if (normal != 0) { 
     310                assertCombination("normal", normal, map, key, false, false, false); 
     311            } 
     312 
     313            if (withShift != 0) { 
     314                assertCombination("shift", withShift, map, key, false, true, false); 
     315            } 
     316 
     317            if (withAltGr != 0) { 
     318                assertCombination("altgr", withAltGr, map, key, false, false, true); 
     319            } 
     320 
     321            if (withShiftAndAltGr != 0) { 
     322                assertCombination("shift and altgr", withShiftAndAltGr, map, key, false, true, true); 
     323            } 
     324        } 
     325        else { 
     326            assertInvalidCombination("normal", normal, map, key, false, false, false); 
     327            assertInvalidCombination("shift", withShift, map, key, false, true, false); 
     328            assertInvalidCombination("altgr", withAltGr, map, key, false, false, true); 
     329            assertInvalidCombination 
     330              ("shift and altgr", withShiftAndAltGr, map, key, false, true, true); 
     331        } 
     332 
     333        if (normal != 0) { 
     334            assertCombination("numlock", normal, map, key, true, false, false); 
     335        } 
     336 
     337        if (withShift != 0) { 
     338            assertCombination("numlock and shift", withShift, map, key, true, true, false); 
     339        } 
     340 
     341        if (withAltGr != 0) { 
     342            assertCombination("numlock and altgr", withAltGr, map, key, true, false, true); 
     343        } 
     344 
     345        if (withShiftAndAltGr != 0) { 
     346            assertCombination 
     347              ("numlock, shift and altgr", withShiftAndAltGr, map, key, true, true, true); 
     348        } 
     349    } 
     350 
     351    /** 
     352     * TODO: comment 
     353     *  
     354     * @param string 
     355     * @param normal 
     356     * @param characterFor 
     357     */ 
     358    private void assertCombination(String      type, 
     359                                   int         expectedChar, 
     360                                   KeyboardMap map, 
     361                                   VirtualKey  key, 
     362                                   boolean     numlock, 
     363                                   boolean     shift, 
     364                                   boolean     altgr) 
    72365    { 
    73       // was expected and is ignored 
    74     } 
    75      
    76     try 
     366        String message = "checked for " + type + ": expected '" + ((char) expectedChar) + "'"; 
     367 
     368        char retrievedChar; 
     369        try { 
     370            retrievedChar = map.getCharacterFor(key, numlock, shift, altgr, false); 
     371        } 
     372        catch (IllegalArgumentException e) { 
     373            fail("no character found. " + message); 
     374            return; 
     375        } 
     376 
     377        message += " but got '" + retrievedChar + "'"; 
     378 
     379        assertEquals(message, expectedChar, retrievedChar); 
     380    } 
     381 
     382    /** 
     383     * TODO: comment 
     384     *  
     385     * @param string 
     386     * @param normal 
     387     * @param characterFor 
     388     */ 
     389    private void assertInvalidCombination(String      type, 
     390                                          int         expectedChar, 
     391                                          KeyboardMap map, 
     392                                          VirtualKey  key, 
     393                                          boolean     numlock, 
     394                                          boolean     shift, 
     395                                          boolean     altgr) 
    77396    { 
    78       map = KeyboardMapFactory.createKeyboardMap(Locale.SIMPLIFIED_CHINESE); 
    79       fail("expected exception did not occur"); 
    80     } 
    81     catch (IllegalArgumentException e) 
    82     { 
    83       // was expected and is ignored 
    84     } 
    85      
    86     try 
    87     { 
    88       map = KeyboardMapFactory.createKeyboardMap(Locale.TRADITIONAL_CHINESE); 
    89       fail("expected exception did not occur"); 
    90     } 
    91     catch (IllegalArgumentException e) 
    92     { 
    93       // was expected and is ignored 
    94     } 
    95      
    96     map = KeyboardMapFactory.createKeyboardMap(Locale.FRANCE); 
    97     assertNotNull(map); 
    98      
    99     map = KeyboardMapFactory.createKeyboardMap(Locale.GERMANY); 
    100     assertNotNull(map); 
    101      
    102     map = KeyboardMapFactory.createKeyboardMap(Locale.ITALY); 
    103     assertNotNull(map); 
    104      
    105     map = KeyboardMapFactory.createKeyboardMap(Locale.JAPAN); 
    106     assertNotNull(map); 
    107      
    108     map = KeyboardMapFactory.createKeyboardMap(Locale.KOREA); 
    109     assertNotNull(map); 
    110      
    111     try 
    112     { 
    113       map = KeyboardMapFactory.createKeyboardMap(Locale.CHINA); 
    114       fail("expected exception did not occur"); 
    115     } 
    116     catch (IllegalArgumentException e) 
    117     { 
    118       // was expected and is ignored 
    119     } 
    120      
    121     try 
    122     { 
    123       map = KeyboardMapFactory.createKeyboardMap(Locale.PRC); 
    124       fail("expected exception did not occur"); 
    125     } 
    126     catch (IllegalArgumentException e) 
    127     { 
    128       // was expected and is ignored 
    129     } 
    130      
    131     try 
    132     { 
    133       map = KeyboardMapFactory.createKeyboardMap(Locale.TAIWAN); 
    134       fail("expected exception did not occur"); 
    135     } 
    136     catch (IllegalArgumentException e) 
    137     { 
    138       // was expected and is ignored 
    139     } 
    140      
    141     map = KeyboardMapFactory.createKeyboardMap(Locale.UK); 
    142     assertNotNull(map); 
    143      
    144     map = KeyboardMapFactory.createKeyboardMap(Locale.US); 
    145     assertNotNull(map); 
    146      
    147     map = KeyboardMapFactory.createKeyboardMap(Locale.CANADA); 
    148     assertNotNull(map); 
    149      
    150     map = KeyboardMapFactory.createKeyboardMap(Locale.CANADA_FRENCH); 
    151     assertNotNull(map); 
    152  
    153     map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 
    154     assertNotNull(map); 
    155      
    156   } 
    157  
    158   //----------------------------------------------------------------------------------------------- 
    159   /** 
    160    * TODO: comment 
    161    * 
    162    */ 
    163   //----------------------------------------------------------------------------------------------- 
    164   @Test 
    165   public void testGermanKeyboardMap() 
    166   { 
    167     KeyboardMap map = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 
    168     assertNotNull(map); 
    169      
    170     assertCombinations(map, VirtualKey.DIGIT_1, '1', '!', '¹', '¡', true); 
    171     assertCombinations(map, VirtualKey.EXCLAMATION_MARK, '1', '!', '¹', '¡', true); 
    172     assertCombinations(map, VirtualKey.INVERTED_EXCLAMATION_MARK, '1', '!', '¹', '¡', true); 
    173      
    174     assertCombinations(map, VirtualKey.DIGIT_2, '2', '"', '²', '⅛', true); 
    175     assertCombinations(map, VirtualKey.QUOTEDBL, '2', '"', '²', '⅛', true); 
    176  
    177     assertCombinations(map, VirtualKey.DIGIT_3, '3', '§', '³', '£', true); 
    178  
    179     assertCombinations(map, VirtualKey.DIGIT_4, '4', '$', '¼', '¤', true); 
    180     assertCombinations(map, VirtualKey.DOLLAR, '4', '$', '¼', '¤', true); 
    181  
    182     assertCombinations(map, VirtualKey.DIGIT_5, '5', '%', '½', '⅜', true); 
    183  
    184     assertCombinations(map, VirtualKey.DIGIT_6, '6', '&', '¾', '⅝', true); 
    185     assertCombinations(map, VirtualKey.AMPERSAND, '6', '&', '¾', '⅝', true); 
    186  
    187     assertCombinations(map, VirtualKey.DIGIT_7, '7', '/', '{', '⅞', true); 
    188     assertCombinations(map, VirtualKey.SLASH, '7', '/', '{', '⅞', true); 
    189     assertCombinations(map, VirtualKey.BRACELEFT, '7', '/', '{', '⅞', true); 
    190  
    191     assertCombinations(map, VirtualKey.DIGIT_8, '8', '(', '[', '™', true); 
    192     assertCombinations(map, VirtualKey.LEFT_PARENTHESIS, '8', '(', '[', '™', true); 
    193     assertCombinations(map, VirtualKey.OPEN_BRACKET, '8', '(', '[', '™', true); 
    194  
    195     assertCombinations(map, VirtualKey.DIGIT_9, '9', ')', ']', '±', true); 
    196     assertCombinations(map, VirtualKey.RIGHT_PARENTHESIS, '9', ')', ']', '±', true); 
    197     assertCombinations(map, VirtualKey.CLOSE_BRACKET, '9', ')', ']', '±', true); 
    198  
    199     assertCombinations(map, VirtualKey.DIGIT_0, '0', '=', '}', 0, true); 
    200     assertCombinations(map, VirtualKey.EQUALS, '0', '=', '}', 0, true); 
    201     assertCombinations(map, VirtualKey.BRACERIGHT, '0', '=', '}', 0, true); 
    202  
    203     assertCombinations(map, VirtualKey.BACK_SLASH, 'ß', '?', '\\', '¿', true); 
    204  
    205     assertCombinations(map, VirtualKey.LETTER_Q, 'q', 'Q', '@', 'Ω', true); 
    206     assertCombinations(map, VirtualKey.AT, 'q', 'Q', '@', 'Ω', true); 
    207  
    208     assertCombinations(map, VirtualKey.LETTER_W, 'w', 'W', 0, 0, true); 
    209  
    210     assertCombinations(map, VirtualKey.LETTER_E, 'e', 'E', '€', 0, true); 
    211     assertCombinations(map, VirtualKey.EURO_SIGN, 'e', 'E', '€', 0, true); 
    212  
    213     assertCombinations(map, VirtualKey.LETTER_R, 'r', 'R', 0, '®', true); 
    214  
    215     assertCombinations(map, VirtualKey.LETTER_T, 't', 'T', 'ŧ', 'Ŧ', true); 
    216  
    217     assertCombinations(map, VirtualKey.LETTER_Z, 'z', 'Z', '←', '¥', true); 
    218  
    219     assertCombinations(map, VirtualKey.LETTER_U, 'u', 'U', '↓', '↑', true); 
    220  
    221     assertCombinations(map, VirtualKey.LETTER_I, 'i', 'I', '→', 'ı', true); 
    222  
    223     assertCombinations(map, VirtualKey.LETTER_O, 'o', 'O', 'ø', 'Ø', true); 
    224  
    225     assertCombinations(map, VirtualKey.LETTER_P, 'p', 'P', 'þ', 'Þ', true); 
    226  
    227     assertCombinations(map, VirtualKey.LETTER_A, 'a', 'A', 'æ', 'Æ', true); 
    228  
    229     assertCombinations(map, VirtualKey.LETTER_S, 's', 'S', 0, 0, true); 
    230  
    231     assertCombinations(map, VirtualKey.LETTER_D, 'd', 'D', 'ð', 'Ð', true); 
    232  
    233     assertCombinations(map, VirtualKey.LETTER_F, 'f', 'F', 'đ', 'ª', true); 
    234  
    235     assertCombinations(map, VirtualKey.LETTER_G, 'g', 'G', 'ŋ', 'Ŋ', true); 
    236  
    237     assertCombinations(map, VirtualKey.LETTER_H, 'h', 'H', 'ħ', 'Ħ', true); 
    238  
    239     assertCombinations(map, VirtualKey.LETTER_J, 'j', 'J', 0, 0, true); 
    240  
    241     assertCombinations(map, VirtualKey.LETTER_K, 'k', 'K', 'ĸ', 0, true); 
    242  
    243     assertCombinations(map, VirtualKey.LETTER_L, 'l', 'L', 0, 0, true); 
    244  
    245     assertCombinations(map, VirtualKey.LETTER_Y, 'y', 'Y', '»', 0, true); 
    246  
    247     assertCombinations(map, VirtualKey.LETTER_X, 'x', 'X', '«', 0, true); 
    248  
    249     assertCombinations(map, VirtualKey.LETTER_C, 'c', 'C', '¢', '©', true); 
    250  
    251     assertCombinations(map, VirtualKey.LETTER_V, 'v', 'V', '„', 0, true); 
    252  
    253     assertCombinations(map, VirtualKey.LETTER_B, 'b', 'B', '“', 0, true); 
    254  
    255     assertCombinations(map, VirtualKey.LETTER_N, 'n', 'N', 0, 0, true); 
    256  
    257     assertCombinations(map, VirtualKey.LETTER_M, 'm', 'M', 'µ', 'º', true); 
    258  
    259     assertCombinations(map, VirtualKey.NUMPAD_0, '0', 0, 0, 0, false); 
    260  
    261     assertCombinations(map, VirtualKey.NUMPAD_1, '1', 0, 0, 0, false); 
    262  
    263     assertCombinations(map, VirtualKey.NUMPAD_2, '2', 0, 0, 0, false); 
    264  
    265     assertCombinations(map, VirtualKey.NUMPAD_3, '3', 0, 0, 0, false); 
    266  
    267     assertCombinations(map, VirtualKey.NUMPAD_4, '4', 0, 0, 0, false); 
    268  
    269     assertCombinations(map, VirtualKey.NUMPAD_5, '5', 0, 0, 0, false); 
    270  
    271     assertCombinations(map, VirtualKey.NUMPAD_6, '6', 0, 0, 0, false); 
    272  
    273     assertCombinations(map, VirtualKey.NUMPAD_7, '7', 0, 0, 0, false); 
    274  
    275     assertCombinations(map, VirtualKey.NUMPAD_8, '8', 0, 0, 0, false); 
    276  
    277     assertCombinations(map, VirtualKey.NUMPAD_9, '9', 0, 0, 0, false); 
    278  
    279     assertCombinations(map, VirtualKey.SEPARATOR, ',', 0, 0, 0, false); 
    280     assertCombinations(map, VirtualKey.DECIMAL, ',', 0, 0, 0, false); 
    281  
    282     assertCombinations(map, VirtualKey.CIRCUMFLEX, '^', '°', '¬', 0, true); 
    283  
    284     assertCombinations(map, VirtualKey.TAB, '\t', 0, '\t', 0, true); 
    285  
    286     assertCombinations(map, VirtualKey.SPACE, ' ', ' ', ' ', ' ', true); 
    287  
    288     assertCombinations(map, VirtualKey.COMMA, ',', ';', '·', '×', true); 
    289     assertCombinations(map, VirtualKey.SEMICOLON, ',', ';', '·', '×', true); 
    290     assertCombinations(map, VirtualKey.MULTIPLY, ',', ';', '·', '×', true); 
    291  
    292     assertCombinations(map, VirtualKey.MINUS, '-', '_', 0, 0, true); 
    293     assertCombinations(map, VirtualKey.UNDERSCORE, '-', '_', 0, 0, true); 
    294  
    295     assertCombinations(map, VirtualKey.PERIOD, '.', ':', '…', '÷', true); 
    296     assertCombinations(map, VirtualKey.COLON, '.', ':', '…', '÷', true); 
    297     assertCombinations(map, VirtualKey.DIVIDE, '.', ':', '…', '÷', true); 
    298  
    299     assertCombinations(map, VirtualKey.PLUS, '+', '*', '~', 0, true); 
    300     assertCombinations(map, VirtualKey.ASTERISK, '+', '*', '~', 0, true); 
    301     assertCombinations(map, VirtualKey.DEAD_TILDE, '+', '*', '~', 0, true); 
    302  
    303     assertCombinations(map, VirtualKey.LESS, '<', '>', '|', '¦', true); 
    304     assertCombinations(map, VirtualKey.GREATER, '<', '>', '|', '¦', true); 
    305  
    306     assertCombinations(map, VirtualKey.NUMBER_SIGN, '#', '\'', 0, 0, true); 
    307  
    308     /*DEAD_GRAVE(KeyEvent.VK_DEAD_GRAVE), 
    309     DEAD_ACUTE(KeyEvent.VK_DEAD_ACUTE), 
    310     DEAD_CIRCUMFLEX(KeyEvent.VK_DEAD_CIRCUMFLEX), 
    311     DEAD_TILDE(KeyEvent.VK_DEAD_TILDE), 
    312     DEAD_MACRON(KeyEvent.VK_DEAD_MACRON), 
    313     DEAD_BREVE(KeyEvent.VK_DEAD_BREVE), 
    314     DEAD_ABOVEDOT(KeyEvent.VK_DEAD_ABOVEDOT), 
    315     DEAD_DIAERESIS(KeyEvent.VK_DEAD_DIAERESIS), 
    316     DEAD_ABOVERING(KeyEvent.VK_DEAD_ABOVERING), 
    317     DEAD_DOUBLEACUTE(KeyEvent.VK_DEAD_DOUBLEACUTE), 
    318     DEAD_CARON(KeyEvent.VK_DEAD_CARON), 
    319     DEAD_CEDILLA(KeyEvent.VK_DEAD_CEDILLA), 
    320     DEAD_OGONEK(KeyEvent.VK_DEAD_OGONEK), 
    321     DEAD_IOTA(KeyEvent.VK_DEAD_IOTA), 
    322     DEAD_VOICED_SOUND(KeyEvent.VK_DEAD_VOICED_SOUND), 
    323     DEAD_SEMIVOICED_SOUND(KeyEvent.VK_DEAD_SEMIVOICED_SOUND),*/ 
    324   } 
    325  
    326   //----------------------------------------------------------------------------------------------- 
    327   /** 
    328    * 
    329    */ 
    330   //----------------------------------------------------------------------------------------------- 
    331   private void assertCombinations(KeyboardMap map, 
    332                                   VirtualKey  key, 
    333                                   int         normal, 
    334                                   int         withShift, 
    335                                   int         withAltGr, 
    336                                   int         withShiftAndAltGr, 
    337                                   boolean     numLockIndependent) 
    338   { 
    339     if (numLockIndependent) 
    340     { 
    341       if (normal != 0) 
    342       { 
    343         assertCombination("normal", normal, map, key, false, false, false); 
    344       } 
    345      
    346       if (withShift != 0) 
    347       { 
    348         assertCombination("shift", withShift, map, key, false, true, false); 
    349       } 
    350      
    351       if (withAltGr != 0) 
    352       { 
    353         assertCombination("altgr", withAltGr, map, key, false, false, true); 
    354       } 
    355      
    356       if (withShiftAndAltGr != 0) 
    357       { 
    358         assertCombination("shift and altgr", withShiftAndAltGr, map, key, false, true, true); 
    359       } 
    360     } 
    361     else 
    362     { 
    363       assertInvalidCombination("normal", normal, map, key, false, false, false); 
    364       assertInvalidCombination("shift", withShift, map, key, false, true, false); 
    365       assertInvalidCombination("altgr", withAltGr, map, key, false, false, true); 
    366       assertInvalidCombination("shift and altgr", withShiftAndAltGr, map, key, false, true, true); 
    367     } 
    368  
    369     if (normal != 0) 
    370     { 
    371       assertCombination("numlock", normal, map, key, true, false, false); 
    372     } 
    373        
    374     if (withShift != 0) 
    375     { 
    376       assertCombination("numlock and shift", withShift, map, key, true, true, false); 
    377     } 
    378        
    379     if (withAltGr != 0) 
    380     { 
    381       assertCombination("numlock and altgr", withAltGr, map, key, true, false, true); 
    382     } 
    383        
    384     if (withShiftAndAltGr != 0) 
    385     { 
    386       assertCombination 
    387         ("numlock, shift and altgr", withShiftAndAltGr, map, key, true, true, true); 
    388     } 
    389   } 
    390    
    391   //----------------------------------------------------------------------------------------------- 
    392   /** 
    393    * TODO: comment 
    394    * 
    395    * @param string 
    396    * @param normal 
    397    * @param characterFor 
    398    */ 
    399   //----------------------------------------------------------------------------------------------- 
    400   private void assertCombination(String      type, 
    401                                  int         expectedChar, 
    402                                  KeyboardMap map, 
    403                                  VirtualKey  key, 
    404                                  boolean     numlock, 
    405                                  boolean     shift, 
    406                                  boolean     altgr) 
    407   { 
    408     String message = "checked for " + type + ": expected '" + ((char) expectedChar) + "'"; 
    409  
    410     char retrievedChar; 
    411     try 
    412     { 
    413       retrievedChar = map.getCharacterFor(key, numlock, shift, altgr, false); 
    414     } 
    415     catch (IllegalArgumentException e) 
    416     { 
    417       fail("no character found. " + message); 
    418       return; 
    419     } 
    420      
    421     message += " but got '" + retrievedChar + "'"; 
    422      
    423     assertEquals(message, expectedChar, retrievedChar); 
    424   } 
    425  
    426   //----------------------------------------------------------------------------------------------- 
    427   /** 
    428    * TODO: comment 
    429    * 
    430    * @param string 
    431    * @param normal 
    432    * @param characterFor 
    433    */ 
    434   //----------------------------------------------------------------------------------------------- 
    435   private void assertInvalidCombination(String      type, 
    436                                         int         expectedChar, 
    437                                         KeyboardMap map, 
    438                                         VirtualKey  key, 
    439                                         boolean     numlock, 
    440                                         boolean     shift, 
    441                                         boolean     altgr) 
    442   { 
    443     char retrievedChar; 
    444     try 
    445     { 
    446       retrievedChar = map.getCharacterFor(key, numlock, shift, altgr, false); 
    447       assertEquals(Character.UNASSIGNED, retrievedChar); 
    448     } 
    449     catch (IllegalArgumentException e) 
    450     { 
    451       // this is ok and checked for 
    452     } 
    453      
    454   } 
     397        char retrievedChar; 
     398        try { 
     399            retrievedChar = map.getCharacterFor(key, numlock, shift, altgr, false); 
     400            assertEquals(Character.UNASSIGNED, retrievedChar); 
     401        } 
     402        catch (IllegalArgumentException e) { 
     403            // this is ok and checked for 
     404        } 
     405 
     406    } 
    455407 
    456408} 
Note: See TracChangeset for help on using the changeset viewer.