• 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 #include "ui_auto_test.h"
17 
18 #include "compare_tools.h"
19 #include "components/root_view.h"
20 #include "components/ui_list.h"
21 #include "components/ui_view_group.h"
22 #include "dfx/event_injector.h"
23 #include "test_layout/ui_auto_test_basic_layout.h"
24 #include "test_render/ui_auto_test_render.h"
25 #include "ui_test_app.h"
26 #include "ui_test_group.h"
27 
28 namespace OHOS {
ResetMainMenu() const29 void UIAutoTest::ResetMainMenu() const
30 {
31     while (RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID) == nullptr) {
32         ClickViewById(UI_TEST_BACK_BUTTON_ID);
33     }
34 }
35 
EnterSubMenu(const char * id) const36 void UIAutoTest::EnterSubMenu(const char* id) const
37 {
38     if (id == nullptr) {
39         return;
40     }
41     UIView* view = RootView::GetInstance()->GetChildById(id);
42     if (view == nullptr) {
43         UIView* view = RootView::GetInstance()->GetChildById(UI_TEST_MAIN_LIST_ID);
44         if (view == nullptr) {
45             return;
46         }
47         ListNode<TestCaseInfo>* node = UITestGroup::GetTestCase().Begin();
48         while (node != UITestGroup::GetTestCase().End()) {
49             if ((node->data_.sliceId != nullptr) && (strcmp(id, node->data_.sliceId) == 0)) {
50                 UITestGroup::GetTestCase().PushFront(node->data_);
51                 UITestGroup::GetTestCase().Remove(node);
52                 break;
53             }
54             node = node->next_;
55         }
56         reinterpret_cast<UIList*>(view)->RefreshList();
57         CompareTools::WaitSuspend();
58     }
59     ClickViewById(id);
60 }
61 
ClickViewById(const char * id) const62 void UIAutoTest::ClickViewById(const char* id) const
63 {
64     if (id == nullptr) {
65         return;
66     }
67     UIView* view = RootView::GetInstance()->GetChildById(id);
68     if (view == nullptr) {
69         return;
70     }
71     Point point;
72     point.x = view->GetOrigRect().GetX();
73     point.y = view->GetOrigRect().GetY();
74     EventInjector::GetInstance()->SetClickEvent(point);
75     CompareTools::WaitSuspend();
76 }
77 
DragViewToHead(const char * id) const78 void UIAutoTest::DragViewToHead(const char* id) const
79 {
80     if (id == nullptr) {
81         return;
82     }
83     UIView* view = RootView::GetInstance()->GetChildById(id);
84     if (view == nullptr) {
85         return;
86     }
87     Point startPoint;
88     startPoint.x = view->GetOrigRect().GetX();
89     startPoint.y = view->GetOrigRect().GetY();
90 
91     Point endPoint;
92     endPoint.x = 100; // 100 :end point x position;
93     endPoint.y = 100; // 100 :end point y position;
94     EventInjector::GetInstance()->SetDragEvent(startPoint, endPoint, 300); // 300: drag time
95     CompareTools::WaitSuspend();
96 }
97 
CompareByBinary(const char * fileName) const98 void UIAutoTest::CompareByBinary(const char* fileName) const
99 {
100     if (fileName == nullptr) {
101         return;
102     }
103     char filePath[DEFAULT_FILE_NAME_MAX_LENGTH] = {0};
104     CompareTools::StrnCatPath(filePath, DEFAULT_FILE_NAME_MAX_LENGTH, fileName, strlen(fileName));
105     if (CompareTools::CheckFileExist(filePath, sizeof(filePath))) {
106         CompareTools::CompareFile(filePath, sizeof(filePath));
107     } else {
108         CompareTools::SaveFile(filePath, sizeof(filePath));
109     }
110 }
111 
SetUpTestCase()112 void UIAutoTest::SetUpTestCase()
113 {
114     AutoTestCaseGroup::AddTestCase(new UIAutoTestRender());
115     AutoTestCaseGroup::AddTestCase(new UIAutoTestBasicLayout());
116 }
117 } // namespace OHOS
118