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 "avsession_errors.h"
18 #include "avsession_log.h"
19 #include "collaboration_manager_utils.h"
20 #include "collaboration_manager.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::AVSession;
24 
25 class CollaborationManagerTest : public testing::Test {
26 public:
27     static void SetUpTestCase(void);
28     static void TearDownTestCase(void);
29     void SetUp();
30     void TearDown();
31 };
32 
SetUpTestCase()33 void CollaborationManagerTest::SetUpTestCase()
34 {
35 }
36 
TearDownTestCase()37 void CollaborationManagerTest::TearDownTestCase()
38 {
39 }
40 
SetUp()41 void CollaborationManagerTest::SetUp()
42 {
43 }
44 
TearDown()45 void CollaborationManagerTest::TearDown()
46 {
47 }
48 
49 /**
50  * @tc.name: RegisterLifecycleCallback001
51  * @tc.desc: Test RegisterLifecycleCallback
52  * @tc.type: FUNC
53  */
HWTEST_F(CollaborationManagerTest, RegisterLifecycleCallback001, testing::ext::TestSize.Level1)54 static HWTEST_F(CollaborationManagerTest, RegisterLifecycleCallback001, testing::ext::TestSize.Level1)
55 {
56     SLOGI("RegisterLifecycleCallback001, start");
57     int32_t ret = CollaborationManager::GetInstance().RegisterLifecycleCallback();
58     EXPECT_EQ(ret, AVSESSION_ERROR);
59     SLOGI("RegisterLifecycleCallback001, end");
60 }
61 
62 /**
63  * @tc.name: RegisterLifecycleCallback002
64  * @tc.desc: Test RegisterLifecycleCallback
65  * @tc.type: FUNC
66  */
HWTEST_F(CollaborationManagerTest, RegisterLifecycleCallback002, testing::ext::TestSize.Level1)67 static HWTEST_F(CollaborationManagerTest, RegisterLifecycleCallback002, testing::ext::TestSize.Level1)
68 {
69     SLOGI("RegisterLifecycleCallback002, start");
70     auto registerLifecycleCallback = [](const char* serviceName, ServiceCollaborationManager_Callback* callback) {
71         return static_cast<int32_t>(0);
72     };
73     CollaborationManager::GetInstance().exportapi_.ServiceCollaborationManager_RegisterLifecycleCallback
74         = registerLifecycleCallback;
75     int32_t ret = CollaborationManager::GetInstance().RegisterLifecycleCallback();
76     EXPECT_EQ(ret, AVSESSION_SUCCESS);
77     SLOGI("RegisterLifecycleCallback002, end");
78 }
79 
80 
81 /**
82  * @tc.name: RegisterLifecycleCallback003
83  * @tc.desc: Test RegisterLifecycleCallback
84  * @tc.type: FUNC
85  */
HWTEST_F(CollaborationManagerTest, RegisterLifecycleCallback003, testing::ext::TestSize.Level1)86 static HWTEST_F(CollaborationManagerTest, RegisterLifecycleCallback003, testing::ext::TestSize.Level1)
87 {
88     SLOGI("RegisterLifecycleCallback003, start");
89     auto registerLifecycleCallback = [](const char* serviceName, ServiceCollaborationManager_Callback* callback) {
90         return static_cast<int32_t>(1);
91     };
92     CollaborationManager::GetInstance().exportapi_.ServiceCollaborationManager_RegisterLifecycleCallback
93         = registerLifecycleCallback;
94     int32_t ret = CollaborationManager::GetInstance().RegisterLifecycleCallback();
95     EXPECT_EQ(ret, AVSESSION_ERROR);
96     SLOGI("RegisterLifecycleCallback003, end");
97 }
98 
99 /**
100  * @tc.name: UnRegisterLifecycleCallback001
101  * @tc.desc: Test UnRegisterLifecycleCallback
102  * @tc.type: FUNC
103  */
HWTEST_F(CollaborationManagerTest, UnRegisterLifecycleCallback001, testing::ext::TestSize.Level1)104 static HWTEST_F(CollaborationManagerTest, UnRegisterLifecycleCallback001, testing::ext::TestSize.Level1)
105 {
106     SLOGI("UnRegisterLifecycleCallback001, start");
107     int32_t ret = CollaborationManager::GetInstance().UnRegisterLifecycleCallback();
108     EXPECT_EQ(ret, AVSESSION_ERROR);
109     SLOGI("UnRegisterLifecycleCallback001, end");
110 }
111 
112 /**
113  * @tc.name: UnRegisterLifecycleCallback002
114  * @tc.desc: Test UnRegisterLifecycleCallback
115  * @tc.type: FUNC
116  */
HWTEST_F(CollaborationManagerTest, UnRegisterLifecycleCallback002, testing::ext::TestSize.Level1)117 static HWTEST_F(CollaborationManagerTest, UnRegisterLifecycleCallback002, testing::ext::TestSize.Level1)
118 {
119     SLOGI("UnRegisterLifecycleCallback002, start");
120     auto unRegisterLifecycleCallback = [](const char* serviceName) {
121         return static_cast<int32_t>(0);
122     };
123     CollaborationManager::GetInstance().exportapi_.ServiceCollaborationManager_UnRegisterLifecycleCallback
124         = unRegisterLifecycleCallback;
125     int32_t ret = CollaborationManager::GetInstance().UnRegisterLifecycleCallback();
126     EXPECT_EQ(ret, AVSESSION_SUCCESS);
127     SLOGI("UnRegisterLifecycleCallback002, end");
128 }
129 
130 /**
131  * @tc.name: UnRegisterLifecycleCallback003
132  * @tc.desc: Test UnRegisterLifecycleCallback
133  * @tc.type: FUNC
134  */
HWTEST_F(CollaborationManagerTest, UnRegisterLifecycleCallback003, testing::ext::TestSize.Level1)135 static HWTEST_F(CollaborationManagerTest, UnRegisterLifecycleCallback003, testing::ext::TestSize.Level1)
136 {
137     SLOGI("UnRegisterLifecycleCallback003, start");
138     auto unRegisterLifecycleCallback = [](const char* serviceName) {
139         return static_cast<int32_t>(1);
140     };
141     CollaborationManager::GetInstance().exportapi_.ServiceCollaborationManager_UnRegisterLifecycleCallback
142         = unRegisterLifecycleCallback;
143     int32_t ret = CollaborationManager::GetInstance().UnRegisterLifecycleCallback();
144     EXPECT_EQ(ret, AVSESSION_ERROR);
145     SLOGI("UnRegisterLifecycleCallback003, end");
146 }
147 
148 /**
149  * @tc.name: PublishServiceState001
150  * @tc.desc: Test PublishServiceState
151  * @tc.type: FUNC
152  */
HWTEST_F(CollaborationManagerTest, PublishServiceState001, testing::ext::TestSize.Level1)153 static HWTEST_F(CollaborationManagerTest, PublishServiceState001, testing::ext::TestSize.Level1)
154 {
155     SLOGI("PublishServiceState001, start");
156     const char* peerNetworkId = "";
157     ServiceCollaborationManagerBussinessStatus state = ServiceCollaborationManagerBussinessStatus::SCM_IDLE;
158     int32_t ret = CollaborationManager::GetInstance().PublishServiceState(peerNetworkId, state);
159     EXPECT_EQ(ret, AVSESSION_ERROR);
160     SLOGI("PublishServiceState001, end");
161 }
162 
163 /**
164  * @tc.name: PublishServiceState002
165  * @tc.desc: Test PublishServiceState
166  * @tc.type: FUNC
167  */
HWTEST_F(CollaborationManagerTest, PublishServiceState002, testing::ext::TestSize.Level1)168 static HWTEST_F(CollaborationManagerTest, PublishServiceState002, testing::ext::TestSize.Level1)
169 {
170     SLOGI("PublishServiceState002, start");
171     const char* peerNetworkId = "";
172     ServiceCollaborationManagerBussinessStatus state = ServiceCollaborationManagerBussinessStatus::SCM_IDLE;
173     auto publishServiceState = [](const char* peerNetworkId, const char* serviceName,
174         const char* extraInfo, ServiceCollaborationManagerBussinessStatus state) {
175             return static_cast<int32_t>(0);
176     };
177     CollaborationManager::GetInstance().exportapi_.ServiceCollaborationManager_PublishServiceState
178         = publishServiceState;
179     int32_t ret = CollaborationManager::GetInstance().PublishServiceState(peerNetworkId, state);
180     EXPECT_EQ(ret, AVSESSION_SUCCESS);
181     SLOGI("PublishServiceState002, end");
182 }
183 
184 /**
185  * @tc.name: PublishServiceState003
186  * @tc.desc: Test PublishServiceState
187  * @tc.type: FUNC
188  */
HWTEST_F(CollaborationManagerTest, PublishServiceState003, testing::ext::TestSize.Level1)189 static HWTEST_F(CollaborationManagerTest, PublishServiceState003, testing::ext::TestSize.Level1)
190 {
191     SLOGI("PublishServiceState003, start");
192     const char* peerNetworkId = "";
193     ServiceCollaborationManagerBussinessStatus state = ServiceCollaborationManagerBussinessStatus::SCM_IDLE;
194     auto publishServiceState = [](const char* peerNetworkId, const char* serviceName,
195         const char* extraInfo, ServiceCollaborationManagerBussinessStatus state) {
196             return static_cast<int32_t>(1);
197     };
198     CollaborationManager::GetInstance().exportapi_.ServiceCollaborationManager_PublishServiceState
199         = publishServiceState;
200     int32_t ret = CollaborationManager::GetInstance().PublishServiceState(peerNetworkId, state);
201     EXPECT_EQ(ret, AVSESSION_ERROR);
202     SLOGI("PublishServiceState003, end");
203 }
204 
205 /**
206  * @tc.name: ApplyAdvancedResource001
207  * @tc.desc: Test ApplyAdvancedResource
208  * @tc.type: FUNC
209  */
HWTEST_F(CollaborationManagerTest, ApplyAdvancedResource001, testing::ext::TestSize.Level1)210 static HWTEST_F(CollaborationManagerTest, ApplyAdvancedResource001, testing::ext::TestSize.Level1)
211 {
212     SLOGI("ApplyAdvancedResource001, start");
213     const char* peerNetworkId = "";
214     int32_t ret = CollaborationManager::GetInstance().ApplyAdvancedResource(peerNetworkId);
215     EXPECT_EQ(ret, AVSESSION_ERROR);
216     SLOGI("ApplyAdvancedResource001, end");
217 }
218 
219 /**
220  * @tc.name: ApplyAdvancedResource002
221  * @tc.desc: Test ApplyAdvancedResource
222  * @tc.type: FUNC
223  */
HWTEST_F(CollaborationManagerTest, ApplyAdvancedResource002, testing::ext::TestSize.Level1)224 static HWTEST_F(CollaborationManagerTest, ApplyAdvancedResource002, testing::ext::TestSize.Level1)
225 {
226     SLOGI("ApplyAdvancedResource002, start");
227     const char* peerNetworkId = "";
228     auto applyAdvancedResource = [](const char* peerNetworkId, const char* serviceName,
229         ServiceCollaborationManager_ResourceRequestInfoSets* resourceRequest,
230         ServiceCollaborationManager_Callback* callback) {
231             return static_cast<int32_t>(0);
232     };
233     CollaborationManager::GetInstance().exportapi_.ServiceCollaborationManager_ApplyAdvancedResource
234         = applyAdvancedResource;
235     int32_t ret = CollaborationManager::GetInstance().ApplyAdvancedResource(peerNetworkId);
236     EXPECT_EQ(ret, AVSESSION_SUCCESS);
237     SLOGI("ApplyAdvancedResource002, end");
238 }
239 
240 /**
241  * @tc.name: ApplyAdvancedResource003
242  * @tc.desc: Test ApplyAdvancedResource
243  * @tc.type: FUNC
244  */
HWTEST_F(CollaborationManagerTest, ApplyAdvancedResource003, testing::ext::TestSize.Level1)245 static HWTEST_F(CollaborationManagerTest, ApplyAdvancedResource003, testing::ext::TestSize.Level1)
246 {
247     SLOGI("ApplyAdvancedResource003, start");
248     const char* peerNetworkId = "";
249     auto applyAdvancedResource = [](const char* peerNetworkId, const char* serviceName,
250         ServiceCollaborationManager_ResourceRequestInfoSets* resourceRequest,
251         ServiceCollaborationManager_Callback* callback) {
252             return static_cast<int32_t>(1);
253     };
254     CollaborationManager::GetInstance().exportapi_.ServiceCollaborationManager_ApplyAdvancedResource
255         = applyAdvancedResource;
256     int32_t ret = CollaborationManager::GetInstance().ApplyAdvancedResource(peerNetworkId);
257     EXPECT_EQ(ret, AVSESSION_ERROR);
258     SLOGI("ApplyAdvancedResource003, end");
259 }