1 /*
2 * Copyright (c) 2023 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
18 #include "connection/screen_snapshot_picker_connection.h"
19 #include "screen_scene_config.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms
28 }
29 class ScreenSnapshotPickerConnectionTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 };
36
SetUpTestCase()37 void ScreenSnapshotPickerConnectionTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void ScreenSnapshotPickerConnectionTest::TearDownTestCase()
42 {
43 usleep(SLEEP_TIME_IN_US);
44 }
45
SetUp()46 void ScreenSnapshotPickerConnectionTest::SetUp()
47 {
48 }
49
TearDown()50 void ScreenSnapshotPickerConnectionTest::TearDown()
51 {
52 }
53
54 namespace {
55
56 /**
57 * @tc.name: SnapshotPickerConnectExtension01
58 * @tc.desc: SnapshotPickerConnectExtension func
59 * @tc.type: FUNC
60 */
61 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension01, Function | SmallTest | Level1)
62 {
63 ScreenSceneConfig::LoadConfigXml();
64 auto strConfig = ScreenSceneConfig::GetStringConfig();
65 std::string bundleName = strConfig["screenSnapshotBundleName"];
66 std::string abilityName = strConfig["screenSnapshotAbilityName"];
67 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
68 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
69 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
70 EXPECT_EQ(ret, false);
71 }
72
73 /**
74 * @tc.name: SnapshotPickerConnectExtension02
75 * @tc.desc: SnapshotPickerConnectExtension func
76 * @tc.type: FUNC
77 */
78 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension02, Function | SmallTest | Level1)
79 {
80 ScreenSceneConfig::LoadConfigXml();
81 auto strConfig = ScreenSceneConfig::GetStringConfig();
82 std::string bundleName = strConfig[""];
83 std::string abilityName = strConfig["screenSnapshotAbilityName"];
84 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
85 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
86 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
87 EXPECT_EQ(ret, false);
88 }
89
90 /**
91 * @tc.name: SnapshotPickerConnectExtension03
92 * @tc.desc: SnapshotPickerConnectExtension func
93 * @tc.type: FUNC
94 */
95 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension03, Function | SmallTest | Level1)
96 {
97 ScreenSceneConfig::LoadConfigXml();
98 auto strConfig = ScreenSceneConfig::GetStringConfig();
99 std::string bundleName = strConfig["screenSnapshotBundleName"];
100 std::string abilityName = strConfig[""];
101 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
102 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
103 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
104 EXPECT_EQ(ret, false);
105 }
106
107 /**
108 * @tc.name: SnapshotPickerConnectExtension04
109 * @tc.desc: SnapshotPickerConnectExtension func
110 * @tc.type: FUNC
111 */
112 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension04, Function | SmallTest | Level1)
113 {
114 ScreenSceneConfig::LoadConfigXml();
115 auto strConfig = ScreenSceneConfig::GetStringConfig();
116 std::string bundleName = strConfig[""];
117 std::string abilityName = strConfig[""];
118 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
119 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
120 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
121 EXPECT_EQ(ret, false);
122 }
123
124 /**
125 * @tc.name: SnapshotPickerConnectExtension05
126 * @tc.desc: SnapshotPickerConnectExtension func
127 * @tc.type: FUNC
128 */
129 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension05, Function | SmallTest | Level1)
130 {
131 ScreenSceneConfig::LoadConfigXml();
132 auto strConfig = ScreenSceneConfig::GetStringConfig();
133 std::string bundleName = strConfig[""];
134 std::string abilityName = strConfig[""];
135 std::unique_ptr<ScreenSessionAbilityConnection> abilityConnection_ =
136 std::make_unique<ScreenSessionAbilityConnection>();
137 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
138 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
139 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
140 EXPECT_EQ(ret, false);
141 }
142
143 /**
144 * @tc.name: SnapshotPickerConnectExtension06
145 * @tc.desc: SnapshotPickerConnectExtension func
146 * @tc.type: FUNC
147 */
148 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension06, Function | SmallTest | Level1)
149 {
150 std::string bundleName = "testScreenSnapshotBundleName";
151 std::string abilityName = "testScreenSnapshotAbilityName";
152 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
153 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
154 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
155 EXPECT_EQ(ret, false);
156 ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
157 EXPECT_EQ(ret, true);
158 }
159
160 /**
161 * @tc.name: GetScreenSnapshotInfo01
162 * @tc.desc: GetScreenSnapshotInfo func
163 * @tc.type: FUNC
164 */
165 HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSnapshotInfo01, Function | SmallTest | Level1)
166 {
167 ScreenSnapshotPickerConnection::GetInstance().abilityConnection_ = nullptr;
168 Media::Rect rect{};
169 ScreenId screenId = SCREEN_ID_INVALID;
170 auto ret = ScreenSnapshotPickerConnection::GetInstance().GetScreenSnapshotInfo(rect, screenId);
171 EXPECT_EQ(ret, -1);
172 }
173
174 /**
175 * @tc.name: GetScreenSnapshotInfo02
176 * @tc.desc: GetScreenSnapshotInfo func
177 * @tc.type: FUNC
178 */
179 HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSnapshotInfo02, Function | SmallTest | Level1)
180 {
181 ScreenSnapshotPickerConnection::GetInstance().abilityConnection_ =
182 std::make_unique<ScreenSessionAbilityConnection>();
183 ScreenSnapshotPickerConnection::GetInstance().abilityConnection_->
184 GetScreenSessionAbilityConnectionStub() = nullptr;
185 Media::Rect rect{};
186 ScreenId screenId;
187 auto ret = ScreenSnapshotPickerConnection::GetInstance().GetScreenSnapshotInfo(rect, screenId);
188 EXPECT_EQ(ret, -1);
189 }
190
191 /**
192 * @tc.name: GetScreenSnapshotInfo03
193 * @tc.desc: GetScreenSnapshotInfo func
194 * @tc.type: FUNC
195 */
196 HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSnapshotInfo03, Function | SmallTest | Level1)
197 {
198 std::string bundleName = "testScreenSnapshotBundleName";
199 std::string abilityName = "testScreenSnapshotAbilityName";
200 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
201 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
202 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
203 EXPECT_EQ(ret, true);
204 Media::Rect rect{};
205 ScreenId screenId;
206 ret = ScreenSnapshotPickerConnection::GetInstance().GetScreenSnapshotInfo(rect, screenId);
207 EXPECT_EQ(ret, true);
208 }
209
210 /**
211 * @tc.name: SnapshotPickerDisconnectExtension01
212 * @tc.desc: SnapshotPickerDisconnectExtension func
213 * @tc.type: FUNC
214 */
215 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerDisconnectExtension01, Function | SmallTest | Level1)
216 {
217 std::unique_ptr<ScreenSessionAbilityConnection> abilityConnection_ = nullptr;
218 ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerDisconnectExtension();
219 EXPECT_EQ(abilityConnection_, nullptr);
220 }
221
222 /**
223 * @tc.name: SnapshotPickerDisconnectExtension02
224 * @tc.desc: SnapshotPickerDisconnectExtension func
225 * @tc.type: FUNC
226 */
227 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerDisconnectExtension02, Function | SmallTest | Level1)
228 {
229 std::unique_ptr<ScreenSessionAbilityConnection> abilityConnection_ =
230 std::make_unique<ScreenSessionAbilityConnection>();
231 ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerDisconnectExtension();
232 EXPECT_NE(abilityConnection_, nullptr);
233 }
234
235 /**
236 * @tc.name: GetScreenSnapshotRect
237 * @tc.desc: GetScreenSnapshotRect func
238 * @tc.type: FUNC
239 */
240 HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSnapshotRect, Function | SmallTest | Level1)
241 {
242 Media::Rect rect{};
243 ScreenId screenId = SCREEN_ID_INVALID;
244 ScreenSceneConfig::LoadConfigXml();
245 auto strConfig = ScreenSceneConfig::GetStringConfig();
246 std::string bundleName = strConfig["screenSnapshotBundleName"];
247 std::string abilityName = strConfig["screenSnapshotAbilityName"];
248 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
249 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
250 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
251 EXPECT_EQ(ret, false);
252 ScreenSnapshotPickerConnection::GetInstance().GetScreenSnapshotInfo(rect, screenId);
253 EXPECT_EQ(rect.top, 0);
254 EXPECT_EQ(rect.left, 0);
255 EXPECT_EQ(rect.width, 0);
256 EXPECT_EQ(rect.height, 0);
257 ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerDisconnectExtension();
258 }
259
260 /**
261 * @tc.name: GetScreenSessionAbilityConnectionStub
262 * @tc.desc: GetScreenSessionAbilityConnectionStub func
263 * @tc.type: FUNC
264 */
265 HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSessionAbilityConnectionStub, Function | SmallTest | Level1)
266 {
267 std::string bundleName = "testScreenSnapshotBundleName";
268 std::string abilityName = "testScreenSnapshotAbilityName";
269 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
270 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
271 bool ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
272 EXPECT_EQ(ret, false);
273 ASSERT_NE(ScreenSnapshotPickerConnection::GetInstance().abilityConnection_, nullptr);
274 EXPECT_NE(ScreenSnapshotPickerConnection::GetInstance().GetScreenSessionAbilityConnectionStub(), nullptr);
275 }
276
277 }
278 } // namespace Rosen
279 } // namespace OHOS