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 "session_manager/include/scene_session_manager.h"
20 #include "session_manager/include/zidl/scene_session_manager_interface.h"
21 #include "window_manager_agent.h"
22 #include "zidl/scene_session_manager_stub.h"
23 #include "zidl/window_manager_agent_interface.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27 namespace OHOS {
28 namespace Rosen {
29 class SceneSessionManagerStubTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 sptr<SceneSessionManagerStub> stub_;
36 };
37
SetUpTestCase()38 void SceneSessionManagerStubTest::SetUpTestCase()
39 {
40 }
41
TearDownTestCase()42 void SceneSessionManagerStubTest::TearDownTestCase()
43 {
44 }
45
SetUp()46 void SceneSessionManagerStubTest::SetUp()
47 {
48 stub_ = new SceneSessionManager();
49 }
50
TearDown()51 void SceneSessionManagerStubTest::TearDown()
52 {
53 }
54
55 namespace {
56 /**
57 * @tc.name: OnRemoteRequest01
58 * @tc.desc: test TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT
59 * @tc.type: FUNC
60 */
61 HWTEST_F(SceneSessionManagerStubTest, OnRemoteRequest01, Function | SmallTest | Level2)
62 {
63 MessageParcel data;
64 MessageParcel reply;
65 MessageOption option;
66
67 data.WriteInterfaceToken(SceneSessionManagerStub::GetDescriptor());
68 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
69 data.WriteUint32(static_cast<uint32_t>(type));
70 sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
71 data.WriteRemoteObject(windowManagerAgent->AsObject());
72
73 uint32_t code = static_cast<uint32_t>(
74 ISceneSessionManager::SceneSessionManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT);
75
76 int res = stub_->OnRemoteRequest(code, data, reply, option);
77 EXPECT_EQ(res, 0);
78 }
79
80 /**
81 * @tc.name: OnRemoteRequest02
82 * @tc.desc: test TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT
83 * @tc.type: FUNC
84 */
85 HWTEST_F(SceneSessionManagerStubTest, OnRemoteRequest02, Function | SmallTest | Level2)
86 {
87 MessageParcel data;
88 MessageParcel reply;
89 MessageOption option;
90
91 data.WriteInterfaceToken(SceneSessionManagerStub::GetDescriptor());
92 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
93 data.WriteUint32(static_cast<uint32_t>(type));
94 sptr<IWindowManagerAgent> windowManagerAgent = new WindowManagerAgent();
95 data.WriteRemoteObject(windowManagerAgent->AsObject());
96
97 uint32_t code = static_cast<uint32_t>(
98 ISceneSessionManager::SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT);
99
100 int res = stub_->OnRemoteRequest(code, data, reply, option);
101 EXPECT_EQ(res, 0);
102 }
103
104 }
105 }
106 }