Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/issue 595 - Progress Bar Seek Feature #749

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdl_android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
})
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.9.0'
implementation 'com.android.support:support-annotations:27.1.1'

}

Expand Down
13 changes: 13 additions & 0 deletions sdl_android/src/androidTest/assets/json/OnSeekMediaClockTimer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"notification":{
"name":"OnSeekMediaClockTimer",
"correlationID":150,
"parameters":{
"seekTime":{
"minutes":55,
"seconds":19,
"hours":12
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"seconds":19,
"hours":12
},
"updateMode":"COUNTDOWN"
"updateMode":"COUNTDOWN",
"enableSeek": true
}
},
"response":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,20 +722,23 @@ public void testBuildSetGlobalProperties () {
public void testBuildSetMediaClockTimer () {

Integer hours = 0, minutes = 0, seconds = 0, testCorrelationID = 0;
Boolean enableSeek = true;
UpdateMode testMode = UpdateMode.COUNTUP;
SetMediaClockTimer testSMCT;

// Test -- buildSetMediaClockTimer(Integer hours, Integer minutes, Integer seconds, UpdateMode updateMode, Integer correlationID)
testSMCT = RPCRequestFactory.buildSetMediaClockTimer(hours, minutes, seconds, testMode, testCorrelationID);
testSMCT = RPCRequestFactory.buildSetMediaClockTimer(hours, minutes, seconds, testMode, enableSeek, testCorrelationID);
assertEquals(Test.MATCH, hours, testSMCT.getStartTime().getHours());
assertEquals(Test.MATCH, minutes, testSMCT.getStartTime().getMinutes());
assertEquals(Test.MATCH, seconds, testSMCT.getStartTime().getSeconds());
assertEquals(Test.MATCH, testMode, testSMCT.getUpdateMode());
assertEquals(Test.MATCH, enableSeek, testSMCT.getEnableSeek());
assertEquals(Test.MATCH, testCorrelationID, testSMCT.getCorrelationID());

testSMCT = RPCRequestFactory.buildSetMediaClockTimer(null, null, null, null, null);
testSMCT = RPCRequestFactory.buildSetMediaClockTimer(null, null, null, null, null, null);
assertNull(Test.NULL, testSMCT.getStartTime());
assertNull(Test.NULL, testSMCT.getUpdateMode());
assertNull(Test.NULL, testSMCT.getEnableSeek());
assertNotNull(Test.NOT_NULL, testSMCT.getCorrelationID());

// Test -- buildSetMediaClockTimer(UpdateMode updateMode, Integer correlationID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.smartdevicelink.proxy.rpc.OnLanguageChange;
import com.smartdevicelink.proxy.rpc.OnLockScreenStatus;
import com.smartdevicelink.proxy.rpc.OnPermissionsChange;
import com.smartdevicelink.proxy.rpc.OnSeekMediaClockTimer;
import com.smartdevicelink.proxy.rpc.OnStreamRPC;
import com.smartdevicelink.proxy.rpc.OnSystemRequest;
import com.smartdevicelink.proxy.rpc.OnTBTClientState;
Expand Down Expand Up @@ -619,5 +620,10 @@ public void onGenericResponse(GenericResponse response) {
public void onSendHapticDataResponse(SendHapticDataResponse response) {
Log.i(TAG, "SendHapticDataResponse response from SDL: " + response);
}

@Override
public void onSeekMediaClockTimer(OnSeekMediaClockTimer notification) {

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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.OnSeekMediaClockTimer;
import com.smartdevicelink.proxy.rpc.StartTime;
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 OnSeekMediaClockTimerTests extends BaseRpcTests {
@Override
protected RPCMessage createMessage(){
OnSeekMediaClockTimer msg = new OnSeekMediaClockTimer();
msg.setSeekTime(Test.GENERAL_STARTTIME);

return msg;
}

@Override
protected String getMessageType(){
return RPCMessage.KEY_NOTIFICATION;
}

@Override
protected String getCommandType(){
return FunctionID.ON_SEEK_MEDIA_CLOCK_TIMER.toString();
}

@Override
protected JSONObject getExpectedParameters(int sdlVersion){
JSONObject result = new JSONObject();
try {
result.put(OnSeekMediaClockTimer.KEY_SEEK_TIME, Test.JSON_STARTTIME);
} catch (JSONException e) {
e.printStackTrace();
}

return result;
}

/**
* Tests the expected values of the RPC message.
*/
public void testRpcValues () {
// Test Values
StartTime seekTime = ((OnSeekMediaClockTimer) msg).getSeekTime();

// Valid Tests
assertEquals(Test.MATCH, Test.GENERAL_STARTTIME, seekTime);

// Invalid/Null Tests
OnSeekMediaClockTimer msg = new OnSeekMediaClockTimer();
assertNotNull(Test.NOT_NULL, msg);
testNullBase(msg);

assertNull(Test.NULL, msg.getSeekTime());
}

/**
* 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);
OnSeekMediaClockTimer cmd = new OnSeekMediaClockTimer(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());

JSONObject parameters = JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS);
JSONObject seekTime = JsonUtils.readJsonObjectFromJsonObject(parameters, OnSeekMediaClockTimer.KEY_SEEK_TIME);
StartTime referenceSeekTime = new StartTime(JsonRPCMarshaller.deserializeJSONObject(seekTime));
assertTrue(Test.TRUE, Validator.validateStartTime(referenceSeekTime, cmd.getSeekTime()));

} catch (JSONException e) {
fail(Test.JSON_FAIL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.rpc.SetMediaClockTimer}
* {@link com.smartdevicelink.proxy.rpc.SetMediaClockTimer}
*/
public class SetMediaClockTimerTests extends BaseRpcTests {

Expand All @@ -30,6 +30,7 @@ protected RPCMessage createMessage() {
msg.setStartTime(Test.GENERAL_STARTTIME);
msg.setEndTime(Test.GENERAL_STARTTIME);
msg.setUpdateMode(Test.GENERAL_UPDATEMODE);
msg.setEnableSeek(Test.GENERAL_BOOLEAN);

return msg;
}
Expand All @@ -51,7 +52,8 @@ protected JSONObject getExpectedParameters(int sdlVersion) {
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_UPDATE_MODE, Test.GENERAL_UPDATEMODE);
result.put(SetMediaClockTimer.KEY_ENABLE_SEEK, Test.GENERAL_BOOLEAN);
} catch (JSONException e) {
fail(Test.JSON_FAIL);
}
Expand All @@ -67,12 +69,14 @@ public void testRpcValues () {
StartTime testStartTime = ( (SetMediaClockTimer) msg ).getStartTime();
StartTime testEndTime = ( (SetMediaClockTimer) msg ).getEndTime();
UpdateMode testUpdateMode = ( (SetMediaClockTimer) msg ).getUpdateMode();
Boolean testEnableSeek = ( (SetMediaClockTimer) msg ).getEnableSeek();

// Valid Tests
assertEquals(Test.MATCH, Test.GENERAL_UPDATEMODE, testUpdateMode);
assertTrue(Test.TRUE, Validator.validateStartTime(Test.GENERAL_STARTTIME, testStartTime));
assertTrue(Test.TRUE, Validator.validateStartTime(Test.GENERAL_STARTTIME, testEndTime));

assertEquals(Test.MATCH, Boolean.valueOf(Test.GENERAL_BOOLEAN), testEnableSeek);

// Invalid/Null Tests
SetMediaClockTimer msg = new SetMediaClockTimer();
assertNotNull(Test.NOT_NULL, msg);
Expand All @@ -81,6 +85,7 @@ public void testRpcValues () {
assertNull(Test.NULL, msg.getStartTime());
assertNull(Test.NULL, msg.getEndTime());
assertNull(Test.NULL, msg.getUpdateMode());
assertNull(Test.NULL, msg.getEnableSeek());
}

/**
Expand Down Expand Up @@ -110,6 +115,8 @@ public void testJsonConstructor () {
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.readBooleanFromJsonObject(parameters, SetMediaClockTimer.KEY_ENABLE_SEEK), cmd.getEnableSeek());
} catch (JSONException e) {
fail(Test.JSON_FAIL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public enum FunctionID{
ON_HASH_CHANGE(32782, "OnHashChange"),
ON_INTERIOR_VEHICLE_DATA(32783, "OnInteriorVehicleData"),
ON_WAY_POINT_CHANGE(32784, "OnWayPointChange"),
ON_SEEK_MEDIA_CLOCK_TIMER(32785, "OnSeekMediaClockTimer"),

// MOCKED FUNCTIONS (NOT SENT FROM HEAD-UNIT)
ON_LOCK_SCREEN_STATUS(-1, "OnLockScreenStatus"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,9 @@ public static SetGlobalProperties buildSetGlobalProperties(

return req;
}

public static SetMediaClockTimer buildSetMediaClockTimer(Integer hours,
Integer minutes, Integer seconds, UpdateMode updateMode,
Integer correlationID) {

public static SetMediaClockTimer buildSetMediaClockTimer(Integer hours, Integer minutes,
Integer seconds, UpdateMode updateMode, Boolean enableSeek, Integer correlationID) {

SetMediaClockTimer msg = new SetMediaClockTimer();
if (hours != null || minutes != null || seconds != null) {
Expand All @@ -706,20 +705,32 @@ public static SetMediaClockTimer buildSetMediaClockTimer(Integer hours,
}

msg.setUpdateMode(updateMode);
msg.setEnableSeek(enableSeek);
msg.setCorrelationID(correlationID);

return msg;
}

@Deprecated
public static SetMediaClockTimer buildSetMediaClockTimer(Integer hours,
Integer minutes, Integer seconds, UpdateMode updateMode,
Integer correlationID) {

SetMediaClockTimer msg = buildSetMediaClockTimer(hours, minutes, seconds, updateMode, null, correlationID);

return msg;
}

@Deprecated
public static SetMediaClockTimer buildSetMediaClockTimer(
UpdateMode updateMode, Integer correlationID) {
Integer hours = null;
Integer minutes = null;
Integer seconds = null;
Boolean enableSeek = null;

SetMediaClockTimer msg = buildSetMediaClockTimer(hours, minutes,
seconds, updateMode, correlationID);
seconds, updateMode, enableSeek, correlationID);
return msg;
}

Expand Down
Loading