/* * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include "gtest/gtest.h" #include "ui/base/geometry/ng/size_t.h" using namespace testing; using namespace testing::ext; namespace OHOS::Ace::NG { class SizeTTest : public testing::Test {}; /** * @tc.name: SizeT_ToString_Normal_Case * @tc.desc: Test the function ToString of the class SizeT. * @tc.type: FUNC */ HWTEST_F(SizeTTest, SizeT_ToString_Normal_Case, TestSize.Level1) { SizeT sizeD(10.5, 20.75); std::string expected = "[10.50 x 20.75]"; EXPECT_EQ(sizeD.ToString(), expected); } /** * @tc.name: SizeT_ToString_Boundary_Case_With_Zero * @tc.desc: Test the function ToString of the class SizeT. * @tc.type: FUNC */ HWTEST_F(SizeTTest, SizeT_ToString_Boundary_Case_With_Zero, TestSize.Level1) { SizeT sizeD(0, 20.75); std::string expected = "[0.00 x 20.75]"; EXPECT_EQ(sizeD.ToString(), expected); sizeD = SizeT(10.5, 0); expected = "[10.50 x 0.00]"; EXPECT_EQ(sizeD.ToString(), expected); sizeD = SizeT(0, 0); expected = "[0.00 x 0.00]"; EXPECT_EQ(sizeD.ToString(), expected); } /** * @tc.name: SizeT_ToString_Boundary_Case_With_Nan_And_Inf * @tc.desc: Test the function ToString of the class SizeT. * @tc.type: FUNC */ HWTEST_F(SizeTTest, SizeT_ToString_Boundary_Case_With_Nan_And_Inf, TestSize.Level1) { SizeT sizeD(std::numeric_limits::infinity(), 20.75); std::string expected = "[inf x 20.75]"; EXPECT_EQ(sizeD.ToString(), expected); sizeD = SizeT(10.5, -std::numeric_limits::infinity()); expected = "[10.50 x -inf]"; EXPECT_EQ(sizeD.ToString(), expected); sizeD = SizeT(std::numeric_limits::quiet_NaN(), -std::numeric_limits::quiet_NaN()); expected = "[nan x -nan]"; EXPECT_EQ(sizeD.ToString(), expected); } } // namespace OHOS::Ace