• 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 {TimestampConverterUtils} from 'test/unit/timestamp_converter_utils';
18import {TraceBuilder} from 'test/unit/trace_builder';
19import {UnitTestUtils} from 'test/unit/utils';
20import {Trace} from './trace';
21
22describe('TraceEntry', () => {
23  let trace: Trace<string>;
24
25  beforeAll(() => {
26    jasmine.addCustomEqualityTester(UnitTestUtils.timestampEqualityTester);
27    trace = new TraceBuilder<string>()
28      .setTimestamps([
29        TimestampConverterUtils.makeRealTimestamp(10n),
30        TimestampConverterUtils.makeRealTimestamp(11n),
31        TimestampConverterUtils.makeRealTimestamp(12n),
32        TimestampConverterUtils.makeRealTimestamp(13n),
33        TimestampConverterUtils.makeRealTimestamp(14n),
34        TimestampConverterUtils.makeRealTimestamp(15n),
35      ])
36      .setEntries([
37        'entry-0',
38        'entry-1',
39        'entry-2',
40        'entry-3',
41        'entry-4',
42        'entry-5',
43      ])
44      .setFrame(0, 0)
45      .setFrame(0, 1)
46      .setFrame(1, 1)
47      .setFrame(2, 1)
48      .setFrame(3, 2)
49      .setFrame(5, 4)
50      .build();
51  });
52
53  it('getFullTrace()', () => {
54    expect(trace.getEntry(0).getFullTrace()).toEqual(trace);
55    expect(trace.sliceEntries(0, 1).getEntry(0).getFullTrace()).toEqual(trace);
56  });
57
58  it('getIndex()', () => {
59    expect(trace.getEntry(0).getIndex()).toEqual(0);
60    expect(trace.sliceEntries(2, 4).getEntry(0).getIndex()).toEqual(2);
61    expect(trace.sliceEntries(2, 4).getEntry(1).getIndex()).toEqual(3);
62  });
63
64  it('getTimestamp()', () => {
65    expect(trace.getEntry(0).getTimestamp()).toEqual(
66      TimestampConverterUtils.makeRealTimestamp(10n),
67    );
68    expect(trace.getEntry(1).getTimestamp()).toEqual(
69      TimestampConverterUtils.makeRealTimestamp(11n),
70    );
71  });
72
73  it('getFramesRange()', () => {
74    expect(trace.getEntry(0).getFramesRange()).toEqual({start: 0, end: 2});
75    expect(trace.getEntry(1).getFramesRange()).toEqual({start: 1, end: 2});
76    expect(trace.getEntry(2).getFramesRange()).toEqual({start: 1, end: 2});
77    expect(trace.getEntry(3).getFramesRange()).toEqual({start: 2, end: 3});
78    expect(trace.getEntry(4).getFramesRange()).toEqual(undefined);
79    expect(trace.getEntry(5).getFramesRange()).toEqual({start: 4, end: 5});
80  });
81
82  it('getValue()', async () => {
83    expect(await trace.getEntry(0).getValue()).toEqual('entry-0');
84    expect(await trace.getEntry(1).getValue()).toEqual('entry-1');
85  });
86});
87