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 
16 #include "gtest/gtest.h"
17 
18 #define private public
19 #define protected public
20 #include "core/components_ng/base/frame_node.h"
21 #include "core/components_ng/base/view_stack_processor.h"
22 #include "frameworks/core/components_ng/property/calc_length.h"
23 
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS::Ace::NG {
29 namespace {
30 constexpr double VP_SCALE = 10.0;
31 constexpr double FP_SCALE = 10.0;
32 constexpr double LPX_SCALE = 10.0;
33 constexpr double PARENT_LENGTH = 10.0;
34 } // namespace
35 
36 class CalcLengthTestNg : public testing::Test {
37 public:
SetUpTestCase()38     static void SetUpTestCase() {};
TearDownTestCase()39     static void TearDownTestCase() {};
40 };
41 
42 /**
43  * @tc.name: CalcLengthTestTest001
44  * @tc.desc: NormalizeToPx method test
45  * @tc.type: FUNC
46  */
47 HWTEST_F(CalcLengthTestNg, calcLengthTest001, TestSize.Level1)
48 {
49     CalcLength calc;
50     double result = 0.0;
51 
52     /**
53      * @tc.steps: step1. When the unit of member variable size is px.
54      * @tc.expected: step1. The return value of the NormalizeToPx method is true.
55      */
56     calc.dimension_ = Dimension(100.0, DimensionUnit::PX);
57     auto calcBool = calc.NormalizeToPx(VP_SCALE, FP_SCALE, LPX_SCALE, PARENT_LENGTH, result);
58     EXPECT_TRUE(calcBool);
59     calc.SetCalcValue("calcLengthTest");
60     calcBool = calc.NormalizeToPx(VP_SCALE, FP_SCALE, LPX_SCALE, PARENT_LENGTH, result);
61     EXPECT_TRUE(calcBool);
62 
63     /**
64      * @tc.steps: step1. When the unit of member variable size is vp.
65      * @tc.expected: step1. The return value of the NormalizeToPx method is true.
66      */
67     calc.dimension_ = Dimension(100.0, DimensionUnit::VP);
68     calc.NormalizeToPx(VP_SCALE, FP_SCALE, LPX_SCALE, PARENT_LENGTH, result);
69     EXPECT_TRUE(calcBool);
70 }
71 } // namespace OHOS::Ace::NG