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 "iremote_object_mocker.h"
22 #include "zidl/screen_session_manager_lite_proxy.h"
23 #include "zidl/screen_session_manager_lite_interface.h"
24 #include "screen_session_manager_lite.h"
25 #include "zidl/screen_session_manager_proxy.h"
26 #include "display_manager_adapter.h"
27 #include "display_manager.h"
28 #include "display_manager_agent_default.h"
29 
30 using namespace testing;
31 using namespace testing::ext;
32 namespace OHOS {
33 namespace Rosen {
34 class ScreenSessionManagerLiteProxyTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp() override;
39     void TearDown() override;
40     sptr<IRemoteObjectMocker> iRemoteObjectMocker_;
41     sptr<ScreenSessionManagerLiteProxy> screenSessionManagerLiteProxy_;
42 };
43 
SetUpTestCase()44 void ScreenSessionManagerLiteProxyTest::SetUpTestCase()
45 {
46 }
47 
TearDownTestCase()48 void ScreenSessionManagerLiteProxyTest::TearDownTestCase()
49 {
50 }
51 
SetUp()52 void ScreenSessionManagerLiteProxyTest::SetUp()
53 {
54     iRemoteObjectMocker_ = new IRemoteObjectMocker();
55     screenSessionManagerLiteProxy_ = new ScreenSessionManagerLiteProxy(iRemoteObjectMocker_);
56 }
57 
TearDown()58 void ScreenSessionManagerLiteProxyTest::TearDown()
59 {
60     screenSessionManagerLiteProxy_ = nullptr;
61 }
62 
63 namespace {
64 /**
65  * @tc.name: RegisterDisplayManagerAgent
66  * @tc.desc: RegisterDisplayManagerAgent
67  * @tc.type: FUNC
68  */
69 HWTEST_F(ScreenSessionManagerLiteProxyTest, RegisterDisplayManagerAgent, Function | SmallTest | Level1)
70 {
71     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
72     MessageParcel reply;
73 
74     sptr<IDisplayManagerAgent> displayManagerAgent = new DisplayManagerAgentDefault();
75     DisplayManagerAgentType type = DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER;
76     DMError err = screenSessionManagerLiteProxy_->RegisterDisplayManagerAgent(displayManagerAgent, type);
77     EXPECT_EQ(err, static_cast<DMError>(reply.ReadInt32()));
78 }
79 
80 /**
81  * @tc.name: UnregisterDisplayManagerAgent
82  * @tc.desc: UnregisterDisplayManagerAgent
83  * @tc.type: FUNC
84  */
85 HWTEST_F(ScreenSessionManagerLiteProxyTest, UnregisterDisplayManagerAgent, Function | SmallTest | Level1)
86 {
87     SingletonContainer::Get<ScreenManagerAdapter>().InitDMSProxy();
88 
89     MessageParcel reply;
90     sptr<IDisplayManagerAgent> displayManagerAgent = new DisplayManagerAgentDefault();
91     DisplayManagerAgentType type = DisplayManagerAgentType::DISPLAY_STATE_LISTENER;
92     DMError err = screenSessionManagerLiteProxy_->UnregisterDisplayManagerAgent(displayManagerAgent, type);
93     EXPECT_EQ(err, static_cast<DMError>(reply.ReadInt32()));
94 }
95 
96 /**
97  * @tc.name: GetFoldDisplayMode
98  * @tc.desc: GetFoldDisplayMode
99  * @tc.type: FUNC
100  */
101 HWTEST_F(ScreenSessionManagerLiteProxyTest, GetFoldDisplayMode, Function | SmallTest | Level1)
102 {
103     FoldDisplayMode res = screenSessionManagerLiteProxy_->GetFoldDisplayMode();
104     EXPECT_EQ(res, FoldDisplayMode::UNKNOWN);
105 }
106 
107 /**
108  * @tc.name: IsFoldable
109  * @tc.desc: IsFoldable
110  * @tc.type: FUNC
111  */
112 HWTEST_F(ScreenSessionManagerLiteProxyTest, IsFoldable, Function | SmallTest | Level1)
113 {
114     bool res = screenSessionManagerLiteProxy_->IsFoldable();
115     ASSERT_FALSE(res);
116 }
117 
118 /**
119  * @tc.name: GetFoldStatus
120  * @tc.desc: GetFoldStatus
121  * @tc.type: FUNC
122  */
123 HWTEST_F(ScreenSessionManagerLiteProxyTest, GetFoldStatus, Function | SmallTest | Level1)
124 {
125     FoldStatus res = screenSessionManagerLiteProxy_->GetFoldStatus();
126     ASSERT_EQ(FoldStatus::UNKNOWN, res);
127 }
128 
129 /**
130  * @tc.name: GetDefaultDisplayInfo
131  * @tc.desc: GetDefaultDisplayInfo
132  * @tc.type: FUNC
133  */
134 HWTEST_F(ScreenSessionManagerLiteProxyTest, GetDefaultDisplayInfo, Function | SmallTest | Level1)
135 {
136     auto res = screenSessionManagerLiteProxy_->GetDefaultDisplayInfo();
137     ASSERT_EQ(nullptr, res);
138 }
139 
140 /**
141  * @tc.name: GetDisplayInfoById
142  * @tc.desc: GetDisplayInfoById
143  * @tc.type: FUNC
144  */
145 HWTEST_F(ScreenSessionManagerLiteProxyTest, GetDisplayInfoById, Function | SmallTest | Level1)
146 {
147     DisplayId displayId = 1001;
148     auto res = screenSessionManagerLiteProxy_->GetDisplayInfoById(displayId);
149     ASSERT_EQ(nullptr, res);
150 }
151 
152 /**
153  * @tc.name: GetCutoutInfo
154  * @tc.desc: GetCutoutInfo
155  * @tc.type: FUNC
156  */
157 HWTEST_F(ScreenSessionManagerLiteProxyTest, GetCutoutInfo, Function | SmallTest | Level1)
158 {
159     DisplayId displayId = 1001;
160     auto res = screenSessionManagerLiteProxy_->GetCutoutInfo(displayId);
161     ASSERT_EQ(nullptr, res);
162 }
163 }
164 }
165 }