1bc03f14fSopenharmony_ci/* 2bc03f14fSopenharmony_ci * Copyright (C) 2024 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 16bc03f14fSopenharmony_ciimport {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 17bc03f14fSopenharmony_ciimport pasteboard from '@ohos.pasteboard' 18bc03f14fSopenharmony_ciimport UDC from '@ohos.data.unifiedDataChannel'; 19bc03f14fSopenharmony_ci 20bc03f14fSopenharmony_civar sumGetUnifiedDataTime = 0; 21bc03f14fSopenharmony_civar plainTextData = new UDC.UnifiedData(); 22bc03f14fSopenharmony_civar date = new Date(); 23bc03f14fSopenharmony_ci 24bc03f14fSopenharmony_ciconst BASE_CONUT = 100; 25bc03f14fSopenharmony_ci 26bc03f14fSopenharmony_cidescribe('PasteBoardDelayPerfJSTest', function () { 27bc03f14fSopenharmony_ci beforeAll(async function () { 28bc03f14fSopenharmony_ci console.info('beforeAll'); 29bc03f14fSopenharmony_ci }) 30bc03f14fSopenharmony_ci 31bc03f14fSopenharmony_ci afterAll(async function () { 32bc03f14fSopenharmony_ci console.info('afterAll'); 33bc03f14fSopenharmony_ci }) 34bc03f14fSopenharmony_ci 35bc03f14fSopenharmony_ci function computeAverageTime(startTime, baseCount, message) { 36bc03f14fSopenharmony_ci let endTime = date.getTime(); 37bc03f14fSopenharmony_ci let averageTime = ((endTime - startTime) * 1000) / baseCount; 38bc03f14fSopenharmony_ci console.info(message + averageTime); 39bc03f14fSopenharmony_ci } 40bc03f14fSopenharmony_ci 41bc03f14fSopenharmony_ci function computeAverageGetTime(baseCount, message) { 42bc03f14fSopenharmony_ci let averageTime = (sumGetUnifiedDataTime * 1000) / baseCount; 43bc03f14fSopenharmony_ci console.info(message + averageTime); 44bc03f14fSopenharmony_ci } 45bc03f14fSopenharmony_ci 46bc03f14fSopenharmony_ci function getPlainTextData(dataType) { 47bc03f14fSopenharmony_ci let plainText = new UDC.PlainText(); 48bc03f14fSopenharmony_ci plainText.details = { 49bc03f14fSopenharmony_ci Key: 'plainText', 50bc03f14fSopenharmony_ci Value: 'plainText', 51bc03f14fSopenharmony_ci }; 52bc03f14fSopenharmony_ci plainText.textContent = 'textContent'; 53bc03f14fSopenharmony_ci plainText.abstract = 'abstract'; 54bc03f14fSopenharmony_ci plainTextData.addRecord(plainText); 55bc03f14fSopenharmony_ci return plainTextData; 56bc03f14fSopenharmony_ci } 57bc03f14fSopenharmony_ci 58bc03f14fSopenharmony_ci /** 59bc03f14fSopenharmony_ci * @tc.name setUnifiedData_delay_performance_test_001 60bc03f14fSopenharmony_ci * @tc.desc setUnifiedData delay interface performance test 61bc03f14fSopenharmony_ci * @tc.type PERFORMANCE 62bc03f14fSopenharmony_ci */ 63bc03f14fSopenharmony_ci it('setUnifiedData_delay_performance_test_001', 0, async function (done) { 64bc03f14fSopenharmony_ci console.info('setUnifiedData_delay_performance_test_001 begin'); 65bc03f14fSopenharmony_ci const systemPasteboard = pasteboard.getSystemPasteboard(); 66bc03f14fSopenharmony_ci let startTime = date.getTime(); 67bc03f14fSopenharmony_ci for (let index = 0; index < BASE_CONUT; ++index) { 68bc03f14fSopenharmony_ci plainTextData = new UDC.UnifiedData(); 69bc03f14fSopenharmony_ci plainTextData.properties.getDelayData = getPlainTextData; 70bc03f14fSopenharmony_ci await systemPasteboard.setUnifiedData(plainTextData); 71bc03f14fSopenharmony_ci } 72bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "setUnifiedData_delay_performance_test_001 averageTime:"); 73bc03f14fSopenharmony_ci done(); 74bc03f14fSopenharmony_ci console.info('setUnifiedData_delay_performance_test_001 end'); 75bc03f14fSopenharmony_ci }) 76bc03f14fSopenharmony_ci 77bc03f14fSopenharmony_ci /** 78bc03f14fSopenharmony_ci * @tc.name getUnifiedData_delay_performance_test_001 79bc03f14fSopenharmony_ci * @tc.desc getUnifiedData delay interface performance test 80bc03f14fSopenharmony_ci * @tc.type PERFORMANCE 81bc03f14fSopenharmony_ci */ 82bc03f14fSopenharmony_ci it('getUnifiedData_delay_performance_test_001', 0, async function (done) { 83bc03f14fSopenharmony_ci console.info('getUnifiedData_delay_performance_test_001 begin'); 84bc03f14fSopenharmony_ci const systemPasteboard = pasteboard.getSystemPasteboard(); 85bc03f14fSopenharmony_ci for (let index = 0; index < BASE_CONUT; ++index) { 86bc03f14fSopenharmony_ci plainTextData = new UDC.UnifiedData(); 87bc03f14fSopenharmony_ci plainTextData.properties.getDelayData = getPlainTextData; 88bc03f14fSopenharmony_ci await systemPasteboard.setUnifiedData(plainTextData); 89bc03f14fSopenharmony_ci let beginGetTime = date.getTime(); 90bc03f14fSopenharmony_ci let unifiedData = await systemPasteboard.getUnifiedData(); 91bc03f14fSopenharmony_ci let endGetTime = date.getTime(); 92bc03f14fSopenharmony_ci sumGetUnifiedDataTime += (endGetTime - beginGetTime); 93bc03f14fSopenharmony_ci } 94bc03f14fSopenharmony_ci computeAverageGetTime(BASE_CONUT, "getUnifiedData_delay_performance_test_001 averageTime:"); 95bc03f14fSopenharmony_ci done(); 96bc03f14fSopenharmony_ci console.info('getUnifiedData_delay_performance_test_001 end'); 97bc03f14fSopenharmony_ci }) 98bc03f14fSopenharmony_ci});