• 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/properties/decoration.h"
27 #include "core/components/popup/popup_theme.h"
28 #include "core/components_ng/base/frame_node.h"
29 #include "core/components_ng/base/view_abstract.h"
30 #include "core/components_ng/base/view_abstract_model.h"
31 #include "core/components_ng/base/view_abstract_model_ng.h"
32 #include "core/components_ng/base/view_stack_model.h"
33 #include "core/components_ng/base/view_stack_model_ng.h"
34 #include "core/components_ng/layout/layout_property.h"
35 #include "core/components_ng/pattern/bubble/bubble_pattern.h"
36 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
37 #include "core/components_ng/pattern/menu/menu_pattern.h"
38 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
39 #include "core/components_ng/pattern/navigation/navigation_model_ng.h"
40 #include "core/components_ng/pattern/navigator/navigator_model_ng.h"
41 #include "core/components_ng/pattern/navrouter/navrouter_model_ng.h"
42 #include "core/components_ng/pattern/picker/datepicker_model_ng.h"
43 #include "core/components_ng/pattern/root/root_pattern.h"
44 #include "core/components_ng/pattern/stepper/stepper_item_model_ng.h"
45 #include "core/components_ng/pattern/text/text_model_ng.h"
46 #include "core/components_ng/property/property.h"
47 #include "core/interfaces/native/node/node_api.h"
48 #include "core/pipeline/base/element_register.h"
49 #include "frameworks/core/components/common/layout/position_param.h"
50 #include "frameworks/core/components_ng/pattern/panel/sliding_panel_model_ng.h"
51 #include "frameworks/core/pipeline/base/element.h"
52 
53 #undef private
54 #undef protected
55 
56 namespace OHOS::Ace::NG {
57 namespace {
58 const Dimension WIDTH { 50.0, DimensionUnit::PX };
59 const Dimension HEIGHT { 100.0, DimensionUnit::PX };
60 const Dimension MIN_WIDTH { 10.0, DimensionUnit::PX };
61 const Dimension MIN_HEIGHT { 20.0, DimensionUnit::PX };
62 const Dimension RADIUS { 10.0, DimensionUnit::PX };
63 const Dimension LEFT { 10.0, DimensionUnit::PX };
64 const Dimension TOP { 20.0, DimensionUnit::PX };
65 const Dimension RIGHT { 10.0, DimensionUnit::PX };
66 const Dimension BOTTOM { 20.0, DimensionUnit::PX };
67 const Dimension VALUE { -50.0, DimensionUnit::PX };
68 const Dimension ZERO { 0.0, DimensionUnit::PX };
69 const BiasPair biasPair(0.5f, 0.5f);
70 const InvertVariant invert = 0.0f;
71 const OffsetF OFFSETF { 1.0, 1.0 };
72 const Offset OFFSET { 2.0, 2.0 };
73 const float RATIO = 1.0f;
74 const double OPACITYS = 10;
75 const int32_t TEN = 10;
76 const int32_t FOUF = 4;
77 const int32_t INDEX = 1;
78 const Color BLUE = Color(0xff0000ff);
79 const SafeAreaExpandOpts safeAreaExpandOpts = SafeAreaExpandOpts();
80 const std::vector<ObscuredReasons> reasonsVector = { ObscuredReasons::PLACEHOLDER };
81 
82 const BackgroundImageSize BACKGROUNDSIZE { BackgroundImageSizeType::AUTO, 1.0 };
83 const BackgroundImagePosition BACKGROUNDPOSITION { BackgroundImagePositionType::PERCENT, -1.0,
84     BackgroundImagePositionType::PERCENT, 0.0 };
85 
86 constexpr char TAG_ROOT[] = "root";
87 constexpr char TAG_CHILD[] = "child";
88 const auto MOCK_PATTERN_ROOT = AceType::MakeRefPtr<Pattern>();
89 const auto FRAME_NODE_ROOT = FrameNode::CreateFrameNode(TAG_ROOT, 1, MOCK_PATTERN_ROOT, true);
90 const auto FRAME_NODE_CHILD = FrameNode::CreateFrameNode(TAG_CHILD, 2, MOCK_PATTERN_ROOT, false);
91 const uint32_t REGISTER_ID = 1 << 20;
92 const auto FRAME_NODE_REGISTER = FrameNode::CreateFrameNode(TAG_ROOT, REGISTER_ID, MOCK_PATTERN_ROOT, false);
93 
94 std::string srcimages = "common/images/mmm.jpg";
95 const std::string VALUE_EMPTY = "";
96 const std::string VALUE_X = "X";
97 const std::string VALUE_CX = "CX";
98 const std::string VALUE_TAB = "TAB";
99 const std::string VALUE_DPAD_UP = "DPAD_UP";
100 ViewAbstractModelNG viewAbstractModelNG;
101 auto callback = []() { srcimages = "test"; };
102 int32_t flag = 0;
103 const ImageSourceInfo imageSourceInfo = ImageSourceInfo("common/images/mmm.jpg", "abstract", "abstract");
104 }; // namespace
105 class ViewAbstractTestNg : public testing::Test {
106 public:
107     static void SetUpTestSuite();
108     static void TearDownTestSuite();
SetUp()109     void SetUp() override
110     {
111         auto* stack = ViewStackProcessor::GetInstance();
112         auto nodeId = stack->ClaimNodeId();
113         auto frameNode =
114             FrameNode::GetOrCreateFrameNode("components", nodeId, []() { return AceType::MakeRefPtr<Pattern>(); });
115         stack->Push(frameNode);
116     }
TearDown()117     void TearDown() override {}
118 };
119 } // namespace OHOS::Ace::NG
120 
121 #endif //TEST_UNITTEST_CORE_BASE_VIEW_ABSTRACT_TEST_NG_H