• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include "accesstoken_kit.h"
18 #include "avcast_controller_stub.h"
19 #include "avsession_service.h"
20 #include "avsession_descriptor.h"
21 #include "avsession_errors.h"
22 #include "avsession_log.h"
23 #include "token_setproc.h"
24 
25 using namespace testing::ext;
26 using namespace OHOS::Security::AccessToken;
27 
28 namespace OHOS {
29 namespace AVSession {
30 
31 static std::shared_ptr<AVSessionService> g_AVSessionService;
32 static uint64_t g_selfTokenId = 0;
33 static HapInfoParams g_info = {
34     .userID = 100,
35     .bundleName = "ohos.permission_test.demo",
36     .instIndex = 0,
37     .appIDDesc = "ohos.permission_test.demo",
38     .isSystemApp = true
39 };
40 
41 static HapPolicyParams g_policy = {
42     .apl = APL_NORMAL,
43     .domain = "test.domain",
44     .permList = {
45         {
46             .permissionName = "ohos.permission.MANAGE_MEDIA_RESOURCES",
47             .bundleName = "ohos.permission_test.demo",
48             .grantMode = 1,
49             .availableLevel = APL_NORMAL,
50             .label = "label",
51             .labelId = 1,
52             .description = "test",
53             .descriptionId = 1
54         }
55     },
56     .permStateList = {
57         {
58             .permissionName = "ohos.permission.MANAGE_MEDIA_RESOURCES",
59             .isGeneral = true,
60             .resDeviceID = {"local"},
61             .grantStatus = {PermissionState::PERMISSION_GRANTED},
62             .grantFlags = {1}
63         }
64     }
65 };
66 
67 class AVCastControllerStubTest : public testing::Test {
68 public:
69     static void SetUpTestCase();
70     static void TearDownTestCase();
71     void SetUp() override;
72     void TearDown() override;
73 };
74 
SetUpTestCase()75 void AVCastControllerStubTest::SetUpTestCase()
76 {
77     g_selfTokenId = GetSelfTokenID();
78     AccessTokenKit::AllocHapToken(g_info, g_policy);
79     AccessTokenIDEx tokenID = AccessTokenKit::GetHapTokenIDEx(g_info.userID, g_info.bundleName, g_info.instIndex);
80     SetSelfTokenID(tokenID.tokenIDEx);
81 
82     g_AVSessionService = std::make_shared<AVSessionService>(OHOS::AVSESSION_SERVICE_ID);
83 }
84 
TearDownTestCase()85 void AVCastControllerStubTest::TearDownTestCase()
86 {
87     SetSelfTokenID(g_selfTokenId);
88     auto tokenId = AccessTokenKit::GetHapTokenID(g_info.userID, g_info.bundleName, g_info.instIndex);
89     AccessTokenKit::DeleteToken(tokenId);
90 }
91 
SetUp()92 void AVCastControllerStubTest::SetUp()
93 {}
94 
TearDown()95 void AVCastControllerStubTest::TearDown()
96 {}
97 
98 class AVCastControllerStubDemo : public AVCastControllerStub {
99 public:
SendControlCommand(const AVCastControlCommand & cmd)100     int32_t SendControlCommand(const AVCastControlCommand& cmd) override
101         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
102 
Start(const AVQueueItem & avQueueItem)103     int32_t Start(const AVQueueItem& avQueueItem) override
104         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
105 
Prepare(const AVQueueItem & avQueueItem)106     int32_t Prepare(const AVQueueItem& avQueueItem) override
107         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
108 
RegisterCallback(const std::shared_ptr<AVCastControllerCallback> & callback)109     int32_t RegisterCallback(const std::shared_ptr<AVCastControllerCallback>& callback) override
110         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
111 
GetDuration(int32_t & duration)112     int32_t GetDuration(int32_t& duration) override
113         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
114 
GetCastAVPlaybackState(AVPlaybackState & avPlaybackState)115     int32_t GetCastAVPlaybackState(AVPlaybackState& avPlaybackState) override
116         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
117 
GetSupportedDecoders(std::vector<std::string> & decoderTypes)118     int32_t GetSupportedDecoders(std::vector<std::string>& decoderTypes) override
119         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
120 
GetRecommendedResolutionLevel(std::string & decoderType,ResolutionLevel & resolutionLevel)121     int32_t GetRecommendedResolutionLevel(std::string& decoderType, ResolutionLevel& resolutionLevel) override
122         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
123 
GetSupportedHdrCapabilities(std::vector<HDRFormat> & hdrFormats)124     int32_t GetSupportedHdrCapabilities(std::vector<HDRFormat>& hdrFormats) override
125         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
126 
GetSupportedPlaySpeeds(std::vector<float> & playSpeeds)127     int32_t GetSupportedPlaySpeeds(std::vector<float>& playSpeeds) override
128         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
129 
GetCurrentItem(AVQueueItem & currentItem)130     int32_t GetCurrentItem(AVQueueItem& currentItem) override
131         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
132 
GetValidCommands(std::vector<int32_t> & cmds)133     int32_t GetValidCommands(std::vector<int32_t>& cmds) override
134         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
135 
SetDisplaySurface(std::string & surfaceId)136     int32_t SetDisplaySurface(std::string& surfaceId) override
137         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
138 
SetCastPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType & filter)139     int32_t SetCastPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter) override
140         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
141 
ProcessMediaKeyResponse(const std::string & assetId,const std::vector<uint8_t> & response)142     int32_t ProcessMediaKeyResponse(const std::string& assetId, const std::vector<uint8_t>& response) override
143         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
144 
AddAvailableCommand(const int32_t cmd)145     int32_t AddAvailableCommand(const int32_t cmd) override
146         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
147 
RemoveAvailableCommand(const int32_t cmd)148     int32_t RemoveAvailableCommand(const int32_t cmd) override
149         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
150 
Destroy()151     int32_t Destroy() override
152         { return isSuccess ? AVSESSION_SUCCESS : AVSESSION_ERROR; }
153 
154     bool isSuccess;
155 
156 protected:
RegisterCallbackInner(const sptr<IRemoteObject> & callback)157     int32_t RegisterCallbackInner(const sptr<IRemoteObject>& callback) override { return 0; }
158 };
159 
160 /**
161 * @tc.name: OnRemoteRequestCode0_1
162 * @tc.desc: test HandleSendControlCommand
163 * @tc.type: FUNC
164 */
165 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode0_1, TestSize.Level1)
166 {
167     SLOGI("OnRemoteRequestCode0_1 begin");
168     uint32_t code = 0;
169     AVCastControllerStubDemo aVCastControllerStubDemo;
170     aVCastControllerStubDemo.isSuccess = true;
171     OHOS::MessageParcel data;
172     auto localDescriptor = IAVCastController::GetDescriptor();
173     data.WriteInterfaceToken(localDescriptor);
174     OHOS::MessageParcel reply;
175     OHOS::MessageOption option;
176     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
177     EXPECT_EQ(ret, ERR_NONE);
178     SLOGI("OnRemoteRequestCode0_1 end");
179 }
180 
181 /**
182 * @tc.name: OnRemoteRequestCode0_2
183 * @tc.desc: test HandleSendControlCommand
184 * @tc.type: FUNC
185 */
186 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode0_2, TestSize.Level1)
187 {
188     SLOGI("OnRemoteRequestCode0_2 begin");
189     uint32_t code = 0;
190     AVCastControllerStubDemo aVCastControllerStubDemo;
191     aVCastControllerStubDemo.isSuccess = false;
192     OHOS::MessageParcel data;
193     auto localDescriptor = IAVCastController::GetDescriptor();
194     data.WriteInterfaceToken(localDescriptor);
195     sptr<AVCastControlCommand> cmd = new AVCastControlCommand();
196     data.WriteParcelable(cmd);
197     OHOS::MessageParcel reply;
198     OHOS::MessageOption option;
199     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
200     EXPECT_EQ(ret, ERR_NONE);
201     SLOGI("OnRemoteRequestCode0_2 end");
202 }
203 
204 /**
205 * @tc.name: OnRemoteRequestCode1_1
206 * @tc.desc: test HandleStart
207 * @tc.type: FUNC
208 */
209 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode1_1, TestSize.Level1)
210 {
211     SLOGI("OnRemoteRequestCode1_1 begin");
212     uint32_t code = 1;
213     AVCastControllerStubDemo aVCastControllerStubDemo;
214     aVCastControllerStubDemo.isSuccess = true;
215     OHOS::MessageParcel data;
216     auto localDescriptor = IAVCastController::GetDescriptor();
217     data.WriteInterfaceToken(localDescriptor);
218     OHOS::MessageParcel reply;
219     OHOS::MessageOption option;
220     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
221     EXPECT_EQ(ret, ERR_NONE);
222     SLOGI("OnRemoteRequestCode1_1 end");
223 }
224 
225 /**
226 * @tc.name: OnRemoteRequestCode1_2
227 * @tc.desc: test HandleStart
228 * @tc.type: FUNC
229 */
230 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode1_2, TestSize.Level1)
231 {
232     SLOGI("OnRemoteRequestCode1_2 begin");
233     uint32_t code = 1;
234     AVCastControllerStubDemo aVCastControllerStubDemo;
235     aVCastControllerStubDemo.isSuccess = false;
236     OHOS::MessageParcel data;
237     auto localDescriptor = IAVCastController::GetDescriptor();
238     data.WriteInterfaceToken(localDescriptor);
239     sptr<AVQueueItem> avQueueItem = new AVQueueItem();
240     data.WriteParcelable(avQueueItem);
241     OHOS::MessageParcel reply;
242     OHOS::MessageOption option;
243     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
244     EXPECT_EQ(ret, ERR_NONE);
245     SLOGI("OnRemoteRequestCode1_2 end");
246 }
247 
248 /**
249 * @tc.name: OnRemoteRequestCode2_1
250 * @tc.desc: test HandlePrepare
251 * @tc.type: FUNC
252 */
253 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode2_1, TestSize.Level1)
254 {
255     SLOGI("OnRemoteRequestCode2_1 begin");
256     uint32_t code = 2;
257     AVCastControllerStubDemo aVCastControllerStubDemo;
258     aVCastControllerStubDemo.isSuccess = true;
259     OHOS::MessageParcel data;
260     auto localDescriptor = IAVCastController::GetDescriptor();
261     data.WriteInterfaceToken(localDescriptor);
262     OHOS::MessageParcel reply;
263     OHOS::MessageOption option;
264     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
265     EXPECT_EQ(ret, ERR_NONE);
266     SLOGI("OnRemoteRequestCode2_1 end");
267 }
268 
269 /**
270 * @tc.name: OnRemoteRequestCode2_2
271 * @tc.desc: test HandlePrepare
272 * @tc.type: FUNC
273 */
274 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode2_2, TestSize.Level1)
275 {
276     SLOGI("OnRemoteRequestCode2_2 begin");
277     uint32_t code = 2;
278     AVCastControllerStubDemo aVCastControllerStubDemo;
279     aVCastControllerStubDemo.isSuccess = false;
280     OHOS::MessageParcel data;
281     auto localDescriptor = IAVCastController::GetDescriptor();
282     data.WriteInterfaceToken(localDescriptor);
283     sptr<AVQueueItem> avQueueItem = new AVQueueItem();
284     data.WriteParcelable(avQueueItem);
285     OHOS::MessageParcel reply;
286     OHOS::MessageOption option;
287     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
288     EXPECT_EQ(ret, ERR_NONE);
289     SLOGI("OnRemoteRequestCode2_2 end");
290 }
291 
292 /**
293 * @tc.name: OnRemoteRequestCode3_1
294 * @tc.desc: test HandleGetDuration
295 * @tc.type: FUNC
296 */
297 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode3_1, TestSize.Level1)
298 {
299     SLOGI("OnRemoteRequestCode3_1 begin");
300     uint32_t code = 3;
301     AVCastControllerStubDemo aVCastControllerStubDemo;
302     aVCastControllerStubDemo.isSuccess = true;
303     OHOS::MessageParcel data;
304     auto localDescriptor = IAVCastController::GetDescriptor();
305     data.WriteInterfaceToken(localDescriptor);
306     OHOS::MessageParcel reply;
307     OHOS::MessageOption option;
308     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
309     EXPECT_EQ(ret, ERR_NONE);
310     SLOGI("OnRemoteRequestCode3_1 end");
311 }
312 
313 /**
314 * @tc.name: OnRemoteRequestCode3_2
315 * @tc.desc: test HandleGetDuration
316 * @tc.type: FUNC
317 */
318 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode3_2, TestSize.Level1)
319 {
320     SLOGI("OnRemoteRequestCode3_2 begin");
321     uint32_t code = 3;
322     AVCastControllerStubDemo aVCastControllerStubDemo;
323     aVCastControllerStubDemo.isSuccess = false;
324     OHOS::MessageParcel data;
325     auto localDescriptor = IAVCastController::GetDescriptor();
326     data.WriteInterfaceToken(localDescriptor);
327     OHOS::MessageParcel reply;
328     OHOS::MessageOption option;
329     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
330     EXPECT_EQ(ret, ERR_NONE);
331     SLOGI("OnRemoteRequestCode3_2 end");
332 }
333 
334 /**
335 * @tc.name: OnRemoteRequestCode4_1
336 * @tc.desc: test HandleGetCastAVPlayBackState
337 * @tc.type: FUNC
338 */
339 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode4_1, TestSize.Level1)
340 {
341     SLOGI("OnRemoteRequestCode4_1 begin");
342     uint32_t code = 4;
343     AVCastControllerStubDemo aVCastControllerStubDemo;
344     aVCastControllerStubDemo.isSuccess = true;
345     OHOS::MessageParcel data;
346     auto localDescriptor = IAVCastController::GetDescriptor();
347     data.WriteInterfaceToken(localDescriptor);
348     OHOS::MessageParcel reply;
349     OHOS::MessageOption option;
350     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
351     EXPECT_EQ(ret, ERR_NONE);
352     SLOGI("OnRemoteRequestCode4_1 end");
353 }
354 
355 /**
356 * @tc.name: OnRemoteRequestCode4_2
357 * @tc.desc: test HandleGetCastAVPlayBackState
358 * @tc.type: FUNC
359 */
360 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode4_2, TestSize.Level1)
361 {
362     SLOGI("OnRemoteRequestCode4_2 begin");
363     uint32_t code = 4;
364     AVCastControllerStubDemo aVCastControllerStubDemo;
365     aVCastControllerStubDemo.isSuccess = false;
366     OHOS::MessageParcel data;
367     auto localDescriptor = IAVCastController::GetDescriptor();
368     data.WriteInterfaceToken(localDescriptor);
369     OHOS::MessageParcel reply;
370     OHOS::MessageOption option;
371     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
372     EXPECT_EQ(ret, ERR_NONE);
373     SLOGI("OnRemoteRequestCode4_2 end");
374 }
375 
376 /**
377 * @tc.name: OnRemoteRequestCode5_1
378 * @tc.desc: test HandleGetCurrentItem
379 * @tc.type: FUNC
380 */
381 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode5_1, TestSize.Level1)
382 {
383     SLOGI("OnRemoteRequestCode5_1 begin");
384     uint32_t code = 5;
385     AVCastControllerStubDemo aVCastControllerStubDemo;
386     aVCastControllerStubDemo.isSuccess = true;
387     OHOS::MessageParcel data;
388     auto localDescriptor = IAVCastController::GetDescriptor();
389     data.WriteInterfaceToken(localDescriptor);
390     OHOS::MessageParcel reply;
391     OHOS::MessageOption option;
392     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
393     EXPECT_EQ(ret, ERR_NONE);
394     SLOGI("OnRemoteRequestCode5_1 end");
395 }
396 
397 /**
398 * @tc.name: OnRemoteRequestCode5_2
399 * @tc.desc: test HandleGetCurrentItem
400 * @tc.type: FUNC
401 */
402 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode5_2, TestSize.Level1)
403 {
404     SLOGI("OnRemoteRequestCode5_2 begin");
405     uint32_t code = 5;
406     AVCastControllerStubDemo aVCastControllerStubDemo;
407     aVCastControllerStubDemo.isSuccess = false;
408     OHOS::MessageParcel data;
409     auto localDescriptor = IAVCastController::GetDescriptor();
410     data.WriteInterfaceToken(localDescriptor);
411     OHOS::MessageParcel reply;
412     OHOS::MessageOption option;
413     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
414     EXPECT_EQ(ret, ERR_NONE);
415     SLOGI("OnRemoteRequestCode5_2 end");
416 }
417 
418 /**
419 * @tc.name: OnRemoteRequestCode6_1
420 * @tc.desc: test HandleGetValidCommands
421 * @tc.type: FUNC
422 */
423 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode6_1, TestSize.Level1)
424 {
425     SLOGI("OnRemoteRequestCode6_1 begin");
426     uint32_t code = 6;
427     AVCastControllerStubDemo aVCastControllerStubDemo;
428     aVCastControllerStubDemo.isSuccess = true;
429     OHOS::MessageParcel data;
430     auto localDescriptor = IAVCastController::GetDescriptor();
431     data.WriteInterfaceToken(localDescriptor);
432     OHOS::MessageParcel reply;
433     OHOS::MessageOption option;
434     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
435     EXPECT_EQ(ret, ERR_NONE);
436     SLOGI("OnRemoteRequestCode6_1 end");
437 }
438 
439 /**
440 * @tc.name: OnRemoteRequestCode6_2
441 * @tc.desc: test HandleGetValidCommands
442 * @tc.type: FUNC
443 */
444 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode6_2, TestSize.Level1)
445 {
446     SLOGI("OnRemoteRequestCode6_2 begin");
447     uint32_t code = 6;
448     AVCastControllerStubDemo aVCastControllerStubDemo;
449     aVCastControllerStubDemo.isSuccess = false;
450     OHOS::MessageParcel data;
451     auto localDescriptor = IAVCastController::GetDescriptor();
452     data.WriteInterfaceToken(localDescriptor);
453     OHOS::MessageParcel reply;
454     OHOS::MessageOption option;
455     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
456     EXPECT_EQ(ret, ERR_NONE);
457     SLOGI("OnRemoteRequestCode6_2 end");
458 }
459 
460 /**
461 * @tc.name: OnRemoteRequestCode7_1
462 * @tc.desc: test HandleSetDisplaySurface
463 * @tc.type: FUNC
464 */
465 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode7_1, TestSize.Level1)
466 {
467     SLOGI("OnRemoteRequestCode7_1 begin");
468     uint32_t code = 7;
469     AVCastControllerStubDemo aVCastControllerStubDemo;
470     aVCastControllerStubDemo.isSuccess = true;
471     OHOS::MessageParcel data;
472     auto localDescriptor = IAVCastController::GetDescriptor();
473     data.WriteInterfaceToken(localDescriptor);
474     OHOS::MessageParcel reply;
475     OHOS::MessageOption option;
476     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
477     SLOGI("OnRemoteRequestCode7_1 ret with %{public}d", ret);
478     EXPECT_EQ(ret, ERR_NONE);
479     SLOGI("OnRemoteRequestCode7_1 end");
480 }
481 
482 /**
483 * @tc.name: OnRemoteRequestCode7_2
484 * @tc.desc: test HandleSetDisplaySurface
485 * @tc.type: FUNC
486 */
487 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode7_2, TestSize.Level1)
488 {
489     SLOGI("OnRemoteRequestCode7_2 begin");
490     uint32_t code = 7;
491     AVCastControllerStubDemo aVCastControllerStubDemo;
492     aVCastControllerStubDemo.isSuccess = false;
493     OHOS::MessageParcel data;
494     auto localDescriptor = IAVCastController::GetDescriptor();
495     data.WriteInterfaceToken(localDescriptor);
496 
497     std::string deviceId = "deviceId";
498     std::string bundleName = "test.ohos.avsession";
499     std::string abilityName = "test.ability";
500     std::string moduleName = "moduleName";
501     AppExecFwk::ElementName elementName(deviceId, bundleName, abilityName, moduleName);
502     sptr<IRemoteObject> obj = g_AVSessionService->CreateSessionInner("test",
503         AVSession::SESSION_TYPE_AUDIO, elementName);
504     data.WriteRemoteObject(obj);
505 
506     OHOS::MessageParcel reply;
507     OHOS::MessageOption option;
508     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
509     SLOGI("OnRemoteRequestCode7_2 ret with %{public}d", ret);
510     EXPECT_EQ(ret, AVSESSION_SUCCESS);
511     SLOGI("OnRemoteRequestCode7_2 end");
512 }
513 
514 /**
515 * @tc.name: OnRemoteRequestCode8_1
516 * @tc.desc: test HandleSetCastPlaybackFilter
517 * @tc.type: FUNC
518 */
519 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode8_1, TestSize.Level1)
520 {
521     SLOGI("OnRemoteRequestCode0_1 begin");
522     uint32_t code = 8;
523     AVCastControllerStubDemo aVCastControllerStubDemo;
524     aVCastControllerStubDemo.isSuccess = true;
525     OHOS::MessageParcel data;
526     auto localDescriptor = IAVCastController::GetDescriptor();
527     data.WriteInterfaceToken(localDescriptor);
528     OHOS::MessageParcel reply;
529     OHOS::MessageOption option;
530     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
531     EXPECT_EQ(ret, ERR_NONE);
532     SLOGI("OnRemoteRequestCode0_1 end");
533 }
534 
535 /**
536 * @tc.name: OnRemoteRequestCode8_2
537 * @tc.desc: test HandleSetCastPlaybackFilter
538 * @tc.type: FUNC
539 */
540 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode8_2, TestSize.Level1)
541 {
542     SLOGI("OnRemoteRequestCode8_2 begin");
543     uint32_t code = 8;
544     AVCastControllerStubDemo aVCastControllerStubDemo;
545     aVCastControllerStubDemo.isSuccess = false;
546     OHOS::MessageParcel data;
547     auto localDescriptor = IAVCastController::GetDescriptor();
548     data.WriteInterfaceToken(localDescriptor);
549     std::string str(14, 'a');
550     data.WriteString(str);
551     OHOS::MessageParcel reply;
552     OHOS::MessageOption option;
553     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
554     EXPECT_EQ(ret, ERR_NONE);
555     SLOGI("OnRemoteRequestCode8_2 end");
556 }
557 
558 /**
559 * @tc.name: OnRemoteRequestCode8_3
560 * @tc.desc: test HandleSetCastPlaybackFilter
561 * @tc.type: FUNC
562 */
563 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode8_3, TestSize.Level1)
564 {
565     SLOGI("OnRemoteRequestCode8_3 begin");
566     uint32_t code = 8;
567     AVCastControllerStubDemo aVCastControllerStubDemo;
568     aVCastControllerStubDemo.isSuccess = false;
569     OHOS::MessageParcel data;
570     auto localDescriptor = IAVCastController::GetDescriptor();
571     data.WriteInterfaceToken(localDescriptor);
572     std::string str{"01010101010101"};
573     data.WriteString(str);
574     OHOS::MessageParcel reply;
575     OHOS::MessageOption option;
576     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
577     EXPECT_EQ(ret, AVSESSION_SUCCESS);
578     SLOGI("OnRemoteRequestCode8_3 end");
579 }
580 
581 /**
582 * @tc.name: OnRemoteRequestCode9_1
583 * @tc.desc: test HandleProcessMediaKeyResponse
584 * @tc.type: FUNC
585 */
586 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode9_1, TestSize.Level1)
587 {
588     SLOGI("OnRemoteRequestCode9_1 begin");
589     uint32_t code = 9;
590     AVCastControllerStubDemo aVCastControllerStubDemo;
591     aVCastControllerStubDemo.isSuccess = true;
592     OHOS::MessageParcel data;
593     auto localDescriptor = IAVCastController::GetDescriptor();
594     data.WriteInterfaceToken(localDescriptor);
595     data.WriteInt32(0);
596     OHOS::MessageParcel reply;
597     OHOS::MessageOption option;
598     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
599     EXPECT_EQ(ret, ERR_NONE);
600     SLOGI("OnRemoteRequestCode9_1 end");
601 }
602 
603 /**
604 * @tc.name: OnRemoteRequestCode9_2
605 * @tc.desc: test HandleProcessMediaKeyResponse
606 * @tc.type: FUNC
607 */
608 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode9_2, TestSize.Level1)
609 {
610     SLOGI("OnRemoteRequestCode9_2 begin");
611     uint32_t code = 9;
612     AVCastControllerStubDemo aVCastControllerStubDemo;
613     aVCastControllerStubDemo.isSuccess = false;
614     OHOS::MessageParcel data;
615     auto localDescriptor = IAVCastController::GetDescriptor();
616     data.WriteInterfaceToken(localDescriptor);
617     data.WriteInt32(4);
618     OHOS::MessageParcel reply;
619     OHOS::MessageOption option;
620     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
621     EXPECT_EQ(ret, ERR_NONE);
622     SLOGI("OnRemoteRequestCode9_2 end");
623 }
624 
625 /**
626 * @tc.name: OnRemoteRequestCode9_3
627 * @tc.desc: test HandleProcessMediaKeyResponse
628 * @tc.type: FUNC
629 */
630 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode9_3, TestSize.Level1)
631 {
632     SLOGI("OnRemoteRequestCode9_3 begin");
633     uint32_t code = 9;
634     AVCastControllerStubDemo aVCastControllerStubDemo;
635     aVCastControllerStubDemo.isSuccess = false;
636     OHOS::MessageParcel data;
637     auto localDescriptor = IAVCastController::GetDescriptor();
638     data.WriteInterfaceToken(localDescriptor);
639     data.WriteInt32(4);
640     std::string str{"****"};
641     data.WriteString(str.c_str());
642     OHOS::MessageParcel reply;
643     OHOS::MessageOption option;
644     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
645     EXPECT_EQ(ret, ERR_NONE);
646     SLOGI("OnRemoteRequestCode9_3 end");
647 }
648 
649 /**
650 * @tc.name: OnRemoteRequestCode10_1
651 * @tc.desc: test HandleRegisterCallbackInner
652 * @tc.type: FUNC
653 */
654 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode10_1, TestSize.Level1)
655 {
656     SLOGI("OnRemoteRequestCode10_1 begin");
657     uint32_t code = 10;
658     AVCastControllerStubDemo aVCastControllerStubDemo;
659     aVCastControllerStubDemo.isSuccess = true;
660 
661     OHOS::MessageParcel data;
662     auto localDescriptor = IAVCastController::GetDescriptor();
663     data.WriteInterfaceToken(localDescriptor);
664     std::string deviceId = "deviceId";
665     std::string bundleName = "test.ohos.avsession";
666     std::string abilityName = "test.ability";
667     std::string moduleName = "moduleName";
668     AppExecFwk::ElementName elementName(deviceId, bundleName, abilityName, moduleName);
669     sptr<IRemoteObject> obj = g_AVSessionService->CreateSessionInner("test",
670         AVSession::SESSION_TYPE_AUDIO, elementName);
671     data.WriteRemoteObject(obj);
672 
673     OHOS::MessageParcel reply;
674     OHOS::MessageOption option;
675     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
676     EXPECT_EQ(ret, ERR_NONE);
677     SLOGI("OnRemoteRequestCode10_1 end");
678 }
679 
680 /**
681 * @tc.name: OnRemoteRequestCode10_2
682 * @tc.desc: test HandleRegisterCallbackInner
683 * @tc.type: FUNC
684 */
685 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode10_2, TestSize.Level1)
686 {
687     SLOGI("OnRemoteRequestCode10_2 begin");
688     uint32_t code = 10;
689     AVCastControllerStubDemo aVCastControllerStubDemo;
690     aVCastControllerStubDemo.isSuccess = false;
691     OHOS::MessageParcel data;
692     auto localDescriptor = IAVCastController::GetDescriptor();
693     data.WriteInterfaceToken(localDescriptor);
694     OHOS::MessageParcel reply;
695     OHOS::MessageOption option;
696     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
697     EXPECT_EQ(ret, ERR_NONE);
698     SLOGI("OnRemoteRequestCode10_2 end");
699 }
700 
701 /**
702 * @tc.name: OnRemoteRequestCode11_1
703 * @tc.desc: test HandleDestroy
704 * @tc.type: FUNC
705 */
706 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode11_1, TestSize.Level1)
707 {
708     SLOGI("OnRemoteRequestCode11_1 begin");
709     uint32_t code = 11;
710     AVCastControllerStubDemo aVCastControllerStubDemo;
711     aVCastControllerStubDemo.isSuccess = true;
712     OHOS::MessageParcel data;
713     auto localDescriptor = IAVCastController::GetDescriptor();
714     data.WriteInterfaceToken(localDescriptor);
715     OHOS::MessageParcel reply;
716     OHOS::MessageOption option;
717     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
718     EXPECT_EQ(ret, ERR_NULL_OBJECT);
719     SLOGI("OnRemoteRequestCode11_1 end");
720 }
721 
722 /**
723 * @tc.name: OnRemoteRequestCode11_2
724 * @tc.desc: test HandleDestroy
725 * @tc.type: FUNC
726 */
727 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode11_2, TestSize.Level1)
728 {
729     SLOGI("OnRemoteRequestCode11_2 begin");
730     uint32_t code = 11;
731     AVCastControllerStubDemo aVCastControllerStubDemo;
732     aVCastControllerStubDemo.isSuccess = false;
733     OHOS::MessageParcel data;
734     auto localDescriptor = IAVCastController::GetDescriptor();
735     data.WriteInterfaceToken(localDescriptor);
736     OHOS::MessageParcel reply;
737     OHOS::MessageOption option;
738     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
739     EXPECT_EQ(ret, ERR_NULL_OBJECT);
740     SLOGI("OnRemoteRequestCode11_2 end");
741 }
742 
743 /**
744 * @tc.name: OnRemoteRequestCode12_1
745 * @tc.desc: test HandleAddAvailableCommand
746 * @tc.type: FUNC
747 */
748 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode12_1, TestSize.Level1)
749 {
750     SLOGI("OnRemoteRequestCode12_1 begin");
751     uint32_t code = 12;
752     AVCastControllerStubDemo aVCastControllerStubDemo;
753     aVCastControllerStubDemo.isSuccess = true;
754     OHOS::MessageParcel data;
755     auto localDescriptor = IAVCastController::GetDescriptor();
756     data.WriteInterfaceToken(localDescriptor);
757     OHOS::MessageParcel reply;
758     OHOS::MessageOption option;
759     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
760     EXPECT_EQ(ret, ERR_NONE);
761     SLOGI("OnRemoteRequestCode12_1 end");
762 }
763 
764 /**
765 * @tc.name: OnRemoteRequestCode12_2
766 * @tc.desc: test HandleAddAvailableCommand
767 * @tc.type: FUNC
768 */
769 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode12_2, TestSize.Level1)
770 {
771     SLOGI("OnRemoteRequestCode12_2 begin");
772     uint32_t code = 12;
773     AVCastControllerStubDemo aVCastControllerStubDemo;
774     aVCastControllerStubDemo.isSuccess = false;
775     OHOS::MessageParcel data;
776     auto localDescriptor = IAVCastController::GetDescriptor();
777     data.WriteInterfaceToken(localDescriptor);
778     OHOS::MessageParcel reply;
779     OHOS::MessageOption option;
780     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
781     EXPECT_EQ(ret, ERR_NONE);
782     SLOGI("OnRemoteRequestCode12_2 end");
783 }
784 
785 /**
786 * @tc.name: OnRemoteRequestCode13_1
787 * @tc.desc: test HandleRemoveAvailableCommand
788 * @tc.type: FUNC
789 */
790 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode13_1, TestSize.Level1)
791 {
792     SLOGI("OnRemoteRequestCode13_1 begin");
793     uint32_t code = 13;
794     AVCastControllerStubDemo aVCastControllerStubDemo;
795     aVCastControllerStubDemo.isSuccess = true;
796     OHOS::MessageParcel data;
797     auto localDescriptor = IAVCastController::GetDescriptor();
798     data.WriteInterfaceToken(localDescriptor);
799     OHOS::MessageParcel reply;
800     OHOS::MessageOption option;
801     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
802     EXPECT_EQ(ret, ERR_NONE);
803     SLOGI("OnRemoteRequestCode13_1 end");
804 }
805 
806 /**
807 * @tc.name: OnRemoteRequestCode13_2
808 * @tc.desc: test HandleRemoveAvailableCommand
809 * @tc.type: FUNC
810 */
811 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode13_2, TestSize.Level1)
812 {
813     SLOGI("OnRemoteRequestCode13_2 begin");
814     uint32_t code = 13;
815     AVCastControllerStubDemo aVCastControllerStubDemo;
816     aVCastControllerStubDemo.isSuccess = false;
817     OHOS::MessageParcel data;
818     auto localDescriptor = IAVCastController::GetDescriptor();
819     data.WriteInterfaceToken(localDescriptor);
820     OHOS::MessageParcel reply;
821     OHOS::MessageOption option;
822     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
823     EXPECT_EQ(ret, ERR_NONE);
824     SLOGI("OnRemoteRequestCode13_2 end");
825 }
826 
827 /**
828 * @tc.name: OnRemoteRequestCode14
829 * @tc.desc: test OnRemoteRequest
830 * @tc.type: FUNC
831 */
832 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode14, TestSize.Level1)
833 {
834     SLOGI("OnRemoteRequestCode14 begin");
835     uint32_t code = 0;
836     AVCastControllerStubDemo aVCastControllerStubDemo;
837     aVCastControllerStubDemo.isSuccess = false;
838     OHOS::MessageParcel data;
839     OHOS::MessageParcel reply;
840     OHOS::MessageOption option;
841     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
842     EXPECT_EQ(ret, AVSESSION_ERROR);
843     SLOGI("OnRemoteRequestCode14 end");
844 }
845 
846 /**
847 * @tc.name: OnRemoteRequestCode15
848 * @tc.desc: test OnRemoteRequest
849 * @tc.type: FUNC
850 */
851 static HWTEST_F(AVCastControllerStubTest, OnRemoteRequestCode15, TestSize.Level1)
852 {
853     SLOGI("OnRemoteRequestCode15 begin");
854     uint32_t code = 1000;
855     AVCastControllerStubDemo aVCastControllerStubDemo;
856     aVCastControllerStubDemo.isSuccess = false;
857     OHOS::MessageParcel data;
858     auto localDescriptor = IAVCastController::GetDescriptor();
859     data.WriteInterfaceToken(localDescriptor);
860     OHOS::MessageParcel reply;
861     OHOS::MessageOption option;
862     int ret = aVCastControllerStubDemo.OnRemoteRequest(code, data, reply, option);
863     EXPECT_EQ(ret, IPC_STUB_UNKNOW_TRANS_ERR);
864     SLOGI("OnRemoteRequestCode15 end");
865 }
866 
867 } // namespace OHOS
868 } // namespace AVSession