01: package abbot.editor.widgets;
02:
03: import java.awt.event.KeyEvent;
04: import java.io.*;
05: import java.util.*;
06:
07: import junit.framework.*;
08: import junit.extensions.abbot.*;
09:
10: import abbot.i18n.Strings;
11:
12: public class MnemonicTest extends TestCase {
13:
14: public void testGetMnemonic() throws Exception {
15: Properties p = new Properties();
16: p.setProperty("MNEMONIC_\u00d6", "O");
17: p
18: .store(
19: new FileOutputStream(
20: "build/test-classes/abbot/editor/widgets/mnemonics.properties"),
21: "test");
22: Strings.addBundle("abbot.editor.widgets.mnemonics");
23: Object[][] strings = {
24: { "None", "None", new Integer(KeyEvent.VK_UNDEFINED),
25: new Integer(-1) },
26: { "&File", "File", new Integer(KeyEvent.VK_F),
27: new Integer(0) },
28: { "&lower", "lower", new Integer(KeyEvent.VK_L),
29: new Integer(0) },
30: { "Last&", "Last&", new Integer(KeyEvent.VK_UNDEFINED),
31: new Integer(-1) },
32: { "&TooMan&y", "TooMan&y", new Integer(KeyEvent.VK_T),
33: new Integer(0) },
34: { "About &Al", "About Al", new Integer(KeyEvent.VK_A),
35: new Integer(6) },
36: { "Rock && Roll", "Rock & Roll",
37: new Integer(KeyEvent.VK_UNDEFINED),
38: new Integer(-1) },
39: { "&Rock && Roll", "Rock & Roll",
40: new Integer(KeyEvent.VK_R), new Integer(0) },
41: { "Rock && &Roll", "Rock & Roll",
42: new Integer(KeyEvent.VK_R), new Integer(7) },
43: { "Rock & Roll", "Rock & Roll",
44: new Integer(KeyEvent.VK_UNDEFINED),
45: new Integer(-1) },
46: { "Sample '&' &character", "Sample '&' character",
47: new Integer(KeyEvent.VK_C), new Integer(11) },
48: { "Chara&cteristic '&'", "Characteristic '&'",
49: new Integer(KeyEvent.VK_C), new Integer(5) },
50: // Looked up via localized mapping
51: { "Unicode &\u00d6", "Unicode \u00d6",
52: new Integer(KeyEvent.VK_O), new Integer(8) },
53: // Looked up via keymap
54: { "Symbol&=", "Symbol=",
55: new Integer(KeyEvent.VK_EQUALS), new Integer(6) }, };
56: for (int i = 0; i < strings.length; i++) {
57: String str = (String) strings[i][0];
58: Mnemonic mnemonic = Mnemonic.getMnemonic(str);
59: assertEquals("Incorrect label for '" + str + "'",
60: strings[i][1], mnemonic.text);
61: if (Mnemonic.useMnemonics()) {
62: assertEquals("Incorrect mnemonic keycode for '" + str
63: + "'", strings[i][2], new Integer(
64: mnemonic.keycode));
65: assertEquals("Incorrect display index for '" + str
66: + "'", strings[i][3], new Integer(
67: mnemonic.index));
68: }
69: }
70: }
71:
72: /** Construct a test case with the given name. */
73: public MnemonicTest(String name) {
74: super (name);
75: }
76:
77: /** Run the default test suite. */
78: public static void main(String[] args) {
79: TestHelper.runTests(args, MnemonicTest.class);
80: }
81: }
|