123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#include <memory> 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci#include "gtest/gtest.h" 1923b3eb3cSopenharmony_ci#include "test/mock/core/pipeline/mock_pipeline_context.h" 2023b3eb3cSopenharmony_ci#include "core/components/common/properties/text_style.h" 2123b3eb3cSopenharmony_ci#include "base/geometry/dimension.h" 2223b3eb3cSopenharmony_ci 2323b3eb3cSopenharmony_ciusing namespace testing; 2423b3eb3cSopenharmony_ciusing namespace testing::ext; 2523b3eb3cSopenharmony_ci 2623b3eb3cSopenharmony_cinamespace OHOS::Ace { 2723b3eb3cSopenharmony_cinamespace { 2823b3eb3cSopenharmony_ciconst double DEFAULT_DOUBLE = 1.0; 2923b3eb3cSopenharmony_ciconst double ZERO_DOUBLE = 0.0; 3023b3eb3cSopenharmony_ci 3123b3eb3cSopenharmony_ciconst Dimension DIMENSION_PX(DEFAULT_DOUBLE, DimensionUnit::PX); 3223b3eb3cSopenharmony_ciconst Dimension DIMENSION_VP(DEFAULT_DOUBLE, DimensionUnit::VP); 3323b3eb3cSopenharmony_ciconst Dimension DIMENSION_FP(DEFAULT_DOUBLE, DimensionUnit::FP); 3423b3eb3cSopenharmony_ciconst Dimension DIMENSION_LPX(DEFAULT_DOUBLE, DimensionUnit::LPX); 3523b3eb3cSopenharmony_ciconst Dimension DIMENSION_PCT(DEFAULT_DOUBLE, DimensionUnit::PERCENT); 3623b3eb3cSopenharmony_ciconst Dimension DIMENSION_AUTO(DEFAULT_DOUBLE, DimensionUnit::AUTO); 3723b3eb3cSopenharmony_ciconst Dimension DIMENSION_CALC(DEFAULT_DOUBLE, DimensionUnit::CALC); 3823b3eb3cSopenharmony_ciconst Dimension DIMENSION_NONE(DEFAULT_DOUBLE, DimensionUnit::NONE); 3923b3eb3cSopenharmony_ci 4023b3eb3cSopenharmony_ciconst std::string DIMENSION_PX_STR = StringUtils::DoubleToString(DEFAULT_DOUBLE).append("px"); 4123b3eb3cSopenharmony_ciconst std::string DIMENSION_VP_STR = StringUtils::DoubleToString(DEFAULT_DOUBLE).append("vp"); 4223b3eb3cSopenharmony_ciconst std::string DIMENSION_FP_STR = StringUtils::DoubleToString(DEFAULT_DOUBLE).append("fp"); 4323b3eb3cSopenharmony_ciconst std::string DIMENSION_LPX_STR = StringUtils::DoubleToString(DEFAULT_DOUBLE).append("lpx"); 4423b3eb3cSopenharmony_ciconst std::string DIMENSION_PCT_STR = StringUtils::DoubleToString(DEFAULT_DOUBLE * 100).append("%"); 4523b3eb3cSopenharmony_ciconst std::string DIMENSION_AUTO_STR = StringUtils::DoubleToString(DEFAULT_DOUBLE).append("auto"); 4623b3eb3cSopenharmony_ciconst std::string DIMENSION_NONE_STR = StringUtils::DoubleToString(DEFAULT_DOUBLE).append("none"); 4723b3eb3cSopenharmony_ci} // namespace 4823b3eb3cSopenharmony_ci 4923b3eb3cSopenharmony_ciclass DimensionTest : public testing::Test { 5023b3eb3cSopenharmony_cipublic: 5123b3eb3cSopenharmony_ci static void SetUpTestSuite() 5223b3eb3cSopenharmony_ci { 5323b3eb3cSopenharmony_ci NG::MockPipelineContext::SetUp(); 5423b3eb3cSopenharmony_ci } 5523b3eb3cSopenharmony_ci static void TearDownTestSuite() 5623b3eb3cSopenharmony_ci { 5723b3eb3cSopenharmony_ci NG::MockPipelineContext::TearDown(); 5823b3eb3cSopenharmony_ci } 5923b3eb3cSopenharmony_ci}; 6023b3eb3cSopenharmony_ci 6123b3eb3cSopenharmony_ci/** 6223b3eb3cSopenharmony_ci * @tc.name: DimensionTest001 6323b3eb3cSopenharmony_ci * @tc.desc: Test the function ConvertToVp of the class Dimension. 6423b3eb3cSopenharmony_ci * @tc.type: FUNC 6523b3eb3cSopenharmony_ci */ 6623b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest001, TestSize.Level1) 6723b3eb3cSopenharmony_ci{ 6823b3eb3cSopenharmony_ci /** 6923b3eb3cSopenharmony_ci * @tc.steps1: Test the function ConvertToVp of the class Dimension. 7023b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE or ZERO_DOUBLE 7123b3eb3cSopenharmony_ci */ 7223b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_PX.ConvertToVp(), DEFAULT_DOUBLE); 7323b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_VP.ConvertToVp(), DEFAULT_DOUBLE); 7423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_FP.ConvertToVp(), DEFAULT_DOUBLE); 7523b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_LPX.ConvertToVp(), DEFAULT_DOUBLE); 7623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_PCT.ConvertToVp(), ZERO_DOUBLE); 7723b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_AUTO.ConvertToVp(), ZERO_DOUBLE); 7823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_CALC.ConvertToVp(), ZERO_DOUBLE); 7923b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_NONE.ConvertToVp(), DEFAULT_DOUBLE); 8023b3eb3cSopenharmony_ci} 8123b3eb3cSopenharmony_ci 8223b3eb3cSopenharmony_ci/** 8323b3eb3cSopenharmony_ci * @tc.name: DimensionTest002 8423b3eb3cSopenharmony_ci * @tc.desc: Test the function ConvertToPx of the class Dimension. 8523b3eb3cSopenharmony_ci * @tc.type: FUNC 8623b3eb3cSopenharmony_ci */ 8723b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest002, TestSize.Level1) 8823b3eb3cSopenharmony_ci{ 8923b3eb3cSopenharmony_ci /** 9023b3eb3cSopenharmony_ci * @tc.steps1: Test the function ConvertToPx of the class Dimension. 9123b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE or ZERO_DOUBLE. 9223b3eb3cSopenharmony_ci */ 9323b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_PX.ConvertToPx(), DEFAULT_DOUBLE); 9423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_VP.ConvertToPx(), DEFAULT_DOUBLE); 9523b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_FP.ConvertToPx(), DEFAULT_DOUBLE); 9623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_LPX.ConvertToPx(), DEFAULT_DOUBLE); 9723b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_PCT.ConvertToPx(), ZERO_DOUBLE); 9823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_AUTO.ConvertToPx(), ZERO_DOUBLE); 9923b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_CALC.ConvertToPx(), ZERO_DOUBLE); 10023b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_NONE.ConvertToPx(), DEFAULT_DOUBLE); 10123b3eb3cSopenharmony_ci} 10223b3eb3cSopenharmony_ci 10323b3eb3cSopenharmony_ci/** 10423b3eb3cSopenharmony_ci * @tc.name: DimensionTest003 10523b3eb3cSopenharmony_ci * @tc.desc: Test the function ToString of the class Dimension. 10623b3eb3cSopenharmony_ci * @tc.type: FUNC 10723b3eb3cSopenharmony_ci */ 10823b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest003, TestSize.Level1) 10923b3eb3cSopenharmony_ci{ 11023b3eb3cSopenharmony_ci /** 11123b3eb3cSopenharmony_ci * @tc.steps1: Test the function ToString of the class Dimension. 11223b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DIMENSION_STR of PX, VP, FP, LPX, PCT and AUTO. 11323b3eb3cSopenharmony_ci */ 11423b3eb3cSopenharmony_ci EXPECT_EQ(DIMENSION_PX.ToString(), DIMENSION_PX_STR); 11523b3eb3cSopenharmony_ci EXPECT_EQ(DIMENSION_VP.ToString(), DIMENSION_VP_STR); 11623b3eb3cSopenharmony_ci EXPECT_EQ(DIMENSION_FP.ToString(), DIMENSION_FP_STR); 11723b3eb3cSopenharmony_ci EXPECT_EQ(DIMENSION_LPX.ToString(), DIMENSION_LPX_STR); 11823b3eb3cSopenharmony_ci EXPECT_EQ(DIMENSION_PCT.ToString(), DIMENSION_PCT_STR); 11923b3eb3cSopenharmony_ci EXPECT_EQ(DIMENSION_AUTO.ToString(), DIMENSION_AUTO_STR); 12023b3eb3cSopenharmony_ci Dimension dimension(DEFAULT_DOUBLE); 12123b3eb3cSopenharmony_ci dimension.SetUnit(static_cast<DimensionUnit>(7)); 12223b3eb3cSopenharmony_ci EXPECT_EQ(dimension.ToString(), DIMENSION_PX_STR); 12323b3eb3cSopenharmony_ci dimension.SetUnit(DimensionUnit::NONE); 12423b3eb3cSopenharmony_ci EXPECT_EQ(dimension.ToString(), DIMENSION_NONE_STR); 12523b3eb3cSopenharmony_ci} 12623b3eb3cSopenharmony_ci 12723b3eb3cSopenharmony_ci/** 12823b3eb3cSopenharmony_ci * @tc.name: DimensionTest004 12923b3eb3cSopenharmony_ci * @tc.desc: Test the function NormalizeToPx of the class Dimension with -DEFAULT_DOUBLE. 13023b3eb3cSopenharmony_ci * @tc.type: FUNC 13123b3eb3cSopenharmony_ci */ 13223b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest004, TestSize.Level1) 13323b3eb3cSopenharmony_ci{ 13423b3eb3cSopenharmony_ci /** 13523b3eb3cSopenharmony_ci * @tc.steps1: Test the function NormalizeToPx of the class Dimension with DIMENSION_PX. 13623b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE. 13723b3eb3cSopenharmony_ci */ 13823b3eb3cSopenharmony_ci double result = 0; 13923b3eb3cSopenharmony_ci EXPECT_TRUE(DIMENSION_PX.NormalizeToPx(-DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, result)); 14023b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, DEFAULT_DOUBLE); 14123b3eb3cSopenharmony_ci 14223b3eb3cSopenharmony_ci /** 14323b3eb3cSopenharmony_ci * @tc.steps2: Test the function NormalizeToPx of the class Dimension with DIMENSION_VP. 14423b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to ZERO_DOUBLE. 14523b3eb3cSopenharmony_ci */ 14623b3eb3cSopenharmony_ci result = 0; 14723b3eb3cSopenharmony_ci EXPECT_FALSE( 14823b3eb3cSopenharmony_ci DIMENSION_VP.NormalizeToPx(-DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, result)); 14923b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, ZERO_DOUBLE); 15023b3eb3cSopenharmony_ci 15123b3eb3cSopenharmony_ci /** 15223b3eb3cSopenharmony_ci * @tc.steps3: Test the function NormalizeToPx of the class Dimension with DIMENSION_FP. 15323b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to ZERO_DOUBLE. 15423b3eb3cSopenharmony_ci */ 15523b3eb3cSopenharmony_ci result = 0; 15623b3eb3cSopenharmony_ci EXPECT_FALSE( 15723b3eb3cSopenharmony_ci DIMENSION_FP.NormalizeToPx(-DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, result)); 15823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, ZERO_DOUBLE); 15923b3eb3cSopenharmony_ci 16023b3eb3cSopenharmony_ci /** 16123b3eb3cSopenharmony_ci * @tc.steps4: Test the function NormalizeToPx of the class Dimension with DIMENSION_LPX. 16223b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to ZERO_DOUBLE. 16323b3eb3cSopenharmony_ci */ 16423b3eb3cSopenharmony_ci result = 0; 16523b3eb3cSopenharmony_ci EXPECT_FALSE( 16623b3eb3cSopenharmony_ci DIMENSION_LPX.NormalizeToPx(-DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, result)); 16723b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, ZERO_DOUBLE); 16823b3eb3cSopenharmony_ci 16923b3eb3cSopenharmony_ci /** 17023b3eb3cSopenharmony_ci * @tc.steps5: Test the function NormalizeToPx of the class Dimension with DIMENSION_PCT. 17123b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to ZERO_DOUBLE. 17223b3eb3cSopenharmony_ci */ 17323b3eb3cSopenharmony_ci result = 0; 17423b3eb3cSopenharmony_ci EXPECT_FALSE( 17523b3eb3cSopenharmony_ci DIMENSION_PCT.NormalizeToPx(-DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, result)); 17623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, ZERO_DOUBLE); 17723b3eb3cSopenharmony_ci 17823b3eb3cSopenharmony_ci /** 17923b3eb3cSopenharmony_ci * @tc.steps6: Test the function NormalizeToPx of the class Dimension with DIMENSION_AUTO. 18023b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to ZERO_DOUBLE. 18123b3eb3cSopenharmony_ci */ 18223b3eb3cSopenharmony_ci result = 0; 18323b3eb3cSopenharmony_ci EXPECT_FALSE( 18423b3eb3cSopenharmony_ci DIMENSION_AUTO.NormalizeToPx(-DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, result)); 18523b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, ZERO_DOUBLE); 18623b3eb3cSopenharmony_ci 18723b3eb3cSopenharmony_ci /** 18823b3eb3cSopenharmony_ci * @tc.steps7: Test the function NormalizeToPx of the class Dimension with DIMENSION_CALC. 18923b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to ZERO_DOUBLE. 19023b3eb3cSopenharmony_ci */ 19123b3eb3cSopenharmony_ci result = 0; 19223b3eb3cSopenharmony_ci EXPECT_FALSE( 19323b3eb3cSopenharmony_ci DIMENSION_CALC.NormalizeToPx(-DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, -DEFAULT_DOUBLE, result)); 19423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, ZERO_DOUBLE); 19523b3eb3cSopenharmony_ci} 19623b3eb3cSopenharmony_ci 19723b3eb3cSopenharmony_ci/** 19823b3eb3cSopenharmony_ci * @tc.name: DimensionTest005 19923b3eb3cSopenharmony_ci * @tc.desc: Test the function NormalizeToPx of the class Dimension with DEFAULT_DOUBLE. 20023b3eb3cSopenharmony_ci * @tc.type: FUNC 20123b3eb3cSopenharmony_ci */ 20223b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest005, TestSize.Level1) 20323b3eb3cSopenharmony_ci{ 20423b3eb3cSopenharmony_ci /** 20523b3eb3cSopenharmony_ci * @tc.steps1: Test the function NormalizeToPx of the class Dimension with DIMENSION_PX. 20623b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE. 20723b3eb3cSopenharmony_ci */ 20823b3eb3cSopenharmony_ci double result = 0; 20923b3eb3cSopenharmony_ci EXPECT_TRUE(DIMENSION_PX.NormalizeToPx(DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, result)); 21023b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, DEFAULT_DOUBLE); 21123b3eb3cSopenharmony_ci 21223b3eb3cSopenharmony_ci /** 21323b3eb3cSopenharmony_ci * @tc.steps2: Test the function NormalizeToPx of the class Dimension with DIMENSION_VP. 21423b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE. 21523b3eb3cSopenharmony_ci */ 21623b3eb3cSopenharmony_ci result = 0; 21723b3eb3cSopenharmony_ci EXPECT_TRUE(DIMENSION_VP.NormalizeToPx(DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, result)); 21823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, DEFAULT_DOUBLE); 21923b3eb3cSopenharmony_ci 22023b3eb3cSopenharmony_ci /** 22123b3eb3cSopenharmony_ci * @tc.steps3: Test the function NormalizeToPx of the class Dimension with DIMENSION_FP. 22223b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE. 22323b3eb3cSopenharmony_ci */ 22423b3eb3cSopenharmony_ci result = 0; 22523b3eb3cSopenharmony_ci EXPECT_TRUE(DIMENSION_FP.NormalizeToPx(DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, result)); 22623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, DEFAULT_DOUBLE); 22723b3eb3cSopenharmony_ci 22823b3eb3cSopenharmony_ci /** 22923b3eb3cSopenharmony_ci * @tc.steps4: Test the function NormalizeToPx of the class Dimension with DIMENSION_LPX. 23023b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE. 23123b3eb3cSopenharmony_ci */ 23223b3eb3cSopenharmony_ci result = 0; 23323b3eb3cSopenharmony_ci EXPECT_TRUE(DIMENSION_LPX.NormalizeToPx(DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, result)); 23423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, DEFAULT_DOUBLE); 23523b3eb3cSopenharmony_ci 23623b3eb3cSopenharmony_ci /** 23723b3eb3cSopenharmony_ci * @tc.steps5: Test the function NormalizeToPx of the class Dimension with DIMENSION_PCT. 23823b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE. 23923b3eb3cSopenharmony_ci */ 24023b3eb3cSopenharmony_ci result = 0; 24123b3eb3cSopenharmony_ci EXPECT_TRUE(DIMENSION_PCT.NormalizeToPx(DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, result)); 24223b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, DEFAULT_DOUBLE); 24323b3eb3cSopenharmony_ci 24423b3eb3cSopenharmony_ci /** 24523b3eb3cSopenharmony_ci * @tc.steps6: Test the function NormalizeToPx of the class Dimension with DIMENSION_AUTO. 24623b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to ZERO_DOUBLE. 24723b3eb3cSopenharmony_ci */ 24823b3eb3cSopenharmony_ci result = 0; 24923b3eb3cSopenharmony_ci EXPECT_FALSE(DIMENSION_AUTO.NormalizeToPx(DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, result)); 25023b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, ZERO_DOUBLE); 25123b3eb3cSopenharmony_ci 25223b3eb3cSopenharmony_ci /** 25323b3eb3cSopenharmony_ci * @tc.steps7: Test the function NormalizeToPx of the class Dimension with DIMENSION_CALC. 25423b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to ZERO_DOUBLE. 25523b3eb3cSopenharmony_ci */ 25623b3eb3cSopenharmony_ci result = 0; 25723b3eb3cSopenharmony_ci EXPECT_FALSE(DIMENSION_CALC.NormalizeToPx(DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, DEFAULT_DOUBLE, result)); 25823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(result, ZERO_DOUBLE); 25923b3eb3cSopenharmony_ci} 26023b3eb3cSopenharmony_ci 26123b3eb3cSopenharmony_ci/** 26223b3eb3cSopenharmony_ci * @tc.name: DimensionTest006 26323b3eb3cSopenharmony_ci * @tc.desc: ConvertToFp(). 26423b3eb3cSopenharmony_ci * @tc.type: FUNC 26523b3eb3cSopenharmony_ci */ 26623b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest006, TestSize.Level1) 26723b3eb3cSopenharmony_ci{ 26823b3eb3cSopenharmony_ci /** 26923b3eb3cSopenharmony_ci * @tc.steps1: Test the function ConvertToFp of the class Dimension. 27023b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE or ZERO_DOUBLE 27123b3eb3cSopenharmony_ci */ 27223b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_PX.ConvertToFp(), DEFAULT_DOUBLE); 27323b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_VP.ConvertToFp(), DEFAULT_DOUBLE); 27423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_FP.ConvertToFp(), DEFAULT_DOUBLE); 27523b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_LPX.ConvertToFp(), DEFAULT_DOUBLE); 27623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_PCT.ConvertToFp(), ZERO_DOUBLE); 27723b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_AUTO.ConvertToFp(), ZERO_DOUBLE); 27823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_CALC.ConvertToFp(), ZERO_DOUBLE); 27923b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(DIMENSION_NONE.ConvertToFp(), DEFAULT_DOUBLE); 28023b3eb3cSopenharmony_ci} 28123b3eb3cSopenharmony_ci 28223b3eb3cSopenharmony_ci/** 28323b3eb3cSopenharmony_ci * @tc.name: DimensionTest007 28423b3eb3cSopenharmony_ci * @tc.desc: FromString(). 28523b3eb3cSopenharmony_ci * @tc.type: FUNC 28623b3eb3cSopenharmony_ci */ 28723b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest007, TestSize.Level1) 28823b3eb3cSopenharmony_ci{ 28923b3eb3cSopenharmony_ci /** 29023b3eb3cSopenharmony_ci * @tc.steps1: Test the function FromString of the class Dimension. 29123b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE or ZERO_DOUBLE 29223b3eb3cSopenharmony_ci */ 29323b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(Dimension::FromString(DIMENSION_PX_STR).Value(), DEFAULT_DOUBLE); 29423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(Dimension::FromString(DIMENSION_VP_STR).Value(), DEFAULT_DOUBLE); 29523b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(Dimension::FromString(DIMENSION_FP_STR).Value(), DEFAULT_DOUBLE); 29623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(Dimension::FromString(DIMENSION_LPX_STR).Value(), DEFAULT_DOUBLE); 29723b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(Dimension::FromString(DIMENSION_PCT_STR).Value(), DEFAULT_DOUBLE); 29823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(Dimension::FromString(DIMENSION_AUTO_STR).Value(), DEFAULT_DOUBLE); 29923b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(Dimension::FromString("").Value(), ZERO_DOUBLE); 30023b3eb3cSopenharmony_ci} 30123b3eb3cSopenharmony_ci 30223b3eb3cSopenharmony_ci/** 30323b3eb3cSopenharmony_ci * @tc.name: DimensionTest008 30423b3eb3cSopenharmony_ci * @tc.desc: ConvertToPxWithSize(). 30523b3eb3cSopenharmony_ci * @tc.type: FUNC 30623b3eb3cSopenharmony_ci */ 30723b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest008, TestSize.Level1) 30823b3eb3cSopenharmony_ci{ 30923b3eb3cSopenharmony_ci /** 31023b3eb3cSopenharmony_ci * @tc.steps1: Test the function ConvertToPxWithSize of the class Dimension. 31123b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE * size. 31223b3eb3cSopenharmony_ci */ 31323b3eb3cSopenharmony_ci Dimension dimension(DEFAULT_DOUBLE, DimensionUnit::PERCENT); 31423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(dimension.ConvertToPxWithSize(5.0), DEFAULT_DOUBLE * 5.0); 31523b3eb3cSopenharmony_ci dimension.SetUnit(DimensionUnit::PX); 31623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(dimension.ConvertToPxWithSize(5.0), DEFAULT_DOUBLE); 31723b3eb3cSopenharmony_ci} 31823b3eb3cSopenharmony_ci 31923b3eb3cSopenharmony_ci/** 32023b3eb3cSopenharmony_ci * @tc.name: DimensionTest009 32123b3eb3cSopenharmony_ci * @tc.desc: ConvertToPxDistribute(). 32223b3eb3cSopenharmony_ci * @tc.type: FUNC 32323b3eb3cSopenharmony_ci */ 32423b3eb3cSopenharmony_ciHWTEST_F(DimensionTest, DimensionTest009, TestSize.Level1) 32523b3eb3cSopenharmony_ci{ 32623b3eb3cSopenharmony_ci /** 32723b3eb3cSopenharmony_ci * @tc.steps1: Test the function ConvertToPxDistribute of the class Dimension. 32823b3eb3cSopenharmony_ci * @tc.expected: The return values are equal to DEFAULT_DOUBLE * size. 32923b3eb3cSopenharmony_ci */ 33023b3eb3cSopenharmony_ci TextStyle textStyle; 33123b3eb3cSopenharmony_ci auto defaultFp = DIMENSION_FP.ConvertToPxDistribute(textStyle.GetMaxFontScale(), textStyle.GetMinFontScale()); 33223b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(defaultFp, DEFAULT_DOUBLE); 33323b3eb3cSopenharmony_ci} 33423b3eb3cSopenharmony_ci} // namespace OHOS::Ace 335