mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-22 22:50:53 +00:00
commit
4be0c63224
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user