| Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2020 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 | #include <gui/DisplayEventReceiver.h> | 
|  | 19 |  | 
|  | 20 | namespace android::test { | 
|  | 21 |  | 
|  | 22 | #define CHECK_OFFSET(type, member, expected_offset) \ | 
|  | 23 | static_assert((offsetof(type, member) == (expected_offset)), "") | 
|  | 24 |  | 
|  | 25 | TEST(DisplayEventStructLayoutTest, TestEventAlignment) { | 
|  | 26 | CHECK_OFFSET(DisplayEventReceiver::Event, vsync, 24); | 
|  | 27 | CHECK_OFFSET(DisplayEventReceiver::Event, hotplug, 24); | 
|  | 28 | CHECK_OFFSET(DisplayEventReceiver::Event, config, 24); | 
|  | 29 |  | 
|  | 30 | CHECK_OFFSET(DisplayEventReceiver::Event::Header, type, 0); | 
|  | 31 | CHECK_OFFSET(DisplayEventReceiver::Event::Header, displayId, 8); | 
|  | 32 | CHECK_OFFSET(DisplayEventReceiver::Event::Header, timestamp, 16); | 
|  | 33 |  | 
|  | 34 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, count, 0); | 
|  | 35 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, expectedVSyncTimestamp, 8); | 
| Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 36 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, deadlineTimestamp, 16); | 
|  | 37 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, vsyncId, 24); | 
| Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 38 |  | 
|  | 39 | CHECK_OFFSET(DisplayEventReceiver::Event::Hotplug, connected, 0); | 
|  | 40 |  | 
|  | 41 | CHECK_OFFSET(DisplayEventReceiver::Event::Config, configId, 0); | 
|  | 42 | CHECK_OFFSET(DisplayEventReceiver::Event::Config, vsyncPeriod, 8); | 
|  | 43 | } | 
|  | 44 |  | 
|  | 45 | } // namespace android::test |