• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <gtest/gtest.h>
16 #include "interfaces/include/ws_common.h"
17 #include "screen_session_manager_client/include/screen_session_manager_client.h"
18 #include "session/host/include/scene_session.h"
19 #include "session/screen/include/screen_session.h"
20 #include "session_manager.h"
21 #include "session_manager/include/scene_session_manager.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 namespace OHOS {
26 namespace Rosen {
27 class SceneSessionManagerFocusTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33     static sptr<SceneSessionManager> ssm_;
34 };
35 sptr<SceneSessionManager> SceneSessionManagerFocusTest::ssm_ = nullptr;
36 
SetUpTestCase()37 void SceneSessionManagerFocusTest::SetUpTestCase()
38 {
39     ssm_ = &SceneSessionManager::GetInstance();
40 }
41 
TearDownTestCase()42 void SceneSessionManagerFocusTest::TearDownTestCase()
43 {
44     ssm_ = nullptr;
45 }
46 
SetUp()47 void SceneSessionManagerFocusTest::SetUp() {}
48 
TearDown()49 void SceneSessionManagerFocusTest::TearDown() {}
50 
51 namespace {
52 
53 /**
54  * @tc.name: AddFocusGroup
55  * @tc.desc: AddFocusGroup
56  * @tc.type: FUNC
57  */
58 HWTEST_F(SceneSessionManagerFocusTest, AddFocusGroup, Function | SmallTest | Level2)
59 {
60     ASSERT_NE(nullptr, ssm_);
61     WSError ret = ssm_->AddFocusGroup(0, 0);
62     EXPECT_EQ(ret, WSError::WS_OK);
63 }
64 
65 /**
66  * @tc.name: RemoveFocusGroup
67  * @tc.desc: RemoveFocusGroup_Invalid
68  * @tc.type: FUNC
69  */
70 HWTEST_F(SceneSessionManagerFocusTest, RemoveFocusGroup_Invalid, Function | SmallTest | Level2)
71 {
72     ASSERT_NE(nullptr, ssm_);
73     WSError ret = ssm_->RemoveFocusGroup(0, 0);
74     EXPECT_EQ(ret, WSError::WS_OK);
75 }
76 
77 /**
78  * @tc.name: OnScreenConnected
79  * @tc.desc: OnScreenConnected
80  * @tc.type: FUNC
81  */
82 HWTEST_F(SceneSessionManagerFocusTest, OnScreenConnected, Function | SmallTest | Level2)
83 {
84     auto screenConnectionChangeListener = sptr<ScreenConnectionChangeListener>::MakeSptr();
85     ASSERT_NE(nullptr, screenConnectionChangeListener);
86     screenConnectionChangeListener->OnScreenConnected(nullptr);
87 
88     sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
89     screenConnectionChangeListener->OnScreenConnected(screenSession);
90 
91     screenSession->SetName("CeliaView");
92     screenSession->SetScreenType(ScreenType::VIRTUAL);
93     screenConnectionChangeListener->OnScreenConnected(screenSession);
94 
95     screenSession->SetName("DevEcoViewer");
96     screenSession->SetScreenType(ScreenType::VIRTUAL);
97     screenConnectionChangeListener->OnScreenConnected(screenSession);
98 }
99 
100 /**
101  * @tc.name: OnScreenDisconnected
102  * @tc.desc: OnScreenDisconnected
103  * @tc.type: FUNC
104  */
105 HWTEST_F(SceneSessionManagerFocusTest, OnScreenDisconnected, Function | SmallTest | Level2)
106 {
107     auto screenConnectionChangeListener = sptr<ScreenConnectionChangeListener>::MakeSptr();
108     ASSERT_NE(nullptr, screenConnectionChangeListener);
109     screenConnectionChangeListener->OnScreenDisconnected(nullptr);
110 
111     sptr<ScreenSession> screenSession = sptr<ScreenSession>::MakeSptr();
112     screenConnectionChangeListener->OnScreenDisconnected(screenSession);
113 
114     screenSession->SetName("CeliaView");
115     screenSession->SetScreenType(ScreenType::VIRTUAL);
116     screenConnectionChangeListener->OnScreenDisconnected(screenSession);
117 
118     screenSession->SetName("DevEcoViewer");
119     screenSession->SetScreenType(ScreenType::VIRTUAL);
120     screenConnectionChangeListener->OnScreenDisconnected(screenSession);
121 }
122 } // namespace
123 } // namespace Rosen
124 } // namespace OHOS