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 "avcast_controller_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 AVCastControllerProxyTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32 
33     sptr<AVCastControllerProxy> avCastControllerProxy_;
34 };
35 
SetUpTestCase()36 void AVCastControllerProxyTest::SetUpTestCase()
37 {
38 }
39 
TearDownTestCase()40 void AVCastControllerProxyTest::TearDownTestCase()
41 {
42 }
43 
SetUp()44 void AVCastControllerProxyTest::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     avCastControllerProxy_ = iface_cast<AVCastControllerProxy>(object);
57 }
58 
TearDown()59 void AVCastControllerProxyTest::TearDown()
60 {
61 }
62 
63 /**
64  * @tc.name: GetDuration001
65  * @tc.desc: Test GetDuration
66  * @tc.type: FUNC
67  */
HWTEST_F(AVCastControllerProxyTest, GetDuration001, testing::ext::TestSize.Level1)68 static HWTEST_F(AVCastControllerProxyTest, GetDuration001, testing::ext::TestSize.Level1)
69 {
70     SLOGI("GetDuration001, start");
71     int32_t duration = 0;
72     int32_t ret = avCastControllerProxy_->GetDuration(duration);
73     EXPECT_EQ(ret, ERR_IPC_SEND_REQUEST);
74     SLOGI("GetDuration001, end");
75 }
76 
77 /**
78  * @tc.name: GetCastAVPlaybackState001
79  * @tc.desc: Test GetCastAVPlaybackState
80  * @tc.type: FUNC
81  */
HWTEST_F(AVCastControllerProxyTest, GetCastAVPlaybackState001, testing::ext::TestSize.Level1)82 static HWTEST_F(AVCastControllerProxyTest, GetCastAVPlaybackState001, testing::ext::TestSize.Level1)
83 {
84     SLOGI("GetCastAVPlaybackState001, start");
85     AVPlaybackState state;
86     int32_t ret = avCastControllerProxy_->GetCastAVPlaybackState(state);
87     EXPECT_EQ(ret, AVSESSION_ERROR);
88     SLOGI("GetCastAVPlaybackState001, end");
89 }
90 
91 /**
92  * @tc.name: GetCurrentItem001
93  * @tc.desc: Test GetCurrentItem
94  * @tc.type: FUNC
95  */
HWTEST_F(AVCastControllerProxyTest, GetCurrentItem001, testing::ext::TestSize.Level1)96 static HWTEST_F(AVCastControllerProxyTest, GetCurrentItem001, testing::ext::TestSize.Level1)
97 {
98     SLOGI("GetCurrentItem001, start");
99     AVQueueItem currentItem;
100     int32_t ret = avCastControllerProxy_->GetCurrentItem(currentItem);
101     EXPECT_EQ(ret, AVSESSION_ERROR);
102     SLOGI("GetCurrentItem001, end");
103 }
104 
105 /**
106  * @tc.name: GetValidCommands001
107  * @tc.desc: Test GetValidCommand
108  * @tc.type: FUNC
109  */
HWTEST_F(AVCastControllerProxyTest, GetValidCommands001, testing::ext::TestSize.Level1)110 static HWTEST_F(AVCastControllerProxyTest, GetValidCommands001, testing::ext::TestSize.Level1)
111 {
112     SLOGI("GetValidCommands001, start");
113     std::vector<int32_t> cmds;
114     int32_t ret = avCastControllerProxy_->GetValidCommands(cmds);
115     EXPECT_EQ(ret, AVSESSION_ERROR);
116     SLOGI("GetValidCommands001, end");
117 }
118 
119 /**
120  * @tc.name: SetDisplaySurface001
121  * @tc.desc: Test SetDisplaySurface
122  * @tc.type: FUNC
123  */
HWTEST_F(AVCastControllerProxyTest, SetDisplaySurface001, testing::ext::TestSize.Level1)124 static HWTEST_F(AVCastControllerProxyTest, SetDisplaySurface001, testing::ext::TestSize.Level1)
125 {
126     SLOGI("SetDisplaySurface001, start");
127     std::string surfaceId = "1111";
128     int32_t ret = avCastControllerProxy_->SetDisplaySurface(surfaceId);
129     EXPECT_EQ(ret, AVSESSION_ERROR);
130     SLOGI("SetDisplaySurface001, end");
131 }
132 
133 /**
134  * @tc.name: ProcessMediaKeyResponse001
135  * @tc.desc: Test ProcessMediaKeyResponse
136  * @tc.type: FUNC
137  */
HWTEST_F(AVCastControllerProxyTest, ProcessMediaKeyResponse001, testing::ext::TestSize.Level1)138 static HWTEST_F(AVCastControllerProxyTest, ProcessMediaKeyResponse001, testing::ext::TestSize.Level1)
139 {
140     SLOGI("ProcessMediaKeyResponse001, start");
141     std::string assetId = "";
142     std::vector<uint8_t> response = {};
143     int32_t ret = avCastControllerProxy_->ProcessMediaKeyResponse(assetId, response);
144     EXPECT_EQ(ret, ERR_IPC_SEND_REQUEST);
145     SLOGI("ProcessMediaKeyResponse001, end");
146 }
147 
148 /**
149  * @tc.name: ProcessMediaKeyResponse002
150  * @tc.desc: Test ProcessMediaKeyResponse
151  * @tc.type: FUNC
152  */
HWTEST_F(AVCastControllerProxyTest, ProcessMediaKeyResponse002, testing::ext::TestSize.Level1)153 static HWTEST_F(AVCastControllerProxyTest, ProcessMediaKeyResponse002, testing::ext::TestSize.Level1)
154 {
155     SLOGI("ProcessMediaKeyResponse002, start");
156     std::string assetId = "";
157     std::vector<uint8_t> response = {1, 0, 1};
158     int32_t ret = avCastControllerProxy_->ProcessMediaKeyResponse(assetId, response);
159     EXPECT_EQ(ret, ERR_IPC_SEND_REQUEST);
160     SLOGI("ProcessMediaKeyResponse002, end");
161 }
162 
163 /**
164  * @tc.name: ProcessMediaKeyResponse003
165  * @tc.desc: Test ProcessMediaKeyResponse
166  * @tc.type: FUNC
167  */
HWTEST_F(AVCastControllerProxyTest, ProcessMediaKeyResponse003, testing::ext::TestSize.Level1)168 static HWTEST_F(AVCastControllerProxyTest, ProcessMediaKeyResponse003, testing::ext::TestSize.Level1)
169 {
170     SLOGI("ProcessMediaKeyResponse003, start");
171     std::string assetId = "";
172     std::vector<uint8_t> response(100000, 1);
173     int32_t ret = avCastControllerProxy_->ProcessMediaKeyResponse(assetId, response);
174     EXPECT_EQ(ret, ERR_IPC_SEND_REQUEST);
175     SLOGI("ProcessMediaKeyResponse003, end");
176 }
177 
178 /**
179  * @tc.name: AddAvailableCommand001
180  * @tc.desc: Test AddAvailableCommand
181  * @tc.type: FUNC
182  */
HWTEST_F(AVCastControllerProxyTest, AddAvailableCommand001, testing::ext::TestSize.Level1)183 static HWTEST_F(AVCastControllerProxyTest, AddAvailableCommand001, testing::ext::TestSize.Level1)
184 {
185     SLOGI("AddAvailableCommand001, start");
186     int32_t cmd = 0;
187     int32_t ret = avCastControllerProxy_->AddAvailableCommand(cmd);
188     EXPECT_EQ(ret, AVSESSION_ERROR);
189     SLOGI("AddAvailableCommand001, end");
190 }
191 
192 /**
193  * @tc.name: RemoveAvailableCommand001
194  * @tc.desc: Test RemoveAvailableCommand
195  * @tc.type: FUNC
196  */
HWTEST_F(AVCastControllerProxyTest, RemoveAvailableCommand001, testing::ext::TestSize.Level1)197 static HWTEST_F(AVCastControllerProxyTest, RemoveAvailableCommand001, testing::ext::TestSize.Level1)
198 {
199     SLOGI("RemoveAvailableCommand001, start");
200     int32_t cmd = 0;
201     int32_t ret = avCastControllerProxy_->RemoveAvailableCommand(cmd);
202     EXPECT_EQ(ret, AVSESSION_ERROR);
203     SLOGI("RemoveAvailableCommand001, end");
204 }
205 
206 } // namespace OHOS::AVSession