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