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 "inner_window.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21 namespace OHOS {
22 namespace Rosen {
23 class WindowInnerWindowTest : public testing::Test {
24 public:
25 static void SetUpTestCase();
26 static void TearDownTestCase();
27 void SetUp() override;
28 void TearDown() override;
29 sptr<PlaceHolderWindow> holderWindow_;
30 sptr<PlaceholderWindowListener> windowListener_;
31 std::shared_ptr<IInputEventConsumer> inputEventConsumer_;
32 };
33
SetUpTestCase()34 void WindowInnerWindowTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void WindowInnerWindowTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void WindowInnerWindowTest::SetUp()
43 {
44 holderWindow_ = new PlaceHolderWindow();
45 windowListener_ = new PlaceholderWindowListener();
46 inputEventConsumer_ = std::make_shared<PlaceholderInputEventConsumer> ();
47 }
48
TearDown()49 void WindowInnerWindowTest::TearDown()
50 {
51 }
52
53 namespace {
54 /**
55 * @tc.name: PlaceHolderWindow01
56 * @tc.desc: test PlaceHolderWindow create/destroy
57 * @tc.type: FUNC
58 */
59 HWTEST_F(WindowInnerWindowTest, CreatePlaceHolderWindow01, Function | SmallTest | Level2)
60 {
61 Rect rect = { 100, 100, 200, 200 };
62 holderWindow_->Create("test01", 0, rect, WindowMode::WINDOW_MODE_FULLSCREEN);
63 holderWindow_->Destroy();
64
65 rect = { 100, 100, 200, 200 };
66 holderWindow_->Create("test02", 0, rect, WindowMode::WINDOW_MODE_FULLSCREEN);
67 holderWindow_->Create("test02", 0, rect, WindowMode::WINDOW_MODE_FULLSCREEN);
68 holderWindow_->Destroy();
69
70 rect = { 100, 100, 200, 200 };
71 holderWindow_->Create("", 0, rect, WindowMode::WINDOW_MODE_FULLSCREEN);
72 holderWindow_->Destroy();
73
74 rect = { 0, 0, 0, 0 };
75 holderWindow_->Create("test03", 0, rect, WindowMode::WINDOW_MODE_FULLSCREEN);
76 holderWindow_->Destroy();
77
78 holderWindow_->Destroy();
79
80 std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
81 auto ret = inputEventConsumer_->OnInputEvent(keyEvent);
82 ASSERT_EQ(ret, true);
83 }
84
85 /**
86 * @tc.name: PlaceholderWindowListener01
87 * @tc.desc: test PlaceholderWindowListener OnTouchOutside/AfterUnfocused
88 * @tc.type: FUNC
89 */
90 HWTEST_F(WindowInnerWindowTest, PlaceholderWindowListener01, Function | SmallTest | Level2)
91 {
92 windowListener_->OnTouchOutside();
93 windowListener_->AfterUnfocused();
94
95 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
96 auto ret = inputEventConsumer_->OnInputEvent(pointerEvent);
97 ASSERT_EQ(ret, true);
98 }
99
100 /**
101 * @tc.name: PlaceholderInputEventConsumer01
102 * @tc.desc: test PlaceholderInputEventConsumer OnInputEvent
103 * @tc.type: FUNC
104 */
105 HWTEST_F(WindowInnerWindowTest, PlaceholderInputEventConsumer01, Function | SmallTest | Level2)
106 {
107 std::shared_ptr<MMI::AxisEvent> axisEvent = nullptr;
108 auto ret = inputEventConsumer_->OnInputEvent(axisEvent);
109 ASSERT_EQ(ret, false);
110 }
111 }
112 }
113 }
114