1bc03f14fSopenharmony_ci/* 2bc03f14fSopenharmony_ci * Copyright (C) 2022-2023 Huawei Device Co., Ltd. 3bc03f14fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the 'License'); 4bc03f14fSopenharmony_ci * you may not use this file except in compliance with the License. 5bc03f14fSopenharmony_ci * You may obtain a copy of the License at 6bc03f14fSopenharmony_ci * 7bc03f14fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc03f14fSopenharmony_ci * 9bc03f14fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc03f14fSopenharmony_ci * distributed under the License is distributed on an 'AS IS' BASIS, 11bc03f14fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc03f14fSopenharmony_ci * See the License for the specific language governing permissions and 13bc03f14fSopenharmony_ci * limitations under the License. 14bc03f14fSopenharmony_ci */ 15bc03f14fSopenharmony_ci// @ts-nocheck 16bc03f14fSopenharmony_ciimport { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; 17bc03f14fSopenharmony_ciimport pasteboard from '@ohos.pasteboard'; 18bc03f14fSopenharmony_ciimport image from '@ohos.multimedia.image'; 19bc03f14fSopenharmony_ci 20bc03f14fSopenharmony_cidescribe('PasteBoardPerfJSTest', function () { 21bc03f14fSopenharmony_ci beforeAll(async function () { 22bc03f14fSopenharmony_ci console.info('beforeAll'); 23bc03f14fSopenharmony_ci }); 24bc03f14fSopenharmony_ci 25bc03f14fSopenharmony_ci afterAll(async function () { 26bc03f14fSopenharmony_ci console.info('afterAll'); 27bc03f14fSopenharmony_ci }); 28bc03f14fSopenharmony_ci 29bc03f14fSopenharmony_ci const BASE_CONUT = 100; 30bc03f14fSopenharmony_ci const htmlText = '<html><head></head><body>Hello!</body></html>'; 31bc03f14fSopenharmony_ci 32bc03f14fSopenharmony_ci /** 33bc03f14fSopenharmony_ci * @tc.name clearData_Callback_performance_test_001 34bc03f14fSopenharmony_ci * @tc.desc clearData interface Callback performance test 35bc03f14fSopenharmony_ci * @tc.type PERF 36bc03f14fSopenharmony_ci * @tc.require I5YP4X 37bc03f14fSopenharmony_ci */ 38bc03f14fSopenharmony_ci it('clearData_Callback_performance_test_001', 0, async function (done) { 39bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 40bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 41bc03f14fSopenharmony_ci clearDataCallbackPerfTest(0); 42bc03f14fSopenharmony_ci 43bc03f14fSopenharmony_ci function clearDataCallbackPerfTest(index) { 44bc03f14fSopenharmony_ci systemPasteboard.clearData(() => { 45bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 46bc03f14fSopenharmony_ci clearDataCallbackPerfTest(index + 1); 47bc03f14fSopenharmony_ci } else { 48bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'clearData_Callback_performance_test_001 averageTime:'); 49bc03f14fSopenharmony_ci done(); 50bc03f14fSopenharmony_ci } 51bc03f14fSopenharmony_ci }); 52bc03f14fSopenharmony_ci } 53bc03f14fSopenharmony_ci }); 54bc03f14fSopenharmony_ci 55bc03f14fSopenharmony_ci /** 56bc03f14fSopenharmony_ci * @tc.name clear_Callback_performance_test_001 57bc03f14fSopenharmony_ci * @tc.desc clear interface Callback performance test 58bc03f14fSopenharmony_ci * @tc.type PERF 59bc03f14fSopenharmony_ci * @tc.require I5YP4X 60bc03f14fSopenharmony_ci */ 61bc03f14fSopenharmony_ci it('clear_Callback_performance_test_001', 0, async function (done) { 62bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 63bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 64bc03f14fSopenharmony_ci clearCallbackPerfTest(0); 65bc03f14fSopenharmony_ci 66bc03f14fSopenharmony_ci function clearCallbackPerfTest(index) { 67bc03f14fSopenharmony_ci systemPasteboard.clear(() => { 68bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 69bc03f14fSopenharmony_ci clearCallbackPerfTest(index + 1); 70bc03f14fSopenharmony_ci } else { 71bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'clear_Callback_performance_test_001 averageTime:'); 72bc03f14fSopenharmony_ci done(); 73bc03f14fSopenharmony_ci } 74bc03f14fSopenharmony_ci }); 75bc03f14fSopenharmony_ci } 76bc03f14fSopenharmony_ci }); 77bc03f14fSopenharmony_ci 78bc03f14fSopenharmony_ci /** 79bc03f14fSopenharmony_ci * @tc.name setData_Callback_performance_test_001 80bc03f14fSopenharmony_ci * @tc.desc setData interface Callback performance test 81bc03f14fSopenharmony_ci * @tc.type PERF 82bc03f14fSopenharmony_ci * @tc.require I5YP4X 83bc03f14fSopenharmony_ci */ 84bc03f14fSopenharmony_ci it('setData_Callback_performance_test_001', 0, async function (done) { 85bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 86bc03f14fSopenharmony_ci let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 87bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 88bc03f14fSopenharmony_ci setDataCallbackPerfTest(0); 89bc03f14fSopenharmony_ci 90bc03f14fSopenharmony_ci function setDataCallbackPerfTest(index) { 91bc03f14fSopenharmony_ci systemPasteboard.setData(pasteData, () => { 92bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 93bc03f14fSopenharmony_ci setDataCallbackPerfTest(index + 1); 94bc03f14fSopenharmony_ci } else { 95bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'setData_Callback_performance_test_001 averageTime:'); 96bc03f14fSopenharmony_ci done(); 97bc03f14fSopenharmony_ci } 98bc03f14fSopenharmony_ci }); 99bc03f14fSopenharmony_ci } 100bc03f14fSopenharmony_ci }); 101bc03f14fSopenharmony_ci 102bc03f14fSopenharmony_ci /** 103bc03f14fSopenharmony_ci * @tc.name setPasteData_Callback_performance_test_001 104bc03f14fSopenharmony_ci * @tc.desc setPasteData interface Callback performance test 105bc03f14fSopenharmony_ci * @tc.type PERF 106bc03f14fSopenharmony_ci * @tc.require I5YP4X 107bc03f14fSopenharmony_ci */ 108bc03f14fSopenharmony_ci it('setPasteData_Callback_performance_test_001', 0, async function (done) { 109bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 110bc03f14fSopenharmony_ci let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 111bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 112bc03f14fSopenharmony_ci setPasteDataCallbackPerfTest(0); 113bc03f14fSopenharmony_ci 114bc03f14fSopenharmony_ci function setPasteDataCallbackPerfTest(index) { 115bc03f14fSopenharmony_ci systemPasteboard.setPasteData(pasteData, () => { 116bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 117bc03f14fSopenharmony_ci setPasteDataCallbackPerfTest(index + 1); 118bc03f14fSopenharmony_ci } else { 119bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'setPasteData_Callback_performance_test_001 averageTime:'); 120bc03f14fSopenharmony_ci done(); 121bc03f14fSopenharmony_ci } 122bc03f14fSopenharmony_ci }); 123bc03f14fSopenharmony_ci } 124bc03f14fSopenharmony_ci }); 125bc03f14fSopenharmony_ci 126bc03f14fSopenharmony_ci /** 127bc03f14fSopenharmony_ci * @tc.name hasData_Callback_performance_test_001 128bc03f14fSopenharmony_ci * @tc.desc hasData interface Callback performance test 129bc03f14fSopenharmony_ci * @tc.type PERF 130bc03f14fSopenharmony_ci * @tc.require I5YP4X 131bc03f14fSopenharmony_ci */ 132bc03f14fSopenharmony_ci it('hasData_Callback_performance_test_001', 0, async function (done) { 133bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 134bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 135bc03f14fSopenharmony_ci hasDataCallbackPerfTest(0); 136bc03f14fSopenharmony_ci 137bc03f14fSopenharmony_ci function hasDataCallbackPerfTest(index) { 138bc03f14fSopenharmony_ci systemPasteboard.hasData(() => { 139bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 140bc03f14fSopenharmony_ci hasDataCallbackPerfTest(index + 1); 141bc03f14fSopenharmony_ci } else { 142bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'hasData_Callback_performance_test_001 averageTime:'); 143bc03f14fSopenharmony_ci done(); 144bc03f14fSopenharmony_ci } 145bc03f14fSopenharmony_ci }); 146bc03f14fSopenharmony_ci } 147bc03f14fSopenharmony_ci }); 148bc03f14fSopenharmony_ci 149bc03f14fSopenharmony_ci /** 150bc03f14fSopenharmony_ci * @tc.name hasPasteData_Callback_performance_test_001 151bc03f14fSopenharmony_ci * @tc.desc hasPasteData interface Callback performance test 152bc03f14fSopenharmony_ci * @tc.type PERF 153bc03f14fSopenharmony_ci * @tc.require I5YP4X 154bc03f14fSopenharmony_ci */ 155bc03f14fSopenharmony_ci it('hasPasteData_Callback_performance_test_001', 0, async function (done) { 156bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 157bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 158bc03f14fSopenharmony_ci hasPasteDataCallbackPerfTest(0); 159bc03f14fSopenharmony_ci 160bc03f14fSopenharmony_ci function hasPasteDataCallbackPerfTest(index) { 161bc03f14fSopenharmony_ci systemPasteboard.hasPasteData(() => { 162bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 163bc03f14fSopenharmony_ci hasPasteDataCallbackPerfTest(index + 1); 164bc03f14fSopenharmony_ci } else { 165bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'hasPasteData_Callback_performance_test_001 averageTime:'); 166bc03f14fSopenharmony_ci done(); 167bc03f14fSopenharmony_ci } 168bc03f14fSopenharmony_ci }); 169bc03f14fSopenharmony_ci } 170bc03f14fSopenharmony_ci }); 171bc03f14fSopenharmony_ci 172bc03f14fSopenharmony_ci /** 173bc03f14fSopenharmony_ci * @tc.name getData_Callback_performance_test_001 174bc03f14fSopenharmony_ci * @tc.desc getData interface Callback performance test 175bc03f14fSopenharmony_ci * @tc.type PERF 176bc03f14fSopenharmony_ci * @tc.require I5YP4X 177bc03f14fSopenharmony_ci */ 178bc03f14fSopenharmony_ci it('getData_Callback_performance_test_001', 0, async function (done) { 179bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 180bc03f14fSopenharmony_ci let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 181bc03f14fSopenharmony_ci await systemPasteboard.clearData(); 182bc03f14fSopenharmony_ci await systemPasteboard.setData(pasteData); 183bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 184bc03f14fSopenharmony_ci getDataCallbackPerfTest(0); 185bc03f14fSopenharmony_ci 186bc03f14fSopenharmony_ci function getDataCallbackPerfTest(index) { 187bc03f14fSopenharmony_ci systemPasteboard.getPasteData(() => { 188bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 189bc03f14fSopenharmony_ci getDataCallbackPerfTest(index + 1); 190bc03f14fSopenharmony_ci } else { 191bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'getData_Callback_performance_test_001 averageTime:'); 192bc03f14fSopenharmony_ci done(); 193bc03f14fSopenharmony_ci } 194bc03f14fSopenharmony_ci }); 195bc03f14fSopenharmony_ci } 196bc03f14fSopenharmony_ci }); 197bc03f14fSopenharmony_ci 198bc03f14fSopenharmony_ci /** 199bc03f14fSopenharmony_ci * @tc.name getPasteData_Callback_performance_test_001 200bc03f14fSopenharmony_ci * @tc.desc getPasteData interface Callback performance test 201bc03f14fSopenharmony_ci * @tc.type PERF 202bc03f14fSopenharmony_ci * @tc.require I5YP4X 203bc03f14fSopenharmony_ci */ 204bc03f14fSopenharmony_ci it('getPasteData_Callback_performance_test_001', 0, async function (done) { 205bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 206bc03f14fSopenharmony_ci let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 207bc03f14fSopenharmony_ci await systemPasteboard.clearData(); 208bc03f14fSopenharmony_ci await systemPasteboard.setData(pasteData); 209bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 210bc03f14fSopenharmony_ci getPasteDataCallbackPerfTest(0); 211bc03f14fSopenharmony_ci 212bc03f14fSopenharmony_ci function getPasteDataCallbackPerfTest(index) { 213bc03f14fSopenharmony_ci systemPasteboard.getPasteData(() => { 214bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 215bc03f14fSopenharmony_ci getPasteDataCallbackPerfTest(index + 1); 216bc03f14fSopenharmony_ci } else { 217bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'getPasteData_Callback_performance_test_001 averageTime:'); 218bc03f14fSopenharmony_ci done(); 219bc03f14fSopenharmony_ci } 220bc03f14fSopenharmony_ci }); 221bc03f14fSopenharmony_ci } 222bc03f14fSopenharmony_ci }); 223bc03f14fSopenharmony_ci 224bc03f14fSopenharmony_ci /** 225bc03f14fSopenharmony_ci * @tc.name convertToText_Callback_performance_test_001 226bc03f14fSopenharmony_ci * @tc.desc convertToText interface Callback performance test 227bc03f14fSopenharmony_ci * @tc.type PERF 228bc03f14fSopenharmony_ci * @tc.require I5YP4X 229bc03f14fSopenharmony_ci */ 230bc03f14fSopenharmony_ci it('convertToText_Callback_performance_test_001', 0, async function (done) { 231bc03f14fSopenharmony_ci let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 232bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 233bc03f14fSopenharmony_ci convertToTextCallbackPerfTest(0); 234bc03f14fSopenharmony_ci 235bc03f14fSopenharmony_ci function convertToTextCallbackPerfTest(index) { 236bc03f14fSopenharmony_ci pasteDataRecord.convertToText(() => { 237bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 238bc03f14fSopenharmony_ci convertToTextCallbackPerfTest(index + 1); 239bc03f14fSopenharmony_ci } else { 240bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'convertToText_Callback_performance_test_001 averageTime:'); 241bc03f14fSopenharmony_ci done(); 242bc03f14fSopenharmony_ci } 243bc03f14fSopenharmony_ci }); 244bc03f14fSopenharmony_ci } 245bc03f14fSopenharmony_ci }); 246bc03f14fSopenharmony_ci 247bc03f14fSopenharmony_ci /** 248bc03f14fSopenharmony_ci * @tc.name convertToTextV9_Callback_performance_test_001 249bc03f14fSopenharmony_ci * @tc.desc convertToTextV9 interface Callback performance test 250bc03f14fSopenharmony_ci * @tc.type PERF 251bc03f14fSopenharmony_ci * @tc.require I5YP4X 252bc03f14fSopenharmony_ci */ 253bc03f14fSopenharmony_ci it('convertToTextV9_Callback_performance_test_001', 0, async function (done) { 254bc03f14fSopenharmony_ci let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 255bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 256bc03f14fSopenharmony_ci convertToTextV9CallbackPerfTest(0); 257bc03f14fSopenharmony_ci 258bc03f14fSopenharmony_ci function convertToTextV9CallbackPerfTest(index) { 259bc03f14fSopenharmony_ci pasteDataRecord.convertToTextV9(() => { 260bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 261bc03f14fSopenharmony_ci convertToTextV9CallbackPerfTest(index + 1); 262bc03f14fSopenharmony_ci } else { 263bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, 'convertToTextV9_Callback_performance_test_001 averageTime:'); 264bc03f14fSopenharmony_ci done(); 265bc03f14fSopenharmony_ci } 266bc03f14fSopenharmony_ci }); 267bc03f14fSopenharmony_ci } 268bc03f14fSopenharmony_ci }); 269bc03f14fSopenharmony_ci 270bc03f14fSopenharmony_ci function computeAverageTime(startTime, baseCount, message) { 271bc03f14fSopenharmony_ci let endTime = new Date().getTime(); 272bc03f14fSopenharmony_ci let averageTime = ((endTime - startTime) * 1000) / baseCount; 273bc03f14fSopenharmony_ci console.info(message + averageTime); 274bc03f14fSopenharmony_ci } 275bc03f14fSopenharmony_ci}); 276