Skip to content

Commit

Permalink
Add more tests to the cert tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amitnj committed Jan 31, 2023
1 parent f951fa9 commit b53083e
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 2 deletions.
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,7 +199,47 @@ private void runCertTests(Activity activity) {
tvCastingApp.mediaPlayback_stopPlayback(kContentApp, callback);
});

// Additional Tests
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
runAndWait(
Expand Down Expand Up @@ -262,6 +304,35 @@ 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 +375,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,75 @@ 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,8 @@ 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 Expand Up @@ -137,6 +139,7 @@ class TvCastingAppJNI
ApplicationNameSuccessHandlerJNI mReadApplicationNameSuccessHandlerJNI;
ProductIDSuccessHandlerJNI mReadProductIDSuccessHandlerJNI;
ApplicationVersionSuccessHandlerJNI mReadApplicationVersionSuccessHandlerJNI;

};

inline class 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
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,102 @@ - (void)mediaPlayback_skipBackward:(ContentApp * _Nonnull)contentApp
});
}

- (void)mediaPlayback_previous:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler
{
ChipLogProgress(
AppServer, "CastingServerBridge().mediaPlayback_previous() called on Content App with endpoint ID %d", contentApp.endpointId);

[_commandResponseCallbacks setObject:responseCallback forKey:@"mediaPlayback_previous"];
dispatch_async(_chipWorkQueue, ^{
TargetEndpointInfo endpoint;
[ConversionUtils convertToCppTargetEndpointInfoFrom:contentApp outTargetEndpointInfo:endpoint];

CHIP_ERROR err = CastingServer::GetInstance()->MediaPlayback_Previous(&endpoint, [](CHIP_ERROR err) {
void (^responseCallback)(bool) =
[[CastingServerBridge getSharedInstance].commandResponseCallbacks objectForKey:@"mediaPlayback_previous"];
responseCallback(CHIP_NO_ERROR == err);
});
dispatch_async(clientQueue, ^{
requestSentHandler(CHIP_NO_ERROR == err);
});
});
}

- (void)mediaPlayback_rewind:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler
{
ChipLogProgress(
AppServer, "CastingServerBridge().mediaPlayback_rewind() called on Content App with endpoint ID %d", contentApp.endpointId);

[_commandResponseCallbacks setObject:responseCallback forKey:@"mediaPlayback_rewind"];
dispatch_async(_chipWorkQueue, ^{
TargetEndpointInfo endpoint;
[ConversionUtils convertToCppTargetEndpointInfoFrom:contentApp outTargetEndpointInfo:endpoint];

CHIP_ERROR err = CastingServer::GetInstance()->MediaPlayback_Rewind(&endpoint, [](CHIP_ERROR err) {
void (^responseCallback)(bool) =
[[CastingServerBridge getSharedInstance].commandResponseCallbacks objectForKey:@"mediaPlayback_rewind"];
responseCallback(CHIP_NO_ERROR == err);
});
dispatch_async(clientQueue, ^{
requestSentHandler(CHIP_NO_ERROR == err);
});
});
}

- (void)mediaPlayback_fastForward:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler
{
ChipLogProgress(
AppServer, "CastingServerBridge().mediaPlayback_fastForward() called on Content App with endpoint ID %d", contentApp.endpointId);

[_commandResponseCallbacks setObject:responseCallback forKey:@"mediaPlayback_fastForward"];
dispatch_async(_chipWorkQueue, ^{
TargetEndpointInfo endpoint;
[ConversionUtils convertToCppTargetEndpointInfoFrom:contentApp outTargetEndpointInfo:endpoint];

CHIP_ERROR err = CastingServer::GetInstance()->MediaPlayback_FastForward(&endpoint, [](CHIP_ERROR err) {
void (^responseCallback)(bool) =
[[CastingServerBridge getSharedInstance].commandResponseCallbacks objectForKey:@"mediaPlayback_fastForward"];
responseCallback(CHIP_NO_ERROR == err);
});
dispatch_async(clientQueue, ^{
requestSentHandler(CHIP_NO_ERROR == err);
});
});
}

- (void)mediaPlayback_startOver:(ContentApp * _Nonnull)contentApp
responseCallback:(void (^_Nonnull)(bool))responseCallback
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler
{
ChipLogProgress(
AppServer, "CastingServerBridge().mediaPlayback_startOver() called on Content App with endpoint ID %d", contentApp.endpointId);

[_commandResponseCallbacks setObject:responseCallback forKey:@"mediaPlayback_startOver"];
dispatch_async(_chipWorkQueue, ^{
TargetEndpointInfo endpoint;
[ConversionUtils convertToCppTargetEndpointInfoFrom:contentApp outTargetEndpointInfo:endpoint];

CHIP_ERROR err = CastingServer::GetInstance()->MediaPlayback_StartOver(&endpoint, [](CHIP_ERROR err) {
void (^responseCallback)(bool) =
[[CastingServerBridge getSharedInstance].commandResponseCallbacks objectForKey:@"mediaPlayback_startOver"];
responseCallback(CHIP_NO_ERROR == err);
});
dispatch_async(clientQueue, ^{
requestSentHandler(CHIP_NO_ERROR == err);
});
});
}

- (void)mediaPlayback_subscribeCurrentState:(ContentApp * _Nonnull)contentApp
minInterval:(uint16_t)minInterval
maxInterval:(uint16_t)maxInterval
Expand Down
Loading

0 comments on commit b53083e

Please sign in to comment.