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 "insight_intent_execute_param.h"
20 #define private public
21 #define protected public
22 #include "bundle_status_adapter.h"
23 #undef protected
24 #undef private
25
26 using namespace testing::ext;
27 using namespace OHOS::AVSession;
28
29 class BundleStatusAdapterTest : public testing::Test {
30 public:
31 static void SetUpTestCase(void);
32 static void TearDownTestCase(void);
33 void SetUp();
34 void TearDown();
35 };
36
SetUpTestCase()37 void BundleStatusAdapterTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void BundleStatusAdapterTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void BundleStatusAdapterTest::SetUp()
46 {
47 BundleStatusAdapter::GetInstance().Init();
48 }
49
TearDown()50 void BundleStatusAdapterTest::TearDown()
51 {
52 }
53
54 /**
55 * @tc.name: GetBundleNameFromUid001
56 * @tc.desc: Test GetBundleNameFromUid
57 * @tc.type: FUNC
58 */
59 static HWTEST_F(BundleStatusAdapterTest, GetBundleNameFromUid001, testing::ext::TestSize.Level1)
60 {
61 SLOGI("GetBundleNameFromUid001, start");
62 const int32_t uid = 0;
63 BundleStatusAdapter::GetInstance().GetBundleNameFromUid(uid);
64 SLOGI("GetBundleNameFromUid001, end");
65 }
66
67 /**
68 * @tc.name: CheckBundleSupport001
69 * @tc.desc: Test CheckBundleSupport
70 * @tc.type: FUNC
71 */
72 static HWTEST_F(BundleStatusAdapterTest, CheckBundleSupport001, testing::ext::TestSize.Level1)
73 {
74 SLOGI("CheckBundleSupport001, start");
75 std::string profile = "";
76 bool ret = BundleStatusAdapter::GetInstance().CheckBundleSupport(profile);
77 EXPECT_EQ(ret, false);
78 SLOGI("CheckBundleSupport001, end");
79 }
80
81 /**
82 * @tc.name: CheckBundleSupport002
83 * @tc.desc: Test CheckBundleSupport
84 * @tc.type: FUNC
85 */
86 static HWTEST_F(BundleStatusAdapterTest, CheckBundleSupport002, testing::ext::TestSize.Level1)
87 {
88 SLOGI("CheckBundleSupport002, start");
89 std::string profile = R"({
90 "insightIntents": [
91 {
92 "intentName": "OTHER_INTENT",
93 "uiAbility": {
94 "executeMode": ["background"]
95 }
96 }
97 ]
98 })";
99 bool ret = BundleStatusAdapter::GetInstance().CheckBundleSupport(profile);
100 EXPECT_EQ(ret, false);
101 SLOGI("CheckBundleSupport002, end");
102 }
103
104 /**
105 * @tc.name: CheckBundleSupport003
106 * @tc.desc: Test CheckBundleSupport
107 * @tc.type: FUNC
108 */
109 static HWTEST_F(BundleStatusAdapterTest, CheckBundleSupport003, testing::ext::TestSize.Level1)
110 {
111 SLOGI("CheckBundleSupport003, start");
112 std::string profile = R"({
113 "insightIntents": [
114 {
115 "intentName": "PLAY_MUSICLIST",
116 "uiAbility": {
117 "executeMode": ["background"]
118 }
119 }
120 ]
121 })";
122 bool ret = BundleStatusAdapter::GetInstance().CheckBundleSupport(profile);
123 EXPECT_EQ(ret, false);
124 SLOGI("CheckBundleSupport003, end");
125 }
126
127 /**
128 * @tc.name: CheckBundleSupport004
129 * @tc.desc: Test CheckBundleSupport
130 * @tc.type: FUNC
131 */
132 static HWTEST_F(BundleStatusAdapterTest, CheckBundleSupport004, testing::ext::TestSize.Level1)
133 {
134 SLOGI("CheckBundleSupport004, start");
135 std::string profile = R"({
136 "insightIntents": [
137 {
138 "intentName": "PLAY_AUDIO",
139 "uiAbility": {
140 "executeMode": ["background"]
141 }
142 }
143 ]
144 })";
145 bool ret = BundleStatusAdapter::GetInstance().CheckBundleSupport(profile);
146 EXPECT_EQ(ret, false);
147 SLOGI("CheckBundleSupport004, end");
148 }
149
150 /**
151 * @tc.name: SubscribeBundleStatusEvent001
152 * @tc.desc: Test SubscribeBundleStatusEvent
153 * @tc.type: FUNC
154 */
155 static HWTEST_F(BundleStatusAdapterTest, SubscribeBundleStatusEvent001, testing::ext::TestSize.Level1)
156 {
157 SLOGI("SubscribeBundleStatusEvent001, start");
158 std::string bundleName = "";
__anon1f4598320102(const std::string& capturedBundleName, int32_t userId) 159 auto callback = [bundleName](const std::string& capturedBundleName, int32_t userId) {
160 SLOGI("SubscribeBundleStatusEvent001: get bundle name: %{public}s, userId: %{public}d",
161 capturedBundleName.c_str(), userId);
162 };
163 bool ret = BundleStatusAdapter::GetInstance().SubscribeBundleStatusEvent(bundleName, callback);
164 EXPECT_EQ(ret, false);
165 SLOGI("SubscribeBundleStatusEvent001, end");
166 }
167
168 /**
169 * @tc.name: SubscribeBundleStatusEvent002
170 * @tc.desc: Test SubscribeBundleStatusEvent
171 * @tc.type: FUNC
172 */
173 static HWTEST_F(BundleStatusAdapterTest, SubscribeBundleStatusEvent002, testing::ext::TestSize.Level1)
174 {
175 SLOGI("SubscribeBundleStatusEvent002, start");
176 std::string bundleName = "com.ohos.camera";
__anon1f4598320202(const std::string& capturedBundleName, int32_t userId) 177 auto callback = [bundleName](const std::string& capturedBundleName, int32_t userId) {
178 SLOGI("SubscribeBundleStatusEvent002: get bundle name: %{public}s, userId: %{public}d",
179 capturedBundleName.c_str(), userId);
180 };
181 bool ret = BundleStatusAdapter::GetInstance().SubscribeBundleStatusEvent(bundleName, callback);
182 EXPECT_EQ(ret, false);
183 SLOGI("SubscribeBundleStatusEvent002, end");
184 }
185
186 /**
187 * @tc.name: IsAudioPlayback001
188 * @tc.desc: Test IsAudioPlayback
189 * @tc.type: FUNC
190 */
191 static HWTEST_F(BundleStatusAdapterTest, IsAudioPlayback001, testing::ext::TestSize.Level1)
192 {
193 SLOGI("IsAudioPlayback001, start");
194 std::string bundleName = "";
195 std::string abilityName = "";
196 bool ret = BundleStatusAdapter::GetInstance().IsAudioPlayback(bundleName, abilityName);
197 EXPECT_EQ(ret, false);
198 SLOGI("IsAudioPlayback001, end");
199 }
200
201 /**
202 * @tc.name: IsAudioPlayback002
203 * @tc.desc: Test IsAudioPlayback
204 * @tc.type: FUNC
205 */
206 static HWTEST_F(BundleStatusAdapterTest, IsAudioPlayback002, testing::ext::TestSize.Level1)
207 {
208 SLOGI("IsAudioPlayback002, start");
209 std::string bundleName = "com.ohos.screenshot";
210 std::string abilityName = "MainAbility";
__anon1f4598320302(const std::string& capturedBundleName, int32_t userId) 211 auto callback = [bundleName](const std::string& capturedBundleName, int32_t userId) {
212 SLOGI("SubscribeBundleStatusEvent003: get bundle name: %{public}s, userId: %{public}d",
213 capturedBundleName.c_str(), userId);
214 };
215 BundleStatusAdapter::GetInstance().SubscribeBundleStatusEvent(bundleName, callback);
216 bool ret = BundleStatusAdapter::GetInstance().IsAudioPlayback(bundleName, abilityName);
217 EXPECT_EQ(ret, false);
218 SLOGI("IsAudioPlayback002, end");
219 }
220
221 /**
222 * @tc.name: NotifyBundleRemoved001
223 * @tc.desc: Test NotifyBundleRemoved
224 * @tc.type: FUNC
225 */
226 static HWTEST_F(BundleStatusAdapterTest, NotifyBundleRemoved001, testing::ext::TestSize.Level1)
227 {
228 SLOGI("NotifyBundleRemoved001, start");
229 std::string bundleName = "com.ohos.screenshot";
230 std::string abilityName = "MainAbility";
__anon1f4598320402(const std::string& capturedBundleName, int32_t userId) 231 auto callback = [bundleName](const std::string& capturedBundleName, int32_t userId) {
232 SLOGI("SubscribeBundleStatusEvent004: get bundle name: %{public}s, userId: %{public}d",
233 capturedBundleName.c_str(), userId);
234 };
235 BundleStatusAdapter::GetInstance().SubscribeBundleStatusEvent(bundleName, callback);
236 BundleStatusAdapter::GetInstance().NotifyBundleRemoved(bundleName, 100);
237 EXPECT_EQ(bundleName, "com.ohos.screenshot");
238 SLOGI("NotifyBundleRemoved001, end");
239 }
240
241 /**
242 * @tc.name: NotifyBundleRemoved002
243 * @tc.desc: Test NotifyBundleRemoved
244 * @tc.type: FUNC
245 */
246 static HWTEST_F(BundleStatusAdapterTest, NotifyBundleRemoved002, testing::ext::TestSize.Level1)
247 {
248 SLOGI("NotifyBundleRemoved002, start");
249 std::string bundleName = "com.ohos.test";
250 std::string abilityName = "MainAbility";
251 BundleStatusAdapter::GetInstance().NotifyBundleRemoved(bundleName, 100);
252 EXPECT_EQ(bundleName, "com.ohos.test");
253 SLOGI("NotifyBundleRemoved002, end");
254 }
255
256 /**
257 * @tc.name: IsSupportPlayIntent001
258 * @tc.desc: Test IsSupportPlayIntent
259 * @tc.type: FUNC
260 */
261 static HWTEST_F(BundleStatusAdapterTest, IsSupportPlayIntent001, testing::ext::TestSize.Level1)
262 {
263 SLOGI("IsSupportPlayIntent001, start");
264 std::string bundleName = "";
265 std::string supportModule = "";
266 std::string profile = "";
267 bool ret = BundleStatusAdapter::GetInstance().IsSupportPlayIntent(bundleName, supportModule, profile);
268 EXPECT_EQ(ret, false);
269 SLOGI("IsSupportPlayIntent001, end");
270 }
271
272 /**
273 * @tc.name: IsSupportPlayIntent002
274 * @tc.desc: Test IsSupportPlayIntent
275 * @tc.type: FUNC
276 */
277 static HWTEST_F(BundleStatusAdapterTest, IsSupportPlayIntent002, testing::ext::TestSize.Level1)
278 {
279 SLOGI("IsSupportPlayIntent002, start");
280 std::string bundleName = "com.IsSupportPlayIntent.test";
281 std::string supportModule = "";
282 std::string profile = "";
__anon1f4598320502(const std::string& capturedBundleName, int32_t userId) 283 auto callback = [bundleName](const std::string& capturedBundleName, int32_t userId) {
284 SLOGI("SubscribeBundleStatusEvent005: get bundle name: %{public}s, userId: %{public}d",
285 capturedBundleName.c_str(), userId);
286 };
287 BundleStatusAdapter::GetInstance().SubscribeBundleStatusEvent(bundleName, callback);
288 bool ret = BundleStatusAdapter::GetInstance().IsSupportPlayIntent(bundleName, supportModule, profile);
289 EXPECT_EQ(ret, false);
290 SLOGI("IsSupportPlayIntent002, end");
291 }