blob: a670d42fe34c19aa0a92531a8e641680585be7f8 [file] [log] [blame]
Rachel Lee18c34372022-01-20 13:57:18 -08001/*
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
23namespace android {
24
25using gui::VsyncEventData;
26using FrameTimeline = gui::VsyncEventData::FrameTimeline;
27
28namespace test {
29
30TEST(VsyncEventData, Parcelling) {
31 VsyncEventData data;
32 data.id = 123;
33 data.deadlineTimestamp = 456;
34 data.frameInterval = 789;
35 data.preferredFrameTimelineIndex = 1;
36 FrameTimeline timeline0 = FrameTimeline(1, 2, 3);
37 FrameTimeline timeline1 = FrameTimeline(4, 5, 6);
38 data.frameTimelines[0] = timeline0;
39 data.frameTimelines[1] = timeline1;
40
41 Parcel p;
42 data.writeToParcel(&p);
43 p.setDataPosition(0);
44
45 VsyncEventData data2;
46 data2.readFromParcel(&p);
47 ASSERT_EQ(data.id, data2.id);
48 ASSERT_EQ(data.deadlineTimestamp, data2.deadlineTimestamp);
49 ASSERT_EQ(data.frameInterval, data2.frameInterval);
50 ASSERT_EQ(data.preferredFrameTimelineIndex, data2.preferredFrameTimelineIndex);
51 for (int i = 0; i < data.frameTimelines.size(); i++) {
52 ASSERT_EQ(data.frameTimelines[i].id, data2.frameTimelines[i].id);
53 ASSERT_EQ(data.frameTimelines[i].deadlineTimestamp,
54 data2.frameTimelines[i].deadlineTimestamp);
55 ASSERT_EQ(data.frameTimelines[i].expectedPresentTime,
56 data2.frameTimelines[i].expectedPresentTime);
57 }
58}
59
60TEST(FrameTimeline, Parcelling) {
61 FrameTimeline timeline = FrameTimeline(1, 2, 3);
62
63 Parcel p;
64 timeline.writeToParcel(&p);
65 p.setDataPosition(0);
66
67 FrameTimeline timeline2;
68 timeline2.readFromParcel(&p);
69 ASSERT_EQ(timeline.id, timeline2.id);
70 ASSERT_EQ(timeline.deadlineTimestamp, timeline2.deadlineTimestamp);
71 ASSERT_EQ(timeline.expectedPresentTime, timeline2.expectedPresentTime);
72}
73
74} // namespace test
75} // namespace android