• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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 {assertDefined} from 'common/assert_utils';
18import {MockLong} from 'test/unit/mock_long';
19import {PropertyTreeBuilder} from 'test/unit/property_tree_builder';
20import {TranslateChanges} from './translate_changes';
21
22describe('TranslateChanges', () => {
23  let operation: TranslateChanges;
24
25  beforeEach(() => {
26    operation = new TranslateChanges();
27  });
28
29  it("decodes 'what' field in LayerState from layerChanges", async () => {
30    const propertyRoot = new PropertyTreeBuilder()
31      .setRootId('TransactionsTraceEntry')
32      .setName('entry')
33      .setIsRoot(true)
34      .setChildren([
35        {
36          name: 'transactions',
37          children: [
38            {
39              name: '0',
40              children: [
41                {
42                  name: 'layerChanges',
43                  children: [
44                    {name: '0', children: [{name: 'what', value: 2}]},
45                    {
46                      name: '1',
47                      children: [{name: 'what', value: new MockLong(2, 0)}],
48                    },
49                    {name: '2', children: [{name: 'what', value: 4294967360}]},
50                    {
51                      name: '3',
52                      children: [{name: 'what', value: new MockLong(64, 1)}],
53                    },
54                  ],
55                },
56              ],
57            },
58          ],
59        },
60      ])
61      .build();
62
63    operation.apply(propertyRoot);
64
65    const layerChanges = assertDefined(
66      propertyRoot
67        .getChildByName('transactions')
68        ?.getChildByName('0')
69        ?.getChildByName('layerChanges'),
70    );
71
72    expect(
73      layerChanges
74        ?.getChildByName('0')
75        ?.getChildByName('what')
76        ?.formattedValue(),
77    ).toEqual('eLayerChanged');
78
79    expect(
80      layerChanges
81        ?.getChildByName('1')
82        ?.getChildByName('what')
83        ?.formattedValue(),
84    ).toEqual('eLayerChanged');
85
86    expect(
87      layerChanges
88        ?.getChildByName('2')
89        ?.getChildByName('what')
90        ?.formattedValue(),
91    ).toEqual('eFlagsChanged | eDestinationFrameChanged');
92
93    expect(
94      layerChanges
95        ?.getChildByName('3')
96        ?.getChildByName('what')
97        ?.formattedValue(),
98    ).toEqual('eFlagsChanged | eDestinationFrameChanged');
99  });
100
101  it("decodes 'what' field in DisplayState from displayChanges", async () => {
102    const propertyRoot = new PropertyTreeBuilder()
103      .setRootId('TransactionsTraceEntry')
104      .setName('entry')
105      .setIsRoot(true)
106      .setChildren([
107        {
108          name: 'transactions',
109          children: [
110            {
111              name: '0',
112              children: [
113                {
114                  name: 'displayChanges',
115                  children: [
116                    {name: '0', children: [{name: 'what', value: 22}]},
117                  ],
118                },
119              ],
120            },
121          ],
122        },
123      ])
124      .build();
125
126    operation.apply(propertyRoot);
127
128    const displayChanges = assertDefined(
129      propertyRoot
130        .getChildByName('transactions')
131        ?.getChildByName('0')
132        ?.getChildByName('displayChanges'),
133    );
134
135    expect(
136      displayChanges
137        ?.getChildByName('0')
138        ?.getChildByName('what')
139        ?.formattedValue(),
140    ).toEqual('eLayerStackChanged | eDisplayProjectionChanged | eFlagsChanged');
141  });
142
143  it("decodes 'what' field in DisplayState from addedDisplays", async () => {
144    const propertyRoot = new PropertyTreeBuilder()
145      .setRootId('TransactionsTraceEntry')
146      .setName('entry')
147      .setIsRoot(true)
148      .setChildren([
149        {
150          name: 'addedDisplays',
151          children: [{name: '0', children: [{name: 'what', value: 22}]}],
152        },
153      ])
154      .build();
155
156    operation.apply(propertyRoot);
157
158    expect(
159      propertyRoot
160        .getChildByName('addedDisplays')
161        ?.getChildByName('0')
162        ?.getChildByName('what')
163        ?.formattedValue(),
164    ).toEqual('eLayerStackChanged | eDisplayProjectionChanged | eFlagsChanged');
165  });
166});
167