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
__anon4ff414750302(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 * @tc.name: GetDisplayDirectionForMmi
74 * @tc.desc: get display direction
75 * @tc.type: FUNC
76 */
77 HWTEST_F(InputWindowMonitorTest, GetDisplayDirectionForMmi01, Function | SmallTest | Level2)
78 {
79 Rotation rotate = Rotation::ROTATION_0;
80 ASSERT_EQ(MMI::DIRECTION0, input_monitor_->GetDisplayDirectionForMmi(rotate));
81 }
82 /**
83 * @tc.name: UpdateDisplayInfo
84 * @tc.desc: update displayinfo
85 * @tc.type: FUNC
86 */
87 HWTEST_F(InputWindowMonitorTest, UpdateDisplayInfo01, Function | SmallTest | Level2)
88 {
89 std::vector<sptr<DisplayInfo>> displayInfos;
90 std::vector<MMI::DisplayInfo> displayInfoVector;
91 displayInfos.clear();
92 displayInfoVector.clear();
93 sptr<DisplayInfo> displayinfo = nullptr;
94 displayInfos.emplace_back(displayinfo);
95 input_monitor_->UpdateDisplayInfo(displayInfos, displayInfoVector);
96 ASSERT_EQ(0, displayInfoVector.size());
97 }
98
99 /**
100 * @tc.name: UpdateDisplayInfo02
101 * @tc.desc: UpdateDisplayInfo
102 * @tc.type: FUNC
103 */
104 HWTEST_F(InputWindowMonitorTest, UpdateDisplayInfo02, Function | SmallTest | Level2)
105 {
106 std::vector<sptr<DisplayInfo>> displayInfos;
107 std::vector<MMI::DisplayInfo> displayInfoVector;
108 displayInfos.clear();
109 displayInfoVector.clear();
110 sptr<DisplayInfo> displayInfo = new (std::nothrow) DisplayInfo();
111 displayInfos.emplace_back(displayInfo);
112 input_monitor_->UpdateDisplayInfo(displayInfos, displayInfoVector);
113 displayInfo->waterfallDisplayCompressionStatus_ = true;
114 ASSERT_NE(0, displayInfoVector.size());
115 }
116
117 /**
118 * @tc.name: TransformWindowRects
119 * @tc.desc: TransformWindowRects
120 * @tc.type: FUNC
121 */
122 HWTEST_F(InputWindowMonitorTest, TransformWindowRects, Function | SmallTest | Level2)
123 {
124 sptr<WindowNode> windowNode = new WindowNode();
125 Rect areaRect;
126 std::vector<Rect> touchHotAreas;
127 std::vector<Rect> pointerHotAreas;
128 input_monitor_->TransformWindowRects(windowNode, areaRect, touchHotAreas, pointerHotAreas);
129 WindowProperty windowProperty;
130 auto result = windowProperty.isNeedComputerTransform();
131 ASSERT_EQ(result, false);
132 }
133
134 /**
135 * @tc.name: GetDisplayDirectionForMmi02
136 * @tc.desc: get display direction
137 * @tc.type: FUNC
138 */
139 HWTEST_F(InputWindowMonitorTest, GetDisplayDirectionForMmi02, Function | SmallTest | Level2)
140 {
141 MMI::Direction direction = MMI::DIRECTION0;
142 Rotation rotate = Rotation::ROTATION_90;
143 rotate = Rotation::ROTATION_180;
144 EXPECT_NE(direction, MMI::DIRECTION180);
145 rotate = Rotation::ROTATION_270;
146 EXPECT_NE(direction, MMI::DIRECTION270);
147 ASSERT_NE(MMI::DIRECTION0, input_monitor_->GetDisplayDirectionForMmi(rotate));
148 }
149 }
150 }
151 }
152