1 /*
2 * Copyright (c) 2022 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 "input_window_monitor.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 class InputWindowMonitorTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28 void SetUp() override;
29 void TearDown() override;
30
31 sptr<WindowRoot> root_;
32 sptr<InputWindowMonitor> input_monitor_;
33 };
34
SetUpTestCase()35 void InputWindowMonitorTest::SetUpTestCase()
36 {
37 }
38
TearDownTestCase()39 void InputWindowMonitorTest::TearDownTestCase()
40 {
41 }
42
SetUp()43 void InputWindowMonitorTest::SetUp()
44 {
45 root_ = new WindowRoot([](Event event, const sptr<IRemoteObject>& remoteObject) {});
46 input_monitor_ = new InputWindowMonitor(root_);
47 }
48
TearDown()49 void InputWindowMonitorTest::TearDown()
50 {
51 root_ = nullptr;
52 input_monitor_->InputWindowMonitor::~InputWindowMonitor();
53 }
54
55 namespace {
56 /**
57 * @tc.name: UpdateInputWindow
58 * @tc.desc: Update Input Window
59 * @tc.type: FUNC
60 */
61 HWTEST_F(InputWindowMonitorTest, UpdateInputWindow01, Function | SmallTest | Level2)
62 {
63 input_monitor_->windowRoot_ = nullptr;
64 input_monitor_->UpdateInputWindow(0);
65 ASSERT_EQ(nullptr, input_monitor_->windowRoot_);
66
__anon4d79757d0302(Event event, const sptr<IRemoteObject>& remoteObject) 67 input_monitor_->windowRoot_ = new WindowRoot([](Event event, const sptr<IRemoteObject>& remoteObject) {});
68 input_monitor_->windowRoot_->windowNodeMap_.insert(std::make_pair(0, nullptr));
69 input_monitor_->UpdateInputWindow(0);
70 ASSERT_EQ(nullptr, input_monitor_->windowRoot_->windowNodeMap_[0]);
71 }
72
73 /**
74 * @tc.name: GetDisplayDirectionForMmi
75 * @tc.desc: get display direction
76 * @tc.type: FUNC
77 */
78 HWTEST_F(InputWindowMonitorTest, GetDisplayDirectionForMmi01, Function | SmallTest | Level2)
79 {
80 Rotation rotate = Rotation::ROTATION_0;
81 ASSERT_EQ(MMI::DIRECTION0, input_monitor_->GetDisplayDirectionForMmi(rotate));
82 }
83
84 /**
85 * @tc.name: UpdateDisplayInfo
86 * @tc.desc: update displayinfo
87 * @tc.type: FUNC
88 */
89 HWTEST_F(InputWindowMonitorTest, UpdateDisplayInfo01, Function | SmallTest | Level2)
90 {
91 std::vector<sptr<DisplayInfo>> displayInfos;
92 std::vector<MMI::DisplayInfo> displayInfoVector;
93 displayInfos.clear();
94 displayInfoVector.clear();
95 sptr<DisplayInfo> displayinfo = nullptr;
96 displayInfos.emplace_back(displayinfo);
97 input_monitor_->UpdateDisplayInfo(displayInfos, displayInfoVector);
98 ASSERT_EQ(0, displayInfoVector.size());
99 }
100
101 /**
102 * @tc.name: UpdateDisplayInfo02
103 * @tc.desc: UpdateDisplayInfo
104 * @tc.type: FUNC
105 */
106 HWTEST_F(InputWindowMonitorTest, UpdateDisplayInfo02, Function | SmallTest | Level2)
107 {
108 std::vector<sptr<DisplayInfo>> displayInfos;
109 std::vector<MMI::DisplayInfo> displayInfoVector;
110 displayInfos.clear();
111 displayInfoVector.clear();
112 sptr<DisplayInfo> displayInfo = new (std::nothrow) DisplayInfo();
113 displayInfos.emplace_back(displayInfo);
114 input_monitor_->UpdateDisplayInfo(displayInfos, displayInfoVector);
115 displayInfo->waterfallDisplayCompressionStatus_ = true;
116 ASSERT_NE(0, displayInfoVector.size());
117 }
118
119 /**
120 * @tc.name: TransformWindowRects
121 * @tc.desc: TransformWindowRects
122 * @tc.type: FUNC
123 */
124 HWTEST_F(InputWindowMonitorTest, TransformWindowRects, Function | SmallTest | Level2)
125 {
126 sptr<WindowNode> windowNode = new WindowNode();
127 Rect areaRect;
128 std::vector<Rect> touchHotAreas;
129 std::vector<Rect> pointerHotAreas;
130 input_monitor_->TransformWindowRects(windowNode, areaRect, touchHotAreas, pointerHotAreas);
131 WindowProperty windowProperty;
132 auto result = windowProperty.isNeedComputerTransform();
133 ASSERT_EQ(result, false);
134 }
135
136 /**
137 * @tc.name: GetDisplayDirectionForMmi02
138 * @tc.desc: get display direction
139 * @tc.type: FUNC
140 */
141 HWTEST_F(InputWindowMonitorTest, GetDisplayDirectionForMmi02, Function | SmallTest | Level2)
142 {
143 MMI::Direction direction = MMI::DIRECTION0;
144 Rotation rotate = Rotation::ROTATION_90;
145 rotate = Rotation::ROTATION_180;
146 EXPECT_NE(direction, MMI::DIRECTION180);
147 rotate = Rotation::ROTATION_270;
148 EXPECT_NE(direction, MMI::DIRECTION270);
149 ASSERT_NE(MMI::DIRECTION0, input_monitor_->GetDisplayDirectionForMmi(rotate));
150 }
151 }
152 }
153 }
154