Skip to content

Commit bcf3068

Browse files
authored
Add more tests to the cert tests (project-chip#24765)
1 parent 6a4fce9 commit bcf3068

File tree

12 files changed

+495
-1
lines changed

12 files changed

+495
-1
lines changed

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CertTestFragment.java

+82-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.chip.casting.FailureCallback;
1616
import com.chip.casting.MatterCallbackHandler;
1717
import com.chip.casting.MatterError;
18+
import com.chip.casting.MediaPlaybackTypes;
19+
import com.chip.casting.SubscriptionEstablishedCallback;
1820
import com.chip.casting.SuccessCallback;
1921
import com.chip.casting.TvCastingApp;
2022
import java.util.ArrayList;
@@ -197,6 +199,46 @@ private void runCertTests(Activity activity) {
197199
tvCastingApp.mediaPlayback_stopPlayback(kContentApp, callback);
198200
});
199201

202+
runAndWait(
203+
"mediaPlayback_previous",
204+
successFailureCallback,
205+
() -> {
206+
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
207+
tvCastingApp.mediaPlayback_previous(kContentApp, callback);
208+
});
209+
210+
runAndWait(
211+
"mediaPlayback_rewind",
212+
successFailureCallback,
213+
() -> {
214+
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
215+
tvCastingApp.mediaPlayback_rewind(kContentApp, callback);
216+
});
217+
218+
runAndWait(
219+
"mediaPlayback_fastForward",
220+
successFailureCallback,
221+
() -> {
222+
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
223+
tvCastingApp.mediaPlayback_fastForward(kContentApp, callback);
224+
});
225+
226+
runAndWait(
227+
"mediaPlayback_startOver",
228+
successFailureCallback,
229+
() -> {
230+
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
231+
tvCastingApp.mediaPlayback_startOver(kContentApp, callback);
232+
});
233+
234+
runAndWait(
235+
"mediaPlayback_seek",
236+
successFailureCallback,
237+
() -> {
238+
// 3.8.5. [TC-MEDIAPLAYBACK-6.5] Mandatory Media Playback Verification (DUT as Client)
239+
tvCastingApp.mediaPlayback_seek(kContentApp, 10000, callback);
240+
});
241+
200242
// Additional Tests
201243
// Mandatory
202244
// OnOff cluster
@@ -262,6 +304,45 @@ private void runCertTests(Activity activity) {
262304
kContentApp, successFailureCallbackInteger, successFailureCallbackInteger);
263305
});
264306

307+
runAndWait(
308+
"mediaPlayback_subscribeToCurrentState",
309+
successFailureCallback,
310+
() -> {
311+
tvCastingApp.mediaPlayback_subscribeToCurrentState(
312+
kContentApp,
313+
new SuccessCallback<MediaPlaybackTypes.PlaybackStateEnum>() {
314+
@Override
315+
public void handle(MediaPlaybackTypes.PlaybackStateEnum response) {
316+
// Lets wait for the timeout to avoid the race condition issue in the SDK with
317+
// ReadClient::Close()
318+
// successFailureCallback.handle(MatterError.NO_ERROR);
319+
addCertTestStatus(
320+
activity, MatterError.NO_ERROR, "mediaPlayback_subscribeToCurrentState");
321+
}
322+
},
323+
successFailureCallback,
324+
0,
325+
20,
326+
new SubscriptionEstablishedCallback() {
327+
@Override
328+
public void handle() {
329+
// Lets wait for the timeout to avoid the race condition issue in the SDK with
330+
// ReadClient::Close()
331+
// successFailureCallback.handle(MatterError.NO_ERROR);
332+
addCertTestStatus(
333+
activity, MatterError.NO_ERROR, "mediaPlayback_subscribeToCurrentState");
334+
}
335+
});
336+
});
337+
338+
runAndWait(
339+
"shutdownAllSubscriptions",
340+
successFailureCallback,
341+
() -> {
342+
tvCastingApp.shutdownAllSubscriptions();
343+
successFailureCallback.handle(MatterError.NO_ERROR);
344+
});
345+
265346
// Unsupported & Optional
266347
// 3.2.2. [TC-LOWPOWER-2.2] Low Power Mode Verification (DUT as Client)
267348
// 3.5.5. [TC-MEDIAINPUT-3.14] Select Input Verification (DUT as Client)
@@ -304,7 +385,7 @@ private void runAndWait(
304385
callback.setCountDownLatch(cdl);
305386
runnable.run();
306387
try {
307-
if (!cdl.await(10, TimeUnit.SECONDS)) {
388+
if (!cdl.await(5, TimeUnit.SECONDS)) {
308389
Log.d(TAG, "Timed out for test to finish : " + testMethod);
309390
}
310391
} catch (InterruptedException e) {

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java

+8
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ public native boolean levelControl_subscribeToMaxLevel(
249249

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

252+
public native boolean mediaPlayback_previous(ContentApp contentApp, Object responseHandler);
253+
254+
public native boolean mediaPlayback_rewind(ContentApp contentApp, Object responseHandler);
255+
256+
public native boolean mediaPlayback_fastForward(ContentApp contentApp, Object responseHandler);
257+
258+
public native boolean mediaPlayback_startOver(ContentApp contentApp, Object responseHandler);
259+
252260
public native boolean mediaPlayback_seek(
253261
ContentApp contentApp, long position, Object responseHandler);
254262

examples/tv-casting-app/android/App/app/src/main/jni/cpp/Constants.h

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ enum MediaCommandName
3030
MediaPlayback_Pause,
3131
MediaPlayback_StopPlayback,
3232
MediaPlayback_Next,
33+
MediaPlayback_Previous,
34+
MediaPlayback_Rewind,
35+
MediaPlayback_FastForward,
36+
MediaPlayback_StartOver,
3337
MediaPlayback_Seek,
3438
MediaPlayback_SkipForward,
3539
MediaPlayback_SkipBackward,

examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp

+74
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,80 @@ JNI_METHOD(jboolean, mediaPlayback_1skipBackward)
944944
return (err == CHIP_NO_ERROR);
945945
}
946946

947+
JNI_METHOD(jboolean, mediaPlayback_1previous)
948+
(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
949+
{
950+
return TvCastingAppJNIMgr().runCastingServerCommand(
951+
env, contentApp, jResponseHandler, "MediaPlayback_Previous", MediaPlayback_Previous,
952+
[](TargetEndpointInfo endpoint) -> CHIP_ERROR {
953+
return CastingServer::GetInstance()->MediaPlayback_Previous(&endpoint, [](CHIP_ERROR err) {
954+
TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Previous).Handle(err);
955+
});
956+
});
957+
}
958+
959+
JNI_METHOD(jboolean, mediaPlayback_1rewind)
960+
(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
961+
{
962+
return TvCastingAppJNIMgr().runCastingServerCommand(
963+
env, contentApp, jResponseHandler, "MediaPlayback_Rewind", MediaPlayback_Rewind,
964+
[](TargetEndpointInfo endpoint) -> CHIP_ERROR {
965+
return CastingServer::GetInstance()->MediaPlayback_Rewind(&endpoint, [](CHIP_ERROR err) {
966+
TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Rewind).Handle(err);
967+
});
968+
});
969+
}
970+
971+
JNI_METHOD(jboolean, mediaPlayback_1fastForward)
972+
(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
973+
{
974+
return TvCastingAppJNIMgr().runCastingServerCommand(
975+
env, contentApp, jResponseHandler, "MediaPlayback_FastForward", MediaPlayback_FastForward,
976+
[](TargetEndpointInfo endpoint) -> CHIP_ERROR {
977+
return CastingServer::GetInstance()->MediaPlayback_FastForward(&endpoint, [](CHIP_ERROR err) {
978+
TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_FastForward).Handle(err);
979+
});
980+
});
981+
}
982+
983+
JNI_METHOD(jboolean, mediaPlayback_1startOver)
984+
(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
985+
{
986+
return TvCastingAppJNIMgr().runCastingServerCommand(
987+
env, contentApp, jResponseHandler, "MediaPlayback_StartOver", MediaPlayback_StartOver,
988+
[](TargetEndpointInfo endpoint) -> CHIP_ERROR {
989+
return CastingServer::GetInstance()->MediaPlayback_StartOver(&endpoint, [](CHIP_ERROR err) {
990+
TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_StartOver).Handle(err);
991+
});
992+
});
993+
}
994+
995+
jboolean TvCastingAppJNI::runCastingServerCommand(JNIEnv * env, jobject contentApp, jobject jResponseHandler,
996+
const char * commandName, MediaCommandName command,
997+
const std::function<CHIP_ERROR(TargetEndpointInfo)> & commandRunner)
998+
{
999+
chip::DeviceLayer::StackLock lock;
1000+
1001+
ChipLogProgress(AppServer, "JNI_METHOD %s called", commandName);
1002+
1003+
TargetEndpointInfo endpoint;
1004+
CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
1005+
VerifyOrExit(err == CHIP_NO_ERROR,
1006+
ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
1007+
err.Format()));
1008+
1009+
err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(command).SetUp(env, jResponseHandler);
1010+
VerifyOrExit(CHIP_NO_ERROR == err,
1011+
ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
1012+
1013+
err = commandRunner(endpoint);
1014+
VerifyOrExit(CHIP_NO_ERROR == err,
1015+
ChipLogError(AppServer, "CastingServer.%s failed %" CHIP_ERROR_FORMAT, commandName, err.Format()));
1016+
1017+
exit:
1018+
return (err == CHIP_NO_ERROR);
1019+
}
1020+
9471021
JNI_METHOD(jboolean, mediaPlayback_1subscribeToCurrentState)
9481022
(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
9491023
jint maxInterval, jobject jSubscriptionEstablishedHandler)

examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.h

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class TvCastingAppJNI
9191
return mReadApplicationVersionSuccessHandlerJNI;
9292
}
9393

94+
jboolean runCastingServerCommand(JNIEnv * env, jobject contentApp, jobject jResponseHandler, const char * commandName,
95+
MediaCommandName command, const std::function<CHIP_ERROR(TargetEndpointInfo)> & commandRunner);
96+
9497
private:
9598
friend TvCastingAppJNI & TvCastingAppJNIMgr();
9699

examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h

+64
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,70 @@
482482
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
483483
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;
484484

485+
/*!
486+
@brief Send a MediaPlayback:Previous request to a TV
487+
488+
@param contentApp Content app endpoint to target
489+
490+
@param responseCallback Callback for when the response has been received
491+
492+
@param clientQueue Queue to invoke callbacks on
493+
494+
@param requestSentHandler Handler to call on sending the request
495+
*/
496+
- (void)mediaPlayback_previous:(ContentApp * _Nonnull)contentApp
497+
responseCallback:(void (^_Nonnull)(bool))responseCallback
498+
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
499+
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;
500+
501+
/*!
502+
@brief Send a MediaPlayback:FastForward request to a TV
503+
504+
@param contentApp Content app endpoint to target
505+
506+
@param responseCallback Callback for when the response has been received
507+
508+
@param clientQueue Queue to invoke callbacks on
509+
510+
@param requestSentHandler Handler to call on sending the request
511+
*/
512+
- (void)mediaPlayback_fastForward:(ContentApp * _Nonnull)contentApp
513+
responseCallback:(void (^_Nonnull)(bool))responseCallback
514+
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
515+
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;
516+
517+
/*!
518+
@brief Send a MediaPlayback:Rewind request to a TV
519+
520+
@param contentApp Content app endpoint to target
521+
522+
@param responseCallback Callback for when the response has been received
523+
524+
@param clientQueue Queue to invoke callbacks on
525+
526+
@param requestSentHandler Handler to call on sending the request
527+
*/
528+
- (void)mediaPlayback_rewind:(ContentApp * _Nonnull)contentApp
529+
responseCallback:(void (^_Nonnull)(bool))responseCallback
530+
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
531+
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;
532+
533+
/*!
534+
@brief Send a MediaPlayback:StartOver request to a TV
535+
536+
@param contentApp Content app endpoint to target
537+
538+
@param responseCallback Callback for when the response has been received
539+
540+
@param clientQueue Queue to invoke callbacks on
541+
542+
@param requestSentHandler Handler to call on sending the request
543+
*/
544+
- (void)mediaPlayback_startOver:(ContentApp * _Nonnull)contentApp
545+
responseCallback:(void (^_Nonnull)(bool))responseCallback
546+
clientQueue:(dispatch_queue_t _Nonnull)clientQueue
547+
requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler;
548+
485549
/*!
486550
@brief Send a MediaPlayback:Seek request to a TV
487551

0 commit comments

Comments
 (0)