• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "ui_test_scroll_bar.h"
17 #include "components/ui_label_button.h"
18 #include "engines/gfx/gfx_engine_manager.h"
19 #include "test_resource_config.h"
20 
21 namespace {
22 constexpr int16_t LABEL_WIDTH = 150;
23 constexpr int16_t LABEL_HEIGHT = 74;
24 constexpr int16_t LABEL_INTERVAL = 50;
25 constexpr int16_t LABEL_LEFT_INTERVAL = 125;
26 constexpr int16_t VIEW_WIDTH = 400;
27 constexpr int16_t VIEW_HEIGHT = 400;
28 }
29 namespace OHOS {
SetUp()30 void UITestScrollBar::SetUp()
31 {
32     BaseGfxEngine::GetInstance()->SetScreenShape(ScreenShape::CIRCLE);
33 
34     if (container_ == nullptr) {
35         container_ = new UIViewGroup();
36     }
37     if (scrollView_ == nullptr) {
38         scrollView_ = new UIScrollView();
39     }
40     if (list_ == nullptr) {
41         list_ = new UIList();
42     }
43     if (foreImg1_ == nullptr) {
44         foreImg1_ = new UIImageView();
45     }
46     if (foreImg2_ == nullptr) {
47         foreImg2_ = new UIImageView();
48     }
49     if (adapter_ == nullptr) {
50         adapter_ = new TextAdapter();
51     }
52     if (adapterData_ == nullptr) {
53         adapterData_ = new List<const char*>();
54         adapterData_->PushBack("abcd0");
55         adapterData_->PushBack("abcd1");
56         adapterData_->PushBack("abcd2");
57         adapterData_->PushBack("abcd3");
58         adapterData_->PushBack("abcd4");
59         adapterData_->PushBack("abcd5");
60         adapterData_->PushBack("abcd6");
61         adapterData_->PushBack("abcd7");
62         adapterData_->PushBack("abcd8");
63         adapterData_->PushBack("abcd9");
64         adapterData_->PushBack("abcd10");
65         adapterData_->PushBack("abcd11");
66         adapterData_->PushBack("abcd12");
67         adapterData_->PushBack("abcd13");
68         adapterData_->PushBack("abcd14");
69         adapterData_->PushBack("abcd15");
70     }
71 
72     container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
73 
74     container_->Add(scrollView_);
75     scrollView_->SetPosition(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
76     scrollView_->SetYScrollBarVisible(true);
77     scrollView_->SetHorizontalScrollState(false);
78     scrollView_->SetReboundSize(50); // 50: rebound size
79     scrollView_->SetScrollBarCenter({200, 200}); // 200: x, y of center
80 
81     container_->Add(list_);
82     list_->SetPosition(450, 0, VIEW_WIDTH, VIEW_HEIGHT); // 450: x
83     list_->SetYScrollBarVisible(true);
84     list_->SetScrollBarSide(SCROLL_BAR_LEFT_SIDE);
85     list_->SetReboundSize(50); // 50: rebound size
86 }
87 
TearDown()88 void UITestScrollBar::TearDown()
89 {
90     DeleteChildren(container_);
91     container_ = nullptr;
92     scrollView_ = nullptr;
93     list_ = nullptr;
94     foreImg1_ = nullptr;
95     foreImg2_ = nullptr;
96     if (adapterData_ != nullptr) {
97         adapterData_->Clear();
98         delete adapterData_;
99         adapterData_ = nullptr;
100     }
101     if (adapter_ != nullptr) {
102         delete adapter_;
103         adapter_ = nullptr;
104     }
105 
106     BaseGfxEngine::GetInstance()->SetScreenShape(ScreenShape::RECTANGLE);
107 }
108 
GetTestView()109 const UIView* UITestScrollBar::GetTestView()
110 {
111     UIKitScrollBarTESTScrollview001();
112     UIKitScrollBarTESTList001();
113     return container_;
114 }
115 
UIKitScrollBarTESTScrollview001()116 void UITestScrollBar::UIKitScrollBarTESTScrollview001()
117 {
118     UILabelButton* label1 = new UILabelButton();
119     scrollView_->Add(label1);
120     label1->LayoutTopOfParent(LABEL_INTERVAL);
121     label1->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
122     label1->SetWidth(LABEL_WIDTH);
123     label1->SetHeight(LABEL_HEIGHT);
124     label1->SetViewId("label1");
125     label1->SetText("label1");
126 
127     UILabelButton* label2 = new UILabelButton();
128     scrollView_->Add(label2);
129     label2->LayoutBottomToSibling("label1", LABEL_INTERVAL);
130     label2->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
131     label2->SetWidth(LABEL_WIDTH);
132     label2->SetHeight(LABEL_HEIGHT);
133     label2->SetViewId("label2");
134     label2->SetText("label2");
135 
136     UILabelButton* label3 = new UILabelButton();
137     scrollView_->Add(label3);
138     label3->LayoutBottomToSibling("label2", LABEL_INTERVAL);
139     label3->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
140     label3->SetWidth(LABEL_WIDTH);
141     label3->SetHeight(LABEL_HEIGHT);
142     label3->SetViewId("label3");
143     label3->SetText("label3");
144 
145     UILabelButton* label4 = new UILabelButton();
146     scrollView_->Add(label4);
147     label4->LayoutBottomToSibling("label3", LABEL_INTERVAL);
148     label4->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
149     label4->SetWidth(LABEL_WIDTH);
150     label4->SetHeight(LABEL_HEIGHT);
151     label4->SetViewId("label4");
152     label4->SetText("label4");
153 
154     UILabelButton* label5 = new UILabelButton();
155     scrollView_->Add(label5);
156     label5->LayoutBottomToSibling("label4", LABEL_INTERVAL);
157     label5->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
158     label5->SetWidth(LABEL_WIDTH);
159     label5->SetHeight(LABEL_HEIGHT);
160     label5->SetViewId("label5");
161     label5->SetText("label5");
162 
163     foreImg1_->SetSrc(TEST_CIRCLE_FORE_IMAGE);
164     container_->Add(foreImg1_);
165     foreImg1_->SetPosition(0, 0);
166 }
167 
UIKitScrollBarTESTList001()168 void UITestScrollBar::UIKitScrollBarTESTList001()
169 {
170     adapter_->SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
171     adapter_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
172     adapter_->SetHeight(LABEL_HEIGHT);
173     adapter_->SetWidth(VIEW_WIDTH);
174     adapter_->SetData(adapterData_);
175 
176     list_->SetAdapter(adapter_);
177     list_->SetIntercept(true);
178     list_->SetYScrollBarVisible(true);
179 
180     foreImg2_->SetSrc(TEST_CIRCLE_FORE_IMAGE);
181     container_->Add(foreImg2_);
182     foreImg2_->SetPosition(450, 0); // 450: x
183 }
184 } // namespace OHOS
185