From 2004736d2838c0d1a6b51a63e08e5134beb29eed Mon Sep 17 00:00:00 2001 From: chrisdecenzo <61757564+chrisdecenzo@users.noreply.github.com> Date: Tue, 7 Jun 2022 12:42:17 -0700 Subject: [PATCH] Address cert test case issues (#19254) * 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 * 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 --- examples/platform/linux/CommissionerMain.cpp | 1 + .../chip/tvapp/MediaPlaybackManagerStub.java | 64 +++++++++++++++++-- .../media-playback/MediaPlaybackManager.cpp | 36 +++++++++-- .../media-playback/MediaPlaybackManager.h | 5 +- 4 files changed, 91 insertions(+), 15 deletions(-) diff --git a/examples/platform/linux/CommissionerMain.cpp b/examples/platform/linux/CommissionerMain.cpp index 6008bc817c6f4d..816c3563122e3d 100644 --- a/examples/platform/linux/CommissionerMain.cpp +++ b/examples/platform/linux/CommissionerMain.cpp @@ -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 diff --git a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/MediaPlaybackManagerStub.java b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/MediaPlaybackManagerStub.java index 9e7c1d7bdca3ba..1c6a003c31d72e 100755 --- a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/MediaPlaybackManagerStub.java +++ b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/MediaPlaybackManagerStub.java @@ -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; @@ -36,27 +41,27 @@ 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; @@ -64,49 +69,94 @@ public long getAttributes(int attributesId) { @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; } @@ -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); } } diff --git a/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.cpp b/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.cpp index 64f1960a8476e2..cac5c4c846cd04 100644 --- a/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.cpp +++ b/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.cpp @@ -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 & 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; @@ -71,7 +73,9 @@ void MediaPlaybackManager::HandlePlay(CommandResponseHelper & 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; @@ -81,7 +85,10 @@ void MediaPlaybackManager::HandlePause(CommandResponseHelper & helper) { // TODO: Insert code here - mCurrentState = PlaybackStateEnum::kNotPlaying; + mCurrentState = PlaybackStateEnum::kNotPlaying; + mPlaybackSpeed = 0; + mPlaybackPosition = { 0, chip::app::DataModel::Nullable(0) }; + Commands::PlaybackResponse::Type response; response.data = chip::MakeOptional(CharSpan::fromCharString("data response")); response.status = MediaPlaybackStatusEnum::kSuccess; @@ -91,6 +98,9 @@ void MediaPlaybackManager::HandleStop(CommandResponseHelper & 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; @@ -100,7 +110,10 @@ void MediaPlaybackManager::HandleFastForward(CommandResponseHelper & helper) { // TODO: Insert code here + mCurrentState = PlaybackStateEnum::kPlaying; + mPlaybackSpeed = 1; mPlaybackPosition = { 0, chip::app::DataModel::Nullable(0) }; + Commands::PlaybackResponse::Type response; response.data = chip::MakeOptional(CharSpan::fromCharString("data response")); response.status = MediaPlaybackStatusEnum::kSuccess; @@ -110,7 +123,9 @@ void MediaPlaybackManager::HandlePrevious(CommandResponseHelper & helper) { // TODO: Insert code here - mPlaybackPosition = { 0, chip::app::DataModel::Nullable(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; @@ -121,7 +136,9 @@ void MediaPlaybackManager::HandleSkipBackward(CommandResponseHelper deltaPositionMilliseconds + ? mPlaybackPosition.position.Value() - deltaPositionMilliseconds + : 0); mPlaybackPosition = { 0, chip::app::DataModel::Nullable(newPosition) }; Commands::PlaybackResponse::Type response; @@ -169,6 +186,10 @@ void MediaPlaybackManager::HandleSeek(CommandResponseHelper & helper) { // TODO: Insert code here + mCurrentState = PlaybackStateEnum::kPlaying; + mPlaybackSpeed = 1; + mPlaybackPosition = { 0, chip::app::DataModel::Nullable(0) }; + Commands::PlaybackResponse::Type response; response.data = chip::MakeOptional(CharSpan::fromCharString("data response")); response.status = MediaPlaybackStatusEnum::kSuccess; @@ -179,6 +200,7 @@ void MediaPlaybackManager::HandleStartOver(CommandResponseHelper(0) }; + Commands::PlaybackResponse::Type response; response.data = chip::MakeOptional(CharSpan::fromCharString("data response")); response.status = MediaPlaybackStatusEnum::kSuccess; diff --git a/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.h b/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.h index 3d583ac837dd0d..78bfb127c72e7a 100644 --- a/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.h +++ b/examples/tv-app/linux/include/media-playback/MediaPlaybackManager.h @@ -52,7 +52,10 @@ class MediaPlaybackManager : public MediaPlaybackDelegate void HandleStartOver(CommandResponseHelper & 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(0) }; float mPlaybackSpeed = 0; uint64_t mStartTime = 0;