| 1 | // Jomic - a viewer for comic book archives. |
| 2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | package net.sf.jomic.tools; |
| 17 | |
| 18 | import java.awt.event.KeyEvent; |
| 19 | |
| 20 | import javax.swing.KeyStroke; |
| 21 | |
| 22 | import junit.framework.TestCase; |
| 23 | |
| 24 | /** |
| 25 | * TestCase for UiTools. |
| 26 | * |
| 27 | * @author Thomas Aglassinger |
| 28 | */ |
| 29 | public class UiToolsTest extends TestCase |
| 30 | { |
| 31 | private UiTools uiTools; |
| 32 | |
| 33 | protected void setUp() |
| 34 | throws Exception { |
| 35 | super.setUp(); |
| 36 | TestTools.instance(); |
| 37 | uiTools = UiTools.instance(); |
| 38 | } |
| 39 | |
| 40 | public void testGetKeyCode() { |
| 41 | assertEquals("A", uiTools.getKeyText(KeyEvent.VK_A)); |
| 42 | assertEquals("SHIFT", uiTools.getKeyText(KeyEvent.VK_SHIFT)); |
| 43 | assertEquals("NUMPAD3", uiTools.getKeyText(KeyEvent.VK_NUMPAD3)); |
| 44 | assertEquals("unknown(0x12345678)", uiTools.getKeyText(0x12345678)); |
| 45 | } |
| 46 | |
| 47 | public void testKeyStrokeToString() { |
| 48 | testKeyStrokeToString("typed A"); |
| 49 | testKeyStrokeToString("pressed SPACE"); |
| 50 | testKeyStrokeToString("released SPACE"); |
| 51 | // TODO: Add test cases like this: testKeyStrokeToString("alt pressed A"); |
| 52 | // However, currently this fails because it turns into "alt button2 pressed A". |
| 53 | } |
| 54 | |
| 55 | protected void tearDown() |
| 56 | throws Exception { |
| 57 | uiTools = null; |
| 58 | super.tearDown(); |
| 59 | } |
| 60 | |
| 61 | private void testKeyStrokeToString(String keyText) { |
| 62 | assert keyText != null; |
| 63 | KeyStroke stroke = KeyStroke.getKeyStroke(keyText); |
| 64 | |
| 65 | assert stroke != null; |
| 66 | assertEquals(keyText, uiTools.keyStrokeToString(stroke)); |
| 67 | } |
| 68 | } |