From 2a3b1fe46ef8302b4a21648a48b6043eda0e53c2 Mon Sep 17 00:00:00 2001 From: evstigneevroman_9cd1 Date: Fri, 15 Aug 2025 09:35:58 +0300 Subject: [PATCH 1/2] implementation drawableDescriptor accessors Signed-off-by: evstigneevroman_9cd1 Change-Id: I92ece813a25c3d9057a9e971d7045f11281402ed --- .../core/interfaces/native/common_sources.gni | 3 + .../animated_drawable_descriptor_accessor.cpp | 29 ++- .../animated_drawable_descriptor_peer.cpp | 63 ++++++ .../animated_drawable_descriptor_peer.h | 55 ++++++ .../implementation/base_gesture_event_peer.h | 7 +- .../implementation/common_method_modifier.cpp | 15 +- .../drawable_descriptor_accessor.cpp | 7 +- .../drawable_descriptor_peer.cpp | 20 ++ .../implementation/drawable_descriptor_peer.h | 55 ++++++ .../layered_drawable_descriptor_accessor.cpp | 22 ++- .../layered_drawable_descriptor_peer.cpp | 32 ++++ .../layered_drawable_descriptor_peer.h | 43 +++++ ...pixel_map_drawable_descriptor_accessor.cpp | 11 +- .../pixel_map_drawable_descriptor_peer.h | 26 +++ .../native/utility/reverse_converter.cpp | 5 + .../native/utility/reverse_converter.h | 2 + test/unittest/capi/accessors/BUILD.gn | 4 + ...ated_drawable_descriptor_accessor_test.cpp | 95 +++++++++ .../drawable_descriptor_accessor_test.cpp | 101 ++++++++++ ...ered_drawable_descriptor_accessor_test.cpp | 180 ++++++++++++++++++ ..._map_drawable_descriptor_accessor_test.cpp | 76 ++++++++ 21 files changed, 831 insertions(+), 20 deletions(-) create mode 100644 frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_peer.cpp create mode 100644 frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_peer.h create mode 100644 frameworks/core/interfaces/native/implementation/drawable_descriptor_peer.cpp create mode 100644 frameworks/core/interfaces/native/implementation/drawable_descriptor_peer.h create mode 100644 frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.cpp create mode 100644 frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.h create mode 100644 frameworks/core/interfaces/native/implementation/pixel_map_drawable_descriptor_peer.h create mode 100644 test/unittest/capi/accessors/animated_drawable_descriptor_accessor_test.cpp create mode 100644 test/unittest/capi/accessors/drawable_descriptor_accessor_test.cpp create mode 100644 test/unittest/capi/accessors/layered_drawable_descriptor_accessor_test.cpp create mode 100644 test/unittest/capi/accessors/pixel_map_drawable_descriptor_accessor_test.cpp diff --git a/frameworks/core/interfaces/native/common_sources.gni b/frameworks/core/interfaces/native/common_sources.gni index b7388b754d5..5f75daaea90 100644 --- a/frameworks/core/interfaces/native/common_sources.gni +++ b/frameworks/core/interfaces/native/common_sources.gni @@ -15,15 +15,18 @@ common_sources = [ "common/api_impl.cpp", "common/view_model.cpp", "common/view_model2.cpp", + "implementation/animated_drawable_descriptor_peer.cpp", "implementation/canvas_path_peer_impl.cpp", "implementation/canvas_renderer_peer_impl.cpp", "implementation/canvas_rendering_context2d_peer_impl.cpp", "implementation/custom_dialog_controller_peer_impl.cpp", "implementation/dialog_common.cpp", + "implementation/drawable_descriptor_peer.cpp", "implementation/drawing_rendering_context_peer_impl.cpp", "implementation/global_scope_animation_helper.cpp", "implementation/image_bitmap_peer_impl.cpp", "implementation/image_common_methods.cpp", + "implementation/layered_drawable_descriptor_peer.cpp", "implementation/matrix2d_peer_impl.cpp", "implementation/navigation_context.cpp", "implementation/offscreen_canvas_peer.cpp", diff --git a/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_accessor.cpp b/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_accessor.cpp index f67f9ff3477..89111132b98 100644 --- a/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_accessor.cpp @@ -13,19 +13,44 @@ * limitations under the License. */ +#include "animated_drawable_descriptor_peer.h" +#include "arkoala_api_generated.h" + #include "core/components_ng/base/frame_node.h" #include "core/interfaces/native/utility/converter.h" -#include "arkoala_api_generated.h" + +namespace OHOS::Ace::NG::Converter { +struct AnimationOptions { + std::optional duration; + std::optional iterations; +}; + +template<> +AnimationOptions Convert(const Ark_AnimationOptions& options) +{ + return { + .duration = OptConvert(options.duration), + .iterations = OptConvert(options.iterations), + }; +} +} // namespace OHOS::Ace::NG::Converter + +using namespace OHOS::Ace::NG::Converter; namespace OHOS::Ace::NG::GeneratedModifier { namespace AnimatedDrawableDescriptorAccessor { void DestroyPeerImpl(Ark_AnimatedDrawableDescriptor peer) { + PeerUtils::DestroyPeer(peer); } Ark_AnimatedDrawableDescriptor CtorImpl(const Array_PixelMap* pixelMaps, const Opt_AnimationOptions* options) { - return nullptr; + auto arrayPixelMaps = OptConvertPtr>>(pixelMaps) + .value_or(std::vector>()); + auto animationOptions = OptConvertPtr(options).value_or(AnimationOptions()); + return PeerUtils::CreatePeer( + arrayPixelMaps, animationOptions.duration, animationOptions.iterations); } Ark_NativePointer GetFinalizerImpl() { diff --git a/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_peer.cpp b/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_peer.cpp new file mode 100644 index 00000000000..e178bf59c22 --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_peer.cpp @@ -0,0 +1,63 @@ +/* + * 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 "animated_drawable_descriptor_peer.h" + +PixelMapPtr AnimatedDrawableDescriptorPeer::GetPixelMap() const +{ + if (pixelMapList.empty()) { + return nullptr; + } + return pixelMapList[0]; +} + +std::vector AnimatedDrawableDescriptorPeer::GetPixelMapList() const +{ + return pixelMapList; +} + +int32_t AnimatedDrawableDescriptorPeer::GetDuration() +{ + if (duration <= 0) { + duration = defaultDuration * static_cast(pixelMapList.size()); + } + return duration; +} + +int32_t AnimatedDrawableDescriptorPeer::GetIterations() +{ + if (iterations < -1) { + iterations = 1; + } + return iterations; +} + +void AnimatedDrawableDescriptorPeer::SetDuration(int32_t value) +{ + if (value <= 0) { + duration = defaultDuration * static_cast(pixelMapList.size()); + } else { + duration = value; + } +} + +void AnimatedDrawableDescriptorPeer::SetIterations(int32_t value) +{ + if (value < -1) { + iterations = 1; + } else { + iterations = value; + } +} \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_peer.h b/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_peer.h new file mode 100644 index 00000000000..f4226587622 --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/animated_drawable_descriptor_peer.h @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#pragma once + +#include "arkoala_api_generated.h" +#include "drawable_descriptor_peer.h" + +#include "core/components_ng/base/frame_node.h" +#include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/peer_utils.h" + +struct AnimatedDrawableDescriptorPeer : public DrawableDescriptorPeer { + DECLARE_ACE_TYPE(AnimatedDrawableDescriptorPeer, DrawableDescriptorPeer); +public: + PixelMapPtr GetPixelMap() const override; + std::vector GetPixelMapList() const; + int32_t GetDuration(); + int32_t GetIterations(); + void SetDuration(int32_t value); + void SetIterations(int32_t value); + +protected: + AnimatedDrawableDescriptorPeer(std::vector pixelMapsValue, std::optional durationValue, + std::optional iterationsValue) + : pixelMapList(std::move(pixelMapsValue)) + { + if (durationValue) { + duration = *durationValue; + } + if (iterationsValue) { + iterations = *iterationsValue; + } + } + ~AnimatedDrawableDescriptorPeer() override = default; + friend OHOS::Ace::NG::PeerUtils; + +private: + static constexpr int defaultDuration = 1000; + std::vector pixelMapList; + int32_t duration = -1; + int32_t iterations = 1; +}; \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/base_gesture_event_peer.h b/frameworks/core/interfaces/native/implementation/base_gesture_event_peer.h index d7d46de74f5..4d89d685bd7 100644 --- a/frameworks/core/interfaces/native/implementation/base_gesture_event_peer.h +++ b/frameworks/core/interfaces/native/implementation/base_gesture_event_peer.h @@ -51,6 +51,7 @@ protected: ~SomeGestureEventPeer() override = default; public: + using InfoType = AceGestureInfo; BaseEventInfo* GetBaseInfo() override { return GetEventInfo(); @@ -82,11 +83,11 @@ protected: friend PeerUtils; }; -template, bool> = true, - std::enable_if_t, bool> = true> +template, bool> = true> static BaseGestureEventPeer* CreateGestureEventPeer(const std::shared_ptr& info) { + using AceGestureEvent = typename std::remove_pointer_t::InfoType; auto event = TypeInfoHelper::DynamicCast(info.get()); CHECK_NULL_RETURN(event, nullptr); auto peer = PeerUtils::CreatePeer(); diff --git a/frameworks/core/interfaces/native/implementation/common_method_modifier.cpp b/frameworks/core/interfaces/native/implementation/common_method_modifier.cpp index 734b8c2489b..615ef94fdee 100644 --- a/frameworks/core/interfaces/native/implementation/common_method_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/common_method_modifier.cpp @@ -163,32 +163,31 @@ Ark_BaseGestureEvent CreateArkBaseGestureEvent(const std::shared_ptr(info); + peer = GeneratedModifier::CreateGestureEventPeer(info); break; } case OHOS::Ace::GestureTypeName::LONG_PRESS_GESTURE: { - peer = GeneratedModifier::CreateGestureEventPeer(info); + peer = GeneratedModifier::CreateGestureEventPeer(info); break; } case OHOS::Ace::GestureTypeName::PAN_GESTURE: { - peer = GeneratedModifier::CreateGestureEventPeer(info); + peer = GeneratedModifier::CreateGestureEventPeer(info); break; } case OHOS::Ace::GestureTypeName::PINCH_GESTURE: { - peer = GeneratedModifier::CreateGestureEventPeer(info); + peer = GeneratedModifier::CreateGestureEventPeer(info); break; } case OHOS::Ace::GestureTypeName::ROTATION_GESTURE: { - peer = GeneratedModifier::CreateGestureEventPeer(info); + peer = GeneratedModifier::CreateGestureEventPeer(info); break; } case OHOS::Ace::GestureTypeName::SWIPE_GESTURE: { - peer = GeneratedModifier::CreateGestureEventPeer(info); + peer = GeneratedModifier::CreateGestureEventPeer(info); break; } default: - peer = GeneratedModifier::CreateGestureEventPeer(info); + peer = GeneratedModifier::CreateGestureEventPeer(info); break; } CHECK_NULL_RETURN(peer, nullptr); diff --git a/frameworks/core/interfaces/native/implementation/drawable_descriptor_accessor.cpp b/frameworks/core/interfaces/native/implementation/drawable_descriptor_accessor.cpp index ed0a22bd6c1..a9a98f7b39c 100644 --- a/frameworks/core/interfaces/native/implementation/drawable_descriptor_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/drawable_descriptor_accessor.cpp @@ -15,16 +15,19 @@ #include "core/components_ng/base/frame_node.h" #include "core/interfaces/native/utility/converter.h" +#include "drawable_descriptor_peer.h" #include "arkoala_api_generated.h" +#include "pixel_map_peer.h" namespace OHOS::Ace::NG::GeneratedModifier { namespace DrawableDescriptorAccessor { void DestroyPeerImpl(Ark_DrawableDescriptor peer) { + PeerUtils::DestroyPeer(peer); } Ark_DrawableDescriptor CtorImpl() { - return nullptr; + return PeerUtils::CreatePeer(); } Ark_NativePointer GetFinalizerImpl() { @@ -32,7 +35,7 @@ Ark_NativePointer GetFinalizerImpl() } Ark_PixelMap GetPixelMapImpl(Ark_DrawableDescriptor peer) { - return {}; + return PixelMapPeer::Create(peer->GetPixelMap()); } } // DrawableDescriptorAccessor const GENERATED_ArkUIDrawableDescriptorAccessor* GetDrawableDescriptorAccessor() diff --git a/frameworks/core/interfaces/native/implementation/drawable_descriptor_peer.cpp b/frameworks/core/interfaces/native/implementation/drawable_descriptor_peer.cpp new file mode 100644 index 00000000000..840dcd27aef --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/drawable_descriptor_peer.cpp @@ -0,0 +1,20 @@ +/* + * 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 "drawable_descriptor_peer.h" + +PixelMapPtr DrawableDescriptorPeer::GetPixelMap() const +{ + return pixelMap; +} \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/drawable_descriptor_peer.h b/frameworks/core/interfaces/native/implementation/drawable_descriptor_peer.h new file mode 100644 index 00000000000..6dba81ccda8 --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/drawable_descriptor_peer.h @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#ifndef FOUNDATION_ARKUI_ACE_ENGINE_FRAMEWORKS_CORE_INTERFACES_NATIVE_IMPL_DRAWABALE_DESCRITOR_PEER_H +#define FOUNDATION_ARKUI_ACE_ENGINE_FRAMEWORKS_CORE_INTERFACES_NATIVE_IMPL_DRAWABALE_DESCRITOR_PEER_H + +#include "arkoala_api_generated.h" + +#include "base/image/pixel_map.h" +#include "core/components_ng/base/frame_node.h" +#include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/peer_utils.h" + +using PixelMapPtr = OHOS::Ace::RefPtr; + +struct DrawableDescriptorPeer : public virtual OHOS::Ace::AceType { + DECLARE_ACE_TYPE(DrawableDescriptorPeer, OHOS::Ace::AceType); +public: + virtual PixelMapPtr GetPixelMap() const; + + void SetPixelMap(PixelMapPtr value) + { + pixelMap = value; + } + inline bool HasPixelMap() const + { + return pixelMap; + } + inline void ResetPixelMap() + { + pixelMap.Reset(); + } + +protected: + DrawableDescriptorPeer() = default; + explicit DrawableDescriptorPeer(PixelMapPtr value) : pixelMap(value) {}; + virtual ~DrawableDescriptorPeer() = default; + friend OHOS::Ace::NG::PeerUtils; + +private: + PixelMapPtr pixelMap; +}; +#endif // FOUNDATION_ARKUI_ACE_ENGINE_FRAMEWORKS_CORE_INTERFACES_NATIVE_IMPL_DRAWABALE_DESCRITOR_PEER_H \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_accessor.cpp b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_accessor.cpp index 67d00aa7969..23315d1e543 100644 --- a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_accessor.cpp @@ -15,18 +15,28 @@ #include "core/components_ng/base/frame_node.h" #include "core/interfaces/native/utility/converter.h" +#include "layered_drawable_descriptor_peer.h" #include "arkoala_api_generated.h" +using namespace OHOS::Ace::NG::Converter; namespace OHOS::Ace::NG::GeneratedModifier { namespace LayeredDrawableDescriptorAccessor { void DestroyPeerImpl(Ark_LayeredDrawableDescriptor peer) { + PeerUtils::DestroyPeer(peer); } Ark_LayeredDrawableDescriptor CtorImpl(const Opt_DrawableDescriptor* foreground, const Opt_DrawableDescriptor* background, const Opt_DrawableDescriptor* mask) { - return nullptr; + std::optional foregroundDescriptor = GetOptPtr(foreground); + std::optional backgroundDescriptor = GetOptPtr(background); + std::optional maskDescriptor = GetOptPtr(mask); + auto foregroundPixelMap = foregroundDescriptor ? foregroundDescriptor.value()->GetPixelMap() : nullptr; + auto backgroundPixelMap = backgroundDescriptor ? backgroundDescriptor.value()->GetPixelMap() : nullptr; + auto maskPixelMap = maskDescriptor ? maskDescriptor.value()->GetPixelMap() : nullptr; + return PeerUtils::CreatePeer( + foregroundPixelMap, backgroundPixelMap, maskPixelMap); } Ark_NativePointer GetFinalizerImpl() { @@ -34,18 +44,22 @@ Ark_NativePointer GetFinalizerImpl() } Ark_DrawableDescriptor GetForegroundImpl(Ark_LayeredDrawableDescriptor peer) { - return {}; + CHECK_NULL_RETURN(peer, nullptr); + return peer->GetForeground(); } Ark_DrawableDescriptor GetBackgroundImpl(Ark_LayeredDrawableDescriptor peer) { - return {}; + CHECK_NULL_RETURN(peer, nullptr); + return peer->GetBackground(); } Ark_DrawableDescriptor GetMaskImpl(Ark_LayeredDrawableDescriptor peer) { - return {}; + CHECK_NULL_RETURN(peer, nullptr); + return peer->GetMask(); } Ark_String GetMaskClipPathImpl() { + LOGE("ARKOALA: Ark_LayeredDrawableDescriptor::GetMaskClipPathImpl not implemented"); return {}; } } // LayeredDrawableDescriptorAccessor diff --git a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.cpp b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.cpp new file mode 100644 index 00000000000..e89c6b2c022 --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.cpp @@ -0,0 +1,32 @@ +/* + * 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 "layered_drawable_descriptor_peer.h" + +using namespace OHOS::Ace::NG; + +DrawableDescriptorPeer* LayeredDrawableDescriptorPeer::GetForeground() const +{ + return PeerUtils::CreatePeer(foreground); +} + +DrawableDescriptorPeer* LayeredDrawableDescriptorPeer::GetBackground() const +{ + return PeerUtils::CreatePeer(background); +} + +DrawableDescriptorPeer* LayeredDrawableDescriptorPeer::GetMask() const +{ + return PeerUtils::CreatePeer(mask); +} \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.h b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.h new file mode 100644 index 00000000000..d90fd873990 --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#pragma once + +#include "arkoala_api_generated.h" +#include "drawable_descriptor_peer.h" + +#include "core/components_ng/base/frame_node.h" +#include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/peer_utils.h" + +struct LayeredDrawableDescriptorPeer : public DrawableDescriptorPeer { + DECLARE_ACE_TYPE(LayeredDrawableDescriptorPeer, DrawableDescriptorPeer); +public: + DrawableDescriptorPeer* GetForeground() const; + DrawableDescriptorPeer* GetBackground() const; + DrawableDescriptorPeer* GetMask() const; + +protected: + LayeredDrawableDescriptorPeer(PixelMapPtr foregroundValue, PixelMapPtr backgroundValue, PixelMapPtr maskValue) + : foreground(foregroundValue), background(backgroundValue), mask(maskValue) + {} + friend OHOS::Ace::NG::PeerUtils; + ~LayeredDrawableDescriptorPeer() override = default; + +private: + PixelMapPtr foreground; + PixelMapPtr background; + PixelMapPtr mask; +}; \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/pixel_map_drawable_descriptor_accessor.cpp b/frameworks/core/interfaces/native/implementation/pixel_map_drawable_descriptor_accessor.cpp index 57c3bb417d5..7376bfcf1a7 100644 --- a/frameworks/core/interfaces/native/implementation/pixel_map_drawable_descriptor_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/pixel_map_drawable_descriptor_accessor.cpp @@ -16,15 +16,24 @@ #include "core/components_ng/base/frame_node.h" #include "core/interfaces/native/utility/converter.h" #include "arkoala_api_generated.h" +#include "pixel_map_drawable_descriptor_peer.h" + +using namespace OHOS::Ace::NG::Converter; namespace OHOS::Ace::NG::GeneratedModifier { namespace PixelMapDrawableDescriptorAccessor { void DestroyPeerImpl(Ark_PixelMapDrawableDescriptor peer) { + PeerUtils::DestroyPeer(peer); } Ark_PixelMapDrawableDescriptor CtorImpl(const Opt_PixelMap* src) { - return nullptr; + auto peer = PeerUtils::CreatePeer(); + CHECK_NULL_RETURN(src, peer); + auto optPixelMap = OptConvert>(*src); + CHECK_NULL_RETURN(optPixelMap, peer); + peer->SetPixelMap(*optPixelMap); + return peer; } Ark_NativePointer GetFinalizerImpl() { diff --git a/frameworks/core/interfaces/native/implementation/pixel_map_drawable_descriptor_peer.h b/frameworks/core/interfaces/native/implementation/pixel_map_drawable_descriptor_peer.h new file mode 100644 index 00000000000..9fc4ad3d4d2 --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/pixel_map_drawable_descriptor_peer.h @@ -0,0 +1,26 @@ +/* + * 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. + */ + +#pragma once + +#include "drawable_descriptor_peer.h" + +struct PixelMapDrawableDescriptorPeer : public DrawableDescriptorPeer { + DECLARE_ACE_TYPE(PixelMapDrawableDescriptorPeer, DrawableDescriptorPeer); +protected: + PixelMapDrawableDescriptorPeer() = default; + ~PixelMapDrawableDescriptorPeer() override = default; + friend OHOS::Ace::NG::PeerUtils; +}; \ No newline at end of file diff --git a/frameworks/core/interfaces/native/utility/reverse_converter.cpp b/frameworks/core/interfaces/native/utility/reverse_converter.cpp index f7e700dc5eb..4e6a98d9eac 100644 --- a/frameworks/core/interfaces/native/utility/reverse_converter.cpp +++ b/frameworks/core/interfaces/native/utility/reverse_converter.cpp @@ -372,6 +372,11 @@ void AssignArkValue(Ark_Padding& dst, const PaddingProperty& src) dst = arkPadding; } +void AssignArkValue(Ark_PixelMap& pixelMap, const RefPtr& info) +{ + pixelMap = PixelMapPeer::Create(info); +} + void AssignArkValue(Ark_PreviewText& dst, const PreviewText& src, ConvContext *ctx) { dst.offset = ArkValue(src.offset); diff --git a/frameworks/core/interfaces/native/utility/reverse_converter.h b/frameworks/core/interfaces/native/utility/reverse_converter.h index 5ec88fbf914..ea937d13810 100644 --- a/frameworks/core/interfaces/native/utility/reverse_converter.h +++ b/frameworks/core/interfaces/native/utility/reverse_converter.h @@ -71,6 +71,7 @@ #include "core/interfaces/native/implementation/mouse_event_peer.h" #include "core/interfaces/native/implementation/navigation_transition_proxy_peer.h" #include "core/interfaces/native/implementation/nav_destination_context_peer.h" +#include "core/interfaces/native/implementation/pixel_map_peer.h" #include "core/interfaces/native/implementation/submit_event_peer.h" #include "core/interfaces/native/implementation/swipe_recognizer_peer.h" #include "core/interfaces/native/implementation/touch_event_peer.h" @@ -289,6 +290,7 @@ namespace OHOS::Ace::NG::Converter { void AssignArkValue(Ark_PanDirection& dst, const PanDirection& src); void AssignArkValue(Ark_PanelMode& dst, const PanelMode& src); void AssignArkValue(Ark_PasteButtonOnClickResult& dst, const SecurityComponentHandleResult& src); + void AssignArkValue(Ark_PixelMap& pixelMap, const RefPtr& info); void AssignArkValue(Ark_Position& dst, const OffsetF& src); void AssignArkValue(Ark_LengthMetricsCustom& dst, const CalcDimension& src); void AssignArkValue(Ark_PositionWithAffinity& dst, const PositionWithAffinity& src); diff --git a/test/unittest/capi/accessors/BUILD.gn b/test/unittest/capi/accessors/BUILD.gn index ef030b81af8..a6142cc6ac9 100644 --- a/test/unittest/capi/accessors/BUILD.gn +++ b/test/unittest/capi/accessors/BUILD.gn @@ -23,6 +23,7 @@ ace_unittest("capi_all_accessors_test") { "accessor_test_utils.cpp", "action_sheet_accessor_test.cpp", "alert_dialog_accessor_test.cpp", + "animated_drawable_descriptor_accessor_test.cpp", "appear_symbol_effect_accessor_test.cpp", "background_color_style_accessor_test.cpp", "base_event_accessor_test.cpp", @@ -53,6 +54,7 @@ ace_unittest("capi_all_accessors_test") { "disappear_symbol_effect_accessor_test.cpp", "drag_event_accessor_test.cpp", "draw_modifier_accessor_test.cpp", + "drawable_descriptor_accessor_test.cpp", #"drawing_canvas_accessor_test.cpp", "drawing_rendering_context_accessor_test.cpp", "ellipse_shape_accessor_test.cpp", @@ -84,6 +86,7 @@ ace_unittest("capi_all_accessors_test") { "indicator_component_controller_accessor_test.cpp", "js_result_accessor_test.cpp", "key_event_accessor_test.cpp", + "layered_drawable_descriptor_accessor_test.cpp", "layout_manager_accessor_test.cpp", "length_metrics_accessor_test.cpp", "letter_spacing_style_accessor_test.cpp", @@ -111,6 +114,7 @@ ace_unittest("capi_all_accessors_test") { "pinch_gesture_event_accessor_test.cpp", "pinch_gesture_interface_accessor_test.cpp", "pinch_recognizer_accessor_test.cpp", + "pixel_map_drawable_descriptor_accessor_test.cpp", "progress_mask_accessor_test.cpp", "pulse_symbol_effect_accessor_test.cpp", "rect_shape_accessor_test.cpp", diff --git a/test/unittest/capi/accessors/animated_drawable_descriptor_accessor_test.cpp b/test/unittest/capi/accessors/animated_drawable_descriptor_accessor_test.cpp new file mode 100644 index 00000000000..70e4777cd3d --- /dev/null +++ b/test/unittest/capi/accessors/animated_drawable_descriptor_accessor_test.cpp @@ -0,0 +1,95 @@ +/* + * 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 "accessor_test_base.h" +#include "accessor_test_fixtures.h" + +#include "core/interfaces/native/implementation/animated_drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/layered_drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/pixel_map_drawable_descriptor_peer.h" +#include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/reverse_converter.h" + +namespace OHOS::Ace::NG { +using namespace testing; +using namespace testing::ext; +using namespace AccessorTestFixtures; +using namespace Converter; + +namespace { +constexpr auto DEFAULT_SIZE_TEST = 0; +constexpr auto DEFAULT_DURATION_TEST = 0; +constexpr auto DEFAULT_ITERATIONS_TEST = 1; +} // namespace + +class AnimatedDrawableDescriptorAccessorTest + : public AccessorTestCtorBase { +public: + void* CreatePeerInstance() override + { + return accessor_->ctor(nullptr, nullptr); + } + RefPtr CreatePixelMap(std::string& src); +}; + +RefPtr AnimatedDrawableDescriptorAccessorTest::CreatePixelMap(std::string& src) +{ + void* ptr = reinterpret_cast(src.data()); + return PixelMap::CreatePixelMap(ptr); +} + +/** + * @tc.name: ctorTestDefault + * @tc.desc: Check the functionality of ctor + * @tc.type: FUNC + */ +HWTEST_F(AnimatedDrawableDescriptorAccessorTest, ctorTestDefault, TestSize.Level1) +{ + EXPECT_FALSE(peer_->GetPixelMap()); + EXPECT_EQ(peer_->GetPixelMapList().size(), DEFAULT_SIZE_TEST); + EXPECT_EQ(peer_->GetDuration(), DEFAULT_DURATION_TEST); + EXPECT_EQ(peer_->GetIterations(), DEFAULT_ITERATIONS_TEST); +} + +/** + * @tc.name: ctorTest + * @tc.desc: Check the functionality of ctor + * @tc.type: FUNC + */ +HWTEST_F(AnimatedDrawableDescriptorAccessorTest, ctorTest, TestSize.Level1) +{ + std::string imagesSrc = "test"; + auto duration = 100; + auto iterations = 10; + auto pixelMap1 = CreatePixelMap(imagesSrc); + auto pixelMap2 = CreatePixelMap(imagesSrc); + const vector> pixelMapArray = { pixelMap1, pixelMap2 }; + auto array = ArkValue(pixelMapArray, Converter::FC); + Ark_AnimationOptions animationOptions = { + .duration = ArkValue(duration), + .iterations = ArkValue(iterations), + }; + auto optOptions = ArkValue(animationOptions); + auto animatedDrawableDescriptor = accessor_->ctor(&array, &optOptions); + ASSERT_TRUE(animatedDrawableDescriptor); + EXPECT_EQ(animatedDrawableDescriptor->GetDuration(), duration); + EXPECT_EQ(animatedDrawableDescriptor->GetIterations(), iterations); + EXPECT_EQ(animatedDrawableDescriptor->GetPixelMapList(), pixelMapArray); +} +} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/capi/accessors/drawable_descriptor_accessor_test.cpp b/test/unittest/capi/accessors/drawable_descriptor_accessor_test.cpp new file mode 100644 index 00000000000..b95422e0808 --- /dev/null +++ b/test/unittest/capi/accessors/drawable_descriptor_accessor_test.cpp @@ -0,0 +1,101 @@ +/* + * 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 "accessor_test_base.h" +#include "accessor_test_fixtures.h" + +#include "core/interfaces/native/implementation/animated_drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/layered_drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/pixel_map_drawable_descriptor_peer.h" +#include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/reverse_converter.h" + +namespace OHOS::Ace::NG { +using namespace testing; +using namespace testing::ext; +using namespace AccessorTestFixtures; +using namespace Converter; + +class DrawableDescriptorAccessorTest + : public AccessorTestBase { +public: + RefPtr CreatePixelMap(std::string& src); +}; + +RefPtr DrawableDescriptorAccessorTest::CreatePixelMap(std::string& src) +{ + void* ptr = reinterpret_cast(src.data()); + return PixelMap::CreatePixelMap(ptr); +} + +/** + * @tc.name: ctorTest + * @tc.desc: Check the functionality of ctor + * @tc.type: FUNC + */ +HWTEST_F(DrawableDescriptorAccessorTest, ctorTest, TestSize.Level1) +{ + EXPECT_FALSE(peer_->HasPixelMap()); +} + +/** + * @tc.name: getPixelMapTest + * @tc.desc: Check the functionality of getPixelMap + * @tc.type: FUNC + */ +HWTEST_F(DrawableDescriptorAccessorTest, getPixelMapTest, TestSize.Level1) +{ + auto checkGetPixelMap = [](DrawableDescriptorPeer* peer, PixelMapPtr pixelMap, bool isEmpty) { + auto pixelMapPeer = accessor_->getPixelMap(peer); + ASSERT_TRUE(pixelMapPeer); + if (isEmpty) { + EXPECT_FALSE(pixelMapPeer->pixelMap); + } else { + ASSERT_TRUE(pixelMapPeer->pixelMap); + } + }; + + // DrawableDescriptorPeer + checkGetPixelMap(peer_, nullptr, true); + + // LayeredDrawablePeer + std::string imagesSrc = "test"; + auto foregroundPixelMap = CreatePixelMap(imagesSrc); + auto backgroundPixelMap = CreatePixelMap(imagesSrc); + auto maskPixelMap = CreatePixelMap(imagesSrc); + auto layeredPeer = + PeerUtils::CreatePeer(foregroundPixelMap, backgroundPixelMap, maskPixelMap); + checkGetPixelMap(layeredPeer, nullptr, true); + PeerUtils::DestroyPeer(layeredPeer); + + // AnimatedDrawableDescriptorPeer + const vector> pixelMapArray = { foregroundPixelMap, backgroundPixelMap, maskPixelMap }; + auto animatedPeer = + PeerUtils::CreatePeer(pixelMapArray, std::nullopt, std::nullopt); + checkGetPixelMap(animatedPeer, foregroundPixelMap, false); + PeerUtils::DestroyPeer(animatedPeer); + + // PixelMapDrawableDescriptorPeer + auto pixelMapPeer = PeerUtils::CreatePeer(); + checkGetPixelMap(pixelMapPeer, nullptr, true); + pixelMapPeer->SetPixelMap(foregroundPixelMap); + checkGetPixelMap(pixelMapPeer, foregroundPixelMap, false); + PeerUtils::DestroyPeer(pixelMapPeer); +} +} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/capi/accessors/layered_drawable_descriptor_accessor_test.cpp b/test/unittest/capi/accessors/layered_drawable_descriptor_accessor_test.cpp new file mode 100644 index 00000000000..b7293d4187d --- /dev/null +++ b/test/unittest/capi/accessors/layered_drawable_descriptor_accessor_test.cpp @@ -0,0 +1,180 @@ +/* + * 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 "accessor_test_base.h" +#include "accessor_test_fixtures.h" + +#include "core/interfaces/native/implementation/animated_drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/layered_drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/pixel_map_drawable_descriptor_peer.h" +#include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/reverse_converter.h" + +namespace OHOS::Ace::NG { +using namespace testing; +using namespace testing::ext; +using namespace AccessorTestFixtures; +using namespace Converter; + +class LayeredDrawableDescriptorAccessorTest + : public AccessorTestCtorBase { +public: + void* CreatePeerInstance() override + { + return accessor_->ctor(nullptr, nullptr, nullptr); + } + RefPtr CreatePixelMap(std::string& src); +}; + +RefPtr LayeredDrawableDescriptorAccessorTest::CreatePixelMap(std::string& src) +{ + void* ptr = reinterpret_cast(src.data()); + return PixelMap::CreatePixelMap(ptr); +} + +/** + * @tc.name: ctorTestDefault + * @tc.desc: Check the functionality of ctor + * @tc.type: FUNC + */ +HWTEST_F(LayeredDrawableDescriptorAccessorTest, ctorTestDefault, TestSize.Level1) +{ + EXPECT_FALSE(peer_->GetPixelMap()); + auto foregroundPeer = peer_->GetForeground(); + ASSERT_TRUE(foregroundPeer); + EXPECT_FALSE(foregroundPeer->GetPixelMap()); + auto backgroundPeer = peer_->GetBackground(); + ASSERT_TRUE(backgroundPeer); + EXPECT_FALSE(backgroundPeer->GetPixelMap()); + auto maskPeer = peer_->GetMask(); + ASSERT_TRUE(maskPeer); + EXPECT_FALSE(maskPeer->GetPixelMap()); +} + +/** + * @tc.name: ctorTest + * @tc.desc: Check the functionality of ctor + * @tc.type: FUNC + */ +HWTEST_F(LayeredDrawableDescriptorAccessorTest, ctorTest, TestSize.Level1) +{ + std::string imagesSrc = "test"; + auto foregroundPixelMap = CreatePixelMap(imagesSrc); + auto backgroundPixelMap = CreatePixelMap(imagesSrc); + auto maskPixelMap = CreatePixelMap(imagesSrc); + auto foregroundDesciptror = PeerUtils::CreatePeer(foregroundPixelMap); + auto backgroundDesciptror = PeerUtils::CreatePeer(backgroundPixelMap); + auto maskDesciptror = PeerUtils::CreatePeer(maskPixelMap); + auto optForegroundDesciptror = ArkValue(foregroundDesciptror); + auto optBackgroundDesciptror = ArkValue(backgroundDesciptror); + auto optMaskDesciptror = ArkValue(maskDesciptror); + auto layeredDrawableDescriptor = accessor_->ctor(&optForegroundDesciptror, + &optBackgroundDesciptror, &optMaskDesciptror); + ASSERT_TRUE(layeredDrawableDescriptor); + auto foregroundPeer = layeredDrawableDescriptor->GetForeground(); + ASSERT_TRUE(foregroundPeer); + EXPECT_EQ(foregroundPeer->GetPixelMap(), foregroundDesciptror->GetPixelMap()); + auto backgroundPeer = layeredDrawableDescriptor->GetBackground(); + ASSERT_TRUE(backgroundPeer); + EXPECT_EQ(backgroundPeer->GetPixelMap(), backgroundDesciptror->GetPixelMap()); + auto maskPeer = layeredDrawableDescriptor->GetMask(); + ASSERT_TRUE(maskPeer); + EXPECT_EQ(maskPeer->GetPixelMap(), maskDesciptror->GetPixelMap()); + finalyzer_(layeredDrawableDescriptor); + PeerUtils::DestroyPeer(foregroundDesciptror); + PeerUtils::DestroyPeer(backgroundDesciptror); + PeerUtils::DestroyPeer(maskDesciptror); +} + +/** + * @tc.name: getForegroundTest + * @tc.desc: Check the functionality of getForeground + * @tc.type: FUNC + */ +HWTEST_F(LayeredDrawableDescriptorAccessorTest, getForegroundTest, TestSize.Level1) +{ + ASSERT_TRUE(accessor_->getForeground); + std::string imagesSrc = "test"; + auto foregroundPixelMap = CreatePixelMap(imagesSrc); + auto empty = ArkValue(); + auto foregroundDesciptor = PeerUtils::CreatePeer(foregroundPixelMap); + auto optForegroundDesciptor = ArkValue(foregroundDesciptor); + auto layeredDrawableDescriptor = accessor_->ctor(&optForegroundDesciptor, &empty, &empty); + ASSERT_TRUE(layeredDrawableDescriptor); + auto foregroundPeer = accessor_->getForeground(layeredDrawableDescriptor); + ASSERT_TRUE(foregroundPeer); + EXPECT_EQ(foregroundPeer->GetPixelMap(), foregroundDesciptor->GetPixelMap()); + finalyzer_(layeredDrawableDescriptor); + PeerUtils::DestroyPeer(foregroundDesciptor); +} + +/** + * @tc.name: getBackgroundTest + * @tc.desc: Check the functionality of getBackground + * @tc.type: FUNC + */ +HWTEST_F(LayeredDrawableDescriptorAccessorTest, getBackgroundTest, TestSize.Level1) +{ + ASSERT_TRUE(accessor_->getBackground); + std::string imagesSrc = "test"; + auto backgroundPixelMap = CreatePixelMap(imagesSrc); + auto empty = ArkValue(); + auto backgroundDesciptor = PeerUtils::CreatePeer(backgroundPixelMap); + auto optBackgroundDesciptror = ArkValue(backgroundDesciptor); + auto layeredDrawableDescriptor = accessor_->ctor(&empty, &optBackgroundDesciptror, &empty); + ASSERT_TRUE(layeredDrawableDescriptor); + auto backgroundPeer = accessor_->getBackground(layeredDrawableDescriptor); + ASSERT_TRUE(backgroundPeer); + EXPECT_EQ(backgroundPeer->GetPixelMap(), backgroundDesciptor->GetPixelMap()); + finalyzer_(layeredDrawableDescriptor); + PeerUtils::DestroyPeer(backgroundDesciptor); +} + +/** + * @tc.name: getMaskTest + * @tc.desc: Check the functionality of getMask + * @tc.type: FUNC + */ +HWTEST_F(LayeredDrawableDescriptorAccessorTest, getMaskTest, TestSize.Level1) +{ + ASSERT_TRUE(accessor_->getMask); + std::string imagesSrc = "test"; + auto maskPixelMap = CreatePixelMap(imagesSrc); + auto empty = ArkValue(); + auto maskDescriptor = PeerUtils::CreatePeer(maskPixelMap); + auto optMaskDescriptor = ArkValue(maskDescriptor); + auto layeredDrawableDescriptor = accessor_->ctor(&empty, &empty, &optMaskDescriptor); + ASSERT_TRUE(layeredDrawableDescriptor); + auto maskPeer = accessor_->getMask(layeredDrawableDescriptor); + ASSERT_TRUE(maskPeer); + EXPECT_EQ(maskPeer->GetPixelMap(), maskDescriptor->GetPixelMap()); + finalyzer_(layeredDrawableDescriptor); + PeerUtils::DestroyPeer(maskDescriptor); +} + +/** + * @tc.name: getMaskClipPathTest + * @tc.desc: Check the functionality of getMaskClipPath + * @tc.type: FUNC + */ +HWTEST_F(LayeredDrawableDescriptorAccessorTest, DISABLED_getMaskClipPathTest, TestSize.Level1) +{ + // not implemented yet +} +} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/capi/accessors/pixel_map_drawable_descriptor_accessor_test.cpp b/test/unittest/capi/accessors/pixel_map_drawable_descriptor_accessor_test.cpp new file mode 100644 index 00000000000..492a0b18aa8 --- /dev/null +++ b/test/unittest/capi/accessors/pixel_map_drawable_descriptor_accessor_test.cpp @@ -0,0 +1,76 @@ +/* + * 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 "accessor_test_base.h" +#include "accessor_test_fixtures.h" + +#include "core/interfaces/native/implementation/animated_drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/layered_drawable_descriptor_peer.h" +#include "core/interfaces/native/implementation/pixel_map_drawable_descriptor_peer.h" +#include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/reverse_converter.h" + +namespace OHOS::Ace::NG { +using namespace testing; +using namespace testing::ext; +using namespace AccessorTestFixtures; +using namespace Converter; + +class PixelMapDrawableDescriptorAccessorTest + : public AccessorTestCtorBase { +public: + void* CreatePeerInstance() override + { + return accessor_->ctor(nullptr); + } + RefPtr CreatePixelMap(std::string& src); +}; + +RefPtr PixelMapDrawableDescriptorAccessorTest::CreatePixelMap(std::string& src) +{ + void* ptr = reinterpret_cast(src.data()); + return PixelMap::CreatePixelMap(ptr); +} + +/** + * @tc.name: ctorTestDefault + * @tc.desc: Check the functionality of ctor + * @tc.type: FUNC + */ +HWTEST_F(PixelMapDrawableDescriptorAccessorTest, ctorTestDefault, TestSize.Level1) +{ + EXPECT_FALSE(peer_->GetPixelMap()); +} + +/** + * @tc.name: ctorTest + * @tc.desc: Check the functionality of ctor + * @tc.type: FUNC + */ +HWTEST_F(PixelMapDrawableDescriptorAccessorTest, ctorTest, TestSize.Level1) +{ + std::string imagesSrc = "test"; + auto pixelMap = CreatePixelMap(imagesSrc); + auto pixelMapPeer = PixelMapPeer::Create(pixelMap); + auto optPixelMapPeer = ArkValue(pixelMapPeer); + auto pixelMapDrawableDescriptor = accessor_->ctor(&optPixelMapPeer); + ASSERT_TRUE(pixelMapDrawableDescriptor); + EXPECT_EQ(pixelMapDrawableDescriptor->GetPixelMap(), pixelMap); +} +} // namespace OHOS::Ace::NG \ No newline at end of file -- Gitee From 3fc86f26ae609a9b56bd8130a7da611ae09fbdf4 Mon Sep 17 00:00:00 2001 From: evstigneevroman_9cd1 Date: Fri, 15 Aug 2025 14:00:32 +0300 Subject: [PATCH 2/2] add MaskPathImpl implementation Signed-off-by: evstigneevroman_9cd1 Change-Id: I4edf06889dbb1088e367dfc6b7ea71ba6d4530de --- .../layered_drawable_descriptor_accessor.cpp | 4 +- .../layered_drawable_descriptor_peer.cpp | 38 ++++++++++++++ .../layered_drawable_descriptor_peer.h | 2 + .../native/utility/reverse_converter.cpp | 25 ++++++++++ .../native/utility/reverse_converter.h | 2 + test/mock/base/mock_image_perf.cpp | 2 +- .../render/mock_render_context_creator.cpp | 2 +- .../capi/accessors/accessor_test_base.h | 2 + ...ered_drawable_descriptor_accessor_test.cpp | 49 ++++++++++++++++++- ...scrollable_common_method_modifier_test.cpp | 2 +- .../capi/modifiers/modifier_test_base.h | 2 + 11 files changed, 123 insertions(+), 7 deletions(-) diff --git a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_accessor.cpp b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_accessor.cpp index 23315d1e543..5becbab4cd1 100644 --- a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_accessor.cpp @@ -15,6 +15,7 @@ #include "core/components_ng/base/frame_node.h" #include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/reverse_converter.h" #include "layered_drawable_descriptor_peer.h" #include "arkoala_api_generated.h" @@ -59,8 +60,7 @@ Ark_DrawableDescriptor GetMaskImpl(Ark_LayeredDrawableDescriptor peer) } Ark_String GetMaskClipPathImpl() { - LOGE("ARKOALA: Ark_LayeredDrawableDescriptor::GetMaskClipPathImpl not implemented"); - return {}; + return ArkValue(LayeredDrawableDescriptorPeer::GetStaticMaskClipPath(), Converter::FC); } } // LayeredDrawableDescriptorAccessor const GENERATED_ArkUILayeredDrawableDescriptorAccessor* GetLayeredDrawableDescriptorAccessor() diff --git a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.cpp b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.cpp index e89c6b2c022..41a2513b523 100644 --- a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.cpp +++ b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.cpp @@ -14,6 +14,38 @@ */ #include "layered_drawable_descriptor_peer.h" +#include "frameworks/core/common/resource/resource_manager.h" +#include "core/interfaces/native/utility/converter.h" +#include "core/interfaces/native/utility/reverse_converter.h" + +#ifdef PREVIEW +#ifdef WINDOWS_PLATFORM +#include +#include +#ifdef ERROR +#undef ERROR +#endif +#elif defined(MAC_PLATFORM) +#include +#else +#include +#endif +#endif + +// define for get resource path in preview scenes +const static std::string PREVIEW_LOAD_RESOURCE_ID = "ohos_drawable_descriptor_path"; +#ifdef PREVIEW +#ifdef WINDOWS_PLATFORM +constexpr static char PREVIEW_LOAD_RESOURCE_PATH[] = "\\resources\\resources.index"; +#else +constexpr static char PREVIEW_LOAD_RESOURCE_PATH[] = "/resources/resources.index"; +#endif + +#ifdef LINUX_PLATFORM +const static size_t MAX_PATH_LEN = 255; +#endif +#endif + using namespace OHOS::Ace::NG; DrawableDescriptorPeer* LayeredDrawableDescriptorPeer::GetForeground() const @@ -29,4 +61,10 @@ DrawableDescriptorPeer* LayeredDrawableDescriptorPeer::GetBackground() const DrawableDescriptorPeer* LayeredDrawableDescriptorPeer::GetMask() const { return PeerUtils::CreatePeer(mask); +} + +std::string LayeredDrawableDescriptorPeer::GetStaticMaskClipPath() +{ + auto resConv = Converter::ArkCreate(PREVIEW_LOAD_RESOURCE_ID, Converter::ResourceType::STRING, Converter::FC); + return Converter::OptConvert(resConv).value_or(""); } \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.h b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.h index d90fd873990..e5fd8a4b698 100644 --- a/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.h +++ b/frameworks/core/interfaces/native/implementation/layered_drawable_descriptor_peer.h @@ -29,6 +29,8 @@ public: DrawableDescriptorPeer* GetBackground() const; DrawableDescriptorPeer* GetMask() const; + static std::string GetStaticMaskClipPath(); + protected: LayeredDrawableDescriptorPeer(PixelMapPtr foregroundValue, PixelMapPtr backgroundValue, PixelMapPtr maskValue) : foreground(foregroundValue), background(backgroundValue), mask(maskValue) diff --git a/frameworks/core/interfaces/native/utility/reverse_converter.cpp b/frameworks/core/interfaces/native/utility/reverse_converter.cpp index 4e6a98d9eac..d2ade119b9a 100644 --- a/frameworks/core/interfaces/native/utility/reverse_converter.cpp +++ b/frameworks/core/interfaces/native/utility/reverse_converter.cpp @@ -904,4 +904,29 @@ void AssignArkValue(Ark_NavigationOperation& dst, const NG::NavigationOperation& { dst = static_cast(src); } + +template<> +Ark_Resource ArkCreate(int64_t id, ResourceType type) +{ + return { + .id = ArkValue(id), + .type = ArkValue(static_cast(type)), + .moduleName = ArkValue(""), + .bundleName = ArkValue(""), + .params = ArkValue(), + }; +} + +template<> +Ark_Resource ArkCreate(std::string name, ResourceType type, ConvContext *ctx) +{ + std::vector params = { name }; + return { + .id = ArkValue(static_cast(-1)), + .type = ArkValue(static_cast(type)), + .moduleName = ArkValue(""), + .bundleName = ArkValue(""), + .params = ArkValue(params, ctx), + }; +} } // namespace OHOS::Ace::NG::Converter diff --git a/frameworks/core/interfaces/native/utility/reverse_converter.h b/frameworks/core/interfaces/native/utility/reverse_converter.h index ea937d13810..e5dc0c82ac7 100644 --- a/frameworks/core/interfaces/native/utility/reverse_converter.h +++ b/frameworks/core/interfaces/native/utility/reverse_converter.h @@ -393,6 +393,8 @@ namespace OHOS::Ace::NG::Converter { // SORTED_SECTION template<> Ark_LengthMetrics ArkCreate(Ark_LengthUnit unit, float value); + template<> Ark_Resource ArkCreate(int64_t id, ResourceType type); + template<> Ark_Resource ArkCreate(std::string name, ResourceType type, ConvContext *ctx); // ATTENTION!!! Add AssignArkValue implementations above this line! diff --git a/test/mock/base/mock_image_perf.cpp b/test/mock/base/mock_image_perf.cpp index ae1377158eb..784a796cf4d 100644 --- a/test/mock/base/mock_image_perf.cpp +++ b/test/mock/base/mock_image_perf.cpp @@ -19,7 +19,7 @@ namespace OHOS::Ace { ImagePerf* ImagePerf::GetPerfMonitor() { - static MockImagePerf instance; + static testing::NiceMock instance; return &instance; } } // namespace OHOS::Ace \ No newline at end of file diff --git a/test/mock/core/render/mock_render_context_creator.cpp b/test/mock/core/render/mock_render_context_creator.cpp index 2a08c1fcf6e..0598859b661 100644 --- a/test/mock/core/render/mock_render_context_creator.cpp +++ b/test/mock/core/render/mock_render_context_creator.cpp @@ -18,6 +18,6 @@ namespace OHOS::Ace::NG { RefPtr RenderContext::Create() { - return MakeRefPtr(); + return MakeRefPtr>(); } } // namespace OHOS::Ace::NG diff --git a/test/unittest/capi/accessors/accessor_test_base.h b/test/unittest/capi/accessors/accessor_test_base.h index 9175287acae..4b2751cd1a3 100644 --- a/test/unittest/capi/accessors/accessor_test_base.h +++ b/test/unittest/capi/accessors/accessor_test_base.h @@ -21,6 +21,7 @@ #include "core/interfaces/native/utility/converter.h" #include "core/interfaces/native/utility/peer_utils.h" #include "core/interfaces/native/utility/reverse_converter.h" +#include "test/mock/base/mock_system_properties.h" #include "test/mock/core/common/mock_container.h" #include "test/mock/core/pipeline/mock_pipeline_context.h" #include "test/mock/core/common/mock_theme_style.h" @@ -72,6 +73,7 @@ public: accessor_ = accessors_ ? (accessors_->*GetAccessorFunc)() : nullptr; MockPipelineContext::SetUp(); + g_isResourceDecoupling = false; themeManager_ = AceType::MakeRefPtr>(); ASSERT_TRUE(MockPipelineContext::GetCurrent()); MockPipelineContext::GetCurrent()->SetThemeManager(themeManager_); diff --git a/test/unittest/capi/accessors/layered_drawable_descriptor_accessor_test.cpp b/test/unittest/capi/accessors/layered_drawable_descriptor_accessor_test.cpp index b7293d4187d..fba00f28fb5 100644 --- a/test/unittest/capi/accessors/layered_drawable_descriptor_accessor_test.cpp +++ b/test/unittest/capi/accessors/layered_drawable_descriptor_accessor_test.cpp @@ -18,6 +18,7 @@ #include "accessor_test_base.h" #include "accessor_test_fixtures.h" +#include "core/common/resource/resource_manager.h" #include "core/interfaces/native/implementation/animated_drawable_descriptor_peer.h" #include "core/interfaces/native/implementation/drawable_descriptor_peer.h" #include "core/interfaces/native/implementation/layered_drawable_descriptor_peer.h" @@ -30,7 +31,44 @@ using namespace testing; using namespace testing::ext; using namespace AccessorTestFixtures; using namespace Converter; +namespace { +constexpr auto TEST_CLIP_PATH = "/some_clip_path/file.svg"; +class MockResourceAdapter : public ResourceAdapter { + DECLARE_ACE_TYPE(MockResourceAdapter, ResourceAdapter); + +public: + MockResourceAdapter() = default; + ~MockResourceAdapter() override = default; + MOCK_METHOD0(Create, RefPtr()); + MOCK_METHOD1(Init, void(const ResourceInfo& resourceInfo)); + MOCK_METHOD2(UpdateConfig, void(const ResourceConfiguration& config, bool themeFlag)); + MOCK_METHOD1(GetTheme, RefPtr(int32_t themeId)); + MOCK_METHOD1(GetColor, Color(uint32_t resId)); + MOCK_METHOD1(GetDimension, Dimension(uint32_t resId)); + MOCK_METHOD1(GetString, std::string(uint32_t resId)); + MOCK_METHOD1(GetDouble, double(uint32_t resId)); + MOCK_METHOD1(GetInt, int32_t(uint32_t resId)); + MOCK_METHOD2(GetPluralString, std::string(uint32_t resId, int quantity)); + MOCK_METHOD1(GetMediaPath, std::string(uint32_t resId)); + MOCK_METHOD1(GetRawfile, std::string(const std::string& fileName)); + MOCK_METHOD3(GetRawFileData, bool(const std::string& rawFile, size_t& len, std::unique_ptr& dest)); + MOCK_METHOD3(GetMediaData, bool(uint32_t resId, size_t& len, std::unique_ptr& dest)); + MOCK_METHOD3(GetMediaData, bool(const std::string& resName, size_t& len, std::unique_ptr& dest)); + MOCK_METHOD2(UpdateResourceManager, void(const std::string& bundleName, const std::string& moduleName)); + MOCK_CONST_METHOD1(GetBoolean, bool(uint32_t resId)); + MOCK_CONST_METHOD1(GetIntArray, std::vector(uint32_t resId)); + MOCK_CONST_METHOD2(GetResource, bool(uint32_t resId, std::ostream& dest)); + MOCK_CONST_METHOD2(GetResource, bool(const std::string& resId, std::ostream& dest)); + MOCK_CONST_METHOD3(GetIdByName, bool(const std::string& resName, const std::string& resType, uint32_t& resId)); + MOCK_CONST_METHOD1(GetStringArray, std::vector(uint32_t resId)); + + std::string GetStringByName(const std::string& resName) override + { + return TEST_CLIP_PATH; + } +}; +} // namespace class LayeredDrawableDescriptorAccessorTest : public AccessorTestCtorBase { @@ -173,8 +211,15 @@ HWTEST_F(LayeredDrawableDescriptorAccessorTest, getMaskTest, TestSize.Level1) * @tc.desc: Check the functionality of getMaskClipPath * @tc.type: FUNC */ -HWTEST_F(LayeredDrawableDescriptorAccessorTest, DISABLED_getMaskClipPathTest, TestSize.Level1) +HWTEST_F(LayeredDrawableDescriptorAccessorTest, getMaskClipPathTest, TestSize.Level1) { - // not implemented yet + g_isResourceDecoupling = true; + auto adapter = AceType::MakeRefPtr(); + ASSERT_TRUE(adapter); + OHOS::Ace::ResourceManager::GetInstance() + .RegisterMainResourceAdapter("", "", OHOS::Ace::Container::CurrentIdSafely(), adapter); + auto path = Convert(accessor_->getMaskClipPath()); + EXPECT_EQ(path, TEST_CLIP_PATH); + g_isResourceDecoupling = false; } } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/capi/modifiers/generated/scrollable_common_method_modifier_test.cpp b/test/unittest/capi/modifiers/generated/scrollable_common_method_modifier_test.cpp index a496362159e..a3255011009 100644 --- a/test/unittest/capi/modifiers/generated/scrollable_common_method_modifier_test.cpp +++ b/test/unittest/capi/modifiers/generated/scrollable_common_method_modifier_test.cpp @@ -707,7 +707,7 @@ HWTEST_P(ScrollableCommonMethodModifierTest, DISABLED_setDigitalCrownSensitivity * @tc.desc: * @tc.type: FUNC */ -HWTEST_P(ScrollableCommonMethodModifierTest, DISABLED_setDigitalCrownSensitivityTestDigitalCrownSensitivityValidValues, +HWTEST_P(ScrollableCommonMethodModifierTest, setDigitalCrownSensitivityTestDigitalCrownSensitivityValidValues, TestSize.Level1) { Opt_CrownSensitivity initValueDigitalCrownSensitivity; diff --git a/test/unittest/capi/modifiers/modifier_test_base.h b/test/unittest/capi/modifiers/modifier_test_base.h index be76ce7aaa5..e70ff018d0f 100644 --- a/test/unittest/capi/modifiers/modifier_test_base.h +++ b/test/unittest/capi/modifiers/modifier_test_base.h @@ -23,6 +23,7 @@ #include "arkoala_api_generated.h" #include "core/interfaces/native/utility/peer_utils.h" +#include "test/mock/base/mock_system_properties.h" #include "test/mock/base/mock_task_executor.h" #include "test/mock/core/common/mock_container.h" #include "test/mock/core/common/mock_theme_manager.h" @@ -112,6 +113,7 @@ public: themeManager_ = AceType::MakeRefPtr<::testing::NiceMock>(); MockPipelineContext::GetCurrent()->SetThemeManager(themeManager_); + g_isResourceDecoupling = false; // assume using of test/mock/core/common/mock_theme_constants.cpp in build themeConstants_ = AceType::MakeRefPtr(nullptr); EXPECT_CALL(*themeManager_, GetThemeConstants(testing::_, testing::_)) -- Gitee