1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci#ifndef UI_TEST_H 17a3e0fd82Sopenharmony_ci#define UI_TEST_H 18a3e0fd82Sopenharmony_ci 19a3e0fd82Sopenharmony_ci#include "components/ui_label.h" 20a3e0fd82Sopenharmony_ci#include "components/ui_view_group.h" 21a3e0fd82Sopenharmony_ci#include "common/screen.h" 22a3e0fd82Sopenharmony_ci 23a3e0fd82Sopenharmony_cinamespace OHOS { 24a3e0fd82Sopenharmony_cistatic constexpr uint16_t TITLE_LABEL_DEFAULT_HEIGHT = 29; 25a3e0fd82Sopenharmony_cistatic constexpr uint16_t FONT_DEFAULT_SIZE = 20; 26a3e0fd82Sopenharmony_cistatic constexpr uint16_t VIEW_DISTANCE_TO_LEFT_SIDE = 48; 27a3e0fd82Sopenharmony_cistatic constexpr uint16_t VIEW_DISTANCE_TO_TOP_SIDE = 48; 28a3e0fd82Sopenharmony_cistatic constexpr uint16_t VIEW_DISTANCE_TO_LEFT_SIDE2 = 24; 29a3e0fd82Sopenharmony_cistatic constexpr uint16_t TEXT_DISTANCE_TO_LEFT_SIDE = 48; 30a3e0fd82Sopenharmony_cistatic constexpr uint16_t TEXT_DISTANCE_TO_TOP_SIDE = 11; 31a3e0fd82Sopenharmony_cistatic constexpr uint16_t HALF_OPA_OPAQUE = OPA_OPAQUE / 2; 32a3e0fd82Sopenharmony_cistatic constexpr uint16_t VIEW_STYLE_BORDER_WIDTH = 2; 33a3e0fd82Sopenharmony_cistatic constexpr uint16_t VIEW_STYLE_BORDER_RADIUS = 8; 34a3e0fd82Sopenharmony_cistatic constexpr uint16_t BUTTON_LABEL_SIZE = 16; 35a3e0fd82Sopenharmony_cistatic constexpr uint8_t BUTTON_STYLE_BORDER_RADIUS_VALUE = 20; 36a3e0fd82Sopenharmony_cistatic constexpr uint32_t BUTTON_STYLE_BACKGROUND_COLOR_VALUE = 0xFF333333; 37a3e0fd82Sopenharmony_cistatic constexpr uint32_t BUTTON_STYLE_BACKGROUND_COLOR_PRESS = 0xFF2D2D2D; 38a3e0fd82Sopenharmony_cistatic constexpr int16_t BACK_BUTTON_HEIGHT = 64; 39a3e0fd82Sopenharmony_cistatic constexpr uint16_t BUTTON_WIDHT1 = 80; 40a3e0fd82Sopenharmony_cistatic constexpr uint16_t BUTTON_HEIGHT1 = 40; 41a3e0fd82Sopenharmony_cistatic constexpr uint16_t BUTTON_WIDHT2 = 120; 42a3e0fd82Sopenharmony_cistatic constexpr uint16_t BUTTON_HEIGHT2 = 40; 43a3e0fd82Sopenharmony_cistatic constexpr uint16_t BUTTON_WIDHT3 = 150; 44a3e0fd82Sopenharmony_cistatic constexpr uint16_t BUTTON_HEIGHT3 = 40; 45a3e0fd82Sopenharmony_ci 46a3e0fd82Sopenharmony_ciclass UITest : public HeapBase { 47a3e0fd82Sopenharmony_cipublic: 48a3e0fd82Sopenharmony_ci UITest() {} 49a3e0fd82Sopenharmony_ci 50a3e0fd82Sopenharmony_ci virtual ~UITest() {} 51a3e0fd82Sopenharmony_ci 52a3e0fd82Sopenharmony_ci /** 53a3e0fd82Sopenharmony_ci * @brief Set up display environment. 54a3e0fd82Sopenharmony_ci * 55a3e0fd82Sopenharmony_ci */ 56a3e0fd82Sopenharmony_ci virtual void SetUp() = 0; 57a3e0fd82Sopenharmony_ci 58a3e0fd82Sopenharmony_ci /** 59a3e0fd82Sopenharmony_ci * @brief Tear down display environment. 60a3e0fd82Sopenharmony_ci * 61a3e0fd82Sopenharmony_ci */ 62a3e0fd82Sopenharmony_ci virtual void TearDown() 63a3e0fd82Sopenharmony_ci { 64a3e0fd82Sopenharmony_ci positionX_ = 0; 65a3e0fd82Sopenharmony_ci positionY_ = 0; 66a3e0fd82Sopenharmony_ci } 67a3e0fd82Sopenharmony_ci 68a3e0fd82Sopenharmony_ci /** 69a3e0fd82Sopenharmony_ci * @brief Get test view to add to root view. 70a3e0fd82Sopenharmony_ci * 71a3e0fd82Sopenharmony_ci * @returns test container view. 72a3e0fd82Sopenharmony_ci * 73a3e0fd82Sopenharmony_ci */ 74a3e0fd82Sopenharmony_ci virtual const UIView* GetTestView() = 0; 75a3e0fd82Sopenharmony_ci 76a3e0fd82Sopenharmony_ci static void DeleteChildren(UIView* view) 77a3e0fd82Sopenharmony_ci { 78a3e0fd82Sopenharmony_ci if (view == nullptr) { 79a3e0fd82Sopenharmony_ci return; 80a3e0fd82Sopenharmony_ci } 81a3e0fd82Sopenharmony_ci while (view != nullptr) { 82a3e0fd82Sopenharmony_ci UIView* tempView = view; 83a3e0fd82Sopenharmony_ci view = view->GetNextSibling(); 84a3e0fd82Sopenharmony_ci if (tempView->IsViewGroup() && (tempView->GetViewType() != UI_DIGITAL_CLOCK)) { 85a3e0fd82Sopenharmony_ci DeleteChildren(static_cast<UIViewGroup*>(tempView)->GetChildrenHead()); 86a3e0fd82Sopenharmony_ci } 87a3e0fd82Sopenharmony_ci if (tempView->GetParent()) { 88a3e0fd82Sopenharmony_ci static_cast<UIViewGroup*>(tempView->GetParent())->Remove(tempView); 89a3e0fd82Sopenharmony_ci } 90a3e0fd82Sopenharmony_ci delete tempView; 91a3e0fd82Sopenharmony_ci } 92a3e0fd82Sopenharmony_ci } 93a3e0fd82Sopenharmony_ci 94a3e0fd82Sopenharmony_ci UILabel* GetTitleLabel(const char* titleName) 95a3e0fd82Sopenharmony_ci { 96a3e0fd82Sopenharmony_ci if (titleName == nullptr) { 97a3e0fd82Sopenharmony_ci return nullptr; 98a3e0fd82Sopenharmony_ci } 99a3e0fd82Sopenharmony_ci UILabel* label = new UILabel(); 100a3e0fd82Sopenharmony_ci if (label == nullptr) { 101a3e0fd82Sopenharmony_ci return nullptr; 102a3e0fd82Sopenharmony_ci } 103a3e0fd82Sopenharmony_ci // 2: half of screen width 104a3e0fd82Sopenharmony_ci label->SetPosition(0, 0, Screen::GetInstance().GetWidth() / 2, TITLE_LABEL_DEFAULT_HEIGHT); 105a3e0fd82Sopenharmony_ci label->SetText(titleName); 106a3e0fd82Sopenharmony_ci label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); 107a3e0fd82Sopenharmony_ci return label; 108a3e0fd82Sopenharmony_ci } 109a3e0fd82Sopenharmony_ci 110a3e0fd82Sopenharmony_ciprotected: 111a3e0fd82Sopenharmony_ci int16_t positionX_ = 0; 112a3e0fd82Sopenharmony_ci int16_t positionY_ = 0; 113a3e0fd82Sopenharmony_ci}; 114a3e0fd82Sopenharmony_ci} // namespace OHOS 115a3e0fd82Sopenharmony_ci#endif 116