1 /*
2  * Copyright (c) 2023-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 FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_GRID_GRID_TEST_NG_H
17 #define FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_GRID_GRID_TEST_NG_H
18 
19 #include "test/unittest/core/pattern/test_ng.h"
20 
21 #include "core/components_ng/pattern/grid/grid_item_model_ng.h"
22 #include "core/components_ng/pattern/grid/grid_model_ng.h"
23 #define protected public
24 #define private public
25 #include "core/components_ng/pattern/grid/grid_pattern.h"
26 
27 namespace OHOS::Ace::NG {
28 namespace {
29 using namespace testing;
30 using namespace testing::ext;
31 constexpr float GRID_WIDTH = 480.f;
32 constexpr float GRID_HEIGHT = 800.f;
33 constexpr int32_t VIEW_LINE_NUMBER = 4;
34 constexpr float ITEM_WIDTH = 120.f;
35 constexpr float ITEM_HEIGHT = 200.f;
36 constexpr Dimension GRIDITEM_FOCUS_INTERVAL = 3.0_vp;
37 constexpr Dimension BORDER_RADIUS = 8.0_vp;
38 constexpr float COL_GAP = 10.f;
39 constexpr float ROW_GAP = 5.f;
40 constexpr float BIG_ROW_GAP = 700.f;
41 constexpr float MEDIUM_ROW_GAP = 75.f;
42 constexpr int32_t FILL_VALUE = -2;
43 } // namespace
44 
45 class GridTestNg : public TestNG {
46 public:
47     static void SetUpTestSuite();
48     static void TearDownTestSuite();
49     void SetUp() override;
50     void TearDown() override;
51     void GetGrid();
52     GridModelNG CreateGrid();
53     GridModelNG CreateRepeatGrid(int32_t itemNumber, std::function<float(uint32_t)>&& getSize);
54 
55     /**
56      * @param height -2 corresponds to 100% height
57      */
58     GridItemModelNG CreateGridItem(
59         float width = NULL_VALUE, float height = NULL_VALUE, GridItemStyle gridItemStyle = GridItemStyle::NONE);
60     void CreateGridItems(int32_t itemNumber = 10, float width = NULL_VALUE, float height = NULL_VALUE,
61         GridItemStyle gridItemStyle = GridItemStyle::NONE);
62     void CreateFocusableGridItems(int32_t itemNumber = 10, float width = NULL_VALUE, float height = NULL_VALUE,
63         GridItemStyle gridItemStyle = GridItemStyle::NONE);
64     void CreateFixedItems(int32_t itemNumber, GridItemStyle gridItemStyle = GridItemStyle::NONE);
65     void CreateFixedHeightItems(int32_t itemNumber, float height, GridItemStyle gridItemStyle = GridItemStyle::NONE);
66     void CreateFixedWidthItems(int32_t itemNumber, float width, GridItemStyle gridItemStyle = GridItemStyle::NONE);
67     void CreateBigItem(int32_t rowStart = NULL_VALUE, int32_t rowEnd = NULL_VALUE, int32_t colStart = NULL_VALUE,
68         int32_t colEnd = NULL_VALUE, float width = NULL_VALUE, float height = NULL_VALUE);
69     void CreateBigColItem(int32_t colStart, int32_t colEnd);
70     void CreateBigRowItem(int32_t rowStart, int32_t rowEnd);
71     void AddFixedHeightItems(int32_t cnt, float height);
72     void ScrollTo(float position);
73     void UpdateCurrentOffset(float offset, int32_t source = SCROLL_FROM_UPDATE);
74     void CreateAdaptChildSizeGridItems(int32_t itemNumber, GridItemStyle gridItemStyle = GridItemStyle::NONE);
75 
76     void CheckPreloadListEqual(const std::list<int32_t>& expectedList) const;
77 
78     RefPtr<FrameNode> frameNode_;
79     RefPtr<GridPattern> pattern_;
80     RefPtr<GridEventHub> eventHub_;
81     RefPtr<GridLayoutProperty> layoutProperty_;
82     RefPtr<GridAccessibilityProperty> accessibilityProperty_;
83 };
84 } // namespace OHOS::Ace::NG
85 
86 #endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_GRID_GRID_TEST_NG_H
87