• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 "av_cast_controller_callback_proxy.h"
18 #include "avsession_log.h"
19 #include "avsession_errors.h"
20 #include "avsession_service.h"
21 #include "iservice_registry.h"
22 #include "system_ability_definition.h"
23 
24 namespace OHOS::AVSession {
25 
26 class AVCastControllerCallbackProxyTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32 
33     sptr<AVCastControllerCallbackProxy> avCastControllerCallbackProxy_;
34 };
35 
SetUpTestCase()36 void AVCastControllerCallbackProxyTest::SetUpTestCase()
37 {
38 }
39 
TearDownTestCase()40 void AVCastControllerCallbackProxyTest::TearDownTestCase()
41 {
42 }
43 
SetUp()44 void AVCastControllerCallbackProxyTest::SetUp()
45 {
46     auto mgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
47     if (mgr == nullptr) {
48         SLOGI("failed to get sa mgr");
49         return;
50     }
51     auto object = mgr->GetSystemAbility(OHOS::AVSESSION_SERVICE_ID);
52     if (object == nullptr) {
53         SLOGI("failed to get service");
54         return;
55     }
56     avCastControllerCallbackProxy_ = iface_cast<AVCastControllerCallbackProxy>(object);
57 }
58 
TearDown()59 void AVCastControllerCallbackProxyTest::TearDown()
60 {
61 }
62 
63 /**
64  * @tc.name: OnKeyRequest001
65  * @tc.desc: Test OnKeyRequest
66  * @tc.type: FUNC
67  */
68 static HWTEST_F(AVCastControllerCallbackProxyTest, OnKeyRequest001, testing::ext::TestSize.Level0)
69 {
70     std::string assetId = "";
71     std::vector<uint8_t> keyRequestData(100000, 0);
72     avCastControllerCallbackProxy_->OnKeyRequest(assetId, keyRequestData);
73     EXPECT_EQ(keyRequestData.empty(), false);
74 }
75 
76 /**
77  * @tc.name: OnKeyRequest002
78  * @tc.desc: Test OnKeyRequest
79  * @tc.type: FUNC
80  */
81 static HWTEST_F(AVCastControllerCallbackProxyTest, OnKeyRequest002, testing::ext::TestSize.Level0)
82 {
83     std::string assetId = "";
84     std::vector<uint8_t> keyRequestData;
85     avCastControllerCallbackProxy_->OnKeyRequest(assetId, keyRequestData);
86     EXPECT_EQ(keyRequestData.empty(), true);
87 }
88 
89 /**
90 * @tc.name: onDataSrcRead001
91 * @tc.desc: Test onDataSrcRead
92 * @tc.type: FUNC
93 */
94 static HWTEST_F(AVCastControllerCallbackProxyTest, onDataSrcRead001, testing::ext::TestSize.Level1)
95 {
96     std::shared_ptr<AVSharedMemoryBase> memory = AVSharedMemoryBase::CreateFromRemote(-1, 10, 1, "test");
97     std::string assetId = "";
98     std::vector<uint8_t> keyRequestData;
99     int32_t result = 0;
100     if (avCastControllerCallbackProxy_ != nullptr) {
101         auto ret = avCastControllerCallbackProxy_->onDataSrcRead(memory, 2, 2, result);
102         EXPECT_NE(ret, ERR_INVALID_DATA);
103     }
104 }
105 } // namespace OHOS::AVSession