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
23namespace OHOS {
24static constexpr uint16_t TITLE_LABEL_DEFAULT_HEIGHT = 29;
25static constexpr uint16_t FONT_DEFAULT_SIZE = 20;
26static constexpr uint16_t VIEW_DISTANCE_TO_LEFT_SIDE = 48;
27static constexpr uint16_t VIEW_DISTANCE_TO_TOP_SIDE = 48;
28static constexpr uint16_t VIEW_DISTANCE_TO_LEFT_SIDE2 = 24;
29static constexpr uint16_t TEXT_DISTANCE_TO_LEFT_SIDE = 48;
30static constexpr uint16_t TEXT_DISTANCE_TO_TOP_SIDE = 11;
31static constexpr uint16_t HALF_OPA_OPAQUE = OPA_OPAQUE / 2;
32static constexpr uint16_t VIEW_STYLE_BORDER_WIDTH = 2;
33static constexpr uint16_t VIEW_STYLE_BORDER_RADIUS = 8;
34static constexpr uint16_t BUTTON_LABEL_SIZE = 16;
35static constexpr uint8_t BUTTON_STYLE_BORDER_RADIUS_VALUE = 20;
36static constexpr uint32_t BUTTON_STYLE_BACKGROUND_COLOR_VALUE = 0xFF333333;
37static constexpr uint32_t BUTTON_STYLE_BACKGROUND_COLOR_PRESS = 0xFF2D2D2D;
38static constexpr int16_t BACK_BUTTON_HEIGHT = 64;
39static constexpr uint16_t BUTTON_WIDHT1 = 80;
40static constexpr uint16_t BUTTON_HEIGHT1 = 40;
41static constexpr uint16_t BUTTON_WIDHT2 = 120;
42static constexpr uint16_t BUTTON_HEIGHT2 = 40;
43static constexpr uint16_t BUTTON_WIDHT3 = 150;
44static constexpr uint16_t BUTTON_HEIGHT3 = 40;
45
46class UITest : public HeapBase {
47public:
48    UITest() {}
49
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     */
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
76    static 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
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
110protected:
111    int16_t positionX_ = 0;
112    int16_t positionY_ = 0;
113};
114} // namespace OHOS
115#endif
116