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_TEXTURE_MAPPER_H
17 #define UI_TEST_TEXTURE_MAPPER_H
18 
19 #include "components/ui_label.h"
20 #include "components/ui_label_button.h"
21 #include "components/ui_scroll_view.h"
22 #include "components/ui_texture_mapper.h"
23 #include "layout/grid_layout.h"
24 #include "ui_test.h"
25 
26 namespace OHOS {
27 class TestTextureMapperStopListener : public UITextureMapper::AnimatorStopListener {
28 public:
TestTextureMapperStopListener(UIViewGroup * viewGroup)29     explicit TestTextureMapperStopListener(UIViewGroup* viewGroup)
30     {
31         if (viewGroup != nullptr) {
32             viewGroup_ = viewGroup;
33             viewGroup_->Add(&label_);
34             label_.SetPosition(0, 0, 200, TITLE_LABEL_DEFAULT_HEIGHT); // 200: width;
35             label_.SetText("OnAnimatorStop");
36             label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
37             label_.SetStyle(STYLE_TEXT_COLOR, Color::Black().full);
38             label_.SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
39             label_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
40             label_.SetVisible(false);
41         }
42     }
43 
~TestTextureMapperStopListener()44     ~TestTextureMapperStopListener()
45     {
46         if (viewGroup_ != nullptr) {
47             viewGroup_->Remove(&label_);
48         }
49     };
50 
OnAnimatorStop(UIView & view)51     void OnAnimatorStop(UIView& view) override
52     {
53         label_.SetVisible(true);
54         label_.Invalidate();
55     }
56 
57 private:
58     UILabel label_;
59     UIViewGroup* viewGroup_ = nullptr;
60 };
61 
62 class UITestTextureMapper : public UITest, public UIView::OnClickListener {
63 public:
UITestTextureMapper()64     UITestTextureMapper() {}
~UITestTextureMapper()65     ~UITestTextureMapper() {}
66     void SetUp() override;
67     void TearDown() override;
68     const UIView* GetTestView() override;
69 
70     void SetUpButton(UILabelButton* btn, const char* title);
71 
72     bool OnClick(UIView& view, const ClickEvent& event) override;
73     bool ExpandClick(UIView& view, const ClickEvent& event);
74 
75     void UIKitTextureMapperTestSetRotateEnd001();
76     void UIKitTextureMapperTestSetRotateStart002();
77     void UIKitTextureMapperTestSetScaleEnd003();
78     void UIKitTextureMapperTestSetScaleStart004();
79     void UIKitTextureMapperTestSetPivot005();
80     void UIKitTextureMapperTestStart006();
81     void UIKitTextureMapperTestReset007();
82     void UIKitTextureMapperTestCancelAnimation008();
83     void UIKitTextureMapperTestSetAnimatorStopListener009();
84 
85 private:
86     UIScrollView* container_ = nullptr;
87     GridLayout* layout_ = nullptr;
88     UITextureMapper* textureMapper_ = nullptr;
89     TestTextureMapperStopListener* listener_ = nullptr;
90 
91     UILabelButton* resetBtn_ = nullptr;
92 
93     UILabelButton* incRotateEndBtn_ = nullptr;
94     UILabelButton* decRotateEndBtn_ = nullptr;
95     UILabelButton* startAngleBtn_ = nullptr;
96 
97     UILabelButton* incScaleEndBtn_ = nullptr;
98     UILabelButton* decScaleEndBtn_ = nullptr;
99     UILabelButton* startScaleBtn_ = nullptr;
100 
101     UILabelButton* durationTimeBtn_ = nullptr;
102     UILabelButton* delayTimeBtn_ = nullptr;
103     UILabelButton* easingBtn_ = nullptr;
104 
105     UILabelButton* incPivotBtn_ = nullptr;
106     UILabelButton* decPivotBtn_ = nullptr;
107     UILabelButton* startBtn_ = nullptr;
108     UILabelButton* cancelBtn_ = nullptr;
109     UILabelButton* resetImageBtn_ = nullptr;
110     UILabelButton* listenerBtn_ = nullptr;
111 };
112 } // namespace OHOS
113 #endif // UI_TEST_TEXTURE_MAPPER_H
114