1 /*
2 * Copyright (c) 2022 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
18 #include "abstract_screen.h"
19 #include "abstract_screen_controller.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 class AbstractScreenTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32
33 static sptr<AbstractScreen> absScreen_;
34 static std::recursive_mutex mutex_;
35 static std::string name_;
36 };
37
38 sptr<AbstractScreen> AbstractScreenTest::absScreen_ = nullptr;
39 std::recursive_mutex AbstractScreenTest::mutex_;
40 std::string AbstractScreenTest::name_ = "AbstractScreenTest";
41
SetUpTestCase()42 void AbstractScreenTest::SetUpTestCase()
43 {
44 sptr<AbstractScreenController> absScreenController = new AbstractScreenController(mutex_);
45 absScreen_ = new AbstractScreen(absScreenController, name_, 0, 0);
46 absScreen_->modes_.clear();
47 absScreen_->activeIdx_ = 0;
48 }
49
TearDownTestCase()50 void AbstractScreenTest::TearDownTestCase()
51 {
52 }
53
SetUp()54 void AbstractScreenTest::SetUp()
55 {
56 }
57
TearDown()58 void AbstractScreenTest::TearDown()
59 {
60 }
61
62 namespace {
63 /**
64 * @tc.name: GetScreenMode
65 * @tc.desc: Get screen mode
66 * @tc.type: FUNC
67 */
68 HWTEST_F(AbstractScreenTest, GetScreenMode, Function | SmallTest | Level3)
69 {
70 sptr<SupportedScreenModes> mode0 = new SupportedScreenModes();
71 sptr<SupportedScreenModes> mode1 = new SupportedScreenModes();
72 absScreen_->modes_ = {mode0, mode1};
73
74 absScreen_->activeIdx_ = -1;
75 ASSERT_EQ(nullptr, absScreen_->GetActiveScreenMode());
76 absScreen_->activeIdx_ = static_cast<int32_t>(absScreen_->modes_.size());
77 ASSERT_EQ(nullptr, absScreen_->GetActiveScreenMode());
78 absScreen_->activeIdx_ = 0;
79 ASSERT_EQ(mode0, absScreen_->GetActiveScreenMode());
80 absScreen_->activeIdx_ = 1;
81 ASSERT_EQ(mode1, absScreen_->GetActiveScreenMode());
82
83 ASSERT_EQ(mode0, (absScreen_->GetAbstractScreenModes())[0]);
84 ASSERT_EQ(mode1, (absScreen_->GetAbstractScreenModes())[1]);
85 }
86 /**
87 * @tc.name: ConvertToScreenInfo
88 * @tc.desc: Convert to screen info
89 * @tc.type: FUNC
90 */
91 HWTEST_F(AbstractScreenTest, ConvertToScreenInfo, Function | SmallTest | Level3)
92 {
93 ASSERT_NE(nullptr, absScreen_->ConvertToScreenInfo());
94 }
95 /**
96 * @tc.name: RSTree
97 * @tc.desc: RS tree
98 * @tc.type: FUNC
99 */
100 HWTEST_F(AbstractScreenTest, RSTree, Function | SmallTest | Level3)
101 {
102 std::shared_ptr<RSSurfaceNode> surfaceNode;
103 absScreen_->rsDisplayNode_ = nullptr;
104 absScreen_->UpdateRSTree(surfaceNode, true);
105 absScreen_->UpdateDisplayGroupRSTree(surfaceNode, 0, true);
106
107 struct RSDisplayNodeConfig config;
108 absScreen_->rsDisplayNode_ = std::make_shared<RSDisplayNode>(config);
109 ASSERT_NE(nullptr, absScreen_->rsDisplayNode_);
110 absScreen_->UpdateRSTree(surfaceNode, true);
111 absScreen_->UpdateDisplayGroupRSTree(surfaceNode, 0, true);
112
113 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
114 surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, RSSurfaceNodeType::DEFAULT);
115 absScreen_->UpdateDisplayGroupRSTree(surfaceNode, 0, true);
116 absScreen_->UpdateDisplayGroupRSTree(surfaceNode, 0, false);
117 ASSERT_NE(nullptr, absScreen_->rsDisplayNode_);
118 absScreen_->rsDisplayNode_ = nullptr;
119 }
120 /**
121 * @tc.name: ColorGamut
122 * @tc.desc: Screen color gamut
123 * @tc.type: FUNC
124 */
125 HWTEST_F(AbstractScreenTest, ColorGamut, Function | SmallTest | Level3)
126 {
127 sptr<AbstractScreenController> absScreenController0 = new AbstractScreenController(mutex_);
128 sptr<AbstractScreen> absScreen0 = new AbstractScreen(absScreenController0, name_, 0, -1ULL);
129 std::vector<ScreenColorGamut> colorGamuts;
130 ASSERT_EQ(DMError::DM_ERROR_RENDER_SERVICE_FAILED, absScreen0->GetScreenSupportedColorGamuts(colorGamuts));
131 ScreenColorGamut colorGamut;
132 ASSERT_EQ(DMError::DM_ERROR_RENDER_SERVICE_FAILED, absScreen0->GetScreenColorGamut(colorGamut));
133
134 ASSERT_EQ(DMError::DM_ERROR_RENDER_SERVICE_FAILED, absScreen0->SetScreenColorGamut(0));
135
136 ScreenGamutMap gamutMap;
137 ASSERT_EQ(DMError::DM_ERROR_RENDER_SERVICE_FAILED, absScreen0->GetScreenGamutMap(gamutMap));
138
139 gamutMap = ScreenGamutMap::GAMUT_MAP_HDR_EXTENSION;
140 ASSERT_EQ(DMError::DM_ERROR_RENDER_SERVICE_FAILED, absScreen0->GetScreenGamutMap(gamutMap));
141 }
142 /**
143 * @tc.name: FillScreenInfo
144 * @tc.desc: Fill screen info
145 * @tc.type: FUNC
146 */
147 HWTEST_F(AbstractScreenTest, FillScreenInfo, Function | SmallTest | Level3)
148 {
149 absScreen_->FillScreenInfo(nullptr);
150 sptr<ScreenInfo> info = new ScreenInfo();
151 ASSERT_NE(nullptr, info);
152
153 absScreen_->virtualPixelRatio_ = 0.f;
154 absScreen_->FillScreenInfo(info);
155 ASSERT_EQ(1.f, info->virtualPixelRatio_);
156
157 absScreen_->virtualPixelRatio_ = 2.f;
158 absScreen_->FillScreenInfo(info);
159 ASSERT_EQ(2.f, info->virtualPixelRatio_);
160 }
161 /**
162 * @tc.name: CalcRotation
163 * @tc.desc: Calc rotation
164 * @tc.type: FUNC
165 */
166 HWTEST_F(AbstractScreenTest, CalcRotation, Function | SmallTest | Level3)
167 {
168 absScreen_->modes_.clear();
169 absScreen_->activeIdx_ = 0;
170
171 ASSERT_EQ(Rotation::ROTATION_0, absScreen_->CalcRotation(Orientation::UNSPECIFIED));
172
173 sptr<SupportedScreenModes> mode = new SupportedScreenModes();
174 mode->width_ = 1;
175 mode->height_ = 1;
176 absScreen_->modes_ = {mode};
177
178 ASSERT_EQ(Rotation::ROTATION_0, absScreen_->CalcRotation(Orientation::UNSPECIFIED));
179 ASSERT_EQ(Rotation::ROTATION_90, absScreen_->CalcRotation(Orientation::VERTICAL));
180 ASSERT_EQ(Rotation::ROTATION_0, absScreen_->CalcRotation(Orientation::HORIZONTAL));
181 ASSERT_EQ(Rotation::ROTATION_270, absScreen_->CalcRotation(Orientation::REVERSE_VERTICAL));
182 ASSERT_EQ(Rotation::ROTATION_180, absScreen_->CalcRotation(Orientation::REVERSE_HORIZONTAL));
183 ASSERT_EQ(Rotation::ROTATION_0, absScreen_->CalcRotation(Orientation::LOCKED));
184 }
185 }
186 } // namespace Rosen
187 } // namespace OHOS
188