• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_H
17 #define UI_TEST_H
18 
19 #include "components/ui_label.h"
20 #include "components/ui_view_group.h"
21 #include "common/screen.h"
22 
23 namespace OHOS {
24 static constexpr uint16_t TITLE_LABEL_DEFAULT_HEIGHT = 29;
25 static constexpr uint16_t FONT_DEFAULT_SIZE = 20;
26 static constexpr uint16_t VIEW_DISTANCE_TO_LEFT_SIDE = 48;
27 static constexpr uint16_t VIEW_DISTANCE_TO_TOP_SIDE = 48;
28 static constexpr uint16_t VIEW_DISTANCE_TO_LEFT_SIDE2 = 24;
29 static constexpr uint16_t TEXT_DISTANCE_TO_LEFT_SIDE = 48;
30 static constexpr uint16_t TEXT_DISTANCE_TO_TOP_SIDE = 11;
31 static constexpr uint16_t HALF_OPA_OPAQUE = OPA_OPAQUE / 2;
32 static constexpr uint16_t VIEW_STYLE_BORDER_WIDTH = 2;
33 static constexpr uint16_t VIEW_STYLE_BORDER_RADIUS = 8;
34 static constexpr uint16_t BUTTON_LABEL_SIZE = 16;
35 static constexpr uint8_t BUTTON_STYLE_BORDER_RADIUS_VALUE = 20;
36 static constexpr uint32_t BUTTON_STYLE_BACKGROUND_COLOR_VALUE = 0xFF333333;
37 static constexpr uint32_t BUTTON_STYLE_BACKGROUND_COLOR_PRESS = 0xFF2D2D2D;
38 static constexpr int16_t BACK_BUTTON_HEIGHT = 64;
39 static constexpr uint16_t BUTTON_WIDHT1 = 80;
40 static constexpr uint16_t BUTTON_HEIGHT1 = 40;
41 static constexpr uint16_t BUTTON_WIDHT2 = 120;
42 static constexpr uint16_t BUTTON_HEIGHT2 = 40;
43 static constexpr uint16_t BUTTON_WIDHT3 = 150;
44 static constexpr uint16_t BUTTON_HEIGHT3 = 40;
45 
46 class UITest : public HeapBase {
47 public:
UITest()48     UITest() {}
49 
~UITest()50     virtual ~UITest() {}
51 
52     /**
53      * @brief Set up display environment.
54      *
55      */
56     virtual void SetUp() = 0;
57 
58     /**
59      * @brief Tear down display environment.
60      *
61      */
TearDown()62     virtual void TearDown()
63     {
64         positionX_ = 0;
65         positionY_ = 0;
66     }
67 
68     /**
69      * @brief Get test view to add to root view.
70      *
71      * @returns test container view.
72      *
73      */
74     virtual const UIView* GetTestView() = 0;
75 
DeleteChildren(UIView * view)76     void DeleteChildren(UIView* view)
77     {
78         if (view == nullptr) {
79             return;
80         }
81         while (view != nullptr) {
82             UIView* tempView = view;
83             view = view->GetNextSibling();
84             if (tempView->IsViewGroup() && (tempView->GetViewType() != UI_DIGITAL_CLOCK)) {
85                 DeleteChildren(static_cast<UIViewGroup*>(tempView)->GetChildrenHead());
86             }
87             if (tempView->GetParent()) {
88                 static_cast<UIViewGroup*>(tempView->GetParent())->Remove(tempView);
89             }
90             delete tempView;
91         }
92     }
93 
GetTitleLabel(const char * titleName)94     UILabel* GetTitleLabel(const char* titleName)
95     {
96         if (titleName == nullptr) {
97             return nullptr;
98         }
99         UILabel* label = new UILabel();
100         if (label == nullptr) {
101             return nullptr;
102         }
103         // 2: half of screen width
104         label->SetPosition(0, 0, Screen::GetInstance().GetWidth() / 2, TITLE_LABEL_DEFAULT_HEIGHT);
105         label->SetText(titleName);
106         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
107         return label;
108     }
109 
110 protected:
111     int16_t positionX_ = 0;
112     int16_t positionY_ = 0;
113 };
114 } // namespace OHOS
115 #endif