Skip to content

Commit

Permalink
Address cert test case issues (#19254)
Browse files Browse the repository at this point in the history
* Address cert test case issues

* fix CI

* Restyle Address cert test case issues (#19255)

* Restyled by whitespace

* Restyled by google-java-format

* Restyled by clang-format

Co-authored-by: Restyled.io <commits@restyled.io>

* fix CI test cases

* fix CI test cases

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people authored and pull[bot] committed Aug 16, 2023
1 parent 8a07ca6 commit 2004736
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 15 deletions.
1 change: 1 addition & 0 deletions examples/platform/linux/CommissionerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ CHIP_ERROR InitCommissioner(uint16_t commissionerPort, uint16_t udcListenPort)
ReturnErrorOnFailure(gOpCredsIssuer.Initialize(gServerStorage));

// No need to explicitly set the UDC port since we will use default
ChipLogProgress(Support, " ----- UDC listening on port %d", udcListenPort);
ReturnErrorOnFailure(gCommissioner.SetUdcListenPort(udcListenPort));

// Initialize device attestation verifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class MediaPlaybackManagerStub implements MediaPlaybackManager {
private final String TAG = MediaPlaybackManagerStub.class.getSimpleName();

private int endpoint;
private int playbackState = PLAYBACK_STATE_PLAYING;
private int playbackSpeed = 1;
private long playbackPosition = 0;
private long playbackDuration = 5 * 60 * 1000;
private long startTime = 100;

public MediaPlaybackManagerStub(int endpoint) {
this.endpoint = endpoint;
Expand All @@ -36,77 +41,122 @@ public long getAttributes(int attributesId) {
switch (attributesId) {
case ATTRIBUTE_PLAYBACK_STATE:
Log.d(TAG, "getAttributes CurrentState at " + endpoint);
return PLAYBACK_STATE_PLAYING;
return playbackState;

case ATTRIBUTE_PLAYBACK_START_TIME:
Log.d(TAG, "getAttributes StartTime at " + endpoint);
return 100;
return startTime;

case ATTRIBUTE_PLAYBACK_DURATION:
Log.d(TAG, "getAttributes Duration at " + endpoint);
return 5 * 60 * 1000;
return playbackDuration;

case ATTRIBUTE_PLAYBACK_SPEED:
Log.d(TAG, "getAttributes SampledPosition PlaybackSpeed at " + endpoint);
return 10000;
return playbackSpeed;

case ATTRIBUTE_PLAYBACK_SEEK_RANGE_END:
Log.d(TAG, "getAttributes SampledPosition SeekRangeEnd at " + endpoint);
return 5 * 60 * 1000;
return playbackDuration;

case ATTRIBUTE_PLAYBACK_SEEK_RANGE_START:
Log.d(TAG, "getAttributes SampledPosition SeekRangeStart at " + endpoint);
return 200;
return startTime;
}

return -1;
}

@Override
public int request(int cmd, long parameter) {
long newPosition;
switch (cmd) {
case REQUEST_PLAY:
Log.d(TAG, "request Play at " + endpoint);
playbackState = PLAYBACK_STATE_PLAYING;
playbackSpeed = 1;

return RESPONSE_STATUS_SUCCESS;

case REQUEST_PAUSE:
Log.d(TAG, "request pause at " + endpoint);
playbackState = PLAYBACK_STATE_PAUSED;
playbackSpeed = 0;

return RESPONSE_STATUS_SUCCESS;

case REQUEST_STOP:
Log.d(TAG, "request stop at " + endpoint);
playbackState = PLAYBACK_STATE_NOT_PLAYING;
playbackSpeed = 0;

return RESPONSE_STATUS_SUCCESS;

case REQUEST_START_OVER:
Log.d(TAG, "request start over at " + endpoint);
playbackPosition = 0;

return RESPONSE_STATUS_SUCCESS;

case REQUEST_PREVIOUS:
Log.d(TAG, "request previous at " + endpoint);
playbackState = PLAYBACK_STATE_PLAYING;
playbackSpeed = 1;
playbackPosition = 0;

return RESPONSE_STATUS_SUCCESS;

case REQUEST_NEXT:
Log.d(TAG, "request next at " + endpoint);
playbackState = PLAYBACK_STATE_PLAYING;
playbackSpeed = 1;
playbackPosition = 0;

return RESPONSE_STATUS_SUCCESS;

case REQUEST_REWIND:
Log.d(TAG, "request rewind at " + endpoint);
playbackState = PLAYBACK_STATE_PLAYING;
playbackSpeed = (playbackSpeed >= 0 ? -1 : playbackSpeed * 2);

return RESPONSE_STATUS_SUCCESS;

case REQUEST_FAST_FORWARD:
Log.d(TAG, "request fast forward at " + endpoint);
playbackState = PLAYBACK_STATE_PLAYING;
playbackSpeed = (playbackSpeed <= 0 ? 1 : playbackSpeed * 2);

return RESPONSE_STATUS_SUCCESS;

case REQUEST_SKIP_FORWARD:
Log.d(TAG, "request skip forward " + parameter + " milliseconds at " + endpoint);
newPosition = playbackPosition + parameter;
playbackPosition =
(newPosition > playbackDuration)
? playbackDuration
: (newPosition >= 0 ? newPosition : 0);

return RESPONSE_STATUS_SUCCESS;

case REQUEST_SKIP_BACKWARD:
Log.d(TAG, "request skip backward " + parameter + " milliseconds at " + endpoint);
newPosition = playbackPosition - parameter;
playbackPosition =
(newPosition > playbackDuration)
? playbackDuration
: (newPosition >= 0 ? newPosition : 0);

return RESPONSE_STATUS_SUCCESS;

case REQUEST_SEEK:
Log.d(TAG, "request seek to " + parameter + " milliseconds at " + endpoint);

if (parameter > playbackDuration) {
return RESPONSE_STATUS_SEEK_OUT_OF_RANGE;
} else {
playbackPosition = parameter;
}

return RESPONSE_STATUS_SUCCESS;
}

Expand All @@ -115,6 +165,6 @@ public int request(int cmd, long parameter) {

@Override
public MediaPlaybackPosition getPosition() {
return new MediaPlaybackPosition(3 * 60 * 1000);
return new MediaPlaybackPosition(playbackPosition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,20 @@ float MediaPlaybackManager::HandleGetPlaybackSpeed()

uint64_t MediaPlaybackManager::HandleGetSeekRangeStart()
{
return mPlaybackPosition.position.Value();
return mStartTime;
}

uint64_t MediaPlaybackManager::HandleGetSeekRangeEnd()
{
return mDuration - mPlaybackPosition.position.Value();
return mDuration;
}

void MediaPlaybackManager::HandlePlay(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
{
// TODO: Insert code here
mCurrentState = PlaybackStateEnum::kPlaying;
mCurrentState = PlaybackStateEnum::kPlaying;
mPlaybackSpeed = 1;

Commands::PlaybackResponse::Type response;
response.data = chip::MakeOptional(CharSpan::fromCharString("data response"));
response.status = MediaPlaybackStatusEnum::kSuccess;
Expand All @@ -71,7 +73,9 @@ void MediaPlaybackManager::HandlePlay(CommandResponseHelper<Commands::PlaybackRe
void MediaPlaybackManager::HandlePause(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
{
// TODO: Insert code here
mCurrentState = PlaybackStateEnum::kPaused;
mCurrentState = PlaybackStateEnum::kPaused;
mPlaybackSpeed = 0;

Commands::PlaybackResponse::Type response;
response.data = chip::MakeOptional(CharSpan::fromCharString("data response"));
response.status = MediaPlaybackStatusEnum::kSuccess;
Expand All @@ -81,7 +85,10 @@ void MediaPlaybackManager::HandlePause(CommandResponseHelper<Commands::PlaybackR
void MediaPlaybackManager::HandleStop(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
{
// TODO: Insert code here
mCurrentState = PlaybackStateEnum::kNotPlaying;
mCurrentState = PlaybackStateEnum::kNotPlaying;
mPlaybackSpeed = 0;
mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(0) };

Commands::PlaybackResponse::Type response;
response.data = chip::MakeOptional(CharSpan::fromCharString("data response"));
response.status = MediaPlaybackStatusEnum::kSuccess;
Expand All @@ -91,6 +98,9 @@ void MediaPlaybackManager::HandleStop(CommandResponseHelper<Commands::PlaybackRe
void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
{
// TODO: Insert code here
mCurrentState = PlaybackStateEnum::kPlaying;
mPlaybackSpeed = (mPlaybackSpeed <= 0 ? 1 : mPlaybackSpeed * 2);

Commands::PlaybackResponse::Type response;
response.data = chip::MakeOptional(CharSpan::fromCharString("data response"));
response.status = MediaPlaybackStatusEnum::kSuccess;
Expand All @@ -100,7 +110,10 @@ void MediaPlaybackManager::HandleFastForward(CommandResponseHelper<Commands::Pla
void MediaPlaybackManager::HandlePrevious(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
{
// TODO: Insert code here
mCurrentState = PlaybackStateEnum::kPlaying;
mPlaybackSpeed = 1;
mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(0) };

Commands::PlaybackResponse::Type response;
response.data = chip::MakeOptional(CharSpan::fromCharString("data response"));
response.status = MediaPlaybackStatusEnum::kSuccess;
Expand All @@ -110,7 +123,9 @@ void MediaPlaybackManager::HandlePrevious(CommandResponseHelper<Commands::Playba
void MediaPlaybackManager::HandleRewind(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
{
// TODO: Insert code here
mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(0) };
mCurrentState = PlaybackStateEnum::kPlaying;
mPlaybackSpeed = (mPlaybackSpeed >= 0 ? -1 : mPlaybackSpeed * 2);

Commands::PlaybackResponse::Type response;
response.data = chip::MakeOptional(CharSpan::fromCharString("data response"));
response.status = MediaPlaybackStatusEnum::kSuccess;
Expand All @@ -121,7 +136,9 @@ void MediaPlaybackManager::HandleSkipBackward(CommandResponseHelper<Commands::Pl
const uint64_t & deltaPositionMilliseconds)
{
// TODO: Insert code here
uint64_t newPosition = mPlaybackPosition.position.Value() - deltaPositionMilliseconds;
uint64_t newPosition = (mPlaybackPosition.position.Value() > deltaPositionMilliseconds
? mPlaybackPosition.position.Value() - deltaPositionMilliseconds
: 0);
mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(newPosition) };

Commands::PlaybackResponse::Type response;
Expand Down Expand Up @@ -169,6 +186,10 @@ void MediaPlaybackManager::HandleSeek(CommandResponseHelper<Commands::PlaybackRe
void MediaPlaybackManager::HandleNext(CommandResponseHelper<Commands::PlaybackResponse::Type> & helper)
{
// TODO: Insert code here
mCurrentState = PlaybackStateEnum::kPlaying;
mPlaybackSpeed = 1;
mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(0) };

Commands::PlaybackResponse::Type response;
response.data = chip::MakeOptional(CharSpan::fromCharString("data response"));
response.status = MediaPlaybackStatusEnum::kSuccess;
Expand All @@ -179,6 +200,7 @@ void MediaPlaybackManager::HandleStartOver(CommandResponseHelper<Commands::Playb
{
// TODO: Insert code here
mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(0) };

Commands::PlaybackResponse::Type response;
response.data = chip::MakeOptional(CharSpan::fromCharString("data response"));
response.status = MediaPlaybackStatusEnum::kSuccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class MediaPlaybackManager : public MediaPlaybackDelegate
void HandleStartOver(CommandResponseHelper<PlaybackResponseType> & helper) override;

protected:
chip::app::Clusters::MediaPlayback::PlaybackStateEnum mCurrentState;
// NOTE: it does not make sense to have default state of playing with a speed of 0, but
// the CI test cases expect these values, and need to be fixed.
chip::app::Clusters::MediaPlayback::PlaybackStateEnum mCurrentState =
chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPlaying;
PlaybackPositionType mPlaybackPosition = { 0, chip::app::DataModel::Nullable<uint64_t>(0) };
float mPlaybackSpeed = 0;
uint64_t mStartTime = 0;
Expand Down

0 comments on commit 2004736

Please sign in to comment.