Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0238] Keyboard Enhancements #1587

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.smartdevicelink.proxy.rpc.enums.ImageType;
import com.smartdevicelink.proxy.rpc.enums.InteractionMode;
import com.smartdevicelink.proxy.rpc.enums.KeyboardEvent;
import com.smartdevicelink.proxy.rpc.enums.KeyboardInputMask;
import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout;
import com.smartdevicelink.proxy.rpc.enums.KeypressMode;
import com.smartdevicelink.proxy.rpc.enums.Language;
Expand Down Expand Up @@ -331,6 +332,7 @@ public class TestValues {
public static final LightControlData GENERAL_LIGHTCONTROLDATA = new LightControlData();
public static final HMISettingsControlData GENERAL_HMISETTINGSCONTROLDATA = new HMISettingsControlData();
public static final DynamicUpdateCapabilities GENERAL_DYNAMICUPDATECAPABILITIES = new DynamicUpdateCapabilities();
public static final KeyboardCapabilities GENERAL_KEYBOARD_CAPABILITIES = new KeyboardCapabilities();
public static final WindowState GENERAL_WINDOWSTATE = new WindowState();

public static final DoorStatusType GENERAL_DOOR_STATUS_TYPE = DoorStatusType.REMOVED;
Expand Down Expand Up @@ -379,6 +381,9 @@ public class TestValues {
public static final List<Turn> GENERAL_TURN_LIST = new ArrayList<Turn>();
public static final List<Choice> GENERAL_CHOICE_LIST = new ArrayList<Choice>();
public static final List<String> GENERAL_STRING_LIST = Arrays.asList(new String[]{"a", "b"});
public static final KeyboardInputMask GENERAL_KEYBOARD_INPUT_MASK = KeyboardInputMask.ENABLE_INPUT_KEY_MASK;
public static final KeyboardLayoutCapability GENERAL_KEYBOARD_LAYOUT_CAPABILITY = new KeyboardLayoutCapability(GENERAL_KEYBOARDLAYOUT, 1);
public static final List<KeyboardLayoutCapability> GENERAL_SUPPORTED_KEYBOARDS_LIST = new ArrayList<KeyboardLayoutCapability>();
public static final List<Integer> GENERAL_INTEGER_LIST = Arrays.asList(new Integer[]{-1, -2});
public static final List<TTSChunk> GENERAL_TTSCHUNK_LIST = new ArrayList<TTSChunk>(2);
public static final List<HMILevel> GENERAL_HMILEVEL_LIST = Arrays.asList(new HMILevel[]{HMILevel.HMI_FULL, HMILevel.HMI_BACKGROUND});
Expand Down Expand Up @@ -505,7 +510,9 @@ public void onVoiceCommandSelected() {
public static final JSONArray JSON_IMAGE_TYPES = new JSONArray();
public static final JSONObject JSON_DISPLAYCAPABILITY = new JSONObject();
public static final JSONArray JSON_DISPLAYCAPABILITY_LIST = new JSONArray();
public static final JSONArray JSON_SUPPORTED_KEYBOARDS_LIST = new JSONArray();
public static final JSONObject JSON_DYNAMICUPDATECAPABILITIES = new JSONObject();
public static final JSONObject JSON_KEYBOARD_CAPABILITY = new JSONObject();
public static final JSONArray JSON_ROOF_STATUSES = new JSONArray();
public static final JSONArray JSON_DOOR_STATUSES = new JSONArray();
public static final JSONArray JSON_GATE_STATUSES = new JSONArray();
Expand Down Expand Up @@ -1076,6 +1083,10 @@ public void onVoiceCommandSelected() {
GENERAL_STABILITY_CONTROL_STATUS.setEscSystem(GENERAL_ESC_SYSTEM);
GENERAL_STABILITY_CONTROL_STATUS.setTrailerSwayControl(GENERAL_S_WAY_CONTROL);

GENERAL_SUPPORTED_KEYBOARDS_LIST.add(GENERAL_KEYBOARD_LAYOUT_CAPABILITY);

GENERAL_KEYBOARD_CAPABILITIES.setMaskInputCharactersSupported(TestValues.GENERAL_BOOLEAN);
GENERAL_KEYBOARD_CAPABILITIES.setSupportedKeyboards(GENERAL_SUPPORTED_KEYBOARDS_LIST);
GENERAL_ROOF_STATUS.setLocation(GENERAL_GRID);
GENERAL_ROOF_STATUS.setState(GENERAL_WINDOW_STATE);
GENERAL_ROOF_STATUS.setStatus(GENERAL_DOOR_STATUS_TYPE);
Expand All @@ -1090,6 +1101,14 @@ public void onVoiceCommandSelected() {
GENERAL_DOOR_STATUS_LIST.add(GENERAL_DOOR_STATUS);

try {

for (KeyboardLayoutCapability keyboard : GENERAL_SUPPORTED_KEYBOARDS_LIST) {
JSON_SUPPORTED_KEYBOARDS_LIST.put(keyboard.serializeJSON());
}

JSON_KEYBOARD_CAPABILITY.put(KeyboardCapabilities.KEY_MASK_INPUT_CHARACTERS_SUPPORTED, GENERAL_BOOLEAN);
JSON_KEYBOARD_CAPABILITY.put(KeyboardCapabilities.KEY_SUPPORTED_KEYBOARDS, JSON_SUPPORTED_KEYBOARDS_LIST);

JSON_HMIPERMISSIONS.put(HMIPermissions.KEY_ALLOWED, GENERAL_HMILEVEL_LIST);
JSON_HMIPERMISSIONS.put(HMIPermissions.KEY_USER_DISALLOWED, GENERAL_HMILEVEL_LIST);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
import com.smartdevicelink.proxy.rpc.enums.HmiZoneCapabilities;
import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout;
import com.smartdevicelink.proxy.rpc.enums.PRNDL;
import com.smartdevicelink.proxy.rpc.enums.PrerecordedSpeech;
import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities;
Expand Down Expand Up @@ -3930,6 +3931,43 @@ public static boolean validateStabilityControlStatus(VehicleDataResult status1,
return status1.getDataType().equals(status2.getDataType()) && status1.getResultCode().equals(status2.getResultCode());
}

public static boolean validateKeyboardLayoutCapability(KeyboardLayoutCapability keyboard1, KeyboardLayoutCapability keyboard2) {
if (keyboard1 == null) {
return (keyboard2 == null);
}
if (keyboard2 == null) {
return (keyboard1 == null);
}
return keyboard1.getKeyboardLayout().equals(keyboard2.getKeyboardLayout()) && keyboard1.getNumConfigurableKeys().equals(keyboard2.getNumConfigurableKeys());
}

public static boolean validateKeyboardCapabilities(KeyboardCapabilities keyboardCapabilities1, KeyboardCapabilities keyboardCapabilities2) {
if (keyboardCapabilities1 == null) {
return (keyboardCapabilities2 == null);
}
if (keyboardCapabilities2 == null) {
return (keyboardCapabilities1 == null);
}

boolean keyboardsEqual = true;
if (keyboardCapabilities1.getSupportedKeyboards() != null && keyboardCapabilities2.getSupportedKeyboards() != null) {

for (KeyboardLayoutCapability keyboardLayoutCapability1 : keyboardCapabilities1.getSupportedKeyboards()) {
for (KeyboardLayoutCapability keyboardLayoutCapability2 : keyboardCapabilities2.getSupportedKeyboards()) {
if (!validateKeyboardLayoutCapability(keyboardLayoutCapability1, keyboardLayoutCapability2)) {
keyboardsEqual = false;
break;
}
}
if (!keyboardsEqual) {
break;
}
}
}

return keyboardsEqual && keyboardCapabilities1.getMaskInputCharactersSupported().equals(keyboardCapabilities2.getMaskInputCharactersSupported());
}

public static boolean validateDoorStatus(DoorStatus status1, DoorStatus status2) {
if (status1 == null) {
return (status2 == null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.marshal.JsonRPCMarshaller;
import com.smartdevicelink.proxy.rpc.KeyboardCapabilities;
import com.smartdevicelink.proxy.rpc.KeyboardLayoutCapability;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.test.Validator;

import junit.framework.TestCase;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

public class KeyboardCapabilitiesTests extends TestCase {
private KeyboardCapabilities msg;

@Override
public void setUp() {
msg = new KeyboardCapabilities();

msg.setMaskInputCharactersSupported(TestValues.GENERAL_BOOLEAN);
msg.setSupportedKeyboards(TestValues.GENERAL_SUPPORTED_KEYBOARDS_LIST);
}

/**
* Tests the expected values of the RPC message.
*/
public void testRpcValues() {
// Test Values
Boolean maskInputCharactersSupported = msg.getMaskInputCharactersSupported();
List<KeyboardLayoutCapability> supportedKeyboards = msg.getSupportedKeyboards();

// Valid Tests
assertEquals(TestValues.MATCH, TestValues.GENERAL_BOOLEAN, (boolean) maskInputCharactersSupported);
assertEquals(TestValues.MATCH, TestValues.GENERAL_SUPPORTED_KEYBOARDS_LIST, supportedKeyboards);

// Invalid/Null Tests
KeyboardCapabilities msg = new KeyboardCapabilities();
assertNotNull(TestValues.NOT_NULL, msg);

assertNull(TestValues.NULL, msg.getMaskInputCharactersSupported());
assertNull(TestValues.NULL, msg.getSupportedKeyboards());
}

public void testJson() {
JSONObject reference = new JSONObject();

try {
reference.put(KeyboardCapabilities.KEY_MASK_INPUT_CHARACTERS_SUPPORTED, TestValues.GENERAL_BOOLEAN);
reference.put(KeyboardCapabilities.KEY_SUPPORTED_KEYBOARDS, TestValues.JSON_SUPPORTED_KEYBOARDS_LIST);

JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());

Iterator<?> iterator = reference.keys();
while (iterator.hasNext()) {
String key = (String) iterator.next();
if (key.equals(KeyboardCapabilities.KEY_SUPPORTED_KEYBOARDS)) {
JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key);
JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key);
assertEquals(TestValues.MATCH, referenceArray.length(), underTestArray.length());

for (int i = 0; i < referenceArray.length(); i++) {
Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(referenceArray.getJSONObject(i));
Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(underTestArray.getJSONObject(i));
assertTrue(TestValues.TRUE, Validator.validateKeyboardLayoutCapability(new KeyboardLayoutCapability(hashReference), new KeyboardLayoutCapability(hashTest)));
}
} else {
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
}
}
} catch (JSONException e) {
fail(TestValues.JSON_FAIL);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.proxy.rpc.KeyboardProperties;
import com.smartdevicelink.proxy.rpc.enums.KeyboardInputMask;
import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout;
import com.smartdevicelink.proxy.rpc.enums.KeypressMode;
import com.smartdevicelink.proxy.rpc.enums.Language;
Expand Down Expand Up @@ -34,8 +35,11 @@ public void setUp() {
msg.setKeypressMode(TestValues.GENERAL_KEYPRESSMODE);
msg.setLanguage(TestValues.GENERAL_LANGUAGE);
msg.setLimitedCharacterList(TestValues.GENERAL_STRING_LIST);
msg.setCustomKeys(TestValues.GENERAL_STRING_LIST);
msg.setMaskInputCharacters(TestValues.GENERAL_KEYBOARD_INPUT_MASK);
}


/**
* Tests the expected values of the RPC message.
*/
Expand All @@ -47,6 +51,8 @@ public void testRpcValues() {
KeypressMode keypressMode = msg.getKeypressMode();
Language language = msg.getLanguage();
List<String> limitedChars = msg.getLimitedCharacterList();
KeyboardInputMask keyInputMask = msg.getMaskInputCharacters();
List<String> customKeys = msg.getCustomKeys();

// Valid Tests
assertEquals(TestValues.MATCH, TestValues.GENERAL_STRING, autoCompleteText);
Expand All @@ -57,18 +63,21 @@ public void testRpcValues() {
assertEquals(TestValues.MATCH, TestValues.GENERAL_LANGUAGE, language);
assertEquals(TestValues.MATCH, TestValues.GENERAL_STRING_LIST.size(), limitedChars.size());
assertTrue(TestValues.TRUE, Validator.validateStringList(TestValues.GENERAL_STRING_LIST, limitedChars));
assertEquals(TestValues.MATCH, TestValues.GENERAL_KEYBOARD_INPUT_MASK, keyInputMask);
assertEquals(TestValues.MATCH, TestValues.GENERAL_STRING_LIST, customKeys);

// Invalid/Null Tests
KeyboardProperties msg = new KeyboardProperties();
assertNotNull(TestValues.NOT_NULL, msg);

// Keypress mode is created in the object constructor
assertNotNull(TestValues.NOT_NULL, msg.getKeypressMode());
assertNull(TestValues.NULL, msg.getKeypressMode());
assertNull(TestValues.NULL, msg.getAutoCompleteText());
assertNull(TestValues.NULL, msg.getAutoCompleteList());
assertNull(TestValues.NULL, msg.getLanguage());
assertNull(TestValues.NULL, msg.getKeyboardLayout());
assertNull(TestValues.NULL, msg.getLimitedCharacterList());
assertNull(TestValues.NULL, msg.getMaskInputCharacters());
assertNull(TestValues.NULL, msg.getCustomKeys());
}

public void testJson() {
Expand All @@ -81,14 +90,16 @@ public void testJson() {
reference.put(KeyboardProperties.KEY_KEYPRESS_MODE, TestValues.GENERAL_KEYPRESSMODE);
reference.put(KeyboardProperties.KEY_LANGUAGE, TestValues.GENERAL_LANGUAGE);
reference.put(KeyboardProperties.KEY_LIMITED_CHARACTER_LIST, JsonUtils.createJsonArray(TestValues.GENERAL_STRING_LIST));
reference.put(KeyboardProperties.KEY_CUSTOM_KEYS, JsonUtils.createJsonArray(TestValues.GENERAL_STRING_LIST));
reference.put(KeyboardProperties.KEY_MASK_INPUT_CHARACTERS, TestValues.GENERAL_KEYBOARD_INPUT_MASK);

JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KostyaBoss On line 102 in the if statement you need to add: || key.equals(KeyboardProperties.KEY_CUSTOMIZE_KEYS) as a clause in the conditional.

So the if would look like: if (key.equals(KeyboardProperties.KEY_LIMITED_CHARACTER_LIST) || key.equals(KeyboardProperties.KEY_AUTO_COMPLETE_LIST) || key.equals(KeyboardProperties.KEY_CUSTOMIZE_KEYS))


Iterator<?> iterator = reference.keys();
while (iterator.hasNext()) {
String key = (String) iterator.next();
if (key.equals(KeyboardProperties.KEY_LIMITED_CHARACTER_LIST) || key.equals(KeyboardProperties.KEY_AUTO_COMPLETE_LIST)) {
if (key.equals(KeyboardProperties.KEY_LIMITED_CHARACTER_LIST) || key.equals(KeyboardProperties.KEY_AUTO_COMPLETE_LIST) || key.equals(KeyboardProperties.KEY_CUSTOM_KEYS)) {
assertTrue(TestValues.TRUE, Validator.validateStringList(JsonUtils.readStringListFromJsonObject(reference, key), JsonUtils.readStringListFromJsonObject(underTest, key)));
} else {
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.smartdevicelink.proxy.rpc.ButtonCapabilities;
import com.smartdevicelink.proxy.rpc.DynamicUpdateCapabilities;
import com.smartdevicelink.proxy.rpc.ImageField;
import com.smartdevicelink.proxy.rpc.KeyboardCapabilities;
import com.smartdevicelink.proxy.rpc.SoftButtonCapabilities;
import com.smartdevicelink.proxy.rpc.TextField;
import com.smartdevicelink.proxy.rpc.WindowCapability;
Expand Down Expand Up @@ -46,6 +47,7 @@ public void setUp() {
msg.setSoftButtonCapabilities(TestValues.GENERAL_SOFTBUTTONCAPABILITIES_LIST);
msg.setMenuLayoutsAvailable(TestValues.GENERAL_MENU_LAYOUT_LIST);
msg.setDynamicUpdateCapabilities(TestValues.GENERAL_DYNAMICUPDATECAPABILITIES);
msg.setKeyboardCapabilities(TestValues.GENERAL_KEYBOARD_CAPABILITIES);
}

/**
Expand All @@ -63,6 +65,7 @@ public void testRpcValues() {
List<SoftButtonCapabilities> softButtonCapabilities = msg.getSoftButtonCapabilities();
List<MenuLayout> menuLayouts = msg.getMenuLayoutsAvailable();
DynamicUpdateCapabilities dynamicUpdateCapabilities = msg.getDynamicUpdateCapabilities();
KeyboardCapabilities keyboardCapabilities = msg.getKeyboardCapabilities();

// Valid Tests
assertEquals(TestValues.MATCH, TestValues.GENERAL_INT, windowID);
Expand All @@ -75,6 +78,7 @@ public void testRpcValues() {
assertEquals(TestValues.MATCH, TestValues.GENERAL_SOFTBUTTONCAPABILITIES_LIST.size(), softButtonCapabilities.size());
assertEquals(TestValues.MATCH, TestValues.GENERAL_MENU_LAYOUT_LIST.size(), menuLayouts.size());
assertEquals(TestValues.MATCH, TestValues.GENERAL_DYNAMICUPDATECAPABILITIES, dynamicUpdateCapabilities);
assertEquals(TestValues.MATCH, TestValues.GENERAL_KEYBOARD_CAPABILITIES, keyboardCapabilities);

for (int i = 0; i < TestValues.GENERAL_TEXTFIELD_LIST.size(); i++) {
assertTrue(TestValues.TRUE, Validator.validateTextFields(TestValues.GENERAL_TEXTFIELD_LIST.get(i), textFields.get(i)));
Expand Down Expand Up @@ -113,6 +117,7 @@ public void testRpcValues() {
assertNull(TestValues.NULL, msg.getSoftButtonCapabilities());
assertNull(TestValues.NULL, msg.getMenuLayoutsAvailable());
assertNull(TestValues.NULL, msg.getDynamicUpdateCapabilities());
assertNull(TestValues.NULL, msg.getKeyboardCapabilities());
}

public void testJson() {
Expand All @@ -129,6 +134,7 @@ public void testJson() {
reference.put(WindowCapability.KEY_SOFT_BUTTON_CAPABILITIES, TestValues.JSON_SOFTBUTTONCAPABILITIES);
reference.put(WindowCapability.KEY_MENU_LAYOUTS_AVAILABLE, JsonUtils.createJsonArray(TestValues.GENERAL_MENU_LAYOUT_LIST));
reference.put(WindowCapability.KEY_DYNAMIC_UPDATE_CAPABILITIES, TestValues.JSON_DYNAMICUPDATECAPABILITIES);
reference.put(WindowCapability.KEY_KEYBOARD_CAPABILITIES, TestValues.JSON_KEYBOARD_CAPABILITY);

JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());
Expand Down Expand Up @@ -214,6 +220,13 @@ public void testJson() {
imageFieldNameListTest.add((ImageFieldName) underTestArray.get(i));
}
assertTrue(TestValues.TRUE, imageFieldNameListReference.containsAll(imageFieldNameListTest) && imageFieldNameListTest.containsAll(imageFieldNameListReference));
} else if (key.equals(WindowCapability.KEY_KEYBOARD_CAPABILITIES)){
JSONObject jsonReference = JsonUtils.readJsonObjectFromJsonObject(reference, key);
JSONObject jsonUnderTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key);

Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(jsonReference);
Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(jsonUnderTest);
assertTrue(TestValues.TRUE, Validator.validateKeyboardCapabilities(new KeyboardCapabilities(hashReference), new KeyboardCapabilities(hashTest)));
} else {
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
}
Expand Down
Loading