1import { decodeAndTransformProto, FILE_TYPES, FILE_DECODERS } from '../src/decode';
2import fs from 'fs';
3import path from 'path';
4import { expectedEntries, expectedLayers, layers_traces } from './traces/ExpectedTraces';
5
6describe("Proto Transformations", () => {
7  it("can transform surface flinger traces", () => {
8    for (var i = 0; i < layers_traces.length; i++) {
9      const trace = layers_traces[i];
10      const buffer = new Uint8Array(fs.readFileSync(path.resolve(__dirname, trace)));
11      const data = decodeAndTransformProto(buffer, FILE_DECODERS[FILE_TYPES.SURFACE_FLINGER_TRACE].decoderParams, true);
12
13      // use final entry as this determines if there was any error in previous entry parsing
14      const transformedEntry = data.entries[data.entries.length-1];
15      const expectedEntry = expectedEntries[i];
16      for (const property in expectedEntry) {
17        expect(transformedEntry[property]).toEqual(expectedEntry[property]);
18      }
19
20      // check final flattened layer
21      const transformedLayer = transformedEntry.flattenedLayers[transformedEntry.flattenedLayers.length-1];
22      const expectedLayer = expectedLayers[i];
23      for (const property in expectedLayer) {
24        expect(transformedLayer[property]).toEqual(expectedLayer[property]);
25      }
26    }
27  });
28});
29