• 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 "auto_test_app.h"
17 #include "auto_test_case_group.h"
18 #include "compare_tools.h"
19 #include "dfx/event_injector.h"
20 #if ENABLE_WINDOW
21 #include "window/window.h"
22 #endif
23 
24 namespace OHOS {
GetInstance()25 AutoTestApp* AutoTestApp::GetInstance()
26 {
27     static AutoTestApp instance;
28     return &instance;
29 }
30 
Start()31 void AutoTestApp::Start()
32 {
33     EventInjector::GetInstance()->RegisterEventInjector(EventDataType::POINT_TYPE);
34     EventInjector::GetInstance()->RegisterEventInjector(EventDataType::KEY_TYPE);
35 
36 #if ENABLE_WINDOW
37     Window* window = RootView::GetInstance()->GetBoundWindow();
38     if (window != nullptr) {
39         EventInjector::GetInstance()->SetWindowId(window->GetWindowId());
40     }
41 #endif
42     CompareTools::WaitSuspend();
43 
44     ListNode<AutoTestCaseGroup::AutoTestCase*>* node = AutoTestCaseGroup::GetTestCase().Begin();
45     while (node != AutoTestCaseGroup::GetTestCase().End()) {
46         node->data_->RunTestList();
47         node->data_->ResetMainMenu();
48         node = node->next_;
49     }
50 }
51 
~AutoTestApp()52 AutoTestApp::~AutoTestApp()
53 {
54     if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::POINT_TYPE)) {
55         EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::POINT_TYPE);
56     }
57     if (EventInjector::GetInstance()->IsEventInjectorRegistered(EventDataType::KEY_TYPE)) {
58         EventInjector::GetInstance()->UnregisterEventInjector(EventDataType::KEY_TYPE);
59     }
60     AutoTestCaseGroup::TearDownTestCase();
61 }
62 } // namespace OHOS
63