• 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 <cstdio>
17 #include <fstream>
18 #include <gtest/gtest.h>
19 
20 #include "mmi_log.h"
21 #include "pointer_event.h"
22 #include "touch_drawing_manager.h"
23 #include "window_info.h"
24 
25 namespace OHOS {
26 namespace MMI {
27 namespace {
28 using namespace testing::ext;
29 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "TouchDrawingManagerTest" };
30 } // namespace
31 class TouchDrawingManagerTest : public testing::Test {
32 public:
SetUpTestCase(void)33     static void SetUpTestCase(void) {};
TearDownTestCase(void)34     static void TearDownTestCase(void) {};
SetUp(void)35     void SetUp(void)
36     {
37         // 创建displayInfo_
38         DisplayInfo info;
39         info.id = 1;
40         info.x =1;
41         info.y = 1;
42         info.width = 1;
43         info.height = 1;
44         int32_t displayDpi = 240;
45         info.dpi = displayDpi;
46         info.name = "xx";
47         info.uniq = "xx";
48         info.direction = DIRECTION0;
49         TOUCH_DRAWING_MANAGER->UpdateDisplayInfo(info);
50     } // void SetUp(void)
51 };
52 
53 /**
54  * @tc.name: TouchDrawingManagerTest_TouchDrawHandler_001
55  * @tc.desc: Test TouchDrawHandler
56  * @tc.type: Function
57  * @tc.require:
58  */
59 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_TouchDrawHandler_001, TestSize.Level1)
60 {
61     CALL_TEST_DEBUG;
62     auto pointerEvent = PointerEvent::Create();
63     EXPECT_NE(pointerEvent, nullptr);
64 
65     PointerEvent::PointerItem item;
66     item.SetPointerId(0);
67     int32_t displayX = 100;
68     int32_t displayY = 100;
69     item.SetDisplayX(displayX);
70     item.SetDisplayY(displayY);
71     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
72     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
73     pointerEvent->SetTargetDisplayId(0);
74     pointerEvent->SetPointerId(0);
75     pointerEvent->AddPointerItem(item);
76     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MANAGER->TouchDrawHandler(pointerEvent));
77 }
78 
79 /**
80  * @tc.name: TouchDrawingManagerTest_TouchDrawHandler_002
81  * @tc.desc: Test TouchDrawHandler
82  * @tc.type: Function
83  * @tc.require:
84  */
85 HWTEST_F(TouchDrawingManagerTest, TouchDrawingManagerTest_TouchDrawHandler_002, TestSize.Level1)
86 {
87     CALL_TEST_DEBUG;
88     auto pointerEvent = PointerEvent::Create();
89     EXPECT_NE(pointerEvent, nullptr);
90 
91     PointerEvent::PointerItem item;
92     item.SetPointerId(0);
93     int32_t displayX = 200;
94     int32_t displayY = 200;
95     item.SetDisplayX(displayX);
96     item.SetDisplayY(displayY);
97     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
98     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
99     pointerEvent->SetTargetDisplayId(0);
100     pointerEvent->SetPointerId(0);
101     pointerEvent->AddPointerItem(item);
102     EXPECT_NO_FATAL_FAILURE(TOUCH_DRAWING_MANAGER->TouchDrawHandler(pointerEvent));
103 }
104 } // namespace MMI
105 } // namespace OHOS
106