1 /*
2  * Copyright (c) 2020-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 #ifndef UI_TEST_SLIDER_H
17 #define UI_TEST_SLIDER_H
18 
19 #include "components/ui_label.h"
20 #include "components/ui_label_button.h"
21 #include "components/ui_scroll_view.h"
22 #include "components/ui_slider.h"
23 #include "ui_test.h"
24 
25 namespace OHOS {
26 class TestUISliderEventListener : public UISlider::UISliderEventListener,
27                                   public UIView::OnClickListener,
28                                   public UIView::OnDragListener {
29 public:
TestUISliderEventListener(UIViewGroup * viewGroup)30     explicit TestUISliderEventListener(UIViewGroup* viewGroup)
31     {
32         viewGroup_ = viewGroup;
33     }
~TestUISliderEventListener()34     virtual ~TestUISliderEventListener() {}
35     void OnChange(int32_t progress) override;
36     void OnRelease(int32_t progress) override;
37     bool OnClick(UIView& view, const ClickEvent& event) override;
38     bool OnDrag(UIView& view, const DragEvent& event) override;
39     bool MallocLabel();
40 
41 private:
42     UILabel* label_ = nullptr;
43     UIViewGroup* viewGroup_ = nullptr;
44     int32_t value_ = 0;
45 };
46 
47 class UITestSlider : public UITest, public UIView::OnClickListener {
48 public:
UITestSlider()49     UITestSlider() {}
~UITestSlider()50     ~UITestSlider() {}
51     void SetUp() override;
52     void TearDown() override;
53     const UIView* GetTestView() override;
54 
55     void SetUpButton(UILabelButton* btn, const char* title, int16_t x, int16_t y);
56     void SetUpLabel(const char* title, int16_t x, int16_t y) const;
57 
58     bool OnClick(UIView& view, const ClickEvent& event) override;
59     bool ExpandClick1(UIView& view, const ClickEvent& event);
60     bool ExpandClick2(UIView& view, const ClickEvent& event);
61 
62     void UIKitSliderTestUISlider001();
63     void UIKitSliderTestSetRange002();
64     void UIKitSliderTestSetValue003();
65     void UIKitSliderTestSetImage004();
66     void UIKitSliderTestSetStyle005();
67     void UIKitSliderTestGetStyle006();
68     void UIKitSliderTestSetKnobWidth007();
69     void UIKitSliderTestSetStep008();
70     void UIKitSliderTestSetColor009();
71     void UIKitSliderTestSetDirection010();
72     void UIKitSliderTestSetValidSize011();
73     void UIKitSliderTestSetRadius012();
74     void UIKitSliderTestSetOnChangeListener013();
75     void UIKitSliderTestSetOnReleaseListener014();
76     void UIKitSliderTestSetOnClickCallback015();
77     void UIKitSliderTestSetOnDragCallback016();
78     void UIKitSliderTestSetCircularStyle017();
79 
80 private:
81     static constexpr int32_t DEFAULT_VALUE = 20;
82     static constexpr int16_t DEFAULT_WIDTH = 50;
83     static constexpr int16_t DEFAULT_HEIGHT = 250;
84     static constexpr int16_t DEFAULT_RADIUS = 10;
85     static constexpr int32_t MAX_VALUE = 100;
86     UIScrollView* container_ = nullptr;
87     UIScrollView* scroll_ = nullptr;
88     UISlider* slider_ = nullptr;
89     TestUISliderEventListener* listener_ = nullptr;
90     UIViewGroup* uiViewGroupFrame_ = nullptr;
91 
92     UILabelButton* resetBtn_ = nullptr;
93     UILabelButton* widthBtn_ = nullptr;
94     UILabelButton* heightBtn_ = nullptr;
95     UILabelButton* incProgressBtn_ = nullptr;
96     UILabelButton* decProgressBtn_ = nullptr;
97     UILabelButton* incMinProgressBtn_ = nullptr;
98     UILabelButton* decMinProgressBtn_ = nullptr;
99     UILabelButton* incMaxProgressBtn_ = nullptr;
100     UILabelButton* decMaxProgressBtn_ = nullptr;
101     UILabelButton* stepBtn_ = nullptr;
102     UILabelButton* dirL2RBtn_ = nullptr;
103     UILabelButton* dirR2LBtn_ = nullptr;
104     UILabelButton* dirT2BBtn_ = nullptr;
105     UILabelButton* dirB2TBtn_ = nullptr;
106     UILabelButton* imageBtn_ = nullptr;
107     UILabelButton* noImageBtn_ = nullptr;
108     UILabelButton* setStyleBtn_ = nullptr;
109     UILabelButton* getStyleBtn_ = nullptr;
110     UILabelButton* incKnobWidthBtn_ = nullptr;
111     UILabelButton* decKnobWidthBtn_ = nullptr;
112     UILabelButton* colorBtn_ = nullptr;
113     UILabelButton* radiusBtn_ = nullptr;
114     UILabelButton* onChangeBtn_ = nullptr;
115     UILabelButton* onReleaseBtn_ = nullptr;
116     UILabelButton* onClickBtn_ = nullptr;
117     UILabelButton* onDragBtn_ = nullptr;
118     UILabelButton* circularStyleBtn_ = nullptr;
119 };
120 } // namespace OHOS
121 #endif // UI_TEST_SLIDER_H
122