1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2024 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19from src.beans.event_node import EventNode 20from src.beans.event_procedures import EventProcedures 21from src.beans.event_scope import EventScope 22from src.beans.event_tree import EventTree 23from src.beans.frame_node import FrameNode 24from src.beans.procedure_step import ProcedureStep 25from src.beans.state_history import StateHistory 26from src.beans.touch_point import TouchPoint 27from src.utils.log_wrapper import log_info, log_error 28 29 30def test_begin(test_info): 31 log_info("# " + test_info + " == test == begin") 32 33 34def test_end(test_info, result): 35 if result: 36 log_info("# " + test_info + " == test PASSED == end") 37 else: 38 log_error("# " + test_info + " == test FAILED == end") 39 40 41def test_frame_node(): 42 test_begin("test_frame_node") 43 node_str = (" nodeId: 0, parentId: -1, tag: root, monopolizeEvents: 0, isHit: 1, hitTestMode: 0, responseRegion: " 44 "RectT (0.00, 0.00) - [720.00 x 1280.00]\n") 45 frame_node = FrameNode(node_str) 46 frame_node.dump() 47 test_end("test_frame_node", frame_node.is_succeed()) 48 49 50def test_touch_point(): 51 test_begin("test_touch_point") 52 touch_point_str = ( 53 "id: 0, point: (123.12, 56.00), screenPoint: (45.00, 280.30), type: down, timestamp: 2017-08-25 15:00:22.295, " 54 "isInjected: 0\n") 55 touch_point = TouchPoint(touch_point_str) 56 touch_point.dump() 57 test_end("test_touch_point", touch_point.is_succeed()) 58 59 60def test_procedure_step(): 61 test_begin("test_procedure_step") 62 procedure_step_str = "procedure: HandleTouchUp, timestamp: 2017-08-25 15:00:22.295" 63 procedure_step = ProcedureStep(procedure_step_str) 64 procedure_step.dump() 65 test_end("test_procedure_step", procedure_step.is_succeed()) 66 67 68def test_state_history(): 69 test_begin("test_state_history") 70 state_history = "stateHistory:\n" + \ 71 " procedure: HandleTouchDown, timestamp: 2017-08-20 15:00:22.247\n" + \ 72 " procedure: HandleTouchUp, timestamp: 2017-08-20 15:00:22.295\n" 73 state_history = StateHistory(state_history) 74 state_history.dump() 75 test_end("test_state_history", state_history.is_succeed()) 76 77 78def test_event_node(): 79 test_begin("test_event_node") 80 event_node_str = ( 81 "frameNodeId: 88, type: LongPressRecognizer, depth: 1, id: 0xef748aa0, parentId: 0xf063eed0, customInfo: " 82 "duration: 500, isForDrag: 0, repeat: 0, fingers: 1\n" 83 "stateHistory:\n" 84 " procedure: HandleTouchDown, timestamp: 2017-08-25 15:00:22.247\n" 85 " procedure: HandleTouchUp, timestamp: 2017-08-25 15:00:22.295\n") 86 event_node = EventNode(event_node_str) 87 event_node.dump() 88 test_end("test_event_node", event_node.is_succeed()) 89 90 91def test_event_scope(): 92 test_begin("test_event_scope") 93 event_scope_str = ("finger: 0\n" 94 " frameNodeId: 0, type: root, depth: 0, id: 0, parentId: -1\n" 95 " stateHistory:\n" 96 " procedure: HandleTouchDown, timestamp: 2017-08-25 15:00:22.247\n" 97 " procedure: HandleTouchUp, timestamp: 2017-08-25 15:00:22.295\n" 98 " frameNodeId: 88, type: LongPressRecognizer, depth: 1, id: 0xef748aa0, parentId: " 99 "0xf063eed0, customInfo: duration: 500, isForDrag: 0, repeat: 0, fingers: 1\n" 100 " stateHistory:\n" 101 " procedure: HandleTouchDown, state: DETECTING, disposal: NONE, timestamp: 2017-08-25 " 102 "15:00:22.247\n" 103 " procedure: HandleTouchUp, state: FAIL, disposal: REJECT, timestamp: 2017-08-25 " 104 "15:00:22.295\n") 105 event_scope = EventScope(event_scope_str) 106 event_scope.dump() 107 test_end("test_event_scope", event_scope.is_succeed()) 108 109 110def test_event_procedures(): 111 test_begin("test_event_procedures") 112 event_procedures_str = ("extra text\n" 113 "finger: 0\n" 114 " frameNodeId: 0, type: root, depth: 0, id: 0, parentId: -1\n" 115 " stateHistory:\n" 116 " procedure: HandleTouchDown, timestamp: 2017-08-25 15:00:22.247\n" 117 " procedure: HandleTouchUp, timestamp: 2017-08-25 15:00:22.295\n" 118 " frameNodeId: 88, type: LongPressRecognizer, depth: 1, id: 0xef748aa0, parentId: " 119 "0xf063eed0, customInfo: duration: 500, isForDrag: 0, repeat: 0, fingers: 1\n" 120 " stateHistory:\n" 121 " procedure: HandleTouchDown, state: DETECTING, disposal: NONE, timestamp: 2017-08-25 " 122 "15:00:22.247\n" 123 " procedure: HandleTouchUp, state: FAIL, disposal: REJECT, timestamp: 2017-08-25 " 124 "15:00:22.295\n" 125 "finger: 1\n" 126 " frameNodeId: 22, type: root, depth: 0, id: 0, parentId: -1\n" 127 " stateHistory:\n" 128 " procedure: HandleTouchDown, timestamp: 2017-08-25 15:00:22.247\n" 129 " procedure: HandleTouchUp, timestamp: 2017-08-25 15:00:22.295\n" 130 " frameNodeId: 66, type: LongPressRecognizer, depth: 3, id: 0xef748aa0, parentId: " 131 "0xf063eed0, customInfo: duration: 500, isForDrag: 0, repeat: 0, fingers: 1\n" 132 " stateHistory:\n" 133 " procedure: HandleTouchDown, state: DETECTING, disposal: NONE, timestamp: 2017-08-25 " 134 "15:00:22.247\n" 135 " procedure: HandleTouchUp, state: FAIL, disposal: REJECT, timestamp: 2017-08-25 " 136 "15:00:22.295\n" 137 "hello world") 138 event_procedures = EventProcedures(event_procedures_str) 139 event_procedures.dump() 140 test_end("test_event_procedures", event_procedures.is_succeed()) 141 142 143def test_event_tree(): 144 test_begin("test_event_tree") 145 event_tree_str = ("1: event tree =>\n" 146 " touch points:\n" 147 " id: 0, point: Offset (288.00, 530.00), screenPoint: Offset (288.00, 530.00), " 148 "type: TouchDown, timestamp: 2017-08-25 15:00:22.043, isInjected: 0\n" 149 " id: 0, point: Offset (288.00, 536.00), screenPoint: Offset (288.00, 536.00), type: TouchUp, " 150 "timestamp: 2017-08-25 15:00:22.130, isInjected: 0\n" 151 " hittest:\n" 152 " nodeId: 0, parentId: -1, tag: root, monopolizeEvents: 0, isHit: 1, hitTestMode: 0, " 153 "responseRegion: RectT (0.00, 0.00) - [720.00 x 1280.00]\n" 154 " nodeId: 1, parentId: 0, tag: stage, monopolizeEvents: 0, isHit: 1, hitTestMode: 0, " 155 "responseRegion: RectT (0.00, 0.00) - [720.00 x 1280.00]\n" 156 " event procedures:\n" 157 " finger:0\n" 158 " frameNodeId: 84, type: TouchEventActuator, depth: 0, id: 0xf072b240, parentId: 0x0\n" 159 " stateHistory:\n" 160 " procedure: HandleTouchDown, timestamp: 2017-08-25 15:00:22.046\n" 161 " procedure: HandleTouchUp, timestamp: 2017-08-25 15:00:22.130\n" 162 " frameNodeId: 84, type: ExclusiveRecognizer, depth: 0, id: 0xf063eed0, parentId: 0x0\n" 163 " stateHistory:\n" 164 " procedure: HandleTouchDown, state: READY, disposal: NONE, timestamp: 2017-08-25 " 165 "15:00:22.046\n" 166 " procedure: HandleTouchUp, state: FAIL, disposal: REJECT, timestamp: 2017-08-25 " 167 "15:00:22.131\n" 168 "2: event tree =>\n") 169 event_tree = EventTree(event_tree_str) 170 event_tree.dump() 171 test_end("test_event_tree", event_tree.is_succeed()) 172 173 174if __name__ == '__main__': 175 test_frame_node() 176 test_touch_point() 177 test_procedure_step() 178 test_state_history() 179 test_event_node() 180 test_event_scope() 181 test_event_procedures() 182 test_event_tree() 183