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_BUTTON_H
17 #define UI_TEST_BUTTON_H
18 
19 #include "components/ui_button.h"
20 #include "components/ui_checkbox.h"
21 #include "components/ui_scroll_view.h"
22 #include "ui_test.h"
23 
24 namespace OHOS {
25 constexpr char* UI_TEST_CHECKBOX_1 = "testCheckBox1";
26 constexpr char* UI_TEST_CHECKBOX_2 = "testCheckBox2";
27 constexpr char* UI_TEST_CHECKBOX_3 = "testCheckBox3";
28 constexpr char* UI_TEST_RADIO_BUTTON_1 = "testRadioButton1";
29 constexpr char* UI_TEST_RADIO_BUTTON_2 = "testRadioButton2";
30 constexpr char* UI_TEST_RADIO_BUTTON_3 = "testRadioButton3";
31 constexpr char* UI_TEST_TOGGLE_BUTTON_1 = "testToggleButton1";
32 constexpr char* UI_TEST_TOGGLE_BUTTON_2 = "testToggleButton2";
33 constexpr char* UI_TEST_TOGGLE_BUTTON_3 = "testToggleButton3";
34 constexpr char* UI_TEST_CHECKBOX_SETIMAGE_1 = "checkBoxSetImage1";
35 constexpr char* UI_TEST_CHECKBOX_SETIMAGE_2 = "checkBoxSetImage2";
36 constexpr char* UI_TEST_CHECKBOX_SETIMAGE_3 = "checkBoxSetImage3";
37 constexpr char* UI_TEST_CHECKBOX_SETIMAGE_4 = "checkBoxSetImage4";
38 constexpr char* UI_TEST_RADIO_SETIMAGE_1 = "radioButtonSetImage1";
39 constexpr char* UI_TEST_RADIO_SETIMAGE_2 = "radioButtonSetImage2";
40 constexpr char* UI_TEST_TOGGLE_SETIMAGE_1 = "toggleButtonSetImage1";
41 constexpr char* UI_TEST_TOGGLE_SETIMAGE_2 = "toggleButtonSetImage2";
42 constexpr char* UI_TEST_BUTTON_1 = "enlarge";
43 constexpr char* UI_TEST_BUTTON_2 = "narrow";
44 constexpr char* UI_TEST_BUTTON_3 = "goLeft";
45 constexpr char* UI_TEST_BUTTON_4 = "goRight";
46 constexpr char* UI_TEST_BUTTON_5 = "goUp";
47 constexpr char* UI_TEST_BUTTON_6 = "goDown";
48 constexpr char* UI_TEST_BUTTON_7 = "hide";
49 constexpr char* UI_TEST_BUTTON_8 = "display";
50 constexpr char* UI_TEST_BUTTON_9 = "touchable";
51 constexpr char* UI_TEST_BUTTON_10 = "untouchable";
52 constexpr char* UI_TEST_BUTTON_11 = "white";
53 constexpr char* UI_TEST_BUTTON_12 = "red";
54 constexpr char* UI_TEST_BUTTON_13 = "resetColor";
55 constexpr char* UI_TEST_BUTTON_14 = "resetAll";
56 constexpr char* UI_TEST_BUTTON_15 = "animation";
57 constexpr char* UI_TEST_BUTTON_16 = "noAnimation";
58 constexpr char* UI_TEST_BUTTON_17 = "buttonWithImage";
59 
60 class UITestBUTTON : public UITest {
61 public:
UITestBUTTON()62     UITestBUTTON() {}
~UITestBUTTON()63     ~UITestBUTTON() {}
64     void SetUp() override;
65     void TearDown() override;
66     const UIView* GetTestView() override;
67 
68     /**
69      * @brief Test Checkbox Function
70      */
71     void UIKitCheckBoxTest001();
72 
73     /**
74      * @brief Test Checkbox's SetImage Function
75      */
76     void UIKitCheckBoxTest002() const;
77 
78     /**
79      * @brief Test Radiobutton Function
80      */
81     void UIKitRadioButtonTest001();
82 
83     /**
84      * @brief Test Radiobutton's SetImage Function
85      */
86     void UIKitRadioButtonTest002() const;
87 
88     /**
89      * @brief Test Togglebutton Function
90      */
91     void UIKitToggleButtonTest001();
92 
93     /**
94      * @brief Test Togglebutton's SetImage Function
95      */
96     void UIKitToggleButtonTest002();
97 
98     /**
99      * @brief Test button Function
100      */
101     void UIKitButtonTest001();
102 
103 private:
104     void UIKitButtonTest002(UIScrollView* container, UIButton* button);
105     UIViewGroup* CreateButtonGroup(int16_t posX, int16_t posY, int16_t width, int16_t height,
106                                     UICheckBox::OnChangeListener** listener,
107                                     const char* id = nullptr,
108                                     UIViewType type = UI_CHECK_BOX,
109                                     const char* name = "aa");
110     void TearDownListeners001();
111     void TearDownListeners002();
112 #if defined(DEFAULT_ANIMATION) && DEFAULT_ANIMATION
113     void EnableAnimator(UIScrollView* container, UIButton* button);
114 #endif
115     void InitButtonListeners001(UIButton* button);
116     void InitButtonListeners002(UIButton* button);
117     static constexpr int16_t CHANGE_SIZE = 10;
118     UIScrollView* container_ = nullptr;
119 
120     UICheckBox::OnChangeListener* checkBoxChangeListener_ = nullptr;
121     UICheckBox::OnChangeListener* checkBoxChangeListener1_ = nullptr;
122     UICheckBox::OnChangeListener* checkBoxChangeListener2_ = nullptr;
123     UICheckBox::OnChangeListener* radioChangeListener_ = nullptr;
124     UICheckBox::OnChangeListener* radioChangeListener1_ = nullptr;
125     UICheckBox::OnChangeListener* radioChangeListener2_ = nullptr;
126     UICheckBox::OnChangeListener* toggleChangeListener_ = nullptr;
127     UICheckBox::OnChangeListener* toggleChangeListener1_ = nullptr;
128     UICheckBox::OnChangeListener* toggleChangeListener2_ = nullptr;
129 
130     UIView::OnClickListener* clickEnableVisiableListener_ = nullptr;
131     UIView::OnClickListener* clickDisableVisiableListener_ = nullptr;
132     UIView::OnClickListener* clickEnableTouchableListener_ = nullptr;
133     UIView::OnClickListener* clickDisableTouchableListener_ = nullptr;
134     UIView::OnClickListener* clickColorToWhiteListener_ = nullptr;
135     UIView::OnClickListener* clickColorToRedListener_ = nullptr;
136     UIView::OnClickListener* clickRevetColorListener_ = nullptr;
137     UIView::OnClickListener* clickRevetToOriginListener_ = nullptr;
138     UIView::OnClickListener* clickBigListener_ = nullptr;
139     UIView::OnClickListener* clickLeftListener_ = nullptr;
140     UIView::OnClickListener* clickRightListener_ = nullptr;
141     UIView::OnClickListener* clickUpListener_ = nullptr;
142     UIView::OnClickListener* clickDownListener_ = nullptr;
143     UIView::OnClickListener* clickSmallListener_ = nullptr;
144     UIView::OnClickListener* enableAnimationListener_ = nullptr;
145     UIView::OnClickListener* disableAnimationListener_ = nullptr;
146 };
147 } // namespace OHOS
148 #endif // UI_TEST_BUTTON_H
149