• 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 <parameter.h>
18 #include <parameters.h>
19 
20 #include "session_manager/include/screen_session_manager.h"
21 #include "screen_scene_config.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29 constexpr uint32_t SLEEP_TIME_IN_US = 100000; // 100ms
30 }
31 class ScreenSessionManagerTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 
38     static sptr<ScreenSessionManager> ssm_;
39 };
40 
41 sptr<ScreenSessionManager> ScreenSessionManagerTest::ssm_ = nullptr;
42 
SetUpTestCase()43 void ScreenSessionManagerTest::SetUpTestCase()
44 {
45     ssm_ = new ScreenSessionManager();
46 }
47 
TearDownTestCase()48 void ScreenSessionManagerTest::TearDownTestCase()
49 {
50     ssm_ = nullptr;
51 }
52 
SetUp()53 void ScreenSessionManagerTest::SetUp()
54 {
55 }
56 
TearDown()57 void ScreenSessionManagerTest::TearDown()
58 {
59     usleep(SLEEP_TIME_IN_US);
60 }
61 
62 namespace {
63 /**
64  * @tc.name: SwitchScrollParam01
65  * @tc.desc: SwitchScrollParam test
66  * @tc.type: FUNC
67  */
68 HWTEST_F(ScreenSessionManagerTest, SwitchScrollParam01, Function | SmallTest | Level3)
69 {
70     ScreenSceneConfig::scrollableParams_.clear();
71     vector<FoldDisplayMode> displayModeALL = {
72         FoldDisplayMode::SUB,
73         FoldDisplayMode::MAIN,
74         FoldDisplayMode::FULL,
75         FoldDisplayMode::UNKNOWN,
76         FoldDisplayMode::COORDINATION,
77     };
78     std::map<FoldDisplayMode, std::string> scrollVelocityScaleParam = {
79         pair<FoldDisplayMode, std::string>(FoldDisplayMode::SUB, "1.0"),
80         pair<FoldDisplayMode, std::string>(FoldDisplayMode::MAIN, "1.1"),
81         pair<FoldDisplayMode, std::string>(FoldDisplayMode::FULL, "1.2"),
82         pair<FoldDisplayMode, std::string>(FoldDisplayMode::UNKNOWN, "1.3"),
83         pair<FoldDisplayMode, std::string>(FoldDisplayMode::COORDINATION, "1.4")
84     };
85     std::map<FoldDisplayMode, std::string> scrollFrictionParam = {
86         pair<FoldDisplayMode, std::string>(FoldDisplayMode::SUB, "1.0"),
87         pair<FoldDisplayMode, std::string>(FoldDisplayMode::MAIN, "2.0"),
88         pair<FoldDisplayMode, std::string>(FoldDisplayMode::FULL, "3.0"),
89         pair<FoldDisplayMode, std::string>(FoldDisplayMode::UNKNOWN, "4.0"),
90         pair<FoldDisplayMode, std::string>(FoldDisplayMode::COORDINATION, "5.0"),
91     };
92     ScreenSessionManager* ssm = new ScreenSessionManager();
93     ASSERT_NE(ssm, nullptr);
94     std::string ret1, ret2;
95     for (FoldDisplayMode displayMode : displayModeALL) {
96         ScrollableParam scrollableParam;
97         scrollableParam.velocityScale_ = scrollVelocityScaleParam.count(displayMode) ?
98             scrollVelocityScaleParam[displayMode] : "";
99         scrollableParam.friction_ = scrollFrictionParam.count(displayMode) ?
100             scrollFrictionParam[displayMode] : "";
101         ScreenSceneConfig::scrollableParams_[displayMode] = scrollableParam;
102         ssm->SwitchScrollParam(displayMode);
103         ret1 = system::GetParameter("persist.scrollable.velocityScale", "0");
104         ret2 = system::GetParameter("persist.scrollable.friction", "0");
105         EXPECT_EQ(ret1, scrollVelocityScaleParam[displayMode]);
106         EXPECT_EQ(ret2, scrollFrictionParam[displayMode]);
107     }
108 }
109 
110 /**
111  * @tc.name: SwitchScrollParam02
112  * @tc.desc: SwitchScrollParam test
113  * @tc.type: FUNC
114  */
115 HWTEST_F(ScreenSessionManagerTest, SwitchScrollParam02, Function | SmallTest | Level3)
116 {
117     ScreenSceneConfig::scrollableParams_.clear();
118     vector<FoldDisplayMode> displayModeALL = {
119         FoldDisplayMode::SUB,
120         FoldDisplayMode::MAIN,
121         FoldDisplayMode::FULL,
122         FoldDisplayMode::UNKNOWN,
123         FoldDisplayMode::COORDINATION,
124     };
125     std::map<FoldDisplayMode, std::string> scrollVelocityScaleParam = {
126         pair<FoldDisplayMode, std::string>(FoldDisplayMode::FULL, "2.0"),
127         pair<FoldDisplayMode, std::string>(FoldDisplayMode::MAIN, "main"),
128         pair<FoldDisplayMode, std::string>(FoldDisplayMode::UNKNOWN, "!!"),
129     };
130     std::map<FoldDisplayMode, std::string> scrollFrictionParam;
131     ScreenSessionManager* ssm = new ScreenSessionManager();
132     ASSERT_NE(ssm, nullptr);
133     std::string ret1, ret2;
134     for (FoldDisplayMode displayMode : displayModeALL) {
135         ScrollableParam scrollableParam;
136         scrollableParam.velocityScale_ = scrollVelocityScaleParam.count(displayMode) ?
137             scrollVelocityScaleParam[displayMode] : "";
138         scrollableParam.friction_ = scrollFrictionParam.count(displayMode) ?
139             scrollFrictionParam[displayMode] : "";
140         ScreenSceneConfig::scrollableParams_[displayMode] = scrollableParam;
141         ssm->SwitchScrollParam(displayMode);
142         ret1 = system::GetParameter("persist.scrollable.velocityScale", "0");
143         ret2 = system::GetParameter("persist.scrollable.friction", "0");
144         EXPECT_EQ(ret1, scrollVelocityScaleParam[displayMode]);
145         EXPECT_EQ(ret2, scrollFrictionParam[displayMode]);
146     }
147 }
148 }
149 }
150 }