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 { threadPool } from '../../../../src/trace/database/SqlLite';
17import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
18import {
19  nativeMemoryChartDataCacheSender,
20  nativeMemoryChartDataSender
21} from '../../../../src/trace/database/data-trafic/NativeMemoryDataSender';
22jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
23  return {};
24});
25jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => {});
26jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
27  return {};
28});
29describe('NativeMemoryDataSender Test',()=>{
30  let NativeMemoryData =  {
31    startTime: 3384,
32    dur: 369,
33    heapsize: 173,
34    density: 193,
35    maxHeapSize: 58,
36    maxDensity: 4993,
37    minHeapSize: 0,
38    minDensity: 0,
39    frame: {
40      x: 17,
41      y: 5,
42      width: 2,
43      height: 30
44    }
45  }
46  it('NativeMemoryDataSenderTest01 ', function () {
47    threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => {
48      callback(NativeMemoryData, 1, true);
49    });
50    let nativeMemoryChartDataTraceRow = TraceRow.skeleton<any>();
51    let setting = {
52      eventType: 0,
53      ipid: 1,
54      model: "native_hook",
55      drawType: 0
56    }
57    nativeMemoryChartDataSender(nativeMemoryChartDataTraceRow,setting).then(res => {
58      expect(res).toHaveLength(1);
59    });
60  });
61  it('NativeMemoryDataSenderTest02 ', function () {
62    threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => {
63      callback(NativeMemoryData, 1, true);
64    });
65    let processes = [1];
66    let model = 'native_hook';
67    nativeMemoryChartDataCacheSender(processes,model).then(res => {
68      expect(res).toHaveLength(2);
69    });
70  });
71})