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 <gtest/gtest.h>
17 #include <message_option.h>
18 #include <message_parcel.h>
19 #include <common/rs_rect.h>
20 #include <transaction/rs_marshalling_helper.h>
21 #include "session_manager/include/screen_session_manager_lite.h"
22 #include "dm_common.h"
23 #include "zidl/screen_session_manager_lite_stub.h"
24 #include "display_manager.h"
25 #include "display_manager_adapter.h"
26 #include "display_manager_agent_default.h"
27 #include "zidl/screen_session_manager_lite_interface.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31 namespace OHOS {
32 namespace Rosen {
33 namespace {
34 constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms
35 }
36 class ScreenSessionManagerLiteStubTest : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp() override;
41 void TearDown() override;
42 sptr<ScreenSessionManagerLiteStub> stub_;
43 };
44
SetUpTestCase()45 void ScreenSessionManagerLiteStubTest::SetUpTestCase()
46 {
47 }
48
TearDownTestCase()49 void ScreenSessionManagerLiteStubTest::TearDownTestCase()
50 {
51 usleep(SLEEP_TIME_IN_US);
52 }
53
SetUp()54 void ScreenSessionManagerLiteStubTest::SetUp()
55 {
56 stub_ = new ScreenSessionManagerLiteStub();
57 }
58
TearDown()59 void ScreenSessionManagerLiteStubTest::TearDown()
60 {
61 }
62
63 namespace {
64 /**
65 * @tc.name: OnRemoteRequest01
66 * @tc.desc: normal function
67 * @tc.type: FUNC
68 */
69 HWTEST_F(ScreenSessionManagerLiteStubTest, OnRemoteRequest01, Function | SmallTest | Level2)
70 {
71 MessageParcel data;
72 MessageParcel reply;
73 MessageOption option;
74
75 data.WriteInterfaceToken(ScreenSessionManagerLiteStub::GetDescriptor());
76 DisplayManagerAgentType type = DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER;
77 data.WriteUint32(static_cast<uint32_t>(type));
78 sptr<IDisplayManagerAgent> displayManagerAgent = new DisplayManagerAgentDefault();
79 data.WriteRemoteObject(displayManagerAgent->AsObject());
80
81 uint32_t code = static_cast<uint32_t>(
82 IScreenSessionManagerLite::ScreenManagerLiteMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT);
83
84 int res = stub_->OnRemoteRequest(code, data, reply, option);
85 EXPECT_EQ(res, 0);
86 }
87
88 /**
89 * @tc.name: OnRemoteRequest02
90 * @tc.desc: normal function
91 * @tc.type: FUNC
92 */
93 HWTEST_F(ScreenSessionManagerLiteStubTest, OnRemoteRequest02, Function | SmallTest | Level2)
94 {
95 MessageParcel data;
96 MessageParcel reply;
97 MessageOption option;
98
99 data.WriteInterfaceToken(ScreenSessionManagerLiteStub::GetDescriptor());
100 DisplayManagerAgentType type = DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER;
101 data.WriteUint32(static_cast<uint32_t>(type));
102 sptr<IDisplayManagerAgent> displayManagerAgent = new DisplayManagerAgentDefault();
103 data.WriteRemoteObject(displayManagerAgent->AsObject());
104
105 uint32_t code = static_cast<uint32_t>(
106 IScreenSessionManagerLite::ScreenManagerLiteMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT);
107
108 int res = stub_->OnRemoteRequest(code, data, reply, option);
109 EXPECT_EQ(res, 0);
110 }
111
112 /**
113 * @tc.name: OnRemoteRequest03
114 * @tc.desc: normal function
115 * @tc.type: FUNC
116 */
117 HWTEST_F(ScreenSessionManagerLiteStubTest, OnRemoteRequest03, Function | SmallTest | Level2)
118 {
119 MessageParcel data;
120 MessageParcel reply;
121 MessageOption option;
122
123 data.WriteInterfaceToken(ScreenSessionManagerLiteStub::GetDescriptor());
124
125 uint32_t code = static_cast<uint32_t>(
126 IScreenSessionManagerLite::ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_GET_FOLD_DISPLAY_MODE);
127
128 int res = stub_->OnRemoteRequest(code, data, reply, option);
129 EXPECT_EQ(res, 0);
130 }
131
132 /**
133 * @tc.name: OnRemoteRequest04
134 * @tc.desc: normal function
135 * @tc.type: FUNC
136 */
137 HWTEST_F(ScreenSessionManagerLiteStubTest, OnRemoteRequest04, Function | SmallTest | Level2)
138 {
139 MessageParcel data;
140 MessageParcel reply;
141 MessageOption option;
142
143 data.WriteInterfaceToken(ScreenSessionManagerLiteStub::GetDescriptor());
144
145 uint32_t code = static_cast<uint32_t>(
146 IScreenSessionManagerLite::ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_IS_FOLDABLE);
147
148 int res = stub_->OnRemoteRequest(code, data, reply, option);
149 EXPECT_EQ(res, 0);
150 }
151
152 /**
153 * @tc.name: OnRemoteRequest05
154 * @tc.desc: normal function
155 * @tc.type: FUNC
156 */
157 HWTEST_F(ScreenSessionManagerLiteStubTest, OnRemoteRequest05, Function | SmallTest | Level2)
158 {
159 MessageParcel data;
160 MessageParcel reply;
161 MessageOption option;
162
163 data.WriteInterfaceToken(ScreenSessionManagerLiteStub::GetDescriptor());
164
165 uint32_t code = static_cast<uint32_t>(
166 IScreenSessionManagerLite::ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_GET_FOLD_STATUS);
167
168 int res = stub_->OnRemoteRequest(code, data, reply, option);
169 EXPECT_EQ(res, 0);
170 }
171
172 /**
173 * @tc.name: OnRemoteRequest06
174 * @tc.desc: normal function
175 * @tc.type: FUNC
176 */
177 HWTEST_F(ScreenSessionManagerLiteStubTest, OnRemoteRequest06, Function | SmallTest | Level2)
178 {
179 MessageParcel data;
180 MessageParcel reply;
181 MessageOption option;
182
183 data.WriteInterfaceToken(ScreenSessionManagerLiteStub::GetDescriptor());
184
185 uint32_t code = static_cast<uint32_t>(
186 IScreenSessionManagerLite::ScreenManagerLiteMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO);
187
188 int res = stub_->OnRemoteRequest(code, data, reply, option);
189 EXPECT_EQ(res, 0);
190 }
191
192 /**
193 * @tc.name: OnRemoteRequest07
194 * @tc.desc: normal function
195 * @tc.type: FUNC
196 */
197 HWTEST_F(ScreenSessionManagerLiteStubTest, OnRemoteRequest07, Function | SmallTest | Level2)
198 {
199 MessageParcel data;
200 MessageParcel reply;
201 MessageOption option;
202
203 data.WriteInterfaceToken(ScreenSessionManagerLiteStub::GetDescriptor());
204 DisplayId displayId = 0;
205 data.WriteUint64(displayId);
206
207 uint32_t code = static_cast<uint32_t>(
208 IScreenSessionManagerLite::ScreenManagerLiteMessage::TRANS_ID_GET_DISPLAY_BY_ID);
209
210 int res = stub_->OnRemoteRequest(code, data, reply, option);
211 EXPECT_EQ(res, 0);
212 }
213
214 /**
215 * @tc.name: OnRemoteRequest08
216 * @tc.desc: normal function
217 * @tc.type: FUNC
218 */
219 HWTEST_F(ScreenSessionManagerLiteStubTest, OnRemoteRequest08, Function | SmallTest | Level2)
220 {
221 MessageParcel data;
222 MessageParcel reply;
223 MessageOption option;
224
225 data.WriteInterfaceToken(ScreenSessionManagerLiteStub::GetDescriptor());
226 DisplayId displayId = 0;
227 data.WriteUint64(displayId);
228
229 uint32_t code = static_cast<uint32_t>(
230 IScreenSessionManagerLite::ScreenManagerLiteMessage::TRANS_ID_GET_CUTOUT_INFO);
231
232 int res = stub_->OnRemoteRequest(code, data, reply, option);
233 EXPECT_EQ(res, 0);
234 }
235 }
236 }
237 }