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     ASSERT_EQ(true, true);
81 }
82 
83 /**
84  * @tc.name: PlaceholderWindowListener01
85  * @tc.desc: test PlaceholderWindowListener OnTouchOutside/AfterUnfocused
86  * @tc.type: FUNC
87  */
88 HWTEST_F(WindowInnerWindowTest, PlaceholderWindowListener01, Function | SmallTest | Level2)
89 {
90     windowListener_->OnTouchOutside();
91     windowListener_->AfterUnfocused();
92 
93     ASSERT_EQ(true, true);
94 }
95 
96 /**
97  * @tc.name: PlaceholderInputEventConsumer01
98  * @tc.desc: test PlaceholderInputEventConsumer OnInputEvent
99  * @tc.type: FUNC
100  */
101 HWTEST_F(WindowInnerWindowTest, PlaceholderInputEventConsumer01, Function | SmallTest | Level2)
102 {
103     std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
104     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
105     std::shared_ptr<MMI::AxisEvent> axisEvent = nullptr;
106 
107     inputEventConsumer_->OnInputEvent(keyEvent);
108     inputEventConsumer_->OnInputEvent(pointerEvent);
109     inputEventConsumer_->OnInputEvent(axisEvent);
110 
111     ASSERT_EQ(true, true);
112 }
113 }
114 }
115 }
116