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 = new SessionStageMocker();
45 sptr<WindowEventChannelStub> windowEventChannelStub_ = new WindowEventChannelMocker(sessionStage);
46 };
47
SetUpTestCase()48 void WindowEventChannelMockStubTest::SetUpTestCase()
49 {
50 }
51
TearDownTestCase()52 void WindowEventChannelMockStubTest::TearDownTestCase()
53 {
54 }
55
SetUp()56 void WindowEventChannelMockStubTest::SetUp()
57 {
58 }
59
TearDown()60 void WindowEventChannelMockStubTest::TearDown()
61 {
62 }
63
64 /**
65 * @tc.name: HandleTransferAccessibilityChildTreeRegister01
66 * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister01
67 * @tc.type: FUNC
68 */
69 HWTEST_F(WindowEventChannelMockStubTest, HandleTransferAccessibilityChildTreeRegister01, Function | SmallTest | Level1)
70 {
71 WLOGI("HandleTransferAccessibilityChildTreeRegister01 begin");
72 MockMessageParcel::ClearAllErrorFlag();
73 MessageParcel data;
74 MessageParcel reply;
75
76 data.WriteUint32(0);
77 data.WriteInt32(0);
78 data.WriteInt64(0);
79
80 MockMessageParcel::SetWriteInt32ErrorFlag(true);
81 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
82 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
83 WLOGI("HandleTransferAccessibilityChildTreeRegister01 end");
84 }
85
86 /**
87 * @tc.name: HandleTransferAccessibilityChildTreeRegister02
88 * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister02
89 * @tc.type: FUNC
90 */
91 HWTEST_F(WindowEventChannelMockStubTest, HandleTransferAccessibilityChildTreeRegister02, Function | SmallTest | Level1)
92 {
93 WLOGI("HandleTransferAccessibilityChildTreeRegister02 begin");
94 MockMessageParcel::ClearAllErrorFlag();
95 MessageParcel data;
96 MessageParcel reply;
97
98 data.WriteUint32(0);
99 data.WriteInt32(0);
100 data.WriteInt64(0);
101
102 MockMessageParcel::SetWriteInt64ErrorFlag(true);
103 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
104 ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
105 WLOGI("HandleTransferAccessibilityChildTreeRegister02 end");
106 }
107
108 /**
109 * @tc.name: HandleTransferAccessibilityChildTreeUnregister
110 * @tc.desc: test function : HandleTransferAccessibilityChildTreeUnregister
111 * @tc.type: FUNC
112 */
113 HWTEST_F(WindowEventChannelMockStubTest, HandleTransferAccessibilityChildTreeUnregister, Function | SmallTest | Level1)
114 {
115 WLOGI("HandleTransferAccessibilityChildTreeUnregister begin");
116 MockMessageParcel::ClearAllErrorFlag();
117 MessageParcel data;
118 MessageParcel reply;
119
120 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
121 ASSERT_EQ(ERR_NONE, windowEventChannelStub_->HandleTransferAccessibilityChildTreeUnregister(data, reply));
122 WLOGI("HandleTransferAccessibilityChildTreeUnregister end");
123 }
124
125 /**
126 * @tc.name: HandleTransferAccessibilityDumpChildInfo
127 * @tc.desc: test function : HandleTransferAccessibilityDumpChildInfo
128 * @tc.type: FUNC
129 */
130 HWTEST_F(WindowEventChannelMockStubTest, HandleTransferAccessibilityDumpChildInfo, Function | SmallTest | Level1)
131 {
132 WLOGI("HandleTransferAccessibilityDumpChildInfo begin");
133 MockMessageParcel::ClearAllErrorFlag();
134 MessageParcel data;
135 MessageParcel reply;
136 std::vector<std::string> params;
137 data.WriteStringVector(params);
138
139 ASSERT_TRUE((windowEventChannelStub_ != nullptr));
140 ASSERT_EQ(ERR_NONE, windowEventChannelStub_->HandleTransferAccessibilityDumpChildInfo(data, reply));
141 WLOGI("HandleTransferAccessibilityDumpChildInfo end");
142 }
143 }
144 }