diff options
Diffstat (limited to 'android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes')
20 files changed, 951 insertions, 15 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java index 524a6bde2..5351bf7a1 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java @@ -1,14 +1,18 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.AudioControlCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; /** @@ -30,6 +34,7 @@ public class AudioControlCapabilitiesTests extends TestCase { msg.setEqualizerAvailable(Test.GENERAL_BOOLEAN); msg.setVolumeAvailable(Test.GENERAL_BOOLEAN); msg.setEqualizerMaxChannelId(Test.GENERAL_INT); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } /** @@ -44,6 +49,7 @@ public class AudioControlCapabilitiesTests extends TestCase { Boolean volumeAvailable = msg.getVolumeAvailable(); Boolean equalizerAvailable = msg.getEqualizerAvailable(); int equalizerMaxChannelId = msg.getEqualizerMaxChannelId(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); @@ -52,6 +58,7 @@ public class AudioControlCapabilitiesTests extends TestCase { assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) volumeAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) equalizerAvailable); assertEquals(Test.MATCH, Test.GENERAL_INT, equalizerMaxChannelId); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); // Invalid/Null Tests AudioControlCapabilities msg = new AudioControlCapabilities(); @@ -63,6 +70,7 @@ public class AudioControlCapabilitiesTests extends TestCase { assertNull(Test.NULL, msg.getVolumeAvailable()); assertNull(Test.NULL, msg.getEqualizerAvailable()); assertNull(Test.NULL, msg.getEqualizerMaxChannelId()); + assertNull(Test.NULL, msg.getModuleInfo()); } public void testJson() { @@ -76,6 +84,7 @@ public class AudioControlCapabilitiesTests extends TestCase { reference.put(AudioControlCapabilities.KEY_VOLUME_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(AudioControlCapabilities.KEY_EQUALIZER_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(AudioControlCapabilities.KEY_EQUALIZER_MAX_CHANNEL_ID, Test.GENERAL_INT); + reference.put(AudioControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -83,9 +92,15 @@ public class AudioControlCapabilitiesTests extends TestCase { Iterator<?> iterator = reference.keys(); while (iterator.hasNext()) { String key = (String) iterator.next(); - - assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); - + if (key.equals(AudioControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } } } catch (JSONException e) { fail(Test.JSON_FAIL); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java index 4365ceafa..71f7d3ecf 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java @@ -1,15 +1,19 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.ButtonCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.proxy.rpc.enums.ButtonName; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; /** @@ -28,6 +32,7 @@ public class ButtonCapabilitiesTests extends TestCase{ msg.setName(Test.GENERAL_BUTTONNAME); msg.setShortPressAvailable(Test.GENERAL_BOOLEAN); msg.setUpDownAvailable(Test.GENERAL_BOOLEAN); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } @@ -40,12 +45,14 @@ public class ButtonCapabilitiesTests extends TestCase{ boolean longPress = msg.getLongPressAvailable(); boolean upDown = msg.getUpDownAvailable(); ButtonName buttonName = msg.getName(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, shortPress); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, longPress); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, upDown); assertEquals(Test.MATCH, Test.GENERAL_BUTTONNAME, buttonName); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); // Invalid/Null Tests ButtonCapabilities msg = new ButtonCapabilities(); @@ -65,15 +72,24 @@ public class ButtonCapabilitiesTests extends TestCase{ reference.put(ButtonCapabilities.KEY_LONG_PRESS_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(ButtonCapabilities.KEY_UP_DOWN_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(ButtonCapabilities.KEY_NAME, Test.GENERAL_BUTTONNAME); + reference.put(ButtonCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); Iterator<?> iterator = reference.keys(); - while(iterator.hasNext()){ + while (iterator.hasNext()) { String key = (String) iterator.next(); - assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + if (key.equals(ButtonCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } } } catch(JSONException e){ fail(Test.JSON_FAIL); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java index eb182f31c..a33f35b27 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java @@ -1,10 +1,13 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.ClimateControlCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.proxy.rpc.enums.DefrostZone; import com.smartdevicelink.proxy.rpc.enums.VentilationMode; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; @@ -13,6 +16,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -44,6 +48,7 @@ public class ClimateControlCapabilitiesTests extends TestCase{ msg.setHeatedWindshieldAvailable(Test.GENERAL_BOOLEAN); msg.setHeatedRearWindowAvailable(Test.GENERAL_BOOLEAN); msg.setHeatedMirrorsAvailable(Test.GENERAL_BOOLEAN); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); msg.setClimateEnableAvailable(Test.GENERAL_BOOLEAN); } @@ -68,6 +73,7 @@ public class ClimateControlCapabilitiesTests extends TestCase{ boolean heatedWindshieldAvailable = msg.getHeatedWindshieldAvailable(); boolean heatedRearWindowAvailable = msg.getHeatedRearWindowAvailable(); boolean heatedMirrorsAvailable = msg.getHeatedMirrorsAvailable(); + ModuleInfo info = msg.getModuleInfo(); boolean climateEnableAvailable = msg.getClimateEnableAvailable(); // Valid Tests @@ -81,6 +87,7 @@ public class ClimateControlCapabilitiesTests extends TestCase{ assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, dualModeEnableAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, defrostZoneAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, ventilationModeAvailable); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); assertEquals(Test.MATCH, Test.GENERAL_DEFROSTZONE_LIST.size(), defrostZone.size()); assertEquals(Test.MATCH, Test.GENERAL_VENTILATIONMODE_LIST.size(), ventilationMode.size()); @@ -117,6 +124,7 @@ public class ClimateControlCapabilitiesTests extends TestCase{ assertNull(Test.NULL, msg.getHeatedWindshieldAvailable()); assertNull(Test.NULL, msg.getHeatedRearWindowAvailable()); assertNull(Test.NULL, msg.getHeatedMirrorsAvailable()); + assertNull(Test.NULL, msg.getModuleInfo()); assertNull(Test.NULL, msg.getClimateEnableAvailable()); } @@ -140,6 +148,7 @@ public class ClimateControlCapabilitiesTests extends TestCase{ reference.put(ClimateControlCapabilities.KEY_HEATED_WIND_SHIELD_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(ClimateControlCapabilities.KEY_HEATED_REAR_WINDOW_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(ClimateControlCapabilities.KEY_HEATED_MIRRORS_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); reference.put(ClimateControlCapabilities.KEY_CLIMATE_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); JSONObject underTest = msg.serializeJSON(); @@ -175,6 +184,12 @@ public class ClimateControlCapabilitiesTests extends TestCase{ ventilationModeListTest.add( (VentilationMode)ventilationModeArrayTest.get(index) ); } assertTrue(Test.TRUE, ventilationModeListReference.containsAll(ventilationModeListTest) && ventilationModeListTest.containsAll(ventilationModeListReference)); + } else if (key.equals(ClimateControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); } else{ assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DisplayCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DisplayCapabilityTests.java new file mode 100644 index 000000000..6bb57761f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DisplayCapabilityTests.java @@ -0,0 +1,111 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.DisplayCapability; +import com.smartdevicelink.proxy.rpc.WindowCapability; +import com.smartdevicelink.proxy.rpc.WindowTypeCapabilities; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.DisplayCapability} + */ +public class DisplayCapabilityTests extends TestCase { + + private DisplayCapability msg; + + @Override + public void setUp() { + msg = new DisplayCapability(); + + msg.setDisplayName(Test.GENERAL_STRING); + msg.setWindowTypeSupported(Test.GENERAL_WINDOW_TYPE_CAPABILITIES_LIST); + msg.setWindowCapabilities(Test.GENERAL_WINDOW_CAPABILITY_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + String displayName = msg.getDisplayName(); + List<WindowTypeCapabilities> windowTypeSupported = msg.getWindowTypeSupported(); + List<WindowCapability> windowCapabilities = msg.getWindowCapabilities(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, displayName); + assertEquals(Test.MATCH, Test.GENERAL_WINDOW_TYPE_CAPABILITIES_LIST.size(), windowTypeSupported.size()); + assertEquals(Test.MATCH, Test.GENERAL_WINDOW_CAPABILITY_LIST.size(), windowCapabilities.size()); + + for (int i = 0; i < Test.GENERAL_WINDOW_TYPE_CAPABILITIES_LIST.size(); i++) { + assertTrue(Test.TRUE, Validator.validateWindowTypeCapabilities(Test.GENERAL_WINDOW_TYPE_CAPABILITIES_LIST.get(i), windowTypeSupported.get(i))); + } + + for (int i = 0; i < Test.GENERAL_WINDOW_CAPABILITY_LIST.size(); i++) { + assertTrue(Test.TRUE, Validator.validateWindowCapability(Test.GENERAL_WINDOW_CAPABILITY_LIST.get(i), windowCapabilities.get(i))); + } + + // Invalid/Null Tests + DisplayCapability msg = new DisplayCapability(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getDisplayName()); + assertNull(Test.NULL, msg.getWindowTypeSupported()); + assertNull(Test.NULL, msg.getWindowCapabilities()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(DisplayCapability.KEY_DISPLAY_NAME, Test.GENERAL_STRING); + reference.put(DisplayCapability.KEY_WINDOW_TYPE_SUPPORTED, Test.JSON_WINDOW_TYPE_CAPABILITIES_LIST); + reference.put(DisplayCapability.KEY_WINDOW_CAPABILITIES, Test.JSON_WINDOW_CAPABILITIES); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while (iterator.hasNext()) { + String key = (String) iterator.next(); + if (key.equals(DisplayCapability.KEY_WINDOW_TYPE_SUPPORTED)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.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(Test.TRUE, Validator.validateWindowTypeCapabilities(new WindowTypeCapabilities(hashReference), new WindowTypeCapabilities(hashTest))); + } + } else if (key.equals(DisplayCapability.KEY_WINDOW_CAPABILITIES)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.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(Test.TRUE, Validator.validateWindowCapability(new WindowCapability(hashReference), new WindowCapability(hashTest))); + } + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GridTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GridTests.java new file mode 100644 index 000000000..95f94c3a7 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GridTests.java @@ -0,0 +1,100 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Grid; +import com.smartdevicelink.test.Test; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Iterator; + +public class GridTests extends TestCase { + + private Grid msg; + + @Override + public void setUp() { + msg = new Grid(); + msg.setColumn(Test.GENERAL_INT); + msg.setRow(Test.GENERAL_INT); + msg.setLevel(Test.GENERAL_INT); + msg.setColumnSpan(Test.GENERAL_INT); + msg.setRowSpan(Test.GENERAL_INT); + msg.setLevelSpan(Test.GENERAL_INT); + } + + public void testRpcValues() { + int col = msg.getColumn(); + int row = msg.getRow(); + int level = msg.getLevel(); + int colSpan = msg.getColumnSpan(); + int rowSpan = msg.getRowSpan(); + int levelSpan = msg.getLevelSpan(); + + //valid tests + assertEquals(Test.MATCH, col, Test.GENERAL_INT); + assertEquals(Test.MATCH, row, Test.GENERAL_INT); + assertEquals(Test.MATCH, level, Test.GENERAL_INT); + assertEquals(Test.MATCH, colSpan, Test.GENERAL_INT); + assertEquals(Test.MATCH, rowSpan, Test.GENERAL_INT); + assertEquals(Test.MATCH, levelSpan, Test.GENERAL_INT); + + //null tests + Grid msg = new Grid(); + assertNull(Test.NULL, msg.getColumn()); + assertNull(Test.NULL, msg.getRow()); + assertNull(Test.NULL, msg.getLevel()); + assertNull(Test.NULL, msg.getColumnSpan()); + assertNull(Test.NULL, msg.getRowSpan()); + assertNull(Test.NULL, msg.getLevelSpan()); + + //test required constructor + Grid msg2 = new Grid(Test.GENERAL_INT, Test.GENERAL_INT); + int row2 = msg2.getRow(); + int col2 = msg2.getColumn(); + assertEquals(Test.MATCH, col2, Test.GENERAL_INT); + assertEquals(Test.MATCH, row2, Test.GENERAL_INT); + } + + public void testJson() { + JSONObject original = new JSONObject(); + try { + original.put(Grid.KEY_COLUMN, Test.GENERAL_INT); + original.put(Grid.KEY_ROW, Test.GENERAL_INT); + original.put(Grid.KEY_LEVEL, Test.GENERAL_INT); + original.put(Grid.KEY_COL_SPAN, Test.GENERAL_INT); + original.put(Grid.KEY_ROW_SPAN, Test.GENERAL_INT); + original.put(Grid.KEY_LEVEL_SPAN, Test.GENERAL_INT); + + JSONObject serialized = msg.serializeJSON(); + assertEquals(serialized.length(), original.length()); + + Iterator<String> iter = original.keys(); + String key = ""; + Grid grid1, grid2; + while (iter.hasNext()) { + key = iter.next(); + grid1 = new Grid(JsonRPCMarshaller.deserializeJSONObject(original)); + grid2 = new Grid(JsonRPCMarshaller.deserializeJSONObject(serialized)); + if (key.equals(Grid.KEY_COLUMN)) { + assertEquals(Test.MATCH, grid1.getColumn(), grid2.getColumn()); + } else if (key.equals(Grid.KEY_ROW)) { + assertEquals(Test.MATCH, grid1.getRow(), grid2.getRow()); + } else if (key.equals(Grid.KEY_LEVEL)) { + assertEquals(Test.MATCH, grid1.getLevel(), grid2.getLevel()); + } else if (key.equals(Grid.KEY_COL_SPAN)) { + assertEquals(Test.MATCH, grid1.getColumnSpan(), grid2.getColumnSpan()); + } else if (key.equals(Grid.KEY_ROW_SPAN)) { + assertEquals(Test.MATCH, grid1.getRowSpan(), grid2.getRowSpan()); + } else if (key.equals(Grid.KEY_LEVEL_SPAN)) { + assertEquals(Test.MATCH, grid1.getLevelSpan(), grid2.getLevelSpan()); + } + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java index 620868b40..aa49bf0ac 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java @@ -1,14 +1,18 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.HMISettingsControlCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; /** @@ -27,6 +31,7 @@ public class HMISettingsControlCapabilitiesTests extends TestCase { msg.setDistanceUnitAvailable(Test.GENERAL_BOOLEAN); msg.setTemperatureUnitAvailable(Test.GENERAL_BOOLEAN); msg.setDisplayModeUnitAvailable(Test.GENERAL_BOOLEAN); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } /** @@ -38,12 +43,14 @@ public class HMISettingsControlCapabilitiesTests extends TestCase { Boolean distanceUnitAvailable = msg.getDistanceUnitAvailable(); Boolean temperatureUnitAvailable = msg.getTemperatureUnitAvailable(); Boolean displayModeUnitAvailable = msg.getDisplayModeUnitAvailable(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) distanceUnitAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) temperatureUnitAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) displayModeUnitAvailable); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); // Invalid/Null Tests HMISettingsControlCapabilities msg = new HMISettingsControlCapabilities(); @@ -53,6 +60,7 @@ public class HMISettingsControlCapabilitiesTests extends TestCase { assertNull(Test.NULL, msg.getDistanceUnitAvailable()); assertNull(Test.NULL, msg.getTemperatureUnitAvailable()); assertNull(Test.NULL, msg.getDisplayModeUnitAvailable()); + assertNull(Test.NULL, msg.getModuleInfo()); } public void testJson() { @@ -63,6 +71,7 @@ public class HMISettingsControlCapabilitiesTests extends TestCase { reference.put(HMISettingsControlCapabilities.KEY_DISTANCE_UNIT_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(HMISettingsControlCapabilities.KEY_TEMPERATURE_UNIT_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(HMISettingsControlCapabilities.KEY_DISPLAY_MODE_UNIT_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(HMISettingsControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -70,8 +79,15 @@ public class HMISettingsControlCapabilitiesTests extends TestCase { Iterator<?> iterator = reference.keys(); while (iterator.hasNext()) { String key = (String) iterator.next(); - - assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + if (key.equals(HMISettingsControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } } } catch (JSONException e) { fail(Test.JSON_FAIL); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageResolutionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageResolutionTests.java index 2609acd37..68baaba62 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageResolutionTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageResolutionTests.java @@ -67,4 +67,26 @@ public class ImageResolutionTests extends TestCase{ fail(Test.JSON_FAIL); } } + + public void testSetResolutionWidth_Odd() { + msg.setResolutionWidth(175); + assertEquals(176, (int)msg.getResolutionWidth()); + } + + public void testSetResolutionHeight_Odd() { + msg.setResolutionHeight(175); + assertEquals(176, (int)msg.getResolutionHeight()); + } + + public void testSetResolutionWidth_Pair() { + msg.setResolutionWidth(176); + assertEquals(176, (int)msg.getResolutionWidth()); + + } + + public void testSetResolutionHeight_Pair() { + msg.setResolutionHeight(176); + assertEquals(176, (int)msg.getResolutionHeight()); + + } }
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java index 4ebd7f467..ad6e5a4ac 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java @@ -3,6 +3,7 @@ package com.smartdevicelink.test.rpc.datatypes; import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.LightCapabilities; import com.smartdevicelink.proxy.rpc.LightControlCapabilities; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; import com.smartdevicelink.test.Validator; @@ -13,6 +14,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -30,6 +32,7 @@ public class LightControlCapabilitiesTests extends TestCase { msg.setModuleName(Test.GENERAL_STRING); msg.setSupportedLights(Test.GENERAL_LIGHTCAPABILITIES_LIST); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); } /** @@ -39,10 +42,12 @@ public class LightControlCapabilitiesTests extends TestCase { // Test Values String moduleName = msg.getModuleName(); List<LightCapabilities> supportedLights = msg.getSupportedLights(); + ModuleInfo info = msg.getModuleInfo(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); assertEquals(Test.MATCH, Test.GENERAL_LIGHTCAPABILITIES_LIST.size(), supportedLights.size()); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); assertTrue(Test.TRUE, Validator.validateLightCapabilitiesList(Test.GENERAL_LIGHTCAPABILITIES_LIST, supportedLights)); @@ -52,6 +57,7 @@ public class LightControlCapabilitiesTests extends TestCase { assertNull(Test.NULL, msg.getModuleName()); assertNull(Test.NULL, msg.getSupportedLights()); + assertNull(Test.NULL, msg.getModuleInfo()); } public void testJson() { @@ -60,6 +66,7 @@ public class LightControlCapabilitiesTests extends TestCase { try { reference.put(LightControlCapabilities.KEY_MODULE_NAME, Test.GENERAL_STRING); reference.put(LightControlCapabilities.KEY_SUPPORTED_LIGHTS, Test.GENERAL_LIGHTCAPABILITIES_LIST); + reference.put(LightControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -75,7 +82,14 @@ public class LightControlCapabilitiesTests extends TestCase { for (LightCapabilities lc : lcReference) { assertTrue(Validator.validateLightCapabilities(lc, new LightCapabilities(JsonRPCMarshaller.deserializeJSONObject(lsArray.getJSONObject(i++))))); } - } else { + } else if(key.equals(LightControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } + else { assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); } } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java index b553587ad..7f4a78b27 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java @@ -39,6 +39,7 @@ public class ModuleDataTests extends TestCase { msg.setAudioControlData(Test.GENERAL_AUDIOCONTROLDATA); msg.setHmiSettingsControlData(Test.GENERAL_HMISETTINGSCONTROLDATA); msg.setLightControlData(Test.GENERAL_LIGHTCONTROLDATA); + msg.setModuleId(Test.GENERAL_STRING); } /** @@ -53,6 +54,7 @@ public class ModuleDataTests extends TestCase { AudioControlData audioControlData = msg.getAudioControlData(); HMISettingsControlData hmiSettingsControlData = msg.getHmiSettingsControlData(); LightControlData lightControlData = msg.getLightControlData(); + String moduleId = msg.getModuleId(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, moduleType); @@ -62,6 +64,7 @@ public class ModuleDataTests extends TestCase { assertTrue(Test.TRUE, Validator.validateAudioControlData(Test.GENERAL_AUDIOCONTROLDATA, audioControlData)); assertTrue(Test.TRUE, Validator.validateHMISettingsControlData(Test.GENERAL_HMISETTINGSCONTROLDATA, hmiSettingsControlData)); assertTrue(Test.TRUE, Validator.validateLightControlData(Test.GENERAL_LIGHTCONTROLDATA, lightControlData)); + assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleId); // Invalid/Null Tests ModuleData msg = new ModuleData(); @@ -74,6 +77,7 @@ public class ModuleDataTests extends TestCase { assertNull(Test.NULL, msg.getAudioControlData()); assertNull(Test.NULL, msg.getHmiSettingsControlData()); assertNull(Test.NULL, msg.getLightControlData()); + assertNull(Test.NULL, msg.getModuleId()); } public void testJson() { @@ -87,6 +91,7 @@ public class ModuleDataTests extends TestCase { reference.put(ModuleData.KEY_AUDIO_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_AUDIOCONTROLDATA.getStore())); reference.put(ModuleData.KEY_HMI_SETTINGS_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_HMISETTINGSCONTROLDATA.getStore())); reference.put(ModuleData.KEY_LIGHT_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_LIGHTCONTROLDATA.getStore())); + reference.put(ModuleData.KEY_MODULE_ID, Test.GENERAL_STRING); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java new file mode 100644 index 000000000..282e43b4f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleInfoTests.java @@ -0,0 +1,70 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Grid; +import com.smartdevicelink.proxy.rpc.ModuleInfo; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +public class ModuleInfoTests extends TestCase { + private ModuleInfo msg; + + @Override + public void setUp() { + msg = new ModuleInfo(); + msg.setModuleId(Test.GENERAL_STRING); + msg.setModuleLocation(Test.GENERAL_GRID); + msg.setModuleServiceArea(Test.GENERAL_GRID); + msg.setMultipleAccessAllowance(Test.GENERAL_BOOLEAN); + } + + public void testRpcValues() { + String id = msg.getModuleId(); + Grid loc = msg.getModuleLocation(); + Grid area = msg.getModuleServiceArea(); + boolean isAllowed = msg.getMultipleAccessAllowance(); + + //valid tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, id); + assertEquals(Test.MATCH, Test.GENERAL_GRID, loc); + assertEquals(Test.MATCH, Test.GENERAL_GRID, area); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, isAllowed); + + //null test + ModuleInfo msg = new ModuleInfo(); + assertNull(Test.NULL, msg.getModuleId()); + assertNull(Test.NULL, msg.getModuleLocation()); + assertNull(Test.NULL, msg.getModuleServiceArea()); + assertNull(Test.NULL, msg.getMultipleAccessAllowance()); + + //test required params constructor + ModuleInfo msg2 = new ModuleInfo(Test.GENERAL_STRING); + assertEquals(Test.MATCH, msg2.getModuleId(), Test.GENERAL_STRING); + } + + public void testJson() { + JSONObject original = new JSONObject(); + try { + original.put(ModuleInfo.KEY_MODULE_ID, Test.GENERAL_STRING); + original.put(ModuleInfo.KEY_MODULE_LOCATION, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_GRID.getStore())); + original.put(ModuleInfo.KEY_MODULE_SERVICE_AREA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_GRID.getStore())); + original.put(ModuleInfo.KEY_MULTIPLE_ACCESS_ALLOWED, Test.GENERAL_BOOLEAN); + + JSONObject serialized = msg.serializeJSON(); + assertEquals(Test.MATCH, original.length(), serialized.length()); + + Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(original); + Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(serialized); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java index a525bdb23..a65a7deef 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java @@ -1,14 +1,18 @@ package com.smartdevicelink.test.rpc.datatypes; +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.ModuleInfo; import com.smartdevicelink.proxy.rpc.RadioControlCapabilities; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; import junit.framework.TestCase; import org.json.JSONException; import org.json.JSONObject; +import java.util.Hashtable; import java.util.Iterator; /** @@ -36,6 +40,7 @@ public class RadioControlCapabilitiesTests extends TestCase{ msg.setHdRadioEnableAvailable(Test.GENERAL_BOOLEAN); msg.setSiriusXMRadioAvailable(Test.GENERAL_BOOLEAN); msg.setSisDataAvailable(Test.GENERAL_BOOLEAN); + msg.setModuleInfo(Test.GENERAL_MODULE_INFO); msg.setAvailableHdChannelsAvailable(Test.GENERAL_BOOLEAN); } @@ -57,6 +62,7 @@ public class RadioControlCapabilitiesTests extends TestCase{ boolean hdRadioEnableAvailable = msg.getHdRadioEnableAvailable(); boolean siriusXMRadioAvailable = msg.getSiriusXMRadioAvailable(); boolean sisDataAvailable = msg.getSisDataAvailable(); + ModuleInfo info = msg.getModuleInfo(); boolean availableHdChannelsAvailable = msg.getAvailableHdChannelsAvailable(); @@ -74,6 +80,7 @@ public class RadioControlCapabilitiesTests extends TestCase{ assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, hdRadioEnableAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, siriusXMRadioAvailable); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, sisDataAvailable); + assertEquals(Test.MATCH, Test.GENERAL_MODULE_INFO, info); assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, availableHdChannelsAvailable); // Invalid/Null Tests @@ -93,6 +100,7 @@ public class RadioControlCapabilitiesTests extends TestCase{ assertNull(Test.NULL, msg.getHdRadioEnableAvailable()); assertNull(Test.NULL, msg.getSiriusXMRadioAvailable()); assertNull(Test.NULL, msg.getSisDataAvailable()); + assertNull(Test.NULL, msg.getModuleInfo()); assertNull(Test.NULL, msg.getAvailableHdChannelsAvailable()); } @@ -113,6 +121,7 @@ public class RadioControlCapabilitiesTests extends TestCase{ reference.put(RadioControlCapabilities.KEY_HD_RADIO_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(RadioControlCapabilities.KEY_SIRIUS_XM_RADIO_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(RadioControlCapabilities.KEY_SIS_DATA_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_MODULE_INFO, Test.JSON_MODULE_INFO); reference.put(RadioControlCapabilities.KEY_AVAILABLE_HD_CHANNELS_AVAILABLE, Test.GENERAL_BOOLEAN); JSONObject underTest = msg.serializeJSON(); @@ -121,8 +130,15 @@ public class RadioControlCapabilitiesTests extends TestCase{ Iterator<?> iterator = reference.keys(); while(iterator.hasNext()){ String key = (String) iterator.next(); - - assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + if (key.equals(RadioControlCapabilities.KEY_MODULE_INFO)) { + JSONObject o1 = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject o2 = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(o1); + Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(o2); + assertTrue(Test.TRUE, Validator.validateModuleInfo(new ModuleInfo(h1), new ModuleInfo(h2))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } } } catch(JSONException e){ diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java new file mode 100644 index 000000000..847564adb --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationCapabilityTests.java @@ -0,0 +1,99 @@ +package com.smartdevicelink.test.rpc.datatypes; + + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.SeatLocation; +import com.smartdevicelink.proxy.rpc.SeatLocationCapability; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +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 SeatLocationCapabilityTests extends TestCase { + + private SeatLocationCapability msg; + + @Override + public void setUp() { + msg = new SeatLocationCapability(); + msg.setCols(Test.GENERAL_INT); + msg.setRows(Test.GENERAL_INT); + msg.setLevels(Test.GENERAL_INT); + msg.setSeats(Test.GENERAL_SEAT_LIST); + } + + public void testRpcValues() { + int row = msg.getRows(); + int col = msg.getCols(); + int level = msg.getLevels(); + List<SeatLocation> seats = msg.getSeatLocations(); + + //valid tests + assertEquals(Test.MATCH, row, Test.GENERAL_INT); + assertEquals(Test.MATCH, col, Test.GENERAL_INT); + assertEquals(Test.MATCH, level, Test.GENERAL_INT); + assertEquals(Test.MATCH, seats.size(), Test.GENERAL_SEAT_LIST.size()); + for (int i = 0; i < Test.GENERAL_SEAT_LIST.size(); i++) { + assertTrue(Test.TRUE, Validator.validateGrid(Test.GENERAL_SEAT_LIST.get(i).getGrid(), seats.get(i).getGrid())); + } + + //null tests + SeatLocationCapability msg = new SeatLocationCapability(); + assertNull(Test.NULL, msg.getCols()); + assertNull(Test.NULL, msg.getRows()); + assertNull(Test.NULL, msg.getLevels()); + assertNull(Test.NULL, msg.getSeatLocations()); + } + + public void testJson() { + JSONObject original = new JSONObject(); + try { + original.put(SeatLocationCapability.KEY_COLS, Test.GENERAL_INT); + original.put(SeatLocationCapability.KEY_ROWS, Test.GENERAL_INT); + original.put(SeatLocationCapability.KEY_LEVELS, Test.GENERAL_INT); + original.put(SeatLocationCapability.KEY_SEATS, Test.JSON_SEAT_LOCATIONS); + + JSONObject serialized = msg.serializeJSON(); + assertEquals(serialized.length(), original.length()); + + Iterator<String> iter = original.keys(); + String key = ""; + while (iter.hasNext()) { + key = iter.next(); + if (key.equals(SeatLocationCapability.KEY_COLS)) { + int i1 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(original)).getCols(); + int i2 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(serialized)).getCols(); + assertEquals(Test.MATCH, i1, i2); + } else if (key.equals(SeatLocationCapability.KEY_ROWS)) { + int i1 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(original)).getRows(); + int i2 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(serialized)).getRows(); + assertEquals(Test.MATCH, i1, i2); + } else if (key.equals(SeatLocationCapability.KEY_LEVELS)) { + int i1 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(original)).getLevels(); + int i2 = new SeatLocationCapability(JsonRPCMarshaller.deserializeJSONObject(serialized)).getLevels(); + assertEquals(Test.MATCH, i1, i2); + } else if (key.equals(SeatLocationCapability.KEY_SEATS)) { + JSONArray arr1 = JsonUtils.readJsonArrayFromJsonObject(original, key); + JSONArray arr2 = JsonUtils.readJsonArrayFromJsonObject(serialized, key); + assertEquals(Test.MATCH, arr1.length(), arr2.length()); + for (int i = 0; i < Test.GENERAL_SEAT_LIST.size(); i++) { + Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(arr1.getJSONObject(i)); + Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(arr2.getJSONObject(i)); + assertTrue(Test.MATCH, Validator.validateSeatLocation(new SeatLocation(h1), new SeatLocation(h2))); + } + } + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationTests.java new file mode 100644 index 000000000..6a102fc66 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatLocationTests.java @@ -0,0 +1,48 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Grid; +import com.smartdevicelink.proxy.rpc.SeatLocation; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +public class SeatLocationTests extends TestCase { + + private SeatLocation msg; + + @Override + public void setUp() { + msg = new SeatLocation(); + msg.setGrid(Test.GENERAL_GRID); + } + + public void testRpcValues() { + Grid grid = msg.getGrid(); + + //valid test + assertTrue(Validator.validateGrid(Test.GENERAL_GRID, grid)); + + //null test + SeatLocation msg = new SeatLocation(); + assertNull(Test.NULL, msg.getGrid()); + } + + public void testJson() { + JSONObject original = new JSONObject(); + try { + original.put(SeatLocation.KEY_GRID, Test.GENERAL_GRID); + + JSONObject serialized = msg.serializeJSON(); + assertEquals(serialized.length(), original.length()); + assertTrue(Test.TRUE, Validator.validateSeatLocation(new SeatLocation(JsonRPCMarshaller.deserializeJSONObject(original)), + new SeatLocation(JsonRPCMarshaller.deserializeJSONObject(serialized)))); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonCapabilitiesTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonCapabilitiesTest.java index f5d0a9217..b422ce627 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonCapabilitiesTest.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonCapabilitiesTest.java @@ -27,6 +27,7 @@ public class SoftButtonCapabilitiesTest extends TestCase { msg.setShortPressAvailable(Test.GENERAL_BOOLEAN); msg.setLongPressAvailable(Test.GENERAL_BOOLEAN); msg.setUpDownAvailable(Test.GENERAL_BOOLEAN); + msg.setTextSupported(Test.GENERAL_BOOLEAN); } /** @@ -38,12 +39,14 @@ public class SoftButtonCapabilitiesTest extends TestCase { Boolean updown = msg.getUpDownAvailable(); Boolean longPress = msg.getLongPressAvailable(); Boolean shortPress = msg.getShortPressAvailable(); + Boolean textSupported = msg.getTextSupported(); // Valid Tests assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, imageSupp); assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, updown); assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, longPress); assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, shortPress); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, textSupported); // Invalid/Null Tests SoftButtonCapabilities msg = new SoftButtonCapabilities(); @@ -53,6 +56,7 @@ public class SoftButtonCapabilitiesTest extends TestCase { assertNull(Test.NULL, msg.getLongPressAvailable()); assertNull(Test.NULL, msg.getShortPressAvailable()); assertNull(Test.NULL, msg.getUpDownAvailable()); + assertNull(Test.NULL, msg.getTextSupported()); } public void testJson() { @@ -63,6 +67,7 @@ public class SoftButtonCapabilitiesTest extends TestCase { reference.put(SoftButtonCapabilities.KEY_UP_DOWN_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(SoftButtonCapabilities.KEY_LONG_PRESS_AVAILABLE, Test.GENERAL_BOOLEAN); reference.put(SoftButtonCapabilities.KEY_SHORT_PRESS_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SoftButtonCapabilities.KEY_TEXT_SUPPORTED, Test.GENERAL_BOOLEAN); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java index bc50907db..c6a3cfa0e 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java @@ -4,6 +4,7 @@ import android.util.Log; import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.AppServicesCapabilities; +import com.smartdevicelink.proxy.rpc.DisplayCapability; import com.smartdevicelink.proxy.rpc.NavigationCapability; import com.smartdevicelink.proxy.rpc.PhoneCapability; import com.smartdevicelink.proxy.rpc.RemoteControlCapabilities; @@ -12,14 +13,13 @@ import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; import com.smartdevicelink.test.JsonUtils; import com.smartdevicelink.test.Test; 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; /** * This is a unit test class for the SmartDeviceLink library project class : @@ -38,7 +38,7 @@ public class SystemCapabilityTests extends TestCase { msg.setCapabilityForType(SystemCapabilityType.PHONE_CALL, Test.GENERAL_PHONECAPABILITY); msg.setCapabilityForType(SystemCapabilityType.REMOTE_CONTROL, Test.GENERAL_REMOTECONTROLCAPABILITIES); msg.setCapabilityForType(SystemCapabilityType.APP_SERVICES, Test.GENERAL_APP_SERVICE_CAPABILITIES); - + msg.setCapabilityForType(SystemCapabilityType.DISPLAYS, Test.GENERAL_DISPLAYCAPABILITY_LIST); } /** @@ -51,6 +51,7 @@ public class SystemCapabilityTests extends TestCase { PhoneCapability testPhoneCapability = (PhoneCapability) msg.getCapabilityForType(SystemCapabilityType.PHONE_CALL); RemoteControlCapabilities testRemoteControlCapabilities = (RemoteControlCapabilities) msg.getCapabilityForType(SystemCapabilityType.REMOTE_CONTROL); AppServicesCapabilities testAppServicesCapabilities = (AppServicesCapabilities) msg.getCapabilityForType(SystemCapabilityType.APP_SERVICES); + List<DisplayCapability> displayCapabilities = (List<DisplayCapability>) msg.getCapabilityForType(SystemCapabilityType.DISPLAYS); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_SYSTEMCAPABILITYTYPE, testType); @@ -59,6 +60,10 @@ public class SystemCapabilityTests extends TestCase { assertTrue(Test.TRUE, Validator.validateRemoteControlCapabilities(Test.GENERAL_REMOTECONTROLCAPABILITIES, testRemoteControlCapabilities)); assertTrue(Test.TRUE, Validator.validateAppServiceCapabilities(Test.GENERAL_APP_SERVICE_CAPABILITIES, testAppServicesCapabilities)); + for(int i = 0; i < Test.GENERAL_DISPLAYCAPABILITY_LIST.size(); i++){ + assertTrue(Test.TRUE, Validator.validateDisplayCapability(Test.GENERAL_DISPLAYCAPABILITY_LIST.get(i), displayCapabilities.get(i))); + } + // Invalid/Null Tests SystemCapability msg = new SystemCapability(); assertNotNull(Test.NOT_NULL, msg); @@ -68,6 +73,7 @@ public class SystemCapabilityTests extends TestCase { assertNull(Test.NULL, msg.getCapabilityForType(SystemCapabilityType.PHONE_CALL)); assertNull(Test.NULL, msg.getCapabilityForType(SystemCapabilityType.REMOTE_CONTROL)); assertNull(Test.NULL, msg.getCapabilityForType(SystemCapabilityType.APP_SERVICES)); + assertNull(Test.NULL, msg.getCapabilityForType(SystemCapabilityType.DISPLAYS)); } public void testJson() { @@ -79,6 +85,7 @@ public class SystemCapabilityTests extends TestCase { reference.put(SystemCapability.KEY_PHONE_CAPABILITY, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_PHONECAPABILITY.getStore())); reference.put(SystemCapability.KEY_REMOTE_CONTROL_CAPABILITY, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_REMOTECONTROLCAPABILITIES.getStore())); reference.put(SystemCapability.KEY_APP_SERVICES_CAPABILITIES, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_APP_SERVICE_CAPABILITIES.getStore())); + reference.put(SystemCapability.KEY_DISPLAY_CAPABILITIES, Test.JSON_DISPLAYCAPABILITY_LIST); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -105,7 +112,7 @@ public class SystemCapabilityTests extends TestCase { Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(objectEquals); Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); assertTrue(Test.TRUE, Validator.validateRemoteControlCapabilities( new RemoteControlCapabilities(hashReference), new RemoteControlCapabilities(hashTest))); - }else if(key.equals(SystemCapability.KEY_APP_SERVICES_CAPABILITIES)){ + } else if(key.equals(SystemCapability.KEY_APP_SERVICES_CAPABILITIES)){ JSONObject objectEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(objectEquals); @@ -113,6 +120,16 @@ public class SystemCapabilityTests extends TestCase { Log.i("TEST REF", hashReference.toString()); Log.i("TEST TEST", hashTest.toString()); assertTrue(Test.TRUE, Validator.validateAppServiceCapabilities( new AppServicesCapabilities(hashReference), new AppServicesCapabilities(hashTest))); + } else if(key.equals(SystemCapability.KEY_DISPLAY_CAPABILITIES)){ + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.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(Test.TRUE, Validator.validateDisplayCapability(new DisplayCapability(hashReference), new DisplayCapability(hashTest))); + } } else{ assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemplateConfigurationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemplateConfigurationTests.java new file mode 100644 index 000000000..fe505218c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemplateConfigurationTests.java @@ -0,0 +1,91 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.TemplateColorScheme; +import com.smartdevicelink.proxy.rpc.TemplateConfiguration; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import junit.framework.TestCase; +import org.json.JSONException; +import org.json.JSONObject; +import java.util.Hashtable; +import java.util.Iterator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.TemplateConfiguration} + */ +public class TemplateConfigurationTests extends TestCase { + + private TemplateConfiguration msg; + + @Override + public void setUp(){ + msg = new TemplateConfiguration(); + + msg.setTemplate(Test.GENERAL_STRING); + msg.setDayColorScheme(Test.GENERAL_DAYCOLORSCHEME); + msg.setNightColorScheme(Test.GENERAL_NIGHTCOLORSCHEME); + + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String testTemplate = msg.getTemplate(); + TemplateColorScheme testDayColorScheme = msg.getDayColorScheme(); + TemplateColorScheme testNightColorScheme = msg.getNightColorScheme(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, testTemplate); + assertEquals(Test.MATCH, Test.GENERAL_DAYCOLORSCHEME, testDayColorScheme); + assertEquals(Test.MATCH, Test.GENERAL_NIGHTCOLORSCHEME, testNightColorScheme); + + // Invalid/Null Tests + TemplateConfiguration msg = new TemplateConfiguration(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getTemplate()); + assertNull(Test.NULL, msg.getDayColorScheme()); + assertNull(Test.NULL, msg.getNightColorScheme()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(TemplateConfiguration.KEY_TEMPLATE, Test.GENERAL_STRING); + reference.put(TemplateConfiguration.KEY_DAY_COLOR_SCHEME, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_DAYCOLORSCHEME.getStore())); + reference.put(TemplateConfiguration.KEY_NIGHT_COLOR_SCHEME, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_NIGHTCOLORSCHEME.getStore())); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while(iterator.hasNext()){ + String key = (String) iterator.next(); + + if (key.equals(TemplateConfiguration.KEY_DAY_COLOR_SCHEME)) { + JSONObject objectEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(objectEquals); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(new TemplateColorScheme(hashReference), new TemplateColorScheme(hashTest))); + } else if (key.equals(TemplateConfiguration.KEY_NIGHT_COLOR_SCHEME)) { + JSONObject objectEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(reference, key); + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(objectEquals); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(new TemplateColorScheme(hashReference), new TemplateColorScheme(hashTest))); + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } + } + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleDataResultTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleDataResultTest.java index 5b982fe97..dd84c8181 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleDataResultTest.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleDataResultTest.java @@ -23,6 +23,7 @@ public class VehicleDataResultTest extends TestCase { msg.setDataType(Test.GENERAL_VEHICLEDATATYPE); msg.setResultCode(Test.GENERAL_VEHICLEDATARESULTCODE); + msg.setOEMCustomVehicleDataType(Test.GENERAL_OEM_CUSTOM_VEHICLE_DATA_NAME); } /** @@ -32,10 +33,12 @@ public class VehicleDataResultTest extends TestCase { // Test Values VehicleDataResultCode result = msg.getResultCode(); VehicleDataType type = msg.getDataType(); + String oemCustomDataType = msg.getOEMCustomVehicleDataType(); // Valid Tests assertEquals(Test.MATCH, Test.GENERAL_VEHICLEDATARESULTCODE, result); assertEquals(Test.MATCH, Test.GENERAL_VEHICLEDATATYPE, type); + assertEquals(Test.MATCH, Test.GENERAL_OEM_CUSTOM_VEHICLE_DATA_NAME, oemCustomDataType); // Invalid/Null Tests VehicleDataResult msg = new VehicleDataResult(); @@ -43,6 +46,7 @@ public class VehicleDataResultTest extends TestCase { assertNull(Test.NULL, msg.getDataType()); assertNull(Test.NULL, msg.getResultCode()); + assertNull(Test.NULL, msg.getOEMCustomVehicleDataType()); } public void testJson() { @@ -51,6 +55,7 @@ public class VehicleDataResultTest extends TestCase { try { reference.put(VehicleDataResult.KEY_RESULT_CODE, Test.GENERAL_VEHICLEDATARESULTCODE); reference.put(VehicleDataResult.KEY_DATA_TYPE, Test.GENERAL_VEHICLEDATATYPE); + reference.put(VehicleDataResult.KEY_OEM_CUSTOM_DATA_TYPE, Test.GENERAL_OEM_CUSTOM_VEHICLE_DATA_NAME); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VideoStreamingCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VideoStreamingCapabilityTests.java index 54cfc1a22..808429d2f 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VideoStreamingCapabilityTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VideoStreamingCapabilityTests.java @@ -30,6 +30,9 @@ public class VideoStreamingCapabilityTests extends TestCase { msg.setPreferredResolution(Test.GENERAL_IMAGERESOLUTION); msg.setMaxBitrate(Test.GENERAL_INT); msg.setIsHapticSpatialDataSupported(Test.GENERAL_BOOLEAN); + msg.setDiagonalScreenSize(Test.GENERAL_DOUBLE); + msg.setPixelPerInch(Test.GENERAL_DOUBLE); + msg.setScale(Test.GENERAL_DOUBLE); } /** @@ -41,12 +44,18 @@ public class VideoStreamingCapabilityTests extends TestCase { ImageResolution res = msg.getPreferredResolution(); Integer maxBitrate = msg.getMaxBitrate(); Boolean isHapticSpatialDataSupported = msg.getIsHapticSpatialDataSupported(); + Double diagonalScreenSize = msg.getDiagonalScreenSize(); + Double pixelPerInch = msg.getPixelPerInch(); + Double scale = msg.getScale(); // Valid Tests assertEquals(Test.MATCH, (List<VideoStreamingFormat>) Test.GENERAL_VIDEOSTREAMINGFORMAT_LIST, format); assertEquals(Test.MATCH, (ImageResolution) Test.GENERAL_IMAGERESOLUTION, res); assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, maxBitrate); assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, isHapticSpatialDataSupported); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, diagonalScreenSize); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, pixelPerInch); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, scale); // Invalid/Null Tests VideoStreamingCapability msg = new VideoStreamingCapability(); @@ -56,6 +65,9 @@ public class VideoStreamingCapabilityTests extends TestCase { assertNull(Test.NULL, msg.getPreferredResolution()); assertNull(Test.NULL, msg.getSupportedFormats()); assertNull(Test.NULL, msg.getIsHapticSpatialDataSupported()); + assertNull(Test.NULL, msg.getDiagonalScreenSize()); + assertNull(Test.NULL, msg.getPixelPerInch()); + assertNull(Test.NULL, msg.getScale()); } public void testJson() { @@ -66,6 +78,9 @@ public class VideoStreamingCapabilityTests extends TestCase { reference.put(VideoStreamingCapability.KEY_PREFERRED_RESOLUTION, Test.GENERAL_IMAGERESOLUTION); reference.put(VideoStreamingCapability.KEY_SUPPORTED_FORMATS, Test.GENERAL_VIDEOSTREAMINGFORMAT_LIST); reference.put(VideoStreamingCapability.KEY_HAPTIC_SPATIAL_DATA_SUPPORTED, Test.GENERAL_BOOLEAN); + reference.put(VideoStreamingCapability.KEY_DIAGONAL_SCREEN_SIZE, Test.GENERAL_DOUBLE); + reference.put(VideoStreamingCapability.KEY_PIXEL_PER_INCH, Test.GENERAL_DOUBLE); + reference.put(VideoStreamingCapability.KEY_SCALE, Test.GENERAL_DOUBLE); JSONObject underTest = msg.serializeJSON(); assertEquals(Test.MATCH, reference.length(), underTest.length()); @@ -87,6 +102,9 @@ public class VideoStreamingCapabilityTests extends TestCase { for(VideoStreamingFormat vsf : vsfReference){ assertTrue(Validator.validateSupportedFormats(vsf, new VideoStreamingFormat(JsonRPCMarshaller.deserializeJSONObject(vsfArray.getJSONObject(i++))))); } + } else if (key.equals(VideoStreamingCapability.KEY_DIAGONAL_SCREEN_SIZE) || key.equals(VideoStreamingCapability.KEY_PIXEL_PER_INCH) || + key.equals(VideoStreamingCapability.KEY_SCALE)) { + assertEquals(JsonUtils.readDoubleFromJsonObject(reference, key), JsonUtils.readDoubleFromJsonObject(underTest, key), 0.0005); } } } catch (JSONException e) { diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WindowCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WindowCapabilityTests.java new file mode 100644 index 000000000..07d2cbd49 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WindowCapabilityTests.java @@ -0,0 +1,190 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.ButtonCapabilities; +import com.smartdevicelink.proxy.rpc.ImageField; +import com.smartdevicelink.proxy.rpc.SoftButtonCapabilities; +import com.smartdevicelink.proxy.rpc.TextField; +import com.smartdevicelink.proxy.rpc.WindowCapability; +import com.smartdevicelink.proxy.rpc.enums.ImageType; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import junit.framework.TestCase; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.WindowCapability} + */ +public class WindowCapabilityTests extends TestCase { + + private WindowCapability msg; + + @Override + public void setUp() { + msg = new WindowCapability(); + msg.setWindowID(Test.GENERAL_INT); + msg.setTextFields(Test.GENERAL_TEXTFIELD_LIST); + msg.setImageFields(Test.GENERAL_IMAGEFIELD_LIST); + msg.setImageTypeSupported(Test.GENERAL_IMAGE_TYPE_LIST); + msg.setTemplatesAvailable(Test.GENERAL_STRING_LIST); + msg.setNumCustomPresetsAvailable(Test.GENERAL_INT); + msg.setButtonCapabilities(Test.GENERAL_BUTTONCAPABILITIES_LIST); + msg.setSoftButtonCapabilities(Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + int windowID = msg.getWindowID(); + List<TextField> textFields = msg.getTextFields(); + List<ImageField> imageFields = msg.getImageFields(); + List<ImageType> imageTypeSupported = msg.getImageTypeSupported(); + List<String> templatesAvailable = msg.getTemplatesAvailable(); + int numCustomPresetsAvailable = msg.getNumCustomPresetsAvailable(); + List<ButtonCapabilities> buttonCapabilities = msg.getButtonCapabilities(); + List<SoftButtonCapabilities> softButtonCapabilities = msg.getSoftButtonCapabilities(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, windowID); + assertEquals(Test.MATCH, Test.GENERAL_TEXTFIELD_LIST.size(), textFields.size()); + assertEquals(Test.MATCH, Test.GENERAL_IMAGEFIELD_LIST.size(), imageFields.size()); + assertEquals(Test.MATCH, Test.GENERAL_IMAGE_TYPE_LIST.size(), imageTypeSupported.size()); + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.size(), templatesAvailable.size()); + assertEquals(Test.MATCH, Test.GENERAL_INT, numCustomPresetsAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BUTTONCAPABILITIES_LIST.size(), buttonCapabilities.size()); + assertEquals(Test.MATCH, Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST.size(), softButtonCapabilities.size()); + + for (int i = 0; i < Test.GENERAL_TEXTFIELD_LIST.size(); i++) { + assertTrue(Test.TRUE, Validator.validateTextFields(Test.GENERAL_TEXTFIELD_LIST.get(i), textFields.get(i))); + } + + for (int i = 0; i < Test.GENERAL_IMAGEFIELD_LIST.size(); i++) { + assertTrue(Test.TRUE, Validator.validateImageFields(Test.GENERAL_IMAGEFIELD_LIST.get(i), imageFields.get(i))); + } + + for (int i = 0; i < Test.GENERAL_IMAGE_TYPE_LIST.size(); i++) { + assertEquals(Test.MATCH, Test.GENERAL_IMAGE_TYPE_LIST.get(i), imageTypeSupported.get(i)); + } + + for (int i = 0; i < Test.GENERAL_STRING_LIST.size(); i++) { + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.get(i), templatesAvailable.get(i)); + } + + assertTrue(Test.TRUE, Validator.validateButtonCapabilities(Test.GENERAL_BUTTONCAPABILITIES_LIST, buttonCapabilities)); + assertTrue(Test.TRUE, Validator.validateSoftButtonCapabilities(Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST, softButtonCapabilities)); + + // Invalid/Null Tests + WindowCapability msg = new WindowCapability(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getWindowID()); + assertNull(Test.NULL, msg.getTextFields()); + assertNull(Test.NULL, msg.getImageFields()); + assertNull(Test.NULL, msg.getImageTypeSupported()); + assertNull(Test.NULL, msg.getTemplatesAvailable()); + assertNull(Test.NULL, msg.getNumCustomPresetsAvailable()); + assertNull(Test.NULL, msg.getButtonCapabilities()); + assertNull(Test.NULL, msg.getSoftButtonCapabilities()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(WindowCapability.KEY_WINDOW_ID, Test.GENERAL_INT); + reference.put(WindowCapability.KEY_TEXT_FIELDS, Test.JSON_TEXTFIELDS); + reference.put(WindowCapability.KEY_IMAGE_FIELDS, Test.JSON_IMAGEFIELDS); + reference.put(WindowCapability.KEY_IMAGE_TYPE_SUPPORTED, Test.JSON_IMAGE_TYPE_SUPPORTED); + reference.put(WindowCapability.KEY_TEMPLATES_AVAILABLE, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + reference.put(WindowCapability.KEY_NUM_CUSTOM_PRESETS_AVAILABLE, Test.GENERAL_INT); + reference.put(WindowCapability.KEY_BUTTON_CAPABILITIES, Test.JSON_BUTTONCAPABILITIES); + reference.put(WindowCapability.KEY_SOFT_BUTTON_CAPABILITIES, Test.JSON_SOFTBUTTONCAPABILITIES); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while (iterator.hasNext()) { + String key = (String) iterator.next(); + + if (key.equals(WindowCapability.KEY_IMAGE_FIELDS)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.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(Test.TRUE, Validator.validateImageFields(new ImageField(hashReference), new ImageField(hashTest))); + } + } else if (key.equals(WindowCapability.KEY_TEXT_FIELDS)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.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(Test.TRUE, Validator.validateTextFields(new TextField(hashReference), new TextField(hashTest))); + } + } else if (key.equals(WindowCapability.KEY_TEMPLATES_AVAILABLE)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.MATCH, referenceArray.length(), underTestArray.length()); + assertTrue(Test.TRUE, Validator.validateStringList(JsonUtils.readStringListFromJsonObject(reference, key), JsonUtils.readStringListFromJsonObject(underTest, key))); + } else if (key.equals(WindowCapability.KEY_BUTTON_CAPABILITIES)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.MATCH, referenceArray.length(), underTestArray.length()); + + List<ButtonCapabilities> referenceList = new ArrayList<ButtonCapabilities>(); + List<ButtonCapabilities> testList = new ArrayList<ButtonCapabilities>(); + for (int i = 0; i < referenceArray.length(); i++) { + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(referenceArray.getJSONObject(i)); + referenceList.add(new ButtonCapabilities(hashReference)); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(underTestArray.getJSONObject(i)); + testList.add(new ButtonCapabilities(hashTest)); + } + assertTrue(Test.TRUE, Validator.validateButtonCapabilities(referenceList, testList)); + } else if (key.equals(WindowCapability.KEY_SOFT_BUTTON_CAPABILITIES)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.MATCH, referenceArray.length(), underTestArray.length()); + + List<SoftButtonCapabilities> referenceList = new ArrayList<SoftButtonCapabilities>(); + List<SoftButtonCapabilities> testList = new ArrayList<SoftButtonCapabilities>(); + for (int i = 0; i < referenceArray.length(); i++) { + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(referenceArray.getJSONObject(i)); + referenceList.add(new SoftButtonCapabilities(hashReference)); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(underTestArray.getJSONObject(i)); + testList.add(new SoftButtonCapabilities(hashTest)); + } + assertTrue(Test.TRUE, Validator.validateSoftButtonCapabilities(referenceList, testList)); + } else if (key.equals(WindowCapability.KEY_IMAGE_TYPE_SUPPORTED)) { + List<String> referenceList = JsonUtils.readStringListFromJsonObject(reference, key); + List<String> underTestList = JsonUtils.readStringListFromJsonObject(underTest, key); + + assertEquals(Test.MATCH, referenceList.size(), underTestList.size()); + for (int i = 0; i < referenceList.size(); i++) { + assertEquals(Test.MATCH, referenceList.get(i), underTestList.get(i)); + } + } else { + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WindowTypeCapabilitiesTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WindowTypeCapabilitiesTest.java new file mode 100644 index 000000000..4b9c767e3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WindowTypeCapabilitiesTest.java @@ -0,0 +1,63 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.WindowTypeCapabilities; +import com.smartdevicelink.proxy.rpc.enums.WindowType; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import junit.framework.TestCase; +import org.json.JSONException; +import org.json.JSONObject; +import java.util.Iterator; + +public class WindowTypeCapabilitiesTest extends TestCase { + + private WindowTypeCapabilities msg; + + @Override + public void setUp() { + msg = new WindowTypeCapabilities(); + + msg.setMaximumNumberOfWindows(Test.GENERAL_INT); + msg.setType(Test.GENERAL_WINDOW_TYPE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + int maximumNumberOfWindows = msg.getMaximumNumberOfWindows(); + WindowType type = msg.getType(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, maximumNumberOfWindows); + assertEquals(Test.MATCH, Test.GENERAL_WINDOW_TYPE, type); + + // Invalid/Null Tests + WindowTypeCapabilities msg = new WindowTypeCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getMaximumNumberOfWindows()); + assertNull(Test.NULL, msg.getType()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(WindowTypeCapabilities.KEY_MAXIMUM_NUMBER_OF_WINDOWS, Test.GENERAL_INT); + reference.put(WindowTypeCapabilities.KEY_TYPE, Test.GENERAL_WINDOW_TYPE); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while (iterator.hasNext()) { + String key = (String) iterator.next(); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key)); + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +}
\ No newline at end of file |