blob: f114522951071adf3abee92c6882c0caf9eb6074 [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
Rachel Leeb9c5a772022-02-04 21:17:37 -080025using gui::ParcelableVsyncEventData;
Rachel Lee18c34372022-01-20 13:57:18 -080026using gui::VsyncEventData;
27using FrameTimeline = gui::VsyncEventData::FrameTimeline;
28
29namespace test {
30
Rachel Leeb9c5a772022-02-04 21:17:37 -080031TEST(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;
Rachel Lee18c34372022-01-20 13:57:18 -080039
40 Parcel p;
41 data.writeToParcel(&p);
42 p.setDataPosition(0);
43
Rachel Leeb9c5a772022-02-04 21:17:37 -080044 ParcelableVsyncEventData data2;
Rachel Lee18c34372022-01-20 13:57:18 -080045 data2.readFromParcel(&p);
Rachel Leeb9c5a772022-02-04 21:17:37 -080046 ASSERT_EQ(data.vsync.frameInterval, data2.vsync.frameInterval);
47 ASSERT_EQ(data.vsync.preferredFrameTimelineIndex, data2.vsync.preferredFrameTimelineIndex);
48 for (int i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) {
49 ASSERT_EQ(data.vsync.frameTimelines[i].vsyncId, data2.vsync.frameTimelines[i].vsyncId);
50 ASSERT_EQ(data.vsync.frameTimelines[i].deadlineTimestamp,
51 data2.vsync.frameTimelines[i].deadlineTimestamp);
52 ASSERT_EQ(data.vsync.frameTimelines[i].expectedPresentationTime,
53 data2.vsync.frameTimelines[i].expectedPresentationTime);
Rachel Lee18c34372022-01-20 13:57:18 -080054 }
55}
56
Rachel Lee18c34372022-01-20 13:57:18 -080057} // namespace test
58} // namespace android