• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <memory>
17 #include <limits>
18 
19 #include "gtest/gtest.h"
20 #include "ui/base/geometry/ng/size_t.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS::Ace::NG {
26 
27 class SizeTTest : public testing::Test {};
28 
29 /**
30  * @tc.name: SizeT_ToString_Normal_Case
31  * @tc.desc: Test the function ToString of the class SizeT.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(SizeTTest, SizeT_ToString_Normal_Case, TestSize.Level1)
35 {
36     SizeT<double> sizeD(10.5, 20.75);
37     std::string expected = "[10.50 x 20.75]";
38     EXPECT_EQ(sizeD.ToString(), expected);
39 }
40 
41 /**
42  * @tc.name: SizeT_ToString_Boundary_Case_With_Zero
43  * @tc.desc: Test the function ToString of the class SizeT.
44  * @tc.type: FUNC
45  */
46 HWTEST_F(SizeTTest, SizeT_ToString_Boundary_Case_With_Zero, TestSize.Level1)
47 {
48     SizeT<double> sizeD(0, 20.75);
49     std::string expected = "[0.00 x 20.75]";
50     EXPECT_EQ(sizeD.ToString(), expected);
51 
52     sizeD = SizeT<double>(10.5, 0);
53     expected = "[10.50 x 0.00]";
54     EXPECT_EQ(sizeD.ToString(), expected);
55 
56     sizeD = SizeT<double>(0, 0);
57     expected = "[0.00 x 0.00]";
58     EXPECT_EQ(sizeD.ToString(), expected);
59 }
60 
61 /**
62  * @tc.name: SizeT_ToString_Boundary_Case_With_Nan_And_Inf
63  * @tc.desc: Test the function ToString of the class SizeT.
64  * @tc.type: FUNC
65  */
66 HWTEST_F(SizeTTest, SizeT_ToString_Boundary_Case_With_Nan_And_Inf, TestSize.Level1)
67 {
68     SizeT<double> sizeD(std::numeric_limits<double>::infinity(), 20.75);
69     std::string expected = "[inf x 20.75]";
70     EXPECT_EQ(sizeD.ToString(), expected);
71 
72     sizeD = SizeT<double>(10.5, -std::numeric_limits<double>::infinity());
73     expected = "[10.50 x -inf]";
74     EXPECT_EQ(sizeD.ToString(), expected);
75 
76     sizeD = SizeT<double>(std::numeric_limits<double>::quiet_NaN(), -std::numeric_limits<double>::quiet_NaN());
77     expected = "[nan x -nan]";
78     EXPECT_EQ(sizeD.ToString(), expected);
79 }
80 
81 } // namespace OHOS::Ace
82