• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TEST_UNITTEST_CORE_BASE_VIEW_ABSTRACT_TEST_NG_H
17 #define TEST_UNITTEST_CORE_BASE_VIEW_ABSTRACT_TEST_NG_H
18 #include "gtest/gtest.h"
19 #define protected public
20 #define private public
21 #include "test/mock/core/common/mock_container.h"
22 #include "test/mock/core/common/mock_theme_manager.h"
23 #include "test/mock/core/pipeline/mock_pipeline_context.h"
24 
25 #include "base/error/error_code.h"
26 #include "core/components/common/layout/position_param.h"
27 #include "core/components/common/properties/decoration.h"
28 #include "core/components/popup/popup_theme.h"
29 #include "core/components_ng/base/frame_node.h"
30 #include "core/components_ng/base/view_abstract.h"
31 #include "core/components_ng/base/view_abstract_model.h"
32 #include "core/components_ng/base/view_abstract_model_ng.h"
33 #include "core/components_ng/base/view_abstract_model_static.h"
34 #include "core/components_ng/base/view_stack_model.h"
35 #include "core/components_ng/base/view_stack_model_ng.h"
36 #include "core/components_ng/layout/layout_property.h"
37 #include "core/components_ng/pattern/bubble/bubble_pattern.h"
38 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
39 #include "core/components_ng/pattern/menu/menu_pattern.h"
40 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
41 #include "core/components_ng/pattern/navigation/navigation_model_ng.h"
42 #include "core/components_ng/pattern/navigator/navigator_model_ng.h"
43 #include "core/components_ng/pattern/navrouter/navrouter_model_ng.h"
44 #include "core/components_ng/pattern/panel/sliding_panel_model_ng.h"
45 #include "core/components_ng/pattern/picker/datepicker_model_ng.h"
46 #include "core/components_ng/pattern/root/root_pattern.h"
47 #include "core/components_ng/pattern/stepper/stepper_item_model_ng.h"
48 #include "core/components_ng/pattern/text/span/span_string.h"
49 #include "core/components_ng/pattern/text/text_model_ng.h"
50 #include "core/components_ng/property/property.h"
51 #include "core/interfaces/native/node/node_api.h"
52 #include "core/pipeline/base/element.h"
53 #include "core/pipeline/base/element_register.h"
54 
55 #undef private
56 #undef protected
57 
58 namespace OHOS::Ace::NG {
59 namespace {
60 const Dimension WIDTH { 50.0, DimensionUnit::PX };
61 const Dimension HEIGHT { 100.0, DimensionUnit::PX };
62 const Dimension MIN_WIDTH { 10.0, DimensionUnit::PX };
63 const Dimension MIN_HEIGHT { 20.0, DimensionUnit::PX };
64 const Dimension RADIUS { 10.0, DimensionUnit::PX };
65 const Dimension LEFT { 10.0, DimensionUnit::PX };
66 const Dimension TOP { 20.0, DimensionUnit::PX };
67 const Dimension RIGHT { 10.0, DimensionUnit::PX };
68 const Dimension BOTTOM { 20.0, DimensionUnit::PX };
69 const Dimension VALUE { -50.0, DimensionUnit::PX };
70 const Dimension ZERO { 0.0, DimensionUnit::PX };
71 const BiasPair biasPair(0.5f, 0.5f);
72 const InvertVariant invert = 0.0f;
73 const OffsetF OFFSETF { 1.0, 1.0 };
74 const Offset OFFSET { 2.0, 2.0 };
75 const float RATIO = 1.0f;
76 const double OPACITYS = 10;
77 const int32_t TEN = 10;
78 const int32_t FOUF = 4;
79 const int32_t INDEX = 1;
80 const Color BLUE = Color(0xff0000ff);
81 const SafeAreaExpandOpts safeAreaExpandOpts = SafeAreaExpandOpts();
82 const std::vector<ObscuredReasons> reasonsVector = { ObscuredReasons::PLACEHOLDER };
83 
84 BackgroundImageSize BACKGROUNDSIZE { BackgroundImageSizeType::AUTO, 1.0 };
85 BackgroundImagePosition BACKGROUNDPOSITION { BackgroundImagePositionType::PERCENT, -1.0,
86     BackgroundImagePositionType::PERCENT, 0.0 };
87 
88 constexpr char TAG_ROOT[] = "root";
89 constexpr char TAG_CHILD[] = "child";
90 const auto MOCK_PATTERN_ROOT = AceType::MakeRefPtr<Pattern>();
91 const auto FRAME_NODE_ROOT = FrameNode::CreateFrameNode(TAG_ROOT, 1, MOCK_PATTERN_ROOT, true);
92 const auto FRAME_NODE_CHILD = FrameNode::CreateFrameNode(TAG_CHILD, 2, MOCK_PATTERN_ROOT, false);
93 const uint32_t REGISTER_ID = 1 << 20;
94 const auto FRAME_NODE_REGISTER = FrameNode::CreateFrameNode(TAG_ROOT, REGISTER_ID, MOCK_PATTERN_ROOT, false);
95 
96 std::string srcimages = "common/images/mmm.jpg";
97 const std::string VALUE_EMPTY = "";
98 const std::string VALUE_X = "X";
99 const std::string VALUE_CX = "CX";
100 const std::string VALUE_TAB = "TAB";
101 const std::string VALUE_DPAD_UP = "DPAD_UP";
102 ViewAbstractModelNG viewAbstractModelNG;
103 auto callback = []() { srcimages = "test"; };
104 int32_t flag = 0;
105 const ImageSourceInfo imageSourceInfo = ImageSourceInfo("common/images/mmm.jpg", "abstract", "abstract");
106 }; // namespace
107 class ViewAbstractTestNg : public testing::Test {
108 public:
109     static void SetUpTestSuite();
110     static void TearDownTestSuite();
SetUp()111     void SetUp() override
112     {
113         auto* stack = ViewStackProcessor::GetInstance();
114         auto nodeId = stack->ClaimNodeId();
115         auto frameNode =
116             FrameNode::GetOrCreateFrameNode("components", nodeId, []() { return AceType::MakeRefPtr<Pattern>(); });
117         stack->Push(frameNode);
118     }
TearDown()119     void TearDown() override {}
120 };
121 } // namespace OHOS::Ace::NG
122 
123 #endif //TEST_UNITTEST_CORE_BASE_VIEW_ABSTRACT_TEST_NG_H