From b8ea90854f5a2fabe819688e5ad5f6318c0652e4 Mon Sep 17 00:00:00 2001 From: WangYing225 Date: Tue, 30 Jul 2024 15:42:53 +0800 Subject: [PATCH] fix differences 6 Signed-off-by: WangYing225 Change-Id: Idaf348cf10ab15b9690b5ef3c10024e99d3a4f2b --- .../render/adapter/media_player_impl.cpp | 52 ++- .../render/adapter/media_player_impl.h | 3 + .../render/adapter/rosen_render_surface.cpp | 4 +- .../components_ng/render/render_surface.h | 29 +- .../render/render_surface_creator.cpp | 24 +- .../native/node/node_stack_modifier.cpp | 2 +- .../native/node/node_stack_modifier.h | 2 +- .../native/node/node_xcomponent_modifier.cpp | 12 +- .../native/native_interface_xcomponent.cpp | 36 +- .../native/native_interface_xcomponent.h | 52 +-- .../core/render/mock_media_player_creator.cpp | 2 +- test/mock/core/render/mock_render_surface.h | 2 +- test/unittest/core/layout/safe_area/BUILD.gn | 2 +- .../safe_area/expand_safe_area_test_ng.cpp | 2 +- .../relative_container_common_ng.cpp | 14 +- .../relative_container_common_ng.h | 1 - .../pattern/xcomponent/xcomponent_test_ng.cpp | 331 +++++++++--------- 17 files changed, 275 insertions(+), 295 deletions(-) diff --git a/frameworks/core/components_ng/render/adapter/media_player_impl.cpp b/frameworks/core/components_ng/render/adapter/media_player_impl.cpp index 83201f2d72e..b573467691d 100755 --- a/frameworks/core/components_ng/render/adapter/media_player_impl.cpp +++ b/frameworks/core/components_ng/render/adapter/media_player_impl.cpp @@ -21,13 +21,14 @@ #include "core/common/container.h" #include "core/components/video/video_utils.h" #include "core/components_ng/render/adapter/render_surface_impl.h" +#ifdef RENDER_EXTRACT_SUPPORTED +#include "core/components_ng/render/adapter/render_texture_impl.h" +#endif #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { namespace { - constexpr int32_t SECONDS_TO_MILLISECONDS = 1000; - } // namespace MediaPlayerImpl::~MediaPlayerImpl() @@ -92,6 +93,11 @@ void MediaPlayerImpl::InitListener() if (player->stateChangeCallback_) { player->stateChangeCallback_(isPlaying ? PlaybackStatus::STARTED : PlaybackStatus::PAUSED); } +#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) + if (player->startRenderFrameCallback_ && isPlaying) { + player->startRenderFrameCallback_(); + } +#endif }, "ArkUIVideoPlayerStatusChanged"); }; @@ -144,8 +150,18 @@ bool MediaPlayerImpl::SetSource(const std::string& src) void MediaPlayerImpl::SetRenderSurface(const RefPtr& renderSurface) { renderSurface_ = renderSurface; +#ifdef RENDER_EXTRACT_SUPPORTED + if (renderSurface ->IsTexture()) { + auto surfaceImpl = AceType::DynamicCast(renderSurface); + surfaceImpl->SetExtSurfaceCallback(AceType::Claim(this)); + } else { + auto surfaceImpl = AceType::DynamicCast(renderSurface); + surfaceImpl->SetExtSurfaceCallback(AceType::Claim(this)); + } +#else auto surfaceImpl = AceType::DynamicCast(renderSurface); surfaceImpl->SetExtSurfaceCallback(AceType::Claim(this)); +#endif } void MediaPlayerImpl::RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUpdatedEvent, @@ -159,6 +175,11 @@ void MediaPlayerImpl::RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUp startRenderFrameCallback_ = startRenderFrameEvent; } +void MediaPlayerImpl::RegisterTextureEvent(TextureRefreshEnVent&& textureRefreshEvent) +{ + textureRefreshCallback_ = textureRefreshEvent; +} + int32_t MediaPlayerImpl::GetDuration(int32_t& duration) { CHECK_NULL_RETURN(player_, -1); @@ -195,9 +216,23 @@ int32_t MediaPlayerImpl::SetPlaybackSpeed(float speed) int32_t MediaPlayerImpl::SetSurface() { CHECK_NULL_RETURN(player_, -1); - auto surfaceImpl = AceType::DynamicCast(renderSurface_.Upgrade()); + auto renderSurface = renderSurface_.Upgrade(); + CHECK_NULL_RETURN(renderSurface, -1); +#ifdef RENDER_EXTRACT_SUPPORTED + if (renderSurface ->IsTexture()) { + auto textureImpl = AceType::DynamicCast(renderSurface); + CHECK_NULL_RETURN(textureImpl, -1); + player_->SetSurfaceId(textureImpl->GetTextureId(), true); + } else { + auto surfaceImpl = AceType::DynamicCast(renderSurface); + CHECK_NULL_RETURN(surfaceImpl, -1); + player_->SetSurfaceId(surfaceImpl->GetSurfaceId(), false); + } +#else + auto surfaceImpl = AceType::DynamicCast(renderSurface); CHECK_NULL_RETURN(surfaceImpl, -1); - player_->SetSurfaceId(surfaceImpl->GetSurfaceId()); + player_->SetSurfaceId(surfaceImpl->GetSurfaceId(), false); +#endif return 0; } @@ -266,4 +301,11 @@ void MediaPlayerImpl::ProcessSurfaceChange(int32_t width, int32_t height) } } -} // namespace OHOS::Ace::NG +void MediaPlayerImpl::ProcessTextureRefresh(int32_t instanceId, int64_t textureId) +{ + if (textureRefreshCallback_) { + textureRefreshCallback_(instanceId, textureId); + } +} + +} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/core/components_ng/render/adapter/media_player_impl.h b/frameworks/core/components_ng/render/adapter/media_player_impl.h index 131c043a2a0..02ae55e4eb8 100644 --- a/frameworks/core/components_ng/render/adapter/media_player_impl.h +++ b/frameworks/core/components_ng/render/adapter/media_player_impl.h @@ -37,6 +37,7 @@ public: void SetRenderSurface(const RefPtr& renderSurface) override; void RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUpdatedEvent, StateChangedEvent&& stateChangedEvent, CommonEvent&& errorEvent, CommonEvent&& resolutionChangeEvent, CommonEvent&& startRenderFrameEvent) override; + void RegisterTextureEvent(TextureRefreshEnVent&& textureRefreshEvent) override; int32_t GetDuration(int32_t& duration) override; int32_t GetVideoWidth() override; int32_t GetVideoHeight() override; @@ -54,6 +55,7 @@ public: void ProcessSurfaceCreate() override; void ProcessSurfaceChange(int32_t width, int32_t height) override; void ProcessSurfaceDestroy() override {} + void ProcessTextureRefresh(int32_t instanceId, int64_t textureId) override; private: void InitListener(); @@ -65,6 +67,7 @@ private: CommonEvent errorCallback_; CommonEvent resolutionChangeCallback_; CommonEvent startRenderFrameCallback_; + TextureRefreshEnVent textureRefreshCallback_; ACE_DISALLOW_COPY_AND_MOVE(MediaPlayerImpl); }; diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp index 09a9dfeac7d..9811486acc8 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp @@ -38,7 +38,7 @@ const uint32_t ADJUST_WEB_DRAW_LENGTH = 3000; const uint32_t DEFAULT_WEB_DRAW_LENGTH = 6167; const std::string SURFACE_WIDTH = "surface_width"; const std::string SURFACE_HEIGHT = "surface_height"; -const int32_t SIZE_LIMIT = 5999; +const int32_t SIZE_LIMIT = 7999; const int32_t PERMITTED_DIFFERENCE = 100; const int32_t FAILED_LIMIT = 3; @@ -320,8 +320,6 @@ bool RosenRenderSurface::CompareBufferSize(int32_t width, int32_t height, failTimes_++; if (failTimes_ <= FAILED_LIMIT) { pipeline->SetIsFreezeFlushMessage(true); - ACE_SCOPED_TRACE("Web SetIsFreezeFlushMessage (width %d, height %d, bufferWidth %d, bufferHeight %d)", - width, height, bufferWidth, bufferHeight); return false; } } diff --git a/frameworks/core/components_ng/render/render_surface.h b/frameworks/core/components_ng/render/render_surface.h index 83f8996d746..cec638f9c42 100644 --- a/frameworks/core/components_ng/render/render_surface.h +++ b/frameworks/core/components_ng/render/render_surface.h @@ -33,21 +33,8 @@ class ACE_FORCE_EXPORT RenderSurface : public virtual AceType { public: RenderSurface() = default; ~RenderSurface() override = default; - -// under the condition of supporting cross platform and texture rendering, -// it is necessary to dynamically set the rendering type of the surface node. -// the defalut type is RenderSurfaceType::TEXTURE. -#ifdef RENDER_EXTRACT_SUPPORTED - enum class RenderSurfaceType { - UNKNOWN = -1, - SURFACE = 0, - TEXTURE - }; - static RefPtr Create(const RenderSurfaceType& type = RenderSurfaceType::TEXTURE); -#else -// under the condition of supporting ohos platform + static RefPtr Create(); -#endif virtual void InitSurface() {} @@ -80,11 +67,6 @@ public: virtual void SetExtSurfaceBounds(int32_t left, int32_t top, int32_t width, int32_t height) {} - virtual bool SetExtSurfaceBoundsSync(int32_t left, int32_t top, int32_t width, int32_t height) - { - return true; - } - virtual void SetExtSurfaceCallback(const RefPtr& extSurfaceCallback) {} virtual void SetTransformHint(uint32_t rotation) {} @@ -99,15 +81,6 @@ public: virtual void SetSurfaceDefaultSize(int32_t width, int32_t height) {} - virtual bool IsTexture() - { - return false; - } - - virtual void AttachToGLContext(int64_t textureId, bool isAttach) {} - - virtual void UpdateTextureImage(std::vector& matrix) {} - virtual void SetWebMessage(OffsetF offset) {} virtual void SetWebSlideAxis(Axis axis) {} diff --git a/frameworks/core/components_ng/render/render_surface_creator.cpp b/frameworks/core/components_ng/render/render_surface_creator.cpp index 4f82a48df65..12ce09bba64 100644 --- a/frameworks/core/components_ng/render/render_surface_creator.cpp +++ b/frameworks/core/components_ng/render/render_surface_creator.cpp @@ -16,39 +16,19 @@ #if defined(ENABLE_ROSEN_BACKEND) && defined(OHOS_PLATFORM) #include "core/components_ng/render/adapter/rosen_render_surface.h" #endif -#ifdef RENDER_EXTRACT_SUPPORTED -#include "core/components_ng/render/adapter/render_texture_impl.h" -#endif #include "core/components_ng/render/adapter/render_surface_impl.h" #include "core/components_ng/render/render_surface.h" namespace OHOS::Ace::NG { -// under the condition of supporting cross platform and texture rendering -#ifdef RENDER_EXTRACT_SUPPORTED -RefPtr RenderSurface::Create(const RenderSurfaceTpye& type) -{ - if (SystemProperties::GetRosenBackendEnabled()) { - switch (type) { - case RenderSurfaceTpye::SURFACE: - return MakeRefPtr(); - case RenderSurfaceTpye::TEXTURE: - return MakeRefPtr(); - default: - break; - } - } - return MakeRefPtr(); -} -#else -// under the condition of supporting ohos platform RefPtr RenderSurface::Create() { if (SystemProperties::GetRosenBackendEnabled()) { #if defined(OHOS_PLATFORM) && defined(ENABLE_ROSEN_BACKEND) return MakeRefPtr(); +#else + return MakeRefPtr(); #endif } return MakeRefPtr(); } -#endif } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/node/node_stack_modifier.cpp b/frameworks/core/interfaces/native/node/node_stack_modifier.cpp index 4c1f1ca108e..466a588dfb3 100644 --- a/frameworks/core/interfaces/native/node/node_stack_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_stack_modifier.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 diff --git a/frameworks/core/interfaces/native/node/node_stack_modifier.h b/frameworks/core/interfaces/native/node/node_stack_modifier.h index 11055e05842..17c3b098ca1 100644 --- a/frameworks/core/interfaces/native/node/node_stack_modifier.h +++ b/frameworks/core/interfaces/native/node/node_stack_modifier.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 diff --git a/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp b/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp index 4e1507b64d9..0bf9d1a4d5b 100644 --- a/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp @@ -29,10 +29,9 @@ std::string g_strValue; void SetXComponentBackgroundColor(ArkUINodeHandle node, uint32_t color) { - auto* frameNode = reinterpret_cast(node); + auto *frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto type = XComponentModelNG::GetType(frameNode); - if (!XComponentModel::IsBackGroundColorAvailable(type)) { + if (!XComponentModelNG::IsTexture(frameNode)) { return; } ViewAbstract::SetBackgroundColor(frameNode, Color(color)); @@ -40,13 +39,12 @@ void SetXComponentBackgroundColor(ArkUINodeHandle node, uint32_t color) void ResetXComponentBackgroundColor(ArkUINodeHandle node) { - auto* frameNode = reinterpret_cast(node); + auto *frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto type = XComponentModelNG::GetType(frameNode); - if (!XComponentModel::IsBackGroundColorAvailable(type)) { + if (!XComponentModelNG::IsTexture(frameNode)) { return; } - ViewAbstract::SetBackgroundColor(frameNode, (type == XComponentType::SURFACE) ? Color::BLACK : Color::TRANSPARENT); + ViewAbstract::SetBackgroundColor(frameNode, Color(Color::TRANSPARENT)); } void SetXComponentOpacity(ArkUINodeHandle node, ArkUI_Float32 opacity) diff --git a/interfaces/native/native_interface_xcomponent.cpp b/interfaces/native/native_interface_xcomponent.cpp index e06f481ea66..663f556910d 100644 --- a/interfaces/native/native_interface_xcomponent.cpp +++ b/interfaces/native/native_interface_xcomponent.cpp @@ -284,24 +284,6 @@ int32_t OH_NativeXComponent_DetachNativeRootNode( return component->DetachNativeRootNode(root->uiNodeHandle); } -int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component, - void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type), - ArkUI_UIInputEvent_Type type) -{ - if ((component == nullptr) || (callback == nullptr)) { - return OHOS::Ace::ERROR_CODE_PARAM_INVALID; - } - if (type == ArkUI_UIInputEvent_Type::ARKUI_UIINPUTEVENT_TYPE_AXIS) { - return component->RegisterUIAxisEventCallback(callback); - } - return OHOS::Ace::ERROR_CODE_PARAM_INVALID; -} - -int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard) -{ - return component ? component->SetNeedSoftKeyboard(needSoftKeyboard) : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER; -} - int32_t OH_NativeXComponent_RegisterSurfaceShowCallback( OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window)) { @@ -316,6 +298,19 @@ int32_t OH_NativeXComponent_RegisterSurfaceHideCallback( : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER; } +int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component, + void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type), + ArkUI_UIInputEvent_Type type) +{ + if ((component == nullptr) || (callback == nullptr)) { + return OHOS::Ace::ERROR_CODE_PARAM_INVALID; + } + if (type == ArkUI_UIInputEvent_Type::ARKUI_UIINPUTEVENT_TYPE_AXIS) { + return component->RegisterUIAxisEventCallback(callback); + } + return OHOS::Ace::ERROR_CODE_PARAM_INVALID; +} + int32_t OH_NativeXComponent_RegisterOnTouchInterceptCallback( OH_NativeXComponent* component, HitTestMode (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event)) { @@ -325,6 +320,11 @@ int32_t OH_NativeXComponent_RegisterOnTouchInterceptCallback( return component->RegisterOnTouchInterceptCallback(callback); } +int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard) +{ + return component ? component->SetNeedSoftKeyboard(needSoftKeyboard) : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER; +} + int32_t OH_NativeXComponent_GetTouchEventSourceType( OH_NativeXComponent* component, int32_t pointId, OH_NativeXComponent_EventSourceType* sourceType) { diff --git a/interfaces/native/native_interface_xcomponent.h b/interfaces/native/native_interface_xcomponent.h index 988b25b7151..b466e9d6916 100644 --- a/interfaces/native/native_interface_xcomponent.h +++ b/interfaces/native/native_interface_xcomponent.h @@ -715,32 +715,6 @@ int32_t OH_NativeXComponent_AttachNativeRootNode(OH_NativeXComponent* component, */ int32_t OH_NativeXComponent_DetachNativeRootNode(OH_NativeXComponent* component, ArkUI_NodeHandle root); -/** - * @brief Registers a UI input event callback for this OH_NativeXComponent instance and enables the callback to - * be invoked when a UI input event is received. - * - * @param component Indicates the pointer to the OH_NativeXComponent instance. - * @param callback Indicates the pointer to the UI input event callback. - * @param type Indicates the type of the current UI input event. - * @return Returns 0 if success. - * Returns 401 if a parameter exception occurs. - * @since 12 - */ -int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component, - void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type), - ArkUI_UIInputEvent_Type type); - -/** - * @brief Set whether the OH_NativeXComponent instance needs soft keyboard. - * @param component Indicates the pointer to this OH_NativeXComponent instance. - * @param needSoftKeyboard Indicates whether the OH_NativeXComponent instance needs soft keyboard or not. - * Default value is false. - * @return Returns the status code of the execution. - * @since 12 - * @version 1.0 - */ -int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard); - /** * @brief Registers a callback for this OH_NativeXComponent instance. * @@ -765,6 +739,21 @@ int32_t OH_NativeXComponent_RegisterSurfaceShowCallback( int32_t OH_NativeXComponent_RegisterSurfaceHideCallback( OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window)); +/** + * @brief Registers a UI input event callback for this OH_NativeXComponent instance and enables the callback to + * be invoked when a UI input event is received. + * + * @param component Indicates the pointer to the OH_NativeXComponent instance. + * @param callback Indicates the pointer to the UI input event callback. + * @param type Indicates the type of the current UI input event. + * @return Returns 0 if success. + * Returns 401 if a parameter exception occurs. + * @since 12 + */ +int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component, + void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type), + ArkUI_UIInputEvent_Type type); + /** * @brief Registers a callback for this OH_NativeXComponent instance. * @@ -777,6 +766,17 @@ int32_t OH_NativeXComponent_RegisterSurfaceHideCallback( int32_t OH_NativeXComponent_RegisterOnTouchInterceptCallback( OH_NativeXComponent* component, HitTestMode (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event)); +/** + * @brief Set whether the OH_NativeXComponent instance needs soft keyboard. + * @param component Indicates the pointer to this OH_NativeXComponent instance. + * @param needSoftKeyboard Indicates whether the OH_NativeXComponent instance needs soft keyboard or not. + * Default value is false. + * @return Returns the status code of the execution. + * @since 12 + * @version 1.0 + */ +int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard); + /** * @brief Obtains the touch event's source type dispatched by the ArkUI XComponent. * diff --git a/test/mock/core/render/mock_media_player_creator.cpp b/test/mock/core/render/mock_media_player_creator.cpp index fde7fb1ae3c..663f3adbfcf 100644 --- a/test/mock/core/render/mock_media_player_creator.cpp +++ b/test/mock/core/render/mock_media_player_creator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 diff --git a/test/mock/core/render/mock_render_surface.h b/test/mock/core/render/mock_render_surface.h index 5a7aa23d809..39e37680728 100644 --- a/test/mock/core/render/mock_render_surface.h +++ b/test/mock/core/render/mock_render_surface.h @@ -27,9 +27,9 @@ public: ~MockRenderSurface() override = default; MOCK_CONST_METHOD0(IsSurfaceValid, bool()); MOCK_METHOD2(AdjustNativeWindowSize, void(uint32_t, uint32_t)); - MOCK_METHOD0(ReleaseSurfaceBuffers, void()); MOCK_METHOD2(ConfigSurface, void(uint32_t, uint32_t)); MOCK_METHOD4(SetExtSurfaceBounds, void(int32_t, int32_t, int32_t, int32_t)); + MOCK_METHOD0(ReleaseSurfaceBuffers, void()); }; } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_SURFACE_H diff --git a/test/unittest/core/layout/safe_area/BUILD.gn b/test/unittest/core/layout/safe_area/BUILD.gn index 7b1f2c61cd2..3f8f6e20522 100644 --- a/test/unittest/core/layout/safe_area/BUILD.gn +++ b/test/unittest/core/layout/safe_area/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024-2025 Huawei Device Co., Ltd. +# Copyright (c) 2024 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 diff --git a/test/unittest/core/layout/safe_area/expand_safe_area_test_ng.cpp b/test/unittest/core/layout/safe_area/expand_safe_area_test_ng.cpp index a65564f599b..2efb037f18d 100644 --- a/test/unittest/core/layout/safe_area/expand_safe_area_test_ng.cpp +++ b/test/unittest/core/layout/safe_area/expand_safe_area_test_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 diff --git a/test/unittest/core/pattern/relative_container/relative_container_common_ng.cpp b/test/unittest/core/pattern/relative_container/relative_container_common_ng.cpp index cf81715d77b..5a11af65d6a 100644 --- a/test/unittest/core/pattern/relative_container/relative_container_common_ng.cpp +++ b/test/unittest/core/pattern/relative_container/relative_container_common_ng.cpp @@ -20,11 +20,10 @@ namespace OHOS::Ace { void RelativeContainerTestUtilsNG::AddAlignRule(const std::string& id, const AlignDirection& direction, const HorizontalAlign& horizontalRule, std::map& alignRules) { - auto alignDirection = AlignDirectionRtl(direction); AlignRule alignRule; alignRule.anchor = id; alignRule.horizontal = horizontalRule; - alignRules[alignDirection] = alignRule; + alignRules[direction] = alignRule; } void RelativeContainerTestUtilsNG::AddAlignRule(const std::string& id, const AlignDirection& direction, @@ -35,15 +34,4 @@ void RelativeContainerTestUtilsNG::AddAlignRule(const std::string& id, const Ali alignRule.vertical = verticalRule; alignRules[direction] = alignRule; } - -AlignDirection RelativeContainerTestUtilsNG::AlignDirectionRtl(const AlignDirection& direction) -{ - if (direction == AlignDirection::START) { - return AlignDirection::LEFT; - } else if (direction == AlignDirection::END) { - return AlignDirection::RIGHT; - } else { - return direction; - } -} } // namespace OHOS::Ace \ No newline at end of file diff --git a/test/unittest/core/pattern/relative_container/relative_container_common_ng.h b/test/unittest/core/pattern/relative_container/relative_container_common_ng.h index b6396faade6..34c0d29007c 100644 --- a/test/unittest/core/pattern/relative_container/relative_container_common_ng.h +++ b/test/unittest/core/pattern/relative_container/relative_container_common_ng.h @@ -28,7 +28,6 @@ public: const HorizontalAlign& horizontalRule, std::map& alignRules); static void AddAlignRule(const std::string& id, const AlignDirection& direction, const VerticalAlign& verticalRule, std::map& alignRules); - static AlignDirection AlignDirectionRtl(const AlignDirection& direction); }; } // namespace OHOS::Ace diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp index 924f3a2bcd1..8187235522f 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp @@ -82,11 +82,11 @@ const float CHILD_OFFSET_HEIGHT = 0.0f; const float FORCE = 3.0f; TestProperty testProperty; bool isFocus = false; -int g_surfaceShowNum = 1; const float SURFACE_WIDTH = 250.0f; const float SURFACE_HEIGHT = 150.0f; const float SURFACE_OFFSETX = 10.0f; const float SURFACE_OFFSETY = 20.0f; +int g_surfaceShowNum = 1; bool isAxis = false; bool isLock = true; @@ -588,6 +588,135 @@ HWTEST_F(XComponentTestNg, XComponentTextureTypeTest011, TestSize.Level1) pattern->InitNativeWindow(MAX_WIDTH, MAX_HEIGHT); } +/** + * @tc.name: XComponentControllerTest + * @tc.desc: Test XComponentController's interface + * @tc.type: FUNC + */ +HWTEST_F(XComponentTestNg, XComponentControllerTest, TestSize.Level1) +{ + /** + * @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE_VALUE and call CreateXComponentNode + * @tc.expected: xcomponent frameNode create successfully + */ + testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; + auto frameNode = CreateXComponentNode(testProperty); + EXPECT_TRUE(frameNode); + EXPECT_EQ(frameNode->GetTag(), V2::XCOMPONENT_ETS_TAG); + auto pattern = frameNode->GetPattern(); + ASSERT_TRUE(pattern); + pattern->hasXComponentInit_ = true; + EXPECT_EQ(pattern->type_, XCOMPONENT_SURFACE_TYPE_VALUE); + EXPECT_TRUE(pattern->IsAtomicNode()); + auto renderContext = AceType::MakeRefPtr(); + pattern->handlingSurfaceRenderContext_ = renderContext; + + /** + * @tc.steps: step2. call XcomponentController's interface releative to SetSurfaceRect + * @tc.expected: handlingSurfaceRenderContext_->SetBounds(SURFACE_OFFSETX, SURFACE_OFFSETY, + * SURFACE_WIDTH, SURFACE_HEIGHT) is called + */ + auto xcomponentController = pattern->xcomponentController_; + EXPECT_TRUE(xcomponentController); + pattern->drawSize_ = MAX_SIZE; + xcomponentController->SetIdealSurfaceWidth(SURFACE_WIDTH); + xcomponentController->SetIdealSurfaceHeight(SURFACE_HEIGHT); + xcomponentController->SetIdealSurfaceOffsetX(SURFACE_OFFSETX); + xcomponentController->SetIdealSurfaceOffsetY(SURFACE_OFFSETY); + EXPECT_CALL(*AceType::DynamicCast(pattern->handlingSurfaceRenderContext_), + SetBounds(SURFACE_OFFSETX, SURFACE_OFFSETY, SURFACE_WIDTH, SURFACE_HEIGHT)) + .WillOnce(Return()); + xcomponentController->UpdateSurfaceBounds(); + + /** + * @tc.steps: step3. call XcomponentController's interface releative to GetSurfaceRect + * @tc.expected: the rect get from GetSurfaceRect equals the rect set by SetSurfaceRect + */ + auto surfaceWidth = 0.0f; + auto surfaceHeight = 0.0f; + auto surfaceOffsetX = 0.0f; + auto surfaceOffsetY = 0.0f; + xcomponentController->GetSurfaceSize(surfaceWidth, surfaceHeight); + xcomponentController->GetLocalLocation(surfaceOffsetX, surfaceOffsetY); + EXPECT_EQ(surfaceOffsetX, SURFACE_OFFSETX); + EXPECT_EQ(surfaceOffsetY, SURFACE_OFFSETY); + EXPECT_EQ(surfaceWidth, SURFACE_WIDTH); + EXPECT_EQ(surfaceHeight, SURFACE_HEIGHT); + + /** + * @tc.steps: step4. call XcomponentController's ClearIdealSurfaceOffset + * @tc.expected: handlingSurfaceRenderContext_->SetBounds(newSurfaceOffsetX, newSurfaceOffsetY, + * SURFACE_WIDTH, SURFACE_HEIGHT) is called + */ + auto newSurfaceOffsetX = (MAX_WIDTH - SURFACE_WIDTH) / 2.0f; + auto newSurfaceOffsetY = (MAX_HEIGHT - SURFACE_HEIGHT) / 2.0f; + xcomponentController->ClearIdealSurfaceOffset(true); + xcomponentController->ClearIdealSurfaceOffset(false); + EXPECT_CALL(*AceType::DynamicCast(pattern->handlingSurfaceRenderContext_), + SetBounds(newSurfaceOffsetX, newSurfaceOffsetY, SURFACE_WIDTH, SURFACE_HEIGHT)) + .WillOnce(Return()); + xcomponentController->UpdateSurfaceBounds(); + + /** + * @tc.steps: step5. call XcomponentController's interface relative to SetSurfaceRotation + * @tc.expected: handlingSurfaceRenderContext_->SetSurfaceRotation(isLock) is called + */ + EXPECT_CALL( + *AceType::DynamicCast(pattern->handlingSurfaceRenderContext_), SetSurfaceRotation(isLock)) + .WillOnce(Return()); + xcomponentController->SetSurfaceRotation(isLock); + + /** + * @tc.steps: step6. call XcomponentController's interface relative to GetSurfaceRotation + * @tc.expected: the lock status get from GetSurfaceRotation equals the lock status set by SetSurfaceRotation + */ + auto lock = xcomponentController->GetSurfaceRotation(); + EXPECT_EQ(lock, isLock); +} + +/** + * @tc.name: XComponentAxisEventTest012 + * @tc.desc: Test AxisEvent + * @tc.type: FUNC + */ +HWTEST_F(XComponentTestNg, XComponentAxisEventTest012, TestSize.Level1) +{ + /** + * @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE and call CreateXComponentNode + * @tc.expected: xcomponent frameNode create successfully + */ + testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; + auto frameNode = CreateXComponentNode(testProperty); + ASSERT_TRUE(frameNode); + auto pattern = frameNode->GetPattern(); + ASSERT_TRUE(pattern); + + /** + * @tc.steps: step2. create nativeXComponent instance + * @tc.expected: focusHub & nativeXComponent instance create successfully + */ + auto pair = pattern->GetNativeXComponent(); + auto weakNativeXComponent = pair.second; + auto nativeXComponent = weakNativeXComponent.lock(); + auto nativeXComponentImpl = pair.first; + ASSERT_TRUE(nativeXComponent); + ASSERT_TRUE(nativeXComponentImpl); + + /** + * @tc.steps: step3. register axis event for nativeXComponent instance + */ + auto callback = [](OH_NativeXComponent* /* nativeXComponent */, ArkUI_UIInputEvent* event, + ArkUI_UIInputEvent_Type type) { isAxis = true; }; + nativeXComponent->RegisterUIAxisEventCallback(callback); + + /** + * @tc.steps: step4. call HandleAxisEvent + */ + AxisInfo event; + pattern->HandleAxisEvent(event); + EXPECT_TRUE(isAxis); +} + /** * @tc.name: XComponentOnAreaChangedInnerTest019 * @tc.desc: Test XComponent OnAreaChangedInner. @@ -871,7 +1000,6 @@ HWTEST_F(XComponentTestNg, XComponentDetachCallbackTest024, TestSize.Level1) xComponentEventHub->FireDetachEvent(XCOMPONENT_ID); EXPECT_FALSE(onDetachKey == CHECK_KEY); - onDetachKey.clear(); XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XCOMPONENT_COMPONENT_TYPE_VALUE); xComponent.SetDetachCallback(std::move(onDetach)); @@ -1046,7 +1174,6 @@ HWTEST_F(XComponentTestNg, XComponentSurfaceTest, TestSize.Level1) ASSERT_TRUE(nativeXComponentImpl); pattern->hasXComponentInit_ = true; - /** * @tc.steps: step3. call surfaceHide and surfaceShow event without register callbacks * @tc.expected: no error happens and g_surfaceShowNum remains the same @@ -1095,135 +1222,6 @@ HWTEST_F(XComponentTestNg, XComponentSurfaceTest, TestSize.Level1) } } -/** - * @tc.name: XComponentControllerTest - * @tc.desc: Test XComponentController's interface - * @tc.type: FUNC - */ -HWTEST_F(XComponentTestNg, XComponentControllerTest, TestSize.Level1) -{ - /** - * @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE_VALUE and call CreateXComponentNode - * @tc.expected: xcomponent frameNode create successfully - */ - testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; - auto frameNode = CreateXComponentNode(testProperty); - EXPECT_TRUE(frameNode); - EXPECT_EQ(frameNode->GetTag(), V2::XCOMPONENT_ETS_TAG); - auto pattern = frameNode->GetPattern(); - ASSERT_TRUE(pattern); - pattern->hasXComponentInit_ = true; - EXPECT_EQ(pattern->type_, XCOMPONENT_SURFACE_TYPE_VALUE); - EXPECT_TRUE(pattern->IsAtomicNode()); - auto renderContext = AceType::MakeRefPtr(); - pattern->handlingSurfaceRenderContext_ = renderContext; - - /** - * @tc.steps: step2. call XcomponentController's interface releative to SetSurfaceRect - * @tc.expected: handlingSurfaceRenderContext_->SetBounds(SURFACE_OFFSETX, SURFACE_OFFSETY, - * SURFACE_WIDTH, SURFACE_HEIGHT) is called - */ - auto xcomponentController = pattern->xcomponentController_; - EXPECT_TRUE(xcomponentController); - pattern->drawSize_ = MAX_SIZE; - xcomponentController->SetIdealSurfaceWidth(SURFACE_WIDTH); - xcomponentController->SetIdealSurfaceHeight(SURFACE_HEIGHT); - xcomponentController->SetIdealSurfaceOffsetX(SURFACE_OFFSETX); - xcomponentController->SetIdealSurfaceOffsetY(SURFACE_OFFSETY); - EXPECT_CALL(*AceType::DynamicCast(pattern->handlingSurfaceRenderContext_), - SetBounds(SURFACE_OFFSETX, SURFACE_OFFSETY, SURFACE_WIDTH, SURFACE_HEIGHT)) - .WillOnce(Return()); - xcomponentController->UpdateSurfaceBounds(); - - /** - * @tc.steps: step3. call XcomponentController's interface releative to GetSurfaceRect - * @tc.expected: the rect get from GetSurfaceRect equals the rect set by SetSurfaceRect - */ - auto surfaceWidth = 0.0f; - auto surfaceHeight = 0.0f; - auto surfaceOffsetX = 0.0f; - auto surfaceOffsetY = 0.0f; - xcomponentController->GetSurfaceSize(surfaceWidth, surfaceHeight); - xcomponentController->GetLocalLocation(surfaceOffsetX, surfaceOffsetY); - EXPECT_EQ(surfaceOffsetX, SURFACE_OFFSETX); - EXPECT_EQ(surfaceOffsetY, SURFACE_OFFSETY); - EXPECT_EQ(surfaceWidth, SURFACE_WIDTH); - EXPECT_EQ(surfaceHeight, SURFACE_HEIGHT); - - /** - * @tc.steps: step4. call XcomponentController's ClearIdealSurfaceOffset - * @tc.expected: handlingSurfaceRenderContext_->SetBounds(newSurfaceOffsetX, newSurfaceOffsetY, - * SURFACE_WIDTH, SURFACE_HEIGHT) is called - */ - auto newSurfaceOffsetX = (MAX_WIDTH - SURFACE_WIDTH) / 2.0f; - auto newSurfaceOffsetY = (MAX_HEIGHT - SURFACE_HEIGHT) / 2.0f; - xcomponentController->ClearIdealSurfaceOffset(true); - xcomponentController->ClearIdealSurfaceOffset(false); - EXPECT_CALL(*AceType::DynamicCast(pattern->handlingSurfaceRenderContext_), - SetBounds(newSurfaceOffsetX, newSurfaceOffsetY, SURFACE_WIDTH, SURFACE_HEIGHT)) - .WillOnce(Return()); - xcomponentController->UpdateSurfaceBounds(); - - /** - * @tc.steps: step5. call XcomponentController's interface relative to SetSurfaceRotation - * @tc.expected: handlingSurfaceRenderContext_->SetSurfaceRotation(isLock) is called - */ - EXPECT_CALL( - *AceType::DynamicCast(pattern->handlingSurfaceRenderContext_), SetSurfaceRotation(isLock)) - .WillOnce(Return()); - xcomponentController->SetSurfaceRotation(isLock); - - /** - * @tc.steps: step6. call XcomponentController's interface relative to GetSurfaceRotation - * @tc.expected: the lock status get from GetSurfaceRotation equals the lock status set by SetSurfaceRotation - */ - auto lock = xcomponentController->GetSurfaceRotation(); - EXPECT_EQ(lock, isLock); -} - -/** - * @tc.name: XComponentAxisEventTest012 - * @tc.desc: Test AxisEvent - * @tc.type: FUNC - */ -HWTEST_F(XComponentTestNg, XComponentAxisEventTest012, TestSize.Level1) -{ - /** - * @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE and call CreateXComponentNode - * @tc.expected: xcomponent frameNode create successfully - */ - testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; - auto frameNode = CreateXComponentNode(testProperty); - ASSERT_TRUE(frameNode); - auto pattern = frameNode->GetPattern(); - ASSERT_TRUE(pattern); - - /** - * @tc.steps: step2. create nativeXComponent instance - * @tc.expected: focusHub & nativeXComponent instance create successfully - */ - auto pair = pattern->GetNativeXComponent(); - auto weakNativeXComponent = pair.second; - auto nativeXComponent = weakNativeXComponent.lock(); - auto nativeXComponentImpl = pair.first; - ASSERT_TRUE(nativeXComponent); - ASSERT_TRUE(nativeXComponentImpl); - - /** - * @tc.steps: step3. register axis event for nativeXComponent instance - */ - auto callback = [](OH_NativeXComponent* /* nativeXComponent */, ArkUI_UIInputEvent* event, - ArkUI_UIInputEvent_Type type) { isAxis = true; }; - nativeXComponent->RegisterUIAxisEventCallback(callback); - - /** - * @tc.steps: step4. call HandleAxisEvent - */ - AxisInfo event; - pattern->HandleAxisEvent(event); - EXPECT_TRUE(isAxis); -} - /** * @tc.name: XComponentSourceTypeTest * @tc.desc: Test SourceType @@ -1261,40 +1259,6 @@ HWTEST_F(XComponentTestNg, XComponentSourceTypeTest, TestSize.Level1) } } -/** - * @tc.name: XComponentImageAnalyzerTest - * @tc.desc: Test Enable Image Analyzer - * @tc.type: FUNC - */ -HWTEST_F(XComponentTestNg, XComponentImageAnalyzerTest, TestSize.Level1) -{ - /** - * @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE and call CreateXComponentNode - * @tc.expected: xcomponent frameNode create successfully - */ - testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; - auto frameNode = CreateXComponentNode(testProperty); - ASSERT_TRUE(frameNode); - auto pattern = frameNode->GetPattern(); - ASSERT_TRUE(pattern); - - /** - * @tc.steps: step2. call EnableImageAnalyzer - * @tc.expected: IsSupportImageAnalyzerFeature() return right value - */ - pattern->EnableAnalyzer(true); - EXPECT_TRUE(pattern->isEnableAnalyzer_); - - if (ImageAnalyzerMgr::GetInstance().IsImageAnalyzerSupported()) { - EXPECT_TRUE(pattern->IsSupportImageAnalyzerFeature()); - } else { - EXPECT_FALSE(pattern->IsSupportImageAnalyzerFeature()); - } - - pattern->imageAnalyzerManager_ = nullptr; - EXPECT_FALSE(pattern->IsSupportImageAnalyzerFeature()); -} - /** * @tc.name: XComponentSurfaceLifeCycleCallback * @tc.desc: Test XComponentController's surface life cycle callback @@ -1362,4 +1326,39 @@ HWTEST_F(XComponentTestNg, XComponentSurfaceLifeCycleCallback, TestSize.Level1) pattern->OnDetachFromFrameNode(AceType::RawPtr(frameNode)); EXPECT_STREQ(SURFACE_ID.c_str(), onSurfaceDestroyedSurfaceId.c_str()); } + +/** + * @tc.name: XComponentImageAnalyzerTest + * @tc.desc: Test Enable Image Analyzer + * @tc.type: FUNC + */ +HWTEST_F(XComponentTestNg, XComponentImageAnalyzerTest, TestSize.Level1) +{ + /** + * @tc.steps: step1. set type = XCOMPONENT_SURFACE_TYPE and call CreateXComponentNode + * @tc.expected: xcomponent frameNode create successfully + */ + testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; + auto frameNode = CreateXComponentNode(testProperty); + ASSERT_TRUE(frameNode); + auto pattern = frameNode->GetPattern(); + ASSERT_TRUE(pattern); + pattern->surfaceId_ = SURFACE_ID; + + /** + * @tc.steps: step2. call EnableImageAnalyzer + * @tc.expected: IsSupportImageAnalyzerFeature() return right value + */ + pattern->EnableAnalyzer(true); + EXPECT_TRUE(pattern->isEnableAnalyzer_); + + if (ImageAnalyzerMgr::GetInstance().IsImageAnalyzerSupported()) { + EXPECT_TRUE(pattern->IsSupportImageAnalyzerFeature()); + } else { + EXPECT_FALSE(pattern->IsSupportImageAnalyzerFeature()); + } + + pattern->imageAnalyzerManager_ = nullptr; + EXPECT_FALSE(pattern->IsSupportImageAnalyzerFeature()); +} } // namespace OHOS::Ace::NG