1/* 2 * Copyright (c) 2021-2022 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 16import inputDevice from '@ohos.multimodalInput.inputDevice'; 17import inputMonitor from '@ohos.multimodalInput.inputMonitor'; 18import inputConsumer from '@ohos.multimodalInput.inputConsumer'; 19import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 20 21describe("apiPerformanceTest", function () { 22 23 beforeAll(function() { 24 // input testsuit setup step,setup invoked before all testcases 25 console.info('beforeAll caled') 26 }) 27 28 afterAll(function() { 29 // input testsuit teardown step,teardown invoked after all testcases 30 console.info('afterAll caled') 31 }) 32 33 beforeEach(function() { 34 // input testcase setup step,setup invoked before each testcases 35 console.info('beforeEach caled') 36 }) 37 38 afterEach(function() { 39 // input testcase teardown step,teardown invoked after each testcases 40 console.info('afterEach caled') 41 }) 42 43 /* 44 * @tc.name:MulJsTest001 45 * @tc.desc:JS API performance 46 * @tc.type: FUNC 47 * @tc.require:SR000GJO2D 48 */ 49 it("MulJsTest001", 0, function () { 50 console.info('----------------------MulJsTest001 start----------------------------'); 51 var start = new Date().getTime(); 52 for (var i = 1; i<=1000; i++) { 53 inputDevice.getDevice(1,(data,err)=>{ 54 }); 55 } 56 var end = new Date().getTime(); 57 var allTime = (end - start); 58 console.info("getDevice running totalTime:" + allTime + "ms"); 59 var time = (end-start)/1000; 60 console.info("getDevice running averageTime:" + time + "ms"); 61 }) 62 63 /* 64 * @tc.name:MulJsTest002 65 * @tc.desc:JS API performance 66 * @tc.type: FUNC 67 * @tc.require:AR000GJO2L 68 */ 69 it("MulJsTest002", 0, function () { 70 console.info('----------------------MulJsTest002 start----------------------------'); 71 var start = new Date().getTime(); 72 for (var i = 1; i<=1000; i++) { 73 inputDevice.getDeviceIds((data,err)=>{ 74 }); 75 } 76 var end = new Date().getTime(); 77 var allTime = (end - start); 78 console.info("getDeviceIds running totalTime:" + allTime + "ms"); 79 var time = (end-start)/1000; 80 console.info("getDeviceIds running averageTime:" + time + "ms"); 81 }) 82 83 /* 84 * @tc.name:MulJsTest003 85 * @tc.desc:JS API performance 86 * @tc.type: FUNC 87 * @tc.require:AR000GJO2L 88 */ 89 it("MulJsTest003", 0, function () { 90 console.info('----------------------MulJsTest003 start----------------------------'); 91 var start = new Date().getTime(); 92 for (var i = 1; i<=1000; i++) { 93 inputMonitor.on("touch", (touchEvent)=>{ 94 }); 95 } 96 var end = new Date().getTime(); 97 var allTime = (end - start); 98 console.info("inputMonitor_on running totalTime:" + allTime + "ms"); 99 var time = (end-start)/1000; 100 console.info("inputMonitor_on running averageTime:" + time + "ms"); 101 }) 102 103 /* 104 * @tc.name:MulJsTest004 105 * @tc.desc:JS API performance 106 * @tc.type: FUNC 107 * @tc.require:AR000GJO2L 108 */ 109 it("MulJsTest004", 0, function () { 110 console.info('----------------------MulJsTest004 start----------------------------'); 111 var start = new Date().getTime(); 112 for (var i = 1; i<=1000; i++) { 113 inputMonitor.off("touch", (touchEvent)=>{ 114 }); 115 } 116 var end = new Date().getTime(); 117 var allTime = (end - start); 118 console.info("inputMonitor_off running totalTime:" + allTime + "ms"); 119 var time = (end-start)/1000; 120 console.info("inputMonitor_off running averageTime:" + time + "ms"); 121 }) 122 123 /* 124 * @tc.name:MulJsTest005 125 * @tc.desc:JS API performance 126 * @tc.type: FUNC 127 * @tc.require:AR000GJO2L 128 */ 129 it("MulJsTest005", 0, function () { 130 console.info('----------------------MulJsTest005 start----------------------------'); 131 var start = new Date().getTime(); 132 for (var i = 1; i<=1000; i++) { 133 inputConsumer.on('key', {preKeys:[],'finalKey':22, 'isFinalKeyDown':true,'finalKeyDownDuration':0},(data,err)=>{ 134 }); 135 } 136 var end = new Date().getTime(); 137 var allTime = (end - start); 138 console.info("inputConsumer_on running totalTime:" + allTime + "ms"); 139 var time = (end-start)/1000; 140 console.info("inputConsumer_on running averageTime:" + time + "ms"); 141 }) 142 143 /* 144 * @tc.name:MulJsTest006 145 * @tc.desc:JS API performance 146 * @tc.type: FUNC 147 * @tc.require:AR000GJO2L 148 */ 149 it("MulJsTest006", 0, function () { 150 console.info('----------------------MulJsTest006 start----------------------------'); 151 var start = new Date().getTime(); 152 for (var i = 1; i<=1000; i++) { 153 inputConsumer.off('key', {preKeys:[],'finalKey':22, 'isFinalKeyDown':true,'finalKeyDownDuration':0},(data,err)=>{ 154 }); 155 } 156 var end = new Date().getTime(); 157 var allTime = (end - start); 158 console.info("inputConsumer_off running totalTime:" + allTime + "ms"); 159 var time = (end-start)/1000; 160 console.info("inputConsumer_off running averageTime:" + time + "ms"); 161 }) 162})