• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "window_impl.h"
18 #include "window_input_channel.h"
19 #include "mock_window_adapter.h"
20 #include "singleton_mocker.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 using WindowMocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
28 class WindowInputChannelTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     virtual void SetUp() override;
33     virtual void TearDown() override;
34     sptr<WindowImpl> window_;
35 };
SetUpTestCase()36 void WindowInputChannelTest::SetUpTestCase()
37 {
38 }
39 
TearDownTestCase()40 void WindowInputChannelTest::TearDownTestCase()
41 {
42 }
43 
SetUp()44 void WindowInputChannelTest::SetUp()
45 {
46     sptr<WindowOption> option = new WindowOption();
47     option->SetWindowName("window");
48     window_ = new WindowImpl(option);
49     window_->Create(INVALID_WINDOW_ID);
50 }
51 
TearDown()52 void WindowInputChannelTest::TearDown()
53 {
54     window_->Destroy();
55     window_ = nullptr;
56 }
57 
58 namespace {
59 /**
60  * @tc.name: HandlePointerEvent
61  * @tc.desc: consume pointer event when receive callback from input
62  * @tc.type: FUNC
63  */
64 HWTEST_F(WindowInputChannelTest, HandlePointerEvent, Function | SmallTest | Level2)
65 {
66     auto pointerEvent = MMI::PointerEvent::Create();
67     sptr<WindowInputChannel> inputChannel = new WindowInputChannel(window_);
68     window_->ConsumePointerEvent(pointerEvent);
69     inputChannel->HandlePointerEvent(pointerEvent);
70 }
71 
72 /**
73  * @tc.name: HandleKeyEvent
74  * @tc.desc: consume key event when receive callback from input
75  * @tc.type: FUNC
76  */
77 HWTEST_F(WindowInputChannelTest, HandleKeyEvent, Function | SmallTest | Level2)
78 {
79     auto keyEvent = MMI::KeyEvent::Create();
80     sptr<WindowInputChannel> inputChannel = new WindowInputChannel(window_);
81     window_->ConsumeKeyEvent(keyEvent);
82     inputChannel->HandleKeyEvent(keyEvent);
83 }
84 }
85 } // namespace Rosen
86 } // namespace OHOS
87