• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {
18  TimestampConverterUtils,
19  timestampEqualityTester,
20} from 'common/time/test_utils';
21import {TraceBuilder} from 'test/unit/trace_builder';
22import {Trace} from './trace';
23
24describe('TraceEntry', () => {
25  let trace: Trace<string>;
26
27  beforeAll(() => {
28    jasmine.addCustomEqualityTester(timestampEqualityTester);
29    trace = new TraceBuilder<string>()
30      .setTimestamps([
31        TimestampConverterUtils.makeRealTimestamp(10n),
32        TimestampConverterUtils.makeRealTimestamp(11n),
33        TimestampConverterUtils.makeRealTimestamp(12n),
34        TimestampConverterUtils.makeRealTimestamp(13n),
35        TimestampConverterUtils.makeRealTimestamp(14n),
36        TimestampConverterUtils.makeRealTimestamp(15n),
37      ])
38      .setEntries([
39        'entry-0',
40        'entry-1',
41        'entry-2',
42        'entry-3',
43        'entry-4',
44        'entry-5',
45      ])
46      .setFrame(0, 0)
47      .setFrame(0, 1)
48      .setFrame(1, 1)
49      .setFrame(2, 1)
50      .setFrame(3, 2)
51      .setFrame(5, 4)
52      .build();
53  });
54
55  it('getFullTrace()', () => {
56    expect(trace.getEntry(0).getFullTrace()).toEqual(trace);
57    expect(trace.sliceEntries(0, 1).getEntry(0).getFullTrace()).toEqual(trace);
58  });
59
60  it('getIndex()', () => {
61    expect(trace.getEntry(0).getIndex()).toEqual(0);
62    expect(trace.sliceEntries(2, 4).getEntry(0).getIndex()).toEqual(2);
63    expect(trace.sliceEntries(2, 4).getEntry(1).getIndex()).toEqual(3);
64  });
65
66  it('getTimestamp()', () => {
67    expect(trace.getEntry(0).getTimestamp()).toEqual(
68      TimestampConverterUtils.makeRealTimestamp(10n),
69    );
70    expect(trace.getEntry(1).getTimestamp()).toEqual(
71      TimestampConverterUtils.makeRealTimestamp(11n),
72    );
73  });
74
75  it('getFramesRange()', () => {
76    expect(trace.getEntry(0).getFramesRange()).toEqual({start: 0, end: 2});
77    expect(trace.getEntry(1).getFramesRange()).toEqual({start: 1, end: 2});
78    expect(trace.getEntry(2).getFramesRange()).toEqual({start: 1, end: 2});
79    expect(trace.getEntry(3).getFramesRange()).toEqual({start: 2, end: 3});
80    expect(trace.getEntry(4).getFramesRange()).toEqual(undefined);
81    expect(trace.getEntry(5).getFramesRange()).toEqual({start: 4, end: 5});
82  });
83
84  it('getValue()', async () => {
85    expect(await trace.getEntry(0).getValue()).toEqual('entry-0');
86    expect(await trace.getEntry(1).getValue()).toEqual('entry-1');
87  });
88});
89