From 1fc290bbb25631b04593fc2be4fade6ff420f45f Mon Sep 17 00:00:00 2001 From: zakalyukinalexander_ac40 Date: Mon, 4 Aug 2025 17:15:54 +0300 Subject: [PATCH] =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=B6=89=E5=8F=8A=E9=9D=9E?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=8F=98=E6=9B=B4:=20=E5=90=A6=20TDD?= =?UTF-8?q?=E8=87=AA=E9=AA=8C=E7=BB=93=E6=9E=9C(=E5=A6=82=E6=9C=89?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=9F=BA=E7=BA=BF=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5):=20Pass?= =?UTF-8?q?=20XTS=E8=87=AA=E9=AA=8C=E7=BB=93=E6=9E=9C(=E5=A6=82=E6=9C=89?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8B=E9=9C=80=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=9F=BA=E7=BA=BF=E6=89=A7=E8=A1=8C=E6=83=85=E5=86=B5):=20?= =?UTF-8?q?=E4=B8=8D=E6=B6=89=E5=8F=8A=20=E6=A3=80=E8=A7=86=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E6=98=AF=E5=90=A6=E9=83=BD=E5=B7=B2=E9=97=AD=E7=8E=AF?= =?UTF-8?q?(=E6=97=A0=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E5=A1=AB?= =?UTF-8?q?=E6=98=AF):=20=E6=98=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zakalyukinalexander_ac40 --- .../native/implementation/path2d_accessor.cpp | 54 +++- .../capi/accessors/path2d_accessor_test.cpp | 234 +++++++++++++++--- 2 files changed, 249 insertions(+), 39 deletions(-) diff --git a/frameworks/core/interfaces/native/implementation/path2d_accessor.cpp b/frameworks/core/interfaces/native/implementation/path2d_accessor.cpp index b13026fc3aa..7de945c15e7 100644 --- a/frameworks/core/interfaces/native/implementation/path2d_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/path2d_accessor.cpp @@ -21,6 +21,17 @@ namespace OHOS::Ace::NG::GeneratedModifier { namespace Path2DAccessor { +namespace { +const std::string EMPTY_STRING = ""; +RefPtr CreatePeerImpl() +{ + auto peerImpl = Referenced::MakeRefPtr(); + peerImpl->IncRefCount(); + peerImpl->SetOptions(); + return peerImpl; +} +} // namespace + void DestroyPeerImpl(Ark_Path2D peer) { auto peerImpl = reinterpret_cast(peer); @@ -30,32 +41,59 @@ void DestroyPeerImpl(Ark_Path2D peer) } Ark_Path2D Construct0Impl() { - auto peerImpl = Referenced::MakeRefPtr(); - peerImpl->IncRefCount(); - peerImpl->SetOptions(); + auto peerImpl = CreatePeerImpl(); return reinterpret_cast(Referenced::RawPtr(peerImpl)); } Ark_Path2D Construct1Impl(Ark_LengthMetricsUnit unit) { - return {}; + auto peerImpl = CreatePeerImpl(); + auto optUnit = Converter::OptConvert(unit).value_or(Ace::CanvasUnit::DEFAULT); + peerImpl->SetUnit(optUnit); + return reinterpret_cast(Referenced::RawPtr(peerImpl)); } Ark_Path2D Construct2Impl(Ark_Path2D path) { - return {}; + auto peerImpl = CreatePeerImpl(); + if (path) { + auto canvasPath = path->GetCanvasPath2d(); + peerImpl->SetCanvasPath2d(canvasPath); + } + return reinterpret_cast(Referenced::RawPtr(peerImpl)); } Ark_Path2D Construct3Impl(Ark_Path2D path, Ark_LengthMetricsUnit unit) { - return {}; + auto peerImpl = CreatePeerImpl(); + auto optUnit = Converter::OptConvert(unit).value_or(Ace::CanvasUnit::DEFAULT); + peerImpl->SetUnit(optUnit); + if (path) { + auto canvasPath = path->GetCanvasPath2d(); + peerImpl->SetCanvasPath2d(canvasPath); + } + return reinterpret_cast(Referenced::RawPtr(peerImpl)); } Ark_Path2D Construct4Impl(const Ark_String* d) { - return {}; + auto peerImpl = CreatePeerImpl(); + auto path = Converter::OptConvertPtr(d).value_or(EMPTY_STRING); + if (!path.empty()) { + auto canvasPath = Referenced::MakeRefPtr(path); + peerImpl->SetCanvasPath2d(canvasPath); + } + return reinterpret_cast(Referenced::RawPtr(peerImpl)); } Ark_Path2D Construct5Impl(const Ark_String* description, Ark_LengthMetricsUnit unit) { - return {}; + auto peerImpl = CreatePeerImpl(); + auto optUnit = Converter::OptConvert(unit).value_or(Ace::CanvasUnit::DEFAULT); + peerImpl->SetUnit(optUnit); + auto path = Converter::OptConvertPtr(description).value_or(EMPTY_STRING); + if (!path.empty()) { + auto canvasPath = Referenced::MakeRefPtr(path); + peerImpl->SetCanvasPath2d(canvasPath); + } + return reinterpret_cast(Referenced::RawPtr(peerImpl)); } Ark_NativePointer GetFinalizerImpl() { diff --git a/test/unittest/capi/accessors/path2d_accessor_test.cpp b/test/unittest/capi/accessors/path2d_accessor_test.cpp index a5ff2065a59..24524e6532e 100755 --- a/test/unittest/capi/accessors/path2d_accessor_test.cpp +++ b/test/unittest/capi/accessors/path2d_accessor_test.cpp @@ -25,16 +25,33 @@ using namespace testing; using namespace testing::ext; namespace { -std::vector NUMBER_TEST_PLAN = { - 100, 10.25, 2.35, 5.42, 12.34, 56.73 -}; +const std::string EXTENDED_PATH = "M0 0 L600 0"; +const std::string DEFAULT_STRING_PATH = ""; +const auto DEFAULT_UNIT = Ace::CanvasUnit::DEFAULT; +const auto DEFAULT_ARK_UNIT = Ark_LengthMetricsUnit::ARK_LENGTH_METRICS_UNIT_DEFAULT; +const std::string EXP_PATH = "CMDS:M0 0 L600 0"; +const std::string EXP_TRANSFORM = "TRANSFORM:100.000000,2.350000,5.420000,10.250000,12.340000,56.730000"; -class MockCanvasPath : public CanvasPath2D { -public: - MockCanvasPath() = default; - ~MockCanvasPath() override = default; - MOCK_METHOD(void, AddPath, (const RefPtr&)); - MOCK_METHOD(void, SetTransform, (double, double, double, double, double, double)); +std::vector numberTestPlan = { 100, 10.25, 2.35, 5.42, 12.34, 56.73 }; +std::vector addPathTestPlan = { + EXP_PATH + " " + EXP_TRANSFORM + " ", + EXP_PATH + " " + EXP_TRANSFORM + " " + EXP_PATH + " " + EXP_TRANSFORM + " ", + EXP_PATH + " " + EXP_TRANSFORM + " " + EXP_PATH + " " + EXP_TRANSFORM + " " + EXP_PATH + " " + EXP_TRANSFORM + " ", +}; +std::vector> pathTestPlan = { + { "M0 0 L600 0", "CMDS:M0 0 L600 0 " }, + { "M0 0 L100 0", "CMDS:M0 0 L100 0 " }, + { "", "CMDS: " }, +}; +std::vector> unitTestPlan = { + { ARK_LENGTH_METRICS_UNIT_DEFAULT, Ace::CanvasUnit::DEFAULT }, + { ARK_LENGTH_METRICS_UNIT_PX, Ace::CanvasUnit::PX }, + { static_cast(-1), Ace::CanvasUnit::DEFAULT }, +}; +std::vector> pathStringTestPlan = { + { Converter::ArkValue("M0 0 L600 0 "), "CMDS:M0 0 L600 0 " }, + { Converter::ArkValue("M0 0 L100 0 "), "CMDS:M0 0 L100 0 " }, + { Converter::ArkValue(""), "" }, }; } // namespace @@ -44,25 +61,182 @@ class Path2DAccessorTest public: void SetUp(void) override { - AccessorTestBase::SetUp(); - mockPath_ = new MockCanvasPath(); - mockPathKeeper_ = AceType::Claim(mockPath_); + ASSERT_NO_FATAL_FAILURE(AccessorTestBase0::SetUp()); + mockPathKeeper_ = AceType::MakeRefPtr(); ASSERT_NE(mockPathKeeper_, nullptr); - RefPtr pathKeeper = mockPathKeeper_; - peer_->SetCanvasPath2d(pathKeeper); - ASSERT_NE(mockPath_, nullptr); + peer_->SetCanvasPath2d(mockPathKeeper_); } void TearDown() override { AccessorTestBaseParent::TearDown(); mockPathKeeper_ = nullptr; - mockPath_ = nullptr; } - MockCanvasPath* mockPath_ = nullptr; - RefPtr mockPathKeeper_ = nullptr; + RefPtr mockPathKeeper_ = nullptr; }; +/** + * @tc.name: construct0Test + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(Path2DAccessorTest, construct0Test, TestSize.Level1) +{ + ASSERT_NE(accessor_->construct1, nullptr); + peer_ = accessor_->construct0(); + ASSERT_NE(peer_, nullptr); + auto canvasPath = peer_->GetCanvasPath2d(); + auto unit = peer_->GetUnit(); + ASSERT_NE(canvasPath, nullptr); + EXPECT_EQ(canvasPath->ToString(), DEFAULT_STRING_PATH); + EXPECT_EQ(unit, DEFAULT_UNIT); +} + +/** + * @tc.name: construct1Test + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(Path2DAccessorTest, construct1Test, TestSize.Level1) +{ + ASSERT_NE(accessor_->construct2, nullptr); + for (const auto& [actual, expected] : unitTestPlan) { + peer_ = accessor_->construct1(actual); + ASSERT_NE(peer_, nullptr); + auto canvasPath = peer_->GetCanvasPath2d(); + auto unit = peer_->GetUnit(); + ASSERT_NE(canvasPath, nullptr); + EXPECT_EQ(canvasPath->ToString(), DEFAULT_STRING_PATH); + EXPECT_EQ(unit, expected); + } +} + +/** + * @tc.name: construct2Test + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(Path2DAccessorTest, construct2Test, TestSize.Level1) +{ + ASSERT_NE(accessor_->construct1, nullptr); + for (const auto& [actual, expected] : pathTestPlan) { + auto path = Referenced::MakeRefPtr(actual); + auto peer = Referenced::MakeRefPtr(); + ASSERT_NE(peer, nullptr); + peer->SetCanvasPath2d(path); + auto arkPeer = Referenced::RawPtr(peer); + ASSERT_NE(arkPeer, nullptr); + peer_ = accessor_->construct2(arkPeer); + ASSERT_NE(peer_, nullptr); + auto canvasPath = peer_->GetCanvasPath2d(); + auto unit = peer_->GetUnit(); + ASSERT_NE(canvasPath, nullptr); + EXPECT_EQ(canvasPath->ToString(), expected); + EXPECT_EQ(unit, DEFAULT_UNIT); + } +} + +/** + * @tc.name: construct3UnitTest + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(Path2DAccessorTest, construct3UnitTest, TestSize.Level1) +{ + ASSERT_NE(accessor_->construct3, nullptr); + for (const auto& [actual, expected] : unitTestPlan) { + peer_ = accessor_->construct3(nullptr, actual); + ASSERT_NE(peer_, nullptr); + auto canvasPath = peer_->GetCanvasPath2d(); + auto unit = peer_->GetUnit(); + ASSERT_NE(canvasPath, nullptr); + EXPECT_EQ(canvasPath->ToString(), DEFAULT_STRING_PATH); + EXPECT_EQ(unit, expected); + } +} + +/** + * @tc.name: construct3PathTest + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(Path2DAccessorTest, construct3PathTest, TestSize.Level1) +{ + ASSERT_NE(accessor_->construct3, nullptr); + for (const auto& [actual, expected] : pathTestPlan) { + auto path = Referenced::MakeRefPtr(actual); + auto peer = Referenced::MakeRefPtr(); + ASSERT_NE(peer, nullptr); + peer->SetCanvasPath2d(path); + auto arkPeer = Referenced::RawPtr(peer); + ASSERT_NE(arkPeer, nullptr); + peer_ = accessor_->construct3(arkPeer, DEFAULT_ARK_UNIT); + ASSERT_NE(peer_, nullptr); + auto canvasPath = peer_->GetCanvasPath2d(); + auto unit = peer_->GetUnit(); + ASSERT_NE(canvasPath, nullptr); + EXPECT_EQ(canvasPath->ToString(), expected); + EXPECT_EQ(unit, DEFAULT_UNIT); + } +} + +/** + * @tc.name: construct4Test + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(Path2DAccessorTest, construct4Test, TestSize.Level1) +{ + ASSERT_NE(accessor_->construct4, nullptr); + for (const auto& [actual, expected] : pathStringTestPlan) { + peer_ = accessor_->construct4(&actual); + ASSERT_NE(peer_, nullptr); + auto canvasPath = peer_->GetCanvasPath2d(); + auto unit = peer_->GetUnit(); + ASSERT_NE(canvasPath, nullptr); + EXPECT_EQ(canvasPath->ToString(), expected); + EXPECT_EQ(unit, DEFAULT_UNIT); + } +} + +/** + * @tc.name: construct5UnitTest + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(Path2DAccessorTest, construct5UnitTest, TestSize.Level1) +{ + ASSERT_NE(accessor_->construct5, nullptr); + for (const auto& [actual, expected] : unitTestPlan) { + peer_ = accessor_->construct5(nullptr, actual); + ASSERT_NE(peer_, nullptr); + auto canvasPath = peer_->GetCanvasPath2d(); + auto unit = peer_->GetUnit(); + ASSERT_NE(canvasPath, nullptr); + EXPECT_EQ(canvasPath->ToString(), DEFAULT_STRING_PATH); + EXPECT_EQ(unit, expected); + } +} + +/** + * @tc.name: construct5DescriptionTest + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(Path2DAccessorTest, construct5DescriptionTest, TestSize.Level1) +{ + ASSERT_NE(accessor_->construct5, nullptr); + for (const auto& [actual, expected] : pathStringTestPlan) { + peer_ = accessor_->construct5(&actual, DEFAULT_ARK_UNIT); + ASSERT_NE(peer_, nullptr); + auto canvasPath = peer_->GetCanvasPath2d(); + auto unit = peer_->GetUnit(); + ASSERT_NE(canvasPath, nullptr); + EXPECT_EQ(canvasPath->ToString(), expected); + EXPECT_EQ(unit, DEFAULT_UNIT); + } +} + /** * @tc.name: addPathTest * @tc.desc: @@ -71,25 +245,23 @@ public: HWTEST_F(Path2DAccessorTest, addPathTest, TestSize.Level1) { ASSERT_NE(accessor_->addPath, nullptr); + auto path = Referenced::MakeRefPtr(EXTENDED_PATH); auto peerPathImpl = Referenced::MakeRefPtr(); + peerPathImpl->SetCanvasPath2d(path); auto arkPath = Referenced::RawPtr(peerPathImpl); - RefPtr pathKeeper = mockPathKeeper_; - peerPathImpl->SetCanvasPath2d(pathKeeper); auto peerMatrix = PeerUtils::CreatePeer(); auto optMatrix = Converter::ArkValue(peerMatrix); - peerMatrix->SetScaleX(NUMBER_TEST_PLAN[0]); - peerMatrix->SetScaleY(NUMBER_TEST_PLAN[1]); - peerMatrix->SetRotateX(NUMBER_TEST_PLAN[2]); - peerMatrix->SetRotateY(NUMBER_TEST_PLAN[3]); - peerMatrix->SetTranslateX(NUMBER_TEST_PLAN[4]); - peerMatrix->SetTranslateY(NUMBER_TEST_PLAN[5]); - auto tr = peerMatrix->GetTransform(); - EXPECT_CALL(*mockPath_, AddPath(peerPathImpl->GetCanvasPath2d())).Times(3); - EXPECT_CALL(*mockPath_, SetTransform(tr.scaleX, tr.skewX, tr.skewY, tr.scaleY, tr.translateX, tr.translateY)) - .Times(3); + peerMatrix->SetScaleX(numberTestPlan[0]); + peerMatrix->SetScaleY(numberTestPlan[1]); + peerMatrix->SetRotateX(numberTestPlan[2]); + peerMatrix->SetRotateY(numberTestPlan[3]); + peerMatrix->SetTranslateX(numberTestPlan[4]); + peerMatrix->SetTranslateY(numberTestPlan[5]); accessor_->addPath(peer_, arkPath, &optMatrix); + EXPECT_EQ(mockPathKeeper_->ToString(), addPathTestPlan[0]); accessor_->addPath(peer_, arkPath, &optMatrix); + EXPECT_EQ(mockPathKeeper_->ToString(), addPathTestPlan[1]); accessor_->addPath(peer_, arkPath, &optMatrix); - pathKeeper->DecRefCount(); + EXPECT_EQ(mockPathKeeper_->ToString(), addPathTestPlan[2]); } } // namespace OHOS::Ace::NG -- Gitee