• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "session/container/include/zidl/window_event_channel_stub.h"
17 #include "session/container/include/zidl/session_stage_interface.h"
18 #include "mock/mock_session_stage.h"
19 #include "mock/mock_window_event_channel.h"
20 #include "iremote_object_mocker.h"
21 #include <message_option.h>
22 #include <message_parcel.h>
23 #include <string>
24 #include <gtest/gtest.h>
25 #include "mock_message_parcel.h"
26 #include "window_manager.h"
27 #include "window_manager_agent.h"
28 #include "window_manager_hilog.h"
29 using namespace testing;
30 using namespace testing::ext;
31 
32 namespace OHOS {
33 namespace Rosen {
34 namespace {
35 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelProxyMockTest" };
36 }
37 class WindowEventChannelMockStubTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp() override;
42     void TearDown() override;
43 
44     sptr<ISessionStage> sessionStage = sptr<SessionStageMocker>::MakeSptr();
45     sptr<WindowEventChannelStub> windowEventChannelStub_ = sptr<WindowEventChannelMocker>::MakeSptr(sessionStage);
46 };
47 
SetUpTestCase()48 void WindowEventChannelMockStubTest::SetUpTestCase() {}
49 
TearDownTestCase()50 void WindowEventChannelMockStubTest::TearDownTestCase() {}
51 
SetUp()52 void WindowEventChannelMockStubTest::SetUp() {}
53 
TearDown()54 void WindowEventChannelMockStubTest::TearDown() {}
55 
56 /**
57  * @tc.name: HandleTransferAccessibilityChildTreeRegister01
58  * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister01
59  * @tc.type: FUNC
60  */
61 HWTEST_F(WindowEventChannelMockStubTest, HandleTransferAccessibilityChildTreeRegister01, TestSize.Level1)
62 {
63     WLOGI("HandleTransferAccessibilityChildTreeRegister01 begin");
64     MockMessageParcel::ClearAllErrorFlag();
65     MessageParcel data;
66     MessageParcel reply;
67 
68     data.WriteUint32(0);
69     data.WriteInt32(0);
70     data.WriteInt64(0);
71 
72     MockMessageParcel::SetWriteInt32ErrorFlag(true);
73     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
74     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
75     WLOGI("HandleTransferAccessibilityChildTreeRegister01 end");
76 }
77 
78 /**
79  * @tc.name: HandleTransferAccessibilityChildTreeRegister02
80  * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister02
81  * @tc.type: FUNC
82  */
83 HWTEST_F(WindowEventChannelMockStubTest, HandleTransferAccessibilityChildTreeRegister02, TestSize.Level1)
84 {
85     WLOGI("HandleTransferAccessibilityChildTreeRegister02 begin");
86     MockMessageParcel::ClearAllErrorFlag();
87     MessageParcel data;
88     MessageParcel reply;
89 
90     data.WriteUint32(0);
91     data.WriteInt32(0);
92     data.WriteInt64(0);
93 
94     MockMessageParcel::SetWriteInt64ErrorFlag(true);
95     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
96     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
97     WLOGI("HandleTransferAccessibilityChildTreeRegister02 end");
98 }
99 
100 /**
101  * @tc.name: HandleTransferAccessibilityChildTreeUnregister
102  * @tc.desc: test function : HandleTransferAccessibilityChildTreeUnregister
103  * @tc.type: FUNC
104  */
105 HWTEST_F(WindowEventChannelMockStubTest, HandleTransferAccessibilityChildTreeUnregister, TestSize.Level1)
106 {
107     WLOGI("HandleTransferAccessibilityChildTreeUnregister begin");
108     MockMessageParcel::ClearAllErrorFlag();
109     MessageParcel data;
110     MessageParcel reply;
111 
112     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
113     ASSERT_EQ(ERR_NONE, windowEventChannelStub_->HandleTransferAccessibilityChildTreeUnregister(data, reply));
114     WLOGI("HandleTransferAccessibilityChildTreeUnregister end");
115 }
116 
117 /**
118  * @tc.name: HandleTransferAccessibilityDumpChildInfo
119  * @tc.desc: test function : HandleTransferAccessibilityDumpChildInfo
120  * @tc.type: FUNC
121  */
122 HWTEST_F(WindowEventChannelMockStubTest, HandleTransferAccessibilityDumpChildInfo, TestSize.Level1)
123 {
124     WLOGI("HandleTransferAccessibilityDumpChildInfo begin");
125     MockMessageParcel::ClearAllErrorFlag();
126     MessageParcel data;
127     MessageParcel reply;
128     std::vector<std::string> params;
129     data.WriteStringVector(params);
130 
131     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
132     ASSERT_EQ(ERR_NONE, windowEventChannelStub_->HandleTransferAccessibilityDumpChildInfo(data, reply));
133     WLOGI("HandleTransferAccessibilityDumpChildInfo end");
134 }
135 } // namespace Rosen
136 } // namespace OHOS