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 "input_manager.h"
18 #include "input_transfer_station.h"
19 #include "window_impl.h"
20 #include "mock_window_adapter.h"
21 #include "singleton_mocker.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Rosen {
28 using WindowMocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
29 class InputTransferStationTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 virtual void SetUp() override;
34 virtual void TearDown() override;
35 sptr<WindowImpl> window_;
36 };
SetUpTestCase()37 void InputTransferStationTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void InputTransferStationTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void InputTransferStationTest::SetUp()
46 {
47 sptr<WindowOption> option = new WindowOption();
48 option->SetWindowName("inputwindow");
49 window_ = new WindowImpl(option);
50 window_->Create(INVALID_WINDOW_ID);
51 }
52
TearDown()53 void InputTransferStationTest::TearDown()
54 {
55 window_->Destroy();
56 window_ = nullptr;
57 }
58
59 namespace {
60 /**
61 * @tc.name: AddInputWindow
62 * @tc.desc: add input window in station.
63 * @tc.type: FUNC
64 * @tc.require: issueI5I5L4
65 */
66 HWTEST_F(InputTransferStationTest, AddInputWindow, Function | SmallTest | Level2)
67 {
68 std::shared_ptr<MMI::IInputEventConsumer> listener = std::make_shared<InputEventListener>(InputEventListener());
69 MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener);
70 InputTransferStation::GetInstance().AddInputWindow(window_);
71 }
72
73 /**
74 * @tc.name: RemoveInputWindow
75 * @tc.desc: remove input window in station.
76 * @tc.type: FUNC
77 * @tc.require: issueI5I5L4
78 */
79 HWTEST_F(InputTransferStationTest, RemoveInputWindow, Function | SmallTest | Level2)
80 {
81 InputTransferStation::GetInstance().RemoveInputWindow(window_->GetWindowId());
82 }
83 }
84 } // namespace Rosen
85 } // namespace OHOS
86