blob: be5771c33e61cc7a94769301388b4abcc9a882d7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/*******************************************************************************
* Copyright (c) 2008 Ketan Padegaonkar and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ketan Padegaonkar - initial API and implementation
*******************************************************************************/
package org.eclipse.swtbot.swt.finder.keyboard;
import static org.junit.Assert.assertEquals;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.swt.SWT;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences.KeyboardLayoutDetector;
import org.junit.After;
import org.junit.Test;
/**
* @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
* @version $Id$
*/
public class KeyboardLayoutTest {
@Test
public void shouldBeAbleToParseUserProvidedKeyboardLayout() throws Exception {
KeyboardLayout layout = KeyboardLayout.getKeyboardLayout("com.foo.bar.BAZ");
assertEquals(keys(SWT.SHIFT, 't'), layout.keyStrokeFor('#'));
}
@Test
public void shouldBeAbleToParseUserProvidedKeyboardLayoutViaPreference() throws Exception {
SWTBotPreferences.KEYBOARD_LAYOUT = "com.foo.bar.MAC_FOOBAR";
KeyboardLayout layout = KeyboardLayout.getDefaultKeyboardLayout();
assertEquals(keys(SWT.SHIFT, 'Y'), layout.keyStrokeFor('*'));
}
@After
public void tearDown() {
SWTBotPreferences.KEYBOARD_LAYOUT = KeyboardLayoutDetector.detectKeyboard();
}
private KeyStroke keys(int modifierKeys, char c) {
return KeyStroke.getInstance(modifierKeys, c);
}
}
|