JBR-3299: The test /jb/sun/awt/macos/NationalLayoutTest/Layout_ABC.java fails on MacOS.

Fixes the Layout_*.java tests by giving them to know the <Ctrl + key> combinations can generate KEY_TYPED event.

(cherry picked from commit eae5198b20)
This commit is contained in:
Nikita Provotorov
2022-02-08 18:35:37 +07:00
committed by alexey.ushakov@jetbrains.com
parent c51c63adb1
commit 09111866d0
8 changed files with 112 additions and 89 deletions

View File

@@ -35,20 +35,20 @@ public enum Layout_ABC implements LayoutKey {
// located on the left side of the key 1 on the Apple International English keyboard
// SECTION ('§', '§', '±', '±'),
VK_MINUS ('-', '', '_', '—'),
VK_EQUALS ('=', '≠', '+', '±'),
VK_MINUS ('-', '', '_', '—', '\u001F'),
VK_EQUALS ('=', '≠', '+', '±', '='),
VK_OPEN_BRACKET ('[', '“', '{', '”'),
VK_CLOSE_BRACKET (']', '', '}', ''),
VK_OPEN_BRACKET ('[', '“', '{', '”', '\u001B'),
VK_CLOSE_BRACKET (']', '', '}', '', '\u001D'),
VK_SEMICOLON (';', '…', ':', 'Ú'),
VK_QUOTE ('\'', 'æ', '"', 'Æ'),
VK_BACK_SLASH ('\\', '«', '|', '»'),
VK_SEMICOLON (';', '…', ':', 'Ú', ';'),
VK_QUOTE ('\'', 'æ', '"', 'Æ', '\''),
VK_BACK_SLASH ('\\', '«', '|', '»', '\u001C'),
VK_BACK_QUOTE (KeyChar.ch('`'), KeyChar.dead('`'), KeyChar.ch('~'), KeyChar.ch('`')),
VK_COMMA (',', '≤', '<', '¯'),
VK_PERIOD ('.', '≥', '>', '˘'),
VK_SLASH ('/', '÷', '?', '¿'),
VK_BACK_QUOTE (KeyChar.ch('`'), KeyChar.dead('`'), KeyChar.ch('~'), KeyChar.ch('`'), KeyChar.ch('`')),
VK_COMMA (',', '≤', '<', '¯', ','),
VK_PERIOD ('.', '≥', '>', '˘', '.'),
VK_SLASH ('/', '÷', '?', '¿', '/'),
//VK_1 ('1', '¡', '!', ''),
//VK_2 ('2', '™', '@', '€'),
@@ -99,12 +99,12 @@ public enum Layout_ABC implements LayoutKey {
private final Key key;
Layout_ABC(char no, char alt, char shift, char alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_ABC(char no, char alt, char shift, char alt_shift, char control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
Layout_ABC(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_ABC(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift, KeyChar control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
public Key getKey() {

View File

@@ -30,20 +30,20 @@ public enum Layout_FRENCH_PC implements LayoutKey {
// Enum name must be the same as KeyEvent.VK_ constant name corresponding to the key on US keyboard layout
// Note that '\u0000' may be used if no char is mapped to a key + modifier or if one wants to skip its testing
VK_MINUS (')', ']', '°', ']'),
VK_EQUALS ('=', '}', '+', '≠'),
VK_MINUS (')', ']', '°', ']', '\u001B'),
VK_EQUALS ('=', '}', '+', '≠', '\u001F'),
VK_OPEN_BRACKET (KeyChar.dead('^'), KeyChar.ch('ô'), KeyChar.dead('¨'), KeyChar.ch('Ô')),
VK_CLOSE_BRACKET ('$', '¤', '£', '¥'),
VK_OPEN_BRACKET (KeyChar.dead('^'), KeyChar.ch('ô'), KeyChar.dead('¨'), KeyChar.ch('Ô'), KeyChar.ch('\u001E')),
VK_CLOSE_BRACKET ('$', '¤', '£', '¥', '\u001D'),
VK_SEMICOLON ('m', 'µ', 'M', 'Ó'),
VK_QUOTE ('ù', 'Ù', '%', '‰'),
VK_BACK_SLASH ('*', '@', 'μ', '#'),
VK_SEMICOLON ('m', 'µ', 'M', 'Ó', '\r'),
VK_QUOTE ('ù', 'Ù', '%', '‰', 'ù'),
VK_BACK_SLASH ('*', '@', 'μ', '#', '\u001C'),
VK_BACK_QUOTE ('<', '«', '>', '≥'),
VK_COMMA (';', '…', '.', '•'),
VK_PERIOD (':', '÷', '/', '\\'),
VK_SLASH ('!', '¡', '§', '±'),
VK_BACK_QUOTE ('<', '«', '>', '≥', '<'),
VK_COMMA (';', '…', '.', '•', ';'),
VK_PERIOD (':', '÷', '/', '\\', ':'),
VK_SLASH ('!', '¡', '§', '±', '='),
;
@@ -51,12 +51,12 @@ public enum Layout_FRENCH_PC implements LayoutKey {
private final Key key;
Layout_FRENCH_PC(char no, char alt, char shift, char alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_FRENCH_PC(char no, char alt, char shift, char alt_shift, char control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
Layout_FRENCH_PC(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_FRENCH_PC(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift, KeyChar control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
public Key getKey() {

View File

@@ -31,20 +31,20 @@ public enum Layout_GERMAN implements LayoutKey {
// Note that '\u0000' may be used if no char is mapped to a key + modifier or if one wants to skip its testing
// Eszett
VK_MINUS ('ß', '¿', '?', '˙'),
VK_EQUALS (KeyChar.dead('´'), KeyChar.ch('\''), KeyChar.dead('`'), KeyChar.ch('˚')),
VK_MINUS ('ß', '¿', '?', '˙', 'ß'),
VK_EQUALS (KeyChar.dead('´'), KeyChar.ch('\''), KeyChar.dead('`'), KeyChar.ch('˚'), KeyChar.ch('´')),
VK_OPEN_BRACKET ('ü', '•', 'Ü', '°'),
VK_CLOSE_BRACKET ('+', '±', '*', ''),
VK_OPEN_BRACKET ('ü', '•', 'Ü', '°', '\u001D'),
VK_CLOSE_BRACKET ('+', '±', '*', '', '+'),
VK_SEMICOLON ('ö', 'œ', 'Ö', 'Œ'),
VK_QUOTE ('ä', 'æ', 'Ä', 'Æ'),
VK_BACK_SLASH ('#', '', '\'', ''),
VK_SEMICOLON ('ö', 'œ', 'Ö', 'Œ', '\u001C'),
VK_QUOTE ('ä', 'æ', 'Ä', 'Æ', '\u001B'),
VK_BACK_SLASH ('#', '', '\'', '', '#'),
VK_BACK_QUOTE ('<', '≤', '>', '≥'),
VK_COMMA (',', '∞', ';', '˛'),
VK_PERIOD ('.', '…', ':', '÷'),
VK_SLASH ('-', '', '_', '—'),
VK_BACK_QUOTE ('<', '≤', '>', '≥', '<'),
VK_COMMA (',', '∞', ';', '˛', ','),
VK_PERIOD ('.', '…', ':', '÷', '.'),
VK_SLASH ('-', '', '_', '—', '-'),
;
@@ -52,12 +52,12 @@ public enum Layout_GERMAN implements LayoutKey {
private final Key key;
Layout_GERMAN(char no, char alt, char shift, char alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_GERMAN(char no, char alt, char shift, char alt_shift, char control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
Layout_GERMAN(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_GERMAN(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift, KeyChar control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
public Key getKey() {

View File

@@ -30,20 +30,20 @@ public enum Layout_SPANISH_ISO implements LayoutKey {
// Enum name must be the same as KeyEvent.VK_ constant name corresponding to the key on US keyboard layout
// Note that '\u0000' may be used if no char is mapped to a key + modifier or if one wants to skip its testing
VK_MINUS ('\'', '´', '?', '¸'),
VK_EQUALS ('¡', '', '¿', '˛'),
VK_MINUS ('\'', '´', '?', '¸', '\u001F'),
VK_EQUALS ('¡', '', '¿', '˛', '='),
VK_OPEN_BRACKET (KeyChar.dead('`'), KeyChar.ch('['), KeyChar.dead('^'), KeyChar.ch('ˆ')),
VK_CLOSE_BRACKET ('+', ']', '*', '±'),
VK_OPEN_BRACKET (KeyChar.dead('`'), KeyChar.ch('['), KeyChar.dead('^'), KeyChar.ch('ˆ'), KeyChar.ch('\u001B')),
VK_CLOSE_BRACKET ('+', ']', '*', '±', '\u001D'),
VK_SEMICOLON (KeyChar.ch('ñ'), KeyChar.dead('~'), KeyChar.ch('Ñ'), KeyChar.ch('˜')),
VK_QUOTE (KeyChar.dead('´'), KeyChar.ch('{'), KeyChar.dead('¨'), KeyChar.ch('«')),
VK_BACK_SLASH ('ç', '}', 'Ç', '»'),
VK_SEMICOLON (KeyChar.ch('ñ'), KeyChar.dead('~'), KeyChar.ch('Ñ'), KeyChar.ch('˜'), KeyChar.ch(':')),
VK_QUOTE (KeyChar.dead('´'), KeyChar.ch('{'), KeyChar.dead('¨'), KeyChar.ch('«'), KeyChar.ch('"')),
VK_BACK_SLASH ('ç', '}', 'Ç', '»', '\u001C'),
VK_BACK_QUOTE ('<', '≤', '>', '≥'),
VK_COMMA (',', '„', ';', '\u0000'),
VK_PERIOD ('.', '…', ':', '…'),
VK_SLASH ('-', '', '_', '—'),
VK_BACK_QUOTE ('<', '≤', '>', '≥', '`'),
VK_COMMA (',', '„', ';', '\u0000', ','),
VK_PERIOD ('.', '…', ':', '…', '.'),
VK_SLASH ('-', '', '_', '—', '/'),
;
@@ -51,12 +51,12 @@ public enum Layout_SPANISH_ISO implements LayoutKey {
private final Key key;
Layout_SPANISH_ISO(char no, char alt, char shift, char alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_SPANISH_ISO(char no, char alt, char shift, char alt_shift, char control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
Layout_SPANISH_ISO(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_SPANISH_ISO(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift, KeyChar control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
public Key getKey() {

View File

@@ -30,21 +30,21 @@ public enum Layout_US_INTERNATIONAL_PC implements LayoutKey {
// Enum name must be the same as KeyEvent.VK_ constant name corresponding to the key on US keyboard layout
// Note that '\u0000' may be used if no char is mapped to a key + modifier or if one wants to skip its testing
VK_MINUS ('-', '', '_', '—'),
VK_EQUALS ('=', '≠', '+', '±'),
VK_MINUS ('-', '', '_', '—', '\u001F'),
VK_EQUALS ('=', '≠', '+', '±', '='),
VK_OPEN_BRACKET ('[', '“', '{', '”'),
VK_CLOSE_BRACKET (']', '', '}', ''),
VK_OPEN_BRACKET ('[', '“', '{', '”', '\u001B'),
VK_CLOSE_BRACKET (']', '', '}', '', '\u001D'),
VK_SEMICOLON (';', '…', ':', 'Ú'),
VK_SEMICOLON (';', '…', ':', 'Ú', ';'),
// ' is a special dead symbol, which may add either acute or cedilla to the next key
VK_QUOTE (KeyChar.dead('\''), KeyChar.ch('æ'), KeyChar.dead('\"'), KeyChar.ch('Æ')),
VK_BACK_SLASH ('\\', '«', '|', '»'),
VK_QUOTE (KeyChar.dead('\''), KeyChar.ch('æ'), KeyChar.dead('\"'), KeyChar.ch('Æ'), KeyChar.ch('\'')),
VK_BACK_SLASH ('\\', '«', '|', '»', '\u001C'),
VK_BACK_QUOTE (KeyChar.dead('`'), KeyChar.dead('`'), KeyChar.dead('~'), KeyChar.ch('`')),
VK_COMMA (',', '≤', '<', '¯'),
VK_PERIOD ('.', '≥', '>', '˘'),
VK_SLASH ('/', '÷', '?', '¿'),
VK_BACK_QUOTE (KeyChar.dead('`'), KeyChar.dead('`'), KeyChar.dead('~'), KeyChar.ch('`'), KeyChar.ch('`')),
VK_COMMA (',', '≤', '<', '¯', ','),
VK_PERIOD ('.', '≥', '>', '˘', '.'),
VK_SLASH ('/', '÷', '?', '¿', '/'),
;
@@ -52,12 +52,12 @@ public enum Layout_US_INTERNATIONAL_PC implements LayoutKey {
private final Key key;
Layout_US_INTERNATIONAL_PC(char no, char alt, char shift, char alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_US_INTERNATIONAL_PC(char no, char alt, char shift, char alt_shift, char control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
Layout_US_INTERNATIONAL_PC(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift));
Layout_US_INTERNATIONAL_PC(KeyChar no, KeyChar alt, KeyChar shift, KeyChar alt_shift, KeyChar control) {
key = new Key(name(), new MappedKeyChars(no, alt, shift, alt_shift, control));
}
public Key getKey() {

View File

@@ -23,20 +23,22 @@ public class MappedKeyChars {
private final KeyChar alt;
private final KeyChar shift;
private final KeyChar alt_shift;
private final KeyChar control;
MappedKeyChars(char no_modifier, char alt, char shift, char alt_shift) {
MappedKeyChars(char no_modifier, char alt, char shift, char alt_shift, char control) {
this.no_modifier = KeyChar.ch(no_modifier);
this.alt = KeyChar.ch(alt);
this.shift = KeyChar.ch(shift);
this.alt_shift = KeyChar.ch(alt_shift);
this.control = KeyChar.ch(control);
}
MappedKeyChars(KeyChar no_modifier, KeyChar alt, KeyChar shift, KeyChar alt_shift) {
MappedKeyChars(KeyChar no_modifier, KeyChar alt, KeyChar shift, KeyChar alt_shift, KeyChar control) {
this.no_modifier = no_modifier;
this.alt = alt;
this.shift = shift;
this.alt_shift = alt_shift;
this.control = control;
}
/*
@@ -57,6 +59,9 @@ public class MappedKeyChars {
if(modifier.isAltShift()) {
return alt_shift;
}
if(modifier.isControl()) {
return control;
}
return KeyChar.ch(Character.MAX_VALUE);
}

View File

@@ -94,6 +94,10 @@ public enum Modifier {
return ((modifiers.length == 2) && list.contains(KeyEvent.VK_ALT) && list.contains(KeyEvent.VK_SHIFT));
}
boolean isControl() {
return ((modifiers.length == 1) && (modifiers[0] == KeyEvent.VK_CONTROL));
}
@Override
public String toString() {
if (modifiers.length == 0) {

View File

@@ -57,7 +57,9 @@ import java.util.stream.Collectors;
* - No keyTyped event is expected as the result of pressing dead key + key.
* - Pressing "dead key + space" generates corresponding diacritic character,
* which may be obtained using inputMethodTextChanged event.
* - Cmd, Ctrl and its combinations with other modifiers are considered as a "shortcut",
* - Ctrl can be used to type the "control characters" (0th to 31th character inclusively in the ASCII table),
* so Ctrl + key can generate keyTyped event.
* - Cmd and its combinations with other modifiers are considered as a "shortcut",
* no keyTyped event is expected as the result of pressing a shortcut,
* no attempts are made to check inputMethodTextChanged event result for a "shortcut".
*
@@ -182,7 +184,7 @@ public class NationalLayoutTest {
for (Modifier modifier : Modifier.values()) {
if(!testLayout(layout, modifier)) {
failed = true;
};
}
}
}
// Provide the test result
@@ -253,7 +255,7 @@ public class NationalLayoutTest {
// Corresponding latch is released in the typeAreaFocusListener.
if(!typeAreaGainedFocus.await(PAUSE, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("TEST ERROR: Failed to request focus in the text area for typing");
};
}
}
/*
@@ -305,9 +307,21 @@ public class NationalLayoutTest {
// Obtain typed char
char keyChar = e.getKeyChar();
int keyCode = KeyEvent.getExtendedKeyCodeForChar(keyChar);
if ((keyCode != NEXT_MODIFIER) && (keyCode != NEXT_KEY) && (keyCode != TERMINATE_KEY)) {
// Store typed char to the corresponding list
charsTyped.add(keyChar);
switch (keyCode) {
case NEXT_MODIFIER:
case NEXT_KEY:
case TERMINATE_KEY:
if ((e.getModifiers() & KeyEvent.CTRL_MASK) == 0) {
// Do not store the typed char only if it is NEXT_MODIFIER, NEXT_KEY, TERMINATE_KEY generated
// without Control modifier: the Control allows to "type" the "control characters"
// (0th to 31th character inclusively in the ASCII table).
break;
}
default:
// Store typed char to the corresponding list
charsTyped.add(keyChar);
break;
}
}
};
@@ -356,7 +370,7 @@ public class NationalLayoutTest {
}
if(!nextModifierSet.await(PAUSE*10, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("TEST ERROR: User has not proceeded with manual testing");
};
}
// Clean up the test text areas
inputArea.setText("");
@@ -411,7 +425,7 @@ public class NationalLayoutTest {
if(!nextKey.await(PAUSE, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("TEST ERROR: "
+ KeyEvent.getKeyText(NEXT_KEY) + " key pressed event was not received");
};
}
// Define array of key codes expected to be pressed as the result of modifiers + key
int[] keysPattern = Arrays.copyOf(modifiers, modifiers.length + 1);
@@ -426,7 +440,7 @@ public class NationalLayoutTest {
// Check if the pressed key codes are equal to the expected ones
if(!checkResult(keysPattern, keysResult, null,null)) {
result = false;
};
}
} else {
// Define array of chars expected to be typed as the result of modifiers + key
// Do not expect any char typed as the result of shortcut (char is undefined in this case)
@@ -440,7 +454,7 @@ public class NationalLayoutTest {
// Check if pressed key codes and typed chars are equal to the expected ones
if(!checkResult(keysPattern, keysResult, charsPattern, charsResult)) {
result = false;
};
}
}
}
// Provide layout + modifier testing result
@@ -473,7 +487,7 @@ public class NationalLayoutTest {
boolean checkKeys = Arrays.equals(patternKeys, resultKeys);
boolean checkChars = Arrays.equals(patternChars, resultChars);
boolean result = (checkKeys & checkChars);
boolean result = (checkKeys && checkChars);
if(!result) {
String[] patternStr = (patternKeys != null) ? intsToStrings(patternKeys) : null;