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