• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // gtest
17 #include <gtest/gtest.h>
18 #include "window_test_utils.h"
19 #include "wm_common.h"
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace {
26     constexpr uint32_t WAIT_ASYNC_US = 100000;  // 100ms
27 }
28 using Utils = WindowTestUtils;
29 class WindowInputTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     virtual void SetUp() override;
34     virtual void TearDown() override;
35     Utils::TestWindowInfo fullScreenWindow_;
36 };
37 
SetUpTestCase()38 void WindowInputTest::SetUpTestCase()
39 {
40     auto display = DisplayManager::GetInstance().GetDisplayById(0);
41     ASSERT_TRUE((display != nullptr));
42     Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
43     Utils::InitByDisplayRect(displayRect);
44 }
45 
TearDownTestCase()46 void WindowInputTest::TearDownTestCase()
47 {
48 }
49 
SetUp()50 void WindowInputTest::SetUp()
51 {
52     fullScreenWindow_ = {
53         .name = "FullWindow",
54         .rect = Utils::customAppRect_,
55         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
56         .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
57         .needAvoid = false,
58         .parentLimit = false,
59         .parentId = INVALID_WINDOW_ID,
60     };
61 }
62 
TearDown()63 void WindowInputTest::TearDown()
64 {
65 }
66 
67 namespace {
68 /**
69  * @tc.name: SetTouchHotAreas01
70  * @tc.desc: Normal scenario testing for Window#SetTouchHotAreas
71  * @tc.type: FUNC
72  */
73 HWTEST_F(WindowInputTest, SetTouchHotAreas01, Function | MediumTest | Level3)
74 {
75     fullScreenWindow_.name = "window_hot_areas.1";
76     const sptr<Window>& window = Utils::CreateTestWindow(fullScreenWindow_);
77     ASSERT_EQ(WMError::WM_OK, window->Show());
78 
79     std::vector<Rect> requestedTouchHotAreas;
80     window->GetRequestedTouchHotAreas(requestedTouchHotAreas);
81     ASSERT_TRUE(requestedTouchHotAreas.empty());
82 
83     usleep(WAIT_ASYNC_US);
84     Rect windowRect = window->GetRect();
85 
86     std::vector<Rect> rects;
87     uint32_t hotAreasNum = 10;
88     uint32_t hotAreaWidth = windowRect.width_ / hotAreasNum;
89     uint32_t hotAreaHeight = windowRect.height_ / hotAreasNum;
90     for (uint32_t i = 0; i < hotAreasNum; ++i) {
91         rects.emplace_back(Rect{ hotAreaWidth * i, hotAreaHeight * i, hotAreaWidth, hotAreaHeight });
92     }
93     ASSERT_EQ(WMError::WM_OK, window->SetTouchHotAreas(rects));
94     window->GetRequestedTouchHotAreas(requestedTouchHotAreas);
95     ASSERT_EQ(rects.size(), requestedTouchHotAreas.size());
96     for (uint32_t i = 0; i < rects.size(); ++i) {
97         ASSERT_TRUE(rects[i] == requestedTouchHotAreas[i]);
98     }
99 
100     rects.clear();
101     rects.emplace_back(Rect{ 0, 0, hotAreaWidth, hotAreaHeight });
102     ASSERT_EQ(WMError::WM_OK, window->SetTouchHotAreas(rects));
103     window->GetRequestedTouchHotAreas(requestedTouchHotAreas);
104     ASSERT_EQ(rects.size(), requestedTouchHotAreas.size());
105     for (uint32_t i = 0; i < rects.size(); ++i) {
106         ASSERT_TRUE(rects[i] == requestedTouchHotAreas[i]);
107     }
108 
109     rects.clear();
110     ASSERT_EQ(WMError::WM_OK, window->SetTouchHotAreas(rects));
111     window->GetRequestedTouchHotAreas(requestedTouchHotAreas);
112     ASSERT_TRUE(requestedTouchHotAreas.empty());
113 
114     ASSERT_EQ(WMError::WM_OK, window->Destroy());
115 }
116 
117 /**
118  * @tc.name: SetTouchHotAreas02
119  * @tc.desc: Abnormal scenario testing for Window#SetTouchHotAreas
120  * @tc.type: FUNC
121  */
122 HWTEST_F(WindowInputTest, SetTouchHotAreas02, Function | MediumTest | Level3)
123 {
124     fullScreenWindow_.name = "window_hot_areas.2";
125     const sptr<Window>& window = Utils::CreateTestWindow(fullScreenWindow_);
126     ASSERT_EQ(WMError::WM_OK, window->Show());
127 
128     usleep(WAIT_ASYNC_US);
129     Rect windowRect = window->GetRect();
130 
131     std::vector<Rect> rects;
132     /* maximum hot areas: 10, test exceeding maximum hot areas */
133     uint32_t hotAreasNum = 11;
134     uint32_t hotAreaWidth = windowRect.width_ / hotAreasNum;
135     uint32_t hotAreaHeight = windowRect.height_ / hotAreasNum;
136     for (uint32_t i = 0; i < hotAreasNum; ++i) {
137         rects.emplace_back(Rect{ hotAreaWidth * i, hotAreaHeight * i, hotAreaWidth, hotAreaHeight });
138     }
139     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects));
140 
141     rects.clear();
142     rects.emplace_back(Rect{ -1, 0, windowRect.width_ / 2, windowRect.height_ / 2 });
143     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects));
144 
145     rects.clear();
146     rects.emplace_back(Rect{ 0, -1, windowRect.width_ / 2, windowRect.height_ / 2 });
147     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects));
148 
149     rects.clear();
150     rects.emplace_back(Rect{ 0, 0, 0, windowRect.height_ / 2 });
151     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects));
152 
153     rects.clear();
154     rects.emplace_back(Rect{ 0, 0, windowRect.width_ / 2, 0 });
155     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects));
156 
157     rects.clear();
158     rects.emplace_back(Rect{ windowRect.width_, 0, windowRect.width_ / 2, windowRect.height_ / 2 });
159     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects));
160 
161     rects.clear();
162     rects.emplace_back(Rect{ 0, windowRect.height_, windowRect.width_ / 2, windowRect.height_ / 2 });
163     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->SetTouchHotAreas(rects));
164 
165     std::vector<Rect> requestedTouchHotAreas;
166     window->GetRequestedTouchHotAreas(requestedTouchHotAreas);
167     ASSERT_TRUE(requestedTouchHotAreas.empty());
168 
169     ASSERT_EQ(WMError::WM_OK, window->Destroy());
170 }
171 } // namespace
172 } // namespace Rosen
173 } // namespace OHOS