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#include "display_manager.h" 18#include "display_manager_proxy.h" 19#include "mock_display_manager_adapter.h" 20#include "singleton_mocker.h" 21#include "display_cutout_controller.h" 22#include "scene_board_judgement.h" 23 24using namespace testing; 25using namespace testing::ext; 26 27namespace OHOS { 28namespace Rosen { 29using Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>; 30using ScreenMocker = SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter>; 31class DisplayTest : public testing::Test { 32public: 33 static void SetUpTestCase(); 34 static void TearDownTestCase(); 35 virtual void SetUp() override; 36 virtual void TearDown() override; 37 38 static sptr<Display> defaultDisplay_; 39 static DisplayId defaultDisplayId_; 40}; 41sptr<Display> DisplayTest::defaultDisplay_ = nullptr; 42DisplayId DisplayTest::defaultDisplayId_ = DISPLAY_ID_INVALID; 43 44void DisplayTest::SetUpTestCase() 45{ 46 defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay(); 47 defaultDisplayId_ = static_cast<DisplayId>(defaultDisplay_->GetId()); 48} 49 50void DisplayTest::TearDownTestCase() 51{ 52 defaultDisplay_ = nullptr; 53} 54 55void DisplayTest::SetUp() 56{ 57} 58 59void DisplayTest::TearDown() 60{ 61} 62 63namespace { 64/** 65 * @tc.name: GetCutoutInfo01 66 * @tc.desc: GetCutoutInfo with valid defaultDisplayId and return success 67 * @tc.type: FUNC 68 * @tc.require: issueI5K0JP 69 */ 70HWTEST_F(DisplayTest, GetCutoutInfo01, Function | SmallTest | Level1) 71{ 72 auto cutoutInfo = defaultDisplay_->GetCutoutInfo(); 73 ASSERT_NE(nullptr, cutoutInfo); 74} 75 76/** 77 * @tc.name: UpdateDisplayInfo01 78 * @tc.desc: UpdateDisplayInfo with nullptr 79 * @tc.type: FUNC 80 * @tc.require: issueI5K0JP 81 */ 82HWTEST_F(DisplayTest, UpdateDisplayInfo01, Function | SmallTest | Level1) 83{ 84 auto baseInfo = defaultDisplay_->GetDisplayInfo(); 85 auto defaultName = baseInfo->GetName(); 86 auto defaultDpi = baseInfo->GetName(); 87 defaultDisplay_->UpdateDisplayInfo(nullptr); 88 89 auto changedInfo = defaultDisplay_->GetDisplayInfo(); 90 ASSERT_EQ(changedInfo->GetName(), defaultName); 91} 92 93/** 94 * @tc.name: SetWaterfallCompression01 95 * @tc.desc: Set waterfall compression related values with valid input. 96 * @tc.type: FUNC 97 * @tc.require: issueI5P8CI 98 */ 99HWTEST_F(DisplayTest, SetWaterfallCompression01, Function | SmallTest | Level1) 100{ 101 bool isWaterfallDisplayOrigin = DisplayCutoutController::IsWaterfallDisplay(); 102 DisplayCutoutController::SetIsWaterfallDisplay(true); 103 bool isCompressionEnableOrigin = 104 DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal(); 105 DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true); 106 uint32_t testSizeOrigin = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal(); 107 uint32_t testSize = 20; 108 DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize); 109 ASSERT_EQ(true, DisplayCutoutController::IsWaterfallDisplay()); 110 ASSERT_EQ(true, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal()); 111 ASSERT_EQ(testSize, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal()); 112 DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSizeOrigin); 113 ASSERT_EQ(testSizeOrigin, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal()); 114 DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(isCompressionEnableOrigin); 115 ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal()); 116 DisplayCutoutController::SetIsWaterfallDisplay(isWaterfallDisplayOrigin); 117 ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallDisplay()); 118} 119 120/** 121 * @tc.name: SetWaterfallCompression02 122 * @tc.desc: Set waterfall compression related values with invalid input. 123 * @tc.type: FUNC 124 * @tc.require: issueI5P8CI 125 */ 126HWTEST_F(DisplayTest, SetWaterfallCompression02, Function | SmallTest | Level1) 127{ 128 bool isWaterfallDisplayOrigin = DisplayCutoutController::IsWaterfallDisplay(); 129 DisplayCutoutController::SetIsWaterfallDisplay(true); 130 bool isCompressionEnableOrigin = 131 DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal(); 132 DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true); 133 uint32_t testSizeOrigin = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal(); 134 135 DisplayCutoutController::SetIsWaterfallDisplay(false); 136 DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true); 137 ASSERT_EQ(false, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal()); 138 139 uint32_t testSize = 20; 140 DisplayCutoutController::SetIsWaterfallDisplay(true); 141 DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(false); 142 DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize); 143 ASSERT_EQ(0, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal()); 144 145 DisplayCutoutController::SetIsWaterfallDisplay(false); 146 DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(false); 147 DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize); 148 ASSERT_EQ(0, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal()); 149 150 DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSizeOrigin); 151 ASSERT_EQ(testSizeOrigin, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal()); 152 DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(isCompressionEnableOrigin); 153 ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal()); 154 DisplayCutoutController::SetIsWaterfallDisplay(isWaterfallDisplayOrigin); 155 ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallDisplay()); 156} 157/** 158 * @tc.name: GetName01 159 * @tc.desc: GetName function cover 160 * @tc.type: FUNC 161 */ 162HWTEST_F(DisplayTest, GetName01, Function | SmallTest | Level1) 163{ 164 auto name = defaultDisplay_->GetName(); 165 ASSERT_FALSE(name.empty()); 166} 167 168/** 169 * @tc.name: GetDpi01 170 * @tc.desc: GetDpi function cover 171 * @tc.type: FUNC 172 */ 173HWTEST_F(DisplayTest, GetDpi01, Function | SmallTest | Level1) 174{ 175 auto dpi = defaultDisplay_->GetDpi(); 176 177 auto vpr = defaultDisplay_->GetVirtualPixelRatio(); 178 ASSERT_EQ(vpr * DOT_PER_INCH, dpi); 179} 180 181/** 182 * @tc.name: HasImmersiveWindow 183 * @tc.desc: test HasImmersiveWindow 184 * @tc.type: FUNC 185 */ 186HWTEST_F(DisplayTest, HasImmersiveWindow, Function | SmallTest | Level1) 187{ 188 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 189 EXPECT_CALL(m->Mock(), HasImmersiveWindow(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 190 bool immersive = false; 191 DMError ret = defaultDisplay_->HasImmersiveWindow(immersive); 192 ASSERT_EQ(ret, DMError::DM_OK); 193} 194 195/** 196 * @tc.name: GetPhysicalWidth 197 * @tc.desc: test GetPhysicalWidth 198 * @tc.type: FUNC 199 */ 200HWTEST_F(DisplayTest, GetPhysicalWidth, Function | SmallTest | Level1) 201{ 202 auto physicalwidth = defaultDisplay_->GetPhysicalWidth(); 203 if (SceneBoardJudgement::IsSceneBoardEnabled()) { 204 ASSERT_NE(physicalwidth, 0); 205 } else { 206 ASSERT_EQ(physicalwidth, 0); 207 } 208} 209 210/** 211 * @tc.name: GetPhysicalHeight 212 * @tc.desc: test GetPhysicalHeight 213 * @tc.type: FUNC 214 */ 215HWTEST_F(DisplayTest, GetPhysicalHeight, Function | SmallTest | Level1) 216{ 217 auto physicalheight = defaultDisplay_->GetPhysicalHeight(); 218 if (SceneBoardJudgement::IsSceneBoardEnabled()) { 219 ASSERT_NE(physicalheight, 0); 220 } else { 221 ASSERT_EQ(physicalheight, 0); 222 } 223} 224 225/** 226 * @tc.name: GetAvailableArea 227 * @tc.desc: test GetAvailableArea 228 * @tc.type: FUNC 229 */ 230HWTEST_F(DisplayTest, GetAvailableArea, Function | SmallTest | Level1) 231{ 232 std::unique_ptr<Mocker> m = std::make_unique<Mocker>(); 233 EXPECT_CALL(m->Mock(), GetAvailableArea(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 234 DMRect area; 235 auto res = defaultDisplay_ ->GetAvailableArea(area); 236 ASSERT_EQ(DMError::DM_OK, res); 237} 238 239/** 240 * @tc.name: GetSupportedHDRFormats 241 * @tc.desc: test GetSupportedHDRFormats 242 * @tc.type: FUNC 243 */ 244HWTEST_F(DisplayTest, GetSupportedHDRFormats, Function | SmallTest | Level1) 245{ 246 std::unique_ptr<ScreenMocker> m = std::make_unique<ScreenMocker>(); 247 EXPECT_CALL(m->Mock(), GetSupportedHDRFormats(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 248 std::vector<uint32_t> hdrFormats; 249 auto res = defaultDisplay_ ->GetSupportedHDRFormats(hdrFormats); 250 ASSERT_EQ(DMError::DM_OK, res); 251} 252 253/** 254 * @tc.name: GetSupportedColorSpaces 255 * @tc.desc: test GetSupportedColorSpaces 256 * @tc.type: FUNC 257 */ 258HWTEST_F(DisplayTest, GetSupportedColorSpaces, Function | SmallTest | Level1) 259{ 260 std::unique_ptr<ScreenMocker> m = std::make_unique<ScreenMocker>(); 261 EXPECT_CALL(m->Mock(), GetSupportedColorSpaces(_, _)).Times(1).WillOnce(Return(DMError::DM_OK)); 262 std::vector<uint32_t> colorSpaces; 263 auto res = defaultDisplay_ -> GetSupportedColorSpaces(colorSpaces); 264 ASSERT_EQ(DMError::DM_OK, res); 265} 266} 267} // namespace Rosen 268} // namespace OHOS