1 /* 2 * Copyright (c) 2024 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 "ui_rotation.h" 18 #include "log/log.h" 19 #include "securec.h" 20 21 using namespace testing::ext; 22 using namespace Updater; 23 24 namespace UpdaterUt { 25 class UiRotationUnitTest : public testing::Test { 26 public: SetUpTestCase(void)27 static void SetUpTestCase(void) {} TearDownTestCase(void)28 static void TearDownTestCase(void) {} SetUp()29 void SetUp() override {} TearDown()30 void TearDown() override {} 31 }; 32 33 HWTEST_F(UiRotationUnitTest, test_init_rotation, TestSize.Level0) 34 { 35 int realWidth = 100; 36 int realHeight = 500; 37 uint8_t pixelBytes = 0; 38 std::vector<UI_ROTATION_DEGREE> degrees = { 39 UI_ROTATION_DEGREE::UI_ROTATION_0, 40 UI_ROTATION_DEGREE::UI_ROTATION_90, 41 UI_ROTATION_DEGREE::UI_ROTATION_180, 42 UI_ROTATION_DEGREE::UI_ROTATION_270 }; 43 for (auto degree : degrees) { 44 UiRotation::GetInstance().SetDegree(degree); 45 UiRotation::GetInstance().InitRotation(realWidth, realHeight, pixelBytes); 46 if (int(degree) % 2 == 1) { 47 EXPECT_EQ(realWidth, UiRotation::GetInstance().GetHeight()); 48 EXPECT_EQ(realHeight, UiRotation::GetInstance().GetWidth()); 49 } else { 50 EXPECT_EQ(realWidth, UiRotation::GetInstance().GetWidth()); 51 EXPECT_EQ(realHeight, UiRotation::GetInstance().GetHeight()); 52 } 53 } 54 } 55 }