• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <future>
17 #include <optional>
18 #include <vector>
19 
20 #include <unistd.h>
21 
22 #include <gtest/gtest.h>
23 #include "pointer_event.h"
24 #include "securec.h"
25 
26 #include "devicestatus_define.h"
27 #include "devicestatus_errors.h"
28 #include "interaction_manager.h"
29 
30 namespace OHOS {
31 namespace Msdp {
32 namespace DeviceStatus {
33 using namespace testing::ext;
34 namespace {
35 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "InteractionDragDrawingTest" };
36 constexpr uint32_t DEFAULT_ICON_COLOR { 0xFF };
37 constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
38 constexpr int32_t PIXEL_MAP_WIDTH { 300 };
39 constexpr int32_t PIXEL_MAP_HEIGHT { 300 };
40 constexpr int32_t MIDDLE_PIXEL_MAP_WIDTH { 400 };
41 constexpr int32_t MIDDLE_PIXEL_MAP_HEIGHT { 400 };
42 constexpr int32_t MAX_PIXEL_MAP_WIDTH { 600 };
43 constexpr int32_t MAX_PIXEL_MAP_HEIGHT { 600 };
44 constexpr int32_t POINTER_ID { 0 };
45 constexpr int32_t DISPLAY_ID { 0 };
46 constexpr int32_t DISPLAY_X { 50 };
47 constexpr int32_t DISPLAY_Y { 50 };
48 constexpr int32_t DRAG_NUM_ONE { 1 };
49 constexpr int32_t SHADOW_NUM_ONE { 1 };
50 constexpr int32_t SHADOW_NUM_MULTIPLE { 3 };
51 constexpr int32_t SHADOW_NUM_TOO_MUCH { 5 };
52 constexpr int32_t DRAG_NUM_MULTIPLE { 10 };
53 constexpr int32_t INT32_BYTE { 4 };
54 constexpr int32_t PROMISE_WAIT_SPAN_MS { 2000 };
55 constexpr int32_t TIME_WAIT_FOR_UPDATE_DRAG_STYLE { 50 };
56 constexpr int32_t TIME_WAIT_FOR_ANIMATION_END { 1000 };
57 constexpr int32_t WINDOW_ID { -1 };
58 constexpr bool HAS_CANCELED_ANIMATION { true };
59 constexpr bool HAS_CUSTOM_ANIMATION { true };
60 constexpr bool DRAG_WINDOW_VISIBLE { true };
61 const std::string UD_KEY { "Unified data key" };
62 const std::string FILTER_INFO { "Undefined filter info" };
63 const std::string EXTRA_INFO { "Undefined extra info" };
64 } // namespace
65 
66 class InteractionDragDrawingTest : public testing::Test {
67 public:
68     void SetUp();
69     void TearDown();
70     static void SetUpTestCase();
71     static std::shared_ptr<Media::PixelMap> CreatePixelMap(int32_t width, int32_t height);
72     static std::optional<DragData> CreateDragData(int32_t sourceType, int32_t pointerId, int32_t dragNum,
73         bool hasCoordinateCorrected, int32_t shadowNum);
74 };
75 
SetUpTestCase()76 void InteractionDragDrawingTest::SetUpTestCase() {}
77 
SetUp()78 void InteractionDragDrawingTest::SetUp() {}
79 
TearDown()80 void InteractionDragDrawingTest::TearDown()
81 {
82     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
83 }
84 
CreatePixelMap(int32_t width,int32_t height)85 std::shared_ptr<Media::PixelMap> InteractionDragDrawingTest::CreatePixelMap(int32_t width, int32_t height)
86 {
87     CALL_DEBUG_ENTER;
88     if (width <= 0 || width > MAX_PIXEL_MAP_WIDTH || height <= 0 || height > MAX_PIXEL_MAP_HEIGHT) {
89         FI_HILOGE("Size invalid, height:%{public}d, width:%{public}d", height, width);
90         return nullptr;
91     }
92     Media::InitializationOptions opts;
93     opts.size.height = height;
94     opts.size.width = width;
95     opts.pixelFormat = Media::PixelFormat::BGRA_8888;
96     opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
97     opts.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE;
98 
99     int32_t colorLen = width * height;
100     uint32_t *pixelColors = new (std::nothrow) uint32_t[colorLen];
101     CHKPP(pixelColors);
102     int32_t colorByteCount = colorLen * INT32_BYTE;
103     errno_t ret = memset_s(pixelColors, colorByteCount, DEFAULT_ICON_COLOR, colorByteCount);
104     if (ret != EOK) {
105         FI_HILOGE("memset_s failed");
106         delete[] pixelColors;
107         return nullptr;
108     }
109     std::shared_ptr<Media::PixelMap> pixelMap = Media::PixelMap::Create(pixelColors, colorLen, opts);
110     if (pixelMap == nullptr) {
111         FI_HILOGE("Create pixelMap failed");
112         delete[] pixelColors;
113         return nullptr;
114     }
115     delete[] pixelColors;
116     return pixelMap;
117 }
118 
119 class TestStartDragListener : public IStartDragListener {
120 public:
TestStartDragListener(std::function<void (const DragNotifyMsg &)> function)121     explicit TestStartDragListener(std::function<void(const DragNotifyMsg&)> function) : function_(function) { }
OnDragEndMessage(const DragNotifyMsg & msg)122     void OnDragEndMessage(const DragNotifyMsg &msg) override
123     {
124         FI_HILOGD("DisplayX:%{public}d, displayY:%{public}d, targetPid:%{public}d, result:%{public}d",
125             msg.displayX, msg.displayY, msg.targetPid, static_cast<int32_t>(msg.result));
126         if (function_ != nullptr) {
127             function_(msg);
128         }
129         FI_HILOGD("Test OnDragEndMessage");
130     }
131 
OnHideIconMessage()132     void OnHideIconMessage() override
133     {
134         FI_HILOGD("Test OnHideIconMessage");
135     }
136 private:
137     std::function<void(const DragNotifyMsg&)> function_;
138 };
139 
CreateDragData(int32_t sourceType,int32_t pointerId,int32_t dragNum,bool hasCoordinateCorrected,int32_t shadowNum)140 std::optional<DragData> InteractionDragDrawingTest::CreateDragData(int32_t sourceType,
141     int32_t pointerId, int32_t dragNum, bool hasCoordinateCorrected, int32_t shadowNum)
142 {
143     CALL_DEBUG_ENTER;
144     DragData dragData;
145     for (int32_t i = 0; i < shadowNum; i++) {
146         std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT);
147         if (pixelMap == nullptr) {
148             FI_HILOGE("CreatePixelMap failed");
149             return std::nullopt;
150         }
151         dragData.shadowInfos.push_back({ pixelMap, 0, 0 });
152     }
153     dragData.buffer = std::vector<uint8_t>(MAX_BUFFER_SIZE, 0);
154     dragData.udKey = UD_KEY;
155     dragData.extraInfo = FILTER_INFO;
156     dragData.extraInfo = EXTRA_INFO;
157     dragData.sourceType = sourceType;
158     dragData.pointerId = pointerId;
159     dragData.dragNum = dragNum;
160     dragData.displayX = DISPLAY_X;
161     dragData.displayY = DISPLAY_Y;
162     dragData.displayId = DISPLAY_ID;
163     dragData.hasCanceledAnimation = HAS_CANCELED_ANIMATION;
164     dragData.hasCoordinateCorrected = hasCoordinateCorrected;
165     return dragData;
166 }
167 
168 /**
169  * @tc.name: InteractionDragDrawingTest_Mouse_DragNum_One
170  * @tc.desc: Drag Drawing
171  * @tc.type: FUNC
172  * @tc.require:
173  */
174 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_DragNum_One, TestSize.Level1)
175 {
176     CALL_TEST_DEBUG;
177     std::optional<DragData> dragData = CreateDragData(
178         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
179     ASSERT_TRUE(dragData);
180     std::promise<bool> promiseFlag;
181     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0202(const DragNotifyMsg &notifyMessage) 182     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
183         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
184             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
185         promiseFlag.set_value(true);
186     };
187     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
188         std::make_shared<TestStartDragListener>(callback));
189     ASSERT_EQ(ret, RET_OK);
190     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
191     ASSERT_EQ(ret, RET_OK);
192     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::DEFAULT);
193     ASSERT_EQ(ret, RET_OK);
194     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
195     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
196     ASSERT_EQ(ret, RET_OK);
197     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
198     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::FORBIDDEN);
199     ASSERT_EQ(ret, RET_OK);
200     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
201     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::MOVE);
202     ASSERT_EQ(ret, RET_OK);
203     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
204     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::DEFAULT);
205     ASSERT_EQ(ret, RET_OK);
206     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
207     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
208     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
209     ASSERT_EQ(ret, RET_OK);
210     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
211 }
212 
213 /**
214  * @tc.name: InteractionDragDrawingTest_Mouse_DragNum_Multiple
215  * @tc.desc: Drag Drawing
216  * @tc.type: FUNC
217  * @tc.require:
218  */
219 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_DragNum_Multiple, TestSize.Level1)
220 {
221     CALL_TEST_DEBUG;
222     std::promise<bool> promiseFlag;
223     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0302(const DragNotifyMsg &notifyMessage) 224     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
225         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d",
226             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result);
227         promiseFlag.set_value(true);
228     };
229     std::optional<DragData> dragData = CreateDragData(
230         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_MULTIPLE, false, SHADOW_NUM_ONE);
231     ASSERT_TRUE(dragData);
232     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
233         std::make_shared<TestStartDragListener>(callback));
234     ASSERT_EQ(ret, RET_OK);
235     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
236     ASSERT_EQ(ret, RET_OK);
237     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
238     ASSERT_EQ(ret, RET_OK);
239     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
240     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::FORBIDDEN);
241     ASSERT_EQ(ret, RET_OK);
242     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
243     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::MOVE);
244     ASSERT_EQ(ret, RET_OK);
245     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
246     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::DEFAULT);
247     ASSERT_EQ(ret, RET_OK);
248     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
249     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::MOVE);
250     ASSERT_EQ(ret, RET_OK);
251     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
252     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
253     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
254     ASSERT_EQ(ret, RET_OK);
255     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
256 }
257 
258 /**
259  * @tc.name: InteractionDragDrawingTest_Touchscreen_DragNum_One
260  * @tc.desc: Drag Drawing
261  * @tc.type: FUNC
262  * @tc.require:
263  */
264 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_DragNum_One, TestSize.Level1)
265 {
266     CALL_TEST_DEBUG;
267     std::promise<bool> promiseFlag;
268     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0402(const DragNotifyMsg &notifyMessage) 269     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
270         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, target:%{public}d, result:%{public}d",
271             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.targetPid, notifyMessage.result);
272         promiseFlag.set_value(true);
273     };
274     std::optional<DragData> dragData = CreateDragData(
275         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
276     ASSERT_TRUE(dragData);
277     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
278         std::make_shared<TestStartDragListener>(callback));
279     ASSERT_EQ(ret, RET_OK);
280     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
281     ASSERT_EQ(ret, RET_OK);
282     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
283     ASSERT_EQ(ret, RET_OK);
284     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
285     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::DEFAULT);
286     ASSERT_EQ(ret, RET_OK);
287     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
288     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::MOVE);
289     ASSERT_EQ(ret, RET_OK);
290     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
291     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::FORBIDDEN);
292     ASSERT_EQ(ret, RET_OK);
293     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
294     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
295     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
296     ASSERT_EQ(ret, RET_OK);
297     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
298 }
299 
300 /**
301  * @tc.name: InteractionDragDrawingTest_Touchscreen_DragNum_Multiple
302  * @tc.desc: Drag Drawing
303  * @tc.type: FUNC
304  * @tc.require:
305  */
306 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_DragNum_Multiple, TestSize.Level1)
307 {
308     CALL_TEST_DEBUG;
309     std::optional<DragData> dragData = CreateDragData(
310         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_MULTIPLE, false, SHADOW_NUM_ONE);
311     ASSERT_TRUE(dragData);
312     std::promise<bool> promiseFlag;
313     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0502(const DragNotifyMsg &notifyMessage) 314     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
315         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d",
316             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result);
317         promiseFlag.set_value(true);
318     };
319     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
320         std::make_shared<TestStartDragListener>(callback));
321     ASSERT_EQ(ret, RET_OK);
322     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
323     ASSERT_EQ(ret, RET_OK);
324     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
325     ASSERT_EQ(ret, RET_OK);
326     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
327     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::DEFAULT);
328     ASSERT_EQ(ret, RET_OK);
329     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
330     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::FORBIDDEN);
331     ASSERT_EQ(ret, RET_OK);
332     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
333     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::MOVE);
334     ASSERT_EQ(ret, RET_OK);
335     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_UPDATE_DRAG_STYLE));
336     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
337     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
338     ASSERT_EQ(ret, RET_OK);
339     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
340 }
341 
342 /**
343  * @tc.name: InteractionDragDrawingTest_UpdateShadowPic
344  * @tc.desc: Drag Drawing
345  * @tc.type: FUNC
346  * @tc.require:
347  */
348 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_UpdateShadowPic, TestSize.Level1)
349 {
350     CALL_TEST_DEBUG;
351     std::promise<bool> promiseFlag;
352     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0602(const DragNotifyMsg &notifyMessage) 353     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
354         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
355             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
356         promiseFlag.set_value(true);
357     };
358     std::optional<DragData> dragData = CreateDragData(
359         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
360     ASSERT_TRUE(dragData);
361     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
362         std::make_shared<TestStartDragListener>(callback));
363     ASSERT_EQ(ret, RET_OK);
364     std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMap(MIDDLE_PIXEL_MAP_WIDTH, MIDDLE_PIXEL_MAP_HEIGHT);
365     ASSERT_NE(pixelMap, nullptr);
366     ShadowInfo shadowInfo = { pixelMap, 0, 0 };
367     ret = InteractionManager::GetInstance()->UpdateShadowPic(shadowInfo);
368     ASSERT_EQ(ret, RET_OK);
369     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
370     ASSERT_EQ(ret, RET_OK);
371     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
372     ASSERT_EQ(ret, RET_OK);
373     DragDropResult dropResult { DragResult::DRAG_FAIL, HAS_CUSTOM_ANIMATION, WINDOW_ID };
374     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
375     ASSERT_EQ(ret, RET_OK);
376     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
377     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_ANIMATION_END));
378 }
379 
380 /**
381  * @tc.name: InteractionDragDrawingTest_Mouse_Animation
382  * @tc.desc: Drag Drawing
383  * @tc.type: FUNC
384  * @tc.require:
385  */
386 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_Animation, TestSize.Level1)
387 {
388     CALL_TEST_DEBUG;
389     std::promise<bool> promiseFlag;
390     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0702(const DragNotifyMsg &notifyMessage) 391     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
392         FI_HILOGD("result:%{public}d, target:%{public}d, displayX:%{public}d, displayY:%{public}d",
393             notifyMessage.result, notifyMessage.targetPid, notifyMessage.displayX, notifyMessage.displayY);
394         promiseFlag.set_value(true);
395     };
396     std::optional<DragData> dragData = CreateDragData(
397         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
398     ASSERT_TRUE(dragData);
399     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
400         std::make_shared<TestStartDragListener>(callback));
401     ASSERT_EQ(ret, RET_OK);
402     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
403     ASSERT_EQ(ret, RET_OK);
404     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
405     ASSERT_EQ(ret, RET_OK);
406     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
407     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
408     ASSERT_EQ(ret, RET_OK);
409     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
410     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_ANIMATION_END));
411 }
412 
413 /**
414  * @tc.name: InteractionDragDrawingTest_Touchscreen_Animation
415  * @tc.desc: Drag Drawing
416  * @tc.type: FUNC
417  * @tc.require:
418  */
419 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Animation, TestSize.Level1)
420 {
421     CALL_TEST_DEBUG;
422     std::promise<bool> promiseFlag;
423     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0802(const DragNotifyMsg &notifyMessage) 424     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
425         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, target:%{public}d, result:%{public}d",
426             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.targetPid, notifyMessage.result);
427         promiseFlag.set_value(true);
428     };
429     std::optional<DragData> dragData = CreateDragData(
430         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
431     ASSERT_TRUE(dragData);
432     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
433         std::make_shared<TestStartDragListener>(callback));
434     ASSERT_EQ(ret, RET_OK);
435     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
436     ASSERT_EQ(ret, RET_OK);
437     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
438     ASSERT_EQ(ret, RET_OK);
439     DragDropResult dropResult { DragResult::DRAG_FAIL, HAS_CUSTOM_ANIMATION, WINDOW_ID };
440     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
441     ASSERT_EQ(ret, RET_OK);
442     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
443 }
444 
445 /**
446  * @tc.name: InteractionDragDrawingTest_Multiple_Shadow
447  * @tc.desc: Drag Drawing
448  * @tc.type: FUNC
449  * @tc.require:
450  */
451 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_ONE_Shadow, TestSize.Level1)
452 {
453     CALL_TEST_DEBUG;
454     std::promise<bool> promiseFlag;
455     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0902(const DragNotifyMsg &notifyMessage) 456     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
457         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
458             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
459         promiseFlag.set_value(true);
460     };
461     std::optional<DragData> dragData = CreateDragData(
462         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
463     ASSERT_TRUE(dragData);
464     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
465         std::make_shared<TestStartDragListener>(callback));
466     ASSERT_EQ(ret, RET_OK);
467     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
468     ASSERT_EQ(ret, RET_OK);
469     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
470     ASSERT_EQ(ret, RET_OK);
471     DragDropResult dropResult { DragResult::DRAG_FAIL, HAS_CUSTOM_ANIMATION, WINDOW_ID };
472     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
473     ASSERT_EQ(ret, RET_OK);
474     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
475 }
476 
477 /**
478  * @tc.name: InteractionDragDrawingTest_Multiple_Shadow
479  * @tc.desc: Drag Drawing
480  * @tc.type: FUNC
481  * @tc.require:
482  */
483 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Multiple_Shadow, TestSize.Level1)
484 {
485     CALL_TEST_DEBUG;
486     std::promise<bool> promiseFlag;
487     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0a02(const DragNotifyMsg &notifyMessage) 488     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
489         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
490             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
491         promiseFlag.set_value(true);
492     };
493     std::optional<DragData> dragData = CreateDragData(
494         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_MULTIPLE);
495     ASSERT_TRUE(dragData);
496     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
497         std::make_shared<TestStartDragListener>(callback));
498     ASSERT_EQ(ret, RET_OK);
499     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
500     ASSERT_EQ(ret, RET_OK);
501     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
502     ASSERT_EQ(ret, RET_OK);
503     DragDropResult dropResult { DragResult::DRAG_FAIL, HAS_CUSTOM_ANIMATION, WINDOW_ID };
504     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
505     ASSERT_EQ(ret, RET_OK);
506     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
507 }
508 
509 /**
510  * @tc.name: InteractionDragDrawingTest_Multiple_Shadow
511  * @tc.desc: Drag Drawing
512  * @tc.type: FUNC
513  * @tc.require:
514  */
515 HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Too_Much_Shadow, TestSize.Level1)
516 {
517     CALL_TEST_DEBUG;
518     std::promise<bool> promiseFlag;
519     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0b02(const DragNotifyMsg &notifyMessage) 520     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
521         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
522             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
523         promiseFlag.set_value(true);
524     };
525     std::optional<DragData> dragData = CreateDragData(
526         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_TOO_MUCH);
527     ASSERT_TRUE(dragData);
528     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
529         std::make_shared<TestStartDragListener>(callback));
530     ASSERT_EQ(ret, RET_OK);
531     ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE);
532     ASSERT_EQ(ret, RET_OK);
533     ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY);
534     ASSERT_EQ(ret, RET_OK);
535     DragDropResult dropResult { DragResult::DRAG_FAIL, HAS_CUSTOM_ANIMATION, WINDOW_ID };
536     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
537     ASSERT_EQ(ret, RET_OK);
538     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
539 }
540 
541 /**
542  * @tc.name: EnterTextEditorArea001
543  * @tc.desc: normal test for pixelMap 8dp bit movement effect
544  * @tc.type: FUNC
545  * @tc.require:
546  */
547 HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea001, TestSize.Level1)
548 {
549     CALL_TEST_DEBUG;
550     std::promise<bool> promiseFlag;
551     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0c02(const DragNotifyMsg &notifyMessage) 552     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
553         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
554             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
555         promiseFlag.set_value(true);
556     };
557     std::optional<DragData> dragData = CreateDragData(
558         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
559     ASSERT_TRUE(dragData);
560     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
561         std::make_shared<TestStartDragListener>(callback));
562     ASSERT_EQ(ret, RET_OK);
563     ret = InteractionManager::GetInstance()->EnterTextEditorArea(true);
564     EXPECT_EQ(ret, RET_OK);
565     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_ANIMATION_END));
566     ret = InteractionManager::GetInstance()->EnterTextEditorArea(false);
567     EXPECT_EQ(ret, RET_OK);
568     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
569     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
570     ASSERT_EQ(ret, RET_OK);
571     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
572 }
573 
574 /**
575  * @tc.name: EnterTextEditorArea002
576  * @tc.desc: abnormal test for pixelMap 8dp bit movement effect
577  * @tc.type: FUNC
578  * @tc.require:
579  */
580 HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea002, TestSize.Level1)
581 {
582     CALL_TEST_DEBUG;
583     std::promise<bool> promiseFlag;
584     std::future<bool> futureFlag = promiseFlag.get_future();
__anond932c23b0d02(const DragNotifyMsg &notifyMessage) 585     auto callback = [&promiseFlag](const DragNotifyMsg &notifyMessage) {
586         FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
587             notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
588         promiseFlag.set_value(true);
589     };
590     std::optional<DragData> dragData = CreateDragData(
591         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
592     ASSERT_TRUE(dragData);
593     int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
594         std::make_shared<TestStartDragListener>(callback));
595     ASSERT_EQ(ret, RET_OK);
596     ret = InteractionManager::GetInstance()->EnterTextEditorArea(false);
597     EXPECT_EQ(ret, RET_ERR);
598     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
599     ret = InteractionManager::GetInstance()->StopDrag(dropResult);
600     ASSERT_EQ(ret, RET_OK);
601     ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
602 }
603 
604 /**
605  * @tc.name: EnterTextEditorArea003
606  * @tc.desc: abnormal test for pixelMap 8dp bit movement effect
607  * @tc.type: FUNC
608  * @tc.require:
609  */
610 HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea003, TestSize.Level1)
611 {
612     CALL_TEST_DEBUG;
613     std::optional<DragData> dragData = CreateDragData(
614         MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, true, SHADOW_NUM_ONE);
615     ASSERT_TRUE(dragData);
616     int32_t ret = InteractionManager::GetInstance()->EnterTextEditorArea(true);
617     EXPECT_EQ(ret, RET_ERR);
618 }
619 } // namespace DeviceStatus
620 } // namespace Msdp
621 } // namespace OHOS
622