1 /*
2 * Copyright (C) 2022 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
17 #include <gtest/gtest.h>
18
19 #include <binder/Parcel.h>
20
21 #include <gui/VsyncEventData.h>
22
23 namespace android {
24
25 using gui::ParcelableVsyncEventData;
26 using gui::VsyncEventData;
27 using FrameTimeline = gui::VsyncEventData::FrameTimeline;
28
29 namespace test {
30
TEST(ParcelableVsyncEventData,Parcelling)31 TEST(ParcelableVsyncEventData, Parcelling) {
32 ParcelableVsyncEventData data;
33 data.vsync.frameInterval = 789;
34 data.vsync.preferredFrameTimelineIndex = 1;
35 FrameTimeline timeline0 = FrameTimeline{1, 2, 3};
36 FrameTimeline timeline1 = FrameTimeline{4, 5, 6};
37 data.vsync.frameTimelines[0] = timeline0;
38 data.vsync.frameTimelines[1] = timeline1;
39 data.vsync.frameTimelinesLength = 2;
40
41 Parcel p;
42 data.writeToParcel(&p);
43 p.setDataPosition(0);
44
45 ParcelableVsyncEventData data2;
46 data2.readFromParcel(&p);
47 ASSERT_EQ(data.vsync.frameInterval, data2.vsync.frameInterval);
48 ASSERT_EQ(data.vsync.preferredFrameTimelineIndex, data2.vsync.preferredFrameTimelineIndex);
49 ASSERT_EQ(data.vsync.frameTimelinesLength, data2.vsync.frameTimelinesLength);
50 for (int i = 0; i < VsyncEventData::kFrameTimelinesCapacity; i++) {
51 ASSERT_EQ(data.vsync.frameTimelines[i].vsyncId, data2.vsync.frameTimelines[i].vsyncId);
52 ASSERT_EQ(data.vsync.frameTimelines[i].deadlineTimestamp,
53 data2.vsync.frameTimelines[i].deadlineTimestamp);
54 ASSERT_EQ(data.vsync.frameTimelines[i].expectedPresentationTime,
55 data2.vsync.frameTimelines[i].expectedPresentationTime);
56 }
57 }
58
59 } // namespace test
60 } // namespace android
61