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 #include "screen_property.h" 16 #include <gtest/gtest.h> 17 18 // using namespace FRAME_TRACE; 19 using namespace testing; 20 using namespace testing::ext; 21 namespace OHOS { 22 namespace Rosen { 23 class ScreenPropertyTest : public testing::Test { 24 public: ScreenPropertyTest()25 ScreenPropertyTest() {} ~ScreenPropertyTest()26 ~ScreenPropertyTest() {} 27 }; 28 29 namespace { 30 /** 31 * @tc.name: SetScreenRotation 32 * @tc.desc: normal function 33 * @tc.type: FUNC 34 */ 35 HWTEST_F(ScreenPropertyTest, SetScreenRotation, Function | SmallTest | Level2) 36 { 37 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenRotation start"; 38 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 39 int64_t ret = 0; 40 Rotation rotation = Rotation::ROTATION_0; 41 property->SetScreenRotation(rotation); 42 43 rotation = Rotation::ROTATION_90; 44 property->SetScreenRotation(rotation); 45 46 rotation = Rotation::ROTATION_180; 47 property->SetScreenRotation(rotation); 48 49 rotation = Rotation::ROTATION_270; 50 property->SetScreenRotation(rotation); 51 ASSERT_EQ(ret, 0); 52 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenRotation end"; 53 } 54 55 /** 56 * @tc.name: UpdateVirtualPixelRatio 57 * @tc.desc: normal function 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(ScreenPropertyTest, UpdateVirtualPixelRatio, Function | SmallTest | Level2) 61 { 62 GTEST_LOG_(INFO) << "ScreenPropertyTest: UpdateVirtualPixelRatio start"; 63 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 64 int64_t ret = 0; 65 RRect bounds; 66 bounds.rect_.width_ = 1344; 67 bounds.rect_.height_ = 2772; 68 69 property->UpdateVirtualPixelRatio(bounds); 70 71 bounds.rect_.height_ = 1111; 72 property->UpdateVirtualPixelRatio(bounds); 73 74 bounds.rect_.width_ = 1111; 75 bounds.rect_.height_ = 2772; 76 property->UpdateVirtualPixelRatio(bounds); 77 78 bounds.rect_.width_ = 1111; 79 bounds.rect_.height_ = 1111; 80 property->UpdateVirtualPixelRatio(bounds); 81 ASSERT_EQ(ret, 0); 82 GTEST_LOG_(INFO) << "ScreenPropertyTest: UpdateVirtualPixelRatio end"; 83 } 84 85 /** 86 * @tc.name: SetBounds 87 * @tc.desc: normal function 88 * @tc.type: FUNC 89 */ 90 HWTEST_F(ScreenPropertyTest, SetBounds, Function | SmallTest | Level2) 91 { 92 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetBounds start"; 93 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 94 int64_t ret = 0; 95 RRect bounds; 96 bounds.rect_.width_ = 1344; 97 bounds.rect_.height_ = 2772; 98 99 uint32_t phyWidth = UINT32_MAX; 100 property->SetPhyWidth(phyWidth); 101 uint32_t phyHeigth = UINT32_MAX; 102 property->SetPhyHeight(phyHeigth); 103 property->SetBounds(bounds); 104 105 bounds.rect_.width_ = 2772; 106 bounds.rect_.height_ = 1344; 107 108 uint32_t phyWidth1 = 2772; 109 property->SetPhyWidth(phyWidth1); 110 uint32_t phyHeigth1 = 1344; 111 property->SetPhyHeight(phyHeigth1); 112 property->SetBounds(bounds); 113 ASSERT_EQ(ret, 0); 114 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetBounds end"; 115 } 116 117 /** 118 * @tc.name: CalculateXYDpi 119 * @tc.desc: normal function 120 * @tc.type: FUNC 121 */ 122 HWTEST_F(ScreenPropertyTest, CalculateXYDpi, Function | SmallTest | Level2) 123 { 124 GTEST_LOG_(INFO) << "ScreenPropertyTest: CalculateXYDpi start"; 125 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 126 uint32_t phyWidth = 0; 127 uint32_t phyHeight = 0; 128 int ret = 0; 129 property->CalculateXYDpi(phyWidth, phyHeight); 130 phyWidth = 1; 131 phyHeight = 1; 132 property->CalculateXYDpi(phyWidth, phyHeight); 133 ASSERT_EQ(ret, 0); 134 delete property; 135 GTEST_LOG_(INFO) << "ScreenPropertyTest: CalculateXYDpi end"; 136 } 137 138 /** 139 * @tc.name: SetOffsetX 140 * @tc.desc: normal function 141 * @tc.type: FUNC 142 */ 143 HWTEST_F(ScreenPropertyTest, SetOffsetX, Function | SmallTest | Level2) 144 { 145 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffsetX start"; 146 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 147 int32_t offsetX = 0; 148 property->SetOffsetX(offsetX); 149 int32_t ret = property->GetOffsetX(); 150 ASSERT_EQ(ret, offsetX); 151 delete property; 152 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffsetX end"; 153 } 154 155 /** 156 * @tc.name: SetOffsetY 157 * @tc.desc: normal function 158 * @tc.type: FUNC 159 */ 160 HWTEST_F(ScreenPropertyTest, SetOffsetY, Function | SmallTest | Level2) 161 { 162 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffsetY start"; 163 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 164 int32_t offsetY = 0; 165 property->SetOffsetY(offsetY); 166 int32_t ret = property->GetOffsetY(); 167 ASSERT_EQ(ret, offsetY); 168 delete property; 169 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffsetY end"; 170 } 171 172 /** 173 * @tc.name: SetOffset 174 * @tc.desc: normal function 175 * @tc.type: FUNC 176 */ 177 HWTEST_F(ScreenPropertyTest, SetOffset, Function | SmallTest | Level2) 178 { 179 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffset start"; 180 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 181 int32_t offsetX = 0; 182 int32_t offsetY = 0; 183 property->SetOffset(offsetX, offsetY); 184 int32_t ret_x = property->GetOffsetX(); 185 int32_t ret_y = property->GetOffsetY(); 186 ASSERT_EQ(ret_x, offsetX); 187 ASSERT_EQ(ret_y, offsetY); 188 delete property; 189 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetOffset end"; 190 } 191 192 /** 193 * @tc.name: SetScreenRequestedOrientation 194 * @tc.desc: normal function 195 * @tc.type: FUNC 196 */ 197 HWTEST_F(ScreenPropertyTest, SetScreenRequestedOrientation, Function | SmallTest | Level2) 198 { 199 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenRequestedOrientation start"; 200 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 201 Orientation orientation = Orientation::UNSPECIFIED; 202 property->SetScreenRequestedOrientation(orientation); 203 Orientation ret = property->GetScreenRequestedOrientation(); 204 ASSERT_EQ(ret, orientation); 205 delete property; 206 GTEST_LOG_(INFO) << "ScreenPropertyTest: SetScreenRequestedOrientation end"; 207 } 208 209 /** 210 * @tc.name: GetPhyHeight 211 * @tc.desc: normal function 212 * @tc.type: FUNC 213 */ 214 HWTEST_F(ScreenPropertyTest, GetPhyHeight, Function | SmallTest | Level2) 215 { 216 GTEST_LOG_(INFO) << "ScreenPropertyTest: GetPhyHeight start"; 217 ScreenProperty* property = new(std::nothrow) ScreenProperty(); 218 uint32_t phyHeight = 1; 219 property->SetPhyHeight(phyHeight); 220 int32_t ret = property->GetPhyHeight(); 221 ASSERT_EQ(ret, phyHeight); 222 delete property; 223 GTEST_LOG_(INFO) << "ScreenPropertyTest: GetPhyHeight end"; 224 } 225 } // namespace 226 } // namespace Rosen 227 } // namespace OHOS 228