mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-01-10 02:41:41 +00:00
add ui_extension_node.cpp test
Signed-off-by: lizhan <lizhan11@huawei.com> Change-Id: Ife1c57a17fd8ae19ffb55a93643fa4073b246af9 Committer: lizhan <lizhan11@huawei.com> Change-Id: I3d10e27d07386a2c6b5acde88ecd91c5aca84893
This commit is contained in:
parent
3e7a5b095e
commit
9272801284
@ -26,7 +26,7 @@ class MockRenderContext : public RenderContext {
|
||||
public:
|
||||
~MockRenderContext() override = default;
|
||||
MOCK_METHOD4(SetBounds, void(float, float, float, float));
|
||||
MOCK_METHOD(RectF, GetPaintRectWithTransform, (), (override));
|
||||
MOCK_METHOD0(GetPaintRectWithTransform, RectF());
|
||||
MOCK_METHOD1(GetPointWithTransform, void(PointF&));
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -35,6 +35,7 @@ template("ace_unittest") {
|
||||
type = "components"
|
||||
ace_animation = false
|
||||
flutter_skia = false
|
||||
render = false
|
||||
ace_unittest_out_path = "ace_engine/$type"
|
||||
ace_unittest_name = target_name
|
||||
ace_unittest_config = [ "$ace_root/test/unittest:ace_unittest_config" ]
|
||||
@ -47,6 +48,10 @@ template("ace_unittest") {
|
||||
"//third_party/googletest:gmock_main",
|
||||
]
|
||||
|
||||
if (defined(invoker.render)) {
|
||||
render = invoker.render
|
||||
}
|
||||
|
||||
if (defined(invoker.ace_log)) {
|
||||
ace_log = invoker.ace_log
|
||||
}
|
||||
@ -64,6 +69,10 @@ template("ace_unittest") {
|
||||
ace_unittest_deps += [ "$ace_root/test/unittest:ace_core_animation" ]
|
||||
}
|
||||
|
||||
if (render) {
|
||||
ace_unittest_deps += [ "$graphic_standard_path/rosen/modules/render_service_client:librender_service_client" ]
|
||||
}
|
||||
|
||||
if (defined(invoker.flutter_skia)) {
|
||||
flutter_skia = invoker.flutter_skia
|
||||
}
|
||||
|
@ -11,13 +11,13 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni")
|
||||
|
||||
ohos_unittest("ui_extension_pattern_test_ng") {
|
||||
module_out_path = pattern_test_output_path
|
||||
|
||||
ace_unittest("ui_extension_pattern_test_ng") {
|
||||
render = true
|
||||
ace_animation = true
|
||||
sources = [
|
||||
"$ace_root/frameworks/core/components_ng/pattern/grid_container/grid_container_layout_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/ui_extension/ui_extension_layout_algorithm.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/pattern/ui_extension/ui_extension_node.cpp",
|
||||
@ -27,97 +27,8 @@ ohos_unittest("ui_extension_pattern_test_ng") {
|
||||
"$ace_root/test/mock/core/pattern/window_scene/mock_host_window_pattern.cpp",
|
||||
"$ace_root/test/unittest/core/pattern/ui_extension/ui_extension_pattern_test_ng.cpp",
|
||||
]
|
||||
|
||||
sources += [
|
||||
# base
|
||||
"$ace_root/frameworks/base/geometry/dimension.cpp",
|
||||
"$ace_root/frameworks/base/json/json_util.cpp",
|
||||
"$ace_root/frameworks/base/utils/base_id.cpp",
|
||||
"$ace_root/frameworks/base/utils/string_expression.cpp",
|
||||
"$ace_root/frameworks/base/utils/string_utils.cpp",
|
||||
|
||||
# components
|
||||
"$ace_root/frameworks/core/components/common/layout/grid_column_info.cpp",
|
||||
"$ace_root/frameworks/core/components/common/layout/grid_container_info.cpp",
|
||||
"$ace_root/frameworks/core/components/common/layout/grid_system_manager.cpp",
|
||||
"$ace_root/frameworks/core/components/common/layout/screen_system_manager.cpp",
|
||||
"$ace_root/frameworks/core/components/common/properties/alignment.cpp",
|
||||
"$ace_root/frameworks/core/components/common/properties/color.cpp",
|
||||
|
||||
# components_ng
|
||||
"$ace_root/frameworks/core/components_ng/base/frame_node.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/base/geometry_node.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/base/ui_node.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/base/view_stack_processor.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/click_event.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/drag_event.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/event_hub.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/focus_hub.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/gesture_event_hub.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/input_event.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/input_event_hub.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/pan_event.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/state_style_manager.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/event/touch_event.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/gesture_referee.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/exclusive_recognizer.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/multi_fingers_recognizer.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/parallel_recognizer.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/recognizer_group.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/gestures/recognizers/sequenced_recognizer.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/layout/box_layout_algorithm.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/layout/layout_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/layout/layout_wrapper.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/layout/layout_wrapper_builder.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/property/calc_length.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/property/grid_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/property/measure_utils.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/property/property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/render/drawing_prop_convertor.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/render/paint_wrapper.cpp",
|
||||
|
||||
# components_v2
|
||||
"$ace_root/frameworks/core/components_v2/inspector/inspector_constants.cpp",
|
||||
|
||||
# pipeline
|
||||
"$ace_root/frameworks/core/pipeline/base/constants.cpp",
|
||||
|
||||
# mock
|
||||
"$ace_root/frameworks/base/test/mock/mock_ressched_report.cpp",
|
||||
"$ace_root/frameworks/base/test/mock/mock_system_properties.cpp",
|
||||
"$ace_root/frameworks/core/common/test/mock/mock_ace_application_info.cpp",
|
||||
"$ace_root/frameworks/core/components/test/unittest/mock/ace_trace_mock.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/animation/mock_geometry_transition.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/base/mock_localization.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/pattern/grid_container/mock_grid_container_layout_property.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_animation_utils.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_modifier_adapter.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_render_context.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_render_context_creator.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/render/mock_render_surface_creator.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/mock/syntax/mock_for_each_node.cpp",
|
||||
"$ace_root/frameworks/core/pipeline_ng/test/mock/mock_element_register.cpp",
|
||||
"$ace_root/frameworks/core/pipeline_ng/test/mock/mock_pipeline_base.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$ace_root/frameworks/base:ace_memory_monitor_ohos",
|
||||
"$ace_root/frameworks/core/components/theme:build_theme_code",
|
||||
"$ace_root/test/unittest:ace_unittest_log",
|
||||
"$cjson_root:cjson_static",
|
||||
"//third_party/googletest:gmock_main",
|
||||
]
|
||||
|
||||
deps += [ "$graphic_standard_path/rosen/modules/render_service_client:librender_service_client" ]
|
||||
|
||||
external_deps = [
|
||||
"input:libmmi-client",
|
||||
"window_manager:scene_session",
|
||||
]
|
||||
|
||||
configs = [ "$ace_root/test/unittest:ace_unittest_config" ]
|
||||
}
|
||||
|
@ -16,13 +16,22 @@
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "core/components_ng/test/mock/render/mock_render_context.h"
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
|
||||
#include "test/mock/core/common/mock_container.h"
|
||||
|
||||
#include "base/geometry/ng/point_t.h"
|
||||
#include "core/common/ace_page.h"
|
||||
#include "core/common/container.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_model_ng.h"
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_node.h"
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_paint_property.h"
|
||||
#include "core/event/touch_event.h"
|
||||
#include "core/pipeline_ng/test/mock/mock_pipeline_base.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -32,9 +41,14 @@ namespace {
|
||||
const std::string BUNDLE_NAME = "com.example.hello";
|
||||
const std::string ABILITY_NAME = "MainAbility";
|
||||
const std::string WANT = R"({bundleName: "com.example.hello", abilityName: "MainAbility"})";
|
||||
const int32_t NODE_ID = 1000;
|
||||
} // namespace
|
||||
|
||||
class UIExtensionPatternTestNg : public testing::Test {};
|
||||
class UIExtensionPatternTestNg : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestSuite() {};
|
||||
static void TearDownTestSuite() {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: UIExtensionCreator001
|
||||
@ -84,4 +98,92 @@ HWTEST_F(UIExtensionPatternTestNg, UIExtensionCreator002, TestSize.Level1)
|
||||
auto result2 = uiExtensionNode->TouchTest(PointF(), PointF(10, 10), touchRestrict, testResult, 1);
|
||||
EXPECT_EQ(static_cast<int>(HitTestResult::OUT_OF_REGION), static_cast<int>(result2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UIExtensionCreator003
|
||||
* @tc.desc: create UIExtension and run GetOrCreateUIExtensionNode success
|
||||
* @tc.type: FUNC
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(UIExtensionPatternTestNg, UIExtensionCreator003, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Create or create UIExtension component.
|
||||
* @tc.expect: Create or create UIExtension component success.
|
||||
*/
|
||||
auto uiExtensionNode = UIExtensionNode::GetOrCreateUIExtensionNode(
|
||||
"UIExtensionNodeTag", NODE_ID, []() { return AceType::MakeRefPtr<Pattern>(); });
|
||||
EXPECT_NE(uiExtensionNode, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Create or create UIExtension component.
|
||||
* @tc.expect: component equal
|
||||
*/
|
||||
auto uiExtensionNodeTemp1 = UIExtensionNode::GetOrCreateUIExtensionNode(
|
||||
"UIExtensionNodeTag", NODE_ID, []() { return AceType::MakeRefPtr<Pattern>(); });
|
||||
EXPECT_EQ(uiExtensionNode, uiExtensionNodeTemp1);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Create or create UIExtension component.
|
||||
* @tc.expect: component not equal
|
||||
*/
|
||||
auto uiExtensionNodeTemp2 = UIExtensionNode::GetOrCreateUIExtensionNode(
|
||||
"UIExtensionNodeTag1", NODE_ID, []() { return AceType::MakeRefPtr<Pattern>(); });
|
||||
EXPECT_NE(uiExtensionNode, uiExtensionNodeTemp2);
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Create or create UIExtension component.
|
||||
* @tc.expect: Create or create UIExtension component success.
|
||||
*/
|
||||
auto parent = UIExtensionNode::GetOrCreateUIExtensionNode(
|
||||
"UIExtensionNodeTagParent", NODE_ID + 1, []() { return AceType::MakeRefPtr<Pattern>(); });
|
||||
EXPECT_NE(parent, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Create or create UIExtension component and set parent.
|
||||
* @tc.expect: Create or create UIExtension component and set parent success.
|
||||
*/
|
||||
uiExtensionNodeTemp2->SetParent(parent);
|
||||
uiExtensionNodeTemp2 = UIExtensionNode::GetOrCreateUIExtensionNode(
|
||||
"UIExtensionNodeTag1", NODE_ID, []() { return AceType::MakeRefPtr<Pattern>(); });
|
||||
EXPECT_NE(uiExtensionNodeTemp2->GetParent(), nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UIExtensionCreator003
|
||||
* @tc.desc: create UIExtension and run TouchTest success
|
||||
* @tc.type: FUNC
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(UIExtensionPatternTestNg, UIExtensionCreator004, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Set up pipeline and container
|
||||
* @tc.steps: step1. Create or create UIExtension component.
|
||||
* @tc.expect: Create or create UIExtension component success.
|
||||
*/
|
||||
MockPipelineBase::SetUp();
|
||||
MockContainer::SetUp();
|
||||
MockContainer::container_->pipelineContext_ = MockPipelineBase::pipeline_;
|
||||
auto container = Container::Current();
|
||||
EXPECT_NE(container, nullptr);
|
||||
auto context = container->GetPipelineContext();
|
||||
EXPECT_NE(context, nullptr);
|
||||
auto model = UIExtensionModelNG();
|
||||
model.Create(BUNDLE_NAME, ABILITY_NAME);
|
||||
|
||||
auto uiExtensionNode =
|
||||
AceType::DynamicCast<UIExtensionNode>(ViewStackProcessor::GetInstance()->GetMainElementNode());
|
||||
|
||||
TouchRestrict touchRestrict;
|
||||
TouchTestResult testResult;
|
||||
|
||||
/**
|
||||
* @tc.expect: result equals with BUBBLING
|
||||
*/
|
||||
auto result = uiExtensionNode->TouchTest(PointF(), PointF(), touchRestrict, testResult, 1);
|
||||
EXPECT_EQ(static_cast<int>(HitTestResult::BUBBLING), static_cast<int>(result));
|
||||
MockPipelineBase::TearDown();
|
||||
MockContainer::TearDown();
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
Loading…
Reference in New Issue
Block a user