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 */ 15import { HeapDataInterface } from '../../src/js-heap/HeapDataInterface'; 16import { HeapNode } from '../../src/js-heap/model/DatabaseStruct'; 17jest.mock('../../src/js-heap/model/DatabaseStruct', () => {}); 18// @ts-ignore 19window.ResizeObserver = 20 window.ResizeObserver || 21 jest.fn().mockImplementation(() => ({ 22 disconnect: jest.fn(), 23 observe: jest.fn(), 24 unobserve: jest.fn(), 25 })); 26jest.mock('../../src/js-heap/utils/Utils', () => { 27 return { 28 HeapNodeToConstructorItem: (node: HeapNode) => {}, 29 }; 30}); 31jest.mock('../../src/js-heap/model/DatabaseStruct', () => {}); 32 33describe('HeapDataInterface Test', () => { 34 let data = { 35 end_ts: 88473497504466, 36 id: 3, 37 isParseSuccess: true, 38 name: 'Test', 39 path: '', 40 pid: 4243, 41 tart_ts: 88473061693464, 42 type: 3, 43 heapLoader: { 44 rootNode: { 45 detachedness: 3, 46 displayName: '', 47 distance: 100000000, 48 edgeCount: 35375, 49 fileId: 30, 50 firstEdgeIndex: 0, 51 flag: 0, 52 id: 1, 53 name: 'Test', 54 nodeIndex: 30, 55 nodeOldIndex: 0, 56 retainedSize: 1838167, 57 retainsCount: 0, 58 retainsEdgeIdx: [0], 59 retainsNodeIdx: [0], 60 selfSize: 30, 61 traceNodeId: 0, 62 type: 9, 63 edges: [ 64 { 65 edgeIndex: 2, 66 edgeOldIndex: 2, 67 fromNodeId: 4, 68 nameOrIndex: '-test-', 69 nodeId: 1523400, 70 retainEdge: [], 71 retainsNode: [], 72 toNodeId: 44500, 73 type: 6, 74 }, 75 { 76 edgeIndex: 6, 77 edgeOldIndex: 3, 78 fromNodeId: 1, 79 nameOrIndex: '-test-', 80 nodeId: 233330, 81 retainEdge: [], 82 retainsNode: [], 83 toNodeId: 32405, 84 type: 5, 85 }, 86 ], 87 }, 88 }, 89 snapshotStruct: { 90 traceNodes: [], 91 nodeMap: new Map(), 92 nodeCount: 1, 93 edges: [ 94 { 95 edgeIndex: 22, 96 edgeOldIndex: 32, 97 fromNodeId: 111, 98 nameOrIndex: '-test-', 99 nodeId: 13331, 100 retainEdge: [], 101 retainsNode: [], 102 toNodeId: 133, 103 type: 32, 104 }, 105 { 106 edgeIndex: 32, 107 edgeOldIndex: 231, 108 fromNodeId: 231, 109 nameOrIndex: '-test-', 110 nodeId: 42321, 111 retainEdge: [], 112 retainsNode: [], 113 toNodeId: 21201, 114 type: 95, 115 }, 116 ], 117 samples: [], 118 }, 119 }; 120 it('HeapDataInterface01', () => { 121 let heapDataInterface = new HeapDataInterface(); 122 heapDataInterface.fileStructs = [data]; 123 expect(heapDataInterface.getClassesListForSummary(1, 0, 0).length).toBe(0); 124 }); 125 it('HeapDataInterface02', () => { 126 let heapDataInterface = new HeapDataInterface(); 127 heapDataInterface.fileStructs = [data]; 128 expect(heapDataInterface.setFileId(1)).toBeFalsy(); 129 }); 130 it('HeapDataInterface03', () => { 131 let heapDataInterface = new HeapDataInterface(); 132 heapDataInterface.fileStructs = [data]; 133 expect(heapDataInterface.setPraseListener({})).toBeFalsy(); 134 }); 135 it('HeapDataInterface04', () => { 136 let heapDataInterface = new HeapDataInterface(); 137 heapDataInterface.fileStructs = [data]; 138 expect(heapDataInterface.getClassesListForSummary(1, 1, 1)).not.toBeUndefined(); 139 }); 140 it('HeapDataInterface05', () => { 141 let heapDataInterface = new HeapDataInterface(); 142 heapDataInterface.fileStructs = [data]; 143 expect(heapDataInterface.getClassListForComparison(1, 2)).toEqual([]); 144 }); 145 it('HeapDataInterface06', () => { 146 let heapDataInterface = new HeapDataInterface(); 147 heapDataInterface.fileStructs = [data]; 148 expect(heapDataInterface.getParentFunction({})).toBeUndefined(); 149 }); 150 it('HeapDataInterface07', () => { 151 let heapDataInterface = new HeapDataInterface(); 152 heapDataInterface.fileStructs = [data]; 153 expect(heapDataInterface.getNextForConstructor({})).not.toBeUndefined(); 154 }); 155 it('HeapDataInterface08', () => { 156 let heapDataInterface = new HeapDataInterface(); 157 heapDataInterface.fileStructs = [data]; 158 expect(heapDataInterface.getNextForComparison({})).not.toBeUndefined(); 159 }); 160 it('HeapDataInterface09', () => { 161 let heapDataInterface = new HeapDataInterface(); 162 heapDataInterface.fileStructs = [data]; 163 expect(heapDataInterface.getRetains({})).not.toBeUndefined(); 164 }); 165 it('HeapDataInterface10', async () => { 166 let heapDataInterface = new HeapDataInterface(); 167 heapDataInterface.fileStructs = [data]; 168 expect(await heapDataInterface.parseData([])).toBeUndefined(); 169 }); 170 it('HeapDataInterface11', () => { 171 let heapDataInterface = new HeapDataInterface(); 172 heapDataInterface.fileStructs = [data]; 173 expect(heapDataInterface.getFileStructs().length).toBe(1); 174 }); 175 it('HeapDataInterface12', () => { 176 let heapDataInterface = new HeapDataInterface(); 177 heapDataInterface.fileStructs = [data]; 178 expect(heapDataInterface.getSamples(1)).toStrictEqual([]); 179 }); 180 it('HeapDataInterface13', () => { 181 let heapDataInterface = new HeapDataInterface(); 182 heapDataInterface.fileStructs = [data]; 183 let node = { 184 fileId:1, 185 type:0, 186 traceNodeId:1 187 } 188 expect(heapDataInterface.getAllocationStackData(node)).toStrictEqual([]); 189 }); 190 it('HeapDataInterface14', () => { 191 let heapDataInterface = new HeapDataInterface(); 192 heapDataInterface.fileStructs = [data]; 193 expect(heapDataInterface.getMinNodeId(1)).toBeUndefined(); 194 }); 195 it('HeapDataInterface15', () => { 196 let heapDataInterface = new HeapDataInterface(); 197 heapDataInterface.fileStructs = [data]; 198 expect(heapDataInterface.getMaxNodeId(1)).toBeUndefined(); 199 }); 200}); 201