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 <string> 17 18 #include "gtest/gtest.h" 19 #include "test/mock/core/rosen/mock_canvas.h" 20 #include "test/mock/core/rosen/testing_rect.h" 21 #include "frameworks/core/components_ng/svg/svg_ulils.h" 22 23 #define private public 24 #define protected public 25 26 #include "core/components_ng/svg/svg_dom.h" 27 #include "core/components_ng/svg/svg_ulils.h" 28 29 using namespace testing; 30 using namespace testing::ext; 31 32 namespace OHOS::Ace::NG { 33 namespace { 34 const Size LAYOUT = { 400, 500 }; 35 const Size SVG_SIZE = { 50, 50 }; 36 const Rect VIEW_BOX = { -4.0, -10.0, 300.0, 300.0 }; 37 } // namespace 38 class SvgDomTestNg : public testing::Test {}; 39 40 /** 41 * @tc.name: SvgDom001 42 * @tc.desc: test fit image 43 * @tc.type: FUNC 44 */ 45 HWTEST_F(SvgDomTestNg, SvgDom001, TestSize.Level1) 46 { 47 auto svgDom = AceType::MakeRefPtr<SvgDom>(); 48 49 svgDom->svgSize_ = SVG_SIZE; 50 svgDom->viewBox_ = VIEW_BOX; 51 Testing::MockCanvas canvas; 52 // check translate and scale parameters 53 auto clipRect = Testing::TestingRect(0, 0, LAYOUT.Width(), LAYOUT.Height()); 54 EXPECT_CALL(canvas, ClipRect(_, _, _)); 55 svgDom->FitImage(canvas, ImageFit::CONTAIN, LAYOUT); 56 } 57 58 /** 59 * @tc.name: SvgDom002 60 * @tc.desc: test svg content Size 61 * @tc.type: FUNC 62 */ 63 HWTEST_F(SvgDomTestNg, SvgDom002, TestSize.Level1) 64 { 65 Size svgContentSize; 66 SvgUtils::CalculateSvgConentSize(svgContentSize, LAYOUT, SVG_SIZE, VIEW_BOX); 67 EXPECT_FLOAT_EQ(svgContentSize.Width(), SVG_SIZE.Width()); 68 EXPECT_FLOAT_EQ(svgContentSize.Height(), SVG_SIZE.Height()); 69 } 70 } // namespace OHOS::Ace::NG 71