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 { SpSystemTrace } from '../../../../src/trace/component/SpSystemTrace'; 17import { SpNativeMemoryChart } from '../../../../src/trace/component/chart/SpNativeMemoryChart'; 18import { SpChartManager } from '../../../../src/trace/component/chart/SpChartManager'; 19const sqlit = require('../../../../src/trace/database/SqlLite'); 20jest.mock('../../../../src/trace/database/SqlLite'); 21window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 22const intersectionObserverMock = () => ({ 23 observe: () => null, 24}); 25// @ts-ignore 26window.ResizeObserver = window.ResizeObserver || 27 jest.fn().mockImplementation(() => ({ 28 disconnect: jest.fn(), 29 unobserve: jest.fn(), 30 observe: jest.fn(), 31 })); 32describe('SpNativeMemoryChart Test', () => { 33 let chartManager = new SpSystemTrace(); 34 let spNativeMemoryChart = new SpNativeMemoryChart(chartManager); 35 36 let queryNativeHookStatisticsCount = sqlit.queryNativeHookStatisticsCount; 37 queryNativeHookStatisticsCount.mockResolvedValue([ 38 { 39 num: 2, 40 }, 41 ]); 42 43 let queryNativeMemoryRealTime = sqlit.queryNativeMemoryRealTime; 44 queryNativeMemoryRealTime.mockResolvedValue([ 45 { 46 ts: 1502013097360370200, 47 clock_name: 'realtime', 48 }, 49 ]); 50 51 let queryBootTime = sqlit.queryBootTime; 52 queryBootTime.mockResolvedValue([ 53 { 54 ts: -557295431, 55 clock_name: 'boottime', 56 }, 57 ]); 58 59 let nativeHookProcess = sqlit.queryNativeHookProcess; 60 nativeHookProcess.mockResolvedValue([ 61 { 62 ipid: 0, 63 pid: 0, 64 name: 'name', 65 }, 66 ]); 67 68 let heapGroupByEvent = sqlit.queryHeapGroupByEvent; 69 heapGroupByEvent.mockResolvedValue([ 70 { 71 eventType: 'AllocEvent', 72 sumHeapSize: 10, 73 }, 74 ]); 75 76 it('SpNativeMemoryChart01', function () { 77 expect(spNativeMemoryChart.initChart()).toBeDefined(); 78 }); 79}); 80