diff options
author | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2019-03-04 11:54:25 -0500 |
---|---|---|
committer | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2019-03-04 11:54:25 -0500 |
commit | 6aa38653411257300a77a885064dc9ddda4cd35f (patch) | |
tree | 72ea420e134ca6ef5d0b937a8656ca657055c6b4 /android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc | |
parent | e59b00f4443f7d3e90c86bae562cde3decd95127 (diff) | |
download | sdl_android-6aa38653411257300a77a885064dc9ddda4cd35f.tar.gz |
Move sdl_android to a subfolder
Diffstat (limited to 'android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc')
329 files changed, 34255 insertions, 0 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCConstructorsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCConstructorsTests.java new file mode 100644 index 000000000..7b497310e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCConstructorsTests.java @@ -0,0 +1,329 @@ +package com.smartdevicelink.test.rpc; + + +import com.smartdevicelink.AndroidTestCase2; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlPullParserFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This is a unit test class for the SmartDeviceLink library project + * It makes sure that for each RPC, all mandatory parameters are set in a constructor + */ + +public class RPCConstructorsTests extends AndroidTestCase2 { + + private final String XML_FILE_NAME = "xml/MOBILE_API.xml"; + private final String RPC_PACKAGE_PREFIX = "com.smartdevicelink.proxy.rpc."; + private Map<String, List<Parameter>> rpcMandatoryParamsMapFromXml; + + private class Parameter { + private String name; + private String type; + private boolean isArray; + + public Parameter(String name, String type, boolean isArray) { + this.name = name; + this.type = type; + this.isArray = isArray; + } + } + + @Override + public void setUp(){ + try { + super.setUp(); + } catch (Exception e) { + e.printStackTrace(); + } + // Map that has keys correspond to the RPC names and values correspond to the + // mandatory params for that RPC. All info are loaded from the RPC spec xml file + rpcMandatoryParamsMapFromXml = getRPCMandatoryParamsMap(XML_FILE_NAME); + + } + + // This method parses the RPC spec xml file and returns a map that has + // keys correspond to the RPC names and values correspond to the mandatory params for that RPC + private Map<String, List<Parameter>> getRPCMandatoryParamsMap(String fileName) { + Map<String, List<Parameter>> rpcMandatoryParamsMap = new HashMap<>(); + try { + InputStream stream = this.mContext.getAssets().open(fileName); + XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance(); + XmlPullParser myParser = xmlFactoryObject.newPullParser(); + myParser.setInput(stream, null); + int event = myParser.getEventType(); + String rpcName = null; + boolean ignoreRPC = false; + while (event != XmlPullParser.END_DOCUMENT) { + String name = myParser.getName(); + switch (event){ + case XmlPullParser.START_TAG: + // Store the RPC name in the map + if(name.equals("function") || name.equals("struct")){ + rpcName = myParser.getAttributeValue(null,"name"); + ignoreRPC = false; + if (name.equals("function") && myParser.getAttributeValue(null, "messagetype").equals("response") && !rpcName.contains("Response")){ + rpcName += "Response"; + } + + // -------------- Exceptional cases because of mismatch between the RPC spec and the Android code -------------- + if(rpcName.equals("SyncMsgVersion")){ + rpcName = "SdlMsgVersion"; + } else if(rpcName.equals("ShowConstantTBTResponse")){ + rpcName = "ShowConstantTbtResponse"; + } else if(rpcName.equals("OASISAddress")) { + rpcName = "OasisAddress"; + } else if(rpcName.equals("ShowConstantTBT")) { + rpcName = "ShowConstantTbt"; + } else if (rpcName.equals("EncodedSyncPData") || rpcName.equals("OnEncodedSyncPData") || rpcName.equals("EncodedSyncPDataResponse") || rpcName.equals("AppInfo")){ + ignoreRPC = true; + } + // ------------------------------------------------------------------------------------------------------------- + + if (!ignoreRPC) { + rpcMandatoryParamsMap.put(rpcName, new ArrayList<Parameter>()); + } + } + // Store the mandatory params for the current RPC in the map + if(name.equals("param") && myParser.getAttributeValue(null, "until") == null && !ignoreRPC){ + boolean mandatory = Boolean.valueOf(myParser.getAttributeValue(null,"mandatory")); + if (mandatory) { + String paramName = myParser.getAttributeValue(null, "name"); + String paramType = myParser.getAttributeValue(null, "type"); + boolean paramIsArray = Boolean.valueOf(myParser.getAttributeValue(null, "array")); + + // -------------- Exceptional cases because of mismatch between the RPC spec and the Android code -------------- + if (paramType.equals("SyncMsgVersion")){ + paramType = "SdlMsgVersion"; + } else if (rpcName.equals("GPSData") && paramType.equals("Float")){ + paramType = "Double"; + } else if (rpcName.equals("TouchEvent") && paramType.equals("Integer") && paramIsArray){ + paramType = "Long"; + } + + if (paramName.equals("syncFileName")){ + paramName = "sdlFileName"; + } else if (paramName.equals("syncMsgVersion")){ + paramName = "sdlMsgVersion"; + } else if (paramName.equals("hmiPermissions")){ + paramName = "hMIPermissions"; + } else if (paramName.equals("resolution")){ + paramName = "imageResolution"; + } else if (paramName.equals("pressureTelltale")){ + paramName = "pressureTellTale"; + } + // ------------------------------------------------------------------------------------------------------------- + + Parameter param = new Parameter(paramName, paramType, paramIsArray); + rpcMandatoryParamsMap.get(rpcName).add(param); + } + } + break; + } + event = myParser.next(); + } + stream.close(); + } catch (IOException | XmlPullParserException e) { + e.printStackTrace(); + } + return rpcMandatoryParamsMap; + } + + // This method makes sure that for every RPC, there is a constructor that has all the mandatory params + // It also checks if there are RPC in the XML file that don't exist in the code + public void testMandatoryParamsMatch() { + // List of RPC names that don't have a constructor that has all mandatory params + List<String> rpcsWithInvalidConstructor = new ArrayList<>(); + + // List of the RPC names that couldn't be found in code + // potentially because of a mismatch between name in the RPC spec xml file and name in code + List<String> rpcsFromXmlNotFoundInCode = new ArrayList<>(); + + // Loop through all RPCs that were loaded from RPC spec XML file + // and make sure that every RPC has a constructor that has all mandatory params + for (String rpcName : rpcMandatoryParamsMapFromXml.keySet()) { + Class aClass; + try { + aClass = Class.forName(RPC_PACKAGE_PREFIX + rpcName); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + rpcsFromXmlNotFoundInCode.add(rpcName); + continue; + } + List<String> mandatoryParamsListFromXML = new ArrayList<>(); + for (Parameter param : rpcMandatoryParamsMapFromXml.get(rpcName)) { + String type = param.type; + // If the param is a list of objects, the type should be like "List<Object>" + if (param.isArray){ + type = String.format("List<%s>", type); + } + mandatoryParamsListFromXML.add(type); + } + List<String> mandatoryParamsListFromCode = new ArrayList<>(); + boolean rpcHasValidConstructor = false; + for (Constructor constructor : aClass.getConstructors()){ + mandatoryParamsListFromCode.clear(); + for (Type paramType : constructor.getGenericParameterTypes()){ + String paramFullType = paramType.toString(); + String paramSimpleType; + + // If the param is a list of objects, the type should be like "List<Object>" + if (paramFullType.matches("java.util.List<.+>")) { + paramSimpleType = String.format("List<%s>", paramFullType.substring(paramFullType.lastIndexOf('.') + 1, paramFullType.length() - 1)); + } + // If the param is a simple object for example "java.lang.String", the type should be the last part "String" + else if (!paramFullType.contains(">")){ + paramSimpleType = paramFullType.substring(paramFullType.lastIndexOf('.') + 1, paramFullType.length()); + } + else { + paramSimpleType = paramFullType; + } + mandatoryParamsListFromCode.add(paramSimpleType); + } + if (mandatoryParamsListFromCode.containsAll(mandatoryParamsListFromXML) && mandatoryParamsListFromXML.containsAll(mandatoryParamsListFromCode)){ + rpcHasValidConstructor = true; + break; + } + } + if (!rpcHasValidConstructor){ + rpcsWithInvalidConstructor.add(rpcName); + } + } + assertTrue("The following RPCs were not found in the code: " + rpcsFromXmlNotFoundInCode, rpcsFromXmlNotFoundInCode.isEmpty()); + assertTrue("The following RPCs don't have a constructor that has all the mandatory params: " + rpcsWithInvalidConstructor, rpcsWithInvalidConstructor.isEmpty()); + } + + // This method makes sure that for every RPC, the constructor that has the mandatory params is setting the values correctly + public void testMandatoryParamsValues() { + // List of RPC names that have a constructor which is not settings the values for the mandatory params correctly + List<String> rpcsWithInvalidConstructor = new ArrayList<>(); + + // List of types that exist in java.lang.* + List<String> javaLangBuiltInTypes = Arrays.asList("String", "Integer", "Float", "Double", "Boolean"); + + // Loop through all RPCs that were loaded from RPC spec XML file + // and make sure that the constructor that has the mandatory params is setting the values correctly + for (String rpcName : rpcMandatoryParamsMapFromXml.keySet()) { + Class aClass; + try { + aClass = Class.forName(RPC_PACKAGE_PREFIX + rpcName); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + continue; + } + + List<Parameter> parameters = rpcMandatoryParamsMapFromXml.get(rpcName); + List<Class<?>> mandatoryParamsTypes = new ArrayList<>(); + List<Object> mandatoryParamsValues = new ArrayList<>(); + + // Loop through all mandatory params for the current RPC + // and try to find the full Java type for each param + // also assign a value for each param from com.smartdevicelink.test.Test class + for (Parameter param : parameters) { + String typeString = null; + Class<?> type = null; + String valueString = null; + Object value = null; + + // Find the full Java type for the current param + try { + if (param.isArray) { + type = List.class; + } else { + if (javaLangBuiltInTypes.contains(param.type)){ + typeString = "java.lang." + param.type; + } else { + typeString = RPC_PACKAGE_PREFIX + param.type; + } + type = Class.forName(typeString); + } + + } catch (ClassNotFoundException e) { + // If the class was not found in the com.smartdevicelink.proxy.rpc package + // try to see if it can be found in com.smartdevicelink.proxy.rpc.enums package + typeString = RPC_PACKAGE_PREFIX + "enums." + param.type; + try { + type = Class.forName(typeString); + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + assertTrue("Type: " + typeString + " cannot be found for RPC: " + rpcName , false); + } + } + + + // Assign a value for the current param from com.smartdevicelink.test.Test based of the param type + try { + // --------------------------------------------- Exceptional cases --------------------------------------------- + // This case is exceptional because the setter changes the input if it is not all digits + if (rpcName.equals("DialNumber") && param.type.equals("String")){ + value = "5558675309"; + } + // ------------------------------------------------------------------------------------------------------------- + + if (value == null) { + valueString = "GENERAL_" + param.type.toUpperCase(); + if (param.isArray){ + valueString += "_LIST"; + } + value = Class.forName("com.smartdevicelink.test.Test").getDeclaredField(valueString).get(null); + } + + } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + assertTrue("Value: " + valueString + " cannot be found for RPC: " + rpcName + ". Make sure that you declared that value in com.smartdevicelink.test.Test" , false); + } + + mandatoryParamsTypes.add(type); + mandatoryParamsValues.add(value); + } + + + // Create an instance of the RPC object using the constructor that has all the mandatory params + Object instance = null; + try { + Constructor constructor = aClass.getConstructor(mandatoryParamsTypes.toArray(new Class<?>[mandatoryParamsTypes.size()])); + instance = constructor.newInstance(mandatoryParamsValues.toArray(new Object[mandatoryParamsValues.size()])); + } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { + e.printStackTrace(); + assertTrue("Constructor for RPC " + rpcName + " cannot be invoked. Make sure that the constructor parameters order and types are identical to the RPC specs", false); + } + + + // Loop through all getter methods for the instance and make sure that they are returning the expected values + if (instance != null) { + for (int i = 0; i < parameters.size(); i++) { + // Find the getter method name by taking the param name, capitalize the first letter, then add thw word "get" to the beginning + // for example if the param name is "buttonName" the method name will be "getButtonName" + String getterMethodName = "get" + parameters.get(i).name.substring(0, 1).toUpperCase() + parameters.get(i).name.substring(1); + try { + Method getterMethod = aClass.getMethod(getterMethodName); + Object val = getterMethod.invoke(instance); + if (val == null || !val.equals(mandatoryParamsValues.get(i))) { + rpcsWithInvalidConstructor.add(rpcName); + break; + } + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + assertTrue("Method: " + getterMethodName + " cannot be found for RPC: " + rpcName + ". Make sure that the method exists and that the parameters order and types are identical to the RPC specs", false); + + } + } + } + } + + assertTrue("The following RPCs have a constructor that is not setting the mandatory params correctly: " + rpcsWithInvalidConstructor, rpcsWithInvalidConstructor.isEmpty()); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AirbagStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AirbagStatusTests.java new file mode 100644 index 000000000..d65e68760 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AirbagStatusTests.java @@ -0,0 +1,102 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.AirbagStatus; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataEventStatus; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AirbagStatus} + */ +public class AirbagStatusTests extends TestCase{ + + private AirbagStatus msg; + + @Override + public void setUp(){ + msg = new AirbagStatus(); + assertNotNull(Test.NOT_NULL, msg); + + msg.setDriverAirbagDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setDriverCurtainAirbagDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setDriverKneeAirbagDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setDriverSideAirbagDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setPassengerAirbagDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setPassengerCurtainAirbagDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setPassengerKneeAirbagDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setPassengerSideAirbagDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + VehicleDataEventStatus airbagStatus = msg.getDriverAirbagDeployed(); + VehicleDataEventStatus curtainStatus = msg.getDriverCurtainAirbagDeployed(); + VehicleDataEventStatus kneeStatus = msg.getDriverKneeAirbagDeployed(); + VehicleDataEventStatus sideStatus = msg.getDriverSideAirbagDeployed(); + VehicleDataEventStatus passengerStatus = msg.getPassengerAirbagDeployed(); + VehicleDataEventStatus passengerCurtainStatus = msg.getPassengerCurtainAirbagDeployed(); + VehicleDataEventStatus passengerKneeStatus = msg.getPassengerKneeAirbagDeployed(); + VehicleDataEventStatus passengerSideStatus = msg.getPassengerSideAirbagDeployed(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, airbagStatus); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, curtainStatus); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, kneeStatus); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, sideStatus); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, passengerStatus); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, passengerCurtainStatus); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, passengerKneeStatus); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, passengerSideStatus); + + // Invalid/Null Tests + AirbagStatus msg = new AirbagStatus(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getDriverAirbagDeployed()); + assertNull(Test.NULL, msg.getDriverSideAirbagDeployed()); + assertNull(Test.NULL, msg.getDriverCurtainAirbagDeployed()); + assertNull(Test.NULL, msg.getPassengerAirbagDeployed()); + assertNull(Test.NULL, msg.getPassengerCurtainAirbagDeployed()); + assertNull(Test.NULL, msg.getDriverKneeAirbagDeployed()); + assertNull(Test.NULL, msg.getPassengerSideAirbagDeployed()); + assertNull(Test.NULL, msg.getPassengerKneeAirbagDeployed()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(AirbagStatus.KEY_DRIVER_AIRBAG_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(AirbagStatus.KEY_DRIVER_CURTAIN_AIRBAG_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(AirbagStatus.KEY_DRIVER_KNEE_AIRBAG_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(AirbagStatus.KEY_DRIVER_SIDE_AIRBAG_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(AirbagStatus.KEY_PASSENGER_AIRBAG_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(AirbagStatus.KEY_PASSENGER_CURTAIN_AIRBAG_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(AirbagStatus.KEY_PASSENGER_KNEE_AIRBAG_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(AirbagStatus.KEY_PASSENGER_SIDE_AIRBAG_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceCapabilityTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceCapabilityTest.java new file mode 100644 index 000000000..6bd5fe01e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceCapabilityTest.java @@ -0,0 +1,86 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.AppServiceCapability; +import com.smartdevicelink.proxy.rpc.AppServiceRecord; +import com.smartdevicelink.proxy.rpc.enums.ServiceUpdateReason; +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.AppServiceCapability} + */ +public class AppServiceCapabilityTest extends TestCase { + + private AppServiceCapability msg; + + @Override + public void setUp(){ + + msg = new AppServiceCapability(); + msg.setUpdatedAppServiceRecord(Test.GENERAL_APP_SERVICE_RECORD); + msg.setUpdateReason(Test.GENERAL_SERVICE_UPDATE_REASON); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + AppServiceRecord serviceRecord = msg.getUpdatedAppServiceRecord(); + ServiceUpdateReason updateReason = msg.getUpdateReason(); + + // Valid Tests + assertEquals(Test.MATCH, serviceRecord, Test.GENERAL_APP_SERVICE_RECORD); + assertEquals(Test.MATCH, updateReason, Test.GENERAL_SERVICE_UPDATE_REASON); + + // Invalid/Null Tests + AppServiceCapability msg = new AppServiceCapability(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getUpdatedAppServiceRecord()); + assertNull(Test.NULL, msg.getUpdateReason()); + } + + public void testRequiredParamsConstructor(){ + msg = new AppServiceCapability(Test.GENERAL_APP_SERVICE_RECORD); + AppServiceRecord serviceRecord = msg.getUpdatedAppServiceRecord(); + assertEquals(Test.MATCH, serviceRecord, Test.GENERAL_APP_SERVICE_RECORD); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(AppServiceCapability.KEY_UPDATE_REASON, Test.GENERAL_SERVICE_UPDATE_REASON); + reference.put(AppServiceCapability.KEY_UPDATED_APP_SERVICE_RECORD, Test.GENERAL_APP_SERVICE_RECORD); + + 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(AppServiceCapability.KEY_UPDATED_APP_SERVICE_RECORD)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateAppServiceRecord(Test.GENERAL_APP_SERVICE_RECORD, new AppServiceRecord(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/AppServiceDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceDataTests.java new file mode 100644 index 000000000..9fec35631 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceDataTests.java @@ -0,0 +1,118 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.AppServiceData; +import com.smartdevicelink.proxy.rpc.MediaServiceData; +import com.smartdevicelink.proxy.rpc.NavigationServiceData; +import com.smartdevicelink.proxy.rpc.WeatherServiceData; +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.AppServiceData} + */ +public class AppServiceDataTests extends TestCase { + + private AppServiceData msg; + + @Override + public void setUp() { + + msg = new AppServiceData(); + msg.setServiceType(Test.GENERAL_STRING); + msg.setServiceId(Test.GENERAL_STRING); + msg.setMediaServiceData(Test.GENERAL_MEDIASERVICE_DATA); + msg.setWeatherServiceData(Test.GENERAL_WEATHERSERVICE_DATA); + msg.setNavigationServiceData(Test.GENERAL_NAVIGATIONSERVICE_DATA); + + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String appServiceType = msg.getServiceType(); + String serviceId = msg.getServiceId(); + MediaServiceData mediaServiceData = msg.getMediaServiceData(); + WeatherServiceData weatherServiceData = msg.getWeatherServiceData(); + NavigationServiceData navigationServiceData = msg.getNavigationServiceData(); + + // Valid Tests + assertEquals(Test.GENERAL_STRING, appServiceType); + assertEquals(Test.GENERAL_STRING, serviceId); + assertEquals(Test.GENERAL_MEDIASERVICE_DATA, mediaServiceData); + assertEquals(Test.GENERAL_WEATHERSERVICE_DATA, weatherServiceData); + assertEquals(Test.GENERAL_NAVIGATIONSERVICE_DATA, navigationServiceData); + + // Invalid/Null Tests + AppServiceData msg = new AppServiceData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getServiceType()); + assertNull(Test.NULL, msg.getServiceId()); + assertNull(Test.NULL, msg.getMediaServiceData()); + assertNull(Test.NULL, msg.getWeatherServiceData()); + assertNull(Test.NULL, msg.getNavigationServiceData()); + + } + + public void testRequiredParamsConstructor(){ + + msg = new AppServiceData(Test.GENERAL_STRING, Test.GENERAL_STRING); + String appServiceType = msg.getServiceType(); + String serviceId = msg.getServiceId(); + assertEquals(Test.GENERAL_STRING, appServiceType); + assertEquals(Test.GENERAL_STRING, serviceId); + + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(AppServiceData.KEY_SERVICE_TYPE, Test.GENERAL_STRING); + reference.put(AppServiceData.KEY_SERVICE_ID, Test.GENERAL_STRING); + reference.put(AppServiceData.KEY_MEDIA_SERVICE_DATA, Test.GENERAL_MEDIASERVICE_DATA); + reference.put(AppServiceData.KEY_WEATHER_SERVICE_DATA, Test.GENERAL_WEATHERSERVICE_DATA); + reference.put(AppServiceData.KEY_NAVIGATION_SERVICE_DATA, Test.GENERAL_NAVIGATIONSERVICE_DATA); + + 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(AppServiceData.KEY_MEDIA_SERVICE_DATA)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateMediaServiceData(Test.GENERAL_MEDIASERVICE_DATA, new MediaServiceData(hashTest))); + } else if (key.equals(AppServiceData.KEY_WEATHER_SERVICE_DATA)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateWeatherServiceData(Test.GENERAL_WEATHERSERVICE_DATA, new WeatherServiceData(hashTest))); + } else if (key.equals(AppServiceData.KEY_NAVIGATION_SERVICE_DATA)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateNavigationServiceData(Test.GENERAL_NAVIGATIONSERVICE_DATA, new NavigationServiceData(hashTest))); + } 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/AppServiceManifestTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceManifestTests.java new file mode 100644 index 000000000..99bd5b716 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceManifestTests.java @@ -0,0 +1,148 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.AppServiceManifest; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.MediaServiceManifest; +import com.smartdevicelink.proxy.rpc.NavigationServiceManifest; +import com.smartdevicelink.proxy.rpc.SdlMsgVersion; +import com.smartdevicelink.proxy.rpc.WeatherServiceManifest; +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; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.AppServiceManifest} + */ +public class AppServiceManifestTests extends TestCase { + + private AppServiceManifest msg; + + @Override + public void setUp(){ + + msg = new AppServiceManifest(); + msg.setServiceType(Test.GENERAL_STRING); + msg.setAllowAppConsumers(Test.GENERAL_BOOLEAN); + msg.setHandledRpcs(Test.GENERAL_FUNCTION_ID_LIST); + msg.setMediaServiceManifest(Test.GENERAL_MEDIA_SERVICE_MANIFEST); + msg.setRpcSpecVersion(Test.GENERAL_SDLMSGVERSION); + msg.setServiceIcon(Test.GENERAL_IMAGE); + msg.setServiceName(Test.GENERAL_STRING); + msg.setWeatherServiceManifest(Test.GENERAL_WEATHER_SERVICE_MANIFEST); + msg.setNavigationServiceManifest(Test.GENERAL_NAVIGATION_SERVICE_MANIFEST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Image serviceIcon = msg.getServiceIcon(); + String serviceName = msg.getServiceName(); + String appServiceType = msg.getServiceType(); + boolean allowAppConsumers = msg.getAllowAppConsumers(); + SdlMsgVersion version = msg.getRpcSpecVersion(); + List<Integer> handledRPCs = msg.getHandledRpcs(); + WeatherServiceManifest weatherServiceManifestTest = msg.getWeatherServiceManifest(); + MediaServiceManifest mediaServiceManifestTest = msg.getMediaServiceManifest(); + NavigationServiceManifest navigationServiceManifest = msg.getNavigationServiceManifest(); + + // Valid Tests + assertEquals(Test.GENERAL_BOOLEAN, allowAppConsumers); + assertEquals(Test.GENERAL_IMAGE, serviceIcon); + assertEquals(Test.GENERAL_STRING, serviceName); + assertEquals(Test.GENERAL_STRING, appServiceType); + assertEquals(Test.GENERAL_SDLMSGVERSION, version); + assertEquals(Test.MATCH, Test.GENERAL_FUNCTION_ID_LIST, handledRPCs); + assertEquals(Test.GENERAL_WEATHER_SERVICE_MANIFEST, weatherServiceManifestTest); + assertEquals(Test.GENERAL_MEDIA_SERVICE_MANIFEST, mediaServiceManifestTest); + assertEquals(Test.GENERAL_NAVIGATION_SERVICE_MANIFEST, navigationServiceManifest); + + // Invalid/Null Tests + AppServiceManifest msg = new AppServiceManifest(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getServiceIcon()); + assertNull(Test.NULL, msg.getServiceName()); + assertNull(Test.NULL, msg.getServiceType()); + assertNull(Test.NULL, msg.getAllowAppConsumers()); + assertNull(Test.NULL, msg.getRpcSpecVersion()); + assertNull(Test.NULL, msg.getHandledRpcs()); + assertNull(Test.NULL, msg.getWeatherServiceManifest()); + assertNull(Test.NULL, msg.getMediaServiceManifest()); + assertNull(Test.NULL, msg.getNavigationServiceManifest()); + } + + public void testRequiredParamsConstructor(){ + msg = new AppServiceManifest(Test.GENERAL_STRING); + String appServiceType = msg.getServiceType(); + assertEquals(Test.GENERAL_STRING, appServiceType); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(AppServiceManifest.KEY_SERVICE_NAME, Test.GENERAL_STRING); + reference.put(AppServiceManifest.KEY_SERVICE_ICON, Test.GENERAL_IMAGE); + reference.put(AppServiceManifest.KEY_SERVICE_TYPE, Test.GENERAL_STRING); + reference.put(AppServiceManifest.KEY_ALLOW_APP_CONSUMERS, Test.GENERAL_BOOLEAN); + reference.put(AppServiceManifest.KEY_RPC_SPEC_VERSION, Test.GENERAL_SDLMSGVERSION.serializeJSON()); + reference.put(AppServiceManifest.KEY_HANDLED_RPCS, Test.GENERAL_FUNCTION_ID_LIST); + reference.put(AppServiceManifest.KEY_WEATHER_SERVICE_MANIFEST, Test.GENERAL_WEATHER_SERVICE_MANIFEST); + reference.put(AppServiceManifest.KEY_MEDIA_SERVICE_MANIFEST, Test.GENERAL_MEDIA_SERVICE_MANIFEST); + reference.put(AppServiceManifest.KEY_NAVIGATION_SERVICE_MANIFEST, Test.GENERAL_NAVIGATION_SERVICE_MANIFEST); + + 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(AppServiceManifest.KEY_RPC_SPEC_VERSION)){ + 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.validateSdlMsgVersion( new SdlMsgVersion(hashReference), new SdlMsgVersion(hashTest))); + }else if(key.equals(AppServiceManifest.KEY_HANDLED_RPCS)){ + List<Integer> list1 = Test.GENERAL_FUNCTION_ID_LIST; + List<Integer> list2 = JsonUtils.readIntegerListFromJsonObject(underTest, key); + assertTrue(Test.TRUE, Validator.validateIntegerList(list1,list2)); + }else if(key.equals(AppServiceManifest.KEY_WEATHER_SERVICE_MANIFEST)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateWeatherServiceManifest( Test.GENERAL_WEATHER_SERVICE_MANIFEST, new WeatherServiceManifest(hashTest))); + }else if(key.equals(AppServiceManifest.KEY_MEDIA_SERVICE_MANIFEST)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateMediaServiceManifest( Test.GENERAL_MEDIA_SERVICE_MANIFEST, new MediaServiceManifest(hashTest))); + } else if(key.equals(AppServiceManifest.KEY_NAVIGATION_SERVICE_MANIFEST)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateNavigationServiceManifest( Test.GENERAL_NAVIGATION_SERVICE_MANIFEST, new NavigationServiceManifest(hashTest))); + }else if(key.equals(AppServiceManifest.KEY_SERVICE_ICON)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Image refIcon1 = new Image(JsonRPCMarshaller.deserializeJSONObject(testEquals)); + assertTrue(Test.TRUE, Validator.validateImage(refIcon1, msg.getServiceIcon())); + }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/AppServiceRecordTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceRecordTests.java new file mode 100644 index 000000000..af58b12fb --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceRecordTests.java @@ -0,0 +1,107 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.AppServiceManifest; +import com.smartdevicelink.proxy.rpc.AppServiceRecord; +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.AppServiceRecord} + */ +public class AppServiceRecordTests extends TestCase { + + private AppServiceRecord msg; + + @Override + public void setUp(){ + + msg = new AppServiceRecord(); + msg.setServicePublished(Test.GENERAL_BOOLEAN); + msg.setServiceActive(Test.GENERAL_BOOLEAN); + msg.setServiceManifest(Test.GENERAL_APP_SERVICE_MANIFEST); + msg.setServiceId(Test.GENERAL_STRING); + + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + + boolean isServicePublished = msg.getServicePublished(); + boolean isServiceActive = msg.getServiceActive(); + AppServiceManifest serviceManifest = msg.getServiceManifest(); + String serviceID = msg.getServiceId(); + + // Valid Tests + assertEquals(Test.GENERAL_BOOLEAN, isServicePublished); + assertEquals(Test.GENERAL_BOOLEAN, isServiceActive); + assertEquals(Test.GENERAL_APP_SERVICE_MANIFEST, serviceManifest); + assertEquals(Test.GENERAL_STRING, serviceID); + + // Invalid/Null Tests + AppServiceRecord msg = new AppServiceRecord(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getServicePublished()); + assertNull(Test.NULL, msg.getServiceActive()); + assertNull(Test.NULL, msg.getServiceManifest()); + assertNull(Test.NULL, msg.getServiceId()); + } + + public void testRequiredParamsConstructor(){ + msg = new AppServiceRecord(Test.GENERAL_STRING, Test.GENERAL_APP_SERVICE_MANIFEST, Test.GENERAL_BOOLEAN, Test.GENERAL_BOOLEAN); + + boolean isServicePublished = msg.getServicePublished(); + boolean isServiceActive = msg.getServiceActive(); + AppServiceManifest serviceManifest = msg.getServiceManifest(); + String serviceID = msg.getServiceId(); + + // Valid Tests + assertEquals(Test.GENERAL_BOOLEAN, isServicePublished); + assertEquals(Test.GENERAL_BOOLEAN, isServiceActive); + assertEquals(Test.GENERAL_APP_SERVICE_MANIFEST, serviceManifest); + assertEquals(Test.GENERAL_STRING, serviceID); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(AppServiceRecord.KEY_SERVICE_ACTIVE, Test.GENERAL_BOOLEAN); + reference.put(AppServiceRecord.KEY_SERVICE_PUBLISHED, Test.GENERAL_BOOLEAN); + reference.put(AppServiceRecord.KEY_SERVICE_ID, Test.GENERAL_STRING); + reference.put(AppServiceRecord.KEY_SERVICE_MANIFEST, Test.GENERAL_APP_SERVICE_MANIFEST); + + 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(AppServiceRecord.KEY_SERVICE_MANIFEST)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateAppServiceManifest( Test.GENERAL_APP_SERVICE_MANIFEST, new AppServiceManifest(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/AppServicesCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServicesCapabilitiesTests.java new file mode 100644 index 000000000..bb2d102f2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServicesCapabilitiesTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.AppServiceCapability; +import com.smartdevicelink.proxy.rpc.AppServicesCapabilities; +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.Iterator; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.AppServicesCapabilities} + */ +public class AppServicesCapabilitiesTests extends TestCase { + + private AppServicesCapabilities msg; + + @Override + public void setUp(){ + + msg = new AppServicesCapabilities(); + msg.setAppServices(Test.GENERAL_APPSERVICECAPABILITY_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<AppServiceCapability> serviceCapabilityList = msg.getAppServices(); + + // Valid Tests + assertEquals(Test.MATCH, serviceCapabilityList, Test.GENERAL_APPSERVICECAPABILITY_LIST); + + // Invalid/Null Tests + AppServicesCapabilities msg = new AppServicesCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getAppServices()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(AppServicesCapabilities.KEY_APP_SERVICES, Test.GENERAL_APPSERVICETYPE_LIST); + + 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(AppServicesCapabilities.KEY_APP_SERVICES)) { + List<AppServiceCapability> list1 = Test.GENERAL_APPSERVICECAPABILITY_LIST; + List<AppServiceCapability> list2 = JsonUtils.readAppServiceCapabilityListFromJsonObject(underTest, key); + assertTrue(Test.TRUE, Validator.validateAppServiceCapabilityList(list1,list2)); + }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/AudioControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java new file mode 100644 index 000000000..524a6bde2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlCapabilitiesTests.java @@ -0,0 +1,94 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.AudioControlCapabilities; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.AudioControlCapabilities} + */ +public class AudioControlCapabilitiesTests extends TestCase { + + private AudioControlCapabilities msg; + + @Override + public void setUp() { + msg = new AudioControlCapabilities(); + + msg.setModuleName(Test.GENERAL_STRING); + msg.setSourceAvailable(Test.GENERAL_BOOLEAN); + msg.setKeepContextAvailable(Test.GENERAL_BOOLEAN); + msg.setVolumeAvailable(Test.GENERAL_BOOLEAN); + msg.setEqualizerAvailable(Test.GENERAL_BOOLEAN); + msg.setVolumeAvailable(Test.GENERAL_BOOLEAN); + msg.setEqualizerMaxChannelId(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + + String moduleName = msg.getModuleName(); + Boolean sourceAvailable = msg.getSourceAvailable(); + Boolean keepContextAvailable = msg.getKeepContextAvailable(); + Boolean volumeAvailable = msg.getVolumeAvailable(); + Boolean equalizerAvailable = msg.getEqualizerAvailable(); + int equalizerMaxChannelId = msg.getEqualizerMaxChannelId(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) sourceAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) keepContextAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) volumeAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) equalizerAvailable); + assertEquals(Test.MATCH, Test.GENERAL_INT, equalizerMaxChannelId); + + // Invalid/Null Tests + AudioControlCapabilities msg = new AudioControlCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getModuleName()); + assertNull(Test.NULL, msg.getSourceAvailable()); + assertNull(Test.NULL, msg.getKeepContextAvailable()); + assertNull(Test.NULL, msg.getVolumeAvailable()); + assertNull(Test.NULL, msg.getEqualizerAvailable()); + assertNull(Test.NULL, msg.getEqualizerMaxChannelId()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + + reference.put(AudioControlCapabilities.KEY_MODULE_NAME, Test.GENERAL_STRING); + reference.put(AudioControlCapabilities.KEY_SOURCE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(AudioControlCapabilities.KEY_KEEP_CONTEXT_AVAILABLE, Test.GENERAL_BOOLEAN); + 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); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlDataTests.java new file mode 100644 index 000000000..4dba080ac --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioControlDataTests.java @@ -0,0 +1,98 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.AudioControlData; +import com.smartdevicelink.proxy.rpc.EqualizerSettings; +import com.smartdevicelink.proxy.rpc.enums.PrimaryAudioSource; +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.Iterator; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AudioControlData} + */ +public class AudioControlDataTests extends TestCase { + + private AudioControlData msg; + + @Override + public void setUp() { + msg = new AudioControlData(); + + msg.setSource(Test.GENERAL_PRIMARYAUDIOSOURCE); + msg.setKeepContext(Test.GENERAL_BOOLEAN); + msg.setVolume(Test.GENERAL_INT); + msg.setEqualizerSettings(Test.GENERAL_EQUALIZERSETTINGS_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + PrimaryAudioSource source = msg.getSource(); + Boolean keepContext = msg.getKeepContext(); + int volume = msg.getVolume(); + List<EqualizerSettings> equalizerSettings = msg.getEqualizerSettings(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_PRIMARYAUDIOSOURCE, source); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) keepContext); + assertEquals(Test.MATCH, Test.GENERAL_INT, volume); + assertEquals(Test.MATCH, Test.GENERAL_EQUALIZERSETTINGS_LIST.size(), equalizerSettings.size()); + + assertTrue(Test.TRUE, Validator.validateEqualizerSettingsList(Test.GENERAL_EQUALIZERSETTINGS_LIST, equalizerSettings)); + + // Invalid/Null Tests + AudioControlData msg = new AudioControlData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getSource()); + assertNull(Test.NULL, msg.getVolume()); + assertNull(Test.NULL, msg.getKeepContext()); + assertNull(Test.NULL, msg.getEqualizerSettings()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(AudioControlData.KEY_SOURCE, Test.GENERAL_PRIMARYAUDIOSOURCE); + reference.put(AudioControlData.KEY_KEEP_CONTEXT, Test.GENERAL_BOOLEAN); + reference.put(AudioControlData.KEY_VOLUME, Test.GENERAL_INT); + reference.put(AudioControlData.KEY_EQUALIZER_SETTINGS, Test.GENERAL_EQUALIZERSETTINGS_LIST); + + 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(AudioControlData.KEY_EQUALIZER_SETTINGS)) { + List<EqualizerSettings> esReference = (List<EqualizerSettings>) JsonUtils.readObjectFromJsonObject(reference, key); + JSONArray esArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + int i = 0; + for (EqualizerSettings es : esReference) { + assertTrue(Validator.validateEqualizerSettings(es, new EqualizerSettings(JsonRPCMarshaller.deserializeJSONObject(esArray.getJSONObject(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/AudioPassThruCapabilitiesTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioPassThruCapabilitiesTest.java new file mode 100644 index 000000000..476898685 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AudioPassThruCapabilitiesTest.java @@ -0,0 +1,78 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.AudioPassThruCapabilities; +import com.smartdevicelink.proxy.rpc.enums.AudioType; +import com.smartdevicelink.proxy.rpc.enums.BitsPerSample; +import com.smartdevicelink.proxy.rpc.enums.SamplingRate; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AudioPassThruCapabilities} + */ +public class AudioPassThruCapabilitiesTest extends TestCase{ + + private AudioPassThruCapabilities msg; + + @Override + public void setUp(){ + msg = new AudioPassThruCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + msg.setAudioType(Test.GENERAL_AUDIOTYPE); + msg.setBitsPerSample(Test.GENERAL_BITSPERSAMPLE); + msg.setSamplingRate(Test.GENERAL_SAMPLINGRATE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + SamplingRate samplingRate = msg.getSamplingRate(); + BitsPerSample bitsPerSample = msg.getBitsPerSample(); + AudioType audioType = msg.getAudioType(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_SAMPLINGRATE, samplingRate); + assertEquals(Test.MATCH, Test.GENERAL_BITSPERSAMPLE, bitsPerSample); + assertEquals(Test.MATCH, Test.GENERAL_AUDIOTYPE, audioType); + + // Invalid/Null Tests + AudioPassThruCapabilities msg = new AudioPassThruCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getAudioType()); + assertNull(Test.NULL, msg.getBitsPerSample()); + assertNull(Test.NULL, msg.getSamplingRate()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(AudioPassThruCapabilities.KEY_AUDIO_TYPE, Test.GENERAL_AUDIOTYPE); + reference.put(AudioPassThruCapabilities.KEY_BITS_PER_SAMPLE, Test.GENERAL_BITSPERSAMPLE); + reference.put(AudioPassThruCapabilities.KEY_SAMPLING_RATE, Test.GENERAL_SAMPLINGRATE); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/BeltStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/BeltStatusTests.java new file mode 100644 index 000000000..5fb53ef3d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/BeltStatusTests.java @@ -0,0 +1,137 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.BeltStatus; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataEventStatus; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.BeltStatus} + */ +public class BeltStatusTests extends TestCase{ + + private BeltStatus msg; + + @Override + protected void setUp() throws Exception{ + msg = new BeltStatus(); + assertNotNull(Test.NOT_NULL, msg); + + msg.setLeftRearInflatableBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setPassengerChildDetected(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setRightRearInflatableBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setDriverBuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setPassengerBuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setRightRow2BuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setDriverBeltDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setPassengerBeltDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setMiddleRow1BuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setMiddleRow1BeltDeployed(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setLeftRow2BuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setMiddleRow2BuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setMiddleRow3BuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setLeftRow3BuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setRightRow3BuckleBelted(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Valid Tests + VehicleDataEventStatus leftRearInflatable = msg.getLeftRearInflatableBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, leftRearInflatable); + + VehicleDataEventStatus rightRearInflatable = msg.getRightRearInflatableBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, rightRearInflatable); + + VehicleDataEventStatus passengerChild = msg.getPassengerChildDetected(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, passengerChild); + + VehicleDataEventStatus driverBuckled = msg.getDriverBuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + driverBuckled = msg.getPassengerBuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + driverBuckled = msg.getRightRow2BuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + driverBuckled = msg.getMiddleRow1BuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + driverBuckled = msg.getLeftRow2BuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + driverBuckled = msg.getMiddleRow2BuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + driverBuckled = msg.getMiddleRow3BuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + driverBuckled = msg.getLeftRow3BuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + driverBuckled = msg.getRightRow3BuckleBelted(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBuckled); + + VehicleDataEventStatus driverBeltDeployed = msg.getDriverBeltDeployed(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBeltDeployed); + driverBeltDeployed = msg.getPassengerBeltDeployed(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBeltDeployed); + driverBeltDeployed = msg.getMiddleRow1BeltDeployed(); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, driverBeltDeployed); + + // Invalid/Null Tests + BeltStatus msg = new BeltStatus(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getLeftRearInflatableBelted()); + assertNull(Test.NULL, msg.getRightRearInflatableBelted()); + assertNull(Test.NULL, msg.getPassengerChildDetected()); + assertNull(Test.NULL, msg.getDriverBuckleBelted()); + assertNull(Test.NULL, msg.getPassengerBuckleBelted()); + assertNull(Test.NULL, msg.getRightRow2BuckleBelted()); + assertNull(Test.NULL, msg.getMiddleRow1BuckleBelted()); + assertNull(Test.NULL, msg.getLeftRow2BuckleBelted()); + assertNull(Test.NULL, msg.getMiddleRow2BuckleBelted()); + assertNull(Test.NULL, msg.getMiddleRow3BuckleBelted()); + assertNull(Test.NULL, msg.getLeftRow3BuckleBelted()); + assertNull(Test.NULL, msg.getRightRow3BuckleBelted()); + assertNull(Test.NULL, msg.getPassengerBeltDeployed()); + assertNull(Test.NULL, msg.getMiddleRow1BeltDeployed()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(BeltStatus.KEY_PASSENGER_CHILD_DETECTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_REAR_INFLATABLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_RIGHT_REAR_INFLATABLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_DRIVER_BELT_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_DRIVER_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_PASSENGER_BELT_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_PASSENGER_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_LEFT_ROW_2_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_RIGHT_ROW_2_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_MIDDLE_ROW_2_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_MIDDLE_ROW_3_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_LEFT_ROW_3_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_RIGHT_ROW_3_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_MIDDLE_ROW_1_BELT_DEPLOYED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(BeltStatus.KEY_MIDDLE_ROW_1_BUCKLE_BELTED, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/BodyInformationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/BodyInformationTests.java new file mode 100644 index 000000000..245ee7ec8 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/BodyInformationTests.java @@ -0,0 +1,93 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.BodyInformation; +import com.smartdevicelink.proxy.rpc.enums.IgnitionStableStatus; +import com.smartdevicelink.proxy.rpc.enums.IgnitionStatus; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.BodyInformation} + */ +public class BodyInformationTests extends TestCase{ + + private BodyInformation msg; + + @Override + public void setUp(){ + msg = new BodyInformation(); + msg.setParkBrakeActive(Test.GENERAL_BOOLEAN); + msg.setIgnitionStatus(Test.GENERAL_IGNITIONSTATUS); + msg.setIgnitionStableStatus(Test.GENERAL_IGNITIONSTABLESTATUS); + + msg.setDriverDoorAjar(Test.GENERAL_BOOLEAN); + msg.setPassengerDoorAjar(Test.GENERAL_BOOLEAN); + msg.setRearLeftDoorAjar(Test.GENERAL_BOOLEAN); + msg.setRearRightDoorAjar(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean parkBrake = msg.getParkBrakeActive(); + IgnitionStatus ignitionStatus = msg.getIgnitionStatus(); + IgnitionStableStatus ignitionStable = msg.getIgnitionStableStatus(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, parkBrake); + assertEquals(Test.MATCH, Test.GENERAL_IGNITIONSTATUS, ignitionStatus); + assertEquals(Test.MATCH, Test.GENERAL_IGNITIONSTABLESTATUS, ignitionStable); + + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) msg.getDriverDoorAjar()); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) msg.getPassengerDoorAjar()); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) msg.getRearLeftDoorAjar()); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) msg.getRearRightDoorAjar()); + + // Invalid/Null Tests + BodyInformation msg = new BodyInformation(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getParkBrakeActive()); + assertNull(Test.NULL, msg.getIgnitionStatus()); + assertNull(Test.NULL, msg.getIgnitionStatus()); + assertNull(Test.NULL, msg.getDriverDoorAjar()); + assertNull(Test.NULL, msg.getPassengerDoorAjar()); + assertNull(Test.NULL, msg.getRearLeftDoorAjar()); + assertNull(Test.NULL, msg.getRearRightDoorAjar()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(BodyInformation.KEY_PARK_BRAKE_ACTIVE, Test.GENERAL_BOOLEAN); + reference.put(BodyInformation.KEY_IGNITION_STATUS, Test.GENERAL_IGNITIONSTATUS); + reference.put(BodyInformation.KEY_IGNITION_STABLE_STATUS, Test.GENERAL_IGNITIONSTABLESTATUS); + reference.put(BodyInformation.KEY_DRIVER_DOOR_AJAR, Test.GENERAL_BOOLEAN); + reference.put(BodyInformation.KEY_PASSENGER_DOOR_AJAR, Test.GENERAL_BOOLEAN); + reference.put(BodyInformation.KEY_REAR_LEFT_DOOR_AJAR, Test.GENERAL_BOOLEAN); + reference.put(BodyInformation.KEY_REAR_RIGHT_DOOR_AJAR, Test.GENERAL_BOOLEAN); + + 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 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 new file mode 100644 index 000000000..b8001dc2c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ButtonCapabilitiesTests.java @@ -0,0 +1,82 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.ButtonCapabilities; +import com.smartdevicelink.proxy.rpc.enums.ButtonName; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ButtonCapabilities} + */ +public class ButtonCapabilitiesTests extends TestCase{ + + private ButtonCapabilities msg; + + @Override + public void setUp(){ + msg = new ButtonCapabilities(); + + msg.setLongPressAvailable(Test.GENERAL_BOOLEAN); + msg.setName(Test.GENERAL_BUTTONNAME); + msg.setShortPressAvailable(Test.GENERAL_BOOLEAN); + msg.setUpDownAvailable(Test.GENERAL_BOOLEAN); + } + + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean shortPress = msg.getShortPressAvailable(); + boolean longPress = msg.getLongPressAvailable(); + boolean upDown = msg.getUpDownAvailable(); + ButtonName buttonName = msg.getName(); + + // 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); + + // Invalid/Null Tests + ButtonCapabilities msg = new ButtonCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getShortPressAvailable()); + assertNull(Test.NULL, msg.getLongPressAvailable()); + assertNull(Test.NULL, msg.getUpDownAvailable()); + assertNull(Test.NULL, msg.getName()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(ButtonCapabilities.KEY_SHORT_PRESS_AVAILABLE, Test.GENERAL_BOOLEAN); + 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); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ChoiceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ChoiceTests.java new file mode 100644 index 000000000..0df50f405 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ChoiceTests.java @@ -0,0 +1,113 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Choice; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.Choice} + */ +public class ChoiceTests extends TestCase{ + + private Choice msg; + + @Override + public void setUp(){ + msg = new Choice(); + + msg.setChoiceID(Test.GENERAL_INT); + msg.setMenuName(Test.GENERAL_STRING); + msg.setImage(Test.GENERAL_IMAGE); + msg.setSecondaryImage(Test.GENERAL_IMAGE); + msg.setSecondaryText(Test.GENERAL_STRING); + msg.setTertiaryText(Test.GENERAL_STRING); + msg.setVrCommands(Test.GENERAL_STRING_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String text3 = msg.getTertiaryText(); + String text2 = msg.getSecondaryText(); + String menuName = msg.getMenuName(); + int choiceId = msg.getChoiceID(); + List<String> vrCommands = msg.getVrCommands(); + Image image2 = msg.getSecondaryImage(); + Image image = msg.getImage(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, text3); + assertEquals(Test.MATCH, Test.GENERAL_STRING, text2); + assertEquals(Test.MATCH, Test.GENERAL_STRING, menuName); + assertEquals(Test.MATCH, Test.GENERAL_INT, choiceId); + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, vrCommands)); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, image2)); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, image)); + + // Invalid/Null Tests + Choice msg = new Choice(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getChoiceID()); + assertNull(Test.NULL, msg.getImage()); + assertNull(Test.NULL, msg.getSecondaryImage()); + assertNull(Test.NULL, msg.getMenuName()); + assertNull(Test.NULL, msg.getSecondaryText()); + assertNull(Test.NULL, msg.getTertiaryText()); + assertNull(Test.NULL, msg.getVrCommands()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(Choice.KEY_CHOICE_ID, Test.GENERAL_INT); + reference.put(Choice.KEY_MENU_NAME, Test.GENERAL_STRING); + reference.put(Choice.KEY_SECONDARY_TEXT, Test.GENERAL_STRING); + reference.put(Choice.KEY_TERTIARY_TEXT, Test.GENERAL_STRING); + reference.put(Choice.KEY_IMAGE, Test.JSON_IMAGE); + reference.put(Choice.KEY_SECONDARY_IMAGE, Test.JSON_IMAGE); + reference.put(Choice.KEY_VR_COMMANDS, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + + 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(Choice.KEY_VR_COMMANDS)){ + assertTrue(Test.TRUE, + Validator.validateStringList(JsonUtils.readStringListFromJsonObject(reference, key), + JsonUtils.readStringListFromJsonObject(underTest, key))); + } else if(key.equals(Choice.KEY_IMAGE) || key.equals(Choice.KEY_SECONDARY_IMAGE)){ + JSONObject objectEquals = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject testEquals = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(objectEquals); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + + assertTrue(Test.TRUE, Validator.validateImage(new Image(hashReference), new Image(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/ClimateControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java new file mode 100644 index 000000000..c391eb4eb --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlCapabilitiesTests.java @@ -0,0 +1,180 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.ClimateControlCapabilities; +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 junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ClimateControlCapabilities} + */ +public class ClimateControlCapabilitiesTests extends TestCase{ + + private ClimateControlCapabilities msg; + + @Override + public void setUp(){ + msg = new ClimateControlCapabilities(); + + msg.setModuleName(Test.GENERAL_STRING); + msg.setFanSpeedAvailable(Test.GENERAL_BOOLEAN); + msg.setDesiredTemperatureAvailable(Test.GENERAL_BOOLEAN); + msg.setAcEnableAvailable(Test.GENERAL_BOOLEAN); + msg.setAcMaxEnableAvailable(Test.GENERAL_BOOLEAN); + msg.setCirculateAirEnableAvailable(Test.GENERAL_BOOLEAN); + msg.setAutoModeEnableAvailable(Test.GENERAL_BOOLEAN); + msg.setDualModeEnableAvailable(Test.GENERAL_BOOLEAN); + msg.setDefrostZoneAvailable(Test.GENERAL_BOOLEAN); + msg.setDefrostZone(Test.GENERAL_DEFROSTZONE_LIST); + msg.setVentilationModeAvailable(Test.GENERAL_BOOLEAN); + msg.setVentilationMode(Test.GENERAL_VENTILATIONMODE_LIST); + msg.setHeatedSteeringWheelAvailable(Test.GENERAL_BOOLEAN); + msg.setHeatedWindshieldAvailable(Test.GENERAL_BOOLEAN); + msg.setHeatedRearWindowAvailable(Test.GENERAL_BOOLEAN); + msg.setHeatedMirrorsAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String moduleName = msg.getModuleName(); + boolean fanSpeedAvailable = msg.getFanSpeedAvailable(); + boolean desiredTemperatureAvailable = msg.getDesiredTemperatureAvailable(); + boolean acEnableAvailable = msg.getAcEnableAvailable(); + boolean acMaxEnableAvailable = msg.getAcMaxEnableAvailable(); + boolean circulateAirEnableAvailable = msg.getCirculateAirEnableAvailable(); + boolean autoModeEnableAvailable = msg.getAutoModeEnableAvailable(); + boolean dualModeEnableAvailable = msg.getDualModeEnableAvailable(); + boolean defrostZoneAvailable = msg.getDefrostZoneAvailable(); + List<DefrostZone> defrostZone = msg.getDefrostZone(); + boolean ventilationModeAvailable = msg.getVentilationModeAvailable(); + List<VentilationMode> ventilationMode = msg.getVentilationMode(); + boolean heatedSteeringWheelAvailable = msg.getHeatedSteeringWheelAvailable(); + boolean heatedWindshieldAvailable = msg.getHeatedWindshieldAvailable(); + boolean heatedRearWindowAvailable = msg.getHeatedRearWindowAvailable(); + boolean heatedMirrorsAvailable = msg.getHeatedMirrorsAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, fanSpeedAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, desiredTemperatureAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, acEnableAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, acMaxEnableAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, circulateAirEnableAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, autoModeEnableAvailable); + 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_DEFROSTZONE_LIST.size(), defrostZone.size()); + assertEquals(Test.MATCH, Test.GENERAL_VENTILATIONMODE_LIST.size(), ventilationMode.size()); + + for(int i = 0; i < Test.GENERAL_DEFROSTZONE_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_DEFROSTZONE_LIST.get(i), defrostZone.get(i)); + } + for(int i = 0; i < Test.GENERAL_VENTILATIONMODE_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_VENTILATIONMODE_LIST.get(i), ventilationMode.get(i)); + } + + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, heatedSteeringWheelAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, heatedWindshieldAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, heatedRearWindowAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, heatedMirrorsAvailable); + // Invalid/Null Tests + ClimateControlCapabilities msg = new ClimateControlCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getModuleName()); + assertNull(Test.NULL, msg.getFanSpeedAvailable()); + assertNull(Test.NULL, msg.getDesiredTemperatureAvailable()); + assertNull(Test.NULL, msg.getAcEnableAvailable()); + assertNull(Test.NULL, msg.getAcMaxEnableAvailable()); + assertNull(Test.NULL, msg.getAutoModeEnableAvailable()); + assertNull(Test.NULL, msg.getDualModeEnableAvailable()); + assertNull(Test.NULL, msg.getDefrostZoneAvailable()); + assertNull(Test.NULL, msg.getDefrostZone()); + assertNull(Test.NULL, msg.getVentilationModeAvailable()); + assertNull(Test.NULL, msg.getVentilationMode()); + assertNull(Test.NULL, msg.getHeatedSteeringWheelAvailable()); + assertNull(Test.NULL, msg.getHeatedWindshieldAvailable()); + assertNull(Test.NULL, msg.getHeatedRearWindowAvailable()); + assertNull(Test.NULL, msg.getHeatedMirrorsAvailable()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(ClimateControlCapabilities.KEY_MODULE_NAME, Test.GENERAL_STRING); + reference.put(ClimateControlCapabilities.KEY_FAN_SPEED_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_DESIRED_TEMPERATURE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_AC_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_AC_MAX_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_CIRCULATE_AIR_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_AUTO_MODE_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_DUAL_MODE_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_DEFROST_ZONE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_VENTILATION_MODE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlCapabilities.KEY_DEFROST_ZONE, JsonUtils.createJsonArray(Test.GENERAL_DEFROSTZONE_LIST)); + reference.put(ClimateControlCapabilities.KEY_VENTILATION_MODE, JsonUtils.createJsonArray(Test.GENERAL_VENTILATIONMODE_LIST)); + reference.put(ClimateControlCapabilities.KEY_HEATED_STEERING_WHEEL_AVAILABLE, Test.GENERAL_BOOLEAN); + 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); + + 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(ClimateControlCapabilities.KEY_DEFROST_ZONE)) { + JSONArray defrostZoneArrayReference = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray defrostZoneArrayTest = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + List<DefrostZone> defrostZoneListReference = new ArrayList<DefrostZone>(); + List<DefrostZone> defrostZoneListTest = new ArrayList<DefrostZone>(); + + assertEquals(Test.MATCH, defrostZoneArrayReference.length(), defrostZoneArrayTest.length()); + + for (int index = 0 ; index < defrostZoneArrayReference.length(); index++) { + defrostZoneListReference.add( (DefrostZone)defrostZoneArrayReference.get(index) ); + defrostZoneListTest.add( (DefrostZone)defrostZoneArrayTest.get(index) ); + } + assertTrue(Test.TRUE, defrostZoneListReference.containsAll(defrostZoneListTest) && defrostZoneListTest.containsAll(defrostZoneListReference)); + } else if(key.equals(ClimateControlCapabilities.KEY_VENTILATION_MODE)) { + JSONArray ventilationModeArrayReference = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray ventilationModeArrayTest = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + List<VentilationMode> ventilationModeListReference = new ArrayList<VentilationMode>(); + List<VentilationMode> ventilationModeListTest = new ArrayList<VentilationMode>(); + + assertEquals(Test.MATCH, ventilationModeArrayReference.length(), ventilationModeArrayTest.length()); + + for (int index = 0 ; index < ventilationModeArrayReference.length(); index++) { + ventilationModeListReference.add( (VentilationMode)ventilationModeArrayReference.get(index) ); + ventilationModeListTest.add( (VentilationMode)ventilationModeArrayTest.get(index) ); + } + assertTrue(Test.TRUE, ventilationModeListReference.containsAll(ventilationModeListTest) && ventilationModeListTest.containsAll(ventilationModeListReference)); + } 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/ClimateControlDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlDataTests.java new file mode 100644 index 000000000..99d5c3285 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClimateControlDataTests.java @@ -0,0 +1,150 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.ClimateControlData; +import com.smartdevicelink.proxy.rpc.Temperature; +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; + +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.rpc.ClimateControlData} + */ +public class ClimateControlDataTests extends TestCase{ + + private ClimateControlData msg; + + @Override + public void setUp(){ + msg = new ClimateControlData(); + + msg.setFanSpeed(Test.GENERAL_INT); + msg.setCurrentTemperature(Test.GENERAL_TEMPERATURE); + msg.setDesiredTemperature(Test.GENERAL_TEMPERATURE); + msg.setAcEnable(Test.GENERAL_BOOLEAN); + msg.setCirculateAirEnable(Test.GENERAL_BOOLEAN); + msg.setAutoModeEnable(Test.GENERAL_BOOLEAN); + msg.setDefrostZone(Test.GENERAL_DEFROSTZONE); + msg.setDualModeEnable(Test.GENERAL_BOOLEAN); + msg.setAcMaxEnable(Test.GENERAL_BOOLEAN); + msg.setVentilationMode(Test.GENERAL_VENTILATIONMODE); + msg.setHeatedSteeringWheelEnable(Test.GENERAL_BOOLEAN); + msg.setHeatedWindshieldEnable(Test.GENERAL_BOOLEAN); + msg.setHeatedRearWindowEnable(Test.GENERAL_BOOLEAN); + msg.setHeatedMirrorsEnable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int fanSpeed = msg.getFanSpeed(); + Temperature currentTemperature = msg.getCurrentTemperature(); + Temperature desiredTemperature = msg.getDesiredTemperature(); + boolean acEnable = msg.getAcEnable(); + boolean circulateAirEnable = msg.getCirculateAirEnable(); + boolean autoModeEnable = msg.getAutoModeEnable(); + DefrostZone defrostZone = msg.getDefrostZone(); + boolean dualModeEnable = msg.getDualModeEnable(); + boolean acMaxEnable = msg.getAcMaxEnable(); + VentilationMode ventilationMode = msg.getVentilationMode(); + boolean heatedSteeringWheelEnable = msg.getHeatedSteeringWheelEnable(); + boolean heatedWindshieldEnable = msg.getHeatedWindshieldEnable(); + boolean heatedRearWindowEnable = msg.getHeatedRearWindowEnable(); + boolean heatedMirrorsEnable = msg.getHeatedMirrorsEnable(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, fanSpeed); + assertTrue(Test.TRUE, Validator.validateTemperature(Test.GENERAL_TEMPERATURE, currentTemperature)); + assertTrue(Test.TRUE, Validator.validateTemperature(Test.GENERAL_TEMPERATURE, desiredTemperature)); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, acEnable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, circulateAirEnable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, autoModeEnable); + assertEquals(Test.MATCH, Test.GENERAL_DEFROSTZONE, defrostZone); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, dualModeEnable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, acMaxEnable); + assertEquals(Test.MATCH, Test.GENERAL_VENTILATIONMODE, ventilationMode); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, heatedSteeringWheelEnable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, heatedWindshieldEnable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, heatedRearWindowEnable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, heatedMirrorsEnable); + + // Invalid/Null Tests + ClimateControlData msg = new ClimateControlData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getFanSpeed()); + assertNull(Test.NULL, msg.getCurrentTemperature()); + assertNull(Test.NULL, msg.getDesiredTemperature()); + assertNull(Test.NULL, msg.getAcEnable()); + assertNull(Test.NULL, msg.getCirculateAirEnable()); + assertNull(Test.NULL, msg.getAutoModeEnable()); + assertNull(Test.NULL, msg.getDefrostZone()); + assertNull(Test.NULL, msg.getDualModeEnable()); + assertNull(Test.NULL, msg.getAcMaxEnable()); + assertNull(Test.NULL, msg.getVentilationMode()); + assertNull(Test.NULL, msg.getHeatedSteeringWheelEnable()); + assertNull(Test.NULL, msg.getHeatedWindshieldEnable()); + assertNull(Test.NULL, msg.getHeatedRearWindowEnable()); + assertNull(Test.NULL, msg.getHeatedMirrorsEnable()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(ClimateControlData.KEY_FAN_SPEED, Test.GENERAL_INT); + reference.put(ClimateControlData.KEY_CURRENT_TEMPERATURE, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_TEMPERATURE.getStore())); + reference.put(ClimateControlData.KEY_DESIRED_TEMPERATURE, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_TEMPERATURE.getStore())); + reference.put(ClimateControlData.KEY_AC_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlData.KEY_CIRCULATE_AIR_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlData.KEY_AUTO_MODE_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlData.KEY_DUAL_MODE_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlData.KEY_AC_MAX_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlData.KEY_DEFROST_ZONE, Test.GENERAL_DEFROSTZONE); + reference.put(ClimateControlData.KEY_VENTILATION_MODE, Test.GENERAL_VENTILATIONMODE); + reference.put(ClimateControlData.KEY_HEATED_STEERING_WHEEL_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlData.KEY_HEATED_WIND_SHIELD_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlData.KEY_HEATED_REAR_WINDOW_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(ClimateControlData.KEY_HEATED_MIRRORS_ENABLE, Test.GENERAL_BOOLEAN); + + 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(ClimateControlData.KEY_CURRENT_TEMPERATURE)){ + 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.validateTemperature( new Temperature(hashReference), new Temperature(hashTest))); + } else if(key.equals(ClimateControlData.KEY_DESIRED_TEMPERATURE)){ + 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.validateTemperature( new Temperature(hashReference), new Temperature(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/CloudAppPropertiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/CloudAppPropertiesTests.java new file mode 100644 index 000000000..5340efdd2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/CloudAppPropertiesTests.java @@ -0,0 +1,96 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.CloudAppProperties; +import com.smartdevicelink.proxy.rpc.enums.HybridAppPreference; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.CloudAppProperties} + */ +public class CloudAppPropertiesTests extends TestCase{ + + private CloudAppProperties msg; + + @Override + public void setUp(){ + msg = new CloudAppProperties(); + + msg.setAppName(Test.GENERAL_STRING); + msg.setAppID(Test.GENERAL_STRING); + msg.setEnabled(Test.GENERAL_BOOLEAN); + msg.setAuthToken(Test.GENERAL_STRING); + msg.setCloudTransportType(Test.GENERAL_STRING); + msg.setHybridAppPreference(Test.GENERAL_HYBRID_APP_PREFERENCE); + msg.setEndpoint(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String appName = msg.getAppName(); + String appID = msg.getAppID(); + boolean enabled = msg.isEnabled(); + String authToken = msg.getAuthToken(); + String cloudTransportType = msg.getCloudTransportType(); + HybridAppPreference hybridAppPreference = msg.getHybridAppPreference(); + String endpoint = msg.getEndpoint(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, appName); + assertEquals(Test.MATCH, Test.GENERAL_STRING, appID); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, enabled); + assertEquals(Test.MATCH, Test.GENERAL_STRING, authToken); + assertEquals(Test.MATCH, Test.GENERAL_STRING, cloudTransportType); + assertEquals(Test.MATCH, Test.GENERAL_HYBRID_APP_PREFERENCE, hybridAppPreference); + assertEquals(Test.MATCH, Test.GENERAL_STRING, endpoint); + + // Invalid/Null Tests + CloudAppProperties msg = new CloudAppProperties(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getAppName()); + assertNull(Test.NULL, msg.getAppID()); + assertNull(Test.NULL, msg.isEnabled()); + assertNull(Test.NULL, msg.getAuthToken()); + assertNull(Test.NULL, msg.getCloudTransportType()); + assertNull(Test.NULL, msg.getHybridAppPreference()); + assertNull(Test.NULL, msg.getEndpoint()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(CloudAppProperties.KEY_APP_NAME, Test.GENERAL_STRING); + reference.put(CloudAppProperties.KEY_APP_ID, Test.GENERAL_STRING); + reference.put(CloudAppProperties.KEY_ENABLED, Test.GENERAL_BOOLEAN); + reference.put(CloudAppProperties.KEY_AUTH_TOKEN, Test.GENERAL_STRING); + reference.put(CloudAppProperties.KEY_CLOUD_TRANSPORT_TYPE, Test.GENERAL_STRING); + reference.put(CloudAppProperties.KEY_HYBRID_APP_PREFERENCE, Test.GENERAL_HYBRID_APP_PREFERENCE); + reference.put(CloudAppProperties.KEY_ENDPOINT, Test.GENERAL_STRING); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClusterModeStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClusterModeStatusTests.java new file mode 100644 index 000000000..883b456fa --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ClusterModeStatusTests.java @@ -0,0 +1,82 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.ClusterModeStatus; +import com.smartdevicelink.proxy.rpc.enums.CarModeStatus; +import com.smartdevicelink.proxy.rpc.enums.PowerModeQualificationStatus; +import com.smartdevicelink.proxy.rpc.enums.PowerModeStatus; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ClusterModeStatus} + */ +public class ClusterModeStatusTests extends TestCase{ + + private ClusterModeStatus msg; + + @Override + public void setUp(){ + msg = new ClusterModeStatus(); + + msg.setPowerModeActive(Test.GENERAL_BOOLEAN); + msg.setCarModeStatus(Test.GENERAL_CARMODESTATUS); + msg.setPowerModeQualificationStatus(Test.GENERAL_POWERMODEQUALIFICATIONSTATUS); + msg.setPowerModeStatus(Test.GENERAL_POWERMODESTATUS); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean powerMode = msg.getPowerModeActive(); + PowerModeQualificationStatus qualification = msg.getPowerModeQualificationStatus(); + PowerModeStatus status = msg.getPowerModeStatus(); + CarModeStatus carStatus = msg.getCarModeStatus(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, powerMode); + assertEquals(Test.MATCH, Test.GENERAL_POWERMODEQUALIFICATIONSTATUS, qualification); + assertEquals(Test.MATCH, Test.GENERAL_POWERMODESTATUS, status); + assertEquals(Test.MATCH, Test.GENERAL_CARMODESTATUS, carStatus); + + // Invalid/Null Tests + ClusterModeStatus msg = new ClusterModeStatus(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getPowerModeActive()); + assertNull(Test.NULL, msg.getPowerModeStatus()); + assertNull(Test.NULL, msg.getPowerModeQualificationStatus()); + assertNull(Test.NULL, msg.getCarModeStatus()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(ClusterModeStatus.KEY_POWER_MODE_ACTIVE, Test.GENERAL_BOOLEAN); + reference.put(ClusterModeStatus.KEY_POWER_MODE_STATUS, Test.GENERAL_POWERMODESTATUS); + reference.put(ClusterModeStatus.KEY_POWER_MODE_QUALIFICATION_STATUS, Test.GENERAL_POWERMODEQUALIFICATIONSTATUS); + reference.put(ClusterModeStatus.KEY_CAR_MODE_STATUS, Test.GENERAL_CARMODESTATUS); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/CoordinateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/CoordinateTests.java new file mode 100644 index 000000000..5f8a8327f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/CoordinateTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.Coordinate; +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; + +/** + * Created by austinkirk on 6/6/17. + */ + +public class CoordinateTests extends TestCase { + + private Coordinate msg; + + @Override + public void setUp(){ + msg = new Coordinate(); + + msg.setLatitudeDegrees(Test.GENERAL_FLOAT); + msg.setLongitudeDegrees(Test.GENERAL_FLOAT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + float floatLat = msg.getLatitudeDegrees(); + float floatLong = msg.getLongitudeDegrees(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, floatLat); + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, floatLong); + // Invalid/Null Tests + Coordinate msg = new Coordinate(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getLatitudeDegrees()); + assertNull(Test.NULL, msg.getLongitudeDegrees()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(Coordinate.KEY_LATITUDE_DEGREES, (Float) Test.GENERAL_FLOAT); + reference.put(Coordinate.KEY_LONGITUDE_DEGREES, (Float) Test.GENERAL_FLOAT); + + JSONObject underTest = msg.serializeJSON(); + + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while(iterator.hasNext()){ + String key = (String) iterator.next(); + + Object a = JsonUtils.readObjectFromJsonObject(reference, key); + Object b = JsonUtils.readObjectFromJsonObject(underTest, key); + + assertEquals(Test.MATCH, a, b); + } + } 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/DIDResultTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DIDResultTests.java new file mode 100644 index 000000000..b929f2f80 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DIDResultTests.java @@ -0,0 +1,70 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.DIDResult; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataResultCode; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DIDResult} + */ +public class DIDResultTests extends TestCase { + + private DIDResult msg; + + @Override + public void setUp(){ + msg = new DIDResult(); + + msg.setData(Test.GENERAL_STRING); + msg.setResultCode(Test.GENERAL_VEHICLEDATARESULTCODE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String data = msg.getData(); + VehicleDataResultCode resultCode = msg.getResultCode(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, data); + assertEquals(Test.MATCH, Test.GENERAL_VEHICLEDATARESULTCODE, resultCode); + + // Invalid/Null Tests + DIDResult msg = new DIDResult(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getData()); + assertNull(Test.NULL, msg.getResultCode()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(DIDResult.KEY_DATA, Test.GENERAL_STRING); + reference.put(DIDResult.KEY_RESULT_CODE, Test.GENERAL_VEHICLEDATARESULTCODE); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DTCTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DTCTests.java new file mode 100644 index 000000000..3079d2003 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DTCTests.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.DTC; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DTC} + */ +public class DTCTests extends TestCase{ + + private DTC msg; + + @Override + public void setUp(){ + msg = new DTC(); + + msg.setIdentifier(Test.GENERAL_STRING); + msg.setStatusByte(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String identifier = msg.getIdentifier(); + String statusByte = msg.getStatusByte(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, identifier); + assertEquals(Test.MATCH, Test.GENERAL_STRING, statusByte); + + // Invalid/Null Tests + DTC msg = new DTC(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getIdentifier()); + assertNull(Test.NULL, msg.getStatusByte()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(DTC.KEY_IDENTIFIER, Test.GENERAL_STRING); + reference.put(DTC.KEY_STATUS_BYTE, Test.GENERAL_STRING); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DateTimeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DateTimeTests.java new file mode 100644 index 000000000..2cf38b68f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DateTimeTests.java @@ -0,0 +1,109 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.DateTime; +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; + +/** + * Created by austinkirk on 6/6/17. + */ + +public class DateTimeTests extends TestCase { + + private DateTime msg; + + @Override + public void setUp(){ + msg = new DateTime(); + + msg.setYear(Test.GENERAL_INT); + msg.setMonth(Test.GENERAL_INT); + msg.setDay(Test.GENERAL_INT); + msg.setHour(Test.GENERAL_INT); + msg.setMinute(Test.GENERAL_INT); + msg.setSecond(Test.GENERAL_INT); + msg.setMilliSecond(Test.GENERAL_INT); + msg.setTzHour(Test.GENERAL_INT); + msg.setTzMinute(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer year = msg.getYear(); + Integer month = msg.getMonth(); + Integer day = msg.getDay(); + Integer hour = msg.getHour(); + Integer min = msg.getMinute(); + Integer sec = msg.getSecond(); + Integer ms = msg.getMilliSecond(); + Integer tzHour = msg.getTzHour(); + Integer tzMin = msg.getTzMinute(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, year); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, month); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, day); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, hour); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, min); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, sec); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, ms); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, tzHour); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, tzMin); + + // Invalid/Null Tests + DateTime msg = new DateTime(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getYear()); + assertNull(Test.NULL, msg.getMonth()); + assertNull(Test.NULL, msg.getDay()); + assertNull(Test.NULL, msg.getHour()); + assertNull(Test.NULL, msg.getMinute()); + assertNull(Test.NULL, msg.getSecond()); + assertNull(Test.NULL, msg.getMilliSecond()); + assertNull(Test.NULL, msg.getTzHour()); + assertNull(Test.NULL, msg.getTzMinute()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(DateTime.KEY_YEAR, (Integer) Test.GENERAL_INT); + reference.put(DateTime.KEY_MONTH, (Integer) Test.GENERAL_INT); + reference.put(DateTime.KEY_DAY, (Integer) Test.GENERAL_INT); + reference.put(DateTime.KEY_HOUR, (Integer) Test.GENERAL_INT); + reference.put(DateTime.KEY_MINUTE, (Integer) Test.GENERAL_INT); + reference.put(DateTime.KEY_SECOND, (Integer) Test.GENERAL_INT); + reference.put(DateTime.KEY_MILLISECOND, (Integer) Test.GENERAL_INT); + reference.put(DateTime.KEY_TZ_HOUR, (Integer) Test.GENERAL_INT); + reference.put(DateTime.KEY_TZ_MINUTE, (Integer) Test.GENERAL_INT); + + JSONObject underTest = msg.serializeJSON(); + + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while(iterator.hasNext()){ + String key = (String) iterator.next(); + + Object a = JsonUtils.readObjectFromJsonObject(reference, key); + Object b = JsonUtils.readObjectFromJsonObject(underTest, key); + + assertEquals(Test.MATCH, a, b); + } + } 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/DeviceInfoTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DeviceInfoTests.java new file mode 100644 index 000000000..cbd432cc2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DeviceInfoTests.java @@ -0,0 +1,89 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.DeviceInfo; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeviceInfo} + */ +public class DeviceInfoTests extends TestCase{ + + private DeviceInfo msg; + + @Override + public void setUp(){ + msg = new DeviceInfo(); + + msg.setCarrier(Test.GENERAL_STRING); + msg.setFirmwareRev(Test.GENERAL_STRING); + msg.setHardware(Test.GENERAL_STRING); + msg.setMaxNumberRFCOMMPorts(Test.GENERAL_INT); + msg.setOs(Test.GENERAL_STRING); + msg.setOsVersion(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String carrier = msg.getCarrier(); + String hardware = msg.getHardware(); + String firmwareRev = msg.getFirmwareRev(); + String os = msg.getOs(); + String osVer = msg.getOsVersion(); + int maxNum = msg.getMaxNumberRFCOMMPorts(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, maxNum); + assertEquals(Test.MATCH, Test.GENERAL_STRING, osVer); + assertEquals(Test.MATCH, Test.GENERAL_STRING, os); + assertEquals(Test.MATCH, Test.GENERAL_STRING, firmwareRev); + assertEquals(Test.MATCH, Test.GENERAL_STRING, hardware); + assertEquals(Test.MATCH, Test.GENERAL_STRING, carrier); + + // Invalid/Null Tests + DeviceInfo msg = new DeviceInfo(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getCarrier()); + assertNull(Test.NULL, msg.getHardware()); + assertNull(Test.NULL, msg.getFirmwareRev()); + assertNull(Test.NULL, msg.getOs()); + assertNull(Test.NULL, msg.getOsVersion()); + assertNull(Test.NULL, msg.getMaxNumberRFCOMMPorts()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(DeviceInfo.KEY_CARRIER, Test.GENERAL_STRING); + reference.put(DeviceInfo.KEY_HARDWARE, Test.GENERAL_STRING); + reference.put(DeviceInfo.KEY_FIRMWARE_REV, Test.GENERAL_STRING); + reference.put(DeviceInfo.KEY_OS, Test.GENERAL_STRING); + reference.put(DeviceInfo.KEY_OS_VERSION, Test.GENERAL_STRING); + reference.put(DeviceInfo.KEY_MAX_NUMBER_RFCOMM_PORTS, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DeviceStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DeviceStatusTests.java new file mode 100644 index 000000000..4c966f06e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DeviceStatusTests.java @@ -0,0 +1,116 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.DeviceStatus; +import com.smartdevicelink.proxy.rpc.enums.DeviceLevelStatus; +import com.smartdevicelink.proxy.rpc.enums.PrimaryAudioSource; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeviceStatus} + */ +public class DeviceStatusTests extends TestCase { + + private DeviceStatus msg; + + @Override + public void setUp(){ + msg = new DeviceStatus(); + + msg.setBattLevelStatus(Test.GENERAL_DEVICELEVELSTATUS); + msg.setBtIconOn(Test.GENERAL_BOOLEAN); + msg.setCallActive(Test.GENERAL_BOOLEAN); + msg.setECallEventActive(Test.GENERAL_BOOLEAN); + msg.setMonoAudioOutputMuted(Test.GENERAL_BOOLEAN); + msg.setPhoneRoaming(Test.GENERAL_BOOLEAN); + msg.setPrimaryAudioSource(Test.GENERAL_PRIMARYAUDIOSOURCE); + msg.setSignalLevelStatus(Test.GENERAL_DEVICELEVELSTATUS); + msg.setStereoAudioOutputMuted(Test.GENERAL_BOOLEAN); + msg.setTextMsgAvailable(Test.GENERAL_BOOLEAN); + msg.setVoiceRecOn(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + DeviceLevelStatus battLevel = msg.getBattLevelStatus(); + boolean btIcon = msg.getBtIconOn(); + boolean callActive = msg.getCallActive(); + boolean ecall = msg.getECallEventActive(); + boolean monoAudio = msg.getMonoAudioOutputMuted(); + boolean phoneRoaming = msg.getPhoneRoaming(); + PrimaryAudioSource primaryAudio = msg.getPrimaryAudioSource(); + DeviceLevelStatus signalLevel = msg.getSignalLevelStatus(); + boolean stereoAudio = msg.getStereoAudioOutputMuted(); + boolean textAvailable = msg.getTextMsgAvailable(); + boolean voiceRec = msg.getVoiceRecOn(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_DEVICELEVELSTATUS, battLevel); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, btIcon); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, callActive); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, ecall); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, monoAudio); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, phoneRoaming); + assertEquals(Test.MATCH, Test.GENERAL_PRIMARYAUDIOSOURCE, primaryAudio); + assertEquals(Test.MATCH, Test.GENERAL_DEVICELEVELSTATUS, signalLevel); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, stereoAudio); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, textAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, voiceRec); + + // Invalid/Null Tests + DeviceStatus msg = new DeviceStatus(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getBattLevelStatus()); + assertNull(Test.NULL, msg.getBtIconOn()); + assertNull(Test.NULL, msg.getCallActive()); + assertNull(Test.NULL, msg.getECallEventActive()); + assertNull(Test.NULL, msg.getMonoAudioOutputMuted()); + assertNull(Test.NULL, msg.getPhoneRoaming()); + assertNull(Test.NULL, msg.getPrimaryAudioSource()); + assertNull(Test.NULL, msg.getSignalLevelStatus()); + assertNull(Test.NULL, msg.getStereoAudioOutputMuted()); + assertNull(Test.NULL, msg.getTextMsgAvailable()); + assertNull(Test.NULL, msg.getVoiceRecOn()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(DeviceStatus.KEY_BATT_LEVEL_STATUS, Test.GENERAL_DEVICELEVELSTATUS); + reference.put(DeviceStatus.KEY_SIGNAL_LEVEL_STATUS, Test.GENERAL_DEVICELEVELSTATUS); + reference.put(DeviceStatus.KEY_PRIMARY_AUDIO_SOURCE, Test.GENERAL_PRIMARYAUDIOSOURCE); + reference.put(DeviceStatus.KEY_BT_ICON_ON, Test.GENERAL_BOOLEAN); + reference.put(DeviceStatus.KEY_CALL_ACTIVE, Test.GENERAL_BOOLEAN); + reference.put(DeviceStatus.KEY_E_CALL_EVENT_ACTIVE, Test.GENERAL_BOOLEAN); + reference.put(DeviceStatus.KEY_MONO_AUDIO_OUTPUT_MUTED, Test.GENERAL_BOOLEAN); + reference.put(DeviceStatus.KEY_STEREO_AUDIO_OUTPUT_MUTED, Test.GENERAL_BOOLEAN); + reference.put(DeviceStatus.KEY_TEXT_MSG_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(DeviceStatus.KEY_PHONE_ROAMING, Test.GENERAL_BOOLEAN); + reference.put(DeviceStatus.KEY_VOICE_REC_ON, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DisplayCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DisplayCapabilitiesTests.java new file mode 100644 index 000000000..9e627c217 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/DisplayCapabilitiesTests.java @@ -0,0 +1,172 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.DisplayCapabilities; +import com.smartdevicelink.proxy.rpc.ImageField; +import com.smartdevicelink.proxy.rpc.ScreenParams; +import com.smartdevicelink.proxy.rpc.TextField; +import com.smartdevicelink.proxy.rpc.enums.DisplayType; +import com.smartdevicelink.proxy.rpc.enums.MediaClockFormat; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DisplayCapabilities} + */ +public class DisplayCapabilitiesTests extends TestCase{ + + private DisplayCapabilities msg; + + @Override + public void setUp(){ + msg = new DisplayCapabilities(); + + msg.setGraphicSupported(Test.GENERAL_BOOLEAN); + msg.setNumCustomPresetsAvailable(Test.GENERAL_INT); + msg.setDisplayType(Test.GENERAL_DISPLAYTYPE); + msg.setDisplayName(Test.GENERAL_STRING); + msg.setImageFields(Test.GENERAL_IMAGEFIELD_LIST); + msg.setTextFields(Test.GENERAL_TEXTFIELD_LIST); + msg.setMediaClockFormats(Test.GENERAL_MEDIACLOCKFORMAT_LIST); + msg.setScreenParams(Test.GENERAL_SCREENPARAMS); + msg.setTemplatesAvailable(Test.GENERAL_STRING_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean graphicSupported = msg.getGraphicSupported(); + int numPresets = msg.getNumCustomPresetsAvailable(); + DisplayType displayType = msg.getDisplayType(); + String displayName = msg.getDisplayName(); + ScreenParams screenParams = msg.getScreenParams(); + List<String> templatesAvailable = msg.getTemplatesAvailable(); + List<MediaClockFormat> mediaClock = msg.getMediaClockFormats(); + List<TextField> textFields = msg.getTextFields(); + List<ImageField> imageFields = msg.getImageFields(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, graphicSupported); + assertEquals(Test.MATCH, Test.GENERAL_INT, numPresets); + assertEquals(Test.MATCH, Test.GENERAL_DISPLAYTYPE, displayType); + assertEquals(Test.MATCH, Test.GENERAL_STRING, displayName); + assertTrue(Test.TRUE, Validator.validateScreenParams(Test.GENERAL_SCREENPARAMS, screenParams)); + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.size(), templatesAvailable.size()); + assertEquals(Test.MATCH, Test.GENERAL_MEDIACLOCKFORMAT_LIST.size(), mediaClock.size()); + assertEquals(Test.MATCH, Test.GENERAL_TEXTFIELD_LIST.size(), textFields.size()); + assertEquals(Test.MATCH, Test.GENERAL_IMAGEFIELD_LIST.size(), imageFields.size()); + + for(int i = 0; i < Test.GENERAL_STRING_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.get(i), templatesAvailable.get(i)); + } + + for(int i = 0; i < Test.GENERAL_MEDIACLOCKFORMAT_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_MEDIACLOCKFORMAT_LIST.get(i), mediaClock.get(i)); + } + + 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))); + } + + // Invalid/Null Tests + DisplayCapabilities msg = new DisplayCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getDisplayType()); + assertNull(Test.NULL, msg.getDisplayName()); + assertNull(Test.NULL, msg.getGraphicSupported()); + assertNull(Test.NULL, msg.getImageFields()); + assertNull(Test.NULL, msg.getMediaClockFormats()); + assertNull(Test.NULL, msg.getNumCustomPresetsAvailable()); + assertNull(Test.NULL, msg.getScreenParams()); + assertNull(Test.NULL, msg.getTemplatesAvailable()); + assertNull(Test.NULL, msg.getTextFields()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(DisplayCapabilities.KEY_NUM_CUSTOM_PRESETS_AVAILABLE, Test.GENERAL_INT); + reference.put(DisplayCapabilities.KEY_GRAPHIC_SUPPORTED, Test.GENERAL_BOOLEAN); + reference.put(DisplayCapabilities.KEY_DISPLAY_TYPE, Test.GENERAL_DISPLAYTYPE); + reference.put(DisplayCapabilities.KEY_DISPLAY_NAME, Test.GENERAL_STRING); + reference.put(DisplayCapabilities.KEY_TEMPLATES_AVAILABLE, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + reference.put(DisplayCapabilities.KEY_MEDIA_CLOCK_FORMATS, JsonUtils.createJsonArray(Test.GENERAL_MEDIACLOCKFORMAT_LIST)); + reference.put(DisplayCapabilities.KEY_TEXT_FIELDS, Test.JSON_TEXTFIELDS); + reference.put(DisplayCapabilities.KEY_IMAGE_FIELDS, Test.JSON_IMAGEFIELDS); + reference.put(DisplayCapabilities.KEY_SCREEN_PARAMS, Test.JSON_SCREENPARAMS); + + 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(DisplayCapabilities.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(DisplayCapabilities.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(DisplayCapabilities.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(DisplayCapabilities.KEY_SCREEN_PARAMS)){ + JSONObject referenceArray = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject underTestArray = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(referenceArray); + Hashtable<String, Object> hashTest= JsonRPCMarshaller.deserializeJSONObject(underTestArray); + + assertTrue(Test.TRUE, Validator.validateScreenParams(new ScreenParams(hashReference), new ScreenParams(hashTest))); + } else if(key.equals(DisplayCapabilities.KEY_MEDIA_CLOCK_FORMATS)){ + 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++){ + assertTrue(Test.TRUE, Validator.validateText(referenceArray.getString(i), underTestArray.getString(i)));// not a string? + } + } 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/ECallInfoTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ECallInfoTests.java new file mode 100644 index 000000000..82a57869a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ECallInfoTests.java @@ -0,0 +1,76 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.ECallInfo; +import com.smartdevicelink.proxy.rpc.enums.ECallConfirmationStatus; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataNotificationStatus; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ECallInfo} + */ +public class ECallInfoTests extends TestCase{ + + private ECallInfo msg; + + @Override + public void setUp(){ + msg = new ECallInfo(); + + msg.setAuxECallNotificationStatus(Test.GENERAL_VEHICLEDATANOTIFICATIONSTATUS); + msg.setECallConfirmationStatus(Test.GENERAL_ECALLCONFIRMATIONSTATUS); + msg.setECallNotificationStatus(Test.GENERAL_VEHICLEDATANOTIFICATIONSTATUS); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + VehicleDataNotificationStatus auxEcall = msg.getAuxECallNotificationStatus(); + VehicleDataNotificationStatus ecallNotify = msg.getECallNotificationStatus(); + ECallConfirmationStatus ecallConfirm = msg.getECallConfirmationStatus(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_VEHICLEDATANOTIFICATIONSTATUS, auxEcall); + assertEquals(Test.MATCH, Test.GENERAL_VEHICLEDATANOTIFICATIONSTATUS, ecallNotify); + assertEquals(Test.MATCH, Test.GENERAL_ECALLCONFIRMATIONSTATUS, ecallConfirm); + + // Invalid/Null Tests + ECallInfo msg = new ECallInfo(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getECallConfirmationStatus()); + assertNull(Test.NULL, msg.getECallNotificationStatus()); + assertNull(Test.NULL, msg.getAuxECallNotificationStatus()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(ECallInfo.KEY_AUX_E_CALL_NOTIFICATION_STATUS, Test.GENERAL_VEHICLEDATANOTIFICATIONSTATUS); + reference.put(ECallInfo.KEY_E_CALL_NOTIFICATION_STATUS, Test.GENERAL_VEHICLEDATANOTIFICATIONSTATUS); + reference.put(ECallInfo.KEY_E_CALL_CONFIRMATION_STATUS, Test.GENERAL_ECALLCONFIRMATIONSTATUS); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/EmergencyEventTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/EmergencyEventTests.java new file mode 100644 index 000000000..6d72e440f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/EmergencyEventTests.java @@ -0,0 +1,87 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.EmergencyEvent; +import com.smartdevicelink.proxy.rpc.enums.EmergencyEventType; +import com.smartdevicelink.proxy.rpc.enums.FuelCutoffStatus; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataEventStatus; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.EmergencyEvent} + */ +public class EmergencyEventTests extends TestCase{ + + private EmergencyEvent msg; + + @Override + public void setUp(){ + msg = new EmergencyEvent(); + + msg.setEmergencyEventType(Test.GENERAL_EMERGENCYEVENTTYPE); + msg.setFuelCutoffStatus(Test.GENERAL_FUELCUTOFFSTATUS); + msg.setMaximumChangeVelocity(Test.GENERAL_INT); + msg.setMultipleEvents(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + msg.setRolloverEvent(Test.GENERAL_VEHCILEDATAEVENTSTATUS); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + EmergencyEventType type = msg.getEmergencyEventType(); + FuelCutoffStatus cutoffStatus = msg.getFuelCutoffStatus(); + VehicleDataEventStatus multipleEvents = msg.getMultipleEvents(); + int changeVelocity = msg.getMaximumChangeVelocity(); + VehicleDataEventStatus rollover = msg.getRolloverEvent(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_EMERGENCYEVENTTYPE, type); + assertEquals(Test.MATCH, Test.GENERAL_FUELCUTOFFSTATUS, cutoffStatus); + assertEquals(Test.MATCH, Test.GENERAL_INT, changeVelocity); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, multipleEvents); + assertEquals(Test.MATCH, Test.GENERAL_VEHCILEDATAEVENTSTATUS, rollover); + + // Invalid/Null Tests + EmergencyEvent msg = new EmergencyEvent(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getEmergencyEventType()); + assertNull(Test.NULL, msg.getFuelCutoffStatus()); + assertNull(Test.NULL, msg.getMaximumChangeVelocity()); + assertNull(Test.NULL, msg.getMultipleEvents()); + assertNull(Test.NULL, msg.getRolloverEvent()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(EmergencyEvent.KEY_FUEL_CUTOFF_STATUS, Test.GENERAL_FUELCUTOFFSTATUS); + reference.put(EmergencyEvent.KEY_MULTIPLE_EVENTS, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(EmergencyEvent.KEY_ROLLOVER_EVENT, Test.GENERAL_VEHCILEDATAEVENTSTATUS); + reference.put(EmergencyEvent.KEY_EMERGENCY_EVENT_TYPE, Test.GENERAL_EMERGENCYEVENTTYPE); + reference.put(EmergencyEvent.KEY_MAXIMUM_CHANGE_VELOCITY, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/EqualizerSettingsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/EqualizerSettingsTests.java new file mode 100644 index 000000000..a803b1ded --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/EqualizerSettingsTests.java @@ -0,0 +1,78 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.EqualizerSettings; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.EqualizerSettings} + */ +public class EqualizerSettingsTests extends TestCase { + + private EqualizerSettings msg; + + @Override + public void setUp() { + msg = new EqualizerSettings(); + + msg.setChannelId(Test.GENERAL_INT); + msg.setChannelName(Test.GENERAL_STRING); + msg.setChannelSetting(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + + int channelId = msg.getChannelId(); + String channelName = msg.getChannelName(); + int channelSetting = msg.getChannelSetting(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, channelId); + assertEquals(Test.MATCH, Test.GENERAL_STRING, channelName); + assertEquals(Test.MATCH, Test.GENERAL_INT, channelSetting); + + // Invalid/Null Tests + EqualizerSettings msg = new EqualizerSettings(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getChannelId()); + assertNull(Test.NULL, msg.getChannelName()); + assertNull(Test.NULL, msg.getChannelSetting()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + + reference.put(EqualizerSettings.KEY_CHANNEL_ID, Test.GENERAL_INT); + reference.put(EqualizerSettings.KEY_CHANNEL_NAME, Test.GENERAL_STRING); + reference.put(EqualizerSettings.KEY_CHANNEL_SETTING, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/FuelRangeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/FuelRangeTests.java new file mode 100644 index 000000000..2dffd2f5b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/FuelRangeTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.FuelRange; +import com.smartdevicelink.proxy.rpc.enums.FuelType; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.FuelRange} + */ +public class FuelRangeTests extends TestCase{ + + private FuelRange msg; + + @Override + public void setUp(){ + msg = new FuelRange(); + + msg.setType(Test.GENERAL_FUELTYPE); + msg.setRange(Test.GENERAL_FLOAT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + FuelType fuelType = msg.getType(); + float range = msg.getRange(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, range); + assertEquals(Test.MATCH, Test.GENERAL_FUELTYPE, fuelType); + + // Invalid/Null Tests + FuelRange msg = new FuelRange(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getType()); + assertNull(Test.NULL, msg.getRange()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(FuelRange.KEY_TYPE, Test.GENERAL_FUELTYPE); + reference.put(FuelRange.KEY_RANGE, (Float) Test.GENERAL_FLOAT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GPSDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GPSDataTests.java new file mode 100644 index 000000000..0c6800ea5 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/GPSDataTests.java @@ -0,0 +1,151 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.GPSData; +import com.smartdevicelink.proxy.rpc.enums.CompassDirection; +import com.smartdevicelink.proxy.rpc.enums.Dimension; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.GPSData} + */ +public class GPSDataTests extends TestCase{ + + private GPSData msg; + + @Override + public void setUp(){ + msg = new GPSData(); + + msg.setActual(Test.GENERAL_BOOLEAN); + msg.setAltitude(Test.GENERAL_DOUBLE); + msg.setCompassDirection(Test.GENERAL_COMPASSDIRECTION); + msg.setDimension(Test.GENERAL_DIMENSION); + msg.setHdop(Test.GENERAL_DOUBLE); + msg.setHeading(Test.GENERAL_DOUBLE); + msg.setLatitudeDegrees(Test.GENERAL_DOUBLE); + msg.setLongitudeDegrees(Test.GENERAL_DOUBLE); + msg.setPdop(Test.GENERAL_DOUBLE); + msg.setSatellites(Test.GENERAL_INT); + msg.setSpeed(Test.GENERAL_DOUBLE); + msg.setUtcDay(Test.GENERAL_INT); + msg.setUtcHours(Test.GENERAL_INT); + msg.setUtcMinutes(Test.GENERAL_INT); + msg.setUtcMonth(Test.GENERAL_INT); + msg.setUtcSeconds(Test.GENERAL_INT); + msg.setUtcYear(Test.GENERAL_INT); + msg.setVdop(Test.GENERAL_DOUBLE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean actual = msg.getActual(); + double latitude = msg.getLatitudeDegrees(); + double longitude = msg.getLongitudeDegrees(); + double altitude = msg.getAltitude(); + double heading = msg.getHeading(); + double speed = msg.getSpeed(); + double pdop = msg.getPdop(); + double hdop = msg.getHdop(); + double vdop = msg.getVdop(); + int utcYear = msg.getUtcYear(); + int utcMin = msg.getUtcMinutes(); + int utcMonths = msg.getUtcMonth(); + int utcDay = msg.getUtcDay(); + int utcHours = msg.getUtcHours(); + int utcSec = msg.getUtcSeconds(); + int satellites = msg.getSatellites(); + Dimension dimension = msg.getDimension(); + CompassDirection direction = msg.getCompassDirection(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, actual); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, latitude); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, longitude); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, altitude); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, heading); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, speed); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, pdop); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, hdop); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, vdop); + assertEquals(Test.MATCH, Test.GENERAL_INT, utcYear); + assertEquals(Test.MATCH, Test.GENERAL_INT, utcMin); + assertEquals(Test.MATCH, Test.GENERAL_INT, utcMonths); + assertEquals(Test.MATCH, Test.GENERAL_INT, utcDay); + assertEquals(Test.MATCH, Test.GENERAL_INT, utcHours); + assertEquals(Test.MATCH, Test.GENERAL_INT, utcSec); + assertEquals(Test.MATCH, Test.GENERAL_INT, satellites); + assertEquals(Test.MATCH, Test.GENERAL_DIMENSION, dimension); + assertEquals(Test.MATCH, Test.GENERAL_COMPASSDIRECTION, direction); + + // Invalid/Null Tests + GPSData msg = new GPSData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getActual()); + assertNull(Test.NULL, msg.getAltitude()); + assertNull(Test.NULL, msg.getCompassDirection()); + assertNull(Test.NULL, msg.getDimension()); + assertNull(Test.NULL, msg.getHdop()); + assertNull(Test.NULL, msg.getHeading()); + assertNull(Test.NULL, msg.getLatitudeDegrees()); + assertNull(Test.NULL, msg.getLongitudeDegrees()); + assertNull(Test.NULL, msg.getPdop()); + assertNull(Test.NULL, msg.getSatellites()); + assertNull(Test.NULL, msg.getSpeed()); + assertNull(Test.NULL, msg.getUtcDay()); + assertNull(Test.NULL, msg.getUtcHours()); + assertNull(Test.NULL, msg.getUtcMinutes()); + assertNull(Test.NULL, msg.getUtcMonth()); + assertNull(Test.NULL, msg.getUtcSeconds()); + assertNull(Test.NULL, msg.getUtcYear()); + assertNull(Test.NULL, msg.getVdop()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(GPSData.KEY_ACTUAL, Test.GENERAL_BOOLEAN); + reference.put(GPSData.KEY_LATITUDE_DEGREES, Test.GENERAL_DOUBLE); + reference.put(GPSData.KEY_LONGITUDE_DEGREES, Test.GENERAL_DOUBLE); + reference.put(GPSData.KEY_ALTITUDE, Test.GENERAL_DOUBLE); + reference.put(GPSData.KEY_HEADING, Test.GENERAL_DOUBLE); + reference.put(GPSData.KEY_SPEED, Test.GENERAL_DOUBLE); + reference.put(GPSData.KEY_PDOP, Test.GENERAL_DOUBLE); + reference.put(GPSData.KEY_HDOP, Test.GENERAL_DOUBLE); + reference.put(GPSData.KEY_VDOP, Test.GENERAL_DOUBLE); + reference.put(GPSData.KEY_UTC_YEAR, Test.GENERAL_INT); + reference.put(GPSData.KEY_UTC_MONTH, Test.GENERAL_INT); + reference.put(GPSData.KEY_UTC_HOURS, Test.GENERAL_INT); + reference.put(GPSData.KEY_UTC_DAY, Test.GENERAL_INT); + reference.put(GPSData.KEY_UTC_MINUTES, Test.GENERAL_INT); + reference.put(GPSData.KEY_UTC_SECONDS, Test.GENERAL_INT); + reference.put(GPSData.KEY_SATELLITES, Test.GENERAL_INT); + reference.put(GPSData.KEY_DIMENSION, Test.GENERAL_DIMENSION); + reference.put(GPSData.KEY_COMPASS_DIRECTION, Test.GENERAL_COMPASSDIRECTION); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMICapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMICapabilitiesTests.java new file mode 100644 index 000000000..cc4813caa --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMICapabilitiesTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.HMICapabilities; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import static com.smartdevicelink.proxy.rpc.HMICapabilities.KEY_NAVIGATION; +import static com.smartdevicelink.proxy.rpc.HMICapabilities.KEY_PHONE_CALL; +import static com.smartdevicelink.proxy.rpc.HMICapabilities.KEY_VIDEO_STREAMING; + +public class HMICapabilitiesTests extends TestCase { + private HMICapabilities msg; + + @Override + public void setUp(){ + msg = new HMICapabilities(); + + msg.setNavigationAvilable(Test.GENERAL_BOOLEAN); + msg.setPhoneCallAvilable(Test.GENERAL_BOOLEAN); + msg.setVideoStreamingAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Boolean navAvail = msg.isNavigationAvailable(); + Boolean phoneAvail = msg.isPhoneCallAvailable(); + Boolean vidStreamAvail = msg.isVideoStreamingAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, navAvail); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, phoneAvail); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, vidStreamAvail); + + // Invalid/Null Tests + HMICapabilities msg = new HMICapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertFalse(msg.isNavigationAvailable()); + assertFalse(msg.isPhoneCallAvailable()); + assertFalse(msg.isVideoStreamingAvailable()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(KEY_NAVIGATION, Test.GENERAL_BOOLEAN); + reference.put(HMICapabilities.KEY_PHONE_CALL, Test.GENERAL_BOOLEAN); + reference.put(HMICapabilities.KEY_VIDEO_STREAMING, Test.GENERAL_BOOLEAN); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + assertEquals(Test.MATCH, JsonUtils.readStringListFromJsonObject(reference, KEY_NAVIGATION), + JsonUtils.readStringListFromJsonObject(underTest, KEY_NAVIGATION)); + + assertEquals(Test.MATCH, JsonUtils.readStringListFromJsonObject(reference, KEY_PHONE_CALL), + JsonUtils.readStringListFromJsonObject(underTest, KEY_PHONE_CALL)); + + assertEquals(Test.MATCH, JsonUtils.readStringListFromJsonObject(reference, KEY_VIDEO_STREAMING), + JsonUtils.readStringListFromJsonObject(underTest, KEY_VIDEO_STREAMING)); + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMIPermissionsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMIPermissionsTests.java new file mode 100644 index 000000000..fd82505f2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMIPermissionsTests.java @@ -0,0 +1,84 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.HMIPermissions; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.HMIPermissions} + */ +public class HMIPermissionsTests extends TestCase{ + + private HMIPermissions msg; + + @Override + public void setUp(){ + msg = new HMIPermissions(); + + msg.setAllowed(Test.GENERAL_HMILEVEL_LIST); + msg.setUserDisallowed(Test.GENERAL_HMILEVEL_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<HMILevel> allowed = msg.getAllowed(); + List<HMILevel> disallowed = msg.getUserDisallowed(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_HMILEVEL_LIST.size(), allowed.size()); + assertEquals(Test.MATCH, Test.GENERAL_HMILEVEL_LIST.size(), disallowed.size()); + + for(int i = 0; i < Test.GENERAL_HMILEVEL_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_HMILEVEL_LIST.get(i), allowed.get(i)); + } + for(int i = 0; i < Test.GENERAL_HMILEVEL_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_HMILEVEL_LIST.get(i), disallowed.get(i)); + } + + // Invalid/Null Tests + HMIPermissions msg = new HMIPermissions(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getAllowed()); + assertNull(Test.NULL, msg.getUserDisallowed()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(HMIPermissions.KEY_ALLOWED, Test.JSON_HMILEVELS); + reference.put(HMIPermissions.KEY_USER_DISALLOWED, Test.JSON_HMILEVELS); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while(iterator.hasNext()){ + String key = (String) iterator.next(); + 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)); + } + } + } 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/HMISettingsControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java new file mode 100644 index 000000000..620868b40 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlCapabilitiesTests.java @@ -0,0 +1,80 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.HMISettingsControlCapabilities; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.HMISettingsControlCapabilities} + */ +public class HMISettingsControlCapabilitiesTests extends TestCase { + + private HMISettingsControlCapabilities msg; + + @Override + public void setUp() { + msg = new HMISettingsControlCapabilities(); + + msg.setModuleName(Test.GENERAL_STRING); + msg.setDistanceUnitAvailable(Test.GENERAL_BOOLEAN); + msg.setTemperatureUnitAvailable(Test.GENERAL_BOOLEAN); + msg.setDisplayModeUnitAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + String moduleName = msg.getModuleName(); + Boolean distanceUnitAvailable = msg.getDistanceUnitAvailable(); + Boolean temperatureUnitAvailable = msg.getTemperatureUnitAvailable(); + Boolean displayModeUnitAvailable = msg.getDisplayModeUnitAvailable(); + + // 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); + + // Invalid/Null Tests + HMISettingsControlCapabilities msg = new HMISettingsControlCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getModuleName()); + assertNull(Test.NULL, msg.getDistanceUnitAvailable()); + assertNull(Test.NULL, msg.getTemperatureUnitAvailable()); + assertNull(Test.NULL, msg.getDisplayModeUnitAvailable()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(HMISettingsControlCapabilities.KEY_MODULE_NAME, Test.GENERAL_STRING); + 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); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlDataTests.java new file mode 100644 index 000000000..85205f617 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HMISettingsControlDataTests.java @@ -0,0 +1,78 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.HMISettingsControlData; +import com.smartdevicelink.proxy.rpc.enums.DisplayMode; +import com.smartdevicelink.proxy.rpc.enums.DistanceUnit; +import com.smartdevicelink.proxy.rpc.enums.TemperatureUnit; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.HMISettingsControlData} + */ +public class HMISettingsControlDataTests extends TestCase { + + private HMISettingsControlData msg; + + @Override + public void setUp() { + msg = new HMISettingsControlData(); + + msg.setDisplayMode(Test.GENERAL_DISPLAYMODE); + msg.setTemperatureUnit(Test.GENERAL_TEMPERATUREUNIT); + msg.setDistanceUnit(Test.GENERAL_DISTANCEUNIT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + DisplayMode displayMode = msg.getDisplayMode(); + TemperatureUnit temperatureUnit = msg.getTemperatureUnit(); + DistanceUnit distanceUnit = msg.getDistanceUnit(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_DISPLAYMODE, displayMode); + assertEquals(Test.MATCH, Test.GENERAL_TEMPERATUREUNIT, temperatureUnit); + assertEquals(Test.MATCH, Test.GENERAL_DISTANCEUNIT, distanceUnit); + + // Invalid/Null Tests + HMISettingsControlData msg = new HMISettingsControlData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getDisplayMode()); + assertNull(Test.NULL, msg.getTemperatureUnit()); + assertNull(Test.NULL, msg.getDistanceUnit()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(HMISettingsControlData.KEY_DISPLAY_MODE, Test.GENERAL_DISPLAYMODE); + reference.put(HMISettingsControlData.KEY_TEMPERATURE_UNIT, Test.GENERAL_TEMPERATUREUNIT); + reference.put(HMISettingsControlData.KEY_DISTANCE_UNIT, Test.GENERAL_DISTANCEUNIT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HapticRectTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HapticRectTests.java new file mode 100644 index 000000000..c72204640 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HapticRectTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.HapticRect; +import com.smartdevicelink.proxy.rpc.Rectangle; +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; + +/** + * Created by brettywhite on 8/24/17. + */ + +public class HapticRectTests extends TestCase { + + private HapticRect msg; + + @Override + public void setUp() { + msg = new HapticRect(); + + msg.setId(Test.GENERAL_INTEGER); + msg.setRect(Test.GENERAL_RECTANGLE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer id = msg.getId(); + Rectangle rect = msg.getRect(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, id); + assertEquals(Test.MATCH, Test.GENERAL_RECTANGLE, rect); + + // Invalid/Null Tests + HapticRect msg = new HapticRect(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getId()); + assertNull(Test.NULL, msg.getRect()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(HapticRect.KEY_ID, Test.GENERAL_INTEGER); + reference.put(HapticRect.KEY_RECT, Test.GENERAL_RECTANGLE); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(reference, HapticRect.KEY_ID), + JsonUtils.readIntegerFromJsonObject(underTest, HapticRect.KEY_ID)); + + assertTrue(Validator.validateRectangle( + (Rectangle) JsonUtils.readObjectFromJsonObject(reference, HapticRect.KEY_RECT), + new Rectangle(JsonRPCMarshaller.deserializeJSONObject( (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, HapticRect.KEY_RECT)))) + ); + + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HeadLampStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HeadLampStatusTests.java new file mode 100644 index 000000000..277786344 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HeadLampStatusTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.HeadLampStatus; +import com.smartdevicelink.proxy.rpc.enums.AmbientLightStatus; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.HeadLampStatus} + */ +public class HeadLampStatusTests extends TestCase{ + + private HeadLampStatus msg; + + @Override + public void setUp(){ + msg = new HeadLampStatus(); + + msg.setAmbientLightStatus(Test.GENERAL_AMBIENTLIGHTSTATUS); + msg.setLowBeamsOn(Test.GENERAL_BOOLEAN); + msg.setHighBeamsOn(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean lowBeams = msg.getLowBeamsOn(); + boolean highBeams = msg.getHighBeamsOn(); + AmbientLightStatus ambientLights = msg.getAmbientLightStatus(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_AMBIENTLIGHTSTATUS, ambientLights); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, highBeams); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, lowBeams); + + // Invalid/Null Tests + HeadLampStatus msg = new HeadLampStatus(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getLowBeamsOn()); + assertNull(Test.NULL, msg.getHighBeamsOn()); + assertNull(Test.NULL, msg.getAmbientLightStatus()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(HeadLampStatus.KEY_HIGH_BEAMS_ON, Test.GENERAL_BOOLEAN); + reference.put(HeadLampStatus.KEY_LOW_BEAMS_ON, Test.GENERAL_BOOLEAN); + reference.put(HeadLampStatus.KEY_AMBIENT_LIGHT_SENSOR_STATUS, Test.GENERAL_AMBIENTLIGHTSTATUS); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HeadersTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HeadersTests.java new file mode 100644 index 000000000..09c69022f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/HeadersTests.java @@ -0,0 +1,109 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.Headers; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.Headers} + */ +public class HeadersTests extends TestCase{ + + private Headers msg; + + @Override + public void setUp(){ + msg = new Headers(); + + msg.setCharset(Test.GENERAL_STRING); + msg.setConnectTimeout(Test.GENERAL_INT); + msg.setContentLength(Test.GENERAL_INT); + msg.setContentType(Test.GENERAL_STRING); + msg.setDoInput(Test.GENERAL_BOOLEAN); + msg.setDoOutput(Test.GENERAL_BOOLEAN); + msg.setInstanceFollowRedirects(Test.GENERAL_BOOLEAN); + msg.setReadTimeout(Test.GENERAL_INT); + msg.setRequestMethod(Test.GENERAL_STRING); + msg.setUseCaches(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String charset = msg.getCharset(); + String contentType = msg.getContentType(); + String requestMode = msg.getRequestMethod(); + int connectTimeout = msg.getConnectTimeout(); + int readTimeout = msg.getReadTimeout(); + int contentLength = msg.getContentLength(); + boolean doOutput = msg.getDoOutput(); + boolean doInput = msg.getDoInput(); + boolean useCache = msg.getUseCaches(); + boolean instanceFollow = msg.getInstanceFollowRedirects(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, charset); + assertEquals(Test.MATCH, Test.GENERAL_STRING, contentType); + assertEquals(Test.MATCH, Test.GENERAL_STRING, requestMode); + assertEquals(Test.MATCH, Test.GENERAL_INT, connectTimeout); + assertEquals(Test.MATCH, Test.GENERAL_INT, readTimeout); + assertEquals(Test.MATCH, Test.GENERAL_INT, contentLength); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, doOutput); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, doInput); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, useCache); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, instanceFollow); + + // Invalid/Null Tests + Headers msg = new Headers(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getCharset()); + assertNull(Test.NULL, msg.getConnectTimeout()); + assertNull(Test.NULL, msg.getContentLength()); + assertNull(Test.NULL, msg.getContentType()); + assertNull(Test.NULL, msg.getDoInput()); + assertNull(Test.NULL, msg.getDoOutput()); + assertNull(Test.NULL, msg.getInstanceFollowRedirects()); + assertNull(Test.NULL, msg.getReadTimeout()); + assertNull(Test.NULL, msg.getRequestMethod()); + assertNull(Test.NULL, msg.getUseCaches()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(Headers.KEY_CHARSET, Test.GENERAL_STRING); + reference.put(Headers.KEY_CONTENT_TYPE, Test.GENERAL_STRING); + reference.put(Headers.KEY_REQUEST_METHOD, Test.GENERAL_STRING); + reference.put(Headers.KEY_CONNECT_TIMEOUT, Test.GENERAL_INT); + reference.put(Headers.KEY_READ_TIMEOUT, Test.GENERAL_INT); + reference.put(Headers.KEY_CONTENT_LENGTH, Test.GENERAL_INT); + reference.put(Headers.KEY_DO_OUTPUT, Test.GENERAL_BOOLEAN); + reference.put(Headers.KEY_DO_INPUT, Test.GENERAL_BOOLEAN); + reference.put(Headers.KEY_USE_CACHES, Test.GENERAL_BOOLEAN); + reference.put(Headers.KEY_INSTANCE_FOLLOW_REDIRECTS, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageFieldTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageFieldTests.java new file mode 100644 index 000000000..4291621df --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageFieldTests.java @@ -0,0 +1,105 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.ImageField; +import com.smartdevicelink.proxy.rpc.ImageResolution; +import com.smartdevicelink.proxy.rpc.enums.FileType; +import com.smartdevicelink.proxy.rpc.enums.ImageFieldName; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ImageField} + */ +public class ImageFieldTests extends TestCase{ + + private ImageField msg; + + @Override + public void setUp(){ + msg = new ImageField(); + + msg.setImageResolution(Test.GENERAL_IMAGERESOLUTION); + msg.setImageTypeSupported(Test.GENERAL_FILETYPE_LIST); + msg.setName(Test.GENERAL_IMAGEFIELDNAME); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ImageResolution imageRes = msg.getImageResolution(); + List<FileType> imageTypes = msg.getImageTypeSupported(); + ImageFieldName name = msg.getName(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateImageResolution(Test.GENERAL_IMAGERESOLUTION, imageRes)); + assertEquals(Test.MATCH, Test.GENERAL_IMAGEFIELDNAME, name); + assertTrue(Test.TRUE, Validator.validateFileTypes(Test.GENERAL_FILETYPE_LIST, imageTypes)); + + // Invalid/Null Tests + ImageField msg = new ImageField(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getImageResolution()); + assertNull(Test.NULL, msg.getImageTypeSupported()); + assertNull(Test.NULL, msg.getName()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(ImageField.KEY_IMAGE_RESOLUTION, Test.JSON_IMAGERESOLUTION); + reference.put(ImageField.KEY_IMAGE_TYPE_SUPPORTED, JsonUtils.createJsonArray(Test.GENERAL_FILETYPE_LIST)); + reference.put(ImageField.KEY_NAME, Test.GENERAL_IMAGEFIELDNAME); + + 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(ImageField.KEY_IMAGE_RESOLUTION)){ + JSONObject objectEquals = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject testEquals = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(objectEquals); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateImageResolution( new ImageResolution(hashReference), new ImageResolution(hashTest))); + } else if(key.equals(ImageField.KEY_IMAGE_TYPE_SUPPORTED)) { + JSONArray imageTypeArrayReference = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray imageTypeArrayTest = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + List<FileType> imageTypeListReference = new ArrayList<FileType>(); + List<FileType> imageTypeListTest = new ArrayList<FileType>(); + + assertEquals(Test.MATCH, imageTypeArrayReference.length(), imageTypeArrayTest.length()); + + for (int index = 0 ; index < imageTypeArrayReference.length(); index++) { + imageTypeListReference.add( (FileType)imageTypeArrayReference.get(index) ); + imageTypeListTest.add( (FileType)imageTypeArrayTest.get(index) ); + } + assertTrue(Test.TRUE, imageTypeListReference.containsAll(imageTypeListTest) && imageTypeListTest.containsAll(imageTypeListReference)); + } 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/ImageResolutionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageResolutionTests.java new file mode 100644 index 000000000..83f3126cf --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageResolutionTests.java @@ -0,0 +1,70 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.ImageResolution; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ImageResolution} + */ +public class ImageResolutionTests extends TestCase{ + + private ImageResolution msg; + + @Override + public void setUp(){ + msg = new ImageResolution(); + + msg.setResolutionHeight(Test.GENERAL_INT); + msg.setResolutionWidth(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int height = msg.getResolutionHeight(); + int width = msg.getResolutionWidth(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, height); + assertEquals(Test.MATCH, Test.GENERAL_INT, width); + + // Invalid/Null Tests + ImageResolution msg = new ImageResolution(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getResolutionHeight()); + assertNull(Test.NULL, msg.getResolutionWidth()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(ImageResolution.KEY_RESOLUTION_HEIGHT, Test.GENERAL_INT); + reference.put(ImageResolution.KEY_RESOLUTION_WIDTH, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageTests.java new file mode 100644 index 000000000..53f5bf435 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ImageTests.java @@ -0,0 +1,76 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.enums.ImageType; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.Image} + */ +public class ImageTests extends TestCase{ + + private Image msg; + + @Override + public void setUp(){ + msg = new Image(); + + msg.setImageType(Test.GENERAL_IMAGETYPE); + msg.setValue(Test.GENERAL_STRING); + msg.setIsTemplate(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ImageType imageType = msg.getImageType(); + String value = msg.getValue(); + Boolean isTemplate = msg.getIsTemplate(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_IMAGETYPE, imageType); + assertEquals(Test.MATCH, Test.GENERAL_STRING, value); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, isTemplate); + + // Invalid/Null Tests + Image msg = new Image(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getImageType()); + assertNull(Test.NULL, msg.getValue()); + assertNull(Test.NULL, msg.getBulkData()); + assertNull(Test.NULL, msg.getIsTemplate()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(Image.KEY_IMAGE_TYPE, Test.GENERAL_IMAGETYPE); + reference.put(Image.KEY_VALUE, Test.GENERAL_STRING); + reference.put(Image.KEY_IS_TEMPLATE, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/KeyboardPropertiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/KeyboardPropertiesTests.java new file mode 100644 index 000000000..3eaf88e28 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/KeyboardPropertiesTests.java @@ -0,0 +1,96 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout; +import com.smartdevicelink.proxy.rpc.enums.KeypressMode; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.KeyboardProperties} + */ +public class KeyboardPropertiesTests extends TestCase{ + + private KeyboardProperties msg; + + @Override + public void setUp(){ + msg = new KeyboardProperties(); + + msg.setAutoCompleteText(Test.GENERAL_STRING); + msg.setKeyboardLayout(Test.GENERAL_KEYBOARDLAYOUT); + msg.setKeypressMode(Test.GENERAL_KEYPRESSMODE); + msg.setLanguage(Test.GENERAL_LANGUAGE); + msg.setLimitedCharacterList(Test.GENERAL_STRING_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String autoComplete = msg.getAutoCompleteText(); + KeyboardLayout keyboardLayout = msg.getKeyboardLayout(); + KeypressMode keypressMode = msg.getKeypressMode(); + Language language = msg.getLanguage(); + List<String> limitedChars = msg.getLimitedCharacterList(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, autoComplete); + assertEquals(Test.MATCH, Test.GENERAL_KEYBOARDLAYOUT, keyboardLayout); + assertEquals(Test.MATCH, Test.GENERAL_KEYPRESSMODE, keypressMode); + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, language); + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.size(), limitedChars.size()); + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, limitedChars)); + + // Invalid/Null Tests + KeyboardProperties msg = new KeyboardProperties(); + assertNotNull(Test.NOT_NULL, msg); + + // Keypress mode is created in the object constructor + assertNotNull(Test.NOT_NULL, msg.getKeypressMode()); + + assertNull(Test.NULL, msg.getAutoCompleteText()); + assertNull(Test.NULL, msg.getLanguage()); + assertNull(Test.NULL, msg.getKeyboardLayout()); + assertNull(Test.NULL, msg.getLimitedCharacterList()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(KeyboardProperties.KEY_AUTO_COMPLETE_TEXT, Test.GENERAL_STRING); + reference.put(KeyboardProperties.KEY_KEYBOARD_LAYOUT, Test.GENERAL_KEYBOARDLAYOUT); + reference.put(KeyboardProperties.KEY_KEYPRESS_MODE, Test.GENERAL_KEYPRESSMODE); + reference.put(KeyboardProperties.KEY_LANGUAGE, Test.GENERAL_LANGUAGE); + reference.put(KeyboardProperties.KEY_LIMITED_CHARACTER_LIST, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + + 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(KeyboardProperties.KEY_LIMITED_CHARACTER_LIST)){ + assertTrue(Test.TRUE, Validator.validateStringList(JsonUtils.readStringListFromJsonObject(reference, key), JsonUtils.readStringListFromJsonObject(underTest, key))); + } 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/LightCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightCapabilitiesTests.java new file mode 100644 index 000000000..6122f4305 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightCapabilitiesTests.java @@ -0,0 +1,81 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.LightCapabilities; +import com.smartdevicelink.proxy.rpc.enums.LightName; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.LightCapabilities} + */ +public class LightCapabilitiesTests extends TestCase { + + private LightCapabilities msg; + + @Override + public void setUp() { + msg = new LightCapabilities(); + + msg.setName(Test.GENERAL_LIGHTNAME); + msg.setDensityAvailable(Test.GENERAL_BOOLEAN); + msg.setRGBColorSpaceAvailable(Test.GENERAL_BOOLEAN); + msg.setStatusAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + LightName name = msg.getName(); + Boolean densityAvailable = msg.getDensityAvailable(); + Boolean rgbColorSpaceAvailable = msg.getRGBColorSpaceAvailable(); + Boolean statusAvailable = msg.getStatusAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_LIGHTNAME, name); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) densityAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) rgbColorSpaceAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, (boolean) statusAvailable); + + // Invalid/Null Tests + LightCapabilities msg = new LightCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getName()); + assertNull(Test.NULL, msg.getDensityAvailable()); + assertNull(Test.NULL, msg.getRGBColorSpaceAvailable()); + assertNull(Test.NULL, msg.getStatusAvailable()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(LightCapabilities.KEY_NAME, Test.GENERAL_LIGHTNAME); + reference.put(LightCapabilities.KEY_DENSITY_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(LightCapabilities.KEY_RGB_COLOR_SPACE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(LightCapabilities.KEY_STATUS_AVAILABLE, Test.GENERAL_BOOLEAN); + + 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 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 new file mode 100644 index 000000000..4ebd7f467 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlCapabilitiesTests.java @@ -0,0 +1,86 @@ +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.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.Iterator; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.LightControlCapabilities} + */ +public class LightControlCapabilitiesTests extends TestCase { + + private LightControlCapabilities msg; + + @Override + public void setUp() { + msg = new LightControlCapabilities(); + + msg.setModuleName(Test.GENERAL_STRING); + msg.setSupportedLights(Test.GENERAL_LIGHTCAPABILITIES_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + String moduleName = msg.getModuleName(); + List<LightCapabilities> supportedLights = msg.getSupportedLights(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); + assertEquals(Test.MATCH, Test.GENERAL_LIGHTCAPABILITIES_LIST.size(), supportedLights.size()); + + assertTrue(Test.TRUE, Validator.validateLightCapabilitiesList(Test.GENERAL_LIGHTCAPABILITIES_LIST, supportedLights)); + + // Invalid/Null Tests + LightControlCapabilities msg = new LightControlCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getModuleName()); + assertNull(Test.NULL, msg.getSupportedLights()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(LightControlCapabilities.KEY_MODULE_NAME, Test.GENERAL_STRING); + reference.put(LightControlCapabilities.KEY_SUPPORTED_LIGHTS, Test.GENERAL_LIGHTCAPABILITIES_LIST); + + 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(LightControlCapabilities.KEY_SUPPORTED_LIGHTS)) { + List<LightCapabilities> lcReference = (List<LightCapabilities>) JsonUtils.readObjectFromJsonObject(reference, key); + JSONArray lsArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + int i = 0; + for (LightCapabilities lc : lcReference) { + assertTrue(Validator.validateLightCapabilities(lc, new LightCapabilities(JsonRPCMarshaller.deserializeJSONObject(lsArray.getJSONObject(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/LightControlDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlDataTests.java new file mode 100644 index 000000000..c891e0769 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightControlDataTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.LightControlData; +import com.smartdevicelink.proxy.rpc.LightState; +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.Iterator; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.LightControlData} + */ +public class LightControlDataTests extends TestCase { + + private LightControlData msg; + + @Override + public void setUp() { + msg = new LightControlData(); + + msg.setLightState(Test.GENERAL_LIGHTSTATE_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + List<LightState> lightState = msg.getLightState(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_LIGHTSTATE_LIST.size(), lightState.size()); + + assertTrue(Test.TRUE, Validator.validateLightStateList(Test.GENERAL_LIGHTSTATE_LIST, lightState)); + + // Invalid/Null Tests + LightControlData msg = new LightControlData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getLightState()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(LightControlData.KEY_LIGHT_STATE, Test.GENERAL_LIGHTSTATE_LIST); + + 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(LightControlData.KEY_LIGHT_STATE)) { + List<LightState> lsReference = (List<LightState>) JsonUtils.readObjectFromJsonObject(reference, key); + JSONArray lsArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + int i = 0; + for (LightState ls : lsReference) { + assertTrue(Validator.validateLightState(ls, new LightState(JsonRPCMarshaller.deserializeJSONObject(lsArray.getJSONObject(i++))))); + } + } + } + } 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/LightStateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightStateTests.java new file mode 100644 index 000000000..196769e00 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LightStateTests.java @@ -0,0 +1,94 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.LightState; +import com.smartdevicelink.proxy.rpc.RGBColor; +import com.smartdevicelink.proxy.rpc.enums.LightName; +import com.smartdevicelink.proxy.rpc.enums.LightStatus; +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.rpc.LightState} + */ +public class LightStateTests extends TestCase { + + private LightState msg; + + @Override + public void setUp() { + msg = new LightState(); + + msg.setId(Test.GENERAL_LIGHTNAME); + msg.setStatus(Test.GENERAL_LIGHTSTATUS); + msg.setDensity(Test.GENERAL_FLOAT); + msg.setColor(Test.GENERAL_RGBCOLOR); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + LightName id = msg.getId(); + LightStatus status = msg.getStatus(); + Float density = msg.getDensity(); + RGBColor color = msg.getColor(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_LIGHTNAME, id); + assertEquals(Test.MATCH, Test.GENERAL_LIGHTSTATUS, status); + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, (float) density); + assertEquals(Test.MATCH, Test.GENERAL_RGBCOLOR, color); + + // Invalid/Null Tests + LightState msg = new LightState(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getId()); + assertNull(Test.NULL, msg.getStatus()); + assertNull(Test.NULL, msg.getDensity()); + assertNull(Test.NULL, msg.getColor()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(LightState.KEY_ID, Test.GENERAL_LIGHTNAME); + reference.put(LightState.KEY_STATUS, Test.GENERAL_LIGHTSTATUS); + reference.put(LightState.KEY_DENSITY, Test.GENERAL_FLOAT); + reference.put(LightState.KEY_COLOR, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_RGBCOLOR.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(LightState.KEY_COLOR)) { + 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.validateRGBColor(new RGBColor(hashReference), new RGBColor(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/LocationDetailsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LocationDetailsTests.java new file mode 100644 index 000000000..18da17eac --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/LocationDetailsTests.java @@ -0,0 +1,113 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Coordinate; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.LocationDetails; +import com.smartdevicelink.proxy.rpc.OasisAddress; +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.List; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class LocationDetailsTests extends TestCase { + private LocationDetails msg; + + @Override + public void setUp(){ + msg = Test.GENERAL_LOCATIONDETAILS; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<String> field1 = msg.getAddressLines(); + String field2 = msg.getLocationDescription(); + String field3 = msg.getLocationName(); + String field4 = msg.getPhoneNumber(); + Coordinate field5 = msg.getCoordinate(); + Image field6 = msg.getLocationImage(); + OasisAddress field7 = msg.getSearchAddress(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST, field1); + assertEquals(Test.MATCH, Test.GENERAL_STRING, field2); + assertEquals(Test.MATCH, Test.GENERAL_STRING, field3); + assertEquals(Test.MATCH, Test.GENERAL_STRING, field4); + assertEquals(Test.MATCH, Test.GENERAL_COORDINATE, field5); + assertEquals(Test.MATCH, Test.GENERAL_IMAGE, field6); + assertEquals(Test.MATCH, Test.GENERAL_OASISADDRESS, field7); + + // Invalid/Null Tests + LocationDetails msg = new LocationDetails(); + assertNotNull(Test.NOT_NULL, msg); + + + assertNull(msg.getAddressLines()); + assertNull(msg.getLocationDescription()); + assertNull(msg.getLocationName()); + assertNull(msg.getPhoneNumber()); + assertNull(msg.getCoordinate()); + assertNull(msg.getLocationImage()); + assertNull(msg.getSearchAddress()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(LocationDetails.KEY_ADDRESS_LINES, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + reference.put(LocationDetails.KEY_LOCATION_DESCRIPTION, Test.GENERAL_STRING); + reference.put(LocationDetails.KEY_LOCATION_NAME, Test.GENERAL_STRING); + reference.put(LocationDetails.KEY_PHONE_NUMBER, Test.GENERAL_STRING); + reference.put(LocationDetails.KEY_COORDINATE, Test.GENERAL_COORDINATE); + reference.put(LocationDetails.KEY_LOCATION_IMAGE, Test.GENERAL_IMAGE); + reference.put(LocationDetails.KEY_SEARCH_ADDRESS, Test.GENERAL_OASISADDRESS); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, LocationDetails.KEY_ADDRESS_LINES), + JsonUtils.readObjectFromJsonObject(underTest, LocationDetails.KEY_ADDRESS_LINES)); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(reference, LocationDetails.KEY_LOCATION_DESCRIPTION), + JsonUtils.readStringFromJsonObject(underTest, LocationDetails.KEY_LOCATION_DESCRIPTION)); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(reference, LocationDetails.KEY_LOCATION_NAME), + JsonUtils.readStringFromJsonObject(underTest, LocationDetails.KEY_LOCATION_NAME)); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(reference, LocationDetails.KEY_PHONE_NUMBER), + JsonUtils.readStringFromJsonObject(underTest, LocationDetails.KEY_PHONE_NUMBER)); + + assertTrue(Validator.validateCoordinate( + (Coordinate) JsonUtils.readObjectFromJsonObject(reference, LocationDetails.KEY_COORDINATE), + new Coordinate(JsonRPCMarshaller.deserializeJSONObject( (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, LocationDetails.KEY_COORDINATE)))) + ); + + assertTrue(Validator.validateImage( + (Image) JsonUtils.readObjectFromJsonObject(reference, LocationDetails.KEY_LOCATION_IMAGE), + new Image(JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(underTest, LocationDetails.KEY_LOCATION_IMAGE))) + )); + + assertTrue(Validator.validateOasisAddress( + (OasisAddress) JsonUtils.readObjectFromJsonObject(reference, LocationDetails.KEY_SEARCH_ADDRESS), + new OasisAddress(JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(underTest, LocationDetails.KEY_SEARCH_ADDRESS))) + )); + + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MassageCushionFirmnessTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MassageCushionFirmnessTest.java new file mode 100644 index 000000000..da8a7cbfe --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MassageCushionFirmnessTest.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.MassageCushionFirmness; +import com.smartdevicelink.proxy.rpc.enums.MassageCushion; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.MassageCushionFirmness} + */ +public class MassageCushionFirmnessTest extends TestCase { + + private MassageCushionFirmness msg; + + @Override + public void setUp() { + msg = new MassageCushionFirmness(); + + msg.setCushion(Test.GENERAL_MASSAGECUSHION); + msg.setFirmness(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + MassageCushion cushion = msg.getCushion(); + Integer firmness = msg.getFirmness(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_MASSAGECUSHION, cushion); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, firmness); + + // Invalid/Null Tests + MassageCushionFirmness msg = new MassageCushionFirmness(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getCushion()); + assertNull(Test.NULL, msg.getFirmness()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(MassageCushionFirmness.KEY_CUSHION, Test.GENERAL_MASSAGECUSHION); + reference.put(MassageCushionFirmness.KEY_FIRMNESS, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MassageModeDataTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MassageModeDataTest.java new file mode 100644 index 000000000..958de9fa2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MassageModeDataTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.MassageModeData; +import com.smartdevicelink.proxy.rpc.enums.MassageMode; +import com.smartdevicelink.proxy.rpc.enums.MassageZone; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.MassageModeData} + */ +public class MassageModeDataTest extends TestCase { + + private MassageModeData msg; + + @Override + public void setUp() { + msg = new MassageModeData(); + + msg.setMassageZone(Test.GENERAL_MASSAGEZONE); + msg.setMassageMode(Test.GENERAL_MASSAGEMODE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + MassageZone massageZone = msg.getMassageZone(); + MassageMode massageMode = msg.getMassageMode(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_MASSAGEZONE, massageZone); + assertEquals(Test.MATCH, Test.GENERAL_MASSAGEMODE, massageMode); + + + // Invalid/Null Tests + MassageModeData msg = new MassageModeData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getMassageMode()); + assertNull(Test.NULL, msg.getMassageZone()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(MassageModeData.KEY_MASSAGE_MODE, Test.GENERAL_MASSAGEMODE); + reference.put(MassageModeData.KEY_MASSAGE_ZONE, Test.GENERAL_MASSAGEZONE); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MediaServiceDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MediaServiceDataTests.java new file mode 100644 index 000000000..2b4c352c5 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MediaServiceDataTests.java @@ -0,0 +1,121 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.MediaServiceData; +import com.smartdevicelink.proxy.rpc.enums.MediaType; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.MediaServiceData} + */ +public class MediaServiceDataTests extends TestCase { + + private MediaServiceData msg; + + @Override + public void setUp(){ + + msg = new MediaServiceData(); + msg.setMediaType(Test.GENERAL_MEDIATYPE); + msg.setMediaTitle(Test.GENERAL_STRING); + msg.setMediaArtist(Test.GENERAL_STRING); + msg.setMediaAlbum(Test.GENERAL_STRING); + msg.setPlaylistName(Test.GENERAL_STRING); + msg.setIsExplicit(Test.GENERAL_BOOLEAN); + msg.setTrackPlaybackProgress(Test.GENERAL_INTEGER); + msg.setTrackPlaybackDuration(Test.GENERAL_INTEGER); + msg.setQueuePlaybackProgress(Test.GENERAL_INTEGER); + msg.setQueuePlaybackDuration(Test.GENERAL_INTEGER); + msg.setQueueCurrentTrackNumber(Test.GENERAL_INTEGER); + msg.setQueueTotalTrackCount(Test.GENERAL_INTEGER); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + MediaType mediaType = msg.getMediaType(); + String mediaTitle = msg.getMediaTitle(); + String mediaArtist = msg.getMediaArtist(); + String mediaAlbum = msg.getMediaAlbum(); + String playlistName = msg.getPlaylistName(); + boolean isExplicit = msg.getIsExplicit(); + Integer trackPlaybackProgress = msg.getTrackPlaybackProgress(); + Integer trackPlaybackDuration = msg.getTrackPlaybackDuration(); + Integer queuePlaybackProgress = msg.getQueuePlaybackProgress(); + Integer queuePlaybackDuration = msg.getQueuePlaybackDuration(); + Integer queueCurrentTrackNumber = msg.getQueueCurrentTrackNumber(); + Integer queueTotalTrackCount = msg.getQueueTotalTrackCount(); + + // Valid Tests + assertEquals(Test.GENERAL_MEDIATYPE, mediaType); + assertEquals(Test.GENERAL_STRING, mediaTitle); + assertEquals(Test.GENERAL_STRING, mediaArtist); + assertEquals(Test.GENERAL_STRING, mediaAlbum); + assertEquals(Test.GENERAL_STRING, playlistName); + assertEquals(Test.GENERAL_BOOLEAN, isExplicit); + assertEquals(Test.GENERAL_INTEGER, trackPlaybackProgress); + assertEquals(Test.GENERAL_INTEGER, trackPlaybackDuration); + assertEquals(Test.GENERAL_INTEGER, queuePlaybackProgress); + assertEquals(Test.GENERAL_INTEGER, queuePlaybackDuration); + assertEquals(Test.GENERAL_INTEGER, queueCurrentTrackNumber); + assertEquals(Test.GENERAL_INTEGER, queueTotalTrackCount); + + // Invalid/Null Tests + MediaServiceData msg = new MediaServiceData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getMediaType()); + assertNull(Test.NULL, msg.getMediaTitle()); + assertNull(Test.NULL, msg.getMediaArtist()); + assertNull(Test.NULL, msg.getMediaAlbum()); + assertNull(Test.NULL, msg.getPlaylistName()); + assertNull(Test.NULL, msg.getIsExplicit()); + assertNull(Test.NULL, msg.getTrackPlaybackProgress()); + assertNull(Test.NULL, msg.getTrackPlaybackDuration()); + assertNull(Test.NULL, msg.getQueuePlaybackProgress()); + assertNull(Test.NULL, msg.getQueuePlaybackDuration()); + assertNull(Test.NULL, msg.getQueueCurrentTrackNumber()); + assertNull(Test.NULL, msg.getQueueTotalTrackCount()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(MediaServiceData.KEY_MEDIA_TYPE, Test.GENERAL_MEDIATYPE); + reference.put(MediaServiceData.KEY_MEDIA_TITLE, Test.GENERAL_STRING); + reference.put(MediaServiceData.KEY_MEDIA_ARTIST, Test.GENERAL_STRING); + reference.put(MediaServiceData.KEY_MEDIA_ALBUM, Test.GENERAL_STRING); + reference.put(MediaServiceData.KEY_PLAYLIST_NAME, Test.GENERAL_STRING); + reference.put(MediaServiceData.KEY_IS_EXPLICIT, Test.GENERAL_BOOLEAN); + reference.put(MediaServiceData.KEY_TRACK_PLAYBACK_PROGRESS, Test.GENERAL_INTEGER); + reference.put(MediaServiceData.KEY_TRACK_PLAYBACK_DURATION, Test.GENERAL_INTEGER); + reference.put(MediaServiceData.KEY_QUEUE_PLAYBACK_PROGRESS, Test.GENERAL_INTEGER); + reference.put(MediaServiceData.KEY_QUEUE_PLAYBACK_DURATION, Test.GENERAL_INTEGER); + reference.put(MediaServiceData.KEY_QUEUE_CURRENT_TRACK_NUMBER, Test.GENERAL_INTEGER); + reference.put(MediaServiceData.KEY_QUEUE_TOTAL_TRACK_COUNT, Test.GENERAL_INTEGER); + + 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); + } + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MediaServiceManifestTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MediaServiceManifestTests.java new file mode 100644 index 000000000..85332bc0c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MediaServiceManifestTests.java @@ -0,0 +1,30 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.MediaServiceManifest; +import com.smartdevicelink.test.Test; + +import junit.framework.TestCase; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.MediaServiceManifest} + */ +public class MediaServiceManifestTests extends TestCase { + + @Override + public void setUp(){ + // nothing to setup yet, this class doesn't contain anything + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + + // Invalid/Null Tests + MediaServiceManifest msg = new MediaServiceManifest(); + assertNotNull(Test.NOT_NULL, msg); + } + +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MenuParamsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MenuParamsTests.java new file mode 100644 index 000000000..ea823f619 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MenuParamsTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.MenuParams; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.MenuParams} + */ +public class MenuParamsTests extends TestCase{ + + private MenuParams msg; + + @Override + public void setUp(){ + msg = new MenuParams(); + + msg.setMenuName(Test.GENERAL_STRING); + msg.setParentID(Test.GENERAL_INT); + msg.setPosition(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String menuName = msg.getMenuName(); + int parentId = msg.getParentID(); + int position = msg.getPosition(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, menuName); + assertEquals(Test.MATCH, Test.GENERAL_INT, parentId); + assertEquals(Test.MATCH, Test.GENERAL_INT, position); + + // Invalid/Null Tests + MenuParams msg = new MenuParams(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getMenuName()); + assertNull(Test.NULL, msg.getParentID()); + assertNull(Test.NULL, msg.getPosition()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(MenuParams.KEY_MENU_NAME, Test.GENERAL_STRING); + reference.put(MenuParams.KEY_PARENT_ID, Test.GENERAL_INT); + reference.put(MenuParams.KEY_POSITION, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MetadataTagsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MetadataTagsTests.java new file mode 100644 index 000000000..5f27cc132 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MetadataTagsTests.java @@ -0,0 +1,110 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.MetadataTags; +import com.smartdevicelink.proxy.rpc.enums.MetadataType; +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.ArrayList; +import java.util.Iterator; +import java.util.List; + + +/** + * This is a unit test class for the SmartDeviceLink library project class: + * {@link MetadataTags} + */ + +public class MetadataTagsTests extends TestCase { + + private MetadataTags msg; + private MetadataTags msg2; + private List<MetadataType> exampleList; + + @Override + public void setUp() { + // Create List for Testing + exampleList = new ArrayList<>(); + exampleList.add(0, MetadataType.CURRENT_TEMPERATURE); + exampleList.add(1, MetadataType.MEDIA_ALBUM); + exampleList.add(2, MetadataType.MEDIA_ARTIST); + + msg = new MetadataTags(); + msg.setMainField1(exampleList); + msg.setMainField2(exampleList); + msg.setMainField3(exampleList); + msg.setMainField4(exampleList); + + // Setup without a list + msg2 = new MetadataTags(); + msg2.setMainField1(MetadataType.CURRENT_TEMPERATURE); + msg2.setMainField2(MetadataType.HUMIDITY); + msg2.setMainField3(MetadataType.MAXIMUM_TEMPERATURE); + msg2.setMainField4(MetadataType.MEDIA_ALBUM); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<MetadataType> mainField1Types = msg.getMainField1(); + List<MetadataType> mainField2Types = msg.getMainField2(); + List<MetadataType> mainField3Types = msg.getMainField3(); + List<MetadataType> mainField4Types = msg.getMainField4(); + + // Valid Tests + assertEquals(Test.MATCH, exampleList, mainField1Types); + assertEquals(Test.MATCH, exampleList, mainField2Types); + assertEquals(Test.MATCH, exampleList, mainField3Types); + assertEquals(Test.MATCH, exampleList, mainField4Types); + + // Test metadata set without a list + mainField1Types = msg2.getMainField1(); + mainField2Types = msg2.getMainField2(); + mainField3Types = msg2.getMainField3(); + mainField4Types = msg2.getMainField4(); + + // Valid Tests + assertEquals(Test.MATCH, MetadataType.CURRENT_TEMPERATURE, mainField1Types.get(0)); + assertEquals(Test.MATCH, MetadataType.HUMIDITY, mainField2Types.get(0)); + assertEquals(Test.MATCH, MetadataType.MAXIMUM_TEMPERATURE, mainField3Types.get(0)); + assertEquals(Test.MATCH, MetadataType.MEDIA_ALBUM, mainField4Types.get(0)); + + // Invalid/Null Tests + MetadataTags msg = new MetadataTags(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getMainField1()); + assertNull(Test.NULL, msg.getMainField2()); + assertNull(Test.NULL, msg.getMainField3()); + assertNull(Test.NULL, msg.getMainField4()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(MetadataTags.KEY_MAIN_FIELD_1_TYPE, Test.JSON_TEXTFIELDTYPES); + reference.put(MetadataTags.KEY_MAIN_FIELD_2_TYPE, Test.JSON_TEXTFIELDTYPES); + reference.put(MetadataTags.KEY_MAIN_FIELD_3_TYPE, Test.JSON_TEXTFIELDTYPES); + reference.put(MetadataTags.KEY_MAIN_FIELD_4_TYPE, Test.JSON_TEXTFIELDTYPES); + + 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); + } + } +} 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 new file mode 100644 index 000000000..b553587ad --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ModuleDataTests.java @@ -0,0 +1,142 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.AudioControlData; +import com.smartdevicelink.proxy.rpc.ClimateControlData; +import com.smartdevicelink.proxy.rpc.HMISettingsControlData; +import com.smartdevicelink.proxy.rpc.LightControlData; +import com.smartdevicelink.proxy.rpc.ModuleData; +import com.smartdevicelink.proxy.rpc.RadioControlData; +import com.smartdevicelink.proxy.rpc.SeatControlData; +import com.smartdevicelink.proxy.rpc.enums.ModuleType; +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.rpc.ModuleData} + */ +public class ModuleDataTests extends TestCase { + + private ModuleData msg; + + @Override + public void setUp() { + msg = new ModuleData(); + msg.setModuleType(Test.GENERAL_MODULETYPE); + msg.setRadioControlData(Test.GENERAL_RADIOCONTROLDATA); + msg.setClimateControlData(Test.GENERAL_CLIMATECONTROLDATA); + msg.setSeatControlData(Test.GENERAL_SEATCONTROLDATA); + msg.setAudioControlData(Test.GENERAL_AUDIOCONTROLDATA); + msg.setHmiSettingsControlData(Test.GENERAL_HMISETTINGSCONTROLDATA); + msg.setLightControlData(Test.GENERAL_LIGHTCONTROLDATA); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + ModuleType moduleType = msg.getModuleType(); + RadioControlData radioControlData = msg.getRadioControlData(); + ClimateControlData climateControlData = msg.getClimateControlData(); + SeatControlData seatControlData = msg.getSeatControlData(); + AudioControlData audioControlData = msg.getAudioControlData(); + HMISettingsControlData hmiSettingsControlData = msg.getHmiSettingsControlData(); + LightControlData lightControlData = msg.getLightControlData(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, moduleType); + assertTrue(Test.TRUE, Validator.validateRadioControlData(Test.GENERAL_RADIOCONTROLDATA, radioControlData)); + assertTrue(Test.TRUE, Validator.validateClimateControlData(Test.GENERAL_CLIMATECONTROLDATA, climateControlData)); + assertTrue(Test.TRUE, Validator.validateSeatControlData(Test.GENERAL_SEATCONTROLDATA, seatControlData)); + 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)); + + // Invalid/Null Tests + ModuleData msg = new ModuleData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getModuleType()); + assertNull(Test.NULL, msg.getRadioControlData()); + assertNull(Test.NULL, msg.getClimateControlData()); + assertNull(Test.NULL, msg.getSeatControlData()); + assertNull(Test.NULL, msg.getAudioControlData()); + assertNull(Test.NULL, msg.getHmiSettingsControlData()); + assertNull(Test.NULL, msg.getLightControlData()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(ModuleData.KEY_MODULE_TYPE, Test.GENERAL_MODULETYPE); + reference.put(ModuleData.KEY_RADIO_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_RADIOCONTROLDATA.getStore())); + reference.put(ModuleData.KEY_CLIMATE_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_CLIMATECONTROLDATA.getStore())); + reference.put(ModuleData.KEY_SEAT_CONTROL_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_SEATCONTROLDATA.getStore())); + 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())); + + 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(ModuleData.KEY_RADIO_CONTROL_DATA)) { + 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.validateRadioControlData(new RadioControlData(hashReference), new RadioControlData(hashTest))); + } else if (key.equals(ModuleData.KEY_CLIMATE_CONTROL_DATA)) { + 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.validateClimateControlData(new ClimateControlData(hashReference), new ClimateControlData(hashTest))); + } else if (key.equals(ModuleData.KEY_SEAT_CONTROL_DATA)) { + 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.validateSeatControlData(new SeatControlData(hashReference), new SeatControlData(hashTest))); + } else if (key.equals(ModuleData.KEY_AUDIO_CONTROL_DATA)) { + 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.validateAudioControlData(new AudioControlData(hashReference), new AudioControlData(hashTest))); + } else if (key.equals(ModuleData.KEY_HMI_SETTINGS_CONTROL_DATA)) { + 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.validateHMISettingsControlData(new HMISettingsControlData(hashReference), new HMISettingsControlData(hashTest))); + } else if (key.equals(ModuleData.KEY_LIGHT_CONTROL_DATA)) { + 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.validateLightControlData(new LightControlData(hashReference), new LightControlData(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/MyKeyTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MyKeyTests.java new file mode 100644 index 000000000..48b0f33ab --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/MyKeyTests.java @@ -0,0 +1,64 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.MyKey; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataStatus; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.MyKey} + */ +public class MyKeyTests extends TestCase{ + + private MyKey msg; + + @Override + public void setUp(){ + msg = new MyKey(); + msg.setE911Override(Test.GENERAL_VEHICLEDATASTATUS); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + VehicleDataStatus override = msg.getE911Override(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_VEHICLEDATASTATUS, override); + + // Invalid/Null Tests + MyKey msg = new MyKey(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getE911Override()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(MyKey.KEY_E_911_OVERRIDE, Test.GENERAL_VEHICLEDATASTATUS); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationCapabilityTests.java new file mode 100644 index 000000000..efbf7e30d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationCapabilityTests.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.NavigationCapability; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.NavigationCapability} + */ +public class NavigationCapabilityTests extends TestCase{ + + private NavigationCapability msg; + + @Override + public void setUp(){ + msg = new NavigationCapability(); + + msg.setSendLocationEnabled(Test.GENERAL_BOOLEAN); + msg.setWayPointsEnabled(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean sendLocationEnabled = msg.getSendLocationEnabled(); + boolean getWayPointsEnabled = msg.getWayPointsEnabled(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, sendLocationEnabled); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, getWayPointsEnabled); + + // Invalid/Null Tests + NavigationCapability msg = new NavigationCapability(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getSendLocationEnabled()); + assertNull(Test.NULL, msg.getWayPointsEnabled()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(NavigationCapability.KEY_GETWAYPOINTS_ENABLED, Test.GENERAL_BOOLEAN); + reference.put(NavigationCapability.KEY_LOCATION_ENABLED, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationInstructionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationInstructionTests.java new file mode 100644 index 000000000..38500561b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationInstructionTests.java @@ -0,0 +1,134 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.DateTime; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.LocationDetails; +import com.smartdevicelink.proxy.rpc.NavigationInstruction; +import com.smartdevicelink.proxy.rpc.enums.Direction; +import com.smartdevicelink.proxy.rpc.enums.NavigationAction; +import com.smartdevicelink.proxy.rpc.enums.NavigationJunction; +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.NavigationInstruction} + */ +public class NavigationInstructionTests extends TestCase { + + private NavigationInstruction msg; + + @Override + public void setUp(){ + msg = new NavigationInstruction(); + + msg.setLocationDetails(Test.GENERAL_LOCATIONDETAILS); + msg.setAction(Test.GENERAL_NAVIGATION_ACTION); + msg.setEta(Test.GENERAL_DATETIME); + msg.setBearing(Test.GENERAL_INTEGER); + msg.setJunctionType(Test.GENERAL_NAVIGATION_JUNCTION); + msg.setDrivingSide(Test.GENERAL_DIRECTION); + msg.setDetails(Test.GENERAL_STRING); + msg.setImage(Test.GENERAL_IMAGE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + LocationDetails locationDetails = msg.getLocationDetails(); + NavigationAction action = msg.getAction(); + DateTime eta = msg.getEta(); + Integer bearing = msg.getBearing(); + NavigationJunction junctionType = msg.getJunctionType(); + Direction drivingSide = msg.getDrivingSide(); + String details = msg.getDetails(); + Image image = msg.getImage(); + + // Valid Tests + assertEquals(Test.GENERAL_LOCATIONDETAILS, locationDetails); + assertEquals(Test.GENERAL_NAVIGATION_ACTION, action); + assertEquals(Test.GENERAL_DATETIME, eta); + assertEquals(Test.GENERAL_INTEGER, bearing); + assertEquals(Test.GENERAL_NAVIGATION_JUNCTION, junctionType); + assertEquals(Test.GENERAL_DIRECTION, drivingSide); + assertEquals(Test.GENERAL_STRING, details); + assertEquals(Test.GENERAL_IMAGE, image); + + // Invalid/Null Tests + NavigationInstruction msg = new NavigationInstruction(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getLocationDetails()); + assertNull(Test.NULL, msg.getAction()); + assertNull(Test.NULL, msg.getEta()); + assertNull(Test.NULL, msg.getBearing()); + assertNull(Test.NULL, msg.getJunctionType()); + assertNull(Test.NULL, msg.getDrivingSide()); + assertNull(Test.NULL, msg.getDetails()); + assertNull(Test.NULL, msg.getImage()); + } + + public void testRequiredConstructor(){ + NavigationInstruction msg = new NavigationInstruction(Test.GENERAL_LOCATIONDETAILS, Test.GENERAL_NAVIGATION_ACTION); + assertNotNull(Test.NOT_NULL, msg); + + LocationDetails locationDetails = msg.getLocationDetails(); + NavigationAction action = msg.getAction(); + + assertEquals(Test.GENERAL_LOCATIONDETAILS, locationDetails); + assertEquals(Test.GENERAL_NAVIGATION_ACTION, action); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(NavigationInstruction.KEY_LOCATION_DETAILS, Test.GENERAL_LOCATIONDETAILS); + reference.put(NavigationInstruction.KEY_ACTION, Test.GENERAL_NAVIGATION_ACTION); + reference.put(NavigationInstruction.KEY_ETA, Test.GENERAL_DATETIME); + reference.put(NavigationInstruction.KEY_BEARING, Test.GENERAL_INTEGER); + reference.put(NavigationInstruction.KEY_JUNCTION_TYPE, Test.GENERAL_NAVIGATION_JUNCTION); + reference.put(NavigationInstruction.KEY_DRIVING_SIDE, Test.GENERAL_DIRECTION); + reference.put(NavigationInstruction.KEY_DETAILS, Test.GENERAL_STRING); + reference.put(NavigationInstruction.KEY_IMAGE, Test.GENERAL_IMAGE); + + 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(NavigationInstruction.KEY_IMAGE)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Image refIcon1 = new Image(JsonRPCMarshaller.deserializeJSONObject(testEquals)); + assertTrue(Test.TRUE, Validator.validateImage(refIcon1, msg.getImage())); + }else if(key.equals(NavigationInstruction.KEY_LOCATION_DETAILS)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateLocationDetails( Test.GENERAL_LOCATIONDETAILS, new LocationDetails(hashTest))); + }else if (key.equals(NavigationInstruction.KEY_ETA)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateDateTime(Test.GENERAL_DATETIME, new DateTime(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/NavigationServiceDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationServiceDataTests.java new file mode 100644 index 000000000..9b59062d4 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationServiceDataTests.java @@ -0,0 +1,143 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.DateTime; +import com.smartdevicelink.proxy.rpc.LocationDetails; +import com.smartdevicelink.proxy.rpc.NavigationInstruction; +import com.smartdevicelink.proxy.rpc.NavigationServiceData; +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.NavigationServiceData} + */ +public class NavigationServiceDataTests extends TestCase { + + private NavigationServiceData msg; + + @Override + public void setUp(){ + msg = new NavigationServiceData(); + + msg.setTimeStamp(Test.GENERAL_DATETIME); + msg.setOrigin(Test.GENERAL_LOCATIONDETAILS); + msg.setDestination(Test.GENERAL_LOCATIONDETAILS); + msg.setDestinationETA(Test.GENERAL_DATETIME); + msg.setInstructions(Test.GENERAL_NAVIGATION_INSTRUCTION_LIST); + msg.setNextInstructionETA(Test.GENERAL_DATETIME); + msg.setNextInstructionDistance(Test.GENERAL_FLOAT); + msg.setNextInstructionDistanceScale(Test.GENERAL_FLOAT); + msg.setPrompt(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + DateTime timestamp = msg.getTimeStamp(); + LocationDetails origin = msg.getOrigin(); + LocationDetails destination = msg.getDestination(); + DateTime destinationETA = msg.getDestinationETA(); + List<NavigationInstruction> instructions = msg.getInstructions(); + DateTime nextInstructionETA = msg.getNextInstructionETA(); + Float nextInstructionDistance = msg.getNextInstructionDistance(); + Float nextInstructionDistanceScale = msg.getNextInstructionDistanceScale(); + String prompt = msg.getPrompt(); + + // Valid Tests + assertEquals(Test.GENERAL_DATETIME, timestamp); + assertEquals(Test.GENERAL_LOCATIONDETAILS, origin); + assertEquals(Test.GENERAL_LOCATIONDETAILS, destination); + assertEquals(Test.GENERAL_DATETIME, destinationETA); + assertEquals(Test.GENERAL_NAVIGATION_INSTRUCTION_LIST, instructions); + assertEquals(Test.GENERAL_DATETIME, nextInstructionETA); + assertEquals(Test.GENERAL_FLOAT, nextInstructionDistance); + assertEquals(Test.GENERAL_FLOAT, nextInstructionDistanceScale); + assertEquals(Test.GENERAL_STRING, prompt); + + // Invalid/Null Tests + NavigationServiceData msg = new NavigationServiceData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getTimeStamp()); + assertNull(Test.NULL, msg.getOrigin()); + assertNull(Test.NULL, msg.getDestination()); + assertNull(Test.NULL, msg.getDestinationETA()); + assertNull(Test.NULL, msg.getInstructions()); + assertNull(Test.NULL, msg.getNextInstructionETA()); + assertNull(Test.NULL, msg.getNextInstructionDistance()); + assertNull(Test.NULL, msg.getNextInstructionDistanceScale()); + assertNull(Test.NULL, msg.getPrompt()); + } + + public void testRequiredConstructor(){ + NavigationServiceData msg = new NavigationServiceData(Test.GENERAL_DATETIME); + assertNotNull(Test.NOT_NULL, msg); + + DateTime locationDetails = msg.getTimeStamp(); + + assertEquals(Test.GENERAL_DATETIME, locationDetails); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(NavigationServiceData.KEY_TIMESTAMP, Test.GENERAL_DATETIME); + reference.put(NavigationServiceData.KEY_ORIGIN, Test.GENERAL_LOCATIONDETAILS); + reference.put(NavigationServiceData.KEY_DESTINATION, Test.GENERAL_LOCATIONDETAILS); + reference.put(NavigationServiceData.KEY_DESTINATION_ETA, Test.GENERAL_DATETIME); + reference.put(NavigationServiceData.KEY_INSTRUCTIONS, Test.GENERAL_NAVIGATION_INSTRUCTION_LIST); + reference.put(NavigationServiceData.KEY_NEXT_INSTRUCTION_ETA, Test.GENERAL_DATETIME); + reference.put(NavigationServiceData.KEY_NEXT_INSTRUCTION_DISTANCE, Test.GENERAL_FLOAT); + reference.put(NavigationServiceData.KEY_NEXT_INSTRUCTION_DISTANCE_SCALE, Test.GENERAL_FLOAT); + reference.put(NavigationServiceData.KEY_PROMPT, Test.GENERAL_STRING); + + + 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(NavigationServiceData.KEY_TIMESTAMP)||key.equals(NavigationServiceData.KEY_DESTINATION_ETA)||key.equals(NavigationServiceData.KEY_NEXT_INSTRUCTION_ETA)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateDateTime(Test.GENERAL_DATETIME, new DateTime(hashTest))); + }else if(key.equals(NavigationServiceData.KEY_DESTINATION)||key.equals(NavigationServiceData.KEY_ORIGIN)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateLocationDetails( Test.GENERAL_LOCATIONDETAILS, new LocationDetails(hashTest))); + }else if (key.equals(NavigationServiceData.KEY_INSTRUCTIONS)){ + JSONArray NavigationInstructionUnderTestListArrayObjTest = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + List<NavigationInstruction> NavigationInstructionUnderTestList = new ArrayList<>(); + for (int index = 0; index < NavigationInstructionUnderTestListArrayObjTest.length(); index++) { + NavigationInstruction NavigationInstructionData = new NavigationInstruction(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)NavigationInstructionUnderTestListArrayObjTest.get(index) )); + NavigationInstructionUnderTestList.add(NavigationInstructionData); + } + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateNavigationInstructionList(Test.GENERAL_NAVIGATION_INSTRUCTION_LIST, NavigationInstructionUnderTestList)); + }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/NavigationServiceManifestTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationServiceManifestTests.java new file mode 100644 index 000000000..de4144677 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/NavigationServiceManifestTests.java @@ -0,0 +1,64 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.NavigationServiceManifest; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.NavigationServiceManifest} + */ +public class NavigationServiceManifestTests extends TestCase { + + private NavigationServiceManifest msg; + + @Override + public void setUp(){ + msg = new NavigationServiceManifest(); + + msg.setAcceptsWayPoints(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean acceptsWayPoints = msg.getAcceptsWayPoints(); + + // Valid Tests + assertEquals(Test.GENERAL_BOOLEAN, acceptsWayPoints); + + // Invalid/Null Tests + NavigationServiceManifest msg = new NavigationServiceManifest(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getAcceptsWayPoints()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(NavigationServiceManifest.KEY_ACCEPTS_WAY_POINTS, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/OasisAddressTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/OasisAddressTests.java new file mode 100644 index 000000000..cf39a3c18 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/OasisAddressTests.java @@ -0,0 +1,95 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.OasisAddress; +import com.smartdevicelink.test.Test; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Iterator; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class OasisAddressTests extends TestCase { + private OasisAddress msg; + + @Override + public void setUp(){ + msg = Test.GENERAL_OASISADDRESS; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String f1 = msg.getAdministrativeArea(); + String f2 = msg.getSubAdministrativeArea(); + String f3 = msg.getCountryCode(); + String f4 = msg.getCountryName(); + String f5 = msg.getLocality(); + String f6 = msg.getSubLocality(); + String f7 = msg.getPostalCode(); + String f8 = msg.getThoroughfare(); + String f9 = msg.getSubThoroughfare(); + + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, f1); + assertEquals(Test.MATCH, Test.GENERAL_STRING, f2); + assertEquals(Test.MATCH, Test.GENERAL_STRING, f3); + assertEquals(Test.MATCH, Test.GENERAL_STRING, f4); + assertEquals(Test.MATCH, Test.GENERAL_STRING, f5); + assertEquals(Test.MATCH, Test.GENERAL_STRING, f6); + assertEquals(Test.MATCH, Test.GENERAL_STRING, f7); + assertEquals(Test.MATCH, Test.GENERAL_STRING, f8); + assertEquals(Test.MATCH, Test.GENERAL_STRING, f9); + + // Invalid/Null Tests + OasisAddress msg = new OasisAddress(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(msg.getAdministrativeArea()); + assertNull(msg.getSubAdministrativeArea()); + assertNull(msg.getCountryCode()); + assertNull(msg.getCountryName()); + assertNull(msg.getLocality()); + assertNull(msg.getSubLocality()); + assertNull(msg.getPostalCode()); + assertNull(msg.getThoroughfare()); + assertNull(msg.getSubThoroughfare()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(OasisAddress.KEY_ADMINISTRATIVE_AREA, Test.GENERAL_STRING); + reference.put(OasisAddress.KEY_SUB_ADMINISTRATIVE_AREA, Test.GENERAL_STRING); + reference.put(OasisAddress.KEY_COUNTRY_CODE, Test.GENERAL_STRING); + reference.put(OasisAddress.KEY_COUNTRY_NAME, Test.GENERAL_STRING); + reference.put(OasisAddress.KEY_LOCALITY, Test.GENERAL_STRING); + reference.put(OasisAddress.KEY_SUB_LOCALITY, Test.GENERAL_STRING); + reference.put(OasisAddress.KEY_POSTAL_CODE, Test.GENERAL_STRING); + reference.put(OasisAddress.KEY_THOROUGH_FARE, Test.GENERAL_STRING); + reference.put(OasisAddress.KEY_SUB_THOROUGH_FARE, Test.GENERAL_STRING); + + 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, reference.get(key), + underTest.get(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/ParameterPermissionsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ParameterPermissionsTests.java new file mode 100644 index 000000000..a40f6a1b0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ParameterPermissionsTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.ParameterPermissions; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ParameterPermissions} + */ +public class ParameterPermissionsTests extends TestCase{ + + private ParameterPermissions msg; + + @Override + public void setUp(){ + msg = new ParameterPermissions(); + + msg.setAllowed(Test.GENERAL_STRING_LIST); + msg.setUserDisallowed(Test.GENERAL_STRING_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<String> allowed = msg.getAllowed(); + List<String> disallowed = msg.getUserDisallowed(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, allowed)); + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, disallowed)); + + // Invalid/Null Tests + ParameterPermissions msg = new ParameterPermissions(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getAllowed()); + assertNull(Test.NULL, msg.getUserDisallowed()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(ParameterPermissions.KEY_ALLOWED, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + reference.put(ParameterPermissions.KEY_USER_DISALLOWED, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while(iterator.hasNext()){ + String key = (String) iterator.next(); + assertTrue(Test.TRUE, Validator.validateStringList(JsonUtils.readStringListFromJsonObject(reference, key), JsonUtils.readStringListFromJsonObject(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/PermissionItemTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/PermissionItemTest.java new file mode 100644 index 000000000..465783ba2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/PermissionItemTest.java @@ -0,0 +1,84 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.HMIPermissions; +import com.smartdevicelink.proxy.rpc.ParameterPermissions; +import com.smartdevicelink.proxy.rpc.PermissionItem; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.PermissionItem} + */ +public class PermissionItemTest extends TestCase { + + private PermissionItem msg; + + @Override + public void setUp() { + msg = new PermissionItem(); + + msg.setRpcName(Test.GENERAL_STRING); + msg.setHMIPermissions(Test.GENERAL_HMIPERMISSIONS); + msg.setParameterPermissions(Test.GENERAL_PARAMETERPERMISSIONS); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String rpcName = msg.getRpcName(); + HMIPermissions hmiPermissions = msg.getHMIPermissions(); + ParameterPermissions parameterPermissions = msg.getParameterPermissions(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, rpcName); + assertTrue(Test.TRUE, Validator.validateHmiPermissions(Test.GENERAL_HMIPERMISSIONS, hmiPermissions)); + assertTrue(Test.TRUE, Validator.validateParameterPermissions(Test.GENERAL_PARAMETERPERMISSIONS, parameterPermissions)); + + // Invalid/Null Tests + PermissionItem msg = new PermissionItem(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getRpcName()); + assertNull(Test.NULL, msg.getHMIPermissions()); + assertNull(Test.NULL, msg.getParameterPermissions()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(PermissionItem.KEY_RPC_NAME, Test.GENERAL_STRING); + reference.put(PermissionItem.KEY_HMI_PERMISSIONS, Test.JSON_HMIPERMISSIONS); + reference.put(PermissionItem.KEY_PARAMETER_PERMISSIONS, Test.JSON_PARAMETERPERMISSIONS); + + 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(PermissionItem.KEY_HMI_PERMISSIONS)) { + assertTrue(Test.TRUE, Validator.validateStringList(JsonUtils.readStringListFromJsonObject(reference, key), JsonUtils.readStringListFromJsonObject(underTest, key))); + } else if (key.equals(PermissionItem.KEY_PARAMETER_PERMISSIONS)) { + assertTrue(Test.TRUE, Validator.validateStringList(JsonUtils.readStringListFromJsonObject(reference, key), JsonUtils.readStringListFromJsonObject(underTest, key))); + } 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/PhoneCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/PhoneCapabilityTests.java new file mode 100644 index 000000000..2614db0fd --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/PhoneCapabilityTests.java @@ -0,0 +1,64 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.PhoneCapability; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.PhoneCapability} + */ +public class PhoneCapabilityTests extends TestCase{ + + private PhoneCapability msg; + + @Override + public void setUp(){ + msg = new PhoneCapability(); + + msg.setDialNumberEnabled(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean dialNumberEnabled = msg.getDialNumberEnabled(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, dialNumberEnabled); + + // Invalid/Null Tests + PhoneCapability msg = new PhoneCapability(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getDialNumberEnabled()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(PhoneCapability.KEY_DIALNUMBER_ENABLED, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/PresetBankCapabilitiesTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/PresetBankCapabilitiesTest.java new file mode 100644 index 000000000..f56d2a212 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/PresetBankCapabilitiesTest.java @@ -0,0 +1,64 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.PresetBankCapabilities; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.PresetBankCapabilities} + */ +public class PresetBankCapabilitiesTest extends TestCase { + + private PresetBankCapabilities msg; + + @Override + public void setUp() { + msg = new PresetBankCapabilities(); + + msg.setOnScreenPresetsAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean presets = msg.onScreenPresetsAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, presets); + + // Invalid/Null Tests + PresetBankCapabilities msg = new PresetBankCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.onScreenPresetsAvailable()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(PresetBankCapabilities.KEY_ON_SCREEN_PRESETS_AVAILABLE, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RGBColorTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RGBColorTest.java new file mode 100644 index 000000000..a9c0033a0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RGBColorTest.java @@ -0,0 +1,70 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.RGBColor; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.RGBColor} + */ +public class RGBColorTest extends TestCase { + + private RGBColor msg; + + @Override + public void setUp() { + msg = new RGBColor(Test.GENERAL_INT, Test.GENERAL_INT, Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer red = msg.getRed(); + Integer green = msg.getGreen(); + Integer blue = msg.getBlue(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, red); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, green); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, blue); + + // Invalid/Null Tests + RGBColor msg = new RGBColor(); + assertNotNull(Test.NOT_NULL, msg); + + assertEquals(Test.MATCH, msg.getRed(), (Integer) 0); + assertEquals(Test.MATCH, msg.getGreen(), (Integer) 0); + assertEquals(Test.MATCH, msg.getBlue(), (Integer) 0); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(RGBColor.KEY_RED, Test.GENERAL_INT); + reference.put(RGBColor.KEY_GREEN, Test.GENERAL_INT); + reference.put(RGBColor.KEY_BLUE, Test.GENERAL_INT); + + 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 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 new file mode 100644 index 000000000..915e779a7 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlCapabilitiesTests.java @@ -0,0 +1,127 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.RadioControlCapabilities; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.RadioControlCapabilities} + */ +public class RadioControlCapabilitiesTests extends TestCase{ + + private RadioControlCapabilities msg; + + @Override + public void setUp(){ + msg = new RadioControlCapabilities(); + + msg.setModuleName(Test.GENERAL_STRING); + msg.setRadioEnableAvailable(Test.GENERAL_BOOLEAN); + msg.setRadioBandAvailable(Test.GENERAL_BOOLEAN); + msg.setRadioFrequencyAvailable(Test.GENERAL_BOOLEAN); + msg.setHdChannelAvailable(Test.GENERAL_BOOLEAN); + msg.setRdsDataAvailable(Test.GENERAL_BOOLEAN); + msg.setAvailableHDsAvailable(Test.GENERAL_BOOLEAN); + msg.setStateAvailable(Test.GENERAL_BOOLEAN); + msg.setSignalStrengthAvailable(Test.GENERAL_BOOLEAN); + msg.setSignalChangeThresholdAvailable(Test.GENERAL_BOOLEAN); + msg.setHdRadioEnableAvailable(Test.GENERAL_BOOLEAN); + msg.setSiriusXMRadioAvailable(Test.GENERAL_BOOLEAN); + msg.setSisDataAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String moduleName = msg.getModuleName(); + boolean radioEnableAvailable = msg.getRadioEnableAvailable(); + boolean radioBandAvailable = msg.getRadioBandAvailable(); + boolean radioFrequencyAvailable = msg.getRadioFrequencyAvailable(); + boolean hdChannelAvailable = msg.getHdChannelAvailable(); + boolean rdsDataAvailable = msg.getRdsDataAvailable(); + boolean availableHDsAvailable = msg.getAvailableHDsAvailable(); + boolean stateAvailable = msg.getStateAvailable(); + boolean signalStrengthAvailable = msg.getSignalStrengthAvailable(); + boolean signalChangeThresholdAvailable = msg.getSignalChangeThresholdAvailable(); + boolean hdRadioEnableAvailable = msg.getHdRadioEnableAvailable(); + boolean siriusXMRadioAvailable = msg.getSiriusXMRadioAvailable(); + boolean sisDataAvailable = msg.getSisDataAvailable(); + + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, radioEnableAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, radioBandAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, radioFrequencyAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, hdChannelAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, rdsDataAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, availableHDsAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, stateAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, signalStrengthAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, signalChangeThresholdAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, hdRadioEnableAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, siriusXMRadioAvailable); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, sisDataAvailable); + + // Invalid/Null Tests + RadioControlCapabilities msg = new RadioControlCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getModuleName()); + assertNull(Test.NULL, msg.getRadioEnableAvailable()); + assertNull(Test.NULL, msg.getRadioBandAvailable()); + assertNull(Test.NULL, msg.getRadioFrequencyAvailable()); + assertNull(Test.NULL, msg.getHdChannelAvailable()); + assertNull(Test.NULL, msg.getRdsDataAvailable()); + assertNull(Test.NULL, msg.getAvailableHDsAvailable()); + assertNull(Test.NULL, msg.getStateAvailable()); + assertNull(Test.NULL, msg.getSignalStrengthAvailable()); + assertNull(Test.NULL, msg.getSignalChangeThresholdAvailable()); + assertNull(Test.NULL, msg.getHdRadioEnableAvailable()); + assertNull(Test.NULL, msg.getSiriusXMRadioAvailable()); + assertNull(Test.NULL, msg.getSisDataAvailable()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(RadioControlCapabilities.KEY_MODULE_NAME, Test.GENERAL_STRING); + reference.put(RadioControlCapabilities.KEY_RADIO_ENABLE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_RADIO_BAND_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_RADIO_FREQUENCY_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_HD_CHANNEL_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_RDS_DATA_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_AVAILABLE_HDS_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_STATE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_SIGNAL_STRENGTH_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlCapabilities.KEY_SIGNAL_CHANGE_THRESHOLD_AVAILABLE, Test.GENERAL_BOOLEAN); + 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); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlDataTests.java new file mode 100644 index 000000000..a560827c4 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RadioControlDataTests.java @@ -0,0 +1,141 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.RadioControlData; +import com.smartdevicelink.proxy.rpc.RdsData; +import com.smartdevicelink.proxy.rpc.SisData; +import com.smartdevicelink.proxy.rpc.enums.RadioBand; +import com.smartdevicelink.proxy.rpc.enums.RadioState; +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.rpc.RadioControlData} + */ +public class RadioControlDataTests extends TestCase{ + + private RadioControlData msg; + + @Override + public void setUp(){ + msg = new RadioControlData(); + + msg.setFrequencyInteger(Test.GENERAL_INT); + msg.setFrequencyFraction(Test.GENERAL_INT); + msg.setBand(Test.GENERAL_RADIOBAND); + msg.setRdsData(Test.GENERAL_RDSDATA); + msg.setAvailableHDs(Test.GENERAL_INT); + msg.setHdChannel(Test.GENERAL_INT); + msg.setSignalStrength(Test.GENERAL_INT); + msg.setSignalChangeThreshold(Test.GENERAL_INT); + msg.setRadioEnable(Test.GENERAL_BOOLEAN); + msg.setState(Test.GENERAL_RADIOSTATE); + msg.setHdRadioEnable(Test.GENERAL_BOOLEAN); + msg.setSisData(Test.GENERAL_SISDATA); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int frequencyInteger = msg.getFrequencyInteger(); + int frequencyFraction = msg.getFrequencyFraction(); + RadioBand band = msg.getBand(); + RdsData rdsData = msg.getRdsData(); + int availableHDs = msg.getAvailableHDs(); + int hdChannel = msg.getHdChannel(); + int signalStrength = msg.getSignalStrength(); + int signalChangeThreshold = msg.getSignalChangeThreshold(); + boolean radioEnable = msg.getRadioEnable(); + RadioState state = msg.getState(); + boolean hdRadioEnable = msg.getHdRadioEnable(); + SisData sisData = msg.getSisData(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, frequencyInteger); + assertEquals(Test.MATCH, Test.GENERAL_INT, frequencyFraction); + assertEquals(Test.MATCH, Test.GENERAL_RADIOBAND, band); + assertTrue(Test.TRUE, Validator.validateRdsData(Test.GENERAL_RDSDATA, rdsData)); + assertEquals(Test.MATCH, Test.GENERAL_INT, availableHDs); + assertEquals(Test.MATCH, Test.GENERAL_INT, hdChannel); + assertEquals(Test.MATCH, Test.GENERAL_INT, signalStrength); + assertEquals(Test.MATCH, Test.GENERAL_INT, signalChangeThreshold); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, radioEnable); + assertEquals(Test.MATCH, Test.GENERAL_RADIOSTATE, state); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, hdRadioEnable); + assertTrue(Test.TRUE, Validator.validateSisData(Test.GENERAL_SISDATA, sisData)); + + // Invalid/Null Tests + RadioControlData msg = new RadioControlData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getFrequencyInteger()); + assertNull(Test.NULL, msg.getFrequencyFraction()); + assertNull(Test.NULL, msg.getBand()); + assertNull(Test.NULL, msg.getRdsData()); + assertNull(Test.NULL, msg.getAvailableHDs()); + assertNull(Test.NULL, msg.getHdChannel()); + assertNull(Test.NULL, msg.getSignalStrength()); + assertNull(Test.NULL, msg.getSignalChangeThreshold()); + assertNull(Test.NULL, msg.getRadioEnable()); + assertNull(Test.NULL, msg.getState()); + assertNull(Test.NULL, msg.getHdRadioEnable()); + assertNull(Test.NULL, msg.getSisData()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(RadioControlData.KEY_FREQUENCY_INTEGER, Test.GENERAL_INT); + reference.put(RadioControlData.KEY_FREQUENCY_FRACTION, Test.GENERAL_INT); + reference.put(RadioControlData.KEY_BAND, Test.GENERAL_RADIOBAND); + reference.put(RadioControlData.KEY_RDS_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_RDSDATA.getStore())); + reference.put(RadioControlData.KEY_AVAILABLE_HDS, Test.GENERAL_INT); + reference.put(RadioControlData.KEY_HD_CHANNEL, Test.GENERAL_INT); + reference.put(RadioControlData.KEY_SIGNAL_STRENGTH, Test.GENERAL_INT); + reference.put(RadioControlData.KEY_SIGNAL_CHANGE_THRESHOLD, Test.GENERAL_INT); + reference.put(RadioControlData.KEY_RADIO_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlData.KEY_STATE, Test.GENERAL_RADIOSTATE); + reference.put(RadioControlData.KEY_HD_RADIO_ENABLE, Test.GENERAL_BOOLEAN); + reference.put(RadioControlData.KEY_SIS_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_SISDATA.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(RadioControlData.KEY_RDS_DATA)){ + 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.validateRdsData(new RdsData(hashReference), new RdsData(hashTest))); + } else if (key.equals(RadioControlData.KEY_SIS_DATA)) { + 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.validateSisData(new SisData(hashReference), new SisData(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/RdsDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RdsDataTests.java new file mode 100644 index 000000000..7414304b0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RdsDataTests.java @@ -0,0 +1,101 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.RdsData; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.RdsData} + */ +public class RdsDataTests extends TestCase{ + + private RdsData msg; + + @Override + public void setUp(){ + msg = new RdsData(); + + msg.setProgramService(Test.GENERAL_STRING); + msg.setRadioText(Test.GENERAL_STRING); + msg.setClockText(Test.GENERAL_STRING); + msg.setProgramIdentification(Test.GENERAL_STRING); + msg.setRegion(Test.GENERAL_STRING); + msg.setTrafficProgram(Test.GENERAL_BOOLEAN); + msg.setTrafficAnnouncement(Test.GENERAL_BOOLEAN); + msg.setProgramType(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String ps = msg.getProgramService(); + String rt = msg.getRadioText(); + String ct = msg.getClockText(); + String pi = msg.getProgramIdentification(); + int pty = msg.getProgramType(); + boolean tp = msg.getTrafficProgram(); + boolean ta = msg.getTrafficAnnouncement(); + String reg = msg.getRegion(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, ps); + assertEquals(Test.MATCH, Test.GENERAL_STRING, rt); + assertEquals(Test.MATCH, Test.GENERAL_STRING, ct); + assertEquals(Test.MATCH, Test.GENERAL_STRING, pi); + assertEquals(Test.MATCH, Test.GENERAL_INT, pty); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, tp); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, ta); + assertEquals(Test.MATCH, Test.GENERAL_STRING, reg); + + // Invalid/Null Tests + RdsData msg = new RdsData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getProgramService()); + assertNull(Test.NULL, msg.getRadioText()); + assertNull(Test.NULL, msg.getClockText()); + assertNull(Test.NULL, msg.getProgramIdentification()); + assertNull(Test.NULL, msg.getRegion()); + assertNull(Test.NULL, msg.getTrafficProgram()); + assertNull(Test.NULL, msg.getTrafficAnnouncement()); + assertNull(Test.NULL, msg.getProgramType()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(RdsData.KEY_PS, Test.GENERAL_STRING); + reference.put(RdsData.KEY_RT, Test.GENERAL_STRING); + reference.put(RdsData.KEY_CT, Test.GENERAL_STRING); + reference.put(RdsData.KEY_PI, Test.GENERAL_STRING); + reference.put(RdsData.KEY_PTY, Test.GENERAL_INT); + reference.put(RdsData.KEY_TP, Test.GENERAL_BOOLEAN); + reference.put(RdsData.KEY_TA, Test.GENERAL_BOOLEAN); + reference.put(RdsData.KEY_REG, Test.GENERAL_STRING); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RectangleTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RectangleTests.java new file mode 100644 index 000000000..569a4db83 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RectangleTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.Rectangle; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link Rectangle} + */ +public class RectangleTests extends TestCase { + + private Rectangle msg; + + @Override + public void setUp() { + msg = new Rectangle(); + + msg.setX(Test.GENERAL_FLOAT); + msg.setY(Test.GENERAL_FLOAT); + msg.setWidth(Test.GENERAL_FLOAT); + msg.setHeight(Test.GENERAL_FLOAT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Float x = msg.getX(); + Float y = msg.getY(); + Float width = msg.getWidth(); + Float height = msg.getHeight(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, x); + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, y); + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, width); + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, height); + + // Invalid/Null Tests + Rectangle msg = new Rectangle(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getX()); + assertNull(Test.NULL, msg.getY()); + assertNull(Test.NULL, msg.getWidth()); + assertNull(Test.NULL, msg.getHeight()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(Rectangle.KEY_X, (Test.GENERAL_FLOAT)); + reference.put(Rectangle.KEY_Y, (Test.GENERAL_FLOAT)); + reference.put(Rectangle.KEY_WIDTH, (Test.GENERAL_FLOAT)); + reference.put(Rectangle.KEY_HEIGHT, (Test.GENERAL_FLOAT)); + + 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); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RemoteControlCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RemoteControlCapabilitiesTests.java new file mode 100644 index 000000000..e6a2d2b9a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/RemoteControlCapabilitiesTests.java @@ -0,0 +1,180 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.AudioControlCapabilities; +import com.smartdevicelink.proxy.rpc.ButtonCapabilities; +import com.smartdevicelink.proxy.rpc.ClimateControlCapabilities; +import com.smartdevicelink.proxy.rpc.HMISettingsControlCapabilities; +import com.smartdevicelink.proxy.rpc.LightControlCapabilities; +import com.smartdevicelink.proxy.rpc.RadioControlCapabilities; +import com.smartdevicelink.proxy.rpc.RemoteControlCapabilities; +import com.smartdevicelink.proxy.rpc.SeatControlCapabilities; +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.rpc.RemoteControlCapabilities} + */ +public class RemoteControlCapabilitiesTests extends TestCase { + + private RemoteControlCapabilities msg; + + @Override + public void setUp() { + msg = new RemoteControlCapabilities(); + msg.setButtonCapabilities(Test.GENERAL_BUTTONCAPABILITIES_LIST); + msg.setRadioControlCapabilities(Test.GENERAL_RADIOCONTROLCAPABILITIES_LIST); + msg.setClimateControlCapabilities(Test.GENERAL_CLIMATECONTROLCAPABILITIES_LIST); + msg.setSeatControlCapabilities(Test.GENERAL_SEATCONTROLCAPABILITIES_LIST); + msg.setAudioControlCapabilities(Test.GENERAL_AUDIOCONTROLCAPABILITIES_LIST); + msg.setHmiSettingsControlCapabilities(Test.GENERAL_HMISETTINGSCONTROLCAPABILITIES); + msg.setLightControlCapabilities(Test.GENERAL_LIGHTCONTROLCAPABILITIES); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + List<ButtonCapabilities> buttonCapabilities = msg.getButtonCapabilities(); + List<RadioControlCapabilities> radioControlCapabilities = msg.getRadioControlCapabilities(); + List<ClimateControlCapabilities> climateControlCapabilities = msg.getClimateControlCapabilities(); + List<SeatControlCapabilities> seatControlCapabilities = msg.getSeatControlCapabilities(); + List<AudioControlCapabilities> audioControlCapabilities = msg.getAudioControlCapabilities(); + HMISettingsControlCapabilities hmiSettingsControlCapabilities = msg.getHmiSettingsControlCapabilities(); + LightControlCapabilities lightControlCapabilities = msg.getLightControlCapabilities(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BUTTONCAPABILITIES_LIST.size(), buttonCapabilities.size()); + assertEquals(Test.MATCH, Test.GENERAL_RADIOCONTROLCAPABILITIES_LIST.size(), radioControlCapabilities.size()); + assertEquals(Test.MATCH, Test.GENERAL_CLIMATECONTROLCAPABILITIES_LIST.size(), climateControlCapabilities.size()); + assertEquals(Test.MATCH, Test.GENERAL_SEATCONTROLCAPABILITIES_LIST.size(), seatControlCapabilities.size()); + + assertTrue(Test.TRUE, Validator.validateButtonCapabilities(Test.GENERAL_BUTTONCAPABILITIES_LIST, buttonCapabilities)); + assertTrue(Test.TRUE, Validator.validateRadioControlCapabilities(Test.GENERAL_RADIOCONTROLCAPABILITIES_LIST, radioControlCapabilities)); + assertTrue(Test.TRUE, Validator.validateClimateControlCapabilities(Test.GENERAL_CLIMATECONTROLCAPABILITIES_LIST, climateControlCapabilities)); + assertTrue(Test.TRUE, Validator.validateSeatControlCapabilitiesList(Test.GENERAL_SEATCONTROLCAPABILITIES_LIST, seatControlCapabilities)); + assertTrue(Test.TRUE, Validator.validateAudioControlCapabilitiesList(Test.GENERAL_AUDIOCONTROLCAPABILITIES_LIST, audioControlCapabilities)); + assertTrue(Test.TRUE, Validator.validateHMISettingsControlCapabilities(Test.GENERAL_HMISETTINGSCONTROLCAPABILITIES, hmiSettingsControlCapabilities)); + assertTrue(Test.TRUE, Validator.validateLightControlCapabilities(Test.GENERAL_LIGHTCONTROLCAPABILITIES, lightControlCapabilities)); + + // Invalid/Null Tests + RemoteControlCapabilities msg = new RemoteControlCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getButtonCapabilities()); + assertNull(Test.NULL, msg.getRadioControlCapabilities()); + assertNull(Test.NULL, msg.getClimateControlCapabilities()); + assertNull(Test.NULL, msg.getSeatControlCapabilities()); + assertNull(Test.NULL, msg.getAudioControlCapabilities()); + assertNull(Test.NULL, msg.getHmiSettingsControlCapabilities()); + assertNull(Test.NULL, msg.getLightControlCapabilities()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(RemoteControlCapabilities.KEY_BUTTON_CAPABILITIES, Test.JSON_BUTTONCAPABILITIES); + reference.put(RemoteControlCapabilities.KEY_RADIO_CONTROL_CAPABILITIES, Test.JSON_RADIOCONTROLCAPABILITIES); + reference.put(RemoteControlCapabilities.KEY_CLIMATE_CONTROL_CAPABILITIES, Test.JSON_CLIMATECONTROLCAPABILITIES); + reference.put(RemoteControlCapabilities.KEY_SEAT_CONTROL_CAPABILITIES, Test.GENERAL_SEATCONTROLCAPABILITIES_LIST); + reference.put(RemoteControlCapabilities.KEY_AUDIO_CONTROL_CAPABILITIES, Test.GENERAL_AUDIOCONTROLCAPABILITIES_LIST); + reference.put(RemoteControlCapabilities.KEY_HMI_SETTINGS_CONTROL_CAPABILITIES, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_HMISETTINGSCONTROLCAPABILITIES.getStore())); + reference.put(RemoteControlCapabilities.KEY_LIGHT_CONTROL_CAPABILITIES, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_LIGHTCONTROLCAPABILITIES.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(RemoteControlCapabilities.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(RemoteControlCapabilities.KEY_RADIO_CONTROL_CAPABILITIES)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.MATCH, referenceArray.length(), underTestArray.length()); + + List<RadioControlCapabilities> referenceList = new ArrayList<RadioControlCapabilities>(); + List<RadioControlCapabilities> testList = new ArrayList<RadioControlCapabilities>(); + for (int i = 0; i < referenceArray.length(); i++) { + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(referenceArray.getJSONObject(i)); + referenceList.add(new RadioControlCapabilities(hashReference)); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(underTestArray.getJSONObject(i)); + testList.add(new RadioControlCapabilities(hashTest)); + } + assertTrue(Test.TRUE, Validator.validateRadioControlCapabilities(referenceList, testList)); + } else if (key.equals(RemoteControlCapabilities.KEY_CLIMATE_CONTROL_CAPABILITIES)) { + JSONArray referenceArray = JsonUtils.readJsonArrayFromJsonObject(reference, key); + JSONArray underTestArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + assertEquals(Test.MATCH, referenceArray.length(), underTestArray.length()); + + List<ClimateControlCapabilities> referenceList = new ArrayList<ClimateControlCapabilities>(); + List<ClimateControlCapabilities> testList = new ArrayList<ClimateControlCapabilities>(); + for (int i = 0; i < referenceArray.length(); i++) { + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(referenceArray.getJSONObject(i)); + referenceList.add(new ClimateControlCapabilities(hashReference)); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(underTestArray.getJSONObject(i)); + testList.add(new ClimateControlCapabilities(hashTest)); + } + assertTrue(Test.TRUE, Validator.validateClimateControlCapabilities(referenceList, testList)); + } else if (key.equals(RemoteControlCapabilities.KEY_SEAT_CONTROL_CAPABILITIES)) { + List<SeatControlCapabilities> sccReference = (List<SeatControlCapabilities>) JsonUtils.readObjectFromJsonObject(reference, key); + JSONArray sccArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + int i = 0; + for (SeatControlCapabilities scc : sccReference) { + assertTrue(Validator.validateSeatControlCapabilities(scc, new SeatControlCapabilities(JsonRPCMarshaller.deserializeJSONObject(sccArray.getJSONObject(i++))))); + } + } else if (key.equals(RemoteControlCapabilities.KEY_AUDIO_CONTROL_CAPABILITIES)) { + List<AudioControlCapabilities> accReference = (List<AudioControlCapabilities>) JsonUtils.readObjectFromJsonObject(reference, key); + JSONArray accArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + int i = 0; + for (AudioControlCapabilities acc : accReference) { + assertTrue(Validator.validateAudioControlCapabilities(acc, new AudioControlCapabilities(JsonRPCMarshaller.deserializeJSONObject(accArray.getJSONObject(i++))))); + } + } else if (key.equals(RemoteControlCapabilities.KEY_HMI_SETTINGS_CONTROL_CAPABILITIES)) { + 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.validateHMISettingsControlCapabilities(new HMISettingsControlCapabilities(hashReference), new HMISettingsControlCapabilities(hashTest))); + } else if (key.equals(RemoteControlCapabilities.KEY_LIGHT_CONTROL_CAPABILITIES)) { + 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.validateLightControlCapabilities(new LightControlCapabilities(hashReference), new LightControlCapabilities(hashTest))); + } + } + } 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/ScreenParamsTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ScreenParamsTest.java new file mode 100644 index 000000000..4621f8950 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/ScreenParamsTest.java @@ -0,0 +1,90 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.ImageResolution; +import com.smartdevicelink.proxy.rpc.ScreenParams; +import com.smartdevicelink.proxy.rpc.TouchEventCapabilities; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ScreenParams} + */ +public class ScreenParamsTest extends TestCase { + + private ScreenParams msg; + + @Override + public void setUp() { + msg = new ScreenParams(); + + msg.setImageResolution(Test.GENERAL_IMAGERESOLUTION); + msg.setTouchEventAvailable(Test.GENERAL_TOUCHEVENTCAPABILITIES); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ImageResolution imageRes = msg.getImageResolution(); + TouchEventCapabilities touchEvent = msg.getTouchEventAvailable(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateImageResolution(Test.GENERAL_IMAGERESOLUTION, imageRes)); + assertTrue(Test.TRUE, Validator.validateTouchEventCapabilities(Test.GENERAL_TOUCHEVENTCAPABILITIES, touchEvent)); + + // Invalid/Null Tests + ScreenParams msg = new ScreenParams(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getImageResolution()); + assertNull(Test.NULL, msg.getTouchEventAvailable()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(ScreenParams.KEY_RESOLUTION, Test.JSON_IMAGERESOLUTION); + reference.put(ScreenParams.KEY_TOUCH_EVENT_AVAILABLE, Test.JSON_TOUCHEVENTCAPABILITIES); + + 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(ScreenParams.KEY_TOUCH_EVENT_AVAILABLE)) { + JSONObject touchEventObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject touchEventObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateTouchEventCapabilities( + new TouchEventCapabilities(JsonRPCMarshaller.deserializeJSONObject(touchEventObjReference)), + new TouchEventCapabilities(JsonRPCMarshaller.deserializeJSONObject(touchEventObjTest)))); + } else if (key.equals(ScreenParams.KEY_RESOLUTION)) { + JSONObject resolutionObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject resolutionObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateImageResolution( + new ImageResolution(JsonRPCMarshaller.deserializeJSONObject(resolutionObjReference)), + new ImageResolution(JsonRPCMarshaller.deserializeJSONObject(resolutionObjTest)))); + } 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/SdlMsgVersionTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SdlMsgVersionTest.java new file mode 100644 index 000000000..645652ea0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SdlMsgVersionTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.SdlMsgVersion; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SdlMsgVersion} + */ +public class SdlMsgVersionTest extends TestCase { + + private SdlMsgVersion msg; + + @Override + public void setUp() { + msg = new SdlMsgVersion(); + + msg.setMajorVersion(Test.GENERAL_INT); + msg.setMinorVersion(Test.GENERAL_INT); + msg.setPatchVersion(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer major = msg.getMajorVersion(); + Integer minor = msg.getMinorVersion(); + Integer patch = msg.getPatchVersion(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, major); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, minor); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, patch); + + // Invalid/Null Tests + SdlMsgVersion msg = new SdlMsgVersion(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getMajorVersion()); + assertNull(Test.NULL, msg.getMinorVersion()); + assertNull(Test.NULL, msg.getPatchVersion()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SdlMsgVersion.KEY_MAJOR_VERSION, Test.GENERAL_INT); + reference.put(SdlMsgVersion.KEY_MINOR_VERSION, Test.GENERAL_INT); + reference.put(SdlMsgVersion.KEY_PATCH_VERSION, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatControlCapabilitiesTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatControlCapabilitiesTest.java new file mode 100644 index 000000000..d988fa991 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatControlCapabilitiesTest.java @@ -0,0 +1,141 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.SeatControlCapabilities; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SeatControlCapabilities} + */ +public class SeatControlCapabilitiesTest extends TestCase { + + private SeatControlCapabilities msg; + + @Override + public void setUp() { + msg = new SeatControlCapabilities(); + msg.setModuleName(Test.GENERAL_STRING); + msg.setHeatingEnabledAvailable(Test.GENERAL_BOOLEAN); + msg.setCoolingEnabledAvailable(Test.GENERAL_BOOLEAN); + msg.setHeatingLevelAvailable(Test.GENERAL_BOOLEAN); + msg.setCoolingLevelAvailable(Test.GENERAL_BOOLEAN); + msg.setHorizontalPositionAvailable(Test.GENERAL_BOOLEAN); + msg.setVerticalPositionAvailable(Test.GENERAL_BOOLEAN); + msg.setFrontVerticalPositionAvailable(Test.GENERAL_BOOLEAN); + msg.setBackVerticalPositionAvailable(Test.GENERAL_BOOLEAN); + msg.setBackTiltAngleAvailable(Test.GENERAL_BOOLEAN); + msg.setHeadSupportVerticalPositionAvailable(Test.GENERAL_BOOLEAN); + msg.setHeadSupportHorizontalPositionAvailable(Test.GENERAL_BOOLEAN); + msg.setMassageEnabledAvailable(Test.GENERAL_BOOLEAN); + msg.setMassageModeAvailable(Test.GENERAL_BOOLEAN); + msg.setMassageCushionFirmnessAvailable(Test.GENERAL_BOOLEAN); + msg.setMemoryAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + String moduleName = msg.getModuleName(); + Boolean heatingEnabledAvailable = msg.getHeatingEnabledAvailable(); + Boolean coolingEnabledAvailable = msg.getCoolingEnabledAvailable(); + Boolean heatingLevelAvailable = msg.getHeatingLevelAvailable(); + Boolean coolingLevelAvailable = msg.getCoolingLevelAvailable(); + Boolean horizontalPositionAvailable = msg.getHorizontalPositionAvailable(); + Boolean verticalPositionAvailable = msg.getVerticalPositionAvailable(); + Boolean frontVerticalPositionAvailable = msg.getFrontVerticalPositionAvailable(); + Boolean backVerticalPositionAvailable = msg.getBackVerticalPositionAvailable(); + Boolean backTiltAngleAvailable = msg.getBackTiltAngleAvailable(); + Boolean headSupportHorizontalPositionAvailable = msg.getHeadSupportHorizontalPositionAvailable(); + Boolean headSupportVerticalPositionAvailable = msg.getHeadSupportVerticalPositionAvailable(); + Boolean massageEnabledAvailable = msg.getMassageEnabledAvailable(); + Boolean massageModeAvailable = msg.getMassageModeAvailable(); + Boolean massageCushionFirmnessAvailable = msg.getMassageCushionFirmnessAvailable(); + + Boolean memoryAvailable = msg.getMemoryAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, moduleName); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, heatingEnabledAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, coolingEnabledAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, heatingLevelAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, coolingLevelAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, horizontalPositionAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, verticalPositionAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, frontVerticalPositionAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, backVerticalPositionAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, backTiltAngleAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, headSupportHorizontalPositionAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, headSupportVerticalPositionAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, massageEnabledAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, massageModeAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, massageCushionFirmnessAvailable); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, memoryAvailable); + + // Invalid/Null Tests + SeatControlCapabilities msg = new SeatControlCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getModuleName()); + assertNull(Test.NULL, msg.getHeatingEnabledAvailable()); + assertNull(Test.NULL, msg.getCoolingEnabledAvailable()); + assertNull(Test.NULL, msg.getHeatingLevelAvailable()); + assertNull(Test.NULL, msg.getCoolingLevelAvailable()); + assertNull(Test.NULL, msg.getHorizontalPositionAvailable()); + assertNull(Test.NULL, msg.getVerticalPositionAvailable()); + assertNull(Test.NULL, msg.getFrontVerticalPositionAvailable()); + assertNull(Test.NULL, msg.getBackVerticalPositionAvailable()); + assertNull(Test.NULL, msg.getBackTiltAngleAvailable()); + assertNull(Test.NULL, msg.getHeadSupportHorizontalPositionAvailable()); + assertNull(Test.NULL, msg.getHeadSupportVerticalPositionAvailable()); + assertNull(Test.NULL, msg.getMassageEnabledAvailable()); + assertNull(Test.NULL, msg.getMassageModeAvailable()); + assertNull(Test.NULL, msg.getMassageCushionFirmnessAvailable()); + assertNull(Test.NULL, msg.getMemoryAvailable()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SeatControlCapabilities.KEY_MODULE_NAME, Test.GENERAL_STRING); + reference.put(SeatControlCapabilities.KEY_HEATING_ENABLED_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_COOLING_ENABLED_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_HEATING_LEVEL_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_COOLING_LEVEL_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_HORIZONTAL_POSITION_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_VERTICAL_POSITION_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_FRONT_VERTICAL_POSITION_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_BACK_VERTICAL_POSITION_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_BACK_TILT_ANGLE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_HEAD_SUPPORT_HORIZONTAL_POSITION_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_HEAD_SUPPORT_VERTICAL_POSITION_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_MASSAGE_ENABLED_AVAILABLE, Test.GENERAL_BOOLEAN); + + reference.put(SeatControlCapabilities.KEY_MASSAGE_MODE_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(SeatControlCapabilities.KEY_MASSAGE_CUSHION_FIRMNESS_AVAILABLE, Test.GENERAL_BOOLEAN); + + reference.put(SeatControlCapabilities.KEY_MEMORY_AVAILABLE, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatControlDataTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatControlDataTest.java new file mode 100644 index 000000000..535e7cf3e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatControlDataTest.java @@ -0,0 +1,173 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.MassageCushionFirmness; +import com.smartdevicelink.proxy.rpc.MassageModeData; +import com.smartdevicelink.proxy.rpc.SeatControlData; +import com.smartdevicelink.proxy.rpc.SeatMemoryAction; +import com.smartdevicelink.proxy.rpc.enums.SupportedSeat; +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.rpc.SeatControlData} + */ +public class SeatControlDataTest extends TestCase { + + private SeatControlData msg; + + @Override + public void setUp() { + msg = new SeatControlData(); + msg.setId(Test.GENERAL_SUPPORTEDSEAT); + msg.setHeatingEnabled(Test.GENERAL_BOOLEAN); + msg.setCoolingEnabled(Test.GENERAL_BOOLEAN); + msg.setHeatingLevel(Test.GENERAL_INT); + msg.setCoolingLevel(Test.GENERAL_INT); + msg.setHorizontalPosition(Test.GENERAL_INT); + msg.setVerticalPosition(Test.GENERAL_INT); + msg.setFrontVerticalPosition(Test.GENERAL_INT); + msg.setBackVerticalPosition(Test.GENERAL_INT); + msg.setBackTiltAngle(Test.GENERAL_INT); + msg.setHeadSupportVerticalPosition(Test.GENERAL_INT); + msg.setHeadSupportHorizontalPosition(Test.GENERAL_INT); + msg.setMassageEnabled(Test.GENERAL_BOOLEAN); + msg.setMassageMode(Test.GENERAL_MASSAGEMODEDATA_LIST); + msg.setMassageCushionFirmness(Test.GENERAL_MASSAGECUSHIONFIRMNESS_LIST); + msg.setMemory(Test.GENERAL_SEATMEMORYACTION); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + SupportedSeat id = msg.getId(); + Boolean heatingEnabled = msg.getHeatingEnabled(); + Boolean coolingEnabled = msg.getCoolingEnabled(); + Integer heatingLevel = msg.getHeatingLevel(); + Integer coolingLevel = msg.getCoolingLevel(); + Integer horizontalPosition = msg.getHorizontalPosition(); + Integer verticalPosition = msg.getVerticalPosition(); + Integer frontVerticalPosition = msg.getFrontVerticalPosition(); + Integer backVerticalPosition = msg.getBackVerticalPosition(); + Integer backTiltAngle = msg.getBackTiltAngle(); + Integer headSupportHorizontalPosition = msg.getHeadSupportHorizontalPosition(); + Integer headSupportVerticalPosition = msg.getHeadSupportVerticalPosition(); + Boolean massageEnabled = msg.getMassageEnabled(); + + List<MassageModeData> massageMode = msg.getMassageMode(); + List<MassageCushionFirmness> massageCushionFirmness = msg.getMassageCushionFirmness(); + SeatMemoryAction memory = msg.getMemory(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_SUPPORTEDSEAT, id); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, heatingEnabled); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, coolingEnabled); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, heatingLevel); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, coolingLevel); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, horizontalPosition); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, verticalPosition); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, frontVerticalPosition); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, backVerticalPosition); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, backTiltAngle); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, headSupportHorizontalPosition); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, headSupportVerticalPosition); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, massageEnabled); + + assertTrue(Test.TRUE, Validator.validateMassageModeDataList(Test.GENERAL_MASSAGEMODEDATA_LIST, massageMode)); + assertTrue(Test.TRUE, Validator.validateMassageCushionFirmnessList(Test.GENERAL_MASSAGECUSHIONFIRMNESS_LIST, massageCushionFirmness)); + + assertTrue(Test.TRUE, Validator.validateSeatMemoryAction(Test.GENERAL_SEATMEMORYACTION, memory)); + + // Invalid/Null Tests + SeatControlData msg = new SeatControlData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getId()); + assertNull(Test.NULL, msg.getHeatingEnabled()); + assertNull(Test.NULL, msg.getCoolingEnabled()); + assertNull(Test.NULL, msg.getHeatingLevel()); + assertNull(Test.NULL, msg.getCoolingLevel()); + assertNull(Test.NULL, msg.getHorizontalPosition()); + assertNull(Test.NULL, msg.getVerticalPosition()); + assertNull(Test.NULL, msg.getFrontVerticalPosition()); + assertNull(Test.NULL, msg.getBackVerticalPosition()); + assertNull(Test.NULL, msg.getBackTiltAngle()); + assertNull(Test.NULL, msg.getHeadSupportHorizontalPosition()); + assertNull(Test.NULL, msg.getHeadSupportVerticalPosition()); + assertNull(Test.NULL, msg.getMassageEnabled()); + assertNull(Test.NULL, msg.getMassageMode()); + assertNull(Test.NULL, msg.getMassageCushionFirmness()); + assertNull(Test.NULL, msg.getMemory()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SeatControlData.KEY_ID, Test.GENERAL_SUPPORTEDSEAT); + reference.put(SeatControlData.KEY_HEATING_ENABLED, Test.GENERAL_BOOLEAN); + reference.put(SeatControlData.KEY_COOLING_ENABLED, Test.GENERAL_BOOLEAN); + reference.put(SeatControlData.KEY_HEATING_LEVEL, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_COOLING_LEVEL, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_HORIZONTAL_POSITION, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_VERTICAL_POSITION, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_FRONT_VERTICAL_POSITION, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_BACK_VERTICAL_POSITION, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_BACK_TILT_ANGLE, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_HEAD_SUPPORT_HORIZONTAL_POSITION, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_HEAD_SUPPORT_VERTICAL_POSITION, Test.GENERAL_INT); + reference.put(SeatControlData.KEY_MASSAGE_ENABLED, Test.GENERAL_BOOLEAN); + + reference.put(SeatControlData.KEY_MASSAGE_MODE, Test.GENERAL_MASSAGEMODEDATA_LIST); + reference.put(SeatControlData.KEY_MASSAGE_CUSHION_FIRMNESS, Test.GENERAL_MASSAGECUSHIONFIRMNESS_LIST); + + reference.put(SeatControlData.KEY_MEMORY, Test.GENERAL_SEATMEMORYACTION); + + 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(SeatControlData.KEY_MASSAGE_MODE)) { + List<MassageModeData> mmdReference = (List<MassageModeData>) JsonUtils.readObjectFromJsonObject(reference, key); + JSONArray mmdArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + int i = 0; + for (MassageModeData mmd : mmdReference) { + assertTrue(Validator.validateMassageModeData(mmd, new MassageModeData(JsonRPCMarshaller.deserializeJSONObject(mmdArray.getJSONObject(i++))))); + } + } else if (key.equals(SeatControlData.KEY_MASSAGE_CUSHION_FIRMNESS)) { + List<MassageCushionFirmness> mcfReference = (List<MassageCushionFirmness>) JsonUtils.readObjectFromJsonObject(reference, key); + JSONArray mcfArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + int i = 0; + for (MassageCushionFirmness mcf : mcfReference) { + assertTrue(Validator.validateMassageCushionFirmness(mcf, new MassageCushionFirmness(JsonRPCMarshaller.deserializeJSONObject(mcfArray.getJSONObject(i++))))); + } + } else if (key.equals(SeatControlData.KEY_MEMORY)) { + SeatMemoryAction mReference = (SeatMemoryAction) JsonUtils.readObjectFromJsonObject(reference, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(JsonUtils.readJsonObjectFromJsonObject(underTest, key)); + assertTrue(Validator.validateSeatMemoryAction(mReference, new SeatMemoryAction(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/SeatMemoryActionTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatMemoryActionTest.java new file mode 100644 index 000000000..a8c17cee3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SeatMemoryActionTest.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.SeatMemoryAction; +import com.smartdevicelink.proxy.rpc.enums.SeatMemoryActionType; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SeatMemoryAction} + */ +public class SeatMemoryActionTest extends TestCase { + + private SeatMemoryAction msg; + + @Override + public void setUp() { + msg = new SeatMemoryAction(); + + msg.setId(Test.GENERAL_INT); + msg.setLabel(Test.GENERAL_STRING); + msg.setAction(Test.GENERAL_SEATMEMORYACTIONTYPE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + Integer id = msg.getId(); + String label = msg.getLabel(); + SeatMemoryActionType action = msg.getAction(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, id); + assertEquals(Test.MATCH, Test.GENERAL_STRING, label); + assertEquals(Test.MATCH, Test.GENERAL_SEATMEMORYACTIONTYPE, action); + + // Invalid/Null Tests + SeatMemoryAction msg = new SeatMemoryAction(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getId()); + assertNull(Test.NULL, msg.getLabel()); + assertNull(Test.NULL, msg.getAction()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SeatMemoryAction.KEY_ID, Test.GENERAL_INT); + reference.put(SeatMemoryAction.KEY_LABEL, Test.GENERAL_STRING); + reference.put(SeatMemoryAction.KEY_ACTION, Test.GENERAL_SEATMEMORYACTIONTYPE); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SingleTireStatusTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SingleTireStatusTest.java new file mode 100644 index 000000000..9f1d3342a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SingleTireStatusTest.java @@ -0,0 +1,76 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.SingleTireStatus; +import com.smartdevicelink.proxy.rpc.enums.ComponentVolumeStatus; +import com.smartdevicelink.proxy.rpc.enums.TPMS; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.SingleTireStatus} + */ +public class SingleTireStatusTest extends TestCase { + + private SingleTireStatus msg; + + @Override + public void setUp() { + msg = new SingleTireStatus(); + + msg.setStatus(Test.GENERAL_COMPONENTVOLUMESTATUS); + msg.setTPMS(Test.GENERAL_TPMS); + msg.setPressure(Test.GENERAL_FLOAT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ComponentVolumeStatus status = msg.getStatus(); + TPMS tpms = msg.getTPMS(); + Float pressure = msg.getPressure(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_COMPONENTVOLUMESTATUS, status); + assertEquals(Test.MATCH, Test.GENERAL_TPMS, tpms); + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, pressure); + + // Invalid/Null Tests + SingleTireStatus msg = new SingleTireStatus(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getStatus()); + assertNull(Test.NULL, msg.getTPMS()); + assertNull(Test.NULL, msg.getPressure()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SingleTireStatus.KEY_STATUS, Test.GENERAL_COMPONENTVOLUMESTATUS); + reference.put(SingleTireStatus.KEY_TPMS, Test.GENERAL_TPMS); + reference.put(SingleTireStatus.KEY_PRESSURE, Test.GENERAL_FLOAT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SisDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SisDataTests.java new file mode 100644 index 000000000..51e38f8d1 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SisDataTests.java @@ -0,0 +1,105 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.GPSData; +import com.smartdevicelink.proxy.rpc.SisData; +import com.smartdevicelink.proxy.rpc.StationIDNumber; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.VehicleDataHelper; + +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.rpc.SisData} + */ +public class SisDataTests extends TestCase { + + private SisData msg; + + @Override + public void setUp() { + msg = new SisData(); + + msg.setStationShortName(Test.GENERAL_STRING); + msg.setStationIDNumber(Test.GENERAL_STATIONIDNUMBER); + msg.setStationLongName(Test.GENERAL_STRING); + msg.setStationLocation(VehicleDataHelper.GPS); + msg.setStationMessage(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + String stationShortName = msg.getStationShortName(); + StationIDNumber stationIDNumber = msg.getStationIDNumber(); + String stationLongName = msg.getStationLongName(); + GPSData stationLocation = msg.getStationLocation(); + String stationMessage = msg.getStationMessage(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, stationShortName); + assertEquals(Test.MATCH, Test.GENERAL_STATIONIDNUMBER, stationIDNumber); + assertEquals(Test.MATCH, Test.GENERAL_STRING, stationLongName); + assertEquals(Test.MATCH, VehicleDataHelper.GPS, stationLocation); + assertEquals(Test.MATCH, Test.GENERAL_STRING, stationMessage); + + // Invalid/Null Tests + SisData msg = new SisData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getStationShortName()); + assertNull(Test.NULL, msg.getStationIDNumber()); + assertNull(Test.NULL, msg.getStationLongName()); + assertNull(Test.NULL, msg.getStationLocation()); + assertNull(Test.NULL, msg.getStationMessage()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SisData.KEY_STATION_SHORT_NAME, Test.GENERAL_STRING); + reference.put(SisData.KEY_STATION_ID_NUMBER, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_STATIONIDNUMBER.getStore())); + reference.put(SisData.KEY_STATION_LONG_NAME, Test.GENERAL_STRING); + reference.put(SisData.KEY_STATION_LOCATION, JsonRPCMarshaller.serializeHashtable(VehicleDataHelper.GPS.getStore())); + reference.put(SisData.KEY_STATION_MESSAGE, Test.GENERAL_STRING); + + 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(SisData.KEY_STATION_ID_NUMBER)) { + 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.validateStationIDNumber(new StationIDNumber(hashReference), new StationIDNumber(hashTest))); + } else if (key.equals(SisData.KEY_STATION_LOCATION)) { + 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.validateGpsData(new GPSData(hashReference), new GPSData(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/SoftButtonCapabilitiesTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonCapabilitiesTest.java new file mode 100644 index 000000000..125aa5e41 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonCapabilitiesTest.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.SoftButtonCapabilities; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SoftButtonCapabilities} + */ +public class SoftButtonCapabilitiesTest extends TestCase { + + private SoftButtonCapabilities msg; + + @Override + public void setUp() { + msg = new SoftButtonCapabilities(); + + msg.setImageSupported(Test.GENERAL_BOOLEAN); + msg.setShortPressAvailable(Test.GENERAL_BOOLEAN); + msg.setLongPressAvailable(Test.GENERAL_BOOLEAN); + msg.setUpDownAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Boolean imageSupp = msg.getImageSupported(); + Boolean updown = msg.getUpDownAvailable(); + Boolean longPress = msg.getLongPressAvailable(); + Boolean shortPress = msg.getShortPressAvailable(); + + // 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); + + // Invalid/Null Tests + SoftButtonCapabilities msg = new SoftButtonCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getImageSupported()); + assertNull(Test.NULL, msg.getLongPressAvailable()); + assertNull(Test.NULL, msg.getShortPressAvailable()); + assertNull(Test.NULL, msg.getUpDownAvailable()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SoftButtonCapabilities.KEY_IMAGE_SUPPORTED, Test.GENERAL_BOOLEAN); + 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); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonTest.java new file mode 100644 index 000000000..b2dfb54fc --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SoftButtonTest.java @@ -0,0 +1,104 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Hashtable; +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.SoftButton; +import com.smartdevicelink.proxy.rpc.enums.SoftButtonType; +import com.smartdevicelink.proxy.rpc.enums.SystemAction; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SoftButton} + */ +public class SoftButtonTest extends TestCase { + + private SoftButton msg; + + @Override + public void setUp() { + msg = new SoftButton(); + + msg.setType(Test.GENERAL_SOFTBUTTONTYPE); + msg.setText(Test.GENERAL_STRING); + msg.setSystemAction(Test.GENERAL_SYSTEMACTION); + msg.setImage(Test.GENERAL_IMAGE); + msg.setIsHighlighted(Test.GENERAL_BOOLEAN); + msg.setSoftButtonID(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + SoftButtonType type = msg.getType(); + String text = msg.getText(); + SystemAction sysAction = msg.getSystemAction(); + Image image = msg.getImage(); + Boolean isHighlighted = msg.getIsHighlighted(); + Integer id = msg.getSoftButtonID(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_SOFTBUTTONTYPE, type); + assertEquals(Test.MATCH, Test.GENERAL_STRING, text); + assertEquals(Test.MATCH, Test.GENERAL_SYSTEMACTION, sysAction); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, image)); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, isHighlighted); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, id); + + // Invalid/Null Tests + SoftButton msg = new SoftButton(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getSoftButtonID()); + assertNull(Test.NULL, msg.getImage()); + assertNull(Test.NULL, msg.getIsHighlighted()); + assertNull(Test.NULL, msg.getSystemAction()); + assertNull(Test.NULL, msg.getText()); + assertNull(Test.NULL, msg.getType()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SoftButton.KEY_SOFT_BUTTON_ID, Test.GENERAL_INT); + reference.put(SoftButton.KEY_TYPE, Test.GENERAL_SOFTBUTTONTYPE); + reference.put(SoftButton.KEY_TEXT, Test.GENERAL_STRING); + reference.put(SoftButton.KEY_IMAGE, Test.JSON_IMAGE); + reference.put(SoftButton.KEY_SYSTEM_ACTION, Test.GENERAL_SYSTEMACTION); + reference.put(SoftButton.KEY_IS_HIGHLIGHTED, Test.GENERAL_BOOLEAN); + + 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(SoftButton.KEY_IMAGE)){ + JSONObject referenceArray = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject underTestArray = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(referenceArray); + Hashtable<String, Object> hashTest= JsonRPCMarshaller.deserializeJSONObject(underTestArray); + assertTrue(Test.TRUE, Validator.validateImage(new Image(hashReference), new Image(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/StartTimeTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/StartTimeTest.java new file mode 100644 index 000000000..7d1c7361b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/StartTimeTest.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.StartTime; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.StartTime} + */ +public class StartTimeTest extends TestCase { + + private StartTime msg; + + @Override + public void setUp() { + msg = new StartTime(); + + msg.setHours(Test.GENERAL_INT); + msg.setMinutes(Test.GENERAL_INT); + msg.setSeconds(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer hours = msg.getHours(); + Integer minutes = msg.getMinutes(); + Integer seconds = msg.getSeconds(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, hours); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, minutes); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, seconds); + + // TimeInterval constructor test + StartTime startTime = new StartTime(7000); + assertEquals(Test.MATCH, (Integer) 1, startTime.getHours()); + assertEquals(Test.MATCH, (Integer) 56, startTime.getMinutes()); + assertEquals(Test.MATCH, (Integer) 40, startTime.getSeconds()); + + // Invalid/Null Tests + StartTime msg = new StartTime(); + assertNotNull(Test.NOT_NULL, msg); + assertNull(Test.NULL, msg.getHours()); + assertNull(Test.NULL, msg.getMinutes()); + assertNull(Test.NULL, msg.getSeconds()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(StartTime.KEY_HOURS, Test.GENERAL_INT); + reference.put(StartTime.KEY_MINUTES, Test.GENERAL_INT); + reference.put(StartTime.KEY_SECONDS, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/StationIDNumberTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/StationIDNumberTests.java new file mode 100644 index 000000000..e7e61f8fd --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/StationIDNumberTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.StationIDNumber; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.StationIDNumber} + */ +public class StationIDNumberTests extends TestCase { + + private StationIDNumber msg; + + @Override + public void setUp() { + msg = new StationIDNumber(); + + msg.setCountryCode(Test.GENERAL_INT); + msg.setFccFacilityId(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + + int countryCode = msg.getCountryCode(); + int fccFacilityId = msg.getFccFacilityId(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, countryCode); + assertEquals(Test.MATCH, Test.GENERAL_INT, fccFacilityId); + + // Invalid/Null Tests + StationIDNumber msg = new StationIDNumber(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getCountryCode()); + assertNull(Test.NULL, msg.getFccFacilityId()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + + reference.put(StationIDNumber.KEY_COUNTRY_CODE, Test.GENERAL_INT); + reference.put(StationIDNumber.KEY_FCC_FACILITY_ID, Test.GENERAL_INT); + + 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 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 new file mode 100644 index 000000000..bc50907db --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/SystemCapabilityTests.java @@ -0,0 +1,124 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import android.util.Log; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.AppServicesCapabilities; +import com.smartdevicelink.proxy.rpc.NavigationCapability; +import com.smartdevicelink.proxy.rpc.PhoneCapability; +import com.smartdevicelink.proxy.rpc.RemoteControlCapabilities; +import com.smartdevicelink.proxy.rpc.SystemCapability; +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.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.SystemCapability} + */ +public class SystemCapabilityTests extends TestCase { + + private SystemCapability msg; + + @Override + public void setUp() { + msg = new SystemCapability(); + + msg.setSystemCapabilityType(Test.GENERAL_SYSTEMCAPABILITYTYPE); + msg.setCapabilityForType(SystemCapabilityType.NAVIGATION, Test.GENERAL_NAVIGATIONCAPABILITY); + 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); + + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + SystemCapabilityType testType = msg.getSystemCapabilityType(); + NavigationCapability testNavigationCapability = (NavigationCapability) msg.getCapabilityForType(SystemCapabilityType.NAVIGATION); + PhoneCapability testPhoneCapability = (PhoneCapability) msg.getCapabilityForType(SystemCapabilityType.PHONE_CALL); + RemoteControlCapabilities testRemoteControlCapabilities = (RemoteControlCapabilities) msg.getCapabilityForType(SystemCapabilityType.REMOTE_CONTROL); + AppServicesCapabilities testAppServicesCapabilities = (AppServicesCapabilities) msg.getCapabilityForType(SystemCapabilityType.APP_SERVICES); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_SYSTEMCAPABILITYTYPE, testType); + assertTrue(Test.TRUE, Validator.validateNavigationCapability(Test.GENERAL_NAVIGATIONCAPABILITY, testNavigationCapability)); + assertTrue(Test.TRUE, Validator.validatePhoneCapability(Test.GENERAL_PHONECAPABILITY, testPhoneCapability)); + assertTrue(Test.TRUE, Validator.validateRemoteControlCapabilities(Test.GENERAL_REMOTECONTROLCAPABILITIES, testRemoteControlCapabilities)); + assertTrue(Test.TRUE, Validator.validateAppServiceCapabilities(Test.GENERAL_APP_SERVICE_CAPABILITIES, testAppServicesCapabilities)); + + // Invalid/Null Tests + SystemCapability msg = new SystemCapability(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getSystemCapabilityType()); + assertNull(Test.NULL, msg.getCapabilityForType(SystemCapabilityType.NAVIGATION)); + assertNull(Test.NULL, msg.getCapabilityForType(SystemCapabilityType.PHONE_CALL)); + assertNull(Test.NULL, msg.getCapabilityForType(SystemCapabilityType.REMOTE_CONTROL)); + assertNull(Test.NULL, msg.getCapabilityForType(SystemCapabilityType.APP_SERVICES)); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(SystemCapability.KEY_SYSTEM_CAPABILITY_TYPE, Test.GENERAL_SYSTEMCAPABILITYTYPE); + reference.put(SystemCapability.KEY_NAVIGATION_CAPABILITY, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_NAVIGATIONCAPABILITY.getStore())); + 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())); + + 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(SystemCapability.KEY_NAVIGATION_CAPABILITY)){ + 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.validateNavigationCapability( new NavigationCapability(hashReference), new NavigationCapability(hashTest))); + } else if(key.equals(SystemCapability.KEY_PHONE_CAPABILITY)){ + 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.validatePhoneCapability( new PhoneCapability(hashReference), new PhoneCapability(hashTest))); + } else if(key.equals(SystemCapability.KEY_REMOTE_CONTROL_CAPABILITY)){ + 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.validateRemoteControlCapabilities( new RemoteControlCapabilities(hashReference), new RemoteControlCapabilities(hashTest))); + }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); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + Log.i("TEST REF", hashReference.toString()); + Log.i("TEST TEST", hashTest.toString()); + assertTrue(Test.TRUE, Validator.validateAppServiceCapabilities( new AppServicesCapabilities(hashReference), new AppServicesCapabilities(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/TTSChunkTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TTSChunkTest.java new file mode 100644 index 000000000..598993771 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TTSChunkTest.java @@ -0,0 +1,66 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +public class TTSChunkTest extends TestCase { + + private TTSChunk msg; + + @Override + public void setUp() { + msg = new TTSChunk(); + + msg.setText(Test.GENERAL_STRING); + msg.setType(Test.GENERAL_SPEECHCAPABILITIES); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String text = msg.getText(); + SpeechCapabilities speechType = msg.getType(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, text); + assertEquals(Test.MATCH, Test.GENERAL_SPEECHCAPABILITIES, speechType); + + // Invalid/Null Tests + TTSChunk msg = new TTSChunk(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getText()); + assertNull(Test.NULL, msg.getType()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(TTSChunk.KEY_TEXT, Test.GENERAL_STRING); + reference.put(TTSChunk.KEY_TYPE, Test.GENERAL_SPEECHCAPABILITIES); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemperatureTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemperatureTests.java new file mode 100644 index 000000000..090f5a235 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemperatureTests.java @@ -0,0 +1,72 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.Temperature; +import com.smartdevicelink.proxy.rpc.enums.TemperatureUnit; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.Temperature} + */ +public class TemperatureTests extends TestCase{ + + private Temperature msg; + + @Override + public void setUp(){ + msg = new Temperature(); + + msg.setUnit(Test.GENERAL_TEMPERATUREUNIT); + msg.setValue(Test.GENERAL_FLOAT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + TemperatureUnit unit = msg.getUnit(); + float value = msg.getValue(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_FLOAT, value); + assertEquals(Test.MATCH, Test.GENERAL_TEMPERATUREUNIT, unit); + + // Invalid/Null Tests + Temperature msg = new Temperature(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getUnit()); + assertNull(Test.NULL, msg.getValue()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(Temperature.KEY_VALUE, (Float) Test.GENERAL_FLOAT); + reference.put(Temperature.KEY_UNIT, Test.GENERAL_TEMPERATUREUNIT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemplateColorSchemeTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemplateColorSchemeTest.java new file mode 100644 index 000000000..0ac90fc86 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TemplateColorSchemeTest.java @@ -0,0 +1,81 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.RGBColor; +import com.smartdevicelink.proxy.rpc.RegisterAppInterface; +import com.smartdevicelink.proxy.rpc.TemplateColorScheme; +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.Iterator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.TemplateColorScheme} + */ +public class TemplateColorSchemeTest extends TestCase { + + private TemplateColorScheme msg; + + @Override + public void setUp() { + msg = new TemplateColorScheme(); + msg.setPrimaryColor(Test.GENERAL_RGBCOLOR); + msg.setSecondaryColor(Test.GENERAL_RGBCOLOR); + msg.setBackgroundColor(Test.GENERAL_RGBCOLOR); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + RGBColor primaryColor = msg.getPrimaryColor(); + RGBColor secondaryColor = msg.getSecondaryColor(); + RGBColor backgroundColor = msg.getBackgroundColor(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateRGBColor(Test.GENERAL_RGBCOLOR, primaryColor)); + assertTrue(Test.TRUE, Validator.validateRGBColor(Test.GENERAL_RGBCOLOR, secondaryColor)); + assertTrue(Test.TRUE, Validator.validateRGBColor(Test.GENERAL_RGBCOLOR, backgroundColor)); + + // Invalid/Null Tests + TemplateColorScheme msg = new TemplateColorScheme(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getPrimaryColor()); + assertNull(Test.NULL, msg.getSecondaryColor()); + assertNull(Test.NULL, msg.getBackgroundColor()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(TemplateColorScheme.KEY_PRIMARY_COLOR, Test.JSON_RGBCOLOR); + reference.put(TemplateColorScheme.KEY_SECONDARY_COLOR, Test.JSON_RGBCOLOR); + reference.put(TemplateColorScheme.KEY_BACKGROUND_COLOR, Test.JSON_RGBCOLOR); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + while (iterator.hasNext()) { + String key = (String) iterator.next(); + JSONObject referenceColorObj = JsonUtils.readJsonObjectFromJsonObject(reference, key); + RGBColor referenceColor = new RGBColor(JsonRPCMarshaller.deserializeJSONObject(referenceColorObj)); + JSONObject underTestColorObj = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + RGBColor underTestColor = new RGBColor(JsonRPCMarshaller.deserializeJSONObject(underTestColorObj)); + assertTrue(Test.TRUE, Validator.validateRGBColor(referenceColor, underTestColor)); + } + } 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/TextFieldTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TextFieldTest.java new file mode 100644 index 000000000..6b5d4d3e2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TextFieldTest.java @@ -0,0 +1,81 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.TextField; +import com.smartdevicelink.proxy.rpc.enums.CharacterSet; +import com.smartdevicelink.proxy.rpc.enums.TextFieldName; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.TextField} + */ +public class TextFieldTest extends TestCase { + + private TextField msg; + + @Override + public void setUp() { + msg = new TextField(); + + msg.setName(Test.GENERAL_TEXTFIELDNAME); + msg.setCharacterSet(Test.GENERAL_CHARACTERSET); + msg.setWidth(Test.GENERAL_INT); + msg.setRows(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + TextFieldName name = msg.getName(); + CharacterSet charSet = msg.getCharacterSet(); + Integer width = msg.getWidth(); + Integer rows = msg.getRows(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_TEXTFIELDNAME, name); + assertEquals(Test.MATCH, Test.GENERAL_CHARACTERSET, charSet); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, width); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, rows); + + // Invalid/Null Tests + TextField msg = new TextField(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getName()); + assertNull(Test.NULL, msg.getWidth()); + assertNull(Test.NULL, msg.getRows()); + assertNull(Test.NULL, msg.getCharacterSet()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(TextField.KEY_CHARACTER_SET, Test.GENERAL_CHARACTERSET); + reference.put(TextField.KEY_WIDTH, Test.GENERAL_INT); + reference.put(TextField.KEY_ROWS, Test.GENERAL_INT); + reference.put(TextField.KEY_NAME, Test.GENERAL_TEXTFIELDNAME); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TireStatusTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TireStatusTest.java new file mode 100644 index 000000000..5552a5c29 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TireStatusTest.java @@ -0,0 +1,108 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.SingleTireStatus; +import com.smartdevicelink.proxy.rpc.TireStatus; +import com.smartdevicelink.proxy.rpc.enums.WarningLightStatus; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.TireStatus} + */ +public class TireStatusTest extends TestCase { + + private TireStatus msg; + + @Override + public void setUp() { + msg = new TireStatus(); + msg.setPressureTellTale(Test.GENERAL_WARNINGLIGHTSTATUS); + SingleTireStatus tireLeftFront = new SingleTireStatus(); + tireLeftFront.setStatus(Test.GENERAL_COMPONENTVOLUMESTATUS); + msg.setLeftFront(tireLeftFront); + SingleTireStatus tireRightFront = new SingleTireStatus(); + tireRightFront.setStatus(Test.GENERAL_COMPONENTVOLUMESTATUS); + msg.setRightFront(tireRightFront); + SingleTireStatus tireLeftRear = new SingleTireStatus(); + tireLeftRear.setStatus(Test.GENERAL_COMPONENTVOLUMESTATUS); + msg.setLeftRear(tireLeftRear); + SingleTireStatus tireRightRear = new SingleTireStatus(); + tireRightRear.setStatus(Test.GENERAL_COMPONENTVOLUMESTATUS); + msg.setRightRear(tireRightRear); + SingleTireStatus tireInnerLeftRear = new SingleTireStatus(); + tireInnerLeftRear.setStatus(Test.GENERAL_COMPONENTVOLUMESTATUS); + msg.setInnerLeftRear(tireInnerLeftRear); + SingleTireStatus tireInnerRightRear = new SingleTireStatus(); + tireInnerRightRear.setStatus(Test.GENERAL_COMPONENTVOLUMESTATUS); + msg.setInnerRightRear(tireInnerRightRear); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + WarningLightStatus pressure = msg.getPressureTellTale(); + SingleTireStatus leftFront = msg.getLeftFront(); + SingleTireStatus rightFront = msg.getRightFront(); + SingleTireStatus leftRear = msg.getLeftRear(); + SingleTireStatus rightRear = msg.getRightRear(); + SingleTireStatus innerLeftRear = msg.getInnerLeftRear(); + SingleTireStatus innerRightRear = msg.getInnerRightRear(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_WARNINGLIGHTSTATUS, pressure); + assertEquals(Test.MATCH, Test.GENERAL_COMPONENTVOLUMESTATUS, leftFront.getStatus()); + assertEquals(Test.MATCH, Test.GENERAL_COMPONENTVOLUMESTATUS, rightFront.getStatus()); + assertEquals(Test.MATCH, Test.GENERAL_COMPONENTVOLUMESTATUS, leftRear.getStatus()); + assertEquals(Test.MATCH, Test.GENERAL_COMPONENTVOLUMESTATUS, rightRear.getStatus()); + assertEquals(Test.MATCH, Test.GENERAL_COMPONENTVOLUMESTATUS, innerLeftRear.getStatus()); + assertEquals(Test.MATCH, Test.GENERAL_COMPONENTVOLUMESTATUS, innerRightRear.getStatus()); + + // Invalid/Null Tests + TireStatus msg = new TireStatus(); + assertNotNull(Test.NOT_NULL, msg); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(TireStatus.KEY_PRESSURE_TELL_TALE, Test.GENERAL_WARNINGLIGHTSTATUS); + JSONObject tireLeftFront = new JSONObject(); + tireLeftFront.put(SingleTireStatus.KEY_STATUS, Test.GENERAL_COMPONENTVOLUMESTATUS); + reference.put(TireStatus.KEY_LEFT_FRONT, tireLeftFront); + JSONObject tireRightFront = new JSONObject(); + tireRightFront.put(SingleTireStatus.KEY_STATUS, Test.GENERAL_COMPONENTVOLUMESTATUS); + reference.put(TireStatus.KEY_RIGHT_FRONT, tireRightFront); + JSONObject tireLeftRear = new JSONObject(); + tireLeftRear.put(SingleTireStatus.KEY_STATUS, Test.GENERAL_COMPONENTVOLUMESTATUS); + reference.put(TireStatus.KEY_LEFT_REAR, tireLeftRear); + JSONObject tireRightRear = new JSONObject(); + tireRightRear.put(SingleTireStatus.KEY_STATUS, Test.GENERAL_COMPONENTVOLUMESTATUS); + reference.put(TireStatus.KEY_RIGHT_REAR, tireRightRear); + JSONObject tireInnerLeftRear = new JSONObject(); + tireInnerLeftRear.put(SingleTireStatus.KEY_STATUS, Test.GENERAL_COMPONENTVOLUMESTATUS); + reference.put(TireStatus.KEY_INNER_LEFT_REAR, tireInnerLeftRear); + JSONObject tireInnerRightRear = new JSONObject(); + tireInnerRightRear.put(SingleTireStatus.KEY_STATUS, Test.GENERAL_COMPONENTVOLUMESTATUS); + reference.put(TireStatus.KEY_INNER_RIGHT_REAR, tireInnerRightRear); + + JSONObject underTest = msg.serializeJSON(); + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + assertTrue(Test.TRUE, Validator.validateTireStatus( + new TireStatus(JsonRPCMarshaller.deserializeJSONObject(reference)), + new TireStatus(JsonRPCMarshaller.deserializeJSONObject(underTest)))); + } 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/TouchCoordTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TouchCoordTest.java new file mode 100644 index 000000000..cfa4a4f33 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TouchCoordTest.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.TouchCoord; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.TouchCoord} + */ +public class TouchCoordTest extends TestCase { + + private TouchCoord msg; + + @Override + public void setUp() { + msg = new TouchCoord(); + + msg.setX(Test.GENERAL_INT); + msg.setY(Test.GENERAL_INT); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer x = msg.getX(); + Integer y = msg.getY(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, x); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, y); + + // Invalid/Null Tests + TouchCoord msg = new TouchCoord(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getX()); + assertNull(Test.NULL, msg.getY()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(TouchCoord.KEY_X, Test.GENERAL_INT); + reference.put(TouchCoord.KEY_Y, Test.GENERAL_INT); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TouchEventCapabilitiesTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TouchEventCapabilitiesTest.java new file mode 100644 index 000000000..b488d4cb7 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TouchEventCapabilitiesTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.TouchEventCapabilities; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.TouchEventCapabilties} + */ +public class TouchEventCapabilitiesTest extends TestCase { + + private TouchEventCapabilities msg; + + @Override + public void setUp() { + msg = new TouchEventCapabilities(); + + msg.setPressAvailable(Test.GENERAL_BOOLEAN); + msg.setDoublePressAvailable(Test.GENERAL_BOOLEAN); + msg.setMultiTouchAvailable(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Boolean press = msg.getPressAvailable(); + Boolean multiTouch = msg.getMultiTouchAvailable(); + Boolean doublePress = msg.getDoublePressAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, press); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, multiTouch); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, doublePress); + + // Invalid/Null Tests + TouchEventCapabilities msg = new TouchEventCapabilities(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getPressAvailable()); + assertNull(Test.NULL, msg.getMultiTouchAvailable()); + assertNull(Test.NULL, msg.getDoublePressAvailable()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(TouchEventCapabilities.KEY_PRESS_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(TouchEventCapabilities.KEY_MULTI_TOUCH_AVAILABLE, Test.GENERAL_BOOLEAN); + reference.put(TouchEventCapabilities.KEY_DOUBLE_PRESS_AVAILABLE, Test.GENERAL_BOOLEAN); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TouchEventTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TouchEventTest.java new file mode 100644 index 000000000..e3207f704 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TouchEventTest.java @@ -0,0 +1,89 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.TouchCoord; +import com.smartdevicelink.proxy.rpc.TouchEvent; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.TouchEvent} + */ +public class TouchEventTest extends TestCase { + + private TouchEvent msg; + + @Override + public void setUp() { + msg = new TouchEvent(); + msg.setId(Test.GENERAL_INT); + msg.setTs(Test.GENERAL_LONG_LIST); + msg.setC(Test.GENERAL_TOUCHCOORD_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer id = msg.getId(); + List<Long> timestamp = msg.getTs(); + List<TouchCoord> coordTest = msg.getC(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, id); + assertTrue(Test.TRUE, Validator.validateLongList(Test.GENERAL_LONG_LIST, timestamp)); + assertEquals(Test.MATCH, Test.GENERAL_TOUCHCOORD_LIST.size(), coordTest.size()); + + for (int index = 0; index < Test.GENERAL_TOUCHCOORD_LIST.size(); index++) { + assertTrue(Test.TRUE, Validator.validateTouchCoord(Test.GENERAL_TOUCHCOORD_LIST.get(index), coordTest.get(index))); + } + + // Invalid/Null Tests + TouchEvent msg = new TouchEvent(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getId()); + assertNull(Test.NULL, msg.getTs()); + assertNull(Test.NULL, msg.getC()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(TouchEvent.KEY_ID, Test.GENERAL_INT); + reference.put(TouchEvent.KEY_TS, JsonUtils.createJsonArray(Test.GENERAL_LONG_LIST)); + reference.put(TouchEvent.KEY_C, Test.JSON_TOUCHCOORDS); + + 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(TouchEvent.KEY_C)) { + assertTrue(Test.TRUE, JsonUtils.readIntegerFromJsonObject(reference, key) == JsonUtils.readIntegerFromJsonObject(underTest, key)); + } else if (key.equals(TouchEvent.KEY_TS)) { + List<Long> tsListReference = JsonUtils.readLongListFromJsonObject(reference, key); + List<Long> tsListTest = JsonUtils.readLongListFromJsonObject(underTest, key); + assertTrue(Test.TRUE, tsListReference.containsAll(tsListTest) && tsListTest.containsAll(tsListReference)); + } 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/TurnTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TurnTests.java new file mode 100644 index 000000000..8986fd4a9 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/TurnTests.java @@ -0,0 +1,56 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.Turn; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +public class TurnTests extends TestCase { + + private Turn msg; + + @Override + public void setUp(){ + msg = new Turn(); + assertNotNull(Test.NOT_NULL, msg); + + msg.setTurnIcon(Test.GENERAL_IMAGE); + msg.setNavigationText(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Image icon = msg.getTurnIcon(); + String text = msg.getNavigationText(); + + // Valid Tests + assertTrue(Test.MATCH, Validator.validateImage(Test.GENERAL_IMAGE, icon)); + assertEquals(Test.MATCH, Test.GENERAL_STRING, text); + + // Invalid/Null Tests + Turn msg = new Turn(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getNavigationText()); + assertNull(Test.NULL, msg.getTurnIcon()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(Turn.KEY_NAVIGATION_TEXT, Test.GENERAL_STRING); + reference.put(Turn.KEY_TURN_IMAGE, Test.JSON_IMAGE); + } 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 new file mode 100644 index 000000000..8d5d1e861 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleDataResultTest.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.VehicleDataResult; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataResultCode; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataType; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +public class VehicleDataResultTest extends TestCase { + + private VehicleDataResult msg; + + @Override + public void setUp() { + msg = new VehicleDataResult(); + + msg.setDataType(Test.GENERAL_VEHICLEDATATYPE); + msg.setResultCode(Test.GENERAL_VEHICLEDATARESULTCODE); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + VehicleDataResultCode result = msg.getResultCode(); + VehicleDataType type = msg.getDataType(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_VEHICLEDATARESULTCODE, result); + assertEquals(Test.MATCH, Test.GENERAL_VEHICLEDATATYPE, type); + + // Invalid/Null Tests + VehicleDataResult msg = new VehicleDataResult(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getDataType()); + assertNull(Test.NULL, msg.getResultCode()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(VehicleDataResult.KEY_RESULT_CODE, Test.GENERAL_VEHICLEDATARESULTCODE); + reference.put(VehicleDataResult.KEY_DATA_TYPE, Test.GENERAL_VEHICLEDATATYPE); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleTypeTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleTypeTest.java new file mode 100644 index 000000000..17f663ae6 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VehicleTypeTest.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.proxy.rpc.VehicleType; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; + +public class VehicleTypeTest extends TestCase { + + private VehicleType msg; + + @Override + public void setUp() { + msg = new VehicleType(); + + msg.setModel(Test.GENERAL_STRING); + msg.setMake(Test.GENERAL_STRING); + msg.setTrim(Test.GENERAL_STRING); + msg.setModelYear(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String year = msg.getModelYear(); + String trim = msg.getTrim(); + String make = msg.getMake(); + String model = msg.getModel(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, year); + assertEquals(Test.MATCH, Test.GENERAL_STRING, model); + assertEquals(Test.MATCH, Test.GENERAL_STRING, make); + assertEquals(Test.MATCH, Test.GENERAL_STRING, trim); + + // Invalid/Null Tests + VehicleType msg = new VehicleType(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getModel()); + assertNull(Test.NULL, msg.getMake()); + assertNull(Test.NULL, msg.getModelYear()); + assertNull(Test.NULL, msg.getTrim()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(VehicleType.KEY_MODEL, Test.GENERAL_STRING); + reference.put(VehicleType.KEY_MAKE, Test.GENERAL_STRING); + reference.put(VehicleType.KEY_MODEL_YEAR, Test.GENERAL_STRING); + reference.put(VehicleType.KEY_TRIM, Test.GENERAL_STRING); + + 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 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 new file mode 100644 index 000000000..54cfc1a22 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VideoStreamingCapabilityTests.java @@ -0,0 +1,96 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.ImageResolution; +import com.smartdevicelink.proxy.rpc.VideoStreamingCapability; +import com.smartdevicelink.proxy.rpc.VideoStreamingFormat; +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 VideoStreamingCapabilityTests extends TestCase { + + private VideoStreamingCapability msg; + + @Override + public void setUp() { + msg = new VideoStreamingCapability(); + msg.setSupportedFormats(Test.GENERAL_VIDEOSTREAMINGFORMAT_LIST); + msg.setPreferredResolution(Test.GENERAL_IMAGERESOLUTION); + msg.setMaxBitrate(Test.GENERAL_INT); + msg.setIsHapticSpatialDataSupported(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<VideoStreamingFormat> format = msg.getSupportedFormats(); + ImageResolution res = msg.getPreferredResolution(); + Integer maxBitrate = msg.getMaxBitrate(); + Boolean isHapticSpatialDataSupported = msg.getIsHapticSpatialDataSupported(); + + // 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); + + // Invalid/Null Tests + VideoStreamingCapability msg = new VideoStreamingCapability(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getMaxBitrate()); + assertNull(Test.NULL, msg.getPreferredResolution()); + assertNull(Test.NULL, msg.getSupportedFormats()); + assertNull(Test.NULL, msg.getIsHapticSpatialDataSupported()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(VideoStreamingCapability.KEY_MAX_BITRATE, Test.GENERAL_INT); + 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); + + 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(VideoStreamingCapability.KEY_MAX_BITRATE) || key.equals(VideoStreamingCapability.KEY_HAPTIC_SPATIAL_DATA_SUPPORTED)) { + assertTrue(Test.TRUE, JsonUtils.readIntegerFromJsonObject(reference, key) == JsonUtils.readIntegerFromJsonObject(underTest, key)); + } else if (key.equals(VideoStreamingCapability.KEY_PREFERRED_RESOLUTION)) { + ImageResolution irReference = (ImageResolution) JsonUtils.readObjectFromJsonObject(reference, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(JsonUtils.readJsonObjectFromJsonObject(underTest, key)); + assertTrue(Validator.validateImageResolution(irReference, new ImageResolution(hashTest))); + } else if (key.equals(VideoStreamingCapability.KEY_SUPPORTED_FORMATS)){ + List<VideoStreamingFormat> vsfReference = (List<VideoStreamingFormat>) JsonUtils.readObjectFromJsonObject(reference, key); + JSONArray vsfArray = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + int i = 0; + for(VideoStreamingFormat vsf : vsfReference){ + assertTrue(Validator.validateSupportedFormats(vsf, new VideoStreamingFormat(JsonRPCMarshaller.deserializeJSONObject(vsfArray.getJSONObject(i++))))); + } + } + } + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VideoStreamingFormatTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VideoStreamingFormatTests.java new file mode 100644 index 000000000..ff7cb2719 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VideoStreamingFormatTests.java @@ -0,0 +1,70 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.ImageResolution; +import com.smartdevicelink.proxy.rpc.VideoStreamingCapability; +import com.smartdevicelink.proxy.rpc.VideoStreamingFormat; +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec; +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol; +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 VideoStreamingFormatTests extends TestCase { + + private VideoStreamingFormat msg; + + @Override + public void setUp() { + msg = new VideoStreamingFormat(); + msg.setProtocol(Test.GENERAL_VIDEOSTREAMINGPROTOCOL); + msg.setCodec(Test.GENERAL_VIDEOSTREAMINGCODEC); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + VideoStreamingProtocol protocol = msg.getProtocol(); + VideoStreamingCodec codec = msg.getCodec(); + + // Valid Tests + assertEquals(Test.MATCH, (VideoStreamingProtocol) Test.GENERAL_VIDEOSTREAMINGPROTOCOL, protocol); + assertEquals(Test.MATCH, (VideoStreamingCodec) Test.GENERAL_VIDEOSTREAMINGCODEC, codec); + + // Invalid/Null Tests + VideoStreamingFormat msg = new VideoStreamingFormat(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getProtocol()); + assertNull(Test.NULL, msg.getCodec()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(VideoStreamingFormat.KEY_PROTOCOL, Test.GENERAL_VIDEOSTREAMINGPROTOCOL); + reference.put(VideoStreamingFormat.KEY_CODEC, Test.GENERAL_VIDEOSTREAMINGCODEC); + + 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); + } + } +} + diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VrHelpItemTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VrHelpItemTest.java new file mode 100644 index 000000000..55f00dd1c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/VrHelpItemTest.java @@ -0,0 +1,85 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import java.util.Hashtable; +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.VrHelpItem; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +public class VrHelpItemTest extends TestCase { + + private VrHelpItem msg; + + @Override + public void setUp() { + msg = new VrHelpItem(); + + msg.setText(Test.GENERAL_STRING); + msg.setImage(Test.GENERAL_IMAGE); + msg.setPosition(Test.GENERAL_INT); + + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String text = msg.getText(); + Image image = msg.getImage(); + Integer position = msg.getPosition(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, text); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, position); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, image)); + + // Invalid/Null Tests + VrHelpItem msg = new VrHelpItem(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getImage()); + assertNull(Test.NULL, msg.getText()); + assertNull(Test.NULL, msg.getPosition()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + try { + reference.put(VrHelpItem.KEY_IMAGE, Test.JSON_IMAGE); + reference.put(VrHelpItem.KEY_TEXT, Test.GENERAL_STRING); + reference.put(VrHelpItem.KEY_POSITION, Test.GENERAL_INT); + + 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(VrHelpItem.KEY_IMAGE)){ + JSONObject objectEquals = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject testEquals = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashReference = JsonRPCMarshaller.deserializeJSONObject(objectEquals); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + + assertTrue(Test.TRUE, Validator.validateImage(new Image(hashReference), new Image(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/WeatherAlertTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherAlertTests.java new file mode 100644 index 000000000..4a8ade572 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherAlertTests.java @@ -0,0 +1,112 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.DateTime; +import com.smartdevicelink.proxy.rpc.WeatherAlert; +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.WeatherAlert} + */ +public class WeatherAlertTests extends TestCase { + + private WeatherAlert msg; + + @Override + public void setUp(){ + + msg = new WeatherAlert(); + msg.setExpires(Test.GENERAL_DATETIME); + msg.setTimeIssued(Test.GENERAL_DATETIME); + msg.setRegions(Test.GENERAL_STRING_LIST); + msg.setSeverity(Test.GENERAL_STRING); + msg.setSummary(Test.GENERAL_STRING); + msg.setTitle(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + DateTime expires = msg.getExpires(); + DateTime issued = msg.getTimeIssued(); + List<String> regions = msg.getRegions(); + String severity = msg.getSeverity(); + String summary = msg.getSummary(); + String title = msg.getTitle(); + + // Valid Tests + assertEquals(Test.MATCH, expires, Test.GENERAL_DATETIME); + assertEquals(Test.MATCH, issued, Test.GENERAL_DATETIME); + assertEquals(Test.MATCH, regions, Test.GENERAL_STRING_LIST); + assertEquals(Test.MATCH, severity, Test.GENERAL_STRING); + assertEquals(Test.MATCH, summary, Test.GENERAL_STRING); + assertEquals(Test.MATCH, title, Test.GENERAL_STRING); + + // Invalid/Null Tests + WeatherAlert msg = new WeatherAlert(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getExpires()); + assertNull(Test.NULL, msg.getTimeIssued()); + assertNull(Test.NULL, msg.getRegions()); + assertNull(Test.NULL, msg.getSeverity()); + assertNull(Test.NULL, msg.getSummary()); + assertNull(Test.NULL, msg.getTitle()); + } + + public void testRequiredParamsConstructor(){ + msg = new WeatherAlert(Test.GENERAL_STRING_LIST); + List<String> regions = msg.getRegions(); + assertEquals(Test.MATCH, regions, Test.GENERAL_STRING_LIST); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(WeatherAlert.KEY_EXPIRES, Test.GENERAL_DATETIME); + reference.put(WeatherAlert.KEY_TIME_ISSUED, Test.GENERAL_DATETIME); + reference.put(WeatherAlert.KEY_REGIONS, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + reference.put(WeatherAlert.KEY_SEVERITY, Test.GENERAL_STRING); + reference.put(WeatherAlert.KEY_SUMMARY, Test.GENERAL_STRING); + reference.put(WeatherAlert.KEY_TITLE, Test.GENERAL_STRING); + + 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(WeatherAlert.KEY_EXPIRES)||key.equals(WeatherAlert.KEY_TIME_ISSUED)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateDateTime(Test.GENERAL_DATETIME, new DateTime(hashTest))); + } else if (key.equals(WeatherAlert.KEY_REGIONS)){ + 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 { + 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/WeatherDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherDataTests.java new file mode 100644 index 000000000..70454f5c3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherDataTests.java @@ -0,0 +1,184 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.DateTime; +import com.smartdevicelink.proxy.rpc.Temperature; +import com.smartdevicelink.proxy.rpc.WeatherData; +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.WeatherData} + */ +public class WeatherDataTests extends TestCase { + + private WeatherData msg; + + @Override + public void setUp(){ + + msg = new WeatherData(); + msg.setCurrentTemperature(Test.GENERAL_TEMPERATURE); + msg.setTemperatureHigh(Test.GENERAL_TEMPERATURE); + msg.setTemperatureLow(Test.GENERAL_TEMPERATURE); + msg.setApparentTemperature(Test.GENERAL_TEMPERATURE); + msg.setApparentTemperatureHigh(Test.GENERAL_TEMPERATURE); + msg.setApparentTemperatureLow(Test.GENERAL_TEMPERATURE); + msg.setWeatherSummary(Test.GENERAL_STRING); + msg.setTime(Test.GENERAL_DATETIME); + msg.setHumidity(Test.GENERAL_FLOAT); + msg.setCloudCover(Test.GENERAL_FLOAT); + msg.setMoonPhase(Test.GENERAL_FLOAT); + msg.setWindBearing(Test.GENERAL_INTEGER); + msg.setWindGust(Test.GENERAL_FLOAT); + msg.setWindSpeed(Test.GENERAL_FLOAT); + msg.setNearestStormBearing(Test.GENERAL_INTEGER); + msg.setNearestStormDistance(Test.GENERAL_INTEGER); + msg.setPrecipAccumulation(Test.GENERAL_FLOAT); + msg.setPrecipIntensity(Test.GENERAL_FLOAT); + msg.setPrecipProbability(Test.GENERAL_FLOAT); + msg.setPrecipType(Test.GENERAL_STRING); + msg.setVisibility(Test.GENERAL_FLOAT); + msg.setWeatherIconImageName(Test.GENERAL_STRING); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Temperature currentTemperature = msg.getCurrentTemperature(); + Temperature temperatureHigh = msg.getTemperatureHigh(); + Temperature temperatureLow = msg.getTemperatureLow(); + Temperature apparentTemperature = msg.getApparentTemperature(); + Temperature apparentTemperatureHigh = msg.getApparentTemperatureHigh(); + String weatherSummary = msg.getWeatherSummary(); + DateTime time = msg.getTime(); + Float humidity = msg.getHumidity(); + Float cloudCover = msg.getCloudCover(); + Float moonPhase = msg.getMoonPhase(); + Integer windBearing = msg.getWindBearing(); + Float windGust = msg.getWindGust(); + Float windSpeed = msg.getWindSpeed(); + Integer nearestStormBearing = msg.getNearestStormBearing(); + Integer nearestStormDistance = msg.getNearestStormDistance(); + Float precipAccumulation = msg.getPrecipAccumulation(); + Float precipIntensity = msg.getPrecipIntensity(); + Float precipProbability = msg.getPrecipProbability(); + String precipType = msg.getPrecipType(); + Float visibility = msg.getVisibility(); + String weatherIconImageName = msg.getWeatherIconImageName(); + + // Valid Tests + assertEquals(Test.MATCH, currentTemperature, Test.GENERAL_TEMPERATURE); + assertEquals(Test.MATCH, temperatureHigh, Test.GENERAL_TEMPERATURE); + assertEquals(Test.MATCH, temperatureLow, Test.GENERAL_TEMPERATURE); + assertEquals(Test.MATCH, apparentTemperature, Test.GENERAL_TEMPERATURE); + assertEquals(Test.MATCH, apparentTemperatureHigh, Test.GENERAL_TEMPERATURE); + assertEquals(Test.MATCH, weatherSummary, Test.GENERAL_STRING); + assertEquals(Test.MATCH, time, Test.GENERAL_DATETIME); + assertEquals(Test.MATCH, humidity, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, cloudCover, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, moonPhase, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, windBearing, Test.GENERAL_INTEGER); + assertEquals(Test.MATCH, windGust, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, windSpeed, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, nearestStormBearing, Test.GENERAL_INTEGER); + assertEquals(Test.MATCH, nearestStormDistance, Test.GENERAL_INTEGER); + assertEquals(Test.MATCH, precipAccumulation, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, precipIntensity, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, precipProbability, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, precipType, Test.GENERAL_STRING); + assertEquals(Test.MATCH, visibility, Test.GENERAL_FLOAT); + assertEquals(Test.MATCH, weatherIconImageName, Test.GENERAL_STRING); + + // Invalid/Null Tests + WeatherData msg = new WeatherData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getCurrentTemperature()); + assertNull(Test.NULL, msg.getTemperatureHigh()); + assertNull(Test.NULL, msg.getTemperatureLow()); + assertNull(Test.NULL, msg.getApparentTemperature()); + assertNull(Test.NULL, msg.getApparentTemperatureHigh()); + assertNull(Test.NULL, msg.getApparentTemperatureLow()); + assertNull(Test.NULL, msg.getWeatherSummary()); + assertNull(Test.NULL, msg.getTime()); + assertNull(Test.NULL, msg.getHumidity()); + assertNull(Test.NULL, msg.getCloudCover()); + assertNull(Test.NULL, msg.getMoonPhase()); + assertNull(Test.NULL, msg.getWindBearing()); + assertNull(Test.NULL, msg.getWindGust()); + assertNull(Test.NULL, msg.getWindSpeed()); + assertNull(Test.NULL, msg.getNearestStormBearing()); + assertNull(Test.NULL, msg.getNearestStormDistance()); + assertNull(Test.NULL, msg.getPrecipAccumulation()); + assertNull(Test.NULL, msg.getPrecipIntensity()); + assertNull(Test.NULL, msg.getPrecipProbability()); + assertNull(Test.NULL, msg.getPrecipType()); + assertNull(Test.NULL, msg.getVisibility()); + assertNull(Test.NULL, msg.getWeatherIconImageName()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(WeatherData.KEY_CURRENT_TEMPERATURE, Test.GENERAL_TEMPERATURE); + reference.put(WeatherData.KEY_TEMPERATURE_HIGH, Test.GENERAL_TEMPERATURE); + reference.put(WeatherData.KEY_TEMPERATURE_LOW, Test.GENERAL_TEMPERATURE); + reference.put(WeatherData.KEY_APPARENT_TEMPERATURE, Test.GENERAL_TEMPERATURE); + reference.put(WeatherData.KEY_APPARENT_TEMPERATURE_HIGH, Test.GENERAL_TEMPERATURE); + reference.put(WeatherData.KEY_APPARENT_TEMPERATURE_LOW, Test.GENERAL_TEMPERATURE); + reference.put(WeatherData.KEY_WEATHER_SUMMARY, Test.GENERAL_STRING); + reference.put(WeatherData.KEY_TIME, Test.GENERAL_DATETIME); + reference.put(WeatherData.KEY_HUMIDITY, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_CLOUD_COVER, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_MOON_PHASE, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_WIND_BEARING, Test.GENERAL_INTEGER); + reference.put(WeatherData.KEY_WIND_GUST, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_WIND_SPEED, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_NEAREST_STORM_BEARING, Test.GENERAL_INTEGER); + reference.put(WeatherData.KEY_NEAREST_STORM_DISTANCE, Test.GENERAL_INTEGER); + reference.put(WeatherData.KEY_PRECIP_ACCUMULATION, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_PRECIP_INTENSITY, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_PRECIP_PROBABILITY, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_PRECIP_TYPE, Test.GENERAL_STRING); + reference.put(WeatherData.KEY_VISIBILITY, Test.GENERAL_FLOAT); + reference.put(WeatherData.KEY_WEATHER_ICON_IMAGE_NAME, Test.GENERAL_STRING); + + 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(WeatherData.KEY_CURRENT_TEMPERATURE) || key.equals(WeatherData.KEY_TEMPERATURE_HIGH)|| + key.equals(WeatherData.KEY_TEMPERATURE_LOW) || key.equals(WeatherData.KEY_APPARENT_TEMPERATURE)|| + key.equals(WeatherData.KEY_APPARENT_TEMPERATURE_HIGH) || key.equals(WeatherData.KEY_APPARENT_TEMPERATURE_LOW)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateTemperature(Test.GENERAL_TEMPERATURE, new Temperature(hashTest))); + } else if (key.equals(WeatherData.KEY_TIME)){ + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateDateTime(Test.GENERAL_DATETIME, new DateTime(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/WeatherServiceDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherServiceDataTests.java new file mode 100644 index 000000000..09c976538 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherServiceDataTests.java @@ -0,0 +1,142 @@ +package com.smartdevicelink.test.rpc.datatypes; + + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.proxy.rpc.LocationDetails; +import com.smartdevicelink.proxy.rpc.WeatherAlert; +import com.smartdevicelink.proxy.rpc.WeatherData; +import com.smartdevicelink.proxy.rpc.WeatherServiceData; +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.WeatherServiceData} + */ +public class WeatherServiceDataTests extends TestCase { + + private WeatherServiceData msg; + + @Override + public void setUp(){ + + msg = new WeatherServiceData(); + msg.setLocation(Test.GENERAL_LOCATIONDETAILS); + msg.setCurrentForecast(Test.GENERAL_WEATHERDATA); + msg.setMinuteForecast(Test.GENERAL_WEATHERDATA_LIST); + msg.setHourlyForecast(Test.GENERAL_WEATHERDATA_LIST); + msg.setMultidayForecast(Test.GENERAL_WEATHERDATA_LIST); + msg.setAlerts(Test.GENERAL_WEATHERALERT_LIST); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + LocationDetails location = msg.getLocation(); + WeatherData currentForecast = msg.getCurrentForecast(); + List<WeatherData> minuteForecast = msg.getMinuteForecast(); + List<WeatherData> hourlyForecast = msg.getHourlyForecast(); + List<WeatherData> multidayForecast = msg.getMultidayForecast(); + List<WeatherAlert> alerts = msg.getAlerts(); + + // Valid Tests + assertEquals(Test.GENERAL_LOCATIONDETAILS, location); + assertEquals(Test.GENERAL_WEATHERDATA, currentForecast); + assertEquals(Test.GENERAL_WEATHERDATA_LIST, minuteForecast); + assertEquals(Test.GENERAL_WEATHERDATA_LIST, hourlyForecast); + assertEquals(Test.GENERAL_WEATHERDATA_LIST, multidayForecast); + assertEquals(Test.GENERAL_WEATHERALERT_LIST, alerts); + + // Invalid/Null Tests + WeatherServiceData msg = new WeatherServiceData(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getLocation()); + assertNull(Test.NULL, msg.getCurrentForecast()); + assertNull(Test.NULL, msg.getMinuteForecast()); + assertNull(Test.NULL, msg.getHourlyForecast()); + assertNull(Test.NULL, msg.getMultidayForecast()); + assertNull(Test.NULL, msg.getAlerts()); + } + + public void testRequiredParamsConstructor(){ + msg = new WeatherServiceData(Test.GENERAL_LOCATIONDETAILS); + LocationDetails location = msg.getLocation(); + assertEquals(Test.GENERAL_LOCATIONDETAILS, location); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(WeatherServiceData.KEY_LOCATION, Test.GENERAL_LOCATIONDETAILS); + reference.put(WeatherServiceData.KEY_CURRENT_FORECAST, Test.GENERAL_WEATHERDATA); + reference.put(WeatherServiceData.KEY_MINUTE_FORECAST, Test.GENERAL_WEATHERDATA_LIST); + reference.put(WeatherServiceData.KEY_HOURLY_FORECAST, Test.GENERAL_WEATHERDATA_LIST); + reference.put(WeatherServiceData.KEY_MULTIDAY_FORECAST, Test.GENERAL_WEATHERDATA_LIST); + reference.put(WeatherServiceData.KEY_ALERTS, Test.GENERAL_WEATHERALERT_LIST); + + 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(WeatherServiceData.KEY_LOCATION)){ + + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateLocationDetails( Test.GENERAL_LOCATIONDETAILS, new LocationDetails(hashTest))); + + } else if(key.equals(WeatherServiceData.KEY_CURRENT_FORECAST)){ + + JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key); + Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals); + assertTrue(Test.TRUE, Validator.validateWeatherData( Test.GENERAL_WEATHERDATA, new WeatherData(hashTest))); + + } else if(key.equals(WeatherServiceData.KEY_MINUTE_FORECAST) || key.equals(WeatherServiceData.KEY_HOURLY_FORECAST) + || key.equals(WeatherServiceData.KEY_MULTIDAY_FORECAST)){ + + JSONArray weatherDataArrayObjTest = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + List<WeatherData> weatherDataUnderTestList = new ArrayList<>(); + for (int index = 0; index < weatherDataArrayObjTest.length(); index++) { + WeatherData weatherData1 = new WeatherData(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)weatherDataArrayObjTest.get(index) )); + weatherDataUnderTestList.add(weatherData1); + } + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateWeatherDataList(Test.GENERAL_WEATHERDATA_LIST, weatherDataUnderTestList)); + + } else if(key.equals(WeatherServiceData.KEY_ALERTS)){ + + JSONArray weatherAlertArrayObjTest = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + List<WeatherAlert> weatherAlertUnderTestList = new ArrayList<>(); + for (int index = 0; index < weatherAlertArrayObjTest.length(); index++) { + WeatherAlert weatherAlert1 = new WeatherAlert(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)weatherAlertArrayObjTest.get(index) )); + weatherAlertUnderTestList.add(weatherAlert1); + } + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateWeatherAlertList(Test.GENERAL_WEATHERALERT_LIST, weatherAlertUnderTestList)); + } + } + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherServiceManifestTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherServiceManifestTests.java new file mode 100644 index 000000000..cbd65fae7 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/WeatherServiceManifestTests.java @@ -0,0 +1,84 @@ +package com.smartdevicelink.test.rpc.datatypes; + +import com.smartdevicelink.proxy.rpc.WeatherServiceManifest; +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; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.WeatherServiceManifest} + */ +public class WeatherServiceManifestTests extends TestCase { + + private WeatherServiceManifest msg; + + @Override + public void setUp(){ + msg = new WeatherServiceManifest(); + + msg.setCurrentForecastSupported(Test.GENERAL_BOOLEAN); + msg.setMaxHourlyForecastAmount(Test.GENERAL_INT); + msg.setMaxMinutelyForecastAmount(Test.GENERAL_INT); + msg.setMaxMultidayForecastAmount(Test.GENERAL_INT); + msg.setWeatherForLocationSupported(Test.GENERAL_BOOLEAN); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean currentForecastSupported = msg.getCurrentForecastSupported(); + boolean weatherForLocationSupported = msg.getWeatherForLocationSupported(); + Integer getMaxHourlyForecastAmt = msg.getMaxHourlyForecastAmount(); + Integer getMaxMinutelyForecastAmt = msg.getMaxMinutelyForecastAmount(); + Integer getMaxMultidayForecastAmt = msg.getMaxMultidayForecastAmount(); + + // Valid Tests + assertEquals(Test.GENERAL_BOOLEAN, currentForecastSupported); + assertEquals(Test.GENERAL_BOOLEAN, weatherForLocationSupported); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, getMaxHourlyForecastAmt); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, getMaxMinutelyForecastAmt); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, getMaxMultidayForecastAmt); + + // Invalid/Null Tests + WeatherServiceManifest msg = new WeatherServiceManifest(); + assertNotNull(Test.NOT_NULL, msg); + + assertNull(Test.NULL, msg.getCurrentForecastSupported()); + assertNull(Test.NULL, msg.getWeatherForLocationSupported()); + assertNull(Test.NULL, msg.getMaxHourlyForecastAmount()); + assertNull(Test.NULL, msg.getMaxMinutelyForecastAmount()); + assertNull(Test.NULL, msg.getMaxMultidayForecastAmount()); + } + + public void testJson(){ + JSONObject reference = new JSONObject(); + + try{ + reference.put(WeatherServiceManifest.KEY_CURRENT_FORECAST_SUPPORTED, Test.GENERAL_BOOLEAN); + reference.put(WeatherServiceManifest.KEY_WEATHER_FOR_LOCATION_SUPPORTED, Test.GENERAL_BOOLEAN); + reference.put(WeatherServiceManifest.KEY_MAX_HOURLY_FORECAST_AMOUNT, Test.GENERAL_INTEGER); + reference.put(WeatherServiceManifest.KEY_MAX_MINUTELY_FORECAST_AMOUNT, Test.GENERAL_INTEGER); + reference.put(WeatherServiceManifest.KEY_MAX_MULTIDAY_FORECAST_AMOUNT, Test.GENERAL_INTEGER); + + 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 diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AmbientLightStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AmbientLightStatusTests.java new file mode 100644 index 000000000..859eafba0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AmbientLightStatusTests.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.AmbientLightStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.AmbientLightStatus} + */ +public class AmbientLightStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + + String example = "DAY"; + AmbientLightStatus enumDay = AmbientLightStatus.valueForString(example); + example = "NIGHT"; + AmbientLightStatus enumNight = AmbientLightStatus.valueForString(example); + example = "UNKNOWN"; + AmbientLightStatus enumUnknown = AmbientLightStatus.valueForString(example); + example = "INVALID"; + AmbientLightStatus enumInvalid = AmbientLightStatus.valueForString(example); + example = "TWILIGHT_1"; + AmbientLightStatus enumTwilight1 = AmbientLightStatus.valueForString(example); + example = "TWILIGHT_2"; + AmbientLightStatus enumTwilight2 = AmbientLightStatus.valueForString(example); + example = "TWILIGHT_3"; + AmbientLightStatus enumTwilight3 = AmbientLightStatus.valueForString(example); + example = "TWILIGHT_4"; + AmbientLightStatus enumTwilight4 = AmbientLightStatus.valueForString(example); + + assertNotNull("DAY returned null", enumDay); + assertNotNull("NIGHT returned null", enumNight); + assertNotNull("UNKNOWN returned null", enumUnknown); + assertNotNull("INVALID returned null", enumInvalid); + assertNotNull("TWILIGHT_1 returned null", enumTwilight1); + assertNotNull("TWILIGHT_2 returned null", enumTwilight2); + assertNotNull("TWILIGHT_3 returned null", enumTwilight3); + assertNotNull("TWILIGHT_4 returned null", enumTwilight4); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "niGHt"; + try { + AmbientLightStatus temp = AmbientLightStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + AmbientLightStatus temp = AmbientLightStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of AmbientLightStatus. + */ + public void testListEnum() { + List<AmbientLightStatus> enumValueList = Arrays.asList(AmbientLightStatus.values()); + List<AmbientLightStatus> enumTestList = new ArrayList<AmbientLightStatus>(); + + enumTestList.add(AmbientLightStatus.DAY); + enumTestList.add(AmbientLightStatus.NIGHT); + enumTestList.add(AmbientLightStatus.UNKNOWN); + enumTestList.add(AmbientLightStatus.INVALID); + enumTestList.add(AmbientLightStatus.TWILIGHT_1); + enumTestList.add(AmbientLightStatus.TWILIGHT_2); + enumTestList.add(AmbientLightStatus.TWILIGHT_3); + enumTestList.add(AmbientLightStatus.TWILIGHT_4); + + assertTrue("Enum value list does not match enum class list.", + enumValueList.containsAll(enumTestList) && + enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppHmiTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppHmiTypeTests.java new file mode 100644 index 000000000..6446cb914 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppHmiTypeTests.java @@ -0,0 +1,111 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.AppHMIType; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.AppHMIType} + */ +public class AppHmiTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "DEFAULT"; + AppHMIType enumDefault = AppHMIType.valueForString(example); + example = "COMMUNICATION"; + AppHMIType enumCommunication = AppHMIType.valueForString(example); + example = "MEDIA"; + AppHMIType enumMedia = AppHMIType.valueForString(example); + example = "MESSAGING"; + AppHMIType enumMessaging = AppHMIType.valueForString(example); + example = "NAVIGATION"; + AppHMIType enumNavigation = AppHMIType.valueForString(example); + example = "INFORMATION"; + AppHMIType enumInformation = AppHMIType.valueForString(example); + example = "SOCIAL"; + AppHMIType enumSocial = AppHMIType.valueForString(example); + example = "BACKGROUND_PROCESS"; + AppHMIType enumBackgroundProcess = AppHMIType.valueForString(example); + example = "PROJECTION"; + AppHMIType enumProjection = AppHMIType.valueForString(example); + example = "TESTING"; + AppHMIType enumTesting = AppHMIType.valueForString(example); + example = "SYSTEM"; + AppHMIType enumSystem = AppHMIType.valueForString(example); + example = "REMOTE_CONTROL"; + AppHMIType enumRemoteControl = AppHMIType.valueForString(example); + + assertNotNull("DEFAULT returned null", enumDefault); + assertNotNull("COMMUNICATION returned null", enumCommunication); + assertNotNull("MEDIA returned null", enumMedia); + assertNotNull("MESSAGING returned null", enumMessaging); + assertNotNull("NAVIGATION returned null", enumNavigation); + assertNotNull("INFORMATION returned null", enumInformation); + assertNotNull("SOCIAL returned null", enumSocial); + assertNotNull("BACKGROUND_PROCESS returned null", enumBackgroundProcess); + assertNotNull("PROJECTION returned null", enumProjection); + assertNotNull("TESTING returned null", enumTesting); + assertNotNull("SYSTEM returned null", enumSystem); + assertNotNull("REMOTE_CONTROL returned null", enumRemoteControl); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "deFaUlt"; + try { + AppHMIType temp = AppHMIType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + AppHMIType temp = AppHMIType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of AmbientLightStatus. + */ + public void testListEnum() { + List<AppHMIType> enumValueList = Arrays.asList(AppHMIType.values()); + + List<AppHMIType> enumTestList = new ArrayList<AppHMIType>(); + enumTestList.add(AppHMIType.DEFAULT); + enumTestList.add(AppHMIType.COMMUNICATION); + enumTestList.add(AppHMIType.MEDIA); + enumTestList.add(AppHMIType.MESSAGING); + enumTestList.add(AppHMIType.NAVIGATION); + enumTestList.add(AppHMIType.INFORMATION); + enumTestList.add(AppHMIType.SOCIAL); + enumTestList.add(AppHMIType.BACKGROUND_PROCESS); + enumTestList.add(AppHMIType.PROJECTION); + enumTestList.add(AppHMIType.TESTING); + enumTestList.add(AppHMIType.SYSTEM); + enumTestList.add(AppHMIType.REMOTE_CONTROL); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppInterfaceUnregisteredReasonTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppInterfaceUnregisteredReasonTests.java new file mode 100644 index 000000000..8896d13e7 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppInterfaceUnregisteredReasonTests.java @@ -0,0 +1,111 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.AppInterfaceUnregisteredReason; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.AppInterfaceUregisteredReason} + */ +public class AppInterfaceUnregisteredReasonTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "USER_EXIT"; + AppInterfaceUnregisteredReason enumUserExit = AppInterfaceUnregisteredReason.valueForString(example); + example = "IGNITION_OFF"; + AppInterfaceUnregisteredReason enumIgnitionOff = AppInterfaceUnregisteredReason.valueForString(example); + example = "BLUETOOTH_OFF"; + AppInterfaceUnregisteredReason enumBluetoothOff = AppInterfaceUnregisteredReason.valueForString(example); + example = "USB_DISCONNECTED"; + AppInterfaceUnregisteredReason enumUsbDisconnected = AppInterfaceUnregisteredReason.valueForString(example); + example = "REQUEST_WHILE_IN_NONE_HMI_LEVEL"; + AppInterfaceUnregisteredReason enumRequestWhileInNoneHmiLevel = AppInterfaceUnregisteredReason.valueForString(example); + example = "TOO_MANY_REQUESTS"; + AppInterfaceUnregisteredReason enumTooManyRequests = AppInterfaceUnregisteredReason.valueForString(example); + example = "DRIVER_DISTRACTION_VIOLATION"; + AppInterfaceUnregisteredReason enumDriverDistractionViolation = AppInterfaceUnregisteredReason.valueForString(example); + example = "LANGUAGE_CHANGE"; + AppInterfaceUnregisteredReason enumLanguageChange = AppInterfaceUnregisteredReason.valueForString(example); + example = "MASTER_RESET"; + AppInterfaceUnregisteredReason enumMasterReset = AppInterfaceUnregisteredReason.valueForString(example); + example = "FACTORY_DEFAULTS"; + AppInterfaceUnregisteredReason enumFactoryDefaults = AppInterfaceUnregisteredReason.valueForString(example); + example = "APP_UNAUTHORIZED"; + AppInterfaceUnregisteredReason enumAppAuthorized = AppInterfaceUnregisteredReason.valueForString(example); + example = "PROTOCOL_VIOLATION"; + AppInterfaceUnregisteredReason enumProtocolViolation = AppInterfaceUnregisteredReason.valueForString(example); + + assertNotNull("USER_EXIT returned null", enumUserExit); + assertNotNull("IGNITION_OFF returned null", enumIgnitionOff); + assertNotNull("BLUETOOTH_OFF returned null", enumBluetoothOff); + assertNotNull("USB_DISCONNECTED returned null", enumUsbDisconnected); + assertNotNull("REQUEST_WHILE_IN_NONE_HMI_LEVEL returned null", enumRequestWhileInNoneHmiLevel); + assertNotNull("TOO_MANY_REQUESTS returned null", enumTooManyRequests); + assertNotNull("DRIVER_DISTRACTION_VIOLATION returned null", enumDriverDistractionViolation); + assertNotNull("LANGUAGE_CHANGE returned null", enumLanguageChange); + assertNotNull("MASTER_RESET returned null", enumMasterReset); + assertNotNull("FACTORY_DEFAULTS returned null", enumFactoryDefaults); + assertNotNull("APP_UNAUTHORIZED returned null", enumAppAuthorized); + assertNotNull("PROTOCOL_VIOLATION returned null", enumProtocolViolation); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "uSer_ExiT"; + try { + AppInterfaceUnregisteredReason temp = AppInterfaceUnregisteredReason.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + AppInterfaceUnregisteredReason temp = AppInterfaceUnregisteredReason.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of AppInterfaceUnregisteredReason. + */ + public void testListEnum() { + List<AppInterfaceUnregisteredReason> enumValueList = Arrays.asList(AppInterfaceUnregisteredReason.values()); + + List<AppInterfaceUnregisteredReason> enumTestList = new ArrayList<AppInterfaceUnregisteredReason>(); + enumTestList.add(AppInterfaceUnregisteredReason.USER_EXIT); + enumTestList.add(AppInterfaceUnregisteredReason.IGNITION_OFF); + enumTestList.add(AppInterfaceUnregisteredReason.BLUETOOTH_OFF); + enumTestList.add(AppInterfaceUnregisteredReason.USB_DISCONNECTED); + enumTestList.add(AppInterfaceUnregisteredReason.REQUEST_WHILE_IN_NONE_HMI_LEVEL); + enumTestList.add(AppInterfaceUnregisteredReason.TOO_MANY_REQUESTS); + enumTestList.add(AppInterfaceUnregisteredReason.DRIVER_DISTRACTION_VIOLATION); + enumTestList.add(AppInterfaceUnregisteredReason.LANGUAGE_CHANGE); + enumTestList.add(AppInterfaceUnregisteredReason.MASTER_RESET); + enumTestList.add(AppInterfaceUnregisteredReason.FACTORY_DEFAULTS); + enumTestList.add(AppInterfaceUnregisteredReason.APP_UNAUTHORIZED); + enumTestList.add(AppInterfaceUnregisteredReason.PROTOCOL_VIOLATION); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppServiceTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppServiceTypeTests.java new file mode 100644 index 000000000..ce4867e41 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AppServiceTypeTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.AppServiceType; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.AppServiceType} + */ +public class AppServiceTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "MEDIA"; + AppServiceType enumMedia = AppServiceType.valueForString(example); + example = "WEATHER"; + AppServiceType enumWeather = AppServiceType.valueForString(example); + example = "NAVIGATION"; + AppServiceType enumNavigation = AppServiceType.valueForString(example); + + assertNotNull("MEDIA returned null", enumMedia); + assertNotNull("WEATHER returned null", enumWeather); + assertNotNull("NAVIGATION returned null", enumNavigation); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "MedIas"; + try { + AppServiceType temp = AppServiceType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + AppServiceType temp = AppServiceType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of AppServiceType. + */ + public void testListEnum() { + List<AppServiceType> enumValueList = Arrays.asList(AppServiceType.values()); + + List<AppServiceType> enumTestList = new ArrayList<>(); + enumTestList.add(AppServiceType.MEDIA); + enumTestList.add(AppServiceType.NAVIGATION); + enumTestList.add(AppServiceType.WEATHER); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioStreamingIndicatorTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioStreamingIndicatorTests.java new file mode 100644 index 000000000..85312ecde --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioStreamingIndicatorTests.java @@ -0,0 +1,80 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.AudioStreamingIndicator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.AudioStreamingIndicator} + */ +public class AudioStreamingIndicatorTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "PLAY_PAUSE"; + AudioStreamingIndicator enumPlayPause = AudioStreamingIndicator.valueForString(example); + example = "PLAY"; + AudioStreamingIndicator enumPlay = AudioStreamingIndicator.valueForString(example); + example = "PAUSE"; + AudioStreamingIndicator enumPause = AudioStreamingIndicator.valueForString(example); + example = "STOP"; + AudioStreamingIndicator enumStop = AudioStreamingIndicator.valueForString(example); + + + assertNotNull("PLAY_PAUSE returned null", enumPlayPause); + assertNotNull("PLAY returned null", enumPlay); + assertNotNull("PAUSE returned null", enumPause); + assertNotNull("STOP returned null", enumStop); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "pLayPauZe"; + try { + AudioStreamingIndicator temp = AudioStreamingIndicator.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + AudioStreamingIndicator temp = AudioStreamingIndicator.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of AudioStreamingIndicator. + */ + public void testListEnum() { + List<AudioStreamingIndicator> enumValueList = Arrays.asList(AudioStreamingIndicator.values()); + + List<AudioStreamingIndicator> enumTestList = new ArrayList<>(); + enumTestList.add(AudioStreamingIndicator.PLAY_PAUSE); + enumTestList.add(AudioStreamingIndicator.PLAY); + enumTestList.add(AudioStreamingIndicator.PAUSE); + enumTestList.add(AudioStreamingIndicator.STOP); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioStreamingStateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioStreamingStateTests.java new file mode 100644 index 000000000..178613e53 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioStreamingStateTests.java @@ -0,0 +1,76 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.AudioStreamingState; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.AudioStreamingState} + */ +public class AudioStreamingStateTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "AUDIBLE"; + AudioStreamingState enumAudible = AudioStreamingState.valueForString(example); + example = "ATTENUATED"; + AudioStreamingState enumAttentuated = AudioStreamingState.valueForString(example); + example = "NOT_AUDIBLE"; + AudioStreamingState enumNotAudible = AudioStreamingState.valueForString(example); + + + assertNotNull("AUDIBLE returned null", enumAudible); + assertNotNull("ATTENUATED returned null", enumAttentuated); + assertNotNull("NOT_AUDIBLE returned null", enumNotAudible); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "aUDibLE"; + try { + AudioStreamingState temp = AudioStreamingState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + AudioStreamingState temp = AudioStreamingState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of AudioStreamingState. + */ + public void testListEnum() { + List<AudioStreamingState> enumValueList = Arrays.asList(AudioStreamingState.values()); + + List<AudioStreamingState> enumTestList = new ArrayList<AudioStreamingState>(); + enumTestList.add(AudioStreamingState.AUDIBLE); + enumTestList.add(AudioStreamingState.ATTENUATED); + enumTestList.add(AudioStreamingState.NOT_AUDIBLE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioTypeTests.java new file mode 100644 index 000000000..6cbecf09a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/AudioTypeTests.java @@ -0,0 +1,68 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.AudioType; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.AudioType} + */ +public class AudioTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "PCM"; + AudioType enumPcm = AudioType.valueForString(example); + + assertNotNull("PCM returned null", enumPcm); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "pCM"; + try { + AudioType temp = AudioType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + AudioType temp = AudioType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + + /** + * Verifies the possible enum values of AudioType. + */ + public void testListEnum() { + List<AudioType> enumValueList = Arrays.asList(AudioType.values()); + + List<AudioType> enumTestList = new ArrayList<AudioType>(); + enumTestList.add(AudioType.PCM); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/BitsPerSampleTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/BitsPerSampleTests.java new file mode 100644 index 000000000..65b4766e8 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/BitsPerSampleTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.BitsPerSample; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.BitsPerSample} + */ +public class BitsPerSampleTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "8_BIT"; + BitsPerSample enum8Bit = BitsPerSample.valueForString(example); + example = "16_BIT"; + BitsPerSample enum16Bit = BitsPerSample.valueForString(example); + + assertNotNull("8_BIT returned null", enum8Bit); + assertNotNull("16_BIT returned null", enum16Bit); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "8_biT"; + try { + BitsPerSample temp = BitsPerSample.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + BitsPerSample temp = BitsPerSample.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of BitsPerSample. + */ + public void testListEnum() { + List<BitsPerSample> enumValueList = Arrays.asList(BitsPerSample.values()); + + List<BitsPerSample> enumTestList = new ArrayList<BitsPerSample>(); + enumTestList.add(BitsPerSample._8_BIT); + enumTestList.add(BitsPerSample._16_BIT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonEventModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonEventModeTests.java new file mode 100644 index 000000000..4145844ee --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonEventModeTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.ButtonEventMode; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.ButtonEventMode} + */ +public class ButtonEventModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "BUTTONUP"; + ButtonEventMode enumButtonUp = ButtonEventMode.valueForString(example); + example = "BUTTONDOWN"; + ButtonEventMode enumButtonDown = ButtonEventMode.valueForString(example); + + assertNotNull("BUTTONUP returned null", enumButtonUp); + assertNotNull("BUTTONDOWN returned null", enumButtonDown); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "buTTonUp"; + try { + ButtonEventMode temp = ButtonEventMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ButtonEventMode temp = ButtonEventMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies the possible enum values of ButtonEventMode. + */ + public void testListEnum() { + List<ButtonEventMode> enumValueList = Arrays.asList(ButtonEventMode.values()); + + List<ButtonEventMode> enumTestList = new ArrayList<ButtonEventMode>(); + enumTestList.add(ButtonEventMode.BUTTONUP); + enumTestList.add(ButtonEventMode.BUTTONDOWN); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonNameTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonNameTests.java new file mode 100644 index 000000000..e823e7593 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonNameTests.java @@ -0,0 +1,242 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.ButtonName; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.ButtonName} + */ +public class ButtonNameTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "OK"; + ButtonName enumOk = ButtonName.valueForString(example); + example = "SEEKLEFT"; + ButtonName enumSeekLeft = ButtonName.valueForString(example); + example = "SEEKRIGHT"; + ButtonName enumSeekRight = ButtonName.valueForString(example); + example = "TUNEUP"; + ButtonName enumTuneUp = ButtonName.valueForString(example); + example = "TUNEDOWN"; + ButtonName enumTuneDown = ButtonName.valueForString(example); + example = "PRESET_0"; + ButtonName enumPreset0 = ButtonName.valueForString(example); + example = "PRESET_1"; + ButtonName enumPreset1 = ButtonName.valueForString(example); + example = "PRESET_2"; + ButtonName enumPreset2 = ButtonName.valueForString(example); + example = "PRESET_3"; + ButtonName enumPreset3 = ButtonName.valueForString(example); + example = "PRESET_4"; + ButtonName enumPreset4 = ButtonName.valueForString(example); + example = "PRESET_5"; + ButtonName enumPreset5 = ButtonName.valueForString(example); + example = "PRESET_6"; + ButtonName enumPreset6 = ButtonName.valueForString(example); + example = "PRESET_7"; + ButtonName enumPreset7 = ButtonName.valueForString(example); + example = "PRESET_8"; + ButtonName enumPreset8 = ButtonName.valueForString(example); + example = "PRESET_9"; + ButtonName enumPreset9 = ButtonName.valueForString(example); + example = "CUSTOM_BUTTON"; + ButtonName enumCustomButton = ButtonName.valueForString(example); + example = "SEARCH"; + ButtonName enumSearch = ButtonName.valueForString(example); + example = "AC_MAX"; + ButtonName enumAcMax = ButtonName.valueForString(example); + example = "AC"; + ButtonName enumAc = ButtonName.valueForString(example); + example = "RECIRCULATE"; + ButtonName enumRecirculate = ButtonName.valueForString(example); + example = "FAN_UP"; + ButtonName enumFanUp = ButtonName.valueForString(example); + example = "FAN_DOWN"; + ButtonName enumFanDown = ButtonName.valueForString(example); + example = "TEMP_UP"; + ButtonName enumTempUp = ButtonName.valueForString(example); + example = "TEMP_DOWN"; + ButtonName enumTempDown = ButtonName.valueForString(example); + example = "DEFROST_MAX"; + ButtonName enumDefrostMax = ButtonName.valueForString(example); + example = "DEFROST"; + ButtonName enumDefrost = ButtonName.valueForString(example); + example = "DEFROST_REAR"; + ButtonName enumDefrostRear = ButtonName.valueForString(example); + example = "UPPER_VENT"; + ButtonName enumUpperVent = ButtonName.valueForString(example); + example = "LOWER_VENT"; + ButtonName enumLowerVent = ButtonName.valueForString(example); + example = "VOLUME_UP"; + ButtonName enumVolumeUp = ButtonName.valueForString(example); + example = "VOLUME_DOWN"; + ButtonName enumVolumeDown = ButtonName.valueForString(example); + example = "EJECT"; + ButtonName enumEject = ButtonName.valueForString(example); + example = "SOURCE"; + ButtonName enumSource = ButtonName.valueForString(example); + example = "SHUFFLE"; + ButtonName enumShuffle = ButtonName.valueForString(example); + example = "REPEAT"; + ButtonName enumRepeat = ButtonName.valueForString(example); + + + + assertNotNull("OK returned null", enumOk); + assertNotNull("SEEKLEFT returned null", enumSeekLeft); + assertNotNull("SEEKRIGHT returned null", enumSeekRight); + assertNotNull("TUNEUP returned null", enumTuneUp); + assertNotNull("TUNEDOWN returned null", enumTuneDown); + assertNotNull("PRESET_0 returned null", enumPreset0); + assertNotNull("PRESET_1 returned null", enumPreset1); + assertNotNull("PRESET_2 returned null", enumPreset2); + assertNotNull("PRESET_3 returned null", enumPreset3); + assertNotNull("PRESET_4 returned null", enumPreset4); + assertNotNull("PRESET_5 returned null", enumPreset5); + assertNotNull("PRESET_6 returned null", enumPreset6); + assertNotNull("PRESET_7 returned null", enumPreset7); + assertNotNull("PRESET_8 returned null", enumPreset8); + assertNotNull("PRESET_9 returned null", enumPreset9); + assertNotNull("CUSTOM_BUTTON returned null", enumCustomButton); + assertNotNull("SEARCH returned null", enumSearch); + assertNotNull("AC_MAX returned null", enumAcMax); + assertNotNull("AC returned null", enumAc); + assertNotNull("RECIRCULATE returned null", enumRecirculate); + assertNotNull("FAN_UP returned null", enumFanUp); + assertNotNull("FAN_DOWN returned null", enumFanDown); + assertNotNull("TEMP_UP returned null", enumTempUp); + assertNotNull("TEMP_DOWN returned null", enumTempDown); + assertNotNull("DEFROST_MAX returned null", enumDefrostMax); + assertNotNull("DEFROST returned null", enumDefrost); + assertNotNull("DEFROST_REAR returned null", enumDefrostRear); + assertNotNull("UPPER_VENT returned null", enumUpperVent); + assertNotNull("LOWER_VENT returned null", enumLowerVent); + assertNotNull("VOLUME_UP returned null", enumVolumeUp); + assertNotNull("VOLUME_DOWN returned null", enumVolumeDown); + assertNotNull("EJECT returned null", enumEject); + assertNotNull("SOURCE returned null", enumSource); + assertNotNull("SHUFFLE returned null", enumShuffle); + assertNotNull("REPEAT returned null", enumRepeat); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "oK"; + try { + ButtonName temp = ButtonName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ButtonName temp = ButtonName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of ButtonName. + */ + public void testListEnum() { + List<ButtonName> enumValueList = Arrays.asList(ButtonName.values()); + + List<ButtonName> enumTestList = new ArrayList<ButtonName>(); + + enumTestList.add(ButtonName.OK); + enumTestList.add(ButtonName.SEEKLEFT); + enumTestList.add(ButtonName.SEEKRIGHT); + enumTestList.add(ButtonName.TUNEUP); + enumTestList.add(ButtonName.TUNEDOWN); + enumTestList.add(ButtonName.PRESET_0); + enumTestList.add(ButtonName.PRESET_1); + enumTestList.add(ButtonName.PRESET_2); + enumTestList.add(ButtonName.PRESET_3); + enumTestList.add(ButtonName.PRESET_4); + enumTestList.add(ButtonName.PRESET_5); + enumTestList.add(ButtonName.PRESET_6); + enumTestList.add(ButtonName.PRESET_7); + enumTestList.add(ButtonName.PRESET_8); + enumTestList.add(ButtonName.PRESET_9); + enumTestList.add(ButtonName.CUSTOM_BUTTON); + enumTestList.add(ButtonName.SEARCH); + enumTestList.add(ButtonName.AC_MAX); + enumTestList.add(ButtonName.AC); + enumTestList.add(ButtonName.RECIRCULATE); + enumTestList.add(ButtonName.FAN_UP); + enumTestList.add(ButtonName.FAN_DOWN); + enumTestList.add(ButtonName.TEMP_UP); + enumTestList.add(ButtonName.TEMP_DOWN); + enumTestList.add(ButtonName.DEFROST_MAX); + enumTestList.add(ButtonName.DEFROST); + enumTestList.add(ButtonName.DEFROST_REAR); + enumTestList.add(ButtonName.UPPER_VENT); + enumTestList.add(ButtonName.LOWER_VENT); + enumTestList.add(ButtonName.VOLUME_UP); + enumTestList.add(ButtonName.VOLUME_DOWN); + enumTestList.add(ButtonName.EJECT); + enumTestList.add(ButtonName.SOURCE); + enumTestList.add(ButtonName.SHUFFLE); + enumTestList.add(ButtonName.REPEAT); + enumTestList.add(ButtonName.PLAY_PAUSE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } + + + /** + * Tests the preset numeric order. + */ + public void testPresetIndeces () { + ButtonName[] inputPresetArray = new ButtonName[] { + ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3, ButtonName.PRESET_4, + ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7, ButtonName.PRESET_8, ButtonName.PRESET_9, + ButtonName.OK}; + + Integer[] expectedValuesArray = new Integer[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, null}; + + for (int index = 0; index < inputPresetArray.length; index++) { + ButtonName input = inputPresetArray[index]; + Integer expect = expectedValuesArray[index]; + + Integer result = ButtonName.indexForPresetButton(input); + assertSame("Enum input " + result + " does not match expected value " + expect, result, expect); + } + } + + /** + * Verifies that a null preset lookup is invalid. + */ + public void testPresetNull () { + try { + assertNull("Passing null as a parameter does not return null", ButtonName.indexForPresetButton(null)); + } + catch (NullPointerException exc){ + fail("Passing null as a parameter throws a NullPointerException"); + } + + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonPressModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonPressModeTests.java new file mode 100644 index 000000000..cbfe16a73 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonPressModeTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.ButtonPressMode; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.ButtonPressMode} + */ +public class ButtonPressModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "LONG"; + ButtonPressMode enumLong = ButtonPressMode.valueForString(example); + example = "SHORT"; + ButtonPressMode enumShort = ButtonPressMode.valueForString(example); + + assertNotNull("LONG returned null", enumLong); + assertNotNull("SHORT returned null", enumShort); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "lONg"; + try { + ButtonPressMode temp = ButtonPressMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ButtonPressMode temp = ButtonPressMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of ButtonPressMode. + */ + public void testListEnum() { + List<ButtonPressMode> enumValueList = Arrays.asList(ButtonPressMode.values()); + + List<ButtonPressMode> enumTestList = new ArrayList<ButtonPressMode>(); + enumTestList.add(ButtonPressMode.LONG); + enumTestList.add(ButtonPressMode.SHORT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CarModeStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CarModeStatusTests.java new file mode 100644 index 000000000..d66760d9a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CarModeStatusTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.CarModeStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.CarModeStatus} + */ +public class CarModeStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NORMAL"; + CarModeStatus enumNormal = CarModeStatus.valueForString(example); + example = "FACTORY"; + CarModeStatus enumFactory = CarModeStatus.valueForString(example); + example = "TRANSPORT"; + CarModeStatus enumTransport = CarModeStatus.valueForString(example); + example = "CRASH"; + CarModeStatus enumCrash = CarModeStatus.valueForString(example); + + assertNotNull("NORMAL returned null", enumNormal); + assertNotNull("FACTORY returned null", enumFactory); + assertNotNull("TRANSPORT returned null", enumTransport); + assertNotNull("CRASH returned null", enumCrash); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "noRmaL"; + try { + CarModeStatus temp = CarModeStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + CarModeStatus temp = CarModeStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of CarModeStatus. + */ + public void testListEnum() { + List<CarModeStatus> enumValueList = Arrays.asList(CarModeStatus.values()); + + List<CarModeStatus> enumTestList = new ArrayList<CarModeStatus>(); + enumTestList.add(CarModeStatus.NORMAL); + enumTestList.add(CarModeStatus.FACTORY); + enumTestList.add(CarModeStatus.TRANSPORT); + enumTestList.add(CarModeStatus.CRASH); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CharacterSetTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CharacterSetTests.java new file mode 100644 index 000000000..99bc37265 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CharacterSetTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.CharacterSet; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.CharacterSet} + */ +public class CharacterSetTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "TYPE2SET"; + CharacterSet enumType2Set = CharacterSet.valueForString(example); + example = "TYPE5SET"; + CharacterSet enumType5Set = CharacterSet.valueForString(example); + example = "CID1SET"; + CharacterSet enumCid1Set = CharacterSet.valueForString(example); + example = "CID2SET"; + CharacterSet enumCid2Set = CharacterSet.valueForString(example); + + assertNotNull("TYPE2SET returned null", enumType2Set); + assertNotNull("TYPE5SET returned null", enumType5Set); + assertNotNull("CID1SET returned null", enumCid1Set); + assertNotNull("CID2SET returned null", enumCid2Set); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "tyPe2SeT"; + try { + CharacterSet temp = CharacterSet.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + CharacterSet temp = CharacterSet.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of CharacterSet. + */ + public void testListEnum() { + List<CharacterSet> enumValueList = Arrays.asList(CharacterSet.values()); + + List<CharacterSet> enumTestList = new ArrayList<CharacterSet>(); + enumTestList.add(CharacterSet.TYPE2SET); + enumTestList.add(CharacterSet.TYPE5SET); + enumTestList.add(CharacterSet.CID1SET); + enumTestList.add(CharacterSet.CID2SET); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CompassDirectionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CompassDirectionTests.java new file mode 100644 index 000000000..7eb7d31a0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/CompassDirectionTests.java @@ -0,0 +1,95 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.CompassDirection; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.CompassDirection} + */ +public class CompassDirectionTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NORTH"; + CompassDirection enumNorth = CompassDirection.valueForString(example); + example = "NORTHWEST"; + CompassDirection enumNorthWest = CompassDirection.valueForString(example); + example = "WEST"; + CompassDirection enumWest = CompassDirection.valueForString(example); + example = "SOUTHWEST"; + CompassDirection enumSouthWest = CompassDirection.valueForString(example); + example = "SOUTH"; + CompassDirection enumSouth = CompassDirection.valueForString(example); + example = "SOUTHEAST"; + CompassDirection enumSouthEast = CompassDirection.valueForString(example); + example = "EAST"; + CompassDirection enumEast = CompassDirection.valueForString(example); + example = "NORTHEAST"; + CompassDirection enumNorthEast = CompassDirection.valueForString(example); + + assertNotNull("NORTH returned null", enumNorth); + assertNotNull("NORTHWEST returned null", enumNorthWest); + assertNotNull("WEST returned null", enumWest); + assertNotNull("SOUTHWEST returned null", enumSouthWest); + assertNotNull("SOUTH returned null", enumSouth); + assertNotNull("SOUTHEAST returned null", enumSouthEast); + assertNotNull("EAST returned null", enumEast); + assertNotNull("NORTHEAST returned null", enumNorthEast); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "noRTh"; + try { + CompassDirection temp = CompassDirection.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + CompassDirection temp = CompassDirection.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of CompassDirection. + */ + public void testListEnum() { + List<CompassDirection> enumValueList = Arrays.asList(CompassDirection.values()); + + List<CompassDirection> enumTestList = new ArrayList<CompassDirection>(); + enumTestList.add(CompassDirection.NORTH); + enumTestList.add(CompassDirection.NORTHWEST); + enumTestList.add(CompassDirection.WEST); + enumTestList.add(CompassDirection.SOUTHWEST); + enumTestList.add(CompassDirection.SOUTH); + enumTestList.add(CompassDirection.SOUTHEAST); + enumTestList.add(CompassDirection.EAST); + enumTestList.add(CompassDirection.NORTHEAST); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ComponentVolumeStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ComponentVolumeStatusTests.java new file mode 100644 index 000000000..20946252c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ComponentVolumeStatusTests.java @@ -0,0 +1,87 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.ComponentVolumeStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.ComponentVolumeStatus} + */ +public class ComponentVolumeStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "UNKNOWN"; + ComponentVolumeStatus enumUnknown = ComponentVolumeStatus.valueForString(example); + example = "NORMAL"; + ComponentVolumeStatus enumNormal = ComponentVolumeStatus.valueForString(example); + example = "LOW"; + ComponentVolumeStatus enumLow = ComponentVolumeStatus.valueForString(example); + example = "FAULT"; + ComponentVolumeStatus enumFault = ComponentVolumeStatus.valueForString(example); + example = "ALERT"; + ComponentVolumeStatus enumAlert = ComponentVolumeStatus.valueForString(example); + example = "NOT_SUPPORTED"; + ComponentVolumeStatus enumNotSupported = ComponentVolumeStatus.valueForString(example); + + assertNotNull("UNKNOWN returned null", enumUnknown); + assertNotNull("NORMAL returned null", enumNormal); + assertNotNull("LOW returned null", enumLow); + assertNotNull("FAULT returned null", enumFault); + assertNotNull("ALERT returned null", enumAlert); + assertNotNull("NOT_SUPPORTED returned null", enumNotSupported); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "unKNowN"; + try { + ComponentVolumeStatus temp = ComponentVolumeStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ComponentVolumeStatus temp = ComponentVolumeStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of ComponentVolumeStatus. + */ + public void testListEnum() { + List<ComponentVolumeStatus> enumValueList = Arrays.asList(ComponentVolumeStatus.values()); + + List<ComponentVolumeStatus> enumTestList = new ArrayList<ComponentVolumeStatus>(); + enumTestList.add(ComponentVolumeStatus.UNKNOWN); + enumTestList.add(ComponentVolumeStatus.NORMAL); + enumTestList.add(ComponentVolumeStatus.LOW); + enumTestList.add(ComponentVolumeStatus.FAULT); + enumTestList.add(ComponentVolumeStatus.ALERT); + enumTestList.add(ComponentVolumeStatus.NOT_SUPPORTED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DefrostZoneTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DefrostZoneTests.java new file mode 100644 index 000000000..f1f375623 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DefrostZoneTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.DefrostZone; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.DefrostZone} + */ +public class DefrostZoneTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "FRONT"; + DefrostZone enumFront = DefrostZone.valueForString(example); + example = "REAR"; + DefrostZone enumRear = DefrostZone.valueForString(example); + example = "ALL"; + DefrostZone enumAll = DefrostZone.valueForString(example); + example = "NONE"; + DefrostZone enumNone = DefrostZone.valueForString(example); + + assertNotNull("FRONT returned null", enumFront); + assertNotNull("REAR returned null", enumRear); + assertNotNull("ALL returned null", enumAll); + assertNotNull("NONE returned null", enumNone); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "fRONT"; + try { + DefrostZone temp = DefrostZone.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + DefrostZone temp = DefrostZone.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of DefrostZone. + */ + public void testListEnum() { + List<DefrostZone> enumValueList = Arrays.asList(DefrostZone.values()); + + List<DefrostZone> enumTestList = new ArrayList<DefrostZone>(); + enumTestList.add(DefrostZone.FRONT); + enumTestList.add(DefrostZone.REAR); + enumTestList.add(DefrostZone.ALL); + enumTestList.add(DefrostZone.NONE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DeviceLevelStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DeviceLevelStatusTests.java new file mode 100644 index 000000000..71c15d0fb --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DeviceLevelStatusTests.java @@ -0,0 +1,87 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.DeviceLevelStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.DeviceLevelStatus} + */ +public class DeviceLevelStatusTests extends TestCase{ + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "ZERO_LEVEL_BARS"; + DeviceLevelStatus enumZeroLevel = DeviceLevelStatus.valueForString(example); + example = "ONE_LEVEL_BARS"; + DeviceLevelStatus enumOneLevel = DeviceLevelStatus.valueForString(example); + example = "TWO_LEVEL_BARS"; + DeviceLevelStatus enumTwoLevel = DeviceLevelStatus.valueForString(example); + example = "THREE_LEVEL_BARS"; + DeviceLevelStatus enumThreeLevel = DeviceLevelStatus.valueForString(example); + example = "FOUR_LEVEL_BARS"; + DeviceLevelStatus enumFourLevel = DeviceLevelStatus.valueForString(example); + example = "NOT_PROVIDED"; + DeviceLevelStatus enumNotProvided = DeviceLevelStatus.valueForString(example); + + assertNotNull("ZERO_LEVEL_BARS returned null", enumZeroLevel); + assertNotNull("ONE_LEVEL_BARS returned null", enumOneLevel); + assertNotNull("TWO_LEVEL_BARS returned null", enumTwoLevel); + assertNotNull("THREE_LEVEL_BARS returned null", enumThreeLevel); + assertNotNull("FOUR_LEVEL_BARS returned null", enumFourLevel); + assertNotNull("NOT_PROVIDED returned null", enumNotProvided); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "onE_LeVeL_barS"; + try { + DeviceLevelStatus temp = DeviceLevelStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + DeviceLevelStatus temp = DeviceLevelStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of DeviceLevelStatus. + */ + public void testListEnum() { + List<DeviceLevelStatus> enumValueList = Arrays.asList(DeviceLevelStatus.values()); + + List<DeviceLevelStatus> enumTestList = new ArrayList<DeviceLevelStatus>(); + enumTestList.add(DeviceLevelStatus.ZERO_LEVEL_BARS); + enumTestList.add(DeviceLevelStatus.ONE_LEVEL_BARS); + enumTestList.add(DeviceLevelStatus.TWO_LEVEL_BARS); + enumTestList.add(DeviceLevelStatus.THREE_LEVEL_BARS); + enumTestList.add(DeviceLevelStatus.FOUR_LEVEL_BARS); + enumTestList.add(DeviceLevelStatus.NOT_PROVIDED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DimensionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DimensionTests.java new file mode 100644 index 000000000..035ac202a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DimensionTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.Dimension; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.Dimension} + */ +public class DimensionTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NO_FIX"; + Dimension enumNoFix = Dimension.valueForString(example); + example = "2D"; + Dimension enum2D = Dimension.valueForString(example); + example = "3D"; + Dimension enum3D = Dimension.valueForString(example); + + assertNotNull("NO_FIX returned null", enumNoFix); + assertNotNull("2D returned null", enum2D); + assertNotNull("3D returned null", enum3D); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "no_FiX"; + try { + Dimension temp = Dimension.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + Dimension temp = Dimension.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of Dimension. + */ + public void testListEnum() { + List<Dimension> enumValueList = Arrays.asList(Dimension.values()); + + List<Dimension> enumTestList = new ArrayList<Dimension>(); + enumTestList.add(Dimension.NO_FIX); + enumTestList.add(Dimension._2D); + enumTestList.add(Dimension._3D); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DirectionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DirectionTests.java new file mode 100644 index 000000000..76492878d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DirectionTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.Direction; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.Direction} + */ +public class DirectionTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "LEFT"; + Direction enumLeft = Direction.valueForString(example); + example = "RIGHT"; + Direction enumRight = Direction.valueForString(example); + + assertNotNull("LEFT returned null", enumLeft); + assertNotNull("RIGHT returned null", enumRight); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "fRONT"; + try { + Direction temp = Direction.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + Direction temp = Direction.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of Direction. + */ + public void testListEnum() { + List<Direction> enumValueList = Arrays.asList(Direction.values()); + + List<Direction> enumTestList = new ArrayList<>(); + enumTestList.add(Direction.LEFT); + enumTestList.add(Direction.RIGHT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DisplayModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DisplayModeTests.java new file mode 100644 index 000000000..94387ef9a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DisplayModeTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.DisplayMode; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.DisplayMode} + */ +public class DisplayModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "DAY"; + DisplayMode enumDay = DisplayMode.valueForString(example); + example = "NIGHT"; + DisplayMode enumNight = DisplayMode.valueForString(example); + example = "AUTO"; + DisplayMode enumAuto = DisplayMode.valueForString(example); + + assertNotNull("DAY returned null", enumDay); + assertNotNull("NIGHT returned null", enumNight); + assertNotNull("AUTO returned null", enumAuto); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "dAY"; + try { + DisplayMode temp = DisplayMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + DisplayMode temp = DisplayMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of DisplayMode. + */ + public void testListEnum() { + List<DisplayMode> enumValueList = Arrays.asList(DisplayMode.values()); + + List<DisplayMode> enumTestList = new ArrayList<DisplayMode>(); + enumTestList.add(DisplayMode.DAY); + enumTestList.add(DisplayMode.NIGHT); + enumTestList.add(DisplayMode.AUTO); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DisplayTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DisplayTypeTests.java new file mode 100644 index 000000000..560bdf025 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DisplayTypeTests.java @@ -0,0 +1,107 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.DisplayType; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.DisplayType} + */ +public class DisplayTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "CID"; + DisplayType enumCid = DisplayType.valueForString(example); + example = "TYPE2"; + DisplayType enumType2 = DisplayType.valueForString(example); + example = "TYPE5"; + DisplayType enumType5 = DisplayType.valueForString(example); + example = "NGN"; + DisplayType enumNgn = DisplayType.valueForString(example); + example = "GEN2_8_DMA"; + DisplayType enumGen2_8Dma = DisplayType.valueForString(example); + example = "GEN2_6_DMA"; + DisplayType enumGen2_6Dma = DisplayType.valueForString(example); + example = "MFD3"; + DisplayType enumMfd3 = DisplayType.valueForString(example); + example = "MFD4"; + DisplayType enumMfd4 = DisplayType.valueForString(example); + example = "MFD5"; + DisplayType enumMfd5 = DisplayType.valueForString(example); + example = "GEN3_8-INCH"; + DisplayType enumGen3_8Inch = DisplayType.valueForString(example); + example = "SDL_GENERIC"; + DisplayType enumGeneric = DisplayType.valueForString(example); + + assertNotNull("CID returned null", enumCid); + assertNotNull("TYPE2 returned null", enumType2); + assertNotNull("TYPE5 returned null", enumType5); + assertNotNull("NGN returned null", enumNgn); + assertNotNull("GEN2_8_DMA returned null", enumGen2_8Dma); + assertNotNull("GEN2_6_DMA returned null", enumGen2_6Dma); + assertNotNull("MFD3 returned null", enumMfd3); + assertNotNull("MFD4 returned null", enumMfd4); + assertNotNull("MFD5 returned null", enumMfd5); + assertNotNull("GEN3_8-INCH returned null", enumGen3_8Inch); + assertNotNull("SDL_GENERIC returned null", enumGeneric); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "cId"; + try { + DisplayType temp = DisplayType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + DisplayType temp = DisplayType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of DisplayType. + */ + public void testListEnum() { + List<DisplayType> enumValueList = Arrays.asList(DisplayType.values()); + + List<DisplayType> enumTestList = new ArrayList<DisplayType>(); + enumTestList.add(DisplayType.CID); + enumTestList.add(DisplayType.TYPE2); + enumTestList.add(DisplayType.TYPE5); + enumTestList.add(DisplayType.NGN); + enumTestList.add(DisplayType.GEN2_8_DMA); + enumTestList.add(DisplayType.GEN2_6_DMA); + enumTestList.add(DisplayType.MFD3); + enumTestList.add(DisplayType.MFD4); + enumTestList.add(DisplayType.MFD5); + enumTestList.add(DisplayType.GEN3_8_INCH); + enumTestList.add(DisplayType.SDL_GENERIC); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DistanceUnitTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DistanceUnitTests.java new file mode 100644 index 000000000..c421d6029 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DistanceUnitTests.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.DistanceUnit; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.DistanceUnit} + */ +public class DistanceUnitTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "MILES"; + DistanceUnit enumMiles = DistanceUnit.valueForString(example); + example = "KILOMETERS"; + DistanceUnit enumKilometers = DistanceUnit.valueForString(example); + + assertNotNull("MILES returned null", enumMiles); + assertNotNull("KILOMETERS returned null", enumKilometers); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "mILES"; + try { + DistanceUnit temp = DistanceUnit.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + DistanceUnit temp = DistanceUnit.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of DistanceUnit. + */ + public void testListEnum() { + List<DistanceUnit> enumValueList = Arrays.asList(DistanceUnit.values()); + List<DistanceUnit> enumTestList = new ArrayList<DistanceUnit>(); + enumTestList.add(DistanceUnit.MILES); + enumTestList.add(DistanceUnit.KILOMETERS); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DriverDistractionStateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DriverDistractionStateTests.java new file mode 100644 index 000000000..2d85caa21 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/DriverDistractionStateTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.DriverDistractionState; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.DriverDistractionState} + */ +public class DriverDistractionStateTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "DD_ON"; + DriverDistractionState enumDdOn = DriverDistractionState.valueForString(example); + example = "DD_OFF"; + DriverDistractionState enumDdOff = DriverDistractionState.valueForString(example); + + assertNotNull("DD_ON returned null", enumDdOn); + assertNotNull("DD_OFF returned null", enumDdOff); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "dD_oN"; + try { + DriverDistractionState temp = DriverDistractionState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + DriverDistractionState temp = DriverDistractionState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of DriverDistractionState. + */ + public void testListEnum() { + List<DriverDistractionState> enumValueList = Arrays.asList(DriverDistractionState.values()); + + List<DriverDistractionState> enumTestList = new ArrayList<DriverDistractionState>(); + enumTestList.add(DriverDistractionState.DD_ON); + enumTestList.add(DriverDistractionState.DD_OFF); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ECallConfirmationStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ECallConfirmationStatusTests.java new file mode 100644 index 000000000..9ce602ee1 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ECallConfirmationStatusTests.java @@ -0,0 +1,91 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.ECallConfirmationStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.ECallConfirmationStatus} + */ +public class ECallConfirmationStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NORMAL"; + ECallConfirmationStatus enumNormal = ECallConfirmationStatus.valueForString(example); + example = "CALL_IN_PROGRESS"; + ECallConfirmationStatus enumCallInProgress = ECallConfirmationStatus.valueForString(example); + example = "CALL_CANCELLED"; + ECallConfirmationStatus enumCancelled = ECallConfirmationStatus.valueForString(example); + example = "CALL_COMPLETED"; + ECallConfirmationStatus enumCompleted = ECallConfirmationStatus.valueForString(example); + example = "CALL_UNSUCCESSFUL"; + ECallConfirmationStatus enumUnsuccessful = ECallConfirmationStatus.valueForString(example); + example = "ECALL_CONFIGURED_OFF"; + ECallConfirmationStatus enumConfiguredOff = ECallConfirmationStatus.valueForString(example); + example = "CALL_COMPLETE_DTMF_TIMEOUT"; + ECallConfirmationStatus enumCompleteDtmfTimeout = ECallConfirmationStatus.valueForString(example); + + assertNotNull("NORMAL returned null", enumNormal); + assertNotNull("CALL_IN_PROGRESS returned null", enumCallInProgress); + assertNotNull("CALL_CANCELLED returned null", enumCancelled); + assertNotNull("CALL_COMPLETED returned null", enumCompleted); + assertNotNull("CALL_UNSUCCESSFUL returned null", enumUnsuccessful); + assertNotNull("ECALL_CONFIGURED_OFF returned null", enumConfiguredOff); + assertNotNull("CALL_COMPLETE_DTMF_TIMEOUT returned null", enumCompleteDtmfTimeout); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "noRMal"; + try { + ECallConfirmationStatus temp = ECallConfirmationStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ECallConfirmationStatus temp = ECallConfirmationStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of ECallConfirmationStatus. + */ + public void testListEnum() { + List<ECallConfirmationStatus> enumValueList = Arrays.asList(ECallConfirmationStatus.values()); + + List<ECallConfirmationStatus> enumTestList = new ArrayList<ECallConfirmationStatus>(); + enumTestList.add(ECallConfirmationStatus.NORMAL); + enumTestList.add(ECallConfirmationStatus.CALL_IN_PROGRESS); + enumTestList.add(ECallConfirmationStatus.CALL_CANCELLED); + enumTestList.add(ECallConfirmationStatus.CALL_COMPLETED); + enumTestList.add(ECallConfirmationStatus.CALL_UNSUCCESSFUL); + enumTestList.add(ECallConfirmationStatus.ECALL_CONFIGURED_OFF); + enumTestList.add(ECallConfirmationStatus.CALL_COMPLETE_DTMF_TIMEOUT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ElectronicParkBrakeStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ElectronicParkBrakeStatusTests.java new file mode 100644 index 000000000..bbeb1bce3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ElectronicParkBrakeStatusTests.java @@ -0,0 +1,82 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.ElectronicParkBrakeStatus; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.ElectronicParkBrakeStatus} + */ +public class ElectronicParkBrakeStatusTests extends TestCase { + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "CLOSED"; + ElectronicParkBrakeStatus enumClosed = ElectronicParkBrakeStatus.valueForString(example); + example = "TRANSITION"; + ElectronicParkBrakeStatus enumTransition = ElectronicParkBrakeStatus.valueForString(example); + example = "OPEN"; + ElectronicParkBrakeStatus enumOpen = ElectronicParkBrakeStatus.valueForString(example); + example = "DRIVE_ACTIVE"; + ElectronicParkBrakeStatus enumDriveActive = ElectronicParkBrakeStatus.valueForString(example); + example = "FAULT"; + ElectronicParkBrakeStatus enumFault = ElectronicParkBrakeStatus.valueForString(example); + + assertNotNull("CLOSED returned null", enumClosed); + assertNotNull("TRANSITION returned null", enumTransition); + assertNotNull("OPEN returned null", enumOpen); + assertNotNull("DRIVE_ACTIVE returned null", enumDriveActive); + assertNotNull("FAULT returned null", enumFault); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "Clsoed"; + try { + ElectronicParkBrakeStatus temp = ElectronicParkBrakeStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ElectronicParkBrakeStatus temp = ElectronicParkBrakeStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of Electronic Brake Status. + */ + public void testListEnum() { + List<ElectronicParkBrakeStatus> enumValueList = Arrays.asList(ElectronicParkBrakeStatus.values()); + + List<ElectronicParkBrakeStatus> enumTestList = new ArrayList<ElectronicParkBrakeStatus>(); + enumTestList.add(ElectronicParkBrakeStatus.CLOSED); + enumTestList.add(ElectronicParkBrakeStatus.TRANSITION); + enumTestList.add(ElectronicParkBrakeStatus.OPEN); + enumTestList.add(ElectronicParkBrakeStatus.DRIVE_ACTIVE); + enumTestList.add(ElectronicParkBrakeStatus.FAULT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/EmergencyEventTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/EmergencyEventTypeTests.java new file mode 100644 index 000000000..21823e4bd --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/EmergencyEventTypeTests.java @@ -0,0 +1,91 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.EmergencyEventType; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.EmergencyEventType} + */ +public class EmergencyEventTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NO_EVENT"; + EmergencyEventType enumEventType = EmergencyEventType.valueForString(example); + example = "FRONTAL"; + EmergencyEventType enumFrontal = EmergencyEventType.valueForString(example); + example = "SIDE"; + EmergencyEventType enumSide = EmergencyEventType.valueForString(example); + example = "REAR"; + EmergencyEventType enumRear = EmergencyEventType.valueForString(example); + example = "ROLLOVER"; + EmergencyEventType enumRollover = EmergencyEventType.valueForString(example); + example = "NOT_SUPPORTED"; + EmergencyEventType enumNotSupported = EmergencyEventType.valueForString(example); + example = "FAULT"; + EmergencyEventType enumFault = EmergencyEventType.valueForString(example); + + assertNotNull("NO_EVENT returned null", enumEventType); + assertNotNull("FRONTAL returned null", enumFrontal); + assertNotNull("SIDE returned null", enumSide); + assertNotNull("REAR returned null", enumRear); + assertNotNull("ROLLOVER returned null", enumRollover); + assertNotNull("NOT_SUPPORTED returned null", enumNotSupported); + assertNotNull("FAULT returned null", enumFault); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "nO_EvenT"; + try { + EmergencyEventType temp = EmergencyEventType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + EmergencyEventType temp = EmergencyEventType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of EmergencyEvent. + */ + public void testListEnum() { + List<EmergencyEventType> enumValueList = Arrays.asList(EmergencyEventType.values()); + + List<EmergencyEventType> enumTestList = new ArrayList<EmergencyEventType>(); + enumTestList.add(EmergencyEventType.NO_EVENT); + enumTestList.add(EmergencyEventType.FRONTAL); + enumTestList.add(EmergencyEventType.SIDE); + enumTestList.add(EmergencyEventType.REAR); + enumTestList.add(EmergencyEventType.ROLLOVER); + enumTestList.add(EmergencyEventType.NOT_SUPPORTED); + enumTestList.add(EmergencyEventType.FAULT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FileTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FileTypeTests.java new file mode 100644 index 000000000..4db206cad --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FileTypeTests.java @@ -0,0 +1,95 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.FileType; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.FileType} + */ +public class FileTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "GRAPHIC_BMP"; + FileType enumGraphicBmp = FileType.valueForString(example); + example = "GRAPHIC_JPEG"; + FileType enumGraphicJpeg = FileType.valueForString(example); + example = "GRAPHIC_PNG"; + FileType enumGraphicPng = FileType.valueForString(example); + example = "AUDIO_WAVE"; + FileType enumAudioWave = FileType.valueForString(example); + example = "AUDIO_AAC"; + FileType enumAudioAac = FileType.valueForString(example); + example = "AUDIO_MP3"; + FileType enumAudioMp3 = FileType.valueForString(example); + example = "BINARY"; + FileType enumBinary = FileType.valueForString(example); + example = "JSON"; + FileType enumJson = FileType.valueForString(example); + + assertNotNull("GRAPHIC_BMP returned null", enumGraphicBmp); + assertNotNull("GRAPHIC_JPEG returned null", enumGraphicJpeg); + assertNotNull("GRAPHIC_PNG returned null", enumGraphicPng); + assertNotNull("AUDIO_WAVE returned null", enumAudioWave); + assertNotNull("AUDIO_AAC returned null", enumAudioAac); + assertNotNull("AUDIO_MP3 returned null", enumAudioMp3); + assertNotNull("BINARY returned null", enumBinary); + assertNotNull("JSON returned null", enumJson); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "uSer_ExiT"; + try { + FileType temp = FileType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + FileType temp = FileType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of FileType. + */ + public void testListEnum() { + List<FileType> enumValueList = Arrays.asList(FileType.values()); + + List<FileType> enumTestList = new ArrayList<FileType>(); + enumTestList.add(FileType.GRAPHIC_BMP); + enumTestList.add(FileType.GRAPHIC_JPEG); + enumTestList.add(FileType.GRAPHIC_PNG); + enumTestList.add(FileType.AUDIO_WAVE); + enumTestList.add(FileType.AUDIO_AAC); + enumTestList.add(FileType.AUDIO_MP3); + enumTestList.add(FileType.BINARY); + enumTestList.add(FileType.JSON); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FuelCutoffStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FuelCutoffStatusTests.java new file mode 100644 index 000000000..4900203f2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FuelCutoffStatusTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.FuelCutoffStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.FuelCutoffStatus} + */ +public class FuelCutoffStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "TERMINATE_FUEL"; + FuelCutoffStatus enumTerminateFuel = FuelCutoffStatus.valueForString(example); + example = "NORMAL_OPERATION"; + FuelCutoffStatus enumNormalOperation = FuelCutoffStatus.valueForString(example); + example = "FAULT"; + FuelCutoffStatus enumFault = FuelCutoffStatus.valueForString(example); + + assertNotNull("TERMINATE_FUEL returned null", enumTerminateFuel); + assertNotNull("NORMAL_OPERATION returned null", enumNormalOperation); + assertNotNull("FAULT returned null", enumFault); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "tErmINAte_FueL"; + try { + FuelCutoffStatus temp = FuelCutoffStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + FuelCutoffStatus temp = FuelCutoffStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of FuelCutoffStatus. + */ + public void testListEnum() { + List<FuelCutoffStatus> enumValueList = Arrays.asList(FuelCutoffStatus.values()); + + List<FuelCutoffStatus> enumTestList = new ArrayList<FuelCutoffStatus>(); + enumTestList.add(FuelCutoffStatus.TERMINATE_FUEL); + enumTestList.add(FuelCutoffStatus.NORMAL_OPERATION); + enumTestList.add(FuelCutoffStatus.FAULT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FuelTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FuelTypeTests.java new file mode 100644 index 000000000..525cc0316 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/FuelTypeTests.java @@ -0,0 +1,87 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.FuelType; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.FuelType} + */ +public class FuelTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "GASOLINE"; + FuelType enumGasoline = FuelType.valueForString(example); + example = "DIESEL"; + FuelType enumDiesel = FuelType.valueForString(example); + example = "CNG"; + FuelType enumCng = FuelType.valueForString(example); + example = "LPG"; + FuelType enumLpg = FuelType.valueForString(example); + example = "HYDROGEN"; + FuelType enumHydrogen = FuelType.valueForString(example); + example = "BATTERY"; + FuelType enumBattery = FuelType.valueForString(example); + + assertNotNull("GASOLINE returned null", enumGasoline); + assertNotNull("DIESEL returned null", enumDiesel); + assertNotNull("CNG returned null", enumCng); + assertNotNull("LPG returned null", enumLpg); + assertNotNull("HYDROGEN returned null", enumHydrogen); + assertNotNull("BATTERY returned null", enumBattery); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "gASOLINE"; + try { + FuelType temp = FuelType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + FuelType temp = FuelType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of FuelType. + */ + public void testListEnum() { + List<FuelType> enumValueList = Arrays.asList(FuelType.values()); + + List<FuelType> enumTestList = new ArrayList<FuelType>(); + enumTestList.add(FuelType.GASOLINE); + enumTestList.add(FuelType.DIESEL); + enumTestList.add(FuelType.CNG); + enumTestList.add(FuelType.LPG); + enumTestList.add(FuelType.HYDROGEN); + enumTestList.add(FuelType.BATTERY); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/GlobalPropertyTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/GlobalPropertyTests.java new file mode 100644 index 000000000..fd7388a6c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/GlobalPropertyTests.java @@ -0,0 +1,91 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.GlobalProperty; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.GlobalProperty} + */ +public class GlobalPropertyTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "HELPPROMPT"; + GlobalProperty enumHelpPrompt = GlobalProperty.valueForString(example); + example = "TIMEOUTPROMPT"; + GlobalProperty enumTimeoutPrompt = GlobalProperty.valueForString(example); + example = "VRHELPTITLE"; + GlobalProperty enumVrHelpTitle = GlobalProperty.valueForString(example); + example = "VRHELPITEMS"; + GlobalProperty enumVrHelpItems = GlobalProperty.valueForString(example); + example = "MENUNAME"; + GlobalProperty enumMenuName = GlobalProperty.valueForString(example); + example = "MENUICON"; + GlobalProperty enumMenuIcon = GlobalProperty.valueForString(example); + example = "KEYBOARDPROPERTIES"; + GlobalProperty enumKeyboardProperties = GlobalProperty.valueForString(example); + + assertNotNull("HELPPROMPT returned null", enumHelpPrompt); + assertNotNull("TIMEOUTPROMPT returned null", enumTimeoutPrompt); + assertNotNull("VRHELPTITLE returned null", enumVrHelpTitle); + assertNotNull("VRHELPITEMS returned null", enumVrHelpItems); + assertNotNull("MENUNAME returned null", enumMenuName); + assertNotNull("MENUICON returned null", enumMenuIcon); + assertNotNull("KEYBOARDPROPERTIES returned null", enumKeyboardProperties); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "heLp_ProMPt"; + try { + GlobalProperty temp = GlobalProperty.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + GlobalProperty temp = GlobalProperty.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of GlobalProperty. + */ + public void testListEnum() { + List<GlobalProperty> enumValueList = Arrays.asList(GlobalProperty.values()); + + List<GlobalProperty> enumTestList = new ArrayList<GlobalProperty>(); + enumTestList.add(GlobalProperty.HELPPROMPT); + enumTestList.add(GlobalProperty.TIMEOUTPROMPT); + enumTestList.add(GlobalProperty.VRHELPTITLE); + enumTestList.add(GlobalProperty.VRHELPITEMS); + enumTestList.add(GlobalProperty.MENUNAME); + enumTestList.add(GlobalProperty.MENUICON); + enumTestList.add(GlobalProperty.KEYBOARDPROPERTIES); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HmiLevelTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HmiLevelTests.java new file mode 100644 index 000000000..b64f9e42b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HmiLevelTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.smartdevicelink.proxy.rpc.enums.HMILevel; + +import junit.framework.TestCase; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.HmiLevel} + */ +public class HmiLevelTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "FULL"; + HMILevel enumFull = HMILevel.valueForString(example); + example = "LIMITED"; + HMILevel enumLimited = HMILevel.valueForString(example); + example = "BACKGROUND"; + HMILevel enumBackground = HMILevel.valueForString(example); + example = "NONE"; + HMILevel enumNone = HMILevel.valueForString(example); + + assertNotNull("FULL returned null", enumFull); + assertNotNull("LIMITED returned null", enumLimited); + assertNotNull("BACKGROUND returned null", enumBackground); + assertNotNull("NONE returned null", enumNone); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "fUlL"; + try { + HMILevel temp = HMILevel.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + HMILevel temp = HMILevel.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of HMILevel. + */ + public void testListEnum() { + List<HMILevel> enumValueList = Arrays.asList(HMILevel.values()); + + List<HMILevel> enumTestList = new ArrayList<HMILevel>(); + enumTestList.add(HMILevel.HMI_FULL); + enumTestList.add(HMILevel.HMI_LIMITED); + enumTestList.add(HMILevel.HMI_BACKGROUND); + enumTestList.add(HMILevel.HMI_NONE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HmiZoneCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HmiZoneCapabilitiesTests.java new file mode 100644 index 000000000..ebe8227c2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HmiZoneCapabilitiesTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.HmiZoneCapabilities; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.HmiZoneCapabilities} + */ +public class HmiZoneCapabilitiesTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "FRONT"; + HmiZoneCapabilities enumFront = HmiZoneCapabilities.valueForString(example); + example = "BACK"; + HmiZoneCapabilities enumBack = HmiZoneCapabilities.valueForString(example); + + assertNotNull("FRONT returned null", enumFront); + assertNotNull("BACK returned null", enumBack); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "fROnT"; + try { + HmiZoneCapabilities temp = HmiZoneCapabilities.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + HmiZoneCapabilities temp = HmiZoneCapabilities.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of HmiZoneCapabilities. + */ + public void testListEnum() { + List<HmiZoneCapabilities> enumValueList = Arrays.asList(HmiZoneCapabilities.values()); + + List<HmiZoneCapabilities> enumTestList = new ArrayList<HmiZoneCapabilities>(); + enumTestList.add(HmiZoneCapabilities.FRONT); + enumTestList.add(HmiZoneCapabilities.BACK); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HybridAppPreferenceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HybridAppPreferenceTests.java new file mode 100644 index 000000000..89485a974 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/HybridAppPreferenceTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.HybridAppPreference; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.HybridAppPreference} + */ +public class HybridAppPreferenceTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "MOBILE"; + HybridAppPreference enumMobile = HybridAppPreference.valueForString(example); + example = "CLOUD"; + HybridAppPreference enumCloud = HybridAppPreference.valueForString(example); + example = "BOTH"; + HybridAppPreference enumBoth = HybridAppPreference.valueForString(example); + + assertNotNull("MOBILE returned null", enumMobile); + assertNotNull("CLOUD returned null", enumCloud); + assertNotNull("BOTH returned null", enumBoth); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "deFaUlt"; + try { + HybridAppPreference temp = HybridAppPreference.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + HybridAppPreference temp = HybridAppPreference.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of HybridAppPreference. + */ + public void testListEnum() { + List<HybridAppPreference> enumValueList = Arrays.asList(HybridAppPreference.values()); + + List<HybridAppPreference> enumTestList = new ArrayList<>(); + enumTestList.add(HybridAppPreference.MOBILE); + enumTestList.add(HybridAppPreference.CLOUD); + enumTestList.add(HybridAppPreference.BOTH); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/IgnitionStableStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/IgnitionStableStatusTests.java new file mode 100644 index 000000000..fc9a8658a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/IgnitionStableStatusTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.IgnitionStableStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.IgnitionStableStatus} + */ +public class IgnitionStableStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "IGNITION_SWITCH_NOT_STABLE"; + IgnitionStableStatus enumIgnitionSwitchNotStable = IgnitionStableStatus.valueForString(example); + example = "IGNITION_SWITCH_STABLE"; + IgnitionStableStatus enumIgnitionSwitchStable = IgnitionStableStatus.valueForString(example); + example = "MISSING_FROM_TRANSMITTER"; + IgnitionStableStatus enumMissingFromTransmitter = IgnitionStableStatus.valueForString(example); + + assertNotNull("IGNITION_SWITCH_NOT_STABLE returned null", enumIgnitionSwitchNotStable); + assertNotNull("IGNITION_SWITCH_STABLE returned null", enumIgnitionSwitchStable); + assertNotNull("MISSING_FROM_TRANSMITTER returned null", enumMissingFromTransmitter); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "iGnitIoN_SwiTch_NoT_StablE"; + try { + IgnitionStableStatus temp = IgnitionStableStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + IgnitionStableStatus temp = IgnitionStableStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of IgnitionStableStatus. + */ + public void testListEnum() { + List<IgnitionStableStatus> enumValueList = Arrays.asList(IgnitionStableStatus.values()); + + List<IgnitionStableStatus> enumTestList = new ArrayList<IgnitionStableStatus>(); + enumTestList.add(IgnitionStableStatus.IGNITION_SWITCH_NOT_STABLE); + enumTestList.add(IgnitionStableStatus.IGNITION_SWITCH_STABLE); + enumTestList.add(IgnitionStableStatus.MISSING_FROM_TRANSMITTER); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/IgnitionStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/IgnitionStatusTests.java new file mode 100644 index 000000000..8fc1992ab --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/IgnitionStatusTests.java @@ -0,0 +1,87 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.IgnitionStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.IgnitionStatus} + */ +public class IgnitionStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "UNKNOWN"; + IgnitionStatus enumUnknown = IgnitionStatus.valueForString(example); + example = "OFF"; + IgnitionStatus enumOff = IgnitionStatus.valueForString(example); + example = "ACCESSORY"; + IgnitionStatus enumAccessory = IgnitionStatus.valueForString(example); + example = "RUN"; + IgnitionStatus enumRun = IgnitionStatus.valueForString(example); + example = "START"; + IgnitionStatus enumStart = IgnitionStatus.valueForString(example); + example = "INVALID"; + IgnitionStatus enumInvalid = IgnitionStatus.valueForString(example); + + assertNotNull("UNKNOWN returned null", enumUnknown); + assertNotNull("OFF returned null", enumOff); + assertNotNull("ACCESSORY returned null", enumAccessory); + assertNotNull("RUN returned null", enumRun); + assertNotNull("START returned null", enumStart); + assertNotNull("INVALID returned null", enumInvalid); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "uNKnowN"; + try { + IgnitionStatus temp = IgnitionStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + IgnitionStatus temp = IgnitionStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of IgnitionStatus. + */ + public void testListEnum() { + List<IgnitionStatus> enumValueList = Arrays.asList(IgnitionStatus.values()); + + List<IgnitionStatus> enumTestList = new ArrayList<IgnitionStatus>(); + enumTestList.add(IgnitionStatus.UNKNOWN); + enumTestList.add(IgnitionStatus.OFF); + enumTestList.add(IgnitionStatus.ACCESSORY); + enumTestList.add(IgnitionStatus.RUN); + enumTestList.add(IgnitionStatus.START); + enumTestList.add(IgnitionStatus.INVALID); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ImageFieldNameTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ImageFieldNameTests.java new file mode 100644 index 000000000..aa2c1cbf1 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ImageFieldNameTests.java @@ -0,0 +1,115 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.ImageFieldName; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.ImageFieldName} + */ +public class ImageFieldNameTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "softButtonImage"; + ImageFieldName enumSoftButtonImage = ImageFieldName.valueForString(example); + example = "choiceImage"; + ImageFieldName enumChoiceImage = ImageFieldName.valueForString(example); + example = "choiceSecondaryImage"; + ImageFieldName enumSecondaryImage = ImageFieldName.valueForString(example); + example = "vrHelpItem"; + ImageFieldName enumVrHelpItem = ImageFieldName.valueForString(example); + example = "turnIcon"; + ImageFieldName enumTurnIcon = ImageFieldName.valueForString(example); + example = "menuIcon"; + ImageFieldName enumMenuIcon = ImageFieldName.valueForString(example); + example = "cmdIcon"; + ImageFieldName enumCmdIcon = ImageFieldName.valueForString(example); + example = "appIcon"; + ImageFieldName enumAppIcon = ImageFieldName.valueForString(example); + example = "graphic"; + ImageFieldName enumGraphicIcon = ImageFieldName.valueForString(example); + example = "showConstantTBTIcon"; + ImageFieldName enumShowConstantTbtIcon = ImageFieldName.valueForString(example); + example = "showConstantTBTNextTurnIcon"; + ImageFieldName enumShowConstantTbtNextTurnIcon = ImageFieldName.valueForString(example); + example = "locationImage"; + ImageFieldName enumLocationImage = ImageFieldName.valueForString(example); + example = "secondaryGraphic"; + ImageFieldName enumSecondaryGraphic = ImageFieldName.valueForString(example); + + assertNotNull("softButtonImage returned null", enumSoftButtonImage); + assertNotNull("choiceImage returned null", enumChoiceImage); + assertNotNull("choiceSecondaryImage returned null", enumSecondaryImage); + assertNotNull("vrHelpItem returned null", enumVrHelpItem); + assertNotNull("turnIcon returned null", enumTurnIcon); + assertNotNull("menuIcon returned null", enumMenuIcon); + assertNotNull("cmdIcon returned null", enumCmdIcon); + assertNotNull("appIcon returned null", enumAppIcon); + assertNotNull("graphic returned null", enumGraphicIcon); + assertNotNull("showConstantTBTIcon returned null", enumShowConstantTbtIcon); + assertNotNull("showConstantTBTNextTurnIcon returned null", enumShowConstantTbtNextTurnIcon); + assertNotNull("location image returned null", enumLocationImage); + assertNotNull("secondary graphic returned null", enumSecondaryGraphic); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "sofTbUtTOnImagE"; + try { + ImageFieldName temp = ImageFieldName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ImageFieldName temp = ImageFieldName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of ImageFieldName. + */ + public void testListEnum() { + List<ImageFieldName> enumValueList = Arrays.asList(ImageFieldName.values()); + + List<ImageFieldName> enumTestList = new ArrayList<ImageFieldName>(); + enumTestList.add(ImageFieldName.softButtonImage); + enumTestList.add(ImageFieldName.choiceImage); + enumTestList.add(ImageFieldName.choiceSecondaryImage); + enumTestList.add(ImageFieldName.vrHelpItem); + enumTestList.add(ImageFieldName.turnIcon); + enumTestList.add(ImageFieldName.menuIcon); + enumTestList.add(ImageFieldName.cmdIcon); + enumTestList.add(ImageFieldName.appIcon); + enumTestList.add(ImageFieldName.graphic); + enumTestList.add(ImageFieldName.showConstantTBTIcon); + enumTestList.add(ImageFieldName.showConstantTBTNextTurnIcon); + enumTestList.add(ImageFieldName.locationImage); + enumTestList.add(ImageFieldName.secondaryGraphic); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ImageTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ImageTypeTests.java new file mode 100644 index 000000000..fb3f609f3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ImageTypeTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.ImageType; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.ImageType} + */ +public class ImageTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "STATIC"; + ImageType enumStatic = ImageType.valueForString(example); + example = "DYNAMIC"; + ImageType enumDynamic = ImageType.valueForString(example); + + assertNotNull("STATIC returned null", enumStatic); + assertNotNull("DYNAMIC returned null", enumDynamic); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "sTatIc"; + try { + ImageType temp = ImageType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ImageType temp = ImageType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of ImageType. + */ + public void testListEnum() { + List<ImageType> enumValueList = Arrays.asList(ImageType.values()); + + List<ImageType> enumTestList = new ArrayList<ImageType>(); + enumTestList.add(ImageType.STATIC); + enumTestList.add(ImageType.DYNAMIC); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/InteractionModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/InteractionModeTests.java new file mode 100644 index 000000000..ab6490cea --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/InteractionModeTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.InteractionMode; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.InteractionMode} + */ +public class InteractionModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "MANUAL_ONLY"; + InteractionMode enumManualOnly = InteractionMode.valueForString(example); + example = "VR_ONLY"; + InteractionMode enumVrOnly = InteractionMode.valueForString(example); + example = "BOTH"; + InteractionMode enumBoth = InteractionMode.valueForString(example); + + assertNotNull("MANUAL_ONLY returned null", enumManualOnly); + assertNotNull("VR_ONLY returned null", enumVrOnly); + assertNotNull("BOTH returned null", enumBoth); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "maNuAL_OnlY"; + try { + InteractionMode temp = InteractionMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + InteractionMode temp = InteractionMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of InteractionMode. + */ + public void testListEnum() { + List<InteractionMode> enumValueList = Arrays.asList(InteractionMode.values()); + + List<InteractionMode> enumTestList = new ArrayList<InteractionMode>(); + enumTestList.add(InteractionMode.MANUAL_ONLY); + enumTestList.add(InteractionMode.VR_ONLY); + enumTestList.add(InteractionMode.BOTH); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/JingleTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/JingleTests.java new file mode 100644 index 000000000..da5ea2836 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/JingleTests.java @@ -0,0 +1,83 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.Jingle; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.Jingle} + */ +public class JingleTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + + String example = "POSITIVE_JINGLE"; + Jingle enumPositiveJingle = Jingle.valueForString(example); + example = "NEGATIVE_JINGLE"; + Jingle enumNegativeJingle = Jingle.valueForString(example); + example = "INITIAL_JINGLE"; + Jingle enumInitialJingle = Jingle.valueForString(example); + example = "LISTEN_JINGLE"; + Jingle enumListenJingle = Jingle.valueForString(example); + example = "HELP_JINGLE"; + Jingle enumHelpJingle = Jingle.valueForString(example); + + assertNotNull("POSITIVE_JINGLE returned null", enumPositiveJingle); + assertNotNull("NEGATIVE_JINGLE returned null", enumNegativeJingle); + assertNotNull("INITIAL_JINGLE returned null", enumInitialJingle); + assertNotNull("LISTEN_JINGLE returned null", enumListenJingle); + assertNotNull("HELP_JINGLE returned null", enumHelpJingle); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "posITive_JiGLE"; + try { + Jingle temp = Jingle.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + Jingle temp = Jingle.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of Jingle. + */ + public void testListEnums () { + List<Jingle> enumValueList = Arrays.asList(Jingle.values()); + List<Jingle> enumTestList = new ArrayList<Jingle>(); + + enumTestList.add(Jingle.HELP); + enumTestList.add(Jingle.INITIAL); + enumTestList.add(Jingle.LISTEN); + enumTestList.add(Jingle.NEGATIVE); + enumTestList.add(Jingle.POSITIVE); + + assertTrue("Enum value list does not match neum class list.", + enumValueList.containsAll(enumTestList) && + enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeyboardEventTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeyboardEventTests.java new file mode 100644 index 000000000..71448acf6 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeyboardEventTests.java @@ -0,0 +1,83 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.KeyboardEvent; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.KeyboardEvent} + */ +public class KeyboardEventTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "KEYPRESS"; + KeyboardEvent enumKeypress = KeyboardEvent.valueForString(example); + example = "ENTRY_SUBMITTED"; + KeyboardEvent enumEntrySubmitted = KeyboardEvent.valueForString(example); + example = "ENTRY_CANCELLED"; + KeyboardEvent enumEntryCancelled = KeyboardEvent.valueForString(example); + example = "ENTRY_ABORTED"; + KeyboardEvent enumEntryAborted = KeyboardEvent.valueForString(example); + example = "ENTRY_VOICE"; + KeyboardEvent enumEntryVoice = KeyboardEvent.valueForString(example); + + assertNotNull("KEYPRESS returned null", enumKeypress); + assertNotNull("ENTRY_SUBMITTED returned null", enumEntrySubmitted); + assertNotNull("ENTRY_CANCELLED returned null", enumEntryCancelled); + assertNotNull("ENTRY_ABORTED returned null", enumEntryAborted); + assertNotNull("ENTRY_VOICE returned null", enumEntryVoice); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "keyPreSS"; + try { + KeyboardEvent temp = KeyboardEvent.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + KeyboardEvent temp = KeyboardEvent.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of KeyboardEvent. + */ + public void testListEnum() { + List<KeyboardEvent> enumValueList = Arrays.asList(KeyboardEvent.values()); + + List<KeyboardEvent> enumTestList = new ArrayList<KeyboardEvent>(); + enumTestList.add(KeyboardEvent.KEYPRESS); + enumTestList.add(KeyboardEvent.ENTRY_SUBMITTED); + enumTestList.add(KeyboardEvent.ENTRY_CANCELLED); + enumTestList.add(KeyboardEvent.ENTRY_ABORTED); + enumTestList.add(KeyboardEvent.ENTRY_VOICE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeyboardLayoutTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeyboardLayoutTests.java new file mode 100644 index 000000000..14d61aa51 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeyboardLayoutTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.KeyboardLayout; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.KeyboardLayout} + */ +public class KeyboardLayoutTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "QWERTY"; + KeyboardLayout enumQwerty = KeyboardLayout.valueForString(example); + example = "QWERTZ"; + KeyboardLayout enumQwertz = KeyboardLayout.valueForString(example); + example = "AZERTY"; + KeyboardLayout enumAzerty = KeyboardLayout.valueForString(example); + + assertNotNull("QWERTY returned null", enumQwerty); + assertNotNull("QWERTZ returned null", enumQwertz); + assertNotNull("AZERTY returned null", enumAzerty); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "qWerTY"; + try { + KeyboardLayout temp = KeyboardLayout.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + KeyboardLayout temp = KeyboardLayout.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of KeyboardLayout. + */ + public void testListEnum() { + List<KeyboardLayout> enumValueList = Arrays.asList(KeyboardLayout.values()); + + List<KeyboardLayout> enumTestList = new ArrayList<KeyboardLayout>(); + enumTestList.add(KeyboardLayout.QWERTY); + enumTestList.add(KeyboardLayout.QWERTZ); + enumTestList.add(KeyboardLayout.AZERTY); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeypressModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeypressModeTests.java new file mode 100644 index 000000000..8bd652969 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/KeypressModeTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.KeypressMode; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.KeypressMode} + */ +public class KeypressModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "SINGLE_KEYPRESS"; + KeypressMode enumSingleKeypress = KeypressMode.valueForString(example); + example = "QUEUE_KEYPRESSES"; + KeypressMode enumQueueKeypresses = KeypressMode.valueForString(example); + example = "RESEND_CURRENT_ENTRY"; + KeypressMode enumResendCurrentEntry = KeypressMode.valueForString(example); + + assertNotNull("SINGLE_KEYPRESS returned null", enumSingleKeypress); + assertNotNull("QUEUE_KEYPRESSES returned null", enumQueueKeypresses); + assertNotNull("RESEND_CURRENT_ENTRY returned null", enumResendCurrentEntry); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "sIngLe_KeyPrESs"; + try { + KeypressMode temp = KeypressMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + KeypressMode temp = KeypressMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of KeypressMode. + */ + public void testListEnum() { + List<KeypressMode> enumValueList = Arrays.asList(KeypressMode.values()); + + List<KeypressMode> enumTestList = new ArrayList<KeypressMode>(); + enumTestList.add(KeypressMode.SINGLE_KEYPRESS); + enumTestList.add(KeypressMode.QUEUE_KEYPRESSES); + enumTestList.add(KeypressMode.RESEND_CURRENT_ENTRY); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LanguageTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LanguageTests.java new file mode 100644 index 000000000..6b87c5d26 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LanguageTests.java @@ -0,0 +1,220 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.Language; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.Language} + */ +public class LanguageTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "EN-US"; + Language enumEnUs = Language.valueForString(example); + example = "EN-SA"; + Language enumEnSa = Language.valueForString(example); + example = "HE-IL"; + Language enumHeIl = Language.valueForString(example); + example = "RO-RO"; + Language enumRoRo = Language.valueForString(example); + example = "UK-UA"; + Language enumUkUa = Language.valueForString(example); + example = "ID-ID"; + Language enumIdId = Language.valueForString(example); + example = "VI-VN"; + Language enumViVn = Language.valueForString(example); + example = "MS-MY"; + Language enumMsMy = Language.valueForString(example); + example = "HI-IN"; + Language enumHiIn = Language.valueForString(example); + example = "NL-BE"; + Language enumNlBe = Language.valueForString(example); + example = "EL-GR"; + Language enumElGr = Language.valueForString(example); + example = "HU-HU"; + Language enumHuHu = Language.valueForString(example); + example = "FI-FI"; + Language enumFiFi = Language.valueForString(example); + example = "SK-SK"; + Language enumSkSk = Language.valueForString(example); + example = "ES-MX"; + Language enumEsMx = Language.valueForString(example); + example = "FR-CA"; + Language enumFrCa = Language.valueForString(example); + example = "DE-DE"; + Language enumDeDe = Language.valueForString(example); + example = "ES-ES"; + Language enumEsEs = Language.valueForString(example); + example = "EN-GB"; + Language enumEnGb = Language.valueForString(example); + example = "RU-RU"; + Language enumRuRu = Language.valueForString(example); + example = "TR-TR"; + Language enumTrTr = Language.valueForString(example); + example = "PL-PL"; + Language enumPlPl = Language.valueForString(example); + example = "FR-FR"; + Language enumFrFr = Language.valueForString(example); + example = "IT-IT"; + Language enumItIt = Language.valueForString(example); + example = "SV-SE"; + Language enumSvSe = Language.valueForString(example); + example = "PT-PT"; + Language enumPtPt = Language.valueForString(example); + example = "NL-NL"; + Language enumNlNl = Language.valueForString(example); + example = "EN-AU"; + Language enumEnAu = Language.valueForString(example); + example = "ZH-CN"; + Language enumZhCn = Language.valueForString(example); + example = "ZH-TW"; + Language enumZhTw = Language.valueForString(example); + example = "JA-JP"; + Language enumJaJp = Language.valueForString(example); + example = "AR-SA"; + Language enumArSa = Language.valueForString(example); + example = "KO-KR"; + Language enumKoKr = Language.valueForString(example); + example = "PT-BR"; + Language enumPtBr = Language.valueForString(example); + example = "CS-CZ"; + Language enumCsCz = Language.valueForString(example); + example = "DA-DK"; + Language enumDaDk = Language.valueForString(example); + example = "NO-NO"; + Language enumNoNo = Language.valueForString(example); + example = "EN-IN"; + Language enumEnIn = Language.valueForString(example); + example = "TH-TH"; + Language enumThTh = Language.valueForString(example); + + assertNotNull("EN-US returned null", enumEnUs); + assertNotNull("EN-SA returned null", enumEnSa); + assertNotNull("HE-IL returned null", enumHeIl); + assertNotNull("RO-RO returned null", enumRoRo); + assertNotNull("UK-UA returned null", enumUkUa); + assertNotNull("ID-ID returned null", enumIdId); + assertNotNull("VI-VN returned null", enumViVn); + assertNotNull("MS-MY returned null", enumMsMy); + assertNotNull("HI-IN returned null", enumHiIn); + assertNotNull("NL-BE returned null", enumNlBe); + assertNotNull("EL-GR returned null", enumElGr); + assertNotNull("HU-HU returned null", enumHuHu); + assertNotNull("FI-FI returned null", enumFiFi); + assertNotNull("SK-SK returned null", enumSkSk); + assertNotNull("ES-MX returned null", enumEsMx); + assertNotNull("FR-CA returned null", enumFrCa); + assertNotNull("DE-DE returned null", enumDeDe); + assertNotNull("ES-ES returned null", enumEsEs); + assertNotNull("EN-GB returned null", enumEnGb); + assertNotNull("RU-RU returned null", enumRuRu); + assertNotNull("TR-TR returned null", enumTrTr); + assertNotNull("PL-PL returned null", enumPlPl); + assertNotNull("FR-FR returned null", enumFrFr); + assertNotNull("IT-IT returned null", enumItIt); + assertNotNull("SV-SE returned null", enumSvSe); + assertNotNull("PT-PT returned null", enumPtPt); + assertNotNull("NL-NL returned null", enumNlNl); + assertNotNull("EN-AU returned null", enumEnAu); + assertNotNull("ZH-CN returned null", enumZhCn); + assertNotNull("ZH-TW returned null", enumZhTw); + assertNotNull("JA-JP returned null", enumJaJp); + assertNotNull("AR-SA returned null", enumArSa); + assertNotNull("KO-KR returned null", enumKoKr); + assertNotNull("PT-BR returned null", enumPtBr); + assertNotNull("CS-CZ returned null", enumCsCz); + assertNotNull("DA-DK returned null", enumDaDk); + assertNotNull("NO-NO returned null", enumNoNo); + assertNotNull("EN-IN returned null", enumEnIn); + assertNotNull("TH-TH returned null", enumThTh); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "eN-Us"; + try { + Language temp = Language.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + Language temp = Language.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of Language. + */ + public void testListEnum() { + List<Language> enumValueList = Arrays.asList(Language.values()); + + List<Language> enumTestList = new ArrayList<Language>(); + + enumTestList.add(Language.EN_US); + enumTestList.add(Language.EN_SA); + enumTestList.add(Language.HE_IL); + enumTestList.add(Language.RO_RO); + enumTestList.add(Language.UK_UA); + enumTestList.add(Language.ID_ID); + enumTestList.add(Language.VI_VN); + enumTestList.add(Language.MS_MY); + enumTestList.add(Language.HI_IN); + enumTestList.add(Language.NL_BE); + enumTestList.add(Language.EL_GR); + enumTestList.add(Language.HU_HU); + enumTestList.add(Language.FI_FI); + enumTestList.add(Language.SK_SK); + enumTestList.add(Language.ES_MX); + enumTestList.add(Language.FR_CA); + enumTestList.add(Language.DE_DE); + enumTestList.add(Language.ES_ES); + enumTestList.add(Language.EN_GB); + enumTestList.add(Language.RU_RU); + enumTestList.add(Language.TR_TR); + enumTestList.add(Language.PL_PL); + enumTestList.add(Language.FR_FR); + enumTestList.add(Language.IT_IT); + enumTestList.add(Language.SV_SE); + enumTestList.add(Language.PT_PT); + enumTestList.add(Language.NL_NL); + enumTestList.add(Language.EN_AU); + enumTestList.add(Language.ZH_CN); + enumTestList.add(Language.ZH_TW); + enumTestList.add(Language.JA_JP); + enumTestList.add(Language.AR_SA); + enumTestList.add(Language.KO_KR); + enumTestList.add(Language.PT_BR); + enumTestList.add(Language.CS_CZ); + enumTestList.add(Language.DA_DK); + enumTestList.add(Language.NO_NO); + enumTestList.add(Language.EN_IN); + enumTestList.add(Language.TH_TH); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LayoutModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LayoutModeTests.java new file mode 100644 index 000000000..904a39520 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LayoutModeTests.java @@ -0,0 +1,84 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.LayoutMode; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.LayoutMode} + */ +public class LayoutModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "ICON_ONLY"; + LayoutMode enumIconOnly = LayoutMode.valueForString(example); + example = "ICON_WITH_SEARCH"; + LayoutMode enumIconWithSearch = LayoutMode.valueForString(example); + example = "LIST_ONLY"; + LayoutMode enumListOnly = LayoutMode.valueForString(example); + example = "LIST_WITH_SEARCH"; + LayoutMode enumListWithSearch = LayoutMode.valueForString(example); + example = "KEYBOARD"; + LayoutMode enumKeyboard = LayoutMode.valueForString(example); + + assertNotNull("ICON_ONLY returned null", enumIconOnly); + assertNotNull("ICON_WITH_SEARCH returned null", enumIconWithSearch); + assertNotNull("LIST_ONLY returned null", enumListOnly); + assertNotNull("LIST_WITH_SEARCH returned null", enumListWithSearch); + assertNotNull("KEYBOARD returned null", enumKeyboard); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "icOn_OnlY"; + try { + LayoutMode temp = LayoutMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + LayoutMode temp = LayoutMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + + /** + * Verifies the possible enum values of LayoutMode. + */ + public void testListEnum() { + List<LayoutMode> enumValueList = Arrays.asList(LayoutMode.values()); + + List<LayoutMode> enumTestList = new ArrayList<LayoutMode>(); + enumTestList.add(LayoutMode.ICON_ONLY); + enumTestList.add(LayoutMode.ICON_WITH_SEARCH); + enumTestList.add(LayoutMode.LIST_ONLY); + enumTestList.add(LayoutMode.LIST_WITH_SEARCH); + enumTestList.add(LayoutMode.KEYBOARD); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LightNameTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LightNameTests.java new file mode 100644 index 000000000..10df1e762 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LightNameTests.java @@ -0,0 +1,261 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.LightName; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.LightName} + */ +public class LightNameTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "FRONT_LEFT_HIGH_BEAM"; + LightName enumFrontLeftHighBeam = LightName.valueForString(example); + example = "FRONT_RIGHT_HIGH_BEAM"; + LightName enumFrontRightHighBeam = LightName.valueForString(example); + example = "FRONT_LEFT_LOW_BEAM"; + LightName enumFrontLeftLowBeam = LightName.valueForString(example); + example = "FRONT_RIGHT_LOW_BEAM"; + LightName enumFrontRightLowBeam = LightName.valueForString(example); + example = "FRONT_LEFT_PARKING_LIGHT"; + LightName enumFrontLeftParkingLight = LightName.valueForString(example); + example = "FRONT_RIGHT_PARKING_LIGHT"; + LightName enumFrontRightParkingLight = LightName.valueForString(example); + example = "FRONT_LEFT_FOG_LIGHT"; + LightName enumFrontLeftFogLight = LightName.valueForString(example); + example = "FRONT_RIGHT_FOG_LIGHT"; + LightName enumFrontRightFogLight = LightName.valueForString(example); + example = "FRONT_LEFT_DAYTIME_RUNNING_LIGHT"; + LightName enumFrontLeftDaytimeRunningLight = LightName.valueForString(example); + example = "FRONT_RIGHT_DAYTIME_RUNNING_LIGHT"; + LightName enumFrontRightDaytimeRunningLight = LightName.valueForString(example); + example = "FRONT_LEFT_TURN_LIGHT"; + LightName enumFrontLeftTurnLight = LightName.valueForString(example); + example = "FRONT_RIGHT_TURN_LIGHT"; + LightName enumFrontRightTurnLight = LightName.valueForString(example); + example = "REAR_LEFT_FOG_LIGHT"; + LightName enumRearLeftFogLight = LightName.valueForString(example); + example = "REAR_RIGHT_FOG_LIGHT"; + LightName enumRearRightFogLight = LightName.valueForString(example); + example = "REAR_LEFT_TAIL_LIGHT"; + LightName enumRearLeftTailLight = LightName.valueForString(example); + example = "REAR_RIGHT_TAIL_LIGHT"; + LightName enumRearRightTailLight = LightName.valueForString(example); + example = "REAR_LEFT_BRAKE_LIGHT"; + LightName enumRearLeftBrakeLight = LightName.valueForString(example); + example = "REAR_RIGHT_BRAKE_LIGHT"; + LightName enumRearRightBrakeLight = LightName.valueForString(example); + example = "REAR_LEFT_TURN_LIGHT"; + LightName enumRearLeftTurnLight = LightName.valueForString(example); + example = "REAR_RIGHT_TURN_LIGHT"; + LightName enumRearRightTurnLight = LightName.valueForString(example); + example = "REAR_REGISTRATION_PLATE_LIGHT"; + LightName enumRearRegistrationPlateLight = LightName.valueForString(example); + example = "HIGH_BEAMS"; + LightName enumHighBeams = LightName.valueForString(example); + example = "LOW_BEAMS"; + LightName enumLowBeams = LightName.valueForString(example); + example = "FOG_LIGHTS"; + LightName enumFogLights = LightName.valueForString(example); + example = "RUNNING_LIGHTS"; + LightName enumRunningLights = LightName.valueForString(example); + example = "PARKING_LIGHTS"; + LightName enumParkingLights = LightName.valueForString(example); + example = "BRAKE_LIGHTS"; + LightName enumBrakeLights = LightName.valueForString(example); + example = "REAR_REVERSING_LIGHTS"; + LightName enumRearReversingLights = LightName.valueForString(example); + example = "SIDE_MARKER_LIGHTS"; + LightName enumSideMarkerLights = LightName.valueForString(example); + example = "LEFT_TURN_LIGHTS"; + LightName enumLeftTurnLights = LightName.valueForString(example); + example = "RIGHT_TURN_LIGHTS"; + LightName enumRightTurnLights = LightName.valueForString(example); + example = "HAZARD_LIGHTS"; + LightName enumHazardLights = LightName.valueForString(example); + + example = "REAR_CARGO_LIGHTS"; + LightName enumRearCargoLights = LightName.valueForString(example); + example = "REAR_TRUCK_BED_LIGHTS"; + LightName enumRearTruckBedLights = LightName.valueForString(example); + example = "REAR_TRAILER_LIGHTS"; + LightName enumRearTrailerLights = LightName.valueForString(example); + example = "LEFT_SPOT_LIGHTS"; + LightName enumLeftSpotLights = LightName.valueForString(example); + example = "RIGHT_SPOT_LIGHTS"; + LightName enumRightSpotLights = LightName.valueForString(example); + example = "LEFT_PUDDLE_LIGHTS"; + LightName enumLeftPuddleLights = LightName.valueForString(example); + example = "RIGHT_PUDDLE_LIGHTS"; + LightName enumRightPuddleLights = LightName.valueForString(example); + example = "AMBIENT_LIGHTS"; + LightName enumAmbientLights = LightName.valueForString(example); + example = "OVERHEAD_LIGHTS"; + LightName enumOverheadLights = LightName.valueForString(example); + example = "READING_LIGHTS"; + LightName enumReadingLights = LightName.valueForString(example); + example = "TRUNK_LIGHTS"; + LightName enumTrunkLights = LightName.valueForString(example); + example = "EXTERIOR_FRONT_LIGHTS"; + LightName enumExteriorFrontLights = LightName.valueForString(example); + example = "EXTERIOR_REAR_LIGHTS"; + LightName enumExteriorRearLights = LightName.valueForString(example); + example = "EXTERIOR_LEFT_LIGHTS"; + LightName enumExteriorLeftLights = LightName.valueForString(example); + example = "EXTERIOR_RIGHT_LIGHTS"; + LightName enumExteriorRightLights = LightName.valueForString(example); + example = "EXTERIOR_ALL_LIGHTS"; + LightName enumExteriorAllLights = LightName.valueForString(example); + + assertNotNull("FRONT_LEFT_HIGH_BEAM returned null", enumFrontLeftHighBeam); + assertNotNull("FRONT_RIGHT_HIGH_BEAM returned null", enumFrontRightHighBeam); + assertNotNull("FRONT_LEFT_LOW_BEAM returned null", enumFrontLeftLowBeam); + assertNotNull("FRONT_RIGHT_LOW_BEAM returned null", enumFrontRightLowBeam); + assertNotNull("FRONT_LEFT_PARKING_LIGHT returned null", enumFrontLeftParkingLight); + assertNotNull("FRONT_RIGHT_PARKING_LIGHT returned null", enumFrontRightParkingLight); + assertNotNull("FRONT_LEFT_FOG_LIGHT returned null", enumFrontLeftFogLight); + assertNotNull("FRONT_RIGHT_FOG_LIGHT returned null", enumFrontRightFogLight); + assertNotNull("FRONT_LEFT_DAYTIME_RUNNING_LIGHT returned null", enumFrontLeftDaytimeRunningLight); + assertNotNull("FRONT_RIGHT_DAYTIME_RUNNING_LIGHT returned null", enumFrontRightDaytimeRunningLight); + + assertNotNull("FRONT_LEFT_TURN_LIGHT returned null", enumFrontLeftTurnLight); + assertNotNull("FRONT_RIGHT_TURN_LIGHT returned null", enumFrontRightTurnLight); + assertNotNull("REAR_LEFT_FOG_LIGHT returned null", enumRearLeftFogLight); + assertNotNull("REAR_RIGHT_FOG_LIGHT returned null", enumRearRightFogLight); + assertNotNull("REAR_LEFT_TAIL_LIGHT returned null", enumRearLeftTailLight); + assertNotNull("REAR_RIGHT_TAIL_LIGHT returned null", enumRearRightTailLight); + assertNotNull("REAR_LEFT_BRAKE_LIGHT returned null", enumRearLeftBrakeLight); + assertNotNull("REAR_RIGHT_BRAKE_LIGHT returned null", enumRearRightBrakeLight); + assertNotNull("REAR_LEFT_TURN_LIGHT returned null", enumRearLeftTurnLight); + assertNotNull("REAR_RIGHT_TURN_LIGHT returned null", enumRearRightTurnLight); + assertNotNull("REAR_REGISTRATION_PLATE_LIGHT returned null", enumRearRegistrationPlateLight); + + assertNotNull("HIGH_BEAMS returned null", enumHighBeams); + assertNotNull("LOW_BEAMS returned null", enumLowBeams); + assertNotNull("FOG_LIGHTS returned null", enumFogLights); + assertNotNull("RUNNING_LIGHTS returned null", enumRunningLights); + assertNotNull("PARKING_LIGHTS returned null", enumParkingLights); + assertNotNull("BRAKE_LIGHTS returned null", enumBrakeLights); + + assertNotNull("REAR_REVERSING_LIGHTS returned null", enumRearReversingLights); + assertNotNull("SIDE_MARKER_LIGHTS returned null", enumSideMarkerLights); + assertNotNull("LEFT_TURN_LIGHTS returned null", enumLeftTurnLights); + assertNotNull("RIGHT_TURN_LIGHTS returned null", enumRightTurnLights); + assertNotNull("HAZARD_LIGHTS returned null", enumHazardLights); + assertNotNull("REAR_CARGO_LIGHTS returned null", enumRearCargoLights); + assertNotNull("REAR_TRUCK_BED_LIGHTS returned null", enumRearTruckBedLights); + assertNotNull("REAR_TRAILER_LIGHTS returned null", enumRearTrailerLights); + assertNotNull("LEFT_SPOT_LIGHTS returned null", enumLeftSpotLights); + assertNotNull("RIGHT_SPOT_LIGHTS returned null", enumRightSpotLights); + assertNotNull("LEFT_PUDDLE_LIGHTS returned null", enumLeftPuddleLights); + assertNotNull("RIGHT_PUDDLE_LIGHTS returned null", enumRightPuddleLights); + + assertNotNull("AMBIENT_LIGHTS returned null", enumAmbientLights); + assertNotNull("OVERHEAD_LIGHTS returned null", enumOverheadLights); + assertNotNull("READING_LIGHTS returned null", enumReadingLights); + assertNotNull("TRUNK_LIGHTS returned null", enumTrunkLights); + + assertNotNull("EXTERIOR_FRONT_LIGHTS returned null", enumExteriorFrontLights); + assertNotNull("EXTERIOR_REAR_LIGHTS returned null", enumExteriorRearLights); + assertNotNull("EXTERIOR_LEFT_LIGHTS returned null", enumExteriorLeftLights); + assertNotNull("EXTERIOR_RIGHT_LIGHTS returned null", enumExteriorRightLights); + + assertNotNull("EXTERIOR_ALL_LIGHTS returned null", enumExteriorAllLights); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "fRONT_LEFT_HIGH_BEAM"; + try { + LightName temp = LightName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + LightName temp = LightName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of LightName. + */ + public void testListEnum() { + List<LightName> enumValueList = Arrays.asList(LightName.values()); + + List<LightName> enumTestList = new ArrayList<LightName>(); + enumTestList.add(LightName.FRONT_LEFT_HIGH_BEAM); + enumTestList.add(LightName.FRONT_RIGHT_HIGH_BEAM); + enumTestList.add(LightName.FRONT_LEFT_LOW_BEAM); + enumTestList.add(LightName.FRONT_RIGHT_LOW_BEAM); + enumTestList.add(LightName.FRONT_LEFT_PARKING_LIGHT); + enumTestList.add(LightName.FRONT_RIGHT_PARKING_LIGHT); + enumTestList.add(LightName.FRONT_LEFT_FOG_LIGHT); + enumTestList.add(LightName.FRONT_RIGHT_FOG_LIGHT); + enumTestList.add(LightName.FRONT_LEFT_DAYTIME_RUNNING_LIGHT); + enumTestList.add(LightName.FRONT_RIGHT_DAYTIME_RUNNING_LIGHT); + enumTestList.add(LightName.FRONT_LEFT_TURN_LIGHT); + enumTestList.add(LightName.FRONT_RIGHT_TURN_LIGHT); + enumTestList.add(LightName.REAR_LEFT_FOG_LIGHT); + enumTestList.add(LightName.REAR_RIGHT_FOG_LIGHT); + enumTestList.add(LightName.REAR_LEFT_TAIL_LIGHT); + enumTestList.add(LightName.REAR_RIGHT_TAIL_LIGHT); + enumTestList.add(LightName.REAR_LEFT_BRAKE_LIGHT); + enumTestList.add(LightName.REAR_RIGHT_BRAKE_LIGHT); + enumTestList.add(LightName.REAR_LEFT_TURN_LIGHT); + enumTestList.add(LightName.REAR_RIGHT_TURN_LIGHT); + enumTestList.add(LightName.REAR_REGISTRATION_PLATE_LIGHT); + enumTestList.add(LightName.HIGH_BEAMS); + enumTestList.add(LightName.LOW_BEAMS); + enumTestList.add(LightName.FOG_LIGHTS); + enumTestList.add(LightName.RUNNING_LIGHTS); + enumTestList.add(LightName.PARKING_LIGHTS); + enumTestList.add(LightName.BRAKE_LIGHTS); + enumTestList.add(LightName.REAR_REVERSING_LIGHTS); + enumTestList.add(LightName.SIDE_MARKER_LIGHTS); + enumTestList.add(LightName.LEFT_TURN_LIGHTS); + enumTestList.add(LightName.RIGHT_TURN_LIGHTS); + enumTestList.add(LightName.HAZARD_LIGHTS); + enumTestList.add(LightName.REAR_CARGO_LIGHTS); + enumTestList.add(LightName.REAR_TRUCK_BED_LIGHTS); + enumTestList.add(LightName.REAR_TRAILER_LIGHTS); + enumTestList.add(LightName.LEFT_SPOT_LIGHTS); + enumTestList.add(LightName.RIGHT_SPOT_LIGHTS); + enumTestList.add(LightName.LEFT_PUDDLE_LIGHTS); + enumTestList.add(LightName.RIGHT_PUDDLE_LIGHTS); + enumTestList.add(LightName.AMBIENT_LIGHTS); + enumTestList.add(LightName.OVERHEAD_LIGHTS); + enumTestList.add(LightName.READING_LIGHTS); + enumTestList.add(LightName.TRUNK_LIGHTS); + enumTestList.add(LightName.EXTERIOR_FRONT_LIGHTS); + enumTestList.add(LightName.EXTERIOR_REAR_LIGHTS); + enumTestList.add(LightName.EXTERIOR_LEFT_LIGHTS); + enumTestList.add(LightName.EXTERIOR_RIGHT_LIGHTS); + enumTestList.add(LightName.EXTERIOR_ALL_LIGHTS); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LightStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LightStatusTests.java new file mode 100644 index 000000000..a97cd6eba --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LightStatusTests.java @@ -0,0 +1,86 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.LightStatus; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.LightStatus} + */ +public class LightStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "ON"; + LightStatus enumOn = LightStatus.valueForString(example); + example = "OFF"; + LightStatus enumOff = LightStatus.valueForString(example); + example = "RAMP_UP"; + LightStatus enumRampUp = LightStatus.valueForString(example); + example = "RAMP_DOWN"; + LightStatus enumRampDown = LightStatus.valueForString(example); + example = "UNKNOWN"; + LightStatus enumUnknown = LightStatus.valueForString(example); + example = "INVALID"; + LightStatus enumInvalid = LightStatus.valueForString(example); + + assertNotNull("ON returned null", enumOn); + assertNotNull("OFF returned null", enumOff); + assertNotNull("RAMP_UP returned null", enumRampUp); + assertNotNull("RAMP_DOWN returned null", enumRampDown); + assertNotNull("UNKNOWN returned null", enumUnknown); + assertNotNull("INVALID returned null", enumInvalid); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "oN"; + try { + LightStatus temp = LightStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + LightStatus temp = LightStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of LightStatus. + */ + public void testListEnum() { + List<LightStatus> enumValueList = Arrays.asList(LightStatus.values()); + + List<LightStatus> enumTestList = new ArrayList<LightStatus>(); + enumTestList.add(LightStatus.ON); + enumTestList.add(LightStatus.OFF); + enumTestList.add(LightStatus.RAMP_UP); + enumTestList.add(LightStatus.RAMP_DOWN); + enumTestList.add(LightStatus.UNKNOWN); + enumTestList.add(LightStatus.INVALID); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LockScreenStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LockScreenStatusTests.java new file mode 100644 index 000000000..ed380d607 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/LockScreenStatusTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.LockScreenStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.LockScreenStatus} + */ +public class LockScreenStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "REQUIRED"; + LockScreenStatus enumRequired = LockScreenStatus.valueForString(example); + example = "OPTIONAL"; + LockScreenStatus enumOptional = LockScreenStatus.valueForString(example); + example = "OFF"; + LockScreenStatus enumOff = LockScreenStatus.valueForString(example); + + assertNotNull("REQUIRED returned null", enumRequired); + assertNotNull("OPTIONAL returned null", enumOptional); + assertNotNull("OFF returned null", enumOff); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "ReqUireD"; + try { + LockScreenStatus temp = LockScreenStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + LockScreenStatus temp = LockScreenStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of LockScreenStatus. + */ + public void testListEnum() { + List<LockScreenStatus> enumValueList = Arrays.asList(LockScreenStatus.values()); + + List<LockScreenStatus> enumTestList = new ArrayList<LockScreenStatus>(); + enumTestList.add(LockScreenStatus.REQUIRED); + enumTestList.add(LockScreenStatus.OPTIONAL); + enumTestList.add(LockScreenStatus.OFF); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageCushionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageCushionTests.java new file mode 100644 index 000000000..e1f58ffef --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageCushionTests.java @@ -0,0 +1,81 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.MassageCushion; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.MassageCushion} + */ +public class MassageCushionTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "TOP_LUMBAR"; + MassageCushion enumTopLumbar = MassageCushion.valueForString(example); + example = "MIDDLE_LUMBAR"; + MassageCushion enumMiddleLumbar = MassageCushion.valueForString(example); + example = "BOTTOM_LUMBAR"; + MassageCushion enumBottomLumbar = MassageCushion.valueForString(example); + example = "BACK_BOLSTERS"; + MassageCushion enumBackBolsters = MassageCushion.valueForString(example); + example = "SEAT_BOLSTERS"; + MassageCushion enumSeatBolsters = MassageCushion.valueForString(example); + + assertNotNull("TOP_LUMBAR returned null", enumTopLumbar); + assertNotNull("MIDDLE_LUMBAR returned null", enumMiddleLumbar); + assertNotNull("BOTTOM_LUMBAR returned null", enumBottomLumbar); + assertNotNull("BACK_BOLSTERS returned null", enumBackBolsters); + assertNotNull("SEAT_BOLSTERS returned null", enumSeatBolsters); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "tOP_LUMBAR"; + try { + MassageCushion temp = MassageCushion.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + MassageCushion temp = MassageCushion.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of MassageCushion. + */ + public void testListEnum() { + List<MassageCushion> enumValueList = Arrays.asList(MassageCushion.values()); + + List<MassageCushion> enumTestList = new ArrayList<MassageCushion>(); + enumTestList.add(MassageCushion.TOP_LUMBAR); + enumTestList.add(MassageCushion.MIDDLE_LUMBAR); + enumTestList.add(MassageCushion.BOTTOM_LUMBAR); + enumTestList.add(MassageCushion.BACK_BOLSTERS); + enumTestList.add(MassageCushion.SEAT_BOLSTERS); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageModeTests.java new file mode 100644 index 000000000..55e82ac21 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageModeTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.MassageMode; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.MassageMode} + */ +public class MassageModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "OFF"; + MassageMode enumOff = MassageMode.valueForString(example); + example = "LOW"; + MassageMode enumLow = MassageMode.valueForString(example); + example = "HIGH"; + MassageMode enumHigh = MassageMode.valueForString(example); + + assertNotNull("OFF returned null", enumOff); + assertNotNull("LOW returned null", enumLow); + assertNotNull("HIGH returned null", enumHigh); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "oFF"; + try { + MassageMode temp = MassageMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + MassageMode temp = MassageMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of MassageMode. + */ + public void testListEnum() { + List<MassageMode> enumValueList = Arrays.asList(MassageMode.values()); + + List<MassageMode> enumTestList = new ArrayList<MassageMode>(); + enumTestList.add(MassageMode.OFF); + enumTestList.add(MassageMode.LOW); + enumTestList.add(MassageMode.HIGH); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageZoneTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageZoneTests.java new file mode 100644 index 000000000..bbd543d4e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MassageZoneTests.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.MassageZone; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.MassageZone} + */ +public class MassageZoneTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "LUMBAR"; + MassageZone enumLumbar = MassageZone.valueForString(example); + example = "SEAT_CUSHION"; + MassageZone enumSeatCushion = MassageZone.valueForString(example); + + assertNotNull("LUMBAR returned null", enumLumbar); + assertNotNull("SEAT_CUSHION returned null", enumSeatCushion); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "lUMBAR"; + try { + MassageZone temp = MassageZone.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + MassageZone temp = MassageZone.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of MassageZone. + */ + public void testListEnum() { + List<MassageZone> enumValueList = Arrays.asList(MassageZone.values()); + + List<MassageZone> enumTestList = new ArrayList<MassageZone>(); + enumTestList.add(MassageZone.LUMBAR); + enumTestList.add(MassageZone.SEAT_CUSHION); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MediaClockFormatTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MediaClockFormatTests.java new file mode 100644 index 000000000..1895430e5 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MediaClockFormatTests.java @@ -0,0 +1,91 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.MediaClockFormat; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.MediaClockFormat} + */ +public class MediaClockFormatTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "CLOCK1"; + MediaClockFormat enumClock1 = MediaClockFormat.valueForString(example); + example = "CLOCK2"; + MediaClockFormat enumClock2 = MediaClockFormat.valueForString(example); + example = "CLOCK3"; + MediaClockFormat enumClock3 = MediaClockFormat.valueForString(example); + example = "CLOCKTEXT1"; + MediaClockFormat enumClockText1 = MediaClockFormat.valueForString(example); + example = "CLOCKTEXT2"; + MediaClockFormat enumClockText2 = MediaClockFormat.valueForString(example); + example = "CLOCKTEXT3"; + MediaClockFormat enumClockText3 = MediaClockFormat.valueForString(example); + example = "CLOCKTEXT4"; + MediaClockFormat enumClockText4 = MediaClockFormat.valueForString(example); + + assertNotNull("CLOCK1 returned null", enumClock1); + assertNotNull("CLOCK2 returned null", enumClock2); + assertNotNull("CLOCK3 returned null", enumClock3); + assertNotNull("CLOCKTEXT1 returned null", enumClockText1); + assertNotNull("CLOCKTEXT2 returned null", enumClockText2); + assertNotNull("CLOCKTEXT3 returned null", enumClockText3); + assertNotNull("CLOCKTEXT4 returned null", enumClockText4); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "cloCK1"; + try { + MediaClockFormat temp = MediaClockFormat.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + MediaClockFormat temp = MediaClockFormat.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of MediaClockFormat. + */ + public void testListEnum() { + List<MediaClockFormat> enumValueList = Arrays.asList(MediaClockFormat.values()); + + List<MediaClockFormat> enumTestList = new ArrayList<MediaClockFormat>(); + enumTestList.add(MediaClockFormat.CLOCK1); + enumTestList.add(MediaClockFormat.CLOCK2); + enumTestList.add(MediaClockFormat.CLOCK3); + enumTestList.add(MediaClockFormat.CLOCKTEXT1); + enumTestList.add(MediaClockFormat.CLOCKTEXT2); + enumTestList.add(MediaClockFormat.CLOCKTEXT3); + enumTestList.add(MediaClockFormat.CLOCKTEXT4); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MediaTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MediaTypeTests.java new file mode 100644 index 000000000..835045418 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MediaTypeTests.java @@ -0,0 +1,77 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.MediaType; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.MediaType} + */ +public class MediaTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "MUSIC"; + MediaType enumMusic = MediaType.valueForString(example); + example = "PODCAST"; + MediaType enumPodcast = MediaType.valueForString(example); + example = "AUDIOBOOK"; + MediaType enumAudioBook = MediaType.valueForString(example); + example = "OTHER"; + MediaType enumOther = MediaType.valueForString(example); + + assertNotNull("MUSIC returned null", enumMusic); + assertNotNull("PODCAST returned null", enumPodcast); + assertNotNull("AUDIOBOOK returned null", enumAudioBook); + assertNotNull("OTHER returned null", enumOther); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "PudCAsT"; + try { + MediaType temp = MediaType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + MediaType temp = MediaType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of MediaType. + */ + public void testListEnum() { + List<MediaType> enumValueList = Arrays.asList(MediaType.values()); + + List<MediaType> enumTestList = new ArrayList<MediaType>(); + enumTestList.add(MediaType.MUSIC); + enumTestList.add(MediaType.PODCAST); + enumTestList.add(MediaType.AUDIOBOOK); + enumTestList.add(MediaType.OTHER); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MetadataTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MetadataTypeTests.java new file mode 100644 index 000000000..c381dfff3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/MetadataTypeTests.java @@ -0,0 +1,112 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.MetadataType; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.MetadataTags} + */ + +public class MetadataTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "mediaTitle"; + MetadataType enumMediaTitle = MetadataType.valueForString(example); + example = "mediaArtist"; + MetadataType enumMediaArtist = MetadataType.valueForString(example); + example = "mediaAlbum"; + MetadataType enumMediaAlbum = MetadataType.valueForString(example); + example = "mediaYear"; + MetadataType enumMediaYear = MetadataType.valueForString(example); + example = "mediaGenre"; + MetadataType enumMediaGenre = MetadataType.valueForString(example); + example = "mediaStation"; + MetadataType enumMediaStation = MetadataType.valueForString(example); + example = "rating"; + MetadataType enumRating = MetadataType.valueForString(example); + example = "currentTemperature"; + MetadataType enumCurrentTemperature = MetadataType.valueForString(example); + example = "maximumTemperature"; + MetadataType enumMaximumTemperature = MetadataType.valueForString(example); + example = "minimumTemperature"; + MetadataType enumMinimumTemperature = MetadataType.valueForString(example); + example = "weatherTerm"; + MetadataType enumWeatherTerm = MetadataType.valueForString(example); + example = "humidity"; + MetadataType enumHumidity = MetadataType.valueForString(example); + + + assertNotNull("mediaTitle returned null", enumMediaTitle); + assertNotNull("mediaArtist returned null", enumMediaArtist); + assertNotNull("mediaAlbum returned null", enumMediaAlbum); + assertNotNull("mediaYear returned null", enumMediaYear); + assertNotNull("mediaGenre returned null", enumMediaGenre); + assertNotNull("mediaStation returned null", enumMediaStation); + assertNotNull("rating returned null", enumRating); + assertNotNull("currentTemperature returned null", enumCurrentTemperature); + assertNotNull("maximumTemperature returned null", enumMaximumTemperature); + assertNotNull("minimumTemperature returned null", enumMinimumTemperature); + assertNotNull("weatherTerm returned null", enumWeatherTerm); + assertNotNull("humidity returned null", enumHumidity); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "MEDIA_TITLEZ"; + try { + MetadataType temp = MetadataType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + MetadataType temp = MetadataType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of MetadataType. + */ + public void testListEnum() { + List<MetadataType> enumValueList = Arrays.asList(MetadataType.values()); + + List<MetadataType> enumTestList = new ArrayList<MetadataType>(); + enumTestList.add(MetadataType.MEDIA_TITLE); + enumTestList.add(MetadataType.MEDIA_ARTIST); + enumTestList.add(MetadataType.MEDIA_ALBUM); + enumTestList.add(MetadataType.MEDIA_YEAR); + enumTestList.add(MetadataType.MEDIA_GENRE); + enumTestList.add(MetadataType.MEDIA_STATION); + enumTestList.add(MetadataType.RATING); + enumTestList.add(MetadataType.CURRENT_TEMPERATURE); + enumTestList.add(MetadataType.MAXIMUM_TEMPERATURE); + enumTestList.add(MetadataType.MINIMUM_TEMPERATURE); + enumTestList.add(MetadataType.WEATHER_TERM); + enumTestList.add(MetadataType.HUMIDITY); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ModuleTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ModuleTypeTests.java new file mode 100644 index 000000000..65432873e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ModuleTypeTests.java @@ -0,0 +1,85 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.ModuleType; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.ModuleType} + */ +public class ModuleTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "CLIMATE"; + ModuleType enumClimate = ModuleType.valueForString(example); + example = "RADIO"; + ModuleType enumRadio = ModuleType.valueForString(example); + example = "SEAT"; + ModuleType enumSeat = ModuleType.valueForString(example); + example = "AUDIO"; + ModuleType enumAudio = ModuleType.valueForString(example); + example = "LIGHT"; + ModuleType enumLight = ModuleType.valueForString(example); + example = "HMI_SETTINGS"; + ModuleType enumHmiSettings = ModuleType.valueForString(example); + + assertNotNull("CLIMATE returned null", enumClimate); + assertNotNull("RADIO returned null", enumRadio); + assertNotNull("SEAT returned null", enumSeat); + assertNotNull("AUDIO returned null", enumAudio); + assertNotNull("LIGHT returned null", enumLight); + assertNotNull("HMI_SETTINGS returned null", enumHmiSettings); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "cLIMATE"; + try { + ModuleType temp = ModuleType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + ModuleType temp = ModuleType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of ModuleType. + */ + public void testListEnum() { + List<ModuleType> enumValueList = Arrays.asList(ModuleType.values()); + + List<ModuleType> enumTestList = new ArrayList<ModuleType>(); + enumTestList.add(ModuleType.CLIMATE); + enumTestList.add(ModuleType.RADIO); + enumTestList.add(ModuleType.SEAT); + enumTestList.add(ModuleType.AUDIO); + enumTestList.add(ModuleType.LIGHT); + enumTestList.add(ModuleType.HMI_SETTINGS); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/NavigationActionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/NavigationActionTests.java new file mode 100644 index 000000000..5051ef337 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/NavigationActionTests.java @@ -0,0 +1,92 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.NavigationAction; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.NavigationAction} + */ +public class NavigationActionTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "TURN"; + NavigationAction enumTurn = NavigationAction.valueForString(example); + example = "EXIT"; + NavigationAction enumExit = NavigationAction.valueForString(example); + example = "STAY"; + NavigationAction enumStay = NavigationAction.valueForString(example); + example = "MERGE"; + NavigationAction enumMerge = NavigationAction.valueForString(example); + example = "FERRY"; + NavigationAction enumFerry = NavigationAction.valueForString(example); + example = "CAR_SHUTTLE_TRAIN"; + NavigationAction enumCarShuttleTrain = NavigationAction.valueForString(example); + example = "WAYPOINT"; + NavigationAction enumWaypoint = NavigationAction.valueForString(example); + + assertNotNull("TURN returned null", enumTurn); + assertNotNull("EXIT returned null", enumExit); + assertNotNull("STAY returned null", enumStay); + assertNotNull("MERGE returned null", enumMerge); + assertNotNull("FERRY returned null", enumFerry); + assertNotNull("CAR_SHUTTLE_TRAIN returned null", enumCarShuttleTrain); + assertNotNull("WAYPOINT returned null", enumWaypoint); + + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "fRONT"; + try { + NavigationAction temp = NavigationAction.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + NavigationAction temp = NavigationAction.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of NavigationAction. + */ + public void testListEnum() { + List<NavigationAction> enumValueList = Arrays.asList(NavigationAction.values()); + + List<NavigationAction> enumTestList = new ArrayList<>(); + enumTestList.add(NavigationAction.TURN); + enumTestList.add(NavigationAction.EXIT); + enumTestList.add(NavigationAction.STAY); + enumTestList.add(NavigationAction.MERGE); + enumTestList.add(NavigationAction.FERRY); + enumTestList.add(NavigationAction.CAR_SHUTTLE_TRAIN); + enumTestList.add(NavigationAction.WAYPOINT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/NavigationJunctionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/NavigationJunctionTests.java new file mode 100644 index 000000000..691480f78 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/NavigationJunctionTests.java @@ -0,0 +1,95 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.NavigationJunction; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.NavigationJunction} + */ +public class NavigationJunctionTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "REGULAR"; + NavigationJunction enumRegular = NavigationJunction.valueForString(example); + example = "BIFURCATION"; + NavigationJunction enumBifurcation = NavigationJunction.valueForString(example); + example = "MULTI_CARRIAGEWAY"; + NavigationJunction enumMultiCarriageway = NavigationJunction.valueForString(example); + example = "ROUNDABOUT"; + NavigationJunction enumRoundabout = NavigationJunction.valueForString(example); + example = "TRAVERSABLE_ROUNDABOUT"; + NavigationJunction enumTraversableRoundabout = NavigationJunction.valueForString(example); + example = "JUGHANDLE"; + NavigationJunction enumJughandle = NavigationJunction.valueForString(example); + example = "ALL_WAY_YIELD"; + NavigationJunction enumAllWayYield = NavigationJunction.valueForString(example); + example = "TURN_AROUND"; + NavigationJunction enumTurnAround = NavigationJunction.valueForString(example); + + assertNotNull("REGULAR returned null", enumRegular); + assertNotNull("BIFURCATION returned null", enumBifurcation); + assertNotNull("MULTI_CARRIAGEWAY returned null", enumMultiCarriageway); + assertNotNull("ROUNDABOUT returned null", enumRoundabout); + assertNotNull("TRAVERSABLE_ROUNDABOUT returned null", enumTraversableRoundabout); + assertNotNull("JUGHANDLE returned null", enumJughandle); + assertNotNull("ALL_WAY_YIELD returned null", enumAllWayYield); + assertNotNull("TURN_AROUND returned null", enumTurnAround); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "fRONT"; + try { + NavigationJunction temp = NavigationJunction.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + NavigationJunction temp = NavigationJunction.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of NavigationJunction. + */ + public void testListEnum() { + List<NavigationJunction> enumValueList = Arrays.asList(NavigationJunction.values()); + + List<NavigationJunction> enumTestList = new ArrayList<>(); + enumTestList.add(NavigationJunction.REGULAR); + enumTestList.add(NavigationJunction.BIFURCATION); + enumTestList.add(NavigationJunction.MULTI_CARRIAGEWAY); + enumTestList.add(NavigationJunction.ROUNDABOUT); + enumTestList.add(NavigationJunction.TRAVERSABLE_ROUNDABOUT); + enumTestList.add(NavigationJunction.JUGHANDLE); + enumTestList.add(NavigationJunction.ALL_WAY_YIELD); + enumTestList.add(NavigationJunction.TURN_AROUND); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PowerModeQualificationStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PowerModeQualificationStatusTests.java new file mode 100644 index 000000000..f3a2a3540 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PowerModeQualificationStatusTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.PowerModeQualificationStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.PowerModeQualificationStatus} + */ +public class PowerModeQualificationStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "POWER_MODE_UNDEFINED"; + PowerModeQualificationStatus enumPowerModeUndefined = PowerModeQualificationStatus.valueForString(example); + example = "POWER_MODE_EVALUATION_IN_PROGRESS"; + PowerModeQualificationStatus enumPowerModeEvaluationInProgress = PowerModeQualificationStatus.valueForString(example); + example = "NOT_DEFINED"; + PowerModeQualificationStatus enumNotDefined = PowerModeQualificationStatus.valueForString(example); + example = "POWER_MODE_OK"; + PowerModeQualificationStatus enumPowerModeOk = PowerModeQualificationStatus.valueForString(example); + + assertNotNull("POWER_MODE_UNDEFINED returned null", enumPowerModeUndefined); + assertNotNull("POWER_MODE_EVALUATION_IN_PROGRESS returned null", enumPowerModeEvaluationInProgress); + assertNotNull("NOT_DEFINED returned null", enumNotDefined); + assertNotNull("POWER_MODE_OK returned null", enumPowerModeOk); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "poweR_moDE_UndEfiNEd"; + try { + PowerModeQualificationStatus temp = PowerModeQualificationStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + PowerModeQualificationStatus temp = PowerModeQualificationStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of PowerModeQualificationStatus. + */ + public void testListEnum() { + List<PowerModeQualificationStatus> enumValueList = Arrays.asList(PowerModeQualificationStatus.values()); + + List<PowerModeQualificationStatus> enumTestList = new ArrayList<PowerModeQualificationStatus>(); + enumTestList.add(PowerModeQualificationStatus.POWER_MODE_UNDEFINED); + enumTestList.add(PowerModeQualificationStatus.POWER_MODE_EVALUATION_IN_PROGRESS); + enumTestList.add(PowerModeQualificationStatus.NOT_DEFINED); + enumTestList.add(PowerModeQualificationStatus.POWER_MODE_OK); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PowerModeStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PowerModeStatusTests.java new file mode 100644 index 000000000..9154a06f0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PowerModeStatusTests.java @@ -0,0 +1,99 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.PowerModeStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.PowerModeStatus} + */ +public class PowerModeStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "KEY_OUT"; + PowerModeStatus enumKeyOut = PowerModeStatus.valueForString(example); + example = "KEY_RECENTLY_OUT"; + PowerModeStatus enumKeyRecentlyOut = PowerModeStatus.valueForString(example); + example = "KEY_APPROVED_0"; + PowerModeStatus enumKeyApproved0 = PowerModeStatus.valueForString(example); + example = "POST_ACCESORY_0"; + PowerModeStatus enumPostAccessory0 = PowerModeStatus.valueForString(example); + example = "ACCESORY_1"; + PowerModeStatus enumAccessory1 = PowerModeStatus.valueForString(example); + example = "POST_IGNITION_1"; + PowerModeStatus enumPostIgnition1 = PowerModeStatus.valueForString(example); + example = "IGNITION_ON_2"; + PowerModeStatus enumIgnitionOn2 = PowerModeStatus.valueForString(example); + example = "RUNNING_2"; + PowerModeStatus enumRunning2 = PowerModeStatus.valueForString(example); + example = "CRANK_3"; + PowerModeStatus enumCrank3 = PowerModeStatus.valueForString(example); + + assertNotNull("KEY_OUT returned null", enumKeyOut); + assertNotNull("KEY_RECENTLY_OUT returned null", enumKeyRecentlyOut); + assertNotNull("KEY_APPROVED_0 returned null", enumKeyApproved0); + assertNotNull("POST_ACCESORY_0 returned null", enumPostAccessory0); + assertNotNull("ACCESORY_1 returned null", enumAccessory1); + assertNotNull("POST_IGNITION_1 returned null", enumPostIgnition1); + assertNotNull("IGNITION_ON_2 returned null", enumIgnitionOn2); + assertNotNull("RUNNING_2 returned null", enumRunning2); + assertNotNull("CRANK_3 returned null", enumCrank3); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "key_Out"; + try { + PowerModeStatus temp = PowerModeStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + PowerModeStatus temp = PowerModeStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of PowerModeStatus. + */ + public void testListEnum() { + List<PowerModeStatus> enumValueList = Arrays.asList(PowerModeStatus.values()); + + List<PowerModeStatus> enumTestList = new ArrayList<PowerModeStatus>(); + enumTestList.add(PowerModeStatus.KEY_OUT); + enumTestList.add(PowerModeStatus.KEY_RECENTLY_OUT); + enumTestList.add(PowerModeStatus.KEY_APPROVED_0); + enumTestList.add(PowerModeStatus.POST_ACCESORY_0); + enumTestList.add(PowerModeStatus.ACCESORY_1); + enumTestList.add(PowerModeStatus.POST_IGNITION_1); + enumTestList.add(PowerModeStatus.IGNITION_ON_2); + enumTestList.add(PowerModeStatus.RUNNING_2); + enumTestList.add(PowerModeStatus.CRANK_3); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PredefinedLayoutTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PredefinedLayoutTests.java new file mode 100644 index 000000000..26b32d08b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PredefinedLayoutTests.java @@ -0,0 +1,144 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.PredefinedLayout; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.PredefinedLayout} + */ +public class PredefinedLayoutTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "DEFAULT"; + PredefinedLayout defaultenum = PredefinedLayout.valueForString(example); + example = "MEDIA"; + PredefinedLayout media = PredefinedLayout.valueForString(example); + example = "NON-MEDIA"; + PredefinedLayout nonmedia = PredefinedLayout.valueForString(example); + example = "ONSCREEN_PRESETS"; + PredefinedLayout onscreen_presets = PredefinedLayout.valueForString(example); + example = "NAV_FULLSCREEN_MAP"; + PredefinedLayout nav_fullscreen_map = PredefinedLayout.valueForString(example); + example = "NAV_LIST"; + PredefinedLayout nav_list = PredefinedLayout.valueForString(example); + example = "NAV_KEYBOARD"; + PredefinedLayout nav_keyboard = PredefinedLayout.valueForString(example); + example = "GRAPHIC_WITH_TEXT"; + PredefinedLayout graphic_with_text = PredefinedLayout.valueForString(example); + example = "TEXT_WITH_GRAPHIC"; + PredefinedLayout text_with_graphic = PredefinedLayout.valueForString(example); + example = "TILES_ONLY"; + PredefinedLayout tiles_only = PredefinedLayout.valueForString(example); + example = "TEXTBUTTONS_ONLY"; + PredefinedLayout textbuttons_only = PredefinedLayout.valueForString(example); + example = "GRAPHIC_WITH_TILES"; + PredefinedLayout graphic_with_tiles = PredefinedLayout.valueForString(example); + example = "TILES_WITH_GRAPHIC"; + PredefinedLayout tiles_with_graphic = PredefinedLayout.valueForString(example); + example = "GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS"; + PredefinedLayout graphic_with_text_and_softbuttons = PredefinedLayout.valueForString(example); + example = "TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC"; + PredefinedLayout text_and_softbuttons_with_graphics = PredefinedLayout.valueForString(example); + example = "GRAPHIC_WITH_TEXTBUTTONS"; + PredefinedLayout graphic_with_textbuttons = PredefinedLayout.valueForString(example); + example = "TEXTBUTTONS_WITH_GRAPHIC"; + PredefinedLayout textbuttons_with_graphic = PredefinedLayout.valueForString(example); + example = "LARGE_GRAPHIC_WITH_SOFTBUTTONS"; + PredefinedLayout large_graphic_with_softbuttons = PredefinedLayout.valueForString(example); + example = "DOUBLE_GRAPHIC_WITH_SOFTBUTTONS"; + PredefinedLayout double_graphic_with_softbuttons = PredefinedLayout.valueForString(example); + example = "LARGE_GRAPHIC_ONLY"; + PredefinedLayout large_graphic_only = PredefinedLayout.valueForString(example); + + assertNotNull("DEFAULT returned null", defaultenum); + assertNotNull("MEDIA returned null", media); + assertNotNull("NON-MEDIA returned null", nonmedia); + assertNotNull("ONSCREEN_PRESETS returned null", onscreen_presets); + assertNotNull("NAV_FULLSCREEN_MAP returned null", nav_fullscreen_map); + assertNotNull("NAV_LIST returned null", nav_list); + assertNotNull("NAV_KEYBOARD returned null", nav_keyboard); + assertNotNull("GRAPHIC_WITH_TEXT returned null", graphic_with_text); + assertNotNull("TEXT_WITH_GRAPHIC returned null", text_with_graphic); + assertNotNull("TILES_ONLY returned null", tiles_only); + assertNotNull("TEXTBUTTONS_ONLY returned null", textbuttons_only); + assertNotNull("GRAPHIC_WITH_TILES returned null", graphic_with_tiles); + assertNotNull("TILES_WITH_GRAPHIC returned null", tiles_with_graphic); + assertNotNull("GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS returned null", graphic_with_text_and_softbuttons); + assertNotNull("TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC returned null", text_and_softbuttons_with_graphics); + assertNotNull("GRAPHIC_WITH_TEXTBUTTONS returned null", graphic_with_textbuttons); + assertNotNull("TEXTBUTTONS_WITH_GRAPHIC returned null", textbuttons_with_graphic); + assertNotNull("LARGE_GRAPHIC_WITH_SOFTBUTTONS returned null", large_graphic_with_softbuttons); + assertNotNull("DOUBLE_GRAPHIC_WITH_SOFTBUTTONS returned null", double_graphic_with_softbuttons); + assertNotNull("LARGE_GRAPHIC_ONLY returned null", large_graphic_only); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "LARGE_GRApHIC_ONLY"; + try { + PredefinedLayout temp = PredefinedLayout.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + PredefinedLayout temp = PredefinedLayout.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of PredefinedLayout. + */ + public void testListEnum() { + List<PredefinedLayout> enumValueList = Arrays.asList(PredefinedLayout.values()); + + List<PredefinedLayout> enumTestList = new ArrayList<>(); + + enumTestList.add(PredefinedLayout.DEFAULT); + enumTestList.add(PredefinedLayout.MEDIA); + enumTestList.add(PredefinedLayout.NON_MEDIA); + enumTestList.add(PredefinedLayout.ONSCREEN_PRESETS); + enumTestList.add(PredefinedLayout.NAV_FULLSCREEN_MAP); + enumTestList.add(PredefinedLayout.NAV_LIST); + enumTestList.add(PredefinedLayout.NAV_KEYBOARD); + enumTestList.add(PredefinedLayout.GRAPHIC_WITH_TEXT); + enumTestList.add(PredefinedLayout.TEXT_WITH_GRAPHIC); + enumTestList.add(PredefinedLayout.TILES_ONLY); + enumTestList.add(PredefinedLayout.TEXTBUTTONS_ONLY); + enumTestList.add(PredefinedLayout.GRAPHIC_WITH_TILES); + enumTestList.add(PredefinedLayout.TILES_WITH_GRAPHIC); + enumTestList.add(PredefinedLayout.GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS); + enumTestList.add(PredefinedLayout.TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC); + enumTestList.add(PredefinedLayout.GRAPHIC_WITH_TEXTBUTTONS); + enumTestList.add(PredefinedLayout.TEXTBUTTONS_WITH_GRAPHIC); + enumTestList.add(PredefinedLayout.LARGE_GRAPHIC_WITH_SOFTBUTTONS); + enumTestList.add(PredefinedLayout.DOUBLE_GRAPHIC_WITH_SOFTBUTTONS); + enumTestList.add(PredefinedLayout.LARGE_GRAPHIC_ONLY); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrerecordedSpeechTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrerecordedSpeechTests.java new file mode 100644 index 000000000..9ab3c9db8 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrerecordedSpeechTests.java @@ -0,0 +1,83 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.PrerecordedSpeech; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.PrerecordedSpeech} + */ +public class PrerecordedSpeechTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "HELP_JINGLE"; + PrerecordedSpeech enumHelpJingle = PrerecordedSpeech.valueForString(example); + example = "INITIAL_JINGLE"; + PrerecordedSpeech enumInitialJingle = PrerecordedSpeech.valueForString(example); + example = "LISTEN_JINGLE"; + PrerecordedSpeech enumListenJingle = PrerecordedSpeech.valueForString(example); + example = "POSITIVE_JINGLE"; + PrerecordedSpeech enumPositiveJingle = PrerecordedSpeech.valueForString(example); + example = "NEGATIVE_JINGLE"; + PrerecordedSpeech enumNegativeJingle = PrerecordedSpeech.valueForString(example); + + assertNotNull("HELP_JINGLE returned null", enumHelpJingle); + assertNotNull("INITIAL_JINGLE returned null", enumInitialJingle); + assertNotNull("LISTEN_JINGLE returned null", enumListenJingle); + assertNotNull("POSITIVE_JINGLE returned null", enumPositiveJingle); + assertNotNull("NEGATIVE_JINGLE returned null", enumNegativeJingle); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "heLP_JingLE"; + try { + PrerecordedSpeech temp = PrerecordedSpeech.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + PrerecordedSpeech temp = PrerecordedSpeech.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of PrerecordedSpeech. + */ + public void testListEnum() { + List<PrerecordedSpeech> enumValueList = Arrays.asList(PrerecordedSpeech.values()); + + List<PrerecordedSpeech> enumTestList = new ArrayList<PrerecordedSpeech>(); + enumTestList.add(PrerecordedSpeech.HELP_JINGLE); + enumTestList.add(PrerecordedSpeech.INITIAL_JINGLE); + enumTestList.add(PrerecordedSpeech.LISTEN_JINGLE); + enumTestList.add(PrerecordedSpeech.POSITIVE_JINGLE); + enumTestList.add(PrerecordedSpeech.NEGATIVE_JINGLE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrimaryAudioSourceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrimaryAudioSourceTests.java new file mode 100644 index 000000000..b3432985d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrimaryAudioSourceTests.java @@ -0,0 +1,111 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.PrimaryAudioSource; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.PrimaryAudioSource} + */ +public class PrimaryAudioSourceTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "NO_SOURCE_SELECTED"; + PrimaryAudioSource enumNoSourceSelected = PrimaryAudioSource.valueForString(example); + example = "USB"; + PrimaryAudioSource enumUsb = PrimaryAudioSource.valueForString(example); + example = "USB2"; + PrimaryAudioSource enumUsb2 = PrimaryAudioSource.valueForString(example); + example = "BLUETOOTH_STEREO_BTST"; + PrimaryAudioSource enumBluetoothStereoBtst = PrimaryAudioSource.valueForString(example); + example = "LINE_IN"; + PrimaryAudioSource enumLineIn = PrimaryAudioSource.valueForString(example); + example = "IPOD"; + PrimaryAudioSource enumIpod = PrimaryAudioSource.valueForString(example); + example = "MOBILE_APP"; + PrimaryAudioSource enumMobileApp = PrimaryAudioSource.valueForString(example); + example = "CD"; + PrimaryAudioSource enumCd = PrimaryAudioSource.valueForString(example); + example = "AM"; + PrimaryAudioSource enumAm = PrimaryAudioSource.valueForString(example); + example = "FM"; + PrimaryAudioSource enumFm = PrimaryAudioSource.valueForString(example); + example = "XM"; + PrimaryAudioSource enumXm = PrimaryAudioSource.valueForString(example); + example = "DAB"; + PrimaryAudioSource enumDab = PrimaryAudioSource.valueForString(example); + + assertNotNull("NO_SOURCE_SELECTED returned null", enumNoSourceSelected); + assertNotNull("USB returned null", enumUsb); + assertNotNull("USB2 returned null", enumUsb2); + assertNotNull("BLUETOOTH_STEREO_BTST returned null", enumBluetoothStereoBtst); + assertNotNull("LINE_IN returned null", enumLineIn); + assertNotNull("IPOD returned null", enumIpod); + assertNotNull("MOBILE_APP returned null", enumMobileApp); + assertNotNull("CD returned null", enumCd); + assertNotNull("AM returned null", enumAm); + assertNotNull("FM returned null", enumFm); + assertNotNull("XM returned null", enumXm); + assertNotNull("DAB returned null", enumDab); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "no_SouRCe_SelEcteD"; + try { + PrimaryAudioSource temp = PrimaryAudioSource.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + PrimaryAudioSource temp = PrimaryAudioSource.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + + /** + * Verifies the possible enum values of PrimaryAudioSource. + */ + public void testListEnum() { + List<PrimaryAudioSource> enumValueList = Arrays.asList(PrimaryAudioSource.values()); + + List<PrimaryAudioSource> enumTestList = new ArrayList<PrimaryAudioSource>(); + enumTestList.add(PrimaryAudioSource.NO_SOURCE_SELECTED); + enumTestList.add(PrimaryAudioSource.USB); + enumTestList.add(PrimaryAudioSource.USB2); + enumTestList.add(PrimaryAudioSource.BLUETOOTH_STEREO_BTST); + enumTestList.add(PrimaryAudioSource.LINE_IN); + enumTestList.add(PrimaryAudioSource.IPOD); + enumTestList.add(PrimaryAudioSource.MOBILE_APP); + enumTestList.add(PrimaryAudioSource.CD); + enumTestList.add(PrimaryAudioSource.AM); + enumTestList.add(PrimaryAudioSource.FM); + enumTestList.add(PrimaryAudioSource.XM); + enumTestList.add(PrimaryAudioSource.DAB); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrndlTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrndlTests.java new file mode 100644 index 000000000..fabf94177 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/PrndlTests.java @@ -0,0 +1,128 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.PRNDL; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.Prndl} + */ +public class PrndlTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "PARK"; + PRNDL enumPark = PRNDL.valueForString(example); + example = "REVERSE"; + PRNDL enumReverse = PRNDL.valueForString(example); + example = "NEUTRAL"; + PRNDL enumNeutral = PRNDL.valueForString(example); + example = "DRIVE"; + PRNDL enumDrive = PRNDL.valueForString(example); + example = "SPORT"; + PRNDL enumSport = PRNDL.valueForString(example); + example = "LOWGEAR"; + PRNDL enumLowGear = PRNDL.valueForString(example); + example = "FIRST"; + PRNDL enumFirst = PRNDL.valueForString(example); + example = "SECOND"; + PRNDL enumSecond = PRNDL.valueForString(example); + example = "THIRD"; + PRNDL enumThird = PRNDL.valueForString(example); + example = "FOURTH"; + PRNDL enumFourth = PRNDL.valueForString(example); + example = "FIFTH"; + PRNDL enumFifth = PRNDL.valueForString(example); + example = "SIXTH"; + PRNDL enumSixth = PRNDL.valueForString(example); + example = "SEVENTH"; + PRNDL enumSeventh = PRNDL.valueForString(example); + example = "EIGHTH"; + PRNDL enumEighth = PRNDL.valueForString(example); + example = "UNKNOWN"; + PRNDL enumUnknown = PRNDL.valueForString(example); + example = "FAULT"; + PRNDL enumFault = PRNDL.valueForString(example); + + assertNotNull("PARK returned null", enumPark); + assertNotNull("REVERSE returned null", enumReverse); + assertNotNull("NEUTRAL returned null", enumNeutral); + assertNotNull("DRIVE returned null", enumDrive); + assertNotNull("SPORT returned null", enumSport); + assertNotNull("LOWGEAR returned null", enumLowGear); + assertNotNull("FIRST returned null", enumFirst); + assertNotNull("SECOND returned null", enumSecond); + assertNotNull("THIRD returned null", enumThird); + assertNotNull("FOURTH returned null", enumFourth); + assertNotNull("FIFTH returned null", enumFifth); + assertNotNull("SIXTH returned null", enumSixth); + assertNotNull("SEVENTH returned null", enumSeventh); + assertNotNull("EIGHTH returned null", enumEighth); + assertNotNull("UNKNOWN returned null", enumUnknown); + assertNotNull("FAULT returned null", enumFault); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "pARk"; + try { + PRNDL temp = PRNDL.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + PRNDL temp = PRNDL.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of PRNDL. + */ + public void testListEnum() { + List<PRNDL> enumValueList = Arrays.asList(PRNDL.values()); + + List<PRNDL> enumTestList = new ArrayList<PRNDL>(); + enumTestList.add(PRNDL.PARK); + enumTestList.add(PRNDL.REVERSE); + enumTestList.add(PRNDL.NEUTRAL); + enumTestList.add(PRNDL.DRIVE); + enumTestList.add(PRNDL.SPORT); + enumTestList.add(PRNDL.LOWGEAR); + enumTestList.add(PRNDL.FIRST); + enumTestList.add(PRNDL.SECOND); + enumTestList.add(PRNDL.THIRD); + enumTestList.add(PRNDL.FOURTH); + enumTestList.add(PRNDL.FIFTH); + enumTestList.add(PRNDL.SIXTH); + enumTestList.add(PRNDL.SEVENTH); + enumTestList.add(PRNDL.EIGHTH); + enumTestList.add(PRNDL.UNKNOWN); + enumTestList.add(PRNDL.FAULT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RadioBandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RadioBandTests.java new file mode 100644 index 000000000..cc5d5b700 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RadioBandTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.RadioBand; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.RadioBand} + */ +public class RadioBandTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "AM"; + RadioBand enumAm = RadioBand.valueForString(example); + example = "FM"; + RadioBand enumFm = RadioBand.valueForString(example); + example = "XM"; + RadioBand enumXm = RadioBand.valueForString(example); + + assertNotNull("AM returned null", enumAm); + assertNotNull("FM returned null", enumFm); + assertNotNull("XM returned null", enumXm); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "aM"; + try { + RadioBand temp = RadioBand.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + RadioBand temp = RadioBand.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of RadioBand. + */ + public void testListEnum() { + List<RadioBand> enumValueList = Arrays.asList(RadioBand.values()); + + List<RadioBand> enumTestList = new ArrayList<RadioBand>(); + enumTestList.add(RadioBand.AM); + enumTestList.add(RadioBand.FM); + enumTestList.add(RadioBand.XM); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RadioStateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RadioStateTests.java new file mode 100644 index 000000000..d16f00599 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RadioStateTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.RadioState; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.RadioState} + */ +public class RadioStateTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "ACQUIRING"; + RadioState enumAcquiring = RadioState.valueForString(example); + example = "ACQUIRED"; + RadioState enumAcquired = RadioState.valueForString(example); + example = "MULTICAST"; + RadioState enumMultiCast = RadioState.valueForString(example); + example = "NOT_FOUND"; + RadioState enumNotFound = RadioState.valueForString(example); + + assertNotNull("ACQUIRING returned null", enumAcquiring); + assertNotNull("ACQUIRED returned null", enumAcquired); + assertNotNull("MULTICAST returned null", enumMultiCast); + assertNotNull("NOT_FOUND returned null", enumNotFound); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "aCQUIRING"; + try { + RadioState temp = RadioState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + RadioState temp = RadioState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of RadioState. + */ + public void testListEnum() { + List<RadioState> enumValueList = Arrays.asList(RadioState.values()); + + List<RadioState> enumTestList = new ArrayList<RadioState>(); + enumTestList.add(RadioState.ACQUIRING); + enumTestList.add(RadioState.ACQUIRED); + enumTestList.add(RadioState.MULTICAST); + enumTestList.add(RadioState.NOT_FOUND); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RequestTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RequestTypeTests.java new file mode 100644 index 000000000..d00cfe93f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/RequestTypeTests.java @@ -0,0 +1,153 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.RequestType; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.RequestType} + */ +public class RequestTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "HTTP"; + RequestType enumHttp = RequestType.valueForString(example); + example = "FILE_RESUME"; + RequestType enumFileResume = RequestType.valueForString(example); + example = "AUTH_REQUEST"; + RequestType enumAuthRequest = RequestType.valueForString(example); + example = "AUTH_CHALLENGE"; + RequestType enumAuthChallenge = RequestType.valueForString(example); + example = "AUTH_ACK"; + RequestType enumAuthAck = RequestType.valueForString(example); + example = "PROPRIETARY"; + RequestType enumProprietary = RequestType.valueForString(example); + + example = "QUERY_APPS"; + RequestType enumQueryApps = RequestType.valueForString(example); + example = "LAUNCH_APP"; + RequestType enumLaunchApp = RequestType.valueForString(example); + example = "LOCK_SCREEN_ICON_URL"; + RequestType enumLockScreen = RequestType.valueForString(example); + example = "TRAFFIC_MESSAGE_CHANNEL"; + RequestType enumTrafficMessage = RequestType.valueForString(example); + example = "DRIVER_PROFILE"; + RequestType enumDriverProfile = RequestType.valueForString(example); + example = "VOICE_SEARCH"; + RequestType enumVoiceSearch = RequestType.valueForString(example); + example = "NAVIGATION"; + RequestType enumNavigation = RequestType.valueForString(example); + example = "PHONE"; + RequestType enumPhone = RequestType.valueForString(example); + example = "CLIMATE"; + RequestType enumClimate = RequestType.valueForString(example); + example = "SETTINGS"; + RequestType enumSettings = RequestType.valueForString(example); + example = "VEHICLE_DIAGNOSTICS"; + RequestType enumDiagnostics = RequestType.valueForString(example); + example = "EMERGENCY"; + RequestType enumEmergency = RequestType.valueForString(example); + example = "MEDIA"; + RequestType enumMedia = RequestType.valueForString(example); + example = "FOTA"; + RequestType enumFota = RequestType.valueForString(example); + example = "ICON_URL"; + RequestType enumIconURL = RequestType.valueForString(example); + + assertNotNull("HTTP returned null", enumHttp); + assertNotNull("FILE_RESUME returned null", enumFileResume); + assertNotNull("AUTH_REQUEST returned null", enumAuthRequest); + assertNotNull("AUTH_CHALLENGE returned null", enumAuthChallenge); + assertNotNull("AUTH_ACK returned null", enumAuthAck); + assertNotNull("PROPRIETARY returned null", enumProprietary); + assertNotNull("ICON_URL returned null", enumIconURL); + + assertNotNull(Test.NOT_NULL, enumQueryApps); + assertNotNull(Test.NOT_NULL, enumLaunchApp); + assertNotNull(Test.NOT_NULL, enumLockScreen); + assertNotNull(Test.NOT_NULL, enumTrafficMessage); + assertNotNull(Test.NOT_NULL, enumDriverProfile); + assertNotNull(Test.NOT_NULL, enumVoiceSearch); + assertNotNull(Test.NOT_NULL, enumNavigation); + assertNotNull(Test.NOT_NULL, enumPhone); + assertNotNull(Test.NOT_NULL, enumClimate); + assertNotNull(Test.NOT_NULL, enumSettings); + assertNotNull(Test.NOT_NULL, enumDiagnostics); + assertNotNull(Test.NOT_NULL, enumEmergency); + assertNotNull(Test.NOT_NULL, enumMedia); + assertNotNull(Test.NOT_NULL, enumFota); + assertNotNull(Test.NOT_NULL, enumIconURL); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "hTTp"; + try { + RequestType temp = RequestType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + RequestType temp = RequestType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of RequestType. + */ + public void testListEnum() { + List<RequestType> enumValueList = Arrays.asList(RequestType.values()); + + List<RequestType> enumTestList = new ArrayList<RequestType>(); + enumTestList.add(RequestType.HTTP); + enumTestList.add(RequestType.FILE_RESUME); + enumTestList.add(RequestType.AUTH_REQUEST); + enumTestList.add(RequestType.AUTH_CHALLENGE); + enumTestList.add(RequestType.AUTH_ACK); + enumTestList.add(RequestType.PROPRIETARY); + + enumTestList.add(RequestType.QUERY_APPS); + enumTestList.add(RequestType.LAUNCH_APP); + enumTestList.add(RequestType.LOCK_SCREEN_ICON_URL); + enumTestList.add(RequestType.TRAFFIC_MESSAGE_CHANNEL); + enumTestList.add(RequestType.DRIVER_PROFILE); + enumTestList.add(RequestType.VOICE_SEARCH); + enumTestList.add(RequestType.NAVIGATION); + enumTestList.add(RequestType.PHONE); + enumTestList.add(RequestType.CLIMATE); + enumTestList.add(RequestType.SETTINGS); + enumTestList.add(RequestType.VEHICLE_DIAGNOSTICS); + enumTestList.add(RequestType.EMERGENCY); + enumTestList.add(RequestType.MEDIA); + enumTestList.add(RequestType.FOTA); + enumTestList.add(RequestType.OEM_SPECIFIC); + enumTestList.add(RequestType.ICON_URL); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ResultTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ResultTests.java new file mode 100644 index 000000000..4cea3acbe --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ResultTests.java @@ -0,0 +1,203 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.Result; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.Result} + */ +public class ResultTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "SUCCESS"; + Result enumSuccess = Result.valueForString(example); + example = "INVALID_DATA"; + Result enumInvalidData = Result.valueForString(example); + example = "UNSUPPORTED_REQUEST"; + Result enumUnsupportedRequest = Result.valueForString(example); + example = "OUT_OF_MEMORY"; + Result enumOutOfMemory = Result.valueForString(example); + example = "TOO_MANY_PENDING_REQUESTS"; + Result enumTooManyPendingRequests = Result.valueForString(example); + example = "INVALID_ID"; + Result enumInvalidId = Result.valueForString(example); + example = "DUPLICATE_NAME"; + Result enumDuplicateName = Result.valueForString(example); + example = "TOO_MANY_APPLICATIONS"; + Result enumTooManyApplications = Result.valueForString(example); + example = "APPLICATION_REGISTERED_ALREADY"; + Result enumApplicationRegisteredAlready = Result.valueForString(example); + example = "UNSUPPORTED_VERSION"; + Result enumUnsupportedVersion = Result.valueForString(example); + example = "WRONG_LANGUAGE"; + Result enumWrongLanguage = Result.valueForString(example); + example = "APPLICATION_NOT_REGISTERED"; + Result enumApplicationNotRegistered = Result.valueForString(example); + example = "IN_USE"; + Result enumInUse = Result.valueForString(example); + example = "VEHICLE_DATA_NOT_ALLOWED"; + Result enumVehicleDataNotAllowed = Result.valueForString(example); + example = "VEHICLE_DATA_NOT_AVAILABLE"; + Result enumVehicleDataNotAvailable = Result.valueForString(example); + example = "REJECTED"; + Result enumRejected = Result.valueForString(example); + example = "ABORTED"; + Result enumAborted = Result.valueForString(example); + example = "IGNORED"; + Result enumIgnored = Result.valueForString(example); + example = "UNSUPPORTED_RESOURCE"; + Result enumUnsupportedResource = Result.valueForString(example); + example = "FILE_NOT_FOUND"; + Result enumFileNotFound = Result.valueForString(example); + example = "GENERIC_ERROR"; + Result enumGenericError = Result.valueForString(example); + example = "DISALLOWED"; + Result enumDisallowed = Result.valueForString(example); + example = "USER_DISALLOWED"; + Result enumUserDisallowed = Result.valueForString(example); + example = "TIMED_OUT"; + Result enumTimedOut = Result.valueForString(example); + example = "CANCEL_ROUTE"; + Result enumCancelRoute = Result.valueForString(example); + example = "TRUNCATED_DATA"; + Result enumTruncatedData = Result.valueForString(example); + example = "RETRY"; + Result enumRetry = Result.valueForString(example); + example = "WARNINGS"; + Result enumWarnings = Result.valueForString(example); + example = "SAVED"; + Result enumSaved = Result.valueForString(example); + example = "INVALID_CERT"; + Result enumInvalidCert = Result.valueForString(example); + example = "EXPIRED_CERT"; + Result enumExpiredCert = Result.valueForString(example); + example = "RESUME_FAILED"; + Result enumResumeFailed = Result.valueForString(example); + example = "DATA_NOT_AVAILABLE"; + Result enumDataNotAvailable = Result.valueForString(example); + example = "READ_ONLY"; + Result enumReadOnly = Result.valueForString(example); + example = "CORRUPTED_DATA"; + Result enumCorruptData = Result.valueForString(example); + + assertNotNull("SUCCESS returned null", enumSuccess); + assertNotNull("INVALID_DATA returned null", enumInvalidData); + assertNotNull("UNSUPPORTED_REQUEST returned null", enumUnsupportedRequest); + assertNotNull("OUT_OF_MEMORY returned null", enumOutOfMemory); + assertNotNull("TOO_MANY_PENDING_REQUESTS returned null", enumTooManyPendingRequests); + assertNotNull("INVALID_ID returned null", enumInvalidId); + assertNotNull("DUPLICATE_NAME returned null", enumDuplicateName); + assertNotNull("TOO_MANY_APPLICATIONS returned null", enumTooManyApplications); + assertNotNull("APPLICATION_REGISTERED_ALREADY returned null", enumApplicationRegisteredAlready); + assertNotNull("UNSUPPORTED_VERSION returned null", enumUnsupportedVersion); + assertNotNull("WRONG_LANGUAGE returned null", enumWrongLanguage); + assertNotNull("APPLICATION_NOT_REGISTERED returned null", enumApplicationNotRegistered); + assertNotNull("IN_USE returned null", enumInUse); + assertNotNull("VEHICLE_DATA_NOT_ALLOWED returned null", enumVehicleDataNotAllowed); + assertNotNull("VEHICLE_DATA_NOT_AVAILABLE returned null", enumVehicleDataNotAvailable); + assertNotNull("REJECTED returned null", enumRejected); + assertNotNull("ABORTED returned null", enumAborted); + assertNotNull("IGNORED returned null", enumIgnored); + assertNotNull("UNSUPPORTED_RESOURCE returned null", enumUnsupportedResource); + assertNotNull("FILE_NOT_FOUND returned null", enumFileNotFound); + assertNotNull("GENERIC_ERROR returned null", enumGenericError); + assertNotNull("DISALLOWED returned null", enumDisallowed); + assertNotNull("USER_DISALLOWED returned null", enumUserDisallowed); + assertNotNull("TIMED_OUT returned null", enumTimedOut); + assertNotNull("CANCEL_ROUTE returned null", enumCancelRoute); + assertNotNull("TRUNCATED_DATA returned null", enumTruncatedData); + assertNotNull("RETRY returned null", enumRetry); + assertNotNull("WARNINGS returned null", enumWarnings); + assertNotNull("SAVED returned null", enumSaved); + assertNotNull("INVALID_CERT returned null", enumInvalidCert); + assertNotNull("EXPIRED_CERT returned null", enumExpiredCert); + assertNotNull("RESUME_FAILED returned null", enumResumeFailed); + assertNotNull("DATA_NOT_AVAILABLE returned null", enumDataNotAvailable); + assertNotNull("READ_ONLY returned null", enumReadOnly); + assertNotNull("CORRUPTED_DATA", enumCorruptData); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "suCcesS"; + try { + Result temp = Result.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + Result temp = Result.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of Result. + */ + public void testListEnum() { + List<Result> enumValueList = Arrays.asList(Result.values()); + + List<Result> enumTestList = new ArrayList<Result>(); + enumTestList.add(Result.SUCCESS); + enumTestList.add(Result.INVALID_DATA); + enumTestList.add(Result.UNSUPPORTED_REQUEST); + enumTestList.add(Result.OUT_OF_MEMORY); + enumTestList.add(Result.TOO_MANY_PENDING_REQUESTS); + enumTestList.add(Result.INVALID_ID); + enumTestList.add(Result.DUPLICATE_NAME); + enumTestList.add(Result.TOO_MANY_APPLICATIONS); + enumTestList.add(Result.APPLICATION_REGISTERED_ALREADY); + enumTestList.add(Result.UNSUPPORTED_VERSION); + enumTestList.add(Result.WRONG_LANGUAGE); + enumTestList.add(Result.APPLICATION_NOT_REGISTERED); + enumTestList.add(Result.IN_USE); + enumTestList.add(Result.VEHICLE_DATA_NOT_ALLOWED); + enumTestList.add(Result.VEHICLE_DATA_NOT_AVAILABLE); + enumTestList.add(Result.REJECTED); + enumTestList.add(Result.ABORTED); + enumTestList.add(Result.IGNORED); + enumTestList.add(Result.UNSUPPORTED_RESOURCE); + enumTestList.add(Result.FILE_NOT_FOUND); + enumTestList.add(Result.GENERIC_ERROR); + enumTestList.add(Result.DISALLOWED); + enumTestList.add(Result.USER_DISALLOWED); + enumTestList.add(Result.TIMED_OUT); + enumTestList.add(Result.CANCEL_ROUTE); + enumTestList.add(Result.TRUNCATED_DATA); + enumTestList.add(Result.RETRY); + enumTestList.add(Result.WARNINGS); + enumTestList.add(Result.SAVED); + enumTestList.add(Result.INVALID_CERT); + enumTestList.add(Result.EXPIRED_CERT); + enumTestList.add(Result.RESUME_FAILED); + enumTestList.add(Result.DATA_NOT_AVAILABLE); + enumTestList.add(Result.READ_ONLY); + enumTestList.add(Result.CORRUPTED_DATA); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SamplingRateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SamplingRateTests.java new file mode 100644 index 000000000..062ce7df3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SamplingRateTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.SamplingRate; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.SamplingRate} + */ +public class SamplingRateTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "8KHZ"; + SamplingRate enum8Khz = SamplingRate.valueForString(example); + example = "16KHZ"; + SamplingRate enum16Khz = SamplingRate.valueForString(example); + example = "22KHZ"; + SamplingRate enum22Khz = SamplingRate.valueForString(example); + example = "44KHZ"; + SamplingRate enum44Khz = SamplingRate.valueForString(example); + + assertNotNull("8KHZ returned null", enum8Khz); + assertNotNull("16KHZ returned null", enum16Khz); + assertNotNull("22KHZ returned null", enum22Khz); + assertNotNull("44KHZ returned null", enum44Khz); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "8kHz"; + try { + SamplingRate temp = SamplingRate.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + SamplingRate temp = SamplingRate.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SamplingRate. + */ + public void testListEnum() { + List<SamplingRate> enumValueList = Arrays.asList(SamplingRate.values()); + + List<SamplingRate> enumTestList = new ArrayList<SamplingRate>(); + enumTestList.add(SamplingRate._8KHZ); + enumTestList.add(SamplingRate._16KHZ); + enumTestList.add(SamplingRate._22KHZ); + enumTestList.add(SamplingRate._44KHZ); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SdlDisconnectedReasonTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SdlDisconnectedReasonTests.java new file mode 100644 index 000000000..c0c06c251 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SdlDisconnectedReasonTests.java @@ -0,0 +1,176 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.AppInterfaceUnregisteredReason; +import com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.SdlDisconnectedReason} + */ +public class SdlDisconnectedReasonTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "USER_EXIT"; + SdlDisconnectedReason enumUserExit = SdlDisconnectedReason.valueForString(example); + example = "IGNITION_OFF"; + SdlDisconnectedReason enumIgnitionOff = SdlDisconnectedReason.valueForString(example); + example = "BLUETOOTH_OFF"; + SdlDisconnectedReason enumBluetoothOff = SdlDisconnectedReason.valueForString(example); + example = "USB_DISCONNECTED"; + SdlDisconnectedReason enumUsbDisconnected = SdlDisconnectedReason.valueForString(example); + example = "REQUEST_WHILE_IN_NONE_HMI_LEVEL"; + SdlDisconnectedReason enumRequestWhileInNoneHmiLevel = SdlDisconnectedReason.valueForString(example); + example = "TOO_MANY_REQUESTS"; + SdlDisconnectedReason enumTooManyRequests = SdlDisconnectedReason.valueForString(example); + example = "DRIVER_DISTRACTION_VIOLATION"; + SdlDisconnectedReason enumDriverDistractionViolation = SdlDisconnectedReason.valueForString(example); + example = "LANGUAGE_CHANGE"; + SdlDisconnectedReason enumLanuguageChange = SdlDisconnectedReason.valueForString(example); + example = "MASTER_RESET"; + SdlDisconnectedReason enumMasterReset = SdlDisconnectedReason.valueForString(example); + example = "FACTORY_DEFAULTS"; + SdlDisconnectedReason enumFactoryDefaults = SdlDisconnectedReason.valueForString(example); + example = "TRANSPORT_ERROR"; + SdlDisconnectedReason enumTransportError = SdlDisconnectedReason.valueForString(example); + example = "APPLICATION_REQUESTED_DISCONNECT"; + SdlDisconnectedReason enumApplicationRequestedDisconnect = SdlDisconnectedReason.valueForString(example); + example = "DEFAULT"; + SdlDisconnectedReason enumDefault = SdlDisconnectedReason.valueForString(example); + example = "TRANSPORT_DISCONNECT"; + SdlDisconnectedReason enumTransportDisconnect = SdlDisconnectedReason.valueForString(example); + example = "HB_TIMEOUT"; + SdlDisconnectedReason enumHbTimeout = SdlDisconnectedReason.valueForString(example); + example = "BLUETOOTH_DISABLED"; + SdlDisconnectedReason enumBluetoothDisabled = SdlDisconnectedReason.valueForString(example); + example = "BLUETOOTH_ADAPTER_ERROR"; + SdlDisconnectedReason enumBluetoothAdapterError = SdlDisconnectedReason.valueForString(example); + example = "SDL_REGISTRATION_ERROR"; + SdlDisconnectedReason enumSdlRegistrationError = SdlDisconnectedReason.valueForString(example); + example = "APP_INTERFACE_UNREG"; + SdlDisconnectedReason enumAppInterfaceUnreg = SdlDisconnectedReason.valueForString(example); + example = "GENERIC_ERROR"; + SdlDisconnectedReason enumGenericError = SdlDisconnectedReason.valueForString(example); + example = "LEGACY_BLUETOOTH_MODE_ENABLED"; + SdlDisconnectedReason enumLegacyMode = SdlDisconnectedReason.valueForString(example); + example = "RPC_SESSION_ENDED"; + SdlDisconnectedReason enumRpcSessionEnded = SdlDisconnectedReason.valueForString(example); + + assertNotNull("USER_EXIT returned null", enumUserExit); + assertNotNull("IGNITION_OFF returned null", enumIgnitionOff); + assertNotNull("BLUETOOTH_OFF returned null", enumBluetoothOff); + assertNotNull("USB_DISCONNECTED returned null", enumUsbDisconnected); + assertNotNull("REQUEST_WHILE_IN_NONE_HMI_LEVEL returned null", enumRequestWhileInNoneHmiLevel); + assertNotNull("TOO_MANY_REQUESTS returned null", enumTooManyRequests); + assertNotNull("DRIVER_DISTRACTION_VIOLATION returned null", enumDriverDistractionViolation); + assertNotNull("LANGUAGE_CHANGE returned null", enumLanuguageChange); + assertNotNull("MASTER_RESET returned null", enumMasterReset); + assertNotNull("FACTORY_DEFAULTS returned null", enumFactoryDefaults); + assertNotNull("TRANSPORT_ERROR returned null", enumTransportError); + assertNotNull("APPLICATION_REQUESTED_DISCONNECT returned null", enumApplicationRequestedDisconnect); + assertNotNull("DEFAULT returned null", enumDefault); + assertNotNull("TRANSPORT_DISCONNECT returned null", enumTransportDisconnect); + assertNotNull("HB_TIMEOUT returned null", enumHbTimeout); + assertNotNull("BLUETOOTH_DISABLED returned null", enumBluetoothDisabled); + assertNotNull("BLUETOOTH_ADAPTER_ERROR returned null", enumBluetoothAdapterError); + assertNotNull("SDL_REGISTRATION_ERROR returned null", enumSdlRegistrationError); + assertNotNull("APP_INTERFACE_UNREG returned null", enumAppInterfaceUnreg); + assertNotNull("GENERIC_ERROR returned null", enumGenericError); + assertNotNull("LEGACY_BLUETOOTH_MODE_ENABLED returned null", enumLegacyMode); + assertNotNull("RPC_SESSION_ENDED returned null", enumRpcSessionEnded); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "uSer_ExiT"; + try { + SdlDisconnectedReason temp = SdlDisconnectedReason.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + SdlDisconnectedReason temp = SdlDisconnectedReason.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SdlDisconnectedReason. + */ + public void testListEnum() { + List<SdlDisconnectedReason> enumValueList = Arrays.asList(SdlDisconnectedReason.values()); + + List<SdlDisconnectedReason> enumTestList = new ArrayList<SdlDisconnectedReason>(); + enumTestList.add(SdlDisconnectedReason.USER_EXIT); + enumTestList.add(SdlDisconnectedReason.IGNITION_OFF); + enumTestList.add(SdlDisconnectedReason.BLUETOOTH_OFF); + enumTestList.add(SdlDisconnectedReason.USB_DISCONNECTED); + enumTestList.add(SdlDisconnectedReason.REQUEST_WHILE_IN_NONE_HMI_LEVEL); + enumTestList.add(SdlDisconnectedReason.TOO_MANY_REQUESTS); + enumTestList.add(SdlDisconnectedReason.DRIVER_DISTRACTION_VIOLATION); + enumTestList.add(SdlDisconnectedReason.LANGUAGE_CHANGE); + enumTestList.add(SdlDisconnectedReason.MASTER_RESET); + enumTestList.add(SdlDisconnectedReason.FACTORY_DEFAULTS); + enumTestList.add(SdlDisconnectedReason.TRANSPORT_ERROR); + enumTestList.add(SdlDisconnectedReason.APPLICATION_REQUESTED_DISCONNECT); + enumTestList.add(SdlDisconnectedReason.DEFAULT); + enumTestList.add(SdlDisconnectedReason.TRANSPORT_DISCONNECT); + enumTestList.add(SdlDisconnectedReason.HB_TIMEOUT); + enumTestList.add(SdlDisconnectedReason.BLUETOOTH_DISABLED); + enumTestList.add(SdlDisconnectedReason.BLUETOOTH_ADAPTER_ERROR); + enumTestList.add(SdlDisconnectedReason.SDL_REGISTRATION_ERROR); + enumTestList.add(SdlDisconnectedReason.APP_INTERFACE_UNREG); + enumTestList.add(SdlDisconnectedReason.GENERIC_ERROR); + enumTestList.add(SdlDisconnectedReason.LEGACY_BLUETOOTH_MODE_ENABLED); + enumTestList.add(SdlDisconnectedReason.RPC_SESSION_ENDED); + enumTestList.add(SdlDisconnectedReason.PRIMARY_TRANSPORT_CYCLE_REQUEST); + enumTestList.add(SdlDisconnectedReason.MINIMUM_PROTOCOL_VERSION_HIGHER_THAN_SUPPORTED); + enumTestList.add(SdlDisconnectedReason.MINIMUM_RPC_VERSION_HIGHER_THAN_SUPPORTED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } + + /** + * Verifies the valid returns of the conversion method, + * {@link com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason#convertAppInterfaceunregisteredReason(AppInterfaceUnregisteredReason)} + */ + public void testConvertMethod () { + assertEquals(Test.MATCH, SdlDisconnectedReason.DEFAULT, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.APP_UNAUTHORIZED)); + assertEquals(Test.MATCH, SdlDisconnectedReason.BLUETOOTH_OFF, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.BLUETOOTH_OFF)); + assertEquals(Test.MATCH, SdlDisconnectedReason.DRIVER_DISTRACTION_VIOLATION, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.DRIVER_DISTRACTION_VIOLATION)); + assertEquals(Test.MATCH, SdlDisconnectedReason.FACTORY_DEFAULTS, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.FACTORY_DEFAULTS)); + assertEquals(Test.MATCH, SdlDisconnectedReason.IGNITION_OFF, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.IGNITION_OFF)); + assertEquals(Test.MATCH, SdlDisconnectedReason.LANGUAGE_CHANGE, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.LANGUAGE_CHANGE)); + assertEquals(Test.MATCH, SdlDisconnectedReason.MASTER_RESET, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.MASTER_RESET)); + assertEquals(Test.MATCH, SdlDisconnectedReason.REQUEST_WHILE_IN_NONE_HMI_LEVEL, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.REQUEST_WHILE_IN_NONE_HMI_LEVEL)); + assertEquals(Test.MATCH, SdlDisconnectedReason.TOO_MANY_REQUESTS, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.TOO_MANY_REQUESTS)); + assertEquals(Test.MATCH, SdlDisconnectedReason.USB_DISCONNECTED, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.USB_DISCONNECTED)); + assertEquals(Test.MATCH, SdlDisconnectedReason.USER_EXIT, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(AppInterfaceUnregisteredReason.USER_EXIT)); + assertNull(Test.MATCH, SdlDisconnectedReason.convertAppInterfaceUnregisteredReason(null)); + } + +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SeatMemoryActionTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SeatMemoryActionTypeTests.java new file mode 100644 index 000000000..2642e35d3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SeatMemoryActionTypeTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.SeatMemoryActionType; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.SeatMemoryActionType} + */ +public class SeatMemoryActionTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "SAVE"; + SeatMemoryActionType enumSave = SeatMemoryActionType.valueForString(example); + example = "RESTORE"; + SeatMemoryActionType enumRestore = SeatMemoryActionType.valueForString(example); + example = "NONE"; + SeatMemoryActionType enumNone = SeatMemoryActionType.valueForString(example); + + assertNotNull("SAVE returned null", enumSave); + assertNotNull("RESTORE returned null", enumRestore); + assertNotNull("NONE returned null", enumNone); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "sAVE"; + try { + SeatMemoryActionType temp = SeatMemoryActionType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + SeatMemoryActionType temp = SeatMemoryActionType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SeatMemoryActionType. + */ + public void testListEnum() { + List<SeatMemoryActionType> enumValueList = Arrays.asList(SeatMemoryActionType.values()); + + List<SeatMemoryActionType> enumTestList = new ArrayList<SeatMemoryActionType>(); + enumTestList.add(SeatMemoryActionType.SAVE); + enumTestList.add(SeatMemoryActionType.RESTORE); + enumTestList.add(SeatMemoryActionType.NONE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ServiceUpdateReasonTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ServiceUpdateReasonTests.java new file mode 100644 index 000000000..f2484ff9e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ServiceUpdateReasonTests.java @@ -0,0 +1,84 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.ServiceUpdateReason; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.ServiceUpdateReason} + */ +public class ServiceUpdateReasonTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "PUBLISHED"; + ServiceUpdateReason enumPublished = ServiceUpdateReason.valueForString(example); + example = "REMOVED"; + ServiceUpdateReason enumRemoved = ServiceUpdateReason.valueForString(example); + example = "ACTIVATED"; + ServiceUpdateReason enumActivated = ServiceUpdateReason.valueForString(example); + example = "DEACTIVATED"; + ServiceUpdateReason enumDeactivated = ServiceUpdateReason.valueForString(example); + example = "MANIFEST_UPDATE"; + ServiceUpdateReason enumManifestUpdate = ServiceUpdateReason.valueForString(example); + + + assertNotNull("PUBLISHED returned null", enumPublished); + assertNotNull("REMOVED returned null", enumRemoved); + assertNotNull("ACTIVATED returned null", enumActivated); + assertNotNull("DEACTIVATED returned null", enumDeactivated); + assertNotNull("MANIFEST_UPDATE returned null", enumManifestUpdate); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "HalFActIvAted"; + try { + ServiceUpdateReason temp = ServiceUpdateReason.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + ServiceUpdateReason temp = ServiceUpdateReason.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of ServiceUpdateReason. + */ + public void testListEnum() { + List<ServiceUpdateReason> enumValueList = Arrays.asList(ServiceUpdateReason.values()); + + List<ServiceUpdateReason> enumTestList = new ArrayList<>(); + enumTestList.add(ServiceUpdateReason.MANIFEST_UPDATE); + enumTestList.add(ServiceUpdateReason.ACTIVATED); + enumTestList.add(ServiceUpdateReason.DEACTIVATED); + enumTestList.add(ServiceUpdateReason.PUBLISHED); + enumTestList.add(ServiceUpdateReason.REMOVED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SoftButtonTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SoftButtonTypeTests.java new file mode 100644 index 000000000..d4ef5c0ff --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SoftButtonTypeTests.java @@ -0,0 +1,76 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.SoftButtonType; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.SoftButtonType} + */ +public class SoftButtonTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "TEXT"; + SoftButtonType enumText = SoftButtonType.valueForString(example); + example = "IMAGE"; + SoftButtonType enumImage = SoftButtonType.valueForString(example); + example = "BOTH"; + SoftButtonType enumBoth = SoftButtonType.valueForString(example); + + assertNotNull("TEXT returned null", enumText); + assertNotNull("IMAGE returned null", enumImage); + assertNotNull("BOTH returned null", enumBoth); + } + + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "teXT"; + try { + SoftButtonType temp = SoftButtonType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + SoftButtonType temp = SoftButtonType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SoftButtonType. + */ + public void testListEnum() { + List<SoftButtonType> enumValueList = Arrays.asList(SoftButtonType.values()); + + List<SoftButtonType> enumTestList = new ArrayList<SoftButtonType>(); + enumTestList.add(SoftButtonType.SBT_TEXT); + enumTestList.add(SoftButtonType.SBT_IMAGE); + enumTestList.add(SoftButtonType.SBT_BOTH); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SpeechCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SpeechCapabilitiesTests.java new file mode 100644 index 000000000..364f7c896 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SpeechCapabilitiesTests.java @@ -0,0 +1,84 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.SpeechCapabilities} + */ +public class SpeechCapabilitiesTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "TEXT"; + SpeechCapabilities enumText = SpeechCapabilities.valueForString(example); + example = "SAPI_PHONEMES"; + SpeechCapabilities enumSapiPhonemes = SpeechCapabilities.valueForString(example); + example = "LHPLUS_PHONEMES"; + SpeechCapabilities enumLhplusPhonemes = SpeechCapabilities.valueForString(example); + example = "PRE_RECORDED"; + SpeechCapabilities enumPreRecorded = SpeechCapabilities.valueForString(example); + example = "SILENCE"; + SpeechCapabilities enumSilence = SpeechCapabilities.valueForString(example); + + assertNotNull("TEXT returned null", enumText); + assertNotNull("SAPI_PHONEMES returned null", enumSapiPhonemes); + assertNotNull("LHPLUS_PHONEMES returned null", enumLhplusPhonemes); + assertNotNull("PRE_RECORDED returned null", enumPreRecorded); + assertNotNull("SILENCE returned null", enumSilence); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "teXT"; + try { + SpeechCapabilities temp = SpeechCapabilities.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + SpeechCapabilities temp = SpeechCapabilities.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SpeechCapabilities. + */ + public void testListEnum() { + List<SpeechCapabilities> enumValueList = Arrays.asList(SpeechCapabilities.values()); + + List<SpeechCapabilities> enumTestList = new ArrayList<SpeechCapabilities>(); + enumTestList.add(SpeechCapabilities.TEXT); + enumTestList.add(SpeechCapabilities.SAPI_PHONEMES); + enumTestList.add(SpeechCapabilities.LHPLUS_PHONEMES); + enumTestList.add(SpeechCapabilities.PRE_RECORDED); + enumTestList.add(SpeechCapabilities.SILENCE); + enumTestList.add(SpeechCapabilities.FILE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/StaticIconNameTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/StaticIconNameTests.java new file mode 100644 index 000000000..b85905039 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/StaticIconNameTests.java @@ -0,0 +1,931 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.StaticIconName; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.StaticIconName} + */ +public class StaticIconNameTests extends TestCase { + + public void testValidEnums(){ + String example = "0x29"; + StaticIconName ACCEPT_CALL = StaticIconName.valueForString(example); + assertNotNull("ACCEPT_CALL returned null", ACCEPT_CALL); + + example = "0x1B"; + StaticIconName ADD_WAYPOINT = StaticIconName.valueForString(example); + assertNotNull("ADD_WAYPOINT returned null", ADD_WAYPOINT); + + example = "0x21"; + StaticIconName ALBUM = StaticIconName.valueForString(example); + assertNotNull("ALBUM returned null", ALBUM); + + example = "0x3d"; + StaticIconName AMBIENT_LIGHTING = StaticIconName.valueForString(example); + assertNotNull("AMBIENT_LIGHTING returned null", AMBIENT_LIGHTING); + + example = "0x40"; + StaticIconName ARROW_NORTH = StaticIconName.valueForString(example); + assertNotNull("ARROW_NORTH returned null", ARROW_NORTH); + + example = "0x12"; + StaticIconName AUDIO_MUTE = StaticIconName.valueForString(example); + assertNotNull("AUDIO_MUTE returned null", AUDIO_MUTE); + + example = "0x83"; + StaticIconName AUDIOBOOK_EPISODE = StaticIconName.valueForString(example); + assertNotNull("AUDIOBOOK_EPISODE returned null", AUDIOBOOK_EPISODE); + + example = "0x82"; + StaticIconName AUDIOBOOK_NARRATOR = StaticIconName.valueForString(example); + assertNotNull("AUDIOBOOK_NARRATOR returned null", AUDIOBOOK_NARRATOR); + + example = "0x45"; + StaticIconName AUXILLARY_AUDIO = StaticIconName.valueForString(example); + assertNotNull("AUXILLARY_AUDIO returned null", AUXILLARY_AUDIO); + + example = "0x86"; + StaticIconName BACK = StaticIconName.valueForString(example); + assertNotNull("BACK returned null", BACK); + + example = "0xF7"; + StaticIconName BATTERY_CAPACITY_0_OF_5 = StaticIconName.valueForString(example); + assertNotNull("BATTERY_CAPACITY_0_OF_5 returned null", BATTERY_CAPACITY_0_OF_5); + + example = "0xF8"; + StaticIconName BATTERY_CAPACITY_1_OF_5 = StaticIconName.valueForString(example); + assertNotNull("BATTERY_CAPACITY_1_OF_5 returned null", BATTERY_CAPACITY_1_OF_5); + + example = "0xF9"; + StaticIconName BATTERY_CAPACITY_2_OF_5 = StaticIconName.valueForString(example); + assertNotNull("BATTERY_CAPACITY_2_OF_5 returned null", BATTERY_CAPACITY_2_OF_5); + + example = "0xFA"; + StaticIconName BATTERY_CAPACITY_3_OF_5 = StaticIconName.valueForString(example); + assertNotNull("BATTERY_CAPACITY_3_OF_5 returned null", BATTERY_CAPACITY_3_OF_5); + + example = "0xf6"; + StaticIconName BATTERY_CAPACITY_4_OF_5 = StaticIconName.valueForString(example); + assertNotNull("BATTERY_CAPACITY_4_OF_5 returned null", BATTERY_CAPACITY_4_OF_5); + + example = "0xFB"; + StaticIconName BATTERY_CAPACITY_5_OF_5 = StaticIconName.valueForString(example); + assertNotNull("BATTERY_CAPACITY_5_OF_5 returned null", BATTERY_CAPACITY_5_OF_5); + + example = "0x09"; + StaticIconName BLUETOOTH_AUDIO_SOURCE = StaticIconName.valueForString(example); + assertNotNull("BLUETOOTH_AUDIO_SOURCE returned null", BLUETOOTH_AUDIO_SOURCE); + + example = "0xcc"; + StaticIconName BLUETOOTH1 = StaticIconName.valueForString(example); + assertNotNull("BLUETOOTH1 returned null", BLUETOOTH1); + + example = "0xCD"; + StaticIconName BLUETOOTH2 = StaticIconName.valueForString(example); + assertNotNull("BLUETOOTH2 returned null", BLUETOOTH2); + + example = "0x77"; + StaticIconName BROWSE = StaticIconName.valueForString(example); + assertNotNull("BROWSE returned null", BROWSE); + + example = "0x66"; + StaticIconName CELL_PHONE_IN_ROAMING_MODE = StaticIconName.valueForString(example); + assertNotNull("CELL_PHONE_IN_ROAMING_MODE returned null", CELL_PHONE_IN_ROAMING_MODE); + + example = "0x67"; + StaticIconName CELL_SERVICE_SIGNAL_STRENGTH_0_OF_5_BARS = StaticIconName.valueForString(example); + assertNotNull("CELL_SERVICE_SIGNAL_STRENGTH_0_OF_5_BARS returned null", CELL_SERVICE_SIGNAL_STRENGTH_0_OF_5_BARS); + + example = "0x68"; + StaticIconName CELL_SERVICE_SIGNAL_STRENGTH_1_OF_5_BARS = StaticIconName.valueForString(example); + assertNotNull("CELL_SERVICE_SIGNAL_STRENGTH_1_OF_5_BARS returned null", CELL_SERVICE_SIGNAL_STRENGTH_1_OF_5_BARS); + + example = "0x69"; + StaticIconName CELL_SERVICE_SIGNAL_STRENGTH_2_OF_5_BARS = StaticIconName.valueForString(example); + assertNotNull("CELL_SERVICE_SIGNAL_STRENGTH_2_OF_5_BARS returned null", CELL_SERVICE_SIGNAL_STRENGTH_2_OF_5_BARS); + + example = "0x6A"; + StaticIconName CELL_SERVICE_SIGNAL_STRENGTH_3_OF_5_BARS = StaticIconName.valueForString(example); + assertNotNull("CELL_SERVICE_SIGNAL_STRENGTH_3_OF_5_BARS returned null", CELL_SERVICE_SIGNAL_STRENGTH_3_OF_5_BARS); + + example = "0x6B"; + StaticIconName CELL_SERVICE_SIGNAL_STRENGTH_4_OF_5_BARS = StaticIconName.valueForString(example); + assertNotNull("CELL_SERVICE_SIGNAL_STRENGTH_4_OF_5_BARS returned null", CELL_SERVICE_SIGNAL_STRENGTH_4_OF_5_BARS); + + example = "0xd3"; + StaticIconName CELL_SERVICE_SIGNAL_STRENGTH_5_OF_5_BARS = StaticIconName.valueForString(example); + assertNotNull("CELL_SERVICE_SIGNAL_STRENGTH_5_OF_5_BARS returned null", CELL_SERVICE_SIGNAL_STRENGTH_5_OF_5_BARS); + + example = "0xc3"; + StaticIconName CHANGE_LANE_LEFT = StaticIconName.valueForString(example); + assertNotNull("CHANGE_LANE_LEFT returned null", CHANGE_LANE_LEFT); + + example = "0xc1"; + StaticIconName CHANGE_LANE_RIGHT = StaticIconName.valueForString(example); + assertNotNull("CHANGE_LANE_RIGHT returned null", CHANGE_LANE_RIGHT); + + example = "0x27"; + StaticIconName CHECK_BOX_CHECKED = StaticIconName.valueForString(example); + assertNotNull("CHECK_BOX_CHECKED returned null", CHECK_BOX_CHECKED); + + example = "0x28"; + StaticIconName CHECK_BOX_UNCHECKED = StaticIconName.valueForString(example); + assertNotNull("CHECK_BOX_UNCHECKED returned null", CHECK_BOX_UNCHECKED); + + example = "0xd1"; + StaticIconName CLIMATE = StaticIconName.valueForString(example); + assertNotNull("CLIMATE returned null", CLIMATE); + + example = "0xfc"; + StaticIconName CLOCK = StaticIconName.valueForString(example); + assertNotNull("CLOCK returned null", CLOCK); + + example = "0x1A"; + StaticIconName COMPOSE = StaticIconName.valueForString(example); + assertNotNull("COMPOSE returned null", COMPOSE); + + example = "0x5C"; + StaticIconName CONTACT = StaticIconName.valueForString(example); + assertNotNull("CONTACT returned null", CONTACT); + + example = "0x42"; + StaticIconName CONTINUE = StaticIconName.valueForString(example); + assertNotNull("CONTINUE returned null", CONTINUE); + + example = "0x7F"; + StaticIconName DASH = StaticIconName.valueForString(example); + assertNotNull("DASH returned null", DASH); + + example = "0x87"; + StaticIconName DATE = StaticIconName.valueForString(example); + assertNotNull("DATE returned null", DATE); + + example = "0x0F"; + StaticIconName DELETE = StaticIconName.valueForString(example); + assertNotNull("DELETE returned null", DELETE); + + example = "0x94"; + StaticIconName DESTINATION = StaticIconName.valueForString(example); + assertNotNull("DESTINATION returned null", DESTINATION); + + example = "0x4D"; + StaticIconName DESTINATION_FERRY_AHEAD = StaticIconName.valueForString(example); + assertNotNull("DESTINATION_FERRY_AHEAD returned null", DESTINATION_FERRY_AHEAD); + + example = "0x2B"; + StaticIconName EBOOKMARK = StaticIconName.valueForString(example); + assertNotNull("EBOOKMARK returned null", EBOOKMARK); + + example = "0x2C"; + StaticIconName END_CALL = StaticIconName.valueForString(example); + assertNotNull("END_CALL returned null", END_CALL); + + example = "0xD6"; + StaticIconName FAIL = StaticIconName.valueForString(example); + assertNotNull("FAIL returned null", FAIL); + + example = "0x08"; + StaticIconName FAST_FORWARD_30_SECS = StaticIconName.valueForString(example); + assertNotNull("FAST_FORWARD_30_SECS returned null", FAST_FORWARD_30_SECS); + + example = "0x0E"; + StaticIconName FAVORITE_HEART = StaticIconName.valueForString(example); + assertNotNull("FAVORITE_HEART returned null", FAVORITE_HEART); + + example = "0x95"; + StaticIconName FAVORITE_STAR = StaticIconName.valueForString(example); + assertNotNull("FAVORITE_STAR returned null", FAVORITE_STAR); + + example = "0x80"; + StaticIconName FAX_NUMBER = StaticIconName.valueForString(example); + assertNotNull("FAX_NUMBER returned null", FAX_NUMBER); + + example = "0x50"; + StaticIconName FILENAME = StaticIconName.valueForString(example); + assertNotNull("FILENAME returned null", FILENAME); + + example = "0x79"; + StaticIconName FILTER = StaticIconName.valueForString(example); + assertNotNull("FILTER returned null", FILTER); + + example = "0x1C"; + StaticIconName FOLDER = StaticIconName.valueForString(example); + assertNotNull("FOLDER returned null", FOLDER); + + example = "0xe9"; + StaticIconName FUEL_PRICES = StaticIconName.valueForString(example); + assertNotNull("FUEL_PRICES returned null", FUEL_PRICES); + + example = "0x0c"; + StaticIconName FULL_MAP = StaticIconName.valueForString(example); + assertNotNull("FULL_MAP returned null", FULL_MAP); + + example = "0x53"; + StaticIconName GENERIC_PHONE_NUMBER = StaticIconName.valueForString(example); + assertNotNull("GENERIC_PHONE_NUMBER returned null", GENERIC_PHONE_NUMBER); + + example = "0x4E"; + StaticIconName GENRE = StaticIconName.valueForString(example); + assertNotNull("GENRE returned null", GENRE); + + example = "0xea"; + StaticIconName GLOBAL_KEYBOARD = StaticIconName.valueForString(example); + assertNotNull("GLOBAL_KEYBOARD returned null", GLOBAL_KEYBOARD); + + example = "0xf4"; + StaticIconName HIGHWAY_EXIT_INFORMATION = StaticIconName.valueForString(example); + assertNotNull("HIGHWAY_EXIT_INFORMATION returned null", HIGHWAY_EXIT_INFORMATION); + + example = "0x55"; + StaticIconName HOME_PHONE_NUMBER = StaticIconName.valueForString(example); + assertNotNull("HOME_PHONE_NUMBER returned null", HOME_PHONE_NUMBER); + + example = "0x78"; + StaticIconName HYPERLINK = StaticIconName.valueForString(example); + assertNotNull("HYPERLINK returned null", HYPERLINK); + + example = "0x51"; + StaticIconName ID3_TAG_UNKNOWN = StaticIconName.valueForString(example); + assertNotNull("ID3_TAG_UNKNOWN returned null", ID3_TAG_UNKNOWN); + + example = "0x57"; + StaticIconName INCOMING_CALLS = StaticIconName.valueForString(example); + assertNotNull("INCOMING_CALLS returned null", INCOMING_CALLS); + + example = "0x5d"; + StaticIconName INFORMATION = StaticIconName.valueForString(example); + assertNotNull("INFORMATION returned null", INFORMATION); + + example = "0x0D"; + StaticIconName IPOD_MEDIA_SOURCE = StaticIconName.valueForString(example); + assertNotNull("IPOD_MEDIA_SOURCE returned null", IPOD_MEDIA_SOURCE); + + example = "0x02"; + StaticIconName JOIN_CALLS = StaticIconName.valueForString(example); + assertNotNull("JOIN_CALLS returned null", JOIN_CALLS); + + example = "0x46"; + StaticIconName KEEP_LEFT = StaticIconName.valueForString(example); + assertNotNull("KEEP_LEFT returned null", KEEP_LEFT); + + example = "0x48"; + StaticIconName KEEP_RIGHT = StaticIconName.valueForString(example); + assertNotNull("KEEP_RIGHT returned null", KEEP_RIGHT); + + example = "0x7D"; + StaticIconName KEY = StaticIconName.valueForString(example); + assertNotNull("KEY returned null", KEY); + + example = "0x9f"; + StaticIconName LEFT = StaticIconName.valueForString(example); + assertNotNull("LEFT returned null", LEFT); + + example = "0x4B"; + StaticIconName LEFT_ARROW = StaticIconName.valueForString(example); + assertNotNull("LEFT_ARROW returned null", LEFT_ARROW); + + example = "0xaf"; + StaticIconName LEFT_EXIT = StaticIconName.valueForString(example); + assertNotNull("LEFT_EXIT returned null", LEFT_EXIT); + + example = "0x06"; + StaticIconName LINE_IN_AUDIO_SOURCE = StaticIconName.valueForString(example); + assertNotNull("LINE_IN_AUDIO_SOURCE returned null", LINE_IN_AUDIO_SOURCE); + + example = "0x22"; + StaticIconName LOCKED = StaticIconName.valueForString(example); + assertNotNull("LOCKED returned null", LOCKED); + + example = "0x17"; + StaticIconName MEDIA_CONTROL_LEFT_ARROW = StaticIconName.valueForString(example); + assertNotNull("MEDIA_CONTROL_LEFT_ARROW returned null", MEDIA_CONTROL_LEFT_ARROW); + + example = "0x20"; + StaticIconName MEDIA_CONTROL_RECORDING = StaticIconName.valueForString(example); + assertNotNull("MEDIA_CONTROL_RECORDING returned null", MEDIA_CONTROL_RECORDING); + + example = "0x15"; + StaticIconName MEDIA_CONTROL_RIGHT_ARROW = StaticIconName.valueForString(example); + assertNotNull("MEDIA_CONTROL_RIGHT_ARROW returned null", MEDIA_CONTROL_RIGHT_ARROW); + + example = "0x16"; + StaticIconName MEDIA_CONTROL_STOP = StaticIconName.valueForString(example); + assertNotNull("MEDIA_CONTROL_STOP returned null", MEDIA_CONTROL_STOP); + + example = "0xe8"; + StaticIconName MICROPHONE = StaticIconName.valueForString(example); + assertNotNull("MICROPHONE returned null", MICROPHONE); + + example = "0x58"; + StaticIconName MISSED_CALLS = StaticIconName.valueForString(example); + assertNotNull("MISSED_CALLS returned null", MISSED_CALLS); + + example = "0x54"; + StaticIconName MOBILE_PHONE_NUMBER = StaticIconName.valueForString(example); + assertNotNull("MOBILE_PHONE_NUMBER returned null", MOBILE_PHONE_NUMBER); + + example = "0xE5"; + StaticIconName MOVE_DOWN = StaticIconName.valueForString(example); + assertNotNull("MOVE_DOWN returned null", MOVE_DOWN); + + example = "0xe4"; + StaticIconName MOVE_UP = StaticIconName.valueForString(example); + assertNotNull("MOVE_UP returned null", MOVE_UP); + + example = "0x24"; + StaticIconName MP3_TAG_ARTIST = StaticIconName.valueForString(example); + assertNotNull("MP3_TAG_ARTIST returned null", MP3_TAG_ARTIST); + + example = "0x8e"; + StaticIconName NAVIGATION = StaticIconName.valueForString(example); + assertNotNull("NAVIGATION returned null", NAVIGATION); + + example = "0x0a"; + StaticIconName NAVIGATION_CURRENT_DIRECTION = StaticIconName.valueForString(example); + assertNotNull("NAVIGATION_CURRENT_DIRECTION returned null", NAVIGATION_CURRENT_DIRECTION); + + example = "0x14"; + StaticIconName NEGATIVE_RATING_THUMBS_DOWN = StaticIconName.valueForString(example); + assertNotNull("NEGATIVE_RATING_THUMBS_DOWN returned null", NEGATIVE_RATING_THUMBS_DOWN); + + example = "0x5E"; + StaticIconName NEW = StaticIconName.valueForString(example); + assertNotNull("NEW returned null", NEW); + + example = "0x56"; + StaticIconName OFFICE_PHONE_NUMBER = StaticIconName.valueForString(example); + assertNotNull("OFFICE_PHONE_NUMBER returned null", OFFICE_PHONE_NUMBER); + + example = "0x5F"; + StaticIconName OPENED = StaticIconName.valueForString(example); + assertNotNull("OPENED returned null", OPENED); + + example = "0x96"; + StaticIconName ORIGIN = StaticIconName.valueForString(example); + assertNotNull("ORIGIN returned null", ORIGIN); + + example = "0x59"; + StaticIconName OUTGOING_CALLS = StaticIconName.valueForString(example); + assertNotNull("OUTGOING_CALLS returned null", OUTGOING_CALLS); + + example = "0x1D"; + StaticIconName PHONE_CALL_1 = StaticIconName.valueForString(example); + assertNotNull("PHONE_CALL_1 returned null", PHONE_CALL_1); + + example = "0x1E"; + StaticIconName PHONE_CALL_2 = StaticIconName.valueForString(example); + assertNotNull("PHONE_CALL_2 returned null", PHONE_CALL_2); + + example = "0x03"; + StaticIconName PHONE_DEVICE = StaticIconName.valueForString(example); + assertNotNull("PHONE_DEVICE returned null", PHONE_DEVICE); + + example = "0x81"; + StaticIconName PHONEBOOK = StaticIconName.valueForString(example); + assertNotNull("PHONEBOOK returned null", PHONEBOOK); + + example = "0x88"; + StaticIconName PHOTO = StaticIconName.valueForString(example); + assertNotNull("PHOTO returned null", PHOTO); + + example = "0xD0"; + StaticIconName PLAY = StaticIconName.valueForString(example); + assertNotNull("PLAY returned null", PLAY); + + example = "0x4F"; + StaticIconName PLAYLIST = StaticIconName.valueForString(example); + assertNotNull("PLAYLIST returned null", PLAYLIST); + + example = "0x76"; + StaticIconName POPUP = StaticIconName.valueForString(example); + assertNotNull("POPUP returned null", POPUP); + + example = "0x13"; + StaticIconName POSITIVE_RATING_THUMBS_UP = StaticIconName.valueForString(example); + assertNotNull("POSITIVE_RATING_THUMBS_UP returned null", POSITIVE_RATING_THUMBS_UP); + + example = "0x5b"; + StaticIconName POWER = StaticIconName.valueForString(example); + assertNotNull("POWER returned null", POWER); + + example = "0x1F"; + StaticIconName PRIMARY_PHONE = StaticIconName.valueForString(example); + assertNotNull("PRIMARY_PHONE returned null", PRIMARY_PHONE); + + example = "0x25"; + StaticIconName RADIO_BUTTON_CHECKED = StaticIconName.valueForString(example); + assertNotNull("RADIO_BUTTON_CHECKED returned null", RADIO_BUTTON_CHECKED); + + example = "0x26"; + StaticIconName RADIO_BUTTON_UNCHECKED = StaticIconName.valueForString(example); + assertNotNull("RADIO_BUTTON_UNCHECKED returned null", RADIO_BUTTON_UNCHECKED); + + example = "0xe7"; + StaticIconName RECENT_CALLS = StaticIconName.valueForString(example); + assertNotNull("RECENT_CALLS returned null", RECENT_CALLS); + + example = "0xf2"; + StaticIconName RECENT_DESTINATIONS = StaticIconName.valueForString(example); + assertNotNull("RECENT_DESTINATIONS returned null", RECENT_DESTINATIONS); + + example = "0x19"; + StaticIconName REDO = StaticIconName.valueForString(example); + assertNotNull("REDO returned null", REDO); + + example = "0x97"; + StaticIconName REFRESH = StaticIconName.valueForString(example); + assertNotNull("REFRESH returned null", REFRESH); + + example = "0x7E"; + StaticIconName REMOTE_DIAGNOSTICS_CHECK_ENGINE = StaticIconName.valueForString(example); + assertNotNull("REMOTE_DIAGNOSTICS_CHECK_ENGINE returned null", REMOTE_DIAGNOSTICS_CHECK_ENGINE); + + example = "0xac"; + StaticIconName RENDERED_911_ASSIST = StaticIconName.valueForString(example); + assertNotNull("RENDERED_911_ASSIST returned null", RENDERED_911_ASSIST); + + example = "0xe6"; + StaticIconName REPEAT = StaticIconName.valueForString(example); + assertNotNull("REPEAT returned null", REPEAT); + + example = "0x73"; + StaticIconName REPEAT_PLAY = StaticIconName.valueForString(example); + assertNotNull("REPEAT_PLAY returned null", REPEAT_PLAY); + + example = "0x04"; + StaticIconName REPLY = StaticIconName.valueForString(example); + assertNotNull("REPLY returned null", REPLY); + + example = "0x07"; + StaticIconName REWIND_30_SECS = StaticIconName.valueForString(example); + assertNotNull("REWIND_30_SECS returned null", REWIND_30_SECS); + + example = "0xa3"; + StaticIconName RIGHT = StaticIconName.valueForString(example); + assertNotNull("RIGHT returned null", RIGHT); + + example = "0xb1"; + StaticIconName RIGHT_EXIT = StaticIconName.valueForString(example); + assertNotNull("RIGHT_EXIT returned null", RIGHT_EXIT); + + example = "0x5A"; + StaticIconName RINGTONES = StaticIconName.valueForString(example); + assertNotNull("RINGTONES returned null", RINGTONES); + + example = "0xee"; + StaticIconName ROUNDABOUT_LEFT_HAND_1 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_LEFT_HAND_1 returned null", ROUNDABOUT_LEFT_HAND_1); + + example = "0x8c"; + StaticIconName ROUNDABOUT_LEFT_HAND_2 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_LEFT_HAND_2 returned null", ROUNDABOUT_LEFT_HAND_2); + + example = "0x84"; + StaticIconName ROUNDABOUT_LEFT_HAND_3 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_LEFT_HAND_3 returned null", ROUNDABOUT_LEFT_HAND_3); + + example = "0x72"; + StaticIconName ROUNDABOUT_LEFT_HAND_4 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_LEFT_HAND_4 returned null", ROUNDABOUT_LEFT_HAND_4); + + example = "0x6e"; + StaticIconName ROUNDABOUT_LEFT_HAND_5 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_LEFT_HAND_5 returned null", ROUNDABOUT_LEFT_HAND_5); + + example = "0x64"; + StaticIconName ROUNDABOUT_LEFT_HAND_6 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_LEFT_HAND_6 returned null", ROUNDABOUT_LEFT_HAND_6); + + example = "0x60"; + StaticIconName ROUNDABOUT_LEFT_HAND_7 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_LEFT_HAND_7 returned null", ROUNDABOUT_LEFT_HAND_7); + + example = "0x62"; + StaticIconName ROUNDABOUT_RIGHT_HAND_1 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_RIGHT_HAND_1 returned null", ROUNDABOUT_RIGHT_HAND_1); + + example = "0x6c"; + StaticIconName ROUNDABOUT_RIGHT_HAND_2 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_RIGHT_HAND_2 returned null", ROUNDABOUT_RIGHT_HAND_2); + + example = "0x70"; + StaticIconName ROUNDABOUT_RIGHT_HAND_3 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_RIGHT_HAND_3 returned null", ROUNDABOUT_RIGHT_HAND_3); + + example = "0x7a"; + StaticIconName ROUNDABOUT_RIGHT_HAND_4 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_RIGHT_HAND_4 returned null", ROUNDABOUT_RIGHT_HAND_4); + + example = "0x8a"; + StaticIconName ROUNDABOUT_RIGHT_HAND_5 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_RIGHT_HAND_5 returned null", ROUNDABOUT_RIGHT_HAND_5); + + example = "0xec"; + StaticIconName ROUNDABOUT_RIGHT_HAND_6 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_RIGHT_HAND_6 returned null", ROUNDABOUT_RIGHT_HAND_6); + + example = "0xf0"; + StaticIconName ROUNDABOUT_RIGHT_HAND_7 = StaticIconName.valueForString(example); + assertNotNull("ROUNDABOUT_RIGHT_HAND_7 returned null", ROUNDABOUT_RIGHT_HAND_7); + + example = "0x89"; + StaticIconName RSS = StaticIconName.valueForString(example); + assertNotNull("RSS returned null", RSS); + + example = "0x49"; + StaticIconName SETTINGS = StaticIconName.valueForString(example); + assertNotNull("SETTINGS returned null", SETTINGS); + + example = "0xa5"; + StaticIconName SHARP_LEFT = StaticIconName.valueForString(example); + assertNotNull("SHARP_LEFT returned null", SHARP_LEFT); + + example = "0xe1"; + StaticIconName SHOW = StaticIconName.valueForString(example); + assertNotNull("SHOW returned null", SHOW); + + example = "0x74"; + StaticIconName SHUFFLE_PLAY = StaticIconName.valueForString(example); + assertNotNull("SHUFFLE_PLAY returned null", SHUFFLE_PLAY); + + example = "0xab"; + StaticIconName SKI_PLACES = StaticIconName.valueForString(example); + assertNotNull("SKI_PLACES returned null", SKI_PLACES); + + example = "0x9d"; + StaticIconName SLIGHT_LEFT = StaticIconName.valueForString(example); + assertNotNull("SLIGHT_LEFT returned null", SLIGHT_LEFT); + + example = "0xa1"; + StaticIconName SLIGHT_RIGHT = StaticIconName.valueForString(example); + assertNotNull("SLIGHT_RIGHT returned null", SLIGHT_RIGHT); + + example = "0x05"; + StaticIconName SMARTPHONE = StaticIconName.valueForString(example); + assertNotNull("SMARTPHONE returned null", SMARTPHONE); + + example = "0x7B"; + StaticIconName SORT_LIST = StaticIconName.valueForString(example); + assertNotNull("SORT_LIST returned null", SORT_LIST); + + example = "0xE0"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_0 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_0 returned null", SPEED_DIAL_NUMBERS_NUMBER_0); + + example = "0xD7"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_1 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_1 returned null", SPEED_DIAL_NUMBERS_NUMBER_1); + + example = "0xD8"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_2 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_2 returned null", SPEED_DIAL_NUMBERS_NUMBER_2); + + example = "0xD9"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_3 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_3 returned null", SPEED_DIAL_NUMBERS_NUMBER_3); + + example = "0xDA"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_4 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_4 returned null", SPEED_DIAL_NUMBERS_NUMBER_4); + + example = "0xDB"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_5 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_5 returned null", SPEED_DIAL_NUMBERS_NUMBER_5); + + example = "0xDC"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_6 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_6 returned null", SPEED_DIAL_NUMBERS_NUMBER_6); + + example = "0xDD"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_7 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_7 returned null", SPEED_DIAL_NUMBERS_NUMBER_7); + + example = "0xDE"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_8 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_8 returned null", SPEED_DIAL_NUMBERS_NUMBER_8); + + example = "0xDF"; + StaticIconName SPEED_DIAL_NUMBERS_NUMBER_9 = StaticIconName.valueForString(example); + assertNotNull("SPEED_DIAL_NUMBERS_NUMBER_9 returned null", SPEED_DIAL_NUMBERS_NUMBER_9); + + example = "0xD5"; + StaticIconName SUCCESS = StaticIconName.valueForString(example); + assertNotNull("SUCCESS returned null", SUCCESS); + + example = "0x4C"; + StaticIconName TRACK_TITLE = StaticIconName.valueForString(example); + assertNotNull("TRACK_TITLE returned null", TRACK_TITLE); + + example = "0x2A"; + StaticIconName TRAFFIC_REPORT = StaticIconName.valueForString(example); + assertNotNull("TRAFFIC_REPORT returned null", TRAFFIC_REPORT); + + example = "0x10"; + StaticIconName TURN_LIST = StaticIconName.valueForString(example); + assertNotNull("TURN_LIST returned null", TURN_LIST); + + example = "0xad"; + StaticIconName UTURN_LEFT_TRAFFIC = StaticIconName.valueForString(example); + assertNotNull("UTURN_LEFT_TRAFFIC returned null", UTURN_LEFT_TRAFFIC); + + example = "0xa9"; + StaticIconName UTURN_RIGHT_TRAFFIC = StaticIconName.valueForString(example); + assertNotNull("UTURN_RIGHT_TRAFFIC returned null", UTURN_RIGHT_TRAFFIC); + + example = "0x18"; + StaticIconName UNDO = StaticIconName.valueForString(example); + assertNotNull("UNDO returned null", UNDO); + + example = "0x23"; + StaticIconName UNLOCKED = StaticIconName.valueForString(example); + assertNotNull("UNLOCKED returned null", UNLOCKED); + + example = "0x0B"; + StaticIconName USB_MEDIA_AUDIO_SOURCE = StaticIconName.valueForString(example); + assertNotNull("USB_MEDIA_AUDIO_SOURCE returned null", USB_MEDIA_AUDIO_SOURCE); + + example = "0xC7"; + StaticIconName VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_1 = StaticIconName.valueForString(example); + assertNotNull("VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_1 returned null", VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_1); + + example = "0xC8"; + StaticIconName VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_2 = StaticIconName.valueForString(example); + assertNotNull("VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_2 returned null", VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_2); + + example = "0xC9"; + StaticIconName VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_3 = StaticIconName.valueForString(example); + assertNotNull("VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_3 returned null", VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_3); + + example = "0xCA"; + StaticIconName VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_4 = StaticIconName.valueForString(example); + assertNotNull("VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_4 returned null", VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_4); + + example = "0x90"; + StaticIconName VOICE_RECOGNITION_FAILED = StaticIconName.valueForString(example); + assertNotNull("VOICE_RECOGNITION_FAILED returned null", VOICE_RECOGNITION_FAILED); + + example = "0x92"; + StaticIconName VOICE_RECOGNITION_PAUSE = StaticIconName.valueForString(example); + assertNotNull("VOICE_RECOGNITION_PAUSE returned null", VOICE_RECOGNITION_PAUSE); + + example = "0x8F"; + StaticIconName VOICE_RECOGNITION_SUCCESSFUL = StaticIconName.valueForString(example); + assertNotNull("VOICE_RECOGNITION_SUCCESSFUL returned null", VOICE_RECOGNITION_SUCCESSFUL); + + example = "0x11"; + StaticIconName VOICE_RECOGNITION_SYSTEM_ACTIVE = StaticIconName.valueForString(example); + assertNotNull("VOICE_RECOGNITION_SYSTEM_ACTIVE returned null", VOICE_RECOGNITION_SYSTEM_ACTIVE); + + example = "0x91"; + StaticIconName VOICE_RECOGNITION_SYSTEM_LISTENING = StaticIconName.valueForString(example); + assertNotNull("VOICE_RECOGNITION_SYSTEM_LISTENING returned null", VOICE_RECOGNITION_SYSTEM_LISTENING); + + example = "0x93"; + StaticIconName VOICE_RECOGNITION_TRY_AGAIN = StaticIconName.valueForString(example); + assertNotNull("VOICE_RECOGNITION_TRY_AGAIN returned null", VOICE_RECOGNITION_TRY_AGAIN); + + example = "0xfe"; + StaticIconName WARNING = StaticIconName.valueForString(example); + assertNotNull("WARNING returned null", WARNING); + + example = "0xeb"; + StaticIconName WEATHER = StaticIconName.valueForString(example); + assertNotNull("WEATHER returned null", WEATHER); + + example = "0x43"; + StaticIconName WIFI_FULL = StaticIconName.valueForString(example); + assertNotNull("WIFI_FULL returned null", WIFI_FULL); + + example = "0x98"; + StaticIconName ZOOM_IN = StaticIconName.valueForString(example); + assertNotNull("ZOOM_IN returned null", ZOOM_IN); + + example = "0x9a"; + StaticIconName ZOOM_OUT = StaticIconName.valueForString(example); + assertNotNull("ZOOM_OUT returned null", ZOOM_OUT); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "SoMeThInG"; + try { + StaticIconName SOMETHING = StaticIconName.valueForString(example); + assertNull("Result of valueForString should be null.", SOMETHING); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + StaticIconName temp = StaticIconName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of StaticIconNames. + */ + public void testListEnum() { + + List<StaticIconName> enumValueList = Arrays.asList(StaticIconName.values()); + + List<StaticIconName> enumTestList = new ArrayList<>(); + enumTestList.add(StaticIconName.ACCEPT_CALL); + enumTestList.add(StaticIconName.ADD_WAYPOINT); + enumTestList.add(StaticIconName.ALBUM); + enumTestList.add(StaticIconName.AMBIENT_LIGHTING); + enumTestList.add(StaticIconName.ARROW_NORTH); + enumTestList.add(StaticIconName.AUDIO_MUTE); + enumTestList.add(StaticIconName.AUDIOBOOK_EPISODE); + enumTestList.add(StaticIconName.AUDIOBOOK_NARRATOR); + enumTestList.add(StaticIconName.AUXILLARY_AUDIO); + enumTestList.add(StaticIconName.BACK); + enumTestList.add(StaticIconName.BATTERY_CAPACITY_0_OF_5); + enumTestList.add(StaticIconName.BATTERY_CAPACITY_1_OF_5); + enumTestList.add(StaticIconName.BATTERY_CAPACITY_2_OF_5); + enumTestList.add(StaticIconName.BATTERY_CAPACITY_3_OF_5); + enumTestList.add(StaticIconName.BATTERY_CAPACITY_4_OF_5); + enumTestList.add(StaticIconName.BATTERY_CAPACITY_5_OF_5); + enumTestList.add(StaticIconName.BLUETOOTH_AUDIO_SOURCE); + enumTestList.add(StaticIconName.BLUETOOTH1); + enumTestList.add(StaticIconName.BLUETOOTH2); + enumTestList.add(StaticIconName.BROWSE); + enumTestList.add(StaticIconName.CELL_PHONE_IN_ROAMING_MODE); + enumTestList.add(StaticIconName.CELL_SERVICE_SIGNAL_STRENGTH_0_OF_5_BARS); + enumTestList.add(StaticIconName.CELL_SERVICE_SIGNAL_STRENGTH_1_OF_5_BARS); + enumTestList.add(StaticIconName.CELL_SERVICE_SIGNAL_STRENGTH_2_OF_5_BARS); + enumTestList.add(StaticIconName.CELL_SERVICE_SIGNAL_STRENGTH_3_OF_5_BARS); + enumTestList.add(StaticIconName.CELL_SERVICE_SIGNAL_STRENGTH_4_OF_5_BARS); + enumTestList.add(StaticIconName.CELL_SERVICE_SIGNAL_STRENGTH_5_OF_5_BARS); + enumTestList.add(StaticIconName.CHANGE_LANE_LEFT); + enumTestList.add(StaticIconName.CHANGE_LANE_RIGHT); + enumTestList.add(StaticIconName.CHECK_BOX_CHECKED); + enumTestList.add(StaticIconName.CHECK_BOX_UNCHECKED); + enumTestList.add(StaticIconName.CLIMATE); + enumTestList.add(StaticIconName.CLOCK); + enumTestList.add(StaticIconName.COMPOSE); + enumTestList.add(StaticIconName.CONTACT); + enumTestList.add(StaticIconName.CONTINUE); + enumTestList.add(StaticIconName.DASH); + enumTestList.add(StaticIconName.DATE); + enumTestList.add(StaticIconName.DELETE); + enumTestList.add(StaticIconName.DESTINATION); + enumTestList.add(StaticIconName.DESTINATION_FERRY_AHEAD); + enumTestList.add(StaticIconName.EBOOKMARK); + enumTestList.add(StaticIconName.END_CALL); + enumTestList.add(StaticIconName.FAIL); + enumTestList.add(StaticIconName.FAST_FORWARD_30_SECS); + enumTestList.add(StaticIconName.FAVORITE_HEART); + enumTestList.add(StaticIconName.FAVORITE_STAR); + enumTestList.add(StaticIconName.FAX_NUMBER); + enumTestList.add(StaticIconName.FILENAME); + enumTestList.add(StaticIconName.FILTER); + enumTestList.add(StaticIconName.FOLDER); + enumTestList.add(StaticIconName.FUEL_PRICES); + enumTestList.add(StaticIconName.FULL_MAP); + enumTestList.add(StaticIconName.GENERIC_PHONE_NUMBER); + enumTestList.add(StaticIconName.GENRE); + enumTestList.add(StaticIconName.GLOBAL_KEYBOARD); + enumTestList.add(StaticIconName.HIGHWAY_EXIT_INFORMATION); + enumTestList.add(StaticIconName.HOME_PHONE_NUMBER); + enumTestList.add(StaticIconName.HYPERLINK); + enumTestList.add(StaticIconName.ID3_TAG_UNKNOWN); + enumTestList.add(StaticIconName.INCOMING_CALLS); + enumTestList.add(StaticIconName.INFORMATION); + enumTestList.add(StaticIconName.IPOD_MEDIA_SOURCE); + enumTestList.add(StaticIconName.JOIN_CALLS); + enumTestList.add(StaticIconName.KEEP_LEFT); + enumTestList.add(StaticIconName.KEEP_RIGHT); + enumTestList.add(StaticIconName.KEY); + enumTestList.add(StaticIconName.LEFT); + enumTestList.add(StaticIconName.LEFT_ARROW); + enumTestList.add(StaticIconName.LEFT_EXIT); + enumTestList.add(StaticIconName.LINE_IN_AUDIO_SOURCE); + enumTestList.add(StaticIconName.LOCKED); + enumTestList.add(StaticIconName.MEDIA_CONTROL_LEFT_ARROW); + enumTestList.add(StaticIconName.MEDIA_CONTROL_RECORDING); + enumTestList.add(StaticIconName.MEDIA_CONTROL_RIGHT_ARROW); + enumTestList.add(StaticIconName.MEDIA_CONTROL_STOP); + enumTestList.add(StaticIconName.MICROPHONE); + enumTestList.add(StaticIconName.MISSED_CALLS); + enumTestList.add(StaticIconName.MOBILE_PHONE_NUMBER); + enumTestList.add(StaticIconName.MOVE_DOWN); + enumTestList.add(StaticIconName.MOVE_UP); + enumTestList.add(StaticIconName.MP3_TAG_ARTIST); + enumTestList.add(StaticIconName.NAVIGATION); + enumTestList.add(StaticIconName.NAVIGATION_CURRENT_DIRECTION); + enumTestList.add(StaticIconName.NEGATIVE_RATING_THUMBS_DOWN); + enumTestList.add(StaticIconName.NEW); + enumTestList.add(StaticIconName.OFFICE_PHONE_NUMBER); + enumTestList.add(StaticIconName.OPENED); + enumTestList.add(StaticIconName.ORIGIN); + enumTestList.add(StaticIconName.OUTGOING_CALLS); + enumTestList.add(StaticIconName.PHONE_CALL_1); + enumTestList.add(StaticIconName.PHONE_CALL_2); + enumTestList.add(StaticIconName.PHONE_DEVICE); + enumTestList.add(StaticIconName.PHONEBOOK); + enumTestList.add(StaticIconName.PHOTO); + enumTestList.add(StaticIconName.PLAY); + enumTestList.add(StaticIconName.PLAYLIST); + enumTestList.add(StaticIconName.POPUP); + enumTestList.add(StaticIconName.POSITIVE_RATING_THUMBS_UP); + enumTestList.add(StaticIconName.POWER); + enumTestList.add(StaticIconName.PRIMARY_PHONE); + enumTestList.add(StaticIconName.RADIO_BUTTON_CHECKED); + enumTestList.add(StaticIconName.RADIO_BUTTON_UNCHECKED); + enumTestList.add(StaticIconName.RECENT_CALLS); + enumTestList.add(StaticIconName.RECENT_DESTINATIONS); + enumTestList.add(StaticIconName.REDO); + enumTestList.add(StaticIconName.REFRESH); + enumTestList.add(StaticIconName.REMOTE_DIAGNOSTICS_CHECK_ENGINE); + enumTestList.add(StaticIconName.RENDERED_911_ASSIST); + enumTestList.add(StaticIconName.REPEAT); + enumTestList.add(StaticIconName.REPEAT_PLAY); + enumTestList.add(StaticIconName.REPLY); + enumTestList.add(StaticIconName.REWIND_30_SECS); + enumTestList.add(StaticIconName.RIGHT); + enumTestList.add(StaticIconName.RIGHT_EXIT); + enumTestList.add(StaticIconName.RINGTONES); + enumTestList.add(StaticIconName.ROUNDABOUT_LEFT_HAND_1); + enumTestList.add(StaticIconName.ROUNDABOUT_LEFT_HAND_2); + enumTestList.add(StaticIconName.ROUNDABOUT_LEFT_HAND_3); + enumTestList.add(StaticIconName.ROUNDABOUT_LEFT_HAND_4); + enumTestList.add(StaticIconName.ROUNDABOUT_LEFT_HAND_5); + enumTestList.add(StaticIconName.ROUNDABOUT_LEFT_HAND_6); + enumTestList.add(StaticIconName.ROUNDABOUT_LEFT_HAND_7); + enumTestList.add(StaticIconName.ROUNDABOUT_RIGHT_HAND_1); + enumTestList.add(StaticIconName.ROUNDABOUT_RIGHT_HAND_2); + enumTestList.add(StaticIconName.ROUNDABOUT_RIGHT_HAND_3); + enumTestList.add(StaticIconName.ROUNDABOUT_RIGHT_HAND_4); + enumTestList.add(StaticIconName.ROUNDABOUT_RIGHT_HAND_5); + enumTestList.add(StaticIconName.ROUNDABOUT_RIGHT_HAND_6); + enumTestList.add(StaticIconName.ROUNDABOUT_RIGHT_HAND_7); + enumTestList.add(StaticIconName.RSS); + enumTestList.add(StaticIconName.SETTINGS); + enumTestList.add(StaticIconName.SHARP_LEFT); + enumTestList.add(StaticIconName.SHARP_RIGHT); + enumTestList.add(StaticIconName.SHOW); + enumTestList.add(StaticIconName.SHUFFLE_PLAY); + enumTestList.add(StaticIconName.SKI_PLACES); + enumTestList.add(StaticIconName.SLIGHT_LEFT); + enumTestList.add(StaticIconName.SLIGHT_RIGHT); + enumTestList.add(StaticIconName.SMARTPHONE); + enumTestList.add(StaticIconName.SORT_LIST); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_0); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_1); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_2); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_3); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_4); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_5); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_6); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_7); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_8); + enumTestList.add(StaticIconName.SPEED_DIAL_NUMBERS_NUMBER_9); + enumTestList.add(StaticIconName.SUCCESS); + enumTestList.add(StaticIconName.TRACK_TITLE); + enumTestList.add(StaticIconName.TRAFFIC_REPORT); + enumTestList.add(StaticIconName.TURN_LIST); + enumTestList.add(StaticIconName.UTURN_LEFT_TRAFFIC); + enumTestList.add(StaticIconName.UTURN_RIGHT_TRAFFIC); + enumTestList.add(StaticIconName.UNDO); + enumTestList.add(StaticIconName.UNLOCKED); + enumTestList.add(StaticIconName.USB_MEDIA_AUDIO_SOURCE); + enumTestList.add(StaticIconName.VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_1); + enumTestList.add(StaticIconName.VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_2); + enumTestList.add(StaticIconName.VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_3); + enumTestList.add(StaticIconName.VOICE_CONTROL_SCROLLBAR_LIST_ITEM_NO_4); + enumTestList.add(StaticIconName.VOICE_RECOGNITION_FAILED); + enumTestList.add(StaticIconName.VOICE_RECOGNITION_PAUSE); + enumTestList.add(StaticIconName.VOICE_RECOGNITION_SUCCESSFUL); + enumTestList.add(StaticIconName.VOICE_RECOGNITION_SYSTEM_ACTIVE); + enumTestList.add(StaticIconName.VOICE_RECOGNITION_SYSTEM_LISTENING); + enumTestList.add(StaticIconName.VOICE_RECOGNITION_TRY_AGAIN); + enumTestList.add(StaticIconName.WARNING); + enumTestList.add(StaticIconName.WEATHER); + enumTestList.add(StaticIconName.WIFI_FULL); + enumTestList.add(StaticIconName.ZOOM_IN); + enumTestList.add(StaticIconName.ZOOM_OUT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SupportedSeatTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SupportedSeatTests.java new file mode 100644 index 000000000..6a2dbd18f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SupportedSeatTests.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.SupportedSeat; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.SupportedSeat} + */ +public class SupportedSeatTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "DRIVER"; + SupportedSeat enumDriver = SupportedSeat.valueForString(example); + example = "FRONT_PASSENGER"; + SupportedSeat enumFrontPassenger = SupportedSeat.valueForString(example); + + assertNotNull("DRIVER returned null", enumDriver); + assertNotNull("FRONT_PASSENGER returned null", enumFrontPassenger); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "dRIVER"; + try { + SupportedSeat temp = SupportedSeat.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + SupportedSeat temp = SupportedSeat.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SupportedSeat. + */ + public void testListEnum() { + List<SupportedSeat> enumValueList = Arrays.asList(SupportedSeat.values()); + + List<SupportedSeat> enumTestList = new ArrayList<SupportedSeat>(); + enumTestList.add(SupportedSeat.DRIVER); + enumTestList.add(SupportedSeat.FRONT_PASSENGER); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemActionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemActionTests.java new file mode 100644 index 000000000..807da0b8a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemActionTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.SystemAction; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.SystemAction} + */ +public class SystemActionTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "DEFAULT_ACTION"; + SystemAction enumDefaultAction = SystemAction.valueForString(example); + example = "STEAL_FOCUS"; + SystemAction enumStealFocus = SystemAction.valueForString(example); + example = "KEEP_CONTEXT"; + SystemAction enumKeepContext = SystemAction.valueForString(example); + + assertNotNull("DEFAULT_ACTION returned null", enumDefaultAction); + assertNotNull("STEAL_FOCUS returned null", enumStealFocus); + assertNotNull("KEEP_CONTEXT returned null", enumKeepContext); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "deFaulT_ActiON"; + try { + SystemAction temp = SystemAction.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + SystemAction temp = SystemAction.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SystemAction. + */ + public void testListEnum() { + List<SystemAction> enumValueList = Arrays.asList(SystemAction.values()); + + List<SystemAction> enumTestList = new ArrayList<SystemAction>(); + enumTestList.add(SystemAction.DEFAULT_ACTION); + enumTestList.add(SystemAction.STEAL_FOCUS); + enumTestList.add(SystemAction.KEEP_CONTEXT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java new file mode 100644 index 000000000..f0f876d00 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemCapabilityTypeTests.java @@ -0,0 +1,123 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType} + */ +public class SystemCapabilityTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NAVIGATION"; + SystemCapabilityType enumNavigation = SystemCapabilityType.valueForString(example); + example = "PHONE_CALL"; + SystemCapabilityType enumPhoneCall = SystemCapabilityType.valueForString(example); + example = "VIDEO_STREAMING"; + SystemCapabilityType enumVideoStreaming = SystemCapabilityType.valueForString(example); + example = "REMOTE_CONTROL"; + SystemCapabilityType enumRemoteControl = SystemCapabilityType.valueForString(example); + example = "HMI"; + SystemCapabilityType enumHmi = SystemCapabilityType.valueForString(example); + example = "DISPLAY"; + SystemCapabilityType enumDisplay = SystemCapabilityType.valueForString(example); + example = "AUDIO_PASSTHROUGH"; + SystemCapabilityType enumAudioPassThrough = SystemCapabilityType.valueForString(example); + example = "BUTTON"; + SystemCapabilityType enumButton = SystemCapabilityType.valueForString(example); + example = "HMI_ZONE"; + SystemCapabilityType enumHmiZone = SystemCapabilityType.valueForString(example); + example = "PRESET_BANK"; + SystemCapabilityType enumPresetBank = SystemCapabilityType.valueForString(example); + example = "SOFTBUTTON"; + SystemCapabilityType enumSoftButton = SystemCapabilityType.valueForString(example); + example = "SPEECH"; + SystemCapabilityType enumSpeech = SystemCapabilityType.valueForString(example); + example = "VOICE_RECOGNITION"; + SystemCapabilityType enumVoiceRecognition = SystemCapabilityType.valueForString(example); + example = "PCM_STREAMING"; + SystemCapabilityType enumPCM = SystemCapabilityType.valueForString(example); + example = "APP_SERVICES"; + SystemCapabilityType enumAppServices = SystemCapabilityType.valueForString(example); + + assertNotNull("NAVIGATION returned null", enumNavigation); + assertNotNull("PHONE_CALL returned null", enumPhoneCall); + assertNotNull("VIDEO_STREAMING returned null", enumVideoStreaming); + assertNotNull("REMOTE_CONTROL returned null", enumRemoteControl); + assertNotNull("HMI returned null", enumHmi); + assertNotNull("DISPLAY returned null", enumDisplay); + assertNotNull("AUDIO_PASSTHROUGH returned null", enumAudioPassThrough); + assertNotNull("BUTTON returned null", enumButton); + assertNotNull("HMI_ZONE returned null", enumHmiZone); + assertNotNull("PRESET_BANK returned null", enumPresetBank); + assertNotNull("SOFTBUTTON returned null", enumSoftButton); + assertNotNull("SPEECH returned null", enumSpeech); + assertNotNull("VOICE_RECOGNITION returned null", enumVoiceRecognition); + assertNotNull("PCM_STREAMING", enumPCM); + assertNotNull("APP_SERVICES", enumAppServices); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "nAVIGATION"; + try { + SystemCapabilityType temp = SystemCapabilityType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + SystemCapabilityType temp = SystemCapabilityType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SystemCapabilityType. + */ + public void testListEnum() { + List<SystemCapabilityType> enumValueList = Arrays.asList(SystemCapabilityType.values()); + + List<SystemCapabilityType> enumTestList = new ArrayList<SystemCapabilityType>(); + enumTestList.add(SystemCapabilityType.NAVIGATION); + enumTestList.add(SystemCapabilityType.PHONE_CALL); + enumTestList.add(SystemCapabilityType.VIDEO_STREAMING); + enumTestList.add(SystemCapabilityType.REMOTE_CONTROL); + enumTestList.add(SystemCapabilityType.HMI); + enumTestList.add(SystemCapabilityType.DISPLAY); + enumTestList.add(SystemCapabilityType.AUDIO_PASSTHROUGH); + enumTestList.add(SystemCapabilityType.BUTTON); + enumTestList.add(SystemCapabilityType.HMI_ZONE); + enumTestList.add(SystemCapabilityType.PRESET_BANK); + enumTestList.add(SystemCapabilityType.SOFTBUTTON); + enumTestList.add(SystemCapabilityType.SPEECH); + enumTestList.add(SystemCapabilityType.VOICE_RECOGNITION); + enumTestList.add(SystemCapabilityType.PCM_STREAMING); + enumTestList.add(SystemCapabilityType.APP_SERVICES); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemContextTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemContextTests.java new file mode 100644 index 000000000..9b325492e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/SystemContextTests.java @@ -0,0 +1,83 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.SystemContext; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.SystemContext} + */ +public class SystemContextTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "MAIN"; + SystemContext enumMain = SystemContext.valueForString(example); + example = "VRSESSION"; + SystemContext enumVrSession = SystemContext.valueForString(example); + example = "MENU"; + SystemContext enumMenu = SystemContext.valueForString(example); + example = "HMI_OBSCURED"; + SystemContext enumHmiObscured = SystemContext.valueForString(example); + example = "ALERT"; + SystemContext enumAlert = SystemContext.valueForString(example); + + assertNotNull("MAIN returned null", enumMain); + assertNotNull("VRSESSION returned null", enumVrSession); + assertNotNull("MENU returned null", enumMenu); + assertNotNull("HMI_OBSCURED returned null", enumHmiObscured); + assertNotNull("ALERT returned null", enumAlert); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "mAIn"; + try { + SystemContext temp = SystemContext.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + SystemContext temp = SystemContext.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of SystemContext. + */ + public void testListEnum() { + List<SystemContext> enumValueList = Arrays.asList(SystemContext.values()); + + List<SystemContext> enumTestList = new ArrayList<SystemContext>(); + enumTestList.add(SystemContext.SYSCTXT_MAIN); + enumTestList.add(SystemContext.SYSCTXT_VRSESSION); + enumTestList.add(SystemContext.SYSCTXT_MENU); + enumTestList.add(SystemContext.SYSCTXT_HMI_OBSCURED); + enumTestList.add(SystemContext.SYSCTXT_ALERT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TPMSTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TPMSTests.java new file mode 100644 index 000000000..c573a0d7a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TPMSTests.java @@ -0,0 +1,95 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.TPMS; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.TPMS} + */ +public class TPMSTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "UNKNOWN"; + TPMS unknown = TPMS.valueForString(example); + example = "SYSTEM_FAULT"; + TPMS systemFault = TPMS.valueForString(example); + example = "SENSOR_FAULT"; + TPMS sensorFault = TPMS.valueForString(example); + example = "LOW"; + TPMS low = TPMS.valueForString(example); + example = "SYSTEM_ACTIVE"; + TPMS systemActive = TPMS.valueForString(example); + example = "TRAIN"; + TPMS train = TPMS.valueForString(example); + example = "TRAINING_COMPLETE"; + TPMS trainingComplete = TPMS.valueForString(example); + example = "NOT_TRAINED"; + TPMS notTrained = TPMS.valueForString(example); + + assertNotNull("UNKNOWN returned null", unknown); + assertNotNull("SYSTEM_FAULT returned null", systemFault); + assertNotNull("SENSOR_FAULT returned null", sensorFault); + assertNotNull("LOW returned null", low); + assertNotNull("SYSTEM_ACTIVE returned null", systemActive); + assertNotNull("TRAIN returned null", train); + assertNotNull("TRAINING_COMPLETE returned null", trainingComplete); + assertNotNull("NOT_TRAINED returned null", notTrained); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "IsHoUldBeNulL"; + try { + TPMS temp = TPMS.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + TPMS temp = TPMS.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of TPMS. + */ + public void testListEnum() { + List<TPMS> enumValueList = Arrays.asList(TPMS.values()); + + List<TPMS> enumTestList = new ArrayList<>(); + enumTestList.add(TPMS.UNKNOWN); + enumTestList.add(TPMS.SYSTEM_FAULT); + enumTestList.add(TPMS.SENSOR_FAULT); + enumTestList.add(TPMS.LOW); + enumTestList.add(TPMS.SYSTEM_ACTIVE); + enumTestList.add(TPMS.TRAIN); + enumTestList.add(TPMS.TRAINING_COMPLETE); + enumTestList.add(TPMS.NOT_TRAINED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TbtStateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TbtStateTests.java new file mode 100644 index 000000000..1fbf8055a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TbtStateTests.java @@ -0,0 +1,103 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.TBTState; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.TbtState} + */ +public class TbtStateTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "ROUTE_UPDATE_REQUEST"; + TBTState enumRouteUpdateRequest = TBTState.valueForString(example); + example = "ROUTE_ACCEPTED"; + TBTState enumRouteAccepted = TBTState.valueForString(example); + example = "ROUTE_REFUSED"; + TBTState enumRouteRefused = TBTState.valueForString(example); + example = "ROUTE_CANCELLED"; + TBTState enumRouteCancelled = TBTState.valueForString(example); + example = "ETA_REQUEST"; + TBTState enumEtaEquest = TBTState.valueForString(example); + example = "NEXT_TURN_REQUEST"; + TBTState enumNextTurnRequest = TBTState.valueForString(example); + example = "ROUTE_STATUS_REQUEST"; + TBTState enumRouteStatusRequest = TBTState.valueForString(example); + example = "ROUTE_SUMMARY_REQUEST"; + TBTState enumRouteSummaryRequest = TBTState.valueForString(example); + example = "TRIP_STATUS_REQUEST"; + TBTState enumTripStatusRequest = TBTState.valueForString(example); + example = "ROUTE_UPDATE_REQUEST_TIMEOUT"; + TBTState enumRouteUpdateRequestTimeout = TBTState.valueForString(example); + + assertNotNull("ROUTE_UPDATE_REQUEST returned null", enumRouteUpdateRequest); + assertNotNull("ROUTE_ACCEPTED returned null", enumRouteAccepted); + assertNotNull("ROUTE_REFUSED returned null", enumRouteRefused); + assertNotNull("ROUTE_CANCELLED returned null", enumRouteCancelled); + assertNotNull("ETA_REQUEST returned null", enumEtaEquest); + assertNotNull("NEXT_TURN_REQUEST returned null", enumNextTurnRequest); + assertNotNull("ROUTE_STATUS_REQUEST returned null", enumRouteStatusRequest); + assertNotNull("ROUTE_SUMMARY_REQUEST returned null", enumRouteSummaryRequest); + assertNotNull("TRIP_STATUS_REQUEST returned null", enumTripStatusRequest); + assertNotNull("ROUTE_UPDATE_REQUEST_TIMEOUT returned null", enumRouteUpdateRequestTimeout); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "rOUte_UpDAte_reQuesT"; + try { + TBTState temp = TBTState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + TBTState temp = TBTState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of TBTState. + */ + public void testListEnum() { + List<TBTState> enumValueList = Arrays.asList(TBTState.values()); + + List<TBTState> enumTestList = new ArrayList<TBTState>(); + enumTestList.add(TBTState.ROUTE_UPDATE_REQUEST); + enumTestList.add(TBTState.ROUTE_ACCEPTED); + enumTestList.add(TBTState.ROUTE_REFUSED); + enumTestList.add(TBTState.ROUTE_CANCELLED); + enumTestList.add(TBTState.ETA_REQUEST); + enumTestList.add(TBTState.NEXT_TURN_REQUEST); + enumTestList.add(TBTState.ROUTE_STATUS_REQUEST); + enumTestList.add(TBTState.ROUTE_SUMMARY_REQUEST); + enumTestList.add(TBTState.TRIP_STATUS_REQUEST); + enumTestList.add(TBTState.ROUTE_UPDATE_REQUEST_TIMEOUT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TextAlignmentTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TextAlignmentTests.java new file mode 100644 index 000000000..1b1130806 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TextAlignmentTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.TextAlignment; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.TextAlignment} + */ +public class TextAlignmentTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "LEFT_ALIGNED"; + TextAlignment enumLeftAligned = TextAlignment.valueForString(example); + example = "RIGHT_ALIGNED"; + TextAlignment enumRightAligned = TextAlignment.valueForString(example); + example = "CENTERED"; + TextAlignment enumCentered = TextAlignment.valueForString(example); + + assertNotNull("LEFT_ALIGNED returned null", enumLeftAligned); + assertNotNull("RIGHT_ALIGNED returned null", enumRightAligned); + assertNotNull("CENTERED returned null", enumCentered); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "leFT_AliGned"; + try { + TextAlignment temp = TextAlignment.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + TextAlignment temp = TextAlignment.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of TextAlignment. + */ + public void testListEnum() { + List<TextAlignment> enumValueList = Arrays.asList(TextAlignment.values()); + + List<TextAlignment> enumTestList = new ArrayList<TextAlignment>(); + enumTestList.add(TextAlignment.LEFT_ALIGNED); + enumTestList.add(TextAlignment.RIGHT_ALIGNED); + enumTestList.add(TextAlignment.CENTERED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TextFieldNameTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TextFieldNameTests.java new file mode 100644 index 000000000..7d0050e66 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TextFieldNameTests.java @@ -0,0 +1,178 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.TextFieldName; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.TextFieldName} + */ +public class TextFieldNameTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "mainField1"; + TextFieldName enumMainField1 = TextFieldName.valueForString(example); + example = "mainField2"; + TextFieldName enumMainField2 = TextFieldName.valueForString(example); + example = "mainField3"; + TextFieldName enumMainField3 = TextFieldName.valueForString(example); + example = "mainField4"; + TextFieldName enumMainField4 = TextFieldName.valueForString(example); + example = "statusBar"; + TextFieldName enumStatusBar = TextFieldName.valueForString(example); + example = "mediaClock"; + TextFieldName enumMediaClock = TextFieldName.valueForString(example); + example = "mediaTrack"; + TextFieldName enumMediaTrack = TextFieldName.valueForString(example); + example = "alertText1"; + TextFieldName enumAlertText1 = TextFieldName.valueForString(example); + example = "alertText2"; + TextFieldName enumAlertText2 = TextFieldName.valueForString(example); + example = "alertText3"; + TextFieldName enumAlertText3 = TextFieldName.valueForString(example); + example = "scrollableMessageBody"; + TextFieldName enumScrollableMessageBody = TextFieldName.valueForString(example); + example = "initialInteractionText"; + TextFieldName enumInitialInteractionText = TextFieldName.valueForString(example); + example = "navigationText1"; + TextFieldName enumNavigationText1 = TextFieldName.valueForString(example); + example = "navigationText2"; + TextFieldName enumNavigationText2 = TextFieldName.valueForString(example); + example = "ETA"; + TextFieldName enumEta = TextFieldName.valueForString(example); + example = "totalDistance"; + TextFieldName enumTotalDistance = TextFieldName.valueForString(example); + example = "audioPassThruDisplayText1"; + TextFieldName enumAudioPassThruDisplayText1 = TextFieldName.valueForString(example); + example = "audioPassThruDisplayText2"; + TextFieldName enumAudioPassThruDisplayText2 = TextFieldName.valueForString(example); + example = "sliderHeader"; + TextFieldName enumSliderHeader = TextFieldName.valueForString(example); + example = "sliderFooter"; + TextFieldName enumSliderFooter = TextFieldName.valueForString(example); + example = "menuName"; + TextFieldName enumMenuName = TextFieldName.valueForString(example); + example = "secondaryText"; + TextFieldName enumSecondaryText = TextFieldName.valueForString(example); + example = "tertiaryText"; + TextFieldName enumTertiaryText = TextFieldName.valueForString(example); + example = "menuTitle"; + TextFieldName enumMenuTitle = TextFieldName.valueForString(example); + example = "locationName"; + TextFieldName enumLocName = TextFieldName.valueForString(example); + example = "locationDescription"; + TextFieldName enumLocDesc = TextFieldName.valueForString(example); + example = "addressLines"; + TextFieldName enumAddLines = TextFieldName.valueForString(example); + example = "phoneNumber"; + TextFieldName enumPhone = TextFieldName.valueForString(example); + + assertNotNull("mainField1 returned null", enumMainField1); + assertNotNull("mainField2 returned null", enumMainField2); + assertNotNull("mainField3 returned null", enumMainField3); + assertNotNull("mainField4 returned null", enumMainField4); + assertNotNull("statusBar returned null", enumStatusBar); + assertNotNull("mediaClock returned null", enumMediaClock); + assertNotNull("mediaTrack returned null", enumMediaTrack); + assertNotNull("alertText1 returned null", enumAlertText1); + assertNotNull("alertText2 returned null", enumAlertText2); + assertNotNull("alertText3 returned null", enumAlertText3); + assertNotNull("scrollableMessageBody returned null", enumScrollableMessageBody); + assertNotNull("initialInteractionText returned null", enumInitialInteractionText); + assertNotNull("navigationText1 returned null", enumNavigationText1); + assertNotNull("navigationText2 returned null", enumNavigationText2); + assertNotNull("ETA returned null", enumEta); + assertNotNull("totalDistance returned null", enumTotalDistance); + assertNotNull("audioPassThruDisplayText1 returned null", enumAudioPassThruDisplayText1); + assertNotNull("audioPassThruDisplayText2 returned null", enumAudioPassThruDisplayText2); + assertNotNull("sliderHeader returned null", enumSliderHeader); + assertNotNull("sliderFooter returned null", enumSliderFooter); + assertNotNull("menuName returned null", enumMenuName); + assertNotNull("secondaryText returned null", enumSecondaryText); + assertNotNull("tertiaryText returned null", enumTertiaryText); + assertNotNull("menuTitle returned null", enumMenuTitle); + + assertNotNull(Test.NOT_NULL, enumLocName); + assertNotNull(Test.NOT_NULL, enumLocDesc); + assertNotNull(Test.NOT_NULL, enumAddLines); + assertNotNull(Test.NOT_NULL, enumPhone); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "mAinField1"; + try { + TextFieldName temp = TextFieldName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + TextFieldName temp = TextFieldName.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of TextFieldName. + */ + public void testListEnum() { + List<TextFieldName> enumValueList = Arrays.asList(TextFieldName.values()); + + List<TextFieldName> enumTestList = new ArrayList<TextFieldName>(); + enumTestList.add(TextFieldName.mainField1); + enumTestList.add(TextFieldName.mainField2); + enumTestList.add(TextFieldName.mainField3); + enumTestList.add(TextFieldName.mainField4); + enumTestList.add(TextFieldName.statusBar); + enumTestList.add(TextFieldName.mediaClock); + enumTestList.add(TextFieldName.mediaTrack); + enumTestList.add(TextFieldName.alertText1); + enumTestList.add(TextFieldName.alertText2); + enumTestList.add(TextFieldName.alertText3); + enumTestList.add(TextFieldName.scrollableMessageBody); + enumTestList.add(TextFieldName.initialInteractionText); + enumTestList.add(TextFieldName.navigationText1); + enumTestList.add(TextFieldName.navigationText2); + enumTestList.add(TextFieldName.ETA); + enumTestList.add(TextFieldName.totalDistance); + enumTestList.add(TextFieldName.audioPassThruDisplayText1); + enumTestList.add(TextFieldName.audioPassThruDisplayText2); + enumTestList.add(TextFieldName.sliderHeader); + enumTestList.add(TextFieldName.sliderFooter); + enumTestList.add(TextFieldName.menuName); + enumTestList.add(TextFieldName.secondaryText); + enumTestList.add(TextFieldName.tertiaryText); + enumTestList.add(TextFieldName.menuTitle); + + enumTestList.add(TextFieldName.locationName); + enumTestList.add(TextFieldName.locationDescription); + enumTestList.add(TextFieldName.addressLines); + enumTestList.add(TextFieldName.phoneNumber); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TouchTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TouchTypeTests.java new file mode 100644 index 000000000..db9c417ef --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TouchTypeTests.java @@ -0,0 +1,81 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.TouchType; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.TouchType} + */ +public class TouchTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "BEGIN"; + TouchType enumBegin = TouchType.valueForString(example); + example = "MOVE"; + TouchType enumMove = TouchType.valueForString(example); + example = "END"; + TouchType enumEnd = TouchType.valueForString(example); + example = "CANCEL"; + TouchType enumCancel = TouchType.valueForString(example); + + + assertNotNull("BEGIN returned null", enumBegin); + assertNotNull("MOVE returned null", enumMove); + assertNotNull("END returned null", enumEnd); + assertNotNull("CANCEL returned null", enumCancel); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "bEgIn"; + try { + TouchType temp = TouchType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + TouchType temp = TouchType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + + /** + * Verifies the possible enum values of TouchType. + */ + public void testListEnum() { + List<TouchType> enumValueList = Arrays.asList(TouchType.values()); + + List<TouchType> enumTestList = new ArrayList<TouchType>(); + enumTestList.add(TouchType.BEGIN); + enumTestList.add(TouchType.MOVE); + enumTestList.add(TouchType.END); + enumTestList.add(TouchType.CANCEL); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TriggerSourceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TriggerSourceTests.java new file mode 100644 index 000000000..5197dec64 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TriggerSourceTests.java @@ -0,0 +1,76 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.TriggerSource} + */ +public class TriggerSourceTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "MENU"; + TriggerSource enumMenu = TriggerSource.valueForString(example); + example = "VR"; + TriggerSource enumVr = TriggerSource.valueForString(example); + example = "KEYBOARD"; + TriggerSource enumKeyboard = TriggerSource.valueForString(example); + + assertNotNull("MENU returned null", enumMenu); + assertNotNull("VR returned null", enumVr); + assertNotNull("KEYBOARD returned null", enumKeyboard); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "meNU"; + try { + TriggerSource temp = TriggerSource.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + TriggerSource temp = TriggerSource.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + + /** + * Verifies the possible enum values of TriggerSource. + */ + public void testListEnum() { + List<TriggerSource> enumValueList = Arrays.asList(TriggerSource.values()); + + List<TriggerSource> enumTestList = new ArrayList<TriggerSource>(); + enumTestList.add(TriggerSource.TS_MENU); + enumTestList.add(TriggerSource.TS_VR); + enumTestList.add(TriggerSource.TS_KEYBOARD); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TurnSignalTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TurnSignalTests.java new file mode 100644 index 000000000..a758d683e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/TurnSignalTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.TurnSignal; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.TurnSignal} + */ +public class TurnSignalTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "OFF"; + TurnSignal off = TurnSignal.valueForString(example); + example = "LEFT"; + TurnSignal left = TurnSignal.valueForString(example); + example = "RIGHT"; + TurnSignal right = TurnSignal.valueForString(example); + example = "BOTH"; + TurnSignal both = TurnSignal.valueForString(example); + + assertNotNull("OFF returned null", off); + assertNotNull("LEFT returned null", left); + assertNotNull("RIGHT returned null", right); + assertNotNull("BOTH returned null", both); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "IsHoUldBeNulL"; + try { + TurnSignal temp = TurnSignal.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + TurnSignal temp = TurnSignal.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of TurnSignal. + */ + public void testListEnum() { + List<TurnSignal> enumValueList = Arrays.asList(TurnSignal.values()); + + List<TurnSignal> enumTestList = new ArrayList<>(); + enumTestList.add(TurnSignal.OFF); + enumTestList.add(TurnSignal.LEFT); + enumTestList.add(TurnSignal.RIGHT); + enumTestList.add(TurnSignal.BOTH); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/UpdateModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/UpdateModeTests.java new file mode 100644 index 000000000..2c808ef03 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/UpdateModeTests.java @@ -0,0 +1,83 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.UpdateMode; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.UpdateMode} + */ +public class UpdateModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "COUNTUP"; + UpdateMode enumCountUp = UpdateMode.valueForString(example); + example = "COUNTDOWN"; + UpdateMode enumCountDown = UpdateMode.valueForString(example); + example = "PAUSE"; + UpdateMode enumPause = UpdateMode.valueForString(example); + example = "RESUME"; + UpdateMode enumResume = UpdateMode.valueForString(example); + example = "CLEAR"; + UpdateMode enumClear = UpdateMode.valueForString(example); + + assertNotNull("COUNTUP returned null", enumCountUp); + assertNotNull("COUNTDOWN returned null", enumCountDown); + assertNotNull("PAUSE returned null", enumPause); + assertNotNull("RESUME returned null", enumResume); + assertNotNull("CLEAR returned null", enumClear); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "coUnTUp"; + try { + UpdateMode temp = UpdateMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + UpdateMode temp = UpdateMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of UpdateMode. + */ + public void testListEnum() { + List<UpdateMode> enumValueList = Arrays.asList(UpdateMode.values()); + + List<UpdateMode> enumTestList = new ArrayList<UpdateMode>(); + enumTestList.add(UpdateMode.COUNTUP); + enumTestList.add(UpdateMode.COUNTDOWN); + enumTestList.add(UpdateMode.PAUSE); + enumTestList.add(UpdateMode.RESUME); + enumTestList.add(UpdateMode.CLEAR); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataEventStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataEventStatusTests.java new file mode 100644 index 000000000..bcee65b19 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataEventStatusTests.java @@ -0,0 +1,83 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.VehicleDataEventStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.VehicleDataEventStatus} + */ +public class VehicleDataEventStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NO_EVENT"; + VehicleDataEventStatus enumNoEvent = VehicleDataEventStatus.valueForString(example); + example = "NO"; + VehicleDataEventStatus enumNo = VehicleDataEventStatus.valueForString(example); + example = "YES"; + VehicleDataEventStatus enumYes = VehicleDataEventStatus.valueForString(example); + example = "NOT_SUPPORTED"; + VehicleDataEventStatus enumNotSupported = VehicleDataEventStatus.valueForString(example); + example = "FAULT"; + VehicleDataEventStatus enumFault = VehicleDataEventStatus.valueForString(example); + + assertNotNull("NO_EVENT returned null", enumNoEvent); + assertNotNull("NO returned null", enumNo); + assertNotNull("YES returned null", enumYes); + assertNotNull("NOT_SUPPORTED returned null", enumNotSupported); + assertNotNull("FAULT returned null", enumFault); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "no_EveNT"; + try { + VehicleDataEventStatus temp = VehicleDataEventStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VehicleDataEventStatus temp = VehicleDataEventStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of AmbientLightStatus. + */ + public void testListEnum() { + List<VehicleDataEventStatus> enumValueList = Arrays.asList(VehicleDataEventStatus.values()); + + List<VehicleDataEventStatus> enumTestList = new ArrayList<VehicleDataEventStatus>(); + enumTestList.add(VehicleDataEventStatus.NO_EVENT); + enumTestList.add(VehicleDataEventStatus.NO); + enumTestList.add(VehicleDataEventStatus.YES); + enumTestList.add(VehicleDataEventStatus.NOT_SUPPORTED); + enumTestList.add(VehicleDataEventStatus.FAULT); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataNotificationStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataNotificationStatusTests.java new file mode 100644 index 000000000..af2f45714 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataNotificationStatusTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.VehicleDataNotificationStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.VehicleDataNotificationStatus} + */ +public class VehicleDataNotificationStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NOT_SUPPORTED"; + VehicleDataNotificationStatus enumNotSupported = VehicleDataNotificationStatus.valueForString(example); + example = "NORMAL"; + VehicleDataNotificationStatus enumNormal = VehicleDataNotificationStatus.valueForString(example); + example = "ACTIVE"; + VehicleDataNotificationStatus enumActive = VehicleDataNotificationStatus.valueForString(example); + example = "NOT_USED"; + VehicleDataNotificationStatus enumNotUsed = VehicleDataNotificationStatus.valueForString(example); + + assertNotNull("NOT_SUPPORTED returned null", enumNotSupported); + assertNotNull("NORMAL returned null", enumNormal); + assertNotNull("ACTIVE returned null", enumActive); + assertNotNull("NOT_USED returned null", enumNotUsed); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "nOT_SuppOrTEd"; + try { + VehicleDataNotificationStatus temp = VehicleDataNotificationStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VehicleDataNotificationStatus temp = VehicleDataNotificationStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of VehicleDataNotification. + */ + public void testListEnum() { + List<VehicleDataNotificationStatus> enumValueList = Arrays.asList(VehicleDataNotificationStatus.values()); + + List<VehicleDataNotificationStatus> enumTestList = new ArrayList<VehicleDataNotificationStatus>(); + enumTestList.add(VehicleDataNotificationStatus.NOT_SUPPORTED); + enumTestList.add(VehicleDataNotificationStatus.NORMAL); + enumTestList.add(VehicleDataNotificationStatus.ACTIVE); + enumTestList.add(VehicleDataNotificationStatus.NOT_USED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataResultCodeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataResultCodeTests.java new file mode 100644 index 000000000..e2161474a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataResultCodeTests.java @@ -0,0 +1,99 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.VehicleDataResultCode; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.VehicleDataResultCode} + */ +public class VehicleDataResultCodeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "SUCCESS"; + VehicleDataResultCode enumSuccess = VehicleDataResultCode.valueForString(example); + example = "TRUNCATED_DATA"; + VehicleDataResultCode enumTruncData = VehicleDataResultCode.valueForString(example); + example = "DISALLOWED"; + VehicleDataResultCode enumDisallowed = VehicleDataResultCode.valueForString(example); + example = "USER_DISALLOWED"; + VehicleDataResultCode enumUserDisallowed = VehicleDataResultCode.valueForString(example); + example = "INVALID_ID"; + VehicleDataResultCode enumInvalidId = VehicleDataResultCode.valueForString(example); + example = "VEHICLE_DATA_NOT_AVAILABLE"; + VehicleDataResultCode enumVehicleDataNotAvailable = VehicleDataResultCode.valueForString(example); + example = "DATA_ALREADY_SUBSCRIBED"; + VehicleDataResultCode enumDataAlreadySubscribed = VehicleDataResultCode.valueForString(example); + example = "DATA_NOT_SUBSCRIBED"; + VehicleDataResultCode enumDataNotSubscribed = VehicleDataResultCode.valueForString(example); + example = "IGNORED"; + VehicleDataResultCode enumIgnored = VehicleDataResultCode.valueForString(example); + + assertNotNull("SUCCESS returned null", enumSuccess); + assertNotNull("TRUNCATED_DATA returned null", enumTruncData); + assertNotNull("DISALLOWED returned null", enumDisallowed); + assertNotNull("USER_DISALLOWED returned null", enumUserDisallowed); + assertNotNull("INVALID_ID returned null", enumInvalidId); + assertNotNull("VEHICLE_DATA_NOT_AVAILABLE returned null", enumVehicleDataNotAvailable); + assertNotNull("DATA_ALREADY_SUBSCRIBED returned null", enumDataAlreadySubscribed); + assertNotNull("DATA_NOT_SUBSCRIBED returned null", enumDataNotSubscribed); + assertNotNull("IGNORED returned null", enumIgnored); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "suCcesS"; + try { + VehicleDataResultCode temp = VehicleDataResultCode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VehicleDataResultCode temp = VehicleDataResultCode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of VehicleDataResultCode. + */ + public void testListEnum() { + List<VehicleDataResultCode> enumValueList = Arrays.asList(VehicleDataResultCode.values()); + + List<VehicleDataResultCode> enumTestList = new ArrayList<VehicleDataResultCode>(); + enumTestList.add(VehicleDataResultCode.SUCCESS); + enumTestList.add(VehicleDataResultCode.TRUNCATED_DATA); + enumTestList.add(VehicleDataResultCode.DISALLOWED); + enumTestList.add(VehicleDataResultCode.USER_DISALLOWED); + enumTestList.add(VehicleDataResultCode.INVALID_ID); + enumTestList.add(VehicleDataResultCode.VEHICLE_DATA_NOT_AVAILABLE); + enumTestList.add(VehicleDataResultCode.DATA_ALREADY_SUBSCRIBED); + enumTestList.add(VehicleDataResultCode.DATA_NOT_SUBSCRIBED); + enumTestList.add(VehicleDataResultCode.IGNORED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataStatusTests.java new file mode 100644 index 000000000..d35780ff4 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataStatusTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.VehicleDataStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.VehicleDataStatus} + */ +public class VehicleDataStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "NO_DATA_EXISTS"; + VehicleDataStatus enumNoDataExists = VehicleDataStatus.valueForString(example); + example = "OFF"; + VehicleDataStatus enumOff = VehicleDataStatus.valueForString(example); + example = "ON"; + VehicleDataStatus enumOn = VehicleDataStatus.valueForString(example); + + assertNotNull("NO_DATA_EXISTS returned null", enumNoDataExists); + assertNotNull("OFF returned null", enumOff); + assertNotNull("ON returned null", enumOn); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "No_DatA_ExiSTs"; + try { + VehicleDataStatus temp = VehicleDataStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VehicleDataStatus temp = VehicleDataStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of VehicleDataStatus. + */ + public void testListEnum() { + List<VehicleDataStatus> enumValueList = Arrays.asList(VehicleDataStatus.values()); + + List<VehicleDataStatus> enumTestList = new ArrayList<VehicleDataStatus>(); + enumTestList.add(VehicleDataStatus.NO_DATA_EXISTS); + enumTestList.add(VehicleDataStatus.OFF); + enumTestList.add(VehicleDataStatus.ON); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataTypeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataTypeTests.java new file mode 100644 index 000000000..56c418590 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VehicleDataTypeTests.java @@ -0,0 +1,187 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.VehicleDataType; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.VehicleDataType} + */ +public class VehicleDataTypeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "VEHICLEDATA_GPS"; + VehicleDataType enumVehicleDataGps = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_SPEED"; + VehicleDataType enumVehicleDataSpeed = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_RPM"; + VehicleDataType enumVehicleDataRpm = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_FUELLEVEL"; + VehicleDataType enumVehicleDataFuelLevel = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_FUELLEVEL_STATE"; + VehicleDataType enumVehicleDataFuelLevelState = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_FUELCONSUMPTION"; + VehicleDataType enumVehicleDataFuelConsumption = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_EXTERNTEMP"; + VehicleDataType enumVehicleDataExternTemp = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_VIN"; + VehicleDataType enumVehicleDataVin = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_PRNDL"; + VehicleDataType enumVehicleDataPrndl = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_TIREPRESSURE"; + VehicleDataType enumVehicleDataTirePressure = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_ODOMETER"; + VehicleDataType enumVehicleDataOdometer = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_BELTSTATUS"; + VehicleDataType enumVehicleDataBeltStatus = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_BODYINFO"; + VehicleDataType enumVehicleDataBodyInfo = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_DEVICESTATUS"; + VehicleDataType enumVehicleDataDeviceStatus = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_BRAKING"; + VehicleDataType enumVehicleDataBraking = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_WIPERSTATUS"; + VehicleDataType enumVehicleDataWiperStatus = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_HEADLAMPSTATUS"; + VehicleDataType enumVehicleDataHeadlampStatus = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_BATTVOLTAGE"; + VehicleDataType enumVehicleDataBattVoltage = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_ENGINETORQUE"; + VehicleDataType enumVehicleDataEngineTorque = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_ENGINEOILLIFE"; + VehicleDataType enumVehicleDataEngineOilLife = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_ACCPEDAL"; + VehicleDataType enumVehicleDataAccPedal = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_STEERINGWHEEL"; + VehicleDataType enumVehicleDataSteeringWheel = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_ECALLINFO"; + VehicleDataType enumVehicleDataECallInfo = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_AIRBAGSTATUS"; + VehicleDataType enumVehicleDataAirbagStatus = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_EMERGENCYEVENT"; + VehicleDataType enumVehicleDataEmergencyEvent = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_CLUSTERMODESTATUS"; + VehicleDataType enumVehicleDataClusterModeStatus = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_MYKEY"; + VehicleDataType enumVehicleDataMyKey = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_FUELRANGE"; + VehicleDataType enumVehicleDataFuelRange = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_TURNSIGNAL"; + VehicleDataType enumVehicleDataTurnSignal = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_ELECTRONICPARKBRAKESTATUS"; + VehicleDataType enumVehicleDataElectronicParkBrakeStatus = VehicleDataType.valueForString(example); + example = "VEHICLEDATA_CLOUDAPPVEHICLEID"; + VehicleDataType enumVehicleCloudAppVehicleId = VehicleDataType.valueForString(example); + + assertNotNull("VEHICLEDATA_GPS returned null", enumVehicleDataGps); + assertNotNull("VEHICLEDATA_SPEED returned null", enumVehicleDataSpeed); + assertNotNull("VEHICLEDATA_RPM returned null", enumVehicleDataRpm); + assertNotNull("VEHICLEDATA_FUELLEVEL returned null", enumVehicleDataFuelLevel); + assertNotNull("VEHICLEDATA_FUELLEVEL_STATE returned null", enumVehicleDataFuelLevelState); + assertNotNull("VEHICLEDATA_FUELCONSUMPTION returned null", enumVehicleDataFuelConsumption); + assertNotNull("VEHICLEDATA_EXTERNTEMP returned null", enumVehicleDataExternTemp); + assertNotNull("VEHICLEDATA_VIN returned null", enumVehicleDataVin); + assertNotNull("VEHICLEDATA_PRNDL returned null", enumVehicleDataPrndl); + assertNotNull("VEHICLEDATA_TIREPRESSURE returned null", enumVehicleDataTirePressure); + assertNotNull("VEHICLEDATA_ODOMETER returned null", enumVehicleDataOdometer); + assertNotNull("VEHICLEDATA_BELTSTATUS returned null", enumVehicleDataBeltStatus); + assertNotNull("VEHICLEDATA_BODYINFO returned null", enumVehicleDataBodyInfo); + assertNotNull("VEHICLEDATA_DEVICESTATUS returned null", enumVehicleDataDeviceStatus); + assertNotNull("VEHICLEDATA_BRAKING returned null", enumVehicleDataBraking); + assertNotNull("VEHICLEDATA_WIPERSTATUS returned null", enumVehicleDataWiperStatus); + assertNotNull("VEHICLEDATA_HEADLAMPSTATUS returned null", enumVehicleDataHeadlampStatus); + assertNotNull("VEHICLEDATA_BATTVOLTAGE returned null", enumVehicleDataBattVoltage); + assertNotNull("VEHICLEDATA_ENGINETORQUE returned null", enumVehicleDataEngineTorque); + assertNotNull("VEHICLEDATA_ENGINEOILLIFE returned null", enumVehicleDataEngineOilLife); + assertNotNull("VEHICLEDATA_ACCPEDAL returned null", enumVehicleDataAccPedal); + assertNotNull("VEHICLEDATA_STEERINGWHEEL returned null", enumVehicleDataSteeringWheel); + assertNotNull("VEHICLEDATA_ECALLINFO returned null", enumVehicleDataECallInfo); + assertNotNull("VEHICLEDATA_AIRBAGSTATUS returned null", enumVehicleDataAirbagStatus); + assertNotNull("VEHICLEDATA_EMERGENCYEVENT returned null", enumVehicleDataEmergencyEvent); + assertNotNull("VEHICLEDATA_CLUSTERMODESTATUS returned null", enumVehicleDataClusterModeStatus); + assertNotNull("VEHICLEDATA_MYKEY returned null", enumVehicleDataMyKey); + assertNotNull("VEHICLEDATA_FUELRANGE returned null", enumVehicleDataFuelRange); + assertNotNull("VEHICLEDATA_TURNSIGNAL returned null", enumVehicleDataTurnSignal); + assertNotNull("VEHICLEDATA_ELECTRONICPARKBRAKESTATUS returned null", enumVehicleDataElectronicParkBrakeStatus); + assertNotNull("VEHICLEDATA_CLOUDAPPVEHICLEID returned null", enumVehicleCloudAppVehicleId); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "VeHIcLEDatA_GPs"; + try { + VehicleDataType temp = VehicleDataType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VehicleDataType temp = VehicleDataType.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of VehicleDataType. + */ + public void testListEnum() { + List<VehicleDataType> enumValueList = Arrays.asList(VehicleDataType.values()); + + List<VehicleDataType> enumTestList = new ArrayList<VehicleDataType>(); + enumTestList.add(VehicleDataType.VEHICLEDATA_GPS); + enumTestList.add(VehicleDataType.VEHICLEDATA_SPEED); + enumTestList.add(VehicleDataType.VEHICLEDATA_RPM); + enumTestList.add(VehicleDataType.VEHICLEDATA_FUELLEVEL); + enumTestList.add(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE); + enumTestList.add(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION); + enumTestList.add(VehicleDataType.VEHICLEDATA_EXTERNTEMP); + enumTestList.add(VehicleDataType.VEHICLEDATA_VIN); + enumTestList.add(VehicleDataType.VEHICLEDATA_PRNDL); + enumTestList.add(VehicleDataType.VEHICLEDATA_TIREPRESSURE); + enumTestList.add(VehicleDataType.VEHICLEDATA_ODOMETER); + enumTestList.add(VehicleDataType.VEHICLEDATA_BELTSTATUS); + enumTestList.add(VehicleDataType.VEHICLEDATA_BODYINFO); + enumTestList.add(VehicleDataType.VEHICLEDATA_DEVICESTATUS); + enumTestList.add(VehicleDataType.VEHICLEDATA_BRAKING); + enumTestList.add(VehicleDataType.VEHICLEDATA_WIPERSTATUS); + enumTestList.add(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS); + enumTestList.add(VehicleDataType.VEHICLEDATA_BATTVOLTAGE); + enumTestList.add(VehicleDataType.VEHICLEDATA_ENGINETORQUE); + enumTestList.add(VehicleDataType.VEHICLEDATA_ENGINEOILLIFE); + enumTestList.add(VehicleDataType.VEHICLEDATA_ACCPEDAL); + enumTestList.add(VehicleDataType.VEHICLEDATA_STEERINGWHEEL); + enumTestList.add(VehicleDataType.VEHICLEDATA_ECALLINFO); + enumTestList.add(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS); + enumTestList.add(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT); + enumTestList.add(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS); + enumTestList.add(VehicleDataType.VEHICLEDATA_MYKEY); + enumTestList.add(VehicleDataType.VEHICLEDATA_FUELRANGE); + enumTestList.add(VehicleDataType.VEHICLEDATA_TURNSIGNAL); + enumTestList.add(VehicleDataType.VEHICLEDATA_ELECTRONICPARKBRAKESTATUS); + enumTestList.add(VehicleDataType.VEHICLEDATA_CLOUDAPPVEHICLEID); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VentilationModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VentilationModeTests.java new file mode 100644 index 000000000..561e66a77 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VentilationModeTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.VentilationMode; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.VentilationMode} + */ +public class VentilationModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "UPPER"; + VentilationMode enumUpper = VentilationMode.valueForString(example); + example = "LOWER"; + VentilationMode enumLower = VentilationMode.valueForString(example); + example = "BOTH"; + VentilationMode enumBoth = VentilationMode.valueForString(example); + example = "NONE"; + VentilationMode enumNone = VentilationMode.valueForString(example); + + assertNotNull("UPPER returned null", enumUpper); + assertNotNull("LOWER returned null", enumLower); + assertNotNull("BOTH returned null", enumBoth); + assertNotNull("NONE returned null", enumNone); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "uPPER"; + try { + VentilationMode temp = VentilationMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VentilationMode temp = VentilationMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of VentilationMode. + */ + public void testListEnum() { + List<VentilationMode> enumValueList = Arrays.asList(VentilationMode.values()); + + List<VentilationMode> enumTestList = new ArrayList<VentilationMode>(); + enumTestList.add(VentilationMode.UPPER); + enumTestList.add(VentilationMode.LOWER); + enumTestList.add(VentilationMode.BOTH); + enumTestList.add(VentilationMode.NONE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingCodecTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingCodecTests.java new file mode 100644 index 000000000..b4aa8fd97 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingCodecTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class VideoStreamingCodecTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "H264"; + VideoStreamingCodec enumH264 = VideoStreamingCodec.valueForString(example); + example = "H265"; + VideoStreamingCodec enumH265 = VideoStreamingCodec.valueForString(example); + example = "Theora"; + VideoStreamingCodec enumTheora = VideoStreamingCodec.valueForString(example); + example = "VP8"; + VideoStreamingCodec enumVP8 = VideoStreamingCodec.valueForString(example); + example = "VP9"; + VideoStreamingCodec enumVP9 = VideoStreamingCodec.valueForString(example); + + assertNotNull("H264 returned null", enumH264); + assertNotNull("H265 returned null", enumH265); + assertNotNull("Theora returned null", enumTheora); + assertNotNull("VP8 returned null", enumVP8); + assertNotNull("VP9 returned null", enumVP9); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "H234"; + try { + VideoStreamingCodec temp = VideoStreamingCodec.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VideoStreamingCodec temp = VideoStreamingCodec.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + + /** + * Verifies the possible enum values of TouchType. + */ + public void testListEnum() { + List<VideoStreamingCodec> enumValueList = Arrays.asList(VideoStreamingCodec.values()); + + List<VideoStreamingCodec> enumTestList = new ArrayList<VideoStreamingCodec>(); + enumTestList.add(VideoStreamingCodec.H264); + enumTestList.add(VideoStreamingCodec.H265); + enumTestList.add(VideoStreamingCodec.Theora); + enumTestList.add(VideoStreamingCodec.VP8); + enumTestList.add(VideoStreamingCodec.VP9); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingProtocolTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingProtocolTests.java new file mode 100644 index 000000000..be50d2c30 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingProtocolTests.java @@ -0,0 +1,82 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec; +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class VideoStreamingProtocolTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "RAW"; + VideoStreamingProtocol enumRAW = VideoStreamingProtocol.valueForString(example); + example = "RTP"; + VideoStreamingProtocol enumRTP = VideoStreamingProtocol.valueForString(example); + example = "RTSP"; + VideoStreamingProtocol enumRTSP = VideoStreamingProtocol.valueForString(example); + example = "RTMP"; + VideoStreamingProtocol enumRTMP = VideoStreamingProtocol.valueForString(example); + example = "WEBM"; + VideoStreamingProtocol enumWEBM = VideoStreamingProtocol.valueForString(example); + + assertNotNull("RAW returned null", enumRAW); + assertNotNull("RTP returned null", enumRTP); + assertNotNull("RTSP returned null", enumRTSP); + assertNotNull("RTMP returned null", enumRTMP); + assertNotNull("WEBM returned null", enumWEBM); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "RAAW"; + try { + VideoStreamingProtocol temp = VideoStreamingProtocol.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VideoStreamingProtocol temp = VideoStreamingProtocol.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + + /** + * Verifies the possible enum values of TouchType. + */ + public void testListEnum() { + List<VideoStreamingProtocol> enumValueList = Arrays.asList(VideoStreamingProtocol.values()); + + List<VideoStreamingProtocol> enumTestList = new ArrayList<VideoStreamingProtocol>(); + enumTestList.add(VideoStreamingProtocol.RAW); + enumTestList.add(VideoStreamingProtocol.RTP); + enumTestList.add(VideoStreamingProtocol.RTSP); + enumTestList.add(VideoStreamingProtocol.RTMP); + enumTestList.add(VideoStreamingProtocol.WEBM); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} + diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingStateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingStateTests.java new file mode 100644 index 000000000..2074efe47 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VideoStreamingStateTests.java @@ -0,0 +1,71 @@ +package com.smartdevicelink.test.rpc.enums; + +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingState; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.enums.VideoStreamingState} + */ +public class VideoStreamingStateTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "STREAMABLE"; + VideoStreamingState enumStreamable = VideoStreamingState.valueForString(example); + example = "NOT_STREAMABLE"; + VideoStreamingState enumNotStreamable = VideoStreamingState.valueForString(example); + + assertNotNull("STREAMABLE returned null", enumStreamable); + assertNotNull("NOT_STREAMABLE returned null", enumNotStreamable); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "StrEAmaBlE"; + try { + VideoStreamingState temp = VideoStreamingState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VideoStreamingState temp = VideoStreamingState.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of VideoStreamingState. + */ + public void testListEnum() { + List<VideoStreamingState> enumValueList = Arrays.asList(VideoStreamingState.values()); + + List<VideoStreamingState> enumTestList = new ArrayList<VideoStreamingState>(); + enumTestList.add(VideoStreamingState.STREAMABLE); + enumTestList.add(VideoStreamingState.NOT_STREAMABLE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VrCapabilitiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VrCapabilitiesTests.java new file mode 100644 index 000000000..33da334b8 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/VrCapabilitiesTests.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.VrCapabilities; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.VrCapabilities} + */ +public class VrCapabilitiesTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "Text"; + VrCapabilities enumText = VrCapabilities.valueForString(example); + + assertNotNull("Text returned null", enumText); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "tExTx"; + try { + VrCapabilities temp = VrCapabilities.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + VrCapabilities temp = VrCapabilities.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of VrCapabilities. + */ + @SuppressWarnings("deprecation") + public void testListEnum() { + List<VrCapabilities> enumValueList = Arrays.asList(VrCapabilities.values()); + + List<VrCapabilities> enumTestList = new ArrayList<VrCapabilities>(); + enumTestList.add(VrCapabilities.TEXT); + enumTestList.add(VrCapabilities.Text); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/WarningLightStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/WarningLightStatusTests.java new file mode 100644 index 000000000..18c6cc046 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/WarningLightStatusTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.WarningLightStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.WarningListStatus} + */ +public class WarningLightStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "OFF"; + WarningLightStatus enumOff = WarningLightStatus.valueForString(example); + example = "ON"; + WarningLightStatus enumOn = WarningLightStatus.valueForString(example); + example = "FLASH"; + WarningLightStatus enumFlash = WarningLightStatus.valueForString(example); + example = "NOT_USED"; + WarningLightStatus enumNotUsed = WarningLightStatus.valueForString(example); + + assertNotNull("OFF returned null", enumOff); + assertNotNull("ON returned null", enumOn); + assertNotNull("FLASH returned null", enumFlash); + assertNotNull("NOT_USED returned null", enumNotUsed); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "OfF"; + try { + WarningLightStatus temp = WarningLightStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + WarningLightStatus temp = WarningLightStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of WarningLightStatus. + */ + public void testListEnum() { + List<WarningLightStatus> enumValueList = Arrays.asList(WarningLightStatus.values()); + + List<WarningLightStatus> enumTestList = new ArrayList<WarningLightStatus>(); + enumTestList.add(WarningLightStatus.OFF); + enumTestList.add(WarningLightStatus.ON); + enumTestList.add(WarningLightStatus.FLASH); + enumTestList.add(WarningLightStatus.NOT_USED); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/WiperStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/WiperStatusTests.java new file mode 100644 index 000000000..1ab3370fa --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/WiperStatusTests.java @@ -0,0 +1,123 @@ +package com.smartdevicelink.test.rpc.enums; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.rpc.enums.WiperStatus; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.enums.WiperStatis} + */ +public class WiperStatusTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums () { + String example = "OFF"; + WiperStatus enumOff = WiperStatus.valueForString(example); + example = "AUTO_OFF"; + WiperStatus enumAutoOff = WiperStatus.valueForString(example); + example = "OFF_MOVING"; + WiperStatus enumOffMoving = WiperStatus.valueForString(example); + example = "MAN_INT_OFF"; + WiperStatus enumManIntOff = WiperStatus.valueForString(example); + example = "MAN_INT_ON"; + WiperStatus enumManIntOn = WiperStatus.valueForString(example); + example = "MAN_LOW"; + WiperStatus enumManLow = WiperStatus.valueForString(example); + example = "MAN_HIGH"; + WiperStatus enumManHigh = WiperStatus.valueForString(example); + example = "MAN_FLICK"; + WiperStatus enumManFlick = WiperStatus.valueForString(example); + example = "WASH"; + WiperStatus enumWash = WiperStatus.valueForString(example); + example = "AUTO_LOW"; + WiperStatus enumAutoLow = WiperStatus.valueForString(example); + example = "AUTO_HIGH"; + WiperStatus enumAutoHigh = WiperStatus.valueForString(example); + example = "COURTESYWIPE"; + WiperStatus enumCourtesyWipe = WiperStatus.valueForString(example); + example = "AUTO_ADJUST"; + WiperStatus enumAutoAdjust = WiperStatus.valueForString(example); + example = "STALLED"; + WiperStatus enumStalled = WiperStatus.valueForString(example); + example = "NO_DATA_EXISTS"; + WiperStatus enumNoDataExists = WiperStatus.valueForString(example); + + assertNotNull("OFF returned null", enumOff); + assertNotNull("AUTO_OFF returned null", enumAutoOff); + assertNotNull("OFF_MOVING returned null", enumOffMoving); + assertNotNull("MAN_INT_OFF returned null", enumManIntOff); + assertNotNull("MAN_INT_ON returned null", enumManIntOn); + assertNotNull("MAN_LOW returned null", enumManLow); + assertNotNull("MAN_HIGH returned null", enumManHigh); + assertNotNull("MAN_FLICK returned null", enumManFlick); + assertNotNull("WASH returned null", enumWash); + assertNotNull("AUTO_LOW returned null", enumAutoLow); + assertNotNull("AUTO_HIGH returned null", enumAutoHigh); + assertNotNull("COURTESYWIPE returned null", enumCourtesyWipe); + assertNotNull("AUTO_ADJUST returned null", enumAutoAdjust); + assertNotNull("STALLED returned null", enumStalled); + assertNotNull("NO_DATA_EXISTS returned null", enumNoDataExists); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum () { + String example = "OFf"; + try { + WiperStatus temp = WiperStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum () { + String example = null; + try { + WiperStatus temp = WiperStatus.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } + catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of WiperStatus. + */ + public void testListEnum() { + List<WiperStatus> enumValueList = Arrays.asList(WiperStatus.values()); + + List<WiperStatus> enumTestList = new ArrayList<WiperStatus>(); + enumTestList.add(WiperStatus.OFF); + enumTestList.add(WiperStatus.AUTO_OFF); + enumTestList.add(WiperStatus.OFF_MOVING); + enumTestList.add(WiperStatus.MAN_INT_OFF); + enumTestList.add(WiperStatus.MAN_INT_ON); + enumTestList.add(WiperStatus.MAN_LOW); + enumTestList.add(WiperStatus.MAN_HIGH); + enumTestList.add(WiperStatus.MAN_FLICK); + enumTestList.add(WiperStatus.WASH); + enumTestList.add(WiperStatus.AUTO_LOW); + enumTestList.add(WiperStatus.AUTO_HIGH); + enumTestList.add(WiperStatus.COURTESYWIPE); + enumTestList.add(WiperStatus.AUTO_ADJUST); + enumTestList.add(WiperStatus.STALLED); + enumTestList.add(WiperStatus.NO_DATA_EXISTS); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAppInterfaceUnregisteredTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAppInterfaceUnregisteredTests.java new file mode 100644 index 000000000..e3c1ee32c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAppInterfaceUnregisteredTests.java @@ -0,0 +1,68 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnAppInterfaceUnregistered; +import com.smartdevicelink.proxy.rpc.enums.AppInterfaceUnregisteredReason; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnAppInterfaceUnregistered} + */ +public class OnAppInterfaceUnregisteredTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnAppInterfaceUnregistered msg = new OnAppInterfaceUnregistered(); + + msg.setReason(Test.GENERAL_APPINTERFACEUNREGISTEREDREASON); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_APP_INTERFACE_UNREGISTERED.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnAppInterfaceUnregistered.KEY_REASON, Test.GENERAL_APPINTERFACEUNREGISTEREDREASON); + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + AppInterfaceUnregisteredReason reason = ( (OnAppInterfaceUnregistered) msg ).getReason(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_APPINTERFACEUNREGISTEREDREASON, reason); + + // Invalid/Null tests + OnAppInterfaceUnregistered msg = new OnAppInterfaceUnregistered(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getReason()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAppServiceDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAppServiceDataTests.java new file mode 100644 index 000000000..108ec930f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAppServiceDataTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.notifications; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AppServiceData; +import com.smartdevicelink.proxy.rpc.OnAppServiceData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONException; +import org.json.JSONObject; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.OnAppServiceData} + */ +public class OnAppServiceDataTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + OnAppServiceData msg = new OnAppServiceData(); + + msg.setServiceData(Test.GENERAL_APPSERVICE_DATA); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_APP_SERVICE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnAppServiceData.KEY_SERVICE_DATA, Test.GENERAL_APPSERVICE_DATA.serializeJSON()); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + AppServiceData cmdId = ( (OnAppServiceData) msg ).getServiceData(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_APPSERVICE_DATA, cmdId); + + // Invalid/Null Tests + OnAppServiceData msg = new OnAppServiceData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getServiceData()); + + // test constructor with param + msg = new OnAppServiceData(Test.GENERAL_APPSERVICE_DATA); + AppServiceData serviceData = msg.getServiceData(); + assertEquals(serviceData, Test.GENERAL_APPSERVICE_DATA); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAudioPassThruTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAudioPassThruTests.java new file mode 100644 index 000000000..b2add2f34 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnAudioPassThruTests.java @@ -0,0 +1,46 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnAudioPassThru; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnAudioPassThru} + */ +public class OnAudioPassThruTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new OnAudioPassThru(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_AUDIO_PASS_THRU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + OnAudioPassThru msg = new OnAudioPassThru(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnButtonEventTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnButtonEventTests.java new file mode 100644 index 000000000..5f6e2e8e3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnButtonEventTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnButtonEvent; +import com.smartdevicelink.proxy.rpc.enums.ButtonEventMode; +import com.smartdevicelink.proxy.rpc.enums.ButtonName; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnButtonEvent} + */ +public class OnButtonEventTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnButtonEvent msg = new OnButtonEvent(); + + msg.setButtonEventMode(Test.GENERAL_BUTTONEVENTMODE); + msg.setButtonName(Test.GENERAL_BUTTONNAME); + msg.setCustomButtonID(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_BUTTON_EVENT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnButtonEvent.KEY_BUTTON_EVENT_MODE, Test.GENERAL_BUTTONEVENTMODE); + result.put(OnButtonEvent.KEY_BUTTON_NAME, Test.GENERAL_BUTTONNAME); + result.put(OnButtonEvent.KEY_CUSTOM_BUTTON_ID, Test.GENERAL_INT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int cmdId = ( (OnButtonEvent) msg ).getCustomButtonID(); + ButtonEventMode mode = ( (OnButtonEvent) msg ).getButtonEventMode(); + ButtonName name = ( (OnButtonEvent) msg ).getButtonName(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, cmdId); + assertEquals(Test.MATCH, Test.GENERAL_BUTTONEVENTMODE, mode); + assertEquals(Test.MATCH, Test.GENERAL_BUTTONNAME, name); + + // Invalid/Null Tests + OnButtonEvent msg = new OnButtonEvent(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getButtonEventMode()); + assertNull(Test.NULL, msg.getButtonName()); + assertNull(Test.NULL, msg.getCustomButtonID()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnButtonPressTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnButtonPressTests.java new file mode 100644 index 000000000..be3c63be2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnButtonPressTests.java @@ -0,0 +1,79 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnButtonPress; +import com.smartdevicelink.proxy.rpc.enums.ButtonName; +import com.smartdevicelink.proxy.rpc.enums.ButtonPressMode; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnButtonPress} + */ +public class OnButtonPressTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnButtonPress msg = new OnButtonPress(); + + msg.setButtonName(Test.GENERAL_BUTTONNAME); + msg.setButtonPressMode(Test.GENERAL_BUTTONPRESSMODE); + msg.setCustomButtonName(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_BUTTON_PRESS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnButtonPress.KEY_CUSTOM_BUTTON_ID, Test.GENERAL_INT); + result.put(OnButtonPress.KEY_BUTTON_NAME, Test.GENERAL_BUTTONNAME); + result.put(OnButtonPress.KEY_BUTTON_PRESS_MODE, Test.GENERAL_BUTTONPRESSMODE); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int customName = ( (OnButtonPress) msg ).getCustomButtonName(); + ButtonName buttonName = ( (OnButtonPress) msg ).getButtonName(); + ButtonPressMode buttonPressMode = ( (OnButtonPress) msg ).getButtonPressMode(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, customName); + assertEquals(Test.MATCH, Test.GENERAL_BUTTONNAME, buttonName); + assertEquals(Test.MATCH, Test.GENERAL_BUTTONPRESSMODE, buttonPressMode); + + // Invalid/Null Tests + OnButtonPress msg = new OnButtonPress(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getCustomButtonName()); + assertNull(Test.NULL, msg.getButtonName()); + assertNull(Test.NULL, msg.getButtonPressMode()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnCommandTests.java new file mode 100644 index 000000000..46026f007 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnCommandTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnCommand; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnCommand} + */ +public class OnCommandTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnCommand msg = new OnCommand(); + + msg.setCmdID(Test.GENERAL_INT); + msg.setTriggerSource(Test.GENERAL_TRIGGERSOURCE); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_COMMAND.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnCommand.KEY_CMD_ID, Test.GENERAL_INT); + result.put(OnCommand.KEY_TRIGGER_SOURCE, Test.GENERAL_TRIGGERSOURCE); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int cmdId = ( (OnCommand) msg ).getCmdID(); + TriggerSource triggerSource = ( (OnCommand) msg ).getTriggerSource(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, cmdId); + assertEquals(Test.MATCH, Test.GENERAL_TRIGGERSOURCE, triggerSource); + + // Invalid/Null Tests + OnCommand msg = new OnCommand(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getTriggerSource()); + assertNull(Test.NULL, msg.getCmdID()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnDriverDistractionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnDriverDistractionTests.java new file mode 100644 index 000000000..090582586 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnDriverDistractionTests.java @@ -0,0 +1,70 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnDriverDistraction; +import com.smartdevicelink.proxy.rpc.enums.DriverDistractionState; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnDriverDistraction} + */ +public class OnDriverDistractionTests extends BaseRpcTests{ + + private static final DriverDistractionState STATUS = DriverDistractionState.DD_ON; + + @Override + protected RPCMessage createMessage(){ + OnDriverDistraction msg = new OnDriverDistraction(); + + msg.setState(STATUS); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_DRIVER_DISTRACTION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnDriverDistraction.KEY_STATE, STATUS); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + DriverDistractionState cmdId = ( (OnDriverDistraction) msg ).getState(); + + // Valid Tests + assertEquals(Test.MATCH, STATUS, cmdId); + + // Invalid/Null Tests + OnDriverDistraction msg = new OnDriverDistraction(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getState()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnErrorTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnErrorTests.java new file mode 100644 index 000000000..a907c8942 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnErrorTests.java @@ -0,0 +1,37 @@ +package com.smartdevicelink.test.rpc.notifications; + +import com.smartdevicelink.proxy.callbacks.InternalProxyMessage; +import com.smartdevicelink.proxy.callbacks.OnError; +import com.smartdevicelink.test.Test; + +import junit.framework.TestCase; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.callbacks.OnError} + */ +public class OnErrorTests extends TestCase { + + /** + * This is a unit test for the following methods : + * {@link com.smartdevicelink.proxy.callbacks.OnError#OnError()} + * {@link com.smartdevicelink.proxy.callbacks.OnError#OnError(String, Exception)} + */ + public void testValues () { + // Valid Tests + OnError testOnError = new OnError(); + assertEquals(Test.MATCH, InternalProxyMessage.OnProxyError, testOnError.getFunctionName()); + + Exception testE = new Exception(); + testOnError = new OnError(Test.GENERAL_STRING, testE); + assertEquals(Test.MATCH, InternalProxyMessage.OnProxyError, testOnError.getFunctionName()); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testOnError.getInfo()); + assertEquals(Test.MATCH, testE, testOnError.getException()); + + // Invalid/Null Tests + testOnError = new OnError(null, null); + assertEquals(Test.MATCH, InternalProxyMessage.OnProxyError, testOnError.getFunctionName()); + assertNull(Test.NULL, testOnError.getInfo()); + assertNull(Test.NULL, testOnError.getException()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnHMIStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnHMIStatusTests.java new file mode 100644 index 000000000..6f38fdfa0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnHMIStatusTests.java @@ -0,0 +1,91 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnHMIStatus; +import com.smartdevicelink.proxy.rpc.enums.AudioStreamingState; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.SystemContext; +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingState; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.util.Version; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.OnHMIStatus} + */ +public class OnHMIStatusTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnHMIStatus msg = new OnHMIStatus(); + + msg.setAudioStreamingState(Test.GENERAL_AUDIOSTREAMINGSTATE); + msg.setVideoStreamingState(Test.GENERAL_VIDEOSTREAMINGSTATE); + msg.setFirstRun(Test.GENERAL_BOOLEAN); + msg.setHmiLevel(Test.GENERAL_HMILEVEL); + msg.setSystemContext(Test.GENERAL_SYSTEMCONTEXT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_HMI_STATUS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnHMIStatus.KEY_AUDIO_STREAMING_STATE, Test.GENERAL_AUDIOSTREAMINGSTATE); + result.put(OnHMIStatus.KEY_VIDEO_STREAMING_STATE, Test.GENERAL_VIDEOSTREAMINGSTATE); + result.put(OnHMIStatus.KEY_HMI_LEVEL, Test.GENERAL_HMILEVEL); + result.put(OnHMIStatus.KEY_SYSTEM_CONTEXT, Test.GENERAL_SYSTEMCONTEXT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + AudioStreamingState audioStreamingState = ( (OnHMIStatus) msg ).getAudioStreamingState(); + VideoStreamingState videoStreamingState = ( (OnHMIStatus) msg ).getVideoStreamingState(); + HMILevel hmiLevel = ( (OnHMIStatus) msg ).getHmiLevel(); + SystemContext context = ( (OnHMIStatus) msg ).getSystemContext(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_AUDIOSTREAMINGSTATE, audioStreamingState); + assertEquals(Test.MATCH, Test.GENERAL_VIDEOSTREAMINGSTATE, videoStreamingState); + assertEquals(Test.MATCH, Test.GENERAL_HMILEVEL, hmiLevel); + assertEquals(Test.MATCH, Test.GENERAL_SYSTEMCONTEXT, context); + + // Invalid/Null Tests + OnHMIStatus msg = new OnHMIStatus(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAudioStreamingState()); + + assertNull(Test.NULL, msg.getVideoStreamingState()); + msg.format(new Version(4,5,0),true); + assertEquals(Test.MATCH, VideoStreamingState.STREAMABLE, msg.getVideoStreamingState()); + assertNull(Test.NULL, msg.getHmiLevel()); + assertNull(Test.NULL, msg.getSystemContext()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnHashChangeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnHashChangeTests.java new file mode 100644 index 000000000..16e101860 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnHashChangeTests.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnHashChange; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnHashChange} + */ +public class OnHashChangeTests extends BaseRpcTests{ + + private static final String HASH_ID = "agh4lg2hb1g9gq3"; + + @Override + protected RPCMessage createMessage(){ + OnHashChange msg = new OnHashChange(); + + msg.setHashID(HASH_ID); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_HASH_CHANGE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnHashChange.KEY_HASH_ID, HASH_ID); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String hashId = ( (OnHashChange) msg ).getHashID(); + + // Valid Tests + assertEquals(Test.MATCH, HASH_ID, hashId); + + // Invalid/Null Tests + OnHashChange msg = new OnHashChange(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getHashID()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnInteriorVehicleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnInteriorVehicleDataTests.java new file mode 100644 index 000000000..4fded53fe --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnInteriorVehicleDataTests.java @@ -0,0 +1,69 @@ +package com.smartdevicelink.test.rpc.notifications; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ModuleData; +import com.smartdevicelink.proxy.rpc.OnInteriorVehicleData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +import org.json.JSONException; +import org.json.JSONObject; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnInteriorVehicleData} + */ +public class OnInteriorVehicleDataTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnInteriorVehicleData msg = new OnInteriorVehicleData(); + msg.setModuleData(Test.GENERAL_MODULEDATA); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_INTERIOR_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnInteriorVehicleData.KEY_MODULE_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_MODULEDATA.getStore())); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ModuleData moduleData = ( (OnInteriorVehicleData) msg ).getModuleData(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateModuleData(Test.GENERAL_MODULEDATA, moduleData)); + + // Invalid/Null Tests + OnInteriorVehicleData msg = new OnInteriorVehicleData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getModuleData()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnKeyboardInputTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnKeyboardInputTests.java new file mode 100644 index 000000000..e950d85fa --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnKeyboardInputTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnKeyboardInput; +import com.smartdevicelink.proxy.rpc.enums.KeyboardEvent; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnKeyboardInput} + */ +public class OnKeyboardInputTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnKeyboardInput msg = new OnKeyboardInput(); + + msg.setData(Test.GENERAL_STRING); + msg.setEvent(Test.GENERAL_KEYBOARDEVENT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_KEYBOARD_INPUT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnKeyboardInput.KEY_DATA, Test.GENERAL_STRING); + result.put(OnKeyboardInput.KEY_EVENT, Test.GENERAL_KEYBOARDEVENT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + KeyboardEvent event = ( (OnKeyboardInput) msg ).getEvent(); + String data = ( (OnKeyboardInput) msg ).getData(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_KEYBOARDEVENT, event); + assertEquals(Test.MATCH, Test.GENERAL_STRING, data); + + // Invalid/Null Tests + OnKeyboardInput msg = new OnKeyboardInput(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getData()); + assertNull(Test.NULL, msg.getEvent()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnLanguageChangeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnLanguageChangeTests.java new file mode 100644 index 000000000..382ef074c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnLanguageChangeTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnLanguageChange; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnLanguageChange} + */ +public class OnLanguageChangeTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnLanguageChange msg = new OnLanguageChange(); + + msg.setLanguage(Test.GENERAL_LANGUAGE); + msg.setHmiDisplayLanguage(Test.GENERAL_LANGUAGE); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_LANGUAGE_CHANGE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnLanguageChange.KEY_LANGUAGE, Test.GENERAL_LANGUAGE); + result.put(OnLanguageChange.KEY_HMI_DISPLAY_LANGUAGE, Test.GENERAL_LANGUAGE); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Language lang = ( (OnLanguageChange) msg ).getLanguage(); + Language hmiLang = ( (OnLanguageChange) msg ).getHmiDisplayLanguage(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, lang); + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, hmiLang); + + // Invalid/Null Tests + OnLanguageChange msg = new OnLanguageChange(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getLanguage()); + assertNull(Test.NULL, msg.getHmiDisplayLanguage()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnLockScreenStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnLockScreenStatusTests.java new file mode 100644 index 000000000..8df1cb641 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnLockScreenStatusTests.java @@ -0,0 +1,85 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnHMIStatus; +import com.smartdevicelink.proxy.rpc.OnLockScreenStatus; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.LockScreenStatus; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnLockScreenStatus} + */ +public class OnLockScreenStatusTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnLockScreenStatus msg = new OnLockScreenStatus(); + + msg.setDriverDistractionStatus(Test.GENERAL_BOOLEAN); + msg.setHMILevel(Test.GENERAL_HMILEVEL); + msg.setShowLockScreen(Test.GENERAL_LOCKSCREENSTATUS); + msg.setUserSelected(Test.GENERAL_BOOLEAN); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_LOCK_SCREEN_STATUS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnLockScreenStatus.KEY_DRIVER_DISTRACTION, Test.GENERAL_BOOLEAN); + result.put(OnHMIStatus.KEY_HMI_LEVEL, Test.GENERAL_HMILEVEL); + result.put(OnLockScreenStatus.KEY_SHOW_LOCK_SCREEN, Test.GENERAL_LOCKSCREENSTATUS); + result.put(OnLockScreenStatus.KEY_USER_SELECTED, Test.GENERAL_BOOLEAN); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Boolean status = ( (OnLockScreenStatus) msg ).getDriverDistractionStatus(); + HMILevel hmiLevel = ( (OnLockScreenStatus) msg ).getHMILevel(); + LockScreenStatus lockScreen = ( (OnLockScreenStatus) msg ).getShowLockScreen(); + boolean userSelected = ( (OnLockScreenStatus) msg ).getUserSelected(); + + // Valid Tests + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, status); + assertEquals(Test.MATCH, Test.GENERAL_HMILEVEL, hmiLevel); + assertEquals(Test.MATCH, Test.GENERAL_LOCKSCREENSTATUS, lockScreen); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, userSelected); + + // Invalid/Null Tests + OnLockScreenStatus msg = new OnLockScreenStatus(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getDriverDistractionStatus()); + assertNull(Test.NULL, msg.getHMILevel()); + assertNull(Test.NULL, msg.getShowLockScreen()); + assertNull(Test.NULL, msg.getUserSelected()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnPermissionsChangeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnPermissionsChangeTests.java new file mode 100644 index 000000000..c3d4c4f46 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnPermissionsChangeTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.notifications; + +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnPermissionsChange; +import com.smartdevicelink.proxy.rpc.PermissionItem; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnPermissionsChange} + */ +public class OnPermissionsChangeTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnPermissionsChange msg = new OnPermissionsChange(); + + msg.setPermissionItem(Test.GENERAL_PERMISSIONITEM_LIST); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_PERMISSIONS_CHANGE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnPermissionsChange.KEY_PERMISSION_ITEM, Test.JSON_PERMISSIONITEMS); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<PermissionItem> data = ( (OnPermissionsChange) msg ).getPermissionItem(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_PERMISSIONITEM_LIST.size(), data.size()); + for(int i=0; i<data.size(); i++){ + assertTrue(Test.TRUE, Validator.validatePermissionItem(Test.GENERAL_PERMISSIONITEM_LIST.get(i), data.get(i))); + } + + // Invalid/Null Tests + OnPermissionsChange msg = new OnPermissionsChange(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getPermissionItem()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnProxyClosedTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnProxyClosedTests.java new file mode 100644 index 000000000..defede878 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnProxyClosedTests.java @@ -0,0 +1,41 @@ +package com.smartdevicelink.test.rpc.notifications; + +import com.smartdevicelink.proxy.callbacks.InternalProxyMessage; +import com.smartdevicelink.proxy.callbacks.OnProxyClosed; +import com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason; +import com.smartdevicelink.test.Test; + +import junit.framework.TestCase; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.callbacks.OnProxyClosed} + */ +public class OnProxyClosedTests extends TestCase { + + /** + * This is a unit test for the following methods : + * {@link com.smartdevicelink.proxy.callbacks.OnProxyClosed#OnProxyClosed()} + * {@link com.smartdevicelink.proxy.callbacks.OnProxyClosed#OnProxyClosed(String, Exception, SdlDisconnectedReason)} + */ + public void testValues () { + // Valid Tests + OnProxyClosed testOnProxyClosed = new OnProxyClosed(); + assertEquals(Test.MATCH, InternalProxyMessage.OnProxyClosed, testOnProxyClosed.getFunctionName()); + + Exception testE = new Exception(); + SdlDisconnectedReason testReason = SdlDisconnectedReason.DEFAULT; + testOnProxyClosed = new OnProxyClosed(Test.GENERAL_STRING, testE, testReason); + assertEquals(Test.MATCH, InternalProxyMessage.OnProxyClosed, testOnProxyClosed.getFunctionName()); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testOnProxyClosed.getInfo()); + assertEquals(Test.MATCH, testE, testOnProxyClosed.getException()); + assertEquals(Test.MATCH, testReason, testOnProxyClosed.getReason()); + + // Invalid/Null Tests + testOnProxyClosed = new OnProxyClosed(null, null, null); + assertEquals(Test.MATCH, InternalProxyMessage.OnProxyClosed, testOnProxyClosed.getFunctionName()); + assertNull(Test.NULL, testOnProxyClosed.getInfo()); + assertNull(Test.NULL, testOnProxyClosed.getException()); + assertNull(Test.NULL, testOnProxyClosed.getReason()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnProxyOpenedTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnProxyOpenedTests.java new file mode 100644 index 000000000..d186098c3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnProxyOpenedTests.java @@ -0,0 +1,26 @@ +package com.smartdevicelink.test.rpc.notifications; + +import junit.framework.TestCase; + +import com.smartdevicelink.proxy.callbacks.InternalProxyMessage; +import com.smartdevicelink.proxy.callbacks.OnProxyOpened; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.callbacks.OnProxyOpened} + */ +public class OnProxyOpenedTests extends TestCase { + + + /** + * This is a unit test for the following methods : + * {@link com.smartdevicelink.proxy.callbacks.OnProxyOpened#OnProxyOpened()} + * {@link com.smartdevicelink.proxy.callbacks.OnProxyOpened#getFunctionName()} + */ + public void testMethods () { + OnProxyOpened testOnProxyOpened = new OnProxyOpened(); + assertNotNull(Test.NOT_NULL, testOnProxyOpened); + assertEquals(Test.MATCH, InternalProxyMessage.OnProxyOpened, testOnProxyOpened.getFunctionName()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnRCStatusTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnRCStatusTests.java new file mode 100644 index 000000000..a6d4d63fd --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnRCStatusTests.java @@ -0,0 +1,92 @@ +package com.smartdevicelink.test.rpc.notifications; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ModuleData; +import com.smartdevicelink.proxy.rpc.OnRCStatus; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class OnRCStatusTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage() { + OnRCStatus msg = new OnRCStatus(); + + List<ModuleData> listAllocatedModules = Test.GENERAL_MODULEDATA_LIST; + + msg.setAllocatedModules(listAllocatedModules); + + List<ModuleData> listFreeModules = new ArrayList<>(); + listFreeModules.add(Test.GENERAL_MODULEDATA); + msg.setFreeModules(listFreeModules); + + msg.setAllowed(Test.GENERAL_BOOLEAN); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType() { + return FunctionID.ON_RC_STATUS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + JSONArray jsonArrayAllocatedModules = new JSONArray(); + JSONArray jsonArrayFreeModules = new JSONArray(); + try { + jsonArrayAllocatedModules.put(JsonRPCMarshaller.serializeHashtable(Test.GENERAL_MODULEDATA.getStore())); + jsonArrayFreeModules.put(JsonRPCMarshaller.serializeHashtable(Test.GENERAL_MODULEDATA.getStore())); + } catch (JSONException e) { + e.printStackTrace(); + } + + try { + result.put(OnRCStatus.KEY_ALLOCATED_MODULES, jsonArrayAllocatedModules); + result.put(OnRCStatus.KEY_FREE_MODULES, jsonArrayFreeModules); + result.put(OnRCStatus.KEY_ALLOWED, Test.GENERAL_BOOLEAN); + } catch (JSONException e) { + e.printStackTrace(); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues() { + // Test Values + List<ModuleData> listAllocatedModules = ((OnRCStatus) msg).getAllocatedModules(); + List<ModuleData> listFreeModules = ((OnRCStatus) msg).getFreeModules(); + Boolean allowed = ((OnRCStatus) msg).getAllowed(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_MODULEDATA, listAllocatedModules.get(0)); + assertEquals(Test.MATCH, Test.GENERAL_MODULEDATA, listFreeModules.get(0)); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, allowed); + + // Invalid/Null Tests + OnRCStatus msg = new OnRCStatus(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAllocatedModules()); + assertNull(Test.NULL, msg.getFreeModules()); + assertNull(Test.NULL, msg.getAllowed()); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSdlChoiceChosenTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSdlChoiceChosenTests.java new file mode 100644 index 000000000..77d2cdb21 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSdlChoiceChosenTests.java @@ -0,0 +1,78 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnSdlChoiceChosen; +import com.smartdevicelink.proxy.rpc.OnSdlChoiceChosen.SdlChoice; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.OnSdlChoiceChosen} + */ +public class OnSdlChoiceChosenTests extends BaseRpcTests{ + + SdlChoice sdlChoice; + + @Override + protected RPCMessage createMessage(){ + OnSdlChoiceChosen msg = new OnSdlChoiceChosen(); + sdlChoice = msg.new SdlChoice(Test.GENERAL_CHOICE); + + msg.setTriggerSource(Test.GENERAL_TRIGGERSOURCE); + msg.setSdlChoice(sdlChoice); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_SDL_CHOICE_CHOSEN.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnSdlChoiceChosen.KEY_TRIGGER_SOURCE, Test.GENERAL_TRIGGERSOURCE); + result.put(OnSdlChoiceChosen.KEY_SDL_CHOICE, sdlChoice); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + SdlChoice data = ( (OnSdlChoiceChosen) msg ).getSdlChoice(); + TriggerSource source = ( (OnSdlChoiceChosen) msg ).getTriggerSource(); + + // Valid Tests + assertTrue(Test.MATCH, Validator.validateChoice(Test.GENERAL_CHOICE, data.getChoice())); + assertEquals(Test.MATCH, Test.GENERAL_TRIGGERSOURCE, source); + + // Invalid/Null Tests + OnSdlChoiceChosen msg = new OnSdlChoiceChosen(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getTriggerSource()); + assertNull(Test.NULL, msg.getSdlChoice()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnStreamRPCTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnStreamRPCTests.java new file mode 100644 index 000000000..58db7d8eb --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnStreamRPCTests.java @@ -0,0 +1,76 @@ +package com.smartdevicelink.test.rpc.notifications; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnStreamRPC; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class OnStreamRPCTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage(){ + OnStreamRPC msg = new OnStreamRPC(); + + msg.setBytesComplete(Test.GENERAL_LONG); + msg.setFileName(Test.GENERAL_STRING); + msg.setFileSize(Test.GENERAL_LONG); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_STREAM_RPC.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnStreamRPC.KEY_BYTESCOMPLETE, Test.GENERAL_LONG); + result.put(OnStreamRPC.KEY_FILENAME, Test.GENERAL_STRING); + result.put(OnStreamRPC.KEY_FILESIZE, Test.GENERAL_LONG); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Long bytes = ((OnStreamRPC) msg).getBytesComplete(); + String fileName = ((OnStreamRPC) msg).getFileName(); + Long fileSize = ((OnStreamRPC) msg).getFileSize(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_LONG, bytes); + assertEquals(Test.MATCH, Test.GENERAL_STRING, fileName); + assertEquals(Test.MATCH, Test.GENERAL_LONG, fileSize); + + // Invalid/Null Tests + OnStreamRPC msg = new OnStreamRPC(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getBytesComplete()); + assertNull(Test.NULL, msg.getFileName()); + assertNull(Test.NULL, msg.getFileSize()); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSystemCapabilityUpdatedTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSystemCapabilityUpdatedTests.java new file mode 100644 index 000000000..ca0fa5f02 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSystemCapabilityUpdatedTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.notifications; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnSystemCapabilityUpdated; +import com.smartdevicelink.proxy.rpc.SystemCapability; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONException; +import org.json.JSONObject; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.OnSystemCapabilityUpdated} + */ +public class OnSystemCapabilityUpdatedTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + OnSystemCapabilityUpdated msg = new OnSystemCapabilityUpdated(); + + msg.setSystemCapability(Test.GENERAL_SYSTEMCAPABILITY); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_SYSTEM_CAPABILITY_UPDATED.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnSystemCapabilityUpdated.KEY_SYSTEM_CAPABILITY, Test.GENERAL_SYSTEMCAPABILITY.serializeJSON()); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + SystemCapability cmdId = ( (OnSystemCapabilityUpdated) msg ).getSystemCapability(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_SYSTEMCAPABILITY, cmdId); + + // Invalid/Null Tests + OnSystemCapabilityUpdated msg = new OnSystemCapabilityUpdated(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSystemCapability()); + + // test constructor with param + msg = new OnSystemCapabilityUpdated(Test.GENERAL_SYSTEMCAPABILITY); + SystemCapability systemCapability = msg.getSystemCapability(); + assertEquals(systemCapability, Test.GENERAL_SYSTEMCAPABILITY); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSystemRequestTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSystemRequestTests.java new file mode 100644 index 000000000..a4bb53e71 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnSystemRequestTests.java @@ -0,0 +1,133 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Headers; +import com.smartdevicelink.proxy.rpc.OnSystemRequest; +import com.smartdevicelink.proxy.rpc.enums.FileType; +import com.smartdevicelink.proxy.rpc.enums.RequestType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.OnSystemRequest} + */ +public class OnSystemRequestTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnSystemRequest msg = new OnSystemRequest(); + + msg.setFileType(Test.GENERAL_FILETYPE); + msg.setLength(Test.GENERAL_LONG); + msg.setOffset(Test.GENERAL_LONG); + msg.setRequestType(Test.GENERAL_REQUESTTYPE); + msg.setRequestSubType(Test.GENERAL_STRING); + msg.setTimeout(Test.GENERAL_INT); + msg.setUrl(Test.GENERAL_STRING); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_SYSTEM_REQUEST.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnSystemRequest.KEY_FILE_TYPE, Test.GENERAL_FILETYPE); + result.put(OnSystemRequest.KEY_LENGTH, Test.GENERAL_LONG); + result.put(OnSystemRequest.KEY_TIMEOUT, Test.GENERAL_INT); + result.put(OnSystemRequest.KEY_OFFSET, Test.GENERAL_LONG); + result.put(OnSystemRequest.KEY_URL, Test.GENERAL_STRING); + result.put(OnSystemRequest.KEY_REQUEST_TYPE, Test.GENERAL_REQUESTTYPE); + result.put(OnSystemRequest.KEY_REQUEST_SUB_TYPE, Test.GENERAL_STRING); + } catch(JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + FileType fileType = ( (OnSystemRequest) msg ).getFileType(); + Long length = ( (OnSystemRequest) msg ).getLength(); + int timeout = ( (OnSystemRequest) msg ).getTimeout(); + Long offset = ( (OnSystemRequest) msg ).getOffset(); + String url = ( (OnSystemRequest) msg ).getUrl(); + RequestType requestType = ( (OnSystemRequest) msg ).getRequestType(); + String requestSubType = ( (OnSystemRequest) msg ).getRequestSubType(); + + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_FILETYPE, fileType); + assertEquals(Test.MATCH, Test.GENERAL_LONG, length); + assertEquals(Test.MATCH, Test.GENERAL_INT, timeout); + assertEquals(Test.MATCH, Test.GENERAL_LONG, offset); + assertEquals(Test.MATCH, Test.GENERAL_STRING, url); + assertEquals(Test.MATCH, Test.GENERAL_REQUESTTYPE, requestType); + assertEquals(Test.MATCH, Test.GENERAL_STRING, requestSubType); + + // Test Body + OnSystemRequest osr = (OnSystemRequest) msg; + String body = osr.getBody(); + assertNull(Test.NULL, body); + + String testBody = "123ABC"; + osr.setBody(testBody); + + String readBody = osr.getBody(); + assertEquals(Test.MATCH, testBody, readBody); + + // Test Headers + Headers headers = osr.getHeader(); + assertNull(Test.NULL, headers); + + Headers testHeaders = new Headers(); + testHeaders.setCharset("ASCII"); + testHeaders.setConnectTimeout(1000); + testHeaders.setContentLength(1024); + testHeaders.setContentType("application/json"); + testHeaders.setDoInput(false); + testHeaders.setDoOutput(true); + testHeaders.setInstanceFollowRedirects(true); + testHeaders.setReadTimeout(800); + testHeaders.setRequestMethod("POST"); + testHeaders.setUseCaches(false); + osr.setHeaders(testHeaders); + + Headers readHeaders = osr.getHeader(); + assertTrue(Test.TRUE, Validator.validateHeaders(testHeaders, readHeaders)); + + // Invalid/Null Tests + OnSystemRequest msg = new OnSystemRequest(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getFileType()); + assertNull(Test.NULL, msg.getLength()); + assertNull(Test.NULL, msg.getOffset()); + assertNull(Test.NULL, msg.getTimeout()); + assertNull(Test.NULL, msg.getUrl()); + assertNull(Test.NULL, msg.getRequestType()); + assertNull(Test.NULL, msg.getRequestSubType()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnTBTClientStateTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnTBTClientStateTests.java new file mode 100644 index 000000000..47352f6f5 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnTBTClientStateTests.java @@ -0,0 +1,68 @@ +package com.smartdevicelink.test.rpc.notifications; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnTBTClientState; +import com.smartdevicelink.proxy.rpc.enums.TBTState; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnTBTClientState} + */ +public class OnTBTClientStateTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnTBTClientState msg = new OnTBTClientState(); + + msg.setState(Test.GENERAL_TBTSTATE); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_TBT_CLIENT_STATE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnTBTClientState.KEY_STATE, Test.GENERAL_TBTSTATE); + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + TBTState data = ( (OnTBTClientState) msg ).getState(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_TBTSTATE, data); + + // Invalid/Null Tests + OnTBTClientState msg = new OnTBTClientState(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getState()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnTouchEventTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnTouchEventTests.java new file mode 100644 index 000000000..613afa55b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnTouchEventTests.java @@ -0,0 +1,81 @@ +package com.smartdevicelink.test.rpc.notifications; + +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.OnTouchEvent; +import com.smartdevicelink.proxy.rpc.TouchEvent; +import com.smartdevicelink.proxy.rpc.enums.TouchType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.OnTouchEvent} + */ +public class OnTouchEventTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + OnTouchEvent msg = new OnTouchEvent(); + msg.setType(Test.GENERAL_TOUCHTYPE); + msg.setEvent(Test.GENERAL_TOUCHEVENT_LIST); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_TOUCH_EVENT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnTouchEvent.KEY_TYPE,Test.GENERAL_TOUCHTYPE); + result.put(OnTouchEvent.KEY_EVENT, Test.JSON_TOUCHEVENTS); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + TouchType type = ( (OnTouchEvent) msg ).getType(); + List<TouchEvent> event = ( (OnTouchEvent) msg ).getEvent(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_TOUCHTYPE, type); + assertEquals(Test.MATCH, Test.GENERAL_TOUCHEVENT_LIST.size(), event.size()); + for(int i=0; i< Test.GENERAL_TOUCHEVENT_LIST.size(); i++){ + TouchEvent referenceEvent = Test.GENERAL_TOUCHEVENT_LIST.get(i); + TouchEvent dataEvent = event.get(i); + assertTrue(Test.TRUE, Validator.validateTouchEvent(referenceEvent, dataEvent)); + } + + // Invalid/Null Tests + OnTouchEvent msg = new OnTouchEvent(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getType()); + assertNull(Test.NULL, msg.getEvent()); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnVehicleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnVehicleDataTests.java new file mode 100644 index 000000000..c530c1278 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnVehicleDataTests.java @@ -0,0 +1,499 @@ +package com.smartdevicelink.test.rpc.notifications; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AirbagStatus; +import com.smartdevicelink.proxy.rpc.BeltStatus; +import com.smartdevicelink.proxy.rpc.BodyInformation; +import com.smartdevicelink.proxy.rpc.ClusterModeStatus; +import com.smartdevicelink.proxy.rpc.DeviceStatus; +import com.smartdevicelink.proxy.rpc.ECallInfo; +import com.smartdevicelink.proxy.rpc.EmergencyEvent; +import com.smartdevicelink.proxy.rpc.FuelRange; +import com.smartdevicelink.proxy.rpc.GPSData; +import com.smartdevicelink.proxy.rpc.HeadLampStatus; +import com.smartdevicelink.proxy.rpc.MyKey; +import com.smartdevicelink.proxy.rpc.OnVehicleData; +import com.smartdevicelink.proxy.rpc.SingleTireStatus; +import com.smartdevicelink.proxy.rpc.TireStatus; +import com.smartdevicelink.proxy.rpc.enums.ComponentVolumeStatus; +import com.smartdevicelink.proxy.rpc.enums.ElectronicParkBrakeStatus; +import com.smartdevicelink.proxy.rpc.enums.PRNDL; +import com.smartdevicelink.proxy.rpc.enums.TurnSignal; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataEventStatus; +import com.smartdevicelink.proxy.rpc.enums.WiperStatus; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.VehicleDataHelper; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.OnVehicleData} + */ +public class OnVehicleDataTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return VehicleDataHelper.VEHICLE_DATA; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(OnVehicleData.KEY_SPEED, VehicleDataHelper.SPEED); + result.put(OnVehicleData.KEY_RPM, VehicleDataHelper.RPM); + result.put(OnVehicleData.KEY_EXTERNAL_TEMPERATURE, VehicleDataHelper.EXTERNAL_TEMPERATURE); + result.put(OnVehicleData.KEY_FUEL_LEVEL, VehicleDataHelper.FUEL_LEVEL); + result.put(OnVehicleData.KEY_VIN, VehicleDataHelper.VIN); + result.put(OnVehicleData.KEY_PRNDL, VehicleDataHelper.PRNDL_FINAL); + result.put(OnVehicleData.KEY_TIRE_PRESSURE, VehicleDataHelper.TIRE_PRESSURE.serializeJSON()); + result.put(OnVehicleData.KEY_ENGINE_TORQUE, VehicleDataHelper.ENGINE_TORQUE); + result.put(OnVehicleData.KEY_ENGINE_OIL_LIFE, VehicleDataHelper.ENGINE_OIL_LIFE); + result.put(OnVehicleData.KEY_ODOMETER, VehicleDataHelper.ODOMETER); + result.put(OnVehicleData.KEY_GPS, VehicleDataHelper.GPS.serializeJSON()); + result.put(OnVehicleData.KEY_FUEL_LEVEL_STATE, VehicleDataHelper.FUEL_LEVEL_STATE); + result.put(OnVehicleData.KEY_INSTANT_FUEL_CONSUMPTION, VehicleDataHelper.INSTANT_FUEL_CONSUMPTION); + result.put(OnVehicleData.KEY_BELT_STATUS, VehicleDataHelper.BELT_STATUS.serializeJSON()); + result.put(OnVehicleData.KEY_BODY_INFORMATION, VehicleDataHelper.BODY_INFORMATION.serializeJSON()); + result.put(OnVehicleData.KEY_DEVICE_STATUS, VehicleDataHelper.DEVICE_STATUS.serializeJSON()); + result.put(OnVehicleData.KEY_DRIVER_BRAKING, VehicleDataHelper.DRIVER_BRAKING); + result.put(OnVehicleData.KEY_WIPER_STATUS, VehicleDataHelper.WIPER_STATUS); + result.put(OnVehicleData.KEY_HEAD_LAMP_STATUS, VehicleDataHelper.HEAD_LAMP_STATUS.serializeJSON()); + result.put(OnVehicleData.KEY_ACC_PEDAL_POSITION, VehicleDataHelper.ACC_PEDAL_POSITION); + result.put(OnVehicleData.KEY_STEERING_WHEEL_ANGLE, VehicleDataHelper.STEERING_WHEEL_ANGLE); + result.put(OnVehicleData.KEY_E_CALL_INFO, VehicleDataHelper.E_CALL_INFO.serializeJSON()); + result.put(OnVehicleData.KEY_AIRBAG_STATUS, VehicleDataHelper.AIRBAG_STATUS.serializeJSON()); + result.put(OnVehicleData.KEY_EMERGENCY_EVENT, VehicleDataHelper.EMERGENCY_EVENT.serializeJSON()); + result.put(OnVehicleData.KEY_CLUSTER_MODE_STATUS, VehicleDataHelper.CLUSTER_MODE_STATUS.serializeJSON()); + result.put(OnVehicleData.KEY_MY_KEY, VehicleDataHelper.MY_KEY.serializeJSON()); + result.put(OnVehicleData.KEY_FUEL_RANGE, VehicleDataHelper.JSON_FUEL_RANGE); + result.put(OnVehicleData.KEY_TURN_SIGNAL, VehicleDataHelper.TURN_SIGNAL); + result.put(OnVehicleData.KEY_ELECTRONIC_PARK_BRAKE_STATUS, VehicleDataHelper.ELECTRONIC_PARK_BRAKE_STATUS); + } catch(JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Double speed = ( (OnVehicleData) msg).getSpeed(); + int rpm = ( (OnVehicleData) msg).getRpm(); + Double external = ( (OnVehicleData) msg).getExternalTemperature(); + Double fuelLevel = ( (OnVehicleData) msg).getFuelLevel(); + String vin = ( (OnVehicleData) msg).getVin(); + PRNDL prndl = ( (OnVehicleData) msg).getPrndl(); + TireStatus pressure = ( (OnVehicleData) msg).getTirePressure(); + Double torque = ( (OnVehicleData) msg).getEngineTorque(); + Float engineOilLife = ( (OnVehicleData) msg).getEngineOilLife(); + int odometer = ( (OnVehicleData) msg).getOdometer(); + GPSData gps = ( (OnVehicleData) msg).getGps(); + ComponentVolumeStatus state = ( (OnVehicleData) msg).getFuelLevelState(); + Double consumption = ( (OnVehicleData) msg).getInstantFuelConsumption(); + BeltStatus belt = ( (OnVehicleData) msg).getBeltStatus(); + BodyInformation body = ( (OnVehicleData) msg).getBodyInformation(); + DeviceStatus device = ( (OnVehicleData) msg).getDeviceStatus(); + VehicleDataEventStatus brake = ( (OnVehicleData) msg).getDriverBraking(); + WiperStatus wiper = ( (OnVehicleData) msg).getWiperStatus(); + HeadLampStatus lamp = ( (OnVehicleData) msg).getHeadLampStatus(); + Double pedal = ( (OnVehicleData) msg).getAccPedalPosition(); + Double wheel = ( (OnVehicleData) msg).getSteeringWheelAngle(); + ECallInfo ecall = ( (OnVehicleData) msg).getECallInfo(); + AirbagStatus airbag = ( (OnVehicleData) msg).getAirbagStatus(); + EmergencyEvent event = ( (OnVehicleData) msg).getEmergencyEvent(); + ClusterModeStatus cluster = ( (OnVehicleData) msg).getClusterModeStatus(); + MyKey key = ( (OnVehicleData) msg).getMyKey(); + List<FuelRange> fuelRangeList = ( (OnVehicleData) msg).getFuelRange(); + TurnSignal turnSignal = ( (OnVehicleData) msg).getTurnSignal(); + ElectronicParkBrakeStatus electronicParkBrakeStatus = ( (OnVehicleData) msg).getElectronicParkBrakeStatus(); + + // Valid Tests + assertEquals(Test.MATCH, VehicleDataHelper.SPEED, speed); + assertEquals(Test.MATCH, VehicleDataHelper.RPM, rpm); + assertEquals(Test.MATCH, VehicleDataHelper.EXTERNAL_TEMPERATURE, external); + assertEquals(Test.MATCH, VehicleDataHelper.FUEL_LEVEL, fuelLevel); + assertEquals(Test.MATCH, VehicleDataHelper.VIN, vin); + assertEquals(Test.MATCH, VehicleDataHelper.PRNDL_FINAL, prndl); + assertTrue(Test.MATCH, Validator.validateTireStatus(VehicleDataHelper.TIRE_PRESSURE, pressure)); + assertEquals(Test.MATCH, VehicleDataHelper.ENGINE_TORQUE, torque); + assertEquals(Test.MATCH, VehicleDataHelper.ENGINE_OIL_LIFE, engineOilLife); + assertEquals(Test.MATCH, VehicleDataHelper.ODOMETER, odometer); + assertTrue(Test.MATCH, Validator.validateGpsData(VehicleDataHelper.GPS, gps)); + assertEquals(Test.MATCH, VehicleDataHelper.FUEL_LEVEL_STATE, state); + assertEquals(Test.MATCH, VehicleDataHelper.INSTANT_FUEL_CONSUMPTION, consumption); + assertTrue(Test.TRUE, Validator.validateBeltStatus(VehicleDataHelper.BELT_STATUS, belt)); + assertTrue(Test.TRUE, Validator.validateBodyInformation(VehicleDataHelper.BODY_INFORMATION, body)); + assertTrue(Test.TRUE, Validator.validateDeviceStatus(VehicleDataHelper.DEVICE_STATUS, device)); + assertEquals(Test.MATCH, VehicleDataHelper.DRIVER_BRAKING, brake); + assertEquals(Test.MATCH, VehicleDataHelper.WIPER_STATUS, wiper); + assertTrue(Test.TRUE, Validator.validateHeadLampStatus(VehicleDataHelper.HEAD_LAMP_STATUS, lamp)); + assertEquals(Test.MATCH, VehicleDataHelper.ACC_PEDAL_POSITION, pedal); + assertEquals(Test.MATCH, VehicleDataHelper.STEERING_WHEEL_ANGLE, wheel); + assertTrue(Test.TRUE, Validator.validateECallInfo(VehicleDataHelper.E_CALL_INFO, ecall)); + assertTrue(Test.TRUE, Validator.validateAirbagStatus(VehicleDataHelper.AIRBAG_STATUS, airbag)); + assertTrue(Test.TRUE, Validator.validateEmergencyEvent(VehicleDataHelper.EMERGENCY_EVENT, event)); + assertTrue(Test.TRUE, Validator.validateClusterModeStatus(VehicleDataHelper.CLUSTER_MODE_STATUS, cluster)); + assertTrue(Test.TRUE, Validator.validateMyKey(VehicleDataHelper.MY_KEY, key)); + assertTrue(Test.TRUE, Validator.validateFuelRange(VehicleDataHelper.FUEL_RANGE_LIST, fuelRangeList)); + assertEquals(Test.MATCH, VehicleDataHelper.TURN_SIGNAL, turnSignal); + assertEquals(Test.MATCH, VehicleDataHelper.ELECTRONIC_PARK_BRAKE_STATUS, electronicParkBrakeStatus); + + // Invalid/Null Tests + OnVehicleData msg = new OnVehicleData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSpeed()); + assertNull(Test.NULL, msg.getRpm()); + assertNull(Test.NULL, msg.getExternalTemperature()); + assertNull(Test.NULL, msg.getFuelLevel()); + assertNull(Test.NULL, msg.getVin()); + assertNull(Test.NULL, msg.getPrndl()); + assertNull(Test.NULL, msg.getTirePressure()); + assertNull(Test.NULL, msg.getEngineTorque()); + assertNull(Test.NULL, msg.getEngineOilLife()); + assertNull(Test.NULL, msg.getOdometer()); + assertNull(Test.NULL, msg.getGps()); + assertNull(Test.NULL, msg.getFuelLevelState()); + assertNull(Test.NULL, msg.getInstantFuelConsumption()); + assertNull(Test.NULL, msg.getBeltStatus()); + assertNull(Test.NULL, msg.getBodyInformation()); + assertNull(Test.NULL, msg.getDeviceStatus()); + assertNull(Test.NULL, msg.getDriverBraking()); + assertNull(Test.NULL, msg.getWiperStatus()); + assertNull(Test.NULL, msg.getHeadLampStatus()); + assertNull(Test.NULL, msg.getAccPedalPosition()); + assertNull(Test.NULL, msg.getSteeringWheelAngle()); + assertNull(Test.NULL, msg.getECallInfo()); + assertNull(Test.NULL, msg.getAirbagStatus()); + assertNull(Test.NULL, msg.getEmergencyEvent()); + assertNull(Test.NULL, msg.getClusterModeStatus()); + assertNull(Test.NULL, msg.getMyKey()); + assertNull(Test.NULL, msg.getFuelRange()); + assertNull(Test.NULL, msg.getTurnSignal()); + assertNull(Test.NULL, msg.getElectronicParkBrakeStatus()); + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + //Objects needed on the first level. + JSONObject tireStatusObj = new JSONObject(); + JSONObject GPSDataObj = new JSONObject(); + JSONObject beltStatusObj = new JSONObject(); + JSONObject bodyInformationObj = new JSONObject(); + JSONObject deviceStatusObj = new JSONObject(); + JSONObject headLampStatusObj = new JSONObject(); + JSONObject ECallInfoObj = new JSONObject(); + JSONObject airbagStatusObj = new JSONObject(); + JSONObject emergencyEventObj = new JSONObject(); + JSONObject clusterModeStatusObj = new JSONObject(); + JSONObject myKeyObj = new JSONObject(); + JSONObject fuelRangeObj = new JSONObject(); + JSONArray fuelRangeArrayObj = new JSONArray(); + + try { + //Set up the JSONObject to represent OnVehicleData: + + //TIRE_PRESSURE + tireStatusObj.put(TireStatus.KEY_PRESSURE_TELL_TALE, VehicleDataHelper.TIRE_PRESSURE_TELL_TALE); + JSONObject tireLeftFront = new JSONObject(); + tireLeftFront.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_LEFT_FRONT); + tireStatusObj.put(TireStatus.KEY_LEFT_FRONT, tireLeftFront); + JSONObject tireRightFront = new JSONObject(); + tireRightFront.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_RIGHT_FRONT); + tireStatusObj.put(TireStatus.KEY_RIGHT_FRONT, tireRightFront); + JSONObject tireLeftRear = new JSONObject(); + tireLeftRear.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_LEFT_REAR); + tireStatusObj.put(TireStatus.KEY_LEFT_REAR, tireLeftRear); + JSONObject tireRightRear = new JSONObject(); + tireRightRear.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_RIGHT_REAR); + tireStatusObj.put(TireStatus.KEY_RIGHT_REAR, tireRightRear); + JSONObject tireInnerLeftRear = new JSONObject(); + tireInnerLeftRear.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_INNER_LEFT_REAR); + tireStatusObj.put(TireStatus.KEY_INNER_LEFT_REAR, tireInnerLeftRear); + JSONObject tireInnerRightRear = new JSONObject(); + tireInnerRightRear.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_INNER_RIGHT_REAR); + tireStatusObj.put(TireStatus.KEY_INNER_RIGHT_REAR, tireInnerRightRear); + + //GPS + GPSDataObj.put(GPSData.KEY_LONGITUDE_DEGREES, VehicleDataHelper.GPS_LONGITUDE); + GPSDataObj.put(GPSData.KEY_LATITUDE_DEGREES, VehicleDataHelper.GPS_LATITUDE); + GPSDataObj.put(GPSData.KEY_UTC_YEAR, VehicleDataHelper.GPS_YEAR); + GPSDataObj.put(GPSData.KEY_UTC_MONTH, VehicleDataHelper.GPS_MONTH); + GPSDataObj.put(GPSData.KEY_UTC_DAY, VehicleDataHelper.GPS_DAY); + GPSDataObj.put(GPSData.KEY_UTC_HOURS, VehicleDataHelper.GPS_HOURS); + GPSDataObj.put(GPSData.KEY_UTC_MINUTES, VehicleDataHelper.GPS_MINUTES); + GPSDataObj.put(GPSData.KEY_UTC_SECONDS, VehicleDataHelper.GPS_SECONDS); + GPSDataObj.put(GPSData.KEY_COMPASS_DIRECTION, VehicleDataHelper.GPS_DIRECTION); + GPSDataObj.put(GPSData.KEY_PDOP, VehicleDataHelper.GPS_PDOP); + GPSDataObj.put(GPSData.KEY_VDOP, VehicleDataHelper.GPS_VDOP); + GPSDataObj.put(GPSData.KEY_HDOP, VehicleDataHelper.GPS_HDOP); + GPSDataObj.put(GPSData.KEY_ACTUAL, VehicleDataHelper.GPS_ACTUAL); + GPSDataObj.put(GPSData.KEY_SATELLITES, VehicleDataHelper.GPS_SATELLITES); + GPSDataObj.put(GPSData.KEY_DIMENSION, VehicleDataHelper.GPS_DIMENSION); + GPSDataObj.put(GPSData.KEY_ALTITUDE, VehicleDataHelper.GPS_ALTITUDE); + GPSDataObj.put(GPSData.KEY_HEADING, VehicleDataHelper.GPS_HEADING); + GPSDataObj.put(GPSData.KEY_SPEED, VehicleDataHelper.GPS_SPEED); + + //BELT_STATUS + beltStatusObj.put(BeltStatus.KEY_DRIVER_BELT_DEPLOYED, VehicleDataHelper.BELT_STATUS_DRIVER_DEPLOYED); + beltStatusObj.put(BeltStatus.KEY_PASSENGER_BELT_DEPLOYED, VehicleDataHelper.BELT_STATUS_PASSENGER_DEPLOYED); + beltStatusObj.put(BeltStatus.KEY_PASSENGER_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_PASSENGER_BELTED); + beltStatusObj.put(BeltStatus.KEY_DRIVER_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_DRIVER_BELTED); + beltStatusObj.put(BeltStatus.KEY_LEFT_ROW_2_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_LEFT_ROW_2_BELTED); + beltStatusObj.put(BeltStatus.KEY_PASSENGER_CHILD_DETECTED, VehicleDataHelper.BELT_STATUS_PASSENGER_CHILD); + beltStatusObj.put(BeltStatus.KEY_RIGHT_ROW_2_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_RIGHT_ROW_2_BELTED); + beltStatusObj.put(BeltStatus.KEY_MIDDLE_ROW_2_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_MIDDLE_ROW_2_BELTED); + beltStatusObj.put(BeltStatus.KEY_MIDDLE_ROW_3_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_MIDDLE_ROW_3_BELTED); + beltStatusObj.put(BeltStatus.KEY_LEFT_ROW_3_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_LEFT_ROW_3_BELTED); + beltStatusObj.put(BeltStatus.KEY_RIGHT_ROW_3_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_RIGHT_ROW_3_BELTED); + beltStatusObj.put(BeltStatus.KEY_REAR_INFLATABLE_BELTED, VehicleDataHelper.BELT_STATUS_LEFT_REAR_INFLATABLE_BELTED); + beltStatusObj.put(BeltStatus.KEY_RIGHT_REAR_INFLATABLE_BELTED, VehicleDataHelper.BELT_STATUS_RIGHT_REAR_INFLATABLE_BELTED); + beltStatusObj.put(BeltStatus.KEY_MIDDLE_ROW_1_BELT_DEPLOYED, VehicleDataHelper.BELT_STATUS_MIDDLE_ROW_1_DEPLOYED); + beltStatusObj.put(BeltStatus.KEY_MIDDLE_ROW_1_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_MIDDLE_ROW_1_BELTED); + + //BODY_INFORMATION + bodyInformationObj.put(BodyInformation.KEY_PARK_BRAKE_ACTIVE, VehicleDataHelper.BODY_INFORMATION_PARK_BRAKE); + bodyInformationObj.put(BodyInformation.KEY_IGNITION_STABLE_STATUS, VehicleDataHelper.BODY_INFORMATION_IGNITION_STATUS); + bodyInformationObj.put(BodyInformation.KEY_IGNITION_STATUS, VehicleDataHelper.BODY_INFORMATION_IGNITION_STABLE_STATUS); + bodyInformationObj.put(BodyInformation.KEY_DRIVER_DOOR_AJAR, VehicleDataHelper.BODY_INFORMATION_DRIVER_AJAR); + bodyInformationObj.put(BodyInformation.KEY_PASSENGER_DOOR_AJAR, VehicleDataHelper.BODY_INFORMATION_PASSENGER_AJAR); + bodyInformationObj.put(BodyInformation.KEY_REAR_LEFT_DOOR_AJAR, VehicleDataHelper.BODY_INFORMATION_REAR_LEFT_AJAR); + bodyInformationObj.put(BodyInformation.KEY_REAR_RIGHT_DOOR_AJAR, VehicleDataHelper.BODY_INFORMATION_REAR_RIGHT_AJAR); + + //DEVICE_STATUS + deviceStatusObj.put(DeviceStatus.KEY_VOICE_REC_ON, VehicleDataHelper.DEVICE_STATUS_VOICE_REC); + deviceStatusObj.put(DeviceStatus.KEY_BT_ICON_ON, VehicleDataHelper.DEVICE_STATUS_BT_ICON); + deviceStatusObj.put(DeviceStatus.KEY_CALL_ACTIVE, VehicleDataHelper.DEVICE_STATUS_CALL_ACTIVE); + deviceStatusObj.put(DeviceStatus.KEY_PHONE_ROAMING, VehicleDataHelper.DEVICE_STATUS_PHONE_ROAMING); + deviceStatusObj.put(DeviceStatus.KEY_TEXT_MSG_AVAILABLE, VehicleDataHelper.DEVICE_STATUS_TEXT_MSG_AVAILABLE); + deviceStatusObj.put(DeviceStatus.KEY_BATT_LEVEL_STATUS, VehicleDataHelper.DEVICE_STATUS_BATT_LEVEL_STATUS); + deviceStatusObj.put(DeviceStatus.KEY_STEREO_AUDIO_OUTPUT_MUTED, VehicleDataHelper.DEVICE_STATUS_STEREO_MUTED); + deviceStatusObj.put(DeviceStatus.KEY_MONO_AUDIO_OUTPUT_MUTED, VehicleDataHelper.DEVICE_STATUS_MONO_MUTED); + deviceStatusObj.put(DeviceStatus.KEY_SIGNAL_LEVEL_STATUS, VehicleDataHelper.DEVICE_STATUS_SIGNAL_LEVEL_STATUS); + deviceStatusObj.put(DeviceStatus.KEY_PRIMARY_AUDIO_SOURCE, VehicleDataHelper.DEVICE_STATUS_PRIMARY_AUDIO); + deviceStatusObj.put(DeviceStatus.KEY_E_CALL_EVENT_ACTIVE, VehicleDataHelper.DEVICE_STATUS_E_CALL_ACTIVE); + + //HEAD_LAMP_STATUS + headLampStatusObj.put(HeadLampStatus.KEY_AMBIENT_LIGHT_SENSOR_STATUS, VehicleDataHelper.HEAD_LAMP_STATUS_AMBIENT_STATUS); + headLampStatusObj.put(HeadLampStatus.KEY_HIGH_BEAMS_ON, VehicleDataHelper.HEAD_LAMP_HIGH_BEAMS); + headLampStatusObj.put(HeadLampStatus.KEY_LOW_BEAMS_ON, VehicleDataHelper.HEAD_LAMP_LOW_BEAMS); + + //E_CALL_INFO + ECallInfoObj.put(ECallInfo.KEY_E_CALL_NOTIFICATION_STATUS, VehicleDataHelper.E_CALL_INFO_E_CALL_NOTIFICATION_STATUS); + ECallInfoObj.put(ECallInfo.KEY_AUX_E_CALL_NOTIFICATION_STATUS, VehicleDataHelper.E_CALL_INFO_AUX_E_CALL_NOTIFICATION_STATUS); + ECallInfoObj.put(ECallInfo.KEY_E_CALL_CONFIRMATION_STATUS, VehicleDataHelper.E_CALL_INFO_CONFIRMATION_STATUS); + + //AIRBAG_STATUS + airbagStatusObj.put(AirbagStatus.KEY_DRIVER_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_DRIVER_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_DRIVER_SIDE_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_DRIVER_SIDE_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_DRIVER_CURTAIN_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_DRIVER_CURTAIN_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_DRIVER_KNEE_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_DRIVER_KNEE_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_PASSENGER_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_PASSENGER_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_PASSENGER_SIDE_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_PASSENGER_SIDE_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_PASSENGER_CURTAIN_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_PASSENGER_CURTAIN_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_PASSENGER_KNEE_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_PASSENGER_KNEE_DEPLOYED); + + //EMERGENCY_EVENT + emergencyEventObj.put(EmergencyEvent.KEY_EMERGENCY_EVENT_TYPE, VehicleDataHelper.EMERGENCY_EVENT_TYPE); + emergencyEventObj.put(EmergencyEvent.KEY_FUEL_CUTOFF_STATUS, VehicleDataHelper.EMERGENCY_EVENT_FUEL_CUTOFF_STATUS); + emergencyEventObj.put(EmergencyEvent.KEY_ROLLOVER_EVENT, VehicleDataHelper.EMERGENCY_EVENT_ROLLOVER_EVENT); + emergencyEventObj.put(EmergencyEvent.KEY_MAXIMUM_CHANGE_VELOCITY, VehicleDataHelper.EMERGENCY_EVENT_MAX_CHANGE_VELOCITY); + emergencyEventObj.put(EmergencyEvent.KEY_MULTIPLE_EVENTS, VehicleDataHelper.EMERGENCY_EVENT_MULTIPLE_EVENTS); + + //CLUSTER_MODE_STATUS + clusterModeStatusObj.put(ClusterModeStatus.KEY_POWER_MODE_ACTIVE, VehicleDataHelper.CLUSTER_MODE_STATUS_POWER_MODE_ACTIVE); + clusterModeStatusObj.put(ClusterModeStatus.KEY_POWER_MODE_QUALIFICATION_STATUS, VehicleDataHelper.CLUSTER_MODE_STATUS_POWER_MODE_QUALIFICATION_STATUS); + clusterModeStatusObj.put(ClusterModeStatus.KEY_CAR_MODE_STATUS, VehicleDataHelper.CLUSTER_MODE_STATUS_CAR_MODE_STATUS); + clusterModeStatusObj.put(ClusterModeStatus.KEY_POWER_MODE_STATUS, VehicleDataHelper.CLUSTER_MODE_STATUS_POWER_MODE_STATUS); + + //MY_KEY + myKeyObj.put(MyKey.KEY_E_911_OVERRIDE, VehicleDataHelper.MY_KEY_E_911_OVERRIDE); + + // FUEL_RANGE + fuelRangeObj.put(FuelRange.KEY_TYPE, VehicleDataHelper.FUEL_RANGE_TYPE); + fuelRangeObj.put(FuelRange.KEY_RANGE, VehicleDataHelper.FUEL_RANGE_RANGE); + fuelRangeArrayObj.put(fuelRangeObj); + + reference.put(OnVehicleData.KEY_SPEED, VehicleDataHelper.SPEED); + reference.put(OnVehicleData.KEY_RPM, VehicleDataHelper.RPM); + reference.put(OnVehicleData.KEY_EXTERNAL_TEMPERATURE, VehicleDataHelper.EXTERNAL_TEMPERATURE); + reference.put(OnVehicleData.KEY_FUEL_LEVEL, VehicleDataHelper.FUEL_LEVEL); + reference.put(OnVehicleData.KEY_VIN, VehicleDataHelper.VIN); + reference.put(OnVehicleData.KEY_PRNDL, VehicleDataHelper.PRNDL_FINAL); + reference.put(OnVehicleData.KEY_TIRE_PRESSURE, tireStatusObj); + reference.put(OnVehicleData.KEY_ENGINE_TORQUE, VehicleDataHelper.ENGINE_TORQUE); + reference.put(OnVehicleData.KEY_ENGINE_OIL_LIFE, VehicleDataHelper.ENGINE_OIL_LIFE); + reference.put(OnVehicleData.KEY_ODOMETER, VehicleDataHelper.ODOMETER); + reference.put(OnVehicleData.KEY_GPS, GPSDataObj); + reference.put(OnVehicleData.KEY_FUEL_LEVEL_STATE, VehicleDataHelper.FUEL_LEVEL_STATE); + reference.put(OnVehicleData.KEY_INSTANT_FUEL_CONSUMPTION, VehicleDataHelper.INSTANT_FUEL_CONSUMPTION); + reference.put(OnVehicleData.KEY_BELT_STATUS, beltStatusObj); + reference.put(OnVehicleData.KEY_BODY_INFORMATION, bodyInformationObj); + reference.put(OnVehicleData.KEY_DEVICE_STATUS, deviceStatusObj); + reference.put(OnVehicleData.KEY_DRIVER_BRAKING, VehicleDataHelper.DRIVER_BRAKING); + reference.put(OnVehicleData.KEY_WIPER_STATUS, VehicleDataHelper.WIPER_STATUS); + reference.put(OnVehicleData.KEY_HEAD_LAMP_STATUS, headLampStatusObj); + reference.put(OnVehicleData.KEY_ACC_PEDAL_POSITION, VehicleDataHelper.ACC_PEDAL_POSITION); + reference.put(OnVehicleData.KEY_STEERING_WHEEL_ANGLE, VehicleDataHelper.STEERING_WHEEL_ANGLE); + reference.put(OnVehicleData.KEY_E_CALL_INFO, ECallInfoObj); + reference.put(OnVehicleData.KEY_AIRBAG_STATUS, airbagStatusObj); + reference.put(OnVehicleData.KEY_EMERGENCY_EVENT, emergencyEventObj); + reference.put(OnVehicleData.KEY_CLUSTER_MODE_STATUS, clusterModeStatusObj); + reference.put(OnVehicleData.KEY_MY_KEY, myKeyObj); + reference.put(OnVehicleData.KEY_FUEL_RANGE, fuelRangeArrayObj); + reference.put(OnVehicleData.KEY_TURN_SIGNAL, VehicleDataHelper.TURN_SIGNAL); + reference.put(OnVehicleData.KEY_ELECTRONIC_PARK_BRAKE_STATUS, VehicleDataHelper.ELECTRONIC_PARK_BRAKE_STATUS); + + JSONObject underTest = msg.serializeJSON(); + //go inside underTest and only return the JSONObject inside the parameters key inside the notification key + underTest = underTest.getJSONObject("notification").getJSONObject("parameters"); + + assertEquals(Test.MATCH, reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + + while (iterator.hasNext()) { + String key = (String) iterator.next(); + + if (key.equals(OnVehicleData.KEY_TIRE_PRESSURE)) { + JSONObject tirePressureReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject tirePressureTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateTireStatus( + new TireStatus(JsonRPCMarshaller.deserializeJSONObject(tirePressureReference)), + new TireStatus(JsonRPCMarshaller.deserializeJSONObject(tirePressureTest)))); + + } else if (key.equals(OnVehicleData.KEY_GPS)) { + JSONObject GPSObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject GPSObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateGpsData( + new GPSData(JsonRPCMarshaller.deserializeJSONObject(GPSObjReference)), + new GPSData(JsonRPCMarshaller.deserializeJSONObject(GPSObjTest)))); + } else if (key.equals(OnVehicleData.KEY_BELT_STATUS)) { + JSONObject beltObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject beltObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateBeltStatus( + new BeltStatus(JsonRPCMarshaller.deserializeJSONObject(beltObjReference)), + new BeltStatus(JsonRPCMarshaller.deserializeJSONObject(beltObjTest)))); + } else if (key.equals(OnVehicleData.KEY_BODY_INFORMATION)) { + JSONObject bodyInfoObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject bodyInfoObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateBodyInformation( + new BodyInformation(JsonRPCMarshaller.deserializeJSONObject(bodyInfoObjReference)), + new BodyInformation(JsonRPCMarshaller.deserializeJSONObject(bodyInfoObjTest)))); + } else if (key.equals(OnVehicleData.KEY_DEVICE_STATUS)) { + JSONObject deviceObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject deviceObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateDeviceStatus( + new DeviceStatus(JsonRPCMarshaller.deserializeJSONObject(deviceObjReference)), + new DeviceStatus(JsonRPCMarshaller.deserializeJSONObject(deviceObjTest)))); + } else if (key.equals(OnVehicleData.KEY_HEAD_LAMP_STATUS)) { + JSONObject headLampObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject headLampObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateHeadLampStatus( + new HeadLampStatus(JsonRPCMarshaller.deserializeJSONObject(headLampObjReference)), + new HeadLampStatus(JsonRPCMarshaller.deserializeJSONObject(headLampObjTest)))); + } else if (key.equals(OnVehicleData.KEY_E_CALL_INFO)) { + JSONObject callInfoObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject callInfoObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateECallInfo( + new ECallInfo(JsonRPCMarshaller.deserializeJSONObject(callInfoObjReference)), + new ECallInfo(JsonRPCMarshaller.deserializeJSONObject(callInfoObjTest)))); + } else if (key.equals(OnVehicleData.KEY_AIRBAG_STATUS)) { + JSONObject airbagObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject airbagObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateAirbagStatus( + new AirbagStatus(JsonRPCMarshaller.deserializeJSONObject(airbagObjReference)), + new AirbagStatus(JsonRPCMarshaller.deserializeJSONObject(airbagObjTest)))); + } + else if (key.equals(OnVehicleData.KEY_EMERGENCY_EVENT)) { + JSONObject emergencyObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject emergencyObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateEmergencyEvent( + new EmergencyEvent(JsonRPCMarshaller.deserializeJSONObject(emergencyObjReference)), + new EmergencyEvent(JsonRPCMarshaller.deserializeJSONObject(emergencyObjTest)))); + } + else if (key.equals(OnVehicleData.KEY_CLUSTER_MODE_STATUS)) { + JSONObject clusterModeObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject clusterModeObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateClusterModeStatus( + new ClusterModeStatus(JsonRPCMarshaller.deserializeJSONObject(clusterModeObjReference)), + new ClusterModeStatus(JsonRPCMarshaller.deserializeJSONObject(clusterModeObjTest)))); + } + else if (key.equals(OnVehicleData.KEY_MY_KEY)) { + JSONObject myKeyObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject myKeyObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue(Test.TRUE, Validator.validateMyKey( + new MyKey(JsonRPCMarshaller.deserializeJSONObject(myKeyObjReference)), + new MyKey(JsonRPCMarshaller.deserializeJSONObject(myKeyObjTest)))); + } + else if (key.equals(OnVehicleData.KEY_ENGINE_OIL_LIFE)) { + assertEquals(JsonUtils.readDoubleFromJsonObject(reference, key), JsonUtils.readDoubleFromJsonObject(underTest, key)); + } + else if (key.equals(OnVehicleData.KEY_FUEL_RANGE)) { + JSONArray fuelRangeArrayObjReference = JsonUtils.readJsonArrayFromJsonObject(reference, key); + List<FuelRange> fuelRangeRefereceList = new ArrayList<FuelRange>(); + for (int index = 0; index < fuelRangeArrayObjReference.length(); index++) { + FuelRange fuelRange = new FuelRange(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)fuelRangeArrayObjReference.get(index) )); + fuelRangeRefereceList.add(fuelRange); + } + + JSONArray fuelRangeArrayObjTest = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + List<FuelRange> fuelRangeUnderTestList = new ArrayList<FuelRange>(); + for (int index = 0; index < fuelRangeArrayObjTest.length(); index++) { + FuelRange fuelRange = new FuelRange(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)fuelRangeArrayObjTest.get(index) )); + fuelRangeUnderTestList.add(fuelRange); + } + + assertTrue(Test.TRUE, Validator.validateFuelRange( + fuelRangeRefereceList, + fuelRangeUnderTestList)); + } + else { + assertEquals(Test.TRUE, 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/notifications/OnWayPointChangeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnWayPointChangeTests.java new file mode 100644 index 000000000..dcc02dafd --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/notifications/OnWayPointChangeTests.java @@ -0,0 +1,86 @@ +package com.smartdevicelink.test.rpc.notifications; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetWayPointsResponse; +import com.smartdevicelink.proxy.rpc.LocationDetails; +import com.smartdevicelink.proxy.rpc.OnWayPointChange; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class OnWayPointChangeTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage(){ + OnWayPointChange msg = new OnWayPointChange(); + + List<LocationDetails> list = new ArrayList<>(); + list.add(Test.GENERAL_LOCATIONDETAILS); + list.add(Test.GENERAL_LOCATIONDETAILS); + + msg.setWayPoints(list); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_NOTIFICATION; + } + + @Override + protected String getCommandType(){ + return FunctionID.ON_WAY_POINT_CHANGE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + JSONArray jsonArray = new JSONArray(); + try { + jsonArray.put(JsonRPCMarshaller.serializeHashtable(Test.GENERAL_LOCATIONDETAILS.getStore())); + jsonArray.put(JsonRPCMarshaller.serializeHashtable(Test.GENERAL_LOCATIONDETAILS.getStore())); + } catch (JSONException e) { + e.printStackTrace(); + } + + try { + result.put(GetWayPointsResponse.KEY_WAY_POINTS, jsonArray); + } catch (JSONException e) { + e.printStackTrace(); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<LocationDetails> list = ((OnWayPointChange) msg).getWayPoints(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_LOCATIONDETAILS, list.get(0)); + assertEquals(Test.MATCH, Test.GENERAL_LOCATIONDETAILS, list.get(1)); + + // Invalid/Null Tests + OnWayPointChange msg = new OnWayPointChange(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getWayPoints()); + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java new file mode 100644 index 000000000..f4864a52d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddCommandTests.java @@ -0,0 +1,137 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AddCommand; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.MenuParams; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AddCommand} + */ +public class AddCommandTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + AddCommand msg = new AddCommand(); + + msg.setCmdIcon(Test.GENERAL_IMAGE); + msg.setMenuParams(Test.GENERAL_MENUPARAMS); + msg.setVrCommands(Test.GENERAL_STRING_LIST); + msg.setCmdID(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.ADD_COMMAND.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(AddCommand.KEY_CMD_ICON, Test.JSON_IMAGE); + result.put(AddCommand.KEY_MENU_PARAMS, Test.JSON_MENUPARAMS); + result.put(AddCommand.KEY_VR_COMMANDS, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + result.put(AddCommand.KEY_CMD_ID, Test.GENERAL_INT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int testCmdId = ( (AddCommand) msg ).getCmdID(); + Image testImage = ( (AddCommand) msg ).getCmdIcon(); + MenuParams testMenuParams = ( (AddCommand) msg ).getMenuParams(); + List<String> testVrCommands = ( (AddCommand) msg ).getVrCommands(); + + // Valid Tests + assertNotNull(Test.NOT_NULL, testMenuParams); + assertNotNull(Test.NOT_NULL, testImage); + assertNotNull(Test.NOT_NULL, testVrCommands); + + assertEquals(Test.MATCH, Test.GENERAL_INT, testCmdId); + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.size(), testVrCommands.size()); + + assertTrue(Test.TRUE, Validator.validateMenuParams(Test.GENERAL_MENUPARAMS, testMenuParams)); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, testImage)); + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, testVrCommands)); + + // Invalid/Null Tests + AddCommand msg = new AddCommand(); + assertNotNull(Test.NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getCmdIcon()); + assertNull(Test.NULL, msg.getCmdID()); + assertNull(Test.NULL, msg.getMenuParams()); + assertNull(Test.NULL, msg.getVrCommands()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + AddCommand cmd = new AddCommand(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + List<String> vrCommandsList = JsonUtils.readStringListFromJsonObject(parameters, AddCommand.KEY_VR_COMMANDS); + List<String> testCommandsList = cmd.getVrCommands(); + assertEquals(Test.MATCH, vrCommandsList.size(), testCommandsList.size()); + assertTrue(Test.TRUE, Validator.validateStringList(vrCommandsList, testCommandsList)); + + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AddCommand.KEY_CMD_ID), cmd.getCmdID()); + + JSONObject menuParams = JsonUtils.readJsonObjectFromJsonObject(parameters, AddCommand.KEY_MENU_PARAMS); + MenuParams referenceMenuParams = new MenuParams(JsonRPCMarshaller.deserializeJSONObject(menuParams)); + assertTrue(Test.TRUE, Validator.validateMenuParams(referenceMenuParams, cmd.getMenuParams())); + + JSONObject cmdIcon = JsonUtils.readJsonObjectFromJsonObject(parameters, AddCommand.KEY_CMD_ICON); + Image referenceCmdIcon = new Image(JsonRPCMarshaller.deserializeJSONObject(cmdIcon)); + assertTrue(Test.TRUE, Validator.validateImage(referenceCmdIcon, cmd.getCmdIcon())); + + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddSubmenuTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddSubmenuTests.java new file mode 100644 index 000000000..6e73121f1 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AddSubmenuTests.java @@ -0,0 +1,122 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AddSubMenu; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.AddSubMenu} + */ +public class AddSubmenuTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + AddSubMenu msg = new AddSubMenu(); + + msg.setMenuID(Test.GENERAL_INT); + msg.setMenuName(Test.GENERAL_STRING); + msg.setPosition(Test.GENERAL_INT); + msg.setMenuIcon(Test.GENERAL_IMAGE); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.ADD_SUB_MENU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(AddSubMenu.KEY_MENU_ID, Test.GENERAL_INT); + result.put(AddSubMenu.KEY_MENU_NAME, Test.GENERAL_STRING); + result.put(AddSubMenu.KEY_POSITION, Test.GENERAL_INT); + result.put(AddSubMenu.KEY_MENU_ICON, Test.JSON_IMAGE); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int testMenuId = ( (AddSubMenu) msg ).getMenuID(); + int testPosition = ( (AddSubMenu) msg ).getPosition(); + String testMenuName = ( (AddSubMenu) msg ).getMenuName(); + Image testMenuIcon = ( (AddSubMenu) msg ).getMenuIcon(); + + // Valid Tests + assertEquals("Menu ID didn't match input menu ID.", Test.GENERAL_INT, testMenuId); + assertEquals("Menu name didn't match input menu name.", Test.GENERAL_STRING, testMenuName); + assertEquals("Position didn't match input position.", Test.GENERAL_INT, testPosition); + assertTrue("Menu icon didn't match input icon.", Validator.validateImage(Test.GENERAL_IMAGE, testMenuIcon)); + + + // Invalid/Null Tests + AddSubMenu msg = new AddSubMenu(); + assertNotNull("Null object creation failed.", msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getMenuID()); + assertNull(Test.NULL, msg.getMenuName()); + assertNull(Test.NULL, msg.getPosition()); + assertNull(Test.NULL, msg.getMenuIcon()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + AddSubMenu cmd = new AddSubMenu(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AddSubMenu.KEY_MENU_ID), cmd.getMenuID()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AddSubMenu.KEY_POSITION), cmd.getPosition()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, AddSubMenu.KEY_MENU_NAME), cmd.getMenuName()); + + JSONObject menuIcon = JsonUtils.readJsonObjectFromJsonObject(parameters, AddSubMenu.KEY_MENU_ICON); + Image referenceMenuIcon = new Image(JsonRPCMarshaller.deserializeJSONObject(menuIcon)); + assertTrue(Test.TRUE, Validator.validateImage(referenceMenuIcon, cmd.getMenuIcon())); + } 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/requests/AlertManeuverTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AlertManeuverTests.java new file mode 100644 index 000000000..83d8e1835 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AlertManeuverTests.java @@ -0,0 +1,123 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AlertManeuver; +import com.smartdevicelink.proxy.rpc.SoftButton; +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AlertManeuver} + */ +public class AlertManeuverTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + AlertManeuver msg = new AlertManeuver(); + + msg.setTtsChunks(Test.GENERAL_TTSCHUNK_LIST); + msg.setSoftButtons(Test.GENERAL_SOFTBUTTON_LIST); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.ALERT_MANEUVER.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(AlertManeuver.KEY_TTS_CHUNKS, Test.JSON_TTSCHUNKS); + result.put(AlertManeuver.KEY_SOFT_BUTTONS, Test.JSON_SOFTBUTTONS); + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<TTSChunk> testTtsChunks = ( (AlertManeuver) msg ).getTtsChunks(); + List<SoftButton> testSoftButtons = ( (AlertManeuver) msg ).getSoftButtons(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateSoftButtons(Test.GENERAL_SOFTBUTTON_LIST, testSoftButtons)); + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, testTtsChunks)); + + // Invalid/Null Tests + AlertManeuver msg = new AlertManeuver(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getTtsChunks()); + assertNull(Test.NULL, msg.getSoftButtons()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + AlertManeuver cmd = new AlertManeuver(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + JSONArray ttsChunkArray = JsonUtils.readJsonArrayFromJsonObject(parameters, AlertManeuver.KEY_TTS_CHUNKS); + + List<TTSChunk> ttsChunkList = new ArrayList<TTSChunk>(); + for (int index = 0; index < ttsChunkArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)ttsChunkArray.get(index))); + ttsChunkList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(ttsChunkList, cmd.getTtsChunks())); + + JSONArray softButtonArray = JsonUtils.readJsonArrayFromJsonObject(parameters, AlertManeuver.KEY_SOFT_BUTTONS); + List<SoftButton> softButtonList = new ArrayList<SoftButton>(); + for (int index = 0; index < softButtonArray.length(); index++) { + SoftButton chunk = new SoftButton(JsonRPCMarshaller.deserializeJSONObject((JSONObject)softButtonArray.get(index))); + softButtonList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateSoftButtons(softButtonList, cmd.getSoftButtons())); + } 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/requests/AlertTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AlertTests.java new file mode 100644 index 000000000..21a33aac0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/AlertTests.java @@ -0,0 +1,158 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Alert; +import com.smartdevicelink.proxy.rpc.SoftButton; +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.Alert} + */ +public class AlertTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + Alert msg = new Alert(); + + msg.setDuration(Test.GENERAL_INT); + msg.setAlertText1(Test.GENERAL_STRING); + msg.setAlertText2(Test.GENERAL_STRING); + msg.setAlertText3(Test.GENERAL_STRING); + msg.setPlayTone(Test.GENERAL_BOOLEAN); + msg.setProgressIndicator(Test.GENERAL_BOOLEAN); + msg.setTtsChunks(Test.GENERAL_TTSCHUNK_LIST); + msg.setSoftButtons(Test.GENERAL_SOFTBUTTON_LIST); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.ALERT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(Alert.KEY_DURATION, Test.GENERAL_INT); + result.put(Alert.KEY_ALERT_TEXT_1, Test.GENERAL_STRING); + result.put(Alert.KEY_ALERT_TEXT_2, Test.GENERAL_STRING); + result.put(Alert.KEY_ALERT_TEXT_3, Test.GENERAL_STRING); + result.put(Alert.KEY_PLAY_TONE, Test.GENERAL_BOOLEAN); + result.put(Alert.KEY_PROGRESS_INDICATOR, Test.GENERAL_BOOLEAN); + result.put(Alert.KEY_TTS_CHUNKS, Test.JSON_TTSCHUNKS); + result.put(Alert.KEY_SOFT_BUTTONS, Test.JSON_SOFTBUTTONS); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int testDuration = ( (Alert) msg ).getDuration(); + String testAlertText1 = ( (Alert) msg ).getAlertText1(); + String testAlertText2 = ( (Alert) msg ).getAlertText2(); + String testAlertText3 = ( (Alert) msg ).getAlertText3(); + boolean testPlayTone = ( (Alert) msg ).getPlayTone(); + boolean testProgressIndicator = ( (Alert) msg ).getProgressIndicator(); + List<TTSChunk> testTtsChunks = ( (Alert) msg ).getTtsChunks(); + List<SoftButton> testSoftButtons = ( (Alert) msg ).getSoftButtons(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, testDuration); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testAlertText1); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testAlertText2); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testAlertText3); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testPlayTone); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testProgressIndicator); + assertTrue(Test.TRUE, Validator.validateSoftButtons(Test.GENERAL_SOFTBUTTON_LIST, testSoftButtons)); + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, testTtsChunks)); + + // Invalid/Null Tests + Alert msg = new Alert(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAlertText1()); + assertNull(Test.NULL, msg.getAlertText2()); + assertNull(Test.NULL, msg.getAlertText3()); + assertNull(Test.NULL, msg.getDuration()); + assertNull(Test.NULL, msg.getPlayTone()); + assertNull(Test.NULL, msg.getProgressIndicator()); + assertNull(Test.NULL, msg.getTtsChunks()); + assertNull(Test.NULL, msg.getSoftButtons()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + Alert cmd = new Alert(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, Alert.KEY_PLAY_TONE), cmd.getPlayTone()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, Alert.KEY_DURATION), cmd.getDuration()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Alert.KEY_ALERT_TEXT_1), cmd.getAlertText1()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Alert.KEY_ALERT_TEXT_2), cmd.getAlertText2()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Alert.KEY_ALERT_TEXT_3), cmd.getAlertText3()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, Alert.KEY_PROGRESS_INDICATOR), cmd.getProgressIndicator()); + + JSONArray ttsChunkArray = JsonUtils.readJsonArrayFromJsonObject(parameters, Alert.KEY_TTS_CHUNKS); + List<TTSChunk> ttsChunkList = new ArrayList<TTSChunk>(); + for (int index = 0; index < ttsChunkArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)ttsChunkArray.get(index)) ); + ttsChunkList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(ttsChunkList, cmd.getTtsChunks())); + + JSONArray softButtonArray = JsonUtils.readJsonArrayFromJsonObject(parameters, Alert.KEY_SOFT_BUTTONS); + List<SoftButton> softButtonList = new ArrayList<SoftButton>(); + for (int index = 0; index < softButtonArray.length(); index++) { + SoftButton chunk = new SoftButton(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)softButtonArray.get(index)) ); + softButtonList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateSoftButtons(softButtonList, cmd.getSoftButtons())); + } 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/requests/ButtonPressTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ButtonPressTests.java new file mode 100644 index 000000000..f16a3a87c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ButtonPressTests.java @@ -0,0 +1,113 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ButtonPress; +import com.smartdevicelink.proxy.rpc.enums.ButtonName; +import com.smartdevicelink.proxy.rpc.enums.ButtonPressMode; +import com.smartdevicelink.proxy.rpc.enums.ModuleType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ButtonPress} + */ +public class ButtonPressTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + ButtonPress msg = new ButtonPress(); + + msg.setModuleType(Test.GENERAL_MODULETYPE); + msg.setButtonPressMode(Test.GENERAL_BUTTONPRESSMODE); + msg.setButtonName(Test.GENERAL_BUTTONNAME); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.BUTTON_PRESS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(ButtonPress.KEY_MODULE_TYPE, Test.GENERAL_MODULETYPE); + result.put(ButtonPress.KEY_BUTTON_NAME, Test.GENERAL_BUTTONNAME); + result.put(ButtonPress.KEY_BUTTON_PRESS_MODE, Test.GENERAL_BUTTONPRESSMODE); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ModuleType testModuleType = ( (ButtonPress) msg ).getModuleType(); + ButtonName testButtonName = ( (ButtonPress) msg ).getButtonName(); + ButtonPressMode testButtonPressMode = ( (ButtonPress) msg ).getButtonPressMode(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, testModuleType); + assertEquals(Test.MATCH, Test.GENERAL_BUTTONNAME, testButtonName); + assertEquals(Test.MATCH, Test.GENERAL_BUTTONPRESSMODE, testButtonPressMode); + + // Invalid/Null Tests + ButtonPress msg = new ButtonPress(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getModuleType()); + assertNull(Test.NULL, msg.getButtonName()); + assertNull(Test.NULL, msg.getButtonPressMode()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ButtonPress cmd = new ButtonPress(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, ButtonPress.KEY_MODULE_TYPE).toString(), cmd.getModuleType().toString()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, ButtonPress.KEY_BUTTON_NAME).toString(), cmd.getButtonName().toString()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, ButtonPress.KEY_BUTTON_PRESS_MODE).toString(), cmd.getButtonPressMode().toString()); + }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/requests/ChangeRegistrationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ChangeRegistrationTests.java new file mode 100644 index 000000000..37ae9e6f9 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ChangeRegistrationTests.java @@ -0,0 +1,104 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ChangeRegistration; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ChangeRegistration} + */ +public class ChangeRegistrationTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + ChangeRegistration msg = new ChangeRegistration(); + + msg.setLanguage(Test.GENERAL_LANGUAGE); + msg.setHmiDisplayLanguage(Test.GENERAL_LANGUAGE); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.CHANGE_REGISTRATION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(ChangeRegistration.KEY_LANGUAGE, Test.GENERAL_LANGUAGE); + result.put(ChangeRegistration.KEY_HMI_DISPLAY_LANGUAGE, Test.GENERAL_LANGUAGE); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Language testLanguage = ( (ChangeRegistration) msg ).getLanguage(); + Language testHmiLanguage = ( (ChangeRegistration) msg ).getHmiDisplayLanguage(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, testLanguage); + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, testHmiLanguage); + + // Invalid/Null Tests + ChangeRegistration msg = new ChangeRegistration(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getLanguage()); + assertNull(Test.NULL, msg.getHmiDisplayLanguage()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ChangeRegistration cmd = new ChangeRegistration(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, ChangeRegistration.KEY_LANGUAGE), cmd.getLanguage().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, ChangeRegistration.KEY_HMI_DISPLAY_LANGUAGE), cmd.getHmiDisplayLanguage().toString()); + } 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/requests/CreateInteractionChoiceSetTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/CreateInteractionChoiceSetTests.java new file mode 100644 index 000000000..168666dcb --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/CreateInteractionChoiceSetTests.java @@ -0,0 +1,115 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Choice; +import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSet; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.CreateInteractionChoiceSet} + */ +public class CreateInteractionChoiceSetTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + CreateInteractionChoiceSet msg = new CreateInteractionChoiceSet(); + + msg.setInteractionChoiceSetID(Test.GENERAL_INT); + msg.setChoiceSet(Test.GENERAL_CHOICE_LIST); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.CREATE_INTERACTION_CHOICE_SET.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(CreateInteractionChoiceSet.KEY_INTERACTION_CHOICE_SET_ID, Test.GENERAL_INT); + result.put(CreateInteractionChoiceSet.KEY_CHOICE_SET, Test.JSON_CHOICES); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int testCmdId = ( (CreateInteractionChoiceSet) msg ).getInteractionChoiceSetID(); + List<Choice> testChoices = ( (CreateInteractionChoiceSet) msg ).getChoiceSet(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, testCmdId); + assertEquals(Test.MATCH, Test.GENERAL_CHOICE_LIST.size(), testChoices.size()); + for(int i = 0; i < testChoices.size(); i++){ + assertTrue(Test.TRUE, Validator.validateChoice(Test.GENERAL_CHOICE_LIST.get(i), testChoices.get(i))); + } + + // Invalid/Null Tests + CreateInteractionChoiceSet msg = new CreateInteractionChoiceSet(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getChoiceSet()); + assertNull(Test.NULL, msg.getInteractionChoiceSetID()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + CreateInteractionChoiceSet cmd = new CreateInteractionChoiceSet(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, CreateInteractionChoiceSet.KEY_INTERACTION_CHOICE_SET_ID), cmd.getInteractionChoiceSetID()); + + JSONArray choiceSetArray = JsonUtils.readJsonArrayFromJsonObject(parameters, CreateInteractionChoiceSet.KEY_CHOICE_SET); + for (int index = 0; index < choiceSetArray.length(); index++) { + Choice chunk = new Choice(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)choiceSetArray.get(index)) ); + assertTrue(Test.TRUE, Validator.validateChoice(chunk, cmd.getChoiceSet().get(index)) ); + } + } 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/requests/DeleteCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DeleteCommandTests.java new file mode 100644 index 000000000..43af829e4 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DeleteCommandTests.java @@ -0,0 +1,98 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeleteCommand; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeleteCommand} + */ +public class DeleteCommandTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + DeleteCommand msg = new DeleteCommand(); + + msg.setCmdID(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.DELETE_COMMAND.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(DeleteCommand.KEY_CMD_ID, Test.GENERAL_INT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int cmdId = ( (DeleteCommand) msg ).getCmdID(); + + // Valid Tests + assertEquals("Command ID didn't match input command ID.", Test.GENERAL_INT, cmdId); + + // Invalid/Null Tests + DeleteCommand msg = new DeleteCommand(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.MATCH, msg.getCmdID()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DeleteCommand cmd = new DeleteCommand(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, DeleteCommand.KEY_CMD_ID), cmd.getCmdID()); + } + 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/requests/DeleteFileTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DeleteFileTests.java new file mode 100644 index 000000000..8d8300e0c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DeleteFileTests.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeleteFile; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeleteFile} + */ +public class DeleteFileTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + DeleteFile msg = new DeleteFile(); + + msg.setSdlFileName(Test.GENERAL_STRING); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.DELETE_FILE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(DeleteFile.KEY_SDL_FILE_NAME, Test.GENERAL_STRING); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String testFilename = ( (DeleteFile) msg ).getSdlFileName(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, testFilename); + + // Invalid/Null Tests + DeleteFile msg = new DeleteFile(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSdlFileName()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DeleteFile cmd = new DeleteFile(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, DeleteFile.KEY_SDL_FILE_NAME), cmd.getSdlFileName()); + } 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/requests/DeleteInteractionChoiceSetTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DeleteInteractionChoiceSetTests.java new file mode 100644 index 000000000..b9b1bbc15 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DeleteInteractionChoiceSetTests.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeleteInteractionChoiceSet} + */ +public class DeleteInteractionChoiceSetTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + DeleteInteractionChoiceSet msg = new DeleteInteractionChoiceSet(); + + msg.setInteractionChoiceSetID(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.DELETE_INTERACTION_CHOICE_SET.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(DeleteInteractionChoiceSet.KEY_INTERACTION_CHOICE_SET_ID, Test.GENERAL_INT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int testChoiceSetId = ( (DeleteInteractionChoiceSet) msg ).getInteractionChoiceSetID(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, testChoiceSetId); + + // Invalid/Null Tests + DeleteInteractionChoiceSet msg = new DeleteInteractionChoiceSet(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getInteractionChoiceSetID()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DeleteInteractionChoiceSet cmd = new DeleteInteractionChoiceSet(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, DeleteInteractionChoiceSet.KEY_INTERACTION_CHOICE_SET_ID), cmd.getInteractionChoiceSetID()); + } 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/requests/DeleteSubMenuTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DeleteSubMenuTests.java new file mode 100644 index 000000000..db9e06e12 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DeleteSubMenuTests.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeleteSubMenu; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeleteSubMenu} + */ +public class DeleteSubMenuTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + DeleteSubMenu msg = new DeleteSubMenu(); + + msg.setMenuID(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.DELETE_SUB_MENU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(DeleteSubMenu.KEY_MENU_ID, Test.GENERAL_INT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int testMenuId = ( (DeleteSubMenu) msg ).getMenuID(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, testMenuId); + + // Invalid/Null Tests + DeleteSubMenu msg = new DeleteSubMenu(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getMenuID()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DeleteSubMenu cmd = new DeleteSubMenu(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, DeleteSubMenu.KEY_MENU_ID), cmd.getMenuID()); + } 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/requests/DiagnosticMessageTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DiagnosticMessageTests.java new file mode 100644 index 000000000..4ee758c3d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DiagnosticMessageTests.java @@ -0,0 +1,119 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DiagnosticMessage; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DiagnosticMessage} + */ +public class DiagnosticMessageTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + DiagnosticMessage msg = new DiagnosticMessage(); + + msg.setMessageLength(Test.GENERAL_INT); + msg.setTargetID(Test.GENERAL_INT); + msg.setMessageData(Test.GENERAL_INTEGER_LIST); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.DIAGNOSTIC_MESSAGE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(DiagnosticMessage.KEY_TARGET_ID, Test.GENERAL_INT); + result.put(DiagnosticMessage.KEY_MESSAGE_LENGTH, Test.GENERAL_INT); + result.put(DiagnosticMessage.KEY_MESSAGE_DATA, JsonUtils.createJsonArray(Test.GENERAL_INTEGER_LIST)); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int testTargetId = ( (DiagnosticMessage) msg ).getTargetID(); + int testMessageLength = ( (DiagnosticMessage) msg ).getMessageLength(); + List<Integer> testMessageData = ( (DiagnosticMessage) msg ).getMessageData(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, testTargetId); + assertEquals(Test.MATCH, Test.GENERAL_INT, testMessageLength); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER_LIST.size(), testMessageData.size()); + + for(int i = 0; i < testMessageData.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_INTEGER_LIST.get(i), testMessageData.get(i)); + } + + // Invalid/Null Tests + DiagnosticMessage msg = new DiagnosticMessage(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getTargetID()); + assertNull(Test.NULL, msg.getMessageLength()); + assertNull(Test.NULL, msg.getMessageData()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DiagnosticMessage cmd = new DiagnosticMessage(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, DiagnosticMessage.KEY_TARGET_ID), cmd.getTargetID()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, DiagnosticMessage.KEY_MESSAGE_LENGTH), cmd.getMessageLength()); + + List<Integer> messageDataList = JsonUtils.readIntegerListFromJsonObject(parameters, DiagnosticMessage.KEY_MESSAGE_DATA); + List<Integer> testDataList = cmd.getMessageData(); + assertEquals(Test.MATCH, messageDataList.size(), testDataList.size()); + assertTrue(Test.TRUE, Validator.validateIntegerList(messageDataList, testDataList)); + } 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/requests/DialNumberTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DialNumberTests.java new file mode 100644 index 000000000..40a8d432f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/DialNumberTests.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DialNumber; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * Created by austinkirk on 6/6/17. + */ + +public class DialNumberTests extends BaseRpcTests { + + private final String TEST_NUMBER = "5558675309"; + + @Override + protected RPCMessage createMessage(){ + DialNumber msg = new DialNumber(); + + msg.setNumber(TEST_NUMBER); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.DIAL_NUMBER.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(DialNumber.KEY_NUMBER, TEST_NUMBER); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String testNumber = ((DialNumber) msg).getNumber(); + + // Valid Tests + assertEquals(Test.MATCH, TEST_NUMBER, testNumber); + // Invalid/Null Tests + DialNumber msg = new DialNumber(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getNumber()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DialNumber cmd = new DialNumber(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, DialNumber.KEY_NUMBER), cmd.getNumber()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/EndAudioPassThruTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/EndAudioPassThruTests.java new file mode 100644 index 000000000..448f592ed --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/EndAudioPassThruTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.EndAudioPassThru; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.EndAudioPassThru} + */ +public class EndAudioPassThruTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new EndAudioPassThru(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.END_AUDIO_PASS_THRU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + EndAudioPassThru msg = new EndAudioPassThru(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + EndAudioPassThru cmd = new EndAudioPassThru(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } 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/requests/GetAppServiceDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetAppServiceDataTests.java new file mode 100644 index 000000000..abda43557 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetAppServiceDataTests.java @@ -0,0 +1,107 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetAppServiceData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +public class GetAppServiceDataTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + GetAppServiceData msg = new GetAppServiceData(); + msg.setServiceType(Test.GENERAL_STRING); + msg.setSubscribe(Test.GENERAL_BOOLEAN); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.GET_APP_SERVICE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(GetAppServiceData.KEY_SERVICE_TYPE, Test.GENERAL_STRING); + result.put(GetAppServiceData.KEY_SUBSCRIBE, Test.GENERAL_BOOLEAN); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String serviceType = ( (GetAppServiceData) msg ).getServiceType(); + boolean subscribe = ( (GetAppServiceData) msg ).getSubscribe(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, serviceType); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, subscribe); + + // Invalid/Null Tests + GetAppServiceData msg = new GetAppServiceData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(msg.getServiceType()); + assertNull(msg.getSubscribe()); + } + + /** + * Tests constructor with required params + */ + public void testRequiredParamsConstructor () { + + GetAppServiceData msg = new GetAppServiceData(Test.GENERAL_STRING); + assertNotNull(Test.NOT_NULL, msg); + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, msg.getServiceType()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetAppServiceData cmd = new GetAppServiceData(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetAppServiceData.KEY_SUBSCRIBE), cmd.getSubscribe()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetAppServiceData.KEY_SERVICE_TYPE).toString(), cmd.getServiceType().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetCloudAppPropertiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetCloudAppPropertiesTests.java new file mode 100644 index 000000000..423e53add --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetCloudAppPropertiesTests.java @@ -0,0 +1,46 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetCloudAppProperties; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONException; +import org.json.JSONObject; + +public class GetCloudAppPropertiesTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + GetCloudAppProperties msg = new GetCloudAppProperties(); + + msg.setAppId(Test.GENERAL_STRING); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_CLOUD_APP_PROPERTIES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetCloudAppProperties.KEY_APP_ID, Test.GENERAL_STRING); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetDTCsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetDTCsTests.java new file mode 100644 index 000000000..1d5cbcad1 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetDTCsTests.java @@ -0,0 +1,105 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetDTCs; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.GetDTCs} + */ +public class GetDTCsTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + GetDTCs msg = new GetDTCs(); + + msg.setEcuName(Test.GENERAL_INT); + msg.setDtcMask(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_DTCS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetDTCs.KEY_ECU_NAME, Test.GENERAL_INT); + result.put(GetDTCs.KEY_DTC_MASK, Test.GENERAL_INT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int testDtcMask = ( (GetDTCs) msg ).getDtcMask(); + int testEcuName = ( (GetDTCs) msg ).getEcuName(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, testDtcMask); + assertEquals(Test.MATCH, Test.GENERAL_INT, testEcuName); + + // Invalid/Null Tests + GetDTCs msg = new GetDTCs(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getEcuName()); + assertNull(Test.NULL, msg.getDtcMask()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetDTCs cmd = new GetDTCs(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetDTCs.KEY_DTC_MASK), cmd.getDtcMask()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetDTCs.KEY_ECU_NAME), cmd.getEcuName()); + } + 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/requests/GetFileTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetFileTests.java new file mode 100644 index 000000000..48214373d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetFileTests.java @@ -0,0 +1,132 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetFile; +import com.smartdevicelink.proxy.rpc.enums.FileType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + + +public class GetFileTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + GetFile msg = new GetFile(); + + msg.setFileName(Test.GENERAL_STRING); + msg.setAppServiceId(Test.GENERAL_STRING); + msg.setFileType(Test.GENERAL_FILETYPE); + msg.setOffset(Test.GENERAL_INT); + msg.setLength(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.GET_FILE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(GetFile.KEY_FILE_NAME, Test.GENERAL_STRING); + result.put(GetFile.KEY_APP_SERVICE_ID, Test.GENERAL_STRING); + result.put(GetFile.KEY_FILE_TYPE, Test.GENERAL_FILETYPE); + result.put(GetFile.KEY_OFFSET, Test.GENERAL_INTEGER); + result.put(GetFile.KEY_LENGTH, Test.GENERAL_INTEGER); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String fileName = ( (GetFile) msg ).getFileName(); + String appServiceId = ( (GetFile) msg ).getAppServiceId(); + FileType fileType = ( (GetFile) msg ).getFileType(); + Integer offset = ( (GetFile) msg ).getOffset(); + Integer length = ( (GetFile) msg ).getLength(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, fileName); + assertEquals(Test.MATCH, Test.GENERAL_STRING, appServiceId); + assertEquals(Test.MATCH, Test.GENERAL_FILETYPE, fileType); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, offset); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, length); + + // Invalid/Null Tests + GetFile msg = new GetFile(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getFileName()); + assertNull(Test.NULL, msg.getAppServiceId()); + assertNull(Test.NULL, msg.getFileType()); + assertNull(Test.NULL, msg.getOffset()); + assertNull(Test.NULL, msg.getLength()); + } + + /** + * Tests constructor with required params + */ + public void testRequiredParamsConstructor () { + + GetFile msg = new GetFile(Test.GENERAL_STRING); + assertNotNull(Test.NOT_NULL, msg); + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, msg.getFileName()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetFile cmd = new GetFile(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetFile.KEY_APP_SERVICE_ID), cmd.getAppServiceId()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetFile.KEY_FILE_NAME), cmd.getFileName()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetFile.KEY_FILE_TYPE).toString(), cmd.getFileType().toString()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetFile.KEY_LENGTH), cmd.getLength()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetFile.KEY_OFFSET), cmd.getOffset()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataTests.java new file mode 100644 index 000000000..5a08d4266 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetInteriorVehicleDataTests.java @@ -0,0 +1,105 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleData; +import com.smartdevicelink.proxy.rpc.enums.ModuleType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.GetInteriorVehicleData} + */ +public class GetInteriorVehicleDataTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + GetInteriorVehicleData msg = new GetInteriorVehicleData(); + + msg.setModuleType(Test.GENERAL_MODULETYPE); + msg.setSubscribe(Test.GENERAL_BOOLEAN); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_INTERIOR_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetInteriorVehicleData.KEY_MODULE_TYPE, Test.GENERAL_MODULETYPE); + result.put(GetInteriorVehicleData.KEY_SUBSCRIBE, Test.GENERAL_BOOLEAN); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ModuleType testModuleType = ( (GetInteriorVehicleData) msg ).getModuleType(); + boolean testSubscribed = ( (GetInteriorVehicleData) msg ).getSubscribe(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_MODULETYPE, testModuleType); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testSubscribed); + + // Invalid/Null Tests + GetInteriorVehicleData msg = new GetInteriorVehicleData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getModuleType()); + assertNull(Test.NULL, msg.getSubscribe()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetInteriorVehicleData cmd = new GetInteriorVehicleData(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleData.KEY_MODULE_TYPE).toString(), cmd.getModuleType().toString()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleData.KEY_SUBSCRIBE), cmd.getSubscribe()); + }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/requests/GetSystemCapabilityTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetSystemCapabilityTests.java new file mode 100644 index 000000000..290a291d1 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetSystemCapabilityTests.java @@ -0,0 +1,101 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetSystemCapability; +import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +public class GetSystemCapabilityTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + GetSystemCapability msg = new GetSystemCapability(); + + msg.setSystemCapabilityType(Test.GENERAL_SYSTEMCAPABILITYTYPE); + msg.setSubscribe(Test.GENERAL_BOOLEAN); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_SYSTEM_CAPABILITY.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetSystemCapability.KEY_SYSTEM_CAPABILITY_TYPE, Test.GENERAL_SYSTEMCAPABILITYTYPE); + result.put(GetSystemCapability.KEY_SUBSCRIBE, Test.GENERAL_BOOLEAN); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + SystemCapabilityType testType = ( (GetSystemCapability) msg ).getSystemCapabilityType(); + boolean testSubscribe = ( (GetSystemCapability) msg ).getSubscribe(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_SYSTEMCAPABILITYTYPE, testType); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testSubscribe); + + // Invalid/Null Tests + GetSystemCapability msg = new GetSystemCapability(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSystemCapabilityType()); + assertNull(Test.NULL, msg.getSubscribe()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetSystemCapability cmd = new GetSystemCapability(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetSystemCapability.KEY_SYSTEM_CAPABILITY_TYPE).toString(), cmd.getSystemCapabilityType().toString()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetSystemCapability.KEY_SUBSCRIBE), cmd.getSubscribe()); + }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/requests/GetVehicleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetVehicleDataTests.java new file mode 100644 index 000000000..54f299fdf --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetVehicleDataTests.java @@ -0,0 +1,235 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetVehicleData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.GetVehicleData} + */ +public class GetVehicleDataTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + GetVehicleData msg = new GetVehicleData(); + + msg.setSpeed(Test.GENERAL_BOOLEAN); + msg.setRpm(Test.GENERAL_BOOLEAN); + msg.setExternalTemperature(Test.GENERAL_BOOLEAN); + msg.setFuelLevel(Test.GENERAL_BOOLEAN); + msg.setPrndl(Test.GENERAL_BOOLEAN); + msg.setTirePressure(Test.GENERAL_BOOLEAN); + msg.setEngineTorque(Test.GENERAL_BOOLEAN); + msg.setEngineOilLife(Test.GENERAL_BOOLEAN); + msg.setOdometer(Test.GENERAL_BOOLEAN); + msg.setGps(Test.GENERAL_BOOLEAN); + msg.setFuelLevelState(Test.GENERAL_BOOLEAN); + msg.setInstantFuelConsumption(Test.GENERAL_BOOLEAN); + msg.setVin(Test.GENERAL_BOOLEAN); + msg.setBeltStatus(Test.GENERAL_BOOLEAN); + msg.setBodyInformation(Test.GENERAL_BOOLEAN); + msg.setDeviceStatus(Test.GENERAL_BOOLEAN); + msg.setDriverBraking(Test.GENERAL_BOOLEAN); + msg.setWiperStatus(Test.GENERAL_BOOLEAN); + msg.setHeadLampStatus(Test.GENERAL_BOOLEAN); + msg.setAccPedalPosition(Test.GENERAL_BOOLEAN); + msg.setSteeringWheelAngle(Test.GENERAL_BOOLEAN); + msg.setECallInfo(Test.GENERAL_BOOLEAN); + msg.setAirbagStatus(Test.GENERAL_BOOLEAN); + msg.setEmergencyEvent(Test.GENERAL_BOOLEAN); + msg.setClusterModeStatus(Test.GENERAL_BOOLEAN); + msg.setMyKey(Test.GENERAL_BOOLEAN); + msg.setFuelRange(Test.GENERAL_BOOLEAN); + msg.setTurnSignal(Test.GENERAL_BOOLEAN); + msg.setElectronicParkBrakeStatus(Test.GENERAL_BOOLEAN); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetVehicleData.KEY_SPEED, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_RPM, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_EXTERNAL_TEMPERATURE, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_FUEL_LEVEL, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_PRNDL, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_TIRE_PRESSURE, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_ENGINE_TORQUE, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_ENGINE_OIL_LIFE, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_ODOMETER, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_GPS, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_FUEL_LEVEL_STATE, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_INSTANT_FUEL_CONSUMPTION, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_VIN, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_BELT_STATUS, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_BODY_INFORMATION, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_DEVICE_STATUS, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_DRIVER_BRAKING, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_WIPER_STATUS, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_HEAD_LAMP_STATUS, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_ACC_PEDAL_POSITION, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_STEERING_WHEEL_ANGLE, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_E_CALL_INFO, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_AIRBAG_STATUS, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_EMERGENCY_EVENT, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_CLUSTER_MODE_STATUS, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_MY_KEY, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_FUEL_RANGE, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_TURN_SIGNAL, Test.GENERAL_BOOLEAN); + result.put(GetVehicleData.KEY_ELECTRONIC_PARK_BRAKE_STATUS, Test.GENERAL_BOOLEAN); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Valid Tests + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getSpeed()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getRpm()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getExternalTemperature()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getFuelLevel()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getPrndl()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getTirePressure()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getEngineTorque()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getEngineOilLife()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getOdometer()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getGps()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getFuelLevelState()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getInstantFuelConsumption()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getVin()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getBeltStatus()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getBodyInformation()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getVin()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getDeviceStatus()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getDriverBraking()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getWiperStatus()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getHeadLampStatus()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getAccPedalPosition()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getSteeringWheelAngle()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getECallInfo()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getAirbagStatus()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getEmergencyEvent()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getClusterModeStatus()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getMyKey()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getFuelRange()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getTurnSignal()); + assertTrue(Test.TRUE, ( (GetVehicleData) msg ).getElectronicParkBrakeStatus()); + + // Invalid/Null Tests + GetVehicleData msg = new GetVehicleData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAccPedalPosition()); + assertNull(Test.NULL, msg.getAirbagStatus()); + assertNull(Test.NULL, msg.getBeltStatus()); + assertNull(Test.NULL, msg.getDriverBraking()); + assertNull(Test.NULL, msg.getFuelLevel()); + assertNull(Test.NULL, msg.getTirePressure()); + assertNull(Test.NULL, msg.getWiperStatus()); + assertNull(Test.NULL, msg.getGps()); + assertNull(Test.NULL, msg.getSpeed()); + assertNull(Test.NULL, msg.getRpm()); + assertNull(Test.NULL, msg.getFuelLevelState()); + assertNull(Test.NULL, msg.getInstantFuelConsumption()); + assertNull(Test.NULL, msg.getExternalTemperature()); + assertNull(Test.NULL, msg.getVin()); + assertNull(Test.NULL, msg.getPrndl()); + assertNull(Test.NULL, msg.getOdometer()); + assertNull(Test.NULL, msg.getBodyInformation()); + assertNull(Test.NULL, msg.getDeviceStatus()); + assertNull(Test.NULL, msg.getHeadLampStatus()); + assertNull(Test.NULL, msg.getEngineTorque()); + assertNull(Test.NULL, msg.getEngineOilLife()); + assertNull(Test.NULL, msg.getSteeringWheelAngle()); + assertNull(Test.NULL, msg.getECallInfo()); + assertNull(Test.NULL, msg.getEmergencyEvent()); + assertNull(Test.NULL, msg.getClusterModeStatus()); + assertNull(Test.NULL, msg.getMyKey()); + assertNull(Test.NULL, msg.getFuelRange()); + assertNull(Test.NULL, msg.getTurnSignal()); + assertNull(Test.NULL, msg.getElectronicParkBrakeStatus()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetVehicleData cmd = new GetVehicleData(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals("Command name doesn't match input name", JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals("Correlation ID doesn't match input ID", JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_SPEED), cmd.getSpeed()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_RPM), cmd.getRpm()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_EXTERNAL_TEMPERATURE), cmd.getExternalTemperature()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_FUEL_LEVEL), cmd.getFuelLevel()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_VIN), cmd.getVin()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_PRNDL), cmd.getPrndl()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_TIRE_PRESSURE), cmd.getTirePressure()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_ENGINE_TORQUE), cmd.getEngineTorque()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_ENGINE_OIL_LIFE), cmd.getEngineOilLife()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_ODOMETER), cmd.getOdometer()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_GPS), cmd.getGps()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_FUEL_LEVEL_STATE), cmd.getFuelLevelState()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_INSTANT_FUEL_CONSUMPTION), cmd.getInstantFuelConsumption()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_BELT_STATUS), cmd.getBeltStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_BODY_INFORMATION), cmd.getBodyInformation()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_DEVICE_STATUS), cmd.getDeviceStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_DRIVER_BRAKING), cmd.getDriverBraking()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_WIPER_STATUS), cmd.getWiperStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_HEAD_LAMP_STATUS), cmd.getHeadLampStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_ACC_PEDAL_POSITION), cmd.getAccPedalPosition()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_STEERING_WHEEL_ANGLE), cmd.getSteeringWheelAngle()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_E_CALL_INFO), cmd.getECallInfo()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_AIRBAG_STATUS), cmd.getAirbagStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_EMERGENCY_EVENT), cmd.getEmergencyEvent()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_CLUSTER_MODE_STATUS), cmd.getClusterModeStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_MY_KEY), cmd.getMyKey()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_FUEL_RANGE), cmd.getFuelRange()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_TURN_SIGNAL), cmd.getTurnSignal()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, GetVehicleData.KEY_ELECTRONIC_PARK_BRAKE_STATUS), cmd.getElectronicParkBrakeStatus()); + } 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/requests/GetWayPointsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetWayPointsTests.java new file mode 100644 index 000000000..bf0531685 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/GetWayPointsTests.java @@ -0,0 +1,96 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetWayPoints; +import com.smartdevicelink.proxy.rpc.enums.WayPointType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * Created by austinkirk on 6/6/17. + */ + +public class GetWayPointsTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage(){ + GetWayPoints msg = new GetWayPoints(); + + msg.setWayPointType(WayPointType.DESTINATION); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_WAY_POINTS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetWayPoints.KEY_WAY_POINT_TYPE, WayPointType.DESTINATION); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + WayPointType testType = ( (GetWayPoints) msg ).getWayPointType(); + + // Valid Tests + assertEquals(Test.MATCH, WayPointType.DESTINATION, testType); + + // Invalid/Null Tests + GetWayPoints msg = new GetWayPoints(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getWayPointType()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetWayPoints cmd = new GetWayPoints(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, WayPointType.valueForString(JsonUtils.readStringFromJsonObject(parameters, GetWayPoints.KEY_WAY_POINT_TYPE)), cmd.getWayPointType()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ListFilesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ListFilesTests.java new file mode 100644 index 000000000..31d20bacf --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ListFilesTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ListFiles; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ListFiles} + */ +public class ListFilesTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new ListFiles(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.LIST_FILES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + ListFiles msg = new ListFiles(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ListFiles cmd = new ListFiles(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } 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/requests/PerformAppServiceInteractionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PerformAppServiceInteractionTests.java new file mode 100644 index 000000000..c5be9b14f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PerformAppServiceInteractionTests.java @@ -0,0 +1,128 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.PerformAppServiceInteraction; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + + +public class PerformAppServiceInteractionTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + PerformAppServiceInteraction msg = new PerformAppServiceInteraction(); + + msg.setServiceUri(Test.GENERAL_STRING); + msg.setAppServiceId(Test.GENERAL_STRING); + msg.setOriginApp(Test.GENERAL_STRING); + msg.setRequestServiceActive(Test.GENERAL_BOOLEAN); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.PERFORM_APP_SERVICES_INTERACTION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(PerformAppServiceInteraction.KEY_SERVICE_URI, Test.GENERAL_STRING); + result.put(PerformAppServiceInteraction.KEY_SERVICE_ID, Test.GENERAL_STRING); + result.put(PerformAppServiceInteraction.KEY_ORIGIN_APP, Test.GENERAL_STRING); + result.put(PerformAppServiceInteraction.KEY_REQUEST_SERVICE_ACTIVE, Test.GENERAL_BOOLEAN); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String serviceUri = ( (PerformAppServiceInteraction) msg ).getServiceUri(); + String appServiceId = ( (PerformAppServiceInteraction) msg ).getAppServiceId(); + String originApp = ( (PerformAppServiceInteraction) msg ).getOriginApp(); + boolean requestServiceActive = ( (PerformAppServiceInteraction) msg ).getRequestServiceActive(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, serviceUri); + assertEquals(Test.MATCH, Test.GENERAL_STRING, appServiceId); + assertEquals(Test.MATCH, Test.GENERAL_STRING, originApp); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, requestServiceActive); + + // Invalid/Null Tests + PerformAppServiceInteraction msg = new PerformAppServiceInteraction(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getServiceUri()); + assertNull(Test.NULL, msg.getAppServiceId()); + assertNull(Test.NULL, msg.getOriginApp()); + assertNull(Test.NULL, msg.getRequestServiceActive()); + } + + /** + * Tests constructor with required params + */ + public void testRequiredParamsConstructor () { + // test with param in constructor + PerformAppServiceInteraction msg = new PerformAppServiceInteraction(Test.GENERAL_STRING,Test.GENERAL_STRING,Test.GENERAL_STRING); + String serviceUri = msg.getServiceUri(); + String appServiceId = msg.getAppServiceId(); + String originApp = msg.getOriginApp(); + assertEquals(Test.MATCH, Test.GENERAL_STRING, serviceUri); + assertEquals(Test.MATCH, Test.GENERAL_STRING, appServiceId); + assertEquals(Test.MATCH, Test.GENERAL_STRING, originApp); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PerformAppServiceInteraction cmd = new PerformAppServiceInteraction(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAppServiceInteraction.KEY_SERVICE_ID), cmd.getAppServiceId()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAppServiceInteraction.KEY_SERVICE_URI), cmd.getServiceUri()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAppServiceInteraction.KEY_ORIGIN_APP), cmd.getOriginApp()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, PerformAppServiceInteraction.KEY_REQUEST_SERVICE_ACTIVE), cmd.getRequestServiceActive()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PerformAudioPassThruTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PerformAudioPassThruTests.java new file mode 100644 index 000000000..d3ecbdfeb --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PerformAudioPassThruTests.java @@ -0,0 +1,157 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.PerformAudioPassThru; +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.proxy.rpc.enums.AudioType; +import com.smartdevicelink.proxy.rpc.enums.BitsPerSample; +import com.smartdevicelink.proxy.rpc.enums.SamplingRate; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.PerformAudioPassThru} + */ +public class PerformAudioPassThruTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + PerformAudioPassThru msg = new PerformAudioPassThru(); + + msg.setInitialPrompt(Test.GENERAL_TTSCHUNK_LIST); + msg.setAudioPassThruDisplayText1(Test.GENERAL_STRING); + msg.setAudioPassThruDisplayText2(Test.GENERAL_STRING); + msg.setSamplingRate(Test.GENERAL_SAMPLINGRATE); + msg.setAudioType(Test.GENERAL_AUDIOTYPE); + msg.setBitsPerSample(Test.GENERAL_BITSPERSAMPLE); + msg.setMaxDuration(Test.GENERAL_INT); + msg.setMuteAudio(Test.GENERAL_BOOLEAN); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.PERFORM_AUDIO_PASS_THRU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(PerformAudioPassThru.KEY_AUDIO_PASS_THRU_DISPLAY_TEXT_1, Test.GENERAL_STRING); + result.put(PerformAudioPassThru.KEY_AUDIO_PASS_THRU_DISPLAY_TEXT_2, Test.GENERAL_STRING); + result.put(PerformAudioPassThru.KEY_MUTE_AUDIO, Test.GENERAL_BOOLEAN); + result.put(PerformAudioPassThru.KEY_MAX_DURATION, Test.GENERAL_INT); + result.put(PerformAudioPassThru.KEY_AUDIO_TYPE, Test.GENERAL_AUDIOTYPE); + result.put(PerformAudioPassThru.KEY_SAMPLING_RATE, Test.GENERAL_SAMPLINGRATE); + result.put(PerformAudioPassThru.KEY_BITS_PER_SAMPLE, Test.GENERAL_BITSPERSAMPLE); + result.put(PerformAudioPassThru.KEY_INITIAL_PROMPT, Test.JSON_TTSCHUNKS); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean testMuteAudio = ( (PerformAudioPassThru) msg ).getMuteAudio(); + int testMaxDuration = ( (PerformAudioPassThru) msg ).getMaxDuration(); + String testText2 = ( (PerformAudioPassThru) msg ).getAudioPassThruDisplayText2(); + String testText1 = ( (PerformAudioPassThru) msg ).getAudioPassThruDisplayText1(); + SamplingRate testSamplingRate = ( (PerformAudioPassThru) msg ).getSamplingRate(); + AudioType testAudioType = ( (PerformAudioPassThru) msg ).getAudioType(); + BitsPerSample testBitsPerSample = ( (PerformAudioPassThru) msg ).getBitsPerSample(); + List<TTSChunk> testInitialPrompt = ( (PerformAudioPassThru) msg ).getInitialPrompt(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_TTSCHUNK_LIST.size(), testInitialPrompt.size()); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testText1); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testText2); + assertEquals(Test.MATCH, Test.GENERAL_SAMPLINGRATE, testSamplingRate); + assertEquals(Test.MATCH, Test.GENERAL_BITSPERSAMPLE, testBitsPerSample); + assertEquals(Test.MATCH, Test.GENERAL_AUDIOTYPE, testAudioType); + assertEquals(Test.MATCH, Test.GENERAL_INT, testMaxDuration); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testMuteAudio); + for (int i = 0; i < Test.GENERAL_TTSCHUNK_LIST.size(); i++) { + assertEquals(Test.MATCH, Test.GENERAL_TTSCHUNK_LIST.get(i), testInitialPrompt.get(i)); + } + + // Invalid/Null Tests + PerformAudioPassThru msg = new PerformAudioPassThru(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getInitialPrompt()); + assertNull(Test.NULL, msg.getAudioPassThruDisplayText1()); + assertNull(Test.NULL, msg.getAudioPassThruDisplayText2()); + assertNull(Test.NULL, msg.getSamplingRate()); + assertNull(Test.NULL, msg.getBitsPerSample()); + assertNull(Test.NULL, msg.getAudioType()); + assertNull(Test.NULL, msg.getMaxDuration()); + assertNull(Test.NULL, msg.getMuteAudio()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PerformAudioPassThru cmd = new PerformAudioPassThru(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, PerformAudioPassThru.KEY_MAX_DURATION), (Integer)cmd.getMaxDuration()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAudioPassThru.KEY_AUDIO_PASS_THRU_DISPLAY_TEXT_1), cmd.getAudioPassThruDisplayText1()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAudioPassThru.KEY_AUDIO_PASS_THRU_DISPLAY_TEXT_2), cmd.getAudioPassThruDisplayText2()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, PerformAudioPassThru.KEY_MUTE_AUDIO), cmd.getMuteAudio()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAudioPassThru.KEY_SAMPLING_RATE), cmd.getSamplingRate().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAudioPassThru.KEY_AUDIO_TYPE), cmd.getAudioType().toString()); + + JSONArray ttsChunkArray = JsonUtils.readJsonArrayFromJsonObject(parameters, PerformAudioPassThru.KEY_INITIAL_PROMPT); + List<TTSChunk> ttsChunkList = new ArrayList<TTSChunk>(); + for (int index = 0; index < ttsChunkArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)ttsChunkArray.get(index)) ); + ttsChunkList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(ttsChunkList, cmd.getInitialPrompt())); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAudioPassThru.KEY_BITS_PER_SAMPLE), cmd.getBitsPerSample().toString()); + } 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/requests/PerformInteractionTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PerformInteractionTests.java new file mode 100644 index 000000000..9ea36f43f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PerformInteractionTests.java @@ -0,0 +1,187 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.PerformInteraction; +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.proxy.rpc.VrHelpItem; +import com.smartdevicelink.proxy.rpc.enums.InteractionMode; +import com.smartdevicelink.proxy.rpc.enums.LayoutMode; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.PerformInteraction} + */ +public class PerformInteractionTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + PerformInteraction msg = new PerformInteraction(); + + msg.setInitialPrompt(Test.GENERAL_TTSCHUNK_LIST); + msg.setHelpPrompt(Test.GENERAL_TTSCHUNK_LIST); + msg.setTimeoutPrompt(Test.GENERAL_TTSCHUNK_LIST); + msg.setVrHelp(Test.GENERAL_VRHELPITEM_LIST); + msg.setInteractionChoiceSetIDList(Test.GENERAL_INTEGER_LIST); + msg.setInteractionLayout(Test.GENERAL_LAYOUTMODE); + msg.setInitialText(Test.GENERAL_STRING); + msg.setInteractionMode(Test.GENERAL_INTERACTIONMODE); + msg.setTimeout(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.PERFORM_INTERACTION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(PerformInteraction.KEY_INITIAL_PROMPT, Test.JSON_TTSCHUNKS); + result.put(PerformInteraction.KEY_HELP_PROMPT, Test.JSON_TTSCHUNKS); + result.put(PerformInteraction.KEY_TIMEOUT_PROMPT, Test.JSON_TTSCHUNKS); + result.put(PerformInteraction.KEY_VR_HELP, Test.JSON_VRHELPITEMS); + result.put(PerformInteraction.KEY_INTERACTION_CHOICE_SET_ID_LIST, JsonUtils.createJsonArray(Test.GENERAL_INTEGER_LIST)); + result.put(PerformInteraction.KEY_INTERACTION_LAYOUT, Test.GENERAL_LAYOUTMODE); + result.put(PerformInteraction.KEY_INITIAL_TEXT, Test.GENERAL_STRING); + result.put(PerformInteraction.KEY_INTERACTION_MODE, Test.GENERAL_INTERACTIONMODE); + result.put(PerformInteraction.KEY_TIMEOUT, Test.GENERAL_INT); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<TTSChunk> testInitialPrompt = ( (PerformInteraction) msg).getInitialPrompt(); + List<TTSChunk> testHelpPrompt = ( (PerformInteraction) msg).getHelpPrompt(); + List<TTSChunk> testTimeoutPrompt = ( (PerformInteraction) msg).getTimeoutPrompt(); + List<VrHelpItem> testVrHelpItems = ( (PerformInteraction) msg).getVrHelp(); + List<Integer> testChoiceSetIds = ( (PerformInteraction) msg).getInteractionChoiceSetIDList(); + LayoutMode testLayout = ( (PerformInteraction) msg).getInteractionLayout(); + String testInitialText = ( (PerformInteraction) msg).getInitialText(); + InteractionMode testMode = ( (PerformInteraction) msg).getInteractionMode(); + Integer testTimeout = ( (PerformInteraction) msg).getTimeout(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, testInitialPrompt)); + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, testHelpPrompt)); + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, testTimeoutPrompt)); + assertTrue(Test.TRUE, Validator.validateVrHelpItems(Test.GENERAL_VRHELPITEM_LIST, testVrHelpItems)); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER_LIST, testChoiceSetIds); + assertEquals(Test.MATCH, Test.GENERAL_LAYOUTMODE, testLayout); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testInitialText); + assertEquals(Test.MATCH, Test.GENERAL_INTERACTIONMODE, testMode); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, testTimeout); + + // Invald/Null Tests + PerformInteraction msg = new PerformInteraction(); + assertNotNull(Test.NOT_NULL, msg); + + testNullBase(msg); + + assertNull(Test.NULL, msg.getInitialPrompt()); + assertNull(Test.NULL, msg.getHelpPrompt()); + assertNull(Test.NULL, msg.getTimeoutPrompt()); + assertNull(Test.NULL, msg.getVrHelp()); + assertNull(Test.NULL, msg.getInteractionChoiceSetIDList()); + assertNull(Test.NULL, msg.getInteractionLayout()); + assertNull(Test.NULL, msg.getInitialText()); + assertNull(Test.NULL, msg.getInteractionMode()); + assertNull(Test.NULL, msg.getTimeout()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PerformInteraction cmd = new PerformInteraction(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformInteraction.KEY_INITIAL_TEXT), cmd.getInitialText()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformInteraction.KEY_INTERACTION_MODE), cmd.getInteractionMode().toString()); + + List<Integer> interactionIDList = JsonUtils.readIntegerListFromJsonObject(parameters, PerformInteraction.KEY_INTERACTION_CHOICE_SET_ID_LIST); + List<Integer> testIDList = cmd.getInteractionChoiceSetIDList(); + assertEquals(Test.MATCH, interactionIDList.size(), testIDList.size()); + assertTrue(Test.TRUE, Validator.validateIntegerList(interactionIDList, testIDList)); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformInteraction.KEY_INTERACTION_LAYOUT), cmd.getInteractionLayout().toString()); + + JSONArray initalPromptArray = JsonUtils.readJsonArrayFromJsonObject(parameters, PerformInteraction.KEY_INITIAL_PROMPT); + List<TTSChunk> initalPromptList = new ArrayList<TTSChunk>(); + for (int index = 0; index < initalPromptArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)initalPromptArray.get(index)) ); + initalPromptList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(initalPromptList, cmd.getInitialPrompt())); + + JSONArray helpPromptArray = JsonUtils.readJsonArrayFromJsonObject(parameters, PerformInteraction.KEY_HELP_PROMPT); + List<TTSChunk> helpPromptList = new ArrayList<TTSChunk>(); + for (int index = 0; index < helpPromptArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)helpPromptArray.get(index)) ); + helpPromptList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(helpPromptList, cmd.getHelpPrompt())); + + JSONArray timeoutPromptArray = JsonUtils.readJsonArrayFromJsonObject(parameters, PerformInteraction.KEY_TIMEOUT_PROMPT); + List<TTSChunk> timeoutPromptList = new ArrayList<TTSChunk>(); + for (int index = 0; index < timeoutPromptArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)timeoutPromptArray.get(index)) ); + timeoutPromptList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(timeoutPromptList, cmd.getTimeoutPrompt())); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, PerformInteraction.KEY_TIMEOUT), cmd.getTimeout()); + + JSONArray vrHelpArray = JsonUtils.readJsonArrayFromJsonObject(parameters, PerformInteraction.KEY_VR_HELP); + List<VrHelpItem> vrHelpList= new ArrayList<VrHelpItem>(); + for (int index = 0; index < vrHelpArray.length(); index++) { + VrHelpItem vrHelpItem = new VrHelpItem(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)vrHelpArray.get(index)) ); + vrHelpList.add(vrHelpItem); + } + assertTrue(Test.TRUE, Validator.validateVrHelpItems(vrHelpList, cmd.getVrHelp()) ); + } 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/requests/PublishAppServiceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PublishAppServiceTests.java new file mode 100644 index 000000000..6d0d67490 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PublishAppServiceTests.java @@ -0,0 +1,107 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AppServiceManifest; +import com.smartdevicelink.proxy.rpc.PublishAppService; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +public class PublishAppServiceTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + PublishAppService msg = new PublishAppService(); + msg.setServiceManifest(Test.GENERAL_APP_SERVICE_MANIFEST); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.PUBLISH_APP_SERVICE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(PublishAppService.KEY_APP_SERVICE_MANIFEST, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_APP_SERVICE_MANIFEST.getStore())); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + AppServiceManifest copy = ( (PublishAppService) msg ).getServiceManifest(); + + // Valid Tests + assertTrue(Validator.validateAppServiceManifest(Test.GENERAL_APP_SERVICE_MANIFEST, copy)); + + // Invalid/Null Tests + PublishAppService msg = new PublishAppService(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.MATCH, msg.getServiceManifest()); + } + + /** + * Tests constructor with required params + */ + public void testRequiredParamsConstructor () { + + PublishAppService msg = new PublishAppService(Test.GENERAL_APP_SERVICE_MANIFEST); + assertNotNull(Test.NOT_NULL, msg); + // Valid Tests + assertTrue(Validator.validateAppServiceManifest(Test.GENERAL_APP_SERVICE_MANIFEST, msg.getServiceManifest())); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PublishAppService cmd = new PublishAppService(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONObject appServiceManifestObject = JsonUtils.readJsonObjectFromJsonObject(parameters, PublishAppService.KEY_APP_SERVICE_MANIFEST); + AppServiceManifest manifestTest = new AppServiceManifest(JsonRPCMarshaller.deserializeJSONObject(appServiceManifestObject)); + assertTrue(Test.TRUE, Validator.validateAppServiceManifest(manifestTest, cmd.getServiceManifest())); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PutFileTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PutFileTests.java new file mode 100644 index 000000000..7b6ce75e5 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/PutFileTests.java @@ -0,0 +1,149 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.zip.CRC32; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.PutFile; +import com.smartdevicelink.proxy.rpc.enums.FileType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.PutFile} + */ +public class PutFileTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + PutFile msg = new PutFile(); + + msg.setFileType(Test.GENERAL_FILETYPE); + msg.setPersistentFile(Test.GENERAL_BOOLEAN); + msg.setSystemFile(Test.GENERAL_BOOLEAN); + msg.setOffset(Test.GENERAL_LONG); + msg.setLength(Test.GENERAL_LONG); + msg.setCRC(Test.GENERAL_BYTE_ARRAY); + msg.setCRC(Test.GENERAL_LONG); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.PUT_FILE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(PutFile.KEY_FILE_TYPE, Test.GENERAL_FILETYPE); + result.put(PutFile.KEY_PERSISTENT_FILE, Test.GENERAL_BOOLEAN); + result.put(PutFile.KEY_SYSTEM_FILE, Test.GENERAL_BOOLEAN); + result.put(PutFile.KEY_OFFSET, Test.GENERAL_LONG); + result.put(PutFile.KEY_LENGTH, Test.GENERAL_LONG); + result.put(PutFile.KEY_CRC, Test.GENERAL_LONG); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + FileType testFileType = ( (PutFile) msg ).getFileType(); + boolean testPersistentFile = ( (PutFile) msg ).getPersistentFile(); + boolean testSystemFile = ( (PutFile) msg ).getSystemFile(); + Long testOffset = ( (PutFile) msg ).getOffset(); + Long testLength = ( (PutFile) msg ).getLength(); + Long testCRC = ( (PutFile) msg ).getCRC(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_FILETYPE, testFileType); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testPersistentFile); + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testSystemFile); + assertEquals(Test.MATCH, Test.GENERAL_LONG, testOffset); + assertEquals(Test.MATCH, Test.GENERAL_LONG, testLength); + assertEquals(Test.MATCH, Test.GENERAL_LONG, testCRC); + + // Invalid/Null Tests + PutFile msg = new PutFile(); + assertNotNull("Null object creation failed.", msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getFileType()); + assertNull(Test.NULL, msg.getPersistentFile()); + assertNull(Test.NULL, msg.getSystemFile()); + assertNull(Test.NULL, msg.getOffset()); + assertNull(Test.NULL, msg.getLength()); + assertNull(Test.NULL, msg.getCRC()); + } + + /** + * Tests the expected values of the CRC checksum. + */ + public void testByteArrayCheckSum () { + // Test Values + PutFile msgCRC = new PutFile(); + msgCRC.setCRC(Test.GENERAL_BYTE_ARRAY); + Long testCRCByteArray = msgCRC.getCRC(); + + CRC32 crc = new CRC32(); + crc.update(Test.GENERAL_BYTE_ARRAY); + Long crcValue = crc.getValue(); + + assertEquals(Test.MATCH, crcValue, testCRCByteArray); + } + + + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PutFile cmd = new PutFile(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, PutFile.KEY_PERSISTENT_FILE), cmd.getPersistentFile()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, PutFile.KEY_SYSTEM_FILE), cmd.getSystemFile()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PutFile.KEY_FILE_TYPE), cmd.getFileType().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PutFile.KEY_SDL_FILE_NAME), cmd.getSdlFileName()); + assertEquals(Test.MATCH, (Long) JsonUtils.readIntegerFromJsonObject(parameters, PutFile.KEY_OFFSET).longValue(), cmd.getOffset()); + assertEquals(Test.MATCH, (Long) JsonUtils.readIntegerFromJsonObject(parameters, PutFile.KEY_LENGTH).longValue(), cmd.getLength()); + assertEquals(Test.MATCH, (Long) JsonUtils.readIntegerFromJsonObject(parameters, PutFile.KEY_CRC).longValue(), cmd.getCRC()); + } 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/requests/ReadDidTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ReadDidTests.java new file mode 100644 index 000000000..477acc1aa --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ReadDidTests.java @@ -0,0 +1,109 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ReadDID; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ReadDID} + */ +public class ReadDidTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + ReadDID msg = new ReadDID(); + + msg.setEcuName(Test.GENERAL_INT); + msg.setDidLocation(Test.GENERAL_INTEGER_LIST); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.READ_DID.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(ReadDID.KEY_ECU_NAME, Test.GENERAL_INT); + result.put(ReadDID.KEY_DID_LOCATION, JsonUtils.createJsonArray(Test.GENERAL_INTEGER_LIST)); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer testEcuName = ( (ReadDID) msg ).getEcuName(); + List<Integer> testDidLocation = ( (ReadDID) msg ).getDidLocation(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, testEcuName); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER_LIST, testDidLocation); + + // Invalid/Null Tests + ReadDID msg = new ReadDID(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getEcuName()); + assertNull(Test.NULL, msg.getDidLocation()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ReadDID cmd = new ReadDID(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, ReadDID.KEY_ECU_NAME), cmd.getEcuName()); + + List<Integer> didLocationList = JsonUtils.readIntegerListFromJsonObject(parameters, ReadDID.KEY_DID_LOCATION); + List<Integer> testLocationList = cmd.getDidLocation(); + assertEquals(Test.MATCH, didLocationList.size(), testLocationList.size()); + assertTrue(Test.TRUE, Validator.validateIntegerList(didLocationList, testLocationList)); + } 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/requests/RegisterAppInterfaceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/RegisterAppInterfaceTests.java new file mode 100644 index 000000000..85b6f28ea --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/RegisterAppInterfaceTests.java @@ -0,0 +1,218 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeviceInfo; +import com.smartdevicelink.proxy.rpc.RegisterAppInterface; +import com.smartdevicelink.proxy.rpc.SdlMsgVersion; +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.proxy.rpc.TemplateColorScheme; +import com.smartdevicelink.proxy.rpc.enums.AppHMIType; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.RegisterAppInterface} + */ +public class RegisterAppInterfaceTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + RegisterAppInterface msg = new RegisterAppInterface(); + + msg.setSdlMsgVersion(Test.GENERAL_SDLMSGVERSION); + msg.setAppName(Test.GENERAL_STRING); + msg.setNgnMediaScreenAppName(Test.GENERAL_STRING); + msg.setFullAppID(Test.GENERAL_FULL_APP_ID); + msg.setLanguageDesired(Test.GENERAL_LANGUAGE); + msg.setHmiDisplayLanguageDesired(Test.GENERAL_LANGUAGE); + msg.setHashID(Test.GENERAL_STRING); + msg.setTtsName(Test.GENERAL_TTSCHUNK_LIST); + msg.setVrSynonyms(Test.GENERAL_STRING_LIST); + msg.setAppHMIType(Test.GENERAL_APPHMITYPE_LIST); + msg.setIsMediaApplication(Test.GENERAL_BOOLEAN); + msg.setDeviceInfo(Test.GENERAL_DEVICEINFO); + msg.setDayColorScheme(Test.GENERAL_DAYCOLORSCHEME); + msg.setNightColorScheme(Test.GENERAL_NIGHTCOLORSCHEME); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.REGISTER_APP_INTERFACE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(RegisterAppInterface.KEY_SDL_MSG_VERSION, Test.JSON_SDLMSGVERSION); + result.put(RegisterAppInterface.KEY_APP_NAME, Test.GENERAL_STRING); + result.put(RegisterAppInterface.KEY_NGN_MEDIA_SCREEN_APP_NAME, Test.GENERAL_STRING); + result.put(RegisterAppInterface.KEY_APP_ID, Test.GENERAL_APP_ID); + result.put(RegisterAppInterface.KEY_FULL_APP_ID, Test.GENERAL_FULL_APP_ID); + result.put(RegisterAppInterface.KEY_LANGUAGE_DESIRED, Test.GENERAL_LANGUAGE); + result.put(RegisterAppInterface.KEY_HMI_DISPLAY_LANGUAGE_DESIRED, Test.GENERAL_LANGUAGE); + result.put(RegisterAppInterface.KEY_HASH_ID, Test.GENERAL_STRING); + result.put(RegisterAppInterface.KEY_TTS_NAME, Test.JSON_TTSCHUNKS); + result.put(RegisterAppInterface.KEY_VR_SYNONYMS, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + result.put(RegisterAppInterface.KEY_APP_HMI_TYPE, JsonUtils.createJsonArrayOfJsonNames(Test.GENERAL_APPHMITYPE_LIST, SDL_VERSION_UNDER_TEST)); + result.put(RegisterAppInterface.KEY_IS_MEDIA_APPLICATION, Test.GENERAL_BOOLEAN); + result.put(RegisterAppInterface.KEY_DEVICE_INFO, Test.JSON_DEVICEINFO); + result.put(RegisterAppInterface.KEY_DAY_COLOR_SCHEME, Test.JSON_DAYCOLORSCHEME); + result.put(RegisterAppInterface.KEY_NIGHT_COLOR_SCHEME, Test.JSON_NIGHTCOLORSCHEME); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + SdlMsgVersion testVersion = ( (RegisterAppInterface) msg).getSdlMsgVersion(); + String testName = ( (RegisterAppInterface) msg).getAppName(); + String testNgnName = ( (RegisterAppInterface) msg).getNgnMediaScreenAppName(); + String testAppId = ( (RegisterAppInterface) msg).getAppID(); + String testFullAppId = ( (RegisterAppInterface) msg).getFullAppID(); + Language testLang = ( (RegisterAppInterface) msg).getLanguageDesired(); + Language testHmiLang = ( (RegisterAppInterface) msg).getHmiDisplayLanguageDesired(); + String testHashId = ( (RegisterAppInterface) msg).getHashID(); + List<TTSChunk> testTts = ( (RegisterAppInterface) msg).getTtsName(); + List<String> testSynonyms = ( (RegisterAppInterface) msg).getVrSynonyms(); + List<AppHMIType> testApps = ( (RegisterAppInterface) msg).getAppHMIType(); + Boolean testMedia = ( (RegisterAppInterface) msg).getIsMediaApplication(); + DeviceInfo testDeviceInfo = ( (RegisterAppInterface) msg).getDeviceInfo(); + TemplateColorScheme testDayColorScheme = ( (RegisterAppInterface) msg).getDayColorScheme(); + TemplateColorScheme testNightColorScheme = ( (RegisterAppInterface) msg).getNightColorScheme(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateSdlMsgVersion(Test.GENERAL_SDLMSGVERSION, testVersion)); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testName); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testNgnName); + assertEquals(Test.MATCH, Test.GENERAL_APP_ID, testAppId); + assertEquals(Test.MATCH, Test.GENERAL_FULL_APP_ID, testFullAppId); + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, testLang); + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, testHmiLang); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testHashId); + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, testTts)); + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST, testSynonyms); + assertEquals(Test.MATCH, Test.GENERAL_APPHMITYPE_LIST, testApps); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, testMedia); + assertTrue(Test.TRUE, Validator.validateDeviceInfo(Test.GENERAL_DEVICEINFO, testDeviceInfo)); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(Test.GENERAL_DAYCOLORSCHEME, testDayColorScheme)); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(Test.GENERAL_NIGHTCOLORSCHEME, testNightColorScheme)); + + // Invalid/Null Tests + RegisterAppInterface msg = new RegisterAppInterface(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSdlMsgVersion()); + assertNull(Test.NULL, msg.getAppName()); + assertNull(Test.NULL, msg.getNgnMediaScreenAppName()); + assertNull(Test.NULL, msg.getAppID()); + assertNull(Test.NULL, msg.getFullAppID()); + assertNull(Test.NULL, msg.getLanguageDesired()); + assertNull(Test.NULL, msg.getHmiDisplayLanguageDesired()); + assertNull(Test.NULL, msg.getHashID()); + assertNull(Test.NULL, msg.getTtsName()); + assertNull(Test.NULL, msg.getVrSynonyms()); + assertNull(Test.NULL, msg.getAppHMIType()); + assertNull(Test.NULL, msg.getIsMediaApplication()); + assertNull(Test.NULL, msg.getDeviceInfo()); + assertNull(Test.NULL, msg.getDayColorScheme()); + assertNull(Test.NULL, msg.getNightColorScheme()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + RegisterAppInterface cmd = new RegisterAppInterface(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + JSONArray ttsNameArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterface.KEY_TTS_NAME); + List<TTSChunk> ttsNameList = new ArrayList<TTSChunk>(); + for (int index = 0; index < ttsNameArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)ttsNameArray.get(index)) ); + ttsNameList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(ttsNameList, cmd.getTtsName())); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterface.KEY_HMI_DISPLAY_LANGUAGE_DESIRED), cmd.getHmiDisplayLanguageDesired().toString()); + + JSONArray appHmiTypeArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterface.KEY_APP_HMI_TYPE); + for (int index = 0; index < appHmiTypeArray.length(); index++) { + AppHMIType appHmiTypeItem = AppHMIType.valueForString( appHmiTypeArray.get(index).toString() ); + assertEquals(Test.MATCH, appHmiTypeItem, cmd.getAppHMIType().get(index) ); + } + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterface.KEY_APP_ID), cmd.getAppID()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterface.KEY_FULL_APP_ID), cmd.getFullAppID()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterface.KEY_LANGUAGE_DESIRED), cmd.getLanguageDesired().toString()); + + JSONObject deviceInfoObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterface.KEY_DEVICE_INFO); + DeviceInfo deviceInfo = new DeviceInfo(JsonRPCMarshaller.deserializeJSONObject(deviceInfoObj)); + assertTrue(Test.TRUE, Validator.validateDeviceInfo(deviceInfo, cmd.getDeviceInfo()) ); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterface.KEY_APP_NAME), cmd.getAppName()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterface.KEY_NGN_MEDIA_SCREEN_APP_NAME), cmd.getNgnMediaScreenAppName()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, RegisterAppInterface.KEY_IS_MEDIA_APPLICATION), cmd.getIsMediaApplication()); + + List<String> vrSynonymsList = JsonUtils.readStringListFromJsonObject(parameters, RegisterAppInterface.KEY_VR_SYNONYMS); + List<String> testSynonymsList = cmd.getVrSynonyms(); + assertEquals(Test.MATCH, vrSynonymsList.size(), testSynonymsList.size()); + assertTrue(Test.TRUE, Validator.validateStringList(vrSynonymsList, testSynonymsList)); + + JSONObject sdlMsgVersionObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterface.KEY_SDL_MSG_VERSION); + SdlMsgVersion sdlMsgVersion = new SdlMsgVersion(JsonRPCMarshaller.deserializeJSONObject(sdlMsgVersionObj)); + assertTrue(Test.TRUE, Validator.validateSdlMsgVersion(sdlMsgVersion, cmd.getSdlMsgVersion()) ); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterface.KEY_HASH_ID), cmd.getHashID()); + + JSONObject dayColorSchemeObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterface.KEY_DAY_COLOR_SCHEME); + TemplateColorScheme dayColorScheme = new TemplateColorScheme(JsonRPCMarshaller.deserializeJSONObject(dayColorSchemeObj)); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(dayColorScheme, cmd.getDayColorScheme()) ); + + JSONObject nightColorSchemeObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterface.KEY_DAY_COLOR_SCHEME); + TemplateColorScheme nightColorScheme = new TemplateColorScheme(JsonRPCMarshaller.deserializeJSONObject(nightColorSchemeObj)); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(nightColorScheme, cmd.getDayColorScheme()) ); + + } 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/requests/ResetGlobalPropertiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ResetGlobalPropertiesTests.java new file mode 100644 index 000000000..dc4fda730 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ResetGlobalPropertiesTests.java @@ -0,0 +1,108 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ResetGlobalProperties; +import com.smartdevicelink.proxy.rpc.enums.GlobalProperty; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ResetGlobalProperties} + */ +public class ResetGlobalPropertiesTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + ResetGlobalProperties msg = new ResetGlobalProperties(); + + msg.setProperties(Test.GENERAL_GLOBALPROPERTY_LIST); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.RESET_GLOBAL_PROPERTIES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(ResetGlobalProperties.KEY_PROPERTIES, JsonUtils.createJsonArray(Test.GENERAL_GLOBALPROPERTY_LIST)); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<GlobalProperty> copy = ( (ResetGlobalProperties) msg ).getProperties(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_GLOBALPROPERTY_LIST.size(), copy.size()); + for(int i = 0; i < Test.GENERAL_GLOBALPROPERTY_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_GLOBALPROPERTY_LIST.get(i), copy.get(i)); + } + + // Invalid/Null Tests + ResetGlobalProperties msg = new ResetGlobalProperties(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getProperties()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ResetGlobalProperties cmd = new ResetGlobalProperties(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONArray propertiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, ResetGlobalProperties.KEY_PROPERTIES); + for (int index = 0; index < propertiesArray.length(); index++) { + GlobalProperty property = GlobalProperty.valueOf(propertiesArray.get(index).toString()); + assertEquals(Test.MATCH, property, cmd.getProperties().get(index)); + } + } 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/requests/ScrollableMessageTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ScrollableMessageTests.java new file mode 100644 index 000000000..f7bca8e78 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ScrollableMessageTests.java @@ -0,0 +1,125 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ScrollableMessage; +import com.smartdevicelink.proxy.rpc.SoftButton; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ScrollableMessage} + */ +public class ScrollableMessageTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + ScrollableMessage msg = new ScrollableMessage(); + + msg.setTimeout(Test.GENERAL_INT); + msg.setSoftButtons(Test.GENERAL_SOFTBUTTON_LIST); + msg.setScrollableMessageBody(Test.GENERAL_STRING); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SCROLLABLE_MESSAGE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(ScrollableMessage.KEY_SCROLLABLE_MESSAGE_BODY, Test.GENERAL_STRING); + result.put(ScrollableMessage.KEY_TIMEOUT, Test.GENERAL_INT); + result.put(ScrollableMessage.KEY_SOFT_BUTTONS, Test.JSON_SOFTBUTTONS); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String testBody = ( (ScrollableMessage) msg ).getScrollableMessageBody(); + Integer testTimeout = ( (ScrollableMessage) msg ).getTimeout(); + List<SoftButton> testSoftButtons = ( (ScrollableMessage) msg ).getSoftButtons(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, testBody); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, testTimeout); + assertEquals(Test.MATCH, Test.GENERAL_SOFTBUTTON_LIST.size(), testSoftButtons.size()); + for (int i = 0; i < Test.GENERAL_SOFTBUTTON_LIST.size(); i++) { + assertEquals(Test.MATCH, Test.GENERAL_SOFTBUTTON_LIST.get(i), testSoftButtons.get(i)); + } + + // Invalid/Null Tests + ScrollableMessage msg = new ScrollableMessage(); + assertNotNull(Test.NOT_NULL, msg); + + testNullBase(msg); + + assertNull(Test.NULL, msg.getScrollableMessageBody()); + assertNull(Test.NULL, msg.getTimeout()); + assertNull(Test.NULL, msg.getSoftButtons()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ScrollableMessage cmd = new ScrollableMessage(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, ScrollableMessage.KEY_SCROLLABLE_MESSAGE_BODY), cmd.getScrollableMessageBody()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, ScrollableMessage.KEY_TIMEOUT), cmd.getTimeout()); + + JSONArray softButtonArray = JsonUtils.readJsonArrayFromJsonObject(parameters, ScrollableMessage.KEY_SOFT_BUTTONS); + List<SoftButton> softButtonList = new ArrayList<SoftButton>(); + for (int index = 0; index < softButtonArray.length(); index++) { + SoftButton chunk = new SoftButton(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)softButtonArray.get(index)) ); + softButtonList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateSoftButtons(softButtonList, cmd.getSoftButtons())); + } 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/requests/SendHapticDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SendHapticDataTests.java new file mode 100644 index 000000000..7c3b0ed90 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SendHapticDataTests.java @@ -0,0 +1,86 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.HapticRect; +import com.smartdevicelink.proxy.rpc.SendHapticData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by brettywhite on 8/9/17. + */ + +public class SendHapticDataTests extends BaseRpcTests { + + private SendHapticData msg; + + @Override + protected RPCMessage createMessage(){ + msg = new SendHapticData(); + + List<HapticRect> list = new ArrayList<>(); + list.add(Test.GENERAL_HAPTIC_RECT); + + msg.setHapticRectData(list); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.SEND_HAPTIC_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + JSONArray jsonArray = new JSONArray(); + try { + jsonArray.put(JsonRPCMarshaller.serializeHashtable(Test.GENERAL_HAPTIC_RECT.getStore())); + } catch (JSONException e) { + e.printStackTrace(); + } + + try { + result.put(SendHapticData.KEY_HAPTIC_RECT_DATA, jsonArray); + } catch (JSONException e) { + e.printStackTrace(); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<HapticRect> list = msg.getHapticRectData(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_HAPTIC_RECT, list.get(0)); + + // Invalid/Null Tests + SendHapticData msg = new SendHapticData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getHapticRectData()); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SendLocationTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SendLocationTests.java new file mode 100644 index 000000000..ee9a93750 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SendLocationTests.java @@ -0,0 +1,145 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.SendLocation; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SendLocation} + */ +public class SendLocationTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + SendLocation msg = new SendLocation(); + + msg.setLatitudeDegrees(Test.GENERAL_DOUBLE); + msg.setLongitudeDegrees(Test.GENERAL_DOUBLE); + msg.setLocationName(Test.GENERAL_STRING); + msg.setLocationDescription(Test.GENERAL_STRING); + msg.setPhoneNumber(Test.GENERAL_STRING); + msg.setAddressLines(Test.GENERAL_STRING_LIST); + msg.setLocationImage(Test.GENERAL_IMAGE); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.SEND_LOCATION.toString(); + } + + @Override + protected JSONObject getExpectedParameters (int sdlVersion){ + JSONObject result = new JSONObject(); + + try { + result.put(SendLocation.KEY_LAT_DEGREES, Test.GENERAL_DOUBLE); + result.put(SendLocation.KEY_LON_DEGREES, Test.GENERAL_DOUBLE); + result.put(SendLocation.KEY_LOCATION_NAME, Test.GENERAL_STRING); + result.put(SendLocation.KEY_LOCATION_DESCRIPTION, Test.GENERAL_STRING); + result.put(SendLocation.KEY_PHONE_NUMBER, Test.GENERAL_STRING); + result.put(SendLocation.KEY_LOCATION_IMAGE, Test.GENERAL_IMAGE.serializeJSON()); + result.put(SendLocation.KEY_ADDRESS_LINES, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Double latitude = ((SendLocation) msg).getLatitudeDegrees(); + Double longitude = ((SendLocation) msg).getLongitudeDegrees(); + String locationName = ((SendLocation) msg).getLocationName(); + String locationDesc = ((SendLocation) msg).getLocationDescription(); + String phoneNumber = ((SendLocation) msg).getPhoneNumber(); + List<String> addressLines = ((SendLocation) msg).getAddressLines(); + Image locationImage = ((SendLocation) msg).getLocationImage(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, longitude); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, latitude); + assertEquals(Test.MATCH, Test.GENERAL_STRING, locationDesc); + assertEquals(Test.MATCH, Test.GENERAL_STRING, locationName); + assertEquals(Test.MATCH, Test.GENERAL_STRING, phoneNumber); + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, addressLines)); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, locationImage)); + + // Invalid/Null Tests + SendLocation msg = new SendLocation(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getLatitudeDegrees()); + assertNull(Test.NULL, msg.getLongitudeDegrees()); + assertNull(Test.NULL, msg.getLocationName()); + assertNull(Test.NULL, msg.getLocationDescription()); + assertNull(Test.NULL, msg.getPhoneNumber()); + assertNull(Test.NULL, msg.getAddressLines()); + assertNull(Test.NULL, msg.getLocationImage()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull("Command object is null", commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SendLocation cmd = new SendLocation(hash); + assertNotNull(Test.NOT_NULL, cmd); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, SendLocation.KEY_LAT_DEGREES), cmd.getLatitudeDegrees()); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, SendLocation.KEY_LON_DEGREES), cmd.getLongitudeDegrees()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SendLocation.KEY_LOCATION_NAME), cmd.getLocationName()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SendLocation.KEY_LOCATION_DESCRIPTION), cmd.getLocationDescription()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SendLocation.KEY_PHONE_NUMBER), cmd.getPhoneNumber()); + + List<String> addressList = JsonUtils.readStringListFromJsonObject(parameters, SendLocation.KEY_ADDRESS_LINES); + List<String> testList = cmd.getAddressLines(); + assertEquals(Test.MATCH, addressList.size(), testList.size()); + assertTrue(Test.TRUE, Validator.validateStringList(addressList, testList)); + + JSONObject cmdIcon = JsonUtils.readJsonObjectFromJsonObject(parameters, SendLocation.KEY_LOCATION_IMAGE); + Image reference = new Image(JsonRPCMarshaller.deserializeJSONObject(cmdIcon)); + assertTrue(Test.TRUE, Validator.validateImage(reference, cmd.getLocationImage())); + + } 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/requests/SetAppIconTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetAppIconTests.java new file mode 100644 index 000000000..c9286b763 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetAppIconTests.java @@ -0,0 +1,98 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SetAppIcon; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetAppIcon} + */ +public class SetAppIconTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SetAppIcon msg = new SetAppIcon(); + + msg.setSdlFileName(Test.GENERAL_STRING); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SET_APP_ICON.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SetAppIcon.KEY_SDL_FILE_NAME, Test.GENERAL_STRING); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String copy = ( (SetAppIcon) msg ).getSdlFileName(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, copy); + + // Invalid/Null Tests + SetAppIcon msg = new SetAppIcon(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSdlFileName()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetAppIcon cmd = new SetAppIcon(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SetAppIcon.KEY_SDL_FILE_NAME), cmd.getSdlFileName()); + + } 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/requests/SetCloudAppPropertiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetCloudAppPropertiesTests.java new file mode 100644 index 000000000..ea817c85e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetCloudAppPropertiesTests.java @@ -0,0 +1,46 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SetCloudAppProperties; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONException; +import org.json.JSONObject; + +public class SetCloudAppPropertiesTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + SetCloudAppProperties msg = new SetCloudAppProperties(); + + msg.setProperties(Test.GENERAL_CLOUD_APP_PROPERTIES); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.SET_CLOUD_APP_PROPERTIES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(SetCloudAppProperties.KEY_PROPERTIES, Test.GENERAL_CLOUD_APP_PROPERTIES.serializeJSON()); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetDisplayLayoutTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetDisplayLayoutTests.java new file mode 100644 index 000000000..d0ccc6fc7 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetDisplayLayoutTests.java @@ -0,0 +1,121 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SetDisplayLayout; +import com.smartdevicelink.proxy.rpc.TemplateColorScheme; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetDisplayLayout} + */ +public class SetDisplayLayoutTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SetDisplayLayout msg = new SetDisplayLayout(); + + msg.setDisplayLayout(Test.GENERAL_STRING); + msg.setDayColorScheme(Test.GENERAL_DAYCOLORSCHEME); + msg.setNightColorScheme(Test.GENERAL_NIGHTCOLORSCHEME); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SET_DISPLAY_LAYOUT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SetDisplayLayout.KEY_DISPLAY_LAYOUT, Test.GENERAL_STRING); + result.put(SetDisplayLayout.KEY_DAY_COLOR_SCHEME, Test.JSON_DAYCOLORSCHEME); + result.put(SetDisplayLayout.KEY_NIGHT_COLOR_SCHEME, Test.JSON_NIGHTCOLORSCHEME); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String testDisplayLayout = ( (SetDisplayLayout) msg ).getDisplayLayout(); + TemplateColorScheme testDayColorScheme = ( (SetDisplayLayout) msg).getDayColorScheme(); + TemplateColorScheme testNightColorScheme = ( (SetDisplayLayout) msg).getNightColorScheme(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, testDisplayLayout); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(Test.GENERAL_DAYCOLORSCHEME, testDayColorScheme)); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(Test.GENERAL_NIGHTCOLORSCHEME, testNightColorScheme)); + + // Invalid/Null Tests + SetDisplayLayout msg = new SetDisplayLayout(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getDisplayLayout()); + assertNull(Test.NULL, msg.getDayColorScheme()); + assertNull(Test.NULL, msg.getNightColorScheme()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetDisplayLayout cmd = new SetDisplayLayout(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.MATCH, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SetDisplayLayout.KEY_DISPLAY_LAYOUT), cmd.getDisplayLayout()); + + + JSONObject dayColorSchemeObj = JsonUtils.readJsonObjectFromJsonObject(parameters, SetDisplayLayout.KEY_DAY_COLOR_SCHEME); + TemplateColorScheme dayColorScheme = new TemplateColorScheme(JsonRPCMarshaller.deserializeJSONObject(dayColorSchemeObj)); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(dayColorScheme, cmd.getDayColorScheme()) ); + + JSONObject nightColorSchemeObj = JsonUtils.readJsonObjectFromJsonObject(parameters, SetDisplayLayout.KEY_DAY_COLOR_SCHEME); + TemplateColorScheme nightColorScheme = new TemplateColorScheme(JsonRPCMarshaller.deserializeJSONObject(nightColorSchemeObj)); + assertTrue(Test.TRUE, Validator.validateTemplateColorScheme(nightColorScheme, cmd.getDayColorScheme()) ); + + + } 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/requests/SetGlobalPropertiesTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetGlobalPropertiesTests.java new file mode 100644 index 000000000..5f791769b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetGlobalPropertiesTests.java @@ -0,0 +1,168 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.KeyboardProperties; +import com.smartdevicelink.proxy.rpc.SetGlobalProperties; +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.proxy.rpc.VrHelpItem; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetGlobalProperties} + */ +public class SetGlobalPropertiesTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SetGlobalProperties msg = new SetGlobalProperties(); + + msg.setVrHelpTitle(Test.GENERAL_STRING); + msg.setMenuTitle(Test.GENERAL_STRING); + msg.setMenuIcon(Test.GENERAL_IMAGE); + msg.setVrHelp(Test.GENERAL_VRHELPITEM_LIST); + msg.setHelpPrompt(Test.GENERAL_TTSCHUNK_LIST); + msg.setTimeoutPrompt(Test.GENERAL_TTSCHUNK_LIST); + msg.setKeyboardProperties(Test.GENERAL_KEYBOARDPROPERTIES); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SET_GLOBAL_PROPERTIES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SetGlobalProperties.KEY_MENU_ICON, Test.JSON_IMAGE); + result.put(SetGlobalProperties.KEY_VR_HELP, Test.JSON_VRHELPITEMS); + result.put(SetGlobalProperties.KEY_HELP_PROMPT, Test.JSON_TTSCHUNKS); + result.put(SetGlobalProperties.KEY_TIMEOUT_PROMPT, Test.JSON_TTSCHUNKS); + result.put(SetGlobalProperties.KEY_MENU_TITLE, Test.GENERAL_STRING); + result.put(SetGlobalProperties.KEY_VR_HELP_TITLE, Test.GENERAL_STRING); + result.put(SetGlobalProperties.KEY_KEYBOARD_PROPERTIES, Test.JSON_KEYBOARDPROPERTIES); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Image testImage = ( (SetGlobalProperties) msg ).getMenuIcon(); + String testVrHelpTitle = ( (SetGlobalProperties) msg ).getVrHelpTitle(); + String testMenuTitle = ( (SetGlobalProperties) msg ).getMenuTitle(); + List<TTSChunk> testHelpPrompt = ( (SetGlobalProperties) msg ).getHelpPrompt(); + List<TTSChunk> testTimeout = ( (SetGlobalProperties) msg ).getTimeoutPrompt(); + List<VrHelpItem> testVrHelpItems = ( (SetGlobalProperties) msg ).getVrHelp(); + KeyboardProperties testKeyboardProperties = ( (SetGlobalProperties) msg ).getKeyboardProperties(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, testMenuTitle); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testVrHelpTitle); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, testImage)); + assertTrue(Test.TRUE, Validator.validateVrHelpItems(Test.GENERAL_VRHELPITEM_LIST, testVrHelpItems)); + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, testHelpPrompt)); + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, testTimeout)); + assertTrue(Test.TRUE, Validator.validateKeyboardProperties(Test.GENERAL_KEYBOARDPROPERTIES, testKeyboardProperties)); + + // Invalid/Null Tests + SetGlobalProperties msg = new SetGlobalProperties(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getMenuIcon()); + assertNull(Test.NULL, msg.getMenuTitle()); + assertNull(Test.NULL, msg.getVrHelp()); + assertNull(Test.NULL, msg.getHelpPrompt()); + assertNull(Test.NULL, msg.getTimeoutPrompt()); + assertNull(Test.NULL, msg.getKeyboardProperties()); + assertNull(Test.NULL, msg.getVrHelpTitle()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetGlobalProperties cmd = new SetGlobalProperties(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SetGlobalProperties.KEY_VR_HELP_TITLE), cmd.getVrHelpTitle()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SetGlobalProperties.KEY_MENU_TITLE), cmd.getMenuTitle()); + + JSONObject menuIcon = JsonUtils.readJsonObjectFromJsonObject(parameters, SetGlobalProperties.KEY_MENU_ICON); + Image referenceMenuIcon = new Image(JsonRPCMarshaller.deserializeJSONObject(menuIcon)); + assertTrue(Test.TRUE, Validator.validateImage(referenceMenuIcon, cmd.getMenuIcon())); + + JSONObject keyboardProperties = JsonUtils.readJsonObjectFromJsonObject(parameters, SetGlobalProperties.KEY_KEYBOARD_PROPERTIES); + KeyboardProperties referenceKeyboardProperties = new KeyboardProperties(JsonRPCMarshaller.deserializeJSONObject(keyboardProperties)); + assertTrue(Test.TRUE, Validator.validateKeyboardProperties(referenceKeyboardProperties, cmd.getKeyboardProperties())); + + JSONArray helpPromptArray = JsonUtils.readJsonArrayFromJsonObject(parameters, SetGlobalProperties.KEY_HELP_PROMPT); + List<TTSChunk> helpPromptList = new ArrayList<TTSChunk>(); + for (int index = 0; index < helpPromptArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)helpPromptArray.get(index)) ); + helpPromptList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(helpPromptList, cmd.getHelpPrompt())); + + JSONArray timeoutPromptArray = JsonUtils.readJsonArrayFromJsonObject(parameters, SetGlobalProperties.KEY_TIMEOUT_PROMPT); + List<TTSChunk> timeoutPromptList = new ArrayList<TTSChunk>(); + for (int index = 0; index < timeoutPromptArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)timeoutPromptArray.get(index)) ); + timeoutPromptList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(timeoutPromptList, cmd.getTimeoutPrompt())); + + JSONArray vrHelpArray = JsonUtils.readJsonArrayFromJsonObject(parameters, SetGlobalProperties.KEY_VR_HELP); + List<VrHelpItem> vrHelpList = new ArrayList<VrHelpItem>(); + for (int index = 0; index < vrHelpArray.length(); index++) { + VrHelpItem chunk = new VrHelpItem(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)vrHelpArray.get(index)) ); + vrHelpList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateVrHelpItems(vrHelpList, cmd.getVrHelp())); + } 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/requests/SetInteriorVehicleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetInteriorVehicleDataTests.java new file mode 100644 index 000000000..f5ecb0d06 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetInteriorVehicleDataTests.java @@ -0,0 +1,102 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ModuleData; +import com.smartdevicelink.proxy.rpc.SetInteriorVehicleData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetInteriorVehicleData} + */ +public class SetInteriorVehicleDataTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + SetInteriorVehicleData msg = new SetInteriorVehicleData(); + + msg.setModuleData(Test.GENERAL_MODULEDATA); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.SET_INTERIOR_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(SetInteriorVehicleData.KEY_MODULE_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_MODULEDATA.getStore())); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ModuleData testModuleData = ( (SetInteriorVehicleData) msg ).getModuleData(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateModuleData(Test.GENERAL_MODULEDATA, testModuleData)); + + // Invalid/Null Tests + SetInteriorVehicleData msg = new SetInteriorVehicleData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getModuleData()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetInteriorVehicleData cmd = new SetInteriorVehicleData(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + ModuleData referenceModuleData = new ModuleData(JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(parameters, SetInteriorVehicleData.KEY_MODULE_DATA))); + + assertTrue(Test.TRUE, Validator.validateModuleData(referenceModuleData, cmd.getModuleData())); + }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/requests/SetMediaClockTimerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetMediaClockTimerTests.java new file mode 100644 index 000000000..8083c65ed --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SetMediaClockTimerTests.java @@ -0,0 +1,189 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SetMediaClockTimer; +import com.smartdevicelink.proxy.rpc.StartTime; +import com.smartdevicelink.proxy.rpc.enums.AudioStreamingIndicator; +import com.smartdevicelink.proxy.rpc.enums.UpdateMode; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.SetMediaClockTimer} + */ +public class SetMediaClockTimerTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SetMediaClockTimer msg = new SetMediaClockTimer(); + + msg.setStartTime(Test.GENERAL_STARTTIME); + msg.setEndTime(Test.GENERAL_STARTTIME); + msg.setUpdateMode(Test.GENERAL_UPDATEMODE); + msg.setAudioStreamingIndicator(Test.GENERAL_AUDIO_STREAMING_INDICATOR); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SET_MEDIA_CLOCK_TIMER.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SetMediaClockTimer.KEY_START_TIME, Test.JSON_STARTTIME); + result.put(SetMediaClockTimer.KEY_END_TIME, Test.JSON_STARTTIME); + result.put(SetMediaClockTimer.KEY_UPDATE_MODE, Test.GENERAL_UPDATEMODE); + result.put(SetMediaClockTimer.KEY_AUDIO_STREAMING_INDICATOR, Test.GENERAL_AUDIO_STREAMING_INDICATOR); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + StartTime testStartTime = ( (SetMediaClockTimer) msg ).getStartTime(); + StartTime testEndTime = ( (SetMediaClockTimer) msg ).getEndTime(); + UpdateMode testUpdateMode = ( (SetMediaClockTimer) msg ).getUpdateMode(); + AudioStreamingIndicator testAudioStreamingIndicator = ( (SetMediaClockTimer) msg ).getAudioStreamingIndicator(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_UPDATEMODE, testUpdateMode); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, testAudioStreamingIndicator); + assertTrue(Test.TRUE, Validator.validateStartTime(Test.GENERAL_STARTTIME, testStartTime)); + assertTrue(Test.TRUE, Validator.validateStartTime(Test.GENERAL_STARTTIME, testEndTime)); + + // Invalid/Null Tests + SetMediaClockTimer msg = new SetMediaClockTimer(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getStartTime()); + assertNull(Test.NULL, msg.getEndTime()); + assertNull(Test.NULL, msg.getUpdateMode()); + assertNull(Test.NULL, msg.getAudioStreamingIndicator()); + } + + /** + * Test static initializers + */ + public void testInitializers(){ + Integer timeInterval1 = 5000; + StartTime startTime1 = new StartTime(timeInterval1); + Integer timeInterval2 = 7000; + StartTime startTime2 = new StartTime(timeInterval2); + SetMediaClockTimer msg; + + msg = SetMediaClockTimer.countUpFromStartTimeInterval(timeInterval1, timeInterval2, Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.COUNTUP); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime1, msg.getStartTime())); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime2, msg.getEndTime())); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + + msg = SetMediaClockTimer.countUpFromStartTime(startTime1, startTime2, Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.COUNTUP); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime1, msg.getStartTime())); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime2, msg.getEndTime())); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + + msg = SetMediaClockTimer.countDownFromStartTimeInterval(timeInterval1, timeInterval2, Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.COUNTDOWN); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime1, msg.getStartTime())); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime2, msg.getEndTime())); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + + msg = SetMediaClockTimer.countDownFromStartTime(startTime1, startTime2, Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.COUNTDOWN); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime1, msg.getStartTime())); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime2, msg.getEndTime())); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + + msg = SetMediaClockTimer.pauseWithPlayPauseIndicator(Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.PAUSE); + assertNull(Test.NULL, msg.getStartTime()); + assertNull(Test.NULL, msg.getEndTime()); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + + msg = SetMediaClockTimer.updatePauseWithNewStartTimeInterval(timeInterval1, timeInterval2, Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.PAUSE); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime1, msg.getStartTime())); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime2, msg.getEndTime())); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + + msg = SetMediaClockTimer.updatePauseWithNewStartTime(startTime1, startTime2, Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.PAUSE); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime1, msg.getStartTime())); + assertTrue(Test.TRUE, Validator.validateStartTime(startTime2, msg.getEndTime())); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + + msg = SetMediaClockTimer.resumeWithPlayPauseIndicator(Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.RESUME); + assertNull(Test.NULL, msg.getStartTime()); + assertNull(Test.NULL, msg.getEndTime()); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + + msg = SetMediaClockTimer.clearWithPlayPauseIndicator(Test.GENERAL_AUDIO_STREAMING_INDICATOR); + assertEquals(Test.MATCH, msg.getUpdateMode(), UpdateMode.CLEAR); + assertNull(Test.NULL, msg.getStartTime()); + assertNull(Test.NULL, msg.getEndTime()); + assertEquals(Test.MATCH, Test.GENERAL_AUDIO_STREAMING_INDICATOR, msg.getAudioStreamingIndicator()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetMediaClockTimer cmd = new SetMediaClockTimer(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + JSONObject startTime = JsonUtils.readJsonObjectFromJsonObject(parameters, SetMediaClockTimer.KEY_START_TIME); + StartTime referenceStartTime = new StartTime(JsonRPCMarshaller.deserializeJSONObject(startTime)); + assertTrue(Test.TRUE, Validator.validateStartTime(referenceStartTime, cmd.getStartTime())); + + JSONObject endTime = JsonUtils.readJsonObjectFromJsonObject(parameters, SetMediaClockTimer.KEY_END_TIME); + StartTime referenceEndTime = new StartTime(JsonRPCMarshaller.deserializeJSONObject(endTime)); + assertTrue(Test.TRUE, Validator.validateStartTime(referenceEndTime, cmd.getEndTime())); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SetMediaClockTimer.KEY_UPDATE_MODE), cmd.getUpdateMode().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SetMediaClockTimer.KEY_AUDIO_STREAMING_INDICATOR), cmd.getAudioStreamingIndicator().toString()); + } 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/requests/ShowConstantTbtTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ShowConstantTbtTests.java new file mode 100644 index 000000000..a6be52608 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ShowConstantTbtTests.java @@ -0,0 +1,175 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.ShowConstantTbt; +import com.smartdevicelink.proxy.rpc.SoftButton; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ShowConstantTbt} + */ +public class ShowConstantTbtTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + ShowConstantTbt msg = new ShowConstantTbt(); + + msg.setDistanceToManeuver(Test.GENERAL_DOUBLE); + msg.setDistanceToManeuverScale(Test.GENERAL_DOUBLE); + msg.setEta(Test.GENERAL_STRING); + msg.setManeuverComplete(true); + msg.setNavigationText1(Test.GENERAL_STRING); + msg.setNavigationText2(Test.GENERAL_STRING); + msg.setNextTurnIcon(Test.GENERAL_IMAGE); + msg.setSoftButtons(Test.GENERAL_SOFTBUTTON_LIST); + msg.setTimeToDestination(Test.GENERAL_STRING); + msg.setTotalDistance(Test.GENERAL_STRING); + msg.setTurnIcon(Test.GENERAL_IMAGE); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SHOW_CONSTANT_TBT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(ShowConstantTbt.KEY_SOFT_BUTTONS, Test.JSON_SOFTBUTTONS); + result.put(ShowConstantTbt.KEY_ETA, Test.GENERAL_STRING); + result.put(ShowConstantTbt.KEY_MANEUVER_COMPLETE, true); + result.put(ShowConstantTbt.KEY_MANEUVER_DISTANCE, Test.GENERAL_DOUBLE); + result.put(ShowConstantTbt.KEY_MANEUVER_DISTANCE_SCALE, Test.GENERAL_DOUBLE); + result.put(ShowConstantTbt.KEY_TEXT1, Test.GENERAL_STRING); + result.put(ShowConstantTbt.KEY_TEXT2, Test.GENERAL_STRING); + result.put(ShowConstantTbt.KEY_TIME_TO_DESTINATION, Test.GENERAL_STRING); + result.put(ShowConstantTbt.KEY_TOTAL_DISTANCE, Test.GENERAL_STRING); + result.put(ShowConstantTbt.KEY_MANEUVER_IMAGE, Test.GENERAL_IMAGE.serializeJSON()); + result.put(ShowConstantTbt.KEY_NEXT_MANEUVER_IMAGE, Test.GENERAL_IMAGE.serializeJSON()); + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Double testScale = ((ShowConstantTbt) msg).getDistanceToManeuverScale(); + Double testDistance = ((ShowConstantTbt) msg).getDistanceToManeuver(); + String testEta = ((ShowConstantTbt) msg).getEta(); + String testTimeToDestination = ((ShowConstantTbt) msg).getTimeToDestination(); + String testTotalDistance = ((ShowConstantTbt) msg).getTotalDistance(); + String testNavText2 = ((ShowConstantTbt) msg).getNavigationText2(); + String testNavText1 = ((ShowConstantTbt) msg).getNavigationText1(); + Boolean testManeuverComplete = ((ShowConstantTbt) msg).getManeuverComplete(); + Image testTurnIcon = ((ShowConstantTbt) msg).getTurnIcon(); + Image testNextTurnIcon = ((ShowConstantTbt) msg).getNextTurnIcon(); + List<SoftButton> testSoftButtons = ((ShowConstantTbt) msg).getSoftButtons(); + + // Valid Test + assertEquals(Test.MATCH, Test.GENERAL_STRING, testTimeToDestination); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, testScale); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testNavText1); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testNavText2); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testEta); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testTotalDistance); + assertEquals(Test.MATCH, Test.GENERAL_DOUBLE, testDistance); + assertTrue(Test.TRUE, testManeuverComplete); + assertTrue(Test.TRUE, Validator.validateSoftButtons(Test.GENERAL_SOFTBUTTON_LIST, testSoftButtons)); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, testTurnIcon)); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, testNextTurnIcon)); + + // Invalid/Null Tests + ShowConstantTbt msg = new ShowConstantTbt(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSoftButtons()); + assertNull(Test.NULL, msg.getNavigationText1()); + assertNull(Test.NULL, msg.getNavigationText2()); + assertNull(Test.NULL, msg.getDistanceToManeuver()); + assertNull(Test.NULL, msg.getDistanceToManeuverScale()); + assertNull(Test.NULL, msg.getEta()); + assertNull(Test.NULL, msg.getManeuverComplete()); + assertNull(Test.NULL, msg.getNextTurnIcon()); + assertNull(Test.NULL, msg.getTimeToDestination()); + assertNull(Test.NULL, msg.getTotalDistance()); + assertNull(Test.NULL, msg.getTurnIcon()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ShowConstantTbt cmd = new ShowConstantTbt(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, ShowConstantTbt.KEY_ETA), cmd.getEta()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, ShowConstantTbt.KEY_MANEUVER_COMPLETE), cmd.getManeuverComplete()); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, ShowConstantTbt.KEY_MANEUVER_DISTANCE), cmd.getDistanceToManeuver()); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, ShowConstantTbt.KEY_MANEUVER_DISTANCE_SCALE), cmd.getDistanceToManeuverScale()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, ShowConstantTbt.KEY_TEXT1), cmd.getNavigationText1()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, ShowConstantTbt.KEY_TEXT2), cmd.getNavigationText2()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, ShowConstantTbt.KEY_TIME_TO_DESTINATION), cmd.getTimeToDestination()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, ShowConstantTbt.KEY_TOTAL_DISTANCE), cmd.getTotalDistance()); + + JSONObject icon1 = JsonUtils.readJsonObjectFromJsonObject(parameters, ShowConstantTbt.KEY_MANEUVER_IMAGE); + Image refIcon1 = new Image(JsonRPCMarshaller.deserializeJSONObject(icon1)); + assertTrue(Test.TRUE, Validator.validateImage(refIcon1, cmd.getTurnIcon())); + + JSONObject icon2 = JsonUtils.readJsonObjectFromJsonObject(parameters, ShowConstantTbt.KEY_NEXT_MANEUVER_IMAGE); + Image refIcon2 = new Image(JsonRPCMarshaller.deserializeJSONObject(icon2)); + assertTrue(Test.TRUE, Validator.validateImage(refIcon2, cmd.getNextTurnIcon())); + + JSONArray softButtonArray = JsonUtils.readJsonArrayFromJsonObject(parameters, ShowConstantTbt.KEY_SOFT_BUTTONS); + List<SoftButton> softButtonList = new ArrayList<SoftButton>(); + for (int index = 0; index < softButtonArray.length(); index++) { + SoftButton chunk = new SoftButton(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)softButtonArray.get(index)) ); + softButtonList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateSoftButtons(softButtonList, cmd.getSoftButtons())); + } 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/requests/ShowTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ShowTests.java new file mode 100644 index 000000000..9c7a681df --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/ShowTests.java @@ -0,0 +1,187 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.MetadataTags; +import com.smartdevicelink.proxy.rpc.Show; +import com.smartdevicelink.proxy.rpc.SoftButton; +import com.smartdevicelink.proxy.rpc.enums.TextAlignment; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.Show} + */ +public class ShowTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + Show msg = new Show(); + + msg.setMainField1(Test.GENERAL_STRING); + msg.setMainField2(Test.GENERAL_STRING); + msg.setMainField3(Test.GENERAL_STRING); + msg.setMainField4(Test.GENERAL_STRING); + msg.setStatusBar(Test.GENERAL_STRING); + msg.setMediaTrack(Test.GENERAL_STRING); + msg.setAlignment(Test.GENERAL_TEXTALIGNMENT); + msg.setGraphic(Test.GENERAL_IMAGE); + msg.setSecondaryGraphic(Test.GENERAL_IMAGE); + msg.setCustomPresets(Test.GENERAL_STRING_LIST); + msg.setSoftButtons(Test.GENERAL_SOFTBUTTON_LIST); + msg.setMetadataTags(Test.GENERAL_METADATASTRUCT); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SHOW.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(Show.KEY_MAIN_FIELD_1, Test.GENERAL_STRING); + result.put(Show.KEY_MAIN_FIELD_2, Test.GENERAL_STRING); + result.put(Show.KEY_MAIN_FIELD_3, Test.GENERAL_STRING); + result.put(Show.KEY_MAIN_FIELD_4, Test.GENERAL_STRING); + result.put(Show.KEY_STATUS_BAR, Test.GENERAL_STRING); + result.put(Show.KEY_MEDIA_TRACK, Test.GENERAL_STRING); + result.put(Show.KEY_GRAPHIC, Test.JSON_IMAGE); + result.put(Show.KEY_SECONDARY_GRAPHIC, Test.JSON_IMAGE); + result.put(Show.KEY_ALIGNMENT, Test.GENERAL_TEXTALIGNMENT); + result.put(Show.KEY_CUSTOM_PRESETS, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + result.put(Show.KEY_SOFT_BUTTONS, Test.JSON_SOFTBUTTONS); + result.put(Show.KEY_METADATA_TAGS, Test.GENERAL_METADATASTRUCT.serializeJSON()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + public void testSoftButtons () { + // TestValues + String testTrack = ( (Show) msg ).getMediaTrack(); + Image testGraphic2 = ( (Show) msg ).getSecondaryGraphic(); + Image testGraphic1 = ( (Show) msg ).getGraphic(); + String testStatusBar = ( (Show) msg ).getStatusBar(); + String testText1 = ( (Show) msg ).getMainField1(); + String testText2 = ( (Show) msg ).getMainField2(); + String testText3 = ( (Show) msg ).getMainField3(); + String testText4 = ( (Show) msg ).getMainField4(); + TextAlignment testAlignment = ( (Show) msg ).getAlignment(); + List<SoftButton> testSoftButtons = ( (Show) msg ).getSoftButtons(); + List<String> testCustomPresets = ( (Show) msg ).getCustomPresets(); + MetadataTags testMetadata = ( (Show) msg ).getMetadataTags(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, testTrack); + assertEquals(Test.MATCH, Test.GENERAL_TEXTALIGNMENT, testAlignment); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testStatusBar); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testText1); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testText2); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testText3); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testText4); + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.size(), testCustomPresets.size()); + assertEquals(Test.MATCH, Test.GENERAL_METADATASTRUCT, testMetadata); + assertTrue(Test.TRUE, Validator.validateSoftButtons(Test.GENERAL_SOFTBUTTON_LIST, testSoftButtons)); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, testGraphic2)); + assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, testGraphic1)); + + // Invalid/Null Tests + Show msg = new Show(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getMainField1()); + assertNull(Test.NULL, msg.getMainField2()); + assertNull(Test.NULL, msg.getMainField3()); + assertNull(Test.NULL, msg.getMainField4()); + assertNull(Test.NULL, msg.getStatusBar()); + assertNull(Test.NULL, msg.getAlignment()); + assertNull(Test.NULL, msg.getGraphic()); + assertNull(Test.NULL, msg.getSecondaryGraphic()); + assertNull(Test.NULL, msg.getCustomPresets()); + assertNull(Test.NULL, msg.getMediaTrack()); + assertNull(Test.NULL, msg.getSoftButtons()); + assertNull(Test.NULL, msg.getMetadataTags()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext,getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + Show cmd = new Show(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONObject graphic = JsonUtils.readJsonObjectFromJsonObject(parameters, Show.KEY_GRAPHIC); + Image referenceGraphic = new Image(JsonRPCMarshaller.deserializeJSONObject(graphic)); + assertTrue(Test.TRUE, Validator.validateImage(referenceGraphic, cmd.getGraphic())); + + List<String> customPresetsList = JsonUtils.readStringListFromJsonObject(parameters, Show.KEY_CUSTOM_PRESETS); + List<String> testPresetsList = cmd.getCustomPresets(); + assertEquals(Test.MATCH, customPresetsList.size(), testPresetsList.size()); + assertTrue(Test.TRUE, Validator.validateStringList(customPresetsList, testPresetsList)); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Show.KEY_MAIN_FIELD_1), cmd.getMainField1()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Show.KEY_MAIN_FIELD_2), cmd.getMainField2()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Show.KEY_MAIN_FIELD_3), cmd.getMainField3()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Show.KEY_MAIN_FIELD_4), cmd.getMainField4()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Show.KEY_STATUS_BAR), cmd.getStatusBar()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Show.KEY_ALIGNMENT), cmd.getAlignment().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Show.KEY_MEDIA_TRACK), cmd.getMediaTrack()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Show.KEY_METADATA_TAGS), cmd.getMetadataTags()); + + JSONObject secondaryGraphic = JsonUtils.readJsonObjectFromJsonObject(parameters, Show.KEY_SECONDARY_GRAPHIC); + Image referenceSecondaryGraphic = new Image(JsonRPCMarshaller.deserializeJSONObject(secondaryGraphic)); + assertTrue(Test.TRUE, Validator.validateImage(referenceSecondaryGraphic, cmd.getSecondaryGraphic())); + + JSONArray softButtonArray = JsonUtils.readJsonArrayFromJsonObject(parameters, Show.KEY_SOFT_BUTTONS); + List<SoftButton> softButtonList = new ArrayList<SoftButton>(); + for (int index = 0; index < softButtonArray.length(); index++) { + SoftButton chunk = new SoftButton(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)softButtonArray.get(index)) ); + softButtonList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateSoftButtons(softButtonList, cmd.getSoftButtons())); + + } 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/requests/SliderTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SliderTests.java new file mode 100644 index 000000000..7c53681b9 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SliderTests.java @@ -0,0 +1,129 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Slider; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.Slider} + */ +public class SliderTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + Slider msg = new Slider(); + + msg.setNumTicks(Test.GENERAL_INT); + msg.setPosition(Test.GENERAL_INT); + msg.setTimeout(Test.GENERAL_INT); + msg.setSliderHeader(Test.GENERAL_STRING); + msg.setSliderFooter(Test.GENERAL_STRING_LIST); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SLIDER.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(Slider.KEY_SLIDER_HEADER, Test.GENERAL_STRING); + result.put(Slider.KEY_SLIDER_FOOTER, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + result.put(Slider.KEY_POSITION, Test.GENERAL_INT); + result.put(Slider.KEY_TIMEOUT, Test.GENERAL_INT); + result.put(Slider.KEY_NUM_TICKS, Test.GENERAL_INT); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer testNumTicks = ( (Slider) msg ).getNumTicks(); + Integer testTimeout = ( (Slider) msg ).getTimeout(); + Integer testPosition = ( (Slider) msg ).getPosition(); + String testSlider = ( (Slider) msg ).getSliderHeader(); + List<String> testFooter = ( (Slider) msg ).getSliderFooter(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, testNumTicks); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, testTimeout); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, testPosition); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testSlider); + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, testFooter)); + + // Invalid/Null Tests + Slider msg = new Slider(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSliderHeader()); + assertNull(Test.NULL, msg.getSliderFooter()); + assertNull(Test.NULL, msg.getPosition()); + assertNull(Test.NULL, msg.getTimeout()); + assertNull(Test.NULL, msg.getNumTicks()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + Slider cmd = new Slider(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, Slider.KEY_NUM_TICKS), cmd.getNumTicks()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, Slider.KEY_SLIDER_HEADER), cmd.getSliderHeader()); + + List<String> sliderFooterList = JsonUtils.readStringListFromJsonObject(parameters, Slider.KEY_SLIDER_FOOTER); + List<String> testFooterList = cmd.getSliderFooter(); + assertEquals(Test.MATCH, sliderFooterList.size(), testFooterList.size()); + assertTrue(Test.TRUE, Validator.validateStringList(sliderFooterList, testFooterList)); + + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, Slider.KEY_POSITION), cmd.getPosition()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, Slider.KEY_TIMEOUT), cmd.getTimeout()); + } + 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/requests/SpeakTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SpeakTests.java new file mode 100644 index 000000000..2051b99f2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SpeakTests.java @@ -0,0 +1,105 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.Speak; +import com.smartdevicelink.proxy.rpc.TTSChunk; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +public class SpeakTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + Speak msg = new Speak(); + + msg.setTtsChunks(Test.GENERAL_TTSCHUNK_LIST); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SPEAK.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(Speak.KEY_TTS_CHUNKS, Test.JSON_TTSCHUNKS); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<TTSChunk> copy = ( (Speak) msg ).getTtsChunks(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateTtsChunks(Test.GENERAL_TTSCHUNK_LIST, copy)); + + // Invalid/Null Tests + Speak msg = new Speak(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.MATCH, msg.getTtsChunks()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + Speak cmd = new Speak(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONArray ttsChunkArray = JsonUtils.readJsonArrayFromJsonObject(parameters, Speak.KEY_TTS_CHUNKS); + List<TTSChunk> ttsChunkList = new ArrayList<TTSChunk>(); + for (int index = 0; index < ttsChunkArray.length(); index++) { + TTSChunk chunk = new TTSChunk(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)ttsChunkArray.get(index)) ); + ttsChunkList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTtsChunks(ttsChunkList, cmd.getTtsChunks())); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SubscribeButtonTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SubscribeButtonTests.java new file mode 100644 index 000000000..4cb3e4b53 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SubscribeButtonTests.java @@ -0,0 +1,98 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SubscribeButton; +import com.smartdevicelink.proxy.rpc.enums.ButtonName; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SubscribeButton} + */ +public class SubscribeButtonTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SubscribeButton msg = new SubscribeButton(); + + msg.setButtonName(Test.GENERAL_BUTTONNAME); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SUBSCRIBE_BUTTON.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SubscribeButton.KEY_BUTTON_NAME, Test.GENERAL_BUTTONNAME); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ButtonName testButtonName = ( (SubscribeButton) msg ).getButtonName(); + + // Valid Tests + assertEquals("Data didn't match input data.", Test.GENERAL_BUTTONNAME, testButtonName); + + // Invalid/Null Tests + SubscribeButton msg = new SubscribeButton(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getButtonName()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SubscribeButton cmd = new SubscribeButton(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SubscribeButton.KEY_BUTTON_NAME), cmd.getButtonName().toString()); + } 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/requests/SubscribeVehicleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SubscribeVehicleDataTests.java new file mode 100644 index 000000000..ce93c52ea --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SubscribeVehicleDataTests.java @@ -0,0 +1,230 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SubscribeVehicleData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.SubscribeVehicleData} + */ +public class SubscribeVehicleDataTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SubscribeVehicleData msg = new SubscribeVehicleData(); + + msg.setSpeed(Test.GENERAL_BOOLEAN); + msg.setRpm(Test.GENERAL_BOOLEAN); + msg.setExternalTemperature(Test.GENERAL_BOOLEAN); + msg.setFuelLevel(Test.GENERAL_BOOLEAN); + msg.setPrndl(Test.GENERAL_BOOLEAN); + msg.setTirePressure(Test.GENERAL_BOOLEAN); + msg.setEngineTorque(Test.GENERAL_BOOLEAN); + msg.setEngineOilLife(Test.GENERAL_BOOLEAN); + msg.setOdometer(Test.GENERAL_BOOLEAN); + msg.setGps(Test.GENERAL_BOOLEAN); + msg.setFuelLevelState(Test.GENERAL_BOOLEAN); + msg.setInstantFuelConsumption(Test.GENERAL_BOOLEAN); + msg.setBeltStatus(Test.GENERAL_BOOLEAN); + msg.setBodyInformation(Test.GENERAL_BOOLEAN); + msg.setDeviceStatus(Test.GENERAL_BOOLEAN); + msg.setDriverBraking(Test.GENERAL_BOOLEAN); + msg.setWiperStatus(Test.GENERAL_BOOLEAN); + msg.setHeadLampStatus(Test.GENERAL_BOOLEAN); + msg.setAccPedalPosition(Test.GENERAL_BOOLEAN); + msg.setSteeringWheelAngle(Test.GENERAL_BOOLEAN); + msg.setECallInfo(Test.GENERAL_BOOLEAN); + msg.setAirbagStatus(Test.GENERAL_BOOLEAN); + msg.setEmergencyEvent(Test.GENERAL_BOOLEAN); + msg.setClusterModeStatus(Test.GENERAL_BOOLEAN); + msg.setMyKey(Test.GENERAL_BOOLEAN); + msg.setFuelRange(Test.GENERAL_BOOLEAN); + msg.setTurnSignal(Test.GENERAL_BOOLEAN); + msg.setElectronicParkBrakeStatus(Test.GENERAL_BOOLEAN); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SUBSCRIBE_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SubscribeVehicleData.KEY_SPEED, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_RPM, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_EXTERNAL_TEMPERATURE, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_FUEL_LEVEL, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_PRNDL, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_TIRE_PRESSURE, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_ENGINE_TORQUE, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_ENGINE_OIL_LIFE, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_ODOMETER, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_GPS, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_FUEL_LEVEL_STATE, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_INSTANT_FUEL_CONSUMPTION, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_BELT_STATUS, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_BODY_INFORMATION, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_DEVICE_STATUS, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_DRIVER_BRAKING, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_WIPER_STATUS, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_HEAD_LAMP_STATUS, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_ACC_PEDAL_POSITION, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_STEERING_WHEEL_ANGLE, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_E_CALL_INFO, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_AIRBAG_STATUS, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_EMERGENCY_EVENT, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_CLUSTER_MODE_STATUS, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_MY_KEY, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_FUEL_RANGE, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_TURN_SIGNAL, Test.GENERAL_BOOLEAN); + result.put(SubscribeVehicleData.KEY_ELECTRONIC_PARK_BRAKE_STATUS, Test.GENERAL_BOOLEAN); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + + // Valid Tests + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getSpeed()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getRpm()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getExternalTemperature()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getFuelLevel()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getPrndl()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getTirePressure()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getEngineTorque()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getEngineOilLife()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getOdometer()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getGps()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getFuelLevelState()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getInstantFuelConsumption()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getBeltStatus()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getBodyInformation()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getDeviceStatus()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getDriverBraking()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getWiperStatus()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getHeadLampStatus()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getAccPedalPosition()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getSteeringWheelAngle()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getECallInfo()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getAirbagStatus()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getEmergencyEvent()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getClusterModeStatus()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getMyKey()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getFuelRange()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getTurnSignal()); + assertTrue(Test.MATCH,( (SubscribeVehicleData) msg ).getElectronicParkBrakeStatus()); + + // Invalid/Null Tests + SubscribeVehicleData msg = new SubscribeVehicleData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAccPedalPosition()); + assertNull(Test.NULL, msg.getAirbagStatus()); + assertNull(Test.NULL, msg.getBeltStatus()); + assertNull(Test.NULL, msg.getDriverBraking()); + assertNull(Test.NULL, msg.getFuelLevel()); + assertNull(Test.NULL, msg.getTirePressure()); + assertNull(Test.NULL, msg.getWiperStatus()); + assertNull(Test.NULL, msg.getGps()); + assertNull(Test.NULL, msg.getSpeed()); + assertNull(Test.NULL, msg.getRpm()); + assertNull(Test.NULL, msg.getFuelLevelState()); + assertNull(Test.NULL, msg.getInstantFuelConsumption()); + assertNull(Test.NULL, msg.getExternalTemperature()); + assertNull(Test.NULL, msg.getPrndl()); + assertNull(Test.NULL, msg.getOdometer()); + assertNull(Test.NULL, msg.getBodyInformation()); + assertNull(Test.NULL, msg.getDeviceStatus()); + assertNull(Test.NULL, msg.getHeadLampStatus()); + assertNull(Test.NULL, msg.getEngineTorque()); + assertNull(Test.NULL, msg.getEngineOilLife()); + assertNull(Test.NULL, msg.getSteeringWheelAngle()); + assertNull(Test.NULL, msg.getECallInfo()); + assertNull(Test.NULL, msg.getEmergencyEvent()); + assertNull(Test.NULL, msg.getClusterModeStatus()); + assertNull(Test.NULL, msg.getMyKey()); + assertNull(Test.NULL, msg.getFuelRange()); + assertNull(Test.NULL, msg.getTurnSignal()); + assertNull(Test.NULL, msg.getElectronicParkBrakeStatus()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SubscribeVehicleData cmd = new SubscribeVehicleData(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_SPEED), cmd.getSpeed()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_RPM), cmd.getRpm()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_EXTERNAL_TEMPERATURE), cmd.getExternalTemperature()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_FUEL_LEVEL), cmd.getFuelLevel()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_PRNDL), cmd.getPrndl()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_TIRE_PRESSURE), cmd.getTirePressure()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_ENGINE_TORQUE), cmd.getEngineTorque()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_ENGINE_OIL_LIFE), cmd.getEngineOilLife()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_ODOMETER), cmd.getOdometer()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_GPS), cmd.getGps()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_FUEL_LEVEL_STATE), cmd.getFuelLevelState()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_INSTANT_FUEL_CONSUMPTION), cmd.getInstantFuelConsumption()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_BELT_STATUS), cmd.getBeltStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_BODY_INFORMATION), cmd.getBodyInformation()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_DEVICE_STATUS), cmd.getDeviceStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_DRIVER_BRAKING), cmd.getDriverBraking()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_WIPER_STATUS), cmd.getWiperStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_HEAD_LAMP_STATUS), cmd.getHeadLampStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_ACC_PEDAL_POSITION), cmd.getAccPedalPosition()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_STEERING_WHEEL_ANGLE), cmd.getSteeringWheelAngle()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_E_CALL_INFO), cmd.getECallInfo()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_AIRBAG_STATUS), cmd.getAirbagStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_EMERGENCY_EVENT), cmd.getEmergencyEvent()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_CLUSTER_MODE_STATUS), cmd.getClusterModeStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_MY_KEY), cmd.getMyKey()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_FUEL_RANGE), cmd.getFuelRange()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_TURN_SIGNAL), cmd.getTurnSignal()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, SubscribeVehicleData.KEY_ELECTRONIC_PARK_BRAKE_STATUS), cmd.getElectronicParkBrakeStatus()); + } 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/requests/SubscribeWayPointsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SubscribeWayPointsTests.java new file mode 100644 index 000000000..06b6ee330 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SubscribeWayPointsTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SubscribeWayPoints; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class SubscribeWayPointsTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage() { + return new SubscribeWayPoints(); + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SUBSCRIBE_WAY_POINTS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SubscribeWayPoints msg = new SubscribeWayPoints(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SubscribeWayPoints cmd = new SubscribeWayPoints(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SystemRequestTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SystemRequestTests.java new file mode 100644 index 000000000..9ca720198 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/SystemRequestTests.java @@ -0,0 +1,123 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SystemRequest; +import com.smartdevicelink.proxy.rpc.enums.RequestType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SystemRequest} + */ +public class SystemRequestTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SystemRequest msg = new SystemRequest(); + + msg.setLegacyData(Test.GENERAL_STRING_LIST); + msg.setFileName(Test.GENERAL_STRING); + msg.setRequestType(Test.GENERAL_REQUESTTYPE); + msg.setRequestSubType(Test.GENERAL_STRING); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.SYSTEM_REQUEST.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SystemRequest.KEY_DATA, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + result.put(SystemRequest.KEY_FILE_NAME, Test.GENERAL_STRING); + result.put(SystemRequest.KEY_REQUEST_TYPE, Test.GENERAL_REQUESTTYPE); + result.put(SystemRequest.KEY_REQUEST_SUB_TYPE, Test.GENERAL_STRING); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + RequestType testRequestType = ( (SystemRequest) msg ).getRequestType(); + String testRequestSubType = ( (SystemRequest) msg ).getRequestSubType(); + String testFileName = ( (SystemRequest) msg ).getFileName(); + List<String> testLegacyData = ( (SystemRequest) msg ).getLegacyData(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_REQUESTTYPE, testRequestType); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testRequestSubType); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testFileName); + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, testLegacyData)); + + // Invalid/Null Tests + SystemRequest msg = new SystemRequest(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getLegacyData()); + assertNull(Test.NULL, msg.getFileName()); + assertNull(Test.NULL, msg.getRequestType()); + assertNull(Test.NULL, msg.getRequestSubType()); + assertNull(Test.NULL, msg.getBulkData()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SystemRequest cmd = new SystemRequest(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SystemRequest.KEY_FILE_NAME), cmd.getFileName()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SystemRequest.KEY_REQUEST_TYPE), cmd.getRequestType().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, SystemRequest.KEY_REQUEST_SUB_TYPE), cmd.getRequestSubType()); + + List<String> dataList = JsonUtils.readStringListFromJsonObject(parameters, SystemRequest.KEY_DATA); + List<String> testDataList = cmd.getLegacyData(); + assertEquals(Test.MATCH, dataList.size(), testDataList.size()); + assertTrue(Test.TRUE, Validator.validateStringList(dataList, testDataList)); + } 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/requests/UnregisterAppInterfaceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnregisterAppInterfaceTests.java new file mode 100644 index 000000000..84607ee98 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnregisterAppInterfaceTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnregisterAppInterface; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.UnregisterAppInterface} + */ +public class UnregisterAppInterfaceTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new UnregisterAppInterface(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.UNREGISTER_APP_INTERFACE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + UnregisterAppInterface msg = new UnregisterAppInterface(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnregisterAppInterface cmd = new UnregisterAppInterface(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } + 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/requests/UnsubscribeButtonTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnsubscribeButtonTests.java new file mode 100644 index 000000000..789c8758a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnsubscribeButtonTests.java @@ -0,0 +1,100 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnsubscribeButton; +import com.smartdevicelink.proxy.rpc.enums.ButtonName; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.UnsubscribeButton} + */ +public class UnsubscribeButtonTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + UnsubscribeButton msg = new UnsubscribeButton(); + + msg.setButtonName(Test.GENERAL_BUTTONNAME); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.UNSUBSCRIBE_BUTTON.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(UnsubscribeButton.KEY_BUTTON_NAME, Test.GENERAL_BUTTONNAME); + + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ButtonName testButtonName = ( (UnsubscribeButton) msg ).getButtonName(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BUTTONNAME, testButtonName); + + // Invalid/Null Tests + UnsubscribeButton msg = new UnsubscribeButton(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getButtonName()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnsubscribeButton cmd = new UnsubscribeButton(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, UnsubscribeButton.KEY_BUTTON_NAME), cmd.getButtonName().toString()); + } + catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnsubscribeVehicleDataTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnsubscribeVehicleDataTests.java new file mode 100644 index 000000000..af8560410 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnsubscribeVehicleDataTests.java @@ -0,0 +1,231 @@ +package com.smartdevicelink.test.rpc.requests; + + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnsubscribeVehicleData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.UnsubscribeVehicleData} + */ +public class UnsubscribeVehicleDataTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + UnsubscribeVehicleData msg = new UnsubscribeVehicleData(); + + msg.setSpeed(Test.GENERAL_BOOLEAN); + msg.setRpm(Test.GENERAL_BOOLEAN); + msg.setExternalTemperature(Test.GENERAL_BOOLEAN); + msg.setFuelLevel(Test.GENERAL_BOOLEAN); + msg.setPrndl(Test.GENERAL_BOOLEAN); + msg.setTirePressure(Test.GENERAL_BOOLEAN); + msg.setEngineTorque(Test.GENERAL_BOOLEAN); + msg.setEngineOilLife(Test.GENERAL_BOOLEAN); + msg.setOdometer(Test.GENERAL_BOOLEAN); + msg.setGps(Test.GENERAL_BOOLEAN); + msg.setFuelLevelState(Test.GENERAL_BOOLEAN); + msg.setInstantFuelConsumption(Test.GENERAL_BOOLEAN); + msg.setBeltStatus(Test.GENERAL_BOOLEAN); + msg.setBodyInformation(Test.GENERAL_BOOLEAN); + msg.setDeviceStatus(Test.GENERAL_BOOLEAN); + msg.setDriverBraking(Test.GENERAL_BOOLEAN); + msg.setWiperStatus(Test.GENERAL_BOOLEAN); + msg.setHeadLampStatus(Test.GENERAL_BOOLEAN); + msg.setAccPedalPosition(Test.GENERAL_BOOLEAN); + msg.setSteeringWheelAngle(Test.GENERAL_BOOLEAN); + msg.setECallInfo(Test.GENERAL_BOOLEAN); + msg.setAirbagStatus(Test.GENERAL_BOOLEAN); + msg.setEmergencyEvent(Test.GENERAL_BOOLEAN); + msg.setClusterModeStatus(Test.GENERAL_BOOLEAN); + msg.setMyKey(Test.GENERAL_BOOLEAN); + msg.setFuelRange(Test.GENERAL_BOOLEAN); + msg.setTurnSignal(Test.GENERAL_BOOLEAN); + msg.setElectronicParkBrakeStatus(Test.GENERAL_BOOLEAN); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.UNSUBSCRIBE_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(UnsubscribeVehicleData.KEY_SPEED, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_RPM, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_EXTERNAL_TEMPERATURE, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_FUEL_LEVEL, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_PRNDL, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_TIRE_PRESSURE, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_ENGINE_TORQUE, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_ENGINE_OIL_LIFE, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_ODOMETER, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_GPS, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_FUEL_LEVEL_STATE, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_INSTANT_FUEL_CONSUMPTION, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_BELT_STATUS, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_BODY_INFORMATION, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_DEVICE_STATUS, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_DRIVER_BRAKING, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_WIPER_STATUS, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_HEAD_LAMP_STATUS, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_ACC_PEDAL_POSITION, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_STEERING_WHEEL_ANGLE, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_E_CALL_INFO, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_AIRBAG_STATUS, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_EMERGENCY_EVENT, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_CLUSTER_MODE_STATUS, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_MY_KEY, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_FUEL_RANGE, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_TURN_SIGNAL, Test.GENERAL_BOOLEAN); + result.put(UnsubscribeVehicleData.KEY_ELECTRONIC_PARK_BRAKE_STATUS, Test.GENERAL_BOOLEAN); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues(){ + // Valid Tests + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getSpeed()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getRpm()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getExternalTemperature()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getFuelLevel()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getPrndl()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getTirePressure()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getEngineTorque()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getEngineOilLife()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getOdometer()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getGps()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getFuelLevelState()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getInstantFuelConsumption()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getBeltStatus()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getBodyInformation()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getDeviceStatus()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getDriverBraking()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getWiperStatus()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getHeadLampStatus()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getAccPedalPosition()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getSteeringWheelAngle()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getECallInfo()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getAirbagStatus()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getEmergencyEvent()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getClusterModeStatus()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getMyKey()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getFuelRange()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getTurnSignal()); + assertTrue(Test.TRUE,( (UnsubscribeVehicleData) msg ).getElectronicParkBrakeStatus()); + + // Invalid/Null Tests + UnsubscribeVehicleData msg = new UnsubscribeVehicleData(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAccPedalPosition()); + assertNull(Test.NULL, msg.getAirbagStatus()); + assertNull(Test.NULL, msg.getBeltStatus()); + assertNull(Test.NULL, msg.getDriverBraking()); + assertNull(Test.NULL, msg.getFuelLevel()); + assertNull(Test.NULL, msg.getTirePressure()); + assertNull(Test.NULL, msg.getWiperStatus()); + assertNull(Test.NULL, msg.getGps()); + assertNull(Test.NULL, msg.getSpeed()); + assertNull(Test.NULL, msg.getRpm()); + assertNull(Test.NULL, msg.getFuelLevelState()); + assertNull(Test.NULL, msg.getInstantFuelConsumption()); + assertNull(Test.NULL, msg.getExternalTemperature()); + assertNull(Test.NULL, msg.getPrndl()); + assertNull(Test.NULL, msg.getOdometer()); + assertNull(Test.NULL, msg.getBodyInformation()); + assertNull(Test.NULL, msg.getDeviceStatus()); + assertNull(Test.NULL, msg.getHeadLampStatus()); + assertNull(Test.NULL, msg.getEngineTorque()); + assertNull(Test.NULL, msg.getEngineOilLife()); + assertNull(Test.NULL, msg.getSteeringWheelAngle()); + assertNull(Test.NULL, msg.getECallInfo()); + assertNull(Test.NULL, msg.getEmergencyEvent()); + assertNull(Test.NULL, msg.getClusterModeStatus()); + assertNull(Test.NULL, msg.getMyKey()); + assertNull(Test.NULL, msg.getFuelRange()); + assertNull(Test.NULL, msg.getTurnSignal()); + assertNull(Test.NULL, msg.getElectronicParkBrakeStatus()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnsubscribeVehicleData cmd = new UnsubscribeVehicleData(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_SPEED), cmd.getSpeed()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_RPM), cmd.getRpm()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_EXTERNAL_TEMPERATURE), cmd.getExternalTemperature()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_FUEL_LEVEL), cmd.getFuelLevel()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_PRNDL), cmd.getPrndl()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_TIRE_PRESSURE), cmd.getTirePressure()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_ENGINE_TORQUE), cmd.getEngineTorque()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_ENGINE_OIL_LIFE), cmd.getEngineOilLife()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_ODOMETER), cmd.getOdometer()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_GPS), cmd.getGps()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_FUEL_LEVEL_STATE), cmd.getFuelLevelState()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_INSTANT_FUEL_CONSUMPTION), cmd.getInstantFuelConsumption()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_BELT_STATUS), cmd.getBeltStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_BODY_INFORMATION), cmd.getBodyInformation()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_DEVICE_STATUS), cmd.getDeviceStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_DRIVER_BRAKING), cmd.getDriverBraking()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_WIPER_STATUS), cmd.getWiperStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_HEAD_LAMP_STATUS), cmd.getHeadLampStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_ACC_PEDAL_POSITION), cmd.getAccPedalPosition()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_STEERING_WHEEL_ANGLE), cmd.getSteeringWheelAngle()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_E_CALL_INFO), cmd.getECallInfo()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_AIRBAG_STATUS), cmd.getAirbagStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_EMERGENCY_EVENT), cmd.getEmergencyEvent()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_CLUSTER_MODE_STATUS), cmd.getClusterModeStatus()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_MY_KEY), cmd.getMyKey()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_FUEL_RANGE), cmd.getFuelRange()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_TURN_SIGNAL), cmd.getTurnSignal()); + assertEquals(Test.MATCH, JsonUtils.readBooleanFromJsonObject(parameters, UnsubscribeVehicleData.KEY_ELECTRONIC_PARK_BRAKE_STATUS), cmd.getElectronicParkBrakeStatus()); + } + 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/requests/UnsubscribeWayPointsTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnsubscribeWayPointsTests.java new file mode 100644 index 000000000..ac4afbbea --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UnsubscribeWayPointsTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.requests; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnsubscribeWayPoints; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class UnsubscribeWayPointsTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage() { + return new UnsubscribeWayPoints(); + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType() { + return FunctionID.UNSUBSCRIBE_WAY_POINTS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + UnsubscribeWayPoints msg = new UnsubscribeWayPoints(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnsubscribeWayPoints cmd = new UnsubscribeWayPoints(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UpdateTurnListTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UpdateTurnListTests.java new file mode 100644 index 000000000..f600e559b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/requests/UpdateTurnListTests.java @@ -0,0 +1,125 @@ +package com.smartdevicelink.test.rpc.requests; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SoftButton; +import com.smartdevicelink.proxy.rpc.Turn; +import com.smartdevicelink.proxy.rpc.UpdateTurnList; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.UpdateTurnList} + */ +public class UpdateTurnListTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + UpdateTurnList msg = new UpdateTurnList(); + + msg.setTurnList(Test.GENERAL_TURN_LIST); + msg.setSoftButtons(Test.GENERAL_SOFTBUTTON_LIST); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_REQUEST; + } + + @Override + protected String getCommandType(){ + return FunctionID.UPDATE_TURN_LIST.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(UpdateTurnList.KEY_SOFT_BUTTONS, Test.JSON_SOFTBUTTONS); + result.put(UpdateTurnList.KEY_TURN_LIST, Test.JSON_TURNS); + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<SoftButton> testSoftButtonList = ( (UpdateTurnList) msg ).getSoftButtons(); + List<Turn> testTurnList = ( (UpdateTurnList) msg ).getTurnList(); + + // Valid Tests + assertNotNull(Test.NOT_NULL, testSoftButtonList); + assertNotNull(Test.NOT_NULL, testTurnList); + + assertTrue(Test.TRUE, Validator.validateSoftButtons(Test.GENERAL_SOFTBUTTON_LIST, testSoftButtonList)); + assertTrue(Test.TRUE, Validator.validateTurnList(Test.GENERAL_TURN_LIST, testTurnList)); + + // Invalid/Null Tests + UpdateTurnList msg = new UpdateTurnList(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getTurnList()); + assertNull(Test.NULL, msg.getSoftButtons()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UpdateTurnList cmd = new UpdateTurnList(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + JSONArray softButtonArray = JsonUtils.readJsonArrayFromJsonObject(parameters, UpdateTurnList.KEY_SOFT_BUTTONS); + List<SoftButton> softButtonList = new ArrayList<SoftButton>(); + for (int index = 0; index < softButtonArray.length(); index++) { + SoftButton chunk = new SoftButton(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)softButtonArray.get(index)) ); + softButtonList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateSoftButtons(softButtonList, cmd.getSoftButtons())); + + JSONArray turnArray = JsonUtils.readJsonArrayFromJsonObject(parameters, UpdateTurnList.KEY_TURN_LIST); + List<Turn> turnList = new ArrayList<Turn>(); + for (int index = 0; index < turnArray.length(); index++) { + Turn chunk = new Turn(JsonRPCMarshaller.deserializeJSONObject((JSONObject) turnArray.get(index))); + if (chunk != null) + turnList.add(chunk); + } + assertTrue(Test.TRUE, Validator.validateTurnList(turnList, cmd.getTurnList())); + } 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/responses/AddCommandResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AddCommandResponseTests.java new file mode 100644 index 000000000..efde2292d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AddCommandResponseTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AddCommand; +import com.smartdevicelink.proxy.rpc.AddCommandResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AddCommandResponse} + */ +public class AddCommandResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new AddCommandResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.ADD_COMMAND.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + AddCommandResponse msg = new AddCommandResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + AddCommand cmd = new AddCommand(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AddSubmenuResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AddSubmenuResponseTests.java new file mode 100644 index 000000000..2a3888de7 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AddSubmenuResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AddSubMenuResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AddSubmenuResponse} + */ +public class AddSubmenuResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new AddSubMenuResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.ADD_SUB_MENU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + AddSubMenuResponse msg = new AddSubMenuResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + AddSubMenuResponse cmd = new AddSubMenuResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertManeuverResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertManeuverResponseTests.java new file mode 100644 index 000000000..64b3ff5f3 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertManeuverResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AlertManeuverResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AlertManeuverResponse} + */ +public class AlertManeuverResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + return new AlertManeuverResponse(); + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.ALERT_MANEUVER.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + AlertManeuverResponse msg = new AlertManeuverResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + AlertManeuverResponse cmd = new AlertManeuverResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java new file mode 100644 index 000000000..a479da245 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/AlertResponseTests.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AlertResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.AlertResponse} + */ +public class AlertResponseTests extends BaseRpcTests{ + + private static final int TRY_AGAIN_TIME = 400; + + @Override + protected RPCMessage createMessage(){ + AlertResponse alert = new AlertResponse(); + alert.setTryAgainTime(TRY_AGAIN_TIME); + return alert; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.ALERT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(AlertResponse.KEY_TRY_AGAIN_TIME, TRY_AGAIN_TIME); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int tryAgainTime = ( (AlertResponse) msg ).getTryAgainTime(); + + // Valid Tests + assertEquals(Test.MATCH, TRY_AGAIN_TIME, tryAgainTime); + + // Invalid/Null Tests + AlertResponse msg = new AlertResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getTryAgainTime()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + AlertResponse cmd = new AlertResponse(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, AlertResponse.KEY_TRY_AGAIN_TIME), cmd.getTryAgainTime()); + + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ButtonPressResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ButtonPressResponseTest.java new file mode 100644 index 000000000..64f5b0c75 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ButtonPressResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ButtonPressResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ButtonPressResponse} + */ +public class ButtonPressResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new ButtonPressResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.BUTTON_PRESS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + ButtonPressResponse msg = new ButtonPressResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ButtonPressResponse cmd = new ButtonPressResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ChangeRegistrationResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ChangeRegistrationResponseTests.java new file mode 100644 index 000000000..906533bfd --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ChangeRegistrationResponseTests.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ChangeRegistrationResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ChangeRegistrationResponse} + */ +public class ChangeRegistrationResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new ChangeRegistrationResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.CHANGE_REGISTRATION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + ChangeRegistrationResponse msg = new ChangeRegistrationResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ChangeRegistrationResponse cmd = new ChangeRegistrationResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/CreateInteractionChoiceSetResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/CreateInteractionChoiceSetResponseTests.java new file mode 100644 index 000000000..f492d0458 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/CreateInteractionChoiceSetResponseTests.java @@ -0,0 +1,47 @@ +package com.smartdevicelink.test.rpc.responses; + +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSetResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.CreateInteractionChoiceSetResponse} + */ +public class CreateInteractionChoiceSetResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new CreateInteractionChoiceSetResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.CREATE_INTERACTION_CHOICE_SET.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + CreateInteractionChoiceSetResponse msg = new CreateInteractionChoiceSetResponse(); + assertNotNull(Test.NOT_NULL, msg); + + testNullBase(msg); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteCommandResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteCommandResponseTests.java new file mode 100644 index 000000000..f40dbc895 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteCommandResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeleteCommandResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeleteCommandResponse} + */ +public class DeleteCommandResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new DeleteCommandResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.DELETE_COMMAND.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + DeleteCommandResponse msg = new DeleteCommandResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DeleteCommandResponse cmd = new DeleteCommandResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteFileResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteFileResponseTests.java new file mode 100644 index 000000000..2c4ecb01f --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteFileResponseTests.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeleteFileResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.DeleteFileResponse} + */ +public class DeleteFileResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + DeleteFileResponse msg = new DeleteFileResponse(); + + msg.setSpaceAvailable(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.DELETE_FILE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(DeleteFileResponse.KEY_SPACE_AVAILABLE, Test.GENERAL_INT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + int spaceAvailable = ( (DeleteFileResponse) msg ).getSpaceAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INT, spaceAvailable); + + // Invalid/Null Tests + DeleteFileResponse msg = new DeleteFileResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSpaceAvailable()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DeleteFileResponse cmd = new DeleteFileResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, DeleteFileResponse.KEY_SPACE_AVAILABLE), cmd.getSpaceAvailable()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteInteractionChoiceSetResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteInteractionChoiceSetResponseTests.java new file mode 100644 index 000000000..e1b6233c0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteInteractionChoiceSetResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSetResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeleteInteractionChoiceSetResponse} + */ +public class DeleteInteractionChoiceSetResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new DeleteInteractionChoiceSetResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.DELETE_INTERACTION_CHOICE_SET.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + DeleteInteractionChoiceSetResponse msg = new DeleteInteractionChoiceSetResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DeleteInteractionChoiceSetResponse cmd = new DeleteInteractionChoiceSetResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteSubMenuResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteSubMenuResponseTests.java new file mode 100644 index 000000000..46fea52e0 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DeleteSubMenuResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DeleteSubMenuResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DeleteSubMenuResponse} + */ +public class DeleteSubMenuResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new DeleteSubMenuResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.DELETE_SUB_MENU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + DeleteSubMenuResponse msg = new DeleteSubMenuResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DeleteSubMenuResponse cmd = new DeleteSubMenuResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DiagnosticMessageResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DiagnosticMessageResponseTests.java new file mode 100644 index 000000000..2732d79b2 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DiagnosticMessageResponseTests.java @@ -0,0 +1,110 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DiagnosticMessageResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.DiagnosticMessageResponse} + */ +public class DiagnosticMessageResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + DiagnosticMessageResponse msg = new DiagnosticMessageResponse(); + + msg.setMessageDataResult(Test.GENERAL_INTEGER_LIST); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.DIAGNOSTIC_MESSAGE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(DiagnosticMessageResponse.KEY_MESSAGE_DATA_RESULT, + JsonUtils.createJsonArray(Test.GENERAL_INTEGER_LIST)); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<Integer> cmdId = ( (DiagnosticMessageResponse) msg ).getMessageDataResult(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INTEGER_LIST.size(), cmdId.size()); + + for(int i = 0; i < Test.GENERAL_INTEGER_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_INTEGER_LIST.get(i), cmdId.get(i)); + } + + // Invalid/Null Tests + DiagnosticMessageResponse msg = new DiagnosticMessageResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getMessageDataResult()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DiagnosticMessageResponse cmd = new DiagnosticMessageResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + List<Integer> dataResultList = JsonUtils.readIntegerListFromJsonObject(parameters, DiagnosticMessageResponse.KEY_MESSAGE_DATA_RESULT); + List<Integer> testResultList = cmd.getMessageDataResult(); + + assertEquals(Test.MATCH, dataResultList.size(), testResultList.size()); + assertTrue(Test.TRUE, Validator.validateIntegerList(dataResultList, testResultList)); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DialNumberResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DialNumberResponseTests.java new file mode 100644 index 000000000..bf625f19a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/DialNumberResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DialNumberResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * Created by austinkirk on 6/6/17. + */ + +public class DialNumberResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + return new DialNumberResponse(); + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.DIAL_NUMBER.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + DialNumberResponse msg = new DialNumberResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + DialNumberResponse cmd = new DialNumberResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/EndAudioPassThruResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/EndAudioPassThruResponseTests.java new file mode 100644 index 000000000..c50e39569 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/EndAudioPassThruResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.EndAudioPassThruResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.EndAudioPassThruResponse} + */ +public class EndAudioPassThruResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new EndAudioPassThruResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.END_AUDIO_PASS_THRU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + EndAudioPassThruResponse msg = new EndAudioPassThruResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + EndAudioPassThruResponse cmd = new EndAudioPassThruResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GenericResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GenericResponseTests.java new file mode 100644 index 000000000..f80c6201b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GenericResponseTests.java @@ -0,0 +1,46 @@ +package com.smartdevicelink.test.rpc.responses; + +import org.json.JSONObject; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GenericResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.GenericResponse} + */ +public class GenericResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return new GenericResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.GENERIC_RESPONSE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + GenericResponse msg = new GenericResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetAppServiceDataResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetAppServiceDataResponseTests.java new file mode 100644 index 000000000..08a8f6536 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetAppServiceDataResponseTests.java @@ -0,0 +1,85 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AppServiceData; +import com.smartdevicelink.proxy.rpc.GetAppServiceDataResponse; +import com.smartdevicelink.proxy.rpc.enums.Result; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.GetAppServiceDataResponse} + */ +public class GetAppServiceDataResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new GetAppServiceDataResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_APP_SERVICE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + GetAppServiceDataResponse msg = new GetAppServiceDataResponse(); + msg.setServiceData(Test.GENERAL_APPSERVICE_DATA); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + // test getter + AppServiceData serviceData = msg.getServiceData(); + assertEquals(Test.GENERAL_APPSERVICE_DATA, serviceData); + + // test constructor + msg = new GetAppServiceDataResponse(true, Result.SUCCESS, Test.GENERAL_APPSERVICE_DATA); + serviceData = msg.getServiceData(); + assertEquals(Test.GENERAL_APPSERVICE_DATA, serviceData); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetAppServiceDataResponse cmd = new GetAppServiceDataResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetCloudAppPropertiesResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetCloudAppPropertiesResponseTests.java new file mode 100644 index 000000000..e082c82f9 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetCloudAppPropertiesResponseTests.java @@ -0,0 +1,42 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetCloudAppPropertiesResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONObject; + +public class GetCloudAppPropertiesResponseTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage(){ + return new GetCloudAppPropertiesResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_CLOUD_APP_PROPERTIES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + GetCloudAppPropertiesResponse msg = new GetCloudAppPropertiesResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetDTCsResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetDTCsResponseTests.java new file mode 100644 index 000000000..0a82ccd75 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetDTCsResponseTests.java @@ -0,0 +1,108 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetDTCsResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.GetDTCsResponse} + */ +public class GetDTCsResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + GetDTCsResponse msg = new GetDTCsResponse(); + + msg.setDtc(Test.GENERAL_STRING_LIST); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_DTCS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetDTCsResponse.KEY_DTC, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<String> cmdId = ( (GetDTCsResponse) msg ).getDtc(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.size(), cmdId.size()); + + for(int i = 0; i < Test.GENERAL_STRING_LIST.size(); i++){ + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.get(i), cmdId.get(i)); + } + + // Invalid/Null Tests + GetDTCsResponse msg = new GetDTCsResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getDtc()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetDTCsResponse cmd = new GetDTCsResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + List<String> dtcList = JsonUtils.readStringListFromJsonObject(parameters, GetDTCsResponse.KEY_DTC); + List<String> testDtcList = cmd.getDtc(); + assertEquals(Test.MATCH, dtcList.size(), testDtcList.size()); + assertTrue(Test.TRUE, Validator.validateStringList(dtcList, testDtcList)); + + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetFileResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetFileResponseTests.java new file mode 100644 index 000000000..25ba20949 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetFileResponseTests.java @@ -0,0 +1,118 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetFileResponse; +import com.smartdevicelink.proxy.rpc.enums.FileType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.GetFileResponse} + */ +public class GetFileResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + + GetFileResponse msg = new GetFileResponse(); + + msg.setCRC(Test.GENERAL_INT); + msg.setFileType(Test.GENERAL_FILETYPE); + msg.setOffset(Test.GENERAL_INT); + msg.setLength(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_FILE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetFileResponse.KEY_CRC, Test.GENERAL_INTEGER); + result.put(GetFileResponse.KEY_FILE_TYPE, Test.GENERAL_FILETYPE); + result.put(GetFileResponse.KEY_OFFSET, Test.GENERAL_INTEGER); + result.put(GetFileResponse.KEY_LENGTH, Test.GENERAL_INTEGER); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer crc = ( (GetFileResponse) msg ).getCRC(); + FileType fileType = ( (GetFileResponse) msg ).getFileType(); + Integer offset = ( (GetFileResponse) msg ).getOffset(); + Integer length = ( (GetFileResponse) msg ).getLength(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, crc); + assertEquals(Test.MATCH, Test.GENERAL_FILETYPE, fileType); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, offset); + assertEquals(Test.MATCH, Test.GENERAL_INTEGER, length); + + // Invalid/Null Tests + GetFileResponse msg = new GetFileResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getCRC()); + assertNull(Test.NULL, msg.getFileType()); + assertNull(Test.NULL, msg.getOffset()); + assertNull(Test.NULL, msg.getLength()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetFileResponse cmd = new GetFileResponse (hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetFileResponse.KEY_CRC), cmd.getCRC()); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetFileResponse.KEY_FILE_TYPE).toString(), cmd.getFileType().toString()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetFileResponse.KEY_LENGTH), cmd.getLength()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetFileResponse.KEY_OFFSET), cmd.getOffset()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataResponseTests.java new file mode 100644 index 000000000..c76388c69 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetInteriorVehicleDataResponseTests.java @@ -0,0 +1,110 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetInteriorVehicleDataResponse; +import com.smartdevicelink.proxy.rpc.ModuleData; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.GetInteriorVehicleDataResponse} + */ +public class GetInteriorVehicleDataResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + + GetInteriorVehicleDataResponse msg = new GetInteriorVehicleDataResponse(); + + msg.setIsSubscribed(Test.GENERAL_BOOLEAN); + msg.setModuleData(Test.GENERAL_MODULEDATA); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_INTERIOR_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetInteriorVehicleDataResponse.KEY_IS_SUBSCRIBED, Test.GENERAL_BOOLEAN); + result.put(GetInteriorVehicleDataResponse.KEY_MODULE_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_MODULEDATA.getStore())); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + boolean testIsSubscribed = ( (GetInteriorVehicleDataResponse) msg ).getIsSubscribed(); + ModuleData testModuleData = ( (GetInteriorVehicleDataResponse) msg ).getModuleData(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_BOOLEAN, testIsSubscribed); + assertTrue(Test.TRUE, Validator.validateModuleData(Test.GENERAL_MODULEDATA, testModuleData)); + + // Invalid/Null Tests + GetInteriorVehicleDataResponse msg = new GetInteriorVehicleDataResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getIsSubscribed()); + assertNull(Test.NULL, msg.getModuleData()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetInteriorVehicleDataResponse cmd = new GetInteriorVehicleDataResponse (hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + ModuleData testModuleData = new ModuleData(JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleDataResponse.KEY_MODULE_DATA))); + ModuleData cmdModuleData = cmd.getModuleData(); + + assertTrue(Test.TRUE, Validator.validateModuleData(testModuleData, cmdModuleData) ); + assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(parameters, GetInteriorVehicleDataResponse.KEY_IS_SUBSCRIBED), cmd.getIsSubscribed()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetSystemCapabilityResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetSystemCapabilityResponseTests.java new file mode 100644 index 000000000..b9fd85a8e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetSystemCapabilityResponseTests.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetSystemCapabilityResponse; +import com.smartdevicelink.proxy.rpc.SystemCapability; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +public class GetSystemCapabilityResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + GetSystemCapabilityResponse msg = new GetSystemCapabilityResponse(); + + msg.setSystemCapability(Test.GENERAL_SYSTEMCAPABILITY); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_SYSTEM_CAPABILITY.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetSystemCapabilityResponse.KEY_SYSTEM_CAPABILITY, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_SYSTEMCAPABILITY.getStore())); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + SystemCapability testCapability = ( (GetSystemCapabilityResponse) msg ).getSystemCapability(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_SYSTEMCAPABILITY.getSystemCapabilityType(), testCapability.getSystemCapabilityType()); + + // Invalid/Null Tests + GetSystemCapabilityResponse msg = new GetSystemCapabilityResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSystemCapability()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetSystemCapabilityResponse cmd = new GetSystemCapabilityResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + SystemCapability testCapability = new SystemCapability(JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(parameters, GetSystemCapabilityResponse.KEY_SYSTEM_CAPABILITY))); + SystemCapability cmdCapability = cmd.getSystemCapability(); + assertEquals(Test.MATCH, testCapability.getSystemCapabilityType(), cmdCapability.getSystemCapabilityType()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetVehicleDataResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetVehicleDataResponseTests.java new file mode 100644 index 000000000..2bcff82ee --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetVehicleDataResponseTests.java @@ -0,0 +1,577 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AirbagStatus; +import com.smartdevicelink.proxy.rpc.BeltStatus; +import com.smartdevicelink.proxy.rpc.BodyInformation; +import com.smartdevicelink.proxy.rpc.ClusterModeStatus; +import com.smartdevicelink.proxy.rpc.DeviceStatus; +import com.smartdevicelink.proxy.rpc.ECallInfo; +import com.smartdevicelink.proxy.rpc.EmergencyEvent; +import com.smartdevicelink.proxy.rpc.FuelRange; +import com.smartdevicelink.proxy.rpc.GPSData; +import com.smartdevicelink.proxy.rpc.GetVehicleDataResponse; +import com.smartdevicelink.proxy.rpc.HeadLampStatus; +import com.smartdevicelink.proxy.rpc.MyKey; +import com.smartdevicelink.proxy.rpc.SingleTireStatus; +import com.smartdevicelink.proxy.rpc.TireStatus; +import com.smartdevicelink.proxy.rpc.enums.TurnSignal; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.VehicleDataHelper; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.GetVehicleDataResponse} + */ +public class GetVehicleDataResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + return VehicleDataHelper.VEHICLE_DATA_RESPONSE; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.GET_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(GetVehicleDataResponse.KEY_SPEED, VehicleDataHelper.SPEED); + result.put(GetVehicleDataResponse.KEY_RPM, VehicleDataHelper.RPM); + result.put(GetVehicleDataResponse.KEY_EXTERNAL_TEMPERATURE, VehicleDataHelper.EXTERNAL_TEMPERATURE); + result.put(GetVehicleDataResponse.KEY_FUEL_LEVEL, VehicleDataHelper.FUEL_LEVEL); + result.put(GetVehicleDataResponse.KEY_VIN, VehicleDataHelper.VIN); + result.put(GetVehicleDataResponse.KEY_PRNDL, VehicleDataHelper.PRNDL_FINAL); + result.put(GetVehicleDataResponse.KEY_TIRE_PRESSURE, VehicleDataHelper.TIRE_PRESSURE.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_ENGINE_TORQUE, VehicleDataHelper.ENGINE_TORQUE); + result.put(GetVehicleDataResponse.KEY_ENGINE_OIL_LIFE, VehicleDataHelper.ENGINE_OIL_LIFE); + result.put(GetVehicleDataResponse.KEY_ODOMETER, VehicleDataHelper.ODOMETER); + result.put(GetVehicleDataResponse.KEY_GPS, VehicleDataHelper.GPS.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_FUEL_LEVEL_STATE, VehicleDataHelper.FUEL_LEVEL_STATE); + result.put(GetVehicleDataResponse.KEY_INSTANT_FUEL_CONSUMPTION, VehicleDataHelper.INSTANT_FUEL_CONSUMPTION); + result.put(GetVehicleDataResponse.KEY_BELT_STATUS, VehicleDataHelper.BELT_STATUS.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_BODY_INFORMATION, VehicleDataHelper.BODY_INFORMATION.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_DEVICE_STATUS, VehicleDataHelper.DEVICE_STATUS.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_DRIVER_BRAKING, VehicleDataHelper.DRIVER_BRAKING); + result.put(GetVehicleDataResponse.KEY_WIPER_STATUS, VehicleDataHelper.WIPER_STATUS); + result.put(GetVehicleDataResponse.KEY_HEAD_LAMP_STATUS, VehicleDataHelper.HEAD_LAMP_STATUS.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_ACC_PEDAL_POSITION, VehicleDataHelper.ACC_PEDAL_POSITION); + result.put(GetVehicleDataResponse.KEY_STEERING_WHEEL_ANGLE, VehicleDataHelper.STEERING_WHEEL_ANGLE); + result.put(GetVehicleDataResponse.KEY_E_CALL_INFO, VehicleDataHelper.E_CALL_INFO.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_AIRBAG_STATUS, VehicleDataHelper.AIRBAG_STATUS.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_EMERGENCY_EVENT, VehicleDataHelper.EMERGENCY_EVENT.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_CLUSTER_MODE_STATUS, VehicleDataHelper.CLUSTER_MODE_STATUS.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_MY_KEY, VehicleDataHelper.MY_KEY.serializeJSON()); + result.put(GetVehicleDataResponse.KEY_FUEL_RANGE, VehicleDataHelper.JSON_FUEL_RANGE); + result.put(GetVehicleDataResponse.KEY_TURN_SIGNAL, VehicleDataHelper.TURN_SIGNAL); + result.put(GetVehicleDataResponse.KEY_ELECTRONIC_PARK_BRAKE_STATUS, VehicleDataHelper.ELECTRONIC_PARK_BRAKE_STATUS); + } catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + public void testJson() { + JSONObject reference = new JSONObject(); + + //objects needed on the first level + JSONObject tireStatusObj = new JSONObject(); + JSONObject GPSDataObj = new JSONObject(); + JSONObject beltStatusObj = new JSONObject(); + JSONObject bodyInformationObj = new JSONObject(); + JSONObject deviceStatusObj = new JSONObject(); + JSONObject headLampStatusObj = new JSONObject(); + JSONObject ECallInfoObj = new JSONObject(); + JSONObject airbagStatusObj = new JSONObject(); + JSONObject emergencyEventObj = new JSONObject(); + JSONObject clusterModeStatusObj = new JSONObject(); + JSONObject myKeyObj = new JSONObject(); + JSONObject fuelRangeObj = new JSONObject(); + JSONArray fuelRangeArrayObj = new JSONArray(); + + try { + //set up the JSONObject to represent GetVehicleDataResponse + //TIRE_PRESSURE + tireStatusObj.put(TireStatus.KEY_PRESSURE_TELL_TALE, VehicleDataHelper.TIRE_PRESSURE_TELL_TALE); + JSONObject tireLeftFront = new JSONObject(); + tireLeftFront.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_LEFT_FRONT); + tireStatusObj.put(TireStatus.KEY_LEFT_FRONT, tireLeftFront); + JSONObject tireRightFront = new JSONObject(); + tireRightFront.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_RIGHT_FRONT); + tireStatusObj.put(TireStatus.KEY_RIGHT_FRONT, tireRightFront); + JSONObject tireLeftRear = new JSONObject(); + tireLeftRear.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_LEFT_REAR); + tireStatusObj.put(TireStatus.KEY_LEFT_REAR, tireLeftRear); + JSONObject tireRightRear = new JSONObject(); + tireRightRear.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_RIGHT_REAR); + tireStatusObj.put(TireStatus.KEY_RIGHT_REAR, tireRightRear); + JSONObject tireInnerLeftRear = new JSONObject(); + tireInnerLeftRear.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_INNER_LEFT_REAR); + tireStatusObj.put(TireStatus.KEY_INNER_LEFT_REAR, tireInnerLeftRear); + JSONObject tireInnerRightRear = new JSONObject(); + tireInnerRightRear.put(SingleTireStatus.KEY_STATUS, VehicleDataHelper.TIRE_PRESSURE_INNER_RIGHT_REAR); + tireStatusObj.put(TireStatus.KEY_INNER_RIGHT_REAR, tireInnerRightRear); + + //GPS + GPSDataObj.put(GPSData.KEY_LONGITUDE_DEGREES, VehicleDataHelper.GPS_LONGITUDE); + GPSDataObj.put(GPSData.KEY_LATITUDE_DEGREES, VehicleDataHelper.GPS_LATITUDE); + GPSDataObj.put(GPSData.KEY_UTC_YEAR, VehicleDataHelper.GPS_YEAR); + GPSDataObj.put(GPSData.KEY_UTC_MONTH, VehicleDataHelper.GPS_MONTH); + GPSDataObj.put(GPSData.KEY_UTC_DAY, VehicleDataHelper.GPS_DAY); + GPSDataObj.put(GPSData.KEY_UTC_HOURS, VehicleDataHelper.GPS_HOURS); + GPSDataObj.put(GPSData.KEY_UTC_MINUTES, VehicleDataHelper.GPS_MINUTES); + GPSDataObj.put(GPSData.KEY_UTC_SECONDS, VehicleDataHelper.GPS_SECONDS); + GPSDataObj.put(GPSData.KEY_COMPASS_DIRECTION, VehicleDataHelper.GPS_DIRECTION); + GPSDataObj.put(GPSData.KEY_PDOP, VehicleDataHelper.GPS_PDOP); + GPSDataObj.put(GPSData.KEY_VDOP, VehicleDataHelper.GPS_VDOP); + GPSDataObj.put(GPSData.KEY_HDOP, VehicleDataHelper.GPS_HDOP); + GPSDataObj.put(GPSData.KEY_ACTUAL, VehicleDataHelper.GPS_ACTUAL); + GPSDataObj.put(GPSData.KEY_SATELLITES, VehicleDataHelper.GPS_SATELLITES); + GPSDataObj.put(GPSData.KEY_DIMENSION, VehicleDataHelper.GPS_DIMENSION); + GPSDataObj.put(GPSData.KEY_ALTITUDE, VehicleDataHelper.GPS_ALTITUDE); + GPSDataObj.put(GPSData.KEY_HEADING, VehicleDataHelper.GPS_HEADING); + GPSDataObj.put(GPSData.KEY_SPEED, VehicleDataHelper.GPS_SPEED); + + //BELT_STATUS + beltStatusObj.put(BeltStatus.KEY_DRIVER_BELT_DEPLOYED, VehicleDataHelper.BELT_STATUS_DRIVER_DEPLOYED); + beltStatusObj.put(BeltStatus.KEY_PASSENGER_BELT_DEPLOYED, VehicleDataHelper.BELT_STATUS_PASSENGER_DEPLOYED); + beltStatusObj.put(BeltStatus.KEY_PASSENGER_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_PASSENGER_BELTED); + beltStatusObj.put(BeltStatus.KEY_DRIVER_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_DRIVER_BELTED); + beltStatusObj.put(BeltStatus.KEY_LEFT_ROW_2_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_LEFT_ROW_2_BELTED); + beltStatusObj.put(BeltStatus.KEY_PASSENGER_CHILD_DETECTED, VehicleDataHelper.BELT_STATUS_PASSENGER_CHILD); + beltStatusObj.put(BeltStatus.KEY_RIGHT_ROW_2_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_RIGHT_ROW_2_BELTED); + beltStatusObj.put(BeltStatus.KEY_MIDDLE_ROW_2_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_MIDDLE_ROW_2_BELTED); + beltStatusObj.put(BeltStatus.KEY_MIDDLE_ROW_3_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_MIDDLE_ROW_3_BELTED); + beltStatusObj.put(BeltStatus.KEY_LEFT_ROW_3_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_LEFT_ROW_3_BELTED); + beltStatusObj.put(BeltStatus.KEY_RIGHT_ROW_3_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_RIGHT_ROW_3_BELTED); + beltStatusObj.put(BeltStatus.KEY_REAR_INFLATABLE_BELTED, VehicleDataHelper.BELT_STATUS_LEFT_REAR_INFLATABLE_BELTED); + beltStatusObj.put(BeltStatus.KEY_RIGHT_REAR_INFLATABLE_BELTED, VehicleDataHelper.BELT_STATUS_RIGHT_REAR_INFLATABLE_BELTED); + beltStatusObj.put(BeltStatus.KEY_MIDDLE_ROW_1_BELT_DEPLOYED, VehicleDataHelper.BELT_STATUS_MIDDLE_ROW_1_DEPLOYED); + beltStatusObj.put(BeltStatus.KEY_MIDDLE_ROW_1_BUCKLE_BELTED, VehicleDataHelper.BELT_STATUS_MIDDLE_ROW_1_BELTED); + + //BODY_INFORMATION + bodyInformationObj.put(BodyInformation.KEY_PARK_BRAKE_ACTIVE, VehicleDataHelper.BODY_INFORMATION_PARK_BRAKE); + bodyInformationObj.put(BodyInformation.KEY_IGNITION_STABLE_STATUS, VehicleDataHelper.BODY_INFORMATION_IGNITION_STATUS); + bodyInformationObj.put(BodyInformation.KEY_IGNITION_STATUS, VehicleDataHelper.BODY_INFORMATION_IGNITION_STABLE_STATUS); + bodyInformationObj.put(BodyInformation.KEY_DRIVER_DOOR_AJAR, VehicleDataHelper.BODY_INFORMATION_DRIVER_AJAR); + bodyInformationObj.put(BodyInformation.KEY_PASSENGER_DOOR_AJAR, VehicleDataHelper.BODY_INFORMATION_PASSENGER_AJAR); + bodyInformationObj.put(BodyInformation.KEY_REAR_LEFT_DOOR_AJAR, VehicleDataHelper.BODY_INFORMATION_REAR_LEFT_AJAR); + bodyInformationObj.put(BodyInformation.KEY_REAR_RIGHT_DOOR_AJAR, VehicleDataHelper.BODY_INFORMATION_REAR_RIGHT_AJAR); + + //DEVICE_STATUS + deviceStatusObj.put(DeviceStatus.KEY_VOICE_REC_ON, VehicleDataHelper.DEVICE_STATUS_VOICE_REC); + deviceStatusObj.put(DeviceStatus.KEY_BT_ICON_ON, VehicleDataHelper.DEVICE_STATUS_BT_ICON); + deviceStatusObj.put(DeviceStatus.KEY_CALL_ACTIVE, VehicleDataHelper.DEVICE_STATUS_CALL_ACTIVE); + deviceStatusObj.put(DeviceStatus.KEY_PHONE_ROAMING, VehicleDataHelper.DEVICE_STATUS_PHONE_ROAMING); + deviceStatusObj.put(DeviceStatus.KEY_TEXT_MSG_AVAILABLE, VehicleDataHelper.DEVICE_STATUS_TEXT_MSG_AVAILABLE); + deviceStatusObj.put(DeviceStatus.KEY_BATT_LEVEL_STATUS, VehicleDataHelper.DEVICE_STATUS_BATT_LEVEL_STATUS); + deviceStatusObj.put(DeviceStatus.KEY_STEREO_AUDIO_OUTPUT_MUTED, VehicleDataHelper.DEVICE_STATUS_STEREO_MUTED); + deviceStatusObj.put(DeviceStatus.KEY_MONO_AUDIO_OUTPUT_MUTED, VehicleDataHelper.DEVICE_STATUS_MONO_MUTED); + deviceStatusObj.put(DeviceStatus.KEY_SIGNAL_LEVEL_STATUS, VehicleDataHelper.DEVICE_STATUS_SIGNAL_LEVEL_STATUS); + deviceStatusObj.put(DeviceStatus.KEY_PRIMARY_AUDIO_SOURCE, VehicleDataHelper.DEVICE_STATUS_PRIMARY_AUDIO); + deviceStatusObj.put(DeviceStatus.KEY_E_CALL_EVENT_ACTIVE, VehicleDataHelper.DEVICE_STATUS_E_CALL_ACTIVE); + + //HEAD_LAMP_STATUS + headLampStatusObj.put(HeadLampStatus.KEY_AMBIENT_LIGHT_SENSOR_STATUS, VehicleDataHelper.HEAD_LAMP_STATUS_AMBIENT_STATUS); + headLampStatusObj.put(HeadLampStatus.KEY_HIGH_BEAMS_ON, VehicleDataHelper.HEAD_LAMP_HIGH_BEAMS); + headLampStatusObj.put(HeadLampStatus.KEY_LOW_BEAMS_ON, VehicleDataHelper.HEAD_LAMP_LOW_BEAMS); + + //E_CALL_INFO + ECallInfoObj.put(ECallInfo.KEY_E_CALL_NOTIFICATION_STATUS, VehicleDataHelper.E_CALL_INFO_E_CALL_NOTIFICATION_STATUS); + ECallInfoObj.put(ECallInfo.KEY_AUX_E_CALL_NOTIFICATION_STATUS, VehicleDataHelper.E_CALL_INFO_AUX_E_CALL_NOTIFICATION_STATUS); + ECallInfoObj.put(ECallInfo.KEY_E_CALL_CONFIRMATION_STATUS, VehicleDataHelper.E_CALL_INFO_CONFIRMATION_STATUS); + + //AIRBAG_STATUS + airbagStatusObj.put(AirbagStatus.KEY_DRIVER_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_DRIVER_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_DRIVER_SIDE_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_DRIVER_SIDE_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_DRIVER_CURTAIN_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_DRIVER_CURTAIN_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_DRIVER_KNEE_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_DRIVER_KNEE_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_PASSENGER_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_PASSENGER_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_PASSENGER_SIDE_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_PASSENGER_SIDE_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_PASSENGER_CURTAIN_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_PASSENGER_CURTAIN_DEPLOYED); + airbagStatusObj.put(AirbagStatus.KEY_PASSENGER_KNEE_AIRBAG_DEPLOYED, VehicleDataHelper.AIRBAG_STATUS_PASSENGER_KNEE_DEPLOYED); + + //EMERGENCY_EVENT + emergencyEventObj.put(EmergencyEvent.KEY_EMERGENCY_EVENT_TYPE, VehicleDataHelper.EMERGENCY_EVENT_TYPE); + emergencyEventObj.put(EmergencyEvent.KEY_FUEL_CUTOFF_STATUS, VehicleDataHelper.EMERGENCY_EVENT_FUEL_CUTOFF_STATUS); + emergencyEventObj.put(EmergencyEvent.KEY_ROLLOVER_EVENT, VehicleDataHelper.EMERGENCY_EVENT_ROLLOVER_EVENT); + emergencyEventObj.put(EmergencyEvent.KEY_MAXIMUM_CHANGE_VELOCITY, VehicleDataHelper.EMERGENCY_EVENT_MAX_CHANGE_VELOCITY); + emergencyEventObj.put(EmergencyEvent.KEY_MULTIPLE_EVENTS, VehicleDataHelper.EMERGENCY_EVENT_MULTIPLE_EVENTS); + + //CLUSTER_MODE_STATUS + clusterModeStatusObj.put(ClusterModeStatus.KEY_POWER_MODE_ACTIVE, VehicleDataHelper.CLUSTER_MODE_STATUS_POWER_MODE_ACTIVE); + clusterModeStatusObj.put(ClusterModeStatus.KEY_POWER_MODE_QUALIFICATION_STATUS, VehicleDataHelper.CLUSTER_MODE_STATUS_POWER_MODE_QUALIFICATION_STATUS); + clusterModeStatusObj.put(ClusterModeStatus.KEY_CAR_MODE_STATUS, VehicleDataHelper.CLUSTER_MODE_STATUS_CAR_MODE_STATUS); + clusterModeStatusObj.put(ClusterModeStatus.KEY_POWER_MODE_STATUS, VehicleDataHelper.CLUSTER_MODE_STATUS_POWER_MODE_STATUS); + + //MY_KEY + myKeyObj.put(MyKey.KEY_E_911_OVERRIDE, VehicleDataHelper.MY_KEY_E_911_OVERRIDE); + + // FUEL_RANGE + fuelRangeObj.put(FuelRange.KEY_TYPE, VehicleDataHelper.FUEL_RANGE_TYPE); + fuelRangeObj.put(FuelRange.KEY_RANGE, VehicleDataHelper.FUEL_RANGE_RANGE); + fuelRangeArrayObj.put(fuelRangeObj); + + reference.put(GetVehicleDataResponse.KEY_SPEED, VehicleDataHelper.SPEED); + reference.put(GetVehicleDataResponse.KEY_RPM, VehicleDataHelper.RPM); + reference.put(GetVehicleDataResponse.KEY_EXTERNAL_TEMPERATURE, VehicleDataHelper.EXTERNAL_TEMPERATURE); + reference.put(GetVehicleDataResponse.KEY_FUEL_LEVEL, VehicleDataHelper.FUEL_LEVEL); + reference.put(GetVehicleDataResponse.KEY_VIN, VehicleDataHelper.VIN); + reference.put(GetVehicleDataResponse.KEY_PRNDL, VehicleDataHelper.PRNDL_FINAL); + reference.put(GetVehicleDataResponse.KEY_TIRE_PRESSURE, tireStatusObj); + reference.put(GetVehicleDataResponse.KEY_ENGINE_TORQUE, VehicleDataHelper.ENGINE_TORQUE); + reference.put(GetVehicleDataResponse.KEY_ENGINE_OIL_LIFE, VehicleDataHelper.ENGINE_OIL_LIFE); + reference.put(GetVehicleDataResponse.KEY_ODOMETER, VehicleDataHelper.ODOMETER); + reference.put(GetVehicleDataResponse.KEY_GPS, GPSDataObj); + reference.put(GetVehicleDataResponse.KEY_FUEL_LEVEL_STATE, VehicleDataHelper.FUEL_LEVEL_STATE); + reference.put(GetVehicleDataResponse.KEY_INSTANT_FUEL_CONSUMPTION, VehicleDataHelper.INSTANT_FUEL_CONSUMPTION); + reference.put(GetVehicleDataResponse.KEY_BELT_STATUS, beltStatusObj); + reference.put(GetVehicleDataResponse.KEY_BODY_INFORMATION, bodyInformationObj); + reference.put(GetVehicleDataResponse.KEY_DEVICE_STATUS, deviceStatusObj); + reference.put(GetVehicleDataResponse.KEY_DRIVER_BRAKING, VehicleDataHelper.DRIVER_BRAKING); + reference.put(GetVehicleDataResponse.KEY_WIPER_STATUS, VehicleDataHelper.WIPER_STATUS); + reference.put(GetVehicleDataResponse.KEY_HEAD_LAMP_STATUS, headLampStatusObj); + reference.put(GetVehicleDataResponse.KEY_ACC_PEDAL_POSITION, VehicleDataHelper.ACC_PEDAL_POSITION); + reference.put(GetVehicleDataResponse.KEY_STEERING_WHEEL_ANGLE, VehicleDataHelper.STEERING_WHEEL_ANGLE); + reference.put(GetVehicleDataResponse.KEY_E_CALL_INFO, ECallInfoObj); + reference.put(GetVehicleDataResponse.KEY_AIRBAG_STATUS, airbagStatusObj); + reference.put(GetVehicleDataResponse.KEY_EMERGENCY_EVENT, emergencyEventObj); + reference.put(GetVehicleDataResponse.KEY_CLUSTER_MODE_STATUS, clusterModeStatusObj); + reference.put(GetVehicleDataResponse.KEY_MY_KEY, myKeyObj); + reference.put(GetVehicleDataResponse.KEY_FUEL_RANGE, fuelRangeArrayObj); + reference.put(GetVehicleDataResponse.KEY_TURN_SIGNAL, TurnSignal.OFF); + reference.put(GetVehicleDataResponse.KEY_ELECTRONIC_PARK_BRAKE_STATUS, VehicleDataHelper.ELECTRONIC_PARK_BRAKE_STATUS); + + JSONObject underTest = msg.serializeJSON(); + + //go inside underTest and only return the JSONObject inside the parameters key inside the response key + underTest = underTest.getJSONObject("response").getJSONObject("parameters"); + + assertEquals("JSON size didn't match expected size.", reference.length(), underTest.length()); + + Iterator<?> iterator = reference.keys(); + + while (iterator.hasNext()) { + String key = (String) iterator.next(); + + if (key.equals(GetVehicleDataResponse.KEY_TIRE_PRESSURE)) { + JSONObject tirePressureReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject tirePressureTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateTireStatus( + new TireStatus(JsonRPCMarshaller.deserializeJSONObject(tirePressureReference)), + new TireStatus(JsonRPCMarshaller.deserializeJSONObject(tirePressureTest)))); + + } + else if (key.equals(GetVehicleDataResponse.KEY_GPS)) { + JSONObject GPSObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject GPSObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateGpsData( + new GPSData(JsonRPCMarshaller.deserializeJSONObject(GPSObjReference)), + new GPSData(JsonRPCMarshaller.deserializeJSONObject(GPSObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_BELT_STATUS)) { + JSONObject beltObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject beltObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateBeltStatus( + new BeltStatus(JsonRPCMarshaller.deserializeJSONObject(beltObjReference)), + new BeltStatus(JsonRPCMarshaller.deserializeJSONObject(beltObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_BODY_INFORMATION)) { + JSONObject bodyInfoObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject bodyInfoObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateBodyInformation( + new BodyInformation(JsonRPCMarshaller.deserializeJSONObject(bodyInfoObjReference)), + new BodyInformation(JsonRPCMarshaller.deserializeJSONObject(bodyInfoObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_DEVICE_STATUS)) { + JSONObject deviceObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject deviceObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateDeviceStatus( + new DeviceStatus(JsonRPCMarshaller.deserializeJSONObject(deviceObjReference)), + new DeviceStatus(JsonRPCMarshaller.deserializeJSONObject(deviceObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_HEAD_LAMP_STATUS)) { + JSONObject headLampObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject headLampObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateHeadLampStatus( + new HeadLampStatus(JsonRPCMarshaller.deserializeJSONObject(headLampObjReference)), + new HeadLampStatus(JsonRPCMarshaller.deserializeJSONObject(headLampObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_E_CALL_INFO)) { + JSONObject callInfoObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject callInfoObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateECallInfo( + new ECallInfo(JsonRPCMarshaller.deserializeJSONObject(callInfoObjReference)), + new ECallInfo(JsonRPCMarshaller.deserializeJSONObject(callInfoObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_AIRBAG_STATUS)) { + JSONObject airbagObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject airbagObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateAirbagStatus( + new AirbagStatus(JsonRPCMarshaller.deserializeJSONObject(airbagObjReference)), + new AirbagStatus(JsonRPCMarshaller.deserializeJSONObject(airbagObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_EMERGENCY_EVENT)) { + JSONObject emergencyObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject emergencyObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateEmergencyEvent( + new EmergencyEvent(JsonRPCMarshaller.deserializeJSONObject(emergencyObjReference)), + new EmergencyEvent(JsonRPCMarshaller.deserializeJSONObject(emergencyObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_CLUSTER_MODE_STATUS)) { + JSONObject clusterModeObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject clusterModeObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateClusterModeStatus( + new ClusterModeStatus(JsonRPCMarshaller.deserializeJSONObject(clusterModeObjReference)), + new ClusterModeStatus(JsonRPCMarshaller.deserializeJSONObject(clusterModeObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_MY_KEY)) { + JSONObject myKeyObjReference = JsonUtils.readJsonObjectFromJsonObject(reference, key); + JSONObject myKeyObjTest = JsonUtils.readJsonObjectFromJsonObject(underTest, key); + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateMyKey( + new MyKey(JsonRPCMarshaller.deserializeJSONObject(myKeyObjReference)), + new MyKey(JsonRPCMarshaller.deserializeJSONObject(myKeyObjTest)))); + } + else if (key.equals(GetVehicleDataResponse.KEY_ENGINE_OIL_LIFE)) { + assertEquals("JSON value didn't match expected value for key \"" + key + "\".", + JsonUtils.readDoubleFromJsonObject(reference, key), JsonUtils.readDoubleFromJsonObject(underTest, key)); + } + else if (key.equals(GetVehicleDataResponse.KEY_FUEL_RANGE)) { + JSONArray fuelRangeArrayObjReference = JsonUtils.readJsonArrayFromJsonObject(reference, key); + List<FuelRange> fuelRangeRefereceList = new ArrayList<FuelRange>(); + for (int index = 0; index < fuelRangeArrayObjReference.length(); index++) { + FuelRange fuelRange = new FuelRange(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)fuelRangeArrayObjReference.get(index) )); + fuelRangeRefereceList.add(fuelRange); + } + + JSONArray fuelRangeArrayObjTest = JsonUtils.readJsonArrayFromJsonObject(underTest, key); + List<FuelRange> fuelRangeUnderTestList = new ArrayList<FuelRange>(); + for (int index = 0; index < fuelRangeArrayObjTest.length(); index++) { + FuelRange fuelRange = new FuelRange(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)fuelRangeArrayObjTest.get(index) )); + fuelRangeUnderTestList.add(fuelRange); + } + + assertTrue("JSON value didn't match expected value for key \"" + key + "\".", + Validator.validateFuelRange( + fuelRangeRefereceList, + fuelRangeUnderTestList)); + } + else { + assertEquals("JSON value didn't match expected value for key \"" + key + "\".", + JsonUtils.readObjectFromJsonObject(reference, key), + JsonUtils.readObjectFromJsonObject(underTest, key)); + } + + } + + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues(){ + // Valid Tests + assertEquals(Test.MATCH, VehicleDataHelper.SPEED, ( (GetVehicleDataResponse) msg ).getSpeed()); + assertEquals(Test.MATCH, (Integer) VehicleDataHelper.RPM, ( (GetVehicleDataResponse) msg ).getRpm()); + assertEquals(Test.MATCH, VehicleDataHelper.EXTERNAL_TEMPERATURE, ( (GetVehicleDataResponse) msg ).getExternalTemperature()); + assertEquals(Test.MATCH, VehicleDataHelper.FUEL_LEVEL, ( (GetVehicleDataResponse) msg ).getFuelLevel()); + assertEquals(Test.MATCH, VehicleDataHelper.PRNDL_FINAL, ( (GetVehicleDataResponse) msg ).getPrndl()); + assertEquals(Test.MATCH, VehicleDataHelper.TIRE_PRESSURE, ( (GetVehicleDataResponse) msg ).getTirePressure()); + assertEquals(Test.MATCH, VehicleDataHelper.ENGINE_TORQUE, ( (GetVehicleDataResponse) msg ).getEngineTorque()); + assertEquals(Test.MATCH, VehicleDataHelper.ENGINE_OIL_LIFE, ( (GetVehicleDataResponse) msg ).getEngineOilLife()); + assertEquals(Test.MATCH, (Integer) VehicleDataHelper.ODOMETER, ( (GetVehicleDataResponse) msg ).getOdometer()); + assertEquals(Test.MATCH, VehicleDataHelper.GPS, ( (GetVehicleDataResponse) msg ).getGps()); + assertEquals(Test.MATCH, VehicleDataHelper.FUEL_LEVEL_STATE, ( (GetVehicleDataResponse) msg ).getFuelLevelState()); + assertEquals(Test.MATCH, VehicleDataHelper.INSTANT_FUEL_CONSUMPTION, ( (GetVehicleDataResponse) msg ).getInstantFuelConsumption()); + assertEquals(Test.MATCH, VehicleDataHelper.BELT_STATUS, ( (GetVehicleDataResponse) msg ).getBeltStatus()); + assertEquals(Test.MATCH, VehicleDataHelper.BODY_INFORMATION, ( (GetVehicleDataResponse) msg ).getBodyInformation()); + assertEquals(Test.MATCH, VehicleDataHelper.DEVICE_STATUS, ( (GetVehicleDataResponse) msg ).getDeviceStatus()); + assertEquals(Test.MATCH, VehicleDataHelper.DRIVER_BRAKING, ( (GetVehicleDataResponse) msg ).getDriverBraking()); + assertEquals(Test.MATCH, VehicleDataHelper.WIPER_STATUS, ( (GetVehicleDataResponse) msg ).getWiperStatus()); + assertEquals(Test.MATCH, VehicleDataHelper.HEAD_LAMP_STATUS, ( (GetVehicleDataResponse) msg ).getHeadLampStatus()); + assertEquals(Test.MATCH, VehicleDataHelper.ACC_PEDAL_POSITION, ( (GetVehicleDataResponse) msg ).getAccPedalPosition()); + assertEquals(Test.MATCH, VehicleDataHelper.STEERING_WHEEL_ANGLE, ( (GetVehicleDataResponse) msg ).getSteeringWheelAngle()); + assertEquals(Test.MATCH, VehicleDataHelper.E_CALL_INFO, ( (GetVehicleDataResponse) msg ).getECallInfo()); + assertEquals(Test.MATCH, VehicleDataHelper.AIRBAG_STATUS, ( (GetVehicleDataResponse) msg ).getAirbagStatus()); + assertEquals(Test.MATCH, VehicleDataHelper.EMERGENCY_EVENT, ( (GetVehicleDataResponse) msg ).getEmergencyEvent()); + assertEquals(Test.MATCH, VehicleDataHelper.CLUSTER_MODE_STATUS, ( (GetVehicleDataResponse) msg ).getClusterModeStatus()); + assertEquals(Test.MATCH, VehicleDataHelper.MY_KEY, ( (GetVehicleDataResponse) msg ).getMyKey()); + assertEquals(Test.MATCH, VehicleDataHelper.TURN_SIGNAL, ( (GetVehicleDataResponse) msg ).getTurnSignal()); + assertEquals(Test.MATCH, VehicleDataHelper.ELECTRONIC_PARK_BRAKE_STATUS, ( (GetVehicleDataResponse) msg ).getElectronicParkBrakeStatus()); + + // Invalid/Null Tests + GetVehicleDataResponse msg = new GetVehicleDataResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAccPedalPosition()); + assertNull(Test.NULL, msg.getAirbagStatus()); + assertNull(Test.NULL, msg.getBeltStatus()); + assertNull(Test.NULL, msg.getDriverBraking()); + assertNull(Test.NULL, msg.getFuelLevel()); + assertNull(Test.NULL, msg.getTirePressure()); + assertNull(Test.NULL, msg.getWiperStatus()); + assertNull(Test.NULL, msg.getGps()); + assertNull(Test.NULL, msg.getSpeed()); + assertNull(Test.NULL, msg.getRpm()); + assertNull(Test.NULL, msg.getFuelLevelState()); + assertNull(Test.NULL, msg.getInstantFuelConsumption()); + assertNull(Test.NULL, msg.getExternalTemperature()); + assertNull(Test.NULL, msg.getPrndl()); + assertNull(Test.NULL, msg.getOdometer()); + assertNull(Test.NULL, msg.getBodyInformation()); + assertNull(Test.NULL, msg.getDeviceStatus()); + assertNull(Test.NULL, msg.getHeadLampStatus()); + assertNull(Test.NULL, msg.getEngineTorque()); + assertNull(Test.NULL, msg.getEngineOilLife()); + assertNull(Test.NULL, msg.getSteeringWheelAngle()); + assertNull(Test.NULL, msg.getECallInfo()); + assertNull(Test.NULL, msg.getEmergencyEvent()); + assertNull(Test.NULL, msg.getClusterModeStatus()); + assertNull(Test.NULL, msg.getMyKey()); + assertNull(Test.NULL, msg.getTurnSignal()); + assertNull(Test.NULL, msg.getElectronicParkBrakeStatus()); + } + + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetVehicleDataResponse cmd = new GetVehicleDataResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, GetVehicleDataResponse.KEY_SPEED), cmd.getSpeed()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetVehicleDataResponse.KEY_RPM), cmd.getRpm()); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, GetVehicleDataResponse.KEY_EXTERNAL_TEMPERATURE), cmd.getExternalTemperature()); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, GetVehicleDataResponse.KEY_FUEL_LEVEL), cmd.getFuelLevel()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetVehicleDataResponse.KEY_VIN), cmd.getVin()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetVehicleDataResponse.KEY_PRNDL), cmd.getPrndl().toString()); + + JSONObject tireStatusObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_TIRE_PRESSURE); + TireStatus tireStatus = new TireStatus(JsonRPCMarshaller.deserializeJSONObject(tireStatusObj)); + assertTrue(Test.TRUE, Validator.validateTireStatus(tireStatus, cmd.getTirePressure()) ); + + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, GetVehicleDataResponse.KEY_ENGINE_TORQUE), cmd.getEngineTorque()); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, GetVehicleDataResponse.KEY_ENGINE_OIL_LIFE), cmd.getEngineOilLife(), 0.0002); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, GetVehicleDataResponse.KEY_ODOMETER), cmd.getOdometer()); + + JSONObject gpsDataObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_GPS); + GPSData gpsData = new GPSData(JsonRPCMarshaller.deserializeJSONObject(gpsDataObj)); + assertTrue(Test.TRUE, Validator.validateGpsData(gpsData, cmd.getGps()) ); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetVehicleDataResponse.KEY_FUEL_LEVEL_STATE), cmd.getFuelLevelState().toString()); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, GetVehicleDataResponse.KEY_INSTANT_FUEL_CONSUMPTION), cmd.getInstantFuelConsumption()); + + JSONObject beltStatusObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_BELT_STATUS); + BeltStatus beltStatus = new BeltStatus(JsonRPCMarshaller.deserializeJSONObject(beltStatusObj)); + assertTrue(Test.TRUE, Validator.validateBeltStatus(beltStatus, cmd.getBeltStatus()) ); + + JSONObject bodyInformationObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_BODY_INFORMATION); + BodyInformation bodyInformation = new BodyInformation(JsonRPCMarshaller.deserializeJSONObject(bodyInformationObj)); + assertTrue(Test.TRUE, Validator.validateBodyInformation(bodyInformation, cmd.getBodyInformation()) ); + + JSONObject deviceStatusObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_DEVICE_STATUS); + DeviceStatus deviceStatus = new DeviceStatus(JsonRPCMarshaller.deserializeJSONObject(deviceStatusObj)); + assertTrue(Test.TRUE, Validator.validateDeviceStatus(deviceStatus, cmd.getDeviceStatus()) ); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetVehicleDataResponse.KEY_DRIVER_BRAKING), cmd.getDriverBraking().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetVehicleDataResponse.KEY_WIPER_STATUS), cmd.getWiperStatus().toString()); + + JSONObject headLampStatusObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_HEAD_LAMP_STATUS); + HeadLampStatus headLampStatus = new HeadLampStatus(JsonRPCMarshaller.deserializeJSONObject(headLampStatusObj)); + assertTrue(Test.TRUE, Validator.validateHeadLampStatus(headLampStatus, cmd.getHeadLampStatus()) ); + + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, GetVehicleDataResponse.KEY_ACC_PEDAL_POSITION), cmd.getAccPedalPosition()); + assertEquals(Test.MATCH, JsonUtils.readDoubleFromJsonObject(parameters, GetVehicleDataResponse.KEY_STEERING_WHEEL_ANGLE), cmd.getSteeringWheelAngle()); + + JSONObject eCallInfoObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_E_CALL_INFO); + ECallInfo eCallInfo = new ECallInfo(JsonRPCMarshaller.deserializeJSONObject(eCallInfoObj)); + assertTrue(Test.TRUE, Validator.validateECallInfo(eCallInfo, cmd.getECallInfo()) ); + + JSONObject airbagStatusObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_AIRBAG_STATUS); + AirbagStatus airbagStatus = new AirbagStatus(JsonRPCMarshaller.deserializeJSONObject(airbagStatusObj)); + assertTrue(Test.TRUE, Validator.validateAirbagStatus(airbagStatus, cmd.getAirbagStatus()) ); + + JSONObject emergencyEventObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_EMERGENCY_EVENT); + EmergencyEvent emergencyEvent = new EmergencyEvent(JsonRPCMarshaller.deserializeJSONObject(emergencyEventObj)); + assertTrue(Test.TRUE, Validator.validateEmergencyEvent(emergencyEvent, cmd.getEmergencyEvent()) ); + + JSONObject clusterModeStatusObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_CLUSTER_MODE_STATUS); + ClusterModeStatus clusterModeStatus = new ClusterModeStatus(JsonRPCMarshaller.deserializeJSONObject(clusterModeStatusObj)); + assertTrue(Test.TRUE, Validator.validateClusterModeStatus(clusterModeStatus, cmd.getClusterModeStatus()) ); + + JSONObject myKeyObj = JsonUtils.readJsonObjectFromJsonObject(parameters, GetVehicleDataResponse.KEY_MY_KEY); + MyKey myKey = new MyKey(JsonRPCMarshaller.deserializeJSONObject(myKeyObj)); + assertTrue(Test.TRUE, Validator.validateMyKey(myKey, cmd.getMyKey()) ); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetVehicleDataResponse.KEY_TURN_SIGNAL), cmd.getTurnSignal().toString()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, GetVehicleDataResponse.KEY_ELECTRONIC_PARK_BRAKE_STATUS), cmd.getElectronicParkBrakeStatus().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetWayPointsResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetWayPointsResponseTests.java new file mode 100644 index 000000000..57d8499df --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/GetWayPointsResponseTests.java @@ -0,0 +1,123 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetWayPointsResponse; +import com.smartdevicelink.proxy.rpc.LocationDetails; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +/** + * Created by austinkirk on 6/6/17. + */ + +public class GetWayPointsResponseTests extends BaseRpcTests { + List<LocationDetails> waypoints = new ArrayList<LocationDetails>(); + + @Override + protected RPCMessage createMessage() { + + waypoints.add(Test.GENERAL_LOCATIONDETAILS); + waypoints.add(Test.GENERAL_LOCATIONDETAILS); + + GetWayPointsResponse getWayPointsResponse = new GetWayPointsResponse(); + getWayPointsResponse.setWayPoints(waypoints); + + return getWayPointsResponse; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.GET_WAY_POINTS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + JSONArray jsonArray = new JSONArray(); + try { + jsonArray.put(JsonRPCMarshaller.serializeHashtable(Test.GENERAL_LOCATIONDETAILS.getStore())); + jsonArray.put(JsonRPCMarshaller.serializeHashtable(Test.GENERAL_LOCATIONDETAILS.getStore())); + } catch (JSONException e) { + e.printStackTrace(); + } + + try { + result.put(GetWayPointsResponse.KEY_WAY_POINTS, jsonArray); + } catch (JSONException e) { + e.printStackTrace(); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + + // Test Values + List<LocationDetails> testWPs = ( (GetWayPointsResponse) msg ).getWayPoints(); + + // Valid Tests + assertEquals(Test.MATCH, waypoints, testWPs); + + // Invalid/Null Tests + GetWayPointsResponse msg = new GetWayPointsResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getWayPoints()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + GetWayPointsResponse cmd = new GetWayPointsResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONArray locArray = JsonUtils.readJsonArrayFromJsonObject(parameters, GetWayPointsResponse.KEY_WAY_POINTS); + List<LocationDetails> locationList = new ArrayList<LocationDetails>(); + for (int index = 0; index < locArray.length(); index++) { + LocationDetails det = new LocationDetails(JsonRPCMarshaller.deserializeJSONObject( (JSONObject) locArray.get(index))); + locationList.add(det); + } + List<LocationDetails> dets = cmd.getWayPoints(); + assertEquals(Test.MATCH, locationList.size(), dets.size()); + + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ListFilesResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ListFilesResponseTests.java new file mode 100644 index 000000000..878a47776 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ListFilesResponseTests.java @@ -0,0 +1,110 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ListFilesResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.ListFilesResponse} + */ +public class ListFilesResponseTests extends BaseRpcTests{ + + @Override + protected RPCMessage createMessage(){ + ListFilesResponse msg = new ListFilesResponse(); + + msg.setFilenames(Test.GENERAL_STRING_LIST); + msg.setSpaceAvailable(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.LIST_FILES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(ListFilesResponse.KEY_FILENAMES, JsonUtils.createJsonArray(Test.GENERAL_STRING_LIST)); + result.put(ListFilesResponse.KEY_SPACE_AVAILABLE, Test.GENERAL_INT); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<String> filenames = ( (ListFilesResponse) msg ).getFilenames(); + int spaceAvailable = ( (ListFilesResponse) msg ).getSpaceAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING_LIST.size(), filenames.size()); + assertTrue(Test.TRUE, Validator.validateStringList(Test.GENERAL_STRING_LIST, filenames)); + assertEquals(Test.MATCH, Test.GENERAL_INT, spaceAvailable); + + // Invalid/Null Tests + ListFilesResponse msg = new ListFilesResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getFilenames()); + assertNull(Test.NULL, msg.getSpaceAvailable()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ListFilesResponse cmd = new ListFilesResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + List<String> fileNamesList = JsonUtils.readStringListFromJsonObject(parameters, ListFilesResponse.KEY_FILENAMES); + List<String> testNamesList = cmd.getFilenames(); + assertEquals(Test.MATCH, fileNamesList.size(), testNamesList.size()); + assertTrue(Test.TRUE, Validator.validateStringList(fileNamesList, testNamesList)); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, ListFilesResponse.KEY_SPACE_AVAILABLE), cmd.getSpaceAvailable()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformAppServiceInteractionResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformAppServiceInteractionResponseTests.java new file mode 100644 index 000000000..ac3be00c6 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformAppServiceInteractionResponseTests.java @@ -0,0 +1,101 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.GetFileResponse; +import com.smartdevicelink.proxy.rpc.PerformAppServiceInteractionResponse; +import com.smartdevicelink.proxy.rpc.enums.FileType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.PerformAppServiceInteractionResponse} + */ +public class PerformAppServiceInteractionResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + + PerformAppServiceInteractionResponse msg = new PerformAppServiceInteractionResponse(); + + msg.setServiceSpecificResult(Test.GENERAL_STRING); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.PERFORM_APP_SERVICES_INTERACTION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(PerformAppServiceInteractionResponse.KEY_SERVICE_SPECIFIC_RESULT, Test.GENERAL_STRING); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + String serviceSpecificResult = ( (PerformAppServiceInteractionResponse) msg ).getServiceSpecificResult(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_STRING, serviceSpecificResult); + + // Invalid/Null Tests + PerformAppServiceInteractionResponse msg = new PerformAppServiceInteractionResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getServiceSpecificResult()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PerformAppServiceInteractionResponse cmd = new PerformAppServiceInteractionResponse (hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformAppServiceInteractionResponse.KEY_SERVICE_SPECIFIC_RESULT), cmd.getServiceSpecificResult()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformAudioPassThruResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformAudioPassThruResponseTest.java new file mode 100644 index 000000000..b330fed72 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformAudioPassThruResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.PerformAudioPassThruResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.PerformAudioPassThruResponse} + */ +public class PerformAudioPassThruResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new PerformAudioPassThruResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.PERFORM_AUDIO_PASS_THRU.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + PerformAudioPassThruResponse msg = new PerformAudioPassThruResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PerformAudioPassThruResponse cmd = new PerformAudioPassThruResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformInteractionResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformInteractionResponseTest.java new file mode 100644 index 000000000..d3f1518af --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PerformInteractionResponseTest.java @@ -0,0 +1,110 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.PerformInteractionResponse; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.PerformInteractionResponse} + */ +public class PerformInteractionResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + PerformInteractionResponse msg = new PerformInteractionResponse(); + + msg.setChoiceID(Test.GENERAL_INT); + msg.setTriggerSource(Test.GENERAL_TRIGGERSOURCE); + msg.setManualTextEntry(Test.GENERAL_STRING); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.PERFORM_INTERACTION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(PerformInteractionResponse.KEY_CHOICE_ID, Test.GENERAL_INT); + result.put(PerformInteractionResponse.KEY_TRIGGER_SOURCE, Test.GENERAL_TRIGGERSOURCE); + result.put(PerformInteractionResponse.KEY_MANUAL_TEXT_ENTRY, Test.GENERAL_STRING); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer testId = ( (PerformInteractionResponse) msg).getChoiceID(); + TriggerSource testSource = ( (PerformInteractionResponse) msg).getTriggerSource(); + String testText = ( (PerformInteractionResponse) msg).getManualTextEntry(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, testId); + assertEquals(Test.MATCH, Test.GENERAL_TRIGGERSOURCE, testSource); + assertEquals(Test.MATCH, Test.GENERAL_STRING, testText); + + // Invalid/Null Tests + PerformInteractionResponse msg = new PerformInteractionResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getChoiceID()); + assertNull(Test.NULL, msg.getTriggerSource()); + assertNull(Test.NULL, msg.getManualTextEntry()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PerformInteractionResponse cmd = new PerformInteractionResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformInteractionResponse.KEY_MANUAL_TEXT_ENTRY), cmd.getManualTextEntry()); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, PerformInteractionResponse.KEY_TRIGGER_SOURCE), cmd.getTriggerSource().toString()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, PerformInteractionResponse.KEY_CHOICE_ID), cmd.getChoiceID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PublishAppServiceResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PublishAppServiceResponseTests.java new file mode 100644 index 000000000..f51a7945a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PublishAppServiceResponseTests.java @@ -0,0 +1,103 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AppServiceRecord; +import com.smartdevicelink.proxy.rpc.PublishAppServiceResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.PublishAppServiceResponse} + */ +public class PublishAppServiceResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + + PublishAppServiceResponse msg = new PublishAppServiceResponse(); + + msg.setServiceRecord(Test.GENERAL_APP_SERVICE_RECORD); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.PUBLISH_APP_SERVICE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(PublishAppServiceResponse.KEY_APP_SERVICE_RECORD, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_APP_SERVICE_RECORD.getStore())); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + AppServiceRecord testRecord = ( (PublishAppServiceResponse) msg ).getServiceRecord(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateAppServiceRecord(Test.GENERAL_APP_SERVICE_RECORD, testRecord)); + + // Invalid/Null Tests + PublishAppServiceResponse msg = new PublishAppServiceResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getServiceRecord()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PublishAppServiceResponse cmd = new PublishAppServiceResponse (hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONObject appServiceRecordObject = JsonUtils.readJsonObjectFromJsonObject(parameters, PublishAppServiceResponse.KEY_APP_SERVICE_RECORD); + AppServiceRecord recordTest = new AppServiceRecord(JsonRPCMarshaller.deserializeJSONObject(appServiceRecordObject)); + assertTrue(Test.TRUE, Validator.validateAppServiceRecord(recordTest, cmd.getServiceRecord())); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PutFileResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PutFileResponseTest.java new file mode 100644 index 000000000..150994180 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/PutFileResponseTest.java @@ -0,0 +1,97 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.PutFileResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.PutFileResponse} + */ +public class PutFileResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + PutFileResponse msg = new PutFileResponse(); + + msg.setSpaceAvailable(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.PUT_FILE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(PutFileResponse.KEY_SPACE_AVAILABLE, Test.GENERAL_INT); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + Integer testSpace = ( (PutFileResponse) msg ).getSpaceAvailable(); + + // Valid Tests + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, testSpace); + + // Invalid/Null Tests + PutFileResponse msg = new PutFileResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSpaceAvailable()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + PutFileResponse cmd = new PutFileResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, PutFileResponse.KEY_SPACE_AVAILABLE), cmd.getSpaceAvailable()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReadDIDResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReadDIDResponseTest.java new file mode 100644 index 000000000..3ffc857cc --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ReadDIDResponseTest.java @@ -0,0 +1,109 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.DIDResult; +import com.smartdevicelink.proxy.rpc.ReadDIDResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ReadDIDResponse} + */ +public class ReadDIDResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + ReadDIDResponse msg = new ReadDIDResponse(); + + msg.setDidResult(Test.GENERAL_DIDRESULT_LIST); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.READ_DID.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(ReadDIDResponse.KEY_DID_RESULT, Test.JSON_DIDRESULTS); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<DIDResult> testResults = ( (ReadDIDResponse) msg ).getDidResult(); + + // Valid Tests + assertTrue("Did results didn't match input data.", Validator.validateDIDResults(Test.GENERAL_DIDRESULT_LIST, testResults)); + + // Invalid/Null Tests + ReadDIDResponse msg = new ReadDIDResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getDidResult()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ReadDIDResponse cmd = new ReadDIDResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONArray didResultArray = JsonUtils.readJsonArrayFromJsonObject(parameters, ReadDIDResponse.KEY_DID_RESULT); + List<DIDResult> didResultList = new ArrayList<DIDResult>(); + for (int index = 0; index < didResultArray.length(); index++) { + DIDResult chunk = new DIDResult(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)didResultArray.get(index)) ); + didResultList.add(chunk); + } + assertTrue(Test.MATCH, Validator.validateDIDResults(didResultList, cmd.getDidResult())); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/RegisterAppInterfaceResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/RegisterAppInterfaceResponseTest.java new file mode 100644 index 000000000..55450898e --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/RegisterAppInterfaceResponseTest.java @@ -0,0 +1,269 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.AudioPassThruCapabilities; +import com.smartdevicelink.proxy.rpc.ButtonCapabilities; +import com.smartdevicelink.proxy.rpc.DisplayCapabilities; +import com.smartdevicelink.proxy.rpc.PresetBankCapabilities; +import com.smartdevicelink.proxy.rpc.RegisterAppInterface; +import com.smartdevicelink.proxy.rpc.RegisterAppInterfaceResponse; +import com.smartdevicelink.proxy.rpc.SdlMsgVersion; +import com.smartdevicelink.proxy.rpc.SoftButtonCapabilities; +import com.smartdevicelink.proxy.rpc.VehicleType; +import com.smartdevicelink.proxy.rpc.enums.HmiZoneCapabilities; +import com.smartdevicelink.proxy.rpc.enums.Language; +import com.smartdevicelink.proxy.rpc.enums.PrerecordedSpeech; +import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities; +import com.smartdevicelink.proxy.rpc.enums.VrCapabilities; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.RegisterAppInterfaceResponse} + */ +public class RegisterAppInterfaceResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + + msg.setSdlMsgVersion(Test.GENERAL_SDLMSGVERSION); + msg.setLanguage(Test.GENERAL_LANGUAGE); + msg.setHmiDisplayLanguage(Test.GENERAL_LANGUAGE); + msg.setDisplayCapabilities(Test.GENERAL_DISPLAYCAPABILITIES); + msg.setPresetBankCapabilities(Test.GENERAL_PRESETBANKCAPABILITIES); + msg.setVehicleType(Test.GENERAL_VEHICLETYPE); + msg.setButtonCapabilities(Test.GENERAL_BUTTONCAPABILITIES_LIST); + msg.setSoftButtonCapabilities(Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST); + msg.setAudioPassThruCapabilities(Test.GENERAL_AUDIOPASSTHRUCAPABILITIES_LIST); + msg.setPcmStreamingCapabilities(Test.GENERAL_AUDIOPASSTHRUCAPABILITIES); + msg.setHmiZoneCapabilities(Test.GENERAL_HMIZONECAPABILITIES_LIST); + msg.setSpeechCapabilities(Test.GENERAL_SPEECHCAPABILITIES_LIST); + msg.setVrCapabilities(Test.GENERAL_VRCAPABILITIES_LIST); + msg.setPrerecordedSpeech(Test.GENERAL_PRERECORDEDSPEECH_LIST); + msg.setSupportedDiagModes(Test.GENERAL_INTEGER_LIST); + msg.setIconResumed(Test.GENERAL_BOOLEAN); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.REGISTER_APP_INTERFACE.toString(); + } + + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(RegisterAppInterfaceResponse.KEY_LANGUAGE, Test.GENERAL_LANGUAGE); + result.put(RegisterAppInterfaceResponse.KEY_HMI_DISPLAY_LANGUAGE, Test.GENERAL_LANGUAGE); + result.put(RegisterAppInterfaceResponse.KEY_SUPPORTED_DIAG_MODES, JsonUtils.createJsonArray(Test.GENERAL_INTEGER_LIST)); + result.put(RegisterAppInterfaceResponse.KEY_SDL_MSG_VERSION, Test.JSON_SDLMSGVERSION); + result.put(RegisterAppInterfaceResponse.KEY_VEHICLE_TYPE, Test.GENERAL_VEHICLETYPE.serializeJSON()); + result.put(RegisterAppInterfaceResponse.KEY_PRESET_BANK_CAPABILITIES, Test.JSON_PRESETBANKCAPABILITIES); + result.put(RegisterAppInterfaceResponse.KEY_DISPLAY_CAPABILITIES, Test.JSON_DISPLAYCAPABILITIES); + result.put(RegisterAppInterfaceResponse.KEY_BUTTON_CAPABILITIES, Test.JSON_BUTTONCAPABILITIES); + result.put(RegisterAppInterfaceResponse.KEY_SOFT_BUTTON_CAPABILITIES, Test.JSON_SOFTBUTTONCAPABILITIES); + result.put(RegisterAppInterfaceResponse.KEY_AUDIO_PASS_THRU_CAPABILITIES, Test.JSON_AUDIOPASSTHRUCAPABILITIES); + result.put(RegisterAppInterfaceResponse.KEY_PCM_STREAM_CAPABILITIES, Test.JSON_PCMSTREAMCAPABILITIES); + result.put(RegisterAppInterfaceResponse.KEY_SPEECH_CAPABILITIES, JsonUtils.createJsonArray(Test.GENERAL_SPEECHCAPABILITIES_LIST)); + result.put(RegisterAppInterfaceResponse.KEY_VR_CAPABILITIES, JsonUtils.createJsonArray(Test.GENERAL_VRCAPABILITIES_LIST)); + result.put(RegisterAppInterfaceResponse.KEY_HMI_ZONE_CAPABILITIES, JsonUtils.createJsonArray(Test.GENERAL_HMIZONECAPABILITIES_LIST)); + result.put(RegisterAppInterfaceResponse.KEY_PRERECORDED_SPEECH, JsonUtils.createJsonArray(Test.GENERAL_PRERECORDEDSPEECH_LIST)); + result.put(RegisterAppInterfaceResponse.KEY_ICON_RESUMED, Test.GENERAL_BOOLEAN); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + List<Integer> testSupportedDiagModes = ( (RegisterAppInterfaceResponse) msg ).getSupportedDiagModes(); + List<PrerecordedSpeech> testPrerecordedSpeech = ( (RegisterAppInterfaceResponse) msg ).getPrerecordedSpeech(); + List<VrCapabilities> testVrCapabilities = ( (RegisterAppInterfaceResponse) msg ).getVrCapabilities(); + List<SpeechCapabilities> testSpeechCapabilities = ( (RegisterAppInterfaceResponse) msg ).getSpeechCapabilities(); + List<HmiZoneCapabilities> testHmiZoneCapabilities = ( (RegisterAppInterfaceResponse) msg ).getHmiZoneCapabilities(); + List<SoftButtonCapabilities> testSoftButtonCapabilities = ( (RegisterAppInterfaceResponse) msg ).getSoftButtonCapabilities(); + List<ButtonCapabilities> testButtonCapabilities = ( (RegisterAppInterfaceResponse) msg ).getButtonCapabilities(); + VehicleType testVehicleType = ( (RegisterAppInterfaceResponse) msg ).getVehicleType(); + PresetBankCapabilities testPbc = ( (RegisterAppInterfaceResponse) msg ).getPresetBankCapabilities(); + DisplayCapabilities testDc = ( (RegisterAppInterfaceResponse) msg ).getDisplayCapabilities(); + Language testHmiLang = ( (RegisterAppInterfaceResponse) msg ).getHmiDisplayLanguage(); + Language testLang = ( (RegisterAppInterfaceResponse) msg ).getLanguage(); + SdlMsgVersion testMsgVersion = ( (RegisterAppInterfaceResponse) msg ).getSdlMsgVersion(); + List<AudioPassThruCapabilities> testAptc = ( (RegisterAppInterfaceResponse) msg ).getAudioPassThruCapabilities(); + AudioPassThruCapabilities testPcmStream = ( (RegisterAppInterfaceResponse) msg ).getPcmStreamingCapabilities(); + Boolean testIconResumed = ( (RegisterAppInterfaceResponse) msg ).getIconResumed(); + + // Valid Tests + assertEquals(Test.MATCH, Test.GENERAL_INTEGER_LIST, testSupportedDiagModes); + assertEquals(Test.MATCH, Test.GENERAL_PRERECORDEDSPEECH_LIST, testPrerecordedSpeech); + assertEquals(Test.MATCH, Test.GENERAL_VRCAPABILITIES_LIST, testVrCapabilities); + assertEquals(Test.MATCH, Test.GENERAL_SPEECHCAPABILITIES_LIST, testSpeechCapabilities); + assertEquals(Test.MATCH, Test.GENERAL_HMIZONECAPABILITIES_LIST, testHmiZoneCapabilities); + assertTrue(Test.TRUE, Validator.validateSoftButtonCapabilities(Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST, testSoftButtonCapabilities)); + assertTrue(Test.TRUE, Validator.validateButtonCapabilities(Test.GENERAL_BUTTONCAPABILITIES_LIST, testButtonCapabilities)); + assertTrue(Test.TRUE, Validator.validateVehicleType(Test.GENERAL_VEHICLETYPE, testVehicleType)); + assertTrue(Test.TRUE, Validator.validatePresetBankCapabilities(Test.GENERAL_PRESETBANKCAPABILITIES, testPbc)); + assertTrue(Test.TRUE, Validator.validateDisplayCapabilities(Test.GENERAL_DISPLAYCAPABILITIES, testDc)); + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, testHmiLang); + assertEquals(Test.MATCH, Test.GENERAL_LANGUAGE, testLang); + assertTrue(Test.TRUE, Validator.validateSdlMsgVersion(Test.GENERAL_SDLMSGVERSION, testMsgVersion)); + assertTrue(Test.TRUE, Validator.validateAudioPassThruCapabilities(Test.GENERAL_AUDIOPASSTHRUCAPABILITIES_LIST, testAptc)); + assertTrue(Test.TRUE, Validator.validatePcmStreamCapabilities(Test.GENERAL_AUDIOPASSTHRUCAPABILITIES, testPcmStream)); + assertEquals(Test.MATCH, (Boolean) Test.GENERAL_BOOLEAN, testIconResumed); + + // Invalid/Null Tests + RegisterAppInterfaceResponse msg = new RegisterAppInterfaceResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getSdlMsgVersion()); + assertNull(Test.NULL, msg.getLanguage()); + assertNull(Test.NULL, msg.getHmiDisplayLanguage()); + assertNull(Test.NULL, msg.getDisplayCapabilities()); + assertNull(Test.NULL, msg.getPresetBankCapabilities()); + assertNull(Test.NULL, msg.getVehicleType()); + assertNull(Test.NULL, msg.getButtonCapabilities()); + assertNull(Test.NULL, msg.getSoftButtonCapabilities()); + assertNull(Test.NULL, msg.getAudioPassThruCapabilities()); + assertNull(Test.NULL, msg.getPcmStreamingCapabilities()); + assertNull(Test.NULL, msg.getHmiZoneCapabilities()); + assertNull(Test.NULL, msg.getSpeechCapabilities()); + assertNull(Test.NULL, msg.getVrCapabilities()); + assertNull(Test.NULL, msg.getPrerecordedSpeech()); + assertNull(Test.NULL, msg.getSupportedDiagModes()); + assertNull(Test.NULL, msg.getIconResumed()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + RegisterAppInterfaceResponse cmd = new RegisterAppInterfaceResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONObject vehicleTypeObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_VEHICLE_TYPE); + VehicleType vehicleType = new VehicleType(JsonRPCMarshaller.deserializeJSONObject(vehicleTypeObj)); + assertTrue(Test.TRUE, Validator.validateVehicleType(vehicleType, cmd.getVehicleType())); + + JSONObject pcmStreamObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_PCM_STREAM_CAPABILITIES); + AudioPassThruCapabilities pcmStreamCap = new AudioPassThruCapabilities(JsonRPCMarshaller.deserializeJSONObject(pcmStreamObj)); + assertTrue(Test.TRUE, Validator.validatePcmStreamCapabilities(pcmStreamCap, cmd.getPcmStreamingCapabilities())); + + JSONArray speechCapabilitiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_SPEECH_CAPABILITIES); + for (int index = 0; index < speechCapabilitiesArray.length(); index++) { + SpeechCapabilities speechCapability = SpeechCapabilities.valueForString( speechCapabilitiesArray.get(index).toString() ); + assertEquals(Test.MATCH, speechCapability, cmd.getSpeechCapabilities().get(index)); + } + + JSONArray vrCapabilitiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_VR_CAPABILITIES); + for (int index = 0; index < vrCapabilitiesArray.length(); index++) { + VrCapabilities vrCapability = VrCapabilities.valueForString( vrCapabilitiesArray.get(index).toString() ); + assertEquals(Test.MATCH, vrCapability, cmd.getVrCapabilities().get(index)); + } + + JSONArray audioPassThruCapabilitiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_AUDIO_PASS_THRU_CAPABILITIES); + List<AudioPassThruCapabilities> audioPassThruCapabilitiesList = new ArrayList<AudioPassThruCapabilities>(); + for (int index = 0; index < audioPassThruCapabilitiesArray.length(); index++) { + AudioPassThruCapabilities audioPassThruCapability = + new AudioPassThruCapabilities(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)audioPassThruCapabilitiesArray.get(index) )); + audioPassThruCapabilitiesList.add(audioPassThruCapability); + } + assertTrue(Test.TRUE, Validator.validateAudioPassThruCapabilities(audioPassThruCapabilitiesList, cmd.getAudioPassThruCapabilities() )); + + JSONArray hmiZoneCapabilitiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_HMI_ZONE_CAPABILITIES); + for (int index = 0; index < hmiZoneCapabilitiesArray.length(); index++) { + HmiZoneCapabilities hmiZoneCapability = HmiZoneCapabilities.valueForString( hmiZoneCapabilitiesArray.get(index).toString() ); + assertEquals(Test.MATCH, hmiZoneCapability, cmd.getHmiZoneCapabilities().get(index)); + } + + JSONArray prerecordedSpeechArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_PRERECORDED_SPEECH); + for (int index = 0; index < prerecordedSpeechArray.length(); index++) { + PrerecordedSpeech prerecordedSpeech = PrerecordedSpeech.valueForString( prerecordedSpeechArray.get(index).toString() ); + assertEquals(Test.MATCH, prerecordedSpeech, cmd.getPrerecordedSpeech().get(index)); + } + + List<Integer> supportedDiagnosticModesList = JsonUtils.readIntegerListFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_SUPPORTED_DIAG_MODES); + List<Integer> testDiagnosticModesList = cmd.getSupportedDiagModes(); + assertEquals(Test.MATCH, supportedDiagnosticModesList.size(), testDiagnosticModesList.size()); + assertTrue(Test.TRUE, Validator.validateIntegerList(supportedDiagnosticModesList, testDiagnosticModesList)); + + JSONObject sdlMsgVersionObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_SDL_MSG_VERSION); + SdlMsgVersion sdlMsgVersion = new SdlMsgVersion(JsonRPCMarshaller.deserializeJSONObject(sdlMsgVersionObj)); + assertTrue(Test.TRUE, Validator.validateSdlMsgVersion(sdlMsgVersion, cmd.getSdlMsgVersion()) ); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_LANGUAGE), cmd.getLanguage().toString()); + + JSONArray buttonCapabilitiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_BUTTON_CAPABILITIES); + List<ButtonCapabilities> buttonCapabilitiesList = new ArrayList<ButtonCapabilities>(); + for (int index = 0; index < buttonCapabilitiesArray.length(); index++) { + ButtonCapabilities buttonCapability = new ButtonCapabilities(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)buttonCapabilitiesArray.get(index) )); + buttonCapabilitiesList.add(buttonCapability); + } + assertTrue(Test.TRUE, Validator.validateButtonCapabilities(buttonCapabilitiesList, cmd.getButtonCapabilities() )); + + JSONObject displayCapabilitiesObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_DISPLAY_CAPABILITIES); + DisplayCapabilities displayCapabilities = new DisplayCapabilities(JsonRPCMarshaller.deserializeJSONObject(displayCapabilitiesObj)); + assertTrue(Test.TRUE, Validator.validateDisplayCapabilities(displayCapabilities, cmd.getDisplayCapabilities()) ); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_HMI_DISPLAY_LANGUAGE), cmd.getHmiDisplayLanguage().toString()); + + JSONArray softButtonCapabilitiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_SOFT_BUTTON_CAPABILITIES); + List<SoftButtonCapabilities> softButtonCapabilitiesList = new ArrayList<SoftButtonCapabilities>(); + for (int index = 0; index < softButtonCapabilitiesArray.length(); index++) { + SoftButtonCapabilities softButtonCapability = + new SoftButtonCapabilities(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)softButtonCapabilitiesArray.get(index) )); + softButtonCapabilitiesList.add(softButtonCapability); + } + assertTrue(Test.TRUE, Validator.validateSoftButtonCapabilities(softButtonCapabilitiesList, cmd.getSoftButtonCapabilities() )); + + JSONObject presetBankCapabilitiesObj = JsonUtils.readJsonObjectFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_PRESET_BANK_CAPABILITIES); + PresetBankCapabilities presetBankCapabilities = new PresetBankCapabilities(JsonRPCMarshaller.deserializeJSONObject(presetBankCapabilitiesObj)); + assertTrue(Test.TRUE, Validator.validatePresetBankCapabilities(presetBankCapabilities, cmd.getPresetBankCapabilities()) ); + + Boolean iconResumed = JsonUtils.readBooleanFromJsonObject(parameters, RegisterAppInterfaceResponse.KEY_ICON_RESUMED); + assertEquals(Test.MATCH, iconResumed, cmd.getIconResumed()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ResetGlobalPropertiesResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ResetGlobalPropertiesResponseTest.java new file mode 100644 index 000000000..7e2faa3e4 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ResetGlobalPropertiesResponseTest.java @@ -0,0 +1,75 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ResetGlobalPropertiesResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ResetGlobalPropertiesResponse} + */ +public class ResetGlobalPropertiesResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new ResetGlobalPropertiesResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.RESET_GLOBAL_PROPERTIES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + ResetGlobalPropertiesResponse msg = new ResetGlobalPropertiesResponse(); + assertNotNull(Test.NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ResetGlobalPropertiesResponse cmd = new ResetGlobalPropertiesResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ScrollableMessageResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ScrollableMessageResponseTest.java new file mode 100644 index 000000000..7c7ad5edf --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ScrollableMessageResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ScrollableMessageResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ScrollableMessageResponse} + */ +public class ScrollableMessageResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new ScrollableMessageResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SCROLLABLE_MESSAGE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + ScrollableMessageResponse msg = new ScrollableMessageResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ScrollableMessageResponse cmd = new ScrollableMessageResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SendLocationResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SendLocationResponseTests.java new file mode 100644 index 000000000..c15607cec --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SendLocationResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SendLocationResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SendLocaitonResponse} + */ +public class SendLocationResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SendLocationResponse msg = new SendLocationResponse(); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.SEND_LOCATION.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SendLocationResponse msg = new SendLocationResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SendLocationResponse cmd = new SendLocationResponse(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetAppIconResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetAppIconResponseTest.java new file mode 100644 index 000000000..977998047 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetAppIconResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SetAppIconResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetAppIconResponse} + */ +public class SetAppIconResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new SetAppIconResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SET_APP_ICON.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SetAppIconResponse msg = new SetAppIconResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetAppIconResponse cmd = new SetAppIconResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetCloudAppPropertiesResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetCloudAppPropertiesResponseTests.java new file mode 100644 index 000000000..894c7ee78 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetCloudAppPropertiesResponseTests.java @@ -0,0 +1,42 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SetCloudAppPropertiesResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.Test; + +import org.json.JSONObject; + +public class SetCloudAppPropertiesResponseTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage(){ + return new SetCloudAppPropertiesResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SET_CLOUD_APP_PROPERTIES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SetCloudAppPropertiesResponse msg = new SetCloudAppPropertiesResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetDisplayLayoutResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetDisplayLayoutResponseTest.java new file mode 100644 index 000000000..2f188ff3b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetDisplayLayoutResponseTest.java @@ -0,0 +1,150 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ButtonCapabilities; +import com.smartdevicelink.proxy.rpc.DisplayCapabilities; +import com.smartdevicelink.proxy.rpc.PresetBankCapabilities; +import com.smartdevicelink.proxy.rpc.SetDisplayLayoutResponse; +import com.smartdevicelink.proxy.rpc.SoftButtonCapabilities; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetDisplayLayoutResponse} + */ +public class SetDisplayLayoutResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + + msg.setDisplayCapabilities(Test.GENERAL_DISPLAYCAPABILITIES); + msg.setPresetBankCapabilities(Test.GENERAL_PRESETBANKCAPABILITIES); + msg.setButtonCapabilities(Test.GENERAL_BUTTONCAPABILITIES_LIST); + msg.setSoftButtonCapabilities(Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.SET_DISPLAY_LAYOUT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SetDisplayLayoutResponse.KEY_DISPLAY_CAPABILITIES, Test.GENERAL_DISPLAYCAPABILITIES.serializeJSON()); + result.put(SetDisplayLayoutResponse.KEY_PRESET_BANK_CAPABILITIES, Test.JSON_PRESETBANKCAPABILITIES); + result.put(SetDisplayLayoutResponse.KEY_BUTTON_CAPABILITIES, Test.JSON_BUTTONCAPABILITIES); + result.put(SetDisplayLayoutResponse.KEY_SOFT_BUTTON_CAPABILITIES, Test.JSON_SOFTBUTTONCAPABILITIES); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + DisplayCapabilities testDisplay = ( (SetDisplayLayoutResponse) msg ).getDisplayCapabilities(); + PresetBankCapabilities testPbc = ( (SetDisplayLayoutResponse) msg ).getPresetBankCapabilities(); + List<ButtonCapabilities> testBc = ( (SetDisplayLayoutResponse) msg ).getButtonCapabilities(); + List<SoftButtonCapabilities> testSbc = ( (SetDisplayLayoutResponse) msg ).getSoftButtonCapabilities(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateDisplayCapabilities(Test.GENERAL_DISPLAYCAPABILITIES, testDisplay)); + assertTrue(Test.TRUE, Validator.validatePresetBankCapabilities(Test.GENERAL_PRESETBANKCAPABILITIES, testPbc)); + assertEquals(Test.MATCH, Test.GENERAL_BUTTONCAPABILITIES_LIST.size(), testBc.size()); + assertEquals(Test.MATCH, Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST.size(), testSbc.size()); + for (int i = 0; i < Test.GENERAL_BUTTONCAPABILITIES_LIST.size(); i++) { + assertEquals(Test.MATCH, Test.GENERAL_BUTTONCAPABILITIES_LIST.get(i), testBc.get(i)); + } + for (int i = 0; i < Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST.size(); i++) { + assertEquals(Test.MATCH, Test.GENERAL_SOFTBUTTONCAPABILITIES_LIST.get(i), testSbc.get(i)); + } + + // Invalid/Null Tests + SetDisplayLayoutResponse msg = new SetDisplayLayoutResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getDisplayCapabilities()); + assertNull(Test.NULL, msg.getPresetBankCapabilities()); + assertNull(Test.NULL, msg.getButtonCapabilities()); + assertNull(Test.NULL, msg.getSoftButtonCapabilities()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetDisplayLayoutResponse cmd = new SetDisplayLayoutResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONArray buttonCapabilitiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, SetDisplayLayoutResponse.KEY_BUTTON_CAPABILITIES); + List<ButtonCapabilities> buttonCapabilitiesList = new ArrayList<ButtonCapabilities>(); + for (int index = 0; index < buttonCapabilitiesArray.length(); index++) { + ButtonCapabilities buttonCapability = new ButtonCapabilities(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)buttonCapabilitiesArray.get(index) )); + buttonCapabilitiesList.add(buttonCapability); + } + assertTrue(Test.TRUE, Validator.validateButtonCapabilities(buttonCapabilitiesList, cmd.getButtonCapabilities() )); + + JSONObject displayCapabilitiesObj = JsonUtils.readJsonObjectFromJsonObject(parameters, SetDisplayLayoutResponse.KEY_DISPLAY_CAPABILITIES); + DisplayCapabilities displayCapabilities = new DisplayCapabilities(JsonRPCMarshaller.deserializeJSONObject(displayCapabilitiesObj)); + assertTrue(Test.TRUE, Validator.validateDisplayCapabilities(displayCapabilities, cmd.getDisplayCapabilities()) ); + + JSONArray softButtonCapabilitiesArray = JsonUtils.readJsonArrayFromJsonObject(parameters, SetDisplayLayoutResponse.KEY_SOFT_BUTTON_CAPABILITIES); + List<SoftButtonCapabilities> softButtonCapabilitiesList = new ArrayList<SoftButtonCapabilities>(); + for (int index = 0; index < softButtonCapabilitiesArray.length(); index++) { + SoftButtonCapabilities softButtonCapability = + new SoftButtonCapabilities(JsonRPCMarshaller.deserializeJSONObject( (JSONObject)softButtonCapabilitiesArray.get(index) )); + softButtonCapabilitiesList.add(softButtonCapability); + } + assertTrue(Test.TRUE, Validator.validateSoftButtonCapabilities(softButtonCapabilitiesList, cmd.getSoftButtonCapabilities() )); + + JSONObject presetBankCapabilitiesObj = JsonUtils.readJsonObjectFromJsonObject(parameters, SetDisplayLayoutResponse.KEY_PRESET_BANK_CAPABILITIES); + PresetBankCapabilities presetBankCapabilities = new PresetBankCapabilities(JsonRPCMarshaller.deserializeJSONObject(presetBankCapabilitiesObj)); + assertTrue(Test.TRUE, Validator.validatePresetBankCapabilities(presetBankCapabilities, cmd.getPresetBankCapabilities()) ); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetGlobalPropertiesResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetGlobalPropertiesResponseTest.java new file mode 100644 index 000000000..ed2c894c8 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetGlobalPropertiesResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SetGlobalPropertiesResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetGlobalPropertiesResponse} + */ +public class SetGlobalPropertiesResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new SetGlobalPropertiesResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SET_GLOBAL_PROPERTIES.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SetGlobalPropertiesResponse msg = new SetGlobalPropertiesResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetGlobalPropertiesResponse cmd = new SetGlobalPropertiesResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetInteriorVehicleDataResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetInteriorVehicleDataResponseTests.java new file mode 100644 index 000000000..c25685157 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetInteriorVehicleDataResponseTests.java @@ -0,0 +1,104 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ModuleData; +import com.smartdevicelink.proxy.rpc.SetInteriorVehicleDataResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetInteriorVehicleDataResponse} + */ +public class SetInteriorVehicleDataResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + + SetInteriorVehicleDataResponse msg = new SetInteriorVehicleDataResponse(); + + msg.setModuleData(Test.GENERAL_MODULEDATA); + + return msg; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SET_INTERIOR_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try{ + result.put(SetInteriorVehicleDataResponse.KEY_MODULE_DATA, JsonRPCMarshaller.serializeHashtable(Test.GENERAL_MODULEDATA.getStore())); + }catch(JSONException e){ + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + ModuleData testModuleData = ( (SetInteriorVehicleDataResponse) msg ).getModuleData(); + + // Valid Tests + assertTrue(Test.TRUE, Validator.validateModuleData(Test.GENERAL_MODULEDATA, testModuleData)); + + // Invalid/Null Tests + SetInteriorVehicleDataResponse msg = new SetInteriorVehicleDataResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getModuleData()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetInteriorVehicleDataResponse cmd = new SetInteriorVehicleDataResponse (hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + ModuleData testModuleData = new ModuleData(JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(parameters, SetInteriorVehicleDataResponse.KEY_MODULE_DATA))); + ModuleData cmdModuleData = cmd.getModuleData(); + + assertTrue(Test.TRUE, Validator.validateModuleData(testModuleData, cmdModuleData) ); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetMediaClockTimerResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetMediaClockTimerResponseTest.java new file mode 100644 index 000000000..6cf9d2977 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SetMediaClockTimerResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SetMediaClockTimerResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SetMediaClockTimerResponse} + */ +public class SetMediaClockTimerResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new SetMediaClockTimerResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SET_MEDIA_CLOCK_TIMER.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SetMediaClockTimerResponse msg = new SetMediaClockTimerResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SetMediaClockTimerResponse cmd = new SetMediaClockTimerResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ShowConstantTbtResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ShowConstantTbtResponseTests.java new file mode 100644 index 000000000..f51739ee9 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ShowConstantTbtResponseTests.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ShowConstantTbtResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.ShowConstantTbtResponse} + */ +public class ShowConstantTbtResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + ShowConstantTbtResponse msg = new ShowConstantTbtResponse(); + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.SHOW_CONSTANT_TBT.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + ShowConstantTbtResponse msg = new ShowConstantTbtResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ShowConstantTbtResponse cmd = new ShowConstantTbtResponse(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ShowResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ShowResponseTest.java new file mode 100644 index 000000000..301e330e7 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/ShowResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.ShowResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.ShowResponse} + */ +public class ShowResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new ShowResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SHOW.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + ShowResponse msg = new ShowResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + ShowResponse cmd = new ShowResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SliderResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SliderResponseTest.java new file mode 100644 index 000000000..4f9b5be98 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SliderResponseTest.java @@ -0,0 +1,94 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SliderResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SliderResponse} + */ +public class SliderResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage() { + SliderResponse msg = new SliderResponse(); + + msg.setSliderPosition(Test.GENERAL_INT); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.SLIDER.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + result.put(SliderResponse.KEY_SLIDER_POSITION, Test.GENERAL_INT); + + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + public void testPosition() { + Integer copy = ( (SliderResponse) msg ).getSliderPosition(); + assertEquals(Test.MATCH, (Integer) Test.GENERAL_INT, copy); + } + + public void testNull() { + SliderResponse msg = new SliderResponse(); + assertNotNull(Test.NOT_NULL, msg); + + testNullBase(msg); + + assertNull(Test.NULL, msg.getSliderPosition()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SliderResponse cmd = new SliderResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(parameters, SliderResponse.KEY_SLIDER_POSITION), cmd.getSliderPosition()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SpeakResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SpeakResponseTest.java new file mode 100644 index 000000000..3488aeae6 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SpeakResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SpeakResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SpeakResponse} + */ +public class SpeakResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new SpeakResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SPEAK.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SpeakResponse msg = new SpeakResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SpeakResponse cmd = new SpeakResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/StreamRPCResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/StreamRPCResponseTests.java new file mode 100644 index 000000000..47801ea90 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/StreamRPCResponseTests.java @@ -0,0 +1,89 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.StreamRPCResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class StreamRPCResponseTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage(){ + StreamRPCResponse response = new StreamRPCResponse(); + response.setFileSize((Long) Test.GENERAL_LONG); + response.setFileName(Test.GENERAL_STRING); + return response; + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.STREAM_RPC.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + JSONObject result = new JSONObject(); + + try { + result.put(StreamRPCResponse.KEY_FILESIZE, (Long) Test.GENERAL_LONG); + result.put(StreamRPCResponse.KEY_FILENAME, Test.GENERAL_STRING); + } catch (JSONException e) { + e.printStackTrace(); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + StreamRPCResponse msg = new StreamRPCResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + StreamRPCResponse cmd = new StreamRPCResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(parameters, StreamRPCResponse.KEY_FILENAME), cmd.getFileName()); + assertEquals(Test.MATCH, JsonUtils.readLongFromJsonObject(parameters, StreamRPCResponse.KEY_FILESIZE), cmd.getFileSize()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeButtonResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeButtonResponseTest.java new file mode 100644 index 000000000..6eaa9f397 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeButtonResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SubscribeButtonResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SubscribeButtonResponse} + */ +public class SubscribeButtonResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new SubscribeButtonResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SUBSCRIBE_BUTTON.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SubscribeButtonResponse msg = new SubscribeButtonResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SubscribeButtonResponse cmd = new SubscribeButtonResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals("Correlation ID doesn't match input ID", JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeVehicleDataResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeVehicleDataResponseTest.java new file mode 100644 index 000000000..e1dfc603c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeVehicleDataResponseTest.java @@ -0,0 +1,353 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SubscribeVehicleDataResponse; +import com.smartdevicelink.proxy.rpc.VehicleDataResult; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.SubscribeVehicleDataResponse} + */ +public class SubscribeVehicleDataResponseTest extends BaseRpcTests { + + // TODO : Test different result codes. + + @Override + protected RPCMessage createMessage() { + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse(); + + msg.setSpeed(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_SPEED.ordinal())); + msg.setRpm(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_RPM.ordinal())); + msg.setExternalTemperature(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_EXTERNTEMP.ordinal())); + msg.setFuelLevel(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELLEVEL.ordinal())); + msg.setPrndl(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_PRNDL.ordinal())); + msg.setTirePressure(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_TIREPRESSURE.ordinal())); + msg.setEngineTorque(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ENGINETORQUE.ordinal())); + msg.setEngineOilLife(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ENGINEOILLIFE.ordinal())); + msg.setOdometer(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ODOMETER.ordinal())); + msg.setGps(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_GPS.ordinal())); + msg.setFuelLevelState(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE.ordinal())); + msg.setInstantFuelConsumption(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION.ordinal())); + msg.setBeltStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BELTSTATUS.ordinal())); + msg.setBodyInformation(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BODYINFO.ordinal())); + msg.setDeviceStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_DEVICESTATUS.ordinal())); + msg.setDriverBraking(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BRAKING.ordinal())); + msg.setWiperStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_WIPERSTATUS.ordinal())); + msg.setHeadLampStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS.ordinal())); + msg.setAccPedalPosition(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ACCPEDAL.ordinal())); + msg.setSteeringWheelAngle(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_STEERINGWHEEL.ordinal())); + msg.setECallInfo(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ECALLINFO.ordinal())); + msg.setAirbagStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS.ordinal())); + msg.setEmergencyEvent(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT.ordinal())); + msg.setClusterModeStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS.ordinal())); + msg.setMyKey(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_MYKEY.ordinal())); + msg.setFuelRange(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELRANGE.ordinal())); + msg.setTurnSignal(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_TURNSIGNAL.ordinal())); + msg.setElectronicParkBrakeStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ELECTRONICPARKBRAKESTATUS.ordinal())); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.SUBSCRIBE_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + + // Note: If the key values stored in SubscribeVehicleDataResponse + // were to be in a list then this could be easily looped through + // instead of individually set. + + result.put(SubscribeVehicleDataResponse.KEY_SPEED, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_SPEED.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_RPM, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_RPM.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_EXTERNAL_TEMPERATURE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_EXTERNTEMP.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_FUEL_LEVEL, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELLEVEL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_PRNDL, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_PRNDL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_TIRE_PRESSURE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_TIREPRESSURE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ENGINE_TORQUE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ENGINETORQUE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ENGINE_OIL_LIFE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ENGINEOILLIFE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ODOMETER, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ODOMETER.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_GPS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_GPS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_FUEL_LEVEL_STATE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_INSTANT_FUEL_CONSUMPTION, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_BELT_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BELTSTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_BODY_INFORMATION, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BODYINFO.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_DEVICE_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_DEVICESTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_DRIVER_BRAKING, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BRAKING.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_WIPER_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_WIPERSTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_HEAD_LAMP_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ACC_PEDAL_POSITION, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ACCPEDAL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_STEERING_WHEEL_ANGLE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_STEERINGWHEEL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_E_CALL_INFO, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ECALLINFO.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_AIRBAG_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_EMERGENCY_EVENT, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_CLUSTER_MODE_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_MY_KEY, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_MYKEY.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_FUEL_RANGE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELRANGE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_TURN_SIGNAL, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_TURNSIGNAL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ELECTRONIC_PARK_BRAKE_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ELECTRONICPARKBRAKESTATUS.ordinal()).serializeJSON()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + VehicleDataResult testGps = ( (SubscribeVehicleDataResponse) msg ).getGps(); + VehicleDataResult testOdometer = ( (SubscribeVehicleDataResponse) msg ).getOdometer(); + VehicleDataResult testTirePressure = ( (SubscribeVehicleDataResponse) msg ).getTirePressure(); + VehicleDataResult testBeltStatus = ( (SubscribeVehicleDataResponse) msg ).getBeltStatus(); + VehicleDataResult testBodyInfo = ( (SubscribeVehicleDataResponse) msg ).getBodyInformation(); + VehicleDataResult testDeviceStatus = ( (SubscribeVehicleDataResponse) msg ).getDeviceStatus(); + VehicleDataResult testHeadLampStatus = ( (SubscribeVehicleDataResponse) msg ).getHeadLampStatus(); + VehicleDataResult testECallInfo = ( (SubscribeVehicleDataResponse) msg ).getECallInfo(); + VehicleDataResult testAirbagStatus = ( (SubscribeVehicleDataResponse) msg ).getAirbagStatus(); + VehicleDataResult testEmergencyEvent = ( (SubscribeVehicleDataResponse) msg ).getEmergencyEvent(); + VehicleDataResult testClusterMode = ( (SubscribeVehicleDataResponse) msg ).getClusterModeStatus(); + VehicleDataResult testMyKey = ( (SubscribeVehicleDataResponse) msg ).getMyKey(); + VehicleDataResult testSpeed = ( (SubscribeVehicleDataResponse) msg ).getSpeed(); + VehicleDataResult testRpm = ( (SubscribeVehicleDataResponse) msg ).getRpm(); + VehicleDataResult testFuelLevel = ( (SubscribeVehicleDataResponse) msg ).getFuelLevel(); + VehicleDataResult testConsumption = ( (SubscribeVehicleDataResponse) msg ).getInstantFuelConsumption(); + VehicleDataResult testExternalTemp = ( (SubscribeVehicleDataResponse) msg ).getExternalTemperature(); + VehicleDataResult testEngineTorque = ( (SubscribeVehicleDataResponse) msg ).getEngineTorque(); + VehicleDataResult testEngineOilLife = ( (SubscribeVehicleDataResponse) msg ).getEngineOilLife(); + VehicleDataResult testAccPedal = ( (SubscribeVehicleDataResponse) msg ).getAccPedalPosition(); + VehicleDataResult testSteeringWheel = ( (SubscribeVehicleDataResponse) msg ).getSteeringWheelAngle(); + VehicleDataResult testFuelLevelState = ( (SubscribeVehicleDataResponse) msg ).getFuelLevelState(); + VehicleDataResult testPrndl = ( (SubscribeVehicleDataResponse) msg ).getPrndl(); + VehicleDataResult testBraking = ( (SubscribeVehicleDataResponse) msg ).getDriverBraking(); + VehicleDataResult testWiperStatus = ( (SubscribeVehicleDataResponse) msg ).getWiperStatus(); + VehicleDataResult testFuelRange = ( (SubscribeVehicleDataResponse) msg ).getFuelRange(); + VehicleDataResult testTurnSignal = ( (SubscribeVehicleDataResponse) msg ).getTurnSignal(); + VehicleDataResult testEBrakeStatus = ( (SubscribeVehicleDataResponse) msg ).getElectronicParkBrakeStatus(); + + // Valid Tests + assertTrue(Test.TRUE, testGps.getDataType().equals(VehicleDataType.VEHICLEDATA_GPS)); + assertTrue(Test.TRUE, testOdometer.getDataType().equals(VehicleDataType.VEHICLEDATA_ODOMETER)); + assertTrue(Test.TRUE, testTirePressure.getDataType().equals(VehicleDataType.VEHICLEDATA_TIREPRESSURE)); + assertTrue(Test.TRUE, testBeltStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_BELTSTATUS)); + assertTrue(Test.TRUE, testBodyInfo.getDataType().equals(VehicleDataType.VEHICLEDATA_BODYINFO)); + assertTrue(Test.TRUE, testDeviceStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_DEVICESTATUS)); + assertTrue(Test.TRUE, testHeadLampStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS)); + assertTrue(Test.TRUE, testECallInfo.getDataType().equals(VehicleDataType.VEHICLEDATA_ECALLINFO)); + assertTrue(Test.TRUE, testAirbagStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS)); + assertTrue(Test.TRUE, testEmergencyEvent.getDataType().equals(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT)); + assertTrue(Test.TRUE, testClusterMode.getDataType().equals(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS)); + assertTrue(Test.TRUE, testMyKey.getDataType().equals(VehicleDataType.VEHICLEDATA_MYKEY)); + assertTrue(Test.TRUE, testSpeed.getDataType().equals(VehicleDataType.VEHICLEDATA_SPEED)); + assertTrue(Test.TRUE, testRpm.getDataType().equals(VehicleDataType.VEHICLEDATA_RPM)); + assertTrue(Test.TRUE, testFuelLevel.getDataType().equals(VehicleDataType.VEHICLEDATA_FUELLEVEL)); + assertTrue(Test.TRUE, testConsumption.getDataType().equals(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION)); + assertTrue(Test.TRUE, testExternalTemp.getDataType().equals(VehicleDataType.VEHICLEDATA_EXTERNTEMP)); + assertTrue(Test.TRUE, testEngineTorque.getDataType().equals(VehicleDataType.VEHICLEDATA_ENGINETORQUE)); + assertTrue(Test.TRUE, testEngineOilLife.getDataType().equals(VehicleDataType.VEHICLEDATA_ENGINEOILLIFE)); + assertTrue(Test.TRUE, testAccPedal.getDataType().equals(VehicleDataType.VEHICLEDATA_ACCPEDAL)); + assertTrue(Test.TRUE, testSteeringWheel.getDataType().equals(VehicleDataType.VEHICLEDATA_STEERINGWHEEL)); + assertTrue(Test.TRUE, testFuelLevelState.getDataType().equals(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE)); + assertTrue(Test.TRUE, testPrndl.getDataType().equals(VehicleDataType.VEHICLEDATA_PRNDL)); + assertTrue(Test.TRUE, testBraking.getDataType().equals(VehicleDataType.VEHICLEDATA_BRAKING)); + assertTrue(Test.TRUE, testWiperStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_WIPERSTATUS)); + assertTrue(Test.TRUE, testFuelRange.getDataType().equals(VehicleDataType.VEHICLEDATA_FUELRANGE)); + assertTrue(Test.TRUE, testTurnSignal.getDataType().equals(VehicleDataType.VEHICLEDATA_TURNSIGNAL)); + assertTrue(Test.TRUE, testEBrakeStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_ELECTRONICPARKBRAKESTATUS)); + + // Invalid/Null Tests + SubscribeVehicleDataResponse msg = new SubscribeVehicleDataResponse(); + assertNotNull("Null object creation failed.", msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAccPedalPosition()); + assertNull(Test.NULL, msg.getAirbagStatus()); + assertNull(Test.NULL, msg.getBeltStatus()); + assertNull(Test.NULL, msg.getDriverBraking()); + assertNull(Test.NULL, msg.getFuelLevel()); + assertNull(Test.NULL, msg.getTirePressure()); + assertNull(Test.NULL, msg.getWiperStatus()); + assertNull(Test.NULL, msg.getGps()); + assertNull(Test.NULL, msg.getSpeed()); + assertNull(Test.NULL, msg.getRpm()); + assertNull(Test.NULL, msg.getFuelLevelState()); + assertNull(Test.NULL, msg.getInstantFuelConsumption()); + assertNull(Test.NULL, msg.getExternalTemperature()); + assertNull(Test.NULL, msg.getPrndl()); + assertNull(Test.NULL, msg.getOdometer()); + assertNull(Test.NULL, msg.getBodyInformation()); + assertNull(Test.NULL, msg.getDeviceStatus()); + assertNull(Test.NULL, msg.getHeadLampStatus()); + assertNull(Test.NULL, msg.getEngineTorque()); + assertNull(Test.NULL, msg.getEngineOilLife()); + assertNull(Test.NULL, msg.getSteeringWheelAngle()); + assertNull(Test.NULL, msg.getECallInfo()); + assertNull(Test.NULL, msg.getEmergencyEvent()); + assertNull(Test.NULL, msg.getClusterModeStatus()); + assertNull(Test.NULL, msg.getMyKey()); + assertNull(Test.NULL, msg.getFuelRange()); + assertNull(Test.NULL, msg.getTurnSignal()); + assertNull(Test.NULL, msg.getElectronicParkBrakeStatus()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SubscribeVehicleDataResponse cmd = new SubscribeVehicleDataResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONObject speed = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_SPEED); + VehicleDataResult referenceSpeed = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(speed)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceSpeed, cmd.getSpeed())); + + JSONObject rpm = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_RPM); + VehicleDataResult referenceRpm = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(rpm)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceRpm, cmd.getRpm())); + + JSONObject fuelLevel = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_FUEL_LEVEL); + VehicleDataResult referenceFuelLevel = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(fuelLevel)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceFuelLevel, cmd.getFuelLevel())); + + JSONObject externalTemperature = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_EXTERNAL_TEMPERATURE); + VehicleDataResult referenceExternalTemperature = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(externalTemperature)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceExternalTemperature, cmd.getExternalTemperature())); + + JSONObject prndl = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_PRNDL); + VehicleDataResult referencePrndl = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(prndl)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referencePrndl, cmd.getPrndl())); + + JSONObject tirePressure = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_TIRE_PRESSURE); + VehicleDataResult referenceTirePressure = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(tirePressure)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceTirePressure, cmd.getTirePressure())); + + JSONObject engineTorque = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_ENGINE_TORQUE); + VehicleDataResult referenceEngineTorque = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(engineTorque)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceEngineTorque, cmd.getEngineTorque())); + + JSONObject engineOilLife = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_ENGINE_OIL_LIFE); + VehicleDataResult referenceEngineOilLife = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(engineOilLife)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceEngineOilLife, cmd.getEngineOilLife())); + + JSONObject odometer = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_ODOMETER); + VehicleDataResult referenceOdometer = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(odometer)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceOdometer, cmd.getOdometer())); + + JSONObject gps = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_GPS); + VehicleDataResult referenceGps = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(gps)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceGps, cmd.getGps())); + + JSONObject fuelLevelState = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_FUEL_LEVEL_STATE); + VehicleDataResult referenceFuelLevelState = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(fuelLevelState)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceFuelLevelState, cmd.getFuelLevelState())); + + JSONObject fuelConsumption = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_INSTANT_FUEL_CONSUMPTION); + VehicleDataResult referenceFuelConsumption = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(fuelConsumption)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceFuelConsumption, cmd.getInstantFuelConsumption())); + + JSONObject beltStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_BELT_STATUS); + VehicleDataResult referenceBeltStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(beltStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceBeltStatus, cmd.getBeltStatus())); + + JSONObject bodyInformation = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_BODY_INFORMATION); + VehicleDataResult referenceBodyInformation = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(bodyInformation)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceBodyInformation, cmd.getBodyInformation())); + + JSONObject deviceStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_DEVICE_STATUS); + VehicleDataResult referenceDeviceStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(deviceStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceDeviceStatus, cmd.getDeviceStatus())); + + JSONObject driverBraking = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_DRIVER_BRAKING); + VehicleDataResult referenceDriverBraking = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(driverBraking)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceDriverBraking, cmd.getDriverBraking())); + + JSONObject wiperStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_WIPER_STATUS); + VehicleDataResult referenceWiperStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(wiperStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceWiperStatus, cmd.getWiperStatus())); + + JSONObject headLampStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_HEAD_LAMP_STATUS); + VehicleDataResult referenceHeadLampStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(headLampStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceHeadLampStatus, cmd.getHeadLampStatus())); + + JSONObject accPedalPosition = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_ACC_PEDAL_POSITION); + VehicleDataResult referenceAccPedalPosition = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(accPedalPosition)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceAccPedalPosition, cmd.getAccPedalPosition())); + + JSONObject steeringWheelAngle = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_STEERING_WHEEL_ANGLE); + VehicleDataResult referenceSteeringWheelAngle = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(steeringWheelAngle)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceSteeringWheelAngle, cmd.getSteeringWheelAngle())); + + JSONObject eCallInfo = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_E_CALL_INFO); + VehicleDataResult referenceECallInfo = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(eCallInfo)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceECallInfo, cmd.getECallInfo())); + + JSONObject airbagStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_AIRBAG_STATUS); + VehicleDataResult referenceAirbagStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(airbagStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceAirbagStatus, cmd.getAirbagStatus())); + + JSONObject emergencyEvent = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_EMERGENCY_EVENT); + VehicleDataResult referenceEmergencyEvent = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(emergencyEvent)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceEmergencyEvent, cmd.getEmergencyEvent())); + + JSONObject clusterModeStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_CLUSTER_MODE_STATUS); + VehicleDataResult referenceClusterModeStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(clusterModeStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceClusterModeStatus, cmd.getClusterModeStatus())); + + JSONObject myKey = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_MY_KEY); + VehicleDataResult referenceMyKey = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(myKey)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceMyKey, cmd.getMyKey())); + + JSONObject fuelRange = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_FUEL_RANGE); + VehicleDataResult referenceFuelRange = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(fuelRange)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceFuelRange, cmd.getFuelRange())); + + JSONObject turnSignal = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_TURN_SIGNAL); + VehicleDataResult referenceTurnSignal = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(turnSignal)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceTurnSignal, cmd.getTurnSignal())); + + JSONObject electronicParkBrakeStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, SubscribeVehicleDataResponse.KEY_ELECTRONIC_PARK_BRAKE_STATUS); + VehicleDataResult referenceEBrakeStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(electronicParkBrakeStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceEBrakeStatus, cmd.getElectronicParkBrakeStatus())); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeWaypointsResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeWaypointsResponseTests.java new file mode 100644 index 000000000..a43220dce --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SubscribeWaypointsResponseTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SubscribeWayPointsResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class SubscribeWaypointsResponseTests extends BaseRpcTests { + @Override + protected RPCMessage createMessage(){ + return new SubscribeWayPointsResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SUBSCRIBE_WAY_POINTS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SubscribeWayPointsResponse msg = new SubscribeWayPointsResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SubscribeWayPointsResponse cmd = new SubscribeWayPointsResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals("Correlation ID doesn't match input ID", JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SystemRequestResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SystemRequestResponseTest.java new file mode 100644 index 000000000..80684a04a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/SystemRequestResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SystemRequestResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.SystemRequestResponse} + */ +public class SystemRequestResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new SystemRequestResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.SYSTEM_REQUEST.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + SystemRequestResponse msg = new SystemRequestResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + SystemRequestResponse cmd = new SystemRequestResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnregisterAppInterfaceResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnregisterAppInterfaceResponseTest.java new file mode 100644 index 000000000..7d2fc1645 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnregisterAppInterfaceResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnregisterAppInterfaceResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.UnregisterAppInterfaceResponse} + */ +public class UnregisterAppInterfaceResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new UnregisterAppInterfaceResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.UNREGISTER_APP_INTERFACE.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + UnregisterAppInterfaceResponse msg = new UnregisterAppInterfaceResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnregisterAppInterfaceResponse cmd = new UnregisterAppInterfaceResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeButtonResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeButtonResponseTest.java new file mode 100644 index 000000000..384c5df57 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeButtonResponseTest.java @@ -0,0 +1,74 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnsubscribeButtonResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.UnsubscribeButtonResponse} + */ +public class UnsubscribeButtonResponseTest extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new UnsubscribeButtonResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.UNSUBSCRIBE_BUTTON.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + UnsubscribeButtonResponse msg = new UnsubscribeButtonResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnsubscribeButtonResponse cmd = new UnsubscribeButtonResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeVehicleDataResponseTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeVehicleDataResponseTest.java new file mode 100644 index 000000000..cba7fcf0d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeVehicleDataResponseTest.java @@ -0,0 +1,355 @@ +package com.smartdevicelink.test.rpc.responses; + + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.SubscribeVehicleDataResponse; +import com.smartdevicelink.proxy.rpc.UnsubscribeVehicleDataResponse; +import com.smartdevicelink.proxy.rpc.VehicleDataResult; +import com.smartdevicelink.proxy.rpc.enums.VehicleDataType; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.Validator; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.proxy.rpc.UnsubscribeVehicleDataResponse} + */ +public class UnsubscribeVehicleDataResponseTest extends BaseRpcTests { + + // TODO : Test different result codes. + + @Override + protected RPCMessage createMessage() { + UnsubscribeVehicleDataResponse msg = new UnsubscribeVehicleDataResponse(); + + msg.setSpeed(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_SPEED.ordinal())); + msg.setRpm(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_RPM.ordinal())); + msg.setExternalTemperature(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_EXTERNTEMP.ordinal())); + msg.setFuelLevel(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELLEVEL.ordinal())); + msg.setPrndl(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_PRNDL.ordinal())); + msg.setTirePressure(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_TIREPRESSURE.ordinal())); + msg.setEngineTorque(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ENGINETORQUE.ordinal())); + msg.setEngineOilLife(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ENGINEOILLIFE.ordinal())); + msg.setOdometer(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ODOMETER.ordinal())); + msg.setGps(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_GPS.ordinal())); + msg.setFuelLevelState(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE.ordinal())); + msg.setInstantFuelConsumption(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION.ordinal())); + msg.setBeltStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BELTSTATUS.ordinal())); + msg.setBodyInformation(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BODYINFO.ordinal())); + msg.setDeviceStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_DEVICESTATUS.ordinal())); + msg.setDriverBraking(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BRAKING.ordinal())); + msg.setWiperStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_WIPERSTATUS.ordinal())); + msg.setHeadLampStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS.ordinal())); + msg.setAccPedalPosition(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ACCPEDAL.ordinal())); + msg.setSteeringWheelAngle(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_STEERINGWHEEL.ordinal())); + msg.setECallInfo(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ECALLINFO.ordinal())); + msg.setAirbagStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS.ordinal())); + msg.setEmergencyEvent(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT.ordinal())); + msg.setClusterModeStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS.ordinal())); + msg.setMyKey(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_MYKEY.ordinal())); + msg.setFuelRange(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELRANGE.ordinal())); + msg.setTurnSignal(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_TURNSIGNAL.ordinal())); + msg.setElectronicParkBrakeStatus(Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ELECTRONICPARKBRAKESTATUS.ordinal())); + + return msg; + } + + @Override + protected String getMessageType() { + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType() { + return FunctionID.UNSUBSCRIBE_VEHICLE_DATA.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion) { + JSONObject result = new JSONObject(); + + try { + + // Note: If the key values stored in SubscribeVehicleDataResponse + // were to be in a list then this could be easily looped through + // instead of individually set. + + result.put(SubscribeVehicleDataResponse.KEY_SPEED, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_SPEED.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_RPM, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_RPM.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_EXTERNAL_TEMPERATURE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_EXTERNTEMP.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_FUEL_LEVEL, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELLEVEL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_PRNDL, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_PRNDL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_TIRE_PRESSURE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_TIREPRESSURE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ENGINE_TORQUE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ENGINETORQUE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ENGINE_OIL_LIFE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ENGINEOILLIFE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ODOMETER, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ODOMETER.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_GPS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_GPS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_FUEL_LEVEL_STATE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_INSTANT_FUEL_CONSUMPTION, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_BELT_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BELTSTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_BODY_INFORMATION, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BODYINFO.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_DEVICE_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_DEVICESTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_DRIVER_BRAKING, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_BRAKING.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_WIPER_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_WIPERSTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_HEAD_LAMP_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ACC_PEDAL_POSITION, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ACCPEDAL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_STEERING_WHEEL_ANGLE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_STEERINGWHEEL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_E_CALL_INFO, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ECALLINFO.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_AIRBAG_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_EMERGENCY_EVENT, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_CLUSTER_MODE_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_MY_KEY, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_MYKEY.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_FUEL_RANGE, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_FUELRANGE.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_TURN_SIGNAL, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_TURNSIGNAL.ordinal()).serializeJSON()); + result.put(SubscribeVehicleDataResponse.KEY_ELECTRONIC_PARK_BRAKE_STATUS, Test.GENERAL_VEHICLEDATARESULT_LIST.get(VehicleDataType.VEHICLEDATA_ELECTRONICPARKBRAKESTATUS.ordinal()).serializeJSON()); + } catch (JSONException e) { + fail(Test.JSON_FAIL); + } + + return result; + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Test Values + VehicleDataResult testGps = ( (UnsubscribeVehicleDataResponse) msg ).getGps(); + VehicleDataResult testOdometer = ( (UnsubscribeVehicleDataResponse) msg ).getOdometer(); + VehicleDataResult testTirePressure = ( (UnsubscribeVehicleDataResponse) msg ).getTirePressure(); + VehicleDataResult testBeltStatus = ( (UnsubscribeVehicleDataResponse) msg ).getBeltStatus(); + VehicleDataResult testBodyInfo = ( (UnsubscribeVehicleDataResponse) msg ).getBodyInformation(); + VehicleDataResult testDeviceStatus = ( (UnsubscribeVehicleDataResponse) msg ).getDeviceStatus(); + VehicleDataResult testHeadLampStatus = ( (UnsubscribeVehicleDataResponse) msg ).getHeadLampStatus(); + VehicleDataResult testECallInfo = ( (UnsubscribeVehicleDataResponse) msg ).getECallInfo(); + VehicleDataResult testAirbagStatus = ( (UnsubscribeVehicleDataResponse) msg ).getAirbagStatus(); + VehicleDataResult testEmergencyEvent = ( (UnsubscribeVehicleDataResponse) msg ).getEmergencyEvent(); + VehicleDataResult testClusterMode = ( (UnsubscribeVehicleDataResponse) msg ).getClusterModeStatus(); + VehicleDataResult testMyKey = ( (UnsubscribeVehicleDataResponse) msg ).getMyKey(); + VehicleDataResult testSpeed = ( (UnsubscribeVehicleDataResponse) msg ).getSpeed(); + VehicleDataResult testRpm = ( (UnsubscribeVehicleDataResponse) msg ).getRpm(); + VehicleDataResult testFuelLevel = ( (UnsubscribeVehicleDataResponse) msg ).getFuelLevel(); + VehicleDataResult testConsumption = ( (UnsubscribeVehicleDataResponse) msg ).getInstantFuelConsumption(); + VehicleDataResult testExternalTemp = ( (UnsubscribeVehicleDataResponse) msg ).getExternalTemperature(); + VehicleDataResult testEngineTorque = ( (UnsubscribeVehicleDataResponse) msg ).getEngineTorque(); + VehicleDataResult testEngineOilLife = ( (UnsubscribeVehicleDataResponse) msg ).getEngineOilLife(); + VehicleDataResult testAccPedal = ( (UnsubscribeVehicleDataResponse) msg ).getAccPedalPosition(); + VehicleDataResult testSteeringWheel = ( (UnsubscribeVehicleDataResponse) msg ).getSteeringWheelAngle(); + VehicleDataResult testFuelLevelState = ( (UnsubscribeVehicleDataResponse) msg ).getFuelLevelState(); + VehicleDataResult testPrndl = ( (UnsubscribeVehicleDataResponse) msg ).getPrndl(); + VehicleDataResult testBraking = ( (UnsubscribeVehicleDataResponse) msg ).getDriverBraking(); + VehicleDataResult testWiperStatus = ( (UnsubscribeVehicleDataResponse) msg ).getWiperStatus(); + VehicleDataResult testFuelRange = ( (UnsubscribeVehicleDataResponse) msg ).getFuelRange(); + VehicleDataResult testTurnSignal = ( (UnsubscribeVehicleDataResponse) msg ).getTurnSignal(); + VehicleDataResult testEBrakeStatus = ( (UnsubscribeVehicleDataResponse) msg ).getElectronicParkBrakeStatus(); + + // Valid Tests + assertTrue(Test.TRUE, testGps.getDataType().equals(VehicleDataType.VEHICLEDATA_GPS)); + assertTrue(Test.TRUE, testOdometer.getDataType().equals(VehicleDataType.VEHICLEDATA_ODOMETER)); + assertTrue(Test.TRUE, testTirePressure.getDataType().equals(VehicleDataType.VEHICLEDATA_TIREPRESSURE)); + assertTrue(Test.TRUE, testBeltStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_BELTSTATUS)); + assertTrue(Test.TRUE, testBodyInfo.getDataType().equals(VehicleDataType.VEHICLEDATA_BODYINFO)); + assertTrue(Test.TRUE, testDeviceStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_DEVICESTATUS)); + assertTrue(Test.TRUE, testHeadLampStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_HEADLAMPSTATUS)); + assertTrue(Test.TRUE, testECallInfo.getDataType().equals(VehicleDataType.VEHICLEDATA_ECALLINFO)); + assertTrue(Test.TRUE, testAirbagStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_AIRBAGSTATUS)); + assertTrue(Test.TRUE, testEmergencyEvent.getDataType().equals(VehicleDataType.VEHICLEDATA_EMERGENCYEVENT)); + assertTrue(Test.TRUE, testClusterMode.getDataType().equals(VehicleDataType.VEHICLEDATA_CLUSTERMODESTATUS)); + assertTrue(Test.TRUE, testMyKey.getDataType().equals(VehicleDataType.VEHICLEDATA_MYKEY)); + assertTrue(Test.TRUE, testSpeed.getDataType().equals(VehicleDataType.VEHICLEDATA_SPEED)); + assertTrue(Test.TRUE, testRpm.getDataType().equals(VehicleDataType.VEHICLEDATA_RPM)); + assertTrue(Test.TRUE, testFuelLevel.getDataType().equals(VehicleDataType.VEHICLEDATA_FUELLEVEL)); + assertTrue(Test.TRUE, testConsumption.getDataType().equals(VehicleDataType.VEHICLEDATA_FUELCONSUMPTION)); + assertTrue(Test.TRUE, testExternalTemp.getDataType().equals(VehicleDataType.VEHICLEDATA_EXTERNTEMP)); + assertTrue(Test.TRUE, testEngineTorque.getDataType().equals(VehicleDataType.VEHICLEDATA_ENGINETORQUE)); + assertTrue(Test.TRUE, testEngineOilLife.getDataType().equals(VehicleDataType.VEHICLEDATA_ENGINEOILLIFE)); + assertTrue(Test.TRUE, testAccPedal.getDataType().equals(VehicleDataType.VEHICLEDATA_ACCPEDAL)); + assertTrue(Test.TRUE, testSteeringWheel.getDataType().equals(VehicleDataType.VEHICLEDATA_STEERINGWHEEL)); + assertTrue(Test.TRUE, testFuelLevelState.getDataType().equals(VehicleDataType.VEHICLEDATA_FUELLEVEL_STATE)); + assertTrue(Test.TRUE, testPrndl.getDataType().equals(VehicleDataType.VEHICLEDATA_PRNDL)); + assertTrue(Test.TRUE, testBraking.getDataType().equals(VehicleDataType.VEHICLEDATA_BRAKING)); + assertTrue(Test.TRUE, testWiperStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_WIPERSTATUS)); + assertTrue(Test.TRUE, testFuelRange.getDataType().equals(VehicleDataType.VEHICLEDATA_FUELRANGE)); + assertTrue(Test.TRUE, testTurnSignal.getDataType().equals(VehicleDataType.VEHICLEDATA_TURNSIGNAL)); + assertTrue(Test.TRUE, testEBrakeStatus.getDataType().equals(VehicleDataType.VEHICLEDATA_ELECTRONICPARKBRAKESTATUS)); + + // Invalid/Null Tests + UnsubscribeVehicleDataResponse msg = new UnsubscribeVehicleDataResponse(); + assertNotNull("Null object creation failed.", msg); + testNullBase(msg); + + assertNull(Test.NULL, msg.getAccPedalPosition()); + assertNull(Test.NULL, msg.getAirbagStatus()); + assertNull(Test.NULL, msg.getBeltStatus()); + assertNull(Test.NULL, msg.getDriverBraking()); + assertNull(Test.NULL, msg.getFuelLevel()); + assertNull(Test.NULL, msg.getTirePressure()); + assertNull(Test.NULL, msg.getWiperStatus()); + assertNull(Test.NULL, msg.getGps()); + assertNull(Test.NULL, msg.getSpeed()); + assertNull(Test.NULL, msg.getRpm()); + assertNull(Test.NULL, msg.getFuelLevelState()); + assertNull(Test.NULL, msg.getInstantFuelConsumption()); + assertNull(Test.NULL, msg.getExternalTemperature()); + assertNull(Test.NULL, msg.getPrndl()); + assertNull(Test.NULL, msg.getOdometer()); + assertNull(Test.NULL, msg.getBodyInformation()); + assertNull(Test.NULL, msg.getDeviceStatus()); + assertNull(Test.NULL, msg.getHeadLampStatus()); + assertNull(Test.NULL, msg.getEngineTorque()); + assertNull(Test.NULL, msg.getEngineOilLife()); + assertNull(Test.NULL, msg.getSteeringWheelAngle()); + assertNull(Test.NULL, msg.getECallInfo()); + assertNull(Test.NULL, msg.getEmergencyEvent()); + assertNull(Test.NULL, msg.getClusterModeStatus()); + assertNull(Test.NULL, msg.getMyKey()); + assertNull(Test.NULL, msg.getFuelRange()); + assertNull(Test.NULL, msg.getTurnSignal()); + assertNull(Test.NULL, msg.getElectronicParkBrakeStatus()); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnsubscribeVehicleDataResponse cmd = new UnsubscribeVehicleDataResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + + JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS); + + JSONObject speed = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_SPEED); + VehicleDataResult referenceSpeed = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(speed)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceSpeed, cmd.getSpeed())); + + JSONObject rpm = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_RPM); + VehicleDataResult referenceRpm = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(rpm)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceRpm, cmd.getRpm())); + + JSONObject fuelLevel = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_FUEL_LEVEL); + VehicleDataResult referenceFuelLevel = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(fuelLevel)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceFuelLevel, cmd.getFuelLevel())); + + JSONObject externalTemperature = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_EXTERNAL_TEMPERATURE); + VehicleDataResult referenceExternalTemperature = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(externalTemperature)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceExternalTemperature, cmd.getExternalTemperature())); + + JSONObject prndl = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_PRNDL); + VehicleDataResult referencePrndl = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(prndl)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referencePrndl, cmd.getPrndl())); + + JSONObject tirePressure = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_TIRE_PRESSURE); + VehicleDataResult referenceTirePressure = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(tirePressure)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceTirePressure, cmd.getTirePressure())); + + JSONObject engineTorque = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_ENGINE_TORQUE); + VehicleDataResult referenceEngineTorque = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(engineTorque)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceEngineTorque, cmd.getEngineTorque())); + + JSONObject engineOilLife = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_ENGINE_OIL_LIFE); + VehicleDataResult referenceEngineOilLife = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(engineOilLife)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceEngineOilLife, cmd.getEngineOilLife())); + + JSONObject odometer = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_ODOMETER); + VehicleDataResult referenceOdometer = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(odometer)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceOdometer, cmd.getOdometer())); + + JSONObject gps = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_GPS); + VehicleDataResult referenceGps = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(gps)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceGps, cmd.getGps())); + + JSONObject fuelLevelState = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_FUEL_LEVEL_STATE); + VehicleDataResult referenceFuelLevelState = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(fuelLevelState)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceFuelLevelState, cmd.getFuelLevelState())); + + JSONObject fuelConsumption = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_INSTANT_FUEL_CONSUMPTION); + VehicleDataResult referenceFuelConsumption = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(fuelConsumption)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceFuelConsumption, cmd.getInstantFuelConsumption())); + + JSONObject beltStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_BELT_STATUS); + VehicleDataResult referenceBeltStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(beltStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceBeltStatus, cmd.getBeltStatus())); + + JSONObject bodyInformation = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_BODY_INFORMATION); + VehicleDataResult referenceBodyInformation = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(bodyInformation)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceBodyInformation, cmd.getBodyInformation())); + + JSONObject deviceStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_DEVICE_STATUS); + VehicleDataResult referenceDeviceStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(deviceStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceDeviceStatus, cmd.getDeviceStatus())); + + JSONObject driverBraking = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_DRIVER_BRAKING); + VehicleDataResult referenceDriverBraking = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(driverBraking)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceDriverBraking, cmd.getDriverBraking())); + + JSONObject wiperStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_WIPER_STATUS); + VehicleDataResult referenceWiperStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(wiperStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceWiperStatus, cmd.getWiperStatus())); + + JSONObject headLampStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_HEAD_LAMP_STATUS); + VehicleDataResult referenceHeadLampStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(headLampStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceHeadLampStatus, cmd.getHeadLampStatus())); + + JSONObject accPedalPosition = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_ACC_PEDAL_POSITION); + VehicleDataResult referenceAccPedalPosition = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(accPedalPosition)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceAccPedalPosition, cmd.getAccPedalPosition())); + + JSONObject steeringWheelAngle = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_STEERING_WHEEL_ANGLE); + VehicleDataResult referenceSteeringWheelAngle = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(steeringWheelAngle)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceSteeringWheelAngle, cmd.getSteeringWheelAngle())); + + JSONObject eCallInfo = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_E_CALL_INFO); + VehicleDataResult referenceECallInfo = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(eCallInfo)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceECallInfo, cmd.getECallInfo())); + + JSONObject airbagStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_AIRBAG_STATUS); + VehicleDataResult referenceAirbagStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(airbagStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceAirbagStatus, cmd.getAirbagStatus())); + + JSONObject emergencyEvent = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_EMERGENCY_EVENT); + VehicleDataResult referenceEmergencyEvent = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(emergencyEvent)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceEmergencyEvent, cmd.getEmergencyEvent())); + + JSONObject clusterModeStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_CLUSTER_MODE_STATUS); + VehicleDataResult referenceClusterModeStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(clusterModeStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceClusterModeStatus, cmd.getClusterModeStatus())); + + JSONObject myKey = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_MY_KEY); + VehicleDataResult referenceMyKey = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(myKey)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceMyKey, cmd.getMyKey())); + + JSONObject fuelRange = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_FUEL_RANGE); + VehicleDataResult referenceFuelRange = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(fuelRange)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceFuelRange, cmd.getFuelRange())); + + JSONObject turnSignal = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_TURN_SIGNAL); + VehicleDataResult referenceTurnSignal = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(turnSignal)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceTurnSignal, cmd.getTurnSignal())); + + JSONObject eBrakeStatus = JsonUtils.readJsonObjectFromJsonObject(parameters, UnsubscribeVehicleDataResponse.KEY_ELECTRONIC_PARK_BRAKE_STATUS); + VehicleDataResult referenceEBrakeStatus = new VehicleDataResult(JsonRPCMarshaller.deserializeJSONObject(eBrakeStatus)); + assertTrue(Test.TRUE, Validator.validateVehicleDataResult(referenceEBrakeStatus, cmd.getElectronicParkBrakeStatus())); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeWayPointsResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeWayPointsResponseTests.java new file mode 100644 index 000000000..b8b69be60 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UnsubscribeWayPointsResponseTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.responses; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UnsubscribeWayPointsResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Hashtable; + +/** + * Created by austinkirk on 6/7/17. + */ + +public class UnsubscribeWayPointsResponseTests extends BaseRpcTests{ + @Override + protected RPCMessage createMessage(){ + return new UnsubscribeWayPointsResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.UNSUBSCRIBE_WAY_POINTS.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + UnsubscribeWayPointsResponse msg = new UnsubscribeWayPointsResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests a valid JSON construction of this RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UnsubscribeWayPointsResponse cmd = new UnsubscribeWayPointsResponse(hash); + + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals("Correlation ID doesn't match input ID", JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UpdateTurnListResponseTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UpdateTurnListResponseTests.java new file mode 100644 index 000000000..757f3b185 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/responses/UpdateTurnListResponseTests.java @@ -0,0 +1,73 @@ +package com.smartdevicelink.test.rpc.responses; + +import java.util.Hashtable; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.smartdevicelink.marshal.JsonRPCMarshaller; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.rpc.UpdateTurnListResponse; +import com.smartdevicelink.test.BaseRpcTests; +import com.smartdevicelink.test.JsonUtils; +import com.smartdevicelink.test.Test; +import com.smartdevicelink.test.json.rpc.JsonFileReader; + +/** + * This is a unit test class for the SmartDeviceLink library project class : + * {@link com.smartdevicelink.rpc.UpdateTurnListResponse} + */ +public class UpdateTurnListResponseTests extends BaseRpcTests { + + @Override + protected RPCMessage createMessage(){ + return new UpdateTurnListResponse(); + } + + @Override + protected String getMessageType(){ + return RPCMessage.KEY_RESPONSE; + } + + @Override + protected String getCommandType(){ + return FunctionID.UPDATE_TURN_LIST.toString(); + } + + @Override + protected JSONObject getExpectedParameters(int sdlVersion){ + return new JSONObject(); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testRpcValues () { + // Invalid/Null Tests + UpdateTurnListResponse msg = new UpdateTurnListResponse(); + assertNotNull(Test.NOT_NULL, msg); + testNullBase(msg); + } + + /** + * Tests the expected values of the RPC message. + */ + public void testJsonConstructor () { + JSONObject commandJson = JsonFileReader.readId(this.mContext, getCommandType(), getMessageType()); + assertNotNull(Test.NOT_NULL, commandJson); + + try { + Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson); + UpdateTurnListResponse cmd = new UpdateTurnListResponse(hash); + JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType()); + assertNotNull(Test.NOT_NULL, body); + + // Test everything in the json body. + assertEquals(Test.MATCH, JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME), cmd.getFunctionName()); + assertEquals(Test.MATCH, JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID), cmd.getCorrelationID()); + } catch (JSONException e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file |