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_BASIC_LAYOUT_H 17 #define UI_TEST_BASIC_LAYOUT_H 18 19 #include "components/ui_label.h" 20 #include "components/ui_label_button.h" 21 #include "components/ui_scroll_view.h" 22 #include "layout/flex_layout.h" 23 #include "layout/grid_layout.h" 24 #include "ui_test.h" 25 26 namespace OHOS { 27 namespace { 28 constexpr char* UI_TEST_BASIC_LAYOUT_ID = "Basic_Layout"; 29 constexpr char* UI_TEST_BASIC_LAYOUT_RESET_BTN_ID = "test_basic_layout_reset_button"; 30 constexpr char* UI_TEST_BASIC_LAYOUT_MARGIN_BTN_ID = "test_basic_layout_margin_button"; 31 constexpr char* UI_TEST_BASIC_LAYOUT_PADDING_BTN_ID = "test_basic_layout_padding_button"; 32 constexpr char* UI_TEST_BASIC_LAYOUT_CENTEROFPARENT_BTN_ID = "test_basic_layout_center_of_parent_button"; 33 constexpr char* UI_TEST_BASIC_LAYOUT_LEFTOFPARENT_BTN_ID = "test_basic_layout_left_of_parent_button"; 34 constexpr char* UI_TEST_BASIC_LAYOUT_RIGHTOFPARENT_BTN_ID = "test_basic_layout_right_of_parent_button"; 35 constexpr char* UI_TEST_BASIC_LAYOUT_TOPOFPARENT_BTN_ID = "test_basic_layout_top_of_parent_button"; 36 constexpr char* UI_TEST_BASIC_LAYOUT_BOTTOMOFPARENT_BTN_ID = "test_basic_layout_bottom_of_parent_button"; 37 constexpr char* UI_TEST_BASIC_LAYOUT_LEFTOFSIBLING_BTN_ID = "test_basic_layout_left_of_sibling_button"; 38 constexpr char* UI_TEST_BASIC_LAYOUT_RIGHTOFSIBLING_BTN_ID = "test_basic_layout_right_of_sibling_button"; 39 constexpr char* UI_TEST_BASIC_LAYOUT_TOPOFSIBLING_BTN_ID = "test_basic_layout_top_of_sibling_button"; 40 constexpr char* UI_TEST_BASIC_LAYOUT_BOTTOMOFSIBLING_BTN_ID = "test_basic_layout_bottom_of_sibling_button"; 41 constexpr char* UI_TEST_BASIC_LAYOUT_HORCENTEROFSIBLING_BTN_ID = "test_basic_layout_hor_center_of_sibling_button"; 42 constexpr char* UI_TEST_BASIC_LAYOUT_VERCENTEROFSIBLING_BTN_ID = "test_basic_layout_ver_center_of_sibling_button"; 43 constexpr char* UI_TEST_BASIC_LAYOUT_LEFTTOSIBLING_BTN_ID = "test_basic_layout_left_to_sibling_button"; 44 constexpr char* UI_TEST_BASIC_LAYOUT_RIGHTTOSIBLING_BTN_ID = "test_basic_layout_right_to_sibling_button"; 45 constexpr char* UI_TEST_BASIC_LAYOUT_TOPTOSIBLING_BTN_ID = "test_basic_layout_top_to_sibling_button"; 46 constexpr char* UI_TEST_BASIC_LAYOUT_BOTTOMTOSIBLING_BTN_ID = "test_basic_layout_bottom_to_sibling_button"; 47 constexpr char* UI_TEST_BASIC_LAYOUT_INVALIDLAYOUT_BTN_ID = "test_basic_layout_invalid_layout_button"; 48 } 49 class UITestBasicLayout : public UITest, public UIView::OnClickListener { 50 public: UITestBasicLayout()51 UITestBasicLayout() {} ~UITestBasicLayout()52 ~UITestBasicLayout() {} 53 void SetUp() override; 54 void TearDown() override; 55 const UIView* GetTestView() override; 56 57 /** 58 * @brief Test basic layout function. 59 */ 60 void UIKitLayoutTestBasicLayout001(); 61 62 bool OnClick(UIView& view, const ClickEvent& event) override; 63 void OnClickButton(UIView& view); 64 void InitSetUpButton(); 65 private: 66 UIScrollView* container_ = nullptr; 67 GridLayout* layout_ = nullptr; 68 UIViewGroup* uiViewGroupFrame_ = nullptr; 69 UIViewGroup* testTarget_ = nullptr; 70 UIView* testTargetSmall1_ = nullptr; 71 UIView* testTargetSmall2_ = nullptr; 72 UIView* refTarget_ = nullptr; 73 UILabelButton* resetBtn_ = nullptr; 74 75 UILabelButton* lCenterOfParentBtn_ = nullptr; 76 UILabelButton* lLeftOfParentBtn_ = nullptr; 77 UILabelButton* lRightOfParentBtn_ = nullptr; 78 UILabelButton* lTopOfParentBtn_ = nullptr; 79 UILabelButton* lBottomOfParentBtn_ = nullptr; 80 81 UILabelButton* aLeftToSiblingBtn_ = nullptr; 82 UILabelButton* aRightToSiblingBtn_ = nullptr; 83 UILabelButton* aTopToSiblingBtn_ = nullptr; 84 UILabelButton* aBottomToSiblingBtn_ = nullptr; 85 UILabelButton* aHorCenterToSiblingBtn_ = nullptr; 86 UILabelButton* aVerCenterToSiblingBtn_ = nullptr; 87 88 UILabelButton* lLeftToSiblingBtn_ = nullptr; 89 UILabelButton* lRightToSiblingBtn_ = nullptr; 90 UILabelButton* lTopToSiblingBtn_ = nullptr; 91 UILabelButton* lBottomToSiblingBtn_ = nullptr; 92 UILabelButton* lInvalidLayoutBtn_ = nullptr; 93 UILabelButton* marginBtn_ = nullptr; 94 UILabelButton* padBtn_ = nullptr; 95 UILabelButton* setStyle_ = nullptr; 96 97 void SetUpButton(UILabelButton* btn, const char* title, const char* id = nullptr) 98 { 99 if (btn == nullptr) { 100 return; 101 } 102 layout_->Add(btn); 103 btn->Resize(BUTTON_WIDHT2, BUTTON_HEIGHT2); 104 btn->SetText(title); 105 btn->SetViewId(id); 106 btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE); 107 btn->SetOnClickListener(this); 108 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED); 109 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED); 110 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE); 111 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED); 112 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED); 113 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE); 114 } 115 }; 116 } // namespace OHOS 117 #endif // UI_TEST_INPUT_EVENT_H 118