• 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 {Parser} from './parser';
18import {RealTimestamp, Timestamp, TimestampType} from './timestamp';
19import {TraceType} from './trace_type';
20
21export class ParserMock<T> implements Parser<T> {
22  constructor(private readonly timestamps: RealTimestamp[], private readonly entries: T[]) {
23    if (timestamps.length !== entries.length) {
24      throw new Error(`Timestamps and entries must have the same length`);
25    }
26  }
27
28  getTraceType(): TraceType {
29    return TraceType.SURFACE_FLINGER;
30  }
31
32  getLengthEntries(): number {
33    return this.entries.length;
34  }
35
36  getTimestamps(type: TimestampType): Timestamp[] | undefined {
37    if (type !== TimestampType.REAL) {
38      throw new Error('Parser mock contains only real timestamps');
39    }
40    return this.timestamps;
41  }
42
43  getEntry(index: number): Promise<T> {
44    return Promise.resolve(this.entries[index]);
45  }
46
47  getDescriptors(): string[] {
48    return ['MockTrace'];
49  }
50}
51