Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 <input/InputTransport.h> |
| 18 | #include <input/Input.h> |
| 19 | |
| 20 | namespace android { |
| 21 | |
| 22 | #define CHECK_OFFSET(type, member, expected_offset) \ |
Chih-Hung Hsieh | 4a186d4 | 2016-05-20 11:33:26 -0700 | [diff] [blame] | 23 | static_assert((offsetof(type, member) == (expected_offset)), "") |
Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 24 | |
| 25 | struct Foo { |
| 26 | uint32_t dummy; |
| 27 | PointerCoords coords; |
| 28 | }; |
| 29 | |
| 30 | void TestPointerCoordsAlignment() { |
| 31 | CHECK_OFFSET(Foo, coords, 8); |
| 32 | } |
| 33 | |
| 34 | void TestInputMessageAlignment() { |
| 35 | CHECK_OFFSET(InputMessage, body, 8); |
| 36 | |
| 37 | CHECK_OFFSET(InputMessage::Body::Key, seq, 0); |
| 38 | CHECK_OFFSET(InputMessage::Body::Key, eventTime, 8); |
| 39 | CHECK_OFFSET(InputMessage::Body::Key, deviceId, 16); |
| 40 | CHECK_OFFSET(InputMessage::Body::Key, source, 20); |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 41 | CHECK_OFFSET(InputMessage::Body::Key, displayId, 24); |
| 42 | CHECK_OFFSET(InputMessage::Body::Key, action, 28); |
| 43 | CHECK_OFFSET(InputMessage::Body::Key, flags, 32); |
| 44 | CHECK_OFFSET(InputMessage::Body::Key, keyCode, 36); |
| 45 | CHECK_OFFSET(InputMessage::Body::Key, scanCode, 40); |
| 46 | CHECK_OFFSET(InputMessage::Body::Key, metaState, 44); |
| 47 | CHECK_OFFSET(InputMessage::Body::Key, repeatCount, 48); |
| 48 | CHECK_OFFSET(InputMessage::Body::Key, downTime, 56); |
Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 49 | |
| 50 | CHECK_OFFSET(InputMessage::Body::Motion, seq, 0); |
| 51 | CHECK_OFFSET(InputMessage::Body::Motion, eventTime, 8); |
| 52 | CHECK_OFFSET(InputMessage::Body::Motion, deviceId, 16); |
| 53 | CHECK_OFFSET(InputMessage::Body::Motion, source, 20); |
Tarandeep Singh | 5864150 | 2017-07-31 10:51:54 -0700 | [diff] [blame] | 54 | CHECK_OFFSET(InputMessage::Body::Motion, displayId, 24); |
| 55 | CHECK_OFFSET(InputMessage::Body::Motion, action, 28); |
| 56 | CHECK_OFFSET(InputMessage::Body::Motion, actionButton, 32); |
| 57 | CHECK_OFFSET(InputMessage::Body::Motion, flags, 36); |
| 58 | CHECK_OFFSET(InputMessage::Body::Motion, metaState, 40); |
| 59 | CHECK_OFFSET(InputMessage::Body::Motion, buttonState, 44); |
Siarhei Vishniakou | 16a2e30 | 2019-01-14 19:21:45 -0800 | [diff] [blame^] | 60 | CHECK_OFFSET(InputMessage::Body::Motion, classification, 48); |
| 61 | CHECK_OFFSET(InputMessage::Body::Motion, edgeFlags, 52); |
Tarandeep Singh | 5864150 | 2017-07-31 10:51:54 -0700 | [diff] [blame] | 62 | CHECK_OFFSET(InputMessage::Body::Motion, downTime, 56); |
| 63 | CHECK_OFFSET(InputMessage::Body::Motion, xOffset, 64); |
| 64 | CHECK_OFFSET(InputMessage::Body::Motion, yOffset, 68); |
| 65 | CHECK_OFFSET(InputMessage::Body::Motion, xPrecision, 72); |
| 66 | CHECK_OFFSET(InputMessage::Body::Motion, yPrecision, 76); |
| 67 | CHECK_OFFSET(InputMessage::Body::Motion, pointerCount, 80); |
| 68 | CHECK_OFFSET(InputMessage::Body::Motion, pointers, 88); |
Siarhei Vishniakou | 1f7c0e4 | 2018-11-16 22:18:53 -0800 | [diff] [blame] | 69 | |
| 70 | CHECK_OFFSET(InputMessage::Body::Finished, seq, 0); |
| 71 | CHECK_OFFSET(InputMessage::Body::Finished, handled, 4); |
Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | } // namespace android |