• 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 {TamperedMessageType} from 'parsers/tampered_message_type';
18import root from 'protos/test/fake_proto/json';
19import {FakeProtoTransformer} from './fake_proto_transformer';
20
21describe('FakeProtoTransformer', () => {
22  let transformer: FakeProtoTransformer;
23
24  beforeAll(() => {
25    transformer = new FakeProtoTransformer(
26      TamperedMessageType.tamper(root.lookupType('Entry')),
27    );
28  });
29
30  it('sets default value (empty array) of array fields', () => {
31    const proto = {};
32    const transformed = transformer.transform(proto);
33    expect(transformed.array).toEqual([]);
34  });
35
36  it('does not decode enum fields', () => {
37    const proto = {
38      enum0: 1n,
39      enum1: 1n,
40    };
41    const transformed = transformer.transform(proto);
42    expect(transformed.enum0).toEqual(1);
43    expect(transformed.enum1).toEqual(1);
44  });
45
46  it('converts fields to number if 32-bits type', () => {
47    const proto = {
48      number_32bit: 32n,
49    };
50    const transformed = transformer.transform(proto);
51    expect(transformed.number_32bit).toEqual(32);
52  });
53
54  it('converts fields to bigint if 64-bits type', () => {
55    const proto = {
56      number_64bit: 64,
57    };
58    const transformed = transformer.transform(proto);
59    expect(transformed.number_64bit).toEqual(64n);
60  });
61});
62