Skip to content

Commit

Permalink
Add more tests to the cert tests (#24765)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitnj authored and pull[bot] committed Aug 10, 2023
1 parent 971dbee commit 3bebd94
Show file tree
Hide file tree
Showing 12 changed files with 495 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.chip.casting.FailureCallback;
import com.chip.casting.MatterCallbackHandler;
import com.chip.casting.MatterError;
import com.chip.casting.MediaPlaybackTypes;
import com.chip.casting.SubscriptionEstablishedCallback;
import com.chip.casting.SuccessCallback;
import com.chip.casting.TvCastingApp;
import java.util.ArrayList;
Expand Down Expand Up @@ -197,6 +199,46 @@ private void runCertTests(Activity activity) {
tvCastingApp.mediaPlayback_stopPlayback(kContentApp, callback);
});

runAndWait(
"mediaPlayback_previous",
successFailureCallback,
() -> {
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
tvCastingApp.mediaPlayback_previous(kContentApp, callback);
});

runAndWait(
"mediaPlayback_rewind",
successFailureCallback,
() -> {
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
tvCastingApp.mediaPlayback_rewind(kContentApp, callback);
});

runAndWait(
"mediaPlayback_fastForward",
successFailureCallback,
() -> {
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
tvCastingApp.mediaPlayback_fastForward(kContentApp, callback);
});

runAndWait(
"mediaPlayback_startOver",
successFailureCallback,
() -> {
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
tvCastingApp.mediaPlayback_startOver(kContentApp, callback);
});

runAndWait(
"mediaPlayback_seek",
successFailureCallback,
() -> {
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
tvCastingApp.mediaPlayback_seek(kContentApp, 10000, callback);
});

// Additional Tests
// Mandatory
// OnOff cluster
Expand Down Expand Up @@ -262,6 +304,45 @@ private void runCertTests(Activity activity) {
kContentApp, successFailureCallbackInteger, successFailureCallbackInteger);
});

runAndWait(
"mediaPlayback_subscribeToCurrentState",
successFailureCallback,
() -> {
tvCastingApp.mediaPlayback_subscribeToCurrentState(
kContentApp,
new SuccessCallback<MediaPlaybackTypes.PlaybackStateEnum>() {
@Override
public void handle(MediaPlaybackTypes.PlaybackStateEnum response) {
// Lets wait for the timeout to avoid the race condition issue in the SDK with
// ReadClient::Close()
// successFailureCallback.handle(MatterError.NO_ERROR);
addCertTestStatus(
activity, MatterError.NO_ERROR, "mediaPlayback_subscribeToCurrentState");
}
},
successFailureCallback,
0,
20,
new SubscriptionEstablishedCallback() {
@Override
public void handle() {
// Lets wait for the timeout to avoid the race condition issue in the SDK with
// ReadClient::Close()
// successFailureCallback.handle(MatterError.NO_ERROR);
addCertTestStatus(
activity, MatterError.NO_ERROR, "mediaPlayback_subscribeToCurrentState");
}
});
});

runAndWait(
"shutdownAllSubscriptions",
successFailureCallback,
() -> {
tvCastingApp.shutdownAllSubscriptions();
successFailureCallback.handle(MatterError.NO_ERROR);
});

// Unsupported & Optional
// 3.2.2. [TC-LOWPOWER-2.2] Low Power Mode Verification (DUT as Client)
// 3.5.5. [TC-MEDIAINPUT-3.14] Select Input Verification (DUT as Client)
Expand Down Expand Up @@ -304,7 +385,7 @@ private void runAndWait(
callback.setCountDownLatch(cdl);
runnable.run();
try {
if (!cdl.await(10, TimeUnit.SECONDS)) {
if (!cdl.await(5, TimeUnit.SECONDS)) {
Log.d(TAG, "Timed out for test to finish : " + testMethod);
}
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ public native boolean levelControl_subscribeToMaxLevel(

public native boolean mediaPlayback_next(ContentApp contentApp, Object responseHandler);

public native boolean mediaPlayback_previous(ContentApp contentApp, Object responseHandler);

public native boolean mediaPlayback_rewind(ContentApp contentApp, Object responseHandler);

public native boolean mediaPlayback_fastForward(ContentApp contentApp, Object responseHandler);

public native boolean mediaPlayback_startOver(ContentApp contentApp, Object responseHandler);

public native boolean mediaPlayback_seek(
ContentApp contentApp, long position, Object responseHandler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ enum MediaCommandName
MediaPlayback_Pause,
MediaPlayback_StopPlayback,
MediaPlayback_Next,
MediaPlayback_Previous,
MediaPlayback_Rewind,
MediaPlayback_FastForward,
MediaPlayback_StartOver,
MediaPlayback_Seek,
MediaPlayback_SkipForward,
MediaPlayback_SkipBackward,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,80 @@ JNI_METHOD(jboolean, mediaPlayback_1skipBackward)
return (err == CHIP_NO_ERROR);
}

JNI_METHOD(jboolean, mediaPlayback_1previous)
(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
{
return TvCastingAppJNIMgr().runCastingServerCommand(
env, contentApp, jResponseHandler, "MediaPlayback_Previous", MediaPlayback_Previous,
[](TargetEndpointInfo endpoint) -> CHIP_ERROR {
return CastingServer::GetInstance()->MediaPlayback_Previous(&endpoint, [](CHIP_ERROR err) {
TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Previous).Handle(err);
});
});
}

JNI_METHOD(jboolean, mediaPlayback_1rewind)
(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
{
return TvCastingAppJNIMgr().runCastingServerCommand(
env, contentApp, jResponseHandler, "MediaPlayback_Rewind", MediaPlayback_Rewind,
[](TargetEndpointInfo endpoint) -> CHIP_ERROR {
return CastingServer::GetInstance()->MediaPlayback_Rewind(&endpoint, [](CHIP_ERROR err) {
TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Rewind).Handle(err);
});
});
}

JNI_METHOD(jboolean, mediaPlayback_1fastForward)
(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
{
return TvCastingAppJNIMgr().runCastingServerCommand(
env, contentApp, jResponseHandler, "MediaPlayback_FastForward", MediaPlayback_FastForward,
[](TargetEndpointInfo endpoint) -> CHIP_ERROR {
return CastingServer::GetInstance()->MediaPlayback_FastForward(&endpoint, [](CHIP_ERROR err) {
TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_FastForward).Handle(err);
});
});
}

JNI_METHOD(jboolean, mediaPlayback_1startOver)
(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
{
return TvCastingAppJNIMgr().runCastingServerCommand(
env, contentApp, jResponseHandler, "MediaPlayback_StartOver", MediaPlayback_StartOver,
[](TargetEndpointInfo endpoint) -> CHIP_ERROR {
return CastingServer::GetInstance()->MediaPlayback_StartOver(&endpoint, [](CHIP_ERROR err) {
TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_StartOver).Handle(err);
});
});
}

jboolean TvCastingAppJNI::runCastingServerCommand(JNIEnv * env, jobject contentApp, jobject jResponseHandler,
const char * commandName, MediaCommandName command,
const std::function<CHIP_ERROR(TargetEndpointInfo)> & commandRunner)
{
chip::DeviceLayer::StackLock lock;

ChipLogProgress(AppServer, "JNI_METHOD %s called", commandName);

TargetEndpointInfo endpoint;
CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
VerifyOrExit(err == CHIP_NO_ERROR,
ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
err.Format()));

err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(command).SetUp(env, jResponseHandler);
VerifyOrExit(CHIP_NO_ERROR == err,
ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));

err = commandRunner(endpoint);
VerifyOrExit(CHIP_NO_ERROR == err,
ChipLogError(AppServer, "CastingServer.%s failed %" CHIP_ERROR_FORMAT, commandName, err.Format()));

exit:
return (err == CHIP_NO_ERROR);
}

JNI_METHOD(jboolean, mediaPlayback_1subscribeToCurrentState)
(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
jint maxInterval, jobject jSubscriptionEstablishedHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class TvCastingAppJNI
return mReadApplicationVersionSuccessHandlerJNI;
}

jboolean runCastingServerCommand(JNIEnv * env, jobject contentApp, jobject jResponseHandler, const char * commandName,
MediaCommandName command, const std::function<CHIP_ERROR(TargetEndpointInfo)> & commandRunner);

private:
friend TvCastingAppJNI & TvCastingAppJNIMgr();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,70 @@
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;

/*!
@brief Send a MediaPlayback:Previous request to a TV
@param contentApp Content app endpoint to target
@param responseCallback Callback for when the response has been received
@param clientQueue Queue to invoke callbacks on
@param requestSentHandler Handler to call on sending the request
*/
- (void)mediaPlayback_previous:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;

/*!
@brief Send a MediaPlayback:FastForward request to a TV
@param contentApp Content app endpoint to target
@param responseCallback Callback for when the response has been received
@param clientQueue Queue to invoke callbacks on
@param requestSentHandler Handler to call on sending the request
*/
- (void)mediaPlayback_fastForward:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;

/*!
@brief Send a MediaPlayback:Rewind request to a TV
@param contentApp Content app endpoint to target
@param responseCallback Callback for when the response has been received
@param clientQueue Queue to invoke callbacks on
@param requestSentHandler Handler to call on sending the request
*/
- (void)mediaPlayback_rewind:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;

/*!
@brief Send a MediaPlayback:StartOver request to a TV
@param contentApp Content app endpoint to target
@param responseCallback Callback for when the response has been received
@param clientQueue Queue to invoke callbacks on
@param requestSentHandler Handler to call on sending the request
*/
- (void)mediaPlayback_startOver:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;

/*!
@brief Send a MediaPlayback:Seek request to a TV
Expand Down
Loading

0 comments on commit 3bebd94

Please sign in to comment.