1/* 2 * Copyright (C) 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 { 17 logDataReceiver, 18 chartLogDataSql 19} from '../../../../src/trace/database/data-trafic/LogDataReceiver'; 20import { TraficEnum } from "../../../../src/trace/database/data-trafic/utils/QueryEnum"; 21 22describe('logDataReceiver Test', () => { 23 let data; 24 let proc; 25 26 beforeEach(() => { 27 data = { 28 params: { 29 trafic: TraficEnum.ProtoBuffer, 30 sharedArrayBuffers: { 31 id: new Uint16Array([1, 2, 3]), 32 }, 33 }, 34 }; 35 proc = jest.fn((sql) => [ 36 {logData: {id: 4, startTs: 4.4, pid: 40, tid: 400, dur: 40000, depth: 4}}, 37 {logData: {id: 5, startTs: 5.5, pid: 50, tid: 500, dur: 50000, depth: 5}}, 38 ]); 39 }); 40 it('logDataReceiverTest01', () => { 41 const args = { 42 recordStartNS: 1000, 43 endNS: 3000, 44 startNS: 2000, 45 width: 10 46 }; 47 expect(chartLogDataSql(args)).toBeTruthy(); 48 }); 49 it('logDataReceiverTest02', () => { 50 const mockPostMessage = jest.fn(); 51 global.postMessage = mockPostMessage; 52 logDataReceiver(data, proc); 53 expect(mockPostMessage).toHaveBeenCalledTimes(1); 54 }); 55});