!48038 Svg TDD补充

Merge pull request !48038 from aryawang/118master
This commit is contained in:
openharmony_ci 2024-11-22 14:18:03 +00:00 committed by Gitee
commit 4be0c63224
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 150 additions and 0 deletions

View File

@ -853,4 +853,23 @@ HWTEST_F(ParseTestTwoNg, ParseNodeTest003, TestSize.Level1)
EXPECT_EQ(svgNode->GetRootViewBox(), Rect());
}
/**
* @tc.name: ParseNodeTest004
* @tc.desc: SvgNode test
* @tc.type: FUNC
*/
HWTEST_F(ParseTestTwoNg, ParseNodeTest004, TestSize.Level1)
{
auto svgStream = SkMemoryStream::MakeCopy(SVG_ANIMATE_TRANSFORM.c_str(), SVG_ANIMATE_TRANSFORM.length());
ImageSourceInfo src;
Size size = { 100, 100 };
src.SetFillColor(Color::GREEN);
auto svgDom = SvgDom::CreateSvgDom(*svgStream, src);
svgDom->SetAnimationOnFinishCallback([](){});
svgDom->SetColorFilter(std::nullopt);
Testing::MockCanvas rSCanvas;
CallBack(rSCanvas);
svgDom->DrawImage(rSCanvas, ImageFit::SCALE_DOWN, size);
}
} // namespace OHOS::Ace::NG

View File

@ -67,4 +67,135 @@ HWTEST_F(SvgDomTestNg, SvgDom002, TestSize.Level1)
EXPECT_FLOAT_EQ(svgContentSize.Width(), SVG_SIZE.Width());
EXPECT_FLOAT_EQ(svgContentSize.Height(), SVG_SIZE.Height());
}
/**
* @tc.name: SvgDomContentSize001
* @tc.desc: test svg content Size
* @tc.type: FUNC
*/
HWTEST_F(SvgDomTestNg, SvgDomContentSize001, TestSize.Level1)
{
Size ContainerSize = { 400, 500 };
Size SvgSize = { 50, 50 };
Rect ViewBox = { -4.0, -10.0, -1, -1 };
Size svgContentSize;
SvgUtils::CalculateSvgConentSize(svgContentSize, ContainerSize, SvgSize, ViewBox);
EXPECT_FLOAT_EQ(svgContentSize.Width(), SVG_SIZE.Width());
EXPECT_FLOAT_EQ(svgContentSize.Height(), SVG_SIZE.Height());
SvgSize = { -50, -50 };
ViewBox = { -4.0, -10.0, -1, -1 };
SvgUtils::CalculateSvgConentSize(svgContentSize, ContainerSize, SvgSize, ViewBox);
EXPECT_FLOAT_EQ(svgContentSize.Width(), ContainerSize.Width());
EXPECT_FLOAT_EQ(svgContentSize.Height(), ContainerSize.Height());
}
/**
* @tc.name: SvgDomContentSize002
* @tc.desc: test svg content Size
* @tc.type: FUNC
*/
HWTEST_F(SvgDomTestNg, SvgDomContentSize002, TestSize.Level1)
{
Size ContainerSize = { 400, 500 };
Size SvgSize = { -50, -50 };
Rect ViewBox = { -4.0, -10.0, 20, 30 };
Size svgContentSize;
SvgUtils::CalculateSvgConentSize(svgContentSize, ContainerSize, SvgSize, ViewBox);
EXPECT_FLOAT_EQ(svgContentSize.Width(), ContainerSize.Width());
EXPECT_FLOAT_EQ(svgContentSize.Height(), ContainerSize.Height());
SvgSize = { -50, 50 };
ViewBox = { -4.0, -10.0, 20, 30 };
SvgUtils::CalculateSvgConentSize(svgContentSize, ContainerSize, SvgSize, ViewBox);
EXPECT_FLOAT_EQ(svgContentSize.Width(), ViewBox.Width() / ViewBox.Height() * SvgSize.Height());
EXPECT_FLOAT_EQ(svgContentSize.Height(), SvgSize.Height());
SvgSize = { 50, -50 };
ViewBox = { -4.0, -10.0, 20, 30 };
SvgUtils::CalculateSvgConentSize(svgContentSize, ContainerSize, SvgSize, ViewBox);
EXPECT_FLOAT_EQ(svgContentSize.Width(), SvgSize.Width());
EXPECT_FLOAT_EQ(svgContentSize.Height(), ViewBox.Height() / ViewBox.Width() * SvgSize.Width());
}
/**
* @tc.name: SvgDomDraw001
* @tc.desc: svg draw with fit
* @tc.type: FUNC
*/
HWTEST_F(SvgDomTestNg, SvgDomDraw001, TestSize.Level1)
{
auto svgDom = AceType::MakeRefPtr<SvgDom>();
svgDom->root_ = nullptr;
Testing::MockCanvas rSCanvas;
svgDom->layout_ = LAYOUT;
svgDom->svgSize_ = SVG_SIZE;
svgDom->viewBox_ = VIEW_BOX;
ImageFit imageFit = ImageFit::FILL;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::CONTAIN;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::COVER;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::FITWIDTH;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::FITHEIGHT;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::NONE;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::SCALE_DOWN;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
}
/**
* @tc.name: SvgDomDraw002
* @tc.desc: svg draw with align
* @tc.type: FUNC
*/
HWTEST_F(SvgDomTestNg, SvgDomDraw002, TestSize.Level1)
{
auto svgDom = AceType::MakeRefPtr<SvgDom>();
svgDom->root_ = nullptr;
Testing::MockCanvas rSCanvas;
svgDom->layout_ = LAYOUT;
svgDom->svgSize_ = SVG_SIZE;
svgDom->viewBox_ = VIEW_BOX;
ImageFit imageFit = ImageFit::TOP_LEFT;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::TOP;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::TOP_END;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::START;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::CENTER;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::END;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::BOTTOM_START;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::BOTTOM;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::BOTTOM_END;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
imageFit = ImageFit::COVER_TOP_LEFT;
EXPECT_CALL(rSCanvas, ClipRect(_, _, _));
svgDom->FitImage(rSCanvas, imageFit, LAYOUT);
}
} // namespace OHOS::Ace::NG