• 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 <gtest/gtest.h>
17 #include "session/host/include/scene_session.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 namespace OHOS {
22 namespace Rosen {
23 class SceneSessionTest : public testing::Test {
24 public:
25     static void SetUpTestCase();
26     static void TearDownTestCase();
27     void SetUp() override;
28     void TearDown() override;
29 };
30 
SetUpTestCase()31 void SceneSessionTest::SetUpTestCase()
32 {
33 }
34 
TearDownTestCase()35 void SceneSessionTest::TearDownTestCase()
36 {
37 }
38 
SetUp()39 void SceneSessionTest::SetUp()
40 {
41 }
42 
TearDown()43 void SceneSessionTest::TearDown()
44 {
45 }
46 
47 namespace {
48 /**
49  * @tc.name: ForegroundAndBackground01
50  * @tc.desc: normal function
51  * @tc.type: FUNC
52  */
53 HWTEST_F(SceneSessionTest, Foreground01, Function | SmallTest | Level2)
54 {
55     SessionInfo info;
56     info.abilityName_ = "Foreground01";
57     info.bundleName_ = "Foreground01";
58     sptr<Rosen::ISession> session_;
59     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
60         new (std::nothrow) SceneSession::SpecificSessionCallback();
61     EXPECT_NE(specificCallback_, nullptr);
62     int resultValue = 0;
63     sptr<SceneSession> scensession;
64 
65     scensession = new (std::nothrow) SceneSession(info, nullptr);
66     EXPECT_NE(scensession, nullptr);
67     scensession->isActive_ = true;
68     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
69     ASSERT_NE(nullptr, property);
70     auto result = scensession->Foreground(property);
71     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
72     specificCallback_->onCreate_ = [&resultValue, specificCallback_](const SessionInfo &info,
73                                                             sptr<WindowSessionProperty> property) -> sptr<SceneSession>
__anone12246aa0202(const SessionInfo &info, sptr<WindowSessionProperty> property) 74     {
75         sptr<SceneSession> scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback_);
76         EXPECT_NE(scensessionreturn, nullptr);
77         resultValue = 1;
78         return scensessionreturn;
79     };
80     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
81     EXPECT_NE(scensession, nullptr);
82     scensession->UpdateSessionState(SessionState::STATE_INACTIVE);
83     scensession->isActive_ = true;
84     result = scensession->Foreground(property);
85     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
86 }
87 
88 /**
89  * @tc.name: Background01
90  * @tc.desc: normal function
91  * @tc.type: FUNC
92  */
93 HWTEST_F(SceneSessionTest, Background01, Function | SmallTest | Level2)
94 {
95     SessionInfo info;
96     info.abilityName_ = "Background01";
97     info.bundleName_ = "Background01";
98     sptr<Rosen::ISession> session_;
99     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
100         new (std::nothrow) SceneSession::SpecificSessionCallback();
101     EXPECT_NE(specificCallback_, nullptr);
102     int resultValue = 0;
103     sptr<SceneSession> scensession;
104 
105     scensession = new (std::nothrow) SceneSession(info, nullptr);
106     EXPECT_NE(scensession, nullptr);
107     scensession->isActive_ = true;
108     auto result = scensession->Background();
109     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
110     specificCallback_->onCreate_ = [&resultValue, specificCallback_](const SessionInfo &info,
111                                                             sptr<WindowSessionProperty> property) -> sptr<SceneSession>
__anone12246aa0302(const SessionInfo &info, sptr<WindowSessionProperty> property) 112     {
113         sptr<SceneSession> scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback_);
114         EXPECT_NE(scensessionreturn, nullptr);
115         resultValue = 1;
116         return scensessionreturn;
117     };
118     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
119     EXPECT_NE(scensession, nullptr);
120     scensession->UpdateSessionState(SessionState::STATE_CONNECT);
121     scensession->isActive_ = true;
122     result = scensession->Background();
123     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
124 }
125 
126 }
127 }
128 }