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 bool g_isPcDevice = ScreenSceneConfig::GetExternalScreenDefaultMode() == "none";
29 }
30 class ScreenSnapshotPickerConnectionTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp() override;
35 void TearDown() override;
36 };
37
SetUpTestCase()38 void ScreenSnapshotPickerConnectionTest::SetUpTestCase()
39 {
40 }
41
TearDownTestCase()42 void ScreenSnapshotPickerConnectionTest::TearDownTestCase()
43 {
44 usleep(SLEEP_TIME_IN_US);
45 }
46
SetUp()47 void ScreenSnapshotPickerConnectionTest::SetUp()
48 {
49 }
50
TearDown()51 void ScreenSnapshotPickerConnectionTest::TearDown()
52 {
53 }
54
55 namespace {
56
57 /**
58 * @tc.name: SnapshotPickerConnectExtension01
59 * @tc.desc: SnapshotPickerConnectExtension func
60 * @tc.type: FUNC
61 */
62 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension01, Function | SmallTest | Level1)
63 {
64 ScreenSceneConfig::LoadConfigXml();
65 auto strConfig = ScreenSceneConfig::GetStringConfig();
66 std::string bundleName = strConfig["screenSnapshotBundleName"];
67 std::string abilityName = strConfig["screenSnapshotAbilityName"];
68 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
69 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
70 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
71 EXPECT_EQ(ret, g_isPcDevice);
72 }
73
74 /**
75 * @tc.name: SnapshotPickerConnectExtension02
76 * @tc.desc: SnapshotPickerConnectExtension func
77 * @tc.type: FUNC
78 */
79 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension02, Function | SmallTest | Level1)
80 {
81 ScreenSceneConfig::LoadConfigXml();
82 auto strConfig = ScreenSceneConfig::GetStringConfig();
83 std::string bundleName = strConfig[""];
84 std::string abilityName = strConfig["screenSnapshotAbilityName"];
85 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
86 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
87 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
88 EXPECT_EQ(ret, false);
89 }
90
91 /**
92 * @tc.name: SnapshotPickerConnectExtension03
93 * @tc.desc: SnapshotPickerConnectExtension func
94 * @tc.type: FUNC
95 */
96 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension03, Function | SmallTest | Level1)
97 {
98 ScreenSceneConfig::LoadConfigXml();
99 auto strConfig = ScreenSceneConfig::GetStringConfig();
100 std::string bundleName = strConfig["screenSnapshotBundleName"];
101 std::string abilityName = strConfig[""];
102 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
103 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
104 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
105 EXPECT_EQ(ret, false);
106 }
107
108 /**
109 * @tc.name: SnapshotPickerConnectExtension04
110 * @tc.desc: SnapshotPickerConnectExtension func
111 * @tc.type: FUNC
112 */
113 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension04, Function | SmallTest | Level1)
114 {
115 ScreenSceneConfig::LoadConfigXml();
116 auto strConfig = ScreenSceneConfig::GetStringConfig();
117 std::string bundleName = strConfig[""];
118 std::string abilityName = strConfig[""];
119 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
120 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
121 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
122 EXPECT_EQ(ret, false);
123 }
124
125 /**
126 * @tc.name: SnapshotPickerConnectExtension05
127 * @tc.desc: SnapshotPickerConnectExtension func
128 * @tc.type: FUNC
129 */
130 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension05, Function | SmallTest | Level1)
131 {
132 ScreenSceneConfig::LoadConfigXml();
133 auto strConfig = ScreenSceneConfig::GetStringConfig();
134 std::string bundleName = strConfig[""];
135 std::string abilityName = strConfig[""];
136 std::unique_ptr<ScreenSessionAbilityConnection> abilityConnection_ =
137 std::make_unique<ScreenSessionAbilityConnection>();
138 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
139 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
140 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
141 EXPECT_EQ(ret, false);
142 }
143
144 /**
145 * @tc.name: SnapshotPickerConnectExtension06
146 * @tc.desc: SnapshotPickerConnectExtension func
147 * @tc.type: FUNC
148 */
149 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerConnectExtension06, Function | SmallTest | Level1)
150 {
151 std::string bundleName = "testScreenSnapshotBundleName";
152 std::string abilityName = "testScreenSnapshotAbilityName";
153 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
154 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
155 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
156 EXPECT_EQ(ret, g_isPcDevice);
157 ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
158 EXPECT_EQ(ret, true);
159 }
160
161 /**
162 * @tc.name: GetScreenSnapshotInfo01
163 * @tc.desc: GetScreenSnapshotInfo func
164 * @tc.type: FUNC
165 */
166 HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSnapshotInfo01, Function | SmallTest | Level1)
167 {
168 ScreenSnapshotPickerConnection::GetInstance().abilityConnection_ = nullptr;
169 Media::Rect rect{};
170 ScreenId screenId = SCREEN_ID_INVALID;
171 auto ret = ScreenSnapshotPickerConnection::GetInstance().GetScreenSnapshotInfo(rect, screenId);
172 EXPECT_EQ(ret, -1);
173 }
174
175 /**
176 * @tc.name: GetScreenSnapshotInfo02
177 * @tc.desc: GetScreenSnapshotInfo func
178 * @tc.type: FUNC
179 */
180 HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSnapshotInfo02, Function | SmallTest | Level1)
181 {
182 ScreenSnapshotPickerConnection::GetInstance().abilityConnection_ =
183 std::make_unique<ScreenSessionAbilityConnection>();
184 ScreenSnapshotPickerConnection::GetInstance().abilityConnection_->
185 GetScreenSessionAbilityConnectionStub() = nullptr;
186 Media::Rect rect{};
187 ScreenId screenId;
188 auto ret = ScreenSnapshotPickerConnection::GetInstance().GetScreenSnapshotInfo(rect, screenId);
189 EXPECT_EQ(ret, -1);
190 }
191
192 /**
193 * @tc.name: GetScreenSnapshotInfo03
194 * @tc.desc: GetScreenSnapshotInfo func
195 * @tc.type: FUNC
196 */
197 HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSnapshotInfo03, Function | SmallTest | Level1)
198 {
199 std::string bundleName = "testScreenSnapshotBundleName";
200 std::string abilityName = "testScreenSnapshotAbilityName";
201 ScreenSnapshotPickerConnection::GetInstance().SetBundleName(bundleName);
202 ScreenSnapshotPickerConnection::GetInstance().SetAbilityName(abilityName);
203 auto ret = ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerConnectExtension();
204 EXPECT_EQ(ret, true);
205 Media::Rect rect{};
206 ScreenId screenId;
207 ret = ScreenSnapshotPickerConnection::GetInstance().GetScreenSnapshotInfo(rect, screenId);
208 EXPECT_EQ(ret, true);
209 }
210
211 /**
212 * @tc.name: SnapshotPickerDisconnectExtension01
213 * @tc.desc: SnapshotPickerDisconnectExtension func
214 * @tc.type: FUNC
215 */
216 HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerDisconnectExtension01, Function | SmallTest | Level1)
217 {
218 ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerDisconnectExtension();
219 EXPECT_EQ(ScreenSnapshotPickerConnection::GetInstance().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, g_isPcDevice);
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
280