1 33 34 package edu.rice.cs.drjava.config; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 import edu.rice.cs.util.newjvm.ExecJVM; 38 39 import javax.swing.*; 40 import java.awt.event.InputEvent ; 41 import java.awt.event.KeyEvent ; 42 import java.io.IOException ; 43 import java.util.Locale ; 44 45 48 public final class KeyStrokeOptionTest extends DrJavaTestCase { 49 50 public KeyStrokeOptionTest(String name) { super(name); } 51 52 public void testGetName() { 53 KeyStrokeOption io1 = new KeyStrokeOption("indent_size",null); 54 KeyStrokeOption io2 = new KeyStrokeOption("max_files",null); 55 56 assertEquals("indent_size", io1.getName()); 57 assertEquals("max_files", io2.getName()); 58 } 59 60 public void testParse() { 61 KeyStrokeOption io = new KeyStrokeOption("max_files",null); 62 assertEquals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK), 63 io.parse("ctrl ENTER")); 64 assertEquals(KeyStrokeOption.NULL_KEYSTROKE, 65 io.parse("<none>")); 66 assertEquals(KeyStroke.getKeyStroke(KeyEvent.VK_NUM_LOCK, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true), 67 io.parse("alt shift released NUM_LOCK")); 68 assertEquals(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, false), 69 io.parse("alt shift COMMA")); 70 assertEquals(KeyStroke.getKeyStroke('%'), 71 io.parse("typed %")); 72 assertEquals(KeyStroke.getKeyStroke(new Character ('%'), InputEvent.ALT_MASK | InputEvent.CTRL_MASK), 73 io.parse("ctrl alt typed %")); 74 75 try { io.parse("true"); fail(); } 76 catch (IllegalArgumentException e) { } 77 78 try { io.parse(".33"); fail(); } 79 catch (IllegalArgumentException e) { } 80 81 try { io.parse("Alt Z"); fail(); } 82 catch (IllegalArgumentException e) { } 83 84 try { io.parse("ctrl alt shift typed F1"); fail(); } 85 catch (IllegalArgumentException e) { } 86 } 87 88 92 public void testFormat() { 93 KeyStrokeOption io = new KeyStrokeOption("max_files",null); 94 KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.ALT_MASK | InputEvent.META_MASK); 95 assertEquals(ks, io.parse(io.format(ks))); 96 ks = KeyStroke.getKeyStroke(KeyEvent.VK_NUMBER_SIGN, InputEvent.ALT_MASK | InputEvent.CTRL_MASK); 97 assertEquals(ks, io.parse(io.format(ks))); 98 99 ks = KeyStroke.getKeyStroke(new Character ('!'), InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK); 100 assertEquals(ks, io.parse(io.format(ks))); 101 ks = KeyStroke.getKeyStroke('!'); 102 assertEquals(ks, io.parse(io.format(ks))); 103 ks = KeyStroke.getKeyStroke(KeyEvent.VK_F10, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true); 104 assertEquals(ks, io.parse(io.format(ks))); 105 } 106 107 111 public void testLocaleSpecificFormat() throws IOException , InterruptedException { 112 String className = "edu.rice.cs.drjava.config.KeyStrokeOptionTest"; 113 String [] args = new String [0]; 114 115 Process process = ExecJVM.runJVMPropagateClassPath(className, args, FileOption.NULL_FILE); 116 int status = process.waitFor(); 117 assertEquals("Local specific keystroke test failed!", 0, status); 118 } 119 120 123 public static void main(String [] args) { 124 Locale.setDefault(Locale.GERMAN); 126 127 KeyStrokeOption io = new KeyStrokeOption("test",null); 128 KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.ALT_MASK | InputEvent.CTRL_MASK | 129 InputEvent.SHIFT_MASK | InputEvent.META_MASK); 130 String s = io.format(ks); 131 if ((s.indexOf("alt") == -1) && (s.indexOf("option") == -1)) System.exit(1); 133 134 if (s.indexOf("ctrl") == -1) System.exit(2); 136 137 if (s.indexOf("shift") == -1) System.exit(3); 139 140 if ((s.indexOf("meta") == -1) && (s.indexOf("command") == -1)) System.exit(4); 142 143 System.exit(0); 145 } 146 } 147 | Popular Tags |