• 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_proxy.h"
17 #include "iremote_object_mocker.h"
18 #include <gtest/gtest.h>
19 #include "ws_common.h"
20 
21 // using namespace FRAME_TRACE;
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 class SessionProxyLifecycleTest : public testing::Test {
28 public:
SessionProxyLifecycleTest()29     SessionProxyLifecycleTest() {}
~SessionProxyLifecycleTest()30     ~SessionProxyLifecycleTest() {}
31 };
32 namespace {
33 
34 /**
35  * @tc.name: Foreground
36  * @tc.desc: normal function
37  * @tc.type: FUNC
38  */
39 HWTEST_F(SessionProxyLifecycleTest, Foreground, Function | SmallTest | Level2)
40 {
41     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: Foreground start";
42     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
43     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
44     sptr<WindowSessionProperty> property;
45     WSError res = sProxy->Foreground(property);
46     ASSERT_EQ(res, WSError::WS_OK);
47     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: Foreground end";
48 }
49 
50 /**
51  * @tc.name: Foreground
52  * @tc.desc: normal function
53  * @tc.type: FUNC
54  */
55 HWTEST_F(SessionProxyLifecycleTest, Foreground1, Function | SmallTest | Level2)
56 {
57     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: Foreground start";
58     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
59     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
60     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
61     ASSERT_NE(property, nullptr);
62     WSError res = sProxy->Foreground(property);
63     ASSERT_EQ(res, WSError::WS_OK);
64     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: Foreground end";
65 }
66 
67 /**
68  * @tc.name: Background
69  * @tc.desc: normal function
70  * @tc.type: FUNC
71  */
72 HWTEST_F(SessionProxyLifecycleTest, Background, Function | SmallTest | Level2)
73 {
74     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: Background start";
75     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
76     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
77     WSError res = sProxy->Background();
78     ASSERT_EQ(res, WSError::WS_OK);
79     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: Background end";
80 }
81 
82 /**
83  * @tc.name: Disconnect
84  * @tc.desc: normal function
85  * @tc.type: FUNC
86  */
87 HWTEST_F(SessionProxyLifecycleTest, Disconnect, Function | SmallTest | Level2)
88 {
89     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: Disconnect start";
90     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
91     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
92     WSError res = sProxy->Disconnect();
93     ASSERT_EQ(res, WSError::WS_OK);
94     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: Disconnect end";
95 }
96 
97 /**
98  * @tc.name: DrawingCompleted
99  * @tc.desc: normal function
100  * @tc.type: FUNC
101  */
102 HWTEST_F(SessionProxyLifecycleTest, DrawingCompleted, Function | SmallTest | Level2)
103 {
104     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: DrawingCompleted start";
105     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
106     ASSERT_NE(iRemoteObjectMocker, nullptr);
107     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
108     ASSERT_NE(sProxy, nullptr);
109     WSError res = sProxy->DrawingCompleted();
110     ASSERT_EQ(res, WSError::WS_OK);
111     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: DrawingCompleted end";
112 }
113 
114 /**
115  * @tc.name: RemoveStartingWindow
116  * @tc.desc: normal function
117  * @tc.type: FUNC
118  */
119 HWTEST_F(SessionProxyLifecycleTest, RemoveStartingWindow, Function | SmallTest | Level2)
120 {
121     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: RemoveStartingWindow start";
122     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
123     ASSERT_NE(iRemoteObjectMocker, nullptr);
124     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
125     ASSERT_NE(sProxy, nullptr);
126     WSError res = sProxy->RemoveStartingWindow();
127     ASSERT_EQ(res, WSError::WS_OK);
128     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: RemoveStartingWindow end";
129 }
130 
131 /**
132  * @tc.name: PendingSessionActivation
133  * @tc.desc: normal function
134  * @tc.type: FUNC
135  */
136 HWTEST_F(SessionProxyLifecycleTest, PendingSessionActivation, Function | SmallTest | Level2)
137 {
138     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: PendingSessionActivation start";
139     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
140     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
141     sptr<AAFwk::SessionInfo> abilitySessionInfo = nullptr;
142     WSError res = sProxy->PendingSessionActivation(abilitySessionInfo);
143     ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION);
144 
145     sptr<AAFwk::SessionInfo> abilitySessionInfo1 = sptr<AAFwk::SessionInfo>::MakeSptr();
146     ASSERT_NE(abilitySessionInfo1, nullptr);
147     res = sProxy->PendingSessionActivation(abilitySessionInfo1);
148     ASSERT_EQ(res, WSError::WS_OK);
149     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: PendingSessionActivation end";
150 }
151 
152 /**
153  * @tc.name: TerminateSession
154  * @tc.desc: normal function
155  * @tc.type: FUNC
156  */
157 HWTEST_F(SessionProxyLifecycleTest, TerminateSession, Function | SmallTest | Level2)
158 {
159     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: TerminateSession start";
160     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
161     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
162     sptr<AAFwk::SessionInfo> abilitySessionInfo = nullptr;
163     WSError res = sProxy->TerminateSession(abilitySessionInfo);
164     ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION);
165 
166     sptr<AAFwk::SessionInfo> abilitySessionInfo1 = sptr<AAFwk::SessionInfo>::MakeSptr();
167     ASSERT_NE(abilitySessionInfo1, nullptr);
168     res = sProxy->TerminateSession(abilitySessionInfo1);
169     ASSERT_EQ(res, WSError::WS_OK);
170     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: TerminateSession end";
171 }
172 
173 /**
174  * @tc.name: NotifySessionException
175  * @tc.desc: normal function
176  * @tc.type: FUNC
177  */
178 HWTEST_F(SessionProxyLifecycleTest, NotifySessionException, Function | SmallTest | Level2)
179 {
180     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: NotifySessionException start";
181     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
182     sptr<SessionProxy> sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
183     sptr<AAFwk::SessionInfo> abilitySessionInfo = nullptr;
184     ExceptionInfo exceptionInfo;
185     WSError res = sProxy->NotifySessionException(abilitySessionInfo, exceptionInfo);
186     ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION);
187 
188     sptr<AAFwk::SessionInfo> abilitySessionInfo1 = sptr<AAFwk::SessionInfo>::MakeSptr();
189     ASSERT_NE(abilitySessionInfo1, nullptr);
190     res = sProxy->NotifySessionException(abilitySessionInfo1, exceptionInfo);
191     ASSERT_EQ(res, WSError::WS_OK);
192     GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: NotifySessionException end";
193 }
194 }
195 }
196 }