1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ciimport { HeapDataInterface } from '../../src/js-heap/HeapDataInterface'; 16fb726d48Sopenharmony_ciimport { HeapNode } from '../../src/js-heap/model/DatabaseStruct'; 17fb726d48Sopenharmony_cijest.mock('../../src/js-heap/model/DatabaseStruct', () => {}); 18fb726d48Sopenharmony_ci// @ts-ignore 19fb726d48Sopenharmony_ciwindow.ResizeObserver = 20fb726d48Sopenharmony_ci window.ResizeObserver || 21fb726d48Sopenharmony_ci jest.fn().mockImplementation(() => ({ 22fb726d48Sopenharmony_ci disconnect: jest.fn(), 23fb726d48Sopenharmony_ci observe: jest.fn(), 24fb726d48Sopenharmony_ci unobserve: jest.fn(), 25fb726d48Sopenharmony_ci })); 26fb726d48Sopenharmony_cijest.mock('../../src/js-heap/utils/Utils', () => { 27fb726d48Sopenharmony_ci return { 28fb726d48Sopenharmony_ci HeapNodeToConstructorItem: (node: HeapNode) => {}, 29fb726d48Sopenharmony_ci }; 30fb726d48Sopenharmony_ci}); 31fb726d48Sopenharmony_cijest.mock('../../src/js-heap/model/DatabaseStruct', () => {}); 32fb726d48Sopenharmony_ci 33fb726d48Sopenharmony_cidescribe('HeapDataInterface Test', () => { 34fb726d48Sopenharmony_ci let data = { 35fb726d48Sopenharmony_ci end_ts: 88473497504466, 36fb726d48Sopenharmony_ci id: 3, 37fb726d48Sopenharmony_ci isParseSuccess: true, 38fb726d48Sopenharmony_ci name: 'Test', 39fb726d48Sopenharmony_ci path: '', 40fb726d48Sopenharmony_ci pid: 4243, 41fb726d48Sopenharmony_ci tart_ts: 88473061693464, 42fb726d48Sopenharmony_ci type: 3, 43fb726d48Sopenharmony_ci heapLoader: { 44fb726d48Sopenharmony_ci rootNode: { 45fb726d48Sopenharmony_ci detachedness: 3, 46fb726d48Sopenharmony_ci displayName: '', 47fb726d48Sopenharmony_ci distance: 100000000, 48fb726d48Sopenharmony_ci edgeCount: 35375, 49fb726d48Sopenharmony_ci fileId: 30, 50fb726d48Sopenharmony_ci firstEdgeIndex: 0, 51fb726d48Sopenharmony_ci flag: 0, 52fb726d48Sopenharmony_ci id: 1, 53fb726d48Sopenharmony_ci name: 'Test', 54fb726d48Sopenharmony_ci nodeIndex: 30, 55fb726d48Sopenharmony_ci nodeOldIndex: 0, 56fb726d48Sopenharmony_ci retainedSize: 1838167, 57fb726d48Sopenharmony_ci retainsCount: 0, 58fb726d48Sopenharmony_ci retainsEdgeIdx: [0], 59fb726d48Sopenharmony_ci retainsNodeIdx: [0], 60fb726d48Sopenharmony_ci selfSize: 30, 61fb726d48Sopenharmony_ci traceNodeId: 0, 62fb726d48Sopenharmony_ci type: 9, 63fb726d48Sopenharmony_ci edges: [ 64fb726d48Sopenharmony_ci { 65fb726d48Sopenharmony_ci edgeIndex: 2, 66fb726d48Sopenharmony_ci edgeOldIndex: 2, 67fb726d48Sopenharmony_ci fromNodeId: 4, 68fb726d48Sopenharmony_ci nameOrIndex: '-test-', 69fb726d48Sopenharmony_ci nodeId: 1523400, 70fb726d48Sopenharmony_ci retainEdge: [], 71fb726d48Sopenharmony_ci retainsNode: [], 72fb726d48Sopenharmony_ci toNodeId: 44500, 73fb726d48Sopenharmony_ci type: 6, 74fb726d48Sopenharmony_ci }, 75fb726d48Sopenharmony_ci { 76fb726d48Sopenharmony_ci edgeIndex: 6, 77fb726d48Sopenharmony_ci edgeOldIndex: 3, 78fb726d48Sopenharmony_ci fromNodeId: 1, 79fb726d48Sopenharmony_ci nameOrIndex: '-test-', 80fb726d48Sopenharmony_ci nodeId: 233330, 81fb726d48Sopenharmony_ci retainEdge: [], 82fb726d48Sopenharmony_ci retainsNode: [], 83fb726d48Sopenharmony_ci toNodeId: 32405, 84fb726d48Sopenharmony_ci type: 5, 85fb726d48Sopenharmony_ci }, 86fb726d48Sopenharmony_ci ], 87fb726d48Sopenharmony_ci }, 88fb726d48Sopenharmony_ci }, 89fb726d48Sopenharmony_ci snapshotStruct: { 90fb726d48Sopenharmony_ci traceNodes: [], 91fb726d48Sopenharmony_ci nodeMap: new Map(), 92fb726d48Sopenharmony_ci nodeCount: 1, 93fb726d48Sopenharmony_ci edges: [ 94fb726d48Sopenharmony_ci { 95fb726d48Sopenharmony_ci edgeIndex: 22, 96fb726d48Sopenharmony_ci edgeOldIndex: 32, 97fb726d48Sopenharmony_ci fromNodeId: 111, 98fb726d48Sopenharmony_ci nameOrIndex: '-test-', 99fb726d48Sopenharmony_ci nodeId: 13331, 100fb726d48Sopenharmony_ci retainEdge: [], 101fb726d48Sopenharmony_ci retainsNode: [], 102fb726d48Sopenharmony_ci toNodeId: 133, 103fb726d48Sopenharmony_ci type: 32, 104fb726d48Sopenharmony_ci }, 105fb726d48Sopenharmony_ci { 106fb726d48Sopenharmony_ci edgeIndex: 32, 107fb726d48Sopenharmony_ci edgeOldIndex: 231, 108fb726d48Sopenharmony_ci fromNodeId: 231, 109fb726d48Sopenharmony_ci nameOrIndex: '-test-', 110fb726d48Sopenharmony_ci nodeId: 42321, 111fb726d48Sopenharmony_ci retainEdge: [], 112fb726d48Sopenharmony_ci retainsNode: [], 113fb726d48Sopenharmony_ci toNodeId: 21201, 114fb726d48Sopenharmony_ci type: 95, 115fb726d48Sopenharmony_ci }, 116fb726d48Sopenharmony_ci ], 117fb726d48Sopenharmony_ci samples: [], 118fb726d48Sopenharmony_ci }, 119fb726d48Sopenharmony_ci }; 120fb726d48Sopenharmony_ci it('HeapDataInterface01', () => { 121fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 122fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 123fb726d48Sopenharmony_ci expect(heapDataInterface.getClassesListForSummary(1, 0, 0).length).toBe(0); 124fb726d48Sopenharmony_ci }); 125fb726d48Sopenharmony_ci it('HeapDataInterface02', () => { 126fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 127fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 128fb726d48Sopenharmony_ci expect(heapDataInterface.setFileId(1)).toBeFalsy(); 129fb726d48Sopenharmony_ci }); 130fb726d48Sopenharmony_ci it('HeapDataInterface03', () => { 131fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 132fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 133fb726d48Sopenharmony_ci expect(heapDataInterface.setPraseListener({})).toBeFalsy(); 134fb726d48Sopenharmony_ci }); 135fb726d48Sopenharmony_ci it('HeapDataInterface04', () => { 136fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 137fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 138fb726d48Sopenharmony_ci expect(heapDataInterface.getClassesListForSummary(1, 1, 1)).not.toBeUndefined(); 139fb726d48Sopenharmony_ci }); 140fb726d48Sopenharmony_ci it('HeapDataInterface05', () => { 141fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 142fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 143fb726d48Sopenharmony_ci expect(heapDataInterface.getClassListForComparison(1, 2)).toEqual([]); 144fb726d48Sopenharmony_ci }); 145fb726d48Sopenharmony_ci it('HeapDataInterface06', () => { 146fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 147fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 148fb726d48Sopenharmony_ci expect(heapDataInterface.getParentFunction({})).toBeUndefined(); 149fb726d48Sopenharmony_ci }); 150fb726d48Sopenharmony_ci it('HeapDataInterface07', () => { 151fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 152fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 153fb726d48Sopenharmony_ci expect(heapDataInterface.getNextForConstructor({})).not.toBeUndefined(); 154fb726d48Sopenharmony_ci }); 155fb726d48Sopenharmony_ci it('HeapDataInterface08', () => { 156fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 157fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 158fb726d48Sopenharmony_ci expect(heapDataInterface.getNextForComparison({})).not.toBeUndefined(); 159fb726d48Sopenharmony_ci }); 160fb726d48Sopenharmony_ci it('HeapDataInterface09', () => { 161fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 162fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 163fb726d48Sopenharmony_ci expect(heapDataInterface.getRetains({})).not.toBeUndefined(); 164fb726d48Sopenharmony_ci }); 165fb726d48Sopenharmony_ci it('HeapDataInterface10', async () => { 166fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 167fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 168fb726d48Sopenharmony_ci expect(await heapDataInterface.parseData([])).toBeUndefined(); 169fb726d48Sopenharmony_ci }); 170fb726d48Sopenharmony_ci it('HeapDataInterface11', () => { 171fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 172fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 173fb726d48Sopenharmony_ci expect(heapDataInterface.getFileStructs().length).toBe(1); 174fb726d48Sopenharmony_ci }); 175fb726d48Sopenharmony_ci it('HeapDataInterface12', () => { 176fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 177fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 178fb726d48Sopenharmony_ci expect(heapDataInterface.getSamples(1)).toStrictEqual([]); 179fb726d48Sopenharmony_ci }); 180fb726d48Sopenharmony_ci it('HeapDataInterface13', () => { 181fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 182fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 183fb726d48Sopenharmony_ci let node = { 184fb726d48Sopenharmony_ci fileId:1, 185fb726d48Sopenharmony_ci type:0, 186fb726d48Sopenharmony_ci traceNodeId:1 187fb726d48Sopenharmony_ci } 188fb726d48Sopenharmony_ci expect(heapDataInterface.getAllocationStackData(node)).toStrictEqual([]); 189fb726d48Sopenharmony_ci }); 190fb726d48Sopenharmony_ci it('HeapDataInterface14', () => { 191fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 192fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 193fb726d48Sopenharmony_ci expect(heapDataInterface.getMinNodeId(1)).toBeUndefined(); 194fb726d48Sopenharmony_ci }); 195fb726d48Sopenharmony_ci it('HeapDataInterface15', () => { 196fb726d48Sopenharmony_ci let heapDataInterface = new HeapDataInterface(); 197fb726d48Sopenharmony_ci heapDataInterface.fileStructs = [data]; 198fb726d48Sopenharmony_ci expect(heapDataInterface.getMaxNodeId(1)).toBeUndefined(); 199fb726d48Sopenharmony_ci }); 200fb726d48Sopenharmony_ci}); 201