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 */ 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 */ 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 */ 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 */ 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 */ 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: RemoveStartingWindow 115 * @tc.desc: normal function 116 * @tc.type: FUNC 117 */ 118 HWTEST_F(SessionProxyLifecycleTest, RemoveStartingWindow, Function | SmallTest | Level2) 119 { 120 GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: RemoveStartingWindow start"; 121 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker(); 122 ASSERT_NE(iRemoteObjectMocker, nullptr); 123 sptr<SessionProxy> sProxy = new (std::nothrow) SessionProxy(iRemoteObjectMocker); 124 ASSERT_NE(sProxy, nullptr); 125 WSError res = sProxy->RemoveStartingWindow(); 126 ASSERT_EQ(res, WSError::WS_OK); 127 GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: RemoveStartingWindow end"; 128 } 129 130 /** 131 * @tc.name: PendingSessionActivation 132 * @tc.desc: normal function 133 * @tc.type: FUNC 134 */ 135 HWTEST_F(SessionProxyLifecycleTest, PendingSessionActivation, Function | SmallTest | Level2) 136 { 137 GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: PendingSessionActivation start"; 138 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker(); 139 SessionProxy* sProxy = new (std::nothrow) SessionProxy(iRemoteObjectMocker); 140 sptr<AAFwk::SessionInfo> abilitySessionInfo = nullptr; 141 WSError res = sProxy->PendingSessionActivation(abilitySessionInfo); 142 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION); 143 144 sptr<AAFwk::SessionInfo> abilitySessionInfo1 = new (std::nothrow) AAFwk::SessionInfo(); 145 ASSERT_NE(abilitySessionInfo1, nullptr); 146 res = sProxy->PendingSessionActivation(abilitySessionInfo1); 147 ASSERT_EQ(res, WSError::WS_OK); 148 GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: PendingSessionActivation end"; 149 } 150 151 /** 152 * @tc.name: TerminateSession 153 * @tc.desc: normal function 154 * @tc.type: FUNC 155 */ 156 HWTEST_F(SessionProxyLifecycleTest, TerminateSession, Function | SmallTest | Level2) 157 { 158 GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: TerminateSession start"; 159 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker(); 160 SessionProxy* sProxy = new (std::nothrow) SessionProxy(iRemoteObjectMocker); 161 sptr<AAFwk::SessionInfo> abilitySessionInfo = nullptr; 162 WSError res = sProxy->TerminateSession(abilitySessionInfo); 163 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION); 164 165 sptr<AAFwk::SessionInfo> abilitySessionInfo1 = new (std::nothrow) AAFwk::SessionInfo(); 166 ASSERT_NE(abilitySessionInfo1, nullptr); 167 res = sProxy->TerminateSession(abilitySessionInfo1); 168 ASSERT_EQ(res, WSError::WS_OK); 169 GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: TerminateSession end"; 170 } 171 172 /** 173 * @tc.name: NotifySessionException 174 * @tc.desc: normal function 175 * @tc.type: FUNC 176 */ 177 HWTEST_F(SessionProxyLifecycleTest, NotifySessionException, Function | SmallTest | Level2) 178 { 179 GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: NotifySessionException start"; 180 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker(); 181 SessionProxy* sProxy = new (std::nothrow) SessionProxy(iRemoteObjectMocker); 182 sptr<AAFwk::SessionInfo> abilitySessionInfo = nullptr; 183 WSError res = sProxy->NotifySessionException(abilitySessionInfo); 184 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION); 185 186 sptr<AAFwk::SessionInfo> abilitySessionInfo1 = new (std::nothrow) AAFwk::SessionInfo(); 187 ASSERT_NE(abilitySessionInfo1, nullptr); 188 res = sProxy->NotifySessionException(abilitySessionInfo1); 189 ASSERT_EQ(res, WSError::WS_OK); 190 GTEST_LOG_(INFO) << "SessionProxyLifecycleTest: NotifySessionException end"; 191 } 192 } 193 } 194 }