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 16// @ts-ignore 17import {TabPaneSmapsStatistics} from "../../../../../../dist/trace/component/trace/sheet/smaps/TabPaneSmapsStatistics.js" 18// @ts-ignore 19import {Smaps, SmapsTreeObj} from "../../../../../../dist/trace/bean/SmapsStruct.js"; 20 21const sqlit = require("../../../../../../dist/trace/database/SqlLite.js") 22jest.mock("../../../../../../dist/trace/database/SqlLite.js"); 23 24window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(() => ({ 25 disconnect: jest.fn(), 26 observe: jest.fn(), 27 unobserve: jest.fn(), 28})) 29 30describe('TabPaneSmapsStatistics Test', () => { 31 let MockgetTabSmapsMaxRss = sqlit.getTabSmapsMaxRss; 32 MockgetTabSmapsMaxRss.mockResolvedValue([{ 33 startNS: 0, max_value: 100 34 }]) 35 let smaps = new Smaps() 36 smaps.tsNS = -1; 37 smaps.start_addr = "aaaaa"; 38 smaps.end_addr = "bbbbb"; 39 smaps.permission = "dddd"; 40 smaps.path = "/asdasdas"; 41 smaps.size = 0; 42 smaps.rss = 0; 43 smaps.pss = 0; 44 smaps.reside = 0; 45 smaps.dirty = 0; 46 smaps.swapper = 0; 47 smaps.address = "aaaaa-bbbbb"; 48 smaps.type = "Dta"; 49 smaps.dirtyStr = "1212"; 50 smaps.swapperStr = "222"; 51 smaps.rssStr = "333"; 52 smaps.pssStr = "444"; 53 smaps.sizeStr = "555"; 54 smaps.resideStr = "666"; 55 smaps.pss = 2 56 let MockgetTabSmapsData = sqlit.getTabSmapsData; 57 MockgetTabSmapsData.mockResolvedValue([smaps]) 58 59 let tabPaneSmapsStatistics = new TabPaneSmapsStatistics(); 60 let dataTree: SmapsTreeObj = new SmapsTreeObj("DATA", "", "DATA"); 61 62 63 it('TabPaneSmapsStatisticsTest01', () => { 64 tabPaneSmapsStatistics.handleSmapsTreeObj(dataTree, 2); 65 expect(dataTree.rsspro).toBe(0); 66 }); 67 68 it('TabPaneSmapsStatisticsTest02', () => { 69 tabPaneSmapsStatistics.handleAllDataTree(new Smaps(), 0, "All", dataTree, 3); 70 expect(dataTree.children.length).toBe(1); 71 }); 72 73 it('TabPaneSmapsStatisticsTest03', () => { 74 tabPaneSmapsStatistics.handleTree(smaps, 0, "TEXT", dataTree, 4); 75 expect(dataTree.pss).toBe(2); 76 }); 77 78 it('TabPaneSmapsStatisticsTest04', () => { 79 let select = { 80 leftNs: 0, 81 rightNs: 500, 82 smapsType: [0, 1, 2] 83 } 84 tabPaneSmapsStatistics.data = select 85 expect(tabPaneSmapsStatistics.data = select).toBeTruthy() 86 }); 87})